Skip to content

Commit

Permalink
Merge pull request #1651 from snap01/fixes
Browse files Browse the repository at this point in the history
Add place rolled characteristics to investigator wizard
  • Loading branch information
snap01 authored Dec 10, 2024
2 parents cbedcbf + 47745ed commit 2a43c3f
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 5 deletions.
1 change: 1 addition & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@
"CoC7.InvestigatorWizard.UseSetupMethod": "Use method from setup item",
"CoC7.InvestigatorWizard.EnforcePointBuy": "Enforce point buy",
"CoC7.InvestigatorWizard.QuickFireValues": "Quick fire characteristics values",
"CoC7.InvestigatorWizard.ChooseAfterRoll": "Choose where to place rolled characteristics",
"CoC7.InvestigatorWizard.Setups": "Character sheets",
"CoC7.InvestigatorWizard.Characteristics": "Characteristic values",
"CoC7.InvestigatorWizard.SetupCounts": "You currently have {count} setup options. It is recommended you set a single setup for all your players to set the default skills on your character sheet. The system comes with a default setup with a CoC ID set. You can add more setups with valid CoC ID values using the header on then setup item sheet. Compendiums with these values set will automatically be added to the available list.",
Expand Down
106 changes: 103 additions & 3 deletions module/apps/investigator-wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export class CoC7InvestigatorWizard extends FormApplication {
METHOD_DEFAULT: 1,
METHOD_ROLL: 1,
METHOD_POINTS: 2,
METHOD_VALUES: 3
METHOD_VALUES: 3,
METHOD_CHOOSE: 4
}
}

