(Mostly) show status update when using an item. Need to fix up the equipping code here

This commit is contained in:
2024-09-12 15:18:09 -07:00
parent 875fa026df
commit f0e75703f6
9 changed files with 200 additions and 78 deletions

View File

@@ -8,6 +8,7 @@ using Godot;
public interface IGame : IProvide<IGameRepo>, IProvide<IGame>, INode3D
{
event Game.StatRaisedAlertEventHandler StatRaisedAlert;
}
[Meta(typeof(IAutoNode))]
@@ -27,6 +28,9 @@ public partial class Game : Node3D, IGame
public GameLogic.IBinding GameBinding { get; set; } = default!;
[Signal]
public delegate void StatRaisedAlertEventHandler(string statRaisedAlert);
[Dependency] public IAppRepo AppRepo => this.DependOn<IAppRepo>();
#region Nodes
@@ -121,6 +125,30 @@ public partial class Game : Node3D, IGame
Map.DungeonFinishedGenerating += Map_DungeonFinishedGenerating;
InGameUI.InventoryMenu.ClosedMenu += InventoryMenu_CloseInventory;
GameRepo.PlayerData.Inventory.InventoryAtCapacity += PlayerInventory_InventoryAtCapacity;
GameRepo.PlayerData.Inventory.RaiseStatRequest += Inventory_RaiseStatRequest;
}
private void Inventory_RaiseStatRequest(ConsumableItemStats consumableItemStats)
{
if (consumableItemStats.RaiseHPAmount > 0 && GameRepo.PlayerData.CurrentHP.Value.Equals(GameRepo.PlayerData.MaximumHP.Value))
RaiseHP(consumableItemStats.RaiseHPAmount);
else if (consumableItemStats.HealHPAmount > 0)
HealHP(consumableItemStats.HealHPAmount);
if (consumableItemStats.RaiseVTAmount > 0 && GameRepo.PlayerData.CurrentVT.Value.Equals(GameRepo.PlayerData.MaximumVT.Value))
RaiseVT(consumableItemStats.RaiseVTAmount);
else if (consumableItemStats.HealVTAmount > 0)
HealVT(consumableItemStats.HealVTAmount);
}
private void RaiseHP(int amountToRaise)
{
if (GameRepo.PlayerData.CurrentHP == GameRepo.PlayerData.MaximumHP)
{
GameRepo.PlayerData.SetMaximumHP(GameRepo.PlayerData.MaximumHP.Value + amountToRaise);
GameRepo.PlayerData.SetCurrentHP(GameRepo.PlayerData.MaximumHP.Value);
EmitSignal(SignalName.StatRaisedAlert, $"{amountToRaise} Maximum HP Up.");
}
}
public void ToggleInventory()
@@ -161,5 +189,27 @@ public partial class Game : Node3D, IGame
GetTree().Paused = isPaused;
}
private void HealHP(int amountToRaise)
{
GameRepo.PlayerData.SetCurrentHP(GameRepo.PlayerData.CurrentHP.Value + amountToRaise);
EmitSignal(SignalName.StatRaisedAlert, $"{amountToRaise}HP Up.");
}
private void RaiseVT(int amountToRaise)
{
if (GameRepo.PlayerData.CurrentVT == GameRepo.PlayerData.MaximumVT)
{
GameRepo.PlayerData.SetMaximumVT(GameRepo.PlayerData.MaximumVT.Value + amountToRaise);
GameRepo.PlayerData.SetCurrentVT(GameRepo.PlayerData.MaximumVT.Value);
EmitSignal(SignalName.StatRaisedAlert, $"{amountToRaise} Maximum VT Up.");
}
}
private void HealVT(int amountToRaise)
{
GameRepo.PlayerData.SetCurrentVT(GameRepo.PlayerData.CurrentVT.Value + amountToRaise);
EmitSignal(SignalName.StatRaisedAlert, $"{amountToRaise}VT Up.");
}
public void OnStart() => GameLogic.Input(new GameLogic.Input.StartGame());
}