/// <summary> /// Add an enemy locally and to xml /// </summary> /// <param name="id"></param> /// <param name="name"></param> /// <param name="maxHealth"></param> /// <param name="dmg"></param> public void addEnemy(int id, string name, float maxHealth, float dmg) { Enemy c = new Enemy(maxHealth, name, dmg); if (npcSecurityCheck(c)) { try { npcs.Add(id, c); } catch (ArgumentException e) { Random r = new Random(); while (npcs.ContainsKey(id)) { id = r.Next(); } npcs.Add(id, c); } addEnemyToXML(id, c); GUI.Instance.appendToOutput("Enemy added with id:" + id); } else { GUI.Instance.appendToOutput("Could not add enemy"); } }
/// <summary> /// Do the combat behaviour with an enemy /// </summary> /// <param name="e"></param> public void doCombat(Enemy e) { string scriptFile; enemy = e; if (scripts.TryGetValue("mainCombat", out scriptFile)) { LuaManager.executeScript(scriptFile); } else { fightTillDeath(); } enemy = null; }
/// <summary> /// Loads npc list from XML /// </summary> private void loadNpcs() { xElem = PersistenceManager.initXML(Properties.Settings.Default.npcFile, "npcs"); npcs = new Dictionary<int, Character>(); foreach (var npc in xElem.Elements()) { Character c; if (npc.Element("isEnemy") == null || (npc.Element("isEnemy")!=null && Int32.Parse(npc.Element("isEnemy").Value) == 0)) { c = new Character(); } else { c = new Enemy(); ((Enemy)c).maxHealth = float.Parse(npc.Element("maxHealth").Value); ((Enemy)c).dmg = float.Parse(npc.Element("dmg").Value); } c.name = npc.Element("name").Value; npcs.Add(Int32.Parse(npc.Element("id").Value), c); } }
/// <summary> /// Adds an enemy to the XML file /// </summary> /// <param name="id"></param> /// <param name="enemy"></param> private void addEnemyToXML(int id, Enemy enemy) { xElem.Add(new XElement("npc", new XElement("id", id), new XElement("name", enemy.name), new XElement("maxHealth", enemy.maxHealth), new XElement("dmg", enemy.dmg), new XElement("isEnemy", 1))); xElem.Save(Properties.Settings.Default.npcFile); }