forked from public/foundryvtt-reve-de-dragon
Utilisation Misc.data
This commit is contained in:
@ -240,8 +240,12 @@ export class RdDActor extends Actor {
|
||||
return id ? this.items.find(it => it._id == id) : undefined;
|
||||
}
|
||||
getItemOfType(type, id) {
|
||||
return id ? this.data.items.find(it => it._id == id && it.type == type) : undefined;
|
||||
return id ? this.items.find(it => it._id == id && it.type == type) : undefined;
|
||||
}
|
||||
getMonnaie(id) {
|
||||
return this.getItemOfType(id, 'monnaie');
|
||||
}
|
||||
|
||||
getTache(id) {
|
||||
return this.getItemOfType(id, 'tache');
|
||||
}
|
||||
@ -267,8 +271,12 @@ export class RdDActor extends Actor {
|
||||
return this.getItemOfType(id, 'recettecuisine');
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getDraconicList() {
|
||||
return this.items.filter(it => Misc.data(it).type == 'competence' && Misc.templateData(it).categorie == 'draconic')
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getBestDraconic() {
|
||||
const list = this.getDraconicList().sort((a, b) => b.data.data.niveau - a.data.data.niveau);
|
||||
const list = this.getDraconicList().sort(Misc.descending(it => Misc.templateData(it).niveau));
|
||||
if (list.length == 0) {
|
||||
return { name: "Aucun", data: { name: "Aucun", data: { niveau: -11 } } };
|
||||
}
|
||||
@ -296,7 +304,7 @@ export class RdDActor extends Actor {
|
||||
getSurprise(isCombat = undefined) {
|
||||
let niveauSurprise = Array.from(this.effects?.values() ?? [])
|
||||
.map(effect => StatusEffects.valeurSurprise(effect.data, isCombat))
|
||||
.reduce((a, b) => a + b, 0);
|
||||
.reduce(Misc.sum(), 0);
|
||||
if (niveauSurprise > 1) {
|
||||
return 'totale';
|
||||
}
|
||||
@ -600,10 +608,10 @@ export class RdDActor extends Actor {
|
||||
async resultCombatReveDeDragon(rollData) {
|
||||
rollData.queues = [];
|
||||
if (rollData.rolled.isEchec) {
|
||||
rollData.queues.push(await this.ajouterQueue());
|
||||
rollData.queues.push(Misc.data(await this.ajouterQueue()));
|
||||
}
|
||||
if (rollData.rolled.isETotal) {
|
||||
rollData.queues.push(await this.ajouterQueue());
|
||||
rollData.queues.push(Misc.data(await this.ajouterQueue()));
|
||||
}
|
||||
if (rollData.rolled.isSuccess) {
|
||||
await this.updatePointDeSeuil();
|
||||
@ -621,31 +629,6 @@ export class RdDActor extends Actor {
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async appliquerReveDeDragon(roll, force) {
|
||||
let message = "";
|
||||
if (roll.isSuccess) {
|
||||
message += "<br>Vous gagnez " + force + " points de Rêve";
|
||||
await this.updatePointDeSeuil();
|
||||
await this.reveActuelIncDec(force);
|
||||
}
|
||||
if (roll.isPart) {
|
||||
// TODO: Dialog pour choix entre HR opu général?
|
||||
message += "<br>Vous gagnez une Tête de dragon: Demander à votre MJ d'effectuer un tirage sur la table des Hauts Rêvants ou des Vrais Rêvants, selon votre choix.";
|
||||
}
|
||||
if (roll.isEchec) {
|
||||
message += "<br>Vous subissez une Queue de Dragon: " + await this.ajouterQueue();
|
||||
}
|
||||
if (roll.isETotal) {
|
||||
message += "<br>A cause de votre échec total, vous subissez une deuxième Queue de Dragon: " + await this.ajouterQueue();
|
||||
}
|
||||
ChatMessage.create({
|
||||
whisper: ChatUtility.getWhisperRecipientsAndGMs(this.name),
|
||||
content: message
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async sortMisEnReserve(rollData, sort) {
|
||||
let reserve = duplicate(Misc.templateData(this).reve.reserve.list);
|
||||
@ -690,7 +673,7 @@ export class RdDActor extends Actor {
|
||||
let comp = this.getCompetence(compName);
|
||||
//console.log(comp);
|
||||
if (comp) {
|
||||
const update = { _id: comp._id }
|
||||
const update = { _id: comp.id }
|
||||
if (fieldName == "niveau")
|
||||
update['data.niveau'] = compValue;
|
||||
else if (fieldName == "dommages")
|
||||
@ -718,7 +701,7 @@ export class RdDActor extends Actor {
|
||||
content: message
|
||||
});
|
||||
}
|
||||
const update = { _id: comp._id, 'data.niveau': nouveauNiveau };
|
||||
const update = { _id: comp.id, 'data.niveau': nouveauNiveau };
|
||||
await this.updateEmbeddedEntity("Item", update); // Updates one EmbeddedEntity
|
||||
} else {
|
||||
console.log("Competence not found", compName);
|
||||
@ -731,7 +714,7 @@ export class RdDActor extends Actor {
|
||||
if (comp) {
|
||||
compValue = compValue ?? 0;
|
||||
this.checkCompetenceXP(compName, compValue);
|
||||
const update = { _id: comp._id, 'data.xp': compValue };
|
||||
const update = { _id: comp.id, 'data.xp': compValue };
|
||||
await this.updateEmbeddedEntity("OwnedItem", update); // Updates one EmbeddedEntity
|
||||
} else {
|
||||
console.log("Competence not found", compName);
|
||||
@ -744,7 +727,7 @@ export class RdDActor extends Actor {
|
||||
let comp = this.getCompetence(compName);
|
||||
if (comp) {
|
||||
compValue = compValue ?? 0;
|
||||
const update = { _id: comp._id, 'data.xp_sort': compValue };
|
||||
const update = { _id: comp.id, 'data.xp_sort': compValue };
|
||||
await this.updateEmbeddedEntity("OwnedItem", update); // Updates one EmbeddedEntity
|
||||
} else {
|
||||
console.log("Competence not found", compName);
|
||||
@ -756,7 +739,7 @@ export class RdDActor extends Actor {
|
||||
let comp = this.getCompetence(compName);
|
||||
if (comp) {
|
||||
compValue = compValue ?? 0;
|
||||
const update = { _id: comp._id, 'data.niveau_archetype': compValue };
|
||||
const update = { _id: comp.id, 'data.niveau_archetype': compValue };
|
||||
await this.updateEmbeddedEntity("OwnedItem", update); // Updates one EmbeddedEntity
|
||||
} else {
|
||||
console.log("Competence not found", compName);
|
||||
@ -813,13 +796,13 @@ export class RdDActor extends Actor {
|
||||
return Number(tplData.encombrement) * Number(tplData.quantite);
|
||||
}
|
||||
const encContenus = tplData.contenu.map(idContenu => this.getRecursiveEnc(this.getObjet(idContenu)));
|
||||
return encContenus.reduce((a, b) => a + b, 0)
|
||||
return encContenus.reduce(Misc.sum(), 0)
|
||||
+ Number(tplData.encombrement) /* TODO? Number(tplData.quantite) -- on pourrait avoir plusieurs conteneurs...*/
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
isConteneurSuffisant(itemId, conteneurId) {
|
||||
if ( !conteneurId){
|
||||
if (!conteneurId) {
|
||||
// on peut toujours vider son sac
|
||||
return true;
|
||||
}
|
||||
@ -1099,7 +1082,7 @@ export class RdDActor extends Actor {
|
||||
/* -------------------------------------------- */
|
||||
async ajouterQueue(options = { chat: false }) {
|
||||
let queue;
|
||||
if (Misc.templateData(this).reve.reve.thanatosused) {
|
||||
if (Misc.data(this).data.reve.reve.thanatosused) {
|
||||
queue = await RdDRollTables.getOmbre();
|
||||
await this.update({ "data.reve.reve.thanatosused": false });
|
||||
}
|
||||
@ -1766,15 +1749,16 @@ export class RdDActor extends Actor {
|
||||
let draconicList = this.getDraconicList();
|
||||
let bestDraconic = this.getBestDraconic();
|
||||
for (let sort of sortList) {
|
||||
let voie = sort.data.draconic.toLowerCase();
|
||||
let draconic = draconicList.find(it => it.data.data.categorie == 'draconic' && it.data.name.toLowerCase().includes(voie));
|
||||
let voie = sort.data.draconic;
|
||||
let draconic = RdDItemCompetence.getVoieDraconic(draconicList, voie);
|
||||
//console.log(draconicList, bestDraconic, draconic, voie);
|
||||
if (sort.name.toLowerCase().includes('aura')) {
|
||||
draconic = bestDraconic;
|
||||
}
|
||||
draconic = duplicate(draconic);
|
||||
// TODO: duplicate sur Misc.data?
|
||||
draconic = duplicate(Misc.data(draconic));
|
||||
if (draconicDone[draconic.name] == undefined) {
|
||||
draconic.data.data.defaut_carac = 'reve';
|
||||
draconic.data.defaut_carac = 'reve';
|
||||
newDraconicList.push(draconic);
|
||||
draconicDone[draconic.name] = newDraconicList.length - 1; // Patch local pour relier facilement voie/compétence
|
||||
}
|
||||
@ -1811,7 +1795,7 @@ export class RdDActor extends Actor {
|
||||
competence: draconicList[0],
|
||||
selectedSort: sortList[0],
|
||||
tmr: TMRUtility.getTMR(coord),
|
||||
diffLibre: sortList[0].data.difficulte, // Per default at startup
|
||||
diffLibre: RdDItemSort.getDifficulte(sortList[0], -7), // Per default at startup
|
||||
coutreve: Array(30).fill().map((item, index) => 1 + index),
|
||||
carac: { 'reve': duplicate(actorData.data.carac.reve) }
|
||||
}
|
||||
@ -2054,23 +2038,25 @@ export class RdDActor extends Actor {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async rollTache(id) {
|
||||
let tache = duplicate(this.getTache(id));
|
||||
let competence = this.getCompetence(tache.data.competence);
|
||||
competence.data.data.defaut_carac = tache.data.carac; // Patch !
|
||||
const actorData = Misc.data(this);
|
||||
const tacheData = Misc.data(this.getTache(id));
|
||||
const compData = duplicate(Misc.data(this.getCompetence(tacheData.data.competence)));
|
||||
compData.data.defaut_carac = tacheData.data.carac; // Patch !
|
||||
|
||||
let rollData = {
|
||||
competence: competence,
|
||||
tache: tache,
|
||||
diffConditions: tache.data.difficulte,
|
||||
competence: compData,
|
||||
tache: tacheData,
|
||||
diffConditions: tacheData.data.difficulte,
|
||||
use: { libre: false, conditions: false },
|
||||
carac: {}
|
||||
};
|
||||
rollData.carac[tache.data.carac] = duplicate(Misc.templateData(this).carac[tache.data.carac]); // Single carac
|
||||
rollData.carac[tacheData.data.carac] = duplicate(actorData.data.carac[tacheData.data.carac]); // Single carac
|
||||
|
||||
console.log("rollTache !!!", rollData);
|
||||
|
||||
const dialog = await RdDRoll.create(this, rollData, { html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html' }, {
|
||||
name: 'jet-competence',
|
||||
label: 'Jet de Tâche ' + tache.name,
|
||||
label: 'Jet de Tâche ' + tacheData.name,
|
||||
callbacks: [
|
||||
this.createCallbackExperience(),
|
||||
this.createCallbackAppelAuMoral(),
|
||||
@ -2465,11 +2451,6 @@ export class RdDActor extends Actor {
|
||||
return this.data.items.filter(it => it.data.type == "sort");
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getDraconicList() {
|
||||
return this.data.items.filter(it => it.data.data.categorie == 'draconic')
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
countMonteeLaborieuse() { // Return +1 par queue/ombre/souffle Montée Laborieuse présente
|
||||
let countMonteeLaborieuse = this.data.items.filter(it => EffetsDraconiques.isMonteeLaborieuse(it)).length;
|
||||
@ -2928,9 +2909,9 @@ export class RdDActor extends Actor {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async monnaieIncDec(id, value) {
|
||||
let monnaie = this.data.items.find(item => item.type == 'monnaie' && item.id == id);
|
||||
let monnaie = this.getMonnaie(id);
|
||||
if (monnaie) {
|
||||
const quantite = Math.max(0, monnaie.data.data.quantite + value);
|
||||
const quantite = Math.max(0, Misc.templateData(monnaie).quantite + value);
|
||||
await this.updateEmbeddedEntity("OwnedItem", { _id: monnaie.id, 'data.quantite': quantite });
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user