Add projectiles
This commit is contained in:
1
Zennysoft.Game.Ma/src/system/PlayerProjectile.cs.uid
Normal file
1
Zennysoft.Game.Ma/src/system/PlayerProjectile.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cytefxt38q6r7
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user