Avancement OwnedItems et Items

- remplacer xxxOwnedItems par xxxEmbeddedDocuments
- corrections des accès aux items vs itemData
- corrections cases spéciales TMR et effets draconiques
- correction monnaies/payer
This commit is contained in:
Vincent Vandemeulebrouck 2021-03-29 23:41:08 +02:00
parent 7f75361a08
commit 0cd4c7c158
29 changed files with 136 additions and 125 deletions

View File

@ -71,14 +71,14 @@ export class RdDActorEntiteSheet extends ActorSheet {
// Update Inventory Item
html.find('.item-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item");
const item = this.actor.getOwnedItem(li.data("itemId"));
const item = this.actor.getEmbeddedDocuments('Item', li.data("itemId"));
item.sheet.render(true);
});
// Delete Inventory Item
html.find('.item-delete').click(ev => {
const li = $(ev.currentTarget).parents(".item");
this.actor.deleteOwnedItem(li.data("itemId"));
this.actor.deleteEmbeddedDocuments('Item', [li.data("itemId")]);
li.slideUp(200, () => this.render(false));
});

View File

@ -87,7 +87,7 @@ export class RdDActorVehiculeSheet extends ActorSheet {
// Update Inventory Item
html.find('.item-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item");
const item = this.actor.getOwnedItem(li.data("itemId"));
const item = this.actor.getEmbeddedDocuments('Item', li.data("itemId"));
item.sheet.render(true);
});
// Delete Inventory Item

View File

