mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-06-08 21:58:11 +02:00
Fixed UseItem and ToChat
This commit is contained in:
parent
8ea596544b
commit
6018763d47
3 changed files with 150 additions and 74 deletions
|
|
@ -10,7 +10,8 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
position: { width: 660, height: 766 },
|
||||
actions: {
|
||||
reactionRoll: this.reactionRoll,
|
||||
attackRoll: this.attackRoll,
|
||||
useItem: this.useItem,
|
||||
toChat: this.toChat,
|
||||
attackConfigure: this.attackConfigure,
|
||||
addExperience: this.addExperience,
|
||||
removeExperience: this.removeExperience,
|
||||
|
|
@ -70,6 +71,12 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
return context;
|
||||
}
|
||||
|
||||
getAction(element) {
|
||||
const itemId = (element.target ?? element).closest('[data-item-id]').dataset.itemId,
|
||||
item = this.document.system.actions.find(x => x.id === itemId);
|
||||
return item;
|
||||
}
|
||||
|
||||
static async updateForm(event, _, formData) {
|
||||
await this.document.update(formData.object);
|
||||
this.render();
|
||||
|
|
@ -100,8 +107,36 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
await new DHAdversarySettings(this.document).render(true);
|
||||
}
|
||||
|
||||
static async attackRoll(event) {
|
||||
this.actor.system.attack.use(event);
|
||||
static async useItem(event) {
|
||||
const action = this.getAction(event) ?? this.actor.system.attack;
|
||||
action.use(event);
|
||||
}
|
||||
|
||||
static async toChat(event, button) {
|
||||
if (button?.dataset?.type === 'experience') {
|
||||
const experience = this.document.system.experiences[button.dataset.uuid];
|
||||
const cls = getDocumentClass('ChatMessage');
|
||||
const systemData = {
|
||||
name: game.i18n.localize('DAGGERHEART.General.Experience.Single'),
|
||||
description: `${experience.name} ${
|
||||
experience.modifier < 0 ? experience.modifier : `+${experience.modifier}`
|
||||
}`
|
||||
};
|
||||
const msg = new cls({
|
||||
type: 'abilityUse',
|
||||
user: game.user.id,
|
||||
system: systemData,
|
||||
content: await foundry.applications.handlebars.renderTemplate(
|
||||
'systems/daggerheart/templates/chat/ability-use.hbs',
|
||||
systemData
|
||||
)
|
||||
});
|
||||
|
||||
cls.create(msg.toObject());
|
||||
} else {
|
||||
const item = this.getAction(event) ?? this.document.system.attack;
|
||||
item.toChat(this.document.id);
|
||||
}
|
||||
}
|
||||
|
||||
static async attackConfigure(event) {
|
||||
|
|
|
|||
|
|
@ -815,9 +815,7 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
const cls = getDocumentClass('ChatMessage');
|
||||
const systemData = {
|
||||
name: game.i18n.localize('DAGGERHEART.General.Experience.Single'),
|
||||
description: `${experience.description} ${
|
||||
experience.total < 0 ? experience.total : `+${experience.total}`
|
||||
}`
|
||||
description: `${experience.name} ${experience.total < 0 ? experience.total : `+${experience.total}`}`
|
||||
};
|
||||
const msg = new cls({
|
||||
type: 'abilityUse',
|
||||
|
|
|
|||
|
|
@ -73,7 +73,10 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
|||
save: new fields.SchemaField({
|
||||
trait: new fields.StringField({ nullable: true, initial: null, choices: SYSTEM.ACTOR.abilities }),
|
||||
difficulty: new fields.NumberField({ nullable: true, initial: 10, integer: true, min: 0 }),
|
||||
damageMod: new fields.StringField({ initial: SYSTEM.ACTIONS.damageOnSave.none.id, choices: SYSTEM.ACTIONS.damageOnSave })
|
||||
damageMod: new fields.StringField({
|
||||
initial: SYSTEM.ACTIONS.damageOnSave.none.id,
|
||||
choices: SYSTEM.ACTIONS.damageOnSave
|
||||
})
|
||||
}),
|
||||
target: new fields.SchemaField({
|
||||
type: new fields.StringField({
|
||||
|
|
@ -98,9 +101,12 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
|||
initial: SYSTEM.GENERAL.healingTypes.hitPoints.id,
|
||||
label: 'Healing'
|
||||
}),
|
||||
resultBased: new fields.BooleanField({ initial: false, label: "DAGGERHEART.Actions.Settings.ResultBased.label" }),
|
||||
resultBased: new fields.BooleanField({
|
||||
initial: false,
|
||||
label: 'DAGGERHEART.Actions.Settings.ResultBased.label'
|
||||
}),
|
||||
value: new fields.EmbeddedDataField(DHActionDiceData),
|
||||
valueAlt: new fields.EmbeddedDataField(DHActionDiceData),
|
||||
valueAlt: new fields.EmbeddedDataField(DHActionDiceData)
|
||||
})
|
||||
},
|
||||
extraSchemas = {};
|
||||
|
|
@ -191,12 +197,14 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
|||
|
||||
// Prepare Costs
|
||||
const costsConfig = this.prepareCost();
|
||||
if(isFastForward && !this.hasCost(costsConfig)) return ui.notifications.warn("You don't have the resources to use that action.");
|
||||
if (isFastForward && !this.hasCost(costsConfig))
|
||||
return ui.notifications.warn("You don't have the resources to use that action.");
|
||||
// config = this.prepareUseCost(config)
|
||||
|
||||
// Prepare Uses
|
||||
const usesConfig = this.prepareUse();
|
||||
if(isFastForward && !this.hasUses(usesConfig)) return ui.notifications.warn("That action doesn't have remaining uses.");
|
||||
if (isFastForward && !this.hasUses(usesConfig))
|
||||
return ui.notifications.warn("That action doesn't have remaining uses.");
|
||||
// config = this.prepareUseCost(config)
|
||||
|
||||
// Prepare Roll Data
|
||||
|
|
@ -209,7 +217,7 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
|||
costs: costsConfig,
|
||||
uses: usesConfig,
|
||||
data: actorData
|
||||
}
|
||||
};
|
||||
|
||||
if (Hooks.call(`${SYSTEM.id}.preUseAction`, this, config) === false) return;
|
||||
|
||||
|
|
@ -287,7 +295,7 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
|||
hasHealing: !!this.healing,
|
||||
hasEffect: !!this.effects?.length,
|
||||
hasSave: this.hasSave
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
requireConfigurationDialog(config) {
|
||||
|
|
@ -317,7 +325,6 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
|||
}
|
||||
targets = targets.map(t => this.formatTarget(t));
|
||||
return targets;
|
||||
|
||||
}
|
||||
|
||||
prepareRange() {
|
||||
|
|
@ -344,7 +351,9 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
|||
}
|
||||
|
||||
async consume(config) {
|
||||
const resources = config.costs.filter(c => c.enabled !== false).map(c => {
|
||||
const resources = config.costs
|
||||
.filter(c => c.enabled !== false)
|
||||
.map(c => {
|
||||
return { type: c.type, value: (c.total ?? c.value) * -1 };
|
||||
});
|
||||
|
||||
|
|
@ -388,7 +397,10 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
|||
|
||||
hasCost(costs) {
|
||||
const realCosts = this.getRealCosts(costs);
|
||||
return realCosts.reduce((a, c) => a && this.actor.system.resources[c.type]?.value >= (c.total ?? c.value), true);
|
||||
return realCosts.reduce(
|
||||
(a, c) => a && this.actor.system.resources[c.type]?.value >= (c.total ?? c.value),
|
||||
true
|
||||
);
|
||||
}
|
||||
/* COST */
|
||||
|
||||
|
|
@ -442,7 +454,7 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
|||
data.system.targets.forEach(async token => {
|
||||
if (!token.hit && !force) return;
|
||||
if (this.hasSave && token.saved.success === true) {
|
||||
effects = this.effects.filter(e => e.onSave === true)
|
||||
effects = this.effects.filter(e => e.onSave === true);
|
||||
}
|
||||
if (!effects.length) return;
|
||||
effects.forEach(async e => {
|
||||
|
|
@ -480,18 +492,24 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
|||
/* SAVE */
|
||||
async rollSave(target, event, message) {
|
||||
if (!target?.actor) return;
|
||||
target.actor.diceRoll({
|
||||
target.actor
|
||||
.diceRoll({
|
||||
event,
|
||||
title: 'Roll Save',
|
||||
roll: {
|
||||
trait: this.save.trait,
|
||||
difficulty: this.save.difficulty,
|
||||
type: "reaction"
|
||||
type: 'reaction'
|
||||
},
|
||||
data: target.actor.getRollData()
|
||||
}).then(async (result) => {
|
||||
if(result) this.updateChatMessage(message, target.id, {result: result.roll.total, success: result.roll.success});
|
||||
})
|
||||
.then(async result => {
|
||||
if (result)
|
||||
this.updateChatMessage(message, target.id, {
|
||||
result: result.roll.total,
|
||||
success: result.roll.success
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async updateChatMessage(message, targetId, changes, chain = true) {
|
||||
|
|
@ -503,14 +521,38 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
|||
await chatMessage.update({ 'system.targets': msgTargets });
|
||||
}, 100);
|
||||
if (chain) {
|
||||
if(message.system.source.message) this.updateChatMessage(ui.chat.collection.get(message.system.source.message), targetId, changes, false);
|
||||
if (message.system.source.message)
|
||||
this.updateChatMessage(ui.chat.collection.get(message.system.source.message), targetId, changes, false);
|
||||
const relatedChatMessages = ui.chat.collection.filter(c => c.system.source.message === message._id);
|
||||
relatedChatMessages.forEach(c => {
|
||||
this.updateChatMessage(c, targetId, changes, false);
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
/* SAVE */
|
||||
|
||||
async toChat(origin) {
|
||||
const cls = getDocumentClass('ChatMessage');
|
||||
const systemData = {
|
||||
title: game.i18n.localize('DAGGERHEART.ActionType.action'),
|
||||
origin: origin,
|
||||
img: this.img,
|
||||
name: this.name,
|
||||
description: this.description,
|
||||
actions: []
|
||||
};
|
||||
const msg = new cls({
|
||||
type: 'abilityUse',
|
||||
user: game.user.id,
|
||||
system: systemData,
|
||||
content: await foundry.applications.handlebars.renderTemplate(
|
||||
'systems/daggerheart/templates/chat/ability-use.hbs',
|
||||
systemData
|
||||
)
|
||||
});
|
||||
|
||||
cls.create(msg.toObject());
|
||||
}
|
||||
}
|
||||
|
||||
export class DHDamageAction extends DHBaseAction {
|
||||
|
|
@ -541,7 +583,7 @@ export class DHDamageAction extends DHBaseAction {
|
|||
const config = {
|
||||
title: game.i18n.format('DAGGERHEART.Chat.DamageRoll.Title', { damage: this.name }),
|
||||
roll: { formula },
|
||||
targets: (data.system?.targets.filter(t => t.hit) ?? data.targets),
|
||||
targets: data.system?.targets.filter(t => t.hit) ?? data.targets,
|
||||
hasSave: this.hasSave,
|
||||
source: data.system?.source,
|
||||
event
|
||||
|
|
@ -597,7 +639,8 @@ export class DHHealingAction extends DHBaseAction {
|
|||
|
||||
getFormulaValue(data) {
|
||||
let formulaValue = this.healing.value;
|
||||
if(this.hasRoll && this.healing.resultBased && data.system.roll.result.duality === -1) return this.healing.valueAlt;
|
||||
if (this.hasRoll && this.healing.resultBased && data.system.roll.result.duality === -1)
|
||||
return this.healing.valueAlt;
|
||||
return formulaValue;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue