Refactor stats
This commit is contained in:
63
Zennysoft.Game.Ma/src/Components/DefenseComponent.cs
Normal file
63
Zennysoft.Game.Ma/src/Components/DefenseComponent.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using Chickensoft.Collections;
|
||||
using System;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
public class DefenseComponent : IDefenseComponent
|
||||
{
|
||||
public IAutoProp<int> CurrentDefense => _currentDefense;
|
||||
|
||||
public IAutoProp<int> MaximumDefense => _maximumDefense;
|
||||
|
||||
public IAutoProp<int> BonusDefense => _bonusDefense;
|
||||
|
||||
private readonly AutoProp<int> _currentDefense;
|
||||
|
||||
private readonly AutoProp<int> _maximumDefense;
|
||||
|
||||
private readonly AutoProp<int> _bonusDefense;
|
||||
|
||||
public int TotalDefense => CurrentDefense.Value + BonusDefense.Value;
|
||||
|
||||
public DefenseComponent(int defenseValue)
|
||||
{
|
||||
_maximumDefense = new AutoProp<int>(defenseValue);
|
||||
_currentDefense = new AutoProp<int>(defenseValue);
|
||||
_bonusDefense = new AutoProp<int>(0);
|
||||
}
|
||||
|
||||
public void Restore(int restoreAmount)
|
||||
{
|
||||
var cappedAmount = Math.Min(restoreAmount + _currentDefense.Value, _maximumDefense.Value);
|
||||
_currentDefense.OnNext(cappedAmount);
|
||||
}
|
||||
|
||||
public void Reduce(int reduceAmount)
|
||||
{
|
||||
var cappedAmount = Math.Max(_currentDefense.Value - reduceAmount, 0);
|
||||
_currentDefense.OnNext(cappedAmount);
|
||||
}
|
||||
|
||||
public void SetDefense(int attack)
|
||||
{
|
||||
var cappedAmount = Math.Min(attack, _maximumDefense.Value);
|
||||
_currentDefense.OnNext(cappedAmount);
|
||||
}
|
||||
|
||||
public void RaiseMaximumDefense(int raiseAmount)
|
||||
{
|
||||
_maximumDefense.OnNext(raiseAmount);
|
||||
Restore(raiseAmount);
|
||||
}
|
||||
|
||||
public void RaiseBonusDefense(int raiseAmount)
|
||||
{
|
||||
_bonusDefense.OnNext(_bonusDefense.Value + raiseAmount);
|
||||
}
|
||||
|
||||
public void ResetBonusDefense()
|
||||
{
|
||||
_bonusDefense.OnNext(0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user