Пример #1
0
        /// <summary>
        /// unique hash string calculation function
        /// </summary>
        /// <param name="emotion"></param>
        private static string calculateHashString(IEmotion emotion)
        {
            StringBuilder builder = ObjectPool <StringBuilder> .GetObject();

            try
            {
                var eventType = emotion.EventName.GetNTerm(1);
                //for property change events the cause of the emotion is just the property names
                //this means that if a new change to a property occcurs the previous emotion associated with it will be reappraised
                if (eventType.ToString().EqualsIgnoreCase(AMConsts.PROPERTY_CHANGE))
                {
                    builder.Append(emotion.EventName.GetNTerm(3));
                }
                else
                {
                    builder.Append(emotion.CauseId);
                }

                using (var it = emotion.AppraisalVariables.GetEnumerator())
                {
                    while (it.MoveNext())
                    {
                        builder.Append("-");
                        builder.Append(it.Current);
                    }
                }

                return(builder.ToString());
            }
            finally
            {
                builder.Length = 0;
                ObjectPool <StringBuilder> .Recycle(builder);
            }
        }
Пример #2
0
        private float DeterminePotential(IEmotion emotion)
        {
            float potetial = emotion.Potential;
            float scale    = (float)emotion.Valence;

            potetial += scale * (this.mood.MoodValue * this.appraisalConfiguration.MoodInfluenceOnEmotionFactor);
            return(potetial < 0 ? 0 : potetial);
        }
            public IActiveEmotion DetermineActiveEmotion(IEmotion potEm)
            {
                EmotionDisposition emotionDisposition = GetEmotionDisposition(potEm.EmotionType);
                float potential = DeterminePotential(potEm);

                if (potential > emotionDisposition.Threshold)
                {
                    return(new ActiveEmotion(potEm, potential, emotionDisposition.Threshold, emotionDisposition.Decay, m_parent.Tick));
                }

                return(null);
            }
