Skip to content

Commit adf730f

Browse files
committed
WIP - update shields
1 parent 018f0ab commit adf730f

5 files changed

Lines changed: 82 additions & 98 deletions

File tree

src/module/actor/ABFActor.js

Lines changed: 10 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -132,77 +132,17 @@ export class ABFActor extends Actor {
132132
return roll.total;
133133
}
134134

135-
/**
136-
* Creates a new supernatural shield item for the ABFActor class and execute a macro using the shield's name.
137-
*
138-
* @param {string} type The type of the supernatural shield ('psychic' or 'mystic').
139-
* @param {any} power - The power object containing information about the psychic power. Only needed if type = 'psychic'.
140-
* @param {number} psychicDifficulty - The difficulty level of the psychic power. Only needed if type = 'psychic'.
141-
* @param {any} spell - The spell object containing information about the mystic spell. Only needed if type = 'mystic'.
142-
* @param {string} spellGrade - The grade of the mystic spell. Only needed if type = 'mystic'.
143-
* @returns {Promise<string>} - The ID of the newly created supernatural shield item.
144-
*/
145-
async newSupernaturalShield(type, power, psychicDifficulty, spell, spellGrade) {
146-
const supernaturalShieldData = {
147-
name: '',
148-
type: ABFItems.SUPERNATURAL_SHIELD,
149-
system: {},
150-
psychic: { overmantained: false, maintainMax: 0 }
151-
};
152-
if (type === 'psychic') {
153-
const {
154-
general: {
155-
settings: { inhuman, zen }
156-
},
157-
psychic
158-
} = this.system;
159-
160-
const potentialBaseDifficulty = psychicPotentialEffect(
161-
psychic.psychicPotential.base.value,
162-
0,
163-
inhuman.value,
164-
zen.value
165-
);
166-
const baseEffect =
167-
shieldBaseValueCheck(potentialBaseDifficulty, power?.system.effects) ?? 0;
168-
const finalEffect = shieldValueCheck(
169-
power?.system.effects[psychicDifficulty].value ?? ''
170-
);
171-
supernaturalShieldData.name = power.name;
172-
supernaturalShieldData.system = {
173-
type: 'psychic',
174-
damageBarrier: 0,
175-
shieldPoints: finalEffect,
176-
origin: this.uuid
177-
};
178-
supernaturalShieldData.psychic = {
179-
overmantained: finalEffect > baseEffect,
180-
maintainMax: baseEffect
181-
};
182-
} else if (type === 'mystic') {
183-
const finalEffect = shieldValueCheck(
184-
spell?.system.grades[spellGrade].description.value ?? ''
185-
);
186-
supernaturalShieldData.name = spell.name;
187-
supernaturalShieldData.system = {
188-
type: 'mystic',
189-
spellGrade,
190-
damageBarrier: 0,
191-
shieldPoints: finalEffect,
192-
origin: this.uuid
193-
};
194-
}
135+
async newSupernaturalShield(shieldData) {
136+
// Accept either DTO or plain create data
137+
const itemCreateData =
138+
typeof shieldData?.toItemCreateData === 'function'
139+
? shieldData.toItemCreateData()
140+
: shieldData;
195141

196-
const item = await this.createItem(supernaturalShieldData);
197-
let args = {
198-
thisActor: this,
199-
newShield: true,
200-
shieldId: item._id
201-
};
202-
if (supernaturalShieldData.psychic.overmantained) {
203-
item.setFlag(game.abf.id, 'psychic', supernaturalShieldData.psychic);
204-
}
205-
executeMacro(supernaturalShieldData.name, args);
142+
const item = await this.createItem(itemCreateData);
143+
144+
const args = { thisActor: this, newShield: true, shieldId: item._id };
145+
executeMacro(itemCreateData.name, args);
206146
return item._id;
207147
}
208148

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { ABFItems } from '../items/ABFItems';
2+
3+
export class ABFSupernaturalShieldData {
4+
/** @param {{name?: string, shieldPoints?: number, abilityFormula?: string, flags?: object}} p */
5+
constructor(p = {}) {
6+
this.name = String(p.name ?? '');
7+
this.type = ABFItems.SUPERNATURAL_SHIELD;
8+
this.system = {
9+
shieldPoints: Number(p.shieldPoints ?? 0) || 0,
10+
abilityFormula: String(p.abilityFormula ?? '')
11+
};
12+
this.flags = p.flags ?? undefined;
13+
}
14+
15+
toItemCreateData() {
16+
const data = { name: this.name, type: this.type, system: { ...this.system } };
17+
if (this.flags) data.flags = this.flags;
18+
return data;
19+
}
20+
21+
static builder() {
22+
return new ABFSupernaturalShieldDataBuilder();
23+
}
24+
}
25+
26+
export class ABFSupernaturalShieldDataBuilder {
27+
constructor() {
28+
this._p = {};
29+
}
30+
31+
name(v) {
32+
this._p.name = String(v ?? '');
33+
return this;
34+
}
35+
shieldPoints(v) {
36+
this._p.shieldPoints = Number(v) || 0;
37+
return this;
38+
}
39+
abilityFormula(v) {
40+
this._p.abilityFormula = String(v ?? '');
41+
return this;
42+
}
43+
flags(o) {
44+
this._p.flags = o ?? undefined;
45+
return this;
46+
}
47+
48+
build() {
49+
return new ABFSupernaturalShieldData(this._p);
50+
}
51+
}

src/module/dialogs/combat/GMCombatDialog.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { calculateCombatResult } from '../../combat/utils/calculateCombatResult'
33
import { ABFSettingsKeys } from '../../../utils/registerSettings';
44
import { executeMacro } from '../../utils/functions/executeMacro';
55
import ABFFoundryRoll from '../../rolls/ABFFoundryRoll.js';
6+
import { ABFSupernaturalShieldData } from '../../combat/ABFSupernaturalShieldData';
7+
import { shieldValueCheck } from '../../combat/utils/shieldValueCheck.js';
68

79
const getInitialData = (attacker, defender, options = {}) => {
810
const attackerActor = attacker.actor;
@@ -385,19 +387,21 @@ export class GMCombatDialog extends FormApplication {
385387

386388
async newSupernaturalShieldIfBeAble() {
387389
const { supShield } = this.modalData.defender.result?.values;
388-
if (
389-
(this.modalData.defender.result?.type === 'mystic' ||
390-
this.modalData.defender.result?.type === 'psychic') &&
391-
supShield.create
392-
) {
393-
const supShieldId = await this.defenderActor.newSupernaturalShield(
394-
this.modalData.defender.result.type,
395-
this.modalData.defender.result?.power ?? {},
396-
this.modalData.defender.result.values?.psychicPotential ?? 0,
397-
this.modalData.defender.result.spell ?? {},
398-
this.modalData.defender.result.values?.spellGrade
399-
);
400-
return supShieldId;
390+
const result = this.modalData.defender.result;
391+
392+
if ((result?.type === 'mystic' || result?.type === 'psychic') && supShield.create) {
393+
const shieldPoints = Number(result.values?.supShield?.shieldPoints ?? 0);
394+
395+
const abilityFormula =
396+
result.type === 'psychic' ? 'TU_FORMULA_PSIQUICA' : 'TU_FORMULA_MAGICA';
397+
398+
const shieldData = ABFSupernaturalShieldData.builder()
399+
.name(result.type === 'psychic' ? result?.power?.name : result?.spell?.name)
400+
.shieldPoints(shieldPoints)
401+
.abilityFormula(abilityFormula)
402+
.build();
403+
404+
return await this.defenderActor.newSupernaturalShield(shieldData);
401405
}
402406
}
403407

@@ -427,10 +431,7 @@ export class GMCombatDialog extends FormApplication {
427431
attacker.result.values.total + this.modalData.attacker.customModifier,
428432
0
429433
);
430-
newCombatResult.at = Math.max(
431-
defender.result.values.at - reducedArmor,
432-
0
433-
);
434+
newCombatResult.at = Math.max(defender.result.values.at - reducedArmor, 0);
434435
newCombatResult.halvedAbsorption =
435436
defender.result.type === 'resistance'
436437
? defender.result.values.surprised
@@ -492,9 +493,7 @@ export class GMCombatDialog extends FormApplication {
492493

493494
if (attacker.result?.type === 'combat') {
494495
const weaponName =
495-
attacker.result.values?.weaponName ||
496-
attacker.result.weapon?.name ||
497-
'Unarmed';
496+
attacker.result.values?.weaponName || attacker.result.weapon?.name || 'Unarmed';
498497
const { name } = { name: weaponName };
499498
macroName = macroPrefixAttack + name;
500499
} else if (attacker.result?.type === 'mystic') {

src/module/types/combat/SupernaturalShieldItemConfig.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ import { ABFItemConfigFactory } from '../ABFItemConfig';
99
* @readonly
1010
*/
1111
export const INITIAL_SUPERNATURAL_SHIELD_DATA = {
12-
type: 'none',
13-
spellGrade: SpellGrades.BASE,
14-
damageBarrier: 0,
1512
shieldPoints: 0,
16-
origin: ''
13+
abilityFormula: ''
1714
};
1815

1916
/** @type {import("../Items").SupernaturalShieldItemConfig} */

src/template.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -785,11 +785,8 @@
785785
"useCustomFormula": {"value": false }
786786
},
787787
"supernaturalShield": {
788-
"type": { "value": "none" },
789-
"spellGrade": { "value": "" },
790-
"damageBarrier": { "value": 0 },
791788
"shieldPoints": { "value": 0 },
792-
"origin": { "value": "" }
789+
"abilityFormula": { "value": "" }
793790
},
794791
"effect": {
795792
"active": { "value": true },

0 commit comments

Comments
 (0)