public GameValueModifier(GameValueModifier template, int count, int key, string description) { this.key = key; this.count = count; this.description = description; gameValueName = template.gameValueName; modifyValueComponent = template.modifyValueComponent; modifyBehavior = template.modifyBehavior; modifyValue = template.modifyValue; }
public string GetModifiersSummary() { string r = ""; for (int i = 0; i < modifiers.Count; i++) { GameValueModifier m = modifiers[i]; r += m.description + ": " + m.modifyValueComponent + " " + ModifyBehaviorString(m.modifyBehavior) + m.modifyValue + (m.isStackable ? "(" + m.count + ")" : "") + "\n"; } return(r); }
void ModifyPermanent(GameValueModifier modifier) { float origValue = GetValue(); if (modifier.modifyValueComponent == GameValueComponent.BaseValue) { baseValue = modifier.Modify(baseValue); } if (modifier.modifyValueComponent == GameValueComponent.BaseMinValue) { if (!valueCapped) { Debug.LogWarning("Game Value '" + name + "' is uncapped, BaseMinValue cant be modified"); } else { capMin = modifier.Modify(capMin); } } if (modifier.modifyValueComponent == GameValueComponent.BaseMaxValue) { if (!valueCapped) { Debug.LogWarning("Game Value '" + name + "' is uncapped, BaseMaxValue cant be modified"); } else { capMax = modifier.Modify(capMax); } } float minVal = GetMinValue(false); float maxVal = GetMaxValue(false); if (valueCapped) { //clamp the base value baseValue = Mathf.Clamp(baseValue, minVal, maxVal); } BroadcastValueChange(origValue, minVal, maxVal); }
// anything modifying base values is permanent, and doesnt get stored in // our modifiers list public void AddModifier(GameValueModifier modifier, int count, int key, string description) { if (modifier.isPermanent) { ModifyPermanent(modifier); return; } float origValue = GetValue(); if (!valueCapped) { if (modifier.modifyValueComponent == GameValueComponent.MinValue) { Debug.LogWarning("Game Value '" + name + "' is uncapped, MinValue cant be modified"); return; } if (modifier.modifyValueComponent == GameValueComponent.MaxValue) { Debug.LogWarning("Game Value '" + name + "' is uncapped, MaxValue cant be modified"); return; } } GameValueModifier existingModifier = GetModifier(key); if (existingModifier != null) { if (existingModifier.description != description) { Debug.LogWarning("Game Value '" + name + "' Description mismatch for same key! 1) " + description + " :: 2) " + existingModifier.description); } existingModifier.count += count; } else { modifiers.Add(new GameValueModifier(modifier, count, key, description)); } BroadcastValueChange(origValue, GetMinValue(false), GetMaxValue(false)); }
public void RemoveModifier(GameValueModifier modifier, int count, int key) { if (modifier.isPermanent) { return; } GameValueModifier existingModifier = GetModifier(key); if (existingModifier != null) { float origValue = GetValue(); existingModifier.count -= count; if (existingModifier.count <= 0) { modifiers.Remove(existingModifier); } BroadcastValueChange(origValue, GetMinValue(), GetMaxValue()); } }