From 1bbefd349937cd7eb8e198df0802abe04322b623 Mon Sep 17 00:00:00 2001 From: LeRatierBretonnien Date: Sun, 25 Dec 2022 18:00:42 +0100 Subject: [PATCH] Astrologie ! --- lang/fr.json | 4 + module/actor/actor-sheet.js | 1 + module/actor/actor.js | 11 +- module/controllers/bol-rolls.js | 60 +++++-- module/system/bol-character-summary.js | 36 ++++- module/system/bol-utility.js | 32 +++- module/system/helpers.js | 13 +- module/system/templates.js | 1 + system.json | 4 +- templates/actor/parts/tabs/actor-biodata.hbs | 148 +++++++++++++----- .../parts/tabs/actor-horoscope-group.hbs | 26 +++ .../actor/parts/tabs/actor-spellalchemy.hbs | 5 +- .../apps/character-summary-template.html | 27 ++++ templates/dialogs/alchemy-roll-dialog.hbs | 2 + templates/dialogs/attribute-roll-dialog.hbs | 4 +- templates/dialogs/horoscope-roll-part.hbs | 26 ++- templates/dialogs/spell-roll-dialog.hbs | 2 + templates/dialogs/weapon-roll-dialog.hbs | 2 + 18 files changed, 336 insertions(+), 68 deletions(-) create mode 100644 templates/actor/parts/tabs/actor-horoscope-group.hbs diff --git a/lang/fr.json b/lang/fr.json index cc15ce7..b5f1637 100644 --- a/lang/fr.json +++ b/lang/fr.json @@ -163,6 +163,10 @@ "BOL.ui.minor": "Mineur", "BOL.ui.major": "Majeur", "BOL.ui.majorgroup": "Majeur de Groupe", + "BOL.ui.horoscopeGroup": "Horoscopes de Groupe", + "BOL.ui.horoscopeDiceRemaining": "Dés restants", + "BOL.ui.horoscopeDiceMax": "Dés Max", + "BOL.ui.astrologyNoPoints": "Vous n'avez pas assez de Points d'Astrologie!", "BOL.ui.advance": "Avancement", "BOL.ui.isbonusdice": "Fourni un dé bonus?", diff --git a/module/actor/actor-sheet.js b/module/actor/actor-sheet.js index c57bf4b..43157f3 100644 --- a/module/actor/actor-sheet.js +++ b/module/actor/actor-sheet.js @@ -160,6 +160,7 @@ export class BoLActorSheet extends ActorSheet { formData.isAstrologer = this.actor.isAstrologer() formData.isMysteries = formData.isSorcerer || formData.isAlchemist || formData.isAstrologer formData.isPriest = this.actor.isPriest() + formData.horoscopeGroupList = game.settings.get("bol", "horoscope-group") formData.isGM = game.user.isGM diff --git a/module/actor/actor.js b/module/actor/actor.js index 02d5ac5..f4ae54d 100644 --- a/module/actor/actor.js +++ b/module/actor/actor.js @@ -481,15 +481,21 @@ export class BoLActor extends Actor { let rID = randomID(16) let horoscopes = duplicate(game.settings.get("bol", "horoscope-group")) horoscopes[rID] = { + id: rID, name: game.i18n.localize("BOL.ui.groupHoroscope") + this.name, maxDice: rollData.careerBonus, availableDice: rollData.careerBonus, type: (rollData.isSuccess) ? "bonus": "malus" } + game.settings.set("bol", "horoscope-group", horoscopes) } } + /*-------------------------------------------- */ + getAstrologyPoints() { + return this.system.resources.astrologypoints.value + } /*-------------------------------------------- */ removeHoroscopeMinor( rollData) { let toDel = [] @@ -619,11 +625,6 @@ export class BoLActor extends Actor { "label": "BOL.featureSubtypes.effects", "ranked": false, "items": this.boleffects - }, - "horoscopes": { - "label": "BOL.featureSubtypes.horoscope", - "ranked": false, - "items": this.horoscopes } } } diff --git a/module/controllers/bol-rolls.js b/module/controllers/bol-rolls.js index 6666de1..15a3764 100644 --- a/module/controllers/bol-rolls.js +++ b/module/controllers/bol-rolls.js @@ -30,6 +30,19 @@ export class BoLRoll { return appEffects } + /* -------------------------------------------- */ + static buildHoroscopeGroupList() { + let horoscopes = game.settings.get("bol", "horoscope-group") + let horoList = [ { id: -1, name: "Aucun", type: "malus", nbDice: 0 }] + for (let id in horoscopes) { + let horo = horoscopes[id] + for (let i=0; i actor.getAstrologyPoints() ) { + ui.notifications.warn(game.i18n.localize("BOL.ui.astrologyNoPoints")) + return + } let rollData = this.getCommonRollData(actor, "horoscope", actor.system.attributes.mind) rollData.careerBonus = actor.getAstrologerBonus() rollData.horoscopeType = horoscopeType rollData.horoscopeTypeLabel = "BOL.ui."+horoscopeType - rollData.astrologyPointsCost = (horoscopeType == "minor") ? 1 : 2 + rollData.astrologyPointsCost = cost rollData.label = game.i18n.localize('BOL.ui.makeHoroscope') rollData.description = game.i18n.localize('BOL.ui.makeHoroscope') + " " + game.i18n.localize(rollData.horoscopeTypeLabel) @@ -276,7 +295,10 @@ export class BoLRoll { } this.rollData.bmDice += this.rollData.horoscopeBonus this.rollData.bmDice -= this.rollData.horoscopeMalus - + if ( this.rollData.selectedGroupHoroscopeIndex && this.rollData.selectedGroupHoroscopeIndex > 0) { + let horo = this.rollData.horoscopeGroupList[this.rollData.selectedGroupHoroscopeIndex] + this.rollData.bmDice += (horo.type == "malus") ? -horo.nbDice : horo.nbDice; + } // Keep track of the final effect modifier this.rollData.effectModifier = effectModifier @@ -425,21 +447,29 @@ export class BoLRoll { this.updateTotalDice() }) html.find('#horoscope-bonus-applied').change((event) => { - if (event.currentTarget.value != undefined) { - this.rollData.selectedHoroscope.push( duplicate(this.rollData.horoscopeBonusList[Number(event.currentTarget.value)]) ) - } + this.rollData.selectedHoroscope = [] + for (let option of event.currentTarget.selectedOptions) { + this.rollData.selectedHoroscope.push( duplicate(this.rollData.horoscopeBonusList[Number(option.index)]) ) + } let horoscopes = $('#horoscope-bonus-applied').val() this.rollData.horoscopeBonus = (!horoscopes || horoscopes.length == 0) ? 0 : horoscopes.length this.updateTotalDice() }) + html.find('#horoscope-malus-applied').change((event) => { - if (event.currentTarget.value != undefined) { - this.rollData.selectedHoroscope.push( duplicate(this.rollData.horoscopeMalusList[Number(event.currentTarget.value)]) ) - } + this.rollData.selectedHoroscope = [] + for (let option of event.currentTarget.selectedOptions) { + this.rollData.selectedHoroscope.push( duplicate(this.rollData.horoscopeBonusList[Number(option.index)]) ) + } let horoscopes = $('#horoscope-malus-applied').val() this.rollData.horoscopeMalus = (!horoscopes || horoscopes.length == 0) ? 0 : horoscopes.length this.updateTotalDice() }) + html.find('#horoscope-group-applied').change((event) => { + this.rollData.selectedGroupHoroscopeIndex = event.currentTarget.value + this.updateTotalDice() + }) + } @@ -608,7 +638,6 @@ export class BoLDefaultRoll { if (this.rollData.reroll == undefined) { this.rollData.reroll = actor.heroReroll() } - if (this.rollData.registerInit) { actor.registerInit(this.rollData) this.rollData.initiativeRank = actor.getInitiativeRank(this.rollData) @@ -616,20 +645,25 @@ export class BoLDefaultRoll { if (this.rollData.isSuccess && this.rollData.mode == "spell") { // PP cost management this.rollData.remainingPP = actor.spendPowerPoint(this.rollData.ppCost + this.rollData.ppCostArmor) } + if (this.rollData.mode == "alchemy") { // PP cost management actor.resetAlchemyStatus(this.rollData.alchemy._id) } if (this.rollData.mode == "bougette" && this.rollData.isFailure) { actor.decBougette() } + + await this.sendChatMessage() + if (this.rollData.mode == "horoscope") { // PP cost management actor.manageHoroscope(this.rollData) } if (this.rollData.selectedHoroscope.length > 0) { // PP cost management actor.removeHoroscopeMinor(this.rollData) } - - await this.sendChatMessage() + if (this.rollData.selectedGroupHoroscopeIndex && this.rollData.selectedGroupHoroscopeIndex > 0) { // PP cost management + BoLUtility.removeGroupHoroscope(this.rollData) + } } /* -------------------------------------------- */ diff --git a/module/system/bol-character-summary.js b/module/system/bol-character-summary.js index 3d763fa..c0f9878 100644 --- a/module/system/bol-character-summary.js +++ b/module/system/bol-character-summary.js @@ -9,6 +9,12 @@ export class BoLCharacterSummary extends Application { static displayPCSummary(){ game.bol.charSummary.render(true) } + /* -------------------------------------------- */ + updatePCSummary(){ + if ( this.rendered) { + this.render(true) + } + } /* -------------------------------------------- */ static createSummaryPos() { @@ -60,6 +66,7 @@ export class BoLCharacterSummary extends Application { } } formData.config = game.bol.config + formData.horoscopeGroupList = game.settings.get("bol", "horoscope-group") if ( toUpdate ) { this.settings.npcList = newList @@ -123,6 +130,33 @@ export class BoLCharacterSummary extends Application { game.bol.charSummary.updateNPC() }) - } + html.find('#horoscope-group-edit-available').change(event => { + const horoId = $(event.currentTarget).data("horo-id") + let newValue = event.currentTarget.value + let horoscopes = duplicate(game.settings.get("bol", "horoscope-group")) + if ( horoId && horoscopes[horoId]) { + horoscopes[horoId].availableDice = Number(newValue) + if (newValue <= 0) { + horoscopes[horoId] = undefined + } + game.settings.set("bol", "horoscope-group", horoscopes) + setTimeout(function() { BoLUtility.updateSheets()}, 800 ) + } + }) + + html.find('#horoscope-group-edit-max').change(event => { + const horoId = $(event.currentTarget).data("horo-id") + let newValue = event.currentTarget.value + let horoscopes = duplicate(game.settings.get("bol", "horoscope-group")) + if ( horoId && horoscopes[horoId]) { + horoscopes[horoId].maxDice = Number(newValue) + if (newValue <= 0) { + horoscopes[horoId] = undefined + } + game.settings.set("bol", "horoscope-group", horoscopes) + setTimeout(function() { BoLUtility.updateSheets()}, 800 ) + } + }) + } } \ No newline at end of file diff --git a/module/system/bol-utility.js b/module/system/bol-utility.js index 54e2f51..0feeb70 100644 --- a/module/system/bol-utility.js +++ b/module/system/bol-utility.js @@ -32,7 +32,7 @@ export class BoLUtility { name: "character-summary-data", scope: "world", config: false, - default: { npcList : [], x: 200, y: 200}, + default: { npcList: [], x: 200, y: 200 }, type: Object }) game.settings.register("bol", "logoActorSheet", { @@ -84,8 +84,8 @@ export class BoLUtility { return this.logoTopLeft } /* -------------------------------------------- */ - static getActorFromRollData(rollData) { - let actor = game.actors.get( rollData.actorId) + static getActorFromRollData(rollData) { + let actor = game.actors.get(rollData.actorId) if (rollData.tokenId) { let token = canvas.tokens.placeables.find(t => t.id == rollData.tokenId) if (token) { @@ -185,7 +185,7 @@ export class BoLUtility { static getOtherWhisperRecipients(name) { let users = [] for (let user of game.users) { - if ( !user.isGM && user.name != name) { + if (!user.isGM && user.name != name) { users.push(user.id) } } @@ -585,5 +585,29 @@ export class BoLUtility { return item } + /* -------------------------------------------- */ + static updateSheets() { + // Then force opened actor refresh if needed + for (let actor of game.actors) { + if (actor.sheet.rendered) { + actor.sheet.render() + } + } + game.bol.charSummary.updatePCSummary() // Refresh if needed + } + /* -------------------------------------------- */ + static removeGroupHoroscope(rollData) { + let horo = rollData.horoscopeGroupList[rollData.selectedGroupHoroscopeIndex] + let horoscopes = duplicate(game.settings.get("bol", "horoscope-group")) + let toChange = duplicate(horoscopes[horo.id]) + toChange.availableDice -= horo.nbDice // Remove the dice + if (toChange.availableDice <= 0) { + horoscopes[horo.id] = undefined + } else { + horoscopes[horo.id] = toChange + } + game.settings.set("bol", "horoscope-group", horoscopes) + this.updateSheets() + } } diff --git a/module/system/helpers.js b/module/system/helpers.js index e984deb..8d9d7e8 100644 --- a/module/system/helpers.js +++ b/module/system/helpers.js @@ -76,6 +76,10 @@ export const registerHandlebarsHelpers = function () { Handlebars.registerHelper('count', function (list) { return list.length; }) + Handlebars.registerHelper('countKeys', function (obj) { + return Object.keys(obj).length; + }) + Handlebars.registerHelper('isEnabled', function (configKey) { return game.settings.get("bol", configKey); }) @@ -129,7 +133,14 @@ export const registerHandlebarsHelpers = function () { } return false }) - + Handlebars.registerHelper('upperFirst', function (text) { + if (typeof text !== 'string') return text + return text.charAt(0).toUpperCase() + text.slice(1) + }) + Handlebars.registerHelper('upperFirstOnly', function (text) { + if (typeof text !== 'string') return text + return text.charAt(0).toUpperCase() + }) } \ No newline at end of file diff --git a/module/system/templates.js b/module/system/templates.js index bed8b82..b111daf 100644 --- a/module/system/templates.js +++ b/module/system/templates.js @@ -16,6 +16,7 @@ export const preloadHandlebarsTemplates = async function () { "systems/bol/templates/actor/parts/tabs/actor-equipment.hbs", "systems/bol/templates/actor/parts/tabs/actor-spellalchemy.hbs", "systems/bol/templates/actor/parts/tabs/actor-biodata.hbs", + "systems/bol/templates/actor/parts/tabs/actor-horoscope-group.hbs", "systems/bol/templates/actor/parts/tabs/creature-stats.hbs", "systems/bol/templates/actor/parts/tabs/creature-actions.hbs", "systems/bol/templates/actor/parts/tabs/vehicle-stats.hbs", diff --git a/system.json b/system.json index 72cc202..dcfb9ba 100644 --- a/system.json +++ b/system.json @@ -14,7 +14,7 @@ ], "url": "https://www.uberwald.me/gitea/public/bol", "license": "LICENSE.txt", - "version": "10.4.15", + "version": "10.5.0", "compatibility": { "minimum": "10", "verified": "10", @@ -203,7 +203,7 @@ ], "socket": true, "manifest": "https://www.uberwald.me/gitea/public/bol/raw/v10/system.json", - "download": "https://www.uberwald.me/gitea/public/bol/archive/bol-v10.4.15.zip", + "download": "https://www.uberwald.me/gitea/public/bol/archive/bol-v10.5.0.zip", "background": "systems/bol/ui/page_accueil.webp", "gridDistance": 1.5, "gridUnits": "m", diff --git a/templates/actor/parts/tabs/actor-biodata.hbs b/templates/actor/parts/tabs/actor-biodata.hbs index 9f699ef..549da35 100644 --- a/templates/actor/parts/tabs/actor-biodata.hbs +++ b/templates/actor/parts/tabs/actor-biodata.hbs @@ -1,52 +1,124 @@ -
    - {{#if (ne charType "creature")}} -
  1. -
    {{localize "BOL.ui.biosize"}}
    -
    -
    {{localize "BOL.ui.bioweight"}}
    -
    -
    {{localize "BOL.ui.bioage"}}
    -
    +
      + {{#if (ne charType 'creature')}} +
    1. +
      + {{localize 'BOL.ui.biosize'}} +
      +
      + +
      +
      + {{localize 'BOL.ui.bioweight'}} +
      +
      + +
      +
      + {{localize 'BOL.ui.bioage'}} +
      +
      + +
    2. -
    3. -
      {{localize "BOL.ui.biohair"}}
      -
      -
      {{localize "BOL.ui.bioeyes"}}
      -
      +
    4. +
      + {{localize 'BOL.ui.biohair'}} +
      +
      + +
      +
      + {{localize 'BOL.ui.bioeyes'}} +
      +
      + +
    5. -
    6. -
      {{localize "BOL.ui.biosigns"}}
      -
      +
    7. +
      + {{localize 'BOL.ui.biosigns'}} +
      +
      + +
    8. {{else}} -
    9. -
      Taille
      -
      - + {{#select details.size}} + {{#each config.creatureSize as |value id|}} + + {{/each}} + {{/select}}
    10. {{/if}} -
    -
      -
    1. -
      {{localize "BOL.ui.biodescription"}}
      -
      +
    + +{{#if (and (not isAstrologer) (countKeys horoscopeGroupList))}} + {{> "systems/bol/templates/actor/parts/tabs/actor-horoscope-group.hbs"}} +{{/if}} + +
      +
    1. +
      + {{localize 'BOL.ui.biodescription'}} +
      +
    -{{editor biography target="system.details.biography" button=true owner=owner -editable=editable}} +{{editor + biography + target='system.details.biography' + button=true + owner=owner + editable=editable +}} -
      -
    1. -
      {{localize "BOL.ui.bionotes"}}
      -
      +
        +
      1. +
        + {{localize 'BOL.ui.bionotes'}} +
        +
      -{{editor notes target="system.details.notes" button=true owner=owner editable=editable}} \ No newline at end of file +{{editor + notes + target='system.details.notes' + button=true + owner=owner + editable=editable +}} \ No newline at end of file diff --git a/templates/actor/parts/tabs/actor-horoscope-group.hbs b/templates/actor/parts/tabs/actor-horoscope-group.hbs new file mode 100644 index 0000000..eda9d54 --- /dev/null +++ b/templates/actor/parts/tabs/actor-horoscope-group.hbs @@ -0,0 +1,26 @@ +
        +
      1. +
        {{localize "BOL.ui.horoscopeGroup"}}
        +
        {{localize "BOL.ui.type"}}
        +
        {{localize "BOL.ui.horoscopeDiceRemaining"}}
        +
        {{localize "BOL.ui.horoscopeDiceMax"}}
        +
        +
      2. + {{#each horoscopeGroupList as |horo id|}} +
      3. +

        +
        {{horo.name}} +

        +
        + {{upperFirst horo.type}} +
        +
        + {{horo.availableDice}} +
        +
        + {{horo.maxDice}} +
        +
        +
      4. + {{/each}} +
      diff --git a/templates/actor/parts/tabs/actor-spellalchemy.hbs b/templates/actor/parts/tabs/actor-spellalchemy.hbs index 5307b2c..1612937 100644 --- a/templates/actor/parts/tabs/actor-spellalchemy.hbs +++ b/templates/actor/parts/tabs/actor-spellalchemy.hbs @@ -105,7 +105,7 @@
      {{localize "BOL.ui.answer"}}
    2. - {{#each horoscopes as |item id|}} + {{#each horoscopes as |item id|}}
    3. {{item.name}} @@ -128,4 +128,7 @@

    4. {{/each}}
    + + {{> "systems/bol/templates/actor/parts/tabs/actor-horoscope-group.hbs"}} + {{/if}} \ No newline at end of file diff --git a/templates/apps/character-summary-template.html b/templates/apps/character-summary-template.html index 78e4c71..854364b 100644 --- a/templates/apps/character-summary-template.html +++ b/templates/apps/character-summary-template.html @@ -79,6 +79,33 @@
  2. {{/each}} + + {{#if (countKeys horoscopeGroupList)}} +
  3. +
    {{localize "BOL.ui.horoscopeGroup"}}
    +
    {{localize "BOL.ui.type"}}
    +
    {{localize "BOL.ui.horoscopeDiceRemaining"}}
    +
    {{localize "BOL.ui.horoscopeDiceMax"}}
    +
    +
  4. + {{#each horoscopeGroupList as |horo id|}} +
  5. +

    +
    {{horo.name}} +

    +
    + {{upperFirst horo.type}} +
    +
    + +
    +
    + +
    +
    +
  6. + {{/each}} + {{/if}}
diff --git a/templates/dialogs/alchemy-roll-dialog.hbs b/templates/dialogs/alchemy-roll-dialog.hbs index bfe82c2..003dde1 100644 --- a/templates/dialogs/alchemy-roll-dialog.hbs +++ b/templates/dialogs/alchemy-roll-dialog.hbs @@ -37,6 +37,8 @@ {{> "systems/bol/templates/dialogs/effect-roll-part.hbs"}} + {{> "systems/bol/templates/dialogs/horoscope-roll-part.hbs"}} + {{> "systems/bol/templates/dialogs/adv-roll-part.hbs"}} {{> "systems/bol/templates/dialogs/mod-roll-part.hbs"}} diff --git a/templates/dialogs/attribute-roll-dialog.hbs b/templates/dialogs/attribute-roll-dialog.hbs index 8612d35..e276787 100644 --- a/templates/dialogs/attribute-roll-dialog.hbs +++ b/templates/dialogs/attribute-roll-dialog.hbs @@ -16,10 +16,10 @@ {{> "systems/bol/templates/dialogs/flaws-roll-part.hbs"}} - {{> "systems/bol/templates/dialogs/horoscope-roll-part.hbs"}} - {{> "systems/bol/templates/dialogs/effect-roll-part.hbs"}} + {{> "systems/bol/templates/dialogs/horoscope-roll-part.hbs"}} + {{> "systems/bol/templates/dialogs/adv-roll-part.hbs"}} {{> "systems/bol/templates/dialogs/mod-roll-part.hbs"}} diff --git a/templates/dialogs/horoscope-roll-part.hbs b/templates/dialogs/horoscope-roll-part.hbs index c2fc51b..3e1af3f 100644 --- a/templates/dialogs/horoscope-roll-part.hbs +++ b/templates/dialogs/horoscope-roll-part.hbs @@ -46,4 +46,28 @@ -{{/if}} \ No newline at end of file +{{/if}} + +{{#if (countKeys horoscopeGroupList)}} +
+
+ +
+
+ +
+
+{{/if}} diff --git a/templates/dialogs/spell-roll-dialog.hbs b/templates/dialogs/spell-roll-dialog.hbs index 791d556..f77ab19 100644 --- a/templates/dialogs/spell-roll-dialog.hbs +++ b/templates/dialogs/spell-roll-dialog.hbs @@ -65,6 +65,8 @@ {{> "systems/bol/templates/dialogs/flaws-roll-part.hbs"}} + {{> "systems/bol/templates/dialogs/horoscope-roll-part.hbs"}} + {{> "systems/bol/templates/dialogs/adv-roll-part.hbs"}} {{> "systems/bol/templates/dialogs/mod-roll-part.hbs"}} diff --git a/templates/dialogs/weapon-roll-dialog.hbs b/templates/dialogs/weapon-roll-dialog.hbs index 20ccf5e..1d0335b 100644 --- a/templates/dialogs/weapon-roll-dialog.hbs +++ b/templates/dialogs/weapon-roll-dialog.hbs @@ -58,6 +58,8 @@ {{> "systems/bol/templates/dialogs/effect-roll-part.hbs"}} + {{> "systems/bol/templates/dialogs/horoscope-roll-part.hbs"}} + {{> "systems/bol/templates/dialogs/adv-roll-part.hbs"}} {{> "systems/bol/templates/dialogs/mod-roll-part.hbs"}}