summaryrefslogtreecommitdiff
path: root/DSACore/DSA_Game
diff options
context:
space:
mode:
authorTrueDoctor <d-kobert@web.de>2018-09-26 20:51:37 +0200
committerTrueDoctor <d-kobert@web.de>2018-09-26 20:51:37 +0200
commitb411aa2128c2724bec0ecedb8cb4e1ffa59f3b53 (patch)
tree14e0a0cca2cf66b95fda402c8c7d7b6bd5b7b222 /DSACore/DSA_Game
parent92e8bb7523c775014ccf68355e3f0178ebf4a61c (diff)
disconnected most vital calles from the Discord Bot
Diffstat (limited to 'DSACore/DSA_Game')
-rw-r--r--DSACore/DSA_Game/Characters/Character.cs286
-rw-r--r--DSACore/DSA_Game/Characters/NPC.cs114
-rw-r--r--DSACore/DSA_Game/Characters/SaveChar.cs44
-rw-r--r--DSACore/DSA_Game/Dsa.cs61
-rw-r--r--DSACore/DSA_Game/Save/Properties.cs77
-rw-r--r--DSACore/DSA_Game/Save/SaveCommand.cs70
-rw-r--r--DSACore/DSA_Game/Save/Session.cs47
7 files changed, 699 insertions, 0 deletions
diff --git a/DSACore/DSA_Game/Characters/Character.cs b/DSACore/DSA_Game/Characters/Character.cs
new file mode 100644
index 0000000..1236b12
--- /dev/null
+++ b/DSACore/DSA_Game/Characters/Character.cs
@@ -0,0 +1,286 @@
+using DSACore.Auxiliary;
+using DSALib;
+using DSALib.Characters;
+
+namespace DiscoBot.DSA_Game.Characters
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using System.Xml;
+
+
+ public class Character : Being, ICharacter
+ {
+ public Character()
+ {
+ this.PropTable.Add("MU", "Mut"); // routing
+ this.PropTable.Add("KL", "Klugheit");
+ this.PropTable.Add("IN", "Intuition");
+ this.PropTable.Add("CH", "Charisma");
+ this.PropTable.Add("FF", "Fingerfertigkeit");
+ this.PropTable.Add("GE", "Gewandtheit");
+ this.PropTable.Add("KO", "Konstitution");
+ this.PropTable.Add("KK", "Körperkraft");
+
+ }
+
+ public Character(string path) : this()
+ {
+ this.Load(path); // load
+ this.Post_process(); // calculate derived values
+ }
+
+ public Character(Character c, string name, int stDv = 2) : this()
+ {
+ this.Name = name;
+ foreach (var i in c.Eigenschaften)
+ {
+ this.Eigenschaften.Add(i.Key, i.Value + (int)Math.Round(RandomMisc.Random(stDv)));
+ }
+
+ foreach (var i in c.Vorteile)
+ {
+ this.Vorteile.Add(new Vorteil(i.Name, i.Value + (int)Math.Round(RandomMisc.Random(stDv))));
+ }
+
+ foreach (var i in c.Talente)
+ {
+ this.Talente.Add(new Talent(i.Name, i.Probe, i.Value + (int)Math.Round(RandomMisc.Random(stDv))));
+ }
+
+ foreach (var i in c.Zauber)
+ {
+ this.Zauber.Add(new Zauber(i.Name, i.Probe, i.Value + (int)Math.Round(RandomMisc.Random(stDv)), i.Complexity, i.Representation));
+ }
+
+ foreach (var i in c.Kampftalente)
+ {
+ this.Kampftalente.Add(new KampfTalent(i.Name, i.At + (int)Math.Round(RandomMisc.Random(stDv)), i.Pa + (int)Math.Round(RandomMisc.Random(stDv))));
+ }
+
+ this.Post_process(); // calculate derived values
+ }
+
+ public Dictionary<string, int> Eigenschaften { get; set; } = new Dictionary<string, int>(); // char properties
+
+ public List<Talent> Talente { get; set; } = new List<Talent>(); // list of talent objects (talents)
+
+ public List<Zauber> Zauber { get; set; } = new List<Zauber>(); // list of spell objects
+
+ public List<KampfTalent> Kampftalente { get; set; } = new List<KampfTalent>(); // list of combat objects
+
+ public List<Vorteil> Vorteile { get; set; } = new List<Vorteil>();
+
+ public Dictionary<string, string> PropTable { get; set; } = new Dictionary<string, string>(); // -> Körperkraft
+
+ public string TestTalent(string talent, int erschwernis = 0) // Talentprobe
+ {
+ return this.Talente.ProbenTest(this, talent, erschwernis);
+ }
+
+ public string TestZauber(string zauber, int erschwernis = 0) // Talentprobe
+ {
+ return this.Zauber.ProbenTest(this, zauber, erschwernis);
+ }
+
+ 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) // pretty self explanatory
+ {
+ var output = new StringBuilder();
+ var sc = new SpellCorrect();
+ var attack = this.Kampftalente.OrderBy(x => sc.Compare(talent, x.Name)).First();
+ if (sc.Compare(talent, attack.Name) > SpellCorrect.ErrorThreshold)
+ {
+ 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 = this.Kampftalente.OrderBy(x => sc.Compare(talent, x.Name)).First();
+
+ if (sc.Compare(talent, attack.Name) > SpellCorrect.ErrorThreshold)
+ {
+ 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 = this.Eigenschaften["fk"];
+ var attack = this.Talente.OrderBy(x => sc.Compare(talent, x.Name)).First();
+ if (sc.Compare(talent, attack.Name) > SpellCorrect.ErrorThreshold)
+ {
+ 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();
+ }
+
+ private void Post_process()
+ {
+ var LE_Wert = this.Eigenschaften["Lebensenergie"];
+ var AE_Wert = this.Eigenschaften.First(s => s.Key.Contains("Astralenergie")).Value;
+
+ //var KL_Wert = this.Eigenschaften.First(s => s.Key.Contains("Klugheit")).Value;
+ var MU_Wert = this.Eigenschaften.First(s => s.Key.Contains("Mut")).Value;
+ var IN_Wert = this.Eigenschaften.First(s => s.Key.Contains("Intuition")).Value;
+ var CH_Wert = this.Eigenschaften.First(s => s.Key.Contains("Charisma")).Value;
+ var KK_Wert = this.Eigenschaften["Körperkraft"];
+ var KO__Wert = this.Eigenschaften["Konstitution"];
+
+ this.Astralpunkte_Basis = 0;
+
+ this.Ausdauer_Basis = 0;
+
+ this.Lebenspunkte_Basis = LE_Wert + (int)(KO__Wert + (KK_Wert / 2.0) + 0.5);
+
+ if (this.Vorteile.Exists(x => x.Name.ToLower().Contains("zauberer")))
+ {
+ this.Astralpunkte_Basis = AE_Wert + (int)((MU_Wert + IN_Wert + CH_Wert) / 2.0 + 0.5);
+ }
+
+ this.Lebenspunkte_Aktuell = this.Lebenspunkte_Basis;
+ this.Astralpunkte_Aktuell = this.Astralpunkte_Basis;
+ this.Ausdauer_Aktuell = this.Ausdauer_Basis;
+
+ }
+
+
+ private void Load(string path)
+ {
+ var reader = new XmlTextReader(path);
+ while (reader.Read())
+ {
+ // read until he hits keywords
+ if (reader.NodeType != XmlNodeType.Element)
+ {
+ continue;
+ }
+
+ switch (reader.Name)
+ {
+ case "Wesen":
+ reader.Skip();
+ break;
+ case "held":
+ this.Name = reader.GetAttribute("name"); // name
+ break;
+ case "eigenschaft":
+ this.Eigenschaften.Add(
+ reader.GetAttribute("name") ?? throw new InvalidOperationException(),
+ 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"))));
+ reader.GetAttribute("value")));
+ }
+ catch
+ {
+ this.Vorteile.Add(new Vorteil(reader.GetAttribute("name")));
+ }
+
+ reader.Read();
+ }
+
+ break;
+ case "talentliste":
+ reader.Read();
+ while (reader.Name.Equals("talent"))
+ {
+ this.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"))
+ {
+ this.Zauber.Add(
+ new Zauber(
+ reader.GetAttribute("name"),
+ reader.GetAttribute("probe")?.Remove(0, 2).Trim(')'),
+ Convert.ToInt32(reader.GetAttribute("value")),
+ reader.GetAttribute("k").ToCharArray()[0],
+ reader.GetAttribute("repraesentation")));
+ 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"));
+ this.Kampftalente.Add(new KampfTalent(atName, at, pa));
+ break;
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/DSACore/DSA_Game/Characters/NPC.cs b/DSACore/DSA_Game/Characters/NPC.cs
new file mode 100644
index 0000000..ec8adfc
--- /dev/null
+++ b/DSACore/DSA_Game/Characters/NPC.cs
@@ -0,0 +1,114 @@
+using DSACore.Auxiliary;
+using DSALib.Characters;
+
+namespace DiscoBot.Characters
+{
+ using System;
+
+ using DiscoBot.Auxiliary;
+ using DiscoBot.DSA_Game.Characters;
+
+ public class Npc : Being, ICharacter
+ {
+ private readonly int mean, stDv;
+
+ public Npc(string name, int mean, int stDv)
+ {
+ this.mean = mean;
+ this.stDv = stDv;
+ this.Name = name;
+ }
+
+ 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(RandomMisc.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(RandomMisc.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";
+ }
+
+ public string TestZauber(string zauber, int erschwernis)
+ {
+ return TestTalent(zauber, erschwernis);
+ }
+ }
+}
diff --git a/DSACore/DSA_Game/Characters/SaveChar.cs b/DSACore/DSA_Game/Characters/SaveChar.cs
new file mode 100644
index 0000000..50cb91c
--- /dev/null
+++ b/DSACore/DSA_Game/Characters/SaveChar.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using DSALib.Characters;
+
+namespace DiscoBot.DSA_Game.Characters
+{
+
+ public class SaveChar
+ {
+ public string Name { get; set; }
+
+ public int Lebenspunkte_Aktuell { get; set; }
+
+ public int Ausdauer_Aktuell { get; set; }
+
+ public int Astralpunkte_Aktuell { get; set; }
+
+ public static SaveChar FromICharacter(ICharacter c)
+ {
+ return new SaveChar
+ {
+ Astralpunkte_Aktuell = c.Astralpunkte_Aktuell,
+ Ausdauer_Aktuell = c.Ausdauer_Aktuell,
+ Lebenspunkte_Aktuell = c.Lebenspunkte_Aktuell,
+ Name = c.Name
+ };
+ }
+ }
+
+
+ public static class ICharExtension
+ {
+ public static void Update(this ICharacter c, SaveChar s)
+ {
+ c.Astralpunkte_Aktuell = s.Astralpunkte_Aktuell;
+ c.Ausdauer_Aktuell = s.Ausdauer_Aktuell;
+ c.Lebenspunkte_Aktuell = s.Lebenspunkte_Aktuell;
+ c.Name = s.Name;
+ }
+ }
+}
diff --git a/DSACore/DSA_Game/Dsa.cs b/DSACore/DSA_Game/Dsa.cs
new file mode 100644
index 0000000..8907f96
--- /dev/null
+++ b/DSACore/DSA_Game/Dsa.cs
@@ -0,0 +1,61 @@
+using DSALib;
+using DSALib.Characters;
+
+namespace DiscoBot.DSA_Game
+{
+ using System.Collections.Generic;
+ using System.IO;
+ using System.Linq;
+ using DiscoBot.DSA_Game.Characters;
+ using DiscoBot.DSA_Game.Save;
+
+ public static class Dsa
+ {
+ private static Session s_session;
+
+ 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 Session Session
+ {
+ get
+ {
+ s_session.Chars = Chars.Select(x => SaveChar.FromICharacter(x)).ToList();
+ return s_session;
+ }
+
+ set
+ {
+ s_session = value;
+ foreach (var x in value.Chars)
+ {
+ Chars.Find(c => c.Name.Equals(x.Name)).Update(x);
+ }
+ }
+ }
+
+ public static void Startup()
+ {
+ //new DiscoBot.Auxiliary.Calculator.StringSolver("1d100 - (1d200 + 1) * -50000").Solve();
+ /*Session = new Session();*/
+ // 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));
+ }
+
+ Properties.Deserialize();
+ Properties.Serialize();
+
+ Talente = Talente.OrderBy(x => x.Name).ToList();
+ Session = new Session
+ {
+ Chars = Chars.Select(x => SaveChar.FromICharacter(x)).ToList()
+ };
+ Session.Save();
+ }
+ }
+} \ No newline at end of file
diff --git a/DSACore/DSA_Game/Save/Properties.cs b/DSACore/DSA_Game/Save/Properties.cs
new file mode 100644
index 0000000..a27c9d7
--- /dev/null
+++ b/DSACore/DSA_Game/Save/Properties.cs
@@ -0,0 +1,77 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using DSACore.Audio;
+using DSACore.Auxiliary;
+
+namespace DiscoBot.DSA_Game.Save
+{
+ using System.Collections;
+ using System.IO;
+ using Newtonsoft.Json;
+
+ public static class Properties
+ {
+ private static Dictionary<string, object> objects;
+
+ static Properties()
+ {
+ objects = new Dictionary<string, object>();
+ /*this.objects.Add("Sounds", new List<Sound>());
+ this.objects.Add("CommandInfos", new List<CommandInfo>());*/
+ }
+
+ public static List<CommandInfo> CommandInfos { get => objects["CommandInfo"] as List<CommandInfo>; set => objects["CommandInfo"] = value; } // use Properties.Commandinfos to access the abstract Object array
+
+ public static List<Sound> Sounds { get => objects["Sound"] as List<Sound>; set => objects["Sound"] = value; }
+
+ public static void Deserialize(string path = @"..\..\Properties")
+ {
+
+ var files = Directory.GetFiles(path, "*.json");
+
+ foreach (string file in files)
+ {
+ try
+ {
+ string name = file.Split('\\').Last().Split('.')[0].Replace('-', '.');
+ string data = File.ReadAllText(file);
+ Type type = Type.GetType(name);
+ if (data.StartsWith("["))
+ {
+ type = typeof(List<>).MakeGenericType(type);
+ }
+
+ var o = JsonConvert.DeserializeObject(data, type);
+ objects.Add(name.Split('.').Last(), o);
+ }
+ catch (Exception e)
+ {
+ // ignored
+ Console.WriteLine($"Laden von Save-File {file} fehlgeschlagen."+ e);
+ }
+
+ }
+
+ }
+
+ public static void Serialize(string path = @"..\..\Properties\")
+ {
+ try
+ {
+ foreach (var o in objects)
+ {
+ string assembly = o.Value is IList list ? ((IList)list)[0]?.GetType().FullName : o.Value.GetType().FullName;
+
+ var name = path + assembly.Replace('.', '-') + ".json";
+ File.WriteAllText(name, JsonConvert.SerializeObject(o.Value, Formatting.Indented)); // Deserialize Data and create CommandInfo Struct
+ }
+ }
+ catch (Exception e)
+ {
+ // ignored
+ Console.WriteLine($"Speichern von Save-File fehlgeschlagen."+ e);
+ }
+ }
+ }
+}
diff --git a/DSACore/DSA_Game/Save/SaveCommand.cs b/DSACore/DSA_Game/Save/SaveCommand.cs
new file mode 100644
index 0000000..9a2ae8e
--- /dev/null
+++ b/DSACore/DSA_Game/Save/SaveCommand.cs
@@ -0,0 +1,70 @@
+using System;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace DiscoBot.DSA_Game.Save
+{
+ using System.IO;
+
+ public class SaveCommand
+ {
+ public void LoadSession(string name = "")
+ {
+ if (name.Equals("?") || name.Equals(string.Empty))
+ {
+ Console.WriteLine($"Gespeicherte Sessions:");
+ Console.WriteLine(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);
+
+ Console.WriteLine($"{name} wurde geladen");
+ }
+
+ public void SessionSave(string name = "")
+ {
+ //var sendFile = this.Context.Channel.SendWebFile("https://cdn.discordapp.com/attachments/377123019673567232/465615882048110603/giphy.gif");
+
+ if (name.Equals("?") || name.Equals(string.Empty))
+ {
+ Console.WriteLine($"Gespeicherte Sessions:");
+ Console.WriteLine(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.SessionName = name;
+ Dsa.Session.Save(path + "\\" + name + $"-{++current}.json");
+ }
+ else
+ {
+ Directory.CreateDirectory(path);
+ Dsa.Session.SessionName = name;
+ Dsa.Session.Save(path + "\\" + name + $"-0.json");
+ }
+
+ Console.WriteLine($"{name} wurde gespeichert");
+ //await sendFile;
+ }
+
+ private string[] ListSessions()
+ {
+ string[] dirs = Directory.GetDirectories(Session.DirectoryPath).OrderByDescending(x => new DirectoryInfo(x).LastAccessTime.Ticks).ToArray();
+ for (int i = 0; i < dirs.Length; i++)
+ {
+ dirs[i] += "; " + new DirectoryInfo(dirs[i]).LastAccessTime;
+ }
+
+ return dirs;
+ }
+ }
+}
diff --git a/DSACore/DSA_Game/Save/Session.cs b/DSACore/DSA_Game/Save/Session.cs
new file mode 100644
index 0000000..d0cba21
--- /dev/null
+++ b/DSACore/DSA_Game/Save/Session.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+
+namespace DiscoBot.DSA_Game.Save
+{
+ using System.IO;
+ using DiscoBot.DSA_Game.Characters;
+ using Newtonsoft.Json;
+
+ public class Session
+ {
+ public static string DirectoryPath { get; set; } = @"..\..\sessions";
+
+ public Dictionary<string, string> Relation { get; set; } = new Dictionary<string, string>(); // dictionary to match the char
+
+ 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
+ {
+ return JsonConvert.DeserializeObject<Session>(File.ReadAllText(path)); // Deserialize Data and create Session Object
+ }
+ catch (Exception e)
+ {
+ // ignored
+ Console.WriteLine($"Laden von Save-File {path} fehlgeschlagen."+ e);
+ return null;
+ }
+ }
+
+ public void Save(string path = @"..\..\session.json")
+ {
+ try
+ {
+ File.WriteAllText(path, JsonConvert.SerializeObject(this, Formatting.Indented)); // Deserialize Data and create CommandInfo Struct
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine($"Speichern von Save-File {path} fehlgeschlagen.\n"+ e);
+ // ignored
+ }
+ }
+ }
+}