Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Commit cd50e2d

Browse files
committed
Spells
1 parent f9bfccf commit cd50e2d

File tree

6 files changed

+173
-6
lines changed

6 files changed

+173
-6
lines changed

resources/templateCharacter.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
### {{ @data.name }}
22
**XP {{ @data.data.details.xp.value }}**
3-
{{ @rollData.details.alignment }} {{ @rollData.traits.size }} {{ @data.items.0.data.creatureType }}
3+
{{ @rollData.details.alignment }} {{ @rollData.traits.size }} {{ @race.data.name }}
44
**Init** {{ @rollData.attributes.init.total }}; Senses {{ @rollData.traits.senses }}; Perception {{ @rollData.skills.per.mod }};
55
**Aura** {}
66

77
#### DEFENSE
88
**AC** {{ @rollData.attributes.ac.normal.total }}, touch {{ @rollData.attributes.ac.touch.total }}, flat-footed {{ @rollData.attributes.ac.flatFooted.total }}
99
**hp** {{ #health }}
1010
**Fort** {{ @rollData.attributes.savingThrows.fort.total }}, **Ref** {{ @rollData.attributes.savingThrows.ref.total }}, **Will** {{ @rollData.attributes.savingThrows.will.total }}
11-
**DR** {}; **Immune** {}; **SR** {}
11+
**DR** {{ @rollData.traits.dr }}; **Immune** {}; **SR** {{ @rollData.attributes.sr.total }}
1212
**Weaknesses** {}
1313

1414
#### OFFENSE
1515
**Speed** {{ @rollData.attributes.speed.land.total }} ft., fly {{ @rollData.attributes.speed.fly.total }} ft. ({{ @rollData.attributes.speed.fly.maneuverability }}), swim {{ @rollData.attributes.speed.swim.total }} ft., climb {{ @rollData.attributes.speed.climb.total }} ft., burrow {{ @rollData.attributes.speed.burrow.total }} ft.
1616
**Melee** {{ #meleeAttacks }}
1717
**Ranged** {{ #rangedAttacks }}
18-
**Space** {}; **Reach** {{ @rollData.range.melee }}
18+
**Space** {} ft.; **Reach** {{ @rollData.range.melee }} ft.
1919
**Special Attacks** {{ #specialAttacks }}
20-
**Spell-Like Abilities** {}
21-
**Spells Known** (CL {}th)
20+
**Spell-Like Abilities** (CL {{ @rollData.spells.spelllike.cl.total }}th) {{ #spellLikes }}
21+
**Spells Known** (CL {{ @rollData.spells.primary.cl.total }}th) {{ #primarySpells }}
2222

2323
#### STATISTICS
2424
**Str** {{ @rollData.abilities.str.value }}, **Dex** {{ @rollData.abilities.dex.value }}, **Con** {{ @rollData.abilities.con.value }}, **Int** {{ @rollData.abilities.int.value }}, **Wis** {{ @rollData.abilities.wis.value }}, **Cha** {{ @rollData.abilities.cha.value }}

scripts/lib/ComputedProperties/MeleeAttacksProperty.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class MeleeAttacksProperty extends ComputedProperty {
1111

1212
for (const [key, value] of items.entries()) {
1313
if (itemTypes.includes(value?.data?.type)) {
14-
console.log(value?.data?.data?.attackType);
14+
// console.log(value?.data?.data?.attackType);
1515
if (value?.data?.data?.actionType === 'mwak' || value?.data?.data?.attackTyp === 'natural') {
1616
attacks.push(`${value.data.name} ${this.getItemAttacks(value.data)} (${this.getItemDamage(value.data)})`);
1717
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import {ComputedProperty} from './ComputedProperty.js';
2+
import {Helpers} from '../Helpers.js';
3+
4+
export class PrimarySpellsProperty extends ComputedProperty {
5+
6+
getProperty() {
7+
const items = this.input?.items;
8+
let spells = {
9+
0: [],
10+
1: [],
11+
2: [],
12+
3: [],
13+
4: [],
14+
5: [],
15+
6: [],
16+
7: [],
17+
8: [],
18+
9: [],
19+
};
20+
let ret = [];
21+
const itemTypes = [
22+
'spell'
23+
];
24+
25+
for (const [key, value] of items.entries()) {
26+
if (itemTypes.includes(value?.data?.type)) {
27+
if (value.data.data.spellbook === 'primary') {
28+
spells[value.data.data.level].push(`${value.data.name}`);
29+
}
30+
}
31+
}
32+
33+
for (const [key, value] of Object.entries(spells)) {
34+
if (value.length === 0) {
35+
continue;
36+
}
37+
38+
let str = Helpers.interation(key);
39+
if (key === '0') {
40+
str += ` (at will) - `;
41+
} else {
42+
str += ` (${this.input?._rollData?.spells.primary.spells[`spell${key}`]?.value}/day) - `;
43+
}
44+
str += value.toString().replaceAll(',', ', ');
45+
46+
ret.push(str)
47+
}
48+
49+
return '\n' + ret.join('\n');
50+
}
51+
52+
getItemDamage(item) {
53+
return Handlebars.helpers.itemDamage(item, this.input._rollData);
54+
}
55+
56+
getItemAttacks(item) {
57+
const attacks = item.document.attackArray;
58+
if (attacks.length === 0) return '';
59+
let ret = `${attacks[0] < 0 ? attacks[0] : `+${attacks[0]}`}`
60+
for (let i = 1; i < attacks.length; i++) {
61+
ret += `/${attacks[i] < 0 ? attacks[i] : `+${attacks[i]}`}`
62+
}
63+
return ret;
64+
}
65+
66+
getDependencies() {
67+
return [];
68+
}
69+
}

scripts/lib/ComputedProperties/PropertyStore.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {SkillsProperty} from './SkillsProperty.js';
1010
import {MeleeAttacksProperty} from './MeleeAttacksProperty.js';
1111
import {RangedAttacksProperty} from './RangedAttacksProperty.js';
1212
import {SpecialAttacksProperty} from './SpecialAttacksProperty.js';
13+
import {PrimarySpellsProperty} from './PrimarySpellsProperty.js';
14+
import {SpellLikesProperty} from './SpellLikesProperty.js';
1315

1416
export class PropertyStore {
1517
static ComputedProperties = {
@@ -25,6 +27,8 @@ export class PropertyStore {
2527
'meleeAttacks': new MeleeAttacksProperty(),
2628
'rangedAttacks': new RangedAttacksProperty(),
2729
'specialAttacks': new SpecialAttacksProperty(),
30+
'primarySpells': new PrimarySpellsProperty(),
31+
'spellLikes': new SpellLikesProperty(),
2832
};
2933

3034
constructor(input) {
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import {ComputedProperty} from './ComputedProperty.js';
2+
import {Helpers} from '../Helpers.js';
3+
4+
export class SpellLikesProperty extends ComputedProperty {
5+
6+
getProperty() {
7+
const items = this.input?.items;
8+
let spells = {
9+
0: [],
10+
};
11+
let ret = [];
12+
const itemTypes = [
13+
'spell'
14+
];
15+
16+
for (const [key, value] of items.entries()) {
17+
if (itemTypes.includes(value?.data?.type)) {
18+
if (value.data.data.spellbook === 'spelllike') {
19+
if (value.data.data.atWill) {
20+
spells[0].push(`${value.data.name}`);
21+
} else {
22+
if (!spells.hasOwnProperty(value.data.data.uses?.max)) {
23+
spells[value.data.data.uses?.max] = [];
24+
}
25+
spells[value.data.data.uses?.max]?.push(`${value.data.name}`);
26+
}
27+
}
28+
}
29+
}
30+
31+
for (const [key, value] of Object.entries(spells)) {
32+
if (value.length === 0) {
33+
continue;
34+
}
35+
36+
let str = '';
37+
if (key === '0') {
38+
str += `at will - `;
39+
} else {
40+
str += `${key}/day - `;
41+
}
42+
str += value.toString().replaceAll(',', ', ');
43+
44+
ret.push(str)
45+
}
46+
47+
return '\n' + ret.join('\n');
48+
}
49+
50+
getItemDamage(item) {
51+
return Handlebars.helpers.itemDamage(item, this.input._rollData);
52+
}
53+
54+
getItemAttacks(item) {
55+
const attacks = item.document.attackArray;
56+
if (attacks.length === 0) return '';
57+
let ret = `${attacks[0] < 0 ? attacks[0] : `+${attacks[0]}`}`
58+
for (let i = 1; i < attacks.length; i++) {
59+
ret += `/${attacks[i] < 0 ? attacks[i] : `+${attacks[i]}`}`
60+
}
61+
return ret;
62+
}
63+
64+
getDependencies() {
65+
return [];
66+
}
67+
}

scripts/lib/Helpers.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export class Helpers {
2+
static fancyNumber(num) {
3+
num = parseInt(num);
4+
5+
return `${num < 0 ? num : `+${num}`}`;
6+
}
7+
8+
static interation(num) {
9+
num = parseInt(num);
10+
11+
if (num <= 0) {
12+
return `${num}`;
13+
}
14+
15+
if (num === 1) {
16+
return `${num}st`;
17+
}
18+
if (num === 2) {
19+
return `${num}nd`;
20+
}
21+
if (num === 3) {
22+
return `${num}rd`;
23+
}
24+
25+
return `${num}th`;
26+
}
27+
}

0 commit comments

Comments
 (0)