// Mutates the insistance object by taking the action, this is actually used in game // when an action is taken. public void apply(Insistance insistance) { foreach (KeyValuePair <InsistanceType, float> effect in effects) { if (insistance.insistanceTypes.Contains(effect.Key)) { insistance.insistances[effect.Key] += effect.Value; // Lowest possible insistance is 1, want squrared insistances to grow. if (insistance.insistances[effect.Key] < 1) { insistance.insistances[effect.Key] = 1; } } else { Debug.Log("Attempted to apply action to insistance object that doesn't contain " + "one of the actions effects."); } } }
// Apply this action to an insistance object, it will mutate the object by changing // The values and updating all other values according to the given time in seconds. // Mostly used when calculating what the insistance WILL BE after an action is taken. public void takeActionAtTime(Insistance insistance, float timeSeconds) { // Begin by increasing all insistances according to how long this action // will take foreach (InsistanceType type in insistance.insistanceTypes) { // Make sure we have a rate for each insistance type if (insistance.growthRates.ContainsKey(type)) { float rate = insistance.growthRates[type]; float increase = rate * timeSeconds; insistance.insistances[type] += increase; } else { Debug.Log("An insistance is missing a growth-rate for one of its types: " + type); } } // Now, appply the affects of this action this.apply(insistance); }