Пример #1
0
        /// <summary>
        /// Add an influencer to this controller. If this controller is not managing the required stat then
        /// do nothing.
        /// </summary>
        /// <param name="influencer">The influencer to add.</param>
        /// <returns>True if the influencer was added, otherwise false.</returns>
        public override bool TryAddInfluencer(StatInfluencerSO influencer)
        {
            if (Memory != null && influencer.Trigger != null)
            {
                MemorySO[] memories = Memory.GetAllMemoriesAbout(influencer.Generator);
                for (int i = 0; i < memories.Length; i++)
                {
                    if (memories[i].stat == influencer.stat && memories[i].time + memories[i].cooldown > Time.timeSinceLevelLoad)
                    {
                        return(false);
                    }
                }
            }

            if (Memory != null)
            {
                StatSO         stat   = GetOrCreateStat(influencer.stat);
                List <StateSO> states = GetDesiredStatesFor(stat);
                bool           isGood = true;
                for (int i = 0; i < states.Count; i++)
                {
                    switch (states[i].objective)
                    {
                    case StateSO.Objective.LessThan:
                        if (influencer.maxChange > 0)
                        {
                            isGood = false;
                        }
                        break;

                    case StateSO.Objective.Approximately:
                        float currentDelta    = states[i].normalizedTargetValue - stat.NormalizedValue;
                        float influencedDelta = states[i].normalizedTargetValue - (stat.NormalizedValue + influencer.maxChange);
                        if (currentDelta < influencedDelta)
                        {
                            isGood = false;
                        }
                        break;

                    case StateSO.Objective.GreaterThan:
                        if (influencer.maxChange < 0)
                        {
                            isGood = false;
                        }
                        break;
                    }

                    if (influencer.Generator != null)
                    {
                        Memory.AddMemory(influencer, isGood);
                    }
                }
            }

            return(base.TryAddInfluencer(influencer));
        }