Refactor stats

This commit is contained in:
2025-10-22 16:24:07 -07:00
parent 6ec45c4805
commit f0c4e65783
77 changed files with 565 additions and 372 deletions

View File

@@ -1,9 +1,9 @@
using Chickensoft.AutoInject;
using Chickensoft.Introspection;
using Godot;
using System;
using System.Collections.Immutable;
using System.Linq;
using Zennysoft.Game.Implementation.Components;
using Zennysoft.Ma.Adapter;
using Zennysoft.Ma.Adapter.Entity;
@@ -26,11 +26,11 @@ public abstract partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLo
[Dependency] protected IPlayer _player => this.DependOn(() => GetParent().GetChildren().OfType<IPlayer>().Single());
#endregion
public HealthComponent HealthComponent { get; private set; }
public IHealthComponent HealthComponent { get; private set; }
public AttackComponent AttackComponent { get; private set; }
public IAttackComponent AttackComponent { get; private set; }
public DefenseComponent DefenseComponent { get; private set; }
public IDefenseComponent DefenseComponent { get; private set; }
public virtual IEnemyModelView EnemyModelView { get; set; } = default!;
@@ -118,36 +118,6 @@ public abstract partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLo
}
public void SetTarget(Vector3 targetPosition) => TargetPosition = targetPosition;
public virtual void SetEnemyPosition(Vector3 newPosition)
{
GlobalPosition = newPosition;
if (this is IHavePatrolBehavior patrolEnemy)
patrolEnemy.PatrolBehavior.HomePosition = GlobalPosition;
_enemyLogic.Input(new EnemyLogic.Input.Reset());
}
public void LookAtTarget(Vector3 targetPosition)
{
var lookDirection = GlobalPosition - targetPosition;
if (lookDirection != GlobalPosition)
LookAt(new Vector3(lookDirection.X, GlobalPosition.Y, lookDirection.Z), Vector3.Up);
}
public virtual void TakeDamage(int damage)
{
GD.Print($"Enemy Hit for {damage} damage.");
HealthComponent.Damage(damage);
}
private void EnemyModelView_HitPlayer(object sender, System.EventArgs e)
{
_player.TakeDamage(new Damage(AttackComponent.TotalAttack, ElementType.None, false, false, false));
}
public virtual void TakeHit()
{
_enemyLogic.Input(new EnemyLogic.Input.Alert());
@@ -181,4 +151,37 @@ public abstract partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLo
_enemyLogic.Stop();
EnemyBinding.Dispose();
}
public virtual void MoveEnemyToNewRoom(IDungeonRoom newRoom)
{
if (newRoom is MonsterRoom monsterRoom)
{
var spawnPoints = monsterRoom.EnemySpawnPoints.GetChildren().OfType<Marker3D>().ToList();
var spawnPointsGodotCollection = new Godot.Collections.Array<Marker3D>(spawnPoints);
var randomSpawnPoint = spawnPointsGodotCollection.PickRandom();
GlobalPosition = randomSpawnPoint.GlobalPosition;
if (this is IHavePatrolBehavior patrolEnemy)
patrolEnemy.PatrolBehavior.HomePosition = GlobalPosition;
_enemyLogic.Input(new EnemyLogic.Input.Reset());
}
throw new NotImplementedException($"Only {nameof(MonsterRoom)} types are currently supported.");
}
protected void LookAtTarget(Vector3 targetPosition)
{
var lookDirection = GlobalPosition - targetPosition;
if (lookDirection != GlobalPosition)
LookAt(new Vector3(lookDirection.X, GlobalPosition.Y, lookDirection.Z), Vector3.Up);
}
protected void SetTarget(Vector3 targetPosition) => TargetPosition = targetPosition;
private void EnemyModelView_HitPlayer(object sender, System.EventArgs e)
{
_player.TakeDamage(new Damage(AttackComponent.TotalAttack, ElementType.None, false, false, false));
}
}

View File

@@ -18,7 +18,7 @@ public abstract partial class Enemy2D : Enemy
[Node] private EnemyModelView2D _enemyModelView { get; set; } = default!;
public void OnReady()
public void OnEnterTree()
{
LineOfSight.BodyEntered += LineOfSight_BodyEntered;
}

View File

@@ -23,12 +23,16 @@ public partial class FollowBehavior : Node3D, IBehavior
private NavigationAgent3D _navigationAgent;
private Timer _thinkTimer;
public void Init(NavigationAgent3D navigationAgent)
public FollowBehavior()
{
_navigationAgent = navigationAgent;
_thinkTimer = new Timer() { WaitTime = _thinkTime };
_thinkTimer.Timeout += OnTimeout;
AddChild(_thinkTimer);
}
public void Init(NavigationAgent3D navigationAgent)
{
_navigationAgent = navigationAgent;
SetPhysicsProcess(false);
}

View File

@@ -28,11 +28,15 @@ public partial class PatrolBehavior : Node3D, IBehavior
[Signal] public delegate void OnVelocityComputedEventHandler(Vector3 safeVelocity);
public void OnReady()
public PatrolBehavior()
{
_patrolTimer = new Timer() { WaitTime = _patrolTime };
_patrolTimer.Timeout += PatrolTimer_Timeout;
AddChild(_patrolTimer);
}
public void OnReady()
{
SetPhysicsProcess(false);
}

View File