Expand Down Expand Up @@ -244,6 +245,8 @@ export class CoC7InvestigatorWizard extends FormApplication {
sheetData.characteristicsMethod = sheetData.characteristicsMethods.METHOD_DEFAULT
if (sheetData.object.enforcePointBuy) {
sheetData.characteristicsMethod = sheetData.characteristicsMethods.METHOD_POINTS
} else if (this.object.chooseRolledValues) {
sheetData.characteristicsMethod = sheetData.characteristicsMethods.METHOD_CHOOSE
} else if (this.object.quickFireValues.length) {
sheetData.characteristicsMethod = sheetData.characteristicsMethods.METHOD_VALUES
}
Expand Down Expand Up @@ -336,6 +339,8 @@ export class CoC7InvestigatorWizard extends FormApplication {
if (typeof setup !== 'undefined') {
if (setup.system.characteristics.points.enabled || this.object.enforcePointBuy) {
sheetData.characteristicsMethod = sheetData.characteristicsMethods.METHOD_POINTS
} else if (this.object.chooseRolledValues) {
sheetData.characteristicsMethod = sheetData.characteristicsMethods.METHOD_CHOOSE
} else if (this.object.quickFireValues.length) {
sheetData.characteristicsMethod = sheetData.characteristicsMethods.METHOD_VALUES
}
Expand Down Expand Up @@ -423,7 +428,7 @@ export class CoC7InvestigatorWizard extends FormApplication {
sheetData.coreCharacteristic = this.object.coreCharacteristic.toLocaleUpperCase()
}
if (!empties && this.object.age >= 15) {
if ([sheetData.characteristicsMethods.METHOD_ROLL, sheetData.characteristicsMethods.METHOD_VALUES].includes(sheetData.characteristicsMethod)) {
if ([sheetData.characteristicsMethods.METHOD_ROLL, sheetData.characteristicsMethods.METHOD_VALUES, sheetData.characteristicsMethods.METHOD_CHOOSE].includes(sheetData.characteristicsMethod)) {
sheetData.canNext = true
} else if (sheetData.setup.total.toString() === sheetData.setup.points.toString()) {
sheetData.canNext = true
Expand Down Expand Up @@ -908,6 +913,7 @@ export class CoC7InvestigatorWizard extends FormApplication {
html.find('.decrease-characteristic').click(this._onDecreaseCharacteristic.bind(this))
html.find('.decrease-10-characteristic').click(this._onDecreaseCharacteristic10.bind(this))
html.find('button.roll_all').click(this._onRollAll.bind(this))
html.find('button.roll_choose').click(this._onRollChoose.bind(this))
html.find('button.roll_edu').click(this._onRollEdu.bind(this))
html.find('button.roll_luck').click(this._onRollLuck.bind(this))
html.find('.item input.submit_on_blur').blur(this._onChangeSubmit.bind(this))
Expand Down Expand Up @@ -995,6 +1001,7 @@ export class CoC7InvestigatorWizard extends FormApplication {
for (const key in this.object.setupPoints) {
this.object.setupPoints[key] = ''
}
this.object.rolledValues = []
}

async setSkillLists () {
Expand Down Expand Up @@ -1063,6 +1070,9 @@ export class CoC7InvestigatorWizard extends FormApplication {
if (event.currentTarget.dataset.characteristicKey) {
const dragData = { type: 'investigatorCharacteristic', key: event.currentTarget.dataset.characteristicKey, value: event.currentTarget.dataset.value }
event.dataTransfer.setData('text/plain', JSON.stringify(dragData))
} else if (event.currentTarget.dataset.offset) {
const dragData = { type: 'investigatorValue', offset: event.currentTarget.dataset.offset }
event.dataTransfer.setData('text/plain', JSON.stringify(dragData))
}
}

Expand All @@ -1079,8 +1089,21 @@ export class CoC7InvestigatorWizard extends FormApplication {
const dataList = JSON.parse(event.dataTransfer.getData('text/plain'))
if (typeof dataList.type !== 'undefined' && dataList.type === 'investigatorCharacteristic') {
dataList.destination = event.target.closest('li').dataset.characteristicKey
if (typeof dataList.destination === 'undefined') {
dataList.destination = event.target.closest('li').dataset.empty
}
dataList.okay = false
if (dataList.key === '-' && typeof this.object.setupPoints[dataList.destination] !== 'undefined') {
if (dataList.destination === 'x') {
const offset = this.object.rolledValues.findIndex(i => i.assigned === true)
if (offset > -1) {
this.object.rolledValues[offset] = {
value: this.object.setupPoints[dataList.key],
assigned: false
}
this.object.setupPoints[dataList.key] = ''
}
dataList.okay = true
} else if (dataList.key === '-' && typeof this.object.setupPoints[dataList.destination] !== 'undefined') {
const index = this.object.placeable.indexOf(parseInt(dataList.value, 10))
if (index !== -1) {
this.object.placeable.splice(index, 1)
Expand Down Expand Up @@ -1108,6 +1131,26 @@ export class CoC7InvestigatorWizard extends FormApplication {
this.render(true)
return
}
} else if (typeof dataList.type !== 'undefined' && dataList.type === 'investigatorValue') {
dataList.destination = event.target.closest('li').dataset.characteristicKey
dataList.okay = false
if (this.object.rolledValues[dataList.offset].assigned === false) {
let old
if (this.object.setupPoints[dataList.destination] !== '') {
old = this.object.setupPoints[dataList.destination]
}
this.object.setupPoints[dataList.destination] = this.object.rolledValues[dataList.offset].value
if (typeof old !== 'undefined') {
this.object.rolledValues[dataList.offset].value = old
} else {
this.object.rolledValues[dataList.offset].assigned = true
}
dataList.okay = true
}
if (dataList.okay) {
this.render(true)
return
}
}
} catch (err) {
}
Expand Down Expand Up @@ -1333,6 +1376,53 @@ export class CoC7InvestigatorWizard extends FormApplication {
this.render(true)
}

async _onRollChoose (event) {
event.preventDefault()
if (this.object.setup !== '') {
const setup = await this.getCacheItemByCoCID(this.object.setup)
if (typeof setup !== 'undefined') {
const rollFormulas = {}
for (const key of ['str', 'con', 'siz', 'dex', 'app', 'int', 'pow', 'edu']) {
rollFormulas[key] = setup.system.characteristics.rolls[key]
}
if (this.object.archetype !== '') {
const archetype = await this.getCacheItemByCoCID(this.object.archetype)
if (typeof archetype !== 'undefined') {
if (this.object.coreCharacteristic !== '') {
if (archetype.system.coreCharacteristicsFormula.enabled) {
rollFormulas[this.object.coreCharacteristic] = archetype.system.coreCharacteristicsFormula.value
}
}
}
}
this.object.rolledValues = []
const html = []
for (const key in rollFormulas) {
const roll = new Roll(rollFormulas[key].toString())
await roll.evaluate({ async: true })
this.object.rolledValues.push({
value: roll.total,
assigned: false
})
html.push(await renderTemplate(Roll.CHAT_TEMPLATE, {
formula: rollFormulas[key].toString(),
tooltip: await roll.getTooltip(),
total: roll.total
}))
}
ChatMessage.create({
user: game.user.id,
speaker: {
alias: game.user.name
},
content: html.join('<div>&nbsp;</div>'),
whisper: ChatMessage.getWhisperRecipients('GM')
})
}
}
this.render(true)
}

async _onIncreaseCharacteristic10 (event) {
event.preventDefault()
const li = event.currentTarget.closest('.item')
Expand Down Expand Up @@ -1503,20 +1593,28 @@ export class CoC7InvestigatorWizard extends FormApplication {
const type = Number(formData['characteristics-method'])
if (type === this.characteristicsMethods.METHOD_DEFAULT) {
this.object.enforcePointBuy = false
this.object.chooseRolledValues = false
this.object.quickFireValues = []
} else if (type === this.characteristicsMethods.METHOD_POINTS) {
this.object.enforcePointBuy = true
this.object.chooseRolledValues = false
this.object.quickFireValues = []
} else if (type === this.characteristicsMethods.METHOD_VALUES) {
this.object.enforcePointBuy = false
this.object.chooseRolledValues = false
if (game.settings.get('CoC7', 'pulpRuleArchetype')) {
this.object.quickFireValues = [90, 80, 70, 60, 60, 50, 50, 40]
} else {
this.object.quickFireValues = [80, 70, 60, 60, 50, 50, 50, 40]
}
} else if (type === this.characteristicsMethods.METHOD_CHOOSE) {
this.object.enforcePointBuy = false
this.object.chooseRolledValues = true
this.object.quickFireValues = []
}
game.settings.set('CoC7', 'InvestigatorWizardPointBuy', this.object.enforcePointBuy)
game.settings.set('CoC7', 'InvestigatorWizardQuickFire', this.object.quickFireValues)
game.settings.set('CoC7', 'InvestigatorWizardChooseValues', this.object.chooseRolledValues)
}
this.object.rerollsEnabled = (typeof formData['rerolls-enabled'] === 'string')
game.settings.set('CoC7', 'InvestigatorWizardRerolls', this.object.rerollsEnabled)
Expand Down Expand Up @@ -1873,6 +1971,7 @@ export class CoC7InvestigatorWizard extends FormApplication {
rerollsEnabled: game.settings.get('CoC7', 'InvestigatorWizardRerolls'),
enforcePointBuy: game.settings.get('CoC7', 'InvestigatorWizardPointBuy'),
quickFireValues: game.settings.get('CoC7', 'InvestigatorWizardQuickFire'),
chooseRolledValues: game.settings.get('CoC7', 'InvestigatorWizardChooseValues'),
placeable: foundry.utils.duplicate(game.settings.get('CoC7', 'InvestigatorWizardQuickFire')),
cacheCoCID: CoC7InvestigatorWizard.loadCacheItemByCoCID(),
cacheBackstories: game.system.api.cocid.fromCoCIDRegexBest({ cocidRegExp: /^rt\.\.backstory-/, type: 'rt' }),
Expand Down Expand Up @@ -1903,6 +2002,7 @@ export class CoC7InvestigatorWizard extends FormApplication {
edu: 0,
luck: 0
},
rolledValues: [],
archetype: '',
coreCharacteristic: '',
occupation: '',
Expand Down
7 changes: 7 additions & 0 deletions module/scripts/register-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,13 @@ export function registerSettings () {
type: Array,
default: []
})
game.settings.register('CoC7', 'InvestigatorWizardChooseValues', {
name: 'Choose where to place rolled characteristics',
scope: 'world',
config: false,
type: Array,
default: []
})
/** Set an initiative formula for the system */
CONFIG.Combat.initiative = {
formula: '@characteristics.dex.value',
Expand Down
6 changes: 6 additions & 0 deletions templates/apps/investigator-wizard/configuration.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
</div>
</div>
{{/if}}
<div class="form-group flexrow">
<label for="characteristics-method-4">{{localize 'CoC7.InvestigatorWizard.ChooseAfterRoll'}}:</label>
<div class="flex1">
<input type="radio" name="characteristics-method" value="4" class="submit_on_change" style="margin-left: -2px; transform: scale(1.5);" {{checked (eq characteristicsMethod characteristicsMethods.METHOD_CHOOSE)}}>
</div>
</div>
<h2>{{localize 'CoC7.InvestigatorWizard.Setups'}}</h2>
<p>{{localize 'CoC7.InvestigatorWizard.SetupCounts' count=setups.length}}</p>
<div class="form-group">
Expand Down
25 changes: 23 additions & 2 deletions templates/apps/investigator-wizard/set-characteristics.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,33 @@
</div>
{{/if}}
{{#if (or object.coreCharacteristic (lt coreCharacteristics.length 1))}}
{{#if (eq characteristicsMethod characteristicsMethods.METHOD_VALUES)}}
{{#if (or (eq characteristicsMethod characteristicsMethods.METHOD_VALUES) (eq characteristicsMethod characteristicsMethods.METHOD_CHOOSE))}}
<p>{{localize 'CoC7.InvestigatorWizard.CharacteristicDragInformation'}}</p>
{{#if object.coreCharacteristic}}
<p>{{localize 'CoC7.InvestigatorWizard.CoreCharacteristicName' coreCharacteristic=coreCharacteristic}}</p>
<p>{{{localize 'CoC7.InvestigatorWizard.CoreCharacteristicName' coreCharacteristic=coreCharacteristic}}}</p>
{{/if}}
<div class="flexcol">
<ol class="item-list">
{{#if (eq characteristicsMethod characteristicsMethods.METHOD_CHOOSE)}}
{{#if (or object.rerollsEnabled (not object.rolledValues.length))}}
<li class="item flexrow">
<div class="flex2"></div>
<button class="roll_choose">{{localize 'CoC7.RollDice'}}</button>
<div class="flex2"></div>
</li>
{{/if}}
{{#if object.rolledValues.length}}
<li class="item flexrow unsorted-characteristics" data-empty="x">
{{#each object.rolledValues as |roll offset|}}
{{#unless roll.assigned}}
<div draggable="true" class="draggable characteristic" data-offset="{{offset}}">
<div>{{roll.value}}</div>
</div>
{{/unless}}
{{/each}}
</li>
{{/if}}
{{else}}
<li class="item flexrow unsorted-characteristics" data-characteristic-key="-">
&nbsp;
{{#each object.placeable as |value|}}
Expand All @@ -32,6 +52,7 @@
</div>
{{/each}}
</li>
{{/if}}
{{#each setup.characteristics as |characteristic|}}
<li class="item flexrow" data-characteristic-key="{{characteristic.key}}">
<div class="item-name flexrow">
Expand Down

0 comments on commit 2a43c3f

Please sign in to comment.