mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-13 04:01:06 +01:00
Merged with action branch
This commit is contained in:
commit
f4539ab158
48 changed files with 2747 additions and 387 deletions
|
|
@ -1,9 +1,10 @@
|
|||
const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api;
|
||||
|
||||
export default class CostSelectionDialog extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
constructor(costs, action, resolve) {
|
||||
constructor(costs, uses, action, resolve) {
|
||||
super({});
|
||||
this.costs = costs;
|
||||
this.uses = uses;
|
||||
this.action = action;
|
||||
this.resolve = resolve;
|
||||
}
|
||||
|
|
@ -41,21 +42,25 @@ export default class CostSelectionDialog extends HandlebarsApplicationMixin(Appl
|
|||
}
|
||||
|
||||
async _prepareContext(_options) {
|
||||
const updatedCosts = this.action.calcCosts(this.costs);
|
||||
const updatedCosts = this.action.calcCosts(this.costs),
|
||||
updatedUses = this.action.calcUses(this.uses);
|
||||
return {
|
||||
costs: updatedCosts,
|
||||
canUse: this.action.getRealCosts(updatedCosts)?.hasCost
|
||||
uses: updatedUses,
|
||||
canUse: this.action.getRealCosts(updatedCosts)?.hasCost && this.action.hasUses(updatedUses)
|
||||
};
|
||||
}
|
||||
|
||||
static async updateForm(event, _, formData) {
|
||||
this.costs = foundry.utils.mergeObject(this.costs, foundry.utils.expandObject(formData.object).costs);
|
||||
this.render(true)
|
||||
const data = foundry.utils.expandObject(formData.object);
|
||||
this.costs = foundry.utils.mergeObject(this.costs, data.costs);
|
||||
this.uses = foundry.utils.mergeObject(this.uses, data.uses);
|
||||
this.render(true);
|
||||
}
|
||||
|
||||
static sendCost(event) {
|
||||
event.preventDefault();
|
||||
this.resolve(this.action.getRealCosts(this.costs));
|
||||
this.resolve({ costs: this.action.getRealCosts(this.costs), uses: this.uses });
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,19 +11,19 @@ export class DHRoll extends Roll {
|
|||
super(formula, data, options);
|
||||
}
|
||||
|
||||
static async build(config={}, message={}) {
|
||||
static async build(config = {}, message = {}) {
|
||||
const roll = await this.buildConfigure(config, message);
|
||||
if(!roll) return;
|
||||
await this.buildEvaluate(roll, config, message={});
|
||||
await this.buildPost(roll, config, message={});
|
||||
if (!roll) return;
|
||||
await this.buildEvaluate(roll, config, (message = {}));
|
||||
await this.buildPost(roll, config, (message = {}));
|
||||
return roll;
|
||||
}
|
||||
|
||||
static async buildConfigure(config={}, message={}) {
|
||||
config.hooks = [...(config.hooks ?? []), ""];
|
||||
|
||||
static async buildConfigure(config = {}, message = {}) {
|
||||
config.hooks = [...(config.hooks ?? []), ''];
|
||||
config.dialog ??= {};
|
||||
for ( const hook of config.hooks ) {
|
||||
if ( Hooks.call(`${SYSTEM.id}.preRoll${hook.capitalize()}`, config, message) === false ) return null;
|
||||
for (const hook of config.hooks) {
|
||||
if (Hooks.call(`${SYSTEM.id}.preRoll${hook.capitalize()}`, config, message) === false) return null;
|
||||
}
|
||||
|
||||
this.applyKeybindings(config);
|
||||
|
|
@ -32,45 +32,44 @@ export class DHRoll extends Roll {
|
|||
// if(config.dialog?.configure === false) {
|
||||
// roll = new this('', config.actor, config);
|
||||
// } else {
|
||||
if(config.dialog.configure !== false) {
|
||||
if (config.dialog.configure !== false) {
|
||||
// Open Roll Dialog
|
||||
const DialogClass = config.dialog?.class ?? this.DefaultDialog;
|
||||
config = await DialogClass.configure(config, message);
|
||||
if(!config) return;
|
||||
if (!config) return;
|
||||
}
|
||||
let roll = new this(config.formula, config.actor, config);
|
||||
|
||||
for ( const hook of config.hooks ) {
|
||||
if ( Hooks.call(`${SYSTEM.id}.post${hook.capitalize()}RollConfiguration`, roll, config, message) === false ) return [];
|
||||
for (const hook of config.hooks) {
|
||||
if (Hooks.call(`${SYSTEM.id}.post${hook.capitalize()}RollConfiguration`, roll, config, message) === false)
|
||||
return [];
|
||||
}
|
||||
|
||||
return roll;
|
||||
}
|
||||
|
||||
static async buildEvaluate(roll, config={}, message={}) {
|
||||
if(config.evaluate !== false) await roll.evaluate();
|
||||
|
||||
static async buildEvaluate(roll, config = {}, message = {}) {
|
||||
if (config.evaluate !== false) await roll.evaluate();
|
||||
this.postEvaluate(roll, config);
|
||||
}
|
||||
|
||||
static async buildPost(roll, config, message) {
|
||||
for ( const hook of config.hooks ) {
|
||||
if ( Hooks.call(`${SYSTEM.id}.postRoll${hook.capitalize()}`, config, message) === false ) return null;
|
||||
}
|
||||
|
||||
// Create Chat Message
|
||||
if(message.data) {
|
||||
|
||||
static async buildPost(roll, config, message) {
|
||||
for (const hook of config.hooks) {
|
||||
if (Hooks.call(`${SYSTEM.id}.postRoll${hook.capitalize()}`, config, message) === false) return null;
|
||||
}
|
||||
|
||||
// Create Chat Message
|
||||
if (message.data) {
|
||||
} else {
|
||||
const messageData = {};
|
||||
await this.toMessage(roll, config);
|
||||
}
|
||||
}
|
||||
|
||||
static async postEvaluate(roll, config={}) {}
|
||||
static async postEvaluate(roll, config = {}) {}
|
||||
|
||||
static async toMessage(roll, config) {
|
||||
console.log(config)
|
||||
const cls = getDocumentClass("ChatMessage"),
|
||||
const cls = getDocumentClass('ChatMessage'),
|
||||
msg = {
|
||||
type: this.messageType,
|
||||
user: game.user.id,
|
||||
|
|
@ -80,7 +79,6 @@ export class DHRoll extends Roll {
|
|||
content: await this.messageTemplate(config),
|
||||
rolls: [roll]
|
||||
};
|
||||
console.log(msg)
|
||||
await cls.create(msg);
|
||||
}
|
||||
|
||||
|
|
@ -95,13 +93,13 @@ export class DHRoll extends Roll {
|
|||
// D20Die
|
||||
|
||||
export class DualityDie extends foundry.dice.terms.Die {
|
||||
constructor({ number=1, faces=12, ...args }={}) {
|
||||
constructor({ number = 1, faces = 12, ...args } = {}) {
|
||||
super({ number, faces, ...args });
|
||||
}
|
||||
}
|
||||
|
||||
export class D20Roll extends DHRoll {
|
||||
constructor(formula, data={}, options={}) {
|
||||
constructor(formula, data = {}, options = {}) {
|
||||
super(formula, data, options);
|
||||
// console.log(data, options)
|
||||
// this.options = this._prepareData(data);
|
||||
|
|
@ -122,21 +120,21 @@ export class D20Roll extends DHRoll {
|
|||
|
||||
// static messageTemplate = 'systems/daggerheart/templates/chat/adversary-roll.hbs';
|
||||
|
||||
static messageTemplate = async (config) => {
|
||||
static messageTemplate = async config => {
|
||||
return 'systems/daggerheart/templates/chat/adversary-roll.hbs';
|
||||
}
|
||||
};
|
||||
|
||||
static CRITICAL_TRESHOLD = 20;
|
||||
|
||||
static DefaultDialog = D20RollDialog;
|
||||
|
||||
get d20() {
|
||||
if ( !(this.terms[0] instanceof foundry.dice.terms.Die) ) this.createBaseDice();
|
||||
if (!(this.terms[0] instanceof foundry.dice.terms.Die)) this.createBaseDice();
|
||||
return this.terms[0];
|
||||
}
|
||||
|
||||
set d20(faces) {
|
||||
if ( !(this.terms[0] instanceof foundry.dice.terms.Die) ) this.createBaseDice();
|
||||
if (!(this.terms[0] instanceof foundry.dice.terms.Die)) this.createBaseDice();
|
||||
this.terms[0].faces = faces;
|
||||
}
|
||||
|
||||
|
|
@ -145,7 +143,7 @@ export class D20Roll extends DHRoll {
|
|||
}
|
||||
|
||||
get isCritical() {
|
||||
if ( !this.d20._evaluated ) return;
|
||||
if (!this.d20._evaluated) return;
|
||||
return this.d20.total >= this.constructor.CRITICAL_TRESHOLD;
|
||||
}
|
||||
|
||||
|
|
@ -163,66 +161,69 @@ export class D20Roll extends DHRoll {
|
|||
advantage: config.event.altKey,
|
||||
disadvantage: config.event.ctrlKey
|
||||
};
|
||||
|
||||
|
||||
// Should the roll configuration dialog be displayed?
|
||||
config.dialog.configure ??= !Object.values(keys).some(k => k);
|
||||
|
||||
// Determine advantage mode
|
||||
const advantage = config.advantage || keys.advantage;
|
||||
const disadvantage = config.disadvantage || keys.disadvantage;
|
||||
if ( advantage && !disadvantage ) config.advantage = this.ADV_MODE.ADVANTAGE;
|
||||
else if ( !advantage && disadvantage ) config.advantage = this.ADV_MODE.DISADVANTAGE;
|
||||
if (advantage && !disadvantage) config.advantage = this.ADV_MODE.ADVANTAGE;
|
||||
else if (!advantage && disadvantage) config.advantage = this.ADV_MODE.DISADVANTAGE;
|
||||
else config.advantage = this.ADV_MODE.NORMAL;
|
||||
}
|
||||
|
||||
createBaseDice() {
|
||||
if ( this.terms[0] instanceof foundry.dice.terms.Die ) return;
|
||||
if (this.terms[0] instanceof foundry.dice.terms.Die) return;
|
||||
this.terms[0] = new foundry.dice.terms.Die({ faces: 20 });
|
||||
}
|
||||
|
||||
applyAdvantage() {
|
||||
this.d20.modifiers.findSplice(m => ["kh", "kl"].includes(m));
|
||||
if ( !this.hasAdvantage && !this.hasAdvantage ) this.number = 1;
|
||||
this.d20.modifiers.findSplice(m => ['kh', 'kl'].includes(m));
|
||||
if (!this.hasAdvantage && !this.hasAdvantage) this.number = 1;
|
||||
else {
|
||||
this.d20.number = 2;
|
||||
this.d20.modifiers.push(this.hasAdvantage ? "kh" : "kl");
|
||||
this.d20.modifiers.push(this.hasAdvantage ? 'kh' : 'kl');
|
||||
}
|
||||
}
|
||||
|
||||
// Trait bonus != Adversary
|
||||
configureModifiers() {
|
||||
|
||||
this.applyAdvantage();
|
||||
|
||||
this.applyBaseBonus();
|
||||
|
||||
this.options.experiences?.forEach(m => {
|
||||
if(this.options.actor.experiences?.[m]) this.options.roll.modifiers.push(
|
||||
{
|
||||
if (this.options.actor.experiences?.[m])
|
||||
this.options.roll.modifiers.push({
|
||||
label: this.options.actor.experiences[m].description,
|
||||
value: this.options.actor.experiences[m].total
|
||||
}
|
||||
);
|
||||
})
|
||||
});
|
||||
});
|
||||
this.options.roll.modifiers?.forEach(m => {
|
||||
this.terms.push(...this.formatModifier(m.value));
|
||||
})
|
||||
});
|
||||
|
||||
if(this.options.extraFormula) this.terms.push(new foundry.dice.terms.OperatorTerm({operator: '+'}), ...this.constructor.parse(this.options.extraFormula, this.getRollData()));
|
||||
if (this.options.extraFormula)
|
||||
this.terms.push(
|
||||
new foundry.dice.terms.OperatorTerm({ operator: '+' }),
|
||||
...this.constructor.parse(this.options.extraFormula, this.getRollData())
|
||||
);
|
||||
|
||||
// this.resetFormula();
|
||||
}
|
||||
|
||||
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 => {
|
||||
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));
|
||||
}) */
|
||||
// }
|
||||
}
|
||||
|
||||
static async postEvaluate(roll, config={}) {
|
||||
static async postEvaluate(roll, config = {}) {
|
||||
if (config.targets?.length) {
|
||||
/* targets = config.targets.map(target => {
|
||||
const difficulty = config.roll.difficulty ?? target.difficulty ?? target.evasion
|
||||
|
|
@ -230,10 +231,10 @@ export class D20Roll extends DHRoll {
|
|||
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;
|
||||
});
|
||||
} else if (config.roll.difficulty) roll.success = roll.total >= config.roll.difficulty;
|
||||
// config.roll.advantage = {
|
||||
// dice: roll.dHope.faces,
|
||||
// value: roll.dHope.total
|
||||
|
|
@ -244,8 +245,8 @@ export class D20Roll extends DHRoll {
|
|||
type: config.advantage,
|
||||
dice: roll.dAdvantage?.denomination,
|
||||
value: roll.dAdvantage?.total
|
||||
}
|
||||
config.roll.modifierTotal = config.roll.modifiers.reduce((a,c) => a + c.value, 0);
|
||||
};
|
||||
config.roll.modifierTotal = config.roll.modifiers.reduce((a, c) => a + c.value, 0);
|
||||
}
|
||||
|
||||
getRollData() {
|
||||
|
|
@ -254,51 +255,54 @@ export class D20Roll extends DHRoll {
|
|||
|
||||
formatModifier(modifier) {
|
||||
const numTerm = modifier < 0 ? '-' : '+';
|
||||
return [new foundry.dice.terms.OperatorTerm({operator: numTerm}), new foundry.dice.terms.NumericTerm({number: Math.abs(modifier)})];
|
||||
return [
|
||||
new foundry.dice.terms.OperatorTerm({ operator: numTerm }),
|
||||
new foundry.dice.terms.NumericTerm({ number: Math.abs(modifier) })
|
||||
];
|
||||
}
|
||||
|
||||
resetFormula() {
|
||||
return this._formula = this.constructor.getFormula(this.terms);
|
||||
return (this._formula = this.constructor.getFormula(this.terms));
|
||||
}
|
||||
}
|
||||
|
||||
export class DualityRoll extends D20Roll {
|
||||
constructor(formula, data={}, options={}) {
|
||||
constructor(formula, data = {}, options = {}) {
|
||||
super(formula, data, options);
|
||||
}
|
||||
|
||||
static messageType = 'dualityRoll';
|
||||
|
||||
// static messageTemplate = 'systems/daggerheart/templates/chat/duality-roll.hbs';
|
||||
|
||||
static messageTemplate = async (config) => {
|
||||
|
||||
static messageTemplate = async config => {
|
||||
return 'systems/daggerheart/templates/chat/duality-roll.hbs';
|
||||
}
|
||||
};
|
||||
|
||||
static DefaultDialog = D20RollDialog;
|
||||
|
||||
get dHope() {
|
||||
// if ( !(this.terms[0] instanceof foundry.dice.terms.Die) ) return;
|
||||
if ( !(this.dice[0] instanceof CONFIG.Dice.daggerheart.DualityDie) ) this.createBaseDice();
|
||||
if (!(this.dice[0] instanceof CONFIG.Dice.daggerheart.DualityDie)) this.createBaseDice();
|
||||
return this.dice[0];
|
||||
// return this.#hopeDice;
|
||||
}
|
||||
|
||||
set dHope(faces) {
|
||||
if ( !(this.dice[0] instanceof CONFIG.Dice.daggerheart.DualityDie) ) this.createBaseDice();
|
||||
if (!(this.dice[0] instanceof CONFIG.Dice.daggerheart.DualityDie)) this.createBaseDice();
|
||||
this.terms[0].faces = faces;
|
||||
// this.#hopeDice = `d${face}`;
|
||||
}
|
||||
|
||||
get dFear() {
|
||||
// if ( !(this.terms[1] instanceof foundry.dice.terms.Die) ) return;
|
||||
if ( !(this.dice[1] instanceof CONFIG.Dice.daggerheart.DualityDie) ) this.createBaseDice();
|
||||
if (!(this.dice[1] instanceof CONFIG.Dice.daggerheart.DualityDie)) this.createBaseDice();
|
||||
return this.dice[1];
|
||||
// return this.#fearDice;
|
||||
}
|
||||
|
||||
set dFear(faces) {
|
||||
if ( !(this.dice[1] instanceof CONFIG.Dice.daggerheart.DualityDie) ) this.createBaseDice();
|
||||
if (!(this.dice[1] instanceof CONFIG.Dice.daggerheart.DualityDie)) this.createBaseDice();
|
||||
this.dice[1].faces = faces;
|
||||
// this.#fearDice = `d${face}`;
|
||||
}
|
||||
|
|
@ -308,17 +312,17 @@ export class DualityRoll extends D20Roll {
|
|||
}
|
||||
|
||||
get isCritical() {
|
||||
if ( !this.dHope._evaluated || !this.dFear._evaluated ) return;
|
||||
if (!this.dHope._evaluated || !this.dFear._evaluated) return;
|
||||
return this.dHope.total === this.dFear.total;
|
||||
}
|
||||
|
||||
get withHope() {
|
||||
if(!this._evaluated) return;
|
||||
if (!this._evaluated) return;
|
||||
return this.dHope.total > this.dFear.total;
|
||||
}
|
||||
|
||||
get withFear() {
|
||||
if(!this._evaluated) return;
|
||||
if (!this._evaluated) return;
|
||||
return this.dHope.total < this.dFear.total;
|
||||
}
|
||||
|
||||
|
|
@ -326,105 +330,110 @@ export class DualityRoll extends D20Roll {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
get totalLabel() {
|
||||
const label =
|
||||
this.withHope
|
||||
? 'DAGGERHEART.General.Hope'
|
||||
: this.withFear
|
||||
? 'DAGGERHEART.General.Fear'
|
||||
: 'DAGGERHEART.General.CriticalSuccess';
|
||||
const label = this.withHope
|
||||
? 'DAGGERHEART.General.Hope'
|
||||
: this.withFear
|
||||
? 'DAGGERHEART.General.Fear'
|
||||
: 'DAGGERHEART.General.CriticalSuccess';
|
||||
|
||||
return game.i18n.localize(label);
|
||||
}
|
||||
|
||||
createBaseDice() {
|
||||
if ( this.dice[0] instanceof CONFIG.Dice.daggerheart.DualityDie && this.dice[1] instanceof CONFIG.Dice.daggerheart.DualityDie ) return;
|
||||
if ( !(this.dice[0] instanceof CONFIG.Dice.daggerheart.DualityDie) ) this.terms[0] = new CONFIG.Dice.daggerheart.DualityDie();
|
||||
this.terms[1] = new foundry.dice.terms.OperatorTerm({operator:'+'});
|
||||
if ( !(this.dice[2] instanceof CONFIG.Dice.daggerheart.DualityDie) ) this.terms[2] = new CONFIG.Dice.daggerheart.DualityDie();
|
||||
if (
|
||||
this.dice[0] instanceof CONFIG.Dice.daggerheart.DualityDie &&
|
||||
this.dice[1] instanceof CONFIG.Dice.daggerheart.DualityDie
|
||||
)
|
||||
return;
|
||||
if (!(this.dice[0] instanceof CONFIG.Dice.daggerheart.DualityDie))
|
||||
this.terms[0] = new CONFIG.Dice.daggerheart.DualityDie();
|
||||
this.terms[1] = new foundry.dice.terms.OperatorTerm({ operator: '+' });
|
||||
if (!(this.dice[2] instanceof CONFIG.Dice.daggerheart.DualityDie))
|
||||
this.terms[2] = new CONFIG.Dice.daggerheart.DualityDie();
|
||||
}
|
||||
|
||||
applyAdvantage() {
|
||||
const dieFaces = 6,
|
||||
bardRallyFaces = this.hasBarRally,
|
||||
advDie = new foundry.dice.terms.Die({faces: dieFaces});
|
||||
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});
|
||||
if(this.hasAdvantage) {
|
||||
this.terms.push(new foundry.dice.terms.PoolTerm({
|
||||
terms: [advDie.formula, rallyDie.formula],
|
||||
modifiers: ["kh"]
|
||||
}))
|
||||
} else if(this.hasDisadvantage){
|
||||
this.terms.push(advDie, new foundry.dice.terms.OperatorTerm({operator:'+'}), rallyDie);
|
||||
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 });
|
||||
if (this.hasAdvantage) {
|
||||
this.terms.push(
|
||||
new foundry.dice.terms.PoolTerm({
|
||||
terms: [advDie.formula, rallyDie.formula],
|
||||
modifiers: ['kh']
|
||||
})
|
||||
);
|
||||
} else if (this.hasDisadvantage) {
|
||||
this.terms.push(advDie, new foundry.dice.terms.OperatorTerm({ operator: '+' }), rallyDie);
|
||||
}
|
||||
} else if(this.hasAdvantage || this.hasDisadvantage) this.terms.push(advDie);
|
||||
} else if (this.hasAdvantage || this.hasDisadvantage) this.terms.push(advDie);
|
||||
}
|
||||
|
||||
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)
|
||||
// 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));
|
||||
}
|
||||
|
||||
static async postEvaluate(roll, config={}) {
|
||||
console.log(roll,config);
|
||||
static async postEvaluate(roll, config = {}) {
|
||||
console.log(roll, config);
|
||||
super.postEvaluate(roll, config);
|
||||
config.roll.hope = {
|
||||
dice: roll.dHope.denomination,
|
||||
value: roll.dHope.total
|
||||
}
|
||||
};
|
||||
config.roll.fear = {
|
||||
dice: roll.dFear.denomination,
|
||||
value: roll.dFear.total
|
||||
}
|
||||
};
|
||||
config.roll.result = {
|
||||
duality: roll.withHope ? 1 : roll.withFear ? -1 : 0,
|
||||
total: roll.dHope.total + roll.dFear.total,
|
||||
label: roll.totalLabel
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export class DamageRoll extends DHRoll {
|
||||
constructor(formula, data={}, options={}) {
|
||||
super(formula, data, options)
|
||||
constructor(formula, data = {}, options = {}) {
|
||||
super(formula, data, options);
|
||||
}
|
||||
|
||||
static messageType = 'damageRoll';
|
||||
|
||||
// static messageTemplate = 'systems/daggerheart/templates/chat/damage-roll.hbs';
|
||||
static messageTemplate = async (config) => {
|
||||
static messageTemplate = async config => {
|
||||
return await foundry.applications.handlebars.renderTemplate(
|
||||
config.messageTemplate ?? 'systems/daggerheart/templates/chat/damage-roll.hbs',
|
||||
config
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
static DefaultDialog = DamageDialog;
|
||||
|
||||
static async postEvaluate(roll, config={}) {
|
||||
console.log(roll, config)
|
||||
|
||||
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
|
||||
};
|
||||
if (roll.healing) config.roll.type = roll.healing.type;
|
||||
/* const dice = [];
|
||||
const modifiers = [];
|
||||
for (var i = 0; i < roll.terms.length; i++) {
|
||||
|
|
@ -444,4 +453,4 @@ export class DamageRoll extends DHRoll {
|
|||
config.roll.dice = dice;
|
||||
config.roll.modifiers = modifiers; */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
|
||||
static DEFAULT_OPTIONS = {
|
||||
tag: 'form',
|
||||
classes: ['daggerheart', 'sheet', 'pc'],
|
||||
position: { width: 810, height: 1080 },
|
||||
classes: ['daggerheart', 'sheet', 'actor', 'dh-style', 'daggerheart', 'character'],
|
||||
position: { width: 850, height: 800 },
|
||||
actions: {
|
||||
attributeRoll: this.rollAttribute,
|
||||
toggleMarks: this.toggleMarks,
|
||||
|
|
@ -47,10 +47,10 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
useAdvancementCard: this.useAdvancementCard,
|
||||
useAdvancementAbility: this.useAdvancementAbility,
|
||||
toggleEquipItem: this.toggleEquipItem,
|
||||
levelup: this.openLevelUp
|
||||
levelup: this.openLevelUp,
|
||||
editImage: this._onEditImage
|
||||
},
|
||||
window: {
|
||||
minimizable: false,
|
||||
resizable: true
|
||||
},
|
||||
form: {
|
||||
|
|
@ -66,9 +66,76 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
};
|
||||
|
||||
static PARTS = {
|
||||
form: {
|
||||
id: 'character',
|
||||
template: 'systems/daggerheart/templates/sheets/character/character.hbs'
|
||||
sidebar: {
|
||||
id: 'sidebar',
|
||||
template: 'systems/daggerheart/templates/sheets/actors/character/sidebar.hbs'
|
||||
},
|
||||
header: {
|
||||
id: 'header',
|
||||
template: 'systems/daggerheart/templates/sheets/actors/character/header.hbs'
|
||||
},
|
||||
features: {
|
||||
id: 'features',
|
||||
template: 'systems/daggerheart/templates/sheets/actors/character/features.hbs'
|
||||
},
|
||||
loadout: {
|
||||
id: 'loadout',
|
||||
template: 'systems/daggerheart/templates/sheets/actors/character/loadout.hbs'
|
||||
},
|
||||
inventory: {
|
||||
id: 'inventory',
|
||||
template: 'systems/daggerheart/templates/sheets/actors/character/inventory.hbs'
|
||||
},
|
||||
biography: {
|
||||
id: 'biography',
|
||||
template: 'systems/daggerheart/templates/sheets/actors/character/biography.hbs'
|
||||
},
|
||||
effects: {
|
||||
id: 'effects',
|
||||
template: 'systems/daggerheart/templates/sheets/actors/character/effects.hbs'
|
||||
}
|
||||
};
|
||||
|
||||
static TABS = {
|
||||
features: {
|
||||
active: true,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'features',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.Sheets.PC.Tabs.Features'
|
||||
},
|
||||
loadout: {
|
||||
active: false,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'loadout',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.Sheets.PC.Tabs.Loadout'
|
||||
},
|
||||
inventory: {
|
||||
active: false,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'inventory',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.Sheets.PC.Tabs.Inventory'
|
||||
},
|
||||
biography: {
|
||||
active: false,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'biography',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.Sheets.PC.Tabs.biography'
|
||||
},
|
||||
effects: {
|
||||
active: false,
|
||||
cssClass: '',
|
||||
group: 'primary',
|
||||
id: 'effects',
|
||||
icon: null,
|
||||
label: 'DAGGERHEART.Sheets.PC.Tabs.effects'
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -150,17 +217,29 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
_attachPartListeners(partId, htmlElement, options) {
|
||||
super._attachPartListeners(partId, htmlElement, options);
|
||||
|
||||
htmlElement.querySelector('.level-value').addEventListener('change', this.onLevelChange.bind(this));
|
||||
// htmlElement.querySelector('.level-value').addEventListener('change', this.onLevelChange.bind(this));
|
||||
// To Remove when ContextMenu Handler is made
|
||||
htmlElement
|
||||
.querySelectorAll('[data-item-id]')
|
||||
.forEach(element => element.addEventListener('contextmenu', this.editItem.bind(this)));
|
||||
}
|
||||
|
||||
static _onEditImage() {
|
||||
const fp = new FilePicker({
|
||||
current: this.document.img,
|
||||
type: 'image',
|
||||
redirectToRoot: ['icons/svg/mystery-man.svg'],
|
||||
callback: async path => this._updateImage.bind(this)(path),
|
||||
top: this.position.top + 40,
|
||||
left: this.position.left + 10
|
||||
});
|
||||
return fp.browse();
|
||||
}
|
||||
|
||||
async _prepareContext(_options) {
|
||||
const context = await super._prepareContext(_options);
|
||||
context.document = this.document;
|
||||
context.tabs = this._getTabs();
|
||||
context.tabs = super._getTabs(this.constructor.TABS);
|
||||
|
||||
context.config = SYSTEM;
|
||||
|
||||
|
|
@ -293,7 +372,7 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
trait: button.dataset.attribute
|
||||
/* label: abilityLabel,
|
||||
modifier: button.dataset.value */
|
||||
},
|
||||
}
|
||||
/* chatMessage: {
|
||||
template: 'systems/daggerheart/templates/chat/duality-roll.hbs'
|
||||
} */
|
||||
|
|
|
|||
|
|
@ -93,21 +93,21 @@ export const healingTypes = {
|
|||
export const conditions = {
|
||||
vulnerable: {
|
||||
id: 'vulnerable',
|
||||
name: 'DAGGERHEART.Condition.Vulnerable.Name',
|
||||
name: 'DAGGERHEART.Condition.vulnerable.name',
|
||||
icon: 'icons/magic/control/silhouette-fall-slip-prone.webp',
|
||||
description: 'DAGGERHEART.Condition.Vulnerable.Description'
|
||||
description: 'DAGGERHEART.Condition.vulnerable.description'
|
||||
},
|
||||
hidden: {
|
||||
id: 'hidden',
|
||||
name: 'DAGGERHEART.Condition.Hidden.Name',
|
||||
name: 'DAGGERHEART.Condition.hidden.name',
|
||||
icon: 'icons/magic/perception/silhouette-stealth-shadow.webp',
|
||||
description: 'DAGGERHEART.Condition.Hidden.Description'
|
||||
description: 'DAGGERHEART.Condition.hidden.description'
|
||||
},
|
||||
restrained: {
|
||||
id: 'restrained',
|
||||
name: 'DAGGERHEART.Condition.Restrained.Name',
|
||||
name: 'DAGGERHEART.Condition.restrained.name',
|
||||
icon: 'icons/magic/control/debuff-chains-shackle-movement-red.webp',
|
||||
description: 'DAGGERHEART.Condition.Restrained.Description'
|
||||
description: 'DAGGERHEART.Condition.restrained.description'
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -109,7 +109,8 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
|||
type: new fields.StringField({
|
||||
choices: SYSTEM.ACTIONS.targetTypes,
|
||||
initial: SYSTEM.ACTIONS.targetTypes.any.id,
|
||||
nullable: true, initial: null
|
||||
nullable: true,
|
||||
initial: null
|
||||
}),
|
||||
amount: new fields.NumberField({ nullable: true, initial: null, integer: true, min: 0 })
|
||||
}),
|
||||
|
|
@ -130,8 +131,8 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
|||
})
|
||||
},
|
||||
extraSchemas = {};
|
||||
|
||||
this.extraSchemas.forEach(s => extraSchemas[s] = extraFields[s]);
|
||||
|
||||
this.extraSchemas.forEach(s => (extraSchemas[s] = extraFields[s]));
|
||||
return extraSchemas;
|
||||
}
|
||||
|
||||
|
|
@ -170,8 +171,8 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
|||
trait: parent.system.trait
|
||||
};
|
||||
}
|
||||
if(parent?.type === 'weapon' && !!this.schema.fields.damage) {
|
||||
updateSource['damage'] = {includeBase: true};
|
||||
if (parent?.type === 'weapon' && !!this.schema.fields.damage) {
|
||||
updateSource['damage'] = { includeBase: true };
|
||||
}
|
||||
if (parent?.system?.range) {
|
||||
updateSource['range'] = parent?.system?.range;
|
||||
|
|
@ -185,9 +186,14 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
|||
...actorData.toObject(),
|
||||
prof: actorData.proficiency?.value ?? 1,
|
||||
cast: actorData.spellcast?.value ?? 1,
|
||||
scale: this.cost.length ? this.cost.reduce((a,c) => {a[c.type] = c.value; return a},{}) : 1,
|
||||
scale: this.cost.length
|
||||
? this.cost.reduce((a, c) => {
|
||||
a[c.type] = c.value;
|
||||
return a;
|
||||
}, {})
|
||||
: 1,
|
||||
roll: {}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async use(event, ...args) {
|
||||
|
|
@ -205,25 +211,30 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
|||
};
|
||||
|
||||
// this.proceedChatDisplay(config);
|
||||
|
||||
|
||||
// Filter selected targets based on Target parameters
|
||||
config.targets = await this.getTarget(config);
|
||||
if(!config.targets) return ui.notifications.warn("Too many targets selected for that actions.");
|
||||
|
||||
if (!config.targets) return ui.notifications.warn('Too many targets selected for that actions.');
|
||||
|
||||
// Filter selected targets based on Range parameters
|
||||
config.range = await this.checkRange(config);
|
||||
if(!config.range.hasRange) return ui.notifications.warn("No Target within range.");
|
||||
if (!config.range.hasRange) return ui.notifications.warn('No Target within range.');
|
||||
|
||||
// Display Costs Dialog & Check if Actor get enough resources
|
||||
config.costs = await this.getCost(config);
|
||||
if(!this.hasRoll() && !config.costs.hasCost) return ui.notifications.warn("You don't have the resources to use that action.");
|
||||
// Display Uses/Costs Dialog & Check if Actor get enough resources
|
||||
config = {
|
||||
...config,
|
||||
...(await this.getCost(config))
|
||||
};
|
||||
if (!this.hasRoll() && (!config.costs.hasCost || !this.hasUses(config.uses)))
|
||||
return ui.notifications.warn("You don't have the resources to use that action.");
|
||||
|
||||
// Proceed with Roll
|
||||
config = await this.proceedRoll(config);
|
||||
if(!config) return;
|
||||
|
||||
if (this.roll && !config.roll.result) return;
|
||||
|
||||
// Update Actor resources based on Action Cost configuration
|
||||
this.spendCost(config.costs.values);
|
||||
this.spendUses(config.uses);
|
||||
|
||||
// console.log(config)
|
||||
|
||||
|
|
@ -238,36 +249,37 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
|||
async proceedRoll(config) {
|
||||
if (!this.hasRoll()) return config;
|
||||
const modifierValue = this.actor.system.traits[this.roll.trait].value;
|
||||
config = {
|
||||
...config,
|
||||
roll: {
|
||||
modifiers: [],
|
||||
trait: this.roll?.trait,
|
||||
label: game.i18n.localize(abilities[this.roll.trait].label),
|
||||
type: this.actionType,
|
||||
difficulty: this.roll?.difficulty
|
||||
}
|
||||
config = {
|
||||
...config,
|
||||
roll: {
|
||||
modifiers: [],
|
||||
trait: this.roll?.trait,
|
||||
label: game.i18n.localize(abilities[this.roll.trait].label),
|
||||
type: this.actionType,
|
||||
difficulty: this.roll?.difficulty
|
||||
}
|
||||
return await this.actor.diceRoll(config, this);
|
||||
};
|
||||
// config = await this.actor.diceRoll(config, this);
|
||||
return this.actor.diceRoll(config, this);
|
||||
}
|
||||
/* ROLL */
|
||||
|
||||
/* COST */
|
||||
async getCost(config) {
|
||||
if(!this.cost?.length || !this.actor) return {values: [], hasCost: true};
|
||||
let cost = foundry.utils.deepClone(this.cost);
|
||||
let costs = this.cost?.length ? foundry.utils.deepClone(this.cost) : { values: [], hasCost: true };
|
||||
let uses = this.getUses();
|
||||
if (!config.event.shiftKey && !this.hasRoll()) {
|
||||
const dialogClosed = new Promise((resolve, _) => {
|
||||
new CostSelectionDialog(cost, this, resolve).render(true);
|
||||
new CostSelectionDialog(costs, uses, this, resolve).render(true);
|
||||
});
|
||||
cost = await dialogClosed;
|
||||
({ costs, uses } = await dialogClosed);
|
||||
}
|
||||
return cost;
|
||||
return { costs, uses };
|
||||
}
|
||||
|
||||
getRealCosts(costs) {
|
||||
const realCosts = costs?.length ? costs.filter(c => c.enabled) : [];
|
||||
return {values: realCosts, hasCost: this.hasCost(realCosts)}
|
||||
return { values: realCosts, hasCost: this.hasCost(realCosts) };
|
||||
}
|
||||
|
||||
calcCosts(costs) {
|
||||
|
|
@ -276,44 +288,69 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
|||
c.step = c.step ?? 1;
|
||||
c.total = c.value * c.scale * c.step;
|
||||
c.enabled = c.hasOwnProperty('enabled') ? c.enabled : true;
|
||||
return c
|
||||
})
|
||||
return c;
|
||||
});
|
||||
}
|
||||
|
||||
hasCost(costs) {
|
||||
return costs.reduce((a, c) => a && this.actor.system.resources[c.type]?.value >= (c.total ?? c.value), true)
|
||||
return costs.reduce((a, c) => a && this.actor.system.resources[c.type]?.value >= (c.total ?? c.value), true);
|
||||
}
|
||||
|
||||
async spendCost(config) {
|
||||
if(!config.costs?.values?.length) return;
|
||||
if (!config.costs?.values?.length) return;
|
||||
return await this.actor.modifyResource(config.costs.values);
|
||||
}
|
||||
/* COST */
|
||||
|
||||
/* USES */
|
||||
async spendUses(config) {
|
||||
if(!this.uses.max) return;
|
||||
if (!this.uses.max || config.enabled === false) return;
|
||||
const newActions = foundry.utils.getProperty(this.item.system, this.systemPath).map(x => x.toObject());
|
||||
newActions[this.index].uses.value++;
|
||||
await this.item.update({ [`system.${this.systemPath}`]: newActions });
|
||||
}
|
||||
|
||||
getUses() {
|
||||
if (!this.uses) return { hasUse: true };
|
||||
const uses = foundry.utils.deepClone(this.uses);
|
||||
if (!uses.value) uses.value = 0;
|
||||
return uses;
|
||||
}
|
||||
|
||||
calcUses(uses) {
|
||||
return {
|
||||
...uses,
|
||||
enabled: uses.hasOwnProperty('enabled') ? uses.enabled : true
|
||||
};
|
||||
}
|
||||
|
||||
hasUses(uses) {
|
||||
return !uses.enabled || uses.value + 1 <= uses.max;
|
||||
}
|
||||
/* USES */
|
||||
|
||||
|
||||
/* TARGET */
|
||||
async getTarget(config) {
|
||||
if(this.target?.type === SYSTEM.ACTIONS.targetTypes.self.id) return this.formatTarget(this.actor.token ?? this.actor.prototypeToken);
|
||||
if (this.target?.type === SYSTEM.ACTIONS.targetTypes.self.id)
|
||||
return this.formatTarget(this.actor.token ?? this.actor.prototypeToken);
|
||||
let targets = Array.from(game.user.targets);
|
||||
// foundry.CONST.TOKEN_DISPOSITIONS.FRIENDLY
|
||||
if(this.target?.type && this.target.type !== SYSTEM.ACTIONS.targetTypes.any.id) {
|
||||
if (this.target?.type && this.target.type !== SYSTEM.ACTIONS.targetTypes.any.id) {
|
||||
targets = targets.filter(t => this.isTargetFriendly(t));
|
||||
if(this.target.amount && targets.length > this.target.amount) return false;
|
||||
if (this.target.amount && targets.length > this.target.amount) return false;
|
||||
}
|
||||
return targets.map(t => this.formatTarget(t));
|
||||
}
|
||||
|
||||
isTargetFriendly(target) {
|
||||
const actorDisposition = this.actor.token ? this.actor.token.disposition : this.actor.prototypeToken.disposition,
|
||||
const actorDisposition = this.actor.token
|
||||
? this.actor.token.disposition
|
||||
: this.actor.prototypeToken.disposition,
|
||||
targetDisposition = target.document.disposition;
|
||||
return (this.target.type === SYSTEM.ACTIONS.targetTypes.friendly.id && actorDisposition === targetDisposition) || (this.target.type === SYSTEM.ACTIONS.targetTypes.hostile.id && (actorDisposition + targetDisposition === 0))
|
||||
return (
|
||||
(this.target.type === SYSTEM.ACTIONS.targetTypes.friendly.id && actorDisposition === targetDisposition) ||
|
||||
(this.target.type === SYSTEM.ACTIONS.targetTypes.hostile.id && actorDisposition + targetDisposition === 0)
|
||||
);
|
||||
}
|
||||
|
||||
formatTarget(actor) {
|
||||
|
|
@ -323,57 +360,58 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
|||
img: actor.actor.img,
|
||||
difficulty: actor.actor.system.difficulty,
|
||||
evasion: actor.actor.system.evasion?.value
|
||||
}
|
||||
};
|
||||
}
|
||||
/* TARGET */
|
||||
|
||||
|
||||
/* RANGE */
|
||||
async checkRange(config) {
|
||||
if(!this.range || !this.actor) return true;
|
||||
return {values: [], hasRange: true};
|
||||
if (!this.range || !this.actor) return true;
|
||||
return { values: [], hasRange: true };
|
||||
}
|
||||
/* RANGE */
|
||||
|
||||
/* EFFECTS */
|
||||
async applyEffects(event, data, force=false) {
|
||||
if(!this.effects?.length || !data.system.targets.length) return;
|
||||
data.system.targets.forEach(async (token) => {
|
||||
async applyEffects(event, data, force = false) {
|
||||
if (!this.effects?.length || !data.system.targets.length) return;
|
||||
data.system.targets.forEach(async token => {
|
||||
// console.log(token, force)
|
||||
if(!token.hit && !force) return;
|
||||
this.effects.forEach(async (e) => {
|
||||
if (!token.hit && !force) return;
|
||||
this.effects.forEach(async e => {
|
||||
const actor = canvas.tokens.get(token.id)?.actor,
|
||||
effect = this.item.effects.get(e._id);
|
||||
if(!actor || !effect) return;
|
||||
if (!actor || !effect) return;
|
||||
await this.applyEffect(effect, actor);
|
||||
})
|
||||
})
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async applyEffect(effect, actor) {
|
||||
// Enable an existing effect on the target if it originated from this effect
|
||||
const existingEffect = actor.effects.find(e => e.origin === origin.uuid);
|
||||
if ( existingEffect ) {
|
||||
return existingEffect.update(foundry.utils.mergeObject({
|
||||
// Enable an existing effect on the target if it originated from this effect
|
||||
const existingEffect = actor.effects.find(e => e.origin === origin.uuid);
|
||||
if (existingEffect) {
|
||||
return existingEffect.update(
|
||||
foundry.utils.mergeObject({
|
||||
...effect.constructor.getInitialDuration(),
|
||||
disabled: false
|
||||
}));
|
||||
}
|
||||
|
||||
// Otherwise, create a new effect on the target
|
||||
const effectData = foundry.utils.mergeObject({
|
||||
...effect.toObject(),
|
||||
disabled: false,
|
||||
transfer: false,
|
||||
origin: origin.uuid
|
||||
});
|
||||
await ActiveEffect.implementation.create(effectData, { parent: actor });
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// Otherwise, create a new effect on the target
|
||||
const effectData = foundry.utils.mergeObject({
|
||||
...effect.toObject(),
|
||||
disabled: false,
|
||||
transfer: false,
|
||||
origin: origin.uuid
|
||||
});
|
||||
await ActiveEffect.implementation.create(effectData, { parent: actor });
|
||||
}
|
||||
/* EFFECTS */
|
||||
|
||||
/* CHAT */
|
||||
async proceedChatDisplay(config) {
|
||||
if(!this.chatDisplay) return;
|
||||
if (!this.chatDisplay) return;
|
||||
}
|
||||
/* CHAT */
|
||||
}
|
||||
|
|
@ -385,15 +423,14 @@ export class DHDamageAction extends DHBaseAction {
|
|||
|
||||
async use(event, ...args) {
|
||||
const config = await super.use(event, args);
|
||||
if(['error', 'warning'].includes(config.type)) return;
|
||||
if(!this.directDamage) return;
|
||||
if (!config || ['error', 'warning'].includes(config.type)) return;
|
||||
if (!this.directDamage) return;
|
||||
return await this.rollDamage(event, config);
|
||||
}
|
||||
|
||||
async rollDamage(event, data) {
|
||||
console.log(event, data)
|
||||
let formula = this.damage.parts.map(p => p.getFormula(this.actor)).join(' + ');
|
||||
|
||||
|
||||
if (!formula || formula == '') return;
|
||||
let roll = { formula: formula, total: formula },
|
||||
bonusDamage = [];
|
||||
|
|
@ -401,10 +438,15 @@ export class DHDamageAction extends DHBaseAction {
|
|||
const config = {
|
||||
title: game.i18n.format('DAGGERHEART.Chat.DamageRoll.Title', { damage: this.name }),
|
||||
formula,
|
||||
targets: (data.system?.targets ?? data.targets).map(x => ({ id: x.id, name: x.name, img: x.img, hit: true }))
|
||||
}
|
||||
targets: (data.system?.targets ?? data.targets).map(x => ({
|
||||
id: x.id,
|
||||
name: x.name,
|
||||
img: x.img,
|
||||
hit: true
|
||||
}))
|
||||
};
|
||||
|
||||
roll = CONFIG.Dice.daggerheart.DamageRoll.build(config)
|
||||
roll = CONFIG.Dice.daggerheart.DamageRoll.build(config);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -449,25 +491,32 @@ export class DHHealingAction extends DHBaseAction {
|
|||
|
||||
async use(event, ...args) {
|
||||
const config = await super.use(event, args);
|
||||
if(['error', 'warning'].includes(config.type)) return;
|
||||
if(this.hasRoll()) return;
|
||||
if (!config || ['error', 'warning'].includes(config.type)) return;
|
||||
if (this.hasRoll()) return;
|
||||
return await this.rollHealing(event, config);
|
||||
}
|
||||
|
||||
async rollHealing(event, data) {
|
||||
console.log(event, data)
|
||||
console.log(event, data);
|
||||
let formula = this.healing.value.getFormula(this.actor);
|
||||
|
||||
|
||||
if (!formula || formula == '') return;
|
||||
let roll = { formula: formula, total: formula },
|
||||
bonusDamage = [];
|
||||
|
||||
const config = {
|
||||
title: game.i18n.format('DAGGERHEART.Chat.HealingRoll.Title', { healing: game.i18n.localize(SYSTEM.GENERAL.healingTypes[this.healing.type].label) }),
|
||||
title: game.i18n.format('DAGGERHEART.Chat.HealingRoll.Title', {
|
||||
healing: game.i18n.localize(SYSTEM.GENERAL.healingTypes[this.healing.type].label)
|
||||
}),
|
||||
formula,
|
||||
targets: (data.system?.targets ?? data.targets).map(x => ({ id: x.id, name: x.name, img: x.img, hit: true })),
|
||||
targets: (data.system?.targets ?? data.targets).map(x => ({
|
||||
id: x.id,
|
||||
name: x.name,
|
||||
img: x.img,
|
||||
hit: true
|
||||
})),
|
||||
messageTemplate: 'systems/daggerheart/templates/chat/healing-roll.hbs'
|
||||
}
|
||||
};
|
||||
|
||||
roll = CONFIG.Dice.daggerheart.DamageRoll.build(config);
|
||||
}
|
||||
|
|
@ -486,13 +535,12 @@ export class DHSummonAction extends DHBaseAction {
|
|||
}
|
||||
|
||||
async use(event, ...args) {
|
||||
if ( !this.canSummon || !canvas.scene ) return;
|
||||
if (!this.canSummon || !canvas.scene) return;
|
||||
const config = await super.use(event, args);
|
||||
|
||||
}
|
||||
|
||||
get canSummon() {
|
||||
return game.user.can("TOKEN_CREATE");
|
||||
return game.user.can('TOKEN_CREATE');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -501,7 +549,7 @@ export class DHEffectAction extends DHBaseAction {
|
|||
|
||||
async use(event, ...args) {
|
||||
const config = await super.use(event, args);
|
||||
if(['error', 'warning'].includes(config.type)) return;
|
||||
if (['error', 'warning'].includes(config.type)) return;
|
||||
return await this.chatApplyEffects(event, config);
|
||||
}
|
||||
|
||||
|
|
@ -545,7 +593,7 @@ export class DHMacroAction extends DHBaseAction {
|
|||
|
||||
async use(event, ...args) {
|
||||
const config = await super.use(event, args);
|
||||
if(['error', 'warning'].includes(config.type)) return;
|
||||
if (['error', 'warning'].includes(config.type)) return;
|
||||
const fixUUID = !this.documentUUID.includes('Macro.') ? `Macro.${this.documentUUID}` : this.documentUUID,
|
||||
macro = await fromUuid(fixUUID);
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -62,14 +62,21 @@ export default class DhCharacter extends BaseDataActor {
|
|||
bags: new fields.NumberField({ initial: 0, integer: true }),
|
||||
chests: new fields.NumberField({ initial: 0, integer: true })
|
||||
}),
|
||||
pronouns: new fields.StringField({}),
|
||||
scars: new fields.TypedObjectField(
|
||||
new fields.SchemaField({
|
||||
name: new fields.StringField({}),
|
||||
description: new fields.HTMLField()
|
||||
})
|
||||
),
|
||||
story: new fields.HTMLField(),
|
||||
biography: new fields.SchemaField({
|
||||
background: new fields.HTMLField(),
|
||||
connections: new fields.HTMLField(),
|
||||
characteristics: new fields.SchemaField({
|
||||
pronouns: new fields.StringField({}),
|
||||
age: new fields.StringField({}),
|
||||
faith: new fields.StringField({})
|
||||
})
|
||||
}),
|
||||
class: new fields.SchemaField({
|
||||
value: new ForeignDocumentUUIDField({ type: 'Item', nullable: true }),
|
||||
subclass: new ForeignDocumentUUIDField({ type: 'Item', nullable: true })
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api;
|
||||
|
||||
export default class D20RollDialog extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
constructor(config={}, options={}) {
|
||||
constructor(config = {}, options = {}) {
|
||||
super(options);
|
||||
|
||||
this.config = config;
|
||||
this.config.experiences = [];
|
||||
|
||||
this.item = config.actor.parent.items.get(config.source.item);
|
||||
this.action = this.item.system.actions.find(a => a._id === config.source.action);
|
||||
|
||||
if (config.source?.action) {
|
||||
this.item = config.actor.parent.items.get(config.source.item);
|
||||
this.action = this.item.system.actions.find(a => a._id === config.source.action);
|
||||
}
|
||||
}
|
||||
|
||||
static DEFAULT_OPTIONS = {
|
||||
|
|
@ -45,23 +47,30 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
|
||||
async _prepareContext(_options) {
|
||||
const context = await super._prepareContext(_options);
|
||||
context.experiences = Object.keys(this.config.actor.experiences).map(id => ({ id, ...this.config.actor.experiences[id] }));
|
||||
context.experiences = Object.keys(this.config.actor.experiences).map(id => ({
|
||||
id,
|
||||
...this.config.actor.experiences[id]
|
||||
}));
|
||||
context.selectedExperiences = this.config.experiences;
|
||||
context.advantage = this.config.advantage;
|
||||
/* context.diceOptions = this.diceOptions; */
|
||||
context.canRoll = true;
|
||||
if(this.config.costs?.length) {
|
||||
if (this.config.costs?.length) {
|
||||
const updatedCosts = this.action.calcCosts(this.config.costs);
|
||||
context.costs = updatedCosts
|
||||
context.costs = updatedCosts;
|
||||
context.canRoll = this.action.getRealCosts(updatedCosts)?.hasCost;
|
||||
}
|
||||
if (this.config.uses?.max) {
|
||||
context.uses = this.action.calcUses(this.config.uses);
|
||||
context.canRoll = context.canRoll && this.action.hasUses(context.uses);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
static updateRollConfiguration(event, _, formData) {
|
||||
const { ...rest } = foundry.utils.expandObject(formData.object);
|
||||
console.log(formData.object, rest)
|
||||
this.config.costs = foundry.utils.mergeObject(this.config.costs, rest.costs);
|
||||
if (this.config.costs) 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);
|
||||
this.render();
|
||||
}
|
||||
|
||||
|
|
@ -81,19 +90,19 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
}
|
||||
|
||||
static async submitRoll() {
|
||||
await this.close({ submitted: true });
|
||||
await this.close({ submitted: true });
|
||||
}
|
||||
|
||||
/** @override */
|
||||
_onClose(options={}) {
|
||||
if ( !options.submitted ) this.config = false;
|
||||
_onClose(options = {}) {
|
||||
if (!options.submitted) this.config = false;
|
||||
}
|
||||
|
||||
static async configure(config={}) {
|
||||
static async configure(config = {}) {
|
||||
return new Promise(resolve => {
|
||||
const app = new this(config);
|
||||
app.addEventListener("close", () => resolve(app.config), { once: true });
|
||||
app.addEventListener('close', () => resolve(app.config), { once: true });
|
||||
app.render({ force: true });
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -269,19 +269,11 @@ export default class DhpActor extends Actor {
|
|||
// console.log(config)
|
||||
config.source = { ...(config.source ?? {}), actor: this.id };
|
||||
const newConfig = {
|
||||
// data: {
|
||||
...config,
|
||||
/* action, */
|
||||
// actor: this.getRollData(),
|
||||
actor: this.system
|
||||
// },
|
||||
// options: {
|
||||
// dialog: false,
|
||||
// },
|
||||
// event: config.event
|
||||
};
|
||||
// console.log(this, newConfig)
|
||||
const roll = CONFIG.Dice.daggerheart[this.type === 'character' ? 'DualityRoll' : 'D20Roll'].build(newConfig);
|
||||
const roll =
|
||||
await CONFIG.Dice.daggerheart[this.type === 'character' ? 'DualityRoll' : 'D20Roll'].build(newConfig);
|
||||
return config;
|
||||
/* let hopeDice = 'd12',
|
||||
fearDice = 'd12',
|
||||
|
|
|
|||
|
|
@ -13,10 +13,43 @@ export default class RegisterHandlebarsHelpers {
|
|||
signedNumber: this.signedNumber,
|
||||
length: this.length,
|
||||
switch: this.switch,
|
||||
case: this.case
|
||||
case: this.case,
|
||||
eq: this.eq,
|
||||
ne: this.ne,
|
||||
lt: this.lt,
|
||||
gt: this.gt,
|
||||
lte: this.lte,
|
||||
gte: this.gte,
|
||||
and: this.and,
|
||||
or: this.or
|
||||
});
|
||||
}
|
||||
|
||||
static eq(v1, v2) {
|
||||
return v1 === v2;
|
||||
}
|
||||
static ne(v1, v2) {
|
||||
return v1 !== v2;
|
||||
}
|
||||
static lt(v1, v2) {
|
||||
return v1 < v2;
|
||||
}
|
||||
static gt(v1, v2) {
|
||||
return v1 > v2;
|
||||
}
|
||||
static lte(v1, v2) {
|
||||
return v1 <= v2;
|
||||
}
|
||||
static gte(v1, v2) {
|
||||
return v1 >= v2;
|
||||
}
|
||||
static and() {
|
||||
return Array.prototype.every.call(arguments, Boolean);
|
||||
}
|
||||
static or() {
|
||||
return Array.prototype.slice.call(arguments, 0, -1).some(Boolean);
|
||||
}
|
||||
|
||||
static times(nr, block) {
|
||||
var accum = '';
|
||||
for (var i = 0; i < nr; ++i) accum += block.fn(i);
|
||||
|
|
@ -101,7 +134,7 @@ export default class RegisterHandlebarsHelpers {
|
|||
}
|
||||
|
||||
static debug(a) {
|
||||
console.log(JSON.stringify(a));
|
||||
console.log(a);
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue