Affichage de la cible dans la fenêtre d'attaque

This commit is contained in:
Vincent Vandemeulebrouck 2022-11-23 21:42:39 +01:00
parent 81aaf9e8d7
commit 7698147e97
5 changed files with 89 additions and 73 deletions

View File

@ -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: `<p>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;
}

View File

@ -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"],

View File

@ -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 <strong>une seule</strong>) à 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: {}
};

56
module/targets.js Normal file
View File

@ -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 <strong>une seule</strong>) à attaquer!");
return;
}
}
}

View File

@ -9,12 +9,12 @@
{{>"systems/foundryvtt-reve-de-dragon/templates/partial-select-carac.html"}}
</div>
{{#if arme}}
{{#if attackerRoll}}
{{#if attackerRoll.tactique}}
<div class="flexrow">
<label>Tactique: </label><label>{{attackerRoll.tactique}}</label>
</div>
{{/if}}
{{#if attackerRoll}}
{{#if attackerRoll.tactique}}
<div class="flexrow">
<label>Tactique: </label><label>{{attackerRoll.tactique}}</label>
</div>
{{/if}}
{{else}}
<div class="flexrow">
<label>Tactique:</label>
@ -32,23 +32,27 @@
</div>
</span>
</div>
{{/if}}
{{#if ajustements.attaqueDefenseurSurpris.used}}
<div class="flexrow">
<label id="defenseur-surprise">{{ajustements.attaqueDefenseurSurpris.label}}</label>
</div>
{{/if}}
{{/if}}
{{/if}}
{{#if targetToken}}
<div class="flexrow">
Cible: {{targetToken.name}}
<img class="sheet-competence-img" src="{{targetToken.img}}" title="{{targetToken.name}}" />
</div>
{{/if}}
{{#if ajustements.attaqueDefenseurSurpris.used}}
<div class="flexrow">
<label id="defenseur-surprise">{{ajustements.attaqueDefenseurSurpris.label}}</label>
</div>
{{/if}}
{{#if arme}}
{{#unless attackerRoll}}
<div class="flexrow">
{{#if (eq arme.system.mortalite 'non-mortel')}}
<label>D&eacute;gats:</label><label class="dmg-arme-actor"></label>
{{else if (eq arme.system.mortalite 'empoignade')}}
<label>D&eacute;gats:</label><label>Empoignade</label>
{{else}}
<label>D&eacute;gats:</label>
{{#if (eq arme.system.mortalite 'non-mortel')}}
<label class="dmg-arme-actor"></label>
{{else if (eq arme.system.mortalite 'empoignade')}}
<label>Empoignade</label>
{{else}}
<span>
<input class="attribute-value" type="checkbox" name="coupsNonMortels" {{#unless (eq mortalite 'mortel')}}checked{{/unless}} />
<label class="dmg-arme-actor"></label>