51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
using Chickensoft.AutoInject;
|
|
using Chickensoft.GodotNodeInterfaces;
|
|
using Chickensoft.Introspection;
|
|
using GameJamDungeon;
|
|
using Godot;
|
|
using System.Linq;
|
|
|
|
[Meta(typeof(IAutoNode))]
|
|
public partial class ThrowableItem : Node3D, IInventoryItem
|
|
{
|
|
public override void _Notification(int what) => this.Notify(what);
|
|
|
|
[Dependency] public IGameRepo GameRepo => this.DependOn<IGameRepo>();
|
|
|
|
[Node] public IAnimationPlayer AnimationPlayer { get; set; } = default!;
|
|
|
|
[Node] public IHitbox Hitbox { get; set; } = default!;
|
|
|
|
public InventoryItemInfo Info => ThrowableItemInfo;
|
|
|
|
[Export]
|
|
public ThrowableItemInfo ThrowableItemInfo { get; set; }
|
|
|
|
[Node] public Sprite3D Sprite { get; set; } = default!;
|
|
|
|
[Node] public Area3D Pickup { get; set; } = default!;
|
|
|
|
public void OnReady()
|
|
{
|
|
AnimationPlayer.AnimationFinished += OnAnimationFinished;
|
|
Hitbox.Damage = 5;
|
|
Sprite.Texture = ThrowableItemInfo.Texture;
|
|
Pickup.BodyEntered += OnEntered;
|
|
}
|
|
|
|
public void OnEntered(Node3D body)
|
|
{
|
|
if (GameRepo.InventoryItems.Value.Count() >= GameRepo.MaxItemSize)
|
|
return;
|
|
|
|
var inventoryList = GameRepo.InventoryItems.Value.Append(this).ToList();
|
|
GameRepo.InventoryItems.OnNext(inventoryList);
|
|
QueueFree();
|
|
}
|
|
|
|
private void OnAnimationFinished(StringName animName)
|
|
{
|
|
QueueFree();
|
|
}
|
|
}
|