예제 #1
0
        /// <inheritdoc />
        public void LoadPlayerInMap(int characterId)
        {
            var player = Players[characterId];

            if (Maps.ContainsKey(player.MapId))
            {
                Maps[player.MapId].LoadPlayer(player);
            }
            else
            {
                var mapDef = _mapDefinitions.Maps.FirstOrDefault(d => d.Id == player.MapId);

                // Map is not found.
                if (mapDef is null)
                {
                    _logger.LogWarning($"Unknown map {player.MapId} for character {player.Id}. Fallback to 0 map.");
                    var town = Maps[0].GetNearestSpawn(player.PosX, player.PosY, player.PosZ, player.Country);
                    player.Teleport(0, town.X, town.Y, town.Z);
                    return;
                }

                if (mapDef.CreateType == CreateType.Party)
                {
                    IPartyMap map;
                    Guid      partyId;

                    if (player.Party is null)
                    // This is very uncommon, but if:
                    // * player is an admin he can load into map even without party.
                    // * player entered portal, while being in party, but while he was loading, all party members left.
                    {
                        partyId = player.PreviousPartyId;
                    }
                    else
                    {
                        partyId = player.Party.Id;
                    }

                    PartyMaps.TryGetValue(partyId, out map);
                    if (map is null)
                    {
                        map = _mapFactory.CreatePartyMap(mapDef.Id, mapDef, _mapsLoader.LoadMapConfiguration(mapDef.Id), player.Party);
                        map.OnAllMembersLeft += PartyMap_OnAllMembersLeft;
                        PartyMaps.TryAdd(partyId, map);
                    }

                    map.LoadPlayer(player);
                }
            }
        }