Esempio n. 1
0
        public async Task ProccessMembersRobbing(Profile attacker, Profile victim, int goldNum, bool robberySuccessfull)
        {
            using var context = new RPGContext(_options);

            if (!robberySuccessfull)
            {
                checked { attacker.RobbingAttackLost++; }
                checked { victim.RobbingDefendWon++; }

                checked { attacker.GoldLostFines += goldNum; }
                checked { victim.GoldGainedFines += goldNum; }

                //Make sure set to negative after you track the results not before.
                goldNum = -goldNum;
            }
            else
            {
                checked { attacker.RobbingAttackWon++; }
                checked { victim.RobbingDefendLost++; }

                checked { attacker.GoldStolen += goldNum; }
                checked { victim.GoldLostFromTheft += goldNum; }
            }

            attacker.RobbingCooldown = DateTime.Now;

            checked { attacker.Gold += goldNum; }
            checked { victim.Gold -= goldNum; }

            context.Profiles.Update(attacker);
            context.Profiles.Update(victim);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Esempio n. 2
0
        public async Task ProccessMemberCoinFlip(ulong memberId, ulong botId, ulong guildId, int goldNum, bool memberWonGame)
        {
            using var context = new RPGContext(_options);

            var profile = await _profileService.GetOrCreateProfileAsync(memberId, guildId);

            var botProfile = await _profileService.GetOrCreateProfileAsync(botId, guildId);

            if (!memberWonGame)
            {
                profile.CoindFlipsLost++;
                checked { profile.GoldLostCoinFlip += goldNum; }

                //Make sure set to negative after you track the results not before.
                goldNum = -goldNum;
            }
            else
            {
                profile.CoinFilpsWon++;
                checked { profile.GoldWonCoinFlip += goldNum; }
            }


            checked { profile.Gold += goldNum; }
            checked { botProfile.Gold -= goldNum; }

            context.Profiles.Update(profile);
            context.Profiles.Update(botProfile);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Esempio n. 3
0
        public async Task ProccessMemberRoulette(Profile profile, Profile botProfile, int goldNum, bool memberWonGame)
        {
            using var context = new RPGContext(_options);

            if (!memberWonGame)
            {
                profile.RouletteFails++;
                profile.GoldLostRoulette += goldNum;

                profile.Gold    -= goldNum;
                botProfile.Gold += goldNum;
            }
            else
            {
                profile.RouletteSuccesses++;
                profile.GoldWonRoulette += goldNum;

                profile.Gold    += goldNum;
                botProfile.Gold -= goldNum;
            }



            context.Profiles.Update(profile);
            context.Profiles.Update(botProfile);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
        public async Task RemoveDictionaryWordFromLists(string newWord)
        {
            using var context = new RPGContext(_options);

            var profileList = context.Profiles.Where(x => x.Xp > 100).ToList();

            foreach (var profile in profileList)
            {
                string[]      prevSpellList = profile.SpellErrorList.Split(", ");
                StringBuilder builder       = new StringBuilder();
                foreach (var word in prevSpellList)
                {
                    if (word != newWord)
                    {
                        builder.Append($"{word}, ");
                    }
                    else
                    {
                        profile.SpellErrorCount -= 1;
                    }
                }

                var endList = builder.ToString().Split(", ").ToList <string>();

                profile.SpellErrorList = String.Join(", ", endList);
            }

            context.Profiles.UpdateRange(profileList);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Esempio n. 5
0
        public async Task ProccessMemberCoinFlip(Profile profile, Profile botProfile, int goldNum, bool memberWonGame)
        {
            using var context = new RPGContext(_options);

            if (!memberWonGame)
            {
                profile.CoindFlipsLost++;
                profile.GoldLostCoinFlip += goldNum;

                //Make sure set to negative after you track the results not before.
                goldNum = -goldNum;
            }
            else
            {
                profile.CoinFilpsWon++;
                profile.GoldWonCoinFlip += goldNum;
            }


            profile.Gold    += goldNum;
            botProfile.Gold -= goldNum;

            context.Profiles.Update(profile);
            context.Profiles.Update(botProfile);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Esempio n. 6
0
        public async Task <GuildPreferences> GetOrCreateGuildPreferences(ulong guildId)
        {
            using var context = new RPGContext(_options);

            GuildPreferences guildPrefences = await context.GuildPreferences
                                              .Where(x => x.GuildId == guildId)
                                              .Include(sc => sc.StatChannels)
                                              .FirstOrDefaultAsync(x => x.GuildId == guildId).ConfigureAwait(false);

            if (guildPrefences != null)
            {
                return(guildPrefences);
            }

            guildPrefences = new GuildPreferences
            {
                GuildId            = guildId,
                XpPerMessage       = 1,
                SpellingEnabled    = false,
                ErrorListLength    = 10,
                AssignableRoleJson = "{\"Roles\":[]}",
                GoldPerLevelUp     = 50,
                IsGoldEnabled      = true
            };

            context.Add(guildPrefences);

            await context.SaveChangesAsync().ConfigureAwait(false);

            return(guildPrefences);
        }
Esempio n. 7
0
        public async Task <bool> PurchaseItemAsync(ulong discordId, ulong guildId, string itemName)
        {
            using var context = new RPGContext(_options);

            Item item = await GetItemByNameAsync(itemName).ConfigureAwait(false);

            if (item == null)
            {
                return(false);
            }

            Profile profile = await _profileService.GetOrCreateProfileAsync(discordId, guildId).ConfigureAwait(false);

            if (profile.Gold < item.Price)
            {
                return(false);
            }

            profile.Gold -= item.Price;
            profile.Items.Add(new ProfileItem
            {
                ItemId    = item.Id,
                ProfileId = profile.Id
            });

            context.Profiles.Update(profile);

            await context.SaveChangesAsync().ConfigureAwait(false);

            return(true);
        }
Esempio n. 8
0
        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)
                          .Include(x => x.Items)
                          .Include(x => x.Items).ThenInclude(x => x.Item)
                          .FirstOrDefaultAsync(x => x.DiscordId == discordId).ConfigureAwait(false);

            if (profile != null)
            {
                return(profile);
            }

            profile = new Profile
            {
                DiscordId = discordId,
                GuildId   = guildId,
                Gold      = 100
            };

            context.Add(profile);

            await context.SaveChangesAsync().ConfigureAwait(false);

            return(profile);
        }
Esempio n. 9
0
        public async Task TransferGold(ulong payerId, ulong payeeId, ulong guildId, int goldAmount, bool allowDebt)
        {
            using var context = new RPGContext(_options);

            var payer = await _profileService.GetOrCreateProfileAsync(payerId, guildId);

            var payee = await _profileService.GetOrCreateProfileAsync(payeeId, guildId);

            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);
        }
Esempio n. 10
0
        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);

            profile.ExpToLevel -= xpAmount;
            profile.Exp        += xpAmount;

            bool levelled = false;

            if (profile.ExpToLevel <= 0)
            {
                float exponent = 1.5f;
                int   baseXP   = 1000;

                profile.Level++;
                profile.ExpToLevel += (int)MathF.Floor((float)baseXP * MathF.Pow(profile.Level, exponent));

                levelled = true;
            }

            context.Profiles.Update(profile);

            await context.SaveChangesAsync().ConfigureAwait(false);

            return(new GrantXpViewModel
            {
                Profile = profile,
                LevelledUp = levelled
            });
        }
