-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathspell_form.cs
475 lines (462 loc) · 19.9 KB
/
spell_form.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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using cdda_item_creator.spell;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
namespace cdda_item_creator
{
public partial class spell_form : Form
{
public spell.spell_type main_spell = new spell.spell_type();
void update_effect_str( string effect )
{
effect_str_combobox.Items.Clear();
effect_str_combobox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown;
if (effect == "recover_energy")
{
effect_str_combobox.Items.AddRange(spell.allowed_strings.recover_energy_types);
effect_str_combobox.SelectedIndex = 0;
effect_combobox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
} else if( effect == "timed_event" )
{
effect_str_combobox.Items.AddRange(spell.allowed_strings.timed_event);
effect_str_combobox.SelectedIndex = 0;
effect_str_combobox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
} else if( effect == "pain_split" || effect == "teleport_random" || effect == "vomit" || effect == "explosion" ||
effect == "flashbang" || effect == "mod_moves" || effect == "map" || effect == "bash" || effect == "charm_monster" )
{
effect_str_combobox.SelectedIndex = -1;
effect_str_combobox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
}
}
private void EnableAllFields()
{
min_damage_updown.Enabled = true;
damage_increment_updown.Enabled = true;
max_damage_updown.Enabled = true;
min_range_updown.Enabled = true;
range_increment_updown.Enabled = true;
max_range_updown.Enabled = true;
min_aoe_updown.Enabled = true;
aoe_increment_updown.Enabled = true;
max_aoe_updown.Enabled = true;
min_duration_updown.Enabled = true;
duration_increment_updown.Enabled = true;
max_duration_updown.Enabled = true;
min_field_intensity_updown.Enabled = true;
field_intensity_increment_updown.Enabled = true;
max_field_intensity_updown.Enabled = true;
field_id_textbox.Enabled = true;
field_chance_updown.Enabled = true;
field_intensity_variance_updown.Enabled = true;
effect_filter_listbox.Enabled = true;
effected_body_part_listbox.Enabled = true;
valid_targets_listbox.Enabled = true;
effect_str_combobox.Enabled = true;
damage_type_combobox.Enabled = true;
// "none" is not desirable for most spells
// and it is also partially hidden down the list
valid_targets_listbox
.SetItemCheckState(4, CheckState.Unchecked);
}
private void ResetDisabledFieldValues()
{
List<NumericUpDown> disablable_fields = new List<NumericUpDown>{
min_damage_updown,
damage_increment_updown,
max_damage_updown,
min_range_updown,
range_increment_updown,
max_range_updown,
min_aoe_updown,
aoe_increment_updown,
max_aoe_updown,
min_duration_updown,
duration_increment_updown,
max_duration_updown,
min_field_intensity_updown,
field_intensity_increment_updown,
max_field_intensity_updown,
field_intensity_variance_updown
};
foreach(NumericUpDown box in disablable_fields)
{
if (!box.Enabled)
{
box.Value = 0;
}
}
if (!field_id_textbox.Enabled)
{
field_id_textbox.Text = "";
}
if(!field_chance_updown.Enabled)
{
field_chance_updown.Value = 1;
}
if (!damage_type_combobox.Enabled)
{
damage_type_combobox.SelectedItem = "NONE";
}
if (!effected_body_part_listbox.Enabled)
{
foreach (int i in effected_body_part_listbox.CheckedIndices)
{
effected_body_part_listbox
.SetItemCheckState(i, CheckState.Unchecked);
}
}
if (!valid_targets_listbox.Enabled)
{
foreach (int i in effected_body_part_listbox.CheckedIndices)
{
valid_targets_listbox
.SetItemCheckState(i, CheckState.Unchecked);
}
// sets to "none"
valid_targets_listbox
.SetItemCheckState(4, CheckState.Checked);
}
if (!effect_filter_listbox.Enabled)
{
foreach (int i in effect_filter_listbox.CheckedIndices)
{
effect_filter_listbox
.SetItemCheckState(i, CheckState.Unchecked);
}
}
}
private void DisableDamage()
{
min_damage_updown.Enabled = false;
damage_increment_updown.Enabled = false;
max_damage_updown.Enabled = false;
damage_type_combobox.Enabled = false;
UnsetDamageToolTip();
}
private void DisableRange()
{
min_range_updown.Enabled = false;
range_increment_updown.Enabled = false;
max_range_updown.Enabled = false;
}
private void DisableAoe()
{
min_aoe_updown.Enabled = false;
aoe_increment_updown.Enabled = false;
max_aoe_updown.Enabled = false;
}
private void DisableDuration()
{
min_duration_updown.Enabled = false;
duration_increment_updown.Enabled = false;
max_duration_updown.Enabled = false;
}
private void DisableFields()
{
min_field_intensity_updown.Enabled = false;
field_intensity_increment_updown.Enabled = false;
max_field_intensity_updown.Enabled = false;
field_id_textbox.Enabled = false;
field_chance_updown.Enabled = false;
field_intensity_variance_updown.Enabled = false;
}
private void EnableValidEffectValues()
{
string effect = effect_combobox.Text;
EnableAllFields();
switch (effect)
{
case "pain_split":
DisableDamage();
DisableRange();
DisableAoe();
DisableDuration();
DisableFields();
effect_filter_listbox.Enabled = false;
effected_body_part_listbox.Enabled = false;
valid_targets_listbox.Enabled = false;
effect_str_combobox.Enabled = false;
break;
case "target_attack":
case "projectile_attack":
case "cone_attack":
case "line_attack":
SetDamageToolTip("The amount of damage you deal to the target.\nIgnores dodge, and heals if the value is negative.");
effect_filter_listbox.Enabled = false;
break;
case "teleport_random":
DisableDamage();
DisableFields();
DisableDuration();
effect_filter_listbox.Enabled = false;
effected_body_part_listbox.Enabled = false;
valid_targets_listbox.Enabled = false;
effect_str_combobox.Enabled = false;
break;
case "spawn_item":
DisableFields();
DisableRange();
DisableAoe();
SetDamageToolTip("The number of items spawned.");
damage_type_combobox.Enabled = false;
effect_filter_listbox.Enabled = false;
effected_body_part_listbox.Enabled = false;
valid_targets_listbox.Enabled = false;
break;
case "recover_energy":
DisableFields();
SetDamageToolTip("The amount of energy recovered.");
damage_type_combobox.Enabled = false;
effect_filter_listbox.Enabled = false;
effected_body_part_listbox.Enabled = false;
break;
case "summon":
DisableFields();
SetDamageToolTip("The Number of creatures summoned.");
damage_type_combobox.Enabled = false;
effect_filter_listbox.Enabled = false;
effected_body_part_listbox.Enabled = false;
break;
case "translocate":
DisableDamage();
DisableDuration();
DisableFields();
effect_filter_listbox.Enabled = false;
effected_body_part_listbox.Enabled = false;
effect_str_combobox.Enabled = false;
break;
case "area_pull":
case "area_push":
DisableFields();
DisableDuration();
SetDamageToolTip("The number of spaces the targets will be moved.");
damage_type_combobox.Enabled = false;
effected_body_part_listbox.Enabled = false;
effect_str_combobox.Enabled = false;
break;
case "timed_event":
DisableDamage();
DisableRange();
DisableAoe();
DisableFields();
effect_filter_listbox.Enabled = false;
effected_body_part_listbox.Enabled = false;
valid_targets_listbox.Enabled = false;
break;
case "ter_transform":
DisableFields();
SetDamageToolTip("For each tile in the Area of effect, it is\na one in damage chance of transforming.");
effect_filter_listbox.Enabled = false;
effected_body_part_listbox.Enabled = false;
break;
case "noise":
DisableFields();
DisableAoe();
DisableDuration();
SetDamageToolTip("The amount of noise made at the target location.");
effect_filter_listbox.Enabled = false;
effected_body_part_listbox.Enabled = false;
break;
case "vomit":
DisableFields();
DisableDamage();
DisableDuration();
effect_filter_listbox.Enabled = false;
effected_body_part_listbox.Enabled = false;
break;
case "explosion":
DisableFields();
DisableDuration();
SetDamageToolTip("The power of the explosion.");
damage_type_combobox.Enabled = false;
effect_filter_listbox.Enabled = false;
effected_body_part_listbox.Enabled = false;
break;
case "flashbang":
DisableFields();
DisableDuration();
DisableDamage();
DisableAoe();
effect_filter_listbox.Enabled = false;
effected_body_part_listbox.Enabled = false;
break;
case "mod_moves":
DisableFields();
DisableDuration();
SetDamageToolTip("The number of moves altered by the spell.\nPositive numbers add mvoes, negative numbers subtract moves.");
damage_type_combobox.Enabled = false;
effect_filter_listbox.Enabled = false;
effected_body_part_listbox.Enabled = false;
break;
case "map":
DisableFields();
DisableDuration();
DisableDamage();
effect_filter_listbox.Enabled = false;
effected_body_part_listbox.Enabled = false;
break;
case "morale":
DisableFields();
SetDamageToolTip("The amount of morale gained by casting the spell. Negative numbers subtract morale.");
damage_type_combobox.Enabled = false;
effect_filter_listbox.Enabled = false;
effected_body_part_listbox.Enabled = false;
break;
case "charm_monster":
DisableFields();
SetDamageToolTip("The largest HP of monsters this spell can affect.");
damage_type_combobox.Enabled = false;
effect_filter_listbox.Enabled = false;
effected_body_part_listbox.Enabled = false;
break;
case "mutate":
DisableFields();
DisableDuration();
SetDamageToolTip("The chance the spell will take effect.\n10000 means 100% and 5000 means 50%.");
damage_type_combobox.Enabled = false;
effect_filter_listbox.Enabled = false;
effected_body_part_listbox.Enabled = false;
break;
case "bash":
DisableFields();
DisableDuration();
SetDamageToolTip("Bashes the location with strength equal to damage.");
damage_type_combobox.Enabled = false;
effect_filter_listbox.Enabled = false;
effected_body_part_listbox.Enabled = false;
break;
case "none":
default:
SetDamageToolTip("");
break;
}
ResetDisabledFieldValues();
}
private void UnsetDamageToolTip()
{
damageToolTip1.Active = false;
damageToolTip2.Active = false;
damageToolTip3.Active = false;
damageToolTip4.Active = false;
}
private void SetDamageToolTip(string tip)
{
damageToolTip1.Active = true;
damageToolTip2.Active = true;
damageToolTip3.Active = true;
damageToolTip4.Active = true;
damageToolTip1.SetToolTip(damage_label, tip);
damageToolTip2.SetToolTip(min_damage_updown, tip);
damageToolTip3.SetToolTip(damage_increment_updown, tip);
damageToolTip4.SetToolTip(max_damage_updown, tip);
}
public spell_form()
{
StaticDataLoader loader = new StaticDataLoader { };
loader.loadAll();
InitializeComponent();
InitializeLists();
validTargetsToolTip.SetToolTip(valid_targets_listbox, "A valid target is not only something you can cast at in the\ntargeting menu, but something that is affected by its spell effect.");
messageToolTip.SetToolTip(spell_message_textbox, "This is the message that displays in the log when the spell is cast.");
energySourceToolTip.SetToolTip(energy_type_combobox, "The type of energy used by the caster in order to cast this spell.\nIf the caster does not have any of this energy available, it will not be castable.");
spelltypeBindingSource.Add(main_spell);
energy_type_combobox.SelectedIndex = 0;
effect_combobox.SelectedIndex = 0;
damage_type_combobox.SelectedIndex = 0;
sound_type_combobox.SelectedIndex = 0;
}
private void clipboard_button_Click(object sender, EventArgs e)
{
main_spell.Flags = flags_listbox.CheckedItems.Cast<string>().ToList();
main_spell.ValidTargets = valid_targets_listbox.CheckedItems.Cast<string>().ToList();
main_spell.AffectedBps = effected_body_part_listbox.CheckedItems.Cast<string>().ToList();
main_spell.EffectTargets = effect_filter_listbox.CheckedItems.Cast<string>().ToList();
if(additionalSpellGrid.Rows.Count > 0)
{
main_spell.ExtraEffects = new List<FakeSpell> { };
}
foreach(DataGridViewRow row in additionalSpellGrid.Rows)
{
FakeSpell spell = new FakeSpell
{
Id = (string)row.Cells[0].Value,
MaxLevel = (int)row.Cells[1].Value,
Self = (bool)row.Cells[2].Value
};
main_spell.ExtraEffects.Add(spell);
}
if (spellsLearnedGrid.Rows.Count > 0)
{
main_spell.LearnSpells = new Dictionary<string, int> { };
}
foreach (DataGridViewRow row in spellsLearnedGrid.Rows)
{
main_spell.LearnSpells.Add((string)row.Cells[0].Value, (int)row.Cells[1].Value);
}
IgnoreEmptyEnumerablesResolver contractResolver = new IgnoreEmptyEnumerablesResolver
{
NamingStrategy = new SnakeCaseNamingStrategy()
};
Clipboard.SetText(JsonConvert.SerializeObject(
main_spell,
Formatting.Indented,
new JsonSerializerSettings
{
DefaultValueHandling = DefaultValueHandling.Ignore,
ContractResolver = contractResolver
}
)); ;
}
private void effect_combobox_SelectedIndexChanged(object sender, EventArgs e)
{
string effect = effect_combobox.SelectedItem.ToString();
if (!spell.allowed_strings.effect_descriptions.ContainsKey(effect))
{
return;
}
spell_effect_description_label.Text = spell.allowed_strings.effect_descriptions[effect];
update_effect_str(effect);
EnableValidEffectValues();
}
private void fakeSpellAddButton_Click(object sender, EventArgs e)
{
string fake_spell_id = FakeSpellIdTextbox.Text;
if(fake_spell_id.Length == 0)
{
// empty spell string is invalid
return;
}
int fake_spell_max_level = (int)fakeSpellUpDown.Value;
bool fake_spell_self = fakeSpellSelfCheckbox.Checked;
additionalSpellGrid.Rows.Add(fake_spell_id, fake_spell_max_level, fake_spell_self);
}
private void spellsLearnedAddButton_Click(object sender, EventArgs e)
{
string spell_id = spellsLearnedTextbox.Text;
if(spell_id.Length == 0)
{
return;
}
int spell_level = (int)SpellsLearnedUpDown.Value;
spellsLearnedGrid.Rows.Add(spell_id, spell_level);
}
private void flags_listbox_SelectedIndexChanged(object sender, EventArgs e)
{
string flag = flags_listbox.SelectedItem.ToString();
if(!spell.allowed_strings.spell_flags_description.ContainsKey(flag))
{
return;
}
flag_description_labe.Text = spell.allowed_strings.spell_flags_description[flag];
}
}
}