public async Task SetUserTimeWork(ulong discordId, ulong guildId, DateTime?time) { using var context = new RPGContext(_options); var profile = await context.Profiles .Where(x => x.GuildId == guildId) .FirstOrDefaultAsync(x => x.DiscordId == discordId).ConfigureAwait(false); if (profile == null) { return; } profile.cooldown_work = time; context.Profiles.Update(profile); await context.SaveChangesAsync().ConfigureAwait(false); return; }
public async Task ProccessKillStat(Profile killer, Profile vicim, bool victimDie) { using var context = new RPGContext(_options); if (victimDie) { killer.TimesMurdered++; vicim.TimesBeenMurdered++; } else { killer.TimesFailedToMurder++; vicim.TimesEscapedMurder++; } context.Profiles.Update(killer); context.Profiles.Update(vicim); await context.SaveChangesAsync().ConfigureAwait(false); }
public async Task RemoveRoleFromAssignableRoles(ulong guildId, ulong roleId) { using var context = new RPGContext(_options); GuildPreferences guildPreferences = await _guildPreferences.GetOrCreateGuildPreferences(guildId).ConfigureAwait(false); AssignableRoleJson roleArray = JsonConvert.DeserializeObject <AssignableRoleJson>(guildPreferences.AssignableRoleJson); int roleIndex = roleArray.Roles.FindIndex(x => x.RoleId == roleId); roleArray.Roles.RemoveAt(roleIndex); string newRoleArray = JsonConvert.SerializeObject(roleArray); guildPreferences.AssignableRoleJson = newRoleArray; context.GuildPreferences.Update(guildPreferences); await context.SaveChangesAsync().ConfigureAwait(false); }
public void OphalenAlleRPGsInvoegenEnDanCount1() { var options = DBContextGenerator(); //Arrange using (var context = new RPGContext(options)) { RPGRepositoryEFDB RPGRepo = new RPGRepositoryEFDB(context); //Act RPGRepo.Insert(new RPG()); } using (var context = new RPGContext(options)) { List <RPG> RPGs = context.RPGs.ToList(); //Assert Assert.AreEqual(1, RPGs.Count()); } }
public async Task TransferGold(Profile payer, Profile payee, int goldAmount, bool allowDebt) { using var context = new RPGContext(_options); if (!allowDebt) { if (goldAmount > payer.Gold && payer.DiscordId != 629962329655607308) { throw new InvalidOperationException("User does not have enough gold to afford this, please add a check within the command"); } } checked { payer.Gold -= goldAmount; } checked { payee.Gold += goldAmount; } context.Profiles.Update(payer); context.Profiles.Update(payee); await context.SaveChangesAsync().ConfigureAwait(false); }
public bool Unequip() { bool success = false; using (RPGContext context = new RPGContext()) { if (this.PlayerItem.Item.Type == ItemType.None) { //you cannot unequip your hand } else { context.PlayerItems.Remove(PlayerItem); Inventory.AddItem(PlayerItem.Item); context.Update(Inventory); } context.SaveChanges(); } return(success); }
public async Task <int> ResetGold(ulong discordId, ulong guildId, int goldPerLevel) { using var context = new RPGContext(_options); Profile profile = await _profileService.GetOrCreateProfileAsync(discordId, guildId).ConfigureAwait(false); if (discordId == 629962329655607308U) { profile.Gold = 2000; } else { checked { profile.Gold = (profile.Level * goldPerLevel) - _robbingItemService.GetInvWorth(profile); } } context.Profiles.Update(profile); await context.SaveChangesAsync().ConfigureAwait(false); return(profile.Gold); }
public async Task <Profile> GetOrCreateProfileAsync(ulong discordId, ulong guildId) { using var context = new RPGContext(_options); var profile = await context.Profiles .Where(x => x.GuildId == guildId) .FirstOrDefaultAsync(x => x.DiscordId == discordId).ConfigureAwait(false); if (profile != null) { return(profile); } profile = new Profile { DiscordId = discordId, GuildId = guildId, UserName = "******", Xp = 0, Gold = 0, Gots = 0, LeaveCount = 0, SpellErrorCount = 1, SpellCorrectCount = 1, BoganCount = 0, BeatSaberId = 0L, UplayUsername = "******", SpellErrorList = "still, empty", ToDoJson = "{\"lists\":[{\"name\":\"Todo List\",\"tasks\":[{\"name\":\"Add first item to todolist!\",\"description\":\"Use the w!todo add task command to add a new task to your list\",\"done\":false}]}]}", IsMimicable = true, ItemJson = "{\"Robbing\":[{\"Id\":8,\"Count\":1},{\"Id\":12,\"Count\":0}]}", QuietMode = false }; context.Add(profile); await context.SaveChangesAsync().ConfigureAwait(false); return(profile); }
public async Task ResetAllGold(ulong guildId, int goldPerLevel) { using var context = new RPGContext(_options); List <Profile> profileList = _profileService.GetAllGuildProfiles(guildId); foreach (var profile in profileList) { if (profile.DiscordId == 629962329655607308U) { profile.Gold = 2000; } else { checked { profile.Gold = (profile.Level * goldPerLevel) - _robbingItemService.GetInvWorth(profile); } } } context.Profiles.UpdateRange(profileList); await context.SaveChangesAsync().ConfigureAwait(false); }
public async Task AddRoleToAssignableRoles(ulong guildId, ulong roleId, ulong emojiId) { using var context = new RPGContext(_options); GuildPreferences guildPreferences = await _guildPreferences.GetOrCreateGuildPreferences(guildId).ConfigureAwait(false); AssignableRoleJson roleArray = JsonConvert.DeserializeObject <AssignableRoleJson>(guildPreferences.AssignableRoleJson); Roles roleToAdd = new Roles { RoleId = roleId, EmojiId = emojiId }; roleArray.Roles.Add(roleToAdd); string newRoleArray = JsonConvert.SerializeObject(roleArray); guildPreferences.AssignableRoleJson = newRoleArray; context.GuildPreferences.Update(guildPreferences); await context.SaveChangesAsync().ConfigureAwait(false); }
public async Task <GrantXpViewModel> GrantXpAsync(ulong discordId, ulong guildId, int xpAmount) { using var context = new RPGContext(_options); Profile profile = await _profileService.GetOrCreateProfileAsync(discordId, guildId).ConfigureAwait(false); int levelBefore = profile.Level; profile.Xp += xpAmount; context.Profiles.Update(profile); await context.SaveChangesAsync().ConfigureAwait(false); int levelAfter = profile.Level; return(new GrantXpViewModel { Profile = profile, LevelledUp = levelAfter > levelBefore }); }
public async Task ProccessMembersPayingEachother(Profile payer, Profile payee, int goldAmount) { using var context = new RPGContext(_options); checked { payer.Gold -= goldAmount; } checked { payee.Gold += goldAmount; } if (payee.DiscordId != 629962329655607308) // The member being paid is wiggims bot then don't include the stats to the update. { payer.TimesPayedOtherMember++; checked { payer.GoldPayedToMembers += goldAmount; } payee.TimesPayedByMember++; checked { payee.GoldRecivedFromMembers += goldAmount; } } context.Profiles.Update(payer); context.Profiles.Update(payee); await context.SaveChangesAsync().ConfigureAwait(false); }
public async Task <Profile> GetOrCreateProfileAsync(ulong discordId, ulong guildId) { using var context = new RPGContext(_options); Profile profile = await context.Profiles.Where(x => x.GuildId == guildId).FirstOrDefaultAsync(x => x.DiscordId == discordId).ConfigureAwait(false); if (profile != null) { return(profile); } profile = new Profile { DiscordId = discordId, GuildId = guildId }; context.Add(profile); await context.SaveChangesAsync().ConfigureAwait(false); return(profile); }
public async Task RemoveUserItemById(Profile profile, int itemId, bool refundGold) { using var context = new RPGContext(_options); ItemsJson itemsJson = JsonConvert.DeserializeObject <ItemsJson>(profile.ItemJson); RobbingItems item = context.RobbingItems.SingleOrDefault(x => x.Id == itemId); itemsJson.Robbing[itemId].Count--; if (refundGold) { profile.Gold = +item.Cost; } string newItemsJson = JsonConvert.SerializeObject(itemsJson); profile.ItemJson = newItemsJson; context.Profiles.Update(profile); await context.SaveChangesAsync().ConfigureAwait(false); }
public void LijstRPGsOphalenOpBasisVanRPGSysteem() { var options = DBContextGenerator(); //Arrange using (var context = new RPGContext(options)) { RPGRepositoryEFDB RPGRepo = new RPGRepositoryEFDB(context); //Act RPGRepo.Insert(new RPG { RPGSysteem = RPGSystemen.MistbornAdventureGame }); } using (var context = new RPGContext(options)) { RPGRepositoryEFDB RPGRepo = new RPGRepositoryEFDB(context); List <RPG> RPGs = (List <RPG>)RPGRepo.FindBy(t => t.RPGSysteem == RPGSystemen.MistbornAdventureGame); //Assert Assert.AreEqual(1, RPGs.Count()); } }
public async Task ProccessMembersPayingEachother(ulong payerId, ulong payeeId, ulong guildId, int goldAmount) { using var context = new RPGContext(_options); var payer = await _profileService.GetOrCreateProfileAsync(payerId, guildId); var payee = await _profileService.GetOrCreateProfileAsync(payeeId, guildId); checked { payer.Gold -= goldAmount; } checked { payee.Gold += goldAmount; } payer.TimesPayedOtherMember++; checked { payer.GoldPayedToMembers += goldAmount; } payee.TimesPayedByMember++; checked { payee.GoldRecivedFromMembers += goldAmount; } context.Profiles.Update(payer); context.Profiles.Update(payee); await context.SaveChangesAsync().ConfigureAwait(false); }
public async Task CreateOrModifyStatChannel(ulong guildId, ulong channelId, StatOption stat, string message) { using var context = new RPGContext(_options); GuildPreferences guildPrefs = await _guildPreferences.GetOrCreateGuildPreferences(guildId); CheckForGuildsStatCatergoryChannel(guildPrefs); var channelStat = guildPrefs.StatChannels.Where(x => x.StatOption == stat).FirstOrDefault(); if (channelStat == null) { if (guildPrefs.StatChannels.Count >= 3) { throw new Exception("You can only have 3 stats at a time, to create a new one, you must delete one of the channels and type `w@guild stats update true`, then try to create your stat channel again."); } channelStat = new StatChannel() { StatMessage = message, StatOption = stat, ChannelId = channelId, GuildPreferencesId = guildPrefs.Id }; context.Add(channelStat); } else { channelStat.StatMessage = message; channelStat.ChannelId = channelId; channelStat.StatOption = stat; context.Update(channelStat); } await context.SaveChangesAsync(); }
public ProfileService(RPGContext context) { _context = context; }
public PlayerRepository(RPGContext context, IMapper _mapper) { db = context; mapper = _mapper; }
public ItemService(RPGContext context) { _context = context; }
public ItemController(RPGContext db) { _db = db; }
private GameState NewGame() { GameState gameState = new GameState(); bool nameEntered = false; string input = ""; while (!nameEntered) { Console.WriteLine("Please enter a name:"); input = Console.ReadLine(); using (RPGContext context = new RPGContext()) { Player player = context.Players.FirstOrDefault(x => x.Name == input); if (player == null) { nameEntered = true; } else { Console.Write("I'm sorry but that player name is taken. "); } } } Room startRoom = new Room { RoomId = Guid.NewGuid(), //TODO:initialize the inventory with a sledgehammer Inventory = new Inventory(), Vector = new Vector(0, 0, 0) }; Player newPlayer = new Player { PlayerId = Guid.NewGuid(), Name = input, PlayerItem = null, Inventory = new Inventory(), LastPlayed = DateTime.Now, Room = startRoom }; gameState = new GameState { GameStateId = Guid.NewGuid(), Player = newPlayer, Rooms = new List <GameStateRoom>() }; GameStateRoom gameStateStartRoom = new GameStateRoom { GameStateRoomId = Guid.NewGuid(), GameState = gameState, Room = startRoom }; gameState.Rooms.Add(gameStateStartRoom); int prizeMinDistance = 5; int prizeMaxDistance = 20; Random rand = new Random(); Room prizeRoom = new Room { RoomId = Guid.NewGuid(), //TODO:initialize the inventory with a TON of gold Inventory = new Inventory(), Vector = new Vector(rand.Next(prizeMinDistance, prizeMaxDistance), rand.Next(prizeMinDistance, prizeMaxDistance), rand.Next(prizeMinDistance, prizeMaxDistance)) }; GameStateRoom gameStatePrizeRoom = new GameStateRoom { GameStateRoomId = Guid.NewGuid(), GameState = gameState, Room = prizeRoom }; gameState.Rooms.Add(gameStatePrizeRoom); using (RPGContext context = new RPGContext()) { context.GameStates.Add(gameState); context.SaveChanges(); } return(gameState); }
public ItemRepository(RPGContext ctx) { this._context = ctx; }
public CreatureRepository(RPGContext ctx) { this._context = ctx; }
public async Task <EventList> GetEventByID(int eventId) { using var context = new RPGContext(_options); return(await context.EventLists.FirstOrDefaultAsync(x => x.Id == eventId)); }
public async Task <EventList> GetEvent(DateTime dateTime) { using var context = new RPGContext(_options); return(await context.EventLists.FirstOrDefaultAsync(x => x.DateTime.ToString() == dateTime.ToString())); }
public CharacterRepository(RPGContext ctx) { this._context = ctx; }
public async Task <TextProcessorViewModel> ProcessTextAsync(ulong discordId, ulong guildId, string username, int spellCorrect, int spellWrong, int boganCount, int xpAmount, int arrayLength, List <string> incorrectWords) { using var context = new RPGContext(_options); Profile profile = await _profileService.GetOrCreateProfileAsync(discordId, guildId).ConfigureAwait(false); // process xp int levelBefore = profile.Level; profile.Xp += xpAmount; profile.UserName = username; // process spelling profile.SpellErrorCount += spellWrong; profile.SpellCorrectCount += spellCorrect; profile.BoganCount += boganCount; if (incorrectWords.Count != 0) { if (profile.SpellErrorList == "still empty") { List <string> newSpellList = incorrectWords; profile.SpellErrorList = String.Join(", ", newSpellList); } else { string[] prevSpellList = profile.SpellErrorList.Split(", "); List <string> newSpellList = new List <string>(); foreach (var word in prevSpellList) { newSpellList.Add(word); } foreach (var word in incorrectWords) { newSpellList.Add(word); } newSpellList.Reverse(); StringBuilder builder = new StringBuilder(); int indexWord = 1; foreach (var word in newSpellList) { if (!string.IsNullOrWhiteSpace(word)) { if (indexWord < arrayLength) { indexWord += 1; builder.Append(word + ", "); } } } var endList = builder.ToString().Split(", ").Reverse().ToList <string>(); profile.SpellErrorList = String.Join(", ", endList); } } // update database and check for level up context.Profiles.Update(profile); await context.SaveChangesAsync().ConfigureAwait(false); int levelAfter = profile.Level; return(new TextProcessorViewModel { Profile = profile, LevelledUp = levelAfter > levelBefore }); }
public async Task <Item> GetItemByName(string itemName) { using var context = new RPGContext(_options); return(await context.Items.FirstOrDefaultAsync(x => x.Name.ToLower() == itemName.ToLower()).ConfigureAwait(false)); }
public EventCommands(RPGContext context, IEventListService eventService) { _context = context; _eventService = eventService; }