示例#1
0
        public int LoadMap(MapDto map)
        {
            // Map = null -> exception;
            if (map == null)
            {
                throw new MapHandlerLoadingException($"Can't load map with value \"null\".");
            }

            // Get map objects
            List <MapObjectDto> mapObjects = new List <MapObjectDto>();

            using (MapContext mapContext = MapRepository.GetMapContext())
            {
                mapObjects.AddRange(mapContext.MapObjects.Where(dto => dto.MapId == map.MapId));
            }

            // Create map objects in real world
            int loadedObjects = 0;

            foreach (MapObjectDto mapObject in mapObjects)
            {
                mapObject.Object =
                    _api.createObject(mapObject.Hash, mapObject.Position, mapObject.Rotation, map.Dimension);
                loadedObjects++;
            }

            _loadedMapObjects.AddRange(mapObjects);
            return(loadedObjects);
        }
示例#2
0
        public MapDto CreateAndSaveNewMap(string mapName, int dimension, List <MapObjectDto> mapObjects,
                                          bool active = true)
        {
            MapDto newMap;

            using (MapContext mapContext = MapRepository.GetMapContext())
            {
                // Add new map.
                newMap = mapContext.Maps.Add(new MapDto
                {
                    Dimension = dimension,
                    Name      = mapName,
                    Active    = active
                });

                // Save map.
                mapContext.SaveChanges();

                // Add new map objects.
                mapObjects.ForEach(dto =>
                {
                    dto.MapId = newMap.MapId;
                    dto.Map   = newMap;
                    mapContext.MapObjects.Add(dto);
                });

                // Save map objects.
                mapContext.SaveChanges();
            }

            return(newMap);
        }
示例#3
0
 private void OnAfterCoreStartupCompleted()
 {
     using (MapContext mapContext = MapRepository.GetMapContext())
     {
         foreach (MapDto mapDto in mapContext.Maps.Where(dto => dto.Active))
         {
             LoadMap(mapDto);
             ConsoleOutput.WriteLine(ConsoleType.Note, $"Map {mapDto.Name} loaded.");
         }
     }
 }
示例#4
0
        public int LoadMap(int mapId)
        {
            using (MapContext mapContext = MapRepository.GetMapContext())
            {
                MapDto map = mapContext.Maps.FirstOrDefault(dto => dto.MapId == mapId);
                if (map == null)
                {
                    throw new MapHandlerLoadingException($"There is no map with id \"{mapId}\".");
                }

                return(LoadMap(map));
            }
        }