Fix various minot stuff + add resources roll
This commit is contained in:
@ -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,
|
||||
},
|
||||
|
Reference in New Issue
Block a user