summaryrefslogtreecommitdiff
path: root/dsa/DSALib/DSA_Game
diff options
context:
space:
mode:
authorDennis Kobert <d-kobert@web.de>2019-06-12 21:47:51 +0200
committerDennis Kobert <d-kobert@web.de>2019-06-12 21:47:51 +0200
commit304437b834e8c87687f68333ae67a13ee1377a73 (patch)
tree51dd246568e8a159627d9cb92e99890adb5cbef8 /dsa/DSALib/DSA_Game
parent2fa4a0e50ebfc97059c8b84dbd17e79f9afc8a8d (diff)
Adjust Codestyle
Diffstat (limited to 'dsa/DSALib/DSA_Game')
-rw-r--r--dsa/DSALib/DSA_Game/Characters/Character.cs58
-rw-r--r--dsa/DSALib/DSA_Game/Characters/NPC.cs31
-rw-r--r--dsa/DSALib/DSA_Game/Characters/SaveChar.cs18
-rw-r--r--dsa/DSALib/DSA_Game/Dsa.cs30
-rw-r--r--dsa/DSALib/DSA_Game/Save/Properties.cs33
-rw-r--r--dsa/DSALib/DSA_Game/Save/SaveCommand.cs27
-rw-r--r--dsa/DSALib/DSA_Game/Save/Session.cs24
7 files changed, 74 insertions, 147 deletions
diff --git a/dsa/DSALib/DSA_Game/Characters/Character.cs b/dsa/DSALib/DSA_Game/Characters/Character.cs
index aea5671..3e4022e 100644
--- a/dsa/DSALib/DSA_Game/Characters/Character.cs
+++ b/dsa/DSALib/DSA_Game/Characters/Character.cs
@@ -9,12 +9,9 @@ using DSALib.Auxiliary;
using DSALib.Characters;
using DSALib.Models.Dsa;
-namespace DSALib.DSA_Game.Characters
-{
- public class Character : Being, ICharacter
- {
- public Character()
- {
+namespace DSALib.DSA_Game.Characters {
+ public class Character : Being, ICharacter {
+ public Character() {
PropTable.Add("MU", "Mut"); // routing
PropTable.Add("KL", "Klugheit");
PropTable.Add("IN", "Intuition");
@@ -25,20 +22,17 @@ namespace DSALib.DSA_Game.Characters
PropTable.Add("KK", "Körperkraft");
}
- public Character(string path) : this()
- {
+ public Character(string path) : this() {
Load(new MemoryStream(File.ReadAllBytes(path))); // load
Post_process(); // calculate derived values
}
- public Character(MemoryStream stream) : this()
- {
+ public Character(MemoryStream stream) : this() {
Load(stream); // load
Post_process(); // calculate derived values
}
- public Character(Character c, string name, int stDv = 2) : this()
- {
+ public Character(Character c, string name, int stDv = 2) : this() {
Name = name;
foreach (var i in c.Eigenschaften)
Eigenschaften.Add(i.Key, i.Value + (int) Math.Round(RandomMisc.Random(stDv)));
@@ -82,8 +76,7 @@ namespace DSALib.DSA_Game.Characters
return Zauber.ProbenTest(this, zauber, erschwernis);
}
- public string TestEigenschaft(string eigenschaft, int erschwernis = 0)
- {
+ public string TestEigenschaft(string eigenschaft, int erschwernis = 0) {
var output = new StringBuilder();
var prop = PropTable[eigenschaft.ToUpper()];
var tap = Eigenschaften[prop];
@@ -115,11 +108,10 @@ namespace DSALib.DSA_Game.Characters
return output.ToString();
}
- public string Parade(string talent, int erschwernis = 0)
- {
+ public string Parade(string talent, int erschwernis = 0) {
var output = new StringBuilder();
- if (Kampftalente.TryMatch(out var iAttack , talent))
+ if (Kampftalente.TryMatch(out var iAttack, talent))
return $"{Name} kann nicht mit der Waffenart {talent} umgehen...";
@@ -136,11 +128,10 @@ namespace DSALib.DSA_Game.Characters
return output.ToString();
}
- public string Fernkampf(string talent, int erschwernis = 0)
- {
+ public string Fernkampf(string talent, int erschwernis = 0) {
var output = new StringBuilder();
var fk = Eigenschaften["fk"];
- if (! Talente.TryMatch(out var iAttack, talent))
+ if (!Talente.TryMatch(out var iAttack, talent))
return $"{Name} kann nicht mit der Waffenart {talent} umgehen...";
var attack = (Talent) iAttack;
@@ -157,8 +148,7 @@ namespace DSALib.DSA_Game.Characters
return output.ToString();
}
- private void Post_process()
- {
+ private void Post_process() {
var LE_Wert = Eigenschaften["Lebensenergie"];
var AE_Wert = Eigenschaften.First(s => s.Key.Contains("Astralenergie")).Value;
@@ -184,16 +174,13 @@ namespace DSALib.DSA_Game.Characters
}
- private void Load(MemoryStream stream)
- {
+ private void Load(MemoryStream stream) {
var reader = new XmlTextReader(stream);
- while (reader.Read())
- {
+ while (reader.Read()) {
// read until he hits keywords
if (reader.NodeType != XmlNodeType.Element) continue;
- switch (reader.Name)
- {
+ switch (reader.Name) {
case "Wesen":
reader.Skip();
break;
@@ -208,17 +195,14 @@ namespace DSALib.DSA_Game.Characters
break;
case "vt":
reader.Read();
- while (reader.Name.Equals("vorteil"))
- {
- try
- {
+ while (reader.Name.Equals("vorteil")) {
+ try {
Vorteile.Add(new Vorteil(
reader.GetAttribute("name"),
// Convert.ToInt32(reader.GetAttribute("value"))));
reader.GetAttribute("value")));
}
- catch
- {
+ catch {
Vorteile.Add(new Vorteil(reader.GetAttribute("name")));
}
@@ -228,8 +212,7 @@ namespace DSALib.DSA_Game.Characters
break;
case "talentliste":
reader.Read();
- while (reader.Name.Equals("talent"))
- {
+ while (reader.Name.Equals("talent")) {
Talente.Add(
new Talent(
reader.GetAttribute("name"),
@@ -241,8 +224,7 @@ namespace DSALib.DSA_Game.Characters
break;
case "zauberliste":
reader.Read();
- while (reader.Name.Equals("zauber"))
- {
+ while (reader.Name.Equals("zauber")) {
Zauber.Add(
new Zauber(
reader.GetAttribute("name"),
diff --git a/dsa/DSALib/DSA_Game/Characters/NPC.cs b/dsa/DSALib/DSA_Game/Characters/NPC.cs
index 105adda..6bcde0c 100644
--- a/dsa/DSALib/DSA_Game/Characters/NPC.cs
+++ b/dsa/DSALib/DSA_Game/Characters/NPC.cs
@@ -1,24 +1,18 @@
using System;
using DSALib.Auxiliary;
-using DSALib.Characters;
-namespace DSALib.Characters
-{
- public class Npc : Being, ICharacter
- {
+namespace DSALib.Characters {
+ public class Npc : Being, ICharacter {
private readonly int mean, stDv;
- public Npc(string name, int mean, int stDv)
- {
+ public Npc(string name, int mean, int stDv) {
this.mean = mean;
this.stDv = stDv;
Name = name;
}
- public string TestTalent(string talent, int tap = 3)
- {
- for (var i = 0; i <= 2; i++)
- {
+ public string TestTalent(string talent, int tap = 3) {
+ for (var i = 0; i <= 2; i++) {
// foreach property, dice and tap
var temp = Dice.Roll();
var eigenschaft = (int) Math.Round(RandomMisc.Random(stDv, mean));
@@ -32,8 +26,7 @@ namespace DSALib.Characters
return $"{Name} scheitert an {talent}";
}
- public string TestEigenschaft(string eigenschaft, int erschwernis = 0)
- {
+ public string TestEigenschaft(string eigenschaft, int erschwernis = 0) {
var temp = Dice.Roll();
var prop = (int) Math.Round(RandomMisc.Random(stDv, stDv));
@@ -42,8 +35,7 @@ namespace DSALib.Characters
return $"{Name} scheitert an {eigenschaft}";
}
- public string Angriff(string waffe, int erschwernis = 0)
- {
+ public string Angriff(string waffe, int erschwernis = 0) {
var temp = Dice.Roll();
if (temp == 1) return $"{Name} greift kritisch mit {waffe} an";
@@ -53,8 +45,7 @@ namespace DSALib.Characters
return $"{Name} haut mit {waffe} daneben";
}
- public string Parade(string waffe, int erschwernis = 0)
- {
+ public string Parade(string waffe, int erschwernis = 0) {
var temp = Dice.Roll();
if (temp == 1) return $"{Name} pariert mit {waffe} meisterlich";
@@ -64,8 +55,7 @@ namespace DSALib.Characters
return $"{Name} schafft es nicht mit {waffe} zu parieren";
}
- public string Fernkampf(string waffe, int erschwernis = 0)
- {
+ public string Fernkampf(string waffe, int erschwernis = 0) {
var temp = Dice.Roll();
if (temp == 1) return $"{Name} trifft kritisch mit {waffe}";
@@ -75,8 +65,7 @@ namespace DSALib.Characters
return $"{Name} schießt mit {waffe} daneben";
}
- public string TestZauber(string zauber, int erschwernis)
- {
+ public string TestZauber(string zauber, int erschwernis) {
return TestTalent(zauber, erschwernis);
}
}
diff --git a/dsa/DSALib/DSA_Game/Characters/SaveChar.cs b/dsa/DSALib/DSA_Game/Characters/SaveChar.cs
index 00e2f86..b3c4fcd 100644
--- a/dsa/DSALib/DSA_Game/Characters/SaveChar.cs
+++ b/dsa/DSALib/DSA_Game/Characters/SaveChar.cs
@@ -1,9 +1,7 @@
using DSALib.Characters;
-namespace DSALib.DSA_Game.Characters
-{
- public class SaveChar
- {
+namespace DSALib.DSA_Game.Characters {
+ public class SaveChar {
public string Name { get; set; }
public int Lebenspunkte_Aktuell { get; set; }
@@ -12,10 +10,8 @@ namespace DSALib.DSA_Game.Characters
public int Astralpunkte_Aktuell { get; set; }
- public static SaveChar FromICharacter(ICharacter c)
- {
- return new SaveChar
- {
+ public static SaveChar FromICharacter(ICharacter c) {
+ return new SaveChar {
Astralpunkte_Aktuell = c.Astralpunkte_Aktuell,
Ausdauer_Aktuell = c.Ausdauer_Aktuell,
Lebenspunkte_Aktuell = c.Lebenspunkte_Aktuell,
@@ -25,10 +21,8 @@ namespace DSALib.DSA_Game.Characters
}
- public static class ICharExtension
- {
- public static void Update(this ICharacter c, SaveChar s)
- {
+ 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;
diff --git a/dsa/DSALib/DSA_Game/Dsa.cs b/dsa/DSALib/DSA_Game/Dsa.cs
index bcd8951..42be212 100644
--- a/dsa/DSALib/DSA_Game/Dsa.cs
+++ b/dsa/DSALib/DSA_Game/Dsa.cs
@@ -1,16 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using DSALib.Characters;
using DSALib.DSA_Game.Characters;
using DSALib.DSA_Game.Save;
-using DSALib;
-using DSALib.Characters;
using DSALib.Models.Dsa;
-namespace DSALib.DSA_Game
-{
- public static class Dsa
- {
+namespace DSALib.DSA_Game {
+ public static class Dsa {
#if DEBUG
public const string
rootPath = ""; //"C:\\Users\\Dennis\\Source\\Repos\\DiscoBot\\DSALib\\";//"DiscoBot\\DSALib\\";
@@ -25,23 +22,19 @@ namespace DSALib.DSA_Game
public static List<Zauber> Zauber { get; set; } = new List<Zauber>();
- public static Session Session
- {
- get
- {
+ public static Session Session {
+ get {
s_session.Chars = Chars.Select(x => SaveChar.FromICharacter(x)).ToList();
return s_session;
}
- set
- {
+ set {
s_session = value;
foreach (var x in value.Chars) Chars.Find(c => c.Name.Equals(x.Name)).Update(x);
}
}
- public static void Startup()
- {
+ public static void Startup() {
//new .Auxiliary.Calculator.StringSolver("1d100 - (1d200 + 1) * -50000").Solve();
/*Session = new Session();*/
// relation.Add("Papo", "Pump aus der Gosse");
@@ -75,20 +68,17 @@ namespace DSALib.DSA_Game
//new WeaponImporter().DownloadWeapons().Wait();
- Session = new Session
- {
+ Session = new Session {
Chars = Chars.Select(SaveChar.FromICharacter).ToList()
};
//Session.Save();
}
- public static ICharacter GetCharacter(ulong id)
- {
+ public static ICharacter GetCharacter(ulong id) {
throw new NotImplementedException();
}
- public static ICharacter GetCharacter(string name, ulong groupId)
- {
+ public static ICharacter GetCharacter(string name, ulong groupId) {
throw new NotImplementedException();
}
}
diff --git a/dsa/DSALib/DSA_Game/Save/Properties.cs b/dsa/DSALib/DSA_Game/Save/Properties.cs
index 2312af0..06628ed 100644
--- a/dsa/DSALib/DSA_Game/Save/Properties.cs
+++ b/dsa/DSALib/DSA_Game/Save/Properties.cs
@@ -6,33 +6,27 @@ using System.Linq;
using DSALib.Auxiliary;
using Newtonsoft.Json;
-namespace DSALib.DSA_Game.Save
-{
- public static class Properties
- {
+namespace DSALib.DSA_Game.Save {
+ public static class Properties {
public static Dictionary<string, object> objects;
- static Properties()
- {
+ 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
- {
+ 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 void Deserialize(string path = @"Properties")
- {
+ public static void Deserialize(string path = @"Properties") {
var files = Directory.GetFiles(path, "*.json");
foreach (var file in files)
- try
- {
+ try {
var name = file.Split('\\').Last().Split('.')[0].Replace('-', '.');
var data = File.ReadAllText(file);
var type = Type.GetType(name);
@@ -41,19 +35,15 @@ namespace DSALib.DSA_Game.Save
var o = JsonConvert.DeserializeObject(data, type);
objects.Add(name.Split('.').Last(), o);
}
- catch (Exception e)
- {
+ 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)
- {
+ public static void Serialize(string path = @"..\..\Properties\") {
+ try {
+ foreach (var o in objects) {
var assembly = o.Value is IList list
? list[0]?.GetType().FullName
: o.Value.GetType().FullName;
@@ -64,8 +54,7 @@ namespace DSALib.DSA_Game.Save
Formatting.Indented)); // Deserialize Data and create CommandInfo Struct
}
}
- catch (Exception e)
- {
+ catch (Exception e) {
// ignored
Console.WriteLine("Speichern von Save-File fehlgeschlagen." + e);
}
diff --git a/dsa/DSALib/DSA_Game/Save/SaveCommand.cs b/dsa/DSALib/DSA_Game/Save/SaveCommand.cs
index c5a1bb4..0153779 100644
--- a/dsa/DSALib/DSA_Game/Save/SaveCommand.cs
+++ b/dsa/DSALib/DSA_Game/Save/SaveCommand.cs
@@ -2,14 +2,10 @@
using System.IO;
using System.Linq;
-namespace DSALib.DSA_Game.Save
-{
- public class SaveCommand
- {
- public void LoadSession(string name = "")
- {
- if (name.Equals("?") || name.Equals(string.Empty))
- {
+namespace DSALib.DSA_Game.Save {
+ public class SaveCommand {
+ public void LoadSession(string name = "") {
+ if (name.Equals("?") || name.Equals(string.Empty)) {
Console.WriteLine("Gespeicherte Sessions:");
Console.WriteLine(ListSessions());
return;
@@ -24,27 +20,23 @@ namespace DSALib.DSA_Game.Save
Console.WriteLine($"{name} wurde geladen");
}
- public void SessionSave(string name = "")
- {
+ 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))
- {
+ if (name.Equals("?") || name.Equals(string.Empty)) {
Console.WriteLine("Gespeicherte Sessions:");
Console.WriteLine(ListSessions());
return;
}
var path = Session.DirectoryPath + @"\" + name;
- if (Directory.Exists(path))
- {
+ if (Directory.Exists(path)) {
var files = Directory.GetFiles(path);
var current = files.Max(x => Convert.ToInt32(x.Split('-').Last().Split('.').First()));
Dsa.Session.SessionName = name;
Dsa.Session.Save(path + "\\" + name + $"-{++current}.json");
}
- else
- {
+ else {
Directory.CreateDirectory(path);
Dsa.Session.SessionName = name;
Dsa.Session.Save(path + "\\" + name + "-0.json");
@@ -54,8 +46,7 @@ namespace DSALib.DSA_Game.Save
//await sendFile;
}
- private string[] ListSessions()
- {
+ private string[] ListSessions() {
var dirs = Directory.GetDirectories(Session.DirectoryPath)
.OrderByDescending(x => new DirectoryInfo(x).LastAccessTime.Ticks).ToArray();
for (var i = 0; i < dirs.Length; i++) dirs[i] += "; " + new DirectoryInfo(dirs[i]).LastAccessTime;
diff --git a/dsa/DSALib/DSA_Game/Save/Session.cs b/dsa/DSALib/DSA_Game/Save/Session.cs
index 62aa8f6..bd36bf8 100644
--- a/dsa/DSALib/DSA_Game/Save/Session.cs
+++ b/dsa/DSALib/DSA_Game/Save/Session.cs
@@ -4,10 +4,8 @@ using System.IO;
using DSALib.DSA_Game.Characters;
using Newtonsoft.Json;
-namespace DSALib.DSA_Game.Save
-{
- public class Session
- {
+namespace DSALib.DSA_Game.Save {
+ public class Session {
public static string DirectoryPath { get; set; } = Dsa.rootPath + @"sessions";
public Dictionary<string, string> Relation { get; set; } =
@@ -17,32 +15,26 @@ namespace DSALib.DSA_Game.Save
public string SessionName { get; set; }
- public static Session Load(string path)
- {
- try
- {
+ public static Session Load(string path) {
+ try {
return
JsonConvert.DeserializeObject<Session>(
File.ReadAllText(path)); // Deserialize Data and create Session Object
}
- catch (Exception e)
- {
+ catch (Exception e) {
// ignored
Console.WriteLine($"Laden von Save-File {path} fehlgeschlagen." + e);
return null;
}
}
- public void Save(string path)
- {
- try
- {
+ public void Save(string path) {
+ try {
File.WriteAllText(path,
JsonConvert.SerializeObject(this,
Formatting.Indented)); // Deserialize Data and create CommandInfo Struct
}
- catch (Exception e)
- {
+ catch (Exception e) {
Console.WriteLine($"Speichern von Save-File {path} fehlgeschlagen.\n" + e);
// ignored
}