Update fight options
All checks were successful
Release Creation / build (release) Successful in 53s
All checks were successful
Release Creation / build (release) Successful in 53s
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
|
||||
import { SYSTEM } from "../config/system.mjs"
|
||||
import CthulhuEternalUtils from "../utils.mjs"
|
||||
|
||||
export default class CthulhuEternalRoll extends Roll {
|
||||
/**
|
||||
@@ -128,29 +129,21 @@ export default class CthulhuEternalRoll extends Roll {
|
||||
static async processWeaponDamage(actor, options) {
|
||||
let isLethal = false
|
||||
let weapon = options.rollItem
|
||||
let ammoUsed = weapon.system.weaponType.includes("ranged") ? 1 : 0 // Default ammo used for melee weapons is 0
|
||||
options.isNudge = false
|
||||
|
||||
// Selective fire management
|
||||
if (weapon.system.hasSelectiveFire && weapon.selectiveFireChoice) {
|
||||
let choice = SYSTEM.WEAPON_SELECTIVE_FIRE_CHOICES[weapon.selectiveFireChoice]
|
||||
if (choice.ammoUsed > weapon.system.ammo.value) {
|
||||
ui.notifications.warn(game.i18n.localize("CTHULHUETERNAL.Notifications.NoAmmo"))
|
||||
return
|
||||
}
|
||||
weapon.system.selectiveFireChoiceLabel = choice.label // Store the choice in the weapon
|
||||
weapon.system.lethality = choice.lethality // Override lethality
|
||||
weapon.system.killRadius = choice.killRadius // Override kill radius
|
||||
ammoUsed = choice.ammoUsed // Override ammo used
|
||||
}
|
||||
|
||||
ammoUsed = Number(ammoUsed)
|
||||
|
||||
let combatants = []
|
||||
if (game?.combat?.combatants) {
|
||||
for (let c of game.combat.combatants) {
|
||||
if (c.actor.id !== actor.id) {
|
||||
combatants.push({ id: c.actor.id, name: c.name })
|
||||
combatants.push({ id: c.id, name: c.name })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -160,12 +153,6 @@ export default class CthulhuEternalRoll extends Roll {
|
||||
await lethalityRoll.evaluate()
|
||||
let lethalScore = (options?.previousResultType === "successCritical") ? weapon.system.lethality * 2 : weapon.system.lethality
|
||||
isLethal = (lethalityRoll.total <= lethalScore)
|
||||
if (ammoUsed > 0) {
|
||||
await actor.updateEmbeddedDocuments("Item", [{
|
||||
_id: weapon._id,
|
||||
"system.ammo.value": Math.max(0, weapon.system.ammo.value - ammoUsed)
|
||||
}])
|
||||
}
|
||||
let wounds = Math.floor(lethalityRoll.total / 10) + (lethalityRoll.total % 10)
|
||||
let msgData = {
|
||||
actorId: actor.id,
|
||||
@@ -173,7 +160,7 @@ export default class CthulhuEternalRoll extends Roll {
|
||||
wounds,
|
||||
lethalScore,
|
||||
isLethal,
|
||||
ammoUsed,
|
||||
ammoUsed: weapon?.ammoUsed || 0,
|
||||
rollResult: lethalityRoll.total,
|
||||
combatants: combatants
|
||||
}
|
||||
@@ -195,12 +182,6 @@ export default class CthulhuEternalRoll extends Roll {
|
||||
if (options?.previousResultType === "successCritical") {
|
||||
formula = `( ${formula} ) * 2`
|
||||
}
|
||||
if (ammoUsed > 0) {
|
||||
await actor.updateEmbeddedDocuments("Item", [{
|
||||
_id: weapon._id,
|
||||
"system.ammo.value": Math.max(0, weapon.system.ammo.value - ammoUsed)
|
||||
}])
|
||||
}
|
||||
|
||||
let damageRoll = new Roll(formula)
|
||||
await damageRoll.evaluate()
|
||||
@@ -208,7 +189,7 @@ export default class CthulhuEternalRoll extends Roll {
|
||||
actorId: actor.id,
|
||||
weapon,
|
||||
formula,
|
||||
ammoUsed,
|
||||
ammoUsed: weapon?.ammoUsed || 0,
|
||||
rollResult: damageRoll.total,
|
||||
combatants: combatants
|
||||
}
|
||||
@@ -234,6 +215,27 @@ export default class CthulhuEternalRoll extends Roll {
|
||||
return modifier
|
||||
}
|
||||
|
||||
static async processAmmoUsed(actor, weapon) {
|
||||
let ammoUsed = weapon.system.weaponType.includes("ranged") ? 1 : 0 // Default ammo used for melee weapons is 0
|
||||
// Selective fire management
|
||||
if (weapon.system.hasSelectiveFire && weapon.selectiveFireChoice) {
|
||||
let choice = SYSTEM.WEAPON_SELECTIVE_FIRE_CHOICES[weapon.selectiveFireChoice]
|
||||
if (choice.ammoUsed > weapon.system.ammo.value) {
|
||||
ui.notifications.warn(game.i18n.localize("CTHULHUETERNAL.Notifications.NoAmmo"))
|
||||
return
|
||||
}
|
||||
ammoUsed = choice.ammoUsed // Override ammo used
|
||||
}
|
||||
ammoUsed = Number(ammoUsed)
|
||||
if (ammoUsed > 0) {
|
||||
await actor.updateEmbeddedDocuments("Item", [{
|
||||
_id: weapon._id,
|
||||
"system.ammo.value": Math.max(0, weapon.system.ammo.value - ammoUsed)
|
||||
}])
|
||||
}
|
||||
weapon.ammoUsed = ammoUsed
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompt the user with a dialog to configure and execute a roll.
|
||||
*
|
||||
@@ -255,9 +257,10 @@ export default class CthulhuEternalRoll extends Roll {
|
||||
options.isNudge = true
|
||||
let actor = game.actors.get(options.actorId)
|
||||
|
||||
let target = CthulhuEternalUtils.getTarget()
|
||||
|
||||
switch (options.rollType) {
|
||||
case "skill":
|
||||
console.log(options.rollItem)
|
||||
options.initialScore = options.rollItem.system.computeScore()
|
||||
break
|
||||
case "luck":
|
||||
@@ -295,12 +298,16 @@ export default class CthulhuEternalRoll extends Roll {
|
||||
console.log("WP Not found", era, options.rollItem.system.weaponType)
|
||||
return
|
||||
}
|
||||
if (!target) {
|
||||
ui.notifications.warn(game.i18n.localize("CTHULHUETERNAL.Notifications.AttackNoTarget"))
|
||||
}
|
||||
// Check if the weapon has enouth ammo in case of a firearm
|
||||
if (options.rollItem.system.isFireArm() && options.rollItem.system.ammo.value <= 0) {
|
||||
ui.notifications.warn(game.i18n.localize("CTHULHUETERNAL.Notifications.NoAmmo"))
|
||||
return
|
||||
}
|
||||
options.weapon = options.rollItem
|
||||
|
||||
if (options.rollItem.system.hasDirectSkill) {
|
||||
let skillName = options.rollItem.name
|
||||
options.rollItem = { type: "skill", name: skillName, system: { base: 0, bonus: options.weapon.system.directSkillValue } }
|
||||
@@ -371,6 +378,7 @@ export default class CthulhuEternalRoll extends Roll {
|
||||
aimingWithSight: false,
|
||||
modifier,
|
||||
formula,
|
||||
targetName: target?.name,
|
||||
hasTarget: options.hasTarget,
|
||||
hasModifier,
|
||||
hasMultiplier,
|
||||
@@ -423,10 +431,14 @@ export default class CthulhuEternalRoll extends Roll {
|
||||
if (rollContext === null) return
|
||||
|
||||
let rollData = foundry.utils.mergeObject(foundry.utils.duplicate(options), rollContext)
|
||||
// If we have a target, get its data
|
||||
rollData.targetId = target?.id
|
||||
rollData.targetName = target?.name
|
||||
rollData.rollMode = rollContext.visibility
|
||||
|
||||
// Update target score
|
||||
console.log("Rolldata", rollData, options)
|
||||
console.log("Rolldata", rollData)
|
||||
|
||||
if (options.rollType === "resource") {
|
||||
rollData.targetScore = options.initialScore * Number(rollContext.multiplier)
|
||||
} else {
|
||||
@@ -446,6 +458,10 @@ export default class CthulhuEternalRoll extends Roll {
|
||||
rollData.modifier = "0"
|
||||
}
|
||||
|
||||
if (options.rollType === "weapon") {
|
||||
await this.processAmmoUsed(actor, rollData.weapon)
|
||||
}
|
||||
|
||||
if (Hooks.call("fvtt-cthulhu-eternal.preRoll", options, rollData) === false) return
|
||||
|
||||
const roll = new this(formula, options.data, rollData)
|
||||
@@ -506,7 +522,64 @@ export default class CthulhuEternalRoll extends Roll {
|
||||
this.options.isLowWP = rollData.isLowWP
|
||||
this.options.isZeroWP = rollData.isZeroWP
|
||||
this.options.isExhausted = rollData.isExhausted
|
||||
rollData.isSuccess = this.options.isSuccess
|
||||
rollData.isFailure = this.options.isFailure
|
||||
rollData.isCritical = this.options.isCritical
|
||||
rollData.resultType = resultType
|
||||
this.options.rollData = foundry.utils.duplicate(rollData)
|
||||
|
||||
// Keep track of the last defense roll for the actor
|
||||
if (game.combat && (rollData?.weapon?.system.type === "melee" || (rollData?.rollItem.type === "skill" && rollData?.rollItem.name?.toLowerCase().includes(game.i18n.localize("CTHULHUETERNAL.Skill.dodgeName").toLowerCase())))) {
|
||||
let actor = game.actors.get(options.actorId)
|
||||
rollData.round = game.combat.round
|
||||
actor.setLastDefenseRoll(foundry.utils.duplicate(rollData))
|
||||
}
|
||||
|
||||
if (game.combat && rollData?.weapon) { // An attack roll
|
||||
rollData.isAttackRoll = true
|
||||
}
|
||||
|
||||
// Now check if we have a target for the current roll, and if the target has done its defense roll this round
|
||||
if (rollData.targetId) {
|
||||
let token = game.scenes.current.tokens.get(rollData.targetId)
|
||||
let defender = token.actor
|
||||
let lastDefenseRoll = defender?.getLastDefenseRoll()
|
||||
// Now compare opposition
|
||||
this.compareRolls(rollData, lastDefenseRoll)
|
||||
rollData.defenseRoll = lastDefenseRoll
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
compareRolls(attackRoll, defenseRoll) {
|
||||
if (!defenseRoll || defenseRoll.round !== game?.combat?.round) {
|
||||
ui.notifications.info(game.i18n.localize("CTHULHUETERNAL.Notifications.NoDefenseRoll"))
|
||||
return
|
||||
}
|
||||
if (attackRoll.isFailure) {
|
||||
attackRoll.attackSucess = false
|
||||
}
|
||||
if (attackRoll.isSuccess && defenseRoll.isFailure) {
|
||||
attackRoll.attackSucess = true
|
||||
}
|
||||
if (attackRoll.isSuccess && defenseRoll.isSuccess) {
|
||||
if (attackRoll.isCritical && !defenseRoll.isCritical) {
|
||||
attackRoll.attackSucess = true
|
||||
}
|
||||
else if (!attackRoll.isCritical && defenseRoll.isCritical) {
|
||||
attackRoll.attackSucess = false
|
||||
}
|
||||
else {
|
||||
// Both are normal success, compare the roll results
|
||||
if (attackRoll.total >= defenseRoll.total) {
|
||||
// Attack successful
|
||||
attackRoll.attackSucess = true
|
||||
} else {
|
||||
// Defense successful
|
||||
attackRoll.attackSucess = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user