Adversary Attack

This commit is contained in:
Dapoolp 2025-06-24 21:28:49 +02:00
parent 5a8aed73d2
commit 2981aab917
19 changed files with 269 additions and 499 deletions

View file

@ -63,6 +63,8 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
if (this.action.damage?.hasOwnProperty('includeBase') && this.action.type === 'attack') context.hasBaseDamage = !!this.action.parent.damage;
context.getRealIndex = this.getRealIndex.bind(this);
context.disableOption = this.disableOption.bind(this);
context.isNPC = this.action.actor.type !== 'character';
return context;
}
@ -95,11 +97,16 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
static async updateForm(event, _, formData) {
const submitData = this._prepareSubmitData(event, formData),
data = foundry.utils.expandObject(foundry.utils.mergeObject(this.action.toObject(), submitData)),
container = foundry.utils.getProperty(this.action.parent, this.action.systemPath);
let newActions;
if(Array.isArray(container)) {
newActions = foundry.utils.getProperty(this.action.parent, this.action.systemPath).map(x => x.toObject()); // Find better way
if (!newActions.findSplice(x => x._id === data._id, data)) newActions.push(data);
if (!newActions.findSplice(x => x._id === data._id, data)) newActions.push(data);
} else newActions = data;
const updates = await this.action.parent.parent.update({ [`system.${this.action.systemPath}`]: newActions });
if (!updates) return;
this.action = foundry.utils.getProperty(updates.system, this.action.systemPath)[this.action.index];
this.action = Array.isArray(container) ? foundry.utils.getProperty(updates.system, this.action.systemPath)[this.action.index] : foundry.utils.getProperty(updates.system, this.action.systemPath);
this.render();
}

View file

