using Chickensoft.Collections; using Godot; using Zennysoft.Game.Abstractions; namespace Zennysoft.Game.Ma.Implementation; 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; 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(IInventoryItem item); public void CloseInventory(); 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 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."); ExpRate = 1; } public void AnnounceMessageOnMainScreen(string message) { AnnounceMessageOnMainScreenEvent?.Invoke(message); } public void AnnounceMessageInInventory(string message) { AnnounceMessageInInventoryEvent?.Invoke(message); } public void RemoveItemFromInventory(IInventoryItem item) { RemoveItemFromInventoryEvent?.Invoke(item); } public void CloseInventory() { CloseInventoryEvent?.Invoke(); } public void OnGameEnded() { 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); } }