예제 #1
0
		/// <summary>
		/// Loads square definition
		/// </summary>
		/// <param name="xml">XmlNode handle</param>
		/// <returns></returns>
		public bool Load(XmlNode xml)
		{
			if (xml == null || xml.Name != Tag)
				return false;

			// A little speedup
			string[] cardinalnames = Enum.GetNames(typeof(CardinalPoint));


			// Attributes of the square
			InFog = xml.Attributes["infog"] != null;
			NoMonster = xml.Attributes["nomonster"] != null;
			NoGhost = xml.Attributes["noghost"] != null;

			if (xml.Attributes["type"] != null)
			{
				SquareType tmptype;
				Enum.TryParse<SquareType>(xml.Attributes["type"].Value, out tmptype);
				Type = tmptype;
			}
			else
				Type = SquareType.Ground;

			foreach (XmlNode node in xml)
			{
				if (node.NodeType == XmlNodeType.Comment)
					continue;



				switch (node.Name.ToLower())
				{
					case "monster":
					{
						Monster monster = new Monster();
						monster.Load(node);
						monster.Teleport(this, (SquarePosition)Enum.Parse(typeof(SquarePosition), node.Attributes["position"].Value));
					}
					break;

					case "item":
					{
						SquarePosition loc = (SquarePosition)Enum.Parse(typeof(SquarePosition), node.Attributes["location"].Value);
						Item item = ResourceManager.CreateAsset<Item>(node.Attributes["name"].Value);
						if (item != null)
							Items[(int)loc].Add(item);
					}
					break;

					case "decoration":
					{
						Decorations[0] = int.Parse(node.Attributes[cardinalnames[0]].Value);
						Decorations[1] = int.Parse(node.Attributes[cardinalnames[1]].Value);
						Decorations[2] = int.Parse(node.Attributes[cardinalnames[2]].Value);
						Decorations[3] = int.Parse(node.Attributes[cardinalnames[3]].Value);
					}
					break;

					case WallSwitch.Tag:
					{
						Actor = new WallSwitch(this);
						Actor.Load(node);
					}
					break;

					case Door.Tag:
					{
						Actor = new Door(this);
						Actor.Load(node);
					}
					break;

					case Teleporter.Tag:
					{
						Actor = new Teleporter(this);
						Actor.Load(node);
					}
					break;

					case PressurePlate.Tag:
					{
						Actor = new PressurePlate(this);
						Actor.Load(node);
					}
					break;

					case Pit.Tag:
					{
						Actor = new Pit(this);
						Actor.Load(node);
					}
					break;

					case ForceField.Tag:
					{
						Actor = new ForceField(this);
						Actor.Load(node);
					}
					break;

					case Stair.Tag:
					{
						Actor = new Stair(this);
						Actor.Load(node);
					}
					break;

					case EventSquare.Tag:
					{
						Actor = new EventSquare(this);
						Actor.Load(node);
					}
					break;

					case AlcoveActor.Tag:
					{
						Actor = new AlcoveActor(this);
						Actor.Load(node);
					}
					break;

					default:
					{
					//	Trace.WriteLine("[Square] Load() : Unknown node \"{0}\"", node.Name);
					}
					break;
				}
			}



			return true;
		}
예제 #2
0
        /// <summary>
        /// Loads square definition
        /// </summary>
        /// <param name="xml">XmlNode handle</param>
        /// <returns></returns>
        public bool Load(XmlNode xml)
        {
            if (xml == null || xml.Name != Tag)
            {
                return(false);
            }

            // A little speedup
            string[] cardinalnames = Enum.GetNames(typeof(CardinalPoint));


            // Attributes of the square
            InFog     = xml.Attributes["infog"] != null;
            NoMonster = xml.Attributes["nomonster"] != null;
            NoGhost   = xml.Attributes["noghost"] != null;

            if (xml.Attributes["type"] != null)
            {
                SquareType tmptype;
                Enum.TryParse <SquareType>(xml.Attributes["type"].Value, out tmptype);
                Type = tmptype;
            }
            else
            {
                Type = SquareType.Ground;
            }

            foreach (XmlNode node in xml)
            {
                if (node.NodeType == XmlNodeType.Comment)
                {
                    continue;
                }



                switch (node.Name.ToLower())
                {
                case "monster":
                {
                    Monster monster = new Monster();
                    monster.Load(node);
                    monster.Teleport(this, (SquarePosition)Enum.Parse(typeof(SquarePosition), node.Attributes["position"].Value));
                }
                break;

                case "item":
                {
                    SquarePosition loc  = (SquarePosition)Enum.Parse(typeof(SquarePosition), node.Attributes["location"].Value);
                    Item           item = ResourceManager.CreateAsset <Item>(node.Attributes["name"].Value);
                    if (item != null)
                    {
                        Items[(int)loc].Add(item);
                    }
                }
                break;

                case "decoration":
                {
                    Decorations[0] = int.Parse(node.Attributes[cardinalnames[0]].Value);
                    Decorations[1] = int.Parse(node.Attributes[cardinalnames[1]].Value);
                    Decorations[2] = int.Parse(node.Attributes[cardinalnames[2]].Value);
                    Decorations[3] = int.Parse(node.Attributes[cardinalnames[3]].Value);
                }
                break;

                case WallSwitch.Tag:
                {
                    Actor = new WallSwitch(this);
                    Actor.Load(node);
                }
                break;

                case Door.Tag:
                {
                    Actor = new Door(this);
                    Actor.Load(node);
                }
                break;

                case Teleporter.Tag:
                {
                    Actor = new Teleporter(this);
                    Actor.Load(node);
                }
                break;

                case PressurePlate.Tag:
                {
                    Actor = new PressurePlate(this);
                    Actor.Load(node);
                }
                break;

                case Pit.Tag:
                {
                    Actor = new Pit(this);
                    Actor.Load(node);
                }
                break;

                case ForceField.Tag:
                {
                    Actor = new ForceField(this);
                    Actor.Load(node);
                }
                break;

                case Stair.Tag:
                {
                    Actor = new Stair(this);
                    Actor.Load(node);
                }
                break;

                case EventSquare.Tag:
                {
                    Actor = new EventSquare(this);
                    Actor.Load(node);
                }
                break;

                case AlcoveActor.Tag:
                {
                    Actor = new AlcoveActor(this);
                    Actor.Load(node);
                }
                break;

                default:
                {
                    //	Trace.WriteLine("[Square] Load() : Unknown node \"{0}\"", node.Name);
                }
                break;
                }
            }



            return(true);
        }