A flexible, generalized numerical system for computing game values.
- npm:
npm i numericsystem
- github: dlqw/NumericSystem:用于计算游戏值的灵活、通用的数值系统。 --- dlqw/NumericSystem: A flexible, generalized numerical system for computing game values. (github.com)
某一属性的基础值,可读,可写,用于写入永久数值变化
某一属性的最终值,只可读,用于获取经过暂时数值变化修饰的数值的最终值
数值修饰器的链表,用于存贮暂时的数值变化
string 数值修正器的名字
int 同一数值修正器的数量
string[]
- 对于加法修饰器,表示收那些乘法修正器影响
- 对于乘法修正器,表示可以修饰哪些加法修正器(或 basicValue)basicValue 对应的 tag 是 “self”
修正器的比较通过方法 WeakEquals
实现,比较的基准是 类型,值和名字
注意,对 tag 的修改会改变所有同名同值同类型的修饰器
public IntNumeric health = new();
public FloatNumeric speed = new();
[Button]
public void AddHealthBuff()
{
health.AddModifier(new IntNumericModifier(10, "治疗术"));
health += new IntNumericModifier(10);
health = health + new IntNumericModifier(10, "治疗术");
health += (10, "治疗术");
health += 10;
health += new IntNumericModifier(10);
}
public void CreateAndInit()
{
IntNumeric intNumeric = new();
IntNumeric intNumeric2 = new(100);
var intNumeric3 = new IntNumeric(100);
IntNumeric intNumeric4 = 100;
// 这里传入的参数是 basicValue
}
public IntNumeric health = new();
public void ChangeValueForever()
{
health.basicValue = 100;
health.basicValue += 10;
health.basicValue %= 10;
}
IntNumeric health = new();
health.AddModifier(new IntNumericModifier()); //无意义
health.AddModifier(new IntNumericModifier(10));
health.AddModifier(new IntNumericModifier(10, "圣光术"));
health.AddModifier(new IntNumericModifier(10, "圣光术", "self"));
health.AddModifier(new IntNumericModifier(10, "圣光术", "self", "装备"));
health += 10;
health += (10, "圣光术");
health += (10, "圣光术", "self");
health.RemoveModifier(new IntNumericModifier()); //无意义
health.RemoveModifier(new IntNumericModifier(10));
health.RemoveModifier(new IntNumericModifier(10, "圣光术"));
health.RemoveModifier(new IntNumericModifier(10, "圣光术", "self"));
health.RemoveModifier(new IntNumericModifier(10, "圣光术", "self", "装备"));
health -= 10;
health -= (10, "圣光术");
health -= (10, "圣光术", "self");
}
覆盖分数修正器会计算目标加法修正器和基础值与本修正器的值的乘积,并覆盖原来的值。如 原本为 10,经过 1/2 覆盖修正后为 5
增量分数修正器不会覆盖原本的值而是在其基础上增加新的值.如 原本为 10,经过 1/2 增量修正后为 15
health.AddModifier(new IncreaseFractionNumericModifier(1, 2, "修改圣光术", "圣光术"));
health.RemoveModifier(new IncreaseFractionNumericModifier(1, 2, "修改圣光术", "圣光术"));
health.AddModifier(new OverrideFractionNumericModifier(1, 2, "修改圣光术", "圣光术"));
health.RemoveModifier(new OverrideFractionNumericModifier(1, 2, "修改圣光术", "圣光术"));
health *= new IncreaseFractionNumericModifier(1, 2, "修改圣光术", "圣光术");
health /= new IncreaseFractionNumericModifier(1, 2, "修改圣光术", "圣光术");
health *= new OverrideFractionNumericModifier(1, 2, "修改圣光术", "圣光术");
health /= new OverrideFractionNumericModifier(1, 2, "修改圣光术", "圣光术");
这里的 * 和 / 分别是 add 和 remove