mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 22:46:12 +01:00
fix weapon action damage and display of calculation.
This commit is contained in:
parent
9fb9a4af55
commit
bf08691bbf
7 changed files with 46 additions and 14 deletions
|
|
@ -38,7 +38,7 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
|
|||
}
|
||||
};
|
||||
|
||||
static CLEAN_ARRAYS = ["damage.parts", "cost", "effects"];
|
||||
static CLEAN_ARRAYS = ['damage.parts', 'cost', 'effects'];
|
||||
|
||||
_getTabs() {
|
||||
const tabs = {
|
||||
|
|
@ -69,7 +69,6 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
|
|||
context.disableOption = this.disableOption.bind(this);
|
||||
context.isNPC = this.action.actor && this.action.actor.type !== 'character';
|
||||
context.hasRoll = this.action.hasRoll;
|
||||
console.log(context)
|
||||
return context;
|
||||
}
|
||||
|
||||
|
|
@ -97,9 +96,9 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
|
|||
|
||||
_prepareSubmitData(event, formData) {
|
||||
const submitData = foundry.utils.expandObject(formData.object);
|
||||
for ( const keyPath of this.constructor.CLEAN_ARRAYS ) {
|
||||
for (const keyPath of this.constructor.CLEAN_ARRAYS) {
|
||||
const data = foundry.utils.getProperty(submitData, keyPath);
|
||||
if ( data ) foundry.utils.setProperty(submitData, keyPath, Object.values(data));
|
||||
if (data) foundry.utils.setProperty(submitData, keyPath, Object.values(data));
|
||||
}
|
||||
return submitData;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ export class DHRoll extends Roll {
|
|||
if (config.dialog.configure !== false) {
|
||||
// Open Roll Dialog
|
||||
const DialogClass = config.dialog?.class ?? this.DefaultDialog;
|
||||
console.log(roll, config);
|
||||
const configDialog = await DialogClass.configure(roll, config, message);
|
||||
if (!configDialog) return;
|
||||
}
|
||||
|
|
@ -465,9 +464,17 @@ export class DamageRoll extends DHRoll {
|
|||
|
||||
static DefaultDialog = DamageDialog;
|
||||
|
||||
static async getDamageModifiers(roll) {
|
||||
const modifierFormula = roll.formula.replace(/[\d]+d[\d]+([a-zA-Z0-9.<>!=]*)?/g, '').replace(/\s*\+\s*/, '');
|
||||
const modifierRoll = new Roll(modifierFormula);
|
||||
await modifierRoll.evaluate();
|
||||
return modifierRoll.total;
|
||||
}
|
||||
|
||||
static async postEvaluate(roll, config = {}) {
|
||||
super.postEvaluate(roll, config);
|
||||
config.roll.type = config.type;
|
||||
config.roll.modifierTotal = await this.getDamageModifiers(roll);
|
||||
if (config.source?.message) {
|
||||
const chatMessage = ui.chat.collection.get(config.source.message);
|
||||
chatMessage.update({ 'system.damage': config });
|
||||
|
|
|
|||
|
|
@ -103,7 +103,6 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
|
|||
context.systemFields = this.actor.system.schema.fields;
|
||||
context.systemFields.attack.fields = this.actor.system.attack.schema.fields;
|
||||
context.isNPC = true;
|
||||
console.log(context)
|
||||
|
||||
return context;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -231,6 +231,7 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
|||
}
|
||||
|
||||
if (this.hasRoll) {
|
||||
console.log(config);
|
||||
const rollConfig = this.prepareRoll(config);
|
||||
config.roll = rollConfig;
|
||||
config = await this.actor.diceRoll(config);
|
||||
|
|
@ -242,7 +243,6 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
|||
if(t.hit) {
|
||||
const target = game.canvas.tokens.get(t.id),
|
||||
actor = target?.actor;
|
||||
console.log(actor)
|
||||
if(!actor) return;
|
||||
actor.saveRoll({
|
||||
event,
|
||||
|
|
@ -621,10 +621,38 @@ export class DHAttackAction extends DHDamageAction {
|
|||
super.prepareData();
|
||||
if (this.damage.includeBase && !!this.item?.system?.damage) {
|
||||
const baseDamage = this.getParentDamage();
|
||||
this.cleanBaseDamage(baseDamage);
|
||||
this.damage.parts.unshift(new DHDamageData(baseDamage));
|
||||
}
|
||||
}
|
||||
|
||||
cleanBaseDamage(baseDamage) {
|
||||
let possibleRoll = new Roll(baseDamage.value.dice);
|
||||
let die = 'd6';
|
||||
let modifier = 0;
|
||||
let nextOperator = '+';
|
||||
|
||||
possibleRoll.terms.forEach(term => {
|
||||
if (term instanceof DiceTerm) {
|
||||
die = `d${term._faces}`;
|
||||
}
|
||||
if (term instanceof OperatorTerm) {
|
||||
nextOperator = term.operator;
|
||||
}
|
||||
if (term instanceof NumericTerm) {
|
||||
if (nextOperator == '+') {
|
||||
modifier += term.number;
|
||||
}
|
||||
|
||||
if (nextOperator == '-') {
|
||||
modifier -= term.number;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return (baseDamage.value = { ...baseDamage.value, dice: die, bonus: modifier });
|
||||
}
|
||||
|
||||
getParentDamage() {
|
||||
return {
|
||||
value: {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
this.config.experiences = [];
|
||||
|
||||
if (config.source?.action) {
|
||||
console.log(config)
|
||||
this.item = config.data.parent.items.get(config.source.item) ?? config.data.parent;
|
||||
this.action =
|
||||
config.data.attack?._id == config.source.action
|
||||
|
|
@ -51,7 +50,6 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
};
|
||||
|
||||
async _prepareContext(_options) {
|
||||
console.log(this.config, this.roll)
|
||||
const context = await super._prepareContext(_options);
|
||||
context.hasRoll = !!this.config.roll;
|
||||
context.roll = this.roll;
|
||||
|
|
@ -77,7 +75,7 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
}
|
||||
context.extraFormula = this.config.extraFormula;
|
||||
context.formula = this.roll.constructFormula(this.config);
|
||||
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
|
|
@ -87,10 +85,10 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
this.config.costs = foundry.utils.mergeObject(this.config.costs, rest.costs);
|
||||
}
|
||||
if (this.config.uses) this.config.uses = foundry.utils.mergeObject(this.config.uses, rest.uses);
|
||||
if(rest.roll?.dice) {
|
||||
if (rest.roll?.dice) {
|
||||
Object.entries(rest.roll.dice).forEach(([key, value]) => {
|
||||
this.roll[key] = value;
|
||||
})
|
||||
});
|
||||
}
|
||||
this.config.extraFormula = rest.extraFormula;
|
||||
this.render();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue