public ConcreteEmotionalState() { this.emotionPool = new Dictionary <string, ActiveEmotion>(); this.mood = new Mood(); this.appraisalConfiguration = new EmotionalAppraisalConfiguration(); }
/// <summary> /// Decays the emotion according to the system's time /// </summary> /// <returns>the intensity of the emotion after being decayed</returns> internal void DecayEmotion(EmotionalAppraisalConfiguration configuration, ulong tick) { var delta = tick - tickATt0; double lambda = Math.Log(configuration.HalfLifeDecayConstant) / configuration.EmotionalHalfLifeDecayTime; float decay = (float)Math.Exp(lambda * this.Decay * delta); Intensity = intensityATt0 * decay; }
public void SetMoodValue(float value, EmotionalAppraisalConfiguration config) { value = value < -10 ? -10 : (value > 10 ? 10 : value); if (Math.Abs(value) < config.MinimumMoodValueForInfluencingEmotions) { value = 0; } this._intensityATt0 = this._intensity = value; }
/// <summary> /// Updates the character's mood when a given emotion is "felt" by the character. /// </summary> /// <param name="emotion">the ActiveEmotion that will influence the agent's current mood</param> public void UpdateMood(ActiveEmotion emotion, EmotionalAppraisalConfiguration config, ulong tick) { if (!emotion.InfluenceMood) { return; } this._tickT0 = tick; float scale = (float)emotion.Valence; SetMoodValue(this._intensity + scale * (emotion.Intensity * config.EmotionInfluenceOnMoodFactor), config); }
/// <summary> /// Decays the mood according to the agent's simulated time /// </summary> /// <returns>the mood's intensity after being decayed</returns> public void DecayMood(EmotionalAppraisalConfiguration config, float tick) { if (this._intensityATt0 == 0) { this._intensity = 0; return; } var delta = (tick - this._tickT0); double lambda = Math.Log(config.HalfLifeDecayConstant) / config.MoodHalfLifeDecayTime; _intensity = (float)(this._intensityATt0 * Math.Exp(lambda * delta)); if (Math.Abs(this._intensity) < config.MinimumMoodValueForInfluencingEmotions) { this._intensity = this._intensityATt0 = 0; this._tickT0 = 0; } }
public void SetObjectData(ISerializationData dataHolder, ISerializationContext context) { if (emotionPool == null) { emotionPool = new Dictionary <string, ActiveEmotion>(); } else { emotionPool.Clear(); } if (mood == null) { mood = new Mood(); } this.appraisalConfiguration = dataHolder.GetValue <EmotionalAppraisalConfiguration>("AppraisalConfiguration"); if (this.appraisalConfiguration == null) { this.appraisalConfiguration = new EmotionalAppraisalConfiguration(); } mood.SetMoodValue(dataHolder.GetValue <float>("Mood"), this.appraisalConfiguration); mood.SetTick0Value(dataHolder.GetValue <ulong>("initialTick")); context.PushContext(); { context.Context = (ulong)0; //Tick var emotions = dataHolder.GetValue <ActiveEmotion[]>("EmotionalPool"); foreach (var emotion in emotions) { emotionPool.Add(calculateHashString(emotion), emotion); } } context.PopContext(); }