Exemple #1
0
        public World(JSMap map, WorldDesc desc)
        {
            Map    = map;
            Width  = map.Width;
            Height = map.Height;

            Background    = desc.Background;
            ShowDisplays  = desc.ShowDisplays;
            AllowTeleport = desc.AllowTeleport;
            BlockSight    = desc.BlockSight;

            Name        = desc.Id;
            DisplayName = desc.DisplayName;

            Entities  = new Dictionary <int, Entity>();
            Quests    = new Dictionary <int, Entity>();
            Constants = new Dictionary <int, Entity>();
            Players   = new Dictionary <int, Player>();
            Statics   = new Dictionary <int, StaticObject>();

            EntityChunks = new ChunkController(Width, Height);
            PlayerChunks = new ChunkController(Width, Height);

            ChatMessages = new List <string>();

            Tiles = new Tile[Width, Height];

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    JSTile js   = map.Tiles[x, y];
                    Tile   tile = Tiles[x, y] = new Tile()
                    {
                        Type        = js.GroundType,
                        Region      = js.Region,
                        UpdateCount = int.MaxValue / 2
                    };

                    if (js.ObjectType != 0xff)
                    {
                        Entity entity = Entity.Resolve(js.ObjectType);
                        if (entity.Desc.Static)
                        {
                            if (entity.Desc.BlocksSight)
                            {
                                tile.BlocksSight = true;
                            }
                            tile.StaticObject = (StaticObject)entity;
                        }

                        AddEntity(entity, new Position(x + 0.5f, y + 0.5f));
                    }
                }
            }
            UpdateCount = int.MaxValue / 2;
        }
Exemple #2
0
        public JSMap(string data)
        {
            json_dat json = JsonConvert.DeserializeObject <json_dat>(data);

            byte[] buffer = ZlibStream.UncompressBuffer(json.data);
            Dictionary <ushort, JSTile> dict = new Dictionary <ushort, JSTile>();

            JSTile[,] tiles = new JSTile[json.width, json.height];

            for (int i = 0; i < json.dict.Length; i++)
            {
                loc o = json.dict[i];
                dict[(ushort)i] = new JSTile
                {
                    GroundType = o.ground == null ? (ushort)255 : Resources.Id2Tile[o.ground].Type,
                    ObjectType = o.objs == null ? (ushort)255 : Resources.Id2Object[o.objs[0].id].Type,
                    Key        = o.objs == null ? null : o.objs[0].name,
                    Region     = o.regions == null ? Region.None : (Region)Enum.Parse(typeof(Region), o.regions[0].id.Replace(' ', '_'))
                };
            }

            using (PacketReader rdr = new PacketReader(new MemoryStream(buffer)))
            {
                for (int y = 0; y < json.height; y++)
                {
                    for (int x = 0; x < json.width; x++)
                    {
                        tiles[x, y] = dict[(ushort)rdr.ReadInt16()];
                    }
                }
            }

            //Add composite under cave walls
            for (int x = 0; x < json.width; x++)
            {
                for (int y = 0; y < json.height; y++)
                {
                    if (tiles[x, y].ObjectType != 255)
                    {
                        ObjectDesc desc = Resources.Type2Object[tiles[x, y].ObjectType];
                        if ((desc.CaveWall || desc.ConnectedWall) && tiles[x, y].GroundType == 255)
                        {
                            tiles[x, y].GroundType = 0xfd;
                        }
                    }
                }
            }

            Tiles  = tiles;
            Width  = json.width;
            Height = json.height;

            InitRegions();
        }
Exemple #3
0
 public void InitRegions()
 {
     Regions = new Dictionary <Region, List <IntPoint> >();
     for (int x = 0; x < Width; x++)
     {
         for (int y = 0; y < Height; y++)
         {
             JSTile tile = Tiles[x, y];
             if (!Regions.ContainsKey(tile.Region))
             {
                 Regions[tile.Region] = new List <IntPoint>();
             }
             Regions[tile.Region].Add(new IntPoint(x, y));
         }
     }
 }