Esempio n. 1
0
 public override void TileEvent(Player player, WmapTile tile)
 {
     switch (tile.Region)
     {
         case TileRegion.Hallway:
             if (!Connecting)
             {
                 player.Client.Reconnect(new ReconnectPacket
                 {
                     Host = "",
                     Port = 2050,
                     Name = "The Shop",
                     GameId = SHOP_ID,
                     Key = Empty<byte>.Array
                 });
                 Connecting = true;
             }
             break;
         case TileRegion.Hallway_1:
             if((player.Party != null && player.Party.Leader == player) || player.Party == null)
             {
                 World tower = Manager.AddWorld(new Tower(1));
                 player.Client.Reconnect(new ReconnectPacket
                 {
                     Host = "",
                     Port = 2050,
                     Name = tower.Name,
                     GameId = tower.Id,
                     Key = Empty<byte>.Array
                 });
             };
             break;
         default:
             break;
     }
 }
Esempio n. 2
0
        int LoadV2(BinaryReader reader, int idBase)
        {
            List<WmapTile> dict = new List<WmapTile>();
            short c = reader.ReadInt16();
            for (short i = 0; i < c; i++)
            {
                WmapTile tile = new WmapTile();
                tile.TileId = (byte)reader.ReadInt16();
                string obj = reader.ReadString();
                tile.ObjType = string.IsNullOrEmpty(obj) ? (short)0 : XmlDatas.IdToType[obj];
                tile.Name = reader.ReadString();
                tile.Terrain = (WmapTerrain)reader.ReadByte();
                tile.Region = (TileRegion)reader.ReadByte();
                dict.Add(tile);
            }
            Width = reader.ReadInt32();
            Height = reader.ReadInt32();
            tiles = new WmapTile[Width, Height];
            int enCount = 0;
            List<Tuple<IntPoint, short, string>> entities = new List<Tuple<IntPoint, short, string>>();
            for (int y = 0; y < Height; y++)
                for (int x = 0; x < Width; x++)
                {
                    WmapTile tile = dict[reader.ReadInt16()];
                    tile.UpdateCount = 1;
                    tile.Elevation = reader.ReadByte();

                    ObjectDesc desc;
                    if (tile.ObjType != 0 &&
                        (!XmlDatas.ObjectDescs.TryGetValue(tile.ObjType, out desc) ||
                        !desc.Static || desc.Enemy))
                    {
                        entities.Add(new Tuple<IntPoint, short, string>(new IntPoint(x, y), tile.ObjType, tile.Name));
                        tile.ObjType = 0;
                    }

                    if (tile.ObjType != 0)
                    {
                        enCount++;
                        tile.ObjId = idBase + enCount;
                    }

                    tiles[x, y] = tile;
                }
            this.entities = entities.ToArray();
            return enCount;
        }
Esempio n. 3
0
        public int Load(DungeonTile[,] tiles, int idBase)
        {
            Width  = tiles.GetLength(0);
            Height = tiles.GetLength(1);

            var wTiles = new WmapDesc[Width, Height];

            for (var i = 0; i < Width; i++)
            {
                for (var j = 0; j < Height; j++)
                {
                    var dTile = tiles[i, j];

                    var wTile = new WmapDesc();
                    wTile.TileId   = _dat.IdToTileType[dTile.TileType.Name];
                    wTile.TileDesc = _dat.Tiles[wTile.TileId];
                    wTile.Terrain  = TerrainType.None;
                    wTile.Region   = (dTile.Region == null) ?
                                     TileRegion.None :
                                     (TileRegion)Enum.Parse(typeof(TileRegion), dTile.Region);
                    if (dTile.Object != null)
                    {
                        wTile.ObjType = _dat.IdToObjectType[dTile.Object.ObjectType.Name];
                        wTile.ObjCfg  = dTile.Object.ToString();
                        _dat.ObjectDescs.TryGetValue(wTile.ObjType, out wTile.ObjDesc);
                    }

                    wTiles[i, j] = wTile;
                }
            }

            _tiles = new WmapTile[Width, Height];

            var enCount  = 0;
            var entities = new List <Tuple <IntPoint, ushort, string> >();

            for (var y = 0; y < Height; y++)
            {
                for (var x = 0; x < Width; x++)
                {
                    var tile = new WmapTile(wTiles[x, y]);

                    if (tile.Region != 0)
                    {
                        Regions.Add(new IntPoint(x, y), tile.Region);
                    }

                    var desc = tile.ObjDesc;
                    if (tile.ObjType != 0 && (desc == null || !desc.Static || desc.Enemy))
                    {
                        entities.Add(new Tuple <IntPoint, ushort, string>(new IntPoint(x, y), tile.ObjType, tile.ObjCfg));
                        if (desc == null || !(desc.Enemy && desc.Static))
                        {
                            tile.ObjType = 0;
                        }
                    }

                    if (tile.ObjType != 0 && (desc == null || !(desc.Enemy && desc.Static)))
                    {
                        enCount++;
                        tile.ObjId = idBase + enCount;
                    }

                    _tiles[x, y] = tile;
                }
            }

            for (var x = 0; x < Width; x++)
            {
                for (var y = 0; y < Height; y++)
                {
                    _tiles[x, y].InitConnection(this, x, y);
                }
            }

            _entities = entities.ToArray();
            return(enCount);
        }
