2024-09-26 00:55:08 +02:00
|
|
|
import { Grammar } from "./grammar.js";
|
|
|
|
import { RdDItemCompetence } from "./item-competence.js";
|
2024-09-25 22:56:24 +02:00
|
|
|
import { ITEM_TYPES } from "./item.js";
|
2020-11-27 10:21:20 +01:00
|
|
|
import { Misc } from "./misc.js";
|
2024-11-28 00:38:34 +01:00
|
|
|
import { FLEUVE_COORD, TMRType, TMRUtility } from "./tmr-utility.js";
|
2020-11-27 10:21:20 +01:00
|
|
|
|
2024-09-26 00:55:08 +02:00
|
|
|
const VOIES_DRACONIC = [
|
2024-10-05 00:37:55 +02:00
|
|
|
{ code: 'O', label: "Voie d'Oniros", short: 'Oniros', ordre: 'a' },
|
|
|
|
{ code: 'H', label: "Voie d'Hypnos", short: 'Hypnos', ordre: 'b' },
|
|
|
|
{ code: 'N', label: "Voie de Narcos", short: 'Narcos', ordre: 'c' },
|
|
|
|
{ code: 'T', label: "Voie de Thanatos", short: 'Thanatos', ordre: 'd' },
|
|
|
|
{ code: 'O/H/N/T', label: "Oniros/Hypnos/Narcos/Thanatos", short: 'Oniros/Hypnos/Narcos/Thanatos', ordre: 'e' },
|
|
|
|
{ code: 'O/H/N', label: "Oniros/Hypnos/Narcos", short: "Oniros/Hypnos/Narcos", ordre: 'f' }
|
2024-09-26 00:55:08 +02:00
|
|
|
]
|
|
|
|
|
2020-12-04 20:52:04 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-11-27 10:21:20 +01:00
|
|
|
export class RdDItemSort extends Item {
|
|
|
|
|
2024-11-24 23:04:56 +01:00
|
|
|
static getDraconicsSort(competencesDraconic, sort) {
|
|
|
|
// se baser sur la voie du sort?
|
2024-09-26 00:55:08 +02:00
|
|
|
switch (Grammar.toLowerCaseNoAccent(sort.name)) {
|
|
|
|
case "lecture d'aura":
|
|
|
|
case "detection d'aura":
|
2024-11-24 23:04:56 +01:00
|
|
|
return competencesDraconic;
|
2024-09-26 00:55:08 +02:00
|
|
|
case "annulation de magie":
|
2024-11-24 23:04:56 +01:00
|
|
|
return competencesDraconic.filter(it => !RdDItemCompetence.isThanatos(it));
|
2024-09-26 00:55:08 +02:00
|
|
|
}
|
2024-11-24 23:04:56 +01:00
|
|
|
const voies = sort.system.draconic.split('/')
|
|
|
|
return voies.map(voie => RdDItemCompetence.getVoieDraconic(competencesDraconic, voie))
|
2024-09-26 00:55:08 +02:00
|
|
|
}
|
|
|
|
|
2024-10-05 00:37:55 +02:00
|
|
|
static getOrdreCode(code) {
|
|
|
|
return (VOIES_DRACONIC.find(it => it.code == code)?.ordre ?? '?')
|
|
|
|
}
|
|
|
|
|
|
|
|
static getVoieCode(voie) {
|
|
|
|
return VOIES_DRACONIC.find(it => voie.name.includes(it.short))?.code ?? '?'
|
|
|
|
}
|
|
|
|
|
|
|
|
static getCodeDraconic(sort, voies = ['O', 'H', 'N', 'T']) {
|
2024-09-26 00:55:08 +02:00
|
|
|
switch (Grammar.toLowerCaseNoAccent(sort.name)) {
|
|
|
|
case "lecture d'aura":
|
|
|
|
case "detection d'aura":
|
2024-10-05 00:37:55 +02:00
|
|
|
return RdDItemSort.$voiesConnues('O/H/N/T', voies)
|
2024-09-26 00:55:08 +02:00
|
|
|
case "annulation de magie":
|
2024-10-05 00:37:55 +02:00
|
|
|
return RdDItemSort.$voiesConnues('O/H/N', voies)
|
2024-09-26 00:55:08 +02:00
|
|
|
}
|
|
|
|
const voie = VOIES_DRACONIC.find(it => it.label.includes(sort.system.draconic))
|
|
|
|
return voie?.code ?? sort.system.draconic
|
|
|
|
}
|
2024-10-05 00:37:55 +02:00
|
|
|
|
|
|
|
static $voiesConnues(voiesSort, voies) {
|
|
|
|
const codes = voies.filter(it => voiesSort.includes(it))
|
|
|
|
.sort(Misc.ascending(it => RdDItemSort.getOrdreCode(it)))
|
|
|
|
return Misc.join(codes ?? [''], '/');
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2023-03-30 01:31:41 +02:00
|
|
|
|
2020-12-04 20:52:04 +01:00
|
|
|
/* -------------------------------------------- */
|
2023-03-30 01:31:41 +02:00
|
|
|
static setCoutReveReel(sort) {
|
2020-11-27 10:21:20 +01:00
|
|
|
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)) {
|
2023-03-30 01:31:41 +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
|
|
|
/**
|
|
|
|
* Retourne une liste de bonus/case pour un item-sheet
|
|
|
|
* @param {} item
|
|
|
|
*/
|
2024-11-28 00:38:34 +01:00
|
|
|
static getBonusCaseList(item) {
|
2020-12-10 02:29:11 +01:00
|
|
|
// Gestion spéciale case bonus
|
2024-09-25 22:56:24 +02:00
|
|
|
if (item.type == ITEM_TYPES.sort) {
|
2024-11-28 00:38:34 +01:00
|
|
|
return RdDItemSort.stringToBonuscases(item.system.bonuscase)
|
2020-12-04 20:52:04 +01:00
|
|
|
}
|
2024-11-28 00:38:34 +01:00
|
|
|
return [];
|
2020-12-04 20:52:04 +01:00
|
|
|
}
|
2023-03-30 01:31:41 +02:00
|
|
|
|
2020-12-04 20:52:04 +01:00
|
|
|
/* -------------------------------------------- */
|
2023-03-30 01:31:41 +02:00
|
|
|
static incrementBonusCase(actor, sort, coord) {
|
2024-11-28 00:38:34 +01:00
|
|
|
if (TMRUtility.isFleuve(coord)) {
|
|
|
|
coord = FLEUVE_COORD;
|
|
|
|
}
|
|
|
|
let list = RdDItemSort.stringToBonuscases(sort.system.bonuscase);
|
|
|
|
const existing = list.find(it => it.case == coord)
|
|
|
|
const bonus = Number(existing?.bonus ?? 0) + 1
|
|
|
|
if (existing) {
|
|
|
|
existing.bonus = bonus
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
list.push({ case: coord, bonus: 1 })
|
2023-03-30 01:31:41 +02:00
|
|
|
}
|
|
|
|
|
2024-11-28 00:38:34 +01:00
|
|
|
actor.updateEmbeddedDocuments('Item', [{ _id: sort._id, 'system.bonuscase': RdDItemSort.bonuscasesToString(list) }]);
|
2020-12-04 20:52:04 +01:00
|
|
|
}
|
2023-03-30 01:31:41 +02:00
|
|
|
|
|
|
|
|
2020-12-04 20:52:04 +01:00
|
|
|
/* -------------------------------------------- */
|
2023-03-30 01:31:41 +02:00
|
|
|
static getCaseBonus(sort, coord) {
|
2024-11-28 00:38:34 +01:00
|
|
|
const search = TMRUtility.isFleuve(coord)
|
|
|
|
? it => it.case == 'Fleuve'
|
|
|
|
: it => it.case == coord;
|
|
|
|
const bc = RdDItemSort.stringToBonuscases(sort.system.bonuscase)
|
|
|
|
.find(search)
|
2023-03-30 01:31:41 +02:00
|
|
|
return Number(bc?.bonus ?? 0);
|
|
|
|
}
|
|
|
|
|
2024-11-28 00:38:34 +01:00
|
|
|
static bonuscasesToString(list) {
|
2023-03-30 01:31:41 +02:00
|
|
|
return list.map(it => `${it.case}:${it.bonus}`)
|
|
|
|
.sort(Misc.ascending())
|
|
|
|
.join(',');
|
|
|
|
}
|
2024-11-28 00:38:34 +01:00
|
|
|
|
|
|
|
static stringToBonuscases(bonuscase) {
|
2024-09-27 02:33:01 +02:00
|
|
|
if (bonuscase == undefined || bonuscase == '') {
|
|
|
|
return []
|
|
|
|
}
|
2024-11-28 00:38:34 +01:00
|
|
|
return bonuscase.split(',')
|
|
|
|
.map(it => it.split(':'))
|
|
|
|
.map(it => { return { case: it[0], bonus: it[1] } });
|
2020-12-04 20:52:04 +01:00
|
|
|
}
|
|
|
|
|
2020-11-27 10:21:20 +01:00
|
|
|
}
|