From b9abcb7ed618f08d7b2614843ab6c4feea5ff573 Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Fri, 22 Jun 2018 15:56:04 +0200 Subject: Character stats do now get updated, when a session is loaded or saved --- DiscoBot/DSA_Game/Characters/SaveChar.cs | 14 ++++++++++++++ DiscoBot/DSA_Game/Dsa.cs | 31 ++++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 7 deletions(-) (limited to 'DiscoBot/DSA_Game') diff --git a/DiscoBot/DSA_Game/Characters/SaveChar.cs b/DiscoBot/DSA_Game/Characters/SaveChar.cs index 89ca98a..4c9a940 100644 --- a/DiscoBot/DSA_Game/Characters/SaveChar.cs +++ b/DiscoBot/DSA_Game/Characters/SaveChar.cs @@ -6,6 +6,8 @@ using System.Threading.Tasks; namespace DiscoBot.DSA_Game.Characters { + using Discord; + public class SaveChar { public string Name { get; set; } @@ -27,4 +29,16 @@ namespace DiscoBot.DSA_Game.Characters }; } } + + + 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/DiscoBot/DSA_Game/Dsa.cs b/DiscoBot/DSA_Game/Dsa.cs index f1ed069..09e874d 100644 --- a/DiscoBot/DSA_Game/Dsa.cs +++ b/DiscoBot/DSA_Game/Dsa.cs @@ -14,6 +14,8 @@ public static class Dsa { + private static Session s_session; + public static ICommandContext GeneralContext { get; set; } public static AudioService Service { get; set; } @@ -22,11 +24,27 @@ public static List Talente { get; set; } = new List(); - public static Session Session { get; set; } = new Session(); + 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() { - + /*Session = new Session();*/ // relation.Add("Papo", "Pump aus der Gosse"); foreach (var filename in Directory.GetFiles("helden", "*.xml")) { @@ -39,12 +57,11 @@ Properties.Serialize(); Talente = Talente.OrderBy(x => x.Name).ToList(); - Session = new Session - { - Chars = Chars.Select(x => SaveChar.FromICharacter(x)).ToList(), - GeneralContext = GeneralContext - }; + { + Chars = Chars.Select(x => SaveChar.FromICharacter(x)).ToList(), + GeneralContext = GeneralContext + }; Session.Save(); } } -- cgit v1.2.3-54-g00ecf