Refactor stats
This commit is contained in:
@@ -1,52 +0,0 @@
|
||||
using Chickensoft.Collections;
|
||||
using Godot;
|
||||
|
||||
namespace Zennysoft.Game.Implementation.Components;
|
||||
|
||||
public class AttackComponent
|
||||
{
|
||||
public IAutoProp<int> CurrentAttack => _currentAttack;
|
||||
|
||||
public IAutoProp<int> MaximumAttack => _maximumAttack;
|
||||
|
||||
public IAutoProp<int> BonusAttack => _bonusAttack;
|
||||
|
||||
public int TotalAttack => CurrentAttack.Value + BonusAttack.Value;
|
||||
|
||||
private readonly AutoProp<int> _currentAttack;
|
||||
|
||||
private readonly AutoProp<int> _maximumAttack;
|
||||
|
||||
private readonly AutoProp<int> _bonusAttack;
|
||||
|
||||
public AttackComponent(int attackValue)
|
||||
{
|
||||
_maximumAttack = new AutoProp<int>(attackValue);
|
||||
_currentAttack = new AutoProp<int>(attackValue);
|
||||
_bonusAttack = new AutoProp<int>(0);
|
||||
}
|
||||
|
||||
public void Restore(int restoreAmount)
|
||||
{
|
||||
var cappedAmount = Math.Min(restoreAmount + _currentAttack.Value, _maximumAttack.Value);
|
||||
_currentAttack.OnNext(cappedAmount);
|
||||
}
|
||||
|
||||
public void Reduce(int reduceAmount)
|
||||
{
|
||||
var cappedAmount = Math.Max(_currentAttack.Value - reduceAmount, 0);
|
||||
_currentAttack.OnNext(cappedAmount);
|
||||
}
|
||||
|
||||
public void SetAttack(int attack)
|
||||
{
|
||||
var cappedAmount = Math.Min(attack, _maximumAttack.Value);
|
||||
_currentAttack.OnNext(cappedAmount);
|
||||
}
|
||||
|
||||
public void RaiseMaximumAttack(int raiseAmount)
|
||||
{
|
||||
_maximumAttack.OnNext(raiseAmount);
|
||||
Restore(raiseAmount);
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
using Chickensoft.Collections;
|
||||
using Godot;
|
||||
|
||||
namespace Zennysoft.Game.Implementation.Components;
|
||||
|
||||
public class DefenseComponent
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public enum ElementType
|
||||
{
|
||||
None,
|
||||
Aeolic,
|
||||
Telluric,
|
||||
Hydric,
|
||||
Igneous,
|
||||
Ferrum
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
using Chickensoft.Collections;
|
||||
|
||||
namespace Zennysoft.Game.Implementation.Components;
|
||||
|
||||
public class ExperiencePointsComponent
|
||||
{
|
||||
public IAutoProp<int> CurrentExp => _currentExp;
|
||||
|
||||
public IAutoProp<int> ExpToNextLevel => _expToNextLevel;
|
||||
|
||||
public IAutoProp<double> ExpGainRate => _expGainRate;
|
||||
|
||||
public IAutoProp<int> Level => _level;
|
||||
|
||||
private readonly AutoProp<int> _currentExp;
|
||||
|
||||
private readonly AutoProp<int> _expToNextLevel;
|
||||
|
||||
private readonly AutoProp<double> _expGainRate;
|
||||
|
||||
private readonly AutoProp<int> _level;
|
||||
|
||||
public ExperiencePointsComponent()
|
||||
{
|
||||
var firstLevelExpRequirement = ExpToNextLevelCalculation(1);
|
||||
_expToNextLevel = new AutoProp<int>(firstLevelExpRequirement);
|
||||
_currentExp = new AutoProp<int>(0);
|
||||
_expGainRate = new AutoProp<double>(1.0);
|
||||
_level = new AutoProp<int>(1);
|
||||
}
|
||||
|
||||
public void Gain(int baseExpGain)
|
||||
{
|
||||
var modifiedExpGain = baseExpGain * _expGainRate.Value;
|
||||
var newCurrentExpTotal = modifiedExpGain + _currentExp.Value;
|
||||
while (modifiedExpGain + _currentExp.Value >= _expToNextLevel.Value)
|
||||
LevelUp();
|
||||
var cappedAmount = Math.Min(baseExpGain + _currentExp.Value, _expToNextLevel.Value);
|
||||
_currentExp.OnNext(cappedAmount);
|
||||
}
|
||||
|
||||
public void LevelUp()
|
||||
{
|
||||
_level.OnNext(_level.Value + 1);
|
||||
var expToNextLevel = ExpToNextLevelCalculation(_level.Value);
|
||||
_currentExp.OnNext(_currentExp.Value - _expToNextLevel.Value);
|
||||
_expToNextLevel.OnNext(expToNextLevel);
|
||||
}
|
||||
|
||||
private int ExpToNextLevelCalculation(int nextLevel)
|
||||
{
|
||||
return (int)(6.5 * nextLevel + 4.5 * Math.Pow(nextLevel, 2) + Math.Pow(nextLevel, 3));
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
using Chickensoft.Collections;
|
||||
|
||||
namespace Zennysoft.Game.Implementation.Components;
|
||||
|
||||
public class HealthComponent
|
||||
{
|
||||
public IAutoProp<int> CurrentHP => _currentHP;
|
||||
|
||||
public IAutoProp<int> MaximumHP => _maximumHP;
|
||||
|
||||
private readonly AutoProp<int> _currentHP;
|
||||
|
||||
private readonly AutoProp<int> _maximumHP;
|
||||
|
||||
public event Action? HealthReachedZero;
|
||||
public event Action? DamageTaken;
|
||||
|
||||
public bool AtFullHealth => CurrentHP.Value == MaximumHP.Value;
|
||||
|
||||
public HealthComponent(int initialHP)
|
||||
{
|
||||
_maximumHP = new AutoProp<int>(initialHP);
|
||||
_currentHP = new AutoProp<int>(initialHP);
|
||||
}
|
||||
|
||||
public void Heal(int healAmount)
|
||||
{
|
||||
var cappedAmount = Math.Min(healAmount + _currentHP.Value, _maximumHP.Value);
|
||||
_currentHP.OnNext(cappedAmount);
|
||||
}
|
||||
|
||||
public void Damage(int damageAmount)
|
||||
{
|
||||
var cappedAmount = Math.Max(_currentHP.Value - damageAmount, 0);
|
||||
_currentHP.OnNext(cappedAmount);
|
||||
|
||||
if (cappedAmount == 0)
|
||||
HealthReachedZero?.Invoke();
|
||||
else
|
||||
DamageTaken?.Invoke();
|
||||
}
|
||||
|
||||
public void SetHealth(int health)
|
||||
{
|
||||
var cappedAmount = Math.Min(health, _maximumHP.Value);
|
||||
_currentHP.OnNext(cappedAmount);
|
||||
}
|
||||
|
||||
public void RaiseMaximumHP(int raiseAmount)
|
||||
{
|
||||
_maximumHP.OnNext(raiseAmount);
|
||||
Heal(raiseAmount);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using Chickensoft.Collections;
|
||||
|
||||
namespace Zennysoft.Game.Implementation.Components;
|
||||
|
||||
public class LuckComponent
|
||||
{
|
||||
public IAutoProp<int> Luck => _luck;
|
||||
|
||||
private AutoProp<int> _luck;
|
||||
|
||||
public LuckComponent(int initialLuck)
|
||||
{
|
||||
_luck = new AutoProp<int>(initialLuck);
|
||||
}
|
||||
|
||||
public void SetLuck(int value) => _luck.OnNext(value);
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ using Zennysoft.Game.Abstractions;
|
||||
|
||||
namespace Zennysoft.Game.Implementation;
|
||||
|
||||
public class SaveFileManager<T> : ISaveFileManager<T>
|
||||
public class SaveFileManager : ISaveFileManager
|
||||
{
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly JsonSerializerOptions _jsonOptions;
|
||||
@@ -36,14 +36,14 @@ public class SaveFileManager<T> : ISaveFileManager<T>
|
||||
}
|
||||
|
||||
|
||||
public Task<T?> ReadFromFile(params IJsonTypeInfoResolver?[] resolvers)
|
||||
public Task<object?> ReadFromFile(params IJsonTypeInfoResolver?[] resolvers)
|
||||
{
|
||||
if (!_fileSystem.File.Exists(_defaultSaveLocation))
|
||||
throw new FileNotFoundException();
|
||||
return ReadFromFile(_defaultSaveLocation, resolvers);
|
||||
}
|
||||
|
||||
public async Task<T?> ReadFromFile(string filePath, params IJsonTypeInfoResolver?[] resolvers)
|
||||
public async Task<object?> ReadFromFile(string filePath, params IJsonTypeInfoResolver?[] resolvers)
|
||||
{
|
||||
if (!_fileSystem.File.Exists(filePath))
|
||||
throw new FileNotFoundException();
|
||||
@@ -52,15 +52,15 @@ public class SaveFileManager<T> : ISaveFileManager<T>
|
||||
|
||||
var resolver = new SerializableTypeResolver();
|
||||
_jsonOptions.TypeInfoResolver = JsonTypeInfoResolver.Combine([resolver, .. resolvers]);
|
||||
return JsonSerializer.Deserialize<T?>(json, _jsonOptions);
|
||||
return JsonSerializer.Deserialize<object?>(json, _jsonOptions);
|
||||
}
|
||||
|
||||
public Task WriteToFile(T gameData, params IJsonTypeInfoResolver?[] resolvers)
|
||||
public Task WriteToFile<T>(T gameData, params IJsonTypeInfoResolver?[] resolvers)
|
||||
{
|
||||
return WriteToFile(gameData, _defaultSaveLocation, resolvers);
|
||||
}
|
||||
|
||||
public async Task WriteToFile(T gameData, string filePath, params IJsonTypeInfoResolver?[] resolvers)
|
||||
public async Task WriteToFile<T>(T gameData, string filePath, params IJsonTypeInfoResolver?[] resolvers)
|
||||
{
|
||||
var resolver = new SerializableTypeResolver();
|
||||
_jsonOptions.TypeInfoResolver = JsonTypeInfoResolver.Combine([resolver, .. resolvers]);
|
||||
|
||||
Reference in New Issue
Block a user