-
Notifications
You must be signed in to change notification settings - Fork 0
/
Character.cs
779 lines (770 loc) · 25 KB
/
Character.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
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
using DnD5e.Utilities;
using System;
using System.Collections.Generic;
using System.ComponentModel;
namespace DnD5e
{
/// <summary>
/// Represents a character used in DnD5e.
/// </summary>
[Serializable]
public class Character
{
/// <summary>
/// Character to be used in DnD 5e
/// </summary>
/// <param name="n">Character Name</param>
/// <param name="St">Strength</param>
/// <param name="Dx">Dexterity</param>
/// <param name="Cn">Constitution</param>
/// <param name="In">Intelligence</param>
/// <param name="Wd">Wisdom</param>
/// <param name="Ch">Charisma</param>
public Character(string n, int St, int Dx, int Cn, int In, int Wd, int Ch)
{
pName = n;
pStrength = St;
pDexterity = Dx;
pConstitution = Cn;
pIntelligence = In;
pWisdom = Wd;
pCharisma = Ch;
InitializeSkills();
}
public Character()
{
}
#region Fields
public string pName { get; set; }
public string Gender { get { return getGender(pGender); } }
public string Race { get { return getRace(pRace); } }
public string SubRace { get { return getSubrace(pSubRace); } }
public string Class { get { return getClass(pClass); } }
public string SubClass { get { return getSubClass(pPrestige); } }
public string Allignment { get { return getAllignment(pAllignment); } }
public string Experience { get { return pExperience.ToString(); } }
public string Level { get { return getLevel(); } }
public int HitPoints { get { return pHitPoints; }}
public int MaxHitPoints { get { return pMaxHP; } set { pMaxHP = value; } }
public int Initiative { get { return pInitiative; } set { pInitiative = value; } }
public List<Proficiencies> Proficiencies {get { return pProficiencies; } set { pProficiencies = value; } }
public List<Spell> Spells { get { return pSpells; } set { pSpells = value; } }
public List<Equipment> Equipment { get { return pEquipment; } set { pEquipment = value; } }
public string pBackground;
private Gender pGender;
private Races pRace;
private SubRaces pSubRace;
private Classes pClass;
private SubClass pPrestige;
private Allignments pAllignment;
private int pExperience = 0;
private int pHitPoints = 0;
private int pMaxHP = 0;
private int pInitiative = 0;
//Abilities
public int pStrength;
public int pDexterity;
public int pConstitution;
public int pIntelligence;
public int pWisdom;
public int pCharisma;
//Skills
public List<Skill> pSkills = new List<Skill>();
//Proficiencies
private List<Proficiencies> pProficiencies;
//Spells
public bool isSpellCaster = false;
private List<Spell> pSpells = new List<Spell>();
//Equipment
private List<Equipment> pEquipment = new List<Equipment>();
#endregion
#region Methods
public override string ToString()
{
return pName + ": " + getLevel() + " " + getRace(pRace) + ", " + getClass(pClass);
}
private void InitializeSkills()
{
pSkills.Add(new Skill("Acrobatics", pDexterity));
pSkills.Add(new Skill("Animal Handling", pWisdom));
pSkills.Add(new Skill("Arcana", pIntelligence));
pSkills.Add(new Skill("Athletics", pStrength));
pSkills.Add(new Skill("Deception", pCharisma));
pSkills.Add(new Skill("History", pIntelligence));
pSkills.Add(new Skill("Insight", pWisdom));
pSkills.Add(new Skill("Intimidation", pCharisma));
pSkills.Add(new Skill("Investigation", pIntelligence));
pSkills.Add(new Skill("Medicine", pWisdom));
pSkills.Add(new Skill("Nature", pIntelligence));
pSkills.Add(new Skill("Perception", pWisdom));
pSkills.Add(new Skill("Performance", pWisdom));
pSkills.Add(new Skill("Persuasion", pCharisma));
pSkills.Add(new Skill("Religion", pIntelligence));
pSkills.Add(new Skill("Insight", pIntelligence));
pSkills.Add(new Skill("Sleight of Hand", pDexterity));
pSkills.Add(new Skill("Stealth", pDexterity));
pSkills.Add(new Skill("Survival", pWisdom));
}
#region Enum Methods
/// <summary>
/// Set the gender based on the string value entered.
/// </summary>
/// <param name="g">Name of the character gender</param>
public void setGender(string g)
{
pGender = g.ParseEnum<Gender>();
}
string getGender(Gender g)
{
return g.GetDescription();
}
/// <summary>
/// Sets the race based on the string value entered.
/// </summary>
/// <param name="r">Name of the character race</param>
public void setRace(string r)
{
pRace = r.ParseEnum<Races>();
}
string getRace(Races r)
{
return r.GetDescription();
}
/// <summary>
/// Sets the subrace based on the string value entered.
/// </summary>
/// <param name="sr">Name of the character subrace</param>
public void setSubRace(string sr)
{
pSubRace = sr.ParseEnum<SubRaces>();
}
string getSubrace(SubRaces sr)
{
return sr.GetDescription();
}
/// <summary>
/// Sets the class based on the string value entered.
/// </summary>
/// <param name="pClass">Name of the character class</param>
public void setClass(string c)
{
pClass = c.ParseEnum<Classes>();
}
string getClass(Classes c)
{
return c.GetDescription();
}
/// <summary>
/// Sets the subclass based on the string value entered.
/// </summary>
/// <param name="c"></param>
public void setSubClass(string c, SubClassTypes t)
{
switch(t)
{
case SubClassTypes.PrimalPaths:
pPrestige = new SubClass(c.ParseEnum<PrimalPaths>());
break;
case SubClassTypes.BardColleges:
pPrestige = new SubClass(c.ParseEnum<BardColleges>());
break;
case SubClassTypes.DivineDomains:
pPrestige = new SubClass(c.ParseEnum<DivineDomains>());
break;
case SubClassTypes.DruidCircles:
pPrestige = new SubClass(c.ParseEnum<DruidCircles>());
break;
case SubClassTypes.MartialArchetypes:
pPrestige = new SubClass(c.ParseEnum<MartialArchetypes>());
break;
case SubClassTypes.MonasticTraditions:
pPrestige = new SubClass(c.ParseEnum<MonasticTraditions>());
break;
case SubClassTypes.SacredOaths:
pPrestige = new SubClass(c.ParseEnum<SacredOaths>());
break;
case SubClassTypes.RangerArchetypes:
pPrestige = new SubClass(c.ParseEnum<RangerArchetypes>());
break;
case SubClassTypes.RoguishArchetypes:
pPrestige = new SubClass(c.ParseEnum<RoguishArchetypes>());
break;
case SubClassTypes.SorcerousOrigins:
pPrestige = new SubClass(c.ParseEnum<SorcerousOrigins>());
break;
case SubClassTypes.OtherworldlyPatrons:
pPrestige = new SubClass(c.ParseEnum<OtherworldlyPatrons>());
break;
case SubClassTypes.ArcaneTraditions:
pPrestige = new SubClass(c.ParseEnum<ArcaneTraditions>());
break;
default:
pPrestige = new SubClass();
break;
}
}
string getSubClass(SubClass c)
{
//Because a class/object can be null but an enum/type cannot be null,
//there needs to be a check here but not in other places.
if (c != null)
{
return c.GetDescription();
}
else
{
return String.Empty;
}
}
/// <summary>
/// Sets the allignment based on the string value entered.
/// </summary>
/// <param name="a">Name of the character allignment</param>
public void setAllignment(string a)
{
pAllignment = a.ParseEnum<Allignments>();
}
string getAllignment(Allignments a)
{
return a.GetDescription();
}
#endregion
#region Attribute Methods
/// <summary>
/// Method to find the ability score modifier based on the ability score.
/// </summary>
/// <param name="attributeScore">Attribute score</param>
/// <returns>Ability modifier score</returns>
public int getBonus(int attributeScore)
{
//The ability modifier is "subtract 10 from the ability score and then divide by 2 (round down)" PHB 13
decimal i = (attributeScore - 10) / 2;
int bonus;
bonus = (int)Math.Floor(i);
return bonus;
}
/// <summary>
/// Sets the attributes of a character which has already been created.
/// </summary>
/// <param name="St">Strength</param>
/// <param name="Dx">Dexterity</param>
/// <param name="Cn">Constitution</param>
/// <param name="In">Intelligence</param>
/// <param name="Wd">Wisdom</param>
/// <param name="Ch">Charisma</param>
public void setAttributes(int St, int Dx, int Cn, int In, int Wd, int Ch)
{
pStrength = St;
pDexterity = Dx;
pConstitution = Cn;
pIntelligence = In;
pWisdom = Wd;
pCharisma = Ch;
}
/// <summary>
/// Gets the selected attribute.
/// </summary>
/// <param name="name">Full name of the attribute.</param>
/// <returns></returns>
public int getAttribute(string name)
{
switch (name)
{
case "Strength":
return pStrength;
case "Dexterity":
return pDexterity;
case "Constitution":
return pConstitution;
case "Intelligence":
return pIntelligence;
case "Wisdom":
return pWisdom;
case "Charisma":
return pCharisma;
default:
return 0;
}
}
public string AttributeString(string name)
{
switch (name)
{
case "Strength":
return pStrength.ToString() + " (" + getBonus(pStrength).ToString() + ")";
case "Dexterity":
return pDexterity.ToString() + " (" + getBonus(pDexterity).ToString() + ")";
case "Constitution":
return pConstitution.ToString() + " (" + getBonus(pConstitution).ToString() + ")";
case "Intelligence":
return pIntelligence.ToString() + " (" + getBonus(pIntelligence).ToString() + ")";
case "Wisdom":
return pWisdom.ToString() + " (" + getBonus(pWisdom).ToString() + ")";
case "Charisma":
return pCharisma.ToString() + " (" + getBonus(pCharisma).ToString() + ")";
default:
return string.Empty;
}
}
#endregion
public void setHP(string hp)
{
if(!int.TryParse(hp, out pHitPoints))
{
pHitPoints = 0;
}
}
public void AddXP(int xp)
{
pExperience += xp;
}
public void resetXP()
{
pExperience = 0;
}
private string getLevel()
{
if(pExperience >= 355000) { return "Level 20"; }
else if(pExperience >= 305000) { return "Level 19"; }
else if (pExperience >= 265000) { return "Level 18"; }
else if (pExperience >= 225000) { return "Level 17"; }
else if (pExperience >= 195000) { return "Level 16"; }
else if (pExperience >= 165000) { return "Level 15"; }
else if (pExperience >= 140000) { return "Level 14"; }
else if (pExperience >= 120000) { return "Level 13"; }
else if (pExperience >= 100000) { return "Level 12"; }
else if (pExperience >= 85000) { return "Level 11"; }
else if (pExperience >= 64000) { return "Level 10"; }
else if (pExperience >= 48000) { return "Level 9"; }
else if (pExperience >= 34000) { return "Level 8"; }
else if (pExperience >= 23000) { return "Level 7"; }
else if (pExperience >= 14000) { return "Level 6"; }
else if (pExperience >= 6500) { return "Level 5"; }
else if (pExperience >= 2700) { return "Level 4"; }
else if (pExperience >= 900) { return "Level 3"; }
else if (pExperience >= 300) { return "Level 2"; }
else { return "Level 1"; }
}
#endregion
}
#region Components
/// <summary>
/// The gender of the character.
/// </summary>
enum Gender
{
None = 0,
Male,
Female
}
/// <summary>
/// The race of the character.
/// </summary>
enum Races
{
None = 0,
Dwarf,
Elf,
Halfling,
Human,
Dragonborn,
Gnome,
[Description("Half-Elf")]
HalfElf,
[Description("Half-Orc")]
HalfOrc,
Tiefling,
Monster
}
//The SubRaces could be refactored to be treated like the SubClasses
/// <summary>
/// The subrace of the character. Not all races have subraces.
/// Due to design, this includes ethnicity (Human) and ancestry (Dragonborn)
/// </summary>
enum SubRaces
{
//Default
None = 0,
//Dwarf
[Description("Hill Dwarf")]
hillDwarf,
[Description("Mountain Dwarf")]
mountainDwarf,
//Elf
[Description("High Elf")]
highElf,
[Description("Wood Elf")]
woodElf,
[Description("Dark Elf (Drow)")]
darkElf,
//Halfling
[Description("Lightfoot Halfling")]
lightfootHalfling,
[Description("Stout Halfling")]
stoutHalfling,
//Gnome
[Description("Forest Gnome")]
forestGnome,
[Description("Rock Gnome")]
rockGnome,
//Human Ethnicity
Calishite,
Chondathan,
Damaran,
Illuskan,
Mulan,
Rashemi,
Shou,
Tethyrian,
Turami,
//Dragonborn Ancestry
Black,
Blue,
Brass,
Bronze,
Copper,
Gold,
Green,
Red,
Silver,
White
}
/// <summary>
/// The class of the character.
/// </summary>
public enum Classes
{
None = 0,
Barbarian,
Bard,
Cleric,
Druid,
Fighter,
Monk,
Paladin,
Ranger,
Rogue,
Sorcerer,
Warlock,
Wizard
}
#region Subclasses
/// <summary>
/// In earlier versions of the game, these would be prestige classes.
/// Each class has their own special paths which become open to players at later levels.
/// </summary>
[Serializable]
public class SubClass
{
#region Constructors
public SubClass()
{
}
public SubClass(Classes c, string enumDesc)
{
switch (c)
{
case Classes.Barbarian:
PrimalPaths p = enumDesc.ParseEnum<PrimalPaths>();
description = p.GetDescription();
break;
case Classes.Bard:
BardColleges b = enumDesc.ParseEnum<BardColleges>();
description = b.GetDescription();
break;
case Classes.Cleric:
DivineDomains cl = enumDesc.ParseEnum<DivineDomains>();
description = cl.GetDescription();
break;
case Classes.Druid:
DruidCircles d = enumDesc.ParseEnum<DruidCircles>();
description = d.GetDescription();
break;
case Classes.Fighter:
MartialArchetypes f = enumDesc.ParseEnum<MartialArchetypes>();
description = f.GetDescription();
break;
case Classes.Monk:
MonasticTraditions m = enumDesc.ParseEnum<MonasticTraditions>();
description = m.GetDescription();
break;
case Classes.Paladin:
SacredOaths pal = enumDesc.ParseEnum<SacredOaths>();
description = pal.GetDescription();
break;
case Classes.Ranger:
RangerArchetypes rang = enumDesc.ParseEnum<RangerArchetypes>();
description = rang.GetDescription();
break;
case Classes.Rogue:
RoguishArchetypes r = enumDesc.ParseEnum<RoguishArchetypes>();
description = r.GetDescription();
break;
case Classes.Sorcerer:
SorcerousOrigins sor = enumDesc.ParseEnum<SorcerousOrigins>();
description = sor.GetDescription();
break;
case Classes.Warlock:
OtherworldlyPatrons war = enumDesc.ParseEnum<OtherworldlyPatrons>();
description = war.GetDescription();
break;
case Classes.Wizard:
ArcaneTraditions wiz = enumDesc.ParseEnum<ArcaneTraditions>();
description = wiz.GetDescription();
break;
default:
description = string.Empty;
break;
}
}
public SubClass(PrimalPaths p)
{
description = p.GetDescription();
}
public SubClass(BardColleges p)
{
description = p.GetDescription();
}
public SubClass(DivineDomains p)
{
description = p.GetDescription();
}
public SubClass(DruidCircles p)
{
description = p.GetDescription();
}
public SubClass(MartialArchetypes p)
{
description = p.GetDescription();
}
public SubClass(MonasticTraditions p)
{
description = p.GetDescription();
}
public SubClass(SacredOaths p)
{
description = p.GetDescription();
}
public SubClass(RangerArchetypes p)
{
description = p.GetDescription();
}
public SubClass(RoguishArchetypes p)
{
description = p.GetDescription();
}
public SubClass(SorcerousOrigins p)
{
description = p.GetDescription();
}
public SubClass(OtherworldlyPatrons p)
{
description = p.GetDescription();
}
public SubClass(ArcaneTraditions p)
{
description = p.GetDescription();
}
#endregion
/// <summary>
/// The description of the selected subclass.
/// </summary>
private string description;
/// <summary>
/// Returns the Description attribute of an enum value if that attribute exists. Otherwise, it returns the name.
/// </summary>
/// <returns></returns>
public string GetDescription()
{
if (description != null)
{
return description;
}
else
{
return String.Empty;
}
}
}
public enum SubClassTypes
{
None = 0,
PrimalPaths,
BardColleges,
DivineDomains,
DruidCircles,
MartialArchetypes,
MonasticTraditions,
SacredOaths,
RangerArchetypes,
RoguishArchetypes,
SorcerousOrigins,
OtherworldlyPatrons,
ArcaneTraditions
}
public enum PrimalPaths
{
None = 0,
//Barbarian: Primal Path
[Description("Path of the Berserker")]
Berserker,
[Description("Path of the Totem Warrior")]
TotemWarrior
}
public enum BardColleges
{
None = 0,
//Bard: Bard College
[Description("College of Lore")]
Lore,
[Description("College of Valor")]
Valor
}
public enum DivineDomains
{
None = 0,
//Cleric: Divine Domain
[Description("Knowledge Domain")]
Knowledge,
[Description("Life Domain")]
Life,
[Description("Light Domain")]
Light,
[Description("Nature Domain")]
Nature,
[Description("Tempest Domain")]
Tempest,
[Description("Trickery Domain")]
Trickery,
[Description("War Domain")]
War
}
public enum DruidCircles
{
None = 0,
//Druid: Druid Circle
[Description("Circle of the Land")]
Land,//Arctic, Coast, Desert, Forest, Grassland, Mountain, Swamp, Underdark
[Description("Circle of the Moon")]
Moon
}
public enum MartialArchetypes
{
None = 0,
//Fighter: Martial Archetype
[Description("Champion")]
Champion,
[Description("Battle Master")]
BattleMaster,
[Description("Eldritch Knight")]
EldritchKnight
}
public enum MonasticTraditions
{
None = 0,
//Monk: Monastic Tradition
[Description("Way of the Open Hands")]
OpenHands,
[Description("Way of the Shadow")]
Shadow,
[Description("Way of the Four Elements")]
Elements
}
public enum SacredOaths
{
None = 0,
//Paladin: Sacred Oath
[Description("Oath of Devotion")]
Devotion,
[Description("Oath of the Ancients")]
Ancients,
[Description("Oath of Vengeance")]
Vengeance
}
public enum RangerArchetypes
{
None = 0,
//Ranger: Ranger Archetype
[Description("Hunter")]
Hunter,
[Description("Beast Master")]
BeastMaster
}
public enum RoguishArchetypes
{
None = 0,
//Rogue: Roguish Archetype
[Description("Thief")]
Thief,
[Description("Assassin")]
Assassin,
[Description("Arcane Trickster")]
Trickster
}
public enum SorcerousOrigins
{
None = 0,
//Sorcerer: Sorcerous Origins
[Description("Draconic Bloodline")]
Draconic,
[Description("Wild Magic")]
Wild
}
public enum OtherworldlyPatrons
{
None = 0,
//Warlock: Otherworldly Patron
[Description("The Archfey")]
Archfey,
[Description("The Fiend")]
Fiend,
[Description("The Great Old One")]
GreatOldOne
}
public enum ArcaneTraditions
{
None = 0,
//Wizard: Arcane Tradition
[Description("School of Abjuration")]
Abjuration,
[Description("School of Conjuration")]
Conjuration,
[Description("School of Divination")]
Divination,
[Description("School of Enchantment")]
Enchantment,
[Description("School of Evocation")]
Evocation,
[Description("School of Illusion")]
Illusion,
[Description("School of Necromancy")]
Necromancy,
[Description("School of Transmutation")]
Transmutation
}
#endregion
/// <summary>
/// The allignment of the character
/// </summary>
enum Allignments
{
[Description("Chaotic Evil")]
chaoticEvil = -4,
[Description("Neutral Evil")]
neutralEvil = -3,
[Description("Lawful Evil")]
lawfulEvil = -2,
[Description("Chaotic Neutral")]
chaoticNeutral = -1,
Neutral = 0,
[Description("Lawful Neutral")]
lawfulNeutral = 1,
[Description("Chaotic Good")]
chaoticGood = 2,
[Description("Neutral Good")]
neutralGood = 3,
[Description("Lawful Good")]
lawfulGood = 4,
}
#endregion
}