Add projectiles

This commit is contained in:
2026-02-10 18:03:53 -08:00
parent 2f377d2d7a
commit 92b4e8662f
41 changed files with 2170 additions and 42 deletions

View File

@@ -0,0 +1 @@
uid://cytefxt38q6r7

View File

@@ -1,16 +1,18 @@
using Chickensoft.AutoInject;
using Chickensoft.Introspection;
using Godot;
using System.Linq;
using Zennysoft.Game.Ma;
using Zennysoft.Ma.Adapter;
using Zennysoft.Ma.Adapter.Entity;
[Meta(typeof(IAutoNode))]
public partial class Projectile : Node3D
{
public override void _Notification(int what) => this.Notify(what);
[Dependency] protected IPlayer _player => this.DependOn(() => GetParent().GetChildren().OfType<IPlayer>().Single());
[Dependency] protected IMap _map => this.DependOn<IMap>();
[Dependency] protected IPlayer _player => this.DependOn<IPlayer>();
[Node] public Area3D ProjectileHitbox { get; set; }
@@ -29,15 +31,27 @@ public partial class Projectile : Node3D
AnimationPlayer.Play("RESET");
}
public void Fire()
public bool Fire()
{
if (AnimationPlayer.IsPlaying())
return false;
Reparent((Map)_map);
GlobalPosition = _player.GlobalPosition;
GlobalBasis = _player.GlobalBasis;
AnimationPlayer.Play("Fire");
return true;
}
private void Hitbox_AreaEntered(Area3D area)
{
if (area.GetOwner() is IPlayer)
_player.TakeDamage(new AttackData(AttackData.Damage, AttackData.ElementType));
if (area.GetOwner() is IPlayer player)
player.TakeDamage(new AttackData(AttackData.Damage, AttackData.ElementType));
if (area.GetOwner() is IEnemy enemy)
{
var projectileDamage = new AttackData(AttackData.Damage, AttackData.ElementType, false, false);
var damageDealt = DamageCalculator.CalculateDamage(projectileDamage, enemy.DefenseComponent.CurrentDefense.Value, enemy.ElementalResistanceSet);
enemy.HealthComponent.Damage(damageDealt);
}
AnimationPlayer.Play("RESET");
}
}
}