//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {Contact : darkwynter.com for licensing information //--------------------------------------------------------------------------------------------------------------------------------------------------- namespace DarkWynter.Engine.EventControl { #region Using Statements using System; using System.Collections.Generic; using System.Text; using System.Xml; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using DarkWynter.Engine.Globals; using DarkWynter.Stream; using DarkWynter.Engine.GameObjects; using DarkWynter.Engine.UserInterface; using DarkWynter.Engine.ObjectLib; using System.Windows.Forms; #endregion /// /// Handles the GameEvents from the game /// Should maybe look at including into GameRules /// public static class GameEventHandler { public static List GameEvents; public static GameEvent CurrentGameConditions; public static int HUD_StackIndex = -1; public static int HUD_MapIndex = -1; /// /// Creates the GameEvents based on the data from the XML files /// public static void LoadEventsXml(string fileName) { // KAT : CLEAN - Can this method be done through Xml now that events is fixed? // See notes in method... GameEventHandler.killEventList(); GameEvents = new List(); CurrentGameConditions = new GameEvent(); // standard radius for the terrain mod for this particular game int radius = 2; int eventID = 0; try { // Load the Terrain Modification events into a list XmlDocument reader = new XmlDocument(); reader.Load(fileName); XmlNodeList allNodes = reader.ChildNodes; foreach (XmlNode eventNode in allNodes) { if (eventNode.Name == "EventsSettings") { XmlNodeList eventNodes = eventNode.ChildNodes; foreach (XmlNode node in eventNodes) { if (node.Name == "GameEvent") { GameEvents.Add(CreateGameEvent(node.Attributes["typeID"].Value, new object[] { node })); } } } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error reading xml"); throw e; } } /// /// Creates an instance of a GameObject using GameObject constructor parameters. /// /// The string-literal class name of the GameObject. EG- "Terrain" /// Constructor parameters, usually empty or using the Load object. /// public static GameEvent CreateGameEvent(string objectName, object[] parameters) { GameEvent gameEvent = new GameEvent(); for (int i = 0; i < ObjectLibrary.types.Count; i++) { if (ObjectLibrary.types[i].Name == objectName) { try { gameEvent = (GameEvent)Activator.CreateInstance(ObjectLibrary.types[i], parameters); } catch (Exception e) { MessageBox.Show(e.Message); DarkWynterEngine.ContentInstall_WarningMessage(); throw new Exception("Error Loading Event"); } } } if (gameEvent.typeID == null) { MessageBox.Show("Cannot find Event class:" + objectName + "\nEnsure that Event typeID in XML and the Event class name match."); DarkWynterEngine.ContentInstall_WarningMessage(); } return gameEvent; } /// /// Update the gameEvents - called from GameEvent.cs /// Handles running the visualization on the event /// and removal when dead /// public static void UpdateEvents() { string debugType = "none"; if (CurrentGameConditions._typeID != null) { debugType = CurrentGameConditions._typeID.ToString(); } // DarkWynterEngine.HUD.UpdateText(HUD_CurrentGameConditions, // "CurrentGameConditions: \n" + CurrentGameConditions.ToString() + debugType + "\n Statics: " + Statics_Engine.PlayerSettings.coinsCollected.ToString() // ); for (int x = 0; x < GameEvents.Count; x ++) { GameEvent thisEvent = GameEvents[x]; if (isEventTriggered(thisEvent)) { // DarkWynterEngine.HUD.UpdateText(HUD_TriggeredEventGameConditions, "This Event's GameConditions : \n" + thisEvent.ToString() + thisEvent.typeID.ToString()); thisEvent.FireEvent(); } if ((thisEvent != null) && (thisEvent.isFinished)) { // "Don't remove from list" flag //if (thisEvent._triggerSanity != -1) //{ GameEvents.RemoveAt(x); x--; //} } } } /// /// Checks to see if the event has been triggered /// /// Instance of the Event /// Is the Event Triggered? public static bool isEventTriggered(GameEvent theEvent) { //zero coins is obviously possible if you are destitute if (theEvent._triggerCoins > -1 && (CurrentGameConditions._triggerCoins != theEvent._triggerCoins)) return false; //0 sanity is possible else if (theEvent._triggerSanity > -1 && CurrentGameConditions._triggerSanity != theEvent._triggerSanity) return false; //nodes start numbering at one else if (theEvent._lastNodeVisited > 0 && CurrentGameConditions._lastNodeVisited != theEvent._lastNodeVisited) return false; else if (theEvent.typeID == "AIEvent") { if (theEvent._trigger_ID == CurrentGameConditions._trigger_ID) { GameEventHandler.CurrentGameConditions._trigger_ID++; return true; } // No Hits return false; } else return true; } /// /// Level reset for HUDMap and coinsCollected /// public static void killEventList() { IHuman human = DarkWynterEngine.engine.objectLibrary.humans[0] as IHuman; human.MapStart = Statics_Engine.SystemSettings.content.Load("Content/_textures/MapHUD/map"); human.SetSpawnPoint(new Vector3(1270, 839, 880)); Statics_Engine.PlayerSettings.coinsCollected = 0; } } }