/// <summary> /// Invoked when a contact has published his or her mood. /// </summary> /// <param name="jid">The JID of the XMPP entity that published the /// mood information.</param> /// <param name="item">The 'item' Xml element of the pubsub publish /// event.</param> void onMood(Jid jid, XmlElement item) { if (item == null || item["mood"] == null) { return; } var moodElement = item["mood"]; Mood?mood = null; if (moodElement.IsEmpty) { mood = Mood.Undefined; } else { // Look for a mood value element. foreach (var v in Enum.GetValues(typeof(Mood))) { string s = MoodToTagName((Mood)v); if (moodElement[s] != null) { mood = (Mood)v; } } } string text = moodElement["text"] != null ? moodElement["text"].InnerText : null; // Raise the 'MoodChanged' event. if (mood.HasValue) { MoodChanged.Raise(this, new MoodChangedEventArgs(jid, mood.Value, text)); } }
private void SetMood(float newMood) { if (CheckIfNumberIsPercent(newMood)) { _moodLevel = newMood; MoodChanged?.Invoke(this, new ValueChangedEventArgs(newMood)); UpdateHealth(); } }
/// <summary> /// Public method to directly set this creature's mood to a particular level. /// Use positive numbers for happiness and negative numbers to make them sad/angry /// </summary> /// <param name="amount"></param> public void SetLevel(int amount) { // maybe do a happy/unhappy face animation to represent this change? level = Mathf.Clamp(amount, 0, maxMoodLevel); MoodChanged?.Invoke(); }