Exemple #1
0
        /// <summary>
        /// Add an influencer to this controller. If this controller is not managing the required stat then
        /// do nothing. If we already added an influencer of this type within the cooldown time then
        /// do nothing.
        /// </summary>
        /// <param name="influencer">The influencer to add.</param>
        /// <returns>True if the influencer was added, otherwise false.</returns>
        public virtual bool TryAddInfluencer(StatInfluencerSO influencer)
        {
            bool exists = false;

            // check that if an influencer already exists we are not in a cooldown period for this influencer
            for (int i = StatsInfluencers.Count - 1; i >= 0; i--)
            {
                if (StatsInfluencers[i].InteractionName == influencer.InteractionName)
                {
                    exists = true;
                    if (Time.timeSinceLevelLoad > StatsInfluencers[i].CooldownCompleteTime)
                    {
                        StatsInfluencers.Add(influencer);
                    }
                    else
                    {
                        // it already exists and we are in cooldown, don't add again.
                        return(false);
                    }
                }
            }

            // If the influencer doesn't already exist add it
            if (!exists)
            {
                StatsInfluencers.Add(influencer);
            }
            return(true);
        }
Exemple #2
0
        internal void ApplyStatInfluencerEffects()
        {
            for (int i = StatsInfluencers.Count - 1; i >= 0; i--)
            {
                if (StatsInfluencers[i] != null)
                {
                    StatsInfluencers[i].ChangeStat(this);

                    if (Mathf.Abs(StatsInfluencers[i].influenceApplied) >= Mathf.Abs(StatsInfluencers[i].maxChange))
                    {
                        if (StatsInfluencers[i].Trigger)
                        {
                            StatsInfluencers[i].Trigger.StopCharacterInteraction(this);
                        }
                        StatsInfluencers.RemoveAt(i);
                    }
                }
                else
                {
                    StatsInfluencers.RemoveAt(i);
                }
            }
        }