2020-12-04 20:52:04 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-11-27 10:21:20 +01:00
|
|
|
import { Misc } from "./misc.js";
|
2020-12-04 20:52:04 +01:00
|
|
|
import { TMRUtility } from "./tmr-utility.js";
|
2020-11-27 10:21:20 +01:00
|
|
|
|
2020-12-04 20:52:04 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-11-27 10:21:20 +01:00
|
|
|
export class RdDItemSort extends Item {
|
|
|
|
|
2020-12-04 20:52:04 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-11-27 10:21:20 +01:00
|
|
|
static isDifficulteVariable(sort) {
|
2022-09-07 09:01:23 +02:00
|
|
|
return sort && (sort.system.difficulte.toLowerCase() == "variable");
|
2020-11-27 10:21:20 +01:00
|
|
|
}
|
2020-12-04 20:52:04 +01:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2020-11-27 10:21:20 +01:00
|
|
|
static isCoutVariable(sort) {
|
2022-09-07 09:01:23 +02:00
|
|
|
return sort && (sort.system.ptreve.toLowerCase() == "variable" || sort.system.ptreve.indexOf("+") >= 0);
|
2020-11-27 10:21:20 +01:00
|
|
|
}
|
|
|
|
|
2020-12-04 20:52:04 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-11-27 10:21:20 +01:00
|
|
|
static setCoutReveReel(sort){
|
|
|
|
if (sort) {
|
2022-06-12 08:17:59 +02:00
|
|
|
sort.system.ptreve_reel = this.isCoutVariable(sort) ? 1 : sort.system.ptreve;
|
2020-11-27 10:21:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-04 20:52:04 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-11-27 10:21:20 +01:00
|
|
|
static getDifficulte(sort, variable) {
|
|
|
|
if (sort && !RdDItemSort.isDifficulteVariable(sort)) {
|
2022-09-07 09:01:23 +02:00
|
|
|
return Misc.toInt(sort.system.difficulte);
|
2020-11-27 10:21:20 +01:00
|
|
|
}
|
|
|
|
return variable;
|
|
|
|
}
|
|
|
|
|
2020-12-04 20:52:04 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static buildBonusCaseList( caseBonusString, newCase ) {
|
2020-12-10 02:29:11 +01:00
|
|
|
if (caseBonusString == undefined) {
|
|
|
|
return [];
|
|
|
|
}
|
2020-12-04 20:52:04 +01:00
|
|
|
let bonusCaseList = [];
|
2020-12-10 02:29:11 +01:00
|
|
|
let bonusCaseArray = caseBonusString == undefined ? [] : caseBonusString.split(',');
|
2020-12-04 20:52:04 +01:00
|
|
|
for( let bonusCase of bonusCaseArray) {
|
|
|
|
let bonusSplit = bonusCase.split(':');
|
|
|
|
bonusCaseList.push( { case: bonusSplit[0], bonus: bonusSplit[1] } );
|
|
|
|
}
|
|
|
|
if ( newCase )
|
|
|
|
bonusCaseList.push( {case: "Nouvelle", bonus: 0} );
|
|
|
|
return bonusCaseList;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/**
|
|
|
|
* Retourne une liste de bonus/case pour un item-sheet
|
|
|
|
* @param {} item
|
|
|
|
*/
|
2021-03-25 09:28:36 +01:00
|
|
|
static getBonusCaseList( item, newCase = false ) {
|
2020-12-10 02:29:11 +01:00
|
|
|
// Gestion spéciale case bonus
|
2021-03-25 09:28:36 +01:00
|
|
|
if ( item.type == 'sort') {
|
2022-09-07 09:01:23 +02:00
|
|
|
return this.buildBonusCaseList(item.system.bonuscase, newCase );
|
2020-12-04 20:52:04 +01:00
|
|
|
}
|
2020-12-10 02:29:11 +01:00
|
|
|
return undefined;
|
|
|
|
}
|
2020-12-04 20:52:04 +01:00
|
|
|
|
2022-09-07 18:47:56 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
/** Met à jour les données de formulaire
|
|
|
|
* si static des bonus de cases sont présents
|
|
|
|
* */
|
2022-10-21 02:10:37 +02:00
|
|
|
static buildBonusCaseStringFromFormData( bonuses, cases ) {
|
|
|
|
if ( bonuses ) {
|
2022-09-07 18:47:56 +02:00
|
|
|
let list = [];
|
|
|
|
let caseCheck = {};
|
2022-10-21 02:10:37 +02:00
|
|
|
for (let i=0; i<bonuses.length; i++) {
|
|
|
|
let coord = cases[i]?.toUpperCase() || 'A1';
|
|
|
|
let bonus = bonuses[i] || 0;
|
|
|
|
if ( TMRUtility.verifyTMRCoord( coord ) && bonus > 0 && caseCheck[coord] == undefined ) {
|
|
|
|
caseCheck[coord] = bonus;
|
|
|
|
list.push( coord+":"+bonus );
|
2020-12-04 20:52:04 +01:00
|
|
|
}
|
|
|
|
}
|
2022-10-21 02:10:37 +02:00
|
|
|
return list.toString();
|
2022-09-07 18:47:56 +02:00
|
|
|
}
|
2022-10-21 02:10:37 +02:00
|
|
|
return undefined;
|
2020-12-04 20:52:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-02-06 21:53:25 +01:00
|
|
|
static incrementBonusCase( actor, sort, coord ) {
|
2022-09-07 09:01:23 +02:00
|
|
|
let bonusCaseList = this.buildBonusCaseList(sort.system.bonuscase, false);
|
2020-12-04 20:52:04 +01:00
|
|
|
//console.log("ITEMSORT", sort, bonusCaseList);
|
|
|
|
|
|
|
|
let found = false;
|
|
|
|
let StringList = [];
|
|
|
|
for( let bc of bonusCaseList) {
|
2021-02-06 21:53:25 +01:00
|
|
|
if (bc.case == coord) { // Case existante
|
2020-12-04 20:52:04 +01:00
|
|
|
found = true;
|
|
|
|
bc.bonus = Number(bc.bonus) + 1;
|
|
|
|
}
|
|
|
|
StringList.push( bc.case+':'+bc.bonus );
|
|
|
|
}
|
|
|
|
if ( !found) { //Nouvelle case, bonus de 1
|
2021-02-06 21:53:25 +01:00
|
|
|
StringList.push(coord+':1');
|
2020-12-04 20:52:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sauvegarde/update
|
|
|
|
let bonuscase = StringList.toString();
|
|
|
|
//console.log("Bonus cae :", bonuscase);
|
2022-09-07 18:47:56 +02:00
|
|
|
actor.updateEmbeddedDocuments('Item', [{ _id: sort._id, 'system.bonuscase': bonuscase }] );
|
2020-12-04 20:52:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-02-06 21:53:25 +01:00
|
|
|
static getCaseBonus( sort, coord) {
|
2022-09-07 09:01:23 +02:00
|
|
|
let bonusCaseList = this.buildBonusCaseList(sort.system.bonuscase, false);
|
2020-12-04 20:52:04 +01:00
|
|
|
for( let bc of bonusCaseList) {
|
2021-02-06 21:53:25 +01:00
|
|
|
if (bc.case == coord) { // Case existante
|
2021-01-22 14:32:46 +01:00
|
|
|
return Number(bc.bonus);
|
2020-12-04 20:52:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-11-27 10:21:20 +01:00
|
|
|
}
|