Drop item

This commit is contained in:
2024-09-22 14:00:52 -07:00
parent 01477b9a0e
commit 490f0d17d2
25 changed files with 401 additions and 257 deletions

View File

@@ -10,27 +10,55 @@ public partial class ThrownItem : RigidBody3D
[Dependency] public IGame Game => this.DependOn<IGame>();
[Node] public Sprite2D Sprite { get; set; } = default!;
public InventoryItemStats ThrownItemStats;
private int _damage = 0;
[Node] public Sprite3D Sprite { get; set; } = default!;
public void OnResolved()
{
BodyEntered += ThrownItem_BodyEntered;
GlobalPosition = Game.Player.GlobalPosition + Vector3.Up;
Sprite.Texture = ThrownItemStats.Texture;
AddCollisionExceptionWith((Node)Game.Player);
}
private void ThrownItem_BodyEntered(Node body)
{
if (body is IEnemy enemy)
enemy.EnemyLogic.Input(new EnemyLogic.Input.HitByPlayer(_damage));
{
if (ThrownItemStats is ThrowableItemStats throwableItemStats)
enemy.EnemyLogic.Input(new EnemyLogic.Input.HitByPlayer(throwableItemStats.Damage));
}
QueueFree();
}
public void Throw(ThrowableItemStats throwableItemStats)
public void Throw()
{
_damage = throwableItemStats.Damage;
ApplyCentralImpulse(Game.Player.GlobalBasis.Z.Normalized() * -20.0f);
ThrowInternal((dynamic)ThrownItemStats);
}
private void ThrowInternal(WeaponStats weaponStats)
{
ApplyCentralImpulse(-Game.Player.GlobalBasis.Z.Normalized() * 5.0f);
}
private void ThrowInternal(ArmorStats armorStats)
{
ApplyCentralImpulse(-Game.Player.GlobalBasis.Z.Normalized() * 5.0f);
}
private void ThrowInternal(AccessoryStats accessoryStats)
{
ApplyCentralImpulse(-Game.Player.GlobalBasis.Z.Normalized() * 5.0f);
}
private void ThrowInternal(ConsumableItemStats consumableItemStats)
{
ApplyCentralImpulse(-Game.Player.GlobalBasis.Z.Normalized() * 5.0f);
}
private void ThrowInternal(ThrowableItemStats throwableItemStats)
{
ApplyCentralImpulse(-Game.Player.GlobalBasis.Z.Normalized() * 20.0f);
}
}