private void parse(string data) { Regex reg = new Regex(pattern_); MatchCollection mc = reg.Matches(data); foreach (Match m in mc) { if (m.Result("${Type}").Length > 0) //monster traits { monsters_traits_.Add(EnumConvert.MonsterTraitsFromString(m.Result("${Type}"))); } if (m.Result("${Chance}").Length > 0) //chance for composition { try { chance_ = int.Parse(m.Result("${Chance}")); } catch (Exception) { } } if (m.Result("${Name}").Length > 0) //composition reference { refs_.Add(m.Result("${Name}")); } } }
/// <summary> /// initialization /// </summary> private void parse(XmlNode node) { town_ = EnumConvert.TownTypeFromString(node.Name); foreach (XmlNode n in node.ChildNodes) { specializations_.Add(n.InnerText); } }
public Guards() { xdocGuards = new XmlDocument(); xdocGuards.Load(GUARDSSOURCEFILENAME); ca_parser_ = new ComboArmyParser(xdocGuards.DocumentElement); m_parser_ = new MonstersParser(xdocGuards.DocumentElement); tg_parser_ = new TownGarrisonParser(xdocGuards.DocumentElement, EnumConvert.MapSizeFromInt(Settings.Default.SelectedSizeIndex)); ts_parser_ = new TownSpecParser(); }
/// <summary> /// Convert town name from xml to href /// </summary> /// <param name="xmltown">xml name</param> /// <returns>href name</returns> private string xmltown_to_hreftown(string xmltown) { string hreftown = EnumConvert.HREFTownStringFromString(xmltown); if (hreftown.Length == 0) { throw new Exception("Critical error: Wrong moster description"); } return(hreftown); }
/// <summary> /// Save first monster in an army /// </summary> /// <param name="xml_node"></param> /// <param name="holder"></param> /// <returns></returns> private XmlNode save_primary_monster(XmlNode xml_node, MonsterPlaceHolder holder) { StringBuilder href = new StringBuilder(); if (holder.Monster.CreatureName == "") //random monster { href.AppendFormat("Random/Random-Monster-L{0}.(AdvMapMonsterShared).xdb", holder.Monster.Level); } else //defined moster { string ext = holder.Monster.CreatureName.Contains(".xdb") ? "" : ".(AdvMapMonsterShared).xdb"; href.AppendFormat("{0}/{1}{2}", EnumConvert.HREFTownStringFromString(holder.Monster.Town), holder.Monster.CreatureName, ext); } XmlNode shared = ((XmlElement)xml_node).GetElementsByTagName("Shared")[0]; ((XmlElement)shared).SetAttribute("href", shared.Attributes["href"].Value.Replace("Random/Random-Monster-L3.(AdvMapMonsterShared).xdb", href.ToString())); XmlNode amount = ((XmlElement)xml_node).GetElementsByTagName("Amount")[0]; amount.InnerText = holder.Amount.ToString(); return(((XmlElement)xml_node).GetElementsByTagName("AdditionalStacks")[0]); }
/// <summary> /// initialization /// </summary> private void parse(XmlElement xml_data) { if (xml_data == null || xml_data.ChildNodes.Count < 4 || xml_data.ChildNodes[3].ChildNodes.Count == 0) { throw new Exception("TownGarrison section not found"); } else { foreach (XmlNode node in xml_data.ChildNodes[3].ChildNodes) { if (EnumConvert.MapSizeFromString(node.Attributes["Size"].Value) == map_size_) { foreach (XmlNode n in node.ChildNodes) { variants_.Add(new TownGarrison(n)); } break; } } } }
internal static XmlNode GenerateTownXML(MapObject mpobjObject, XmlNode xndTown, Guards guardsGenerator) //, string strPlayerId) { //ObjectsReader obrdGetTown = new ObjectsReader(); //XmlNode xndTown = obrdGetTown.GetObjectByName("Town"); //set blacksmith string strBlackSmith = mpobjObject.ObjectSpacificProperties[eTown.BlackSmith.ToString()]; if (bool.Parse(strBlackSmith)) { SetTownXMLAttribute(xndTown, eTown.BlackSmith.ToString(), 1); } else { SetTownXMLAttribute(xndTown, eTown.BlackSmith.ToString(), 0); } //set dwelling level and upgrade string strDwellingLevel = mpobjObject.ObjectSpacificProperties[eTown.DwellingLevel.ToString()]; string strDwellingsUpgrades = mpobjObject.ObjectSpacificProperties[eTown.DwellingsUpgrades.ToString()]; int iUpgradeLevel = Convert.ToInt32((bool.Parse(strDwellingsUpgrades))); iUpgradeLevel++; for (int i = 1; i <= int.Parse(strDwellingLevel); i++) { SetTownXMLAttribute(xndTown, "DWELLING_" + i.ToString(), iUpgradeLevel); } //set income level string strIncomeLevel = mpobjObject.ObjectSpacificProperties[eTown.IncomeLevel.ToString()]; SetTownXMLAttribute(xndTown, "TOWN_HALL", (int)Enum.Parse(typeof(eIncome), strIncomeLevel)); //set player string strIsStarting = mpobjObject.ObjectSpacificProperties[eTown.IsStartingTown.ToString()]; //if it needs player assignment assaign it the needed player if (bool.Parse(strIsStarting)) { ////todo:unmark and add playerid xndTown.SelectSingleNode(".//PlayerID").InnerText = mpobjObject.ObjectSpacificProperties["PlayerId"]; ////set type according to user selected town //string strType = mpobjObject.ObjectSpacificProperties[eTown.Type.ToString()]; ////eTownXMLType. //xndTown.SelectSingleNode(".//Shared"); //for a starting zone the template's town settings is not important.. //only first screen will determine town settings and currently //its only random. string strType = mpobjObject.ObjectSpacificProperties[eTown.Type.ToString()]; XmlNode xndSharedType = xndTown.SelectSingleNode(".//Shared"); string strHref = xndSharedType.Attributes["href"].Value; string strName = strHref.Substring("/MapObjects/".Length, strHref.LastIndexOf('.') - "/MapObjects/".Length); if (strName.IndexOf('/') > 0) { strName = strName.Split('/')[1]; } if (strType == eTownType.Random.ToString()) { strHref = strHref.Replace(strName, Enum.Parse(typeof(eTownXMLType), ((int)Enum.Parse(typeof(eTownType), strType)).ToString()).ToString()); } else { strHref = strHref.Replace(strName, Enum.Parse(typeof(eTownXMLType), ((int)Enum.Parse(typeof(eTownType), strType)).ToString()).ToString() + ".(AdvMapTownShared)"); } ((XmlElement)xndSharedType).SetAttribute("href", strHref); //set town specialization TownSpecBuilder ts_builder = new TownSpecBuilder(guardsGenerator.TSParser); string spec = ts_builder.GetRandomSpecialization(EnumConvert.TownTypeFromString(strType)); XmlNode xndSpec = xndTown.SelectSingleNode(".//Specialization"); StringBuilder sb = new StringBuilder(); sb.AppendFormat("/GameMechanics/TownSpecialization/{0}/Random/{1}#xpointer(/TownSpecialization)", ((eTownSpecXMLHREFType)EnumConvert.TownTypeFromString(strType)).ToString(), spec); ((XmlElement)xndSpec).SetAttribute("href", sb.ToString()); } else { //set type according to template definition //set type according to user selected town string strType = mpobjObject.ObjectSpacificProperties[eTown.Type.ToString()]; XmlNode xndSharedType = xndTown.SelectSingleNode(".//Shared"); string strHref = xndSharedType.Attributes["href"].Value; string strName = strHref.Substring("/MapObjects/".Length, strHref.LastIndexOf('.') - "/MapObjects/".Length); if (strName.IndexOf('/') > 0) { strName = strName.Split('/')[1]; } if (strType == eTownType.Random.ToString()) { strHref = strHref.Replace(strName, Enum.Parse(typeof(eTownXMLType), ((int)Enum.Parse(typeof(eTownType), strType)).ToString()).ToString()); } else { strHref = strHref.Replace(strName, Enum.Parse(typeof(eTownXMLType), ((int)Enum.Parse(typeof(eTownType), strType)).ToString()).ToString() + ".(AdvMapTownShared)"); } ((XmlElement)xndSharedType).SetAttribute("href", strHref); //set guards for neutral town TownGarrisonBuilder tgbuilder = new TownGarrisonBuilder(guardsGenerator.TGParser); TownGarrison tg = tgbuilder.GetRandomTownGarrison(); if (tg != null) { XmlNode xndArmySlots = xndTown.SelectSingleNode(".//armySlots"); foreach (XmlNode n in tg.Node.ChildNodes) { xndArmySlots.AppendChild(xndArmySlots.OwnerDocument.ImportNode(n, true)); } } } //set mage guild level string strMageGuildLevel = mpobjObject.ObjectSpacificProperties[eTown.MageGuildLevel.ToString()]; SetTownXMLAttribute(xndTown, "MAGIC_GUILD", int.Parse(strMageGuildLevel)); //set mage guild level string strResourceLevel = mpobjObject.ObjectSpacificProperties[eTown.ResourceLevel.ToString()]; SetTownXMLAttribute(xndTown, "MARKETPLACE", (int)Enum.Parse(typeof(eResource), strResourceLevel)); //set blacksmith string strTavern = mpobjObject.ObjectSpacificProperties[eTown.Tavern.ToString()]; if (bool.Parse(strTavern)) { SetTownXMLAttribute(xndTown, eTown.Tavern.ToString(), 1); } else { SetTownXMLAttribute(xndTown, eTown.Tavern.ToString(), 0); } //set Town Walls string strTownWalls = mpobjObject.ObjectSpacificProperties[eTown.TownWalls.ToString()]; SetTownXMLAttribute(xndTown, "FORT", (int)Enum.Parse(typeof(eWalls), strTownWalls)); return(xndTown); }