Skip to content

Commit

Permalink
Merge pull request #422 from ben/new-roll-engine
Browse files Browse the repository at this point in the history
New roll engine
  • Loading branch information
ben authored Aug 24, 2022
2 parents c48c331 + 2f9d663 commit c8ea864
Show file tree
Hide file tree
Showing 52 changed files with 2,131 additions and 424 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next Release

- Add a new dice-rolling engine, and upgrade the move/stat/track/progress rolling dialogs ([#422](https://github.com/ben/foundry-ironsworn/pull/422))
- Fix the die-roll backgrounds in the SF theme
- Don't open editors for non-editable items when clicking a move link and no character move sheet is open.
- Add a start for Polish translations (see [#428](https://github.com/ben/foundry-ironsworn/issues/428))
Expand Down
53 changes: 12 additions & 41 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,8 @@ import * as lodash from 'lodash'
import { marked } from 'marked'
import { IronswornActor } from './module/actor/actor'
import { CreateActorDialog } from './module/applications/createActorDialog'
import {
createIronswornChatRoll,
createIronswornDenizenChat,
rollAndDisplayOracleResult,
} from './module/chat/chatrollhelpers'
import { RANKS, RANK_INCREMENTS } from './module/constants'
import * as dataforgedHelpers from './module/dataforged'
import { importFromDatasworn } from './module/datasworn'
import { defaultActor } from './module/helpers/actors'
import { moveDataByName } from './module/helpers/data'
import {
attachInlineRollListeners,
RollDialog,
rollSiteFeature,
} from './module/helpers/rolldialog'
import { SFRollMoveDialog } from './module/helpers/rolldialog-sf'
import { IronswornSettings } from './module/helpers/settings'
import { AssetItem } from './module/item/asset/assetitem'
import { BaseItem } from './module/item/baseitem'
import { BondsetItem } from './module/item/bondset/bondsetitem'
Expand All @@ -28,6 +13,11 @@ import { MoveItem } from './module/item/move/moveitem'
import { ProgressItem } from './module/item/progress/progressitem'
import { VowItem } from './module/item/vow/vowitem'
import { starforged } from 'dataforged'
import {
IronswornRoll,
IronswornPrerollDialog,
IronswornRollChatMessage,
} from './module/rolls'

export interface IronswornConfig {
itemClasses: Array<typeof BaseItem>
Expand All @@ -37,19 +27,9 @@ export interface IronswornConfig {
createActorDialog: CreateActorDialog | null
}

// These are for Vue
IronswornSettings: typeof IronswornSettings
RollDialog: typeof RollDialog
SFRollMoveDialog: typeof SFRollMoveDialog
Ranks: typeof RANKS
RankIncrements: typeof RANK_INCREMENTS
attachInlineRollListeners: typeof attachInlineRollListeners
createIronswornChatRoll: typeof createIronswornChatRoll
createIronswornDenizenChat: typeof createIronswornDenizenChat
rollSiteFeature: typeof rollSiteFeature
moveDataByName: typeof moveDataByName
defaultActor: typeof defaultActor
rollAndDisplayOracleResult: typeof rollAndDisplayOracleResult
IronswornRoll: typeof IronswornRoll
IronswornPrerollDialog: typeof IronswornPrerollDialog
IronswornRollChatMessage: typeof IronswornRollChatMessage

Dataforged: typeof starforged
dataforgedHelpers: typeof dataforgedHelpers
Expand All @@ -74,20 +54,11 @@ export const IRONSWORN: IronswornConfig = {
createActorDialog: null,
},

importFromDatasworn,
IronswornRoll,
IronswornPrerollDialog,
IronswornRollChatMessage,

IronswornSettings,
RollDialog,
SFRollMoveDialog,
Ranks: RANKS,
RankIncrements: RANK_INCREMENTS,
attachInlineRollListeners,
createIronswornChatRoll,
createIronswornDenizenChat,
rollSiteFeature,
moveDataByName,
defaultActor,
rollAndDisplayOracleResult,
importFromDatasworn,

Dataforged: starforged,
dataforgedHelpers,
Expand Down
14 changes: 1 addition & 13 deletions src/module/actor/actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,10 @@ export class IronswornActor extends Actor {
return undefined
}

/** @override */
prepareDerivedData() {
// Calculate momentum max/reset from debilities
if (this.data.type === 'character') {
const data = this.data.data
const numDebilitiesMarked = Object.values(data.debility).filter(
(x) => x
).length
data.momentumMax = 10 - numDebilitiesMarked
data.momentumReset = Math.max(0, 2 - numDebilitiesMarked)
}
}

async burnMomentum() {
if (this.data.type != 'character') return
const { momentum, momentumReset } = this.data.data
console.log({ momentum, momentumReset })
if (momentum > momentumReset) {
this.update({
data: { momentum: momentumReset },
Expand Down
48 changes: 28 additions & 20 deletions src/module/chat/cards.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { capitalize } from 'lodash'
import { moveDataByName, MoveOracle, MoveOracleEntry } from '../helpers/data'
import { MoveContentCallbacks } from './movecontentcallbacks'
import { HIT_TYPE, rollAndDisplayOracleResult } from './chatrollhelpers'
import { rollAndDisplayOracleResult } from './chatrollhelpers'
import {
DelveDomainDataProperties,
DelveThemeDataProperties,
Expand All @@ -13,6 +13,8 @@ import { defaultActor } from '../helpers/actors'
import { IronswornItem } from '../item/item'
import { IronswornHandlebarsHelpers } from '../helpers/handlebars'
import { cachedDocumentsForPack } from '../features/pack-cache'
import { DfRollOutcome, RollOutcome } from '../rolls/roll'
import { IronswornRollChatMessage } from '../rolls'

export class IronswornChatCard {
id?: string | null
Expand Down Expand Up @@ -44,6 +46,9 @@ export class IronswornChatCard {
html
.find('.burn-momentum-sf')
.on('click', (ev) => this._sfBurnMomentum.call(this, ev))
html
.find('.ironsworn-roll-burn-momentum')
.on('click', (ev) => this._irBurnMomentum.call(this, ev))
html
.find('.ironsworn__delvedepths__roll')
.on('click', (ev) => this._delveDepths.call(this, ev))
Expand Down Expand Up @@ -106,9 +111,12 @@ export class IronswornChatCard {
}

async _burnMomentum(ev: JQuery.ClickEvent) {
ev.preventDefault()

const { actor, move, stat, hittype } = ev.target.dataset
const hitTypeKey = {
[RollOutcome.Miss]: 'Miss',
[RollOutcome.Weak_hit]: 'Weak',
[RollOutcome.Strong_hit]: 'Strong',
}[hittype]

const theActor = game.actors?.get(actor)
theActor?.burnMomentum()
Expand All @@ -117,23 +125,19 @@ export class IronswornChatCard {
let result: string
if (move) {
const theMove = await moveDataByName(move)
result = theMove && theMove[capitalize(hittype.toLowerCase())]
result = theMove && theMove[hitTypeKey]
bonusContent = MoveContentCallbacks[move]?.call(this, {
hitType: hittype as HIT_TYPE,
hitType: hittype as RollOutcome,
stat,
})
} else {
const i18nKey = {
[HIT_TYPE.STRONG]: 'StrongHit',
[HIT_TYPE.WEAK]: 'WeakHit',
[HIT_TYPE.MISS]: 'Miss',
}[hittype]
result = `<strong>${game.i18n.localize('IRONSWORN.' + i18nKey)}</strong>`
const i18nKey = 'IRONSWORN.' + RollOutcome[parseInt(hittype)]
result = `<strong>${game.i18n.localize(i18nKey)}</strong>`
}

const parent = $(ev.currentTarget).parents('.message-content')
parent.find('.roll-result').addClass('strikethru')
parent.find('.roll-result button').prop('disabled', true)
parent.find('.move-outcome').addClass('strikethru')
parent.find('.move-outcome button').prop('disabled', true)
parent.find('.momentum-burn').html(`
<h3>${game.i18n.localize('IRONSWORN.MomentumBurnt')}</h3>
${result || ''}
Expand All @@ -157,11 +161,7 @@ export class IronswornChatCard {
(await sfPack?.getDocument(move))) as IronswornItem

// Get the new result
const k = {
[HIT_TYPE.STRONG]: 'Strong Hit',
[HIT_TYPE.WEAK]: 'Weak Hit',
[HIT_TYPE.MISS]: 'Miss',
}[hittype]
const k = DfRollOutcome[hittype]
const moveData = theMove.data as SFMoveDataProperties
const newOutcome = moveData.data.Outcomes?.[k]?.Text

Expand All @@ -170,8 +170,8 @@ export class IronswornChatCard {

// Replace the chat-card HTML
const parent = $(ev.currentTarget).parents('.message-content')
parent.find('.roll-result').addClass('strikethru')
parent.find('.roll-result button').prop('disabled', true)
parent.find('.move-outcome').addClass('strikethru')
parent.find('.move-outcome button').prop('disabled', true)
parent.find('.momentum-burn').html(`
<h3>${game.i18n.localize('IRONSWORN.MomentumBurnt')}</h3>
<strong>${hittypetext}:</strong>
Expand All @@ -182,6 +182,14 @@ export class IronswornChatCard {
await this.message?.update({ content })
}

async _irBurnMomentum(ev: JQuery.ClickEvent) {
ev.preventDefault()

const msgId = $(ev.target).parents('.chat-message').data('message-id')
const irmsg = await IronswornRollChatMessage.fromMessage(msgId)
irmsg?.burnMomentum()
}

async _delveDepths(ev: JQuery.ClickEvent) {
ev.preventDefault()

Expand Down
Loading

0 comments on commit c8ea864

Please sign in to comment.