public async Task <PlayerEntity> GetUserPlayer(int userId) { return(await _playerDomainService.GetUserPlayer(userId)); }
public async Task <Unit> Handle(CreateCommand command, CancellationToken cancellationToken) { var name = command.Name; var gender = command.Gender; var userId = command.UserId; var str = command.Str; var @int = command.Int; var dex = command.Dex; var con = command.Con; var player = await _playerDomainService.Get(p => p.Name == name); if (player != null) { await _bus.RaiseEvent(new DomainNotification("角色名已被使用,请更改!")); return(Unit.Value); } player = await _playerDomainService.GetUserPlayer(userId); if (player != null) { await _bus.RaiseEvent(new DomainNotification("已经超过最大可创建角色数!")); return(Unit.Value); } if (str + @int + dex + con != 80) { await _bus.RaiseEvent(new DomainNotification("所有先天属性之和必须为80!")); return(Unit.Value); } var roomId = _appConfig.Site.BornRoomId; if (roomId <= 0) { await _bus.RaiseEvent(new DomainNotification("未设置出生地点!")); return(Unit.Value); } var room = await _roomDomainService.Get(roomId); if (room == null) { await _bus.RaiseEvent(new DomainNotification("设置的出生地点不存在!")); return(Unit.Value); } Random random = new Random(); player = new PlayerEntity { CreateDate = DateTime.Now, LastDate = DateTime.Now, Level = 1, Name = name, UserId = userId, Status = PlayerStatusEnum.空闲, Gender = gender, Age = 14 * 12, ConAdd = 0, DexAdd = 0, FactionId = 0, IntAdd = 0, Money = 0, RoomId = roomId, Title = "", StrAdd = 0, Atk = 0, Str = str, Con = con, Int = @int, Dex = dex, Exp = 0, Cor = 20, Cps = 20, Pot = 0, Kar = random.Next(1, 100), Def = 0, Hp = 0, LimitMp = 0, MaxHp = 0, MaxMp = 0, Mp = 0, Hit = 0, Parry = 0, Flee = 0, Per = random.Next(10, 50), Nrg = 0 }; player = await _playerDomainService.Computed(player); await _playerDomainService.Add(player); var jwtAccount = new JwtAccount { UserId = userId, Email = _account.Email, PlayerId = player.Id, PlayerName = player.Name }; await _httpAccessor.HttpContext.SignIn("user", jwtAccount); if (await Commit()) { await _bus.RaiseEvent(new CreatedEvent(player)).ConfigureAwait(false); } return(Unit.Value); }