public async Task <Character> CreateCharacterAsync(NaheulbookExecutionContext executionContext, CreateCharacterRequest request) { using (var uow = _unitOfWorkFactory.CreateUnitOfWork()) { var character = _characterFactory.CreateCharacter(request); if (request.GroupId.HasValue) { var group = await uow.Groups.GetAsync(request.GroupId.Value); if (group == null) { throw new GroupNotFoundException(request.GroupId.Value); } _authorizationUtil.EnsureIsGroupOwner(executionContext, group); character.Group = group; } character.OwnerId = executionContext.UserId; character.Items = await _itemUtil.CreateInitialPlayerInventoryAsync(request.Money); uow.Characters.Add(character); await uow.SaveChangesAsync(); return(character); } }
public async Task <List <Npc> > LoadNpcsAsync(NaheulbookExecutionContext executionContext, int groupId) { using var uow = _unitOfWorkFactory.CreateUnitOfWork(); var group = await uow.Groups.GetAsync(groupId); if (group == null) { throw new GroupNotFoundException(groupId); } _authorizationUtil.EnsureIsGroupOwner(executionContext, group); return(await uow.Npcs.GetByGroupIdAsync(groupId)); }
public async Task <Group> GetGroupDetailsAsync(NaheulbookExecutionContext executionContext, int groupId) { using (var uow = _unitOfWorkFactory.CreateUnitOfWork()) { var group = await uow.Groups.GetGroupsWithDetailsAsync(groupId); if (group == null) { throw new GroupNotFoundException(groupId); } _authorizationUtil.EnsureIsGroupOwner(executionContext, group); return(group); } }
public async Task <Loot> CreateLootAsync(NaheulbookExecutionContext executionContext, int groupId, CreateLootRequest request) { using (var uow = _unitOfWorkFactory.CreateUnitOfWork()) { var group = await uow.Groups.GetAsync(groupId); if (group == null) { throw new GroupNotFoundException(groupId); } _authorizationUtil.EnsureIsGroupOwner(executionContext, group); var loot = new Loot { Group = group, Name = request.Name, IsVisibleForPlayer = false }; uow.Loots.Add(loot); await uow.SaveChangesAsync(); return(loot); } }
public async Task <Monster> GetMonsterAsync(NaheulbookExecutionContext executionContext, int monsterId) { using (var uow = _unitOfWorkFactory.CreateUnitOfWork()) { var monster = await uow.Monsters.GetWithGroupAsync(monsterId); if (monster == null) { throw new MonsterNotFoundException(monsterId); } _authorizationUtil.EnsureIsGroupOwner(executionContext, monster.Group); return(monster); } }
public void ApplyCharactersChange(NaheulbookExecutionContext executionContext, PatchCharacterRequest request, Character character, INotificationSession notificationSession) { if (request.Debilibeuk.HasValue) { _authorizationUtil.EnsureIsGroupOwner(executionContext, character.Group); var gmData = _jsonUtil.Deserialize <CharacterGmData>(character.GmData) ?? new CharacterGmData(); gmData.Debilibeuk = request.Debilibeuk.Value; character.GmData = _jsonUtil.Serialize(gmData); notificationSession.NotifyCharacterGmChangeData(character, gmData); } if (request.Mankdebol.HasValue) { _authorizationUtil.EnsureIsGroupOwner(executionContext, character.Group); var gmData = _jsonUtil.Deserialize <CharacterGmData>(character.GmData) ?? new CharacterGmData(); gmData.Mankdebol = request.Mankdebol.Value; character.GmData = _jsonUtil.Serialize(gmData); notificationSession.NotifyCharacterGmChangeData(character, gmData); } if (request.IsActive.HasValue) { _authorizationUtil.EnsureIsGroupOwner(executionContext, character.Group); character.IsActive = request.IsActive.Value; notificationSession.NotifyCharacterGmChangeActive(character); } if (request.Color != null) { _authorizationUtil.EnsureIsGroupOwner(executionContext, character.Group); character.Color = request.Color; notificationSession.NotifyCharacterGmChangeColor(character); } if (request.OwnerId != null) { _authorizationUtil.EnsureIsGroupOwner(executionContext, character.Group); character.OwnerId = request.OwnerId.Value; } if (request.Target != null) { _authorizationUtil.EnsureIsGroupOwner(executionContext, character.Group); if (request.Target.IsMonster) { character.TargetedCharacterId = null; character.TargetedMonsterId = request.Target.Id; } else { character.TargetedMonsterId = null; character.TargetedCharacterId = request.Target.Id; } notificationSession.NotifyCharacterGmChangeTarget(character, request.Target); } if (request.Ev.HasValue) { character.AddHistoryEntry(_characterHistoryUtil.CreateLogChangeEv(character, character.Ev, request.Ev)); character.Ev = request.Ev; notificationSession.NotifyCharacterChangeEv(character); } if (request.Ea.HasValue) { character.AddHistoryEntry(_characterHistoryUtil.CreateLogChangeEa(character, character.Ea, request.Ea)); character.Ea = request.Ea; notificationSession.NotifyCharacterChangeEa(character); } if (request.FatePoint.HasValue) { character.AddHistoryEntry(_characterHistoryUtil.CreateLogChangeFatePoint(character, character.FatePoint, request.FatePoint)); character.FatePoint = request.FatePoint.Value; notificationSession.NotifyCharacterChangeFatePoint(character); } if (request.Experience.HasValue) { character.AddHistoryEntry(_characterHistoryUtil.CreateLogChangeExperience(character, character.Experience, request.Experience)); character.Experience = request.Experience.Value; notificationSession.NotifyCharacterChangeExperience(character); } if (request.Sex != null) { character.AddHistoryEntry(_characterHistoryUtil.CreateLogChangeSex(character, character.Sex, request.Sex)); character.Sex = request.Sex; notificationSession.NotifyCharacterChangeSex(character); } if (request.Name != null) { character.AddHistoryEntry(_characterHistoryUtil.CreateLogChangeName(character, character.Name, request.Name)); character.Name = request.Name; notificationSession.NotifyCharacterChangeName(character); } if (request.Notes != null) { character.Notes = request.Notes; notificationSession.NotifyCharacterChangeNotes(character); } }