Made fight fightable

This commit is contained in:
jonathan
2025-09-30 16:23:05 +02:00
parent f27dd199b8
commit 0e315396c9
42 changed files with 889 additions and 251 deletions
+46 -106
View File
@@ -1,131 +1,72 @@
using Godot;
using System;
using Babushka.scripts.CSharp.Common.Fight.ActionDetails;
using Godot;
using Godot.Collections;
namespace Babushka.scripts.CSharp.Common.Fight;
[Tool]
public partial class FighterVisual : Node2D
{
//[Export] public string name;
//[Export] public int maxHealth;
//[Export] public int attackStrength;
//[Export] public int maxActions = 1;
[Export] public FightWorld.Fighter.Type type;
#region Shortcuts
[ExportCategory("References")]
[Export] private Node2D _attackButtons;
[Export] private Node2D _targetButtons;
[Export] private Node2D _targetMarker;
[Export] private Label _healthText;
[Export] private Node2D _visualSprite;
private FightWorld.FightHappeningData HappeningData =>
FightWorld.Instance.fightHappeningData ?? throw new NoFightHappeningException();
[Signal] public delegate void DamageTakenEventHandler();
[Signal] public delegate void AttackingEventHandler();
[Signal] public delegate void DyingEventHandler();
[Signal] public delegate void HealedEventHandler();
#endregion
[ExportCategory("References")]
[Export] private Node2D _visualParent;
[Export] private Node2D _targetSelectionParent;
[Signal]
public delegate void DamageTakenEventHandler();
[Signal]
public delegate void AttackingEventHandler();
[Signal]
public delegate void DyingEventHandler();
[Signal]
public delegate void HealedEventHandler();
private FightWorld.Fighter _boundFighter;
//private void Die()
//{
// _visualSprite.Scale = new Vector2(1, 0.3f);
// EmitSignalDying();
//}
//public override void _Ready()
//{
// UpdateHealthVisual();
// ResetActions();
//}
public void Initialize(FightWorld.Fighter fighter)
{
_boundFighter = fighter;
UpdateHealthVisual();
UpdateMirrorState();
}
public void Attack()
/// <summary>
/// fighter visuals should always look to the right in the scene.
/// This function flips the sprites horizontally, when the fighter is an enemy.
/// </summary>
private void UpdateMirrorState()
{
//FightHappening.SelectAttack(this);
_visualParent.Scale = new Vector2(_boundFighter.isEnemy ? -1 : 1, 1);
}
public void HideAttackButton()
public void SetTargetSelectionActive(bool value)
{
_attackButtons.Hide();
_targetSelectionParent.Visible = value;
_targetSelectionParent.ProcessMode = value ? ProcessModeEnum.Inherit : ProcessModeEnum.Disabled;
}
public void ShowAttackButton()
// listen from inside
public void ClickedTarget()
{
_attackButtons.Show();
}
if (HappeningData.actionStaging!.CurrentDetail() is not TargetSelectActionDetail targetDetail)
throw new InvalidOperationException("No target selection needed right now");
public void HideTargetButtons()
{
_targetButtons.Hide();
targetDetail.SetTarget(_boundFighter);
FightHappening.Instance.DetailFilled();
}
public void ShowTargetButtons()
{
_targetButtons.Show();
}
public void TargetMouseEvent(Node viewport, InputEvent inputEvent, int shapeIdx)
{
if (inputEvent.IsPressed())
ClickedTarget();
}
public void AttackMouseEvent(Node viewport, InputEvent inputEvent, int shapeIdx)
{
if (inputEvent.IsPressed())
ClickedAttack();
}
public void HealMouseEvent(Node viewport, InputEvent inputEvent, int shapeIdx)
{
if (inputEvent.IsPressed())
ClickedHeal();
}
private void ClickedAttack()
{
//FightHappening.SelectAttack(this);
}
private void ClickedHeal()
{
//FightHappening.SelectHeal(this);
}
private void ClickedTarget()
{
//FightHappening.SelectTargetAndAttack(this);
}
public void StartHoverTarget()
{
_targetMarker.Visible = true;
}
public void EndHoverTarget()
{
_targetMarker.Visible = false;
}
public void UpdateHealthVisual()
{
_healthText.Text = $"{_boundFighter.health}";
}
public bool IsDead()
{
//return Health <= 0;
return true;
}
public void ResetActions()
{
//_actions = maxActions;
}
// Animations
public void AttackAnimation(FightAttack attack)
{
EmitSignalAttacking();
@@ -134,7 +75,6 @@ public partial class FighterVisual : Node2D
tween.TweenCallback(Callable.From(() => attack.target?.HitAnimation(attack)));
tween.TweenProperty(this, "position", new Vector2(0, 0), 0.7)
.SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
}
private void HitAnimation(FightAttack attack)
@@ -154,4 +94,4 @@ public partial class FighterVisual : Node2D
tween.TweenProperty(this, "scale", new Vector2(1, 1), 0.4)
.SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
}
}
}