diff options
author | TrueDoctor <d-kobert@web.de> | 2018-06-15 09:58:24 +0200 |
---|---|---|
committer | TrueDoctor <d-kobert@web.de> | 2018-06-15 09:58:24 +0200 |
commit | 380d9ec6048663b0e497e2437222d783236b864f (patch) | |
tree | 635fd93e6902c696abe31526da1fc15db7f2d516 | |
parent | c00b3bbf39ae2756aecceaa54b3a87a0e3955a9e (diff) |
Added Properties Class
auto load last settings
removed sound enumerable
moved Sonds to properties
moved Commands to properties
-rw-r--r-- | DiscoBot/Audio/AudioModule.cs | 2 | ||||
-rw-r--r-- | DiscoBot/Audio/Sound.cs | 21 | ||||
-rw-r--r-- | DiscoBot/Audio/Soundeffects.cs | 26 | ||||
-rw-r--r-- | DiscoBot/Audio/Voice.cs | 4 | ||||
-rw-r--r-- | DiscoBot/Auxiliary/TalentEnumerableExtension.cs | 4 | ||||
-rw-r--r-- | DiscoBot/Commands/Help.cs | 12 | ||||
-rw-r--r-- | DiscoBot/DSA_Game/Characters/Character.cs | 6 | ||||
-rw-r--r-- | DiscoBot/DSA_Game/Dsa.cs | 7 | ||||
-rw-r--r-- | DiscoBot/DSA_Game/Save/Properties.cs | 51 | ||||
-rw-r--r-- | DiscoBot/DiscoBot.csproj | 2 | ||||
-rw-r--r-- | DiscoBot/Properties.json | 99 |
11 files changed, 208 insertions, 26 deletions
diff --git a/DiscoBot/Audio/AudioModule.cs b/DiscoBot/Audio/AudioModule.cs index f2097b7..f8834f3 100644 --- a/DiscoBot/Audio/AudioModule.cs +++ b/DiscoBot/Audio/AudioModule.cs @@ -71,7 +71,7 @@ namespace DiscoBot.Audio await _service.SendAudioAsync(Context.Guild, Context.Channel, song); } - SoundEffects.Play(tSound); + SoundEffects.Play(song); } } }
\ No newline at end of file diff --git a/DiscoBot/Audio/Sound.cs b/DiscoBot/Audio/Sound.cs new file mode 100644 index 0000000..174c076 --- /dev/null +++ b/DiscoBot/Audio/Sound.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DiscoBot.Audio +{ + public class Sound + { + public Sound(string name, string url) + { + Name = name; + Url = url; + } + + public string Name { get; } + + public string Url { get; } + } +} diff --git a/DiscoBot/Audio/Soundeffects.cs b/DiscoBot/Audio/Soundeffects.cs index 1e6dda1..317d0ff 100644 --- a/DiscoBot/Audio/Soundeffects.cs +++ b/DiscoBot/Audio/Soundeffects.cs @@ -5,7 +5,7 @@ using DiscoBot.Commands; - public enum Sound + /*public enum Sound { Bell, Ding, @@ -17,45 +17,45 @@ Stupid, Police, Roblox - } + }*/ public static class SoundEffects { public static int Volume { get; set; } = 50; - public static void Play(Sound s) + public static void Play(string s) { string url = string.Empty; int volume = 255; switch (s) { - case Sound.Bell: - case Sound.Ding: + case "Bell": + case "Ding": url = "https://www.myinstants.com/media/sounds/boxing-bell.mp3"; break; - case Sound.Finish: + case "Finish": url = "https://www.myinstants.com/media/sounds/finishhim.swf.mp3"; break; - case Sound.Magic: + case "Magic": url = "https://www.myinstants.com/media/sounds/dream-harp-sound-effect.mp3"; break; - case Sound.Monsterkill: + case "Monsterkill": url = "https://www.myinstants.com/media/sounds/announcer_kill_monster_01.mp3"; break; - case Sound.Nooo: + case "Nooo": url = "https://www.myinstants.com/media/sounds/nooo.swf.mp3"; break; - case Sound.Roblox: + case "Roblox": url = "https://www.myinstants.com/media/sounds/roblox-death-sound_ytkBL7X.mp3"; break; - case Sound.Stupid: + case "Stupid": url = "https://www.myinstants.com/media/sounds/stupid_dum_03.mp3"; volume = 10; break; - case Sound.Police: + case "Police": url = "https://www.myinstants.com/media/sounds/sound-of-the-police.mp3"; break; - case Sound.Wrong: + case "Wrong": url = "https://www.myinstants.com/media/sounds/wrong-answer-sound-effect.mp3"; volume = 50; break; diff --git a/DiscoBot/Audio/Voice.cs b/DiscoBot/Audio/Voice.cs index 2c8f75e..5417560 100644 --- a/DiscoBot/Audio/Voice.cs +++ b/DiscoBot/Audio/Voice.cs @@ -66,7 +66,7 @@ if (Client != null) { - SoundEffects.Play(Sound.Nooo); + SoundEffects.Play("Nooo"); await Client.StopAsync(); Client = null; } @@ -105,7 +105,7 @@ await Task.Run(() => Voice.Send(path)); } - await Task.Run(() => SoundEffects.Play(tSound)); + await Task.Run(() => SoundEffects.Play(path)); } private static Process CreateStream(string path, int vol = 256) diff --git a/DiscoBot/Auxiliary/TalentEnumerableExtension.cs b/DiscoBot/Auxiliary/TalentEnumerableExtension.cs index c366674..43c917e 100644 --- a/DiscoBot/Auxiliary/TalentEnumerableExtension.cs +++ b/DiscoBot/Auxiliary/TalentEnumerableExtension.cs @@ -23,7 +23,7 @@ namespace DiscoBot.Auxiliary { try { - SoundEffects.Play(Sound.Stupid); + SoundEffects.Play("Stupid"); } catch { } return $"{c.Name} kann nicht {talent}..."; @@ -90,7 +90,7 @@ namespace DiscoBot.Auxiliary { try { - SoundEffects.Play(Sound.Wrong); + SoundEffects.Play("Wrong"); } catch { } } diff --git a/DiscoBot/Commands/Help.cs b/DiscoBot/Commands/Help.cs index 7b77e2b..bf58070 100644 --- a/DiscoBot/Commands/Help.cs +++ b/DiscoBot/Commands/Help.cs @@ -5,9 +5,11 @@ namespace DiscoBot.Commands using System; using System.Collections.Generic; using System.IO; + using System.Security.Cryptography; using System.Threading.Tasks; using DiscoBot.Auxiliary; + using DiscoBot.DSA_Game; using Discord.Commands; @@ -19,7 +21,7 @@ namespace DiscoBot.Commands { static Help() { - TextReader stream = new StreamReader(@"..\..\Help.json"); // Load command-description file + /*TextReader stream = new StreamReader(@"..\..\Help.json"); // Load command-description file var reader = new JsonTextReader(stream); // create stream reader reader.Read(); // step into structure, until the array starts @@ -35,23 +37,23 @@ namespace DiscoBot.Commands catch (Exception e) { // ignored - } + }*/ } - public static List<CommandInfo> Commands { get; } = new List<CommandInfo>(); + //public static List<CommandInfo> Commands { get; } = new List<CommandInfo>(); public static string Get_Specific_Help(string command) { // return command specific help - var com = Commands.OrderBy(x => SpellCorrect.CompareEasy(x.Name, command.ToLower())).First(); // get best fit command + var com = Dsa.Properties.CommandInfos.OrderBy(x => SpellCorrect.CompareEasy(x.Name, command.ToLower())).First(); // get best fit command return com.GetDescription(); } public static string Get_Generic_Help() { string res = ""; - foreach (var com in Commands) + foreach (var com in Dsa.Properties.CommandInfos) { int first_column_width = 8; res += ("!" + com.Name + ": ").AddSpaces(first_column_width) + com.Brief; diff --git a/DiscoBot/DSA_Game/Characters/Character.cs b/DiscoBot/DSA_Game/Characters/Character.cs index 5c39fc5..c1acd39 100644 --- a/DiscoBot/DSA_Game/Characters/Character.cs +++ b/DiscoBot/DSA_Game/Characters/Character.cs @@ -120,7 +120,7 @@ { try { - SoundEffects.Play(Sound.Wrong); + SoundEffects.Play("Wrong"); } catch { } @@ -149,7 +149,7 @@ { try { - SoundEffects.Play(Sound.Wrong); + SoundEffects.Play("Wrong"); } catch { } return $"{this.Name} kann nicht mit der Waffenart {talent} umgehen..."; @@ -177,7 +177,7 @@ { try { - SoundEffects.Play(Sound.Wrong); + SoundEffects.Play("Wrong"); } catch { } return $"{this.Name} kann nicht mit der Waffenart {talent} umgehen..."; diff --git a/DiscoBot/DSA_Game/Dsa.cs b/DiscoBot/DSA_Game/Dsa.cs index e514691..c6ea1c3 100644 --- a/DiscoBot/DSA_Game/Dsa.cs +++ b/DiscoBot/DSA_Game/Dsa.cs @@ -6,7 +6,9 @@ using DiscoBot.Audio; using DiscoBot.Auxiliary; + using DiscoBot.Commands; using DiscoBot.DSA_Game.Characters; + using DiscoBot.DSA_Game.Save; using Discord.Commands; @@ -21,6 +23,8 @@ public static List<ICharacter> Chars { get; set; } = new List<ICharacter>(); // list of all characters public static List<Talent> Talente { get; set; } = new List<Talent>(); + + public static Properties Properties { get; set; } public static void Startup() { @@ -53,6 +57,9 @@ .Where(c => !Talente.Exists(v => v.Name.Equals(c.Name))).ToList().ForEach(v => Talente.Add(v)); } + Properties = Save.Properties.Deserialize(); + Properties.Serialize(); + Talente = Talente.OrderBy(x => x.Name).ToList(); } } diff --git a/DiscoBot/DSA_Game/Save/Properties.cs b/DiscoBot/DSA_Game/Save/Properties.cs new file mode 100644 index 0000000..5d99a56 --- /dev/null +++ b/DiscoBot/DSA_Game/Save/Properties.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DiscoBot.DSA_Game.Save +{ + using System.IO; + + using DiscoBot.Audio; + using DiscoBot.Auxiliary; + using DiscoBot.Commands; + + using Newtonsoft.Json; + + public class Properties + { + public List<CommandInfo> CommandInfos { get; set; } + + public List<Sound> Sounds { get; set; } + + public static Properties Deserialize(string path = @"..\..\Properties.json") + { + try + { + return JsonConvert.DeserializeObject<Properties>(File.ReadAllText(path)); // Deserialize Data and create CommandInfo Struct + } + catch (Exception e) + { + // ignored + return null; + } + } + + public void Serialize(string path = @"..\..\Properties.json") + {/* + var stream = new StreamWriter(path); // Load properties file + var reader = new JsonTextWriter(stream); // create stream reader*/ + + try + { + File.WriteAllText(path, JsonConvert.SerializeObject(this, Formatting.Indented)); // Deserialize Data and create CommandInfo Struct + } + catch (Exception e) + { + // ignored + } + } + } +} diff --git a/DiscoBot/DiscoBot.csproj b/DiscoBot/DiscoBot.csproj index f22c356..48aa374 100644 --- a/DiscoBot/DiscoBot.csproj +++ b/DiscoBot/DiscoBot.csproj @@ -96,6 +96,7 @@ <ItemGroup> <Compile Include="Audio\AudioModule.cs" /> <Compile Include="Audio\AudioService.cs" /> + <Compile Include="Audio\Sound.cs" /> <Compile Include="Auxiliary\CommandInfo.cs" /> <Compile Include="Auxiliary\Extensions.cs" /> <Compile Include="Commands\Help.cs" /> @@ -108,6 +109,7 @@ <Compile Include="Auxiliary\Permissions.cs" /> <Compile Include="Commands\MiscCommands.cs" /> <Compile Include="Auxiliary\SpellCorrect.cs" /> + <Compile Include="DSA_Game\Save\Properties.cs" /> <Compile Include="DSA_Game\Talent.cs" /> <Compile Include="DSA_Game\Vorteil.cs" /> <Compile Include="DSA_Game\Characters\Character.cs" /> diff --git a/DiscoBot/Properties.json b/DiscoBot/Properties.json new file mode 100644 index 0000000..c1fcccf --- /dev/null +++ b/DiscoBot/Properties.json @@ -0,0 +1,99 @@ +{ + "CommandInfos": [ + { + "Name": "ich bin", + "Scope": "All", + "Brief": "Setzt den gespielten Charakter fest", + "Description": [ + "Mit \"!Ich bin\" kann der gespielte Charakter definiert, bzw. gewechselt werden.\n", + " Die Charaktere müssen als *.xml Dateien hinterlegt sein.\n\n", + " !ich Zeigt an welcher Charakter zur Zeit gespielt wird\n", + " !ich bin Zalibius Wechsel zum Helden Zalibius\n", + " !ich Rhoktar Orkische Variante von !ich bin.\n", + " Wechselt zu Rhoktar.\n\n", + " !list chars Zeigt die Liste verfügbarer Charaktere.\n", + " \n" + ] + }, + { + "Name": "List", + "Scope": "All", + "Brief": "Anzeige vonSpielrelevanten Listen", + "Description": [ + "Mit \"!list\" lassen sich spielrelevante Listen ausgeben. Die Angezeigte Liste wird nach einiger Zeit wieder gelöscht.\n", + "\n", + " !list chars Liste aller verfügbaren Helden (eingelesen per *.xml)\n", + " und NSCs.\n", + " (Mit \"!ich bin\" kann der Held ausgewählt werden.)\n", + " !list commands Liste aller verwendbaren Bot-Kommandos.\n", + " !list sounds Liste der Soundeffekte." + ] + }, + { + "Name": "Held", + "Scope": "All", + "Brief": "Anzeige von Heldenwerten", + "Description": [ + "Mit \"!Held\" lassen sich Heldenwerte ausgeben. Mehrere Werte können gleichzeitig angefordert werde. \"!Held LE Waffen\" liefert so z.B. Informationen zur Lebensenergie und den Kampfwerten.\n Bis auf wenige Ausnahmen wird die Angezeigte Liste nach einiger Zeit wieder gelöscht.\n", + "\n", + " !Held Zeigt den Heldenbrief an.\n", + " (Diese Liste wird nicht automatisch gelöscht)\n", + " !Held Eigenschaften Zeigt die Eigenschaften MU/KL/CH/IN/KK/GE/FF/KO.\n", + " !Held e Kurzform von \"!Held Eigenschaften\".\n", + " !Held LE Zeigt LE an.\n", + " !Held AE Zeigt AE an.\n", + " !Held stats Zeigt Eigenschaften und zusätzlich SO/LE/AE.\n", + " !Held Kampfwerte Zeigt AT/PA für aktivierte Waffentalente.\n", + " !Held Waffe/!list w Kurzformen von \"!Held Kampfwerte\".\n", + " !Held Vorteile Zeigt Vor- und Nachteile an.\n", + " !Held v Kurzform von \"!Held Vorteile\".\n", + " !Held Talente Zeigt die Liste aller aktivierten Talente, deren TaW,\n", + " sowie die Probe.\n", + " !Held t Kurzform von \"!Held Talente\".\n", + " !Held Zauber Zeigt die Liste aller aktivierten Zauber, deren ZaW,\n", + " sowie die Probe.\n", + " !Held z Kurzform von \"!Held Zauber\".\n" + ] + }, + { + "Name": "LE", + "Scope": "All", + "Brief": "Ändert dein Leben - im wahrsten Sinne des Wortes", + "Description": [ + "Mit !LE zeigt man die Lebensenergie an, ändert sie, oder setzt sie auf einen neuen Wert\n\n", + " !LE Zeigt Lebensenergie an\n", + " !LE 30 Setzt LE auf 30\n", + " !LE +5 Erhöht LE um 5 (bis zum Maximum)\n", + " !LE ++5 Erhöht LE um 5 (ignoriert Maximum)\n", + " !LE -5 Verringert LE um 5\n \n" + ] + }, + { + "Name": "AE", + "Scope": "All", + "Brief": "Ändert Astralenergie", + "Description": [ + "Mit !AE (oder !Asp) zeigt man die Astralenergie an, ändert sie, oder setzt sie auf einen neuen Wert\n\n", + " !AE Zeigt Astralenergie an\n", + " !AE 30 Setzt Asp auf 30\n", + " !AE +5 Erhöht Asp um 5 (bis zum Maximum)\n", + " !AE ++5 Erhöht Asp um 5 (ignoriert Maximum)\n", + " !AE -5 Verringert Asp um 5 (Minimum 0)\n" + ] + }, + { + "Name": "Gm", + "Scope": "Meister", + "Brief": "Testbeschreibung", + "Description": [ + "Gm Aktionen" + ] + } + ], + "Sounds": [ + { + "Name": "Test", + "Url": "http" + } + ] +}
\ No newline at end of file |