示例#1
0
        private bool LoadRooms(XmlDocument file, string filename)
        {
            XmlNodeList list = file.GetElementsByTagName ("RoomData");

            foreach (XmlNode node in list)
            {
                RoomData room = new RoomData ();
                room.Number = -1;

                try
                {
                    room.Number = Int32.Parse (node.Attributes["Number"].Value);

                    foreach (XmlNode child in node.ChildNodes)
                    {
                        switch (child.Name)
                        {
                            case "Name":
                                room.Name = child.InnerText;
                                break;

                            case "Description":
                                room.Description = child.InnerText;
                                break;

                            case "Zone":
                                room.Zone = Int32.Parse (child.InnerText);
                                break;

                            case "Flags":
                                room.Flags = long.Parse (child.InnerText);
                                break;

                            case "SectorType":
                                room.SectorType = (SectorTypes)int.Parse (child.InnerText);
                                break;

                            case "Direction":
                                int direction = Int32.Parse (child.Attributes["Direction"].Value);

                                if (room.DirectionOptions[direction] != null)
                                {
                                    Log ("SYSERR: Direction [" + direction + "] already defined in XML file: " + filename);
                                    continue;
                                }

                                room.DirectionOptions[direction] = new RoomDirectionData ();
                                room.DirectionOptions[direction].Description = child["Description"].InnerText;
                                room.DirectionOptions[direction].Keyword = child["Keyword"].InnerText;
                                room.DirectionOptions[direction].Key = Int32.Parse (child["Key"].InnerText);
                                room.DirectionOptions[direction].ToRoom = Int32.Parse (child["ToRoom"].InnerText);

                                int exitinfo = Convert.ToInt32 (child["Flags"].InnerText);

                                if (exitinfo == 1)
                                    room.DirectionOptions[direction].ExitInfo = (long)DirectionOptionFlags.IsDoor;
                                else if (exitinfo == 2)
                                    room.DirectionOptions[direction].ExitInfo = (long)DirectionOptionFlags.IsDoor | (long)DirectionOptionFlags.PickProof;
                                else
                                    room.DirectionOptions[direction].ExitInfo = (long)DirectionOptionFlags.None;
                                break;

                            case "ExtraDescription":
                                ExtraDescriptionData description = new ExtraDescriptionData ();
                                description.Keyword = child["Keyword"].InnerText;
                                description.Description = child["Description"].InnerText;
                                room.ExtraDescriptions.Add (description);
                                break;

                            case "Trigger":
                                // TODO: Add trigger stuff here.
                                break;
                        }
                    }
                }
                catch
                {
                    Log ("SYSERR: Error pasing XML for room [" + room.Number + "] in file: " + filename);
                    return false;
                }

                _rooms.Add (_topOfRoomTable++, room);
            }

            return true;
        }
示例#2
0
        private bool LoadObjects(XmlDocument file, string filename)
        {
            XmlNodeList list = file.GetElementsByTagName ("ObjectData");

            foreach (XmlNode node in list)
            {
                ObjectData obj = new ObjectData ();
                int virtualNumber = -1;

                try
                {
                    virtualNumber = Int32.Parse (node.Attributes["Number"].Value);
                    obj.Number = _topOfObjectTable;

                    foreach (XmlNode child in node.ChildNodes)
                    {
                        switch (child.Name)
                        {
                            case "Name":
                                obj.Name = child.InnerText;
                                break;

                            case "ShortDescription":
                                obj.ShortDescription = child.InnerText;
                                break;

                            case "Description":
                                obj.Description = child.InnerText;
                                break;

                            case "ActionDescription":
                                obj.ActionDescription = child.InnerText;
                                break;

                            case "ObjectType":
                                obj.Type = (ObjectTypes)int.Parse (child.InnerText);
                                break;

                            case "ObjectFlags":
                                obj.Flags.ObjectFlags = long.Parse (child.InnerText);
                                break;

                            case "WearFlags":
                                obj.Flags.WearFlags = long.Parse (child.InnerText);
                                break;

                            case "Bitvector":
                                obj.Flags.Bitvector = long.Parse (child.InnerText);
                                break;

                            case "Values":
                                obj.Flags.Values[0] = Int32.Parse (child.Attributes["One"].Value);
                                obj.Flags.Values[1] = Int32.Parse (child.Attributes["Two"].Value);
                                obj.Flags.Values[2] = Int32.Parse (child.Attributes["Three"].Value);
                                obj.Flags.Values[3] = Int32.Parse (child.Attributes["Four"].Value);
                                break;

                            case "Weight":
                                obj.Flags.Weight = Int32.Parse (child.InnerText);
                                break;

                            case "Cost":
                                obj.Flags.Cost = Int32.Parse (child.InnerText);
                                break;

                            case "CostPerDay":
                                obj.Flags.CostPerDay = Int32.Parse (child.InnerText);
                                break;

                            case "MinimumLevel":
                                obj.Flags.MinimumLevel = Int32.Parse (child.InnerText);
                                break;

                            case "Affect":
                                ObjectAffectData affect = new ObjectAffectData ();
                                affect.Location = (ApplyTypes)Int32.Parse (child["Location"].InnerText);
                                affect.Modifier = Int32.Parse (child["Modifier"].InnerText);
                                obj.Affects.Add (affect);
                                break;

                            case "ExtraDescription":
                                ExtraDescriptionData description = new ExtraDescriptionData ();
                                description.Keyword = child["Keyword"].InnerText;
                                description.Description = child["Description"].InnerText;
                                obj.ExtraDescriptions.Add (description);
                                break;

                            case "Trigger":
                                // TODO: Add trigger stuff here.
                                break;
                        }
                    }
                }
                catch
                {
                    Log ("SYSERR: Error pasing XML for object [" + virtualNumber + "] in file: " + filename);
                    return false;
                }

                IndexData index = new IndexData ();
                index.VirtualNumber = virtualNumber;
                index.Count = 0;
                _objectIndex.Add (_topOfObjectTable, index);

                _objects.Add (_topOfObjectTable++, obj);
            }

            return true;
        }