Refactor stats
This commit is contained in:
48
Zennysoft.Game.Ma/src/Components/VTComponent.cs
Normal file
48
Zennysoft.Game.Ma/src/Components/VTComponent.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using Chickensoft.Collections;
|
||||
using System;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
public class VTComponent : IVTComponent
|
||||
{
|
||||
public IAutoProp<int> CurrentVT => _currentVT;
|
||||
|
||||
public IAutoProp<int> MaximumVT => _maximumVT;
|
||||
|
||||
private readonly AutoProp<int> _currentVT;
|
||||
|
||||
private readonly AutoProp<int> _maximumVT;
|
||||
|
||||
public bool AtFullVT => CurrentVT.Value == MaximumVT.Value;
|
||||
|
||||
public VTComponent(int initialVT)
|
||||
{
|
||||
_maximumVT = new AutoProp<int>(initialVT);
|
||||
_currentVT = new AutoProp<int>(initialVT);
|
||||
}
|
||||
|
||||
public void Restore(int restoreAmount)
|
||||
{
|
||||
var cappedAmount = Math.Min(restoreAmount + _currentVT.Value, _maximumVT.Value);
|
||||
_currentVT.OnNext(cappedAmount);
|
||||
}
|
||||
|
||||
public void Reduce(int reduceAmount)
|
||||
{
|
||||
var cappedAmount = Math.Max(_currentVT.Value - reduceAmount, 0);
|
||||
_currentVT.OnNext(cappedAmount);
|
||||
}
|
||||
|
||||
public void SetVT(int vt)
|
||||
{
|
||||
var cappedAmount = Math.Min(vt, _maximumVT.Value);
|
||||
_currentVT.OnNext(cappedAmount);
|
||||
}
|
||||
|
||||
public void RaiseMaximumVT(int raiseAmount)
|
||||
{
|
||||
_maximumVT.OnNext(raiseAmount);
|
||||
Restore(raiseAmount);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user