public bool Load() { try { XmlDocument xdoc = new XmlDocument(); xdoc.Load(AssetManager.Get().GetAsset(DBPath)); foreach (XmlNode ttNode in xdoc.DocumentElement.ChildNodes) { XmlElement ttElem = (XmlElement)ttNode; if (ttElem != null && ttElem.Name == "tournament") { try { List <TriadGameModifier> rules = new List <TriadGameModifier>(); foreach (XmlNode innerNode in ttElem.ChildNodes) { XmlElement testElem = (XmlElement)innerNode; if (testElem != null) { if (testElem.Name == "rule") { int ruleId = int.Parse(testElem.GetAttribute("id")); rules.Add(TriadGameModifierDB.Get().mods[ruleId].Clone()); } } } TriadTournament newTournament = new TriadTournament(int.Parse(ttElem.GetAttribute("id")), rules); while (tournaments.Count <= newTournament.Id) { tournaments.Add(null); } tournaments[newTournament.Id] = newTournament; } catch (Exception ex) { Logger.WriteLine("Loading failed! Exception:" + ex); } } } } catch (Exception ex) { Logger.WriteLine("Loading failed! Exception:" + ex); } Logger.WriteLine("Loaded tournaments: " + tournaments.Count); return(tournaments.Count > 0); }
public bool Load() { try { XmlDocument xdoc = new XmlDocument(); xdoc.Load(AssetManager.Get().GetAsset(DBPath)); foreach (XmlNode npcNode in xdoc.DocumentElement.ChildNodes) { XmlElement npcElem = (XmlElement)npcNode; if (npcElem != null && npcElem.Name == "npc") { try { List <TriadGameModifier> rules = new List <TriadGameModifier>(); List <TriadCard> rewards = new List <TriadCard>(); int[] deckA = new int[5]; int[] deckV = new int[5]; foreach (XmlNode innerNode in npcElem.ChildNodes) { XmlElement testElem = (XmlElement)innerNode; if (testElem != null) { if (testElem.Name == "rule") { int ruleId = int.Parse(testElem.GetAttribute("id")); rules.Add(TriadGameModifierDB.Get().mods[ruleId].Clone()); } else if (testElem.Name == "reward") { int cardId = int.Parse(testElem.GetAttribute("id")); rewards.Add(TriadCardDB.Get().cards[cardId]); } else if (testElem.Name == "deckA") { deckA[0] = int.Parse(testElem.GetAttribute("id0")); deckA[1] = int.Parse(testElem.GetAttribute("id1")); deckA[2] = int.Parse(testElem.GetAttribute("id2")); deckA[3] = int.Parse(testElem.GetAttribute("id3")); deckA[4] = int.Parse(testElem.GetAttribute("id4")); } else if (testElem.Name == "deckV") { deckV[0] = int.Parse(testElem.GetAttribute("id0")); deckV[1] = int.Parse(testElem.GetAttribute("id1")); deckV[2] = int.Parse(testElem.GetAttribute("id2")); deckV[3] = int.Parse(testElem.GetAttribute("id3")); deckV[4] = int.Parse(testElem.GetAttribute("id4")); } } } TriadNpc newNpc = new TriadNpc( int.Parse(npcElem.GetAttribute("id")), rules, rewards, deckA, deckV); newNpc.LocationX = int.Parse(npcElem.GetAttribute("mx")); newNpc.LocationY = int.Parse(npcElem.GetAttribute("my")); while (npcs.Count <= newNpc.Id) { npcs.Add(null); } npcs[newNpc.Id] = newNpc; } catch (Exception ex) { Logger.WriteLine("Loading failed! Exception:" + ex); } } } } catch (Exception ex) { Logger.WriteLine("Loading failed! Exception:" + ex); } Logger.WriteLine("Loaded npcs: " + npcs.Count); return(npcs.Count > 0); }