Affichage de la cible dans la fenêtre d'attaque
This commit is contained in:
		| @@ -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; | ||||
|       } | ||||
|   | ||||
| @@ -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"], | ||||
|   | ||||
| @@ -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
									
								
							
							
						
						
									
										56
									
								
								module/targets.js
									
									
									
									
									
										Normal 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; | ||||
|     } | ||||
|   } | ||||
|  | ||||
| } | ||||
| @@ -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égats:</label><label class="dmg-arme-actor"></label> | ||||
|           {{else if (eq arme.system.mortalite 'empoignade')}} | ||||
|           <label>Dégats:</label><label>Empoignade</label> | ||||
|           {{else}} | ||||
|           <label>Dé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> | ||||
| @@ -61,7 +65,7 @@ | ||||
|       {{>"systems/foundryvtt-reve-de-dragon/templates/partial-roll-surenc.html"}} | ||||
|       {{>"systems/foundryvtt-reve-de-dragon/templates/partial-roll-enctotal.html"}} | ||||
|     </div> | ||||
|      | ||||
|  | ||||
|     <div class="flex-group-left"> | ||||
|       {{#if attackerRoll}} | ||||
|       {{>"systems/foundryvtt-reve-de-dragon/templates/partial-roll-diffFixe.html"}} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user