Refactor Player class to use components, also use components in Enemy class types and fiddle with boss structure
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,12 @@ namespace Zennysoft.Game.Ma;
|
||||
|
||||
public static class BattleExtensions
|
||||
{
|
||||
public static bool IsCriticalHit(double luckStat)
|
||||
public static bool IsCriticalHit(int luckStat)
|
||||
{
|
||||
var rng = new RandomNumberGenerator();
|
||||
rng.Randomize();
|
||||
var roll = rng.Randf();
|
||||
var isCriticalHit = roll <= luckStat;
|
||||
var isCriticalHit = roll <= (luckStat / 100);
|
||||
return isCriticalHit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
[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")
|
||||
@@ -1,10 +1,11 @@
|
||||
using Chickensoft.Collections;
|
||||
using Zennysoft.Game.Implementation.Components;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
public interface ICharacterStats
|
||||
{
|
||||
public IAutoProp<HealthComponent> HP { get; }
|
||||
public HealthComponent HP { get; }
|
||||
|
||||
public IAutoProp<int> CurrentAttack { get; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user