// return the StatValue of the specified type if it exists in the statSet. Otherwise return a 0 StatValue public StatValue getStatValue(StatType type) { StatValue thisStat; if (this.statSet.TryGetValue(type, out thisStat)) { return(thisStat); } // some stats can bever have a base value equal to or less than zero, so we need to fix it if its not. if (type.needsPositiveBase()) { // just set it to 1f for now StatValue defaultValue = 1f; this.statSet.Add(type, defaultValue); return(defaultValue); } return(thisStat); }
// set a base stat to a value OR add it if it doesn't exist. // this will not update any dependants so its kept private private void setOrAddBaseStat(StatType type, float value) { // make sure we aren't setting anything non-positive that shouldn't be if (type.needsPositiveBase() && value <= 0f) { // just set it to 1f for now value = 1f; } // set the stat, and if its not in the dictionary yet, add it. if (this.statSet.ContainsKey(type)) { this.statSet[type] = new StatValue(value, this.statSet[type].modifier, this.statSet[type].lowerLimit, this.statSet[type].upperLimit); } else { this.statSet.Add(type, value); } // store the Dictionary into serializable lists after any change this.storeStatSet(); }