Exemplo n.º 1
0
        public static MapRegion LoadRegion(XmlElement xml)
        {
            MapRegion r = new MapRegion();

            XmlSupport.ReadString(xml, "name", ref r.m_Name);
            XmlSupport.ReadInt32(xml, "priority", ref r.m_Priority);
            XmlSupport.ReadString(xml, "type", ref r.m_Type);

            XmlElement zrange = xml["zrange"];
            XmlSupport.ReadInt32(zrange, "min", ref r.m_MinZ, false);
            XmlSupport.ReadInt32(zrange, "max", ref r.m_MaxZ, false);

            foreach (XmlElement xmlRect in xml.SelectNodes("rect"))
            {
                MapRect rect = new MapRect();
                if (XmlSupport.ReadRectangle3D(xmlRect, r.m_MinZ, r.m_MaxZ, ref rect))
                    r.m_Area.Add(rect);
            }

            if (!XmlSupport.ReadPoint3D(xml["go"], ref r.m_GoLocation, false) && r.m_Area.Count > 0)
            {
                Point2D start = ((MapRect)r.m_Area[0]).Start;

                Point2D end = ((MapRect)r.m_Area[0]).End;

                int x = start.X + (end.X - start.X) / 2;
                int y = start.Y + (end.Y - start.Y) / 2;

                r.m_GoLocation = new Point3D(x, y, 0);
            }

            int entranceX = int.MinValue;
            int entranceY = int.MinValue;
            int entranceZ = int.MinValue;

            XmlElement entrance = xml["entrance"];
            if (entrance != null)
            {
                XmlSupport.ReadInt32(entrance, "x", ref entranceX);
                XmlSupport.ReadInt32(entrance, "y", ref entranceY);
                XmlSupport.ReadInt32(entrance, "z", ref entranceZ);
            }

            r.m_Entrance.X = entranceX;
            r.m_Entrance.Y = entranceY;
            r.m_Entrance.Z = entranceZ;

            XmlSupport.ReadString(xml["music"], "name", ref r.m_Music);

            // <rune name="Haven City" />
            XmlSupport.ReadString(xml["rune"], "name", ref r.m_Rune);
            // <smartNoHousing active="true" />
            XmlSupport.ReadXmlBool(xml["smartNoHousing"], "active", ref r.m_SmartNoHousing);
            // <logoutDelay active="false" />
            XmlSupport.ReadXmlBool(xml["logoutDelay"], "active", ref r.m_LogoutDelayActive);
            // <guards disabled="true" />
            XmlSupport.ReadXmlBool(xml["guards"], "disabled", ref r.m_GuardsDisabled);

            // spawning, for now just keep a record of the info so we can persist it.
            r.m_Spawning = xml.SelectNodes("spawning");

            // Subregions
            foreach (XmlElement xRegion in xml.SelectNodes("region"))
            {
                MapRegion sub = MapRegion.LoadRegion(xRegion);

                if (sub != null)
                    r.m_SubRegions.Add(sub);
            }

            return r;
        }
Exemplo n.º 2
0
        public static MapRegion LoadRegion(XmlElement xml)
        {
            MapRegion r = new MapRegion();

            XmlSupport.ReadString(xml, "name", ref r.m_Name);
            XmlSupport.ReadInt32(xml, "priority", ref r.m_Priority);
            XmlSupport.ReadString(xml, "type", ref r.m_Type);

            XmlElement zrange = xml["zrange"];

            XmlSupport.ReadInt32(zrange, "min", ref r.m_MinZ, false);
            XmlSupport.ReadInt32(zrange, "max", ref r.m_MaxZ, false);

            foreach (XmlElement xmlRect in xml.SelectNodes("rect"))
            {
                MapRect rect = new MapRect();
                if (XmlSupport.ReadRectangle3D(xmlRect, r.m_MinZ, r.m_MaxZ, ref rect))
                {
                    r.m_Area.Add(rect);
                }
            }

            if (!XmlSupport.ReadPoint3D(xml["go"], ref r.m_GoLocation, false) && r.m_Area.Count > 0)
            {
                Point2D start = ((MapRect)r.m_Area[0]).Start;

                Point2D end = ((MapRect)r.m_Area[0]).End;

                int x = start.X + (end.X - start.X) / 2;
                int y = start.Y + (end.Y - start.Y) / 2;

                r.m_GoLocation = new Point3D(x, y, 0);
            }

            int entranceX = int.MinValue;
            int entranceY = int.MinValue;
            int entranceZ = int.MinValue;

            XmlElement entrance = xml["entrance"];

            if (entrance != null)
            {
                XmlSupport.ReadInt32(entrance, "x", ref entranceX);
                XmlSupport.ReadInt32(entrance, "y", ref entranceY);
                XmlSupport.ReadInt32(entrance, "z", ref entranceZ);
            }

            r.m_Entrance.X = entranceX;
            r.m_Entrance.Y = entranceY;
            r.m_Entrance.Z = entranceZ;

            XmlSupport.ReadString(xml["music"], "name", ref r.m_Music);

            // <rune name="Haven City" />
            XmlSupport.ReadString(xml["rune"], "name", ref r.m_Rune);
            // <smartNoHousing active="true" />
            XmlSupport.ReadXmlBool(xml["smartNoHousing"], "active", ref r.m_SmartNoHousing);
            // <logoutDelay active="false" />
            XmlSupport.ReadXmlBool(xml["logoutDelay"], "active", ref r.m_LogoutDelayActive);
            // <guards disabled="true" />
            XmlSupport.ReadXmlBool(xml["guards"], "disabled", ref r.m_GuardsDisabled);


            // spawning, for now just keep a record of the info so we can persist it.
            r.m_Spawning = xml.SelectNodes("spawning");

            // Subregions
            foreach (XmlElement xRegion in xml.SelectNodes("region"))
            {
                MapRegion sub = MapRegion.LoadRegion(xRegion);

                if (sub != null)
                {
                    r.m_SubRegions.Add(sub);
                }
            }

            return(r);
        }