Revamp boss logic
This commit is contained in:
@@ -31,7 +31,7 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
[Export] protected EnemyStatResource _enemyStatResource { get; set; } = default!;
|
||||
|
||||
[Export]
|
||||
private float _movementSpeed = 2f;
|
||||
protected float _movementSpeed = 2f;
|
||||
#endregion
|
||||
|
||||
#region Node Dependencies
|
||||
@@ -39,16 +39,14 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
|
||||
[Node] private Area3D _lineOfSight { get; set; } = default!;
|
||||
|
||||
[Node] private Timer _attackTimer { get; set; } = default!;
|
||||
[Node] protected Timer _attackTimer { get; set; } = default!;
|
||||
|
||||
[Node] private RayCast3D _raycast { get; set; } = default!;
|
||||
|
||||
[Node] protected IEnemyModelView _enemyModelView { get; set; } = default!;
|
||||
#endregion
|
||||
|
||||
public double CurrentHP => _currentHP.Value;
|
||||
|
||||
private AutoProp<double> _currentHP { get; set; }
|
||||
public AutoProp<double> CurrentHP { get; set; }
|
||||
|
||||
private float _knockbackStrength = 0.0f;
|
||||
|
||||
@@ -80,14 +78,14 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
|
||||
_enemyLogic.Start();
|
||||
|
||||
_currentHP = new AutoProp<double>(_enemyStatResource.MaximumHP);
|
||||
_currentHP.Sync += OnHPChanged;
|
||||
CurrentHP = new AutoProp<double>(_enemyStatResource.MaximumHP);
|
||||
CurrentHP.Sync += OnHPChanged;
|
||||
_lineOfSight.BodyEntered += LineOfSight_BodyEntered;
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
if (CurrentHP <= 0)
|
||||
if (CurrentHP.Value <= 0)
|
||||
return;
|
||||
|
||||
var lookDir = GlobalPosition + Velocity;
|
||||
@@ -118,7 +116,7 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
|
||||
public virtual void TakeDamage(double damage, ElementType elementType, bool isCriticalHit = false, bool ignoreDefense = false, bool ignoreElementalResistance = false)
|
||||
{
|
||||
if (_currentHP.Value > 0)
|
||||
if (CurrentHP.Value > 0)
|
||||
{
|
||||
if (!ignoreElementalResistance)
|
||||
damage = CalculateElementalResistance(damage, elementType);
|
||||
@@ -127,10 +125,10 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
if (isCriticalHit)
|
||||
damage *= 2;
|
||||
GD.Print($"Enemy Hit for {damage} damage.");
|
||||
_currentHP.OnNext(_currentHP.Value - damage);
|
||||
GD.Print("Current HP: " + _currentHP.Value);
|
||||
CurrentHP.OnNext(CurrentHP.Value - damage);
|
||||
GD.Print("Current HP: " + CurrentHP.Value);
|
||||
|
||||
if (_currentHP.Value <= 0)
|
||||
if (CurrentHP.Value <= 0)
|
||||
return;
|
||||
|
||||
_enemyModelView.PlayHitAnimation();
|
||||
@@ -149,7 +147,7 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
|
||||
public void Die()
|
||||
{
|
||||
_currentHP.OnNext(0);
|
||||
CurrentHP.OnNext(0);
|
||||
_enemyLogic.Input(new EnemyLogic.Input.EnemyDefeated());
|
||||
_collisionShape.SetDeferred("disabled", true);
|
||||
_enemyModelView.PlayDeathAnimation();
|
||||
@@ -161,7 +159,7 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
|
||||
public void SetCurrentHP(int targetHP)
|
||||
{
|
||||
_currentHP.OnNext(targetHP);
|
||||
CurrentHP.OnNext(targetHP);
|
||||
}
|
||||
|
||||
public int GetMaximumHP()
|
||||
@@ -169,12 +167,12 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
return _enemyStatResource.MaximumHP;
|
||||
}
|
||||
|
||||
public void StartAttackTimer()
|
||||
public virtual void StartAttackTimer()
|
||||
{
|
||||
_attackTimer.Timeout += OnAttackTimeout;
|
||||
}
|
||||
|
||||
public void StopAttackTimer()
|
||||
public virtual void StopAttackTimer()
|
||||
{
|
||||
_attackTimer.Timeout -= OnAttackTimeout;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user