Пример #4
0
 /// <summary>
 /// Creates a new ActiveEmotion
 /// </summary>
 /// <param name="emotion">the BaseEmotion that is the base for this ActiveEmotion</param>
 /// <param name="potential">the potential for the intensity of the emotion</param>
 /// <param name="threshold">the threshold for the specific emotion</param>
 /// <param name="decay">the decay rate for the specific emotion</param>
 public ActiveEmotion(IEmotion emotion, float potential, int threshold, int decay, ulong tickStamp)
 {
     this.EmotionType        = emotion.EmotionType;
     this.Valence            = emotion.Valence;
     this.AppraisalVariables = emotion.AppraisalVariables.ToArray();
     this.InfluenceMood      = emotion.InfluenceMood;
     this.CauseId            = emotion.CauseId;
     this.Direction          = emotion.Direction;
     this.Threshold          = threshold;
     this.Decay = decay;
     SetIntensity(potential, tickStamp);
 }
 /// <summary>
 /// Creates a new ActiveEmotion
 /// </summary>
 /// <param name="emotion">the BaseEmotion that is the base for this ActiveEmotion</param>
 /// <param name="potential">the potential for the intensity of the emotion</param>
 /// <param name="threshold">the threshold for the specific emotion</param>
 /// <param name="decay">the decay rate for the specific emotion</param>
 public ActiveEmotion(IEmotion emotion, float potential, int threshold, int decay, ulong tickStamp)
 {
     this.EmotionType = emotion.EmotionType;
     this.Valence = emotion.Valence;
     this.AppraisalVariables = emotion.AppraisalVariables.ToArray();
     this.InfluenceMood = emotion.InfluenceMood;
     this.CauseId = emotion.CauseId;
     this.Direction = emotion.Direction;
     this.Threshold = threshold;
     this.Decay = decay;
     SetIntensity(potential,tickStamp);
 }
            /// <summary>
            /// Creates and Adds to the emotional state a new ActiveEmotion based on
            /// a received BaseEmotion. However, the ActiveEmotion will be created
            /// and added to the emotional state only if the final intensity for
            /// the emotion surpasses the threshold for the emotion type.
            /// </summary>
            /// <param name="emotion">the BaseEmotion that creates the ActiveEmotion</param>
            /// <returns>the ActiveEmotion created if it was added to the EmotionalState.
            /// Otherwise, if the intensity of the emotion was not enough to be added to the EmotionalState, the method returns null</returns>
            public IActiveEmotion AddEmotion(IEmotion emotion)
            {
                if (emotion == null)
                {
                    return(null);
                }

                int           decay;
                ActiveEmotion auxEmotion  = null;
                bool          reappraisal = false;

                EmotionDisposition disposition = GetEmotionDisposition(emotion.EmotionType);

                decay = disposition.Decay;

                ActiveEmotion previousEmotion;
                string        hash = calculateHashString(emotion, m_parent.m_am);

                if (emotionPool.TryGetValue(hash, out previousEmotion))
                {
                    //if this test is true, it means that this is 100% a reappraisal of the same event
                    //if not true, it is not a reappraisal, but the appraisal of a new event of the same
                    //type
                    if (previousEmotion.CauseId == emotion.CauseId)
                    {
                        reappraisal = true;
                    }

                    //in both cases we need to remove the old emotion. In the case of reappraisal it is obvious.
                    //In the case of the appraisal of a similar event, we want to aggregate all the similar resulting
                    //emotions into only one emotion
                    emotionPool.Remove(hash);
                }

                float potential = DeterminePotential(emotion);

                if (potential > disposition.Threshold)
                {
                    auxEmotion = new ActiveEmotion(emotion, potential, disposition.Threshold, decay, m_parent.Tick);
                    emotionPool.Add(hash, auxEmotion);
                    if (!reappraisal)
                    {
                        this.mood.UpdateMood(auxEmotion, m_parent);
                    }

                    auxEmotion.GetCause(m_parent.m_am).LinkEmotion(auxEmotion.EmotionType);
                }

                return(auxEmotion);
            }
            /// <summary>
            /// unique hash string calculation function
            /// </summary>
            /// <param name="emotion"></param>
            private static string calculateHashString(IEmotion emotion, AM am)
            {
                StringBuilder builder = ObjectPool <StringBuilder> .GetObject();

                try
                {
                    builder.Append(emotion.GetCause(am).EventName.ToString().ToUpper());
                    using (var it = emotion.AppraisalVariables.GetEnumerator())
                    {
                        while (it.MoveNext())
                        {
                            builder.Append("-");
                            builder.Append(it.Current);
                        }
                    }

                    return(builder.ToString());
                }
                finally
                {
                    builder.Length = 0;
                    ObjectPool <StringBuilder> .Recycle(builder);
                }
            }
 public EventEmotion(string entityId, IEmotion emotion)
 {
     this.entityId = entityId;
     this.emotion  = emotion;
 }
Пример #9
0
 private void _EmotionControllerProvider_Unsupply(IEmotion obj)
 {
     _EmotionSkill = null;
 }
Пример #10
0
 private void _EmotionControllerProvider_Supply(Regulus.Project.ItIsNotAGame1.Data.IEmotion obj)
 {
     _EmotionSkill = obj;
 }
            private float DeterminePotential(IEmotion emotion)
            {
                float potetial = emotion.Potential;
                float scale = (float)emotion.Valence;

                potetial += scale*(this.mood.MoodValue* m_parent.MoodInfluenceOnEmotionFactor);
                return potetial < 0 ? 0 : potetial;
            }
Пример #12
0
 public void AddSmart()
 {
     Emotion = _factory.Get(EmotionTypes.Love);
 }
Пример #13
0
 private void _EmotionControllerProvider_Unsupply(IEmotion obj)
 {
     _EmotionSkill = null;
 }
Пример #14
0
 private void _ClearEmotion(IEmotion obj)
 {
     _Emotion = null;
 }
