Example #1
0
        public async Task Handle(MovedEvent message, CancellationToken cancellationToken)
        {
            var player  = message.Player;
            var roomIn  = message.RoomIn;
            var roomOut = message.RoomOut;

            //更新玩家在线数据
            await _chatOnlineProvider.SetPlayerOnline(new PlayerOnlineModel
            {
                IsOnline   = true,
                LastDate   = DateTime.Now,
                Level      = player.Level,
                PlayerName = player.Name,
                PlayerId   = player.Id,
                RoomId     = player.RoomId,
                Gender     = player.Gender,
                Title      = player.Title
            });

            //更新玩家聊天房间
            await _mudProvider.RemoveFromRoom(player.Id, roomOut.Id);

            await _mudProvider.AddToRoom(player.Id, roomIn.Id);

            //更新新房间玩家列表
            var playersIn = await _chatOnlineProvider.GetPlayerList(roomIn.Id);

            await _mudProvider.UpdateRoomPlayerList(roomIn.Id, playersIn);

            //更新旧房间玩家列表
            var playersOut = await _chatOnlineProvider.GetPlayerList(roomOut.Id);

            await _mudProvider.UpdateRoomPlayerList(roomOut.Id, playersOut);


            var roomModel = _mapper.Map <RoomModel>(roomIn);

            await _mudProvider.Move(player.Id, roomModel);

            //更新当前玩家显示的npc列表
            var nps = (await _npcDomainService.GetAll()).Where(x => x.RoomId == roomIn.Id);
            await _mudProvider.UpdatePlayerRoomNpcList(player.Id, nps);


            //输出移动信息
            await _mudProvider.ShowMessage(player.Id, $"你来到了{roomIn.Name}。");

            await _mudProvider.ShowRoomOthersMessage(roomIn.Id, player.Id, $"[{player.Name}] 从{roomOut.Name}走了过来。");

            await _mudProvider.ShowRoomOthersMessage(roomOut.Id, player.Id, $"[{player.Name}] 往{roomIn.Name}离开。");
        }