Esempio n. 11
0
        public async Task CreateNewItemAsync(Item item)
        {
            using var context = new RPGContext(_options);

            context.Add(item);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Esempio n. 12
0
        public async Task CreateNewEvent(EventList eventList)
        {
            using var context = new RPGContext(_options);

            await context.AddAsync(eventList).ConfigureAwait(false);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Esempio n. 13
0
        public async Task EditEvent(EventList eventList)
        {
            using var context = new RPGContext(_options);

            context.Update(eventList);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Esempio n. 14
0
        public async Task CreateNewItem(string itemName, string itemDescription, int itemCost, int maxAllowed, int levelRequired, decimal defenseBuff, decimal attackBuff, bool allowHeist = false)
        {
            using var context = new RPGContext(_options);

            var existingItems = GetAllRobbingItems();

            if (existingItems.Exists(x => x.Name.ToLower() == itemName.ToLower()))
            {
                throw new Exception("An item with that name already exists.");
            }

            if (itemCost < 0)
            {
                throw new Exception("You cannot have a negative value for the item cost.");
            }

            if (maxAllowed < 1)
            {
                throw new Exception("The minimum max allowed is 1.");
            }

            if (defenseBuff > 0.5M)
            {
                throw new Exception("The defense buff is really high, please use a lower value.");
            }

            if (defenseBuff < -0.5M)
            {
                throw new Exception("The defense buff is really low, please use a higher value.");
            }

            if (attackBuff > 0.5M)
            {
                throw new Exception("The attack buff is really high, please use a lower value.");
            }

            if (attackBuff < -0.5M)
            {
                throw new Exception("The attack buff is really low, please use a higher value.");
            }

            var item = new RobbingItems
            {
                Name        = itemName,
                Cost        = itemCost,
                Description = itemDescription,
                LvlRequired = levelRequired,
                AllowHeist  = allowHeist,
                MaxAllowed  = maxAllowed,
                AttackBuff  = attackBuff,
                DefenseBuff = defenseBuff
            };

            context.Add(item);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Esempio n. 15
0
        public async Task GiveUserItem(Profile profile, Profile botProfile, string itemName)
        {
            using var context = new RPGContext(_options);

            RobbingItems item = context.RobbingItems.First(x => x.Name.ToLower() == itemName.ToLower());

            if (profile.Gold < item.Cost)
            {
                throw new Exception("User cannot afford the item.");
            }

            if (profile.Level < item.LvlRequired)
            {
                throw new Exception("User is not the right level");
            }

            ItemsJson itemsJson = JsonConvert.DeserializeObject <ItemsJson>(profile.ItemJson);

            string newItemsJson;

            if (itemsJson.Robbing.Exists(x => x.Id == item.Id))
            {
                if (itemsJson.Robbing.SingleOrDefault(x => x.Id == item.Id).Count >= item.MaxAllowed)
                {
                    throw new Exception("user already owns max amount of items.");
                }


                itemsJson.Robbing.SingleOrDefault(x => x.Id == item.Id).Count++;

                newItemsJson = JsonConvert.SerializeObject(itemsJson);
            }
            else
            {
                Robbing newRobbing = new Robbing {
                    Id = item.Id, Count = 1
                };

                itemsJson.Robbing.Add(newRobbing);

                newItemsJson = JsonConvert.SerializeObject(itemsJson);
            }



            profile.ItemJson = newItemsJson;
            profile.Gold    -= item.Cost;

            context.Profiles.Update(profile);

            botProfile.Gold += item.Cost;

            context.Profiles.Update(botProfile);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Esempio n. 16
0
        public async Task TackAMimic(Profile profile)
        {
            using var context = new RPGContext(_options);

            profile.TimesMimicked++;

            context.Profiles.Update(profile);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Esempio n. 17
0
        public async Task <bool> RemoveItemAsync(string itemName)
        {
            using var context = new RPGContext(_options);

            var item = await GetItemByNameAsync(itemName).ConfigureAwait(false);

            context.Remove(item);
            await context.SaveChangesAsync().ConfigureAwait(false);

            return(true);
        }
Esempio n. 18
0
        public async Task SetAutoRole(ulong guildId, ulong roleId)
        {
            using var context = new RPGContext(_options);

            var guildPrefs = await GetOrCreateGuildPreferences(guildId);

            guildPrefs.AutoRole = roleId;

            context.GuildPreferences.Update(guildPrefs);

            await context.SaveChangesAsync();
        }
Esempio n. 19
0
        public async Task SetStatChannelCategory(ulong guildId, ulong channelId)
        {
            using var context = new RPGContext(_options);

            var guildPrefs = await GetOrCreateGuildPreferences(guildId);

            guildPrefs.StatChannelCatergoryId = channelId;

            context.GuildPreferences.Update(guildPrefs);

            await context.SaveChangesAsync();
        }
Esempio n. 20
0
        public async Task SetGold(ulong discordId, ulong guildId, int goldAmount)
        {
            using var context = new RPGContext(_options);

            Profile profile = await _profileService.GetOrCreateProfileAsync(discordId, guildId).ConfigureAwait(false);

            profile.Gold = goldAmount;

            context.Profiles.Update(profile);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Esempio n. 21
0
        public async Task SetSpellListLength(ulong guildId, int listLength)
        {
            using var context = new RPGContext(_options);

            GuildPreferences guildPreferences = await _guildPreferences.GetOrCreateGuildPreferences(guildId).ConfigureAwait(false);

            guildPreferences.ErrorListLength = listLength;

            context.GuildPreferences.Update(guildPreferences);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Esempio n. 22
0
        public async Task GiveUserItem(Profile profile, Profile botProfile, int itemId)
        {
            using var context = new RPGContext(_options);

            RobbingItems item = context.RobbingItems.SingleOrDefault(x => x.Id == itemId);

            if (profile.Gold < item.Cost)
            {
                throw new InvalidOperationException("The user cannot afford to purchase this item.");
            }

            if (profile.Level < item.LvlRequired)
            {
                throw new InvalidOperationException("The user is not the correct level to purchase this item.");
            }

            ItemsJson itemsJson = JsonConvert.DeserializeObject <ItemsJson>(profile.ItemJson);

            if (itemsJson.Robbing.SingleOrDefault(x => x.Id == itemId).Count >= item.MaxAllowed)
            {
                throw new InvalidOperationException("The user already owns the maximum number of items allowed.");
            }

            string newItemsJson;

            if (itemsJson.Robbing.Exists(x => x.Id == itemId))
            {
                itemsJson.Robbing.SingleOrDefault(x => x.Id == itemId).Count++;

                newItemsJson = JsonConvert.SerializeObject(itemsJson);
            }
            else
            {
                Robbing newRobbing = new Robbing {
                    Id = itemId, Count = 1
                };

                itemsJson.Robbing.Add(newRobbing);

                newItemsJson = JsonConvert.SerializeObject(itemsJson);
            }

            profile.ItemJson = newItemsJson;
            profile.Gold    -= item.Cost;

            context.Profiles.Update(profile);

            botProfile.Gold += item.Cost;

            context.Profiles.Update(botProfile);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Esempio n. 23
0
        public async Task SetGoldPerLvlUp(ulong guildId, int goldPerLvlUp)
        {
            using var context = new RPGContext(_options);

            var guildPrefs = await GetOrCreateGuildPreferences(guildId);

            guildPrefs.GoldPerLevelUp = goldPerLvlUp;

            context.GuildPreferences.Update(guildPrefs);

            await context.SaveChangesAsync();
        }
Esempio n. 24
0
        public async Task ToggleSpellTracking(ulong guildId, bool enabled)
        {
            using var context = new RPGContext(_options);

            GuildPreferences guildPreferences = await _guildPreferences.GetOrCreateGuildPreferences(guildId).ConfigureAwait(false);

            guildPreferences.SpellingEnabled = enabled;

            context.GuildPreferences.Update(guildPreferences);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Esempio n. 25
0
        public async Task SetUplayIdAsync(ulong discordId, ulong guildId, string UplayId)
        {
            using var context = new RPGContext(_options);

            Profile profile = await _profileService.GetOrCreateProfileAsync(discordId, guildId).ConfigureAwait(false);

            profile.UplayUsername = UplayId;

            context.Profiles.Update(profile);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Esempio n. 26
0
        public async Task GrantSpellCorrectAsync(ulong discordId, ulong guildId, int SpellCorrectAmount)
        {
            using var context = new RPGContext(_options);

            Profile profile = await _profileService.GetOrCreateProfileAsync(discordId, guildId).ConfigureAwait(false);

            profile.SpellCorrectCount += SpellCorrectAmount;

            context.Profiles.Update(profile);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Esempio n. 27
0
        public async Task SetMimicableAsync(ulong discordId, ulong guildId, bool enabled)
        {
            using var context = new RPGContext(_options);

            Profile profile = await _profileService.GetOrCreateProfileAsync(discordId, guildId).ConfigureAwait(false);

            profile.IsMimicable = enabled;

            context.Profiles.Update(profile);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Esempio n. 28
0
                public async Task UpdateChannelStats(CommandContext ctx, bool force = false)
                {
                    if (!updateNeeded.ContainsKey(ctx.Guild.Id))
                    {
                        ctx.Client.DebugLogger.LogMessage(LogLevel.Debug, ctx.Client.CurrentApplication.Name, $"{ctx.Guild.Name} not found in updateNeeded dictionary creating new instance.", DateTime.Now);
                        updateNeeded.Add(ctx.Guild.Id, true);
                    }

                    if (!updateNeeded[ctx.Guild.Id] && !force)
                    {
                        ctx.Client.DebugLogger.LogMessage(LogLevel.Debug, ctx.Client.CurrentApplication.Name, $"{ctx.Guild.Name} Does not need to update stats.", DateTime.Now);
                        return;
                    }

                    ctx.Client.DebugLogger.LogMessage(LogLevel.Debug, ctx.Client.CurrentApplication.Name, $"{ctx.Guild.Name} needs stats to be updating, updating now...", DateTime.Now);

                    updateNeeded[ctx.Guild.Id] = false;


                    using var context = new RPGContext(_options);

                    var guildPrefs = await _guildPreferences.GetOrCreateGuildPreferences(ctx.Guild.Id);

                    guildPrefs.TotalCommandsExecuted++;
                    context.Update(guildPrefs);
                    await context.SaveChangesAsync();

                    if (guildPrefs.StatChannels.Count == 0)
                    {
                        ctx.Client.DebugLogger.LogMessage(DSharpPlus.LogLevel.Debug, ctx.Client.CurrentApplication.Name, "This guild is not configured to update a stat channel, updating other stats and returning.", DateTime.Now);
                        return;
                    }

                    foreach (var statChannel in guildPrefs.StatChannels)
                    {
                        DiscordChannel channel = null;

                        channel = ctx.Guild.GetChannel(statChannel.ChannelId);

                        if (channel == null)
                        {
                            ctx.Client.DebugLogger.LogMessage(LogLevel.Warning, ctx.Client.CurrentApplication.Name, $"The stat channel for stat option {statChannel.StatOption} in the guild '{ctx.Guild.Name}' no longer exists and the data base entry will be removed.", DateTime.Now);
                            await _statChannelService.DeleteStatChannel(ctx.Guild.Id, statChannel.StatOption);

                            break;
                        }

                        await channel.ModifyAsync(x => x.Name = $"{statChannel.StatMessage}: { GetStat(ctx, statChannel.StatOption) }").ConfigureAwait(false);
                    }
                }
Esempio n. 29
0
        public async Task ProccessMemberDaily(Profile profile, Profile botProfile, int goldNum)
        {
            using var context = new RPGContext(_options);

            profile.DailyCooldown       = DateTime.Now;
            profile.Gold               += goldNum;
            profile.TotalDailyEarnings += goldNum;
            profile.DailiesCollected++;

            botProfile.Gold -= goldNum;

            context.Profiles.Update(profile);
            context.Profiles.Update(botProfile);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Esempio n. 30
0
        public async Task TransferGoldWTax(Profile payer, Profile payee, Profile wigsBotProfile, int goldAmount, decimal wigsBotTaxPercent)
        {
            using var context = new RPGContext(_options);

            checked { payer.Gold -= goldAmount; }

            checked { payee.Gold += goldAmount - Convert.ToInt32(Convert.ToDecimal(goldAmount) * wigsBotTaxPercent); }

            checked { wigsBotProfile.Gold += Convert.ToInt32(Convert.ToDecimal(goldAmount) * wigsBotTaxPercent); }

            context.Profiles.Update(payer);
            context.Profiles.Update(payee);
            context.Profiles.Update(wigsBotProfile);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }