summaryrefslogtreecommitdiff
path: root/DSALib
diff options
context:
space:
mode:
authorTrueDoctor <d-kobert@web.de>2018-07-09 23:38:43 +0200
committerTrueDoctor <d-kobert@web.de>2018-07-09 23:38:43 +0200
commit496c9c32cb8d0d067e675855289904a22b05d9ac (patch)
treec5fdb099be736b2debc9cd8685f63a9053e1195b /DSALib
parentf8123cd7a2df78fa1e08d2cbf08ce9ffda3d9583 (diff)
Implemented critter class and fixed some gui errors
Diffstat (limited to 'DSALib')
-rw-r--r--DSALib/Characters/Critter.cs74
-rw-r--r--DSALib/CritterAttack.cs27
-rw-r--r--DSALib/DSALib.csproj7
-rw-r--r--DSALib/packages.config4
4 files changed, 100 insertions, 12 deletions
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<CritterAttack> 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<CritterAttack> 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<Critter>(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 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+ <HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
@@ -45,11 +48,15 @@
<Compile Include="Characters\ICombatant.cs" />
<Compile Include="Characters\Entity.cs" />
<Compile Include="Characters\ICharacter.cs" />
+ <Compile Include="CritterAttack.cs" />
<Compile Include="KampfTalent.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Talent.cs" />
<Compile Include="Vorteil.cs" />
<Compile Include="Zauber.cs" />
</ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> \ 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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="Newtonsoft.Json" version="11.0.2" targetFramework="net461" />
+</packages> \ No newline at end of file