From 496c9c32cb8d0d067e675855289904a22b05d9ac Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Mon, 9 Jul 2018 23:38:43 +0200 Subject: Implemented critter class and fixed some gui errors --- DSALib/Characters/Critter.cs | 74 +++++++++++++++++++++++++++++++++++++------- DSALib/CritterAttack.cs | 27 ++++++++++++++++ DSALib/DSALib.csproj | 7 +++++ DSALib/packages.config | 4 +++ 4 files changed, 100 insertions(+), 12 deletions(-) create mode 100644 DSALib/CritterAttack.cs create mode 100644 DSALib/packages.config (limited to 'DSALib') diff --git a/DSALib/Characters/Critter.cs b/DSALib/Characters/Critter.cs index 5090b6b..c6776ed 100644 --- a/DSALib/Characters/Critter.cs +++ b/DSALib/Characters/Critter.cs @@ -1,26 +1,64 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace DSALib.Characters { + using System.IO; + using DiscoBot.DSA_Game.Characters; + using Newtonsoft.Json; + public class Critter : Being, ICombatant { - private int rs, mr, ko, pa, gs, gw; - + public int Rs { get; set; } + + public int Mr { get; set; } + + public int Ko { get; set; } + + public int Pa { get; set; } + + public int Gs { get; set; } + + public int Gw { get; set; } + + public string Ini { get; set; } + + public string Comment { get; set; } + + public List CritterAttacks { get; set; } - public Critter(int gw, int gs, int rs, int mr, int ko, int pa) + private CritterAttack lastAttack; + + public Critter(int gw, int gs, int rs, int mr, int ko, int pa, string ini, List critterAttacks) + { + this.Gw = gw; + this.Gs = gs; + this.Rs = rs; + this.Mr = mr; + this.Ko = ko; + this.Pa = pa; + this.Ini = ini; + this.CritterAttacks = critterAttacks; + this.lastAttack = this.CritterAttacks[new Random().Next(critterAttacks.Count)]; + } + + public Critter() + { + } + + public static Critter Load(string path) { - this.gw = gw; - this.gs = gs; - this.rs = rs; - this.mr = mr; - this.ko = ko; - this.pa = pa; + try + { + return JsonConvert.DeserializeObject(File.ReadAllText(path)); // Deserialize Data and create Session Object + } + catch (Exception e) + { + Console.WriteLine($"Laden von Save-File {path} fehlgeschlagen." + e); + return null; + } } public string Angriff(string talent, int erschwernis = 0) @@ -32,5 +70,17 @@ namespace DSALib.Characters { throw new NotImplementedException(); } + + public void Save(string path = @"..\..\Critters\") + { + try + { + File.WriteAllText(path + this.Name + ".json", JsonConvert.SerializeObject(this, Formatting.Indented)); // Deserialize Data and create CommandInfo Struct + } + catch (Exception e) + { + Console.WriteLine($"Speichern von Save-File {path} fehlgeschlagen." + e); + } + } } } diff --git a/DSALib/CritterAttack.cs b/DSALib/CritterAttack.cs new file mode 100644 index 0000000..0ad4a66 --- /dev/null +++ b/DSALib/CritterAttack.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DSALib +{ + public class CritterAttack + { + public CritterAttack(string name, int at, string tp, string comment = "") + { + this.Name = name; + this.At = at; + this.Tp = tp; + this.Comment = comment; + } + + public string Name { get; set; } + + public int At { get; set; } + + public string Tp { get; set; } + + public string Comment { get; set; } + } +} diff --git a/DSALib/DSALib.csproj b/DSALib/DSALib.csproj index db17bf7..27514d5 100644 --- a/DSALib/DSALib.csproj +++ b/DSALib/DSALib.csproj @@ -30,6 +30,9 @@ 4 + + ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + @@ -45,11 +48,15 @@ + + + + \ No newline at end of file diff --git a/DSALib/packages.config b/DSALib/packages.config new file mode 100644 index 0000000..5762754 --- /dev/null +++ b/DSALib/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file -- cgit v1.2.3-54-g00ecf