public void Init() { int [] list = new int[] { 0, 1, 33, 30, 36, 37, 47, 169, 209, 269, 289, 309, 329, 451, 469, 489, 529 }; foreach (int i in list) { FileStream fsa = new FileStream(World.Path + "mapd" + i.ToString() + ".bin", FileMode.Open, FileAccess.Read); BinaryReader ra = new BinaryReader(fsa); while (true) { int mapid = ra.ReadInt32(); if (mapid == -1) { break; } int areaid = ra.ReadInt32(); float xmin = ra.ReadSingle(); float xmax = ra.ReadSingle(); float ymin = ra.ReadSingle(); float ymax = ra.ReadSingle(); if (WorldDelimiters[mapid] == null) { WorldDelimiters[mapid] = new Hashtable(); } Continent(mapid)[areaid] = new ZoneDelimiters(areaid, xmin, ymin, xmax, ymax); } ra.Close(); } }
public int NearestZoneId(int mapId, float x, float y) { IDictionaryEnumerator zoneEnumerator = null; zoneEnumerator = Continent(mapId).GetEnumerator(); while (zoneEnumerator.MoveNext()) { ZoneDelimiters zd = zoneEnumerator.Value as ZoneDelimiters; if (zd.Xmax + UNITSIZE >= x && zd.Xmin - UNITSIZE <= x && zd.Ymax + UNITSIZE / 2 >= y && zd.Ymin - UNITSIZE / 2 <= y) { return((int)zoneEnumerator.Key); } } return(-1); }
public Hashtable GetZoneHash(int mapId, int zoneId, float x, float y) { ZoneDelimiters zd = null; Hashtable continent = null; zd = Continent(mapId)[zoneId] as ZoneDelimiters; if (zd == null) { Console.WriteLine("Unknown zone id {0}", zoneId); return(null); } if (!zd.Loaded) { Load(mapId, zoneId); } continent = (Hashtable)this.Azeroth[mapId * 1024 + zoneId]; return(continent); }
public void Init() { int []list = new int[] { 0, 1, 33, 30, 36, 37, 47, 169, 209, 269, 289, 309, 329, 451, 469, 489, 529 }; foreach( int i in list ) { FileStream fsa = new FileStream( World.Path + "mapd" + i.ToString() + ".bin", FileMode.Open, FileAccess.Read); BinaryReader ra = new BinaryReader( fsa ); while( true ) { int mapid = ra.ReadInt32(); if ( mapid == -1 ) break; int areaid = ra.ReadInt32(); float xmin = ra.ReadSingle(); float xmax = ra.ReadSingle(); float ymin = ra.ReadSingle(); float ymax = ra.ReadSingle(); if ( WorldDelimiters[ mapid ] == null ) WorldDelimiters[ mapid ] = new Hashtable(); Continent( mapid )[ areaid ] = new ZoneDelimiters( areaid, xmin, ymin, xmax, ymax ); } ra.Close(); } }
public MapPoint NearestPoint(Hashtable continent, int mapId, int zoneId, float x, float y) { float dist = float.MaxValue; ZoneDelimiters zd = null; if (continent == null) { zd = Continent(mapId)[zoneId] as ZoneDelimiters; if (zd == null) { Console.WriteLine("Unknown zone id {0}", zoneId); } if (!zd.Loaded) { Load(mapId, zoneId); } continent = (Hashtable)this.Azeroth[mapId * 1024 + zoneId]; } if (continent == null) { Console.WriteLine("zone"); } IDictionaryEnumerator zoneEnumerator = continent.GetEnumerator(); int ax = 0; int ay = 0; float az = 0; //x -= zd.Xmin; //y -= zd.Ymin; y /= UNITSIZE * 0.5f; int aey = (int)y; if ((int)((int)y & 2) == 1) { x -= UNITSIZE * 0.5f; } x /= UNITSIZE; while (zoneEnumerator.MoveNext()) { uint a = (uint)zoneEnumerator.Key; short xx = (short)((a >> 16) - 0x8000); short yy = (short)((a & 0xffff) - 0x8000); float px = Math.Abs((float)xx - x); float py = Math.Abs((float)yy - y); px *= px; py *= py; px += py; if (px < dist) { dist = px; ax = (int)xx; ay = (int)yy; az = (float)zoneEnumerator.Value; } } if ((int)(ay & 2) == 1) { return(new MapPoint((UNITSIZE / 2) + ((float)ax * UNITSIZE), (float)ay * UNITSIZE * 0.5f, az)); } return(new MapPoint((float)ax * UNITSIZE, (float)ay * UNITSIZE * 0.5f, az)); }
public MapPoint Get(int pos, int zoneId, int mapId, Mobile mob, bool reenter) { float x = mob.X; float y = mob.Y; // Hashtable hy = mob.SpawnerLink.ZoneHash; ZoneDelimiters zd = null; Hashtable continent = Continent(mapId); if (continent == null) { Console.WriteLine("Invalid mapId {0} -> DrNexus", mapId); return(null); } zd = continent[zoneId] as ZoneDelimiters; if (!(zd.Xmax + UNITSIZE > x && zd.Xmin - UNITSIZE < x && zd.Ymax + UNITSIZE > y && zd.Ymin - UNITSIZE < y)) { // Console.WriteLine( "Mob outside his zone {0} {1} [{2},{3};{4},{5}] {6}!", x, y, zd.Xmin, zd.Ymin, zd.Xmax, zd.Ymax, zoneId ); // return new MapPoint( mob.SpawnerLink.X, mob.SpawnerLink.Y, mob.SpawnerLink.Z ); return(this.NearestPoint(mob.SpawnerLink.ZoneHash, mapId, zoneId, x, y)); } if (!zd.Loaded) { Load(mapId, zoneId); } // coordx = coordx >> 2; Hashtable hy = null; hy = (Hashtable)Azeroth[mapId * 1024 + zoneId]; int coordy = (int)(y / (UNITSIZE * 0.5f)); if ((int)(coordy & 2) == 1) { x -= (UNITSIZE * 0.5f); } int coordx = (int)(x / UNITSIZE); if (hy == null) { Console.WriteLine("hy map == null for {0}/{1}", mapId, zoneId); return(null); } switch (pos) { case 0: coordy--; // if ( ( coordy & 1 ) == 0 ) coordx--; break; case 1: coordy--; // if ( ( coordy & 1 ) == 1 ) // coordx++; break; case 2: coordx++; break; case 5: coordx--; break; case 4: coordy++; // if ( ( coordy & 1 ) == 0 ) // coordx--; break; case 3: coordy++; // if ( ( coordy & 1 ) == 1 ) coordx++; break; } uint cx = (uint)coordx + 0x8000; uint cy = (uint)coordy + 0x8000; object o = hy[((uint)cx << 16) + (uint)cy]; if (o == null) { o = hy[cx + (uint)cy + 1]; if (o == null) { o = hy[cx + (uint)cy - 1]; if (o == null) { o = hy[(uint)((cx + 1) << 16) + (uint)cy]; if (o == null) { o = hy[(uint)((cx - 1) << 16) + (uint)cy]; if (o != null) { return(new MapPoint((float)--coordx * (UNITSIZE), (float)coordy * UNITSIZE * 0.5f, (float)o)); } } else { return(new MapPoint((float)++coordx * (UNITSIZE), (float)coordy * UNITSIZE * 0.5f, (float)o)); } } else { return(new MapPoint((float)coordx * (UNITSIZE), (float)--coordy * UNITSIZE * 0.5f, (float)o)); } } else { return(new MapPoint((float)coordx * (UNITSIZE), (float)++coordy * UNITSIZE * 0.5f, (float)o)); } if (reenter) { return(null); } MapPoint mp = NearestPoint(mob.SpawnerLink.ZoneHash, mapId, zoneId, x, y); return(Get(pos, zoneId, mapId, mob, true)); } return(new MapPoint((float)coordx * (UNITSIZE), (float)coordy * UNITSIZE * 0.5f, (float)o)); }