From 32ff14f40d06d64e1b7d70f4c08c91565e497041 Mon Sep 17 00:00:00 2001 From: Jason Hardin Date: Thu, 5 Nov 2020 22:36:50 -0500 Subject: [PATCH] enhancements and fixes --- lang/de.json | 4 +- lang/en.json | 4 +- lang/fr.json | 4 +- module/actor/sheets/base.js | 146 ++++++++++++++----------- module/apps/advantage-selector.js | 5 +- module/config.js | 17 +++ module/migration.js | 9 +- module/svnsea2e.js | 2 +- system.json | 4 +- template.json | 6 +- templates/chats/skill-roll-dialog.html | 10 +- 11 files changed, 131 insertions(+), 80 deletions(-) diff --git a/lang/de.json b/lang/de.json index 2322e1b..404f903 100644 --- a/lang/de.json +++ b/lang/de.json @@ -318,5 +318,7 @@ "SVNSEA2E.SorceryAlquimia": "Alquimia", "SETTINGS.None": "Keiner", "SVNSEA2E.Great": "Toll", - "SVNSEA2E.Small": "Klein" + "SVNSEA2E.Small": "Klein", + "SVNSEA2E.IncreaseThreshold": "Erhöhen Sie den Schwellenwert um 5", + "SVNSEA2E.GMIncreasedThreshold": "(GM erhöhte den Schwellenwert um 5)" } diff --git a/lang/en.json b/lang/en.json index f42fef3..389a110 100644 --- a/lang/en.json +++ b/lang/en.json @@ -326,5 +326,7 @@ "SVNSEA2E.Fear": "Fear Rank", "SETTINGS.None": "None", "SVNSEA2E.Great": "Great", - "SVNSEA2E.Small": "Small" + "SVNSEA2E.Small": "Small", + "SVNSEA2E.IncreaseThreshold": "Increase Threshold by 5", + "SVNSEA2E.GMIncreasedThreshold": "(GM increased the threshold by 5)" } diff --git a/lang/fr.json b/lang/fr.json index 43db7cf..a1eb434 100644 --- a/lang/fr.json +++ b/lang/fr.json @@ -318,5 +318,7 @@ "SVNSEA2E.SorceryAlquimia": "Alquimia", "SETTINGS.None": "Aucun", "SVNSEA2E.Great": "Génial", - "SVNSEA2E.Small": "Petit" + "SVNSEA2E.Small": "Petit", + "SVNSEA2E.IncreaseThreshold": "Augmenter le seuil de 5", + "SVNSEA2E.GMIncreasedThreshold": "(GM a augmenté le seuil de 5)" } diff --git a/module/actor/sheets/base.js b/module/actor/sheets/base.js index 02966ca..cbebd8f 100644 --- a/module/actor/sheets/base.js +++ b/module/actor/sheets/base.js @@ -159,7 +159,6 @@ export default class ActorSheetSS2e extends ActorSheet { * @private */ _processCircle(event){ - console.log(event) const actor = this.actor const adata = actor.data.data const data = event.target.dataset @@ -180,15 +179,14 @@ export default class ActorSheetSS2e extends ActorSheet { } break; case 'corrupt': - tval = adata[data.key] == 1 + tval = adata[data.key] break; case 'fear': tval = adata[data.key].value break; } - console.log(data.name, tval) + if (parseInt(tval) == 1){ - console.log(tval) data.value = 0 } } @@ -234,35 +232,17 @@ export default class ActorSheetSS2e extends ActorSheet { dwounds = data.dwounds.value const dwestimate = Math.trunc(wounds / 5) - if (dwestimate > data.dwounds.value){ - dwounds = dwestimate - } + if (dwestimate > data.dwounds.value) dwounds = dwestimate - if(edata.value == 1 && data.wounds.value == 1){ - wounds = 0 - } + if(edata.value == 1 && data.wounds.value == 1) wounds = 0 } else { // If the event dramatic wound is larger than the current dramatic wound // increase the dramatic wound and the regular wounds - if(edata.value > data.dwounds.value){ - dwounds = edata.value - // Only increase the regular wounds if they are less than 5x the dramatic wounds. - if((edata.value * 5) > data.wounds.value){ - wounds = edata.value * 5 - } else { - wounds = data.wounds.value - } - } else if(edata.value == data.dwounds.value){ - dwounds = data.dwounds.value - 1 - wounds = data.wounds.value - } else { - dwounds = edata.value - if(data.wounds.value > (edata.value * 5)){ - wounds = edata.value * 5 - } else { - wounds = data.wounds.value - } - } + if(edata.value > data.dwounds.value) dwounds = edata.value + else if(edata.value == data.dwounds.value) dwounds = data.dwounds.value - 1 + else dwounds = edata.value + + if(data.wounds.value > (edata.value * 5)) wounds = edata.value * 5 } updateObj['data.wounds.value'] = wounds @@ -665,7 +645,8 @@ export default class ActorSheetSS2e extends ActorSheet { // if the character's skill is 4 or more then they can get 2 raises when matching to a 15 if (skillvalue >= 4) rolldata['threshold'] = 15 - if (skillvalue === 5 || data.dwounds === 3) rolldata['explode'] = true + + if (skillvalue == 5 || data.dwounds.value == 3) rolldata['explode'] = true const traits = {} for (const trait of Object.keys(data.traits)) { @@ -817,19 +798,59 @@ export default class ActorSheetSS2e extends ActorSheet { } // Increase the raise value based on the threshold matched. - const _addRaise = function (threshold = 10) { + const _addRaise = function (threshold = 10, incThreshold = false) { let raises = 1 let combos = [] - if (threshold === 15) raises++ + if ((threshold === 15 && !incThreshold) || (threshold === 20 && incThreshold)) raises++ return raises } - const nd = parseInt(rolldata['skilldice']) + parseInt(form.trait.value) + parseInt(form.bonusDice.value) + const _leftOverDice = function (rolls, threshold = 10, incThreshold = false){ + let total = 0 + let combotxt = '' + let data = { + 'rolls': [], + 'combos': [], + 'raises': 0 + } + + //Loop through the left over rolls and create die combos that are greater than the threshold + while (i--) { + if (i > 0 && total === 0) { + total += rolls[0] + rolls[i] + combotxt = rolls[0].toString() + ' + ' + rolls[i].toString() + rolls.splice(i, 1) + rolls.splice(0, 1) + i-- // length needs to shrink twice because we removed two elements from the array + } else { + total += rolls[0] + combotxt = combotxt + ' + ' + rolls[0].toString() + rolls.splice(0, 1) + } + + if (total >= threshold) { + data['raises'] += _addRaise(threshold, incThreshold) + data['combos'].push(combotxt) + combotxt = '' + total = 0 + } + } + + data['rolls'] = rolls + return data + } + const nd = parseInt(rolldata['skilldice']) + parseInt(form.trait.value) + parseInt(form.bonusDice.value) + let incThreshold =form.increaseThreshold.checked let d10 = new Die({faces: 10, number: nd}).evaluate() let exploded = false + + // GM spent a danger point and increased the threshold by 5 + if(incThreshold) rolldata.threshold += 5 + let matcharr = CONFIG.SVNSEA2E.match10 if(rolldata['threshold'] == 15) matcharr = CONFIG.SVNSEA2E.match15 + if(rolldata['threshold'] == 20) matcharr = CONFIG.SVNSEA2E.match20 // explode the dice on 10s if the character has a high enough skill or has taken 3 dynamic wounds if (rolldata['explode']) { @@ -855,6 +876,8 @@ export default class ActorSheetSS2e extends ActorSheet { raises++ combos.push('10') rolls.splice(i, 1) + } else if (rolls[i] < 10) { + break } } } @@ -863,7 +886,7 @@ export default class ActorSheetSS2e extends ActorSheet { for (let c = 0; c < matcharr.two.length; c++) { let vals = _getIndexes(rolls, matcharr.two[c]) while (vals[0] > -1 && vals[1] > -1) { - raises += _addRaise(rolldata['threshold']) + raises += _addRaise(rolldata['threshold'], incThreshold) combos.push(rolls[vals[0]].toString() + ' + ' + rolls[vals[1]].toString()) rolls.splice(vals[0], 1) rolls.splice(rolls.indexOf(matcharr.two[c][1]), 1) @@ -875,7 +898,7 @@ export default class ActorSheetSS2e extends ActorSheet { for (let c = 0; c < matcharr.three.length; c++) { var vals = _getIndexes(rolls, matcharr.three[c]) while (vals[0] > -1 && vals[1] > -1 && vals[2] > -1) { - raises += _addRaise(rolldata['threshold']) + raises += _addRaise(rolldata['threshold'], incThreshold) combos.push(rolls[vals[0]].toString() + ' + ' + rolls[vals[1]].toString() + ' + ' + rolls[vals[2]].toString()) rolls.splice(vals[0], 1) rolls.splice(rolls.indexOf(matcharr.three[c][1]), 1) @@ -888,6 +911,11 @@ export default class ActorSheetSS2e extends ActorSheet { let rerolled = false let reroll = '' + const sortedRolls = d10.values + sortedRolls.sort(function (a, b) { + return a - b + }) + // reroll the first die in our results if it is less than 5 if (i > 0 && rolldata['reroll'] && rolls[0] < 5) { const orgroll = rolls[0] @@ -897,42 +925,36 @@ export default class ActorSheetSS2e extends ActorSheet { roll2: rolls[0] }) rerolled = true - } - - let total = 0 - let combotxt = '' - //Loop through the left over rolls and create die combos that are greater than the threshold - while (i--) { - if (i > 0 && total === 0) { - total += rolls[0] + rolls[i] - combotxt = rolls[0].toString() + ' + ' + rolls[i].toString() - rolls.splice(i, 1) - rolls.splice(0, 1) - i-- // length needs to shrink twice because we removed two elements from the array - } else { - total += rolls[0] - combotxt = combotxt + ' + ' + rolls[0].toString() - rolls.splice(0, 1) + for(let k = 0; k < sortedRolls.length && sortedRolls[k] < 5; k++){ + if(sortedRolls[k] == orgroll) sortedRolls[k] = rolls[0] } - if (total >= rolldata['threshold']) { - raises += _addRaise(rolldata['threshold']) - combos.push(combotxt) - combotxt = '' - total = 0 - } + sortedRolls.sort(function (a, b) { + return a - b + }) } - const sortedRolls = d10.values - sortedRolls.sort(function (a, b) { - return a - b - }) + let leftdata = _leftOverDice(rolls, rolldata['threshold'], incThreshold) + combos.push(...leftdata['combos']) + raises += leftdata['raises'] + + // If the threshold is 15 and we have left over dice check for matching 10s for a single rais + if(leftdata['rolls'].length > 0 && ((!incThreshold && rolldata['threshold'] == 15) || + (incThreshold && rolldata['threshold'] == 20))) { + let leftdata2 = _leftOverDice(leftdata['rolls'], rolldata['threshold']-5, incThreshold) + combos.push(...leftdata2['combos']) + raises += leftdata2['raises'] + } const messageOptions = { rollmode: 'gmroll' } + let thresholdmsg = rolldata['threshold'].toString() + + if(incThreshold) thresholdmsg = rolldata['threshold'].toString() + ' ' + game.i18n.localize('SVNSEA2E.GMIncreasedThreshold') + const templateData = { actor: actor, raisetxt: (raises > 1) ? game.i18n.localize('SVNSEA2E.Raises') : game.i18n.localize('SVNSEA2E.Raise'), @@ -947,7 +969,7 @@ export default class ActorSheetSS2e extends ActorSheet { rerolled: rerolled, reroll: reroll, threshold: game.i18n.format('SVNSEA2E.RollThreshold', { - threshold: rolldata['threshold'].toString() + threshold: thresholdmsg }) } diff --git a/module/apps/advantage-selector.js b/module/apps/advantage-selector.js index 141d920..60add46 100644 --- a/module/apps/advantage-selector.js +++ b/module/apps/advantage-selector.js @@ -24,7 +24,7 @@ export default class AdvantageSelector extends FormApplication { getData () { // Get current values const advantages = this.object.data.data.advantages - console.log(this.options.choices) + // Populate choices const choices = duplicate(this.options.choices) for (const [k, v] of Object.entries(choices)) { @@ -33,8 +33,7 @@ export default class AdvantageSelector extends FormApplication { chosen: advantages ? advantages.includes(v) : false } } - - console.log(choices) + // Return data return { choices: choices diff --git a/module/config.js b/module/config.js index 40035d4..8d47618 100644 --- a/module/config.js +++ b/module/config.js @@ -285,3 +285,20 @@ SVNSEA2E.match15 = { [5, 5, 5] ] } + +SVNSEA2E.match20 = { + two: [ + [10, 10] + ], + three: [ + [1, 9, 10], + [2, 9, 9], + [3, 8, 9], + [4, 7, 9], + [5, 6, 9], + [4, 8, 8], + [5, 7, 8], + [6, 6, 8], + [6, 7, 7] + ] +} diff --git a/module/migration.js b/module/migration.js index 54fb768..1020a73 100644 --- a/module/migration.js +++ b/module/migration.js @@ -89,6 +89,10 @@ export const migrateCompendium = async function(pack) { export const migrateActorData = function (actor) { const updateData = {} + if (actor.type === 'playercharacter' && actor.data.wealth == null){ + updateData['data.wealth'] = 0 + } + if ((actor.type !== 'dangerpts' && actor.type !== 'brute') && actor.data.wounds.max != 20) { updateData['data.wounds.max'] = 20 } @@ -98,8 +102,8 @@ export const migrateActorData = function (actor) { } if ((actor.type === 'villain' || actor.type === 'monster') && actor.data.traits.strength.max != 10) { - updateData['data.traits.strength.max'] = 10 - updateData['data.traits.influence.max'] = 10 + updateData['data.traits.strength.max'] = 20 + updateData['data.traits.influence.max'] = 20 updateData['data.traits.influence.min'] = 0 } @@ -118,7 +122,6 @@ export const migrateActorData = function (actor) { } if(actor.type === 'ship' && actor.data.crewstatus == null ) { - console.log('ship migration') updateData['data.crewstatus'] = "" } diff --git a/module/svnsea2e.js b/module/svnsea2e.js index 9d4125c..2fe3457 100644 --- a/module/svnsea2e.js +++ b/module/svnsea2e.js @@ -167,7 +167,7 @@ Hooks.once('ready', async function () { if (!currentVersion) { currentVersion = 0.6 } - const NEEDS_MIGRATION_VERSION = 2.3 + const NEEDS_MIGRATION_VERSION = 2.4 // const COMPATIBLE_MIGRATION_VERSION = 0.6 const needMigration = (currentVersion < NEEDS_MIGRATION_VERSION) diff --git a/system.json b/system.json index f53b5ff..57862b6 100644 --- a/system.json +++ b/system.json @@ -2,7 +2,7 @@ "name": "svnsea2e", "title": "7th Sea Second Edition (Unofficial)", "description": "The 7th Sea Second Edition (Unofficial) system for FoundryVTT!", - "version": 2.3, + "version": 2.4, "minimumCoreVersion": "0.7.0", "compatibleCoreVersion": "0.7.5", "templateVersion": 2, @@ -32,6 +32,6 @@ "secondaryTokenAttribute": "dwounds", "url": "https://github.com/Detailing-the-Realm/svnsea2e/", "manifest": "https://raw.githubusercontent.com/Detailing-the-Realm/svnsea2e/master/system.json", - "download": "https://github.com/Detailing-the-Realm/svnsea2e/archive/2.3.zip", + "download": "https://github.com/Detailing-the-Realm/svnsea2e/archive/2.4.zip", "license": "LICENSE.txt" } diff --git a/template.json b/template.json index fb972ae..f4804f4 100644 --- a/template.json +++ b/template.json @@ -151,12 +151,12 @@ "influence": { "value": 5, "min": 0, - "max": 10 + "max": 20 }, "strength": { "value": 5, "min": 1, - "max": 10 + "max": 20 } } } @@ -166,7 +166,7 @@ "wounds": { "value": 0, "min": 0, - "max": 5 + "max": 20 }, "traits": { "strength": { diff --git a/templates/chats/skill-roll-dialog.html b/templates/chats/skill-roll-dialog.html index dbbb42b..3be711c 100644 --- a/templates/chats/skill-roll-dialog.html +++ b/templates/chats/skill-roll-dialog.html @@ -1,7 +1,7 @@
- - {{#each traits as |value label|}} {{/each}} @@ -9,7 +9,11 @@
- + +
+
+ +