Drop item
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user