示例#1
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);
        }
示例#2
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);
        }
示例#3
0
        public async Task CreateNewItemAsync(Item item)
        {
            using var context = new RPGContext(_options);

            context.Add(item);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
示例#4
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);
        }
示例#5
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)
                          .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);
        }
示例#6
0
        public async Task <Profile> GetOrCreateProfileAsync(ulong discordId, ulong guildId)
        {
            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
            };

            _context.Add(profile);
            await _context.SaveChangesAsync().ConfigureAwait(false);

            return(profile);
        }
示例#7
0
        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();
        }