Refactor character attributes system; replace individual attributes with a dictionary-based approach for better scalability and maintainability
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using Data;
|
||||
using Interfaces;
|
||||
using Attribute = Data.Attribute;
|
||||
|
||||
namespace Modifiers
|
||||
{
|
||||
@@ -9,51 +10,20 @@ namespace Modifiers
|
||||
{
|
||||
private float lastAppliedAmount;
|
||||
|
||||
public Stat stat;
|
||||
public Attribute stat;
|
||||
public float percent;
|
||||
public string Description => GetDescription();
|
||||
|
||||
public void Apply(CharacterAttributes attributes)
|
||||
{
|
||||
var baseValue = GetBaseValue<float>(attributes);
|
||||
var baseValue = attributes.Get(stat);
|
||||
lastAppliedAmount = baseValue * percent;
|
||||
|
||||
var flatModifier = new FlatStatModifier
|
||||
{
|
||||
value = lastAppliedAmount,
|
||||
stat = stat
|
||||
};
|
||||
|
||||
flatModifier.Apply(attributes);
|
||||
attributes.Modify(stat, lastAppliedAmount);
|
||||
}
|
||||
|
||||
public void Remove(CharacterAttributes attributes)
|
||||
{
|
||||
var flatModifier = new FlatStatModifier
|
||||
{
|
||||
value = -lastAppliedAmount,
|
||||
stat = stat
|
||||
};
|
||||
|
||||
flatModifier.Apply(attributes);
|
||||
}
|
||||
|
||||
private T GetBaseValue<T>(CharacterAttributes attributes)
|
||||
{
|
||||
return stat switch
|
||||
{
|
||||
Stat.Health => (T)(object)attributes.Health,
|
||||
Stat.MaxHealth => (T)(object)attributes.MaxHealth,
|
||||
Stat.MoveSpeed => (T)(object)attributes.MoveSpeed,
|
||||
Stat.Luck => (T)(object)attributes.Luck,
|
||||
Stat.Armor => (T)(object)attributes.Armor,
|
||||
Stat.Damage => (T)(object)attributes.Damage,
|
||||
Stat.RangedDamage => (T)(object)attributes.RangedDamage,
|
||||
Stat.MeleeDamage => (T)(object)attributes.MeleeDamage,
|
||||
Stat.AttackRange => (T)(object)attributes.AttackRange,
|
||||
Stat.AttackSpeed => (T)(object)attributes.AttackSpeed,
|
||||
_ => throw new System.ArgumentOutOfRangeException()
|
||||
};
|
||||
attributes.Modify(stat, -lastAppliedAmount);
|
||||
}
|
||||
|
||||
private string GetDescription()
|
||||
|
Reference in New Issue
Block a user