Beispiel #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;
        }
Beispiel #2
0
        public void MoveEntity(Entity en, Position to)
        {
#if DEBUG
            if (en == null)
            {
                throw new Exception("Undefined entity.");
            }
#endif
            if (en.Position != to)
            {
                en.Position = to;
                en.UpdateCount++;

                if (en is StaticObject)
                {
                    return;
                }

                ChunkController controller = (en is Player || en is Decoy)
                    ? PlayerChunks : EntityChunks;
                controller.Insert(en);
            }
        }