Ejemplo n.º 1
0
        /// <summary>
        /// Loads an upgrade type definition from the given XML node.
        /// </summary>
        /// <param name="upgradeTypeElem">The XML node to load from.</param>
        /// <param name="metadata">The metadata object being constructed.</param>
        private static void LoadUpgradeType(XElement upgradeTypeElem, ScenarioMetadata metadata)
        {
            XAttribute nameAttr = upgradeTypeElem.Attribute(XmlMetadataConstants.TYPE_NAME_ATTR);

            if (nameAttr == null)
            {
                throw new SimulatorException("Upgrade type name not defined!");
            }

            UpgradeType upgradeType = new UpgradeType(nameAttr.Value, metadata);

            LoadScenarioElementType(upgradeTypeElem, upgradeType, metadata);

            XElement researchedInElem = upgradeTypeElem.Element(XmlMetadataConstants.RESEARCHEDIN_ELEM);

            if (researchedInElem != null)
            {
                upgradeType.SetResearchedIn(researchedInElem.Value);
            }

            XElement previousLevelElem = upgradeTypeElem.Element(XmlMetadataConstants.PREVIOUSLEVEL_ELEM);

            if (previousLevelElem != null)
            {
                upgradeType.SetPreviousLevelName(previousLevelElem.Value);
            }

            XElement effectsElem = upgradeTypeElem.Element(XmlMetadataConstants.EFFECTS_ELEM);

            if (effectsElem != null)
            {
                foreach (XElement effectElem in effectsElem.Elements())
                {
                    upgradeType.AddEffect(LoadUpgradeEffect(effectElem, metadata));
                }
            }

            metadata.AddUpgradeType(upgradeType);
        }