diff --git a/module/actor.js b/module/actor.js index 0a3b5c28..8e813305 100644 --- a/module/actor.js +++ b/module/actor.js @@ -35,7 +35,7 @@ import { ENTITE_BLURETTE, ENTITE_INCARNE, ENTITE_NONINCARNE, HIDE_DICE, SHOW_DIC import { RdDConfirm } from "./rdd-confirm.js"; import { DialogValidationEncaissement } from "./dialog-validation-encaissement.js"; import { RdDRencontre } from "./item-rencontre.js"; -import { DialogSelectTarget } from "./dialog-select-target.js"; +import { Targets } from "./targets.js"; const POSSESSION_SANS_DRACONIC = { img: 'systems/foundryvtt-reve-de-dragon/icons/entites/possession.webp', @@ -2552,8 +2552,8 @@ export class RdDActor extends Actor { competence: this.getCompetence(idOrName) } if (rollData.competence.type == 'competencecreature') { - if (rollData.competence.system.iscombat && options.tryTarget && DialogSelectTarget.hasTargets()) { - DialogSelectTarget.selectOneToken(target => { + if (rollData.competence.system.iscombat && options.tryTarget && Targets.hasTargets()) { + Targets.selectOneToken(target => { if (rollData.competence.system.ispossession) { RdDPossession.onAttaquePossession(target, this, rollData.competence) } @@ -3222,7 +3222,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ rollArme(arme) { - if (!DialogSelectTarget.hasTargets()) { + if (!Targets.hasTargets()) { RdDConfirm.confirmer({ settingConfirmer: "confirmer-combat-sans-cible", content: `

Voulez vous faire un jet de compétence ${arme.system.competence} sans choisir de cible valide? @@ -3236,8 +3236,8 @@ export class RdDActor extends Actor { }); return; } - DialogSelectTarget.selectOneToken(target => { - if (RdDCombat.isTargetEntite(target)){ + Targets.selectOneToken(target => { + if (Targets.isTargetEntite(target)){ ui.notifications.warn(`Vous ne pouvez pas attaquer une entité non incarnée avec votre ${arme.name}!!!!`); return; } diff --git a/module/dialog-select-target.js b/module/dialog-select-target.js index 9b6b128a..87f504f3 100644 --- a/module/dialog-select-target.js +++ b/module/dialog-select-target.js @@ -1,29 +1,5 @@ export class DialogSelectTarget extends Dialog { - static hasTargets() { - return (game.user.targets?.size ?? 0) > 0; - } - - static async selectOneToken(onSelectTarget = target => { }) { - if (DialogSelectTarget.hasTargets()) { - const targets = game.user.targets.map(it => it); - switch (targets.size) { - case 0: return; - case 1: - onSelectTarget(targets[0]); - return; - default: - { - const tokens = targets.map(it => { return { id: it.id, name: it.document.name, img: it.document.texture.src ?? it.actor.img ?? 'icons/svg/mystery-man.svg' } }) - const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/dialog-select-target.html", { - tokens: tokens - }); - new DialogSelectTarget(html, onSelectTarget, targets).render(true); - } - } - } - } - constructor(html, onSelectTarget, targets) { const options = { classes: ["rdd-dialog-select-target"], diff --git a/module/rdd-combat.js b/module/rdd-combat.js index 9c77347f..587581af 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -12,6 +12,7 @@ import { RdDRoll } from "./rdd-roll.js"; import { RdDRollTables } from "./rdd-rolltables.js"; import { ReglesOptionelles } from "./settings/regles-optionelles.js"; import { STATUSES } from "./settings/status-effects.js"; +import { Targets } from "./targets.js"; /* -------------------------------------------- */ const premierRoundInit = [ @@ -470,28 +471,6 @@ export class RdDCombat { return true; } - /* -------------------------------------------- */ - static getTarget() { - const targets = game.user.targets; - switch (targets?.size ?? 0) { - case 1: - for (let t of targets) { - return t; - } - case 0: - ui.notifications.warn("Vous devez choisir une cible à attaquer!"); - break; - default: - DialogSelectTarget.selectOneToken(t => console.info(`selecte target ${t}`)); - ui.notifications.warn("Vous devez choisir une cible (et une seule) à attaquer!"); - return; - } - } - - static isTargetEntite(target) { - return target?.actor.type == 'entite' && target?.actor.system.definition.typeentite == ENTITE_NONINCARNE; - } - /* -------------------------------------------- */ static rddCombatTarget(target, attacker) { const defender = target?.actor; @@ -506,7 +485,7 @@ export class RdDCombat { let target = undefined if (!defenderTokenId || !defender) { console.warn(`RdDCombat.rddCombatForAttackerAndDefender: appel avec defenderTokenId ${defenderTokenId} incorrect, ou pas de defender correspondant`); - target = RdDCombat.getTarget() + target = Targets.getTarget() if (!target) { return; } @@ -841,6 +820,7 @@ export class RdDCombat { competence: competence, surprise: this.attacker.getSurprise(true), surpriseDefenseur: this.defender.getSurprise(true), + targetToken: Targets.extractTokenData(this.target), essais: {} }; diff --git a/module/targets.js b/module/targets.js new file mode 100644 index 00000000..f975a60d --- /dev/null +++ b/module/targets.js @@ -0,0 +1,56 @@ +import { ENTITE_NONINCARNE } from "./constants.js"; +import { DialogSelectTarget } from "./dialog-select-target.js"; + +export class Targets { + static listTargets() { + return Array.from(game.user.targets); + } + + static hasTargets() { + return Targets.listTargets().length > 0; + } + + static extractTokenData(target) { + if (!target) { + return undefined + } + return { id: target.id, name: target.document.name, img: target.document.texture.src ?? target.actor.img ?? 'icons/svg/mystery-man.svg' }; + } + + static isTargetEntite(target) { + return target?.actor.type == 'entite' && target?.actor.system.definition.typeentite == ENTITE_NONINCARNE; + } + + static async selectOneToken(onSelectTarget = target => { }) { + const targets = Targets.listTargets(); + switch (targets.length) { + case 0: return; + case 1: + onSelectTarget(targets[0]); + return; + default: + { + const tokens = targets.map(it => Targets.extractTokenData(it)) + const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/dialog-select-target.html", { + tokens: tokens + }); + new DialogSelectTarget(html, onSelectTarget, targets).render(true); + } + } + } + + static getTarget() { + const targets = Targets.listTargets(); + switch (targets.length) { + case 1: + return targets[0]; + case 0: + ui.notifications.warn("Vous devez choisir une cible à attaquer!"); + break; + default: + ui.notifications.warn("Vous devez choisir une cible (et une seule) à attaquer!"); + return; + } + } + +} \ No newline at end of file diff --git a/templates/dialog-roll-competence.html b/templates/dialog-roll-competence.html index 110368e1..1df0b15d 100644 --- a/templates/dialog-roll-competence.html +++ b/templates/dialog-roll-competence.html @@ -9,12 +9,12 @@ {{>"systems/foundryvtt-reve-de-dragon/templates/partial-select-carac.html"}} {{#if arme}} - {{#if attackerRoll}} - {{#if attackerRoll.tactique}} -

- -
- {{/if}} + {{#if attackerRoll}} + {{#if attackerRoll.tactique}} +
+ +
+ {{/if}} {{else}}
@@ -32,23 +32,27 @@
- {{/if}} - {{#if ajustements.attaqueDefenseurSurpris.used}} -
- -
- {{/if}} - {{/if}} + {{/if}} + {{#if targetToken}} +
+ Cible: {{targetToken.name}} + +
+ {{/if}} + {{#if ajustements.attaqueDefenseurSurpris.used}} +
+ +
+ {{/if}} - {{#if arme}} {{#unless attackerRoll}}
- {{#if (eq arme.system.mortalite 'non-mortel')}} - - {{else if (eq arme.system.mortalite 'empoignade')}} - - {{else}} + {{#if (eq arme.system.mortalite 'non-mortel')}} + + {{else if (eq arme.system.mortalite 'empoignade')}} + + {{else}} @@ -61,7 +65,7 @@ {{>"systems/foundryvtt-reve-de-dragon/templates/partial-roll-surenc.html"}} {{>"systems/foundryvtt-reve-de-dragon/templates/partial-roll-enctotal.html"}}
- +
{{#if attackerRoll}} {{>"systems/foundryvtt-reve-de-dragon/templates/partial-roll-diffFixe.html"}}