-
Notifications
You must be signed in to change notification settings - Fork 1
/
StatBlockDisplay.cs
388 lines (348 loc) · 15.3 KB
/
StatBlockDisplay.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using Newtonsoft.Json.Linq;
using System.Xml;
namespace Critter2FG
{
public partial class StatBlockDisplay : UserControl
{
public string name { get; set; }
public string nonIDName { get; set; }
public string size { get; set; }
public string type { get; set; }
public string alignment { get; set; }
public int armorclass { get; set; }
public string armorclasstext { get; set; }
public int hitpoints { get; set; }
public string hitpointstext { get; set; }
public string speed { get; set; }
public int statSTR { get; set; }
public int modSTR { get; set; }
public int statDEX { get; set; }
public int modDEX { get; set; }
public int statCON { get; set; }
public int modCON { get; set; }
public int statINT { get; set; }
public int modINT { get; set; }
public int statWIS { get; set; }
public int modWIS { get; set; }
public int statCHA { get; set; }
public int modCHA { get; set; }
public string savingthrows { get; set; }
public string skills { get; set; }
public string damagevulnerabilities { get; set; }
public string damageresistences { get; set; }
public string damageimmunities { get; set; }
public string conditionimmunities { get; set; }
public string senses { get; set; }
public string languages { get; set; }
public int challengerating { get; set; }
public int xp { get; set; }
public List<string[]> traits { get; set; }
public List<string[]> actions { get; set; }
public List<string[]> reactions { get; set; }
public List<string[]> legendaryactions { get; set; }
public List<string[]> lairactions { get; set; }
public List<string[]> innatespells { get; set; }
public StatBlockDisplay()
{
InitializeComponent();
lblAC.Text = "";
ConvertFromJSON("");
lblAC.Text = armorclass.ToString() + " " + armorclasstext;
lblHP.Text = hitpoints + " " + hitpointstext;
lblSpeed.Text = speed;
lblName.Text = name;
lblFlavor.Text = size + " " + type + " ," + alignment;
lblSTR.Text = abilityScore(statSTR, modSTR);
lblDEX.Text = abilityScore(statDEX, modDEX);
lblCON.Text = abilityScore(statCON, modCON);
lblINT.Text = abilityScore(statINT, modINT);
lblWIS.Text = abilityScore(statWIS, modWIS);
lblCHA.Text = abilityScore(statCHA, modCHA);
}
private void panel4_Paint(object sender, PaintEventArgs e)
{
}
public string abilityScore(int score, int mod)
{
string modsign = "";
if (mod > 0)
{
modsign = "+";
}
string abilityscore = score + " (" + modsign + mod + ")";
return abilityscore;
}
public string mod(int mod)
{
string modsign = "";
if (mod > 0)
{
modsign = "+";
}
string modstring = modsign + mod;
return modstring;
}
public void ConvertFromJSON(string jsonpath)
{
string json = File.ReadAllText(@"D:\Downloads\Astral-Dreadnought.json");
JObject o = JObject.Parse(json);
name = (string)o["name"];
type = (string)o["stats"]["race"];
size = (string)o["stats"]["size"];
alignment = (string)o["stats"]["alignment"];
armorclass = (int)o["stats"]["armorClass"];
armorclasstext = (string)o["stats"]["armorType"];
hitpoints = (int)o["stats"]["hitPoints"];
hitpointstext = (string)o["stats"]["hitPointsStr"];
speed = (string)o["stats"]["speed"];
//--------------------------Abilities------------------------------------//
//--STR
statSTR = (int)o["stats"]["abilityScores"]["strength"];
modSTR = (int)o["stats"]["abilityScoreModifiers"]["strength"];
//--DEX
statDEX = (int)o["stats"]["abilityScores"]["dexterity"];
modDEX = (int)o["stats"]["abilityScoreModifiers"]["dexterity"];
//--CON
statCON = (int)o["stats"]["abilityScores"]["constitution"];
modCON = (int)o["stats"]["abilityScoreModifiers"]["constitution"];
//--INT
statINT = (int)o["stats"]["abilityScores"]["intelligence"];
modINT = (int)o["stats"]["abilityScoreModifiers"]["intelligence"];
//--WIS
statWIS = (int)o["stats"]["abilityScores"]["wisdom"];
modWIS = (int)o["stats"]["abilityScoreModifiers"]["wisdom"];
//--CHA
statCHA = (int)o["stats"]["abilityScores"]["charisma"];
modCHA = (int)o["stats"]["abilityScoreModifiers"]["charisma"];
//--------------------------------------------------------------------------//
//Saving Throws
List<string> savingthrowlist = new List<string>();
foreach (JObject savingthrow in o["stats"]["savingThrows"])
{
savingthrowlist.Add((string)savingthrow["modifierStr"]);
}
savingthrows = string.Join(",", savingthrowlist);
//Skills
List<string> skillslist = new List<string>();
foreach (JObject skills in o["stats"]["skills"])
{
skillslist.Add((string)skills["modifierStr"]);
}
skills = string.Join(",", skillslist);
//Damage Resistances
}
public void SingleAttribute(XmlWriter writer, string attributename, string type, string value)
{
writer.WriteStartElement(attributename);
writer.WriteAttributeString("type", type);
writer.WriteString(value);
writer.WriteEndElement();
}
public void ExportToXML(string name)
{
using (FileStream fileStream = new FileStream(name + ".xml", FileMode.Create))
using (StreamWriter sw = new StreamWriter(fileStream))
using (XmlTextWriter writer = new XmlTextWriter(sw))
{
/*
*
<name type="string">Astral Dreadnought</name>
<savingthrows type="string">Dex +5, Wis +9</savingthrows>
<senses type="string">darkvision 120 ft., passive Perception 19</senses>
<size type="string">Gargantuan</size>
<skills type="string">Perception +9</skills>
<speed type="string">15 ft., fly 80 ft. (hover)</speed>
<alignment type="string">unaligned</alignment>
<conditionimmunities type="string">charmed, exhaustion, frightened, paralyzed, petrified, poisoned, prone, stunned</conditionimmunities>
<cr type="string">21</cr>
<damageresistances type="string">bludgeoning, piercing, and slashing from nonmagical weapons</damageresistances>
<hd type="string">(17d20 + 119)</hd>
<hp type="number">297</hp>
<ac type="number">20</ac>
<actext type="string">(natural armor)</actext>
<type type="string">monstrosity (titan)</type>
* */
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.WriteStartElement("id-00001");
//name
SingleAttribute(writer, "name", "string", name);
//size
writer.WriteStartElement("size");
writer.WriteAttributeString("type", "string");
writer.WriteString(size);
writer.WriteEndElement();
//type
writer.WriteStartElement("type");
writer.WriteAttributeString("type", "string");
writer.WriteString(type);
writer.WriteEndElement();
//alignment
writer.WriteStartElement("alignment");
writer.WriteAttributeString("type", "string");
writer.WriteString(alignment);
writer.WriteEndElement();
//
writer.WriteStartElement("abilities");
//STR
writer.WriteStartElement("strength");
writer.WriteStartElement("bonus");
writer.WriteAttributeString("type", "number");
writer.WriteString(modSTR.ToString());
writer.WriteEndElement();
writer.WriteStartElement("modifier");
writer.WriteAttributeString("type", "string");
writer.WriteString(mod(modSTR));
writer.WriteEndElement();
writer.WriteStartElement("score");
writer.WriteAttributeString("type", "number");
writer.WriteString(statSTR.ToString());
writer.WriteEndElement();
writer.WriteEndElement();
//DEX
writer.WriteStartElement("dexterity");
writer.WriteStartElement("bonus");
writer.WriteAttributeString("type", "number");
writer.WriteString(modDEX.ToString());
writer.WriteEndElement();
writer.WriteStartElement("modifier");
writer.WriteAttributeString("type", "string");
writer.WriteString(mod(modDEX));
writer.WriteEndElement();
writer.WriteStartElement("score");
writer.WriteAttributeString("type", "number");
writer.WriteString(statDEX.ToString());
writer.WriteEndElement();
writer.WriteEndElement();
//CON
writer.WriteStartElement("constitution");
writer.WriteStartElement("bonus");
writer.WriteAttributeString("type", "number");
writer.WriteString(modCON.ToString());
writer.WriteEndElement();
writer.WriteStartElement("modifier");
writer.WriteAttributeString("type", "string");
writer.WriteString(mod(modCON));
writer.WriteEndElement();
writer.WriteStartElement("score");
writer.WriteAttributeString("type", "number");
writer.WriteString(statCON.ToString());
writer.WriteEndElement();
writer.WriteEndElement();
//INT
writer.WriteStartElement("intelligence");
writer.WriteStartElement("bonus");
writer.WriteAttributeString("type", "number");
writer.WriteString(modINT.ToString());
writer.WriteEndElement();
writer.WriteStartElement("modifier");
writer.WriteAttributeString("type", "string");
writer.WriteString(mod(modINT));
writer.WriteEndElement();
writer.WriteStartElement("score");
writer.WriteAttributeString("type", "number");
writer.WriteString(statINT.ToString());
writer.WriteEndElement();
writer.WriteEndElement();
//WIS
writer.WriteStartElement("wisdom");
writer.WriteStartElement("bonus");
writer.WriteAttributeString("type", "number");
writer.WriteString(modWIS.ToString());
writer.WriteEndElement();
writer.WriteStartElement("modifier");
writer.WriteAttributeString("type", "string");
writer.WriteString(mod(modWIS));
writer.WriteEndElement();
writer.WriteStartElement("score");
writer.WriteAttributeString("type", "number");
writer.WriteString(statWIS.ToString());
writer.WriteEndElement();
writer.WriteEndElement();
//CHA
writer.WriteStartElement("charisma");
writer.WriteStartElement("bonus");
writer.WriteAttributeString("type", "number");
writer.WriteString(modCHA.ToString());
writer.WriteEndElement();
writer.WriteStartElement("modifier");
writer.WriteAttributeString("type", "string");
writer.WriteString(mod(modCHA));
writer.WriteEndElement();
writer.WriteStartElement("score");
writer.WriteAttributeString("type", "number");
writer.WriteString(statCHA.ToString());
writer.WriteEndElement();
//end abilities
writer.WriteEndElement();
/*
*
<name type="string">Astral Dreadnought</name>
<savingthrows type="string">Dex +5, Wis +9</savingthrows>
<senses type="string">darkvision 120 ft., passive Perception 19</senses>
<size type="string">Gargantuan</size>
<skills type="string">Perception +9</skills>
<speed type="string">15 ft., fly 80 ft. (hover)</speed>
<alignment type="string">unaligned</alignment>
<conditionimmunities type="string">charmed, exhaustion, frightened, paralyzed, petrified, poisoned, prone, stunned</conditionimmunities>
<cr type="string">21</cr>
<damageresistances type="string">bludgeoning, piercing, and slashing from nonmagical weapons</damageresistances>
<hd type="string">(17d20 + 119)</hd>
<hp type="number">297</hp>
<ac type="number">20</ac>
<actext type="string">(natural armor)</actext>
<type type="string">monstrosity (titan)</type>
* */
//saving throws
if (!string.IsNullOrEmpty(skills))
{
writer.WriteStartElement("savingthrows");
writer.WriteAttributeString("type", "string");
writer.WriteString(savingthrows);
writer.WriteEndElement();
}
if (!string.IsNullOrEmpty(skills))
{
//skills
writer.WriteStartElement("skills");
writer.WriteAttributeString("type", "string");
writer.WriteString(skills);
writer.WriteEndElement();
}
if (!string.IsNullOrEmpty(damageresistences))
{
//skills
writer.WriteStartElement("damageresistances");
writer.WriteAttributeString("type", "string");
writer.WriteString(damageresistences);
writer.WriteEndElement();
}
if (!string.IsNullOrEmpty(conditionimmunities))
{
//skills
writer.WriteStartElement("conditionimmunities");
writer.WriteAttributeString("type", "string");
writer.WriteString(conditionimmunities);
writer.WriteEndElement();
}
writer.Flush();
}
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void panel6_Paint(object sender, PaintEventArgs e)
{
}
}
}