Exemplo n.º 1
0
        private int LoadV2(BinaryReader reader, int idBase)
        {
            var dict = new List<WmapTile>();
            var c = reader.ReadInt16();
            for (short i = 0; i < c; i++)
            {
                var tile = new WmapTile();
                tile.TileId = (byte)reader.ReadInt16();
                var obj = reader.ReadString();
                tile.ObjType = string.IsNullOrEmpty(obj) ? (short)0 : XmlData.IdToObjectType[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];
            var enCount = 0;
            var entities = new List<Tuple<IntPoint, short, string>>();
            for (var y = 0; y < Height; y++)
                for (var x = 0; x < Width; x++)
                {
                    var tile = dict[reader.ReadInt16()];
                    tile.UpdateCount = 1;
                    tile.Elevation = reader.ReadByte();

                    ObjectDesc desc;
                    if (tile.ObjType != 0 &&
                        (!XmlData.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;
        }
Exemplo n.º 2
0
 private static bool IsBlocking(WmapTile tile)
 {
     return(tile.ObjType != 0 &&
            tile.ObjDesc != null &&
            tile.ObjDesc.BlocksSight);
 }
Exemplo n.º 3
0
        public static bool GenRandomRoom(World world, float x, float y, Wall theWall)
        {
            try
            {
                Random rand = new Random();
                if (rand.Next(1, 60) != 1)
                {
                    return(false);
                }
                //Console.Out.WriteLine("Generating room...");
                List <string> dirs = new List <string>();
                for (int tx = -1; tx <= 1; tx++)
                {
                    for (int ty = -1; ty <= 1; ty++)
                    {
                        WmapTile targetTile = world.Map[(int)x + tx, (int)y + ty];
                        WmapTile thisTile   = world.Map[(int)x, (int)y];
                        if (targetTile.TileId == 0xff)
                        {
                            if (tx == -1 && ty == 0)
                            {
                                dirs.Add("left");
                            }
                            else if (tx == 1 && ty == 0)
                            {
                                dirs.Add("right");
                            }
                            else if (tx == 0 && ty == 1)
                            {
                                dirs.Add("down");
                            }
                            else if (tx == 0 && ty == -1)
                            {
                                dirs.Add("up");
                            }
                        }
                    }
                }
                if (dirs.Count < 1)
                {
                    return(false);
                }
                dirs.Shuffle();
                //Console.Out.WriteLine("Room direction: " + dirs.First());
                float mainX     = x;
                float mainY     = y;
                float entranceX = x;
                float entranceY = y;
                switch (dirs.First())
                {
                case "up":
                    mainX     = x - 6; mainY = y - 8;
                    entranceY = y - 1; break;

                case "down":
                    mainX     = x - 6; mainY = y + 1;
                    entranceY = y + 1; break;

                case "left":
                    mainX     = x - 12; mainY = y - 3;
                    entranceX = x - 1; break;

                case "right":
                    mainX     = x + 1; mainY = y - 3;
                    entranceX = x + 1; break;
                }
                List <WmapTile> addedTiles = new List <WmapTile>();
                for (int ty = (int)mainY; ty <= mainY + 7; ty++)
                {
                    for (int tx = (int)mainX; tx <= mainX + 11; tx++)
                    {
                        WmapTile tTile = world.Map[tx, ty];
                        if (tTile.TileId != 0xff || tTile.ObjType != 0)
                        {
                            //Console.Out.WriteLine("Found collision while generating room!");
                            return(false);
                        }
                        tTile.TileId = world.Map[(int)x, (int)y].TileId;
                        addedTiles.Add(tTile);
                    }
                }
                //Console.Out.WriteLine("Generated tiles, placing...");
                int tileNum = 0;
                for (int ty = (int)mainY; ty <= mainY + 7; ty++)
                {
                    for (int tx = (int)mainX; tx <= mainX + 11; tx++)
                    {
                        WmapTile ctile = addedTiles[tileNum];
                        if ((tx == (int)mainX || tx == (int)mainX + 11 || ty == (int)mainY || ty == (int)mainY + 7) && !(tx == entranceX && ty == entranceY))
                        {
                            //Console.Out.WriteLine("Placed wall");
                            Wall e = new Wall(theWall.ObjectType, XmlDatas.TypeToElement[theWall.ObjectType]);
                            e.Move(tx, ty);
                            world.EnterWorld(e);
                            ctile.ObjType = theWall.ObjectType;
                        }
                        else
                        {
                            //Console.Out.WriteLine("Placed treasure");
                            if (rand.Next(1, 30) == 1)
                            {
                                Entity e = Entity.Resolve(XmlDatas.IdToType["Coral Gift"]);
                                e.Move(tx + 0.5f, ty + 0.5f);
                                world.EnterWorld(e);
                                ctile.ObjType = XmlDatas.IdToType["Coral Gift"];
                            }
                        }
                        world.Map[tx, ty] = ctile;
                    }
                }
                //Console.Out.WriteLine("Placed tiles!");
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Exemplo n.º 4
0
        public static bool GenRandomRoom(World world, float x, float y, Wall theWall)
        {
            try
            {
                Random rand = new Random();
                if (rand.Next(1, 60) != 1)
                {
                    return(false);
                }
                //Console.Out.WriteLine("Generating room...");
                List <string> dirs = new List <string>();
                for (int tx = -1; tx <= 1; tx++)
                {
                    for (int ty = -1; ty <= 1; ty++)
                    {
                        WmapTile targetTile = world.Map[(int)x + tx, (int)y + ty];
                        WmapTile thisTile   = world.Map[(int)x, (int)y];
                        if (targetTile.TileId == 0xff)
                        {
                            if (tx == -1 && ty == 0)
                            {
                                dirs.Add("left");
                            }
                            else if (tx == 1 && ty == 0)
                            {
                                dirs.Add("right");
                            }
                            else if (tx == 0 && ty == 1)
                            {
                                dirs.Add("down");
                            }
                            else if (tx == 0 && ty == -1)
                            {
                                dirs.Add("up");
                            }
                        }
                    }
                }
                if (dirs.Count < 1)
                {
                    return(false);
                }
                dirs.Shuffle();
                //Console.Out.WriteLine("Room direction: " + dirs.First());
                float mainX     = x;
                float mainY     = y;
                float entranceX = x;
                float entranceY = y;

                int rsX = 1;
                int rsY = 1;
                do
                {
                    rsX = rand.Next(6, 12 + 1);
                }while (rsX % 2 > 0);

                do
                {
                    rsY = rand.Next(6, 12 + 1);
                }while (rsY % 2 > 0);

                //Console.Out.WriteLine("Room size: " + rsX + ", " + rsY);

                switch (dirs.First())
                {
                case "up":
                    mainX     = x - (rsX / 2); mainY = y - rsY;
                    entranceY = y - 1; break;

                case "down":
                    mainX     = x - (rsX / 2); mainY = y + 1;
                    entranceY = y + 1; break;

                case "left":
                    mainX     = x - rsX; mainY = y - ((rsY - 2) / 2);
                    entranceX = x - 1; break;

                case "right":
                    mainX     = x + 1; mainY = y - ((rsY - 2) / 2);
                    entranceX = x + 1; break;
                }
                entranceX -= 0.5f;
                entranceY -= 0.5f;
                List <WmapTile> addedTiles = new List <WmapTile>();
                for (int ty = (int)mainY; ty <= mainY + (rsY - 1); ty++)
                {
                    for (int tx = (int)mainX; tx <= mainX + (rsX - 1); tx++)
                    {
                        WmapTile tTile = world.Map[tx, ty];
                        if (tTile.TileId != 0xff || tTile.ObjType != 0)
                        {
                            Console.Out.WriteLine("Found collision while generating room!");
                            return(false);
                        }
                        tTile.TileId = world.Map[(int)x, (int)y].TileId;
                        addedTiles.Add(tTile);
                    }
                }
                //Console.Out.WriteLine("Generated tiles, placing...");
                int   tileNum       = 0;
                float blackPotSpotX = (float)rand.Next((int)mainX + 1, (int)mainX + rsX);
                float blackPotSpotY = (float)rand.Next((int)mainY + 1, (int)mainY + rsY);
                for (int ty = (int)mainY; ty <= mainY + (rsY - 1); ty++)
                {
                    for (int tx = (int)mainX; tx <= mainX + (rsX - 1); tx++)
                    {
                        WmapTile ctile = addedTiles[tileNum];
                        world.Map[tx, ty] = ctile;
                        if ((tx == (int)mainX || tx == (int)mainX + (rsX - 1) || ty == (int)mainY || ty == (int)mainY + (rsY - 1)) && !(tx == entranceX && ty == entranceY))
                        {
                            //Console.Out.WriteLine(tx + ", " + ty + " - " + entranceX + ", " + entranceY);
                            //Console.Out.WriteLine("Placed wall");
                            GenWall(world, tx + 0.5f, ty + 0.5f, rand);
                        }
                        else
                        {
                            //Console.Out.WriteLine("Placed treasure");
                            if (rand.Next(1, 25) == 1)
                            {
                                if ((world as Mine).RoomsFound == 3 ? (tx != blackPotSpotX && ty != blackPotSpotY) : true)
                                {
                                    Entity e = Entity.Resolve((short)rand.Next(0x196f, 0x1972));
                                    e.Move(tx + 0.5f, ty + 0.5f);
                                    world.EnterWorld(e);
                                }
                            }
                        }
                    }
                }
                (world as Mine).RoomsFound++;
                if ((world as Mine).RoomsFound == 4)
                {
                    Entity e = Entity.Resolve(XmlDatas.IdToType["Pot of Descent"]);
                    e.Move(blackPotSpotX + 0.5f, blackPotSpotY + 0.5f);
                    world.EnterWorld(e);
                }
                //Console.Out.WriteLine("Placed tiles!");
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Exemplo n.º 5
0
 public virtual void TileEvent(Player player, WmapTile tile)
 {
 }
Exemplo n.º 6
0
        private int LoadV2(BinaryReader reader, int idBase)
        {
            List<WmapTile> dict = new List<WmapTile>();
            ushort c = (ushort)reader.ReadInt16();
            for (ushort i = 0; i < c; i++)
            {
                WmapTile tile = new WmapTile();
                tile.TileId = (ushort)reader.ReadInt16();
                string obj = reader.ReadString();
                try
                {
                    tile.ObjType = string.IsNullOrEmpty(obj) ? (ushort)0 : data.IdToObjectType[obj];
                }
                catch (Exception ex) { log.Error(ex); }
                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, ushort, string>> entities = new List<Tuple<IntPoint, ushort, 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 &&
                        (!data.ObjectDescs.TryGetValue(tile.ObjType, out desc) || isGuildMerchant(tile.ObjType) ||
                         !desc.Static || desc.Enemy))
                    {
                        entities.Add(new Tuple<IntPoint, ushort, 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;
        }
Exemplo n.º 7
0
        public int Load(Stream stream, int idBase)
        {
            List<WmapTile> dict = new List<WmapTile>();
            using (BinaryReader rdr = new BinaryReader(new ZlibStream(stream, CompressionMode.Decompress)))
            {
                short c = rdr.ReadInt16();
                for (short i = 0; i < c; i++)
                {
                    WmapTile tile = new WmapTile();
                    tile.TileId = (byte)rdr.ReadInt16();
                    string obj = rdr.ReadString();
                    tile.ObjType = string.IsNullOrEmpty(obj) ? (short)0 : XmlDatas.IdToType[obj];
                    tile.Name = rdr.ReadString();
                    tile.Terrain = (WmapTerrain)rdr.ReadByte();
                    tile.Region = (TileRegion)rdr.ReadByte();
                    dict.Add(tile);
                }
                Width = rdr.ReadInt32();
                Height = rdr.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[rdr.ReadInt16()];
                        tile.UpdateCount = 1;

                        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;
            }
        }
Exemplo n.º 8
0
 public virtual void LeaveWorld(Entity entity)
 {
     if (!(entity is Pet || entity is Portal))
     {
         if (entity is Wall && entity.ObjectDesc != null && entity.ObjectDesc.FullOccupy || entity.ObjectDesc.OccupySquare || entity.ObjectDesc.EnemyOccupySquare)
         {
             WmapTile tile = Map[(int)entity.X, (int)entity.Y].Clone();
             tile.TileId     = Map[(int)entity.X, (int)entity.Y].TileId;
             tile.ObjType    = 0;
             tile.ObjectDesc = null;
             Map[(int)entity.X, (int)entity.Y] = tile;
         }
     }
     if (entity is Player)
     {
         Player dummy;
         if (!Players.TryRemove(entity.Id, out dummy))
         {
             Console.WriteLine("Could not remove {0} from world {1}", entity.Name, Name);
         }
         PlayersCollision.Remove(entity);
     }
     else if (entity is Enemy)
     {
         Enemy dummy;
         Enemies.TryRemove(entity.Id, out dummy);
         EnemiesCollision.Remove(entity);
         if (entity.ObjectDesc.Quest)
         {
             Quests.TryRemove(entity.Id, out dummy);
         }
     }
     else
     {
         var projectile = entity as Projectile;
         if (projectile != null)
         {
             var p = projectile;
             Projectiles.TryRemove(new Tuple <int, byte>(p.ProjectileOwner.Self.Id, p.ProjectileId), out p);
         }
         else if (entity is StaticObject)
         {
             StaticObject dummy;
             StaticObjects.TryRemove(entity.Id, out dummy);
             if (entity is Decoy)
             {
                 PlayersCollision.Remove(entity);
             }
             else
             {
                 EnemiesCollision.Remove(entity);
             }
         }
         else if (entity is Pet)
         {
             if (entity.IsPet)
             {
                 Pet dummy2;
                 Pets.TryRemove(entity.Id, out dummy2);
                 PlayersCollision.Remove(entity);
             }
         }
     }
     entity.Owner = null;
     entity.Dispose();
 }