//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// Copyright (C)2007 DarkWynter Studios. All rights reserved.
//
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------
namespace DarkWynter.EventSystem
{
#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 Microsoft.Xna.Framework.Content;
using DarkWynter.EventSystem.EventTypes;
#endregion
///
/// Handles the GameEvents from the game
///
public static class GameEventHandler
{
public static List GameEvents;
public static GameEvent CurrentGameConditions;
public static ContentManager content;
// 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(EventSystemDemo.EventSystemMain game,string fileName)
{
content = game.Content;
GameEventHandler.killEventList();
GameEvents = new List();
CurrentGameConditions = new GameEvent();
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 == "DialogueEvent")
{
DialogueEvent thisEvent = new DialogueEvent(node);
GameEvents.Add(thisEvent);
}
else if (typeID == "MapEvent")
{
HUDEvent thisEvent = new HUDEvent(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";
Vector2 debugPosition = new Vector2(300, 400);
if (CurrentGameConditions._typeID != null)
{
debugType = CurrentGameConditions._typeID.ToString();
}
//Game1.hud.AddTextDisplay("debug", "CurrentGameConditions: \n" + CurrentGameConditions.ToString() + debugType,
// debugPosition, Color.Black, true);
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()
{
// 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);
}
}
}