public virtual void ModifyStatPermanently(float value, StatModifier.StatModificationType modType) { switch (modType) { case StatModifier.StatModificationType.Additive: BaseValue += value; break; case StatModifier.StatModificationType.Multiplicative: float adj; if (value < 0) { adj = Mathf.Clamp01(1 + value); } else { adj = 1 + value; } BaseValue *= adj; break; } if (this is CappedStat) { CappedStat stat = this as CappedStat; if (stat.BaseValue > stat.MaxValue) { stat.Refresh(); } } }
public void RemoveTrackedMod(StatType type, StatModifier mod, GameObject cause, params StatModifierOption[] statOptions) { List <StatModifierOption> options = ConvertStatOptionsToList(statOptions); BaseStat targetStat = GetStat(type); if (targetStat == null) { Debug.Log("Stat: " + type + " not found"); return; } if (options.Contains(StatModifierOption.Cap)) { CappedStat capped = TryConvertToCappedStat(targetStat); if (capped != null) { capped.RemoveCapModifier(mod); OnStatChanged(type, cause); } } if ((options.Count < 1 || options.Contains(StatModifierOption.Base))) { targetStat.RemoveModifier(mod); OnStatChanged(type, cause); } }
public void ResetStat(StatType type, params StatModifierOption[] statOptions) { List <StatModifierOption> options = ConvertStatOptionsToList(statOptions); BaseStat targetStat = GetStat(type); if (targetStat == null) { Debug.Log("Stat: " + type + " not found"); return; } if (options.Contains(StatModifierOption.Cap)) { CappedStat capped = TryConvertToCappedStat(targetStat); if (capped != null) { capped.ResetCap(); OnStatChanged(type, null); } } if ((options.Count < 1 || options.Contains(StatModifierOption.Base))) { targetStat.Reset(); OnStatChanged(type, null); } }
public void ApplyPermanentMod(StatType type, float value, StatModificationType modType, GameObject cause, params StatModifierOption[] statOptions) { List <StatModifierOption> options = ConvertStatOptionsToList(statOptions); BaseStat targetStat = GetStat(type); if (targetStat == null) { Debug.LogError("Stat: " + type + " not found"); return; } if (options.Contains(StatModifierOption.Cap)) { CappedStat capped = TryConvertToCappedStat(targetStat); if (capped != null) { capped.ModifyCapPermanently(value, modType); OnStatChanged(type, cause); } } if ((options.Count < 1 || options.Contains(StatModifierOption.Base))) { targetStat.ModifyStatPermanently(value, modType); OnStatChanged(type, cause); } }
public float GetCappedStatRatio(StatType type) { BaseStat targetStat = GetStat(type); //Debug.Log("trying to get the stat ratio for " + type); CappedStat cap = TryConvertToCappedStat(targetStat); if (cap != null) { //Debug.Log(type + " has a ratio of " + cap.Ratio); return(cap.Ratio); } //if (targetStat != null && targetStat is CappedStat) { // CappedStat capped = targetStat as CappedStat; // return capped.Ratio; //} Debug.LogError("The ratio value was reqested for a stat with no max. Returning 0"); return(0f); }
public void TakeDamage(float damage, LivingThing attacker) { Health -= damage; if (TakeDamageEvent != null) { TakeDamageEvent(damage, attacker); } if (Health.GetVal() <= 0) { Die(); } }
private CappedStat TryConvertToCappedStat(BaseStat targetStat) { CappedStat capped = null; try { capped = targetStat as CappedStat; if (capped == null) { throw new System.NullReferenceException(); } } catch { Debug.LogError(targetStat.Type + " is not a capped stat but told to convert to a capped stat"); return(null); } return(capped); }
private CappedStat TryConvertToCappedStat(BaseStat targetStat) { CappedStat capped = null; //Debug.Log(targetStat.Type + " is being converted"); try { capped = targetStat as CappedStat; if (capped == null) { throw new System.NullReferenceException(); } } catch { Debug.LogError(" Stat collection tried to convert a stat to a capped stat but failed"); return(null); } return(capped); }
public float GetStatMaxValue(StatType type) { BaseStat targetStat = GetStat(type); CappedStat cap = TryConvertToCappedStat(targetStat); if (cap != null) { return(cap.MaxValue); } //if(targetStat != null && targetStat is CappedStat) { // CappedStat capped = targetStat as CappedStat; // return capped.MaxValue; //} Debug.LogError("The maximum value was reqested for a stat with no max. Returning 0"); return(0f); }
public static CappedStat operator -(CappedStat argLHS, float argRHS) { CappedStat myStat = new CappedStat(argLHS); myStat.Current -= argRHS; return myStat; }
/// <summary> /// Copy Constructor /// </summary> /// <param name="argStat"></param> public CappedStat(CappedStat argStat) : base(argStat) { cap = argStat.Cap; }
public void AddStat(StatType type, float value, float maxValue) { CappedStat newCappedStat = new CappedStat(type, value, maxValue); AddStat(newCappedStat); }