diff --git a/modules/mournblade-actor.js b/modules/mournblade-actor.js index c640fd6..afe7ff7 100644 --- a/modules/mournblade-actor.js +++ b/modules/mournblade-actor.js @@ -36,7 +36,7 @@ export class MournbladeActor extends Actor { if (data.type == 'personnage') { const skills = await MournbladeUtility.loadCompendium("fvtt-mournblade.skills") - data.items = skills.map(i => i.toObject()); + data.items = skills.map(i => i.toObject()) } if (data.type == 'pnj') { } @@ -92,10 +92,18 @@ export class MournbladeActor extends Actor { /* -------------------------------------------- */ prepareDerivedData() { - if (this.type == 'character') { + if (this.type == 'personnage') { + let newSante = (this.data.data.attributs.pui.value + this.data.data.attributs.tre.value)*2 + 5 + if (this.data.data.sante.base!=newSante ) { + this.update( {'data.sante.base': newSante} ) + } + let newAme = (this.data.data.attributs.cla.value + this.data.data.attributs.tre.value)*2 + 5 + if (this.data.data.ame.base!=newAme ) { + this.update( {'data.ame.base': newAme} ) + } } - super.prepareDerivedData(); + super.prepareDerivedData() } /* -------------------------------------------- */ @@ -225,6 +233,19 @@ export class MournbladeActor extends Actor { } } + /* -------------------------------------------- */ + getCompetence( compId ) { + return this.data.items.get(compId) + } + + /* -------------------------------------------- */ + async setPredilectionUsed( compId, predIdx) { + let comp = this.data.items.get(compId) + let pred = duplicate(comp.data.data.predilections) + pred[predIdx].used = true + await this.updateEmbeddedDocuments('Item', [ {_id: compId, 'data.predilections': pred}]) + } + /* -------------------------------------------- */ getCommonRollData(attrKey = undefined, compId = undefined) { let rollData = MournbladeUtility.getBasicRollData() diff --git a/modules/mournblade-item-sheet.js b/modules/mournblade-item-sheet.js index 0cf84bc..0f0466d 100644 --- a/modules/mournblade-item-sheet.js +++ b/modules/mournblade-item-sheet.js @@ -119,15 +119,40 @@ export class MournbladeItemSheet extends ItemSheet { // Update Inventory Item html.find('.item-edit').click(ev => { - const li = $(ev.currentTarget).parents(".item"); - const item = this.object.options.actor.getOwnedItem(li.data("item-id")); + const li = $(ev.currentTarget).parents(".item") + const item = this.object.options.actor.getOwnedItem(li.data("item-id")) item.sheet.render(true); }); html.find('.delete-subitem').click(ev => { this.deleteSubitem(ev); - }); - + }) + html.find('.edit-prediction').change(ev => { + const li = $(ev.currentTarget).parents(".prediction-item") + let index = li.data("prediction-index") + let pred = duplicate(this.object.data.data.predilections) + pred[index].name = ev.currentTarget.value + this.object.update( { 'data.predilections': pred }) + }) + html.find('.delete-prediction').click(ev => { + const li = $(ev.currentTarget).parents(".prediction-item") + let index = li.data("prediction-index") + let pred = duplicate(this.object.data.data.predilections) + pred.splice(index,1) + this.object.update( { 'data.predilections': pred }) + }) + html.find('.use-prediction').change(ev => { + const li = $(ev.currentTarget).parents(".prediction-item") + let index = li.data("prediction-index") + let pred = duplicate(this.object.data.data.predilections) + pred[index].used = ev.currentTarget.checked + this.object.update( { 'data.predilections': pred }) + }) + html.find('#add-predilection').click(ev => { + let pred = duplicate(this.object.data.data.predilections) + pred.push( { name: "Nouvelle prédilection", used: false }) + this.object.update( { 'data.predilections': pred }) + }) // Update Inventory Item html.find('.item-delete').click(ev => { const li = $(ev.currentTarget).parents(".item"); @@ -135,14 +160,6 @@ export class MournbladeItemSheet extends ItemSheet { let itemType = li.data("item-type"); }); - html.find('.view-subitem').click(ev => { - this.viewSubitem(ev); - }); - - html.find('.view-spec').click(ev => { - this.manageSpec(); - }); - } /* -------------------------------------------- */ diff --git a/modules/mournblade-utility.js b/modules/mournblade-utility.js index bbd84b2..8a89c9a 100644 --- a/modules/mournblade-utility.js +++ b/modules/mournblade-utility.js @@ -94,9 +94,16 @@ export class MournbladeUtility { /* -------------------------------------------- */ static async chatListeners(html) { - html.on("click", '.view-item-from-chat', event => { - game.system.Mournblade.creator.openItemView(event) - }); + html.on("click", '.predilection-reroll', async event => { + let predIdx = $(event.currentTarget).data("predilection-index") + let messageId = MournbladeUtility.findChatMessageId(event.currentTarget) + let message = game.messages.get(messageId) + let rollData = message.getFlag("world", "mournblade-roll") + let actor = game.actors.get(rollData.actorId) + await actor.setPredilectionUsed( rollData.competence._id, predIdx) + rollData.competence = duplicate( actor.getCompetence(rollData.competence._id) ) + MournbladeUtility.rollMournblade(rollData) + }) } /* -------------------------------------------- */ @@ -126,7 +133,7 @@ export class MournbladeUtility { } static findChatMessage(current) { - return MournbladeUtility.findNodeMatching(current, it => it.classList.contains('chat-message') && it.attributes.getNamedItem('data-message-id')); + return MournbladeUtility.findNodeMatching(current, it => it.classList.contains('chat-message') && it.attributes.getNamedItem('data-message-id')) } static findNodeMatching(current, predicate) { @@ -288,12 +295,11 @@ export class MournbladeUtility { /* -------------------------------------------- */ static async rollMournblade(rollData) { - let actor = game.actors.get(rollData.actorId) + let actor = game.actors.get(rollData.actorId) if (rollData.attrKey == "tochoose") { // No attr selected, force address rollData.attrKey = "adr" } if ( !rollData.attr) { - console.log("ATTR!!!", rollData.attrKey) rollData.actionImg = "systems/fvtt-mournblade/assets/icons/" + actor.data.data.attributs[rollData.attrKey].labelnorm + ".webp" rollData.attr = duplicate(actor.data.data.attributs[rollData.attrKey]) } @@ -306,6 +312,7 @@ export class MournbladeUtility { } } if (rollData.competence) { + rollData.predilections = duplicate( rollData.competence.data.predilections.filter( pred => !pred.used) || [] ) let compmod = (rollData.competence.data.niveau == 0) ? -3 : 0 rollData.diceFormula += `+${rollData.attr.value}+${rollData.competence.data.niveau}+${rollData.modificateur}+${compmod}` } else { @@ -523,6 +530,16 @@ export class MournbladeUtility { let actor = game.actors.get(rollData.actorId) return ( !rollData.isReroll && actor.getEclat() > 0 && actor.getAlignement() == "chaotique") } + let hasPredilection = function (li) { + let message = game.messages.get(li.attr("data-message-id")) + let rollData = message.getFlag("world", "mournblade-roll") + let actor = game.actors.get(rollData.actorId) + if ( rollData.competence) { + let nbPred = rollData.competence.data.predilections.filter( pred => !pred.used).length + return ( !rollData.isReroll && rollData.competence && nbPred > 0 ) + } + return false + } options.push( { @@ -556,14 +573,6 @@ export class MournbladeUtility { callback: li => MournbladeUtility.applyEclatRoll(li, -1, "+10") } ) - options.push( - { - name: "Ajouter +1d20(1 Point d'Eclat)", - icon: "", - condition: canApply && canApplyPEChaotique, - callback: li => MournbladeUtility.applyEclatRoll(li, -1, "+1d20") - } - ) return options } diff --git a/styles/simple.css b/styles/simple.css index 4727ff9..7488c16 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -1116,7 +1116,7 @@ ul, li { cursor: pointer; color: #ffffff; font-size: 0.8rem; - padding: 4px 12px 0px 12px; + padding: 4px 4px 0px 4px; text-decoration: none; text-shadow: 0px 1px 0px #4d3534; position: relative; diff --git a/system.json b/system.json index cc86b02..09fccb1 100644 --- a/system.json +++ b/system.json @@ -17,7 +17,7 @@ "library": false, "license": "LICENSE.txt", "manifest": "https://www.uberwald.me/gitea/public/fvtt-mournblade/raw/branch/main/system.json", - "download": "https://www.uberwald.me/gitea/public/fvtt-mournblade/archive/fvtt-mournblade-0.0.11.zip", + "download": "https://www.uberwald.me/gitea/public/fvtt-mournblade/archive/fvtt-mournblade-0.0.13.zip", "manifestPlusVersion": "1.0.0", "media": [], "minimumCoreVersion": "0.8.0", @@ -70,9 +70,9 @@ "styles": [ "styles/simple.css" ], - "templateVersion": 9, + "templateVersion": 11, "title": "Mournblade", "url": "", - "version": "0.0.11", + "version": "0.0.13", "background": "./images/ui/mournblade_welcome.webp" } \ No newline at end of file diff --git a/template.json b/template.json index 5144c7b..348f97b 100644 --- a/template.json +++ b/template.json @@ -105,14 +105,10 @@ "description": "" } }, - "types": [ "arme", "competence", "protection", "pacte", "traitchaotique", "monnaie", "don", "tendance", "rune", "predilection", "equipement", "capacite"], + "types": [ "arme", "competence", "protection", "pacte", "traitchaotique", "monnaie", "don", "tendance", "rune", "equipement", "capacite"], "capacite":{ "templates": [ "base" ] }, - "predilection": { - "competence": "", - "templates": [ "base" ] - }, "equipement": { "rarete": 0, "prix": 0, @@ -137,6 +133,7 @@ "attribut1": "", "attribut2": "", "attribut3": "", + "predilections": [], "templates": [ "base" ] }, "protection": { diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index 9bfb23b..642ec58 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -80,6 +80,16 @@ +