Skip to content

Commit

Permalink
Added "reduces by" synonym to attributephrase. Handled 0 VIGOUR death
Browse files Browse the repository at this point in the history
  • Loading branch information
rajch committed Sep 1, 2024
1 parent 5fc5f84 commit a1ed7a3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
4 changes: 4 additions & 0 deletions assets/sampledata.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@

Your VIGOUR increases by 10.

But at a small cost to your Chi.

Your PSI reduces by 1.

Turn to 203.

Or, [[return to the beginning->Start]].
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/attributephraseplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import '../core/types'
// This matches a sentence by itself in a paragraph.
const deadPhraseRegex = /\nYou are dead.\n/g
// This matches a sentence that ends a paragraph.
const phraseRegex = /Your (VIGOUR|AGILITY|PSI) ((?:is restored)|(?:increases by)|(?:decreases by))( \d{1,2})?\.\n/g
const phraseRegex = /Your (VIGOUR|AGILITY|PSI) ((?:is restored)|(?:increases by)|(?:decreases by)|(?:reduces by))( \d{1,2})?\.\n/g

export class AttributePhrasePlugin extends BBScannerPlugin {
/** @type {CharacterSheetPlugin} */
Expand Down Expand Up @@ -61,7 +61,7 @@ export class AttributePhrasePlugin extends BBScannerPlugin {
const amount = action === 'is restored'
? 1000 // a high amount restores the attribute
: phraseMatch[3]
? parseInt(phraseMatch[3].trimStart()) * (action === 'decreases by' ? -1 : 1)
? parseInt(phraseMatch[3].trimStart()) * (action === 'decreases by' || action === 'reduces by' ? -1 : 1)
: 0

this.#charactersheet[attribute] += amount
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/charactersheetplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ export class CharacterSheetPlugin extends BBGlobalStatePlugin {
this.#vigourlabel.textContent = value
this.setCurrentState({ sheet: structuredClone(this.#currentSheet) })

// Handle the death case
if (value === 0 ) {
this.player.preventNavigation()
}
}

/**
Expand Down
17 changes: 1 addition & 16 deletions src/plugins/combatplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ export class CombatPlugin extends BBScannerPlugin {
init (player) {
super.init(player)

// This should move to renderer interface
// const element = document.querySelector('div.combat')

// this.#foenamelabel = element.querySelector('label.foename')
// this.#foevigourlabel = element.querySelector('label.foevigour')
// this.#element = element

this.#diceboard = player.getPlugin('diceboard')
if (!this.#diceboard) {
throw new Error('Combat plugin requires the Dice Board plugin')
Expand Down Expand Up @@ -79,12 +72,10 @@ export class CombatPlugin extends BBScannerPlugin {
) {
if (rule.action === 'loses') {
combat.foeVigour = combat.foeVigour - rule.turnAmount;
// this.#foevigourlabel.textContent = combat.foeVigour
updateFightArea(`You hit ${combat.foe} for ${rule.turnAmount} points.`)
if (combat.foeVigour <= 0) {
this.#won = true
this.#lost = false
// this.#foenamelabel.textContent = 'DEFEATED!'
replaceFightArea('You won!')
this.#diceboard.hide('combat')
this.setCurrentState({ defeated: true })
Expand Down Expand Up @@ -168,7 +159,6 @@ export class CombatPlugin extends BBScannerPlugin {
// Player had won earlier
this.#won = true
this.#lost = false
// this.#element.classList.add('hidden')
this.player.allowNavigation()
return true
} else if (state?.playerdefeated) {
Expand Down Expand Up @@ -232,12 +222,8 @@ export class CombatPlugin extends BBScannerPlugin {

this.#combat = combat

// this.#foenamelabel.textContent = combat.foe
// this.#foevigourlabel.textContent = combat.foeVigour

this.#diceboard.setDice(combat.numberOfDice)
this.#diceboard.show('combat')
// this.#element.classList.remove('hidden')
this.player.preventNavigation()

console.log('Combat detected:')
Expand All @@ -248,13 +234,12 @@ export class CombatPlugin extends BBScannerPlugin {
}

this.#diceboard.hide('combat')
// this.#element.classList.add('hidden')
this.player.allowNavigation()
return false
}
}

const combatTemplate = '<div class="combattable"><div><div>{foe}</div><div>VIGOUR: <span class="foeVigour">{foeVigour}</span></div><div><table><caption>Rules</caption><tbody>{rules}</tbody></table><div>{flee}</div></div></div><div class="rollstatus"></div></div>{wingoto}{losegoto}'
const combatTemplate = '<div class="combattable"><div><div><table><caption>Rules</caption><tbody>{rules}</tbody></table><div>{flee}</div></div><div>{foe}</div><div>VIGOUR: <span class="foeVigour">{foeVigour}</span></div></div><div class="rollstatus"></div></div>{wingoto}{losegoto}'

/**
*
Expand Down

0 comments on commit a1ed7a3

Please sign in to comment.