Gestion des signes draconiques #455
@ -194,7 +194,7 @@ export class RdDActor extends Actor {
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
isHautRevant() {
|
||||
return Misc.templateData(this).attributs.hautrevant.value != ""
|
||||
return this.isPersonnage() && Misc.templateData(this).attributs.hautrevant.value != ""
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getFatigueActuelle() {
|
||||
@ -1089,11 +1089,17 @@ export class RdDActor extends Actor {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
computeIsHautRevant() {
|
||||
const tplData = Misc.templateData(this);
|
||||
tplData.attributs.hautrevant.value = this.listItemsData('tete').find(it => Grammar.toLowerCaseNoAccent(it.name) == 'don de haut-reve')
|
||||
if (this.isPersonnage()){
|
||||
Misc.templateData(this).attributs.hautrevant.value = this.hasItemNamed('tete', 'don de haut-reve')
|
||||
? "Haut rêvant"
|
||||
: "";
|
||||
}
|
||||
}
|
||||
|
||||
hasItemNamed(type, name) {
|
||||
name = Grammar.toLowerCaseNoAccent(name);
|
||||
return this.listItemsData(type).find(it => Grammar.toLowerCaseNoAccent(it.name) == name);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async computeEncombrementTotalEtMalusArmure() {
|
||||
|
114
module/dialog-create-signedraconique-actors.js
Normal file
114
module/dialog-create-signedraconique-actors.js
Normal file
@ -0,0 +1,114 @@
|
||||
import { ChatUtility } from "./chat-utility.js";
|
||||
import { HtmlUtility } from "./html-utility.js";
|
||||
import { RdDItemSigneDraconique } from "./item-signedraconique.js";
|
||||
import { Misc } from "./misc.js";
|
||||
import { TMRType, TMRUtility } from "./tmr-utility.js";
|
||||
|
||||
export class DialogCreateSigneDraconiqueForActors extends Dialog {
|
||||
|
||||
static async createSigneForActors() {
|
||||
let dialogData = {
|
||||
signe: {
|
||||
name: 'Un signe draconique',
|
||||
type: "signedraconique",
|
||||
img: 'systems/foundryvtt-reve-de-dragon/icons/tmr/gift.webp',
|
||||
data: {
|
||||
typesTMR: DialogCreateSigneDraconiqueForActors.selectRandomTmrs(),
|
||||
ephemere: true,
|
||||
duree: "1 round",
|
||||
difficulte: -5,
|
||||
valeur: { norm: 10, sign: 10, part: 15 },
|
||||
}
|
||||
},
|
||||
actors: game.actors.filter(actor => actor.isHautRevant()).map(it => duplicate(Misc.data(it)))
|
||||
};
|
||||
dialogData.tmrs = TMRUtility.listSelectedTMR(dialogData.signe.data.typesTMR ?? []);
|
||||
dialogData.actors.forEach(it => it.selected = false);
|
||||
|
||||
const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/dialog-create-signedraconique-actors.html", dialogData);
|
||||
new DialogCreateSigneDraconiqueForActors(dialogData, html)
|
||||
.render(true);
|
||||
|
||||
}
|
||||
|
||||
static selectRandomTmrs() {
|
||||
let tmrs = Object.values(TMRType).map(value => Misc.upperFirst(value.name));
|
||||
const nbTmr = tmrs.length;
|
||||
let remove = Math.floor(Math.random() * (nbTmr - 1));
|
||||
for (let i = nbTmr; i > remove; i--) {
|
||||
tmrs.splice(Math.floor(Math.random() * i), 1);
|
||||
}
|
||||
return tmrs;
|
||||
}
|
||||
|
||||
constructor(dialogData, html, callback) {
|
||||
let options = { classes: ["DialogCreateSigneDraconiqueActorsActors"], width: 500, height: 650, 'z-index': 99999 };
|
||||
|
||||
let conf = {
|
||||
title: "Créer un signe pour les personnages",
|
||||
content: html,
|
||||
default: "Créer le signe",
|
||||
buttons: { "Créer le signe": { label: "Créer le signe", callback: it => { this._onCreerSigne(); } } }
|
||||
};
|
||||
super(conf, options);
|
||||
this.dialogData = dialogData;
|
||||
}
|
||||
|
||||
async _onCreerSigne() {
|
||||
this.dialogData.actors.filter(it => it.selected).map(it => game.actors.get(it._id))
|
||||
.forEach(actor => this._createSigneForActor(actor, this.dialogData.signe));
|
||||
}
|
||||
|
||||
async _createSigneForActor(actor, signe) {
|
||||
actor.createEmbeddedDocuments("Item", [signe]);
|
||||
ChatMessage.create({
|
||||
whisper: ChatUtility.getWhisperRecipientsAndGMs(Misc.data(actor).name),
|
||||
content: await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/chat-signe-draconique-actor.html", {
|
||||
signe: signe,
|
||||
alias: Misc.data(actor).name
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
this.setEphemere(this.dialogData.signe.data.ephemere);
|
||||
html.find(".signe-name").change((event) => this.dialogData.signe.name = event.currentTarget.value);
|
||||
html.find(".signe-data-ephemere").change((event) => this.setEphemere(event.currentTarget.checked));
|
||||
html.find(".select-tmr").change((event) => this.onSelectTmr(event));
|
||||
html.find(".select-actor").change((event) => this.onSelectActor(event));
|
||||
html.find(".valeur-xp-sort").change((event) => this.onValeurXpSort(event));
|
||||
}
|
||||
async setEphemere(ephemere){
|
||||
this.dialogData.signe.data.ephemere = ephemere;
|
||||
HtmlUtility._showControlWhen($(".signe-data-duree"), ephemere);
|
||||
}
|
||||
|
||||
async onSelectTmr(event) {
|
||||
event.preventDefault();
|
||||
this.dialogData.signe.data.typesTMR = $(".select-tmr").val();
|
||||
}
|
||||
|
||||
async onSelectActor(event) {
|
||||
event.preventDefault();
|
||||
let selectActor = $(".select-actor");
|
||||
const options = event.currentTarget.options;
|
||||
for (var i = 0; i < options.length; i++) { // looping over the options
|
||||
const actorId = options[i].attributes["data-actor-id"].value;
|
||||
const actor = this.dialogData.actors.find(it => it._id == actorId);
|
||||
if (actor) {
|
||||
actor.selected = options[i].selected;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
onValeurXpSort(event) {
|
||||
const codeReussite = event.currentTarget.attributes['data-typereussite']?.value ?? 0;
|
||||
const xp = Number(event.currentTarget.value);
|
||||
const oldValeur = this.dialogData.signe.data.valeur;
|
||||
this.dialogData.signe.data.valeur = RdDItemSigneDraconique.calculValeursXpSort(codeReussite, xp, oldValeur);
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
import { RdDItemSigneDraconique } from "./item-signedraconique.js";
|
||||
import { Misc } from "./misc.js";
|
||||
import { TMRType } from "./tmr-utility.js";
|
||||
import { TMRType, TMRUtility } from "./tmr-utility.js";
|
||||
|
||||
/**
|
||||
* Item sheet pour signes draconiques
|
||||
@ -48,16 +49,10 @@ export class RdDSigneDraconiqueItemSheet extends ItemSheet {
|
||||
editable: this.isEditable,
|
||||
cssClass: this.isEditable ? "editable" : "locked",
|
||||
});
|
||||
formData.tmrs = RdDSigneDraconiqueItemSheet.listTMRTypes(formData.data.typesTMR ?? []);
|
||||
formData.tmrs = TMRUtility.listSelectedTMR(formData.data.typesTMR ?? []);
|
||||
return formData;
|
||||
}
|
||||
|
||||
static listTMRTypes(typesTMR) {
|
||||
return Object.values(TMRType).map(value => Misc.upperFirst(value.name))
|
||||
.sort()
|
||||
.map(name => { return { name: name, selected: typesTMR.includes(name) } });
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
activateListeners(html) {
|
||||
@ -75,28 +70,12 @@ export class RdDSigneDraconiqueItemSheet extends ItemSheet {
|
||||
this.object.update({ 'data.typesTMR': selectedTMR });
|
||||
}
|
||||
|
||||
async onValeurXpSort(qualite, valeur) {
|
||||
let tplData = Misc.templateData(this.object);
|
||||
if (valeur != tplData.valeur[qualite])
|
||||
{
|
||||
await this.object.update({ [`data.valeur.${qualite}`]: valeur });
|
||||
|
||||
tplData = Misc.templateData(this.object);
|
||||
switch (qualite) {
|
||||
case "norm":
|
||||
if (valeur > tplData.valeur.sign) await this.object.update({ 'data.valeur.sign': valeur });
|
||||
if (valeur > tplData.valeur.part) await this.object.update({ 'data.valeur.part': valeur });
|
||||
break;
|
||||
case "sign":
|
||||
if (valeur < tplData.valeur.norm) await this.object.update({ 'data.valeur.norm': valeur });
|
||||
if (valeur > tplData.valeur.part) await this.object.update({ 'data.valeur.part': valeur });
|
||||
break;
|
||||
case "part":
|
||||
if (valeur < tplData.valeur.norm) await this.object.update({ 'data.valeur.norm': valeur });
|
||||
if (valeur < tplData.valeur.sign) await this.object.update({ 'data.valeur.sign': valeur });
|
||||
break;
|
||||
}
|
||||
}
|
||||
async onValeurXpSort(event) {
|
||||
const codeReussite = event.currentTarget.attributes['data-typereussite']?.value ?? 0;
|
||||
const xp = Number(event.currentTarget.value);
|
||||
const oldValeur = Misc.templateData(this.object).valeur;
|
||||
const newValeur = RdDItemSigneDraconique.calculValeursXpSort(codeReussite, xp, oldValeur);
|
||||
await this.object.update({ 'data.valeur': newValeur });
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
@ -34,4 +34,27 @@ export class RdDItemSigneDraconique {
|
||||
return Misc.data(signe).data.valeur[code] ?? 0;
|
||||
}
|
||||
|
||||
static calculValeursXpSort(qualite, valeur, avant) {
|
||||
switch (qualite) {
|
||||
case "norm":
|
||||
return {
|
||||
norm: valeur,
|
||||
sign: Math.max(valeur, avant.sign),
|
||||
part: Math.max(valeur, avant.part)
|
||||
}
|
||||
case "sign":
|
||||
return {
|
||||
norm: Math.min(valeur, avant.norm),
|
||||
sign: valeur,
|
||||
part: Math.max(valeur, avant.part)
|
||||
}
|
||||
case "part":
|
||||
return {
|
||||
norm: Math.min(valeur, avant.norm),
|
||||
sign: Math.min(valeur, avant.sign),
|
||||
part: valeur
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
/* -------------------------------------------- */
|
||||
|
||||
import { DialogCreateSigneDraconiqueForActors } from "./dialog-create-signedraconique-actors.js";
|
||||
import { RdDItemCompetence } from "./item-competence.js";
|
||||
import { Misc } from "./misc.js";
|
||||
import { RdDCarac } from "./rdd-carac.js";
|
||||
@ -82,6 +83,17 @@ export class RdDCommands {
|
||||
descr: `Affiche les heures de chance et de malchance selon l'heure de naissance donnée en argument. Exemples:
|
||||
<br><strong>/astro Lyre</strong>`
|
||||
});
|
||||
|
||||
rddCommands.registerCommand({
|
||||
path: ["/signe", "+"], func: (content, msg, params) => rddCommands.creerSignesDraconiques(),
|
||||
descr: "Crée un signe draconique et l'ajoute aux haut-rêvants choisis."
|
||||
});
|
||||
|
||||
rddCommands.registerCommand({
|
||||
path: ["/signe", "-"], func: (content, msg, params) => rddCommands.supprimerSignesDraconiquesEphemeres(),
|
||||
descr: "Supprime les signes draconiques éphémères"
|
||||
});
|
||||
|
||||
game.system.rdd.commands = rddCommands;
|
||||
}
|
||||
}
|
||||
@ -312,5 +324,20 @@ export class RdDCommands {
|
||||
}
|
||||
}
|
||||
|
||||
async creerSignesDraconiques() {
|
||||
DialogCreateSigneDraconiqueForActors.createSigneForActors();
|
||||
return true;
|
||||
}
|
||||
|
||||
async supprimerSignesDraconiquesEphemeres() {
|
||||
game.actors.forEach(actor => {
|
||||
const ephemeres = actor.filterItems(item => Misc.data(item).type = 'signedraconique' && Misc.data(item).data.ephemere)
|
||||
.map(item => item.id);
|
||||
if (ephemeres.length > 0) {
|
||||
actor.deleteEmbeddedDocuments("Item", ephemeres);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -205,7 +205,8 @@ export class RdDUtility {
|
||||
'systems/foundryvtt-reve-de-dragon/templates/chat-actor-competence-xp.html',
|
||||
'systems/foundryvtt-reve-de-dragon/templates/chat-actor-carac-xp.html',
|
||||
'systems/foundryvtt-reve-de-dragon/templates/chat-potionenchantee-chateaudormant.html',
|
||||
'systems/foundryvtt-reve-de-dragon/templates/chat-fabriquer-potion-base.html'
|
||||
'systems/foundryvtt-reve-de-dragon/templates/chat-fabriquer-potion-base.html',
|
||||
'systems/foundryvtt-reve-de-dragon/templates/chat-signe-draconique-actor.html'
|
||||
];
|
||||
|
||||
Handlebars.registerHelper('upperFirst', str => Misc.upperFirst(str ?? 'Null'));
|
||||
|
@ -346,6 +346,12 @@ export class TMRUtility {
|
||||
return Grammar.articleDetermine(tmr.type) + ' ' + tmr.label;
|
||||
}
|
||||
|
||||
static listSelectedTMR(typesTMR) {
|
||||
return Object.values(TMRType).map(value => Misc.upperFirst(value.name))
|
||||
.sort()
|
||||
.map(name => { return { name: name, selected: typesTMR.includes(name) } });
|
||||
}
|
||||
|
||||
static isCaseHumide(tmr) {
|
||||
return tmr.type == 'fleuve' || tmr.type == 'lac' || tmr.type == 'marais';
|
||||
}
|
||||
|
7
templates/chat-signe-draconique-actor.html
Normal file
7
templates/chat-signe-draconique-actor.html
Normal file
@ -0,0 +1,7 @@
|
||||
<h4><img class="chat-icon" src="{{signe.img}}" alt="{{signe.name}}" />
|
||||
{{alias}} perçoit {{signe.name}}
|
||||
</h4>
|
||||
<p>Pour le lire ce signe draconique, rendez-vous dans les
|
||||
Terres Médianes du Rêve et trouvez une case de résonnance.
|
||||
{{#if signe.data.ephemere}}C'est un signe éphémère, qui ne restera présent que pour {{signe.data.duree}}{{/if}}
|
||||
</p>
|
57
templates/dialog-create-signedraconique-actors.html
Normal file
57
templates/dialog-create-signedraconique-actors.html
Normal file
@ -0,0 +1,57 @@
|
||||
<form class="skill-roll-dialog">
|
||||
<div>
|
||||
<h4>Un signe draconique éphémère se manifeste:
|
||||
<br><input class="signe-name" type="text" name="signe.name" value="{{signe.name}}" data-dtype="String" />
|
||||
</h4>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="actors">Personnages concernés</label>
|
||||
<select class="select-actor attribute-value" name="actors" id="actors" size="7" multiple>
|
||||
{{#each actors as |actor key|}}
|
||||
<option value="{{actor.name}}" data-actor-id="{{actor._id}}" {{#if actor.selected}}selected{{/if}}>
|
||||
<img class="chat-icon" src="{{actor.img}}" title="{{actor.name}}" alt="{{actor.name}}" />
|
||||
{{actor.name}}
|
||||
</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label for="signe.data.difficulte">Difficulte</label>
|
||||
<input class="attribute-value" type="number" name="signe.data.difficulte" value="{{signe.data.difficulte}}" data-dtype="Number" />
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="signe.data.valeur.norm">Expérience en sorts</label>
|
||||
<div class="flexrow">
|
||||
<input class="valeur-xp-sort" type="number" name="signe.data.valeur.norm" data-typereussite="norm"
|
||||
value="{{signe.data.valeur.norm}}" min="1" max="100" data-dtype="Number" />
|
||||
<span>Sign.</span>
|
||||
<input class="valeur-xp-sort" type="number" name="signe.data.valeur.sign" data-typereussite="sign"
|
||||
value="{{signe.data.valeur.sign}}" min="1" max="100" data-dtype="Number" />
|
||||
<span>Part.</span>
|
||||
<input class="valeur-xp-sort" type="number" name="signe.data.valeur.part" data-typereussite="part"
|
||||
value="{{signe.data.valeur.part}}" min="1" max="100" data-dtype="Number" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<span>
|
||||
<label for="signe.data.ephemere">Ephémère</label>
|
||||
<input class="attribute-value signe-data-ephemere" type="checkbox" name="signe.data.ephemere" {{#if signe.data.ephemere}}checked{{/if}} />
|
||||
</span>
|
||||
<span>
|
||||
<input class="signe-data-duree attribute-value" type="text" name="signe.data.duree" value="{{signe.data.duree}}" data-dtype="String" />
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="tmrs">Terres médianes</label>
|
||||
<select class="select-tmr attribute-value" name="tmrs" id="tmrs" size="{{tmrs.length}}" multiple>
|
||||
{{#each tmrs as |tmr key|}}
|
||||
<option value="{{tmr.name}}" {{#if tmr.selected}}selected{{/if}}>{{tmr.name}}</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
</form>
|
@ -29,15 +29,15 @@
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="xp">Difficulté</label>
|
||||
<input class="attribute-value" type="text" name="data.difficulte" value="{{data.difficulte}}" data-dtype="Number"/>
|
||||
<input class="attribute-value" type="number" name="data.difficulte" value="{{data.difficulte}}" data-dtype="Number"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="xp">Points de tâches</label>
|
||||
<input class="attribute-value" type="text" name="data.points_de_tache" value="{{data.points_de_tache}}" data-dtype="Number"/>
|
||||
<input class="attribute-value" type="number" name="data.points_de_tache" value="{{data.points_de_tache}}" data-dtype="Number"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="xp">Expérience</label>
|
||||
<input class="attribute-value" type="text" name="data.xp" value="{{data.xp}}" data-dtype="String"/>
|
||||
<input class="attribute-value" type="number" name="data.xp" value="{{data.xp}}" data-dtype="Number"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="xp">Niveau minimum</label>
|
||||
@ -49,15 +49,15 @@
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="xp">Encombrement </label>
|
||||
<input class="attribute-value" type="text" name="data.encombrement" value="{{data.encombrement}}" data-dtype="Number"/>
|
||||
<input class="attribute-value" type="number" name="data.encombrement" value="{{data.encombrement}}" data-dtype="Number"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Quantité </label>
|
||||
<input class="attribute-value" type="text" name="data.quantite" value="{{data.quantite}}" data-dtype="Number" />
|
||||
<input class="attribute-value" type="number" name="data.quantite" value="{{data.quantite}}" data-dtype="Number" />
|
||||
</div>
|
||||
<div class="form-group item-cout">
|
||||
<label for="xp">Prix (sols) </label>
|
||||
<input class="attribute-value" type="text" name="data.cout" value="{{data.cout}}" data-dtype="Number"/>
|
||||
<input class="attribute-value" type="number" name="data.cout" value="{{data.cout}}" data-dtype="Number"/>
|
||||
</div>
|
||||
<div class="flexcol">
|
||||
<span><label>Description : </label></span>
|
||||
|
@ -8,6 +8,24 @@
|
||||
|
||||
{{!-- Sheet Body --}}
|
||||
<section class="sheet-body">
|
||||
<div class="form-group">
|
||||
<label for="data.difficulte">Difficulte</label>
|
||||
<input class="attribute-value" type="number" name="data.difficulte" value="{{data.difficulte}}"
|
||||
data-dtype="Number" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="data.valeur.norm">Expérience en sorts</label>
|
||||
<div class="flexrow">
|
||||
<input class="valeur-xp-sort" type="number" name="data.valeur.norm" data-typereussite="norm"
|
||||
value="{{data.valeur.norm}}" min="1" max="100" data-dtype="Number" />
|
||||
<span>Sign.</span>
|
||||
<input class="valeur-xp-sort" type="number" name="data.valeur.sign" data-typereussite="sign"
|
||||
value="{{data.valeur.sign}}" min="1" max="100" data-dtype="Number" />
|
||||
<span>Part.</span>
|
||||
<input class="valeur-xp-sort" type="number" name="data.valeur.part" data-typereussite="part"
|
||||
value="{{data.valeur.part}}" min="1" max="100" data-dtype="Number" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="data.ephemere">Ephémère</label>
|
||||
<input class="attribute-value" type="checkbox" name="data.ephemere" {{#if data.ephemere}}checked{{/if}} />
|
||||
@ -18,24 +36,6 @@
|
||||
<input class="attribute-value" type="text" name="data.duree" value="{{data.duree}}" data-dtype="String" />
|
||||
</div>
|
||||
{{/if}}
|
||||
<div class="form-group">
|
||||
<label for="data.difficulte">Difficulte</label>
|
||||
<input class="attribute-value" type="text" name="data.difficulte" value="{{data.difficulte}}"
|
||||
data-dtype="Number" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="data.valeur.norm">Expérience en sorts</label>
|
||||
<div class="flexrow">
|
||||
<input class="valeur-xp-sort" type="number" name="data.valeur.norm" data-typereussite="norm" value="{{data.valeur.norm}}"
|
||||
min="1" max="100" data-dtype="Number" />
|
||||
<span>Sign.</span>
|
||||
<input class="valeur-xp-sort" type="number" name="data.valeur.sign" data-typereussite="sign" value="{{data.valeur.sign}}"
|
||||
min="1" max="100" data-dtype="Number" />
|
||||
<span>Part.</span>
|
||||
<input class="valeur-xp-sort" type="number" name="data.valeur.part" data-typereussite="part" value="{{data.valeur.part}}"
|
||||
min="1" max="100" data-dtype="Number" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="tmrs">Terres médianes</label>
|
||||
<select class="select-tmr attribute-value" name="tmrs" id="tmrs" size={{tmrs.length}} multiple />
|
||||
|
Loading…
Reference in New Issue
Block a user