Rework enemy behavior (still in progress but shouldn't crash)
This commit is contained in:
25
Zennysoft.Game.Ma/src/system/stats/AttackComponent.cs
Normal file
25
Zennysoft.Game.Ma/src/system/stats/AttackComponent.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Collections;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class AttackComponent : Node
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Export]
|
||||
public int InitialMaximumAttack { get; set; }
|
||||
|
||||
public AutoProp<int> MaximumAttack { get; private set; }
|
||||
|
||||
public AutoProp<int> CurrentAttack { get; private set; }
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
MaximumAttack = new AutoProp<int>(InitialMaximumAttack);
|
||||
CurrentAttack = new AutoProp<int>(InitialMaximumAttack);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://dvt65kjs85ro
|
||||
39
Zennysoft.Game.Ma/src/system/stats/HealthComponent.cs
Normal file
39
Zennysoft.Game.Ma/src/system/stats/HealthComponent.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Collections;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class HealthComponent : Node
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Export]
|
||||
public int InitialMaximumHP { get; set; }
|
||||
|
||||
public AutoProp<int> MaximumHP { get; private set; }
|
||||
|
||||
public AutoProp<int> CurrentHP { get; private set; }
|
||||
|
||||
[Signal]
|
||||
public delegate void HealthReachedZeroEventHandler();
|
||||
[Signal]
|
||||
public delegate void HealthLoweredEventHandler();
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
MaximumHP = new AutoProp<int>(InitialMaximumHP);
|
||||
CurrentHP = new AutoProp<int>(InitialMaximumHP);
|
||||
CurrentHP.Changed += CurrentHP_Changed;
|
||||
}
|
||||
|
||||
private void CurrentHP_Changed(int obj)
|
||||
{
|
||||
if (obj <= 0)
|
||||
EmitSignal(SignalName.HealthReachedZero);
|
||||
else
|
||||
EmitSignal(SignalName.HealthLowered);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bne4tlmh1i5e8
|
||||
6
Zennysoft.Game.Ma/src/system/stats/HealthComponent.tscn
Normal file
6
Zennysoft.Game.Ma/src/system/stats/HealthComponent.tscn
Normal file
@@ -0,0 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://bxymnqkoi78oa"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bne4tlmh1i5e8" path="res://src/system/stats/HealthComponent.cs" id="1_177fp"]
|
||||
|
||||
[node name="HealthComponent" type="Node"]
|
||||
script = ExtResource("1_177fp")
|
||||
@@ -4,9 +4,7 @@ namespace Zennysoft.Game.Ma;
|
||||
|
||||
public interface ICharacterStats
|
||||
{
|
||||
public IAutoProp<double> CurrentHP { get; }
|
||||
|
||||
public IAutoProp<double> MaximumHP { get; }
|
||||
public IAutoProp<HealthComponent> HP { get; }
|
||||
|
||||
public IAutoProp<int> CurrentAttack { get; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user