This commit is contained in:
2021-05-07 00:01:09 +02:00
19 changed files with 213 additions and 284 deletions

View File

@ -299,8 +299,18 @@ export class RdDActor extends Actor {
filterItemsData(filter) {
return this.data.items.map(it => Misc.data(it)).filter(filter);
}
filterItems(filter) {
return this.data.items.filter(it => filter(Misc.data(it)));
}
getItemOfType(id, type) {
return id ? this.data.items.find(it => it.id == id && Misc.data(it).type == type) : undefined;
if (id && type) {
let itemById = this.data.items.find(it => it.id == id);
const itemData = Misc.data(itemById);
if (itemData.type == type) {
return itemById;
}
}
return undefined;
}
getMonnaie(id) {
return this.getItemOfType(id, 'monnaie');
@ -1221,13 +1231,13 @@ export class RdDActor extends Actor {
}
/* -------------------------------------------- */
async cacheTMR( ) {
async cacheTMR() {
await this.update({ 'data.reve.tmrpos.cache': true });
}
async montreTMR( ) {
async montreTMR() {
await this.update({ 'data.reve.tmrpos.cache': false });
}
isTMRCache( ) {
isTMRCache() {
return this.data.data.reve.tmrpos.cache;
}
/* -------------------------------------------- */
@ -1318,7 +1328,7 @@ export class RdDActor extends Actor {
async reveActuelIncDec(value) {
let mydata = Misc.templateData(this);
let reve = Math.max(mydata.reve.reve.value + value, 0);
await this.update( { "data.reve.reve.value": reve });
await this.update({ "data.reve.reve.value": reve });
}
/* -------------------------------------------- */
@ -1681,7 +1691,7 @@ export class RdDActor extends Actor {
if (rollEthylisme.isEchec) {
await this._jetDeMoralEthylique(ethylisme);
}
await this.update({'data.compteurs.ethylisme': ethylisme});
await this.update({ 'data.compteurs.ethylisme': ethylisme });
}
/* -------------------------------------------- */
@ -1708,6 +1718,7 @@ export class RdDActor extends Actor {
switch (Misc.data(item).type) {
case 'nourritureboisson': return await this.actionNourritureboisson(item);
case 'potion': return await this.actionPotion(item);
case 'livre': return await this.actionLire(item);
}
}
@ -1719,6 +1730,12 @@ export class RdDActor extends Actor {
async actionPotion(item) {
return await this.consommerPotion(item)
}
async actionLire(item) {
const tache = await this.creerTacheDepuisLivre(item, { renderSheet: false });
if (tache) {
await this.rollTache(tache.id);
}
}
/* -------------------------------------------- */
async consommer(item, choix) {
@ -2022,8 +2039,8 @@ export class RdDActor extends Actor {
let draconicList = this.getDraconicList().map(d => duplicate(Misc.data(d)));
for (let sort of sortList) {
let draconicsSort = this.getDraconicsSort(draconicList, sort).map(it => it.name);
for (let index = 0; index < draconicList.length && sort.data.listIndex==undefined; index++){
if (draconicsSort.includes(draconicList[index].name)){
for (let index = 0; index < draconicList.length && sort.data.listIndex == undefined; index++) {
if (draconicsSort.includes(draconicList[index].name)) {
sort.data.listIndex = index;
}
}
@ -2288,22 +2305,29 @@ export class RdDActor extends Actor {
}
/* -------------------------------------------- */
async creerTacheDepuisLivre(item) {
async creerTacheDepuisLivre(item, options = { renderSheet: true }) {
const itemData = Misc.data(item);
let tache = {
name: "Lire " + item.name, type: 'tache',
data: {
carac: 'intellect',
competence: 'Ecriture',
difficulte: itemData.data.difficulte,
periodicite: "60 minutes",
fatigue: 2,
points_de_tache: itemData.data.points_de_tache,
points_de_tache_courant: 0,
description: "Lecture du livre " + item.name + " - XP : " + itemData.data.xp + " - Compétences : " + itemData.data.competence
const nomTache = "Lire " + itemData.name;
const filterTacheLecture = it => it.type == 'tache' && it.name == nomTache;
let tachesExistantes = this.filterItems(filterTacheLecture);
if (tachesExistantes.length == 0) {
const tache = {
name: nomTache, type: 'tache',
data: {
carac: 'intellect',
competence: 'Ecriture',
difficulte: itemData.data.difficulte,
periodicite: "60 minutes",
fatigue: 2,
points_de_tache: itemData.data.points_de_tache,
points_de_tache_courant: 0,
description: "Lecture du livre " + item.name + " - XP : " + itemData.data.xp + " - Compétences : " + itemData.data.competence
}
}
await this.createEmbeddedDocuments('Item', [tache], options);
tachesExistantes = this.filterItems(filterTacheLecture);
}
await this.createEmbeddedDocuments('Item', [tache], { renderSheet: true });
return tachesExistantes.length > 0 ? tachesExistantes[0] : undefined;
}
/* -------------------------------------------- */
@ -2330,7 +2354,6 @@ export class RdDActor extends Actor {
callbacks: [
this.createCallbackExperience(),
this.createCallbackAppelAuMoral(),
{ condition: r => r.rolled.isETotal, action: r => this._tacheETotal(r) },
{ action: r => this._tacheResult(r) }
]
});
@ -2340,19 +2363,17 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
async _tacheResult(rollData) {
// Mise à jour de la tache
rollData.tache = duplicate(rollData.tache);
rollData.tache.data.points_de_tache_courant += rollData.rolled.ptTache;
if (rollData.rolled.isETotal){
rollData.tache.data.difficulte--;
}
this.updateEmbeddedDocuments('Item', [rollData.tache]);
this.santeIncDec("fatigue", rollData.tache.data.fatigue);
RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-tache.html');
}
/* -------------------------------------------- */
_tacheETotal(rollData) {
rollData.tache.data.difficulte--;
this.updateEmbeddedDocuments('Item', [rollData.tache]);
}
/* -------------------------------------------- */
async _rollArt(artData, selected, oeuvre, callBackResult = r => this._resultArt(r)) {
const actorData = Misc.data(this);
@ -2776,7 +2797,7 @@ export class RdDActor extends Actor {
refreshTMRView(tmrData) {
console.log("REFRESH !!!!");
if (this.currentTMR) {
this.currentTMR.externalRefresh( tmrData)
this.currentTMR.externalRefresh(tmrData)
}
}