コード例 #1
0
        private void frmPickGuard_FormClosing(object sender, FormClosingEventArgs e)
        {
            Guards gTemplateXMLGenerator = new Guards();

            if (radbtnNormal.Checked)
            {
                XmlElement xTemplateGuard = gTemplateXMLGenerator.GetTemplateGuardXML(Convert.ToInt32(msktxtMainValue.Text));
                if (bIsTownMode)
                {
                }
                else
                {
                    //set connection guard value
                    Program.frmTemplateEdit.thTemplate.ImportGuardToConnection(xTemplateGuard, iConnection);
                }
            }


            bIsTownMode = false;
            e.Cancel    = true;
            this.Hide();
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        internal static XmlNode GenerateGarrisonXML(MapObject mpobjObject, XmlNode xndGarrison, Guards guardsGenerator, eMonsterStrength iStrength)
        {
            //set guards for garrison
            XmlNode xndGuard = guardsGenerator.GetGarrisonGuards((int)(mpobjObject.iValue * double.Parse(Settings.Default.MonsterFactor)),
                                                                 false,
                                                                 iStrength,
                                                                 xndGarrison.SelectSingleNode(".//armySlots"));

            return(xndGarrison);
        }