Esempio n. 1
0
        public async Task <Unit> Handle(ShowFriendCommand command, CancellationToken cancellationToken)
        {
            var playerId = command.PlayerId;

            var player = await _playerDomainService.Get(playerId);

            if (player == null)
            {
                await _bus.RaiseEvent(new DomainNotification($"角色不存在!"));

                return(Unit.Value);
            }

            var playerRelationQuery = await _playerRelationDomainService.GetAll();

            //我加了别人的
            var requestIds = playerRelationQuery.Where(x => x.PlayerId == playerId && x.Type == PlayerRelationTypeEnum.好友).Select(x => x.RelationId).ToList();

            //别人加了我的
            var friendToMeIds = playerRelationQuery.Where(x => x.RelationId == playerId && x.Type == PlayerRelationTypeEnum.好友).Select(x => x.PlayerId).ToList();

            //互相加了的
            var friendIds = requestIds.Intersect(friendToMeIds).ToList();

            requestIds    = requestIds.Except(friendIds).ToList();
            friendToMeIds = friendToMeIds.Except(friendIds).ToList();

            var playerQuery = await _playerDomainService.GetAll();

            var players     = playerQuery.Where(x => friendIds.Contains(x.Id)).ToList();
            var requests    = playerQuery.Where(x => requestIds.Contains(x.Id)).ToList();
            var friendToMes = playerQuery.Where(x => friendToMeIds.Contains(x.Id)).ToList();

            await _mudProvider.ShowFriend(playerId, new MyFriendModel
            {
                Friends   = _mapper.Map <List <PlayerBaseInfo> >(players),
                Requests  = _mapper.Map <List <PlayerBaseInfo> >(requests),
                FriendMes = _mapper.Map <List <PlayerBaseInfo> >(friendToMes)
            });



            return(Unit.Value);
        }