Ranged attacks

This commit is contained in:
2022-08-17 22:51:52 +02:00
parent 68b8d42925
commit 08157116e8
9 changed files with 150 additions and 21 deletions

View File

@ -556,7 +556,16 @@ export class CrucibleActor extends Actor {
rollData.forceRollDisadvantage = this.isForcedRollDisadvantage()
rollData.noAdvantage = this.isNoAdvantage()
if ( rollData.defenderTokenId) {
let defender = game.canvas.tokens.get(rollData.defenderTokenId).actor
let defenderToken = game.canvas.tokens.get(rollData.defenderTokenId)
let defender = defenderToken.actor
// Distance management
if ( this.token) {
const ray = new Ray(this.token.object.center, defenderToken.center)
rollData.tokensDistance = canvas.grid.measureDistances([{ray}], {gridSpaces:false})[0] / canvas.grid.grid.options.dimensions.distance
} else {
ui.notifications.info("No token connected to this actor, unable to compute distance.")
}
if (defender ) {
rollData.forceAdvantage = defender.isAttackerAdvantage()
rollData.advantageFromTarget = true
@ -625,6 +634,10 @@ export class CrucibleActor extends Actor {
if ( !rollData.forceDisadvantage) { // This is an attack, check if disadvantaged
rollData.forceDisadvantage = this.isAttackDisadvantage()
}
if (rollData.weapon.system.isranged && rollData.tokensDistance > CrucibleUtility.getWeaponMaxRange(rollData.weapon) ) {
ui.notifications.warn(`Your target is out of range of your weapon (max: ${CrucibleUtility.getWeaponMaxRange(rollData.weapon)} - current : ${rollData.tokensDistance})` )
return
}
this.startRoll(rollData)
} else {
ui.notifications.warn("Unable to find the relevant skill for weapon " + weapon.name)
@ -663,6 +676,23 @@ export class CrucibleActor extends Actor {
}
}
/* -------------------------------------------- */
rollDefenseRanged(attackRollData) {
let rollData = this.getCommonRollData()
rollData.defenderTokenId = undefined // Cleanup
rollData.mode = "rangeddefense"
rollData.attackRollData = duplicate(attackRollData)
rollData.sizeDice = CrucibleUtility.getSizeDice( this.system.biodata.size )
rollData.effectiveRange = CrucibleUtility.getWeaponRange(attackRollData.weapon)
rollData.tokensDistance = attackRollData.tokensDistance // QoL copy
rollData.distanceBonusDice = Math.max(0, Math.floor((rollData.tokensDistance - rollData.effectiveRange) + 0.5))
rollData.hasCover = "none"
rollData.situational = "none"
rollData.useshield = false
rollData.shield = this.getEquippedShield()
this.startRoll(rollData)
}
/* -------------------------------------------- */
rollShieldDie() {
let shield = this.getEquippedShield()