예제 #1
0
        public static void Load()
        {
            string     text1;
            Map        map1;
            string     text2;
            Region     region1;
            XmlElement element4;
            string     text3;
            Region     region2;

            if (!File.Exists("Data/Regions.xml"))
            {
                Console.WriteLine("Error: Data/Regions.xml does not exist");
                return;
            }
            Console.Write("Regions: Loading...");
            XmlDocument document1 = new XmlDocument();

            document1.Load("Data/Regions.xml");
            XmlElement element1 = document1["ServerRegions"];

            foreach (XmlElement element2 in element1.GetElementsByTagName("Facet"))
            {
                text1 = element2.GetAttribute("name");
                map1  = null;
                try
                {
                    map1 = Map.Parse(text1);
                }
                catch
                {
                }
                if ((map1 == null) || (map1 == Map.Internal))
                {
                    if (Region.m_SupressXmlWarnings)
                    {
                        continue;
                    }
                    Console.WriteLine("Regions.xml: Invalid facet name \'{0}\'", text1);
                    continue;
                }
                foreach (XmlElement element3 in element2.GetElementsByTagName("region"))
                {
                    text2 = element3.GetAttribute("name");
                    if ((text2 != null) && (text2.Length > 0))
                    {
                        region1 = Region.GetByName(text2, map1);
                        if (region1 != null)
                        {
                            if (!region1.LoadFromXml)
                            {
                                if (Region.m_SupressXmlWarnings)
                                {
                                    continue;
                                }
                                Console.WriteLine("Regions.xml: Region \'{0}\' has an XML entry, but is set not to LoadFromXml.", text2);
                                continue;
                            }
                            try
                            {
                                region1.Priority = int.Parse(element3.GetAttribute("priority"));
                            }
                            catch
                            {
                                if (!Region.m_SupressXmlWarnings)
                                {
                                    Console.WriteLine("Regions.xml: Could not parse priority for region \'{0}\' (assuming TownPriority)", region1.Name);
                                }
                                region1.Priority = 50;
                            }
                            element4 = element3["go"];
                            if (element4 != null)
                            {
                                try
                                {
                                    region1.GoLocation = Point3D.Parse(element4.GetAttribute("location"));
                                }
                                catch
                                {
                                    if (!Region.m_SupressXmlWarnings)
                                    {
                                        Console.WriteLine("Regions.xml: Could not parse go location for region \'{0}\'", region1.Name);
                                    }
                                }
                            }
                            element4 = element3["music"];
                            if (element4 != null)
                            {
                                try
                                {
                                    region1.Music = ((MusicName)Enum.Parse(typeof(MusicName), element4.GetAttribute("name"), true));
                                }
                                catch
                                {
                                    if (!Region.m_SupressXmlWarnings)
                                    {
                                        Console.WriteLine("Regions.xml: Could not parse music for region \'{0}\'", region1.Name);
                                    }
                                }
                            }
                            element4 = element3["zrange"];
                            if (element4 != null)
                            {
                                text3 = element4.GetAttribute("min");
                                if ((text3 != null) && (text3 != ""))
                                {
                                    try
                                    {
                                        region1.MinZ = int.Parse(text3);
                                    }
                                    catch
                                    {
                                        if (!Region.m_SupressXmlWarnings)
                                        {
                                            Console.WriteLine("Regions.xml: Could not parse zrange:min for region \'{0}\'", region1.Name);
                                        }
                                    }
                                }
                                text3 = element4.GetAttribute("max");
                                if ((text3 != null) && (text3 != ""))
                                {
                                    try
                                    {
                                        region1.MaxZ = int.Parse(text3);
                                    }
                                    catch
                                    {
                                        if (!Region.m_SupressXmlWarnings)
                                        {
                                            Console.WriteLine("Regions.xml: Could not parse zrange:max for region \'{0}\'", region1.Name);
                                        }
                                    }
                                }
                            }
                            foreach (XmlElement element5 in element3.GetElementsByTagName("rect"))
                            {
                                try
                                {
                                    if (region1.m_LoadCoords == null)
                                    {
                                        region1.m_LoadCoords = new ArrayList(1);
                                    }
                                    region1.m_LoadCoords.Add(Region.ParseRectangle(element5, true));
                                    continue;
                                }
                                catch
                                {
                                    if (Region.m_SupressXmlWarnings)
                                    {
                                        continue;
                                    }
                                    Console.WriteLine("Regions.xml: Error parsing rect for region \'{0}\'", region1.Name);
                                    continue;
                                }
                            }
                            foreach (XmlElement element6 in element3.GetElementsByTagName("inn"))
                            {
                                try
                                {
                                    if (region1.InnBounds == null)
                                    {
                                        region1.InnBounds = new ArrayList(1);
                                    }
                                    region1.InnBounds.Add(Region.ParseRectangle(element6, false));
                                    continue;
                                }
                                catch
                                {
                                    if (Region.m_SupressXmlWarnings)
                                    {
                                        continue;
                                    }
                                    Console.WriteLine("Regions.xml: Error parsing inn for region \'{0}\'", region1.Name);
                                    continue;
                                }
                            }
                            continue;
                        }
                    }
                }
            }
            ArrayList list1 = new ArrayList(Region.m_Regions);
            int       num1  = 0;

            while ((num1 < list1.Count))
            {
                region2 = ((Region)list1[num1]);
                if (!region2.LoadFromXml && (region2.m_Coords == null))
                {
                    region2.Coords = new ArrayList();
                }
                else if (region2.LoadFromXml)
                {
                    if (region2.m_LoadCoords == null)
                    {
                        region2.m_LoadCoords = new ArrayList();
                    }
                    region2.Coords = region2.m_LoadCoords;
                }
                ++num1;
            }
            for (num1 = 0; (num1 < Map.AllMaps.Count); ++num1)
            {
                ((Map)Map.AllMaps[num1]).Regions.Sort();
            }
            ArrayList list2 = new ArrayList(World.Mobiles.Values);

            foreach (Mobile mobile1 in list2)
            {
                mobile1.ForceRegionReEnter(true);
            }
            Console.WriteLine("done");
        }
		public static Dictionary<Map, int> ImportDoors(string file)
		{
			var result = new Dictionary<Map, int>();

			var doc = new XmlDocument();

			doc.Load(file);

			var root = doc["doors"];

			if (root == null)
			{
				return result;
			}

			var doors = new List<BaseDoor>();
			var link = new List<BaseDoor>();

			int index, count;

			Map map;
			BaseDoor door;

			foreach (XmlElement m in root.GetElementsByTagName("facet"))
			{
				count = 0;
				map = null;

				index = XmlConvert.ToInt32(m.GetAttribute("index"));

				if (index > 0 && index < Map.Maps.Length)
				{
					map = Map.Maps[index];
				}

				if (map == null)
				{
					map = Map.Parse(m.GetAttribute("name"));
				}

				if (map == null)
				{
					continue;
				}

#if STRICT
				Region reg;

				foreach (XmlElement r in m.GetElementsByTagName("region"))
				{
					var name = r.GetAttribute("name");

					if (name == map.Name)
					{
						reg = map.DefaultRegion;
					}
					else if (!map.Regions.ContainsKey(name))
					{
						continue;
					}
					else
					{
						reg = map.Regions[name];
					}

					if (reg == null)
					{
						continue;
					}

					foreach (XmlElement o in r)
					{
#else
				foreach (var o in m.GetElementsByTagName("region").OfType<XmlElement>().SelectMany(r => r.OfType<XmlElement>()))
				{
#endif
					switch (o.Name)
					{
						case "door":
						{
							door = DeserializeDoor(o);

							if (door != null)
							{
								AddDoor(doors, door, map);

								++count;
							}
						}
							break;
						case "doors":
						{
							link.Clear();

							foreach (XmlElement d in o.GetElementsByTagName("door"))
							{
								door = DeserializeDoor(d);

								if (door != null)
								{
									AddDoor(doors, door, map);

									++count;

									link.Add(door);
								}
							}

							if (link.Count > 1)
							{
								for (var i = 0; i < link.Count; i++)
								{
									link[i].Link = link[(i + 1) % link.Count];
								}
							}

							link.Clear();
						}
							break;
					}
				}
#if STRICT
				}
#endif
				result[map] = count;
			}

			doors.Clear();
			doors.TrimExcess();

			return result;
		}
예제 #3
0
        public static void ConvertXmlToSpawners()
        {
            string filename = "Spawns";

            if (System.IO.Directory.Exists(filename) == true)
            {
                List <string> files = null;
                string[]      dirs  = null;

                try
                {
                    files = new List <string>(Directory.GetFiles(filename, "*.xml"));
                    dirs  = Directory.GetDirectories(filename);
                }
                catch { }

                if (dirs != null && dirs.Length > 0)
                {
                    foreach (var dir in dirs)
                    {
                        try
                        {
                            string[] dirFiles = Directory.GetFiles(dir, "*.xml");
                            files.AddRange(dirFiles);
                        }
                        catch { }
                    }
                }

                ToConsole(String.Format("Found {0} Xmlspawner files for conversion.", files.Count), files != null && files.Count > 0 ? ConsoleColor.Green : ConsoleColor.Red);

                if (files != null && files.Count > 0)
                {
                    int converted = 0;
                    int failed    = 0;
                    int keep      = 0;

                    foreach (string file in files)
                    {
                        FileStream fs = null;

                        try
                        {
                            fs = File.Open(file, FileMode.Open, FileAccess.Read);
                        }
                        catch { }

                        if (fs == null)
                        {
                            ToConsole(String.Format("Unable to open {0} for loading", filename), ConsoleColor.Red);
                            continue;
                        }

                        DataSet ds = new DataSet("Spawns");

                        try
                        {
                            ds.ReadXml(fs);
                        }
                        catch
                        {
                            fs.Close();
                            ToConsole(String.Format("Error reading xml file {0}", filename), ConsoleColor.Red);
                            continue;
                        }

                        if (ds.Tables != null && ds.Tables.Count > 0)
                        {
                            if (ds.Tables["Points"] != null && ds.Tables["Points"].Rows.Count > 0)
                            {
                                foreach (DataRow dr in ds.Tables["Points"].Rows)
                                {
                                    string id = null;

                                    try
                                    {
                                        id = (string)dr["UniqueId"];
                                    }
                                    catch { }

                                    bool convert = id != null && ConvertSpawner(id, dr);

                                    if (!convert)
                                    {
                                        Point3D loc      = Point3D.Zero;
                                        Map     spawnMap = null;

                                        try
                                        {
                                            loc      = new Point3D(int.Parse((string)dr["CentreX"]), int.Parse((string)dr["CentreY"]), int.Parse((string)dr["CentreZ"]));
                                            spawnMap = Map.Parse((string)dr["Map"]);
                                        }
                                        catch {}

                                        if (loc != Point3D.Zero && spawnMap != null && spawnMap != Map.Internal)
                                        {
                                            if (!ConvertSpawnerByLocation(loc, spawnMap, dr, ref keep))
                                            {
                                                failed++;
                                            }
                                            else
                                            {
                                                converted++;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        converted++;
                                    }
                                }
                            }
                        }

                        fs.Close();
                    }

                    if (converted > 0)
                    {
                        ToConsole(String.Format("Converted {0} XmlSpawners to standard spawners.", converted), ConsoleColor.Green);
                    }

                    if (failed > 0)
                    {
                        ToConsole(String.Format("Failed to convert {0} XmlSpawners to standard spawners. {1} kept due to XmlSpawner Functionality", failed, keep), ConsoleColor.Red);
                    }

                    _SpawnsConverted = true;
                }
                else
                {
                    ToConsole(String.Format("Directory Not Found: {0}", filename), ConsoleColor.Red);
                }
            }
        }
예제 #4
0
        private static void LoadCsvFiles()
        {
            StreamReader reader = new StreamReader(m_Path);

            string line;
            int    lineNum = 0;

            while ((line = reader.ReadLine()) != null)
            {
                ++lineNum;
                line = line.Trim();
                if (line.StartsWith("#"))
                {
                    continue;
                }
                string[] parts = line.Split(m_Sep);
                if (parts.Length != 9)
                {
                    continue;
                }
                try
                {
                    Point3D pointLoc = new Point3D(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]));
                    Map     mapLoc   = Map.Parse(parts[3]);

                    Point3D pointDest = new Point3D(int.Parse(parts[4]), int.Parse(parts[5]), int.Parse(parts[6]));
                    Map     mapDest   = Map.Parse(parts[7]);

                    Teleport teleport = new Teleport(pointLoc, mapLoc, pointDest, mapDest);
                    if (bool.Parse(parts[8]))
                    {
                        teleport.Oneway = false;
                    }

                    Point4D Loc = new Point4D(pointLoc.X, pointLoc.Y, pointLoc.Z, mapLoc.MapID);
                    if (m_TeleportersD1.ContainsKey(Loc))
                    {
                        continue;
                    }
                    m_TeleportersD1.Add(Loc, teleport);

                    if (teleport.Oneway == false)
                    {
                        Teleport teleport2 = new Teleport(pointLoc, mapLoc, pointDest, mapDest);
                        teleport2.Oneway = teleport.Oneway;
                        Point4D Dest = new Point4D(pointDest.X, pointDest.Y, pointDest.Z, mapDest.MapID);
                        if (m_TeleportersD2.ContainsKey(Dest))
                        {
                            continue;
                        }
                        m_TeleportersD2.Add(Dest, teleport2);
                    }
                }
                catch (FormatException)
                {
                    Console.WriteLine(string.Format("Bad number format on line {0}", lineNum));
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(string.Format("Argument Execption {0} on line {1}", ex.Message, lineNum));
                }
            }
            reader.Close();
        }
예제 #5
0
        public static void Load()
        {
            string path = Path.Combine(Core.Config.ConfigDirectory, "Regions.xml");

            if (!System.IO.File.Exists(path))
            {
                log.ErrorFormat("{0} does not exist", path);
                return;
            }

            log.Info("Loading regions");

            XmlDocument doc = new XmlDocument();

            doc.Load(path);

            XmlElement root = doc["ServerRegions"];

            foreach (XmlElement facet in root.GetElementsByTagName("Facet"))
            {
                string facetName = facet.GetAttribute("name");
                Map    map       = null;

                try { map = Map.Parse(facetName); }
                catch {}
                if (map == null || map == Map.Internal)
                {
                    log.ErrorFormat("Regions.xml: Invalid facet name '{0}'", facetName);
                    continue;
                }

                foreach (XmlElement reg in facet.GetElementsByTagName("region"))
                {
                    string name = reg.GetAttribute("name");
                    if (name == null || name.Length <= 0)
                    {
                        continue;
                    }

                    Region r = GetByName(name, map);
                    if (r == null)
                    {
                        //if ( !m_SupressXmlWarnings )
                        //	Console.WriteLine( "Regions.xml: Region '{0}' not defined.", name );
                        continue;
                    }
                    else if (!r.LoadFromXml)
                    {
                        log.ErrorFormat("Regions.xml: Region '{0}' has an XML entry, but is set not to LoadFromXml.",
                                        name);
                        continue;
                    }

                    try
                    {
                        r.Priority = int.Parse(reg.GetAttribute("priority"));
                    }
                    catch (Exception e)
                    {
                        log.Error(String.Format("Regions.xml: Could not parse priority for region '{0}' (assuming TownPriority)",
                                                r.Name),
                                  e);
                        r.Priority = TownPriority;
                    }

                    XmlElement el;

                    el = reg["go"];
                    if (el != null)
                    {
                        try
                        {
                            r.GoLocation = Point3D.Parse(el.GetAttribute("location"));
                        }
                        catch (Exception e)
                        {
                            log.Error(String.Format("Regions.xml: Could not parse go location for region '{0}'",
                                                    r.Name),
                                      e);
                        }
                    }

                    el = reg["music"];
                    if (el != null)
                    {
                        try
                        {
                            r.Music = (MusicName)Enum.Parse(typeof(MusicName), el.GetAttribute("name"), true);
                        }
                        catch (Exception e)
                        {
                            log.Error(String.Format("Regions.xml: Could not parse music for region '{0}'",
                                                    r.Name),
                                      e);
                        }
                    }

                    el = reg["zrange"];
                    if (el != null)
                    {
                        string s = el.GetAttribute("min");
                        if (s != null && s != "")
                        {
                            try
                            {
                                r.MinZ = int.Parse(s);
                            }
                            catch (Exception e)
                            {
                                log.Error(String.Format("Regions.xml: Could not parse zrange:min for region '{0}'",
                                                        r.Name),
                                          e);
                            }
                        }

                        s = el.GetAttribute("max");
                        if (s != null && s != "")
                        {
                            try
                            {
                                r.MaxZ = int.Parse(s);
                            }
                            catch (Exception e)
                            {
                                log.Error(String.Format("Regions.xml: Could not parse zrange:max for region '{0}'",
                                                        r.Name),
                                          e);
                            }
                        }
                    }

                    foreach (XmlElement rect in reg.GetElementsByTagName("rect"))
                    {
                        try
                        {
                            if (r.m_LoadCoords == null)
                            {
                                r.m_LoadCoords = new ArrayList(1);
                            }

                            r.m_LoadCoords.Add(ParseRectangle(rect, true));
                        }
                        catch (Exception e)
                        {
                            log.Error(String.Format("Regions.xml: Error parsing rect for region '{0}'", r.Name),
                                      e);
                            continue;
                        }
                    }

                    foreach (XmlElement rect in reg.GetElementsByTagName("inn"))
                    {
                        try
                        {
                            if (r.InnBounds == null)
                            {
                                r.InnBounds = new ArrayList(1);
                            }

                            r.InnBounds.Add(ParseRectangle(rect, false));
                        }
                        catch (Exception e)
                        {
                            log.Error(String.Format("Regions.xml: Error parsing inn for region '{0}'",
                                                    r.Name),
                                      e);
                            continue;
                        }
                    }
                }
            }

            ArrayList copy = new ArrayList(m_Regions);

            int i;

            for (i = 0; i < copy.Count; ++i)
            {
                Region region = (Region)copy[i];
                if (!region.LoadFromXml && region.m_Coords == null)
                {
                    region.Coords = new ArrayList();
                }
                else if (region.LoadFromXml)
                {
                    if (region.m_LoadCoords == null)
                    {
                        region.m_LoadCoords = new ArrayList();
                    }

                    region.Coords = region.m_LoadCoords;

                    //if ( !m_SupressXmlWarnings )
                    //	Console.WriteLine( "Warning: Region '{0}' did not contain any coords in Regions.xml (map={0})", region, region.Map.Name );
                }
            }

            for (i = 0; i < Map.AllMaps.Count; ++i)
            {
                ((Map)Map.AllMaps[i]).Regions.Sort();
            }

            ArrayList list = new ArrayList(World.Mobiles.Values);

            foreach (Mobile m in list)
            {
                m.ForceRegionReEnter(true);
            }

            log.Info("Finished loading regions");
        }