Rust
This commit is contained in:
@@ -34,6 +34,8 @@ public abstract partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLo
|
||||
|
||||
public IDefenseComponent DefenseComponent { get; private set; }
|
||||
|
||||
public IStatusEffectComponent StatusEffectComponent { get; private set; }
|
||||
|
||||
public virtual IEnemyModelView EnemyModelView { get; set; } = default!;
|
||||
|
||||
public Vector3 TargetPosition { get; private set; }
|
||||
@@ -69,6 +71,9 @@ public abstract partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLo
|
||||
[Node] private AudioStreamPlayer3D _dieSFX { get; set; } = default!;
|
||||
[Node] private AudioStreamPlayer3D _aggroSFX { get; set; } = default!;
|
||||
|
||||
private Timer _rustTimer;
|
||||
private Timer _rustDuration;
|
||||
|
||||
protected bool _activated = false;
|
||||
private Vector3 _previousPosition = Vector3.Zero;
|
||||
|
||||
@@ -86,8 +91,22 @@ public abstract partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLo
|
||||
HealthComponent.HealthReachedZero += Die;
|
||||
HealthComponent.DamageTaken += TakeHit;
|
||||
|
||||
_rustTimer = new Timer();
|
||||
_rustDuration = new Timer();
|
||||
|
||||
_rustTimer.WaitTime = 3;
|
||||
_rustDuration.WaitTime = 30;
|
||||
_rustTimer.Timeout += _rustTimer_Timeout;
|
||||
_rustDuration.Timeout += _rustDuration_Timeout;
|
||||
|
||||
AddChild(_rustTimer);
|
||||
AddChild(_rustDuration);
|
||||
|
||||
AttackComponent = new AttackComponent(InitialAttack);
|
||||
DefenseComponent = new DefenseComponent(InitialDefense);
|
||||
StatusEffectComponent = new StatusEffectComponent(30);
|
||||
|
||||
StatusEffectComponent.Rust.Changed += OnRusted;
|
||||
|
||||
EnemyBinding
|
||||
.Handle((in EnemyLogic.Output.Activate _) =>
|
||||
@@ -160,6 +179,8 @@ public abstract partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLo
|
||||
public virtual void Die()
|
||||
{
|
||||
SetPhysicsProcess(false);
|
||||
_rustDuration.Stop();
|
||||
_rustTimer.Stop();
|
||||
_enemyLogic.Input(new EnemyLogic.Input.Defeated());
|
||||
_player.ExperiencePointsComponent.Gain(ExpGiven);
|
||||
EnemyModelView.PlayDeathAnimation();
|
||||
@@ -244,4 +265,28 @@ public abstract partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLo
|
||||
{
|
||||
_player.TakeDamage(new AttackData(AttackComponent.CurrentAttack.Value, ElementType.None));
|
||||
}
|
||||
|
||||
private void OnRusted(bool rustStatus)
|
||||
{
|
||||
if (rustStatus)
|
||||
{
|
||||
_rustTimer.Start();
|
||||
_rustDuration.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
_rustTimer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
private void _rustTimer_Timeout()
|
||||
{
|
||||
HealthComponent.Damage(3);
|
||||
TakeHit();
|
||||
}
|
||||
|
||||
private void _rustDuration_Timeout()
|
||||
{
|
||||
StatusEffectComponent.Rust.OnNext(false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user