public async Task MoveHouse(string houseName, [Remainder] SocketGuildUser mention) { var activeCharacter = _stewardContext.PlayerCharacters .Include(c => c.House) .ThenInclude(h => h.HouseOwner) .SingleOrDefault(c => c.DiscordUserId == mention.Id.ToString() && c.YearOfDeath == null); if (activeCharacter == null) { await ReplyAsync("The player doesn't have a living character."); return; } if (activeCharacter.House != null) { if (activeCharacter == activeCharacter.House.HouseOwner) { activeCharacter.House.HouseOwner = null; activeCharacter.House.HouseOwnerId = null; } } if (houseName == "null") { activeCharacter.House = null; activeCharacter.HouseId = null; _stewardContext.PlayerCharacters.Update(activeCharacter); await _stewardContext.SaveChangesAsync(); await ReplyAsync("Character removed from house."); } else { var newHouse = _stewardContext.Houses.SingleOrDefault(h => h.HouseName == houseName); if (newHouse == null) { await ReplyAsync("Could not find house."); return; } activeCharacter.House = newHouse; _stewardContext.PlayerCharacters.Update(activeCharacter); await _stewardContext.SaveChangesAsync(); await _houseRoleManager.UpdatePlayerHouseRole(activeCharacter, _stewardContext.Houses.ToList()); await ReplyAsync("Character moved to new house."); } }
public async Task CreateCharacter( [Summary("The name of your character, use quotation marks around the name if it includes a space.")] string name, [Summary("The name of the house your character is part of.")] string houseName, [Summary("Strength")] int str, [Summary("Endurance")] int end, [Summary("Dexterity")] int dex, [Summary("Perception")] int per, [Summary("Intelligence")] int intel) { var discordUser = _stewardContext.DiscordUsers .Include(du => du.Characters) .SingleOrDefault(du => du.DiscordId == Context.User.Id.ToString()); var activeCharacter = discordUser.Characters.SingleOrDefault(ac => ac.IsAlive()); if (activeCharacter != null) { await ReplyAsync($"You still have an active character named {activeCharacter.CharacterName}. Get that one killed first."); return; } House house = null; if (houseName != "null") { house = _stewardContext.Houses.FirstOrDefault(h => h.HouseName == houseName); if (house == null) { await ReplyAsync($"Could not find house '{houseName}'."); return; } } var totalPoints = str + dex + end + per + intel; if (totalPoints != 50) { await ReplyAsync("The total amount of ability points has to be 50."); return; } if (str > 15 || dex > 15 || end > 15 || per > 15 || intel > 15) { await ReplyAsync("An ability score cannot be higher than 15."); return; } if (str < 8 || dex < 8 || end < 8 || per < 8 || intel < 8) { await ReplyAsync("An ability score cannot be lower than 8."); return; } var year = _stewardContext.Year.First(); var randomStartingAge = new Random().Next(18, 25); var randomBirthYear = year.CurrentYear - randomStartingAge; PlayerCharacter newCharacter = null; if (house != null) { newCharacter = new PlayerCharacter() { CharacterName = name, House = house, HouseId = house.HouseId, DiscordUser = discordUser, DiscordUserId = discordUser.DiscordId, YearOfBirth = randomBirthYear, STR = str, DEX = dex, END = end, PER = per, INT = intel }; await _houseRoleManager.UpdatePlayerHouseRole(newCharacter, _stewardContext.Houses.ToList()); } else { newCharacter = new PlayerCharacter() { CharacterName = name, DiscordUser = discordUser, DiscordUserId = discordUser.DiscordId, YearOfBirth = randomBirthYear, STR = str, DEX = dex, END = end, PER = per, INT = intel }; } _stewardContext.PlayerCharacters.Add(newCharacter); _stewardContext.SaveChanges(); await ReplyAsync($"Created character with the name {newCharacter.CharacterName}."); }