Skip to content

Commit

Permalink
enhancements and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
psychoph committed Nov 6, 2020
1 parent 353b11f commit 32ff14f
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 80 deletions.
4 changes: 3 additions & 1 deletion lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
4 changes: 3 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
4 changes: 3 additions & 1 deletion lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
146 changes: 84 additions & 62 deletions module/actor/sheets/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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']) {
Expand All @@ -855,6 +876,8 @@ export default class ActorSheetSS2e extends ActorSheet {
raises++
combos.push('10')
rolls.splice(i, 1)
} else if (rolls[i] < 10) {
break
}
}
}
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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]
Expand All @@ -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'),
Expand All @@ -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
})
}

Expand Down
5 changes: 2 additions & 3 deletions module/apps/advantage-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -33,8 +33,7 @@ export default class AdvantageSelector extends FormApplication {
chosen: advantages ? advantages.includes(v) : false
}
}

console.log(choices)

// Return data
return {
choices: choices
Expand Down
17 changes: 17 additions & 0 deletions module/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
]
}
9 changes: 6 additions & 3 deletions module/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}

Expand All @@ -118,7 +122,6 @@ export const migrateActorData = function (actor) {
}

if(actor.type === 'ship' && actor.data.crewstatus == null ) {
console.log('ship migration')
updateData['data.crewstatus'] = ""
}

Expand Down
2 changes: 1 addition & 1 deletion module/svnsea2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions system.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"
}
6 changes: 3 additions & 3 deletions template.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@
"influence": {
"value": 5,
"min": 0,
"max": 10
"max": 20
},
"strength": {
"value": 5,
"min": 1,
"max": 10
"max": 20
}
}
}
Expand All @@ -166,7 +166,7 @@
"wounds": {
"value": 0,
"min": 0,
"max": 5
"max": 20
},
"traits": {
"strength": {
Expand Down
Loading

0 comments on commit 32ff14f

Please sign in to comment.