@ -42,6 +42,7 @@ export default class CostSelectionDialog extends HandlebarsApplicationMixin(Appl
}
async _prepareContext(_options) {
console.log(this.costs)
const updatedCosts = this.action.calcCosts(this.costs),
updatedUses = this.action.calcUses(this.uses);
return {

View file

@ -27,18 +27,14 @@ export class DHRoll extends Roll {
}
this.applyKeybindings(config);
// let roll;
// if(config.dialog?.configure === false) {
// roll = new this('', config.actor, config);
// } else {
if(config.dialog.configure !== false) {
// Open Roll Dialog
const DialogClass = config.dialog?.class ?? this.DefaultDialog;
config = await DialogClass.configure(config, message);
if(!config) return;
}
let roll = new this(config.formula, config.actor, config);
let roll = new this(config.formula, config.data, config);
for ( const hook of config.hooks ) {
if ( Hooks.call(`${SYSTEM.id}.post${hook.capitalize()}RollConfiguration`, roll, config, message) === false ) return [];
@ -101,9 +97,6 @@ export class DualityDie extends foundry.dice.terms.Die {
export class D20Roll extends DHRoll {
constructor(formula, data={}, options={}) {
super(formula, data, options);
// console.log(data, options)
// this.options = this._prepareData(data);
// this.options = options;
this.createBaseDice();
this.configureModifiers();
@ -195,10 +188,10 @@ export class D20Roll extends DHRoll {
this.applyBaseBonus();
this.options.experiences?.forEach(m => {
if(this.options.actor.experiences?.[m]) this.options.roll.modifiers.push(
if(this.options.data.experiences?.[m]) this.options.roll.modifiers.push(
{
label: this.options.actor.experiences[m].description,
value: this.options.actor.experiences[m].total
label: this.options.data.experiences[m].description,
value: this.options.data.experiences[m].total
}
);
})
@ -212,30 +205,16 @@ export class D20Roll extends DHRoll {
}
applyBaseBonus() {
// if(this.options.action) {
if(this.options.type === "attack") this.terms.push(...this.formatModifier(this.options.actor.system.attack.modifier));
/* this.options.roll.modifiers?.forEach(m => {
this.terms.push(...this.formatModifier(m));
}) */
// }
if(this.options.type === "attack") this.terms.push(...this.formatModifier(this.options.data.attack.roll.bonus));
}
static async postEvaluate(roll, config={}) {
if (config.targets?.length) {
/* targets = config.targets.map(target => {
const difficulty = config.roll.difficulty ?? target.difficulty ?? target.evasion
target.hit = roll.total >= difficulty;
return target;
}); */
config.targets.forEach(target => {
const difficulty = config.roll.difficulty ?? target.difficulty ?? target.evasion
const difficulty = config.roll.difficulty ?? target.difficulty ?? target.evasion
target.hit = roll.total >= difficulty;
})
} else if(config.roll.difficulty) roll.success = roll.total >= config.roll.difficulty;
// config.roll.advantage = {
// dice: roll.dHope.faces,
// value: roll.dHope.total
// }
config.roll.total = roll.total;
config.roll.formula = roll.formula;
config.roll.advantage = {
@ -244,10 +223,19 @@ export class D20Roll extends DHRoll {
value: roll.dAdvantage?.total
}
config.roll.modifierTotal = config.roll.modifiers.reduce((a,c) => a + c.value, 0);
config.roll.dice = [];
roll.dice.forEach(d => {
config.roll.dice.push({
dice: d.denomination,
total: d.total,
formula: d.formula,
results: d.results
})
})
}
getRollData() {
return this.options.actor.getRollData();
return this.options.data();
}
formatModifier(modifier) {
@ -348,7 +336,6 @@ export class DualityRoll extends D20Roll {
const dieFaces = 6,
bardRallyFaces = this.hasBarRally,
advDie = new foundry.dice.terms.Die({faces: dieFaces});
// console.log(this.hasAdvantage, this.hasDisadvantage)
if(this.hasAdvantage || this.hasDisadvantage || bardRallyFaces) this.terms.push(new foundry.dice.terms.OperatorTerm({operator:'+'}));
if(bardRallyFaces) {
const rallyDie = new foundry.dice.terms.Die({faces: bardRallyFaces});
@ -364,23 +351,16 @@ export class DualityRoll extends D20Roll {
}
applyBaseBonus() {
// if(this.options.action) {
// console.log(this.options, this.options.actor.system.traits[this.options.roll.trait].bonus)
// console.log(this.options.actor.system);
/* if(this.options.roll?.trait) this.terms.push(...this.formatModifier(this.options.actor.traits[this.options.roll.trait].total)); */
if(!this.options.roll.modifiers) this.options.roll.modifiers = [];
if(this.options.roll?.trait) this.options.roll.modifiers.push(
{
label: `DAGGERHEART.Abilities.${this.options.roll.trait}.name`,
value: this.options.actor.traits[this.options.roll.trait].total
}
);
console.log(this.options)
// } else if(this.options.trait) this.terms.push(...this.formatModifier(this.options.actor.system.traits[this.options.roll.trait].total));
if(!this.options.roll.modifiers) this.options.roll.modifiers = [];
if(this.options.roll?.trait) this.options.roll.modifiers.push(
{
label: `DAGGERHEART.Abilities.${this.options.roll.trait}.name`,
value: this.options.data.traits[this.options.roll.trait].total
}
);
}
static async postEvaluate(roll, config={}) {
console.log(roll,config);
super.postEvaluate(roll, config);
config.roll.hope = {
dice: roll.dHope.denomination,
@ -416,30 +396,10 @@ export class DamageRoll extends DHRoll {
static DefaultDialog = DamageDialog;
static async postEvaluate(roll, config={}) {
console.log(roll, config)
config.roll = {
// formula : config.formula,
result: roll.total,
dice: roll.dice
}
if(roll.healing) config.roll.type = roll.healing.type
/* const dice = [];
const modifiers = [];
for (var i = 0; i < roll.terms.length; i++) {
const term = roll.terms[i];
if (term.faces) {
dice.push({
type: `d${term.faces}`,
rolls: term.results.map(x => x.result),
total: term.results.reduce((acc, x) => acc + x.result, 0)
});
} else if (term.operator) {
} else if (term.number) {
const operator = i === 0 ? '' : roll.terms[i - 1].operator;
modifiers.push({ value: term.number, operator: operator });
}
}
config.roll.dice = dice;
config.roll.modifiers = modifiers; */
}
}

View file

@ -1,3 +1,4 @@
import DHActionConfig from '../config/Action.mjs';
import DaggerheartSheet from './daggerheart-sheet.mjs';
const { ActorSheetV2 } = foundry.applications.sheets;
@ -9,6 +10,7 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) {
actions: {
reactionRoll: this.reactionRoll,
attackRoll: this.attackRoll,
attackConfigure: this.attackConfigure,
addExperience: this.addExperience,
removeExperience: this.removeExperience,
toggleHP: this.toggleHP,
@ -51,7 +53,9 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) {
const context = await super._prepareContext(_options);
context.document = this.document;
context.tabs = super._getTabs(this.constructor.TABS);
context.systemFields.attack.fields = this.document.system.attack.schema.fields;
context.isNPC = true;
console.log(context)
return context;
}
@ -78,25 +82,11 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) {
}
static async attackRoll(event) {
const { modifier, damage, name: attackName } = this.actor.system.attack,
config = {
event: event,
title: attackName,
roll: {
modifier: modifier,
type: 'action'
},
chatMessage: {
type: 'adversaryRoll',
template: 'systems/daggerheart/templates/chat/adversary-attack-roll.hbs'
},
damage: {
value: damage.value,
type: damage.type
},
checkTarget: true
};
this.actor.diceRoll(config);
this.actor.system.attack.use(event);
}
static async attackConfigure(event) {
await new DHActionConfig(this.document.system.attack).render(true);
}
static async addExperience() {