mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Damage actor handler
This commit is contained in:
parent
335f4d5430
commit
4fd31d7988
7 changed files with 100 additions and 4 deletions
|
|
@ -15,6 +15,8 @@ public partial class Actor : CharacterBody2D
|
|||
private GameManager _gameManager;
|
||||
|
||||
private List<ActorModule> _modules = new();
|
||||
|
||||
public bool IsDestroyed { get; set; }
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ public partial class ActorFreeMovement : MovementHandler
|
|||
get => _parent.MovementDirection;
|
||||
set => _parent.MovementDirection = value;
|
||||
}
|
||||
|
||||
public bool IsDestroyed => _parent.IsDestroyed;
|
||||
|
||||
public override void Init(Actor parent)
|
||||
{
|
||||
|
|
@ -32,6 +34,8 @@ public partial class ActorFreeMovement : MovementHandler
|
|||
|
||||
public override void PhysicsUpdate(double delta)
|
||||
{
|
||||
if (IsDestroyed) return;
|
||||
|
||||
MovementDirection = AggregateInputProviders().Normalized();
|
||||
|
||||
var aimingDirection = GetAimingDirection().Normalized();
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ public partial class AnimationHandler : ActorModule
|
|||
|
||||
protected Actor _parent;
|
||||
|
||||
public bool IsDestroyed => _parent.IsDestroyed;
|
||||
|
||||
public override void Init(Actor parent)
|
||||
{
|
||||
_parent = parent;
|
||||
|
|
@ -25,6 +27,8 @@ public partial class AnimationHandler : ActorModule
|
|||
|
||||
public override void Update(double delta)
|
||||
{
|
||||
if (IsDestroyed) return;
|
||||
|
||||
var direction = _parent.FacingDirection; //GetSnappedDirection();
|
||||
|
||||
if (_parent.Velocity.Length() > 0)
|
||||
|
|
@ -38,7 +42,6 @@ public partial class AnimationHandler : ActorModule
|
|||
_animatedSprite.Play("walk_" + DirectionToString(direction));
|
||||
_animatedSprite.SpeedScale = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void PhysicsUpdate(double delta)
|
||||
|
|
|
|||
66
Scripts/Components/Actors/DamageReceiverActorModule.cs
Normal file
66
Scripts/Components/Actors/DamageReceiverActorModule.cs
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.Actors;
|
||||
|
||||
public partial class DamageReceiverActorModule : ActorModule
|
||||
{
|
||||
protected Actor _actor;
|
||||
|
||||
[Export]
|
||||
public ActorResourceProvider HealthProvider { get; private set; }
|
||||
|
||||
[Export]
|
||||
public bool Invulnerable { get; private set; } = false;
|
||||
|
||||
[Export] protected BulletOwner BulletGroup { get; set; } = BulletOwner.None;
|
||||
|
||||
public override void Init(Actor actor)
|
||||
{
|
||||
_actor = actor;
|
||||
|
||||
HealthProvider.ResourceDepleted += OnDeath;
|
||||
}
|
||||
|
||||
public override void Update(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void PhysicsUpdate(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void _on_damage_hitbox_area_entered(Area2D area)
|
||||
{
|
||||
if (_actor.IsDestroyed) return;
|
||||
if (Invulnerable) return;
|
||||
if (area is not Bullet bullet) return;
|
||||
|
||||
if (BulletGroup is BulletOwner.None)
|
||||
{
|
||||
this.Hit(bullet.Damage);
|
||||
bullet.RequestCollisionDestruction();
|
||||
return;
|
||||
}
|
||||
|
||||
if (bullet.BulletInfo.Owner == BulletGroup) return;
|
||||
|
||||
this.Hit(bullet.Damage);
|
||||
bullet.RequestCollisionDestruction();
|
||||
}
|
||||
|
||||
public void Hit(float damage, DamageType damageType = DamageType.Neutral)
|
||||
{
|
||||
if (_actor.IsDestroyed) return;
|
||||
if (Invulnerable) return;
|
||||
|
||||
HealthProvider.CurrentResource -= damage;
|
||||
}
|
||||
|
||||
protected void OnDeath()
|
||||
{
|
||||
_actor.IsDestroyed = true;
|
||||
GD.Print("Actor dead");
|
||||
}
|
||||
}
|
||||
|
|
@ -19,6 +19,8 @@ public partial class EnemyNavigationMovement : MovementHandler
|
|||
set => _parent.MovementDirection = value;
|
||||
}
|
||||
|
||||
public bool IsDestroyed => _parent.IsDestroyed;
|
||||
|
||||
[Export] private bool _navigationEnabled = false;
|
||||
|
||||
[Export] public float AlarmReactRange = 200f;
|
||||
|
|
@ -83,6 +85,7 @@ public partial class EnemyNavigationMovement : MovementHandler
|
|||
|
||||
public override void PhysicsUpdate(double delta)
|
||||
{
|
||||
if (IsDestroyed) return;
|
||||
if (_actorAi.Ai is not AiState.Enabled)
|
||||
return;
|
||||
|
||||
|
|
@ -149,7 +152,6 @@ public partial class EnemyNavigationMovement : MovementHandler
|
|||
Shoot();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ public partial class EnemyPossessionMovement : ActorFreeMovement
|
|||
{
|
||||
|
||||
private ActorAi _actorAi;
|
||||
|
||||
public bool IsDestroyed => _parent.IsDestroyed;
|
||||
// State accessor
|
||||
|
||||
public override void Init(Actor parent)
|
||||
|
|
@ -16,6 +16,7 @@ public partial class EnemyPossessionMovement : ActorFreeMovement
|
|||
|
||||
public override void PhysicsUpdate(double delta)
|
||||
{
|
||||
if (IsDestroyed) return;
|
||||
if (_actorAi.Ai is AiState.Controlled)
|
||||
base.PhysicsUpdate(delta);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue