Fix various minot stuff + add resources roll

This commit is contained in:
LeRatierBretonnien 2025-01-25 18:24:20 +01:00
parent 70c4fd5a74
commit 7758085bf8
15 changed files with 217 additions and 113 deletions

View File

@ -371,6 +371,10 @@ i.fvtt-cthulhu-eternal {
min-width: 2.4rem;
max-width: 2.4rem;
}
.fvtt-cthulhu-eternal .protagonist-main .protagonist-pc .protagonist-right .willpower input[type="checkbox"] {
min-width: 1rem;
max-width: 1rem;
}
.fvtt-cthulhu-eternal .protagonist-main .protagonist-pc .protagonist-right .willpower .label-field {
flex-grow: 1;
margin-left: 4px;
@ -491,7 +495,7 @@ i.fvtt-cthulhu-eternal {
gap: 8px;
}
.fvtt-cthulhu-eternal .protagonist-biography .resources label {
min-width: 12rem;
min-width: 8rem;
}
.fvtt-cthulhu-eternal .protagonist-biography .features,
.fvtt-cthulhu-eternal .protagonist-biography .biodata {

View File

@ -323,6 +323,12 @@
"veryHarsh": "Very Harsh"
},
"Label": {
"Hand": "Hand",
"Stowed": "Stowed",
"Storage": "Storage",
"resourceRating": "Resource rating",
"Resources": "Resources",
"multiplier": "Multiplier",
"setBP": "Set BP",
"Vehicle": "Vehicle",
"Speed": "Speed",

View File

@ -191,6 +191,11 @@ export default class CthulhuEternalProtagonistSheet extends CthulhuEternalActorS
// Debug : console.log(">>>>", event, target, rollType)
// Deprecated : if (this.isEditMode) return
switch (rollType) {
case "resource":
item = foundry.utils.duplicate(this.actor.system.resources)
item.name = game.i18n.localize(`CTHULHUETERNAL.Label.Resources`)
item.targetScore = item.permanentRating
break
case "char":
let charId = $(event.currentTarget).data("char-id")
item = foundry.utils.duplicate(this.actor.system.characteristics[charId])

View File

@ -209,6 +209,26 @@ export const WEAPON_SKILL_MAPPING = {
"unarmed": "CTHULHUETERNAL.Skill.UnarmedCombat"
}
}
export const MODIFIER_CHOICES = {
"-10": "-10",
"-20": "-20",
"-40": "-40",
"+0": "+0",
"+10": "+10",
"+20": "+20",
"+40": "+40",
}
export const MULTIPLIER_CHOICES = {
"0.25": "0.25",
"0.5": "0.5",
"1": "1",
"2": "2",
"4": "4",
"5": "5"
}
/**
* Include all constant definitions within the SYSTEM global export
* @type {Object}
@ -229,5 +249,7 @@ export const SYSTEM = {
EQUIPMENT_STATES,
RESOURCE_BREAKDOWN,
VEHICLE_SPEED,
MODIFIER_CHOICES,
MULTIPLIER_CHOICES,
ASCII
}

View File

@ -59,18 +59,6 @@ export default class CthulhuEternalRoll extends Roll {
return this.options.hasTarget
}
get targetName() {
return this.options.targetName
}
get targetArmor() {
return this.options.targetArmor
}
get targetMalus() {
return this.options.targetMalus
}
get realDamage() {
return this.options.realDamage
}
@ -90,7 +78,24 @@ export default class CthulhuEternalRoll extends Roll {
get isExhausted() {
return this.options.isExhausted
}
static updateResourceDialog(options) {
let rating = 0
if (options.rollItem.enableHand) {
rating += options.rollItem.hand
}
if (options.rollItem.enableStowed) {
rating += options.rollItem.stowed
}
if (options.rollItem.enableStorage) {
rating += options.rollItem.storage
}
let multiplier = Number($(`.roll-skill-multiplier`).val())
options.initialScore = rating
options.percentScore = rating * multiplier
$(".resource-score").text(`${rating} (${options.percentScore}%)`)
}
/**
* Prompt the user with a dialog to configure and execute a roll.
*
@ -107,7 +112,10 @@ export default class CthulhuEternalRoll extends Roll {
*/
static async prompt(options = {}) {
let formula = "1d100"
switch (options.rollType) {
let hasModifier = true
let hasMultiplier = false
switch (options.rollType) {
case "skill":
console.log(options.rollItem)
options.initialScore = options.rollItem.system.computeScore()
@ -116,35 +124,45 @@ export default class CthulhuEternalRoll extends Roll {
case "char":
options.initialScore = options.rollItem.targetScore
break
case "damage":
let formula = options.rollItem.system.damage
case "resource":
hasModifier = false
hasMultiplier = true
options.initialScore = options.rollItem.targetScore
options.totalRating = options.rollItem.targetScore
options.percentScore = options.rollItem.targetScore * 5
options.rollItem.enableHand = true
options.rollItem.enableStowed = true
options.rollItem.enableStorage = true
break
case "damage":
let formula = options.rollItem.system.damage
let damageRoll = new Roll(formula)
await damageRoll.evaluate()
await damageRoll.toMessage({
flavor: `${options.rollItem.name} - Damage Roll`
});
let isLethal = false
if (options.rollItem.system.lethality > 0 ) {
if (options.rollItem.system.lethality > 0) {
let lethalityRoll = new Roll("1d100")
await lethalityRoll.evaluate()
isLethal = (lethalityRoll.total <= options.rollItem.system.lethality)
isLethal = (lethalityRoll.total <= options.rollItem.system.lethality)
await lethalityRoll.toMessage({
flavor: `${options.rollItem.name} - Lethality Roll : ${lethalityRoll.total} <= ${options.rollItem.system.lethality} => ${isLethal}`
});
}
}
return
case "weapon":
case "weapon":
let era = game.settings.get("fvtt-cthulhu-eternal", "settings-era")
if (!SYSTEM.WEAPON_SKILL_MAPPING[era] || !SYSTEM.WEAPON_SKILL_MAPPING[era][options.rollItem.system.weaponType]) {
ui.notifications.error(game.i18n.localize("CTHULHUETERNAL.Notifications.NoWeaponType") )
ui.notifications.error(game.i18n.localize("CTHULHUETERNAL.Notifications.NoWeaponType"))
return
}
let skillName = game.i18n.localize(SYSTEM.WEAPON_SKILL_MAPPING[era][options.rollItem.system.weaponType])
let skillName = game.i18n.localize(SYSTEM.WEAPON_SKILL_MAPPING[era][options.rollItem.system.weaponType])
let actor = game.actors.get(options.actorId)
options.weapon = options.rollItem
options.rollItem = actor.items.find(i => i.type === "skill" && i.name.toLowerCase() === skillName.toLowerCase())
if (!options.rollItem) {
ui.notifications.error(game.i18n.localize("CTHULHUETERNAL.Notifications.NoWeaponSkill") )
ui.notifications.error(game.i18n.localize("CTHULHUETERNAL.Notifications.NoWeaponSkill"))
return
}
options.initialScore = options.rollItem.system.computeScore()
@ -162,38 +180,34 @@ export default class CthulhuEternalRoll extends Roll {
default: "public",
})
const choiceModifier = {
"-10": "-10",
"-20": "-20",
"-40": "-40",
"0": "0",
"+10": "+10",
"+20": "+20",
"+40": "+40",
}
const choiceModifier = SYSTEM.MODIFIER_CHOICES
const choiceMultiplier = SYSTEM.MULTIPLIER_CHOICES
let modifier = "0"
let targetMalus = "0"
let targetName
let targetArmor
let modifier = "+0"
let multiplier = "5"
let dialogContext = {
rollType: options.rollType,
rollItem: foundry.utils.duplicate(options.rollItem), // Object only, no class
weapon: options?.weapon,
weapon: options?.weapon,
initialScore: options.initialScore,
targetScore: options.initialScore,
isLowWP: options.isLowWP,
isZeroWP: options.isZeroWP,
isExhausted: options.isExhausted,
enableHand: options.rollItem.enableHand,
enableStowed: options.rollItem.enableStowed,
enableStorage: options.rollItem.enableStorage,
rollModes,
fieldRollMode,
choiceModifier,
choiceMultiplier,
formula,
hasTarget: options.hasTarget,
hasModifier,
hasMultiplier,
modifier,
targetName,
targetArmor
multiplier
}
const content = await renderTemplate("systems/fvtt-cthulhu-eternal/templates/roll-dialog.hbs", dialogContext)
@ -215,30 +229,49 @@ export default class CthulhuEternalRoll extends Roll {
},
},
],
actions: {
"selectHand": (event, button, dialog) => {
options.rollItem.enableHand = !options.rollItem.enableHand
this.updateResourceDialog(options)
},
"selectStowed": (event, button, dialog) => {
options.rollItem.enableStowed = !options.rollItem.enableStowed
this.updateResourceDialog(options)
},
"selectStorage": (event, button, dialog) => {
options.rollItem.enableStorage = !options.rollItem.enableStorage
this.updateResourceDialog(options)
}
},
rejectClose: false, // Click on Close button will not launch an error
render: (event, dialog) => {
},
$(".roll-skill-multiplier").change(event => {
options.multiplier = Number(event.target.value)
this.updateResourceDialog(options)
})
}
})
// If the user cancels the dialog, exit
if (rollContext === null) return
let rollData = foundry.utils.mergeObject(foundry.utils.duplicate(options), rollContext)
rollData.rollMode = rollContext.visibility
rollData.targetName = targetName
rollData.targetArmor = targetArmor
rollData.targetMalus = targetMalus
rollData.rollMode = rollContext.visibility
// Update target score
console.log(rollData)
rollData.targetScore = Math.min( Math.max(options.initialScore + Number(rollData.modifier), 0), 100)
if ( rollData.isLowWP || rollData.isExhausted) {
rollData.targetScore -= 20
if (options.rollType === "resource" ) {
rollData.targetScore = options.initialScore * Number(rollContext.multiplier)
} else {
rollData.targetScore = Math.min(Math.max(options.initialScore + Number(rollData.modifier), 0), 100)
if (rollData.isLowWP || rollData.isExhausted) {
rollData.targetScore -= 20
}
if (rollData.isZeroWP) {
rollData.targetScore = 0
}
rollData.targetScore = Math.min(Math.max(rollData.targetScore, 0), 100)
}
if ( rollData.isZeroWP ) {
rollData.targetScore = 0
}
rollData.targetScore = Math.min( Math.max(rollData.targetScore, 0), 100)
/**
* A hook event that fires before the roll is made.
@ -249,9 +282,9 @@ export default class CthulhuEternalRoll extends Roll {
await roll.evaluate()
// Compute the result quality
let resultType = "failure"
let dec = Math.floor(roll.total/10)
let unit = roll.total - (dec*10)
let resultType = "failure"
let dec = Math.floor(roll.total / 10)
let unit = roll.total - (dec * 10)
if (roll.total <= rollData.targetScore) {
resultType = "success"
// Detect if decimal == unit in the dire total result
@ -294,9 +327,9 @@ export default class CthulhuEternalRoll extends Roll {
return `${game.i18n.localize("CTHULHUETERNAL.Label.titleSkill")}`
case "weapon":
return `${game.i18n.localize("CTHULHUETERNAL.Label.titleWeapon")}`
case "char":
case "char":
return `${game.i18n.localize("CTHULHUETERNAL.Label.titleCharacteristic")}`
case "san":
case "san":
return `${game.i18n.localize("CTHULHUETERNAL.Label.titleSAN")}`
default:
return game.i18n.localize("CTHULHUETERNAL.Label.titleStandard")
@ -335,10 +368,10 @@ export default class CthulhuEternalRoll extends Roll {
*/
async _getChatCardData(isPrivate) {
let cardData = foundry.utils.duplicate(this.options)
cardData.css = [SYSTEM.id, "dice-roll"]
cardData.data = this.data
cardData.diceTotal = this.dice.reduce((t, d) => t + d.total, 0)
cardData.isGM = game.user.isGM
cardData.css = [SYSTEM.id, "dice-roll"]
cardData.data = this.data
cardData.diceTotal = this.dice.reduce((t, d) => t + d.total, 0)
cardData.isGM = game.user.isGM
cardData.formula = this.formula
cardData.total = this.total
cardData.actorId = this.actorId
@ -354,7 +387,7 @@ export default class CthulhuEternalRoll extends Roll {
cardData.isLowWP = this.isLowWP
cardData.isZeroWP = this.isZeroWP
cardData.isExhausted = this.isExhausted
console.log(cardData)
@ -379,9 +412,6 @@ export default class CthulhuEternalRoll extends Roll {
actingCharName: this.actorName,
actingCharImg: this.actorImage,
hasTarget: this.hasTarget,
targetName: this.targetName,
targetArmor: this.targetArmor,
targetMalus: this.targetMalus,
realDamage: this.realDamage,
...messageData,
},

View File

@ -1 +1 @@
MANIFEST-000052
MANIFEST-000068

View File

@ -1,3 +1,8 @@
2025/01/10-00:04:46.700736 7f0abaffd6c0 Recovering log #50
2025/01/10-00:04:46.711152 7f0abaffd6c0 Delete type=3 #48
2025/01/10-00:04:46.711210 7f0abaffd6c0 Delete type=0 #50
2025/01/25-18:18:47.579516 7f69797fa6c0 Recovering log #66
2025/01/25-18:18:47.635623 7f69797fa6c0 Delete type=3 #64
2025/01/25-18:18:47.635705 7f69797fa6c0 Delete type=0 #66
2025/01/25-18:23:50.402055 7f6978bff6c0 Level-0 table #71: started
2025/01/25-18:23:50.402099 7f6978bff6c0 Level-0 table #71: 0 bytes OK
2025/01/25-18:23:50.411525 7f6978bff6c0 Delete type=0 #69
2025/01/25-18:23:50.411705 7f6978bff6c0 Manual compaction at level-0 from '!folders!DD8331Hda4rhvEf9' @ 72057594037927935 : 1 .. '!items!zplzTG30QXHURusr' @ 0 : 0; will stop at (end)
2025/01/25-18:23:50.411749 7f6978bff6c0 Manual compaction at level-1 from '!folders!DD8331Hda4rhvEf9' @ 72057594037927935 : 1 .. '!items!zplzTG30QXHURusr' @ 0 : 0; will stop at (end)

View File

@ -1,8 +1,8 @@
2025/01/09-15:39:16.704802 7f0abb7fe6c0 Recovering log #46
2025/01/09-15:39:16.715860 7f0abb7fe6c0 Delete type=3 #44
2025/01/09-15:39:16.715933 7f0abb7fe6c0 Delete type=0 #46
2025/01/09-16:20:07.336867 7f0ab9bff6c0 Level-0 table #51: started
2025/01/09-16:20:07.336898 7f0ab9bff6c0 Level-0 table #51: 0 bytes OK
2025/01/09-16:20:07.343031 7f0ab9bff6c0 Delete type=0 #49
2025/01/09-16:20:07.352821 7f0ab9bff6c0 Manual compaction at level-0 from '!folders!DD8331Hda4rhvEf9' @ 72057594037927935 : 1 .. '!items!zplzTG30QXHURusr' @ 0 : 0; will stop at (end)
2025/01/09-16:20:07.369688 7f0ab9bff6c0 Manual compaction at level-1 from '!folders!DD8331Hda4rhvEf9' @ 72057594037927935 : 1 .. '!items!zplzTG30QXHURusr' @ 0 : 0; will stop at (end)
2025/01/25-17:02:58.822790 7f6979ffb6c0 Recovering log #62
2025/01/25-17:02:58.899589 7f6979ffb6c0 Delete type=3 #60
2025/01/25-17:02:58.899681 7f6979ffb6c0 Delete type=0 #62
2025/01/25-18:12:05.328260 7f6978bff6c0 Level-0 table #67: started
2025/01/25-18:12:05.328291 7f6978bff6c0 Level-0 table #67: 0 bytes OK
2025/01/25-18:12:05.334284 7f6978bff6c0 Delete type=0 #65
2025/01/25-18:12:05.334447 7f6978bff6c0 Manual compaction at level-0 from '!folders!DD8331Hda4rhvEf9' @ 72057594037927935 : 1 .. '!items!zplzTG30QXHURusr' @ 0 : 0; will stop at (end)
2025/01/25-18:12:05.362492 7f6978bff6c0 Manual compaction at level-1 from '!folders!DD8331Hda4rhvEf9' @ 72057594037927935 : 1 .. '!items!zplzTG30QXHURusr' @ 0 : 0; will stop at (end)

Binary file not shown.

Binary file not shown.

View File

@ -130,6 +130,10 @@
min-width: 2.4rem;
max-width: 2.4rem;
}
input[type="checkbox"] {
min-width: 1rem;
max-width: 1rem;
}
.label-field {
flex-grow: 1;
margin-left: 4px;
@ -266,7 +270,7 @@
grid-template-columns: repeat(3, 1fr);
gap: 8px;
label {
min-width: 12rem;
min-width: 8rem;
}
}

View File

@ -17,8 +17,12 @@
{{#if weapon}}
<li><strong>Weapon : {{weapon.name}}</strong></li>
{{/if}}
{{#if (eq rollType "resource")}}
<li><strong>{{rollItem.name}} : {{initialScore}}</strong></li>
{{else}}
<li><strong>{{rollItem.name}} : {{initialScore}}%</strong></li>
{{/if}}
{{#if isZeroWP}}
<li class="red-warning">Zero WP : Automatic failure (ie 0%)</li>
@ -32,8 +36,12 @@
<li class="orange-warning">Exhausted : -20%</li>
{{/if}}
{{#if (eq rollType "resource")}}
<li>{{localize "CTHULHUETERNAL.Label.multiplier"}} : {{multiplier}}</li>
{{else}}
<li>{{localize "CTHULHUETERNAL.Label.modifier"}} : {{modifier}}%</li>
{{/if}}
<li>{{localize "CTHULHUETERNAL.Label.targetScore"}} : {{targetScore}}%</li>
{{#if isSuccess}}
{{#if isCritical}}

View File

@ -4,9 +4,6 @@
<legend>{{localize "CTHULHUETERNAL.Label.resources"}}</legend>
<div class="resources">
{{formField systemFields.resources.fields.permanentRating value=system.resources.permanentRating name="system.resources.permanentRating" localize=true}}
{{formField systemFields.resources.fields.hand value=system.resources.hand name="system.resources.hand" localize=true disabled=true}}
{{formField systemFields.resources.fields.stowed value=system.resources.stowed name="system.resources.stowed" localize=true disabled=true}}
{{formField systemFields.resources.fields.storage value=system.resources.storage name="system.resources.storage" localize=true disabled=true}}
<div>
<span class="label-field">{{localize "CTHULHUETERNAL.Label.resourceChecks"}}</span>
{{#each system.resources.checks as |check idx|}}
@ -14,7 +11,10 @@
data-name="checks" {{#if check}} checked {{/if}} {{#if (gte @index @root.system.resources.nbValidChecks)}} disabled {{/if}}>
{{/each}}
</div>
<button class="resource-roll">Resource roll</button>
<button class="resource-roll rollable" data-roll-type="resource"><img src="systems/fvtt-cthulhu-eternal/assets/ui/d100.svg" class="d100" />Resource roll</button>
{{formField systemFields.resources.fields.hand value=system.resources.hand name="system.resources.hand" localize=true disabled=true}}
{{formField systemFields.resources.fields.stowed value=system.resources.stowed name="system.resources.stowed" localize=true disabled=true}}
{{formField systemFields.resources.fields.storage value=system.resources.storage name="system.resources.storage" localize=true disabled=true}}
</div>
</fieldset>

View File

@ -1,39 +1,59 @@
{{log "roll-dialog" this}}
<div class="fvtt-cthulhu-eternal-roll-dialog">
<fieldSet>
{{#if (eq rollType "skill")}}
<legend>{{localize "CTHULHUETERNAL.Label.skill"}}</legend>
{{/if}}
{{#if (eq rollType "char")}}
<legend>{{localize "CTHULHUETERNAL.Label.characteristic"}}</legend>
{{/if}}
<fieldSet>
{{#if (eq rollType "skill")}}
<legend>{{localize "CTHULHUETERNAL.Label.skill"}}</legend>
{{/if}}
{{#if (eq rollType "char")}}
<legend>{{localize "CTHULHUETERNAL.Label.characteristic"}}</legend>
{{/if}}
<div class="dialog-skill">{{rollItem.name}} : {{initialScore}}%</div>
{{#if (eq rollType "resource")}}
<legend>{{localize "CTHULHUETERNAL.Label.resourceRating"}}</legend>
<div class="dialog-skill">{{rollItem.name}} : <span class="resource-score">{{initialScore}} ({{mul initialScore 5}}%)</span></div>
<div class="dialog-skill">{{localize "CTHULHUETERNAL.Label.Hand"}} : {{rollItem.hand}} <input type="checkbox" data-action="selectHand" {{checked rollItem.enableHand}}></div>
<div class="dialog-skill">{{localize "CTHULHUETERNAL.Label.Stowed"}} : {{rollItem.stowed}} <input type="checkbox" data-action="selectStowed" {{checked rollItem.enableStowed}}></div>
<div class="dialog-skill">{{localize "CTHULHUETERNAL.Label.Storage"}} : {{rollItem.storage}} <input type="checkbox" data-action="selectStorage" {{checked rollItem.enableStorage}}></div>
{{else}}
<div class="dialog-skill">{{rollItem.name}} : {{initialScore}}%</div>
{{/if}}
{{#if weapon}}
<div class="dialog-skill">Weapon : {{weapon.name}}</div>
{{/if}}
{{#if weapon}}
<div class="dialog-skill">Weapon : {{weapon.name}}</div>
{{/if}}
{{#if isZeroWP}}
<div class="dialog-skill red-warning">Zero WP : Automatic failure (ie 0%)</div>
{{else}}
{{#if isLowWP}}
<div class="dialog-skill orange-warning">Low WP : -20%</div>
{{/if}}
{{/if}}
{{#if isZeroWP}}
<div class="dialog-skill red-warning">Zero WP : Automatic failure (ie 0%)</div>
{{else}}
{{#if isLowWP}}
<div class="dialog-skill orange-warning">Low WP : -20%</div>
{{/if}}
{{/if}}
{{#if isExhausted}}
<div class="dialog-skill orange-warning">Exhausted : -20%</div>
{{/if}}
</fieldSet>
{{#if isExhausted}}
<div class="dialog-skill orange-warning">Exhausted : -20%</div>
{{/if}}
</fieldSet>
{{#if hasModifier}}
<fieldSet class="dialog-modifier">
<legend>{{localize "CTHULHUETERNAL.Label.modifier"}}</legend>
<select name="modifier" class="roll-skill-modifier">
{{selectOptions choiceModifier selected=modifier}}
</select>
</fieldSet>
{{/if}}
{{#if hasMultiplier}}
<fieldSet class="dialog-modifier">
<legend>{{localize "CTHULHUETERNAL.Label.multiplier"}}</legend>
<select name="multiplier" class="roll-skill-modifier roll-skill-multiplier">
{{selectOptions choiceMultiplier selected=multiplier}}
</select>
</fieldSet>
{{/if}}
<fieldSet class="dialog-modifier">
<legend>{{localize "CTHULHUETERNAL.Label.modifier"}}</legend>
<select name="modifier" class="roll-skill-modifier">
{{selectOptions choiceModifier selected=modifier}}
</select>
</fieldSet>
<fieldSet>
<legend>{{localize "CTHULHUETERNAL.Label.rollView"}}</legend>
<select name="visibility">