From ba1f440d0762ab77cd3f08734043df7db5b4329e Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Fri, 15 Jun 2018 21:58:34 +0200 Subject: implemented session saves --- DiscoBot/DSA_Game/Characters/Character.cs | 4 +- DiscoBot/DSA_Game/Characters/SaveChar.cs | 69 +++++++++++++++++ DiscoBot/DSA_Game/Dsa.cs | 27 ++++--- DiscoBot/DSA_Game/Save/Properties.cs | 5 +- DiscoBot/DSA_Game/Save/Session.cs | 50 ++++++++++++ DiscoBot/DiscoBot.csproj | 2 + DiscoBot/Properties.json | 3 +- DiscoBot/session.json | 125 ++++++++++++++++++++++++++++++ 8 files changed, 269 insertions(+), 16 deletions(-) create mode 100644 DiscoBot/DSA_Game/Characters/SaveChar.cs create mode 100644 DiscoBot/DSA_Game/Save/Session.cs create mode 100644 DiscoBot/session.json diff --git a/DiscoBot/DSA_Game/Characters/Character.cs b/DiscoBot/DSA_Game/Characters/Character.cs index c1acd39..6616a03 100644 --- a/DiscoBot/DSA_Game/Characters/Character.cs +++ b/DiscoBot/DSA_Game/Characters/Character.cs @@ -222,9 +222,9 @@ this.Lebenspunkte_Aktuell = this.Lebenspunkte_Basis; this.Astralpunkte_Aktuell = this.Astralpunkte_Basis; this.Ausdauer_Aktuell = this.Ausdauer_Basis; - - + } + private void Load(string path) { diff --git a/DiscoBot/DSA_Game/Characters/SaveChar.cs b/DiscoBot/DSA_Game/Characters/SaveChar.cs new file mode 100644 index 0000000..94538bb --- /dev/null +++ b/DiscoBot/DSA_Game/Characters/SaveChar.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DiscoBot.DSA_Game.Characters +{ + public class SaveChar : ICharacter + { + public string Name { get; set; } + + public int Lebenspunkte_Basis { get; set; } + + public int Lebenspunkte_Aktuell { get; set; } + + public int Ausdauer_Basis { get; set; } + + public int Ausdauer_Aktuell { get; set; } + + public int Astralpunkte_Basis { get; set; } + + public int Astralpunkte_Aktuell { get; set; } + + public static SaveChar FromICharacter(ICharacter c) + { + return new SaveChar + { + Astralpunkte_Aktuell = c.Astralpunkte_Aktuell, + Astralpunkte_Basis = c.Astralpunkte_Basis, + Ausdauer_Aktuell = c.Ausdauer_Aktuell, + Ausdauer_Basis = c.Ausdauer_Basis, + Lebenspunkte_Aktuell = c.Lebenspunkte_Aktuell, + Lebenspunkte_Basis = c.Lebenspunkte_Basis, + Name = c.Name + }; + } + + public string TestTalent(string talent, int erschwernis = 0) + { + throw new NotImplementedException(); + } + + public string TestEigenschaft(string eigenschaft, int erschwernis = 0) + { + throw new NotImplementedException(); + } + + public string Angriff(string talent, int erschwernis = 0) + { + throw new NotImplementedException(); + } + + public string Parade(string talent, int erschwernis = 0) + { + throw new NotImplementedException(); + } + + public string Fernkampf(string talent, int erschwernis = 0) + { + throw new NotImplementedException(); + } + + public string TestZauber(string waffe, int erschwernis) + { + throw new NotImplementedException(); + } + } +} diff --git a/DiscoBot/DSA_Game/Dsa.cs b/DiscoBot/DSA_Game/Dsa.cs index c6ea1c3..44175b6 100644 --- a/DiscoBot/DSA_Game/Dsa.cs +++ b/DiscoBot/DSA_Game/Dsa.cs @@ -1,11 +1,11 @@ namespace DiscoBot.DSA_Game { + using System; using System.Collections.Generic; using System.IO; using System.Linq; using DiscoBot.Audio; - using DiscoBot.Auxiliary; using DiscoBot.Commands; using DiscoBot.DSA_Game.Characters; using DiscoBot.DSA_Game.Save; @@ -25,7 +25,9 @@ public static List Talente { get; set; } = new List(); public static Properties Properties { get; set; } - + + public static Session Session { get; set; } + public static void Startup() { Relation.Add("The Doctor", "Numeri Illuminus"); // Relation @@ -37,18 +39,18 @@ Relation.Add("Nicolas", "Hartmut Reiher"); Relation.Add("TrueKuehli", "Ledur Torfinson"); - //Relation.Add("Papo","Gwendelson"); - //Relation.Add("Papo", "Pump aus der Gosse"); + // Relation.Add("Papo","Gwendelson"); + // Relation.Add("Papo", "Pump aus der Gosse"); - //Nachteile für LE, AE, MR + // Nachteile für LE, AE, MR // Relation.Add("Papo", "Angilbert Arres"); - //Vorteile für LE, AE, MR + // Vorteile für LE, AE, MR Relation.Add("Papo", "Beef"); - //Relation.Add("Papo", "Astrallos"); + // Relation.Add("Papo", "Astrallos"); Relation.Add("Potus", "Potus"); - + // relation.Add("Papo", "Pump aus der Gosse"); foreach (var filename in Directory.GetFiles("helden", "*.xml")) { @@ -57,10 +59,17 @@ .Where(c => !Talente.Exists(v => v.Name.Equals(c.Name))).ToList().ForEach(v => Talente.Add(v)); } - Properties = Save.Properties.Deserialize(); + Properties = Properties.Deserialize(); Properties.Serialize(); Talente = Talente.OrderBy(x => x.Name).ToList(); + + Session = new Session(); + List save = Chars.Select(SaveChar.FromICharacter).ToList(); + Session.Chars = save.Select(x=>x as ICharacter).ToList(); + Session.GeneralContext = GeneralContext; + Session.Relation = Relation; + Session.Save(); } } } \ No newline at end of file diff --git a/DiscoBot/DSA_Game/Save/Properties.cs b/DiscoBot/DSA_Game/Save/Properties.cs index 5d99a56..fe2f798 100644 --- a/DiscoBot/DSA_Game/Save/Properties.cs +++ b/DiscoBot/DSA_Game/Save/Properties.cs @@ -34,10 +34,7 @@ namespace DiscoBot.DSA_Game.Save } 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 diff --git a/DiscoBot/DSA_Game/Save/Session.cs b/DiscoBot/DSA_Game/Save/Session.cs new file mode 100644 index 0000000..b0a34a5 --- /dev/null +++ b/DiscoBot/DSA_Game/Save/Session.cs @@ -0,0 +1,50 @@ +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.DSA_Game.Characters; + + using Discord.Commands; + + using Newtonsoft.Json; + + public class Session + { + public ICommandContext GeneralContext { get; set; } + + public Dictionary Relation { get; set; } = new Dictionary(); // dictionary to match the char + + public List Chars { get; set; } = new List(); // list of all characters + + public static Session Load(string path = @"..\..\session.json") + { + try + { + return JsonConvert.DeserializeObject(File.ReadAllText(path)); // Deserialize Data and create Session Object + } + catch (Exception e) + { + // ignored + 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) + { + // ignored + } + } + } +} diff --git a/DiscoBot/DiscoBot.csproj b/DiscoBot/DiscoBot.csproj index 48aa374..f632c76 100644 --- a/DiscoBot/DiscoBot.csproj +++ b/DiscoBot/DiscoBot.csproj @@ -104,12 +104,14 @@ + + diff --git a/DiscoBot/Properties.json b/DiscoBot/Properties.json index c1fcccf..67765d4 100644 --- a/DiscoBot/Properties.json +++ b/DiscoBot/Properties.json @@ -93,7 +93,8 @@ "Sounds": [ { "Name": "Test", - "Url": "http" + "Url": "http", + "Volume": 100 } ] } \ No newline at end of file diff --git a/DiscoBot/session.json b/DiscoBot/session.json new file mode 100644 index 0000000..19251d5 --- /dev/null +++ b/DiscoBot/session.json @@ -0,0 +1,125 @@ +{ + "GeneralContext": null, + "Relation": { + "The Doctor": "Numeri Illuminus", + "Tardis": "Helga von Drachenei, Tausendsasserin", + "DSA Bot": "Morla", + "Morla": "Morla", + "Rhoktar": "Rhoktar4", + "MagicBro5": "Krenko", + "Nicolas": "Hartmut Reiher", + "TrueKuehli": "Ledur Torfinson", + "Papo": "Beef", + "Potus": "Potus" + }, + "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 + } + ] +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf