Beispiel #1
0
 /// <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);
 }
Beispiel #2
0
 /// <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);
 }
Beispiel #3
0
        /// <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);
        }
Beispiel #4
0
        /// <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);
        }
Beispiel #5
0
        /// <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));
        }
Beispiel #6
0
 /// <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);
Beispiel #7
0
 /// <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];
Beispiel #8
0
 /// <summary>
 /// Whether a favor value exists for the specified <see cref = "FavorComponent"/>.
 /// </summary>
 bool HasFavor(FavorComponent favorComponent) =>
 SocialComponentToFavor.ContainsKey(favorComponent);
Beispiel #9
0
 public FavorChangedEventArgs(FavorComponent favorComponent, float value)
 {
     FavorComponent = favorComponent;
     Value          = value;
 }
Beispiel #10
0
 public DelayedFavorChange(int rounds, FavorComponent favorComponent, float amount)
 {
     Rounds         = rounds;
     FavorComponent = favorComponent;
     Amount         = amount;
 }
Beispiel #11
0
 /// <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);
Beispiel #12
0
 /// <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);