Exemple #1
0
        public async Task <Unit> Handle(InitGameCommand command, CancellationToken cancellationToken)
        {
            _logger.LogDebug($"Handle InitGameCommand:{JsonConvert.SerializeObject(command)}");

            var playerId = command.PlayerId;

            if (playerId <= 0)
            {
                await _bus.RaiseEvent(new DomainNotification($"请重新进入!"));

                return(Unit.Value);
            }

            var player = await _playerDomainService.Get(playerId);

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

                return(Unit.Value);
            }

            var room = await _roomDomainService.Get(player.RoomId);

            if (room == null)
            {
                await _bus.RaiseEvent(new DomainNotification("房间不存在!"));

                return(Unit.Value);
            }

            player.LastDate = DateTime.Now;


            await _cache.GetOrCreateAsync(CacheKey.IsActivityIn24Hours, async x => {
                x.AbsoluteExpiration = DateTime.UtcNow.AddHours(24);
                Random random        = new Random();
                player.Kar           = random.Next(1, 100);
                return(await Task.FromResult(true));
            });

            player.Computed();


            await _playerDomainService.Update(player);



            if (await Commit())
            {
                await _bus.RaiseEvent(new InitGameEvent(player)).ConfigureAwait(false);

                await _bus.RaiseEvent(new PlayerInRoomEvent(player, room)).ConfigureAwait(false);
            }


            return(Unit.Value);
        }
Exemple #2
0
        private async Task JoinAsync()
        {
            var connectionId = await _mudOnlineProvider.GetConnectionId(_account.PlayerId);

            if (!string.IsNullOrEmpty(connectionId) && connectionId != Context.ConnectionId)
            {
                await KickOut(connectionId);
            }

            await _mudOnlineProvider.SetConnectionId(_account.PlayerId, Context.ConnectionId);

            await Groups.AddToGroupAsync(Context.ConnectionId, "room_" + _account.RoomId);

            await Groups.AddToGroupAsync(Context.ConnectionId, "faction_" + _account.FactionId);


            _logger.LogDebug($"InitGame:{_account.PlayerId}");
            var command = new InitGameCommand(_account.PlayerId);
            await _bus.SendCommand(command).ConfigureAwait(false);;
        }
Exemple #3
0
 public virtual void ExecuteInitGame(InitGameCommand command)
 {
     command.Sender = OutOfGameRoot;
     OutOfGameRoot.InitGame.OnNext(command);
 }
 public virtual void InitGameHandler(InitGameCommand command)
 {
     this.InitGame(command.Sender as OutOfGameRootViewModel);
 }