Beispiel #1
0
        /// <inheritdoc />
        public async Task <Character> LoadPlayer(int characterId, WorldClient client)
        {
            using var database = DependencyContainer.Instance.Resolve <IDatabase>();
            var dbCharacter = await database.Characters.Include(c => c.Skills).ThenInclude(cs => cs.Skill)
                              .Include(c => c.Items).ThenInclude(ci => ci.Item)
                              .Include(c => c.ActiveBuffs).ThenInclude(cb => cb.Skill)
                              .Include(c => c.Friends).ThenInclude(cf => cf.Friend)
                              .Include(c => c.Quests)
                              .Include(c => c.QuickItems)
                              .Include(c => c.User)
                              .FirstOrDefaultAsync(c => c.Id == characterId);

            var newPlayer = Character.FromDbCharacter(dbCharacter,
                                                      DependencyContainer.Instance.Resolve <ILogger <Character> >(),
                                                      this,
                                                      _characterConfig,
                                                      _taskQueue,
                                                      _databasePreloader,
                                                      DependencyContainer.Instance.Resolve <IChatManager>(),
                                                      DependencyContainer.Instance.Resolve <ILinkingManager>(),
                                                      DependencyContainer.Instance.Resolve <IDyeingManager>());

            newPlayer.Client = client;

            Players.TryAdd(newPlayer.Id, newPlayer);
            TradeManagers.TryAdd(newPlayer.Id, new TradeManager(this, newPlayer));
            PartyManagers.TryAdd(newPlayer.Id, new PartyManager(this, newPlayer));
            DuelManagers.TryAdd(newPlayer.Id, new DuelManager(this, newPlayer));

            _logger.LogDebug($"Player {newPlayer.Id} connected to game world");
            newPlayer.Client.OnPacketArrived += Client_OnPacketArrived;

            return(newPlayer);
        }
Beispiel #2
0
        /// <inheritdoc />
        public async Task <Character> LoadPlayer(int characterId, WorldClient client)
        {
            var newPlayer = await _characterFactory.CreateCharacter(characterId, client);

            if (newPlayer is null)
            {
                return(null);
            }

            Players.TryAdd(newPlayer.Id, newPlayer);
            TradeManagers.TryAdd(newPlayer.Id, new TradeManager(this, newPlayer));
            PartyManagers.TryAdd(newPlayer.Id, new PartyManager(this, newPlayer));
            DuelManagers.TryAdd(newPlayer.Id, new DuelManager(this, newPlayer));

            _logger.LogDebug($"Player {newPlayer.Id} connected to game world");
            newPlayer.Client.OnPacketArrived += Client_OnPacketArrived;

            return(newPlayer);
        }