Пример #1
0
        public GuiWindow(Map map, byte gridsize, int width, int height, GraphicsMode mode, string title, DataAccessHelper dbContextBuilder) : base(
                width * gridsize, height * gridsize, mode, title)
        {
            _dbContextBuilder = dbContextBuilder;
            _mapMonsterDao    = new Dao <MapMonster, MapMonsterDto, int>(_logger, _dbContextBuilder);
            _mapNpcDao        = new Dao <MapNpc, MapNpcDto, int>(_logger, _dbContextBuilder);
            _npcMonsterDao    = new Dao <NpcMonster, NpcMonsterDto, short>(_logger, _dbContextBuilder);
            _originalWidth    = width * gridsize;
            _originalHeight   = height * gridsize;
            _map       = map;
            _gridsizeX = gridsize;
            _gridsizeY = gridsize;
            _gridsize  = gridsize;
            _monsters  = _mapMonsterDao.Where(s => s.MapId == map.MapId)
                         ?.Adapt <List <GameObject.MapMonster> >() ?? new List <GameObject.MapMonster>();
            var npcMonsters = _npcMonsterDao.LoadAll().ToList();

            using var mapInstance =
                      new MapInstance(map, new Guid(), false, MapInstanceType.BaseMapInstance,
                                      new MapItemProvider(new List <IEventHandler <MapItem, Tuple <MapItem, GetPacket> > >()),
                                      _logger, new List <IMapInstanceEventHandler>())
                  {
                      IsSleeping = false
                  };
            foreach (var mapMonster in _monsters)
            {
                mapMonster.PositionX     = mapMonster.MapX;
                mapMonster.PositionY     = mapMonster.MapY;
                mapMonster.MapInstance   = mapInstance;
                mapMonster.MapInstanceId = mapInstance.MapInstanceId;
                mapMonster.Mp            = 100;
                mapMonster.Hp            = 100;
                mapMonster.Speed         = npcMonsters.Find(s => s.NpcMonsterVNum == mapMonster.MapId)?.Speed ?? 0;
                mapMonster.IsAlive       = true;
            }

            _npcs = _mapNpcDao.Where(s => s.MapId == map.MapId)?.Adapt <List <GameObject.MapNpc> >() ?? new List <GameObject.MapNpc>();
            foreach (var mapNpc in _npcs)
            {
                mapNpc.PositionX     = mapNpc.MapX;
                mapNpc.PositionY     = mapNpc.MapY;
                mapNpc.MapInstance   = mapInstance;
                mapNpc.MapInstanceId = mapInstance.MapInstanceId;
                mapNpc.Mp            = 100;
                mapNpc.Hp            = 100;
                mapNpc.Speed         = npcMonsters.Find(s => s.NpcMonsterVNum == mapNpc.MapId)?.Speed ?? 0;
                mapNpc.IsAlive       = true;
            }

            Parallel.ForEach(_monsters.Where(s => s.Life == null), monster => monster.StartLifeAsync());
            Parallel.ForEach(_npcs.Where(s => s.Life == null), npc => npc.StartLifeAsync());
            GetMap();
        }
Пример #2
0
        public GuiWindow(Map map, byte gridsize, int width, int height, GraphicsMode mode, string title) : base(
                width * gridsize, height * gridsize, mode, title)
        {
            _originalWidth  = width * gridsize;
            _originalHeight = height * gridsize;
            _map            = map;
            _gridsizeX      = gridsize;
            _gridsizeY      = gridsize;
            _gridsize       = gridsize;
            _monsters       = DAOFactory.MapMonsterDAO.Where(s => s.MapId == map.MapId).Cast <MapMonster>().ToList();
            _npcMonsters    = DAOFactory.NpcMonsterDAO.LoadAll().ToList();
            var mapInstance = new MapInstance(map, new Guid(), false, MapInstanceType.BaseMapInstance);

            mapInstance.IsSleeping = false;
            foreach (var mapMonster in _monsters)
            {
                mapMonster.PositionX     = mapMonster.MapX;
                mapMonster.PositionY     = mapMonster.MapY;
                mapMonster.MapInstance   = mapInstance;
                mapMonster.MapInstanceId = mapInstance.MapInstanceId;
                mapMonster.Mp            = 100;
                mapMonster.Hp            = 100;
                mapMonster.Speed         = _npcMonsters.FirstOrDefault(s => s.NpcMonsterVNum == mapMonster.MapId)?.Speed ?? 0;
                mapMonster.IsAlive       = true;
            }
            _npcs = DAOFactory.MapNpcDAO.Where(s => s.MapId == map.MapId).Cast <MapNpc>().ToList();
            foreach (var mapNpc in _npcs)
            {
                mapNpc.PositionX     = mapNpc.MapX;
                mapNpc.PositionY     = mapNpc.MapY;
                mapNpc.MapInstance   = mapInstance;
                mapNpc.MapInstanceId = mapInstance.MapInstanceId;
                mapNpc.Mp            = 100;
                mapNpc.Hp            = 100;
                mapNpc.Speed         = _npcMonsters.FirstOrDefault(s => s.NpcMonsterVNum == mapNpc.MapId)?.Speed ?? 0;
                mapNpc.IsAlive       = true;
            }
            Parallel.ForEach(_monsters.Where(s => s.Life == null), monster => monster.StartLife());
            Parallel.ForEach(_npcs.Where(s => s.Life == null), npc => npc.StartLife());
            GetMap();
        }