public string ToString(StatModifierInstance instance) { var val = value.Value; switch (modifierType) { case StatModifierType.AdditiveAbsolute: return($"{val:+0.##;-0.##}"); case StatModifierType.AdditiveRelative: return($"{val:+0.##%;-0.##%}"); case StatModifierType.MultiplicativeRelative: return($"*{val:+0.##%;-0.##%}"); default: throw new InvalidOperationException("type not supported"); } }
/// <summary> /// Add a new StatModifier. /// </summary> /// <param name="modifier">new StatModifier</param> /// <param name="source">modifier source</param> /// <returns>true if changed</returns> public bool AddModifier(StatModifier modifier, IStatModifierSource source) { if (modifier.attributeType.Type != attributeType.Type) { return(false); } if (!_modifiers.TryGetValue(modifier.modifierType, out var statModifiers)) { statModifiers = new List <StatModifierInstance>(); _modifiers.Add(modifier.modifierType, statModifiers); } var instance = new StatModifierInstance(modifier, this, source); statModifiers.Add(instance); modifier.value.AddListener(OnDependencyChange); MarkDirty(); return(true); }