Fix attacks by player and enemy
This commit is contained in:
@@ -8,6 +8,7 @@ namespace GameJamDungeon;
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class Enemy : RigidBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
{
|
||||
#region Registration
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
private IEnemyLogic _enemyLogic { get; set; } = default!;
|
||||
@@ -15,6 +16,7 @@ public partial class Enemy : RigidBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
IEnemyLogic IProvide<IEnemyLogic>.Value() => _enemyLogic;
|
||||
|
||||
public EnemyLogic.IBinding EnemyBinding { get; set; } = default!;
|
||||
#endregion
|
||||
|
||||
#region Dependencies
|
||||
|
||||
@@ -24,7 +26,7 @@ public partial class Enemy : RigidBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
#endregion
|
||||
|
||||
#region Exports
|
||||
[Export] private EnemyStatResource _enemyStatResource { get; set; } = default!;
|
||||
[Export] protected EnemyStatResource _enemyStatResource { get; set; } = default!;
|
||||
#endregion
|
||||
|
||||
#region Node Dependencies
|
||||
@@ -57,11 +59,6 @@ public partial class Enemy : RigidBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
_enemyLogic.Set(GameRepo);
|
||||
}
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
SetPhysicsProcess(true);
|
||||
}
|
||||
|
||||
public void TakeDamage(double damage, ElementType elementType, bool isCriticalHit = false, bool ignoreDefense = false, bool ignoreElementalResistance = false)
|
||||
{
|
||||
if (_currentHP.Value > 0)
|
||||
@@ -77,6 +74,10 @@ public partial class Enemy : RigidBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
GD.Print($"Enemy Hit for {damage} damage.");
|
||||
_currentHP.OnNext(_currentHP.Value - damage);
|
||||
GD.Print("Current HP: " + _currentHP.Value);
|
||||
|
||||
if (_currentHP.Value <= 0)
|
||||
return;
|
||||
|
||||
EnemyModelView.PlayHitAnimation();
|
||||
_enemyLogic.Input(new EnemyLogic.Input.Alerted());
|
||||
}
|
||||
@@ -90,8 +91,8 @@ public partial class Enemy : RigidBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
var velocity = (targetPosition - GlobalTransform.Origin).Normalized() * 2f * delta;
|
||||
var lookAtDir = GlobalTransform.Origin - velocity;
|
||||
var lookAtPosition = new Vector3(lookAtDir.X, GlobalPosition.Y, lookAtDir.Z);
|
||||
if (GlobalPosition.DistanceTo(target) > 1.0f && !velocity.IsEqualApprox(Vector3.Zero) && !GlobalPosition.IsEqualApprox(lookAtPosition))
|
||||
LookAt(lookAtPosition);
|
||||
if (GlobalPosition.DistanceTo(target) > 1.0f && !velocity.IsEqualApprox(Vector3.Zero) && !Position.IsEqualApprox(lookAtPosition))
|
||||
LookAt(lookAtPosition + new Vector3(0.001f, 0.001f, 0.001f), Vector3.Up);
|
||||
EnemyModelView.RotateModel(GlobalTransform.Basis, -GameRepo.PlayerGlobalTransform.Value.Basis.Z);
|
||||
_knockbackStrength = _knockbackStrength * 0.9f;
|
||||
MoveAndCollide(velocity + (_knockbackDirection * _knockbackStrength));
|
||||
@@ -118,7 +119,6 @@ public partial class Enemy : RigidBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
})
|
||||
.Handle((in EnemyLogic.Output.Defeated output) =>
|
||||
{
|
||||
Die();
|
||||
});
|
||||
|
||||
this.Provide();
|
||||
|
||||
Reference in New Issue
Block a user