Pick up thrown items

This commit is contained in:
2025-03-27 00:37:16 -07:00
parent 096786f97e
commit 2378030a0f
5 changed files with 53 additions and 8 deletions

View File

@@ -20,23 +20,39 @@ public partial class ThrownItem : RigidBody3D
[Node] public Sprite2D Sprite { get; set; } = default!;
[Node] public Area3D Collision { get; set; } = default!;
public void OnResolved()
{
BodyEntered += ThrownItem_BodyEntered;
Collision.AreaEntered += Collision_AreaEntered;
GlobalPosition = Player.CurrentPosition;
Sprite.Texture = ItemThatIsThrown.GetTexture();
AddCollisionExceptionWith((Node)Player);
Collision.SetCollisionLayerValue(3, false);
}
private void ThrownItem_BodyEntered(Node body)
private void Collision_AreaEntered(Area3D area)
{
if (body is IEnemy enemy)
if (area.GetOwner() is IEnemy enemy)
{
CalculateEffect(enemy);
QueueFree();
}
else if (ItemThatIsThrown is ThrowableItem)
}
private void ThrownItem_BodyEntered(Node body)
{
if (ItemThatIsThrown is ThrowableItem)
{
QueueFree();
}
else
{
RemoveCollisionExceptionWith((Node)Player);
Collision.SetCollisionLayerValue(3, true);
}
}
public void Throw(EffectService effectService)
@@ -84,6 +100,9 @@ public partial class ThrownItem : RigidBody3D
private void CalculateEffect(IEnemy enemy)
{
if (ItemThatIsThrown.ItemTag == ItemTag.MysteryItem)
ItemThatIsThrown = Game.RerollItem(ItemThatIsThrown, false);
if (ItemThatIsThrown is ThrowableItem throwableItem)
{
switch (throwableItem.ThrowableItemTag)