Généralisation des fréquences
Tout objet d'inventaire a une fréquence (en ville/village, ou autre milieu)
This commit is contained in:
64
module/item/raretes.js
Normal file
64
module/item/raretes.js
Normal file
@ -0,0 +1,64 @@
|
||||
|
||||
const RARETE_COMMUNE = { code: 'Commune', label: 'Commune', frequence: 54, min: 27, max: 108 };
|
||||
const RARETE_FREQUENTE = { code: 'Frequente', label: 'Fréquente', frequence: 18, min: 9, max: 36 };
|
||||
const RARETE_RARE = { code: 'Rare', label: 'Rare', frequence: 6, min: 3, max: 12 };
|
||||
const RARETE_RARISSIME = { code: 'Rarissime', label: 'Rarissime', frequence: 2, min: 1, max: 4 };
|
||||
const RARETE_INEXISTANT = { code: 'Inexistant', label: 'Inexistant', frequence: 0, min: 0, max: 0 };
|
||||
|
||||
const RARETES = [
|
||||
RARETE_COMMUNE,
|
||||
RARETE_FREQUENTE,
|
||||
RARETE_RARE,
|
||||
RARETE_RARISSIME,
|
||||
RARETE_INEXISTANT,
|
||||
]
|
||||
|
||||
export class RdDRaretes {
|
||||
|
||||
static getRareteByCode(code = undefined) {
|
||||
return RARETES.find(it => it.code == code) ?? RARETE_FREQUENTE;
|
||||
}
|
||||
|
||||
static getChamp(rarete, field = undefined) {
|
||||
const selected = this.getRareteByCode(rarete);
|
||||
return field ? selected[field] : selected[frequence];
|
||||
}
|
||||
|
||||
static rareteFrequente() {
|
||||
return RARETE_FREQUENTE;
|
||||
}
|
||||
|
||||
static raretes() {
|
||||
return RARETES;
|
||||
}
|
||||
|
||||
static selonEnvironnement(item, milieux = undefined) {
|
||||
const list = item.getEnvironnement(milieux);
|
||||
const freqMax = Math.max(0, ...list.map(env => env.frequence));
|
||||
const env = list.find(env => env.frequence == freqMax);
|
||||
if (env) {
|
||||
return RdDRaretes.getRareteByCode(env.rarete)
|
||||
}
|
||||
if (milieux == undefined) {
|
||||
return RdDRaretes.selonQualite(item)
|
||||
}
|
||||
return RARETE_INEXISTANT;
|
||||
}
|
||||
|
||||
static selonQualite(item) {
|
||||
const qualite = item.system.qualite ?? 0;
|
||||
if (qualite <= 0) {
|
||||
return RARETE_COMMUNE
|
||||
}
|
||||
if (qualite <= 3) {
|
||||
return RARETE_FREQUENTE
|
||||
}
|
||||
if (qualite <= 6) {
|
||||
return RARETE_RARE
|
||||
}
|
||||
if (qualite <= 9) {
|
||||
return RARETE_RARISSIME
|
||||
}
|
||||
return RARETE_INEXISTANT
|
||||
}
|
||||
}
|
119
module/item/sheet-base-inventaire.js
Normal file
119
module/item/sheet-base-inventaire.js
Normal file
@ -0,0 +1,119 @@
|
||||
import { HtmlUtility } from "../html-utility.js";
|
||||
import { RdDItemSheet } from "../item-sheet.js";
|
||||
import { Misc } from "../misc.js";
|
||||
import { RdDRaretes } from "./raretes.js";
|
||||
|
||||
const TYPE_ITEMS_NATURELS = ["faune", "herbe", "plante", "ingredient"];
|
||||
|
||||
export class RdDItemInventaireSheet extends RdDItemSheet {
|
||||
|
||||
static get defaultOptions() {
|
||||
return mergeObject(RdDItemSheet.defaultOptions, {
|
||||
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "informations" }]
|
||||
});
|
||||
}
|
||||
|
||||
setPosition(options = {}) {
|
||||
const position = super.setPosition(options);
|
||||
const sheetHeader = this.element.find(".sheet-header");
|
||||
const sheetBody = this.element.find(".sheet-body");
|
||||
sheetBody.css("height", position.height - sheetHeader[0].clientHeight)
|
||||
return position;
|
||||
}
|
||||
|
||||
async getData() {
|
||||
const formData = await super.getData();
|
||||
return mergeObject(formData, {
|
||||
milieux: await game.system.rdd.environnement.autresMilieux(this.item)
|
||||
});
|
||||
}
|
||||
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
HtmlUtility.showControlWhen(this.html.find("div.description-milieu"), TYPE_ITEMS_NATURELS.includes(this.item.type));
|
||||
|
||||
if (!this.options.editable) return;
|
||||
this.html.find("a.preparer-nourriture").click(event => this.preparerNourriture(event));
|
||||
this.html.find("a.manger-nourriture").click(event => this.mangerNourriture(event));
|
||||
|
||||
this.html.find("input.input-selection-milieu").keypress(event => {
|
||||
if (event.keyCode == '13') {
|
||||
this.onAddMilieu(event);
|
||||
}
|
||||
event.stopPropagation();
|
||||
})
|
||||
this.html.find("a.milieu-add").click(event => this.onAddMilieu(event));
|
||||
this.html.find("div.environnement-milieu a.milieu-delete").click(event => this.onDeleteMilieu(event));
|
||||
this.html.find("div.environnement-milieu select.environnement-rarete").change(event => this.onChange(event,
|
||||
updated => this.$changeRarete(event, updated)));
|
||||
this.html.find("div.environnement-milieu input[name='environnement-frequence']").change(event => this.onChange(event,
|
||||
updated => this.$changeFrequence(event, updated)));
|
||||
|
||||
|
||||
}
|
||||
|
||||
async preparerNourriture(event) {
|
||||
if (this.actor && this.item.getUtilisationCuisine() == 'brut') {
|
||||
await this.actor.preparerNourriture(this.item);
|
||||
}
|
||||
}
|
||||
|
||||
async mangerNourriture(event) {
|
||||
if (this.actor && this.item.getUtilisation() == 'cuisine') {
|
||||
await this.actor.mangerNourriture(this.item);
|
||||
}
|
||||
}
|
||||
|
||||
$changeFrequence(event, updated) {
|
||||
updated.frequence = Number(this.html.find(event.currentTarget).val());
|
||||
}
|
||||
|
||||
$changeRarete(event, updated) {
|
||||
const code = this.html.find(event.currentTarget).val();
|
||||
const rarete = RdDRaretes.getRareteByCode(code);
|
||||
updated.rarete = rarete.code;
|
||||
updated.frequence = rarete.frequence;
|
||||
}
|
||||
|
||||
async onAddMilieu(event) {
|
||||
const milieu = this.html.find('input.input-selection-milieu').val();
|
||||
if (!milieu) {
|
||||
ui.notifications.warn(`Choisissez le milieu dans lequel se trouve le/la ${this.item.name}`);
|
||||
return
|
||||
}
|
||||
const list = this.item.getEnvironnement();
|
||||
const exists = list.find(it => it.milieu == milieu);
|
||||
if (exists) {
|
||||
ui.notifications.warn(`${this.item.name} a déjà une rareté ${exists.rarete} en ${milieu} (fréquence: ${exists.frequence})`);
|
||||
return
|
||||
}
|
||||
const rarete = RdDRaretes.rareteFrequente();
|
||||
const newList = [...list, { milieu, rarete: rarete.code, frequence: rarete.frequence }].sort(Misc.ascending(it => it.milieu))
|
||||
await this.item.update({ 'system.environnement': newList })
|
||||
}
|
||||
|
||||
async onDeleteMilieu(event) {
|
||||
const milieu = this.$getEventMilieu(event);
|
||||
if (milieu != undefined) {
|
||||
const newList = this.item.getEnvironnement().filter(it => it.milieu != milieu)
|
||||
.sort(Misc.ascending(it => it.milieu));
|
||||
await this.item.update({ 'system.environnement': newList });
|
||||
}
|
||||
}
|
||||
|
||||
async onChange(event, doMutation) {
|
||||
const list = this.item.system.environnement;
|
||||
const milieu = this.$getEventMilieu(event);
|
||||
const updated = list.find(it => it.milieu == milieu);
|
||||
if (updated) {
|
||||
doMutation(updated);
|
||||
const newList = [...list.filter(it => it.milieu != milieu), updated]
|
||||
.sort(Misc.ascending(it => it.milieu));
|
||||
await this.item.update({ 'system.environnement': newList });
|
||||
}
|
||||
}
|
||||
|
||||
$getEventMilieu(event) {
|
||||
return this.html.find(event.currentTarget)?.parents("div.environnement-milieu").data("milieu");
|
||||
}
|
||||
}
|
61
module/item/sheet-conteneur.js
Normal file
61
module/item/sheet-conteneur.js
Normal file
@ -0,0 +1,61 @@
|
||||
import { RdDBaseActorSheet } from "../actor/base-actor-sheet.js";
|
||||
import { RdDSheetUtility } from "../rdd-sheet-utility.js";
|
||||
import { RdDUtility } from "../rdd-utility.js";
|
||||
import { RdDItemInventaireSheet } from "./sheet-base-inventaire.js";
|
||||
|
||||
export class RdDConteneurItemSheet extends RdDItemInventaireSheet {
|
||||
|
||||
static get ITEM_TYPE() { return "conteneur" };
|
||||
|
||||
async getData() {
|
||||
const formData = await super.getData();
|
||||
if (this.actor) {
|
||||
this.prepareConteneurData(formData);
|
||||
}
|
||||
return formData;
|
||||
}
|
||||
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
if (!this.options.editable) return;
|
||||
|
||||
this.html.find('.conteneur-name a').click(async event => {
|
||||
RdDUtility.toggleAfficheContenu(RdDSheetUtility.getItemId(event));
|
||||
this.render(true);
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
prepareConteneurData(formData) {
|
||||
RdDBaseActorSheet.filterItemsPerTypeForSheet(formData, this.actor.itemTypes);
|
||||
|
||||
this.objetVersConteneur = RdDUtility.buildArbreDeConteneurs(formData.conteneurs, formData.objets);
|
||||
formData.subItems = formData.conteneurs.find(it => it._id == this.item.id)?.subItems;
|
||||
}
|
||||
|
||||
async _onDragStart(event) {
|
||||
console.log("_onDragStart", event);
|
||||
if (event.target.classList.contains("entity-link")) return;
|
||||
|
||||
const itemId = event.srcElement?.attributes["data-item-id"].value;
|
||||
const item = this.actor.items.get(itemId);
|
||||
// Create drag data
|
||||
const dragData = {
|
||||
actorId: this.actor.id,
|
||||
type: "Item",
|
||||
data: item.system
|
||||
};
|
||||
|
||||
event.dataTransfer.setData("text/plain", JSON.stringify(dragData));
|
||||
}
|
||||
|
||||
async _onDropItem(event, dragData) {
|
||||
if (this.actor) {
|
||||
const dropParams = await RdDSheetUtility.prepareItemDropParameters(this.item.id, this.actor, dragData, this.objetVersConteneur);
|
||||
await this.actor.processDropItem(dropParams);
|
||||
await this.render(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
38
module/item/sheet-faune.js
Normal file
38
module/item/sheet-faune.js
Normal file
@ -0,0 +1,38 @@
|
||||
import { RdDItemInventaireSheet } from "./sheet-base-inventaire.js";
|
||||
|
||||
export class RdDFauneItemSheet extends RdDItemInventaireSheet {
|
||||
|
||||
static get ITEM_TYPE() { return "faune" };
|
||||
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
if (!this.options.editable) return;
|
||||
|
||||
html.find("a.linked-actor-delete").click(event => this.onDeleteLinkedActor());
|
||||
}
|
||||
|
||||
async _onDropActor(event, dragData) {
|
||||
console.log('faune:dropActor', event, dragData)
|
||||
const linkedActor = fromUuidSync(dragData.uuid);
|
||||
if (linkedActor?.pack) {
|
||||
this.item.update({
|
||||
'system.actor.pack': linkedActor.pack,
|
||||
'system.actor.id': linkedActor._id,
|
||||
'system.actor.name': linkedActor.name
|
||||
});
|
||||
}
|
||||
else {
|
||||
ui.notifications.warn(`${linkedActor.name} ne provient pas d'un compendium.
|
||||
<br>Choisissez une créature du compendium pour représenter un élément de faune générique`)
|
||||
}
|
||||
}
|
||||
async onDeleteLinkedActor() {
|
||||
this.item.update({
|
||||
'system.actor.pack': '',
|
||||
'system.actor.id': '',
|
||||
'system.actor.name': ''
|
||||
});
|
||||
}
|
||||
|
||||
}
|
6
module/item/sheet-herbe.js
Normal file
6
module/item/sheet-herbe.js
Normal file
@ -0,0 +1,6 @@
|
||||
import { RdDItemInventaireSheet } from "./sheet-base-inventaire.js";
|
||||
|
||||
export class RdDHerbeItemSheet extends RdDItemInventaireSheet {
|
||||
|
||||
static get ITEM_TYPE() { return "herbe" };
|
||||
}
|
5
module/item/sheet-ingredient.js
Normal file
5
module/item/sheet-ingredient.js
Normal file
@ -0,0 +1,5 @@
|
||||
import { RdDItemInventaireSheet } from "./sheet-base-inventaire.js";
|
||||
|
||||
export class RdDIngredientItemSheet extends RdDItemInventaireSheet {
|
||||
static get ITEM_TYPE() { return "ingredient" };
|
||||
}
|
7
module/item/sheet-plante.js
Normal file
7
module/item/sheet-plante.js
Normal file
@ -0,0 +1,7 @@
|
||||
import { RdDItemInventaireSheet } from "./sheet-base-inventaire.js";
|
||||
|
||||
export class RdDPlanteItemSheet extends RdDItemInventaireSheet {
|
||||
|
||||
static get ITEM_TYPE() { return "plante" };
|
||||
|
||||
}
|
78
module/item/sheet-rencontre.js
Normal file
78
module/item/sheet-rencontre.js
Normal file
@ -0,0 +1,78 @@
|
||||
import { RdDRencontre } from "./rencontre.js";
|
||||
import { RdDItemSheet } from "../item-sheet.js";
|
||||
|
||||
export class RdDRencontreItemSheet extends RdDItemSheet {
|
||||
|
||||
static get ITEM_TYPE() { return "rencontre" };
|
||||
|
||||
static get defaultOptions() {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "carac" }]
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
setPosition(options = {}) {
|
||||
const position = super.setPosition(options);
|
||||
const sheetHeader = this.element.find(".sheet-header");
|
||||
const sheetBody = this.element.find(".sheet-body");
|
||||
sheetBody.css("height", position.height - sheetHeader[0].clientHeight)
|
||||
return position;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async getData() {
|
||||
const formData = await super.getData();
|
||||
mergeObject(formData, {
|
||||
effets: {
|
||||
succes: {
|
||||
liste: RdDRencontre.getEffetsSucces(),
|
||||
select: RdDRencontre.mapEffets(this.item.system.succes.effets)
|
||||
},
|
||||
echec: {
|
||||
liste: RdDRencontre.getEffetsEchec(),
|
||||
select: RdDRencontre.mapEffets(this.item.system.echec.effets)
|
||||
}
|
||||
}
|
||||
});
|
||||
return formData;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
if (!this.options.editable) return;
|
||||
this.html.find("a.effet-add").click(event => this.onAddEffet(event));
|
||||
this.html.find("a.effet-delete").click(event => this.onDeleteEffet(event));
|
||||
}
|
||||
|
||||
async onAddEffet(event) {
|
||||
const resultat = this.html.find(event.currentTarget)?.data("effet-resultat");
|
||||
const keyEffets = `system.${resultat}.effets`;
|
||||
|
||||
const code = this.html.find(event.currentTarget)?.data("effet-code");
|
||||
const liste = RdDRencontre.getListeEffets(this.item, resultat);
|
||||
liste.push(code);
|
||||
|
||||
await this._updateEffetsRencontre(keyEffets, liste);
|
||||
}
|
||||
|
||||
async onDeleteEffet(event) {
|
||||
const resultat = this.html.find(event.currentTarget)?.data("effet-resultat");
|
||||
const keyEffets = `system.${resultat}.effets`;
|
||||
|
||||
const pos = this.html.find(event.currentTarget)?.data("effet-pos");
|
||||
const liste = RdDRencontre.getListeEffets(this.item, resultat);
|
||||
liste.splice(pos, 1);
|
||||
|
||||
await this._updateEffetsRencontre(keyEffets, liste);
|
||||
}
|
||||
|
||||
async _updateEffetsRencontre(key, liste) {
|
||||
const updates = {};
|
||||
updates[key] = liste;
|
||||
this.item.update(updates);
|
||||
}
|
||||
}
|
16
module/item/sheet-service.js
Normal file
16
module/item/sheet-service.js
Normal file
@ -0,0 +1,16 @@
|
||||
import { RdDItemSheet } from "../item-sheet.js";
|
||||
|
||||
export class RdDServiceItemSheet extends RdDItemSheet {
|
||||
|
||||
static get ITEM_TYPE() { return "service" };
|
||||
|
||||
async getData() {
|
||||
const formData = await super.getData();
|
||||
formData.disabled = formData.isGM || formData.isOwned ? '' : 'disabled';
|
||||
return formData;
|
||||
}
|
||||
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
}
|
||||
}
|
68
module/item/sheet-signedraconique.js
Normal file
68
module/item/sheet-signedraconique.js
Normal file
@ -0,0 +1,68 @@
|
||||
import { RdDItemSheet } from "../item-sheet.js";
|
||||
import { RdDItemSigneDraconique } from "./signedraconique.js";
|
||||
import { TMRUtility } from "../tmr-utility.js";
|
||||
|
||||
/**
|
||||
* Item sheet pour signes draconiques
|
||||
* @extends {RdDItemSheet}
|
||||
*/
|
||||
export class RdDSigneDraconiqueItemSheet extends RdDItemSheet {
|
||||
|
||||
static get ITEM_TYPE() { return "signedraconique" }
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
setPosition(options = {}) {
|
||||
const position = super.setPosition(options);
|
||||
const sheetHeader = this.element.find(".sheet-header");
|
||||
const sheetBody = this.element.find(".sheet-body");
|
||||
sheetBody.css("height", position.height - sheetHeader[0].clientHeight)
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async getData() {
|
||||
const formData = await super.getData();
|
||||
this.tmrs = TMRUtility.buildSelectionTypesTMR(this.item.system.typesTMR);
|
||||
formData.tmrs = this.tmrs;
|
||||
return formData;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
if (!this.options.editable) return;
|
||||
|
||||
html.find(".signe-aleatoire").click(event => this.setSigneAleatoire());
|
||||
html.find("input.select-tmr").change(event => this.onSelectTmr(event));
|
||||
html.find(".signe-xp-sort").change(event => this.onValeurXpSort(event.currentTarget.attributes['data-typereussite']?.value, Number(event.currentTarget.value)));
|
||||
}
|
||||
|
||||
async setSigneAleatoire() {
|
||||
const newSigne = await RdDItemSigneDraconique.randomSigneDraconique();
|
||||
newSigne.name = this.item.name;
|
||||
this.item.update(newSigne);
|
||||
}
|
||||
|
||||
async onSelectTmr(event) {
|
||||
const tmrName = $(event.currentTarget)?.data("tmr-name");
|
||||
const onTmr = this.tmrs.find(it => it.name == tmrName);
|
||||
if (onTmr){
|
||||
onTmr.selected = event.currentTarget.checked;
|
||||
}
|
||||
|
||||
this.item.update({ 'system.typesTMR': TMRUtility.buildListTypesTMRSelection(this.tmrs) });
|
||||
}
|
||||
|
||||
async onValeurXpSort(event) {
|
||||
const codeReussite = event.currentTarget.attributes['data-typereussite']?.value ?? 0;
|
||||
const xp = Number(event.currentTarget.value);
|
||||
const oldValeur = this.item.system.valeur;
|
||||
const newValeur = RdDItemSigneDraconique.calculValeursXpSort(codeReussite, xp, oldValeur);
|
||||
await this.item.update({ 'system.valeur': newValeur });
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user