Ejemplo n.º 1
0
        public static MapDB DecompressMap(MapJson mapj)
        {
            MapDB map = new MapDB();

            map.Key            = mapj.MapId;
            map.AreaId         = mapj.AreaId;
            map.AreaName       = mapj.AreaName;
            map.GlobalAreaName = mapj.GlobalAreaName;
            map.Height         = mapj.Height;
            map.Width          = mapj.Width;
            map.Cells          = new MapCell[mapj.MapData.Length / 10];
            string cellsValues;

            for (int i = 0; i < mapj.MapData.Length; i += 10)
            {
                cellsValues       = mapj.MapData.Substring(i, 10);
                map.Cells[i / 10] = DecompressCell(mapj, cellsValues, Convert.ToInt16(i / 10));
            }
            map.TopCellsTeleport    = DecompressTeleportCells(map.Cells, MovementDirectionEnum.TOP);
            map.RightCellsTeleport  = DecompressTeleportCells(map.Cells, MovementDirectionEnum.RIGHT);
            map.BottomCellsTeleport = DecompressTeleportCells(map.Cells, MovementDirectionEnum.BOTTOM);
            map.LeftCellsTeleport   = DecompressTeleportCells(map.Cells, MovementDirectionEnum.LEFT);
            map.Coordinate          = mapj.Coordinate;
            return(map);
        }
Ejemplo n.º 2
0
        public static MapCell DecompressCell(MapJson map, string cellData, short cellId)
        {
            byte[] cellInformations = new byte[cellData.Length];

            for (int i = 0; i < cellData.Length; i++)
            {
                cellInformations[i] = Convert.ToByte(Hash.GetHash(cellData[i]));
            }

            int   mapWidth   = map.Width;
            int   loc5       = cellId / ((mapWidth * 2) - 1);
            int   loc6       = cellId - (loc5 * ((mapWidth * 2) - 1));
            int   loc7       = loc6 % mapWidth;
            short interactiv = ((cellInformations[7] & 2) >> 1) != 0 ? Convert.ToInt16(((cellInformations[0] & 2) << 12) + ((cellInformations[7] & 1) << 12) + (cellInformations[8] << 6) + cellInformations[9]) : Convert.ToInt16(-1);

            MapCell cell = new MapCell()
            {
                Id                = cellId,
                Type              = (CellTypeEnum)((cellInformations[2] & 56) >> 3),
                IsActive          = (cellInformations[0] & 32) >> 5 != 0,
                IsInLineOfSight   = (cellInformations[0] & 1) != 1,
                InteractiveObject = interactiv,
                LayerObject2      = Convert.ToInt16(((cellInformations[0] & 2) << 12) + ((cellInformations[7] & 1) << 12) + (cellInformations[8] << 6) + cellInformations[9]),
                LayerObject1      = Convert.ToInt16(((cellInformations[0] & 4) << 11) + ((cellInformations[4] & 1) << 12) + (cellInformations[5] << 6) + cellInformations[6]),
                LayerGroundLevel  = Convert.ToByte(cellInformations[1] & 15),
                LayerGroundSlope  = Convert.ToByte((cellInformations[4] & 60) >> 2),
                X = (cellId - ((mapWidth - 1) * (loc5 - loc7))) / mapWidth,
                Y = loc5 - loc7
            };

            return(cell);
        }