/// <summary> /// Add a new modifer /// </summary> /// <param name="mod"></param> public void AddModifier(StatModifier mod) { switch (mod.effectType) { case EffectTypes.Instant: if (!value.IsNumeric()) { Debug.Log(damageType + " only sustained modifiers can be used on stats with non-numeric values"); return; } mod.Initialize(this); switch (mod.valueTarget) { case EffectValueTarget.MaximumValue: if (modifierType == DamageModType.Weakness) { CurrentBaseMaximum += mod.AppliedValue; } break; case EffectValueTarget.Value: CurrentBaseValue += mod.AppliedValue; break; } break; case EffectTypes.Recurring: if (!value.IsNumeric()) { Debug.Log(damageType + " only sustained modifiers can be used on stats with non-numeric values"); return; } mod.Initialize(this); ActiveModifiers.Add(mod); break; case EffectTypes.Sustained: mod.Initialized = false; ActiveModifiers.Add(mod); switch (mod.valueTarget) { case EffectValueTarget.MaximumValue: if (modifierType == DamageModType.Weakness) { ReCalcCurrentMax(); } break; case EffectValueTarget.Value: ReCalcCurrentValue(CurrentBaseValue); break; } break; } }
/// <summary> /// Load StatValue data from stream /// </summary> /// <param name="stream"></param> public void Load(Stream stream, float version) { if (version != 1.4f) { return; } name = stream.ReadStringPacket(); curBaseValue = stream.ReadFloat(); curBaseMin = stream.ReadFloat(); curBaseMax = stream.ReadFloat(); curBaseRegenAmount = stream.ReadFloat(); curBaseRegenDelay = stream.ReadFloat(); curValue = stream.ReadFloat(); curMin = stream.ReadFloat(); curMax = stream.ReadFloat(); curRegenAmount = stream.ReadFloat(); curRegenDelay = stream.ReadFloat(); nextRegen = stream.ReadFloat(); ActiveModifiers.Clear(); int count = stream.ReadInt(); for (int i = 0; i < count; i++) { StatModifier sm = new StatModifier(); sm.Load(stream); ActiveModifiers.Add(sm); } // Raise events if (onInit != null) { onInit.Invoke(); } }
/// <summary> /// Add a new modifer /// </summary> /// <param name="mod"></param> public void AddModifier(StatModifier mod) { switch (mod.effectType) { case EffectTypes.Instant: if (!value.IsNumeric()) { Debug.Log(name + " only sustained modifiers can be used on stats with non-numeric values"); return; } mod.Initialize(this); switch (mod.valueTarget) { case EffectValueTarget.MaximumValue: CurrentBaseMaximum += mod.AppliedValue; break; case EffectValueTarget.MinimumValue: CurrentBaseMinimum += mod.AppliedValue; break; case EffectValueTarget.RegenAmount: CurrentBaseRegenAmount += mod.AppliedValue; break; case EffectValueTarget.RegenDelay: CurrentBaseRegenDelay += mod.AppliedValue; break; case EffectValueTarget.Value: CurrentBaseValue += mod.AppliedValue; break; } break; case EffectTypes.Recurring: if (!value.IsNumeric()) { Debug.Log(name + " only sustained modifiers can be used on stats with non-numeric values"); return; } mod.Initialize(this); ActiveModifiers.Add(mod); break; case EffectTypes.Sustained: mod.Initialized = false; ActiveModifiers.Add(mod); switch (mod.valueTarget) { case EffectValueTarget.MaximumValue: ReCalcCurrentMax(); break; case EffectValueTarget.MinimumValue: ReCalcCurrentMin(); break; case EffectValueTarget.Value: ReCalcCurrentValue(CurrentBaseValue); break; case EffectValueTarget.RegenAmount: ReCalcCurrentRegenAmount(); break; case EffectValueTarget.RegenDelay: ReCalcCurrentRegenDelay(); break; } break; } }