@@ -16,7 +16,7 @@ public partial class Sproingy : Enemy2D, IHavePatrolBehavior, IHaveEngagePlayerB
[Node] public Area3D PlayerDetector { get; set; } = default!;
public new void OnReady()
public void OnReady()
{
FollowBehavior.Init(NavigationAgent);
PatrolBehavior.Init(NavigationAgent);

View File

@@ -81,6 +81,8 @@ shape = SubResource("CylinderShape3D_drfkj")
[node name="EnemyModelView" parent="Visual" instance=ExtResource("4_o3b7p")]
unique_name_in_owner = true
_upperThreshold = 0.5
_lowerThreshold = -0.5
[node name="Components" type="Node3D" parent="."]

View File

@@ -33,46 +33,22 @@ shape = SubResource("CapsuleShape3D_7uhtm")
unique_name_in_owner = true
[node name="Skeleton3D" parent="EnemyModelView/Armature" index="0"]
bones/0/position = Vector3(-0.260271, -1.05324, -1.96773)
bones/0/rotation = Quaternion(0.0915277, -0.692111, -0.0341586, 0.715149)
bones/1/rotation = Quaternion(0.0828172, 0.0642671, -0.39627, 0.91213)
bones/2/rotation = Quaternion(-0.137837, 0.137086, 0.403643, 0.894025)
bones/3/rotation = Quaternion(-0.00338816, 0.00852271, 0.0152662, 0.999842)
bones/4/rotation = Quaternion(0.037164, 0.133882, 0.101977, 0.985036)
bones/5/rotation = Quaternion(-0.0397875, -0.0104688, 0.0235613, 0.998875)
bones/0/position = Vector3(-0.260254, -1.05135, -1.96786)
bones/6/rotation = Quaternion(-0.0474983, -0.294201, -0.744151, 0.597854)
bones/7/rotation = Quaternion(0.0788712, -0.0306685, -0.220772, 0.971647)
bones/8/rotation = Quaternion(-0.127286, 0.0273856, -0.425308, 0.895635)
bones/9/rotation = Quaternion(-0.0931654, 0.0493592, -0.752794, 0.649757)
bones/10/rotation = Quaternion(0.0429966, 0.0102923, 0.363547, 0.930526)
bones/11/rotation = Quaternion(-0.779773, -0.0573165, 0.0817155, 0.618054)
bones/12/rotation = Quaternion(-0.607818, -0.670503, -0.284916, 0.31592)
bones/13/rotation = Quaternion(-0.255941, 0.586097, -0.127235, 0.758153)
bones/14/rotation = Quaternion(-0.513517, -0.227335, -0.228787, 0.795157)
bones/15/rotation = Quaternion(-0.215465, 0.745342, 0.613525, -0.147065)
bones/11/rotation = Quaternion(-0.779814, -0.0573517, 0.0816353, 0.61801)
bones/15/rotation = Quaternion(-0.21544, 0.745303, 0.613567, -0.147118)
bones/16/rotation = Quaternion(-0.486067, -0.16412, -0.362283, 0.778174)
bones/17/rotation = Quaternion(-0.0553629, -0.0361614, 0.62832, 0.77514)
bones/18/rotation = Quaternion(-0.119289, 0.0998131, -0.0173011, 0.987678)
bones/19/position = Vector3(-0.381043, -1.19992, -1.71791)
bones/19/rotation = Quaternion(0.627663, 0.29282, 0.545153, -0.472338)
bones/20/rotation = Quaternion(-0.327815, -0.422723, -0.300673, 0.789581)
bones/21/rotation = Quaternion(-0.0604945, 0.00129838, 0.489705, 0.869786)
bones/22/rotation = Quaternion(0.156218, 0.0483037, -0.624744, 0.763516)
bones/23/rotation = Quaternion(0.123936, -0.00678731, -0.347765, 0.92933)
bones/24/rotation = Quaternion(0.427621, 0.561851, 0.530083, 0.469549)
bones/25/position = Vector3(4.82744, -12.3397, 0.183847)
bones/25/rotation = Quaternion(-0.400051, 0.463947, -0.598439, 0.516317)
bones/26/position = Vector3(-0.0233502, -1.11395, -2.01916)
bones/26/rotation = Quaternion(0.608697, -0.3155, -0.575514, -0.445793)
bones/27/rotation = Quaternion(-0.202236, 0.424675, 0.137941, 0.871622)
bones/28/rotation = Quaternion(-0.0627838, -0.00116445, -0.50126, 0.863015)
bones/29/rotation = Quaternion(0.150998, -0.0515735, 0.668372, 0.726511)
bones/31/position = Vector3(-7.29038, -6.72226, -0.133983)
bones/31/rotation = Quaternion(-0.453784, 0.542292, 0.542291, -0.453784)
bones/32/rotation = Quaternion(0.456756, 0.539878, -0.539587, -0.456893)
bones/19/position = Vector3(-0.379519, -1.19848, -1.72293)
bones/19/rotation = Quaternion(0.627358, 0.293207, 0.545673, -0.471903)
bones/20/rotation = Quaternion(-0.327492, -0.423093, -0.300135, 0.789722)
bones/21/rotation = Quaternion(-0.0604877, 0.00129843, 0.48965, 0.869818)
bones/26/position = Vector3(-0.0278308, -1.11395, -2.01914)
bones/27/rotation = Quaternion(-0.202309, 0.424634, 0.137996, 0.871616)
bones/28/rotation = Quaternion(-0.0627943, -0.00116438, -0.501344, 0.862966)
[node name="BoneAttachment3D" parent="EnemyModelView/Armature/Skeleton3D" index="0"]
transform = Transform3D(-0.266252, -0.0359368, -0.963233, -0.333724, -0.934064, 0.127095, -0.904288, 0.355294, 0.236703, -1.68948, 8.20049, 4.9569)
transform = Transform3D(-0.266252, -0.0359368, -0.963233, -0.333724, -0.934064, 0.127095, -0.904288, 0.355294, 0.236703, -1.68946, 8.20239, 4.95677)
[node name="Collision" type="Area3D" parent="."]
collision_layer = 2048