示例#1
0
        /// <summary>
        /// Apply an immediate change to a given Stats, if this controller is tracking that stat.
        /// </summary>
        ///
        /// <param name="influencer">The influencer imparting the change.</param>
        /// <param name="change">The change to make. The result is kept within the -100 to 100 range.</param>
        internal void ChangeStat(StatInfluencerSO influencer, float change)
        {
            StatSO stat = GetOrCreateStat(influencer.statName);

            stat.value += change;
            influencer.influenceApplied += change;
            //Debug.Log(gameObject.name + " changed stat " + influencer.statName + " by " + change);
        }
示例#2
0
        /// <summary>
        /// Create a memory about an influencer object. See `AddMemory(MemorySO memory)`.
        /// </summary>
        /// <param name="influencer">The influencer that this memory should record.</param>
        /// <param name="isGood">Is this a good memory that represents an experience to be repeated?</param>
        internal void AddMemory(StatInfluencerSO influencer, bool isGood)
        {
            MemorySO memory = ScriptableObject.CreateInstance <MemorySO>();

            memory.about     = influencer.generator;
            memory.statName  = influencer.statName;
            memory.influence = influencer.maxChange;
            memory.cooldown  = influencer.cooldown;
            memory.isGood    = isGood;
            AddMemory(memory);
        }
        private void OnTriggerEnter(Collider other)
        {
            StatsController controller = other.GetComponent <StatsController>();

            if (controller != null)
            {
                StatInfluencerSO influencer = ScriptableObject.CreateInstance <StatInfluencerSO>();
                influencer.name      = m_StatName + " influencer from " + name + " : " + GetInstanceID();;
                influencer.generator = gameObject;
                influencer.statName  = m_StatName;
                influencer.maxChange = m_MaxChange;
                influencer.duration  = m_Duration;
                influencer.cooldown  = m_Cooldown;

                controller.TryAddInfluencer(influencer);
            }
        }
        public IEnumerator StatInstantInfluencer()
        {
            string          statName   = "Test Immediate Influencer Stat";
            StatsController controller = new GameObject().AddComponent <StatsController>();

            StatInfluencerSO influencer = ScriptableObject.CreateInstance <StatInfluencerSO>();

            influencer.statName  = statName;
            influencer.maxChange = 10;
            influencer.duration  = 0;

            Assert.True(controller.TryAddInfluencer(influencer), "Was not able to add the Stat influencer");

            yield return(null);

            Assert.True(controller.GetOrCreateStat(statName).value > 0, "Seems the influencer has had no effect.");

            yield return(null);
        }
示例#5
0
        /// <summary>
        /// Add an influencer to this controller. If this controller is not managing the required stat then
        /// do nothing. If this character has any memory of being influenced by the object within short term
        /// memory this new influence will be rejected.
        /// </summary>
        /// <param name="influencer">The influencer to add.</param>
        /// <returns>True if the influencer was added, otherwise false.</returns>
        public bool TryAddInfluencer(StatInfluencerSO influencer)
        {
            StatSO stat   = GetOrCreateStat(influencer.statName);
            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);
        }