/// <inheritdoc/> public void EnsureMap(DbCharacter dbCharacter) { if (Maps.ContainsKey(dbCharacter.Map)) // All fine, map is presented on server. { return; } // Map was completely deleted from the server. Fallback to map 0. if (!AvailableMapIds.Contains(dbCharacter.Map)) { var coordinates = Maps[0].GetNearestSpawn(0, 0, 0, dbCharacter.User.Faction == Fraction.Light ? CountryType.Light : CountryType.Dark); dbCharacter.Map = 0; dbCharacter.PosX = coordinates.X; dbCharacter.PosY = coordinates.Y; dbCharacter.PosZ = coordinates.Z; return; } // Map is an instance map. Likely for guild or party. Find out what is the rebirth map. if (!Maps.ContainsKey(dbCharacter.Map)) { var definition = _mapDefinitions.Maps.First(m => m.Id == dbCharacter.Map); if (definition.RebirthMap != null) // Rebirth map for both factions set. { dbCharacter.Map = definition.RebirthMap.MapId; dbCharacter.PosX = definition.RebirthMap.PosX; dbCharacter.PosY = definition.RebirthMap.PosY; dbCharacter.PosZ = definition.RebirthMap.PosZ; return; } if (dbCharacter.User.Faction == Fraction.Light) { dbCharacter.Map = definition.LightRebirthMap.MapId; dbCharacter.PosX = definition.LightRebirthMap.PosX; dbCharacter.PosY = definition.LightRebirthMap.PosY; dbCharacter.PosZ = definition.LightRebirthMap.PosZ; return; } if (dbCharacter.User.Faction == Fraction.Dark) { dbCharacter.Map = definition.DarkRebirthMap.MapId; dbCharacter.PosX = definition.DarkRebirthMap.PosX; dbCharacter.PosY = definition.DarkRebirthMap.PosY; dbCharacter.PosZ = definition.DarkRebirthMap.PosZ; return; } } _logger.LogError("Couldn't ensure map {id} for player {characterId}! Check it manually!", dbCharacter.Map, dbCharacter.Id); }
/// <summary> /// Initializes maps with startup values like mobs, npc, areas, obelisks etc. /// </summary> private void InitMaps() { _mapDefinitions = _mapsLoader.LoadMapDefinitions(); foreach (var mapDefinition in _mapDefinitions.Maps) { var config = _mapsLoader.LoadMapConfiguration(mapDefinition.Id); if (mapDefinition.CreateType == CreateType.Default) { var map = _mapFactory.CreateMap(mapDefinition.Id, mapDefinition, config, _mapsLoader.GetObelisks(mapDefinition.Id)); map.GameWorld = this; if (Maps.TryAdd(mapDefinition.Id, map)) { _logger.LogInformation("Map {id} was successfully loaded.", map.Id); } } AvailableMapIds.Add(mapDefinition.Id); } }