//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// 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.Game.GameObjects;
using DarkWynter.Engine.EventControl.EventTypes;
using DarkWynter.Engine.Init;
using DarkWynter.Engine.Globals;
using DarkWynter.Stream;
using DarkWynter.Engine.GameObjects;
using DarkWynter.Engine.UserInterface;
#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;
// private static int HUD_CurrentGameConditions;
// private static int HUD_TriggeredEventGameConditions;
public static int HUD_StackIndex = -1;
///
/// Creates the GameEvents based on the data from the XML files
///
public static void LoadEventsXml(string fileName)
{
// HUD_CurrentGameConditions = DarkWynterEngine.HUD.AddTextDisplay("", new Vector2(700, 50), Color.WhiteSmoke);
// HUD_TriggeredEventGameConditions = DarkWynterEngine.HUD.AddTextDisplay("", new Vector2(700, 400), Color.Yellow);
// 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")
{
string typeID = node.Attributes["typeID"].Value;
if (typeID == "TerrainEvent")
{
TerrainEvent thisEvent = new TerrainEvent(node, radius);
GameEvents.Add(thisEvent);
}
else if (typeID == "DialogueEvent")
{
DialogueEvent thisEvent = new DialogueEvent(node);
GameEvents.Add(thisEvent);
}
else if (typeID == "MapEvent")
{
HUDMapEvent thisEvent = new HUDMapEvent(node);
GameEvents.Add(thisEvent);
}
else if (typeID == "StackEvent")
{
HUDStackEvent thisEvent = new HUDStackEvent(node);
GameEvents.Add(thisEvent);
}
else if (typeID == "AIEvent")
{
AIEvent thisEvent = new AIEvent(node);
GameEvents.Add(thisEvent);
}
else if (typeID == "LevelChangeEvent")
{
LevelChangeEvent thisEvent = new LevelChangeEvent(node);
GameEvents.Add(thisEvent);
}
}
}
}
}
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine("Error reading xml");
throw e;
}
}
///
/// 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 is 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()
{
// KAT CLEAN: We shouldn't need this human access
// Is there a better Xml solution??
IHuman human = DarkWynterEngine.engine.objectLibrary.humans[0] as IHuman;
human.MapStart = Statics_Engine.SystemSettings.content.Load("Content/_textures/MapHUD/map");
//human.StackStart = Statics_Engine.SystemSettings.content.Load("Content/_textures/StackHUD/ThoughtStackNode1.1");
human.SetSpawnPoint(new Vector3(1270, 839, 880));
Statics_Engine.PlayerSettings.coinsCollected = 0;
DarkWynterEngine._HUD.UpdateImageDisplay(human.mapIndex, human.MapStart, human.MAP_IMAGE_LOCATION, human.MapStart.Width, human.MapStart.Height, Color.White, true);
// DarkWynterEngine.HUD.UpdateImageDisplay(human.stackIndex, human.StackStart, human.STACK_IMAGE_LOCATION, human.StackStart.Width, human.StackStart.Height, Color.White, true);
}
}
}