/// <summary> /// Removes the specified <see cref = "FavorComponent"/> from the <see cref = "SocialComponentToFavor"/> dictionary /// if the favor value equals the <see cref = "DEFAULT_FAVOR"/> value. /// </summary> void RemoveIfDefault(FavorComponent favorComponent) { if (!(Math.Abs(SocialComponentToFavor[favorComponent] - DEFAULT_FAVOR) < float.Epsilon)) { return; } SocialComponentToFavor.Remove(favorComponent); }
/// <summary> /// Sets the <see cref = "DEFAULT_FAVOR"/> value for the specified <see cref = "FavorComponent"/>. /// </summary> void Register(FavorComponent favorComponent) { if (HasFavor(favorComponent)) { return; } SocialComponentToFavor.Add(favorComponent, DEFAULT_FAVOR); }
/// <summary> /// Increases the favor value for the specified <see cref = "FavorComponent"/> by the specified amount. /// </summary> public void IncreaseFavor(FavorComponent favorComponent, float amount) { if (amount == 0) { return; } var currentFavor = GetFavor(favorComponent); SetFavor(favorComponent, currentFavor + amount); }
/// <summary> /// Increases the favor value for the specified <see cref = "FavorComponent"/> by the specified amount for the specified number of rounds. /// </summary> public void IncreaseFavorForRounds(FavorComponent favorComponent, float amount, int rounds) { if (rounds < 1) { this.Log($"Favor for {favorComponent} cannot be increased for {rounds} rounds: rounds are less than 1", LogType.Warning); return; } IncreaseFavor(favorComponent, amount); var delayedFavorChange = new DelayedFavorChange(rounds, favorComponent, amount); DelayedFavorChanges.Add(delayedFavorChange); }
/// <summary> /// Sets the specified favor value for the specified <see cref = "FavorComponent"/> /// </summary> /// <remarks> /// Registers the <see cref = "FavorComponent"/>. /// Clamps the favor value between <see cref = "MIN_FAVOR"/> and <see cref = "MAX_FAVOR"/>. /// Invokes the <see cref = "FavorChanged"/> event if the value changed. /// </remarks> public void SetFavor(FavorComponent favorComponent, float value) { Register(favorComponent); var currentFavor = GetFavor(favorComponent); if (Math.Abs(currentFavor - value) < float.Epsilon) { RemoveIfDefault(favorComponent); return; } SocialComponentToFavor[favorComponent] = Mathf.Clamp(value, MIN_FAVOR, MAX_FAVOR); RemoveIfDefault(favorComponent); FavorChanged?.Invoke(this, new FavorChangedEventArgs(favorComponent, value)); }
/// <summary> /// Resets the favor value of the specified <see cref = "FavorComponent"/> to the <see cref = "DEFAULT_FAVOR"/> value. /// </summary> public void ResetFavor(FavorComponent favorComponent) => SetFavor(favorComponent, DEFAULT_FAVOR);
/// <summary> /// Returns the favor value for the specified <see cref = "FavorComponent"/>. /// </summary> /// <remarks> /// If the SocialComponent is not registered, the <see cref = "DEFAULT_FAVOR"/> value will be returned. /// </remarks> public float GetFavor(FavorComponent favorComponent) => !HasFavor(favorComponent) ? DEFAULT_FAVOR : SocialComponentToFavor[favorComponent];
/// <summary> /// Whether a favor value exists for the specified <see cref = "FavorComponent"/>. /// </summary> bool HasFavor(FavorComponent favorComponent) => SocialComponentToFavor.ContainsKey(favorComponent);
public FavorChangedEventArgs(FavorComponent favorComponent, float value) { FavorComponent = favorComponent; Value = value; }
public DelayedFavorChange(int rounds, FavorComponent favorComponent, float amount) { Rounds = rounds; FavorComponent = favorComponent; Amount = amount; }
/// <summary> /// Decreases the favor value for the specified <see cref = "FavorComponent"/> by the specified amount for the specified number of rounds. /// </summary> public void DecreaseFavorForRounds(FavorComponent favorComponent, float amount, int rounds) => IncreaseFavorForRounds(favorComponent, -amount, rounds);
/// <summary> /// Decreases the favor value for the specified <see cref = "FavorComponent"/> by the specified amount. /// </summary> public void DecreaseFavor(FavorComponent favorComponent, float amount) => IncreaseFavor(favorComponent, -amount);