47 lines
1.1 KiB
C#
47 lines
1.1 KiB
C#
using Chickensoft.Collections;
|
|
|
|
namespace Zennysoft.Game.Implementation.Components;
|
|
|
|
public class VTComponent
|
|
{
|
|
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);
|
|
}
|
|
}
|