Pick up thrown items
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user