Пример #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 bool TryAddInfluencer(StatInfluencerSO influencer)
        {
            if (m_Memory != null && influencer.generator != null)
            {
                MemorySO[] memories = m_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);
                    }
                }
            }

            StatSO stat   = GetOrCreateStat(influencer.stat.name);
            bool   isGood = true;

            switch (stat.desiredState.objective)
            {
            case DesiredState.Objective.LessThan:
                if (influencer.maxChange > 0)
                {
                    isGood = false;
                }
                break;

            case DesiredState.Objective.Approximately:
                float currentDelta    = stat.desiredState.targetValue - stat.value;
                float influencedDelta = stat.desiredState.targetValue - (stat.value + influencer.maxChange);
                if (currentDelta < influencedDelta)
                {
                    isGood = false;
                }
                break;

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

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

            m_StatsInfluencers.Add(influencer);

            return(true);
        }
Пример #2
0
        public IEnumerator ShortTermMemoryCommit()
        {
            SetupMemory();

            // Add the three short term memories destined to stay in short term
            controller.AddMemory(shortTermMemory);
            Assert.AreEqual(1, controller.GetShortTermMemories().Length, "The first short term memory item was not committed to memory.");
            Assert.AreEqual(5, controller.GetShortTermMemoriesAbout(shortTermInfluencer)[0].influence);

            controller.AddMemory(shortTermMemory);
            Assert.AreEqual(1, controller.GetShortTermMemories().Length, "The second short term memory item should not have been committed as it is a duplicate of an existing short term memory.");

            controller.AddMemory(shortTermMemoryNegativeInflunce);
            Assert.AreEqual(2, controller.GetShortTermMemories().Length, "The short term memory item 1 should have been committed.");
            Assert.AreEqual(1, controller.GetShortTermMemoriesAbout(shortTermInfluencer).Length, "The first short term memory item was not committed to memory.");
            Assert.AreEqual(1, controller.GetShortTermMemoriesAbout(shortTermNegativeInfluencer).Length, "The first short term 1 memory item was not committed to memory.");
            Assert.AreEqual(-5, controller.GetShortTermMemoriesAbout(shortTermNegativeInfluencer)[0].influence);

            yield return(null);
        }