spell-modal.component.ts 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. import { Component, Input } from '@angular/core';
  2. import { ModalService } from 'src/services/modal/modal.service';
  3. import { Damage } from 'src/interfaces/damage';
  4. import { Heal } from 'src/interfaces/heal';
  5. import { Spell } from 'src/interfaces/spell';
  6. @Component({
  7. selector: 'spell-modal',
  8. templateUrl: './spell-modal.component.html',
  9. styleUrls: ['./spell-modal.component.scss'],
  10. })
  11. export class SpellModalComponent {
  12. public constructor(private modalAccessor: ModalService) {}
  13. @Input() public spell: any;
  14. @Input() public level: number = 0;
  15. @Input() classes: string[] = [];
  16. @Input() public id: number = 0;
  17. @Input() public isModification: boolean = false;
  18. @Input() public isBasedOnOfficialSpell: boolean = false;
  19. // #region Properties
  20. public german: string = '';
  21. public english: string = '';
  22. public cost: string = 'action';
  23. public duration: number = 0;
  24. public timeToCast: number = 0;
  25. public canRitual: 'true' | 'false' | 'only' = 'false';
  26. public needsConcentration: boolean = false;
  27. public needsVerbal: boolean = false;
  28. public needsSomatic: boolean = false;
  29. public needsMaterial: boolean = false;
  30. public school: string = '';
  31. public description_de: string = '';
  32. public doesDamage: boolean = false;
  33. public doesHeal: boolean = false;
  34. public needsAttackRoll: boolean = false;
  35. public needsSavingThrow: boolean = false;
  36. public savingThrowAttribute: string = '';
  37. public heal: Heal = {
  38. diceNumber: '',
  39. diceType: '',
  40. additionalHeal: 0,
  41. };
  42. public attackBonus: string = '';
  43. public damage: Damage[] = [{ diceNumber: '', diceType: '', damageType: '' }];
  44. public isRanged: boolean = false;
  45. public range: number = 5;
  46. public hasAreaOfEffect: boolean = false;
  47. public radius: number = 0;
  48. public areaOfEffectType: string = '';
  49. // #endregion
  50. // #region OPTIONS
  51. public areaTypes: any[] = [
  52. { display: 'Kegel', value: 'cone' },
  53. { display: 'Kugel', value: 'sphere' },
  54. { display: 'Kreis', value: 'circle' },
  55. { display: 'Linie', value: 'line' },
  56. { display: 'Quadrat', value: 'square' },
  57. { display: 'Würfel', value: 'cube' },
  58. ];
  59. public schools: any[] = [
  60. { display: 'Verwandlung', value: 'transmutation' },
  61. { display: 'Verzauberung', value: 'enchantment' },
  62. { display: 'Illusion', value: 'illusion' },
  63. { display: 'Nekromantie', value: 'necromancy' },
  64. { display: 'Beschwörung', value: 'conjuration' },
  65. { display: 'Hervorrufung', value: 'evocation' },
  66. { display: 'Bannmagie', value: 'abjuration' },
  67. { display: 'Wahrsagerei', value: 'divination' },
  68. ];
  69. public savingThrowAttributes: any[] = [
  70. { display: 'Stärke', value: 'strength' },
  71. { display: 'Geschicklichkeit', value: 'dexterity' },
  72. { display: 'Konstitution', value: 'constitution' },
  73. { display: 'Intelligenz', value: 'intelligence' },
  74. { display: 'Weisheit', value: 'wisdom' },
  75. { display: 'Charisma', value: 'charisma' },
  76. ];
  77. public damageTypes: any[] = [
  78. { display: 'Wucht', value: 'bludgeoning' },
  79. { display: 'Stich', value: 'piercing' },
  80. { display: 'Hieb', value: 'slashing' },
  81. { display: 'Feuer', value: 'fire' },
  82. { display: 'Kälte', value: 'cold' },
  83. { display: 'Blitz', value: 'lightning' },
  84. { display: 'Gift', value: 'poison' },
  85. { display: 'Säure', value: 'acid' },
  86. { display: 'Nekrotisch', value: 'necrotic' },
  87. { display: 'Psychisch', value: 'psychic' },
  88. { display: 'Heilig', value: 'holy' },
  89. { display: 'Göttlich', value: 'divine' },
  90. { display: 'Kraft', value: 'force' },
  91. ];
  92. public dice: string[] = ['d4', 'd6', 'd8', 'd10', 'd12', 'd20', 'd100'];
  93. public numbers: string[] = [
  94. '1',
  95. '2',
  96. '3',
  97. '4',
  98. '5',
  99. '6',
  100. '7',
  101. '8',
  102. '9',
  103. '10',
  104. ];
  105. public costs: any[] = [
  106. { display: 'Aktion', value: 'action' },
  107. { display: 'Bonusaktion', value: 'bonus action' },
  108. { display: 'Reaktion', value: 'reaction' },
  109. ];
  110. // #endregion
  111. public ngOnInit(): void {
  112. if (this.isModification || this.isBasedOnOfficialSpell) {
  113. this.loadspell();
  114. }
  115. }
  116. // #region RESPONSES
  117. public cancel(): void {
  118. this.modalAccessor.handleModalClosing('cancel', undefined);
  119. this.resetSpell();
  120. }
  121. public add(): void {
  122. this.modalAccessor.handleModalClosing('add', this.createSpell());
  123. this.resetSpell();
  124. }
  125. public update(): void {
  126. this.modalAccessor.handleModalClosing('update', this.createSpell());
  127. this.resetSpell();
  128. }
  129. // #endregion
  130. // #region FUNCTIONS
  131. private loadspell(): void {
  132. if (this.isModification) {
  133. this.id = this.spell.id;
  134. this.german = this.spell.german;
  135. this.classes = this.spell.classes;
  136. } else {
  137. this.german = this.spell.german + ' (Kopie)';
  138. }
  139. this.english = this.spell.english;
  140. this.level = this.spell.level;
  141. this.cost = this.spell.cost;
  142. this.canRitual = this.spell.canRitual;
  143. this.duration = this.spell.duration;
  144. this.timeToCast = this.spell.timeToCast;
  145. this.needsConcentration = this.spell.needsConcentration;
  146. this.needsVerbal = this.spell.needsVerbal;
  147. this.needsSomatic = this.spell.needsSomatic;
  148. this.needsMaterial = this.spell.needsMaterial;
  149. this.school = this.spell.school;
  150. this.description_de = this.spell.description_de;
  151. this.doesDamage = this.spell.doesDamage;
  152. this.needsSavingThrow = this.spell.needsSavingThrow;
  153. this.savingThrowAttribute = this.spell.savingThrowAttribute;
  154. this.damage = this.spell.damage;
  155. this.isRanged = this.spell.isRanged;
  156. this.range = this.spell.range;
  157. this.hasAreaOfEffect = this.spell.hasAreaOfEffect;
  158. this.radius = this.spell.radius;
  159. this.areaOfEffectType = this.spell.areaOfEffectType;
  160. this.needsAttackRoll = this.spell.needsAttackRoll;
  161. this.attackBonus = this.spell.attackBonus;
  162. this.doesHeal = this.spell.doesHeal;
  163. this.heal = this.spell.heal;
  164. }
  165. private createSpell(): Spell {
  166. const spell: Spell = {
  167. id: this.id,
  168. isCustom: true,
  169. english: this.english,
  170. german: this.german,
  171. classes: this.classes,
  172. duration: 0, // FIXME: only mocked
  173. timeToCast: 0, // FIXME: only mocked
  174. damage: this.damage,
  175. heal: this.heal,
  176. level: parseInt(this.level.toString()),
  177. cost: this.cost,
  178. canRitual: this.canRitual,
  179. school: this.school,
  180. description_de: this.description_de,
  181. needsConcentration: this.needsConcentration,
  182. needsVerbal: this.needsVerbal,
  183. needsSomatic: this.needsSomatic,
  184. needsMaterial: this.needsMaterial,
  185. needsAttackRoll: this.needsAttackRoll,
  186. needsSavingThrow: this.needsSavingThrow,
  187. savingThrowAttribute: this.savingThrowAttribute,
  188. isRanged: this.isRanged,
  189. range: this.range,
  190. radius: this.radius,
  191. hasAreaOfEffect: this.hasAreaOfEffect,
  192. areaOfEffectType: this.areaOfEffectType,
  193. doesDamage: this.doesDamage,
  194. doesHeal: this.doesHeal,
  195. };
  196. return spell;
  197. }
  198. private resetSpell(): void {
  199. this.id = 0;
  200. this.german = '';
  201. this.english = '';
  202. this.classes = [];
  203. this.level = 0;
  204. this.cost = 'action';
  205. this.canRitual = 'false';
  206. this.duration = 0;
  207. this.timeToCast = 0;
  208. this.needsConcentration = false;
  209. this.needsVerbal = false;
  210. this.needsSomatic = false;
  211. this.needsMaterial = false;
  212. this.school = '';
  213. this.description_de = '';
  214. this.doesDamage = true;
  215. this.needsSavingThrow = false;
  216. this.savingThrowAttribute = '';
  217. this.damage = [{ diceNumber: '', diceType: '', damageType: '' }];
  218. this.isRanged = false;
  219. this.range = 5;
  220. this.hasAreaOfEffect = false;
  221. this.radius = 0;
  222. this.areaOfEffectType = '';
  223. this.needsAttackRoll = false;
  224. this.attackBonus = '';
  225. this.doesHeal = false;
  226. this.heal = { diceNumber: '', diceType: '', additionalHeal: 0 };
  227. }
  228. public addDamage(): void {
  229. this.damage.push({ diceNumber: '', diceType: '', damageType: '' });
  230. }
  231. public removeDamage(index: number): void {
  232. this.damage.splice(index, 1);
  233. }
  234. // #endregion
  235. }