diff --git a/module/item-signedraconique-sheet.js b/module/item-signedraconique-sheet.js new file mode 100644 index 00000000..b597264d --- /dev/null +++ b/module/item-signedraconique-sheet.js @@ -0,0 +1,110 @@ +import { Misc } from "./misc.js"; +import { TMRType } from "./tmr-utility.js"; + +/** + * Item sheet pour signes draconiques + * @extends {ItemSheet} + */ +export class RdDSigneDraconiqueItemSheet extends ItemSheet { + + /** @override */ + static get defaultOptions() { + return mergeObject(super.defaultOptions, { + classes: ["foundryvtt-reve-de-dragon", "sheet", "item"], + template: "systems/foundryvtt-reve-de-dragon/templates/item-signedraconique-sheet.html", + width: 550, + height: 550 + }); + } + + /* -------------------------------------------- */ + _getHeaderButtons() { + let buttons = super._getHeaderButtons(); + buttons.unshift({ class: "post", icon: "fas fa-comment", onclick: ev => this.item.postItem() }); + return buttons; + } + + /* -------------------------------------------- */ + /** @override */ + setPosition(options = {}) { + const position = super.setPosition(options); + const sheetHeader = this.element.find(".sheet-header"); + const sheetBody = this.element.find(".sheet-body"); + const bodyHeight = position.height - sheetHeader[0].clientHeight; + sheetBody.css("height", bodyHeight); + return position; + } + + + /* -------------------------------------------- */ + async getData() { + const formData = duplicate(Misc.data(this.object)); + mergeObject(formData, { + title: formData.name, + isGM: game.user.isGM, + owner: this.document.isOwner, + isOwned: this.actor ? true : false, + actorId: this.actor?.id, + editable: this.isEditable, + cssClass: this.isEditable ? "editable" : "locked", + }); + formData.tmrs = RdDSigneDraconiqueItemSheet.listTMRTypes(formData.data.typesTMR ?? []); + return formData; + } + + static listTMRTypes(typesTMR) { + return Object.values(TMRType).map(value => Misc.upperFirst(value.name)) + .sort() + .map(name => { return { name: name, selected: typesTMR.includes(name) } }); + } + + /* -------------------------------------------- */ + /** @override */ + activateListeners(html) { + super.activateListeners(html); + + if (!this.options.editable) return; + + html.find(".select-tmr").change((event) => this.onSelectTmr(event)); + html.find(".valeur-xp-sort").change((event) => this.onValeurXpSort(event.currentTarget.attributes['data-typereussite']?.value, Number(event.currentTarget.value))); + } + + async onSelectTmr(event) { + event.preventDefault(); + const selectedTMR = $(".select-tmr").val(); + this.object.update({ 'data.typesTMR': selectedTMR }); + } + + async onValeurXpSort(qualite, valeur) { + let tplData = Misc.templateData(this.object); + if (valeur != tplData.valeur[qualite]) + { + await this.object.update({ [`data.valeur.${qualite}`]: valeur }); + + tplData = Misc.templateData(this.object); + switch (qualite) { + case "norm": + if (valeur > tplData.valeur.sign) await this.object.update({ 'data.valeur.sign': valeur }); + if (valeur > tplData.valeur.part) await this.object.update({ 'data.valeur.part': valeur }); + break; + case "sign": + if (valeur < tplData.valeur.norm) await this.object.update({ 'data.valeur.norm': valeur }); + if (valeur > tplData.valeur.part) await this.object.update({ 'data.valeur.part': valeur }); + break; + case "part": + if (valeur < tplData.valeur.norm) await this.object.update({ 'data.valeur.norm': valeur }); + if (valeur < tplData.valeur.sign) await this.object.update({ 'data.valeur.sign': valeur }); + break; + } + } + } + + /* -------------------------------------------- */ + get template() { + return `systems/foundryvtt-reve-de-dragon/templates/item-signedraconique-sheet.html`; + } + + get title() { + return `Signe draconique: ${this.object.name}`; + } +} diff --git a/module/item-signedraconique.js b/module/item-signedraconique.js new file mode 100644 index 00000000..b2cad95c --- /dev/null +++ b/module/item-signedraconique.js @@ -0,0 +1,37 @@ +import { Misc } from "./misc.js"; + +export class RdDItemSigneDraconique { + + static prepareSigneDraconiqueMeditation(meditation, rolled) { + if (rolled.isSuccess != undefined) { + meditation = Misc.data(meditation); + return { + name: "de la " + meditation.name, + type: "signedraconique", + img: meditation.img, + data: { + "typesTMR": [Misc.upperFirst(meditation.data.tmr)], + "difficulte": RdDItemSigneDraconique.getDiffSigneMeditation(rolled.code), + "ephemere": true, + "duree": "1 round", + "valeur": { "norm": 3, "sign": 5, "part": 10 } + } + }; + } + return undefined; + } + + static getDiffSigneMeditation(code) { + switch (code) { + case "norm": return -7; + case "sign": return -3; + case "part": return 0; + } + return undefined; + } + + static getXpSortSigneDraconique(code, signe) { + return Misc.data(signe).data.valeur[code] ?? 0; + } + +} \ No newline at end of file diff --git a/module/rdd-main.js b/module/rdd-main.js index e7136f9c..d96303cc 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -31,6 +31,7 @@ import { EffetsDraconiques } from "./tmr/effets-draconiques.js"; import { RdDHerbes } from "./rdd-herbes.js"; import { RdDItem } from "./item.js"; import { RdDDice } from "./rdd-dice.js"; +import { RdDSigneDraconiqueItemSheet } from "./item-signedraconique-sheet.js"; /* -------------------------------------------- */ /* Foundry VTT Initialization */ @@ -167,6 +168,11 @@ Hooks.once("init", async function () { Actors.registerSheet("foundryvtt-reve-de-dragon", RdDActorVehiculeSheet, { types: ["vehicule"], makeDefault: true }); Actors.registerSheet("foundryvtt-reve-de-dragon", RdDActorEntiteSheet, { types: ["entite"], makeDefault: true }); Items.unregisterSheet("core", ItemSheet); + Items.registerSheet("foundryvtt-reve-de-dragon", RdDSigneDraconiqueItemSheet, { + label: "Signe draconique", + types: ["signedraconique"], + makeDefault: true + }); Items.registerSheet("foundryvtt-reve-de-dragon", RdDItemSheet, { makeDefault: true }); CONFIG.Combat.documentClass = RdDCombatManager; diff --git a/module/rdd-utility.js b/module/rdd-utility.js index bdd25d71..a39c7135 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -140,6 +140,7 @@ export class RdDUtility { 'systems/foundryvtt-reve-de-dragon/templates/item-monnaie-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/item-meditation-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/item-nourritureboisson-sheet.html', + 'systems/foundryvtt-reve-de-dragon/templates/item-signedraconique-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/competence-carac-defaut.html', 'systems/foundryvtt-reve-de-dragon/templates/competence-base.html', 'systems/foundryvtt-reve-de-dragon/templates/enum-aspect-tarot.html', @@ -271,6 +272,7 @@ export class RdDUtility { formData.munitions = this.checkNull(formData.itemsByType['munition']); formData.herbes = this.checkNull(formData.itemsByType['herbe']); formData.sorts = this.checkNull(formData.itemsByType['sort']); + formData.signesdraconiques = this.checkNull(formData.itemsByType['signedraconique']); formData.queues = this.checkNull(formData.itemsByType['queue']); formData.souffles = this.checkNull(formData.itemsByType['souffle']); formData.ombres = this.checkNull(formData.itemsByType['ombre']); diff --git a/template.json b/template.json index 6a610cc9..a18b5589 100644 --- a/template.json +++ b/template.json @@ -577,7 +577,7 @@ "Item": { "types": ["objet", "arme", "armure", "conteneur", "competence", "sort", "herbe", "ingredient", "livre", "potion", "munition", "rencontresTMR", "queue", "ombre", "souffle", "tete", "competencecreature", "tarot", "monnaie", "nombreastral", "tache", "meditation", "casetmr", "recettealchimique", - "musique", "chant", "danse", "jeu", "recettecuisine", "maladie", "poison", "oeuvre", "nourritureboisson" ], + "musique", "chant", "danse", "jeu", "recettecuisine", "maladie", "poison", "oeuvre", "nourritureboisson", "signedraconique" ], "objet": { "description": "", "quantite": 1, @@ -868,6 +868,18 @@ "encombrement": 0, "quantite": 1, "cout": 0 + }, + "signedraconique": { + "typesTMR": [], + "ephemere": true, + "duree": "1 round", + "difficulte": 0, + "valeur": { + "norm": 3, + "sign": 5, + "part": 10 + }, + "description": "" } } } diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index 069e0eac..35825de3 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -432,6 +432,20 @@
{{#if data.attributs.hautrevant.value}} + {{#if options.isGM}} +

Signes draconiques

+ + {{/if}}

Sorts: