159 lines
3.1 KiB
C#
159 lines
3.1 KiB
C#
using Chickensoft.Collections;
|
|
using Godot;
|
|
|
|
namespace Zennysoft.Ma.Adapter;
|
|
|
|
public interface IGameRepo : IDisposable
|
|
{
|
|
event Action? Ended;
|
|
|
|
event Action? CloseInventoryEvent;
|
|
|
|
event Action<string>? AnnounceMessageOnMainScreenEvent;
|
|
|
|
event Action<string>? AnnounceMessageInInventoryEvent;
|
|
|
|
event Action<int>? DoubleExpTimeStart;
|
|
|
|
event Action? DoubleExpTimeEnd;
|
|
|
|
event Action<InventoryItem>? RemoveItemFromInventoryEvent;
|
|
|
|
event Action? PlayerAttack;
|
|
|
|
event Action? PlayerAttackedWall;
|
|
|
|
void Pause();
|
|
|
|
void Resume();
|
|
|
|
IAutoProp<bool> 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 CloseInventory();
|
|
|
|
public void GameEnded();
|
|
|
|
public double ExpRate { get; }
|
|
}
|
|
|
|
public class GameRepo : IGameRepo
|
|
{
|
|
public event Action? Ended;
|
|
public event Action? CloseInventoryEvent;
|
|
public event Action<string>? AnnounceMessageOnMainScreenEvent;
|
|
public event Action<string>? AnnounceMessageInInventoryEvent;
|
|
public event Action<int>? DoubleExpTimeStart;
|
|
public event Action? DoubleExpTimeEnd;
|
|
public event Action<InventoryItem>? RemoveItemFromInventoryEvent;
|
|
public event Action? PlayerAttack;
|
|
public event Action? PlayerAttackedWall;
|
|
|
|
public IAutoProp<bool> IsPaused => _isPaused;
|
|
private readonly AutoProp<bool> _isPaused;
|
|
|
|
public double ExpRate { get; private set; }
|
|
|
|
private bool _disposedValue;
|
|
|
|
public GameRepo()
|
|
{
|
|
_isPaused = new AutoProp<bool>(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(InventoryItem item)
|
|
{
|
|
RemoveItemFromInventoryEvent?.Invoke(item);
|
|
}
|
|
|
|
public void OnPlayerAttack()
|
|
{
|
|
PlayerAttack?.Invoke();
|
|
}
|
|
|
|
public void OnPlayerAttackedWall()
|
|
{
|
|
PlayerAttackedWall?.Invoke();
|
|
}
|
|
|
|
public void CloseInventory()
|
|
{
|
|
CloseInventoryEvent?.Invoke();
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|