//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {Contact : darkwynter.com for licensing information //--------------------------------------------------------------------------------------------------------------------------------------------------- namespace DarkWynter.Engine.EventControl { using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System.Diagnostics; using DarkWynter.Engine.Globals; using DarkWynter.Stream; using System.Xml; /// /// Handles each GameEvent's Conditions, the SBE (currentGameConditions) /// Is the abstract of each GameEvent /// public class GameEvent { protected int eventLimitMilli; protected String eventSpeaker = ""; protected String eventMessage = ""; protected Texture2D eventTexture; protected Color eventBoxColor = Color.CornflowerBlue; // Enables visualization of GameEvents in 3D World protected List drawList; #region GameEvent State Variables protected bool Finished = true; public bool isFinished { get { return Finished; } set { Finished = value; } } protected bool Triggered = false; public bool isTriggered { get { return Triggered; } set { Triggered = value; Finished = false; } } protected bool Retriggerable = false; public bool isRetriggerable { get { return Retriggerable; } set { Retriggerable = value; } } #endregion #region Static Board Evaluator (SBE) State Machine /// /// Type, used for parsing into the List /// public string typeID { get { return _typeID; } set { _typeID = value; } } public string _typeID; /// /// Sanity level that triggers the event /// public int _trigger_ID; public int trigger_ID { get { return _trigger_ID; } set { _trigger_ID = value; GameEventHandler.UpdateEvents(); } } /// /// ID Number of the Last Node Visited /// public int _lastNodeVisited; /// /// ID Number of the Last Node Visited /// Use the _underscore varient of this variable to avoid calling UpdateConditions. /// public int lastNodeVisited { get { return _lastNodeVisited; } set { _lastNodeVisited = value; GameEventHandler.UpdateEvents(); } } /// /// Number of coins that triggers the event /// public int _triggerCoins; /// /// Number of coins that triggers the event /// Use the _underscore varient of this variable to avoid calling UpdateConditions. /// public int triggerCoins { get { return _triggerCoins; } set { _triggerCoins = value; GameEventHandler.UpdateEvents(); } } /// /// Sanity level that triggers the event /// public int _triggerSanity; /// /// Sanity level that triggers the event /// Setting this variable also calls UpdatedEvents, causing Event System to trigger event if conditions match. /// Use the _underscore varient of this variable to avoid calling UpdateConditions. /// public int triggerSanity { get { return _triggerSanity; } set { _triggerSanity = value; GameEventHandler.UpdateEvents(); } } /// /// Tells the LevelEditor to draw the event /// public bool drawable { get { return _drawable; } set { _drawable = value; } } private bool _drawable; #endregion /// /// CurrentGameConditions Constructor /// public GameEvent() { drawList = new List(); _trigger_ID = -1; _lastNodeVisited = 0; _triggerCoins = -1; _triggerSanity = -1; } /// /// Constructor for each Game Event /// /// XML Node public GameEvent(XmlNode node) { drawList = new List(); // Make object drawable on board if (node.Attributes["drawable"] != null) { this.drawable = bool.Parse(node.Attributes["drawable"].Value); } else { this.drawable = false; } this._typeID = node.Attributes["typeID"].Value; this._lastNodeVisited = int.Parse(node.Attributes["node"].Value); this._triggerCoins = int.Parse(node.Attributes["coins"].Value); this._triggerSanity = int.Parse(node.Attributes["sanity"].Value); this.isTriggered = true; } public virtual void FireEvent() { } public virtual List Draw() { return null; } /// /// Create XML for Events /// /// string public virtual string ToXml() { string xml = "typeID=" + this._trigger_ID + "node=" + this._lastNodeVisited + "coins=" + this._triggerCoins + "sanity=" + this._triggerSanity; return xml; } /// /// Overrides the ToString method for each GameEvent Condition /// and CurrentGameConditions /// /// string public override string ToString() { string text = "ID: " + _trigger_ID + "\n" + "LastNode: " + _lastNodeVisited + "\n" + "Coins: " + _triggerCoins + "\n" + "Sanity: " + _triggerSanity + "\n"; return text; } } }