From 165c8c81c79edcc86cd5214d2d02857147de8180 Mon Sep 17 00:00:00 2001 From: Vlyan Date: Fri, 11 Feb 2022 11:28:21 +0100 Subject: [PATCH] added token target id --- CHANGELOG.md | 2 +- system/scripts/dice/dice-picker-dialog.js | 28 +++++++++++++++-------- system/scripts/dice/roll.js | 2 ++ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21b1cde..5e3db06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog ## 1.7.0 - DiceRoller for Techniques & Npc Generator -- NPC Sheet : Added generator feature (demeanor, clan and families names courteously authorized by Edge). +- NPC Sheet : Added random generator feature (demeanor, clan and families names courteously authorized by Edge). - PC/NPC sheet: - Added the ability to techniques, with a skill set, to open the DicePicker with presets values. - Some can interact with targets, but do the default difficulty if none. diff --git a/system/scripts/dice/dice-picker-dialog.js b/system/scripts/dice/dice-picker-dialog.js index 4fc6431..10a4278 100644 --- a/system/scripts/dice/dice-picker-dialog.js +++ b/system/scripts/dice/dice-picker-dialog.js @@ -41,6 +41,7 @@ export class DicePickerDialog extends FormApplication { value: 2, hidden: false, addVoidPoint: false, + targetTokenId: null, }, useVoidPoint: false, isInitiativeRoll: false, @@ -528,6 +529,7 @@ export class DicePickerDialog extends FormApplication { roll.l5r5e.difficultyHidden = this.object.difficulty.hidden; roll.l5r5e.voidPointUsed = this.object.useVoidPoint; roll.l5r5e.skillAssistance = this.object.skill.assistance; + roll.l5r5e.targetTokenId = this.object.difficulty.targetTokenId; await roll.roll(); message = await roll.toMessage(); @@ -611,21 +613,21 @@ export class DicePickerDialog extends FormApplication { } /** - * Return the actor who have the min/max value for this property + * Return the token actor who have the min/max value for this property * @param {string} property Property name (vigilance, strife.value) * @param {boolean|null} isMin Null: single target, Min/Max: get the actor who have the max value - * @return {ActorL5r5e|null} + * @return {TokenDocument|null} * @private */ - static _getTargetActorFromSelection(property, isMin = null) { + static _getTargetTokenFromSelection(property, isMin = null) { if (game.user.targets.size < 1) { return null; } - let targetActor; + let targetToken; if (isMin === null) { // only one target, get the first element - targetActor = Array.from(game.user.targets).values().next()?.value.document.actor; + targetToken = Array.from(game.user.targets).values().next()?.value.document.actor; } else { // Group (Min/Max) const targetGrp = Array.from(game.user.targets).reduce( @@ -642,16 +644,16 @@ export class DicePickerDialog extends FormApplication { } if ((isMin && value < acc.value) || (!isMin && value > acc.value)) { - acc.actor = targetActor; + acc.actor = tgt.document; acc.value = value; } return acc; }, { actor: null, value: 0 } ); - targetActor = targetGrp.actor; + targetToken = targetGrp.actor; } - return targetActor; + return targetToken; } /** @@ -686,15 +688,20 @@ export class DicePickerDialog extends FormApplication { } // Define which actor is needed for the difficulty - let targetActor; + let targetActor = null; + let targetTokenId = null; if (infos[1] === "S") { targetActor = this._actor; } else if (game.user.targets.size > 0) { // Between the targets - targetActor = DicePickerDialog._getTargetActorFromSelection( + const targetToken = DicePickerDialog._getTargetTokenFromSelection( infos[4] || infos[2], !infos[3] ? null : infos[3] === "min" ); + if (targetToken) { + targetActor = targetToken.actor; + targetTokenId = targetToken.data._id; + } } // Wrong syntax or no target set, do manual TN if (!targetActor) { @@ -713,6 +720,7 @@ export class DicePickerDialog extends FormApplication { if (infos[1] === "T") { this.difficultyHidden = true; this._difficultyHiddenIsLock.option = true; + this.object.difficulty.targetTokenId = targetTokenId; } } diff --git a/system/scripts/dice/roll.js b/system/scripts/dice/roll.js index 5aa75e3..1c89c55 100644 --- a/system/scripts/dice/roll.js +++ b/system/scripts/dice/roll.js @@ -13,6 +13,7 @@ export class RollL5r5e extends Roll { skillId: "", skillCatId: "", actor: null, + targetTokenId: null, difficulty: 2, difficultyHidden: false, voidPointUsed: false, @@ -250,6 +251,7 @@ export class RollL5r5e extends Roll { if (!this._evaluated) { await this.roll(); } + console.log(this.l5r5e); // Define chat data const chatData = {