using Chickensoft.Collections; using Godot; using Zennysoft.Game.Abstractions; namespace Zennysoft.Ma.Adapter; public interface IGameRepo : IDisposable { event Action? Ended; event Action? CloseInventoryEvent; event Action? AnnounceMessageOnMainScreenEvent; event Action? AnnounceMessageInInventoryEvent; event Action? DoubleExpTimeStart; event Action? DoubleExpTimeEnd; event Action? RemoveItemFromInventoryEvent; event Action? PlayerAttack; event Action? PlayerAttackedWall; event Action? PlayerAttackedEnemy; event Action? EquippedItem; event Action? UnequippedItem; event Action? RestorativePickedUp; void Pause(); void Resume(); IAutoProp IsPaused { get; } public void StartDoubleEXP(TimeSpan lengthOfEffect); public void EndDoubleExp(); public void AnnounceMessageOnMainScreen(string message); public void AnnounceMessageInInventory(string message); public void RemoveItemFromInventory(InventoryItem item); public void OnPlayerAttack(); public void OnPlayerAttackedWall(); public void OnPlayerAttackedEnemy(); public void OnRestorativePickedUp(IHealthPack restorative); public void CloseInventory(); public void GameEnded(); public void OnEquippedItem(EquipableItem item); public void OnUnequippedItem(EquipableItem item); public double ExpRate { get; } } public class GameRepo : IGameRepo { public event Action? Ended; public event Action? CloseInventoryEvent; public event Action? AnnounceMessageOnMainScreenEvent; public event Action? AnnounceMessageInInventoryEvent; public event Action? DoubleExpTimeStart; public event Action? DoubleExpTimeEnd; public event Action? RemoveItemFromInventoryEvent; public event Action? PlayerAttack; public event Action? PlayerAttackedWall; public event Action? PlayerAttackedEnemy; public event Action? EquippedItem; public event Action? UnequippedItem; public event Action? RestorativePickedUp; public IAutoProp IsPaused => _isPaused; private readonly AutoProp _isPaused; public double ExpRate { get; private set; } private bool _disposedValue; public GameRepo() { _isPaused = new AutoProp(true); ExpRate = 1; } public void Pause() { _isPaused.OnNext(true); GD.Print("Paused"); } public void Resume() { _isPaused.OnNext(false); GD.Print("Resume"); } public void StartDoubleEXP(TimeSpan lengthOfEffect) { AnnounceMessageInInventory("Experience points temporarily doubled."); DoubleExpTimeStart?.Invoke(lengthOfEffect.Seconds); ExpRate = 2; } public void EndDoubleExp() { AnnounceMessageOnMainScreen("Experience points effect wore off."); DoubleExpTimeEnd?.Invoke(); ExpRate = 1; } public void AnnounceMessageOnMainScreen(string message) { AnnounceMessageOnMainScreenEvent?.Invoke(message); } public void AnnounceMessageInInventory(string message) { AnnounceMessageInInventoryEvent?.Invoke(message); } public void RemoveItemFromInventory(InventoryItem item) { RemoveItemFromInventoryEvent?.Invoke(item); } public void OnPlayerAttack() { PlayerAttack?.Invoke(); } public void OnPlayerAttackedWall() { PlayerAttackedWall?.Invoke(); } public void OnPlayerAttackedEnemy() { PlayerAttackedEnemy?.Invoke(); } public void OnRestorativePickedUp(IHealthPack restorative) { RestorativePickedUp?.Invoke(restorative); } public void CloseInventory() { CloseInventoryEvent?.Invoke(); } public void OnEquippedItem(EquipableItem item) => EquippedItem?.Invoke(item); public void OnUnequippedItem(EquipableItem item) => UnequippedItem?.Invoke(item); public void GameEnded() { Pause(); Ended?.Invoke(); } protected void Dispose(bool disposing) { if (!_disposedValue) { if (disposing) { _isPaused.OnCompleted(); _isPaused.Dispose(); } _disposedValue = true; } } public void Dispose() { Dispose(disposing: true); GC.SuppressFinalize(this); } }