示例#1
0
        /*	if(hopeEmotion != null) {
         *              if(fearEmotion != null && fearEmotion.Intensity > hopeEmotion.Intensity) {
         *                      potential = fearEmotion.Potential;
         *                      finalEmotion = fearfullOutcome;
         *              }
         *              else {
         *                      potential = hopeEmotion.Potential;
         *                      finalEmotion = hopefullOutcome;
         *              }
         *      }
         *      else if(fearEmotion != null) {
         *              potential = fearEmotion.Potential;
         *              finalEmotion = fearfullOutcome;
         *      }
         *
         *      //The goal importance now affects 66% of the final potential value for the emotion
         *      potential = (potential +  2* goalImportance) / 3;
         *
         *      return new OCCBaseEmotion(finalEmotion, potential, evtId, eventName);
         * }*/


        /*
         *  private static OCCBaseEmotion AppraiseGoalEnd(OCCEmotionType hopefullOutcome, OCCEmotionType fearfullOutcome, IActiveEmotion hopeEmotion, IActiveEmotion fearEmotion, float goalImportance, uint evtId, Name eventName) {
         *
         *              OCCEmotionType finalEmotion;
         *              float potential = goalImportance;
         *              finalEmotion = hopefullOutcome;
         *
         *              if(hopeEmotion != null) {
         *                      if(fearEmotion != null && fearEmotion.Intensity > hopeEmotion.Intensity) {
         *                              potential = fearEmotion.Potential;
         *                              finalEmotion = fearfullOutcome;
         *                      }
         *                      else {
         *                              potential = hopeEmotion.Potential;
         *                              finalEmotion = hopefullOutcome;
         *                      }
         *              }
         *              else if(fearEmotion != null) {
         *                      potential = fearEmotion.Potential;
         *                      finalEmotion = fearfullOutcome;
         *              }
         *
         *              //The goal importance now affects 66% of the final potential value for the emotion
         *              potential = (potential +  2* goalImportance) / 3;
         *
         *              return new OCCBaseEmotion(finalEmotion, potential, evtId, eventName);
         *      }
         *
         * */
        ///// <summary>
        ///// Appraises a Goal's success according to the emotions that the agent is experiencing
        ///// </summary>
        ///// <param name="hopeEmotion">the emotion of Hope for achieving the goal that the character feels</param>
        ///// <param name="fearEmotion">the emotion of Fear for not achieving the goal that the character feels</param>
        ///// <param name="goalImportance">how important is the goal to the agent</param>
        ///// <param name="evt">The event that triggered the emotion</param>
        ///// <returns>the emotion created</returns>
        //private static OCCBaseEmotion AppraiseGoalSuccess(IActiveEmotion hopeEmotion, IActiveEmotion fearEmotion, float goalImportance, uint evt) {
        //	return AppraiseGoalEnd(OCCEmotionType.Satisfaction,OCCEmotionType.Relief,hopeEmotion,fearEmotion,goalImportance,evt);
        //}

        ///// <summary>
        ///// Appraises a Goal's Failure according to the emotions that the agent is experiencing
        ///// </summary>
        ///// <param name="hopeEmotion">the emotion of Hope for achieving the goal that the character feels</param>
        ///// <param name="fearEmotion">the emotion of Fear for not achieving the goal that the character feels</param>
        ///// <param name="goalImportance">how important is the goal to the agent</param>
        ///// <param name="evt">The event that triggered the emotion</param>
        ///// <returns></returns>
        //public static OCCBaseEmotion AppraiseGoalFailure(IActiveEmotion hopeEmotion, IActiveEmotion fearEmotion, float goalImportance, uint evt) {
        //	return AppraiseGoalEnd(OCCEmotionType.Disappointment,OCCEmotionType.FearsConfirmed,hopeEmotion,fearEmotion,goalImportance,evt);
        //}

        ///// <summary>
        ///// Appraises a Goal's likelihood of succeeding
        ///// </summary>
        ///// <param name="e">The event that triggered the emotion</param>
        ///// <param name="goalConduciveness">???????</param>
        ///// <param name="prob">probability of sucess</param>
        ///// <returns></returns>
        //	public static OCCBaseEmotion AppraiseGoalSuccessProbability(uint evt, float goalConduciveness, float prob) {
        //		return new OCCBaseEmotion(OCCEmotionType.Hope, prob * goalConduciveness, evt);
        //	}

        ///// <summary>
        ///// Appraises a Goal's likelihood of failure
        ///// </summary>
        ///// <param name="e">The event that triggered the emotion</param>
        ///// <param name="goalConduciveness">???????</param>
        ///// <param name="prob">probability of failure</param>
        ///// <returns></returns>
        //public static OCCBaseEmotion AppraiseGoalFailureProbability(uint evt, float goalConduciveness, float prob)
        //{
        //	return new OCCBaseEmotion(OCCEmotionType.Fear, prob * goalConduciveness, evt);
        //}

        public IEnumerable <IEmotion> AffectDerivation(EmotionalAppraisalAsset emotionalModule, IAppraisalFrame frame)
        {
            var evt = frame.AppraisedEvent;


            if (frame.ContainsAppraisalVariable(OCCAppraisalVariables.DESIRABILITY) && frame.ContainsAppraisalVariable(OCCAppraisalVariables.PRAISEWORTHINESS))
            {
                float desirability     = frame.GetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY);
                float praiseworthiness = frame.GetAppraisalVariable(OCCAppraisalVariables.PRAISEWORTHINESS);

                var composedEmotion = OCCAppraiseCompoundEmotions(evt, desirability, praiseworthiness);
                if (composedEmotion != null)
                {
                    yield return(composedEmotion);
                }
            }

            if (frame.ContainsAppraisalVariable(OCCAppraisalVariables.DESIRABILITY))
            {
                float desirability = frame.GetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY);
                if (desirability != 0)
                {
                    // yield return OCCAppraiseWellBeing(evt.Id, evt.EventName, desirability * 0.5f);
                    int counter = 0;
                    foreach (string variable in frame.AppraisalVariables.Where(v => v.StartsWith(OCCAppraisalVariables.DESIRABILITY_FOR_OTHER)))
                    {
                        counter++;
                        string other = variable.Substring(OCCAppraisalVariables.DESIRABILITY_FOR_OTHER.Length);
                        float  desirabilityForOther = frame.GetAppraisalVariable(variable);
                        if (desirabilityForOther != 0)
                        {
                            yield return(OCCAppraiseFortuneOfOthers(evt, desirability, desirabilityForOther, other));
                        }
                    }
                    if (counter == 0)
                    {
                        yield return(OCCAppraiseWellBeing(evt.Id, evt.EventName, desirability));
                    }
                }
            }



            foreach (string variable in frame.AppraisalVariables.Where(v => v.StartsWith(OCCAppraisalVariables.PRAISEWORTHINESS)))
            {
                float  praiseworthiness = frame.GetAppraisalVariable(variable);
                string other            = variable.Substring(OCCAppraisalVariables.PRAISEWORTHINESS.Length);
                if (other == null || other == " ")
                {
                    yield return(OCCAppraisePraiseworthiness(evt, praiseworthiness, "SELF"));
                }

                else
                {
                    yield return(OCCAppraisePraiseworthiness(evt, praiseworthiness, other));
                }
            }


            /*if(frame.ContainsAppraisalVariable(OCCAppraisalVariables.PRAISEWORTHINESS))
             * {
             *      float praiseworthiness = frame.GetAppraisalVariable(OCCAppraisalVariables.PRAISEWORTHINESS);
             *      if (praiseworthiness != 0)
             *              yield return OCCAppraisePraiseworthiness(evt, praiseworthiness, frame.Perspective);
             * }*/



            if (frame.ContainsAppraisalVariable(OCCAppraisalVariables.LIKE))
            {
                float like = frame.GetAppraisalVariable(OCCAppraisalVariables.LIKE);
                if (like != 0)
                {
                    yield return(OCCAppraiseAttribution(evt, like));
                }
            }

            foreach (string variable in frame.AppraisalVariables.Where(v => v.StartsWith(OCCAppraisalVariables.GOALSUCCESSPROBABILITY)))
            {
                float goalSuccessProbability = frame.GetAppraisalVariable(variable);

                string goalName = variable.Substring(OCCAppraisalVariables.GOALSUCCESSPROBABILITY.Length + 1);

                var goals = emotionalModule.GetAllGoals().ToList();


                GoalDTO g = goals.Find(x => goalName.ToString() == x.Name.ToString());

                if (g == null)
                {
                    continue;
                }

                var previousValue = g.Likelihood;

                g.Likelihood = goalSuccessProbability;


                yield return(AppraiseGoalSuccessProbability(evt, goalSuccessProbability, previousValue, g.Significance));
            }
        }