Ejemplo n.º 1
0
        private void LoadAreas()
        {
            OnProgress("Building world areas");

            var areas = this._xmlRoot.SelectSingleNode("ns:Areas", this._xnm);

            if (areas == null)
            {
                throw new InvalidOperationException();
            }

            XmlNodeList areaList = areas.SelectNodes("ns:Area", this._xnm);

            if (areaList == null)
            {
                throw new InvalidOperationException();
            }

            this._playerStartStates.Clear();
            this._tileDefinitionCollections.Clear();
            this._randomMonsterDistributions.Clear();
            this._randomFruitDistributions.Clear();

            foreach (XmlElement area in areaList)
            {
                var areaRect = RectangleExtensions.GetRectangleFromDefinition(area);

                var startPos = (XmlElement)area.SelectSingleNode("ns:PlayerStartState", this._xnm);
                if (startPos != null)
                {
                    var pss = PlayerStartState.FromXml(startPos);
                    pss.Area = areaRect;
                    this._playerStartStates.Add(pss);
                }

                var tileDefinitions = area.SelectNodes("ns:TileDefinitions/ns:*", this._xnm);
                if (tileDefinitions != null && tileDefinitions.Count != 0)
                {
                    var td = TileDefinitionCollection.FromXml(tileDefinitions);
                    td.Area = areaRect;
                    this._tileDefinitionCollections.Add(td);
                }

                var fruitPopulation = (XmlElement)area.SelectSingleNode("ns:FruitDefinitions", this._xnm);
                if (fruitPopulation != null && fruitPopulation.ChildNodes.Count != 0)
                {
                    var fd = RandomFruitDistribution.FromXml(fruitPopulation);
                    fd.Area = areaRect;
                    this._randomFruitDistributions.Add(fd);
                }

                var randomMonsterDistribution = (XmlElement)area.SelectSingleNode("ns:RandomMonsterDistribution", this._xnm);
                if (randomMonsterDistribution != null)
                {
                    var md = RandomMonsterDistribution.FromXml(randomMonsterDistribution, this._xnm);
                    md.Area = areaRect;
                    this._randomMonsterDistributions.Add(md);
                }
            }
        }
Ejemplo n.º 2
0
        public WorldArea(XmlElement area, XmlNamespaceManager xnm)
        {
            this.Area = RectangleExtensions.GetRectangleFromDefinition(area);

            string worldStart = area.GetAttribute("WorldStart");

            this.IsInitialArea = !string.IsNullOrWhiteSpace(worldStart) && bool.Parse(worldStart);

            var startPos = (XmlElement)area.SelectSingleNode("ns:PlayerStartState", xnm);

            if (startPos != null)
            {
                var pss = PlayerStartState.FromXml(startPos);
                if (!this.Area.ContainsTile(pss.Position))
                {
                    throw new InvalidOperationException("Invalid player start position - co-ordinate is not within the area.");
                }
                this.PlayerStartState = pss;
            }

            var tileDefinitions = area.SelectNodes("ns:TileDefinitions/ns:*", xnm);

            if (tileDefinitions != null)
            {
                var td = TileDefinitionCollection.FromXml(tileDefinitions);
                td.Area = this.Area;
                this.TileDefinitionCollection = td;
            }

            var fruitPopulation = area.SelectNodes("ns:FruitDefinitions/ns:FruitDef", xnm);

            if (fruitPopulation != null)
            {
                var fd = RandomFruitDistribution.FromXml(fruitPopulation);
                fd.Area = this.Area;
                this.FruitDefinitions = fd;
            }

            var randomMonsterDistribution = (XmlElement)area.SelectSingleNode("ns:RandomMonsterDistribution", xnm);

            if (randomMonsterDistribution != null)
            {
                var md = RandomMonsterDistribution.FromXml(randomMonsterDistribution, xnm);
                md.Area = this.Area;
                this.RandomMonsterDistribution = md;
            }
        }
Ejemplo n.º 3
0
        public static RandomMonsterDistribution FromXml(XmlElement node, XmlNamespaceManager xnm)
        {
            var result = new RandomMonsterDistribution
            {
                DiceRoll        = new DiceRoll(node.GetAttribute("DiceToRoll")),
                CountOfMonsters = int.Parse(node.GetAttribute("CountOfMonsters"))
            };

            // ReSharper disable once PossibleNullReferenceException
            foreach (XmlElement mdef in node.SelectNodes("ns:MonsterTemplates/ns:Monster", xnm))
            {
                var md = MonsterDef.FromXml(mdef, xnm);
                int matchingDiceRoll = int.Parse(mdef.GetAttribute("MatchingDiceRoll"));
                result.Templates.Add(matchingDiceRoll, md);
            }

            return(result);
        }