(Mostly) show status update when using an item. Need to fix up the equipping code here
This commit is contained in:
@@ -25,9 +25,17 @@ public interface IInventory : INode
|
||||
|
||||
public bool IsEquipped(IEquipable equipable);
|
||||
|
||||
public void Use(IInventoryItem inventoryItem);
|
||||
|
||||
public void Throw(IInventoryItem inventoryItem);
|
||||
|
||||
public void Drop(IInventoryItem inventoryItem);
|
||||
|
||||
event Inventory.InventoryAtCapacityEventHandler InventoryAtCapacity;
|
||||
|
||||
event Inventory.AccessoryUnequippedEventHandler AccessoryUnequipped;
|
||||
|
||||
event Inventory.RaiseStatRequestEventHandler RaiseStatRequest;
|
||||
}
|
||||
|
||||
public partial class Inventory : Node, IInventory
|
||||
@@ -39,6 +47,8 @@ public partial class Inventory : Node, IInventory
|
||||
public delegate void InventoryAtCapacityEventHandler(string rejectedItemName);
|
||||
[Signal]
|
||||
public delegate void AccessoryUnequippedEventHandler(AccessoryStats unequippedAccessory);
|
||||
[Signal]
|
||||
public delegate void RaiseStatRequestEventHandler(ConsumableItemStats consumableItemStats);
|
||||
|
||||
public Inventory()
|
||||
{
|
||||
@@ -108,4 +118,23 @@ public partial class Inventory : Node, IInventory
|
||||
else
|
||||
throw new NotImplementedException("Item type is not supported.");
|
||||
}
|
||||
|
||||
public void Use(IInventoryItem item)
|
||||
{
|
||||
if (item is ConsumableItem consumableItem)
|
||||
{
|
||||
EmitSignal(SignalName.RaiseStatRequest, consumableItem.ConsumableItemInfo);
|
||||
Remove(consumableItem);
|
||||
}
|
||||
}
|
||||
|
||||
public void Throw(IInventoryItem item)
|
||||
{
|
||||
Remove(item);
|
||||
}
|
||||
|
||||
public void Drop(IInventoryItem item)
|
||||
{
|
||||
Remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,5 @@ namespace GameJamDungeon
|
||||
public IGameRepo GameRepo { get; }
|
||||
|
||||
public InventoryItemStats Info { get; }
|
||||
|
||||
public void Throw();
|
||||
|
||||
public void Drop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ using Chickensoft.Introspection;
|
||||
using GameJamDungeon;
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class ConsumableItem : Node3D, IInventoryItem
|
||||
@@ -29,58 +28,6 @@ public partial class ConsumableItem : Node3D, IInventoryItem
|
||||
Pickup.BodyEntered += OnEntered;
|
||||
}
|
||||
|
||||
public void Use()
|
||||
{
|
||||
if (ConsumableItemInfo.RaiseHPAmount != 0)
|
||||
RaiseHP();
|
||||
if (ConsumableItemInfo.RaiseVTAmount != 0)
|
||||
RaiseVT();
|
||||
if (ConsumableItemInfo.HealHPAmount != 0)
|
||||
HealHP();
|
||||
if (ConsumableItemInfo.HealVTAmount != 0)
|
||||
HealVT();
|
||||
|
||||
GameRepo.PlayerData.Inventory.Remove(this);
|
||||
}
|
||||
|
||||
private void RaiseHP()
|
||||
{
|
||||
if (GameRepo.PlayerData.CurrentHP == GameRepo.PlayerData.MaximumHP)
|
||||
{
|
||||
GameRepo.PlayerData.SetMaximumHP(GameRepo.PlayerData.MaximumHP.Value + ConsumableItemInfo.RaiseHPAmount);
|
||||
GameRepo.PlayerData.SetCurrentHP(GameRepo.PlayerData.MaximumHP.Value);
|
||||
}
|
||||
}
|
||||
|
||||
private void HealHP()
|
||||
{
|
||||
GameRepo.PlayerData.SetCurrentHP(GameRepo.PlayerData.CurrentHP.Value + ConsumableItemInfo.HealHPAmount);
|
||||
}
|
||||
|
||||
private void RaiseVT()
|
||||
{
|
||||
if (GameRepo.PlayerData.CurrentVT == GameRepo.PlayerData.MaximumVT)
|
||||
{
|
||||
GameRepo.PlayerData.SetMaximumVT(GameRepo.PlayerData.MaximumVT.Value + ConsumableItemInfo.RaiseVTAmount);
|
||||
GameRepo.PlayerData.SetCurrentVT(GameRepo.PlayerData.MaximumVT.Value);
|
||||
}
|
||||
}
|
||||
|
||||
private void HealVT()
|
||||
{
|
||||
GameRepo.PlayerData.SetCurrentVT(GameRepo.PlayerData.CurrentVT.Value + ConsumableItemInfo.HealVTAmount);
|
||||
}
|
||||
|
||||
public void Throw()
|
||||
{
|
||||
GameRepo.PlayerData.Inventory.Remove(this);
|
||||
}
|
||||
|
||||
public void Drop()
|
||||
{
|
||||
GameRepo.PlayerData.Inventory.Remove(this);
|
||||
}
|
||||
|
||||
public void OnEntered(Node3D body)
|
||||
{
|
||||
var isAdded = GameRepo.PlayerData.Inventory.TryAdd(this);
|
||||
|
||||
Reference in New Issue
Block a user