mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
ActiveEffect values can now specify ORIGIN. to grab the value from the origin (#534)
This commit is contained in:
parent
ee5c3a9322
commit
5757db3f49
3 changed files with 42 additions and 23 deletions
|
|
@ -139,14 +139,14 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
|
||||||
config = await this.actor.diceRoll(config);
|
config = await this.actor.diceRoll(config);
|
||||||
if (!config) return;
|
if (!config) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.doFollowUp()) {
|
if (this.doFollowUp()) {
|
||||||
if (this.rollDamage && this.damage.parts.length) await this.rollDamage(event, config);
|
if (this.rollDamage && this.damage.parts.length) await this.rollDamage(event, config);
|
||||||
else if (this.trigger) await this.trigger(event, config);
|
else if (this.trigger) await this.trigger(event, config);
|
||||||
else if(this.hasSave || this.hasEffect) {
|
else if (this.hasSave || this.hasEffect) {
|
||||||
const roll = new Roll('');
|
const roll = new Roll('');
|
||||||
roll._evaluated = true;
|
roll._evaluated = true;
|
||||||
if(this.hasTarget) config.targetSelection = config.targets.length > 0;
|
if (this.hasTarget) config.targetSelection = config.targets.length > 0;
|
||||||
await CONFIG.Dice.daggerheart.DHRoll.toMessage(roll, config);
|
await CONFIG.Dice.daggerheart.DHRoll.toMessage(roll, config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -199,9 +199,7 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
|
||||||
formula: this.roll.getFormula(),
|
formula: this.roll.getFormula(),
|
||||||
advantage: CONFIG.DH.ACTIONS.advantageState[this.roll.advState].value
|
advantage: CONFIG.DH.ACTIONS.advantageState[this.roll.advState].value
|
||||||
};
|
};
|
||||||
if (this.roll?.type === 'diceSet'
|
if (this.roll?.type === 'diceSet' || !this.hasRoll) roll.lite = true;
|
||||||
|| !this.hasRoll
|
|
||||||
) roll.lite = true;
|
|
||||||
|
|
||||||
return roll;
|
return roll;
|
||||||
}
|
}
|
||||||
|
|
@ -284,8 +282,9 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
|
||||||
}
|
}
|
||||||
|
|
||||||
async applyEffect(effect, actor) {
|
async applyEffect(effect, actor) {
|
||||||
|
const origin = effect.parent?.parent ? effect.parent.parent.uuid : effect.parent.uuid;
|
||||||
// Enable an existing effect on the target if it originated from this effect
|
// Enable an existing effect on the target if it originated from this effect
|
||||||
const existingEffect = actor.effects.find(e => e.origin === origin.uuid);
|
const existingEffect = actor.effects.find(e => e.origin === origin);
|
||||||
if (existingEffect) {
|
if (existingEffect) {
|
||||||
return existingEffect.update(
|
return existingEffect.update(
|
||||||
foundry.utils.mergeObject({
|
foundry.utils.mergeObject({
|
||||||
|
|
@ -300,7 +299,7 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
|
||||||
...effect.toObject(),
|
...effect.toObject(),
|
||||||
disabled: false,
|
disabled: false,
|
||||||
transfer: false,
|
transfer: false,
|
||||||
origin: origin.uuid
|
origin: origin
|
||||||
});
|
});
|
||||||
await ActiveEffect.implementation.create(effectData, { parent: actor });
|
await ActiveEffect.implementation.create(effectData, { parent: actor });
|
||||||
}
|
}
|
||||||
|
|
@ -312,8 +311,8 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
|
||||||
const title = actor.isNPC
|
const title = actor.isNPC
|
||||||
? game.i18n.localize('DAGGERHEART.GENERAL.reactionRoll')
|
? game.i18n.localize('DAGGERHEART.GENERAL.reactionRoll')
|
||||||
: game.i18n.format('DAGGERHEART.UI.Chat.dualityRoll.abilityCheckTitle', {
|
: game.i18n.format('DAGGERHEART.UI.Chat.dualityRoll.abilityCheckTitle', {
|
||||||
ability: game.i18n.localize(abilities[this.save.trait]?.label)
|
ability: game.i18n.localize(abilities[this.save.trait]?.label)
|
||||||
});
|
});
|
||||||
return actor.diceRoll({
|
return actor.diceRoll({
|
||||||
event,
|
event,
|
||||||
title,
|
title,
|
||||||
|
|
@ -329,7 +328,7 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
|
||||||
}
|
}
|
||||||
|
|
||||||
updateSaveMessage(result, message, targetId) {
|
updateSaveMessage(result, message, targetId) {
|
||||||
if(!result) return;
|
if (!result) return;
|
||||||
const updateMsg = this.updateChatMessage.bind(this, message, targetId, {
|
const updateMsg = this.updateChatMessage.bind(this, message, targetId, {
|
||||||
result: result.roll.total,
|
result: result.roll.total,
|
||||||
success: result.roll.success
|
success: result.roll.success
|
||||||
|
|
@ -352,16 +351,16 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
|
||||||
async updateChatMessage(message, targetId, changes, chain = true) {
|
async updateChatMessage(message, targetId, changes, chain = true) {
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
const chatMessage = ui.chat.collection.get(message._id),
|
const chatMessage = ui.chat.collection.get(message._id),
|
||||||
msgTarget = chatMessage.system.targets.find(mt => mt.id === targetId) ?? chatMessage.system.oldTargets.find(mt => mt.id === targetId);
|
msgTarget =
|
||||||
|
chatMessage.system.targets.find(mt => mt.id === targetId) ??
|
||||||
|
chatMessage.system.oldTargets.find(mt => mt.id === targetId);
|
||||||
msgTarget.saved = changes;
|
msgTarget.saved = changes;
|
||||||
await chatMessage.update(
|
await chatMessage.update({
|
||||||
{
|
system: {
|
||||||
system: {
|
targets: chatMessage.system.targets,
|
||||||
targets: chatMessage.system.targets,
|
oldTargets: chatMessage.system.oldTargets
|
||||||
oldTargets: chatMessage.system.oldTargets
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
}, 100);
|
}, 100);
|
||||||
if (chain) {
|
if (chain) {
|
||||||
if (message.system.source.message)
|
if (message.system.source.message)
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,17 @@ export default class DhActiveEffect extends foundry.documents.ActiveEffect {
|
||||||
|
|
||||||
/**@inheritdoc*/
|
/**@inheritdoc*/
|
||||||
static applyField(model, change, field) {
|
static applyField(model, change, field) {
|
||||||
const evalValue = this.effectSafeEval(itemAbleRollParse(change.value, model, change.effect.parent));
|
const isOriginTarget = change.value.toLowerCase().includes('origin.@');
|
||||||
|
let parseModel = model;
|
||||||
|
if (isOriginTarget && change.effect.origin) {
|
||||||
|
change.value = change.value.replaceAll(/origin\.@/gi, '@');
|
||||||
|
try {
|
||||||
|
const doc = foundry.utils.fromUuidSync(change.effect.origin);
|
||||||
|
if (doc) parseModel = doc;
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
const evalValue = this.effectSafeEval(itemAbleRollParse(change.value, parseModel, change.effect.parent));
|
||||||
change.value = evalValue ?? change.value;
|
change.value = evalValue ?? change.value;
|
||||||
super.applyField(model, change, field);
|
super.applyField(model, change, field);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,6 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
|
||||||
getTargetList() {
|
getTargetList() {
|
||||||
const targets = this.system.hitTargets;
|
const targets = this.system.hitTargets;
|
||||||
return targets.map(target => game.canvas.tokens.documentCollection.find(t => t.actor.uuid === target.actorId));
|
return targets.map(target => game.canvas.tokens.documentCollection.find(t => t.actor.uuid === target.actorId));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async onDamage(event) {
|
async onDamage(event) {
|
||||||
|
|
@ -77,7 +76,7 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
|
||||||
const targets = this.getTargetList();
|
const targets = this.getTargetList();
|
||||||
|
|
||||||
if (this.system.onSave) {
|
if (this.system.onSave) {
|
||||||
const pendingingSaves = this.system.hitTargets.filter(t => t.saved.success === null);
|
const pendingingSaves = this.system.hitTargets.filter(t => t.saved.success === null);
|
||||||
if (pendingingSaves.length) {
|
if (pendingingSaves.length) {
|
||||||
const confirm = await foundry.applications.api.DialogV2.confirm({
|
const confirm = await foundry.applications.api.DialogV2.confirm({
|
||||||
window: { title: 'Pending Reaction Rolls found' },
|
window: { title: 'Pending Reaction Rolls found' },
|
||||||
|
|
@ -112,6 +111,17 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getAction(actor, itemId, actionId) {
|
||||||
|
const item = actor.items.get(itemId),
|
||||||
|
action =
|
||||||
|
actor.system.attack?._id === actionId
|
||||||
|
? actor.system.attack
|
||||||
|
: item.system.attack?._id === actionId
|
||||||
|
? item.system.attack
|
||||||
|
: item?.system?.actions?.get(actionId);
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
|
||||||
async onApplyEffect(event) {
|
async onApplyEffect(event) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
const actor = await foundry.utils.fromUuid(this.system.source.actor);
|
const actor = await foundry.utils.fromUuid(this.system.source.actor);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue