Exemple #1
0
        public async Task AddInspriaton(string Name, int table, int card, [Remainder] string description)
        {
            //Basic var
            DndInspiration insp = null;

            //Add it
            using (var uow = DBHandler.UnitOfWork())
            {
                insp = uow.DndInspiration.GetOrCreateInspiration(Name, description, table, card);
            }

            //error oh no
            if (insp == null)
            {
                await Context.Channel.SendErrorAsync("Error adding the inspiraton.");

                return;
            }

            //Ok good
            var embed = new EmbedBuilder().WithTitle($"Added Inspiration | Table: {insp.TableNumber}, Card: {insp.CardNumber}").WithDnDColour();

            //Alright
            embed.AddField(efb => efb.WithName(insp.Name).WithValue(insp.Description));

            //Embed
            await Context.Channel.BlankEmbedAsync(embed.Build());
        }
Exemple #2
0
        public async Task DeleteInspiration(int table, int card)
        {
            DndInspiration deleted = null;

            using (var uow = DBHandler.UnitOfWork())
            {
                deleted = uow.DndInspiration.RemoveInspiration(table, card);
            }

            if (deleted == null)
            {
                return;
            }

            //Ok good
            var embed = new EmbedBuilder().WithTitle($"Deleted Inspiration | Table: {deleted.TableNumber}, Card: {deleted.CardNumber}").WithDnDColour();

            //Alright
            embed.AddField(efb => efb.WithName(deleted.Name).WithValue(deleted.Description));

            //Embed
            await Context.Channel.BlankEmbedAsync(embed.Build());
        }
Exemple #3
0
        public async Task CheckInspiration(int table, int card)
        {
            DndInspiration checkedInsp = null;

            using (var uow = DBHandler.UnitOfWork())
            {
                checkedInsp = uow.DndInspiration.GetInspirationTableCard(table, card);
            }

            if (checkedInsp == null)
            {
                await Context.Channel.SendErrorAsync($"No inspiration exists in table {table} at position {card}");
            }

            //Ok good
            var embed = new EmbedBuilder().WithTitle($"Checked Inspiration | Table: {checkedInsp.TableNumber}, Card: {checkedInsp.CardNumber}").WithDnDColour();

            //Alright
            embed.AddField(efb => efb.WithName(checkedInsp.Name).WithValue(checkedInsp.Description));

            //Embed
            await Context.Channel.BlankEmbedAsync(embed.Build());
        }
Exemple #4
0
        public async Task Inspiration()
        {
            //Table weights
            List <Table> InspirationTables = new List <Table>()
            {
                new Table("Copper", 1, 10),
                new Table("Silver", 2, 6),
                new Table("Gold", 3, 3),
                new Table("Platinum", 4, 1)
            };

            //Get the total table weight
            int totalWeight = 0;

            foreach (Table t in InspirationTables)
            {
                totalWeight += t.Weight;
            }

            //Sort the table by the probability low to high
            InspirationTables = InspirationTables.OrderBy(x => x.Weight).ToList();

            //Roll the result
            Table selectedTable = new Table("", -1, -1);
            int   rngPick       = _random.Next(0, totalWeight);

            foreach (Table t in InspirationTables)
            {
                //If the weight is lower than the current table then we pick it
                if (rngPick < t.Weight)
                {
                    selectedTable = t;
                    break;
                }

                //This wont be reached if picked, if it is we knock the rngpick down by the weight and check again
                rngPick -= t.Weight;
            }

            //Something went badly
            if (selectedTable.TableNumber == -1)
            {
                await Context.Channel.SendErrorAsync("Error choosing table.");

                return;
            }

            DndInspiration chosenInspiration = null;
            int            cardNumber;

            using (var uow = DBHandler.UnitOfWork())
            {
                //Woo woo
                int totalCards = uow.DndInspiration.CountInTable(selectedTable.TableNumber);

                //Now we roll for a card using the amount in the selected table
                cardNumber = _random.Next(totalCards) + 1; //This rolls between 1-50 instead of 0-49.

                //Now we have the table and card number we just need to get it
                chosenInspiration = uow.DndInspiration.GetInspirationTableCard(selectedTable.TableNumber, cardNumber);
            }

            //Oh no
            if (chosenInspiration == null)
            {
                await Context.Channel.SendErrorAsync($"Error choosing inspiration from table: {selectedTable.Name}.");

                return;
            }

            //Embed
            var embed = new EmbedBuilder().WithDnDColour().WithTitle($"Dramatic Inspiration. | {selectedTable.Name} / {cardNumber}");

            //Add field
            embed.AddField(efb => efb.WithName(chosenInspiration.Name).WithValue(chosenInspiration.Description));

            //Send embed
            await Context.Channel.BlankEmbedAsync(embed.Build());
        }