diff options
Diffstat (limited to 'DiscoBot')
-rw-r--r-- | DiscoBot/App.config | 16 | ||||
-rw-r--r-- | DiscoBot/Char.cs | 145 | ||||
-rw-r--r-- | DiscoBot/Character.cs | 309 | ||||
-rw-r--r-- | DiscoBot/CommandExtension.cs | 47 | ||||
-rw-r--r-- | DiscoBot/Commands.cs | 324 | ||||
-rw-r--r-- | DiscoBot/DSA.cs | 38 | ||||
-rw-r--r-- | DiscoBot/DiscoBot.csproj | 90 | ||||
-rw-r--r-- | DiscoBot/ICharacter.cs | 23 | ||||
-rw-r--r-- | DiscoBot/Misc.cs | 162 | ||||
-rw-r--r-- | DiscoBot/NPC.cs | 107 | ||||
-rw-r--r-- | DiscoBot/Program.cs | 2 | ||||
-rw-r--r-- | DiscoBot/Properties/Settings.Designer.cs | 38 | ||||
-rw-r--r-- | DiscoBot/Properties/Settings.settings | 9 | ||||
-rw-r--r-- | DiscoBot/packages.config | 38 |
14 files changed, 1104 insertions, 244 deletions
diff --git a/DiscoBot/App.config b/DiscoBot/App.config index f107529..5740218 100644 --- a/DiscoBot/App.config +++ b/DiscoBot/App.config @@ -1,5 +1,10 @@ <?xml version="1.0" encoding="utf-8"?> <configuration> + <configSections> + <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > + <section name="DiscoBot.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /> + </sectionGroup> + </configSections> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> </startup> @@ -17,6 +22,17 @@ <assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" /> </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-1.2.2.0" newVersion="1.2.2.0" /> + </dependentAssembly> </assemblyBinding> </runtime> + <userSettings> + <DiscoBot.Properties.Settings> + <setting name="Token" serializeAs="String"> + <value>Mjk0NTU0MDU4Nzg4NzAwMTYx.DOzDcQ.J-nCikbZdZtdrug0E8TwwV_2ITw</value> + </setting> + </DiscoBot.Properties.Settings> + </userSettings> </configuration> diff --git a/DiscoBot/Char.cs b/DiscoBot/Char.cs deleted file mode 100644 index 45d975e..0000000 --- a/DiscoBot/Char.cs +++ /dev/null @@ -1,145 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml; - -namespace DiscoBot -{ - public class Char - { - - public string name; //charname - public Dictionary<string, int> eigenschaften = new Dictionary<string, int>(); //char porperties - public List<Talent> talente = new List<Talent>(); //ist of talent objects (talents and spells) - public List<Kampf> kampftalente = new List<Kampf>(); //list of combat objects - - public Dictionary<string, string> Proptable = new Dictionary<string, string>(); //KK -> Körperkraft - - - public Char(String path ) - { - - Load(path); //load - } - - private void Load(string path) - { - XmlTextReader reader = new XmlTextReader(path); - while (reader.Read()) //read until he hits keywords - { - if (reader.NodeType == XmlNodeType.Element) - switch (reader.Name) - { - case "held": - name = reader.GetAttribute("name"); //name - break; - case "eigenschaft": - eigenschaften.Add(reader.GetAttribute("name"), Convert.ToInt32(reader.GetAttribute("value")) + Convert.ToInt32(reader.GetAttribute("mod"))); - break; - case "talentliste": - reader.Read(); - while (reader.Name.Equals("talent")) - { - talente.Add(new Talent(reader.GetAttribute("name"), reader.GetAttribute("probe").Remove(0, 2).Trim(')'), Convert.ToInt32(reader.GetAttribute("value")))); - reader.Read(); - } - break; - case "zauberliste": - reader.Read(); - while (reader.Name.Equals("zauber")) - { - talente.Add(new Talent(reader.GetAttribute("name"), reader.GetAttribute("probe").Remove(0, 2).Trim(')'), Convert.ToInt32(reader.GetAttribute("value")))); - reader.Read(); - } - break; - case "kampfwerte": - string atname = reader.GetAttribute("name"); - reader.Read(); - int at = Convert.ToInt32(reader.GetAttribute("value")); - reader.Read(); - int pa = Convert.ToInt32(reader.GetAttribute("value")); - kampftalente.Add(new Kampf(atname, at, pa)); - break; - } - - - - } - Proptable.Add("MU", "Mut"); //routing - Proptable.Add("KL", "Klugheit"); - Proptable.Add("IN", "Intuition"); - Proptable.Add("CH", "Charisma"); - Proptable.Add("FF", "Fingerfertigkeit"); - Proptable.Add("GE", "Gewandtheit"); - Proptable.Add("KO", "Konstitution"); - Proptable.Add("KK", "Körperkraft"); - - } - public string TestTalent(string talent) //Talentprobe - { - var output = new StringBuilder(); - var ttalentlist = talente.Select(v => v.CheckName(talent)).ToList(); //find the talent - int error = ttalentlist.Min(); - var ttalent = talente[ttalentlist.IndexOf(error)]; - var props = ttalent.Test(); //get the required properties - int tap = ttalent.value; //get tap - List<int> werte = new List<int>(); - foreach (string p in props) - { - werte.Add(eigenschaften[Proptable[p]]); - } - output.AppendFormat("{0} würfelt: {1} \n{2} - {3} taw:{4} \n", this.name,ttalent.name,ttalent.probe,String.Join("/",werte),ttalent.value); - output.Append(" "); - for (int i = 0; i <= 2; i++) //foreach property, dice and tap - { - int temp = dice.Roll(); - int eigenschaft = eigenschaften[Proptable[props[i]]]; - if (eigenschaft < temp) - tap -= temp - eigenschaft; - output.Append("["+temp + "]"); //add to string - } - - output.AppendFormat(" tap: {0,20}",tap); - if (error == 100) - return talent + " nicht gefunden!"; - return output.ToString(); //return output - } - public string Angriff(string talent) //prety self explanetory - { - var output = new StringBuilder(); - var attack = kampftalente.Find(x => x.name.ToLower().Equals(talent.ToLower())); - int tap = attack.at; - output.AppendFormat("{0}-Angriff taw:{1} \n", attack.name, tap); - int temp = dice.Roll(); - output.Append(temp ); - return output.ToString(); - } - public string Parade(string talent) - { - var output = new StringBuilder(); - var attack = kampftalente.Find(x => x.name.ToLower().Equals(talent.ToLower())); - int tap = attack.pa; - output.AppendFormat("{0}-Parade taw:{1} \n", attack.name, tap); - int temp = dice.Roll(); - output.Append(temp); - return output.ToString(); - } - public string Fernkampf(string talent,int erschwernis=0) - { - var output = new StringBuilder(); - int fk = eigenschaften["fk"]; - var attack = talente.Find(v => v.name.ToLower().Equals(talent.ToLower())); - int tap = attack.value ; - output.AppendFormat("{0} taw:{1} erschwernis:{2} \n", attack.name, tap,erschwernis); - tap -= erschwernis; - int temp = dice.Roll(); - tap -= temp>fk?temp-fk:0; - output.Append(temp + " tap:" + tap); - return output.ToString(); - } - - } - -} diff --git a/DiscoBot/Character.cs b/DiscoBot/Character.cs new file mode 100644 index 0000000..18b6213 --- /dev/null +++ b/DiscoBot/Character.cs @@ -0,0 +1,309 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml; + +namespace DiscoBot +{ + public class Character : ICharacter + { + public string Name { get; set; } //charname + public Dictionary<string, int> Eigenschaften = new Dictionary<string, int>(); //char porperties + public List<Talent> Talente = new List<Talent>(); //ist of talent objects (talents and spells) + public List<Kampf> Kampftalente = new List<Kampf>(); //list of combat objects + public List<Vorteil> Vorteile = new List<Vorteil>(); + + public Dictionary<string, string> Proptable = new Dictionary<string, string>(); //KK -> Körperkraft + + + public Character(String path) + { + Load(path); //load + Proptable.Add("MU", "Mut"); //routing + Proptable.Add("KL", "Klugheit"); + Proptable.Add("IN", "Intuition"); + Proptable.Add("CH", "Charisma"); + Proptable.Add("FF", "Fingerfertigkeit"); + Proptable.Add("GE", "Gewandtheit"); + Proptable.Add("KO", "Konstitution"); + Proptable.Add("KK", "Körperkraft"); + } + + public Character(Character c, string name, int stDv = 2) + { + Proptable.Add("MU", "Mut"); //routing + Proptable.Add("KL", "Klugheit"); + Proptable.Add("IN", "Intuition"); + Proptable.Add("CH", "Charisma"); + Proptable.Add("FF", "Fingerfertigkeit"); + Proptable.Add("GE", "Gewandtheit"); + Proptable.Add("KO", "Konstitution"); + Proptable.Add("KK", "Körperkraft"); + this.Proptable.Add("**", "Klugheit"); + + this.Name = name; + foreach (var i in c.Eigenschaften) + { + this.Eigenschaften.Add(i.Key, i.Value + (int)Math.Round(Misc.Random(stDv))); + } + + foreach (var i in c.Vorteile) + { + this.Vorteile.Add(new Vorteil(i.name, i.value + (int)Math.Round(Misc.Random(stDv)))); + } + + foreach (var i in c.Talente) + { + this.Talente.Add(new Talent(i.name, i.probe, i.value + (int)Math.Round(Misc.Random(stDv)))); + } + + foreach (var i in c.Kampftalente) + { + this.Kampftalente.Add(new Kampf(i.name, i.at + (int)Math.Round(Misc.Random(stDv)), i.pa + (int)Math.Round(Misc.Random(stDv)))); + } + } + + private void Load(string path) + { + XmlTextReader reader = new XmlTextReader(path); + while (reader.Read()) //read until he hits keywords + { + if (reader.NodeType == XmlNodeType.Element) + { + + switch (reader.Name) + { + case "Wesen": + reader.Skip(); + break; + case "held": + Name = reader.GetAttribute("name"); //name + break; + case "eigenschaft": + Eigenschaften.Add( + reader.GetAttribute("name"), + Convert.ToInt32(reader.GetAttribute("value")) + + Convert.ToInt32(reader.GetAttribute("mod"))); + break; + case "vt": + reader.Read(); + while (reader.Name.Equals("vorteil")) + { + try + { + this.Vorteile.Add(new Vorteil( + reader.GetAttribute("name"), + Convert.ToInt32(reader.GetAttribute("value")))); + } + catch + { + this.Vorteile.Add(new Vorteil(reader.GetAttribute("name"))); + } + reader.Read(); + } + + break; + case "talentliste": + reader.Read(); + while (reader.Name.Equals("talent")) + { + Talente.Add( + new Talent( + reader.GetAttribute("name"), + reader.GetAttribute("probe").Remove(0, 2).Trim(')'), + Convert.ToInt32(reader.GetAttribute("value")))); + reader.Read(); + } + break; + case "zauberliste": + reader.Read(); + while (reader.Name.Equals("zauber")) + { + Talente.Add( + new Talent( + reader.GetAttribute("name"), + reader.GetAttribute("probe").Remove(0, 2).Trim(')'), + Convert.ToInt32(reader.GetAttribute("value")))); + reader.Read(); + } + break; + case "kampfwerte": + string atname = reader.GetAttribute("name"); + reader.Read(); + int at = Convert.ToInt32(reader.GetAttribute("value")); + reader.Read(); + int pa = Convert.ToInt32(reader.GetAttribute("value")); + Kampftalente.Add(new Kampf(atname, at, pa)); + break; + } + } + } + + + } + + public string TestTalent(string talent, int erschwernis = 0) //Talentprobe + { + try + { + var output = new StringBuilder(); + var sc = new SpellCorrect(); + var ttalent = Talente.OrderBy(x => sc.Compare(talent, x.name)).First(); + + var deug = Talente.OrderBy(x => sc.Compare(talent, x.name)); + var fit = deug.Select(x => sc.Compare(talent, x.name)); + + if (sc.Compare(talent, ttalent.name) > 94100) throw new Exception(); + + var props = ttalent.Test(); //get the required properties + int tap = ttalent.value; //get tap + var werte = props.Select(p => this.Eigenschaften[this.Proptable[p]]).ToList(); + + output.AppendFormat( + "{0} würfelt: {1} \n{2} - {3} taw:{4} {5} \n", + this.Name, + ttalent.name, + ttalent.probe, + String.Join("/", werte), + ttalent.value, + erschwernis.Equals(0) ? string.Empty : "Erschwernis: " + erschwernis); + + output.Append(" "); + tap -= erschwernis; + int gesamt_erschwernis = tap; + if (gesamt_erschwernis < 0) + { + tap = 0; + for (int i = 0; i <= 2; i++) //foreach property, dice and tap + { + int temp = dice.Roll(); + int eigenschaft = Eigenschaften[Proptable[props[i]]]; + + if (eigenschaft - gesamt_erschwernis < temp) + { + tap -= temp - eigenschaft + gesamt_erschwernis; + } + + output.Append($"[{temp}]"); //add to string + } + + if (tap >= 0) + { + tap = 1; + } + } + else + { + for (int i = 0; i <= 2; i++) //foreach property, dice and tap + { + int temp = dice.Roll(); + int eigenschaft = Eigenschaften[Proptable[props[i]]]; + + if (eigenschaft < temp) + { + tap -= temp - eigenschaft; + } + output.Append($"[{temp}]"); //add to string + } + } + + tap = tap == 0 ? 1 : tap; + + output.AppendFormat(" tap: {0,2}", tap); + + return output.ToString(); //return output + } + catch (Exception) + { + throw new Exception( + $"{talent} nicht vorhanden! Besitzt {Name} {talent} nicht? \n Oder ist {talent} falsch geschrieben?"); + } + } + + public string TestEigenschaft(string eigenschaft, int erschwernis = 0) + { + var output = new StringBuilder(); + var prop = this.Proptable[eigenschaft.ToUpper()]; + int tap = this.Eigenschaften[prop]; + output.AppendFormat( + "{0}-Eigenschaftsprobe ew:{1} {2} \n", + prop, + tap, + erschwernis.Equals(0) ? string.Empty : "Erschwernis: " + erschwernis); + int roll = dice.Roll(); + output.Append($"Gewürfelt: {roll} übrig: {tap - roll - erschwernis}"); + return output.ToString(); + } + + public string Angriff(string talent, int erschwernis = 0) //prety self explanetory + { + var output = new StringBuilder(); + var sc = new SpellCorrect(); + var attack = Kampftalente.OrderBy(x => sc.Compare(talent, x.name)).First(); + if (sc.Compare(talent, attack.name) > 94) + { + return $"{this.Name} kann nicht mit der Waffenart {talent} umgehen..."; + } + + int tap = attack.at; + output.AppendFormat("{0}-Angriff taw:{1} {2} \n", + attack.name, + tap, + erschwernis.Equals(0) ? string.Empty : "Erschwernis: " + erschwernis); + + int temp = dice.Roll(); + output.Append(temp - erschwernis); + return output.ToString(); + } + public string Parade(string talent, int erschwernis = 0) + { + var output = new StringBuilder(); + var sc = new SpellCorrect(); + var attack = Kampftalente.OrderBy(x => sc.Compare(talent, x.name)).First(); + + if (sc.Compare(talent, attack.name) > 94) + { + return $"{this.Name} kann nicht mit der Waffenart {talent} umgehen..."; + } + + int tap = attack.pa; + output.AppendFormat( + "{0}-Parade taw:{1} {2}\n", + attack.name, + tap, + erschwernis.Equals(0) ? string.Empty : "Erschwernis: " + erschwernis); + + int temp = dice.Roll(); + output.Append(temp - erschwernis); + return output.ToString(); + } + + public string Fernkampf(string talent, int erschwernis = 0) + { + var output = new StringBuilder(); + var sc = new SpellCorrect(); + int fk = Eigenschaften["fk"]; + var attack = Talente.OrderBy(x => sc.Compare(talent, x.name)).First(); + if(sc.Compare(talent, attack.name) > 94) + { + return $"{this.Name} kann nicht mit der Waffenart {talent} umgehen..."; + } + + int tap = attack.value; + output.AppendFormat( + "{0} taw:{1} {2} \n", + attack.name, + tap, + erschwernis.Equals(0) ? string.Empty : "Erschwernis: " + erschwernis); + tap -= erschwernis; + int temp = dice.Roll(); + tap -= temp > fk ? temp - fk : 0; + output.Append($"W20: {temp} tap: {tap}"); + return output.ToString(); + } + + } + +} diff --git a/DiscoBot/CommandExtension.cs b/DiscoBot/CommandExtension.cs new file mode 100644 index 0000000..06eec92 --- /dev/null +++ b/DiscoBot/CommandExtension.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DiscoBot +{ + using System.ComponentModel; + using System.Threading; + using Discord; + using Discord.Commands; + + public static class CommandExtension + { + public static async Task ReplyTimed(this ModuleBase m, string message, TimeSpan time) + { + var token = message.GetHashCode(); + var send = m.Context.Channel.SendMessageAsync($"#{token}\n```xl\n{message}```", true); + + BackgroundWorker barInvoker = new BackgroundWorker(); + barInvoker.DoWork += delegate + { + Thread.Sleep(time); + delete(token, m); + }; + + await send; + barInvoker.RunWorkerAsync(); + } + + private static async void delete(int token, ModuleBase m) + { + var messagesAsync = m.Context.Channel.GetMessagesAsync(100); + Task.WaitAll(messagesAsync.ToArray()); + var list = messagesAsync.ToEnumerable().ToList(); + var messages = new List<IMessage>(); + foreach (var task in list) + { + messages.AddRange(task.ToList()); + } + + await m.Context.Channel.DeleteMessagesAsync(messages.Where(x => x.Content.StartsWith($"#{token}\n") && x.Author.IsBot)); + } + } + +} diff --git a/DiscoBot/Commands.cs b/DiscoBot/Commands.cs index 7459451..55ad530 100644 --- a/DiscoBot/Commands.cs +++ b/DiscoBot/Commands.cs @@ -10,32 +10,19 @@ using Discord.WebSocket; namespace DiscoBot { - public static class DSA - { - public static Dictionary<string, string> relation = new Dictionary<string, string>(); //dictionary to match the char - public static List<Char> chars = new List<Char>(); //list of all charackters - public static void Startup() - { - relation.Add("The Doctor", "Numeri Illuminus");//Relation - relation.Add("Tardis", "Numeri Illuminus"); - relation.Add("DSA Bot", "Felis Exodus Schattenwald"); - relation.Add("Papo","Gwendelson"); - relation.Add("Potus","Volant"); - chars.Add(new Char(@"helden\Felis.xml")); //Savefile - chars.Add(new Char(@"helden\Numeri.xml")); - chars.Add(new Char(@"helden\Volant.xml")); + using System.ComponentModel; + using System.Diagnostics.CodeAnalysis; + using System.Threading; - } - } public class Info : ModuleBase { [Command("say"), Summary("Echos a message.")] + [Alias("s")] public async Task Say([Remainder, Summary("The text to echo")] string echo) { - var a = Context.User.Username; - + var a = Context.User.Username; + await ReplyAsync(echo); - } } @@ -45,31 +32,63 @@ namespace DiscoBot [Alias("R", "Roll", "roll", "Würfle")] public async Task Say([Remainder, Summary("Weapon")] string roll) { - await ReplyAsync("```xl\n" + Misc.Roll(roll) + "\n```"); + } + } + public class SetGeneral : ModuleBase + { + [Command("general"), Summary("Set General ")] + public async Task Say([Remainder, Summary("Set General")] int i = 0) + { + DSA.GeneralContext = this.Context; + await this.Context.Channel.SendMessageAsync($"```xl\n Der Dachs hat in '{this.Context.Channel.Name}' ein Zuhause gefunden. Gm Nachrichten werden nun auch in diesem Channel gepostet. \n```"); } } + [SuppressMessage("ReSharper", "PublicMembersMustHaveComments", Justification = "OK")] public class TestTalent : ModuleBase { [Command("t"), Summary("Würfelt ein Talent-/Zauberprobe")] - [Alias("T", "Talent", "talent","zauber","z", "versuche")] - public async Task Say([Remainder, Summary("Talent oder Zaubername")] string talent) + [Alias("T", "Talent", "talent", "zauber", "z", "versuche")] + public async Task Say([Summary("Talent oder Zaubername")] string talent, int erschwernis = 0) { + string res = Gm.CheckCommand(DSA.relation[Context.User.Username], Commands.Talent, talent, erschwernis); + await this.ReplyAsync("```xl\n" + res + "\n```"); + + var tmessages = this.Context.Channel.GetMessagesAsync(10); + Task.WaitAll(tmessages.ToArray()); + var list = tmessages.ToEnumerable().ToList(); + var messages = new List<IMessage>(); + foreach (var task in list) + { + messages.AddRange(task.ToList()); + } - await ReplyAsync("```xl\n" + DSA.chars.Find(x=>x.name.Equals(DSA.relation[Context.User.Username])).TestTalent(talent) + "\n```"); + //await this.Context.Channel.DeleteMessagesAsync(messages.Where(x => x.Content[0].Equals('!') && (x.Author as SocketGuildUser).Roles.ToList().Exists(v => v.Name.Equals("Meister")))); + } + } + + public class TestEigenschaft : ModuleBase + { + [Command("e"), Summary("Würfelt eine Eifenschaftsprobe")] + [Alias("E", "Eigenschaft", "eigenschaft", "eigen")] + public async Task Say([Summary("Eigenschafts kürzel und Erschwernis")] string talent, int erschwernis = 0) + { + var chr = DSA.chars.Find(x => x.Name.Equals(DSA.relation[Context.User.Username])); + string res = chr.TestEigenschaft(talent, erschwernis); + await this.ReplyAsync("```xl\n" + res + "\n```"); } } + public class Angriff : ModuleBase { [Command("a"), Summary("Würfelt ein Angriff")] - [Alias("A", "Angriff", "angriff", "attackiere_mit","attacke","Attacke")] - public async Task Say([Remainder, Summary("Weapon")] string weapon) + [Alias("At", "at", "Angriff", "angriff", "attackiere_mit", "attacke", "Attacke")] + public async Task Say([Summary("Weapon")] string weapon, int erschwernis = 0) { - - await ReplyAsync("```xl\n" + DSA.chars.Find(x => x.name.Equals(DSA.relation[Context.User.Username])).Angriff(weapon) + "\n```"); + await ReplyAsync("```xl\n" + DSA.chars.Find(x => x.Name.Equals(DSA.relation[Context.User.Username])).Angriff(weapon, erschwernis) + "\n```"); } } @@ -77,10 +96,10 @@ namespace DiscoBot { // ~say hello -> hello [Command("p"), Summary("Würfelt eine Parade Probe")] - [Alias("P", "Parade", "parade","pariere_mit")] - public async Task Say([Remainder, Summary("Parade Weapon")] string talent) + [Alias("P", "Parade", "parade", "pariere_mit")] + public async Task Say([Summary("Parade Weapon")] string talent, int erschwernis = 0) { - await ReplyAsync("```xl\n" + DSA.chars.Find(x => x.name.Equals(DSA.relation[Context.User.Username])).Parade(talent) + "\n```"); + await ReplyAsync("```xl\n" + DSA.chars.Find(x => x.Name.Equals(DSA.relation[Context.User.Username])).Parade(talent, erschwernis) + "\n```"); } } @@ -89,16 +108,40 @@ namespace DiscoBot // ~say hello -> hello [Command("f"), Summary("Führt eine Fernkampfprobe aus")] [Alias("F", "fernkampf", "Fernkampf", "schieße", "schieße_mit")] - public async Task Say([Summary("Fernkampfwaffe")] string talent,int erschwernis=0) + public async Task Say([Summary("Fernkampfwaffe")] string waffe, int erschwernis = 0) { // ReplyAsync is a method on ModuleBase + await ReplyAsync("```xl\n" + DSA.chars.Find(x => x.Name.Equals(DSA.relation[Context.User.Username])).Fernkampf(waffe, erschwernis) + "\n```"); + } + public async Task Say([Summary("Fernkampfwaffe")] string charName, string waffe, ICommandContext context, int erschwernis = 0) + { + // ReplyAsync is a method on ModuleBase + await context.Channel.SendMessageAsync("Hello World\n"); + await context.Channel.SendMessageAsync("```xl\n" + DSA.chars.Find(x => x.Name.Equals(charName)).Fernkampf(waffe, erschwernis) + "\n```"); + } + } - await ReplyAsync("```xl\n" + DSA.chars.Find(x => x.name.Equals(DSA.relation[Context.User.Username])).Fernkampf(talent,erschwernis) + "\n```"); + public class Voice : ModuleBase + { + [Command("join")] + public async Task JoinChannel(IVoiceChannel channel = null) + { + // Get the audio channel + channel = channel ?? (this.Context.User as IGuildUser)?.VoiceChannel; + if (channel == null) + { + await this.Context.Channel.SendMessageAsync( + "User must be in a voice channel, or a voice channel must be passed as an argument."); + return; + } + // For the next step with transmitting audio, you would want to pass this Audio Client in to a service. + var audioClient = await channel.ConnectAsync(); + } } - [Group("sample")] + [Group("gmtr")] public class Sample : ModuleBase { // ~sample square 20 -> 400 @@ -108,7 +151,7 @@ namespace DiscoBot // We can also access the channel from the Command Context. await Context.Channel.SendMessageAsync($"{num}^2 = {Math.Pow(num, 2)}"); } - + [Command("userinfo"), Summary("Returns info about the current user, or the user parameter, if one passed.")] [Alias("user", "whois")] public async Task UserInfo([Summary("The (optional) user to get info for")] IUser user = null) @@ -118,4 +161,217 @@ namespace DiscoBot } } + public class List : ModuleBase + { + // ~say hello -> hello + [Command("list"), Summary("gibt eine Auflistung aus")] + public async Task Say([Summary("Aktion")] string prop) + { + var res = new List<string>(); + switch (prop.ToLower()) + { + case "chars": + case "Chars": + res.AddRange(DSA.chars.Select(x => x.Name)); + break; + case "t": + case "ta": + case "talent": + case "zauber": + res.AddRange( + ((Character)DSA.chars.Find(x => x.Name.Equals(DSA.relation[this.Context.User.Username]))) + .Talente.Select(s => s.name + "\t " + s.value + "\t " + s.probe)); + break; + case "w": + case "waffe": + case "waffen": + res.AddRange( + ((Character)DSA.chars.Find(x => x.Name.Equals(DSA.relation[this.Context.User.Username]))) + .Kampftalente.Select(s => s.name)); + break; + case "fern": + res.AddRange( + ((Character)DSA.chars.Find(x => x.Name.Equals(DSA.relation[this.Context.User.Username]))) + .Talente.Select(s => s.name)); + break; + case "v": + case "vt": + case "vor": + case "vorteil": + res.AddRange( + ((Character)DSA.chars.Find(x => x.Name.Equals(DSA.relation[this.Context.User.Username]))) + .Vorteile + .Select(s => s.name + "\t " + (s.value == 0 ? "" : s.value.ToString()))); + break; + + default: + res.Add($"Kommando {prop} nicht gefunden"); + break; + } + + //await this.ReplyAsync(res.Aggregate((seed, next) => seed + "\n" + next)); + var sb = new StringBuilder(); + foreach (string re in res) + { + if (sb.Length + re.Length > 1798) + { + await this.ReplyTimed(sb.ToString(), TimeSpan.FromSeconds(90)); + sb.Clear(); + } + + sb.AppendLine(re); + } + + await this.ReplyTimed(sb.ToString(), TimeSpan.FromSeconds(90)); + } + + } + + public class Gm : ModuleBase + { + // ~say hello -> hello + [Command("gm"), Summary("Führt eine probe aus")] + [Alias("GM", "as", "As", "als")] + public async Task Say([Summary("Fernkampfwaffe")] string name, string command, string waffe, int erschwernis = 0) + { + if (!(this.Context.User as SocketGuildUser).Roles.ToList().Exists(v => v.Name.Equals("Meister"))) + { + await ReplyAsync("```xl\n Keine ausreichenden Berechtigunen\n```"); + return; + } + + command = command.ToLower(); + string res; + switch (command) + { + case "f": + case "fern": + case "fernkampf": + res = CheckCommand(name, Commands.Fernkampf, waffe, erschwernis); + break; + case "t": + case "ta": + case "talent": + res = CheckCommand(name, Commands.Talent, waffe, erschwernis); + break; + case "e": + case "ei": + case "eigenschaft": + res = CheckCommand(name, Commands.Eigenschaft, waffe, erschwernis); + break; + case "z": + case "za": + case "zauber": + case "magie": + case "m": + res = CheckCommand(name, Commands.Talent, waffe, erschwernis); + break; + case "a": + case "at": + case "an": + case "angrif": + case "angriff": + res = CheckCommand(name, Commands.Angriff, waffe, erschwernis); + break; + case "p": + case "pa": + case "parade": + res = CheckCommand(name, Commands.Parade, waffe, erschwernis); + break; + case "talente": + throw new NotImplementedException(); + default: + res = $"Kommando {command} nicht gefunden"; + break; + } + + if (DSA.GeneralContext != null) + { + if (DSA.GeneralContext.Channel.Id != Context.Channel.Id) + { + await DSA.GeneralContext.Channel.SendMessageAsync("```xl\n" + res + "\n```"); + } + + await ReplyAsync("```xl\n" + res + "\n```"); + } + else + { + await ReplyAsync("```xl\n" + res + "\n```"); + } + } + + public static string CheckCommand(string name, Commands command, string waffe, int erschwernis = 0) + { + var comp = new SpellCorrect(); + var chr = DSA.chars.OrderBy(x => comp.Compare(x.Name, name)).First(); + switch (command) + { + case Commands.Talent: + return chr.TestTalent(waffe, erschwernis); + case Commands.Eigenschaft: + return chr.TestEigenschaft(waffe, erschwernis); + case Commands.Angriff: + return chr.Angriff(waffe, erschwernis); + case Commands.Parade: + return chr.Parade(waffe, erschwernis); + case Commands.Fernkampf: + return chr.Fernkampf(waffe, erschwernis); + } + + return $"{name} verwendet {waffe}"; + } + } + + public class GenerateNpc : ModuleBase + { + // ~say hello -> hello + [Command("npc"), Summary("Erstellt ein NPC")] + [Alias("Npc", "NPc", "NPC", "nPC")] + public async Task Say([Summary("Create Random")] string npcName, int mean = 9, int stDv = 1) + { + DSA.chars.Add(new NPC(npcName, mean, stDv)); + await this.ReplyAsync($"{npcName} wurde zufällig generiert"); + } + } + + public class CopyNpc : ModuleBase + { + // ~say hello -> hello + [Command("npc"), Summary("Erstellt ein NPC")] + [Alias("Npc", "NPc", "NPC", "nPC")] + public async Task Say([Summary("Create Copy")] string npcName, string source, int stDv = 1) + { + if (DSA.chars.Exists(x => x.Name.Equals(npcName))) + { + throw new Exception("Char gibt es schon"); + } + + var comp = new SpellCorrect(); + var chr = DSA.chars.OrderBy(x => comp.Compare(x.Name, source)).First(); + DSA.chars.Add(new Character(chr as Character, npcName, stDv)); + await ReplyAsync($"{npcName} wurde als variierte Kopie von {source} erstellt"); + } + } + + public class NpcAction : ModuleBase + { + // ~say hello -> hello + [Command("npc"), Summary("Führt eine NPC-Probe aus")] + [Alias("Npc", "NPc", "NPC", "nPC")] + public async Task Say([Summary("Aktion")] string NpcName, string command, string Aktion, int erschwernis = 0) + { + string test = ""; + } + } + + + public enum Commands + { + Talent, + Eigenschaft, + Angriff, + Parade, + Fernkampf, + KeinChar + } } diff --git a/DiscoBot/DSA.cs b/DiscoBot/DSA.cs new file mode 100644 index 0000000..60b25ce --- /dev/null +++ b/DiscoBot/DSA.cs @@ -0,0 +1,38 @@ +namespace DiscoBot +{ + using System.Collections.Generic; + using System.IO; + using System.Linq; + + using Discord.Commands; + + public static class DSA + { + public static ICommandContext GeneralContext { get; set; } + public static Dictionary<string, string> relation = new Dictionary<string, string>(); //dictionary to match the char + public static List<ICharacter> chars = new List<ICharacter>(); //list of all charackters + + public static List<Talent> Talente { get; set; } = new List<Talent>(); + + public static void Startup() + { + relation.Add("The Doctor", "Numeri Illuminus");//Relation + relation.Add("Tardis", "Morla");//"Numeri Illuminus"); + relation.Add("DSA Bot", "Morla");//"Felis Exodus Schattenwald"); + relation.Add("Morla", "Morla"); + relation.Add("Rhoktar", "Rhoktar4"); + //relation.Add("Papo","Gwendelson"); + relation.Add("Papo", "Pump aus der Gosse"); + relation.Add("Potus", "Potus"); + //relation.Add("Papo", "Pump aus der Gosse"); + foreach (var filename in Directory.GetFiles("helden", "*.xml")) + { + chars.Add(new Character(filename)); + (chars.Last() as Character)?.Talente.Select(x => new Talent(x.name, x.probe, 0)) + .Where(c => !Talente.Exists(v => v.name.Equals(c.name))).ToList().ForEach(v => Talente.Add(v)); + } + + Talente = Talente.OrderBy(x => x.name).ToList(); + } + } +}
\ No newline at end of file diff --git a/DiscoBot/DiscoBot.csproj b/DiscoBot/DiscoBot.csproj index d4f3290..91ce25e 100644 --- a/DiscoBot/DiscoBot.csproj +++ b/DiscoBot/DiscoBot.csproj @@ -12,6 +12,8 @@ <FileAlignment>512</FileAlignment> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <TargetFrameworkProfile /> + <NuGetPackageImportStamp> + </NuGetPackageImportStamp> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> @@ -33,51 +35,53 @@ <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> - <Reference Include="Discord.Net.Commands, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL"> - <HintPath>..\packages\Discord.Net.Commands.1.0.1\lib\netstandard1.1\Discord.Net.Commands.dll</HintPath> + <Reference Include="Discord.Net.Commands, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>..\packages\Discord.Net.Commands.1.0.2\lib\netstandard1.1\Discord.Net.Commands.dll</HintPath> </Reference> - <Reference Include="Discord.Net.Core, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL"> - <HintPath>..\packages\Discord.Net.Core.1.0.1\lib\net45\Discord.Net.Core.dll</HintPath> + <Reference Include="Discord.Net.Core, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>..\packages\Discord.Net.Core.1.0.2\lib\net45\Discord.Net.Core.dll</HintPath> </Reference> - <Reference Include="Discord.Net.Rest, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL"> - <HintPath>..\packages\Discord.Net.Rest.1.0.1\lib\net45\Discord.Net.Rest.dll</HintPath> + <Reference Include="Discord.Net.Rest, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>..\packages\Discord.Net.Rest.1.0.2\lib\net45\Discord.Net.Rest.dll</HintPath> </Reference> - <Reference Include="Discord.Net.Rpc, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL"> - <HintPath>..\packages\Discord.Net.Rpc.1.0.1\lib\net45\Discord.Net.Rpc.dll</HintPath> + <Reference Include="Discord.Net.Rpc, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>..\packages\Discord.Net.Rpc.1.0.2\lib\net45\Discord.Net.Rpc.dll</HintPath> </Reference> - <Reference Include="Discord.Net.Webhook, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL"> - <HintPath>..\packages\Discord.Net.Webhook.1.0.1\lib\netstandard1.1\Discord.Net.Webhook.dll</HintPath> + <Reference Include="Discord.Net.Webhook, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>..\packages\Discord.Net.Webhook.1.0.2\lib\netstandard1.1\Discord.Net.Webhook.dll</HintPath> </Reference> - <Reference Include="Discord.Net.WebSocket, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL"> - <HintPath>..\packages\Discord.Net.WebSocket.1.0.1\lib\net45\Discord.Net.WebSocket.dll</HintPath> + <Reference Include="Discord.Net.WebSocket, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>..\packages\Discord.Net.WebSocket.1.0.2\lib\net45\Discord.Net.WebSocket.dll</HintPath> </Reference> - <Reference Include="Microsoft.Extensions.DependencyInjection, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL"> - <HintPath>..\packages\Microsoft.Extensions.DependencyInjection.1.1.1\lib\netstandard1.1\Microsoft.Extensions.DependencyInjection.dll</HintPath> + <Reference Include="Microsoft.Extensions.DependencyInjection, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL"> + <HintPath>..\packages\Microsoft.Extensions.DependencyInjection.2.0.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.dll</HintPath> </Reference> - <Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL"> - <HintPath>..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.1.1.1\lib\netstandard1.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath> + <Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL"> + <HintPath>..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.2.0.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath> </Reference> <Reference Include="Microsoft.Win32.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <HintPath>..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll</HintPath> </Reference> <Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> - <HintPath>..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath> + <HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> + </Reference> + <Reference Include="Sodium, Version=0.10.0.0, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>..\packages\libsodium-net.0.10.0\lib\Net40\Sodium.dll</HintPath> </Reference> <Reference Include="System" /> <Reference Include="System.AppContext, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <HintPath>..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll</HintPath> </Reference> - <Reference Include="System.Collections.Immutable, Version=1.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> - <HintPath>..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath> - <Private>True</Private> + <Reference Include="System.Collections.Immutable, Version=1.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\packages\System.Collections.Immutable.1.4.0\lib\netstandard2.0\System.Collections.Immutable.dll</HintPath> </Reference> <Reference Include="System.ComponentModel.Composition" /> <Reference Include="System.Console, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <HintPath>..\packages\System.Console.4.3.0\lib\net46\System.Console.dll</HintPath> </Reference> <Reference Include="System.Core" /> - <Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> - <HintPath>..\packages\System.Diagnostics.DiagnosticSource.4.3.0\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath> + <Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.2.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> + <HintPath>..\packages\System.Diagnostics.DiagnosticSource.4.4.1\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath> </Reference> <Reference Include="System.Globalization.Calendars, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <HintPath>..\packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll</HintPath> @@ -98,8 +102,9 @@ <Reference Include="System.IO.FileSystem.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <HintPath>..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll</HintPath> </Reference> - <Reference Include="System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> - <HintPath>..\packages\System.Net.Http.4.3.0\lib\net46\System.Net.Http.dll</HintPath> + <Reference Include="System.Net.Http, Version=4.1.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\packages\System.Net.Http.4.3.3\lib\net46\System.Net.Http.dll</HintPath> + <Private>True</Private> </Reference> <Reference Include="System.Net.Sockets, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <HintPath>..\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll</HintPath> @@ -109,7 +114,9 @@ <HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath> </Reference> <Reference Include="System.Security.Cryptography.Algorithms, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> - <HintPath>..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll</HintPath> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\packages\System.Security.Cryptography.Algorithms.4.3.1\lib\net461\System.Security.Cryptography.Algorithms.dll</HintPath> + <Private>True</Private> </Reference> <Reference Include="System.Security.Cryptography.Encoding, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <HintPath>..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll</HintPath> @@ -117,8 +124,9 @@ <Reference Include="System.Security.Cryptography.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <HintPath>..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll</HintPath> </Reference> - <Reference Include="System.Security.Cryptography.X509Certificates, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> - <HintPath>..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll</HintPath> + <Reference Include="System.Security.Cryptography.X509Certificates, Version=4.1.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\packages\System.Security.Cryptography.X509Certificates.4.3.2\lib\net461\System.Security.Cryptography.X509Certificates.dll</HintPath> + <Private>True</Private> </Reference> <Reference Include="System.Xml.Linq" /> <Reference Include="System.Data.DataSetExtensions" /> @@ -126,19 +134,43 @@ <Reference Include="System.Data" /> <Reference Include="System.Xml" /> <Reference Include="System.Xml.ReaderWriter, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> - <HintPath>..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll</HintPath> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\packages\System.Xml.ReaderWriter.4.3.1\lib\net46\System.Xml.ReaderWriter.dll</HintPath> + <Private>True</Private> </Reference> </ItemGroup> <ItemGroup> - <Compile Include="Char.cs" /> + <Compile Include="Character.cs" /> + <Compile Include="CommandExtension.cs" /> <Compile Include="Commands.cs" /> + <Compile Include="DSA.cs" /> + <Compile Include="ICharacter.cs" /> <Compile Include="Misc.cs" /> + <Compile Include="NPC.cs" /> <Compile Include="Program.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="Properties\Settings.Designer.cs"> + <AutoGen>True</AutoGen> + <DesignTimeSharedInput>True</DesignTimeSharedInput> + <DependentUpon>Settings.settings</DependentUpon> + </Compile> </ItemGroup> <ItemGroup> <None Include="App.config" /> <None Include="packages.config" /> + <None Include="Properties\Settings.settings"> + <Generator>SettingsSingleFileGenerator</Generator> + <LastGenOutput>Settings.Designer.cs</LastGenOutput> + </None> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <Import Project="..\packages\Baseclass.Contrib.Nuget.Output.2.4.1\build\net40\Baseclass.Contrib.Nuget.Output.targets" Condition="Exists('..\packages\Baseclass.Contrib.Nuget.Output.2.4.1\build\net40\Baseclass.Contrib.Nuget.Output.targets')" /> + <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> + <PropertyGroup> + <ErrorText>Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}".</ErrorText> + </PropertyGroup> + <Error Condition="!Exists('..\packages\Baseclass.Contrib.Nuget.Output.2.4.1\build\net40\Baseclass.Contrib.Nuget.Output.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Baseclass.Contrib.Nuget.Output.2.4.1\build\net40\Baseclass.Contrib.Nuget.Output.targets'))" /> + <Error Condition="!Exists('..\packages\NETStandard.Library.2.0.1\build\netstandard2.0\NETStandard.Library.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NETStandard.Library.2.0.1\build\netstandard2.0\NETStandard.Library.targets'))" /> + </Target> + <Import Project="..\packages\NETStandard.Library.2.0.1\build\netstandard2.0\NETStandard.Library.targets" Condition="Exists('..\packages\NETStandard.Library.2.0.1\build\netstandard2.0\NETStandard.Library.targets')" /> </Project>
\ No newline at end of file diff --git a/DiscoBot/ICharacter.cs b/DiscoBot/ICharacter.cs new file mode 100644 index 0000000..fbaabd3 --- /dev/null +++ b/DiscoBot/ICharacter.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DiscoBot +{ + public interface ICharacter + { + string Name { get; set; } + + string TestTalent(string talent, int erschwernis = 0); + + string TestEigenschaft(string eigenschaft, int erschwernis = 0); + + string Angriff(string talent, int erschwernis = 0); + + string Parade(string talent, int erschwernis = 0); + + string Fernkampf(string talent, int erschwernis = 0); + } +} diff --git a/DiscoBot/Misc.cs b/DiscoBot/Misc.cs index 3876321..9c9456c 100644 --- a/DiscoBot/Misc.cs +++ b/DiscoBot/Misc.cs @@ -8,9 +8,12 @@ namespace DiscoBot { public static class Misc { - public static string Roll(string input) + private static readonly Random Rand = new Random(); + + // use: 4w6 +4 + public static string Roll(string input) { - int count = 1, d,mod=0; + int count = 1, d ,mod=0; var Output = new StringBuilder(); List<string> strings = input.Split('w','d').ToList(); count = Convert.ToInt32(strings[0]); @@ -31,7 +34,131 @@ namespace DiscoBot return Output.ToString(); } + + public static double Random(double stdDev = 1, double mean = 0) + { + double u1 = Rand.NextDouble(); // uniform(0,1) random doubles + double u2 = Rand.NextDouble(); + double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * + Math.Sin(2.0 * Math.PI * u2); // random normal(0,1) + double randNormal = + mean + stdDev * randStdNormal; // random normal(mean,stdDev^2) + return randNormal; + } + } + + public class SpellCorrect : StringComparer + { + public override int Compare(string x, string y) + { + if (x.Equals(y)) + return 0; + x=x.ToLower(); + y=y.ToLower(); + if (x.Equals(y)) + return 1; + var subs = y.Split(' ', '/'); + int score = subs.Count(); + foreach (string s in subs) + { + if (s.Equals(x)) + { + score--; + } + } + + if (score < subs.Count()) + { + return score + 1; + } + + return 100000 - (int)(compare_exact(x, y) * 1000.0); + /*if (y.Contains(x)) + return 6;*/ + + } + + public override bool Equals(string x, string y) + { + throw new NotImplementedException(); + } + + public override int GetHashCode(string obj) + { + throw new NotImplementedException(); + } + + public double compare_exact(string s, string q) + { + int i, j; + const double Match = 3.0; + const double Gap = -2.0; + const double Mismatch = -2.0; + + double decay = 0.0; + + double[,] matrix = new double[s.Length + 1, q.Length + 1]; + double max = 0.0; + matrix[0, 0] = 0.0; + + for (i = 1; i < s.Length; i++) + { + matrix[i, 0] = 0.0; + } + + for (i = 1; i < q.Length; i++) + { + matrix[0, i] = 0.0; + } + + for (i = 1; i <= s.Length; i++) + { + for (j = 1; j <= q.Length; j++) + { + decay = j / (double)(s.Length * 1000); + double add = s[i - 1] == q[j - 1] ? (Match - decay) : Mismatch; + double score = matrix[i - 1, j - 1] + add; + + if (score < (matrix[i - 1, j] + Gap)) + { + score = matrix[i - 1, j] + Gap; + } + + if (score < (matrix[i, j - 1] + Gap)) + { + score = matrix[i, j - 1] + Gap; + } + + if (i > 1 && j > 1) + { + if (s[i - 1] == q[j - 2] && s[i - 2] == q[j - 1]) + { + add = (3 / 2.0) * Match - decay; + if (score < matrix[i - 2, j - 2] + add) + { + score = matrix[i - 2, j - 2] + add; + } + } + } + + if (score < 0) + { + score = 0; + } + + if (max < score) + { + max = score; + } + + matrix[i, j] = score; + } + } + + return max; + } } + public static class dice//roll it! { static System.Random rnd = new System.Random(); @@ -40,6 +167,19 @@ namespace DiscoBot return rnd.Next(1, d+1); } } + + public class Vorteil //talent objekt + { + public string name; + public int value; + + public Vorteil(string name, int value = 0) + { + this.name = name; + this.value = value; + } + } + public class Talent //talent objekt { public string name, probe; @@ -55,24 +195,12 @@ namespace DiscoBot public int CheckName(string quary) { - if (quary.Equals(name)) - return 0; - if (String.Compare(name, quary, StringComparison.InvariantCultureIgnoreCase) == 0) - return 1; - var subs = name.Split(' ','/'); - int score = subs.Count(); - foreach (String s in subs) - if (String.Compare(name, quary, StringComparison.InvariantCultureIgnoreCase) == 0) - score--; - if (score != subs.Count()) - return score+1; - if (name.ToLowerInvariant().Contains(quary.ToLower())) - return 3; - - return 100; + var sc = (StringComparer)new SpellCorrect(); + return sc.Compare(quary, this.name); } } + public class Kampf { public string name; diff --git a/DiscoBot/NPC.cs b/DiscoBot/NPC.cs new file mode 100644 index 0000000..4104947 --- /dev/null +++ b/DiscoBot/NPC.cs @@ -0,0 +1,107 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DiscoBot +{ + public class NPC : ICharacter + { + private int mean, stDv; + + public NPC(string name, int mean, int stDv) + { + this.mean = mean; + this.stDv = stDv; + this.Name = name; + } + + public string Name { get; set; } + + public string TestTalent(string talent, int tap = 3) + { + for (int i = 0; i <= 2; i++) //foreach property, dice and tap + { + int temp = dice.Roll(); + int eigenschaft = (int)Math.Round(Misc.Random(this.stDv, this.mean)); + + if (eigenschaft < temp) + { + tap -= temp - eigenschaft; + } + } + + if (tap >= 0) + { + return $"{this.Name} vollführt {talent} erfolgreich"; + } + + return $"{this.Name} scheitert an {talent}"; + } + + public string TestEigenschaft(string eigenschaft, int erschwernis = 0) + { + int temp = dice.Roll(); + int prop = (int)Math.Round(Misc.Random(this.stDv, this.stDv)); + + if (temp + erschwernis < prop) + { + return $"{this.Name} vollführt {eigenschaft} erfolgreich"; + } + + return $"{this.Name} scheitert an {eigenschaft}"; + } + + public string Angriff(string waffe, int erschwernis = 0) + { + int temp = dice.Roll(); + + if (temp == 1) + { + return $"{this.Name} greift kritisch mit {waffe} an"; + } + + if (temp < erschwernis) + { + return $"{this.Name} greift mit {waffe} an"; + } + + return $"{this.Name} haut mit {waffe} daneben"; + } + + public string Parade(string waffe, int erschwernis = 0) + { + int temp = dice.Roll(); + + if (temp == 1) + { + return $"{this.Name} pariert mit {waffe} meisterlich"; + } + + if (temp < erschwernis) + { + return $"{this.Name} pariert mit {waffe} an"; + } + + return $"{this.Name} schafft es nicht mit {waffe} zu parieren"; + } + + public string Fernkampf(string waffe, int erschwernis = 0) + { + int temp = dice.Roll(); + + if (temp == 1) + { + return $"{this.Name} trifft kritisch mit {waffe}"; + } + + if (temp < erschwernis) + { + return $"{this.Name} greift mit {waffe} an"; + } + + return $"{this.Name} schießt mit {waffe} daneben"; + } + } +} diff --git a/DiscoBot/Program.cs b/DiscoBot/Program.cs index a6e496c..b90ed54 100644 --- a/DiscoBot/Program.cs +++ b/DiscoBot/Program.cs @@ -28,7 +28,7 @@ namespace DiscoBot client = new DiscordSocketClient(); commands = new CommandService(); - string token = ""; + string token = Properties.Settings.Default.Token; services = new ServiceCollection() .BuildServiceProvider(); diff --git a/DiscoBot/Properties/Settings.Designer.cs b/DiscoBot/Properties/Settings.Designer.cs new file mode 100644 index 0000000..9813b8a --- /dev/null +++ b/DiscoBot/Properties/Settings.Designer.cs @@ -0,0 +1,38 @@ +//------------------------------------------------------------------------------ +// <auto-generated> +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// </auto-generated> +//------------------------------------------------------------------------------ + +namespace DiscoBot.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.6.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("Mjk0NTU0MDU4Nzg4NzAwMTYx.DOzDcQ.J-nCikbZdZtdrug0E8TwwV_2ITw")] + public string Token { + get { + return ((string)(this["Token"])); + } + set { + this["Token"] = value; + } + } + } +} diff --git a/DiscoBot/Properties/Settings.settings b/DiscoBot/Properties/Settings.settings new file mode 100644 index 0000000..f3be2b7 --- /dev/null +++ b/DiscoBot/Properties/Settings.settings @@ -0,0 +1,9 @@ +<?xml version='1.0' encoding='utf-8'?> +<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="DiscoBot.Properties" GeneratedClassName="Settings"> + <Profiles /> + <Settings> + <Setting Name="Token" Type="System.String" Scope="User"> + <Value Profile="(Default)">Mjk0NTU0MDU4Nzg4NzAwMTYx.DOzDcQ.J-nCikbZdZtdrug0E8TwwV_2ITw</Value> + </Setting> + </Settings> +</SettingsFile>
\ No newline at end of file diff --git a/DiscoBot/packages.config b/DiscoBot/packages.config index cf276c0..e3bca0f 100644 --- a/DiscoBot/packages.config +++ b/DiscoBot/packages.config @@ -1,26 +1,28 @@ <?xml version="1.0" encoding="utf-8"?> <packages> - <package id="Discord.Net" version="1.0.1" targetFramework="net461" /> - <package id="Discord.Net.Commands" version="1.0.1" targetFramework="net461" /> - <package id="Discord.Net.Core" version="1.0.1" targetFramework="net461" /> - <package id="Discord.Net.Rest" version="1.0.1" targetFramework="net461" /> - <package id="Discord.Net.Rpc" version="1.0.1" targetFramework="net461" /> - <package id="Discord.Net.Webhook" version="1.0.1" targetFramework="net461" /> - <package id="Discord.Net.WebSocket" version="1.0.1" targetFramework="net461" /> - <package id="Microsoft.Extensions.DependencyInjection" version="1.1.1" targetFramework="net461" /> - <package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="1.1.1" targetFramework="net461" /> - <package id="Microsoft.NETCore.Platforms" version="1.1.0" targetFramework="net461" /> + <package id="Baseclass.Contrib.Nuget.Output" version="2.4.1" targetFramework="net461" /> + <package id="Discord.Net" version="1.0.2" targetFramework="net461" /> + <package id="Discord.Net.Commands" version="1.0.2" targetFramework="net461" /> + <package id="Discord.Net.Core" version="1.0.2" targetFramework="net461" /> + <package id="Discord.Net.Rest" version="1.0.2" targetFramework="net461" /> + <package id="Discord.Net.Rpc" version="1.0.2" targetFramework="net461" /> + <package id="Discord.Net.Webhook" version="1.0.2" targetFramework="net461" /> + <package id="Discord.Net.WebSocket" version="1.0.2" targetFramework="net461" /> + <package id="libsodium-net" version="0.10.0" targetFramework="net461" /> + <package id="Microsoft.Extensions.DependencyInjection" version="2.0.0" targetFramework="net461" /> + <package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="2.0.0" targetFramework="net461" /> + <package id="Microsoft.NETCore.Platforms" version="2.0.1" targetFramework="net461" /> <package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="net461" /> - <package id="NETStandard.Library" version="1.6.1" targetFramework="net461" /> - <package id="Newtonsoft.Json" version="10.0.2" targetFramework="net461" /> + <package id="NETStandard.Library" version="2.0.1" targetFramework="net461" /> + <package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" /> <package id="System.AppContext" version="4.3.0" targetFramework="net461" /> <package id="System.Collections" version="4.3.0" targetFramework="net461" /> <package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net461" /> - <package id="System.Collections.Immutable" version="1.3.1" targetFramework="net461" /> + <package id="System.Collections.Immutable" version="1.4.0" targetFramework="net461" /> <package id="System.ComponentModel" version="4.3.0" targetFramework="net461" /> <package id="System.Console" version="4.3.0" targetFramework="net461" /> <package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="net461" /> - <package id="System.Diagnostics.DiagnosticSource" version="4.3.0" targetFramework="net461" /> + <package id="System.Diagnostics.DiagnosticSource" version="4.4.1" targetFramework="net461" /> <package id="System.Diagnostics.Tools" version="4.3.0" targetFramework="net461" /> <package id="System.Diagnostics.Tracing" version="4.3.0" targetFramework="net461" /> <package id="System.Globalization" version="4.3.0" targetFramework="net461" /> @@ -33,7 +35,7 @@ <package id="System.IO.FileSystem.Primitives" version="4.3.0" targetFramework="net461" /> <package id="System.Linq" version="4.3.0" targetFramework="net461" /> <package id="System.Linq.Expressions" version="4.3.0" targetFramework="net461" /> - <package id="System.Net.Http" version="4.3.0" targetFramework="net461" /> + <package id="System.Net.Http" version="4.3.3" targetFramework="net461" /> <package id="System.Net.Primitives" version="4.3.0" targetFramework="net461" /> <package id="System.Net.Sockets" version="4.3.0" targetFramework="net461" /> <package id="System.ObjectModel" version="4.3.0" targetFramework="net461" /> @@ -47,16 +49,16 @@ <package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="net461" /> <package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net461" /> <package id="System.Runtime.Numerics" version="4.3.0" targetFramework="net461" /> - <package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net461" /> + <package id="System.Security.Cryptography.Algorithms" version="4.3.1" targetFramework="net461" /> <package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net461" /> <package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net461" /> - <package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net461" /> + <package id="System.Security.Cryptography.X509Certificates" version="4.3.2" targetFramework="net461" /> <package id="System.Text.Encoding" version="4.3.0" targetFramework="net461" /> <package id="System.Text.Encoding.Extensions" version="4.3.0" targetFramework="net461" /> <package id="System.Text.RegularExpressions" version="4.3.0" targetFramework="net461" /> <package id="System.Threading" version="4.3.0" targetFramework="net461" /> <package id="System.Threading.Tasks" version="4.3.0" targetFramework="net461" /> <package id="System.Threading.Timer" version="4.3.0" targetFramework="net461" /> - <package id="System.Xml.ReaderWriter" version="4.3.0" targetFramework="net461" /> + <package id="System.Xml.ReaderWriter" version="4.3.1" targetFramework="net461" /> <package id="System.Xml.XDocument" version="4.3.0" targetFramework="net461" /> </packages>
\ No newline at end of file |