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

@@ -5,11 +5,13 @@ using Godot;
using System;
[Meta(typeof(IAutoNode))]
public partial class ConsumableItem : Node3D, IInventoryItem
public partial class ConsumableItem : Node3D, IUsableItem, IThrowableItem
{
public override void _Notification(int what) => this.Notify(what);
[Dependency] public IGame Game => this.DependOn<IGame>();
[Dependency] public IGameRepo GameRepo => this.DependOn<IGameRepo>();
[Dependency] public IGameEventDepot GameEventDepot => this.DependOn<IGameEventDepot>();
public InventoryItemStats Info => ConsumableItemInfo;
@@ -22,6 +24,21 @@ public partial class ConsumableItem : Node3D, IInventoryItem
public Guid ID => Guid.NewGuid();
public void Use()
{
GameEventDepot.OnHealingItemConsumed(ConsumableItemInfo);
}
public void Throw()
{
var throwableScene = GD.Load<PackedScene>("res://src/items/thrown/ThrownItem.tscn");
var throwable = throwableScene.Instantiate<ThrownItem>();
throwable.ThrownItemStats = ConsumableItemInfo;
Game.AddChild(throwable);
throwable.Throw();
GameRepo.PlayerData.Inventory.Remove(this);
}
public void OnReady()
{
Sprite.Texture = ConsumableItemInfo.Texture;