forge friendlier health and damage management
Removed knockback though
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Gamesmiths.Forge.Attributes;
|
||||
using Gamesmiths.Forge.Core;
|
||||
using Gamesmiths.Forge.Cues;
|
||||
using Gamesmiths.Forge.Godot.Core;
|
||||
@@ -7,12 +10,12 @@ using Gamesmiths.Forge.Tags;
|
||||
using Movementtests.interfaces;
|
||||
using Movementtests.tools;
|
||||
|
||||
[GlobalClass, Icon("res://assets/ui/IconGodotNode/control/icon_text_panel.png")]
|
||||
public partial class PlayerUi : Control, ICueHandler
|
||||
[GlobalClass, Icon("res://assets/ui/IconGodotNode/control/icon_text_panel.png"), Meta(typeof(IAutoOn), typeof(IAutoConnect))]
|
||||
public partial class PlayerUi : Control
|
||||
{
|
||||
private TextureRect _enemyTarget = null!;
|
||||
private Healthbar _healthbar = null!;
|
||||
private Healthbar _manabar = null!;
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
#region Utils
|
||||
|
||||
public enum TargetState
|
||||
{
|
||||
@@ -20,29 +23,33 @@ public partial class PlayerUi : Control, ICueHandler
|
||||
TargetWouldNotKill,
|
||||
TargetWouldKill
|
||||
}
|
||||
|
||||
public record TargetProperties(TargetState State, Vector2 Position);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Nodes
|
||||
|
||||
[Node] public required TextureRect EnemyTarget { get; set; }
|
||||
[Node] public required ResourceBar Healthbar { get; set; }
|
||||
[Node] public required ResourceBar Manabar { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Exports
|
||||
|
||||
[Export]
|
||||
public Color WouldKillColor { get; set; } = new Color("009c8f");
|
||||
[Export]
|
||||
public Color WouldNotKillColor { get; set; } = new Color("fc001c");
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_enemyTarget = GetNode<TextureRect>("%EnemyTarget");
|
||||
_healthbar = GetNode<Healthbar>("%Healthbar");
|
||||
_manabar = GetNode<Healthbar>("%Manabar");
|
||||
|
||||
var tagsManager = ForgeManagers.Instance.TagsManager;
|
||||
var cuesManager = ForgeManagers.Instance.CuesManager;
|
||||
cuesManager.RegisterCue(Tag.RequestTag(tagsManager, "cues.resources.mana"), this);
|
||||
}
|
||||
|
||||
public void Initialize(float initialHealth, float initialMana)
|
||||
#endregion
|
||||
|
||||
|
||||
public void Initialize(EntityAttribute health, EntityAttribute mana)
|
||||
{
|
||||
_healthbar.Initialize(initialHealth);
|
||||
_manabar.Initialize(initialMana);
|
||||
var tagsManager = ForgeManagers.Instance.TagsManager;
|
||||
Healthbar.Initialize(health, Tag.RequestTag(tagsManager, "cues.resources.health"));
|
||||
Manabar.Initialize(mana, Tag.RequestTag(tagsManager, "cues.resources.mana"));
|
||||
}
|
||||
|
||||
public void SetEnemyTargetProperties(TargetProperties targetProperties)
|
||||
@@ -57,38 +64,8 @@ public partial class PlayerUi : Control, ICueHandler
|
||||
TargetState.TargetWouldKill => WouldKillColor,
|
||||
_ => WouldNotKillColor
|
||||
};
|
||||
_enemyTarget.SetVisible(visible);
|
||||
_enemyTarget.SetPosition(position - _enemyTarget.Size / 2);
|
||||
_enemyTarget.SetModulate(modulation);
|
||||
}
|
||||
|
||||
public void OnHealthChanged(IHealthable healthable, HealthChangedRecord healthChanged)
|
||||
{
|
||||
_healthbar.CurrentHealth = healthChanged.CurrentHealth;
|
||||
}
|
||||
|
||||
public void OnManaChanged(float newValue)
|
||||
{
|
||||
_manabar.CurrentHealth = newValue;
|
||||
}
|
||||
|
||||
public void OnExecute(IForgeEntity? target, CueParameters? parameters)
|
||||
{
|
||||
if (target == null || !parameters.HasValue || !IsInstanceValid(_manabar)) return;
|
||||
|
||||
float magnitude = parameters.Value.Magnitude;
|
||||
_manabar.CurrentHealth += magnitude;
|
||||
}
|
||||
|
||||
public void OnApply(IForgeEntity? target, CueParameters? parameters)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnRemove(IForgeEntity? target, bool interrupted)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnUpdate(IForgeEntity? target, CueParameters? parameters)
|
||||
{
|
||||
EnemyTarget.SetVisible(visible);
|
||||
EnemyTarget.SetPosition(position - EnemyTarget.Size / 2);
|
||||
EnemyTarget.SetModulate(modulation);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user