Esempio n. 4
0
        public int Load(Stream stream, int idBase)
        {
            var ver = stream.ReadByte();

            if (ver < 0 || ver > 2)
            {
                throw new NotSupportedException("WMap version " + ver);
            }

            using (var rdr = new BinaryReader(new ZlibStream(stream, CompressionMode.Decompress)))
            {
                var dict = new List <WmapDesc>();
                var c    = rdr.ReadInt16();
                for (var i = 0; i < c; i++)
                {
                    var desc = new WmapDesc();
                    desc.TileId   = rdr.ReadUInt16();
                    desc.TileDesc = _dat.Tiles[desc.TileId];
                    var obj = rdr.ReadString();
                    desc.ObjType = 0;
                    if (_dat.IdToObjectType.ContainsKey(obj))
                    {
                        desc.ObjType = _dat.IdToObjectType[obj];
                    }
                    else if (!string.IsNullOrEmpty(obj))
                    {
                        Log.Warn($"Object: {obj} not found.");
                    }
                    desc.ObjCfg  = rdr.ReadString();
                    desc.Terrain = (TerrainType)rdr.ReadByte();
                    desc.Region  = (TileRegion)rdr.ReadByte();
                    if (ver == 1)
                    {
                        desc.Elevation = rdr.ReadByte();
                    }
                    _dat.ObjectDescs.TryGetValue(desc.ObjType, out desc.ObjDesc);
                    dict.Add(desc);
                }

                Width  = rdr.ReadInt32();
                Height = rdr.ReadInt32();
                _tiles = new WmapTile[Width, Height];

                var enCount  = 0;
                var entities = new List <Tuple <IntPoint, ushort, string> >();
                for (var y = 0; y < Height; y++)
                {
                    for (var x = 0; x < Width; x++)
                    {
                        var tile = new WmapTile(dict[rdr.ReadInt16()]);
                        if (ver == 2)
                        {
                            tile.Elevation = rdr.ReadByte();
                        }

                        if (tile.Region != 0)
                        {
                            Regions.Add(new IntPoint(x, y), tile.Region);
                        }

                        var desc = tile.ObjDesc;
                        if (tile.ObjType != 0 && (desc == null || !desc.Static || desc.Enemy))
                        {
                            entities.Add(new Tuple <IntPoint, ushort, string>(new IntPoint(x, y), tile.ObjType, tile.ObjCfg));
                            if (desc == null || !(desc.Enemy && desc.Static))
                            {
                                tile.ObjType = 0;
                            }
                        }

                        if (tile.ObjType != 0 && (desc == null || !(desc.Enemy && desc.Static)))
                        {
                            enCount++;
                            tile.ObjId = idBase + enCount;
                        }

                        _tiles[x, y] = tile;
                    }
                }

                for (var x = 0; x < Width; x++)
                {
                    for (var y = 0; y < Height; y++)
                    {
                        _tiles[x, y].InitConnection(this, x, y);
                    }
                }

                _entities = entities.ToArray();
                return(enCount);
            }
        }