Ejemplo n.º 1
0
        /**
         * I only need to compare the title to see if the spell is equal.
         */
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            CeleritySpell comparingObj = obj as CeleritySpell;

            if (comparingObj == null)
            {
                return(false);
            }
            return(this.title.Equals(comparingObj.title));
        }
Ejemplo n.º 2
0
        public List <CeleritySpell> readSpellList()
        {
            string        line = "";
            int           counter = 0;
            CeleritySpell previous = null, current = null;
            string        filename = "database\\celerity-spells.txt";

            System.IO.StreamReader file = new System.IO.StreamReader(filename);
            while ((line = file.ReadLine()) != null)
            {
                string[] stringList = line.Split('$');
                current = new CeleritySpell(stringList[0], stringList[1], stringList[2], stringList[3], stringList[4], stringList[5],
                                            stringList[6], stringList[7], stringList[8], stringList[9], stringList[10],
                                            stringList[11]);
                current.body.Replace("&", "\n\n");

                if (previous == null)
                {
                    cspell.Add(current);
                    previous = current;
                }
                else
                {
                    if (previous.Equals(current))
                    {
                        cspell[counter].addSpellLevel(current.getSpellLevel()[0]);
                    }
                    else
                    {
                        cspell.Add(current);
                        previous = current;
                        counter++;
                    }
                }
            }

            file.Close();
            return(this.cspell);
        }
Ejemplo n.º 3
0
            public async Task Spell(CommandContext ctx, params string[] args)
            {
                string spellClass = "";
                int    spellLevel = -1;
                bool   nameSearch = true;

                //Determine if user looked for name or spell class/level
                for (int i = 0; i < args.Length; i++)
                {
                    args[i] = args[i].ToLower();
                    if (args[i].Equals("class"))
                    {
                        spellClass = args[i + 1];
                        spellClass = Char.ToUpper(spellClass[0]) + spellClass.Substring(1);
                        nameSearch = false;
                    }
                    if (args[i].Equals("level"))
                    {
                        if (!Int32.TryParse(args[i + 1], out spellLevel))
                        {
                            await ctx.RespondAsync("Invalid spell level!");

                            return;
                        }
                        nameSearch = false;
                    }
                } // end validation

                // Loads spell database
                CelerityIO           cio            = new CelerityIO();
                List <CeleritySpell> celeritySpells = cio.readSpellList();

                if (nameSearch)
                {
                    // User is searching for spell name
                    string        name  = String.Join(" ", args);
                    bool          found = false;
                    CeleritySpell data  = null;
                    foreach (CeleritySpell cs in celeritySpells)
                    {
                        if (cs.title.ToLower().Equals(name))
                        {
                            found = true;
                            data  = cs;
                            break;
                        }
                    } // end foreach

                    if (!found)
                    {
                        await ctx.RespondAsync("Spell not found: " + name);

                        return;
                    }
                    else
                    {
                        // Found a corresponding spell
                        Console.WriteLine("Spell Found: " + name + "\n");
                        Console.WriteLine(data.ToString());
                        DiscordEmbedBuilder embed = new DiscordEmbedBuilder {
                            Title = data.title, Color = new DiscordColor(1621076), Url = data.link
                        };
                        if (!data.category.Equals("null"))
                        {
                            embed.AddField("Category", data.category);
                        }
                        embed.AddField("Class Level", data.spellLevelsToString());
                        if (!data.components.Equals("null"))
                        {
                            embed.AddField("Components", data.components);
                        }
                        if (!data.castingTime.Equals("null"))
                        {
                            embed.AddField("Casting Time", data.castingTime);
                        }
                        if (!data.range.Equals("null"))
                        {
                            embed.AddField("Range", data.range);
                        }
                        if (!data.target.Equals("null"))
                        {
                            embed.AddField("Target", data.target);
                        }
                        if (!data.duration.Equals("null"))
                        {
                            embed.AddField("Duration", data.duration);
                        }
                        if (!data.effect.Equals("null"))
                        {
                            embed.AddField("Effect", data.effect);
                        }
                        if (!data.savingThrow.Equals("null"))
                        {
                            embed.AddField("Saving Throw", data.savingThrow);
                        }
                        embed.AddField("Description", data.body);

                        await ctx.RespondAsync(embed : embed);

                        return;
                    }
                }
                else
                {
                    List <string> result = new List <string>();
                    int           match  = 0;
                    foreach (CeleritySpell cs in celeritySpells)
                    {
                        foreach (CeleritySpell.SpellLevel sl in cs.spellLevel)
                        {
                            bool found = true;
                            // If spell class is to be found
                            if (!spellClass.Equals(""))
                            {
                                if (!sl.caster.Equals(spellClass))
                                {
                                    found = false;
                                }
                            }
                            // If spell level is to be found
                            if (spellLevel != -1)
                            {
                                if (sl.level != spellLevel)
                                {
                                    found = false;
                                }
                            }
                            if (found)
                            {
                                match++;
                                result.Add(cs.title);
                                break;
                            }
                        }
                    } // end foreach
                    string ret = "";
                    if (result.Count() == 0)
                    {
                        ret = "None";
                    }
                    else
                    {
                        ret = String.Join("\n", result);
                    }
                    Console.WriteLine("Result length: " + ret.Length.ToString());

                    DiscordEmbedBuilder embed = new DiscordEmbedBuilder {
                        Title = "Search Result", Color = new DiscordColor(1621076)
                    };
                    if (ret.Length <= 1024)
                    {
                        embed.AddField(match.ToString() + " results found", ret);
                    }
                    else
                    {
                        embed.AddField(match.ToString() + " results found", ret.Substring(0, 1024));
                        int  counter = 1;
                        bool stop    = false;
                        while (!stop)
                        {
                            int lineLength = 1024;
                            if (ret.Length <= 1024 * (counter + 1))
                            {
                                stop       = true;
                                lineLength = ret.Length - (1024 * counter);
                            }
                            embed.AddField("--", ret.Substring(1024 * counter, lineLength));
                            counter++;
                        }
                    }

                    await ctx.RespondAsync(embed : embed);

                    return;
                }
            }