Пример #15
0
 /// <summary>
 /// Searches for a given emotion in the EmotionalState
 /// </summary>
 /// <param name="emotionKey">a BaseEmotion that serves as a template to find the active emotion in the EmotionalState</param>
 /// <returns>the found ActiveEmotion if it exists in the EmotionalState, null if the emotion doesn't exist anymore</returns>
 public IActiveEmotion GetEmotion(IEmotion emotion)
 {
     return(GetEmotion(calculateHashString(emotion)));
 }
Пример #16
0
 public void RecievedGift()
 {
     Emotion = new Happiness();
 }
        public void InverseAffectDerivation(EmotionalAppraisalAsset emotionalModule, IEmotion emotion, IWritableAppraisalFrame frame)
        {
            //const float MAGIC_VALUE_FOR_LOVE = 1.43f;
            //TODO improve this code

            //ignoring mood for now

            EmotionDispositionDTO emotionDisposition = emotionalModule.EmotionDispositions.FirstOrDefault(e => e.Emotion == emotion.EmotionType);
            if (emotionDisposition == null)
            {
                emotionDisposition = emotionalModule.DefaultEmotionDisposition;
            }

            int threshold = emotionDisposition.Threshold;
            float potentialValue = emotion.Potential + threshold;

            //if(emotion.EmotionType == OCCEmotionType.Love.Name)
            //{
            //	frame.SetAppraisalVariable(OCCAppraisalVariables.LIKE, potentialValue * MAGIC_VALUE_FOR_LOVE);
            //}
            //else if(emotion.EmotionType == OCCEmotionType.Hate.Name)
            //{
            //	frame.SetAppraisalVariable(OCCAppraisalVariables.LIKE, potentialValue * -MAGIC_VALUE_FOR_LOVE);
            //}
            //else
            if (emotion.EmotionType == OCCEmotionType.Joy.Name)
            {
                frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY, potentialValue);
            }
            else if (emotion.EmotionType == OCCEmotionType.Distress.Name)
            {
                frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY, -potentialValue);
            }
            else if (emotion.EmotionType == OCCEmotionType.Pride.Name)
            {
                frame.SetAppraisalVariable(OCCAppraisalVariables.PRAISEWORTHINESS, potentialValue);
            }
            else if (emotion.EmotionType == OCCEmotionType.Shame.Name)
            {
                frame.SetAppraisalVariable(OCCAppraisalVariables.PRAISEWORTHINESS, -potentialValue);
            }
            //else if (emotion.EmotionType == OCCEmotionType.Gloating.Name)
            //{
            //	frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY, potentialValue);
            //	frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY_FOR_OTHER, -potentialValue);
            //}
            //else if (emotion.EmotionType == OCCEmotionType.HappyFor.Name)
            //{
            //	frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY, potentialValue);
            //	frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY_FOR_OTHER, potentialValue);
            //}
            //else if (emotion.EmotionType == OCCEmotionType.Pitty.Name)
            //{
            //	frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY, -potentialValue);
            //	frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY_FOR_OTHER, -potentialValue);
            //}
            //else if (emotion.EmotionType == OCCEmotionType.Resentment.Name)
            //{
            //	frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY_FOR_OTHER, potentialValue);
            //}
            //else if (emotion.EmotionType == OCCEmotionType.Gratification.Name)
            //{
            //	frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY, potentialValue);
            //	frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY_FOR_OTHER, potentialValue);
            //}
            //else if (emotion.EmotionType == OCCEmotionType.Anger.Name)
            //{
            //	frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY, -potentialValue);
            //	frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY_FOR_OTHER, -potentialValue);
            //}
        }
 private void _SetEmotion(IEmotion obj)
 {
     _Emotion = obj;
 }