@ -39,12 +39,14 @@ export class RdDActor extends Actor {
static init() {
Hooks.on("deleteActiveEffect", (effect, options, userId) => RdDActor.getParentActor(effect)?.onDeleteActiveEffect(effect, options));
Hooks.on("createActiveEffect", (effect, options, userId) => RdDActor.getParentActor(effect)?.onCreateActiveEffect(effect, options));
Hooks.on("createOwnedItem", (item, options, id) => RdDActor.getParentActor(item)?.onCreateOwnedItem(item, options, id));
Hooks.on("deleteOwnedItem", (item, options, id) => RdDActor.getParentActor(item)?.onDeleteOwnedItem(item, options, id));
Hooks.on("preUpdateItem", (item, change, options, id) => RdDActor.getParentActor(item)?.onPreUpdateItem(item, change, options, id));
Hooks.on("createItem", (item, options, id) => RdDActor.getParentActor(item)?.onCreateItem(item, options, id));
Hooks.on("deleteItem", (item, options, id) => RdDActor.getParentActor(item)?.onDeleteItem(item, options, id));
Hooks.on("updateActor", (actor, change, options, actorId) => actor.onUpdateActor(change, options, actorId));
}
static getParentActor(document){
static getParentActor(document) {
return document?.parent instanceof Actor ? document.parent : undefined
}
@ -241,10 +243,10 @@ export class RdDActor extends Actor {
}
/* -------------------------------------------- */
getObjet(id) {
return id ? this.items.find(it => it._id == id) : undefined;
return id ? this.data.items.find(it => it.id == id) : undefined;
}
getItemOfType(type, id) {
return id ? this.items.find(it => it._id == id && it.type == type) : undefined;
getItemOfType(id, type) {
return id ? this.data.items.find(it => it.id == id && it.type == type) : undefined;
}
getMonnaie(id) {
return this.getItemOfType(id, 'monnaie');
@ -266,7 +268,7 @@ export class RdDActor extends Actor {
return this.getItemOfType(id, 'musique');
}
getOeuvre(id, type = 'oeuvre') {
return this.getItemOfType(type, id);
return this.getItemOfType(id, type);
}
getJeu(id) {
return this.getItemOfType(id, 'jeu');
@ -685,7 +687,7 @@ export class RdDActor extends Actor {
else
update['data.carac_value'] = compValue;
//console.log(update);
const updated = await this.updateEmbeddedDocuments("Item", update); // Updates one EmbeddedEntity
const updated = await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
}
}
@ -706,7 +708,7 @@ export class RdDActor extends Actor {
});
}
const update = { _id: comp.id, 'data.niveau': nouveauNiveau };
await this.updateEmbeddedDocuments("Item", update); // Updates one EmbeddedEntity
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
} else {
console.log("Competence not found", compName);
}
@ -719,7 +721,7 @@ export class RdDActor extends Actor {
compValue = compValue ?? 0;
this.checkCompetenceXP(compName, compValue);
const update = { _id: comp.id, 'data.xp': compValue };
await this.updateEmbeddedDocuments("OwnedItem", update); // Updates one EmbeddedEntity
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
} else {
console.log("Competence not found", compName);
}
@ -732,7 +734,7 @@ export class RdDActor extends Actor {
if (comp) {
compValue = compValue ?? 0;
const update = { _id: comp.id, 'data.xp_sort': compValue };
await this.updateEmbeddedDocuments("OwnedItem", update); // Updates one EmbeddedEntity
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
} else {
console.log("Competence not found", compName);
}
@ -744,7 +746,7 @@ export class RdDActor extends Actor {
if (comp) {
compValue = compValue ?? 0;
const update = { _id: comp.id, 'data.niveau_archetype': compValue };
await this.updateEmbeddedDocuments("OwnedItem", update); // Updates one EmbeddedEntity
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
} else {
console.log("Competence not found", compName);
}
@ -860,10 +862,7 @@ export class RdDActor extends Actor {
let list = [];
list.push({ id: itemId, conteneurId: undefined }); // Init list
this.buildSubConteneurObjetList(itemId, list);
//console.log("List to delete", list);
for (let item of list) {
await this.deleteOwnedItem(item.id);
}
await this.deleteEmbeddedDocuments('Item', list.map(it => it.id));
}
/* -------------------------------------------- */
@ -880,7 +879,7 @@ export class RdDActor extends Actor {
contenu.splice(index, 1);
index = contenu.indexOf(itemId);
}
await this.updateEmbeddedDocuments("OwnedItem", data2use);
await this.updateEmbeddedDocuments('Item', [data2use]);
}
}
@ -892,7 +891,7 @@ export class RdDActor extends Actor {
if (conteneur?.type == 'conteneur') {
let data2use = duplicate(Misc.data(conteneur));
data2use.data.contenu.push(itemId);
await this.updateEmbeddedDocuments("OwnedItem", data2use);
await this.updateEmbeddedDocuments('Item', [data2use]);
}
}
@ -907,7 +906,7 @@ export class RdDActor extends Actor {
}
}
if (conteneurFixedList.length > 0)
await this.updateOwnedItem(conteneurFixedList);
await this.updateEmbeddedDocuments('Item', conteneurFixedList);
}
/* -------------------------------------------- */
@ -935,11 +934,11 @@ export class RdDActor extends Actor {
console.log('New conteneur filling!', newConteneur, newItemId, item);
let contenu = duplicate(newConteneur.data.contenu);
contenu.push(newItemId);
await this.updateOwnedItem({ _id: newConteneurId, 'data.contenu': contenu });
await this.updateEmbeddedDocuments('Item', [{ _id: newConteneurId, 'data.contenu': contenu }]);
}
}
for (let item of itemsList) {
await sourceActor.deleteOwnedItem(item.id);
await sourceActor.deleteEmbeddedDocuments('Item', [item.id]);
}
}
@ -1837,7 +1836,7 @@ export class RdDActor extends Actor {
if (rencSpecial) {
rencSpecial = duplicate(rencSpecial); // To keep it
if (rencSpecial.type != 'souffle') {
this.deleteOwnedItem(rencSpecial._id); // Suppression dans la liste des queues
this.deleteEmbeddedDocuments('Item', [rencSpecial._id]); // Suppression dans la liste des queues
addMsg = " La queue a été supprimée de votre fiche automatiquement";
} else {
addMsg = " Vous devez gérer manuellement le décompte de mauvaises rencontres manuellement.";
@ -2075,7 +2074,7 @@ export class RdDActor extends Actor {
async _tacheResult(rollData) {
// Mise à jour de la tache
rollData.tache.data.points_de_tache_courant += rollData.rolled.ptTache;
this.updateEmbeddedDocuments("OwnedItem", rollData.tache);
this.updateEmbeddedDocuments('Item', [rollData.tache]);
this.santeIncDec("fatigue", rollData.tache.data.fatigue);
RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-tache.html');
@ -2084,7 +2083,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
_tacheETotal(rollData) {
rollData.tache.data.difficulte--;
this.updateEmbeddedDocuments("OwnedItem", rollData.tache);
this.updateEmbeddedDocuments('Item', [rollData.tache]);
}
/* -------------------------------------------- */
@ -2249,7 +2248,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
_meditationETotal(meditationData) {
meditationData.meditation.data.malus--;
this.updateEmbeddedDocuments("OwnedItem", meditationData.meditation);
this.updateEmbeddedDocuments('Item', [meditationData.meditation]);
}
/* -------------------------------------------- */
@ -2352,7 +2351,7 @@ export class RdDActor extends Actor {
xpComp = xp - xpCarac;
competence = duplicate(competence);
competence.data.xp = Misc.toInt(competence.data.xp) + xpComp;
await this.updateEmbeddedDocuments("OwnedItem", competence);
await this.updateEmbeddedDocuments('Item', [competence]);
} else {
xpCarac = Math.max(xpCarac, 1);
}
@ -2386,12 +2385,12 @@ export class RdDActor extends Actor {
name: "Nombre Astral", type: "nombreastral", data:
{ value: data.nbAstral, istrue: data.isvalid, jourindex: Number(data.date), jourlabel: game.system.rdd.calendrier.getDateFromIndex(Number(data.date)) }
};
await this.createEmbeddedDocuments("OwnedItem", [item]);
await this.createEmbeddedDocuments("Item", [item]);
// Suppression des anciens nombres astraux
let toDelete = this.data.items.filter(it => it.data.jourindex < game.system.rdd.calendrier.getCurrentDayIndex());
const deletions = toDelete.map(it => it._id);
await this.deleteEmbeddedDocuments("OwnedItem", deletions);
await this.deleteEmbeddedDocuments("Item", deletions);
// Affichage Dialog
this.astrologieNombresAstraux();
@ -2533,7 +2532,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
getArmeParade(armeParadeId) {
const item = armeParadeId ? this.getOwnedItem(armeParadeId) : undefined;
const item = armeParadeId ? this.getEmbeddedDocuments('Item', armeParadeId) : undefined;
return RdDItemArme.getArmeData(item);
}
@ -2550,12 +2549,12 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
async equiperObjet(itemID) {
let item = this.getOwnedItem(itemID);
let item = this.getEmbeddedDocuments('Item', itemID);
if (item?.data?.data) {
let itemData = Misc.itemData(item);
const isEquipe = !itemData.data.equipe;
let update = { _id: item._id, "data.equipe": isEquipe };
await this.updateEmbeddedDocuments("OwnedItem", update);
await this.updateEmbeddedDocuments('Item', [update]);
this.computeEncombrementTotalEtMalusArmure(); // Mise à jour encombrement
this.computePrixTotalEquipement(); // Mis à jour du prix total de l'équipement
if (isEquipe)
@ -2595,7 +2594,7 @@ export class RdDActor extends Actor {
if (!ReglesOptionelles.isUsing('deteriorationArmure')) {
return;
}
let itemData = duplicate(Misc.itemData(item));
let itemData = duplicate(Misc.data(item));
itemData.data.deterioration = (itemData.data.deterioration ?? 0) + dmg;
if (itemData.data.deterioration >= 10) {
itemData.data.deterioration = 0;
@ -2612,7 +2611,7 @@ export class RdDActor extends Actor {
}
ChatMessage.create({ content: "Votre armure s'est détériorée, elle protège maintenant de " + itemData.data.protection });
}
this.updateEmbeddedDocuments("OwnedItem", itemData);
this.updateEmbeddedDocuments('Item', [itemData]);
}
/* -------------------------------------------- */
@ -2857,17 +2856,18 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
async optimizeArgent(sumDenier, monnaies) {
let parValeur = Misc.classifyFirst(monnaies, it => it.data.valeur_deniers);
let parValeur = Misc.classifyFirst(monnaies, it => Misc.templateData(it).valeur_deniers);
let fortune = {
1000: Math.floor(sumDenier / 1000), // or
100: Math.floor(sumDenier / 100) % 10, // argent
10: Math.floor(sumDenier / 10) % 10, // bronze
1: sumDenier % 10 // étain
}
let updates = []
for (const [valeur, nombre] of Object.entries(fortune)) {
let piece = parValeur[valeur];
await this.updateEmbeddedDocuments("OwnedItem", { _id: piece._id, 'data.quantite': nombre });
updates.push( { _id: parValeur[valeur]._id, 'data.quantite': nombre });
}
await this.updateEmbeddedDocuments('Item', updates);
}
/* -------------------------------------------- */
@ -2881,8 +2881,8 @@ export class RdDActor extends Actor {
sumDenier = Number(sumDenier);
let denierDisponible = 0;
for (let piece of monnaies) {
denierDisponible += piece.data.valeur_deniers * Number(piece.data.quantite);
for (let pieceData of monnaies.map(m => Misc.data(m))) {
denierDisponible += pieceData.data.valeur_deniers * Number(pieceData.data.quantite);
}
console.log("DENIER", game.user.character, sumDenier, denierDisponible);
@ -2916,7 +2916,7 @@ export class RdDActor extends Actor {
let monnaie = this.getMonnaie(id);
if (monnaie) {
const quantite = Math.max(0, Misc.templateData(monnaie).quantite + value);
await this.updateEmbeddedDocuments("OwnedItem", { _id: monnaie.id, 'data.quantite': quantite });
await this.updateEmbeddedDocuments('Item', [{ _id: monnaie.id, 'data.quantite': quantite }]);
}
}
@ -3138,15 +3138,7 @@ export class RdDActor extends Actor {
}
/* -------------------------------------------- */
async updateEmbeddedDocuments(embeddedName, data, options) {
if (data?.type == 'competence' && data['data.defaut_carac'] && data['data.xp']) { // C'est une compétence
this.checkCompetenceXP(data['name'], data['data.xp']);
}
return super.updateEmbeddedDocuments(embeddedName, [data], options);
}
/* -------------------------------------------- */
async onCreateOwnedItem(item, options, id) {
async onCreateItem(item, options, id) {
switch (item.type) {
case 'tete':
case 'queue':
@ -3157,7 +3149,14 @@ export class RdDActor extends Actor {
}
}
async onDeleteOwnedItem(item, options, id) {
async onPreUpdateItem(item, change, options, id) {
const itemData = Misc.data(item);
if (itemData.type == 'competence' && itemData.data.defaut_carac && itemData.data.xp) {
await this.checkCompetenceXP(itemData.name, itemData.data.xp);
}
}
async onDeleteItem(item, options, id) {
switch (item.type) {
case 'tete':
case 'queue':

View File

@ -3,7 +3,7 @@ import { RdDUtility } from "./rdd-utility.js";
/* -------------------------------------------- */
// Activate chat listeners defined
Hooks.on('renderChatLog', (log, html, data) => {
RdDUtility.chatListeners(html);
});
// Hooks.on('renderChatLog', (log, html, data) => {
// RdDUtility.chatListeners(html);
// });

View File

@ -106,7 +106,7 @@ export class RdDItemSort extends Item {
// Sauvegarde/update
let bonuscase = StringList.toString();
//console.log("Bonus cae :", bonuscase);
actor.updateEmbeddedDocuments("OwnedItem", { _id: sort._id, 'data.bonuscase': bonuscase } );
actor.updateEmbeddedDocuments('Item', [{ _id: sort._id, 'data.bonuscase': bonuscase }] );
}
/* -------------------------------------------- */

View File

@ -104,7 +104,7 @@ export class RdDCombatManager extends Combat {
const roll = super._getInitiativeRoll(c, rollFormula);
if (roll.total <= 0) roll.total = 0.00;
console.log("Compute init for", rollFormula, roll.total);
await this.updateEmbeddedDocuments("Combatant", { _id: c._id, initiative: roll.total });
await this.updateEmbeddedDocuments("Combatant", [{ _id: c._id, initiative: roll.total }]);
// Send a chat message
let rollMode = messageOptions.rollMode || game.settings.get("core", "rollMode");
@ -334,8 +334,8 @@ export class RdDCombat {
static init() {
this.initStorePasseArmes();
Hooks.on("updateCombat", (combat, data) => { RdDCombat.onUpdateCombat(combat, data) });
Hooks.on("preDeleteCombat", (combat, options) => { RdDCombat.onPreDeleteCombat(combat, options); });
Hooks.on("updateCombat", (combat, change, options, userId) => { RdDCombat.onUpdateCombat(combat, change, options, userId) });
Hooks.on("preDeleteCombat", (combat, options, userId) => { RdDCombat.onPreDeleteCombat(combat, options, userId); });
}
/* -------------------------------------------- */
@ -357,14 +357,14 @@ export class RdDCombat {
}
/* -------------------------------------------- */
static onUpdateCombat(combat, data) {
static onUpdateCombat(combat, change, options, userId) {
if (combat.data.round != 0 && combat.turns && combat.data.active) {
RdDCombat.combatNouveauTour(combat);
}
}
/* -------------------------------------------- */
static onPreDeleteCombat(combat, options) {
static onPreDeleteCombat(combat, options, userId) {
if (game.user.isGM) {
combat.cleanItemUse();
ChatUtility.removeChatMessageContaining(`<div data-combatid="${combat.id}" data-combatmessage="actor-turn-summary">`)
@ -1130,7 +1130,7 @@ export class RdDCombat {
resistance -= perteResistance;
defenderRoll.show.deteriorationArme = resistance <= 0 ? 'brise' : 'perte';
defenderRoll.show.perteResistance = perteResistance;
this.defender.updateEmbeddedDocuments("OwnedItem", { _id: defenderRoll.arme._id, 'data.resistance': resistance });
this.defender.updateEmbeddedDocuments('Item', [{ _id: defenderRoll.arme._id, 'data.resistance': resistance }]);
}
}
} else {
@ -1147,7 +1147,7 @@ export class RdDCombat {
resistance -= dmg;
defenderRoll.show.deteriorationArme = resistance <= 0 ? 'brise' : 'perte';
defenderRoll.show.perteResistance = dmg;
this.defender.updateEmbeddedDocuments("OwnedItem", { _id: defenderRoll.arme._id, 'data.resistance': resistance });
this.defender.updateEmbeddedDocuments('Item', [{ _id: defenderRoll.arme._id, 'data.resistance': resistance }]);
}
}
// Si l'arme de parade n'est pas un bouclier, jet de désarmement (p.132)

View File

@ -153,6 +153,7 @@ Hooks.once("init", async function () {
CONFIG.Combat.documentClass = RdDCombatManager;
// préparation des différents modules
RdDUtility.init();
RdDCommands.init();
RdDCombat.init();
RdDCombatManager.init(),
@ -224,8 +225,3 @@ Hooks.on("chatMessage", (html, content, msg) => {
return true;
});
/* -------------------------------------------- */
Hooks.on("renderChatMessage", async (app, html, msg) => {
RdDUtility.onRenderChatMessage(app, html, msg);
});

View File

@ -130,14 +130,16 @@ export class RdDTMRDialog extends Dialog {
return EffetsDraconiques.rencontre.token(this.pixiTMR, rencontre, () => rencontre.coord);
}
_tokenCaseSpeciale(casetmr) {
const draconique = Draconique.get(casetmr.data.specific);
return draconique?.token(this.pixiTMR, casetmr, () => casetmr.data.coord);
const caseData = Misc.data(casetmr);
const draconique = Draconique.get(caseData.data.specific);
return draconique?.token(this.pixiTMR, caseData, () => caseData.data.coord);
}
_tokenSortEnReserve(sortEnReserve) {
return EffetsDraconiques.sortReserve.token(this.pixiTMR, sortEnReserve.sort, () => sortEnReserve.coord);
}
_tokenDemiReve() {
return EffetsDraconiques.demiReve.token(this.pixiTMR, this.actor, () => Misc.data(this.actor).data.reve.tmrpos.coord);
const actorData = Misc.data(this.actor);
return EffetsDraconiques.demiReve.token(this.pixiTMR, actorData, () => actorData.data.reve.tmrpos.coord);
}
_updateDemiReve() {

View File

@ -92,6 +92,13 @@ const definitionsEncaissement = {
/* -------------------------------------------- */
export class RdDUtility {
/* -------------------------------------------- */
static async init() {
Hooks.on("renderChatMessage", async (app, html, msg) => RdDUtility.onRenderChatMessage(app, html, msg));
Hooks.on('renderChatLog', (log, html, data) => RdDUtility.chatListeners(html));
}
/* -------------------------------------------- */
static async preloadHandlebarsTemplates() {
const templatePaths = [
@ -544,7 +551,7 @@ export class RdDUtility {
actor.tmrApp.lancerSortEnReserve(coord, sortId);
});
// Gestion du bouton payer
html.on("click", '#payer-button', event => {
html.on("click", '.payer-button', event => {
let sumdenier = event.currentTarget.attributes['data-somme-denier'].value;
let quantite = 1;
if (event.currentTarget.attributes['data-quantite']) {
@ -595,7 +602,7 @@ export class RdDUtility {
let sumtotald = sumd + (sums * 100);
let msgPayer = "La somme de " + sums + " Sols et " + sumd + " Deniers est à payer, cliquer sur le lien ci-dessous si besoin.<br>";
msgPayer += "<a id='payer-button' class='chat-card-button' data-somme-denier='" + sumtotald + "'>Payer</a>"
msgPayer += "<a class='payer-button chat-card-button' data-somme-denier='" + sumtotald + "'>Payer</a>"
ChatMessage.create({ content: msgPayer });
}
@ -658,7 +665,7 @@ export class RdDUtility {
label: "Supprimer l'objet",
callback: () => {
console.log("Delete : ", itemId);
actorSheet.actor.deleteOwnedItem(itemId);
actorSheet.actor.deleteEmbeddedDocuments('Item', [itemId]);
li.slideUp(200, () => actorSheet.render(false));
}
},

View File

@ -29,14 +29,14 @@ export class Conquete extends Draconique {
}
async _creerConquete(actor, queue) {
let existants = actor.data.items.filter(it => this.isCase(it)).map(it => it.data.coord);
let existants = actor.data.items.filter(it => this.isCase(it)).map(it => Misc.data(it).data.coord);
let possibles = TMRUtility.filterTMR(tmr => !TMRUtility.isCaseHumide(tmr) && !existants.includes(tmr.coord));
let conquete = Misc.rollOneOf(possibles);
await this.createCaseTmr(actor, 'Conquête: ' + conquete.label, conquete, queue._id);
await this.createCaseTmr(actor, 'Conquête: ' + conquete.label, conquete, queue.id);
}
async onActorDeleteCaseTmr(actor, casetmr) {
await actor.deleteOwnedItem(casetmr.data.sourceid);
await actor.deleteEmbeddedDocuments('Item', [casetmr.data.sourceid]);
}
}

View File

@ -14,7 +14,7 @@ export class Debordement extends Draconique {
async onActorCreateOwned(actor, souffle) {
const existants = actor.data.items.filter(it => this.isCase(it)).map(it => it.data.coord);
const tmr = TMRUtility.getTMRAleatoire(it => !(TMRUtility.isCaseHumide(it) || existants.includes(it.coord)));
await this.createCaseTmr(actor, 'Debordement: ' + tmr.label, tmr, souffle._id);
await this.createCaseTmr(actor, 'Debordement: ' + tmr.label, tmr, souffle.id);
}
code() { return 'debordement' }

View File

@ -43,7 +43,7 @@ export class Desorientation extends Draconique {
const existants = actor.data.items.filter(it => this.isCase(it)).map(it => it.data.coord);
let tmrs = TMRUtility.filterTMR(it => it.type == type && !existants.includes(it.coord));
for (let tmr of tmrs) {
await this.createCaseTmr(actor, 'Désorientation: ' + tmr.label, tmr, souffle._id);
await this.createCaseTmr(actor, 'Désorientation: ' + tmr.label, tmr, souffle.id);
}
}

View File

@ -1,3 +1,4 @@
import { Misc } from "../misc.js";
import { TMRUtility } from "../tmr-utility.js";
import { PixiTMR } from "./pixi-tmr.js";
@ -8,11 +9,11 @@ const registeredEffects = [
* Définition des informations d'une "draconique" (queue, ombre, tête, souffle) qui influence les TMR
*/
export class Draconique {
static isCaseTMR(element) { return element.type == 'casetmr'; }
static isQueueDragon(element) { return element.type == 'queue' || element.type == 'ombre'; }
static isSouffleDragon(element) { return element.type == 'souffle'; }
static isTeteDragon(element) { return element.type == 'tete'; }
static isQueueSouffle(it) { return Draconique.isQueueDragon(it) || Draconique.isSouffleDragon(it); }
static isCaseTMR(itemData) { return itemData.type == 'casetmr'; }
static isQueueDragon(itemData) { return itemData.type == 'queue' || itemData.type == 'ombre'; }
static isSouffleDragon(itemData) { return itemData.type == 'souffle'; }
static isTeteDragon(itemData) { return itemData.type == 'tete'; }
static isQueueSouffle(itemData) { return Draconique.isQueueDragon(itemData) || Draconique.isSouffleDragon(itemData); }
tmrLabel(linkData) { return TMRUtility.getTMRLabel(linkData.data.coord); }
@ -37,7 +38,8 @@ export class Draconique {
* @returns true si l'item correspond
*/
match(item) {
return Draconique.isQueueDragon(item) || Draconique.isSouffleDragon(item) || Draconique.isTeteDragon(item);
const itemData = Misc.data(item);
return Draconique.isQueueDragon(itemData) || Draconique.isSouffleDragon(itemData) || Draconique.isTeteDragon(itemData);
}
/**
@ -110,35 +112,40 @@ export class Draconique {
/**
*
* @param {*} it un item à tester
* @param {*} item un item à tester
* @param {*} coord les coordonnées d'une case. Si undefined toute case du type correspondra,
*/
isCase(it, coord = undefined) {
return Draconique.isCaseTMR(it) && it.data.specific == this.code() && (coord ? it.data.coord == coord : true);
isCase(item, coord = undefined) {
const itemData = Misc.data(item);
return Draconique.isCaseTMR(itemData) && itemData.data.specific == this.code() && (coord ? itemData.data.coord == coord : true);
}
find(list, coord = undefined) {
return list.find(c => this.isCase(c, coord));
return list.find(c => this.isCase(Misc.data(c), coord));
}
async createCaseTmr(actor, label, tmr, sourceId = undefined) {
await actor.createEmbeddedDocuments('Item',[{
name: label, type: 'casetmr', img: this.img(), _id: randomID(16),
const casetmrData = {
name: label, type: 'casetmr', img: this.img(),
data: { coord: tmr.coord, specific: this.code(), sourceid: sourceId }
}]);
};
await actor.createEmbeddedDocuments('Item', [casetmrData]);
}
async deleteCasesTmr(actor, draconique) {
let caseTmrs = actor.data.items.filter(it => this.isCase(it) && it.data.sourceid == draconique._id);
for (let casetmr of caseTmrs) {
await actor.deleteOwnedItem(casetmr._id);
}
let caseTmrs = actor.data.items.filter(it => this.isCaseForSource(it, draconique));
await actor.deleteEmbeddedDocuments('Item', caseTmrs.map(it => it.id));
}
isCaseForSource(item, draconique) {
const itemData = Misc.data(item);
return Draconique.isCaseTMR(itemData) && itemData.data.specific == this.code() && itemData.data.sourceid == draconique.id;
}
async onVisiteSupprimer(actor, tmr, onRemoveToken) {
let existants = actor.data.items.filter(it => this.isCase(it, tmr.coord));
await actor.deleteEmbeddedDocuments('Item', existants.map(it => it.id));
for (let casetmr of existants) {
await actor.deleteOwnedItem(casetmr._id);
onRemoveToken(tmr, casetmr);
}
}

View File

@ -32,7 +32,7 @@ export class FermetureCites extends Draconique {
let existants = actor.data.items.filter(it => this.isCase(it)).map(it => it.data.coord);
let ouvertes = TMRUtility.filterTMR(it => it.type == 'cite' && !existants.includes(it.coord));
for (let tmr of ouvertes) {
await this.createCaseTmr(actor, 'Fermeture: ' + tmr.label, tmr, souffle._id);
await this.createCaseTmr(actor, 'Fermeture: ' + tmr.label, tmr, souffle.id);
}
}
}

View File

@ -14,7 +14,7 @@ export class Pelerinage extends Draconique {
async onActorCreateOwned(actor, queue) {
let tmr = TMRUtility.getTMRAleatoire();
await this.createCaseTmr(actor, 'Pèlerinage: ' + tmr.label, tmr, queue._id);
await this.createCaseTmr(actor, 'Pèlerinage: ' + tmr.label, tmr, queue.id);
}
@ -32,7 +32,7 @@ export class Pelerinage extends Draconique {
}
async onActorDeleteCaseTmr(actor, casetmr) {
await actor.deleteOwnedItem(casetmr.data.sourceid);
await actor.deleteEmbeddedDocuments('Item', [casetmr.data.sourceid]);
}
}

View File

@ -16,7 +16,7 @@ export class Periple extends Draconique {
let terrain = new Roll("1d2").evaluate().total == 1 ? 'sanctuaire' : 'necropole';
let tmrs = TMRUtility.getListTMR(terrain);
for (let tmr of tmrs) {
await this.createCaseTmr(actor, 'Périple: ' + tmr.label, tmr, souffle._id);
await this.createCaseTmr(actor, 'Périple: ' + tmr.label, tmr, souffle.id);
}
}

View File

@ -14,7 +14,7 @@ export class PontImpraticable extends Draconique {
async onActorCreateOwned(actor, souffle) {
const ponts = TMRUtility.getListTMR('pont');
for (let tmr of ponts) {
await this.createCaseTmr(actor, 'Pont impraticable: ' + tmr.label, tmr, souffle._id);
await this.createCaseTmr(actor, 'Pont impraticable: ' + tmr.label, tmr, souffle.id);
}
}

View File

@ -40,7 +40,7 @@ export class PresentCites extends Draconique {
else {
let cites = TMRUtility.filterTMR(it => it.type == 'cite');
for (let tmr of cites) {
await this.createCaseTmr(actor, 'Présent: ' + tmr.label, tmr, tete._id);
await this.createCaseTmr(actor, 'Présent: ' + tmr.label, tmr, tete.id);
}
}
}
@ -60,6 +60,6 @@ export class PresentCites extends Draconique {
}
async ouvrirLePresent(actor, casetmr) {
await actor.deleteOwnedItem(casetmr._id);
await actor.deleteEmbeddedDocuments('Item', [casetmr.id]);
}
}

View File

@ -11,7 +11,7 @@ export class QueteEaux extends Draconique {
match(item) { return Draconique.isTeteDragon(item) && Grammar.toLowerCaseNoAccent(item.name).includes("quete des eaux"); }
manualMessage() { return "Vous devrez re-configurer votre Quête des Eaux une fois un lac ou marais vaincu" }
async onActorCreateOwned(actor, tete) {
await this.createCaseTmr(actor, "Quête des eaux à déterminer", { coord: 'A0' }, tete._id);
await this.createCaseTmr(actor, "Quête des eaux à déterminer", { coord: 'A0' }, tete.id);
}
code() { return 'maitrisee' }

View File

@ -13,7 +13,7 @@ export class ReserveExtensible extends Draconique {
async onActorCreateOwned(actor, tete) {
const existants = actor.data.items.filter(it => this.isCase(it)).map(it => it.data.coord);
const tmr = TMRUtility.getTMRAleatoire(it => !(it.type == 'fleuve' || existants.includes(it.coord)));
await this.createCaseTmr(actor, "Nouvelle Réserve extensible", tmr, tete._id);
await this.createCaseTmr(actor, "Nouvelle Réserve extensible", tmr, tete.id);
}
code() { return 'reserve_extensible' }

View File

@ -12,7 +12,7 @@ export class TerreAttache extends Draconique {
manualMessage() { return "Vous pouvez re-configurer votre Terre d'Attache" }
async onActorCreateOwned(actor, tete) {
await this.createCaseTmr(actor, "Terre d'attache à déterminer", { coord: 'A0' }, tete._id);
await this.createCaseTmr(actor, "Terre d'attache à déterminer", { coord: 'A0' }, tete.id);
}
code() { return 'attache' }

View File

@ -14,7 +14,7 @@ export class TrouNoir extends Draconique {
async onActorCreateOwned(actor, souffle) {
const existants = actor.data.items.filter(it => this.isCase(it)).map(it => it.data.coord);
const tmr = TMRUtility.getTMRAleatoire(it => !(TMRUtility.isCaseHumide(it) || existants.includes(it.coord)));
await this.createCaseTmr(actor, 'Trou noir: ' + tmr.label, tmr, souffle._id);
await this.createCaseTmr(actor, 'Trou noir: ' + tmr.label, tmr, souffle.id);
}
code() { return 'trounoir' }

View File

@ -23,20 +23,20 @@ export class UrgenceDraconique extends Draconique {
whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
content: `En l'absence de sorts en réserve, l'urgence draconique de ${actor.name} se transforme en ${ideeFixe.name}`
});
await actor.createEmbeddedDocuments('Item',[ideeFixe]);
await actor.deleteOwnedItem(queue._id);
await actor.createEmbeddedDocuments('Item', [ideeFixe]);
await actor.deleteEmbeddedDocuments('Item', [queue.id]);
return;
}
else {
const demiReve = actor.getDemiReve();
coordSortsReserve.sort(Misc.ascending(t => TMRUtility.distanceTMR(t, demiReve)));
const tmr = TMRUtility.getTMR(coordSortsReserve[0]);
await this.createCaseTmr(actor, 'Urgence draconique: ' + tmr.label, tmr, queue._id);
await this.createCaseTmr(actor, 'Urgence draconique: ' + tmr.label, tmr, queue.id);
}
}
async onActorDeleteCaseTmr(actor, casetmr) {
await actor.deleteOwnedItem(casetmr.data.sourceid);
await actor.deleteEmbeddedDocuments('Item', [casetmr.data.sourceid]);
}
code() { return 'urgence' }

View File

@ -31,7 +31,7 @@
"name": "Fab"
}
],
"esmodules": [ "module/rdd-main.js", "module/hook-renderChatLog.js" ],
"esmodules": [ "module/rdd-main.js"],
"styles": ["styles/simple.css"],
"media": [
{

View File

@ -15,7 +15,7 @@
<div class="form-group">
<label for="niveau">Mode spécifique</label>
<select name="data.specific" id="specific" data-dtype="String">
{{#select item.data.specific}}
{{#select data.specific}}
{{>"systems/foundryvtt-reve-de-dragon/templates/casetmr-specific-list.html"}}
{{/select}}
</select>

View File

@ -11,7 +11,7 @@
<div class="form-group">
<label class="alchimie-title" for="xp">Type</label>
<select name="data.type" data-dtype="String">
{{#select item.data.type}}
{{#select data.type}}
<option value="adressehasard">Adresse/Hasard</option>
<option value="de">Dés</option>
<option value="carte">Cartes</option>

View File

@ -11,7 +11,7 @@
<div class="form-group">
<label for="xp">Compétence</label>
<select name="data.competence" id="competenceselect" data-dtype="String">
{{#select item.data.competence}}
{{#select data.competence}}
{{#each competences as |competence key|}}
<option value="{{competence.name}}">{{competence.name}}</option>
{{/each}}
@ -29,7 +29,7 @@
<div class="form-group">
<label for="xp">Heure</label>
<select name="data.heure" id="heure" data-dtype="String">
{{#select item.data.heure}}
{{#select data.heure}}
{{>"systems/foundryvtt-reve-de-dragon/templates/heures-select-option.html"}}
{{/select}}
</select>
@ -49,7 +49,7 @@
<div class="form-group">
<label for="xp">Case TMR</label>
<select name="data.tmr" id="tmr" data-dtype="String">
{{#select item.data.tmr}}
{{#select data.tmr}}
{{>"systems/foundryvtt-reve-de-dragon/templates/sort-tmr.html"}}
{{/select}}
</select>
@ -58,7 +58,7 @@
<label for="xp">Malus</label>
{{#if isGM}}
<select name="data.malus" id="malus" data-dtype="Number">
{{#select item.data.malus}}
{{#select data.malus}}
<option value="0">0</option>
<option value="-1">-1</option>
<option value="-2">-2</option>

View File

@ -11,7 +11,7 @@
<div class="form-group">
<label>Caractéristique</label>
<select name="data.default_carac" id="default_carac" data-dtype="String">
{{#select item.data.default_carac}}
{{#select data.default_carac}}
{{>"systems/foundryvtt-reve-de-dragon/templates/competence-carac-defaut.html"}}
{{/select}}
</select>
@ -19,7 +19,7 @@
<div class="form-group">
<label>Compétence</label>
<select name="data.competence" id="competenceselect" data-dtype="String">
{{#select item.data.competence}}
{{#select data.competence}}
{{#each competences as |competence key|}}
<option value="{{competence.name}}">{{competence.name}}</option>
{{/each}}

View File

@ -26,7 +26,7 @@
{{#if hasPrice}}
<span class="chat-card-button-area">
<a id='payer-button' class='chat-card-button market-button' data-jsondata='{{jsondata}}'
<a class='payer-button chat-card-button market-button' data-jsondata='{{jsondata}}'
data-somme-denier="{{data.cout_deniers_total}}" data-quantite="{{data.quantite}}">Payer</a>
</span>
{{/if}}