diff options
-rw-r--r-- | DiscoBot/DSA_Game/Dsa.cs | 2 | ||||
-rw-r--r-- | DiscoBot/DSA_Game/Save/Properties.cs | 6 | ||||
-rw-r--r-- | DiscoBot/DSA_Game/Save/SaveCommand.cs | 41 | ||||
-rw-r--r-- | DiscoBot/DSA_Game/Save/Session.cs | 9 | ||||
-rw-r--r-- | DiscoBot/Properties/DiscoBot-Audio-Sound.json (renamed from DiscoBot/sessions/DiscoBot-Audio-Sound.json) | 0 | ||||
-rw-r--r-- | DiscoBot/Properties/DiscoBot-Commands-Help.json (renamed from DiscoBot/sessions/DiscoBot-Commands-Help.json) | 0 | ||||
-rw-r--r-- | DiscoBot/Properties/DiscoBot-DSA_Game-Characters-Character.json (renamed from DiscoBot/sessions/DiscoBot-DSA_Game-Characters-Character.json) | 0 | ||||
-rw-r--r-- | DiscoBot/session.json | 36 | ||||
-rw-r--r-- | DiscoBot/sessions/copy/copy-0.json | 79 | ||||
-rw-r--r-- | DiscoBot/sessions/test/test-0.json | 79 | ||||
-rw-r--r-- | DiscoBot/sessions/test/test-1.json | 79 |
11 files changed, 284 insertions, 47 deletions
diff --git a/DiscoBot/DSA_Game/Dsa.cs b/DiscoBot/DSA_Game/Dsa.cs index 5b4833b..f1ed069 100644 --- a/DiscoBot/DSA_Game/Dsa.cs +++ b/DiscoBot/DSA_Game/Dsa.cs @@ -22,7 +22,7 @@ public static List<Talent> Talente { get; set; } = new List<Talent>(); - public static Session Session { get; set; } + public static Session Session { get; set; } = new Session(); public static void Startup() { diff --git a/DiscoBot/DSA_Game/Save/Properties.cs b/DiscoBot/DSA_Game/Save/Properties.cs index 45bad4a..67d30b0 100644 --- a/DiscoBot/DSA_Game/Save/Properties.cs +++ b/DiscoBot/DSA_Game/Save/Properties.cs @@ -34,7 +34,7 @@ namespace DiscoBot.DSA_Game.Save public static List<Sound> Sounds { get => objects["Sound"] as List<Sound>; set => objects["Sound"] = value; } - public static void Deserialize(string path = @"..\..\sessions") + public static void Deserialize(string path = @"..\..\Properties") { var files = Directory.GetFiles(path, "*.json"); @@ -65,7 +65,7 @@ namespace DiscoBot.DSA_Game.Save } - public static void Serialize(string path = @"..\..\sessions\") + public static void Serialize(string path = @"..\..\Properties\") { try { @@ -80,6 +80,8 @@ namespace DiscoBot.DSA_Game.Save catch (Exception e) { // ignored + var log = new LogMessage(LogSeverity.Warning, "Properties", $"Speichern von Save-File fehlgeschlagen.", e); + Console.WriteLine(log); } } } diff --git a/DiscoBot/DSA_Game/Save/SaveCommand.cs b/DiscoBot/DSA_Game/Save/SaveCommand.cs index 310d38a..07bcbac 100644 --- a/DiscoBot/DSA_Game/Save/SaveCommand.cs +++ b/DiscoBot/DSA_Game/Save/SaveCommand.cs @@ -15,27 +15,54 @@ namespace DiscoBot.DSA_Game.Save public class SaveCommand : ModuleBase { - [Command("save"), Summary("Save Session")] - public async Task ReportAsync() + [Command("load"), Summary("Load Session")] + public async Task LoadSessionAsync([Remainder, Summary("Session Name")] string name = "") { - + if (name.Equals("?") || name.Equals(string.Empty)) + { + await this.ReplyAsync($"Gespeicherte Sessions:"); + await this.ReplyAsync(this.ListSessions()); + return; + } + + var path = DSA_Game.Save.Session.DirectoryPath + @"\" + name; + + var files = Directory.GetFiles(path); + var session = files.OrderByDescending(x => Convert.ToInt32(x.Split('-').Last().Split('.').First())).First(); + Dsa.Session = Session.Load(session); - await this.ReplyAsync($"Dein report wurde hinzugefĆ¼gt"); + await this.ReplyAsync($"{name} wurde geladen"); } [Command("save"), Summary("Save Session")] - public async Task ReportAsync([Remainder, Summary("Session Name")] string name) + public async Task SessionSaveAsync([Remainder, Summary("Session Name")] string name = "") { - if (name.Equals("?")) + if (name.Equals("?") || name.Equals(string.Empty)) { await this.ReplyAsync($"Gespeicherte Sessions:"); await this.ReplyAsync(this.ListSessions()); + return; } + + var path = DSA_Game.Save.Session.DirectoryPath + @"\" + name; + if (Directory.Exists(path)) + { + var files = Directory.GetFiles(path); + int current = files.Max(x => Convert.ToInt32(x.Split('-').Last().Split('.').First())); + Dsa.Session.Save(path + "\\" + name + $"-{++current}.json"); + } + else + { + Directory.CreateDirectory(path); + Dsa.Session.Save(path + "\\" + name + $"-0.json"); + } + + await this.ReplyAsync($"{name} wurde gespeichert"); } private string[] ListSessions() { - return Directory.GetDirectories(@"..\..\sessions"); + return Directory.GetDirectories(Session.DirectoryPath); } diff --git a/DiscoBot/DSA_Game/Save/Session.cs b/DiscoBot/DSA_Game/Save/Session.cs index ed9c18d..0358b22 100644 --- a/DiscoBot/DSA_Game/Save/Session.cs +++ b/DiscoBot/DSA_Game/Save/Session.cs @@ -10,12 +10,15 @@ namespace DiscoBot.DSA_Game.Save using DiscoBot.DSA_Game.Characters; + using Discord; using Discord.Commands; using Newtonsoft.Json; public class Session { + public static string DirectoryPath { get; set; } = @"..\..\sessions"; + public ICommandContext GeneralContext { get; set; } public Dictionary<string, string> Relation { get; set; } = new Dictionary<string, string>(); // dictionary to match the char @@ -23,7 +26,7 @@ namespace DiscoBot.DSA_Game.Save public List<SaveChar> Chars { get; set; } = new List<SaveChar>(); // list of all characters public string SessionName { get; set; } - + public static Session Load(string path = @"..\..\session.json") { try @@ -33,6 +36,8 @@ namespace DiscoBot.DSA_Game.Save catch (Exception e) { // ignored + var log = new LogMessage(LogSeverity.Warning, "Properties", $"Laden von Save-File {path} fehlgeschlagen.", e); + Console.WriteLine(log); return null; } } @@ -45,6 +50,8 @@ namespace DiscoBot.DSA_Game.Save } catch (Exception e) { + var log = new LogMessage(LogSeverity.Warning, "Properties", $"Speichern von Save-File {path} fehlgeschlagen.", e); + Console.WriteLine(log); // ignored } } diff --git a/DiscoBot/sessions/DiscoBot-Audio-Sound.json b/DiscoBot/Properties/DiscoBot-Audio-Sound.json index 87a0e6b..87a0e6b 100644 --- a/DiscoBot/sessions/DiscoBot-Audio-Sound.json +++ b/DiscoBot/Properties/DiscoBot-Audio-Sound.json diff --git a/DiscoBot/sessions/DiscoBot-Commands-Help.json b/DiscoBot/Properties/DiscoBot-Commands-Help.json index df1046d..df1046d 100644 --- a/DiscoBot/sessions/DiscoBot-Commands-Help.json +++ b/DiscoBot/Properties/DiscoBot-Commands-Help.json diff --git a/DiscoBot/sessions/DiscoBot-DSA_Game-Characters-Character.json b/DiscoBot/Properties/DiscoBot-DSA_Game-Characters-Character.json index 2dee9db..2dee9db 100644 --- a/DiscoBot/sessions/DiscoBot-DSA_Game-Characters-Character.json +++ b/DiscoBot/Properties/DiscoBot-DSA_Game-Characters-Character.json diff --git a/DiscoBot/session.json b/DiscoBot/session.json index cd2e455..03c46f3 100644 --- a/DiscoBot/session.json +++ b/DiscoBot/session.json @@ -4,110 +4,74 @@ "Chars": [ { "Name": "Felis Exodus Schattenwald", - "Lebenspunkte_Basis": 30, "Lebenspunkte_Aktuell": 30, - "Ausdauer_Basis": 0, "Ausdauer_Aktuell": 0, - "Astralpunkte_Basis": 20, "Astralpunkte_Aktuell": 20 }, { "Name": "Gardist", - "Lebenspunkte_Basis": 29, "Lebenspunkte_Aktuell": 29, - "Ausdauer_Basis": 0, "Ausdauer_Aktuell": 0, - "Astralpunkte_Basis": 0, "Astralpunkte_Aktuell": 0 }, { "Name": "Hartmut Reiher", - "Lebenspunkte_Basis": 31, "Lebenspunkte_Aktuell": 31, - "Ausdauer_Basis": 0, "Ausdauer_Aktuell": 0, - "Astralpunkte_Basis": 0, "Astralpunkte_Aktuell": 0 }, { "Name": "Helga vom Drachenei, Tausendsasserin", - "Lebenspunkte_Basis": 21, "Lebenspunkte_Aktuell": 21, - "Ausdauer_Basis": 0, "Ausdauer_Aktuell": 0, - "Astralpunkte_Basis": 35, "Astralpunkte_Aktuell": 35 }, { "Name": "Krenko", - "Lebenspunkte_Basis": 25, "Lebenspunkte_Aktuell": 25, - "Ausdauer_Basis": 0, "Ausdauer_Aktuell": 0, - "Astralpunkte_Basis": 0, "Astralpunkte_Aktuell": 0 }, { "Name": "Ledur Torfinson", - "Lebenspunkte_Basis": 39, "Lebenspunkte_Aktuell": 39, - "Ausdauer_Basis": 0, "Ausdauer_Aktuell": 0, - "Astralpunkte_Basis": 0, "Astralpunkte_Aktuell": 0 }, { "Name": "Morla", - "Lebenspunkte_Basis": 26, "Lebenspunkte_Aktuell": 26, - "Ausdauer_Basis": 0, "Ausdauer_Aktuell": 0, - "Astralpunkte_Basis": 13, "Astralpunkte_Aktuell": 13 }, { "Name": "Numeri Illuminus", - "Lebenspunkte_Basis": 28, "Lebenspunkte_Aktuell": 28, - "Ausdauer_Basis": 0, "Ausdauer_Aktuell": 0, - "Astralpunkte_Basis": 40, "Astralpunkte_Aktuell": 40 }, { "Name": "Potus", - "Lebenspunkte_Basis": 39, "Lebenspunkte_Aktuell": 39, - "Ausdauer_Basis": 0, "Ausdauer_Aktuell": 0, - "Astralpunkte_Basis": 16, "Astralpunkte_Aktuell": 16 }, { "Name": "Pump aus der Gosse", - "Lebenspunkte_Basis": 18, "Lebenspunkte_Aktuell": 18, - "Ausdauer_Basis": 0, "Ausdauer_Aktuell": 0, - "Astralpunkte_Basis": 13, "Astralpunkte_Aktuell": 13 }, { "Name": "Rhoktar4", - "Lebenspunkte_Basis": 34, "Lebenspunkte_Aktuell": 34, - "Ausdauer_Basis": 0, "Ausdauer_Aktuell": 0, - "Astralpunkte_Basis": 17, "Astralpunkte_Aktuell": 17 }, { "Name": "Volant", - "Lebenspunkte_Basis": 28, "Lebenspunkte_Aktuell": 28, - "Ausdauer_Basis": 0, "Ausdauer_Aktuell": 0, - "Astralpunkte_Basis": 43, "Astralpunkte_Aktuell": 43 } ], diff --git a/DiscoBot/sessions/copy/copy-0.json b/DiscoBot/sessions/copy/copy-0.json new file mode 100644 index 0000000..03c46f3 --- /dev/null +++ b/DiscoBot/sessions/copy/copy-0.json @@ -0,0 +1,79 @@ +{ + "GeneralContext": null, + "Relation": {}, + "Chars": [ + { + "Name": "Felis Exodus Schattenwald", + "Lebenspunkte_Aktuell": 30, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 20 + }, + { + "Name": "Gardist", + "Lebenspunkte_Aktuell": 29, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 0 + }, + { + "Name": "Hartmut Reiher", + "Lebenspunkte_Aktuell": 31, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 0 + }, + { + "Name": "Helga vom Drachenei, Tausendsasserin", + "Lebenspunkte_Aktuell": 21, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 35 + }, + { + "Name": "Krenko", + "Lebenspunkte_Aktuell": 25, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 0 + }, + { + "Name": "Ledur Torfinson", + "Lebenspunkte_Aktuell": 39, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 0 + }, + { + "Name": "Morla", + "Lebenspunkte_Aktuell": 26, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 13 + }, + { + "Name": "Numeri Illuminus", + "Lebenspunkte_Aktuell": 28, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 40 + }, + { + "Name": "Potus", + "Lebenspunkte_Aktuell": 39, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 16 + }, + { + "Name": "Pump aus der Gosse", + "Lebenspunkte_Aktuell": 18, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 13 + }, + { + "Name": "Rhoktar4", + "Lebenspunkte_Aktuell": 34, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 17 + }, + { + "Name": "Volant", + "Lebenspunkte_Aktuell": 28, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 43 + } + ], + "SessionName": null +}
\ No newline at end of file diff --git a/DiscoBot/sessions/test/test-0.json b/DiscoBot/sessions/test/test-0.json new file mode 100644 index 0000000..03c46f3 --- /dev/null +++ b/DiscoBot/sessions/test/test-0.json @@ -0,0 +1,79 @@ +{ + "GeneralContext": null, + "Relation": {}, + "Chars": [ + { + "Name": "Felis Exodus Schattenwald", + "Lebenspunkte_Aktuell": 30, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 20 + }, + { + "Name": "Gardist", + "Lebenspunkte_Aktuell": 29, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 0 + }, + { + "Name": "Hartmut Reiher", + "Lebenspunkte_Aktuell": 31, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 0 + }, + { + "Name": "Helga vom Drachenei, Tausendsasserin", + "Lebenspunkte_Aktuell": 21, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 35 + }, + { + "Name": "Krenko", + "Lebenspunkte_Aktuell": 25, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 0 + }, + { + "Name": "Ledur Torfinson", + "Lebenspunkte_Aktuell": 39, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 0 + }, + { + "Name": "Morla", + "Lebenspunkte_Aktuell": 26, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 13 + }, + { + "Name": "Numeri Illuminus", + "Lebenspunkte_Aktuell": 28, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 40 + }, + { + "Name": "Potus", + "Lebenspunkte_Aktuell": 39, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 16 + }, + { + "Name": "Pump aus der Gosse", + "Lebenspunkte_Aktuell": 18, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 13 + }, + { + "Name": "Rhoktar4", + "Lebenspunkte_Aktuell": 34, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 17 + }, + { + "Name": "Volant", + "Lebenspunkte_Aktuell": 28, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 43 + } + ], + "SessionName": null +}
\ No newline at end of file diff --git a/DiscoBot/sessions/test/test-1.json b/DiscoBot/sessions/test/test-1.json new file mode 100644 index 0000000..03c46f3 --- /dev/null +++ b/DiscoBot/sessions/test/test-1.json @@ -0,0 +1,79 @@ +{ + "GeneralContext": null, + "Relation": {}, + "Chars": [ + { + "Name": "Felis Exodus Schattenwald", + "Lebenspunkte_Aktuell": 30, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 20 + }, + { + "Name": "Gardist", + "Lebenspunkte_Aktuell": 29, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 0 + }, + { + "Name": "Hartmut Reiher", + "Lebenspunkte_Aktuell": 31, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 0 + }, + { + "Name": "Helga vom Drachenei, Tausendsasserin", + "Lebenspunkte_Aktuell": 21, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 35 + }, + { + "Name": "Krenko", + "Lebenspunkte_Aktuell": 25, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 0 + }, + { + "Name": "Ledur Torfinson", + "Lebenspunkte_Aktuell": 39, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 0 + }, + { + "Name": "Morla", + "Lebenspunkte_Aktuell": 26, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 13 + }, + { + "Name": "Numeri Illuminus", + "Lebenspunkte_Aktuell": 28, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 40 + }, + { + "Name": "Potus", + "Lebenspunkte_Aktuell": 39, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 16 + }, + { + "Name": "Pump aus der Gosse", + "Lebenspunkte_Aktuell": 18, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 13 + }, + { + "Name": "Rhoktar4", + "Lebenspunkte_Aktuell": 34, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 17 + }, + { + "Name": "Volant", + "Lebenspunkte_Aktuell": 28, + "Ausdauer_Aktuell": 0, + "Astralpunkte_Aktuell": 43 + } + ], + "SessionName": null +}
\ No newline at end of file |