Пример #19
0
        public void InverseAffectDerivation(EmotionalAppraisalAsset emotionalModule, IEmotion emotion, IWritableAppraisalFrame frame)
        {
            const float MAGIC_VALUE_FOR_LOVE = 1.43f;
            //TODO improve this code

            //ignoring mood for now

            EmotionDispositionDTO emotionDisposition = emotionalModule.EmotionDispositions.FirstOrDefault(e => e.Emotion == emotion.EmotionType);

            if (emotionDisposition == null)
            {
                emotionDisposition = emotionalModule.DefaultEmotionDisposition;
            }

            int   threshold      = emotionDisposition.Threshold;
            float potentialValue = emotion.Potential + threshold;

            if (emotion.EmotionType == OCCEmotionType.Love.Name)
            {
                frame.SetAppraisalVariable(OCCAppraisalVariables.LIKE, potentialValue * MAGIC_VALUE_FOR_LOVE);
            }
            else if (emotion.EmotionType == OCCEmotionType.Hate.Name)
            {
                frame.SetAppraisalVariable(OCCAppraisalVariables.LIKE, potentialValue * -MAGIC_VALUE_FOR_LOVE);
            }
            else
            if (emotion.EmotionType == OCCEmotionType.Joy.Name)
            {
                frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY, potentialValue);
            }
            else if (emotion.EmotionType == OCCEmotionType.Distress.Name)
            {
                frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY, -potentialValue);
            }
            else if (emotion.EmotionType == OCCEmotionType.Pride.Name)
            {
                frame.SetAppraisalVariable(OCCAppraisalVariables.PRAISEWORTHINESS, potentialValue);
            }
            else if (emotion.EmotionType == OCCEmotionType.Shame.Name)
            {
                frame.SetAppraisalVariable(OCCAppraisalVariables.PRAISEWORTHINESS, -potentialValue);
            }
            else if (emotion.EmotionType == OCCEmotionType.Gloating.Name)
            {
                frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY, potentialValue);
                frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY_FOR_OTHER, -potentialValue);
            }
            else if (emotion.EmotionType == OCCEmotionType.HappyFor.Name)
            {
                frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY, potentialValue);
                frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY_FOR_OTHER, potentialValue);
            }
            else if (emotion.EmotionType == OCCEmotionType.Pitty.Name)
            {
                frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY, -potentialValue);
                frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY_FOR_OTHER, -potentialValue);
            }
            else if (emotion.EmotionType == OCCEmotionType.Resentment.Name)
            {
                frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY_FOR_OTHER, potentialValue);
            }
            else if (emotion.EmotionType == OCCEmotionType.Gratification.Name)
            {
                frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY, potentialValue);
                frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY_FOR_OTHER, potentialValue);
            }
            else if (emotion.EmotionType == OCCEmotionType.Anger.Name)
            {
                frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY, -potentialValue);
                frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY_FOR_OTHER, -potentialValue);
            }
        }
 private void _ClearEmotion(IEmotion obj)
 {
     _Emotion = null;
 }
 /// <summary>
 /// Searches for a given emotion in the EmotionalState
 /// </summary>
 /// <param name="emotionKey">a BaseEmotion that serves as a template to find the active emotion in the EmotionalState</param>
 /// <returns>the found ActiveEmotion if it exists in the EmotionalState, null if the emotion doesn't exist anymore</returns>
 public IActiveEmotion GetEmotion(IEmotion emotion)
 {
     return(GetEmotion(calculateHashString(emotion, m_parent.m_am)));
 }
Пример #22
0
 private void _SetEmotion(IEmotion obj)
 {
     _Emotion = obj;
 }
            /// <summary>
            /// Creates and Adds to the emotional state a new ActiveEmotion based on 
            /// a received BaseEmotion. However, the ActiveEmotion will be created 
            /// and added to the emotional state only if the final intensity for 
            /// the emotion surpasses the threshold for the emotion type. 
            /// </summary>
            /// <param name="emotion">the BaseEmotion that creates the ActiveEmotion</param>
            /// <returns>the ActiveEmotion created if it was added to the EmotionalState.
            /// Otherwise, if the intensity of the emotion was not enough to be added to the EmotionalState, the method returns null</returns>
            public IActiveEmotion AddEmotion(IEmotion emotion)
            {
                if (emotion == null)
                    return null;

                int decay;
                ActiveEmotion auxEmotion = null;
                bool reappraisal = false;

                EmotionDisposition disposition = GetEmotionDisposition(emotion.EmotionType);
                decay = disposition.Decay;

                ActiveEmotion previousEmotion;
                string hash = calculateHashString(emotion, m_parent.m_am);
                if (emotionPool.TryGetValue(hash,out previousEmotion))
                {
                    //if this test is true, it means that this is 100% a reappraisal of the same event
                    //if not true, it is not a reappraisal, but the appraisal of a new event of the same
                    //type
                    if (previousEmotion.CauseId == emotion.CauseId)
                        reappraisal = true;

                    //in both cases we need to remove the old emotion. In the case of reappraisal it is obvious.
                    //In the case of the appraisal of a similar event, we want to aggregate all the similar resulting
                    //emotions into only one emotion
                    emotionPool.Remove(hash);
                }

                float potential = DeterminePotential(emotion);
                if (potential > disposition.Threshold)
                {
                    auxEmotion = new ActiveEmotion(emotion, potential, disposition.Threshold, decay, m_parent.Tick);
                    emotionPool.Add(hash, auxEmotion);
                    if (!reappraisal)
                        this.mood.UpdateMood(auxEmotion,m_parent);

                    auxEmotion.GetCause(m_parent.m_am).LinkEmotion(auxEmotion.EmotionType);
                }

                return auxEmotion;
            }
Пример #24
0
 public People(IEmotion emotion)
 {
     _emotion     = emotion;
     _currentMood = Mood.Normal;
 }
            public IActiveEmotion DetermineActiveEmotion(IEmotion potEm)
            {
                EmotionDisposition emotionDisposition = GetEmotionDisposition(potEm.EmotionType);
                float potential = DeterminePotential(potEm);

                if (potential > emotionDisposition.Threshold)
                    return new ActiveEmotion(potEm, potential, emotionDisposition.Threshold, emotionDisposition.Decay,m_parent.Tick);

                return null;
            }
 /// <summary>
 /// Searches for a given emotion in the EmotionalState
 /// </summary>
 /// <param name="emotionKey">a BaseEmotion that serves as a template to find the active emotion in the EmotionalState</param>
 /// <returns>the found ActiveEmotion if it exists in the EmotionalState, null if the emotion doesn't exist anymore</returns>
 public IActiveEmotion GetEmotion(IEmotion emotion)
 {
     return GetEmotion(calculateHashString(emotion,m_parent.m_am));
 }
            /// <summary>
            /// unique hash string calculation function
            /// </summary>
            /// <param name="emotion"></param>
            private static string calculateHashString(IEmotion emotion, AM am)
            {
                StringBuilder builder = ObjectPool<StringBuilder>.GetObject();
                try
                {
                    builder.Append(emotion.GetCause(am).EventName.ToString().ToUpper());
                    using (var it = emotion.AppraisalVariables.GetEnumerator())
                    {
                        while (it.MoveNext())
                        {
                            builder.Append("-");
                            builder.Append(it.Current);
                        }
                    }

                    return builder.ToString();
                }
                finally
                {
                    builder.Length = 0;
                    ObjectPool<StringBuilder>.Recycle(builder);
                }
            }
Пример #28
0
 private void _EmotionControllerProvider_Supply(Regulus.Project.ItIsNotAGame1.Data.IEmotion obj)
 {
     _EmotionSkill = obj;
 }
Пример #29
0
 public void RecieveGift()
 {
     Emotion = _factory.Get(EmotionTypes.Happiness);
 }