public static MapPackage GetMap(int X, int Y, int W, int H) { if (Map.m_X == X && Map.m_Y == Y && (Map.m_Width == W && Map.m_Height == H) && (Map.m_World == Engine.m_World && Map.m_IsCached && !Map.m_QueueInvalidate)) { return(Map.m_Cached); } Map.m_QueueInvalidate = false; if (Map.m_Cached.cells != null) { int length1 = Map.m_Cached.cells.GetLength(0); int length2 = Map.m_Cached.cells.GetLength(1); for (int index1 = 0; index1 < length1; ++index1) { for (int index2 = 0; index2 < length2; ++index2) { ArrayList arrayList = Map.m_Cached.cells[index1, index2]; if (arrayList != null) { int count = arrayList.Count; for (int index3 = 0; index3 < count; ++index3) { ((IDisposable)arrayList[index3]).Dispose(); } } } } } Map.m_X = X; Map.m_Y = Y; Map.m_Width = W; Map.m_Height = H; Map.m_World = Engine.m_World; if (Map.m_StrongReferences == null) { Map.m_StrongReferences = new MapBlock[W * H]; } int length3 = W << 3; int length4 = H << 3; if (Map.m_CellPool == null) { Map.m_CellPool = new ArrayList[length3, length4]; for (int index1 = 0; index1 < length3; ++index1) { for (int index2 = 0; index2 < length4; ++index2) { Map.m_CellPool[index1, index2] = new ArrayList(4); } } } else { for (int index1 = 0; index1 < length3; ++index1) { for (int index2 = 0; index2 < length4; ++index2) { ArrayList arrayList = Map.m_CellPool[index1, index2]; for (int index3 = 0; index3 < arrayList.Count; ++index3) { AgentCell agentCell = arrayList[index3] as AgentCell; if (agentCell != null) { agentCell.Owner = (ArrayList)null; } } arrayList.Clear(); } } } if (Map.m_LandTiles == null) { Map.m_LandTiles = new LandTile[length3, length4]; for (int index1 = 0; index1 < length3; ++index1) { for (int index2 = 0; index2 < length4; ++index2) { Map.m_LandTiles[index1, index2] = new LandTile(); Map.m_LandTiles[index1, index2].x = index1; Map.m_LandTiles[index1, index2].y = index2; } } } if (Map.m_IndexPool == null) { Map.m_IndexPool = new byte[length3, length4]; } if (Map.m_FlagPool == null) { Map.m_FlagPool = new byte[length3, length4]; } ArrayList[,] arrayListArray = Map.m_CellPool; IComparer comparer = TileSorter.Comparer; Engine.Multis.Update(new MapPackage() { cells = arrayListArray, CellX = X << 3, CellY = Y << 3 }); int num1 = Engine.m_World; TileMatrix matrix = Map.GetMatrix(num1); Viewport viewport = World.Viewport; int num2 = 0; int x1 = X; while (num2 < W) { int num3 = 0; int y1 = Y; while (num3 < H) { MapBlock block = matrix.GetBlock(x1, y1); Map.m_StrongReferences[num3 * W + num2] = block; HuedTile[][][] huedTileArray1 = block == null ? matrix.EmptyStaticBlock : block.m_StaticTiles; if (block != null) { Tile[] tileArray = block.m_LandTiles; } else { Tile[] invalidLandBlock = matrix.InvalidLandBlock; } int index1 = 0; int x2 = x1 << 3; int index2 = num2 << 3; while (index1 < 8) { int index3 = 0; int y2 = y1 << 3; int index4 = num3 << 3; while (index3 < 8) { HuedTile[] huedTileArray2 = huedTileArray1[index1][index3]; for (int influence = 0; influence < huedTileArray2.Length; ++influence) { arrayListArray[index2, index4].Add((object)StaticItem.Instantiate(huedTileArray2[influence], influence, x2 * matrix.Height + y2 | influence << 25)); } LandTile landTile = viewport.GetLandTile(x2, y2, num1); landTile.x = index2; landTile.y = index4; arrayListArray[index2, index4].Add((object)landTile); ++index3; ++y2; ++index4; } ++index1; ++x2; ++index2; } ++num3; ++y1; } ++num2; ++x1; } int num4 = X << 3; int num5 = Y << 3; foreach (Item obj in World.Items.Values) { if (obj.InWorld && obj.Visible && !obj.IsMulti) { int index1 = obj.X - num4; int index2 = obj.Y - num5; if (index1 >= 0 && index1 < length3 && (index2 >= 0 && index2 < length4)) { AgentCell agentCell = obj.AcquireViewportCell(); arrayListArray[index1, index2].Add((object)agentCell); agentCell.Owner = arrayListArray[index1, index2]; } } } foreach (Mobile mobile in World.Mobiles.Values) { if (mobile.InWorld && mobile.Visible) { int index1 = mobile.X - num4; int index2 = mobile.Y - num5; if (index1 >= 0 && index1 < length3 && (index2 >= 0 && index2 < length4)) { AgentCell agentCell = mobile.AcquireViewportCell(); arrayListArray[index1, index2].Add((object)agentCell); agentCell.Owner = arrayListArray[index1, index2]; } } } for (int index1 = 0; index1 < length3; ++index1) { for (int index2 = 0; index2 < length4; ++index2) { ArrayList arrayList = arrayListArray[index1, index2]; if (arrayList.Count > 1) { arrayList.Sort(comparer); } } } MapPackage mapPackage = new MapPackage(); mapPackage.cells = arrayListArray; mapPackage.CellX = X << 3; mapPackage.CellY = Y << 3; Map.m_Cached = mapPackage; Map.m_IsCached = true; for (int index = -1; index <= H; ++index) { Engine.QueueMapLoad(X - 1, Y + index, matrix); } for (int index = 0; index < W; ++index) { Engine.QueueMapLoad(X + index, Y - 1, matrix); Engine.QueueMapLoad(X + index, Y + H, matrix); } for (int index = -1; index <= H; ++index) { Engine.QueueMapLoad(X + W, Y + index, matrix); } return(mapPackage); }
public void Update(MapPackage map) { int count1 = this.m_Items.Count; if (count1 == 0) { return; } int length1 = map.cells.GetLength(0); int length2 = map.cells.GetLength(1); int num1 = map.CellX; int num2 = map.CellY; int num3 = num1 + length1; int num4 = num2 + length2; int houseLevel = Options.Current.HouseLevel; for (int index1 = 0; index1 < count1; ++index1) { Item obj = (Item)this.m_Items[index1]; if (obj.InWorld) { CustomMultiEntry customMulti = CustomMultiLoader.GetCustomMulti(obj.Serial, obj.Revision); Multi multi = (Multi)null; if (customMulti != null) { multi = customMulti.Multi; } if (multi == null) { multi = obj.Multi; } if (multi != null) { int xMin; int yMin; int xMax; int yMax; multi.GetBounds(out xMin, out yMin, out xMax, out yMax); xMin += obj.X; yMin += obj.Y; xMax += obj.X; yMax += obj.Y; if (xMin < num3 && xMax >= num1 && (yMin < num4 && yMax >= num2)) { ArrayList list = multi.List; int count2 = list.Count; int num5 = int.MinValue | index1; for (int index2 = 0; index2 < count2; ++index2) { MultiItem multiItem = (MultiItem)list[index2]; if (multiItem.Flags != 0 || index2 == 0) { int num6 = obj.X + (int)multiItem.X; int num7 = obj.Y + (int)multiItem.Y; int index3 = num6 - num1; int index4 = num7 - num2; if (index3 >= 0 && index3 < length1 && (index4 >= 0 && index4 < length2)) { bool flag = true; int num8 = (int)multiItem.ItemID; if (flag) { map.cells[index3, index4].Add((object)StaticItem.Instantiate((short)num8, multiItem.ItemID, (sbyte)(obj.Z + (int)multiItem.Z), num5 | index2 << 16)); } } } } } } } } }