|
|
|
@ -63,26 +63,22 @@ export class CrucibleActor extends Actor {
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
computeHitPoints() {
|
|
|
|
|
if (this.type == "character") {
|
|
|
|
|
let hp = duplicate(this.system.secondary.hp)
|
|
|
|
|
let max = (this.system.abilities.str.value + this.system.abilities.con.value) * 6
|
|
|
|
|
if (max != hp.max || hp.value > max) {
|
|
|
|
|
hp.max = max
|
|
|
|
|
hp.value = max // Init case
|
|
|
|
|
this.update({ 'system.secondary.hp': hp })
|
|
|
|
|
}
|
|
|
|
|
let hp = duplicate(this.system.secondary.hp)
|
|
|
|
|
let max = (this.system.abilities.str.value + this.system.abilities.con.value) * 6
|
|
|
|
|
if (max != hp.max || hp.value > max) {
|
|
|
|
|
hp.max = max
|
|
|
|
|
hp.value = max // Init case
|
|
|
|
|
this.update({ 'system.secondary.hp': hp })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
computeEffortPoints() {
|
|
|
|
|
if (this.type == "character") {
|
|
|
|
|
let effort = duplicate(this.system.secondary.effort)
|
|
|
|
|
let max = (this.system.abilities.con.value + this.system.abilities.int.value) * 6
|
|
|
|
|
if (max != effort.max || effort.value > max) {
|
|
|
|
|
effort.max = max
|
|
|
|
|
effort.value = max // Init case
|
|
|
|
|
this.update({ 'system.secondary.effort': effort })
|
|
|
|
|
}
|
|
|
|
|
let effort = duplicate(this.system.secondary.effort)
|
|
|
|
|
let max = (this.system.abilities.con.value + this.system.abilities.int.value) * 6
|
|
|
|
|
if (max != effort.max || effort.value > max) {
|
|
|
|
|
effort.max = max
|
|
|
|
|
effort.value = max // Init case
|
|
|
|
|
this.update({ 'system.secondary.effort': effort })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -333,21 +329,21 @@ export class CrucibleActor extends Actor {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
async rollArmor(rollData) {
|
|
|
|
|
async rollArmor( rollData) {
|
|
|
|
|
let armor = this.getEquippedArmor()
|
|
|
|
|
if (armor) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return { armor: "none" }
|
|
|
|
|
return { armor: "none"}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
async incDecHP(formula) {
|
|
|
|
|
let dmgRoll = new Roll(formula).roll({ async: false })
|
|
|
|
|
async incDecHP( formula ) {
|
|
|
|
|
let dmgRoll = new Roll(formula).roll( {async: false})
|
|
|
|
|
await CrucibleUtility.showDiceSoNice(dmgRoll, game.settings.get("core", "rollMode"))
|
|
|
|
|
let hp = duplicate(this.system.secondary.hp)
|
|
|
|
|
hp.value = Number(hp.value) + Number(dmgRoll.total)
|
|
|
|
|
this.update({ 'system.secondary.hp': hp })
|
|
|
|
|
this.update( {'system.secondary.hp': hp })
|
|
|
|
|
return Number(dmgRoll.total)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -505,38 +501,38 @@ export class CrucibleActor extends Actor {
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
isForcedAdvantage() {
|
|
|
|
|
return this.items.find(cond => cond.type == "condition" && cond.system.advantage)
|
|
|
|
|
return this.items.find(cond => cond.type =="condition" && cond.system.advantage)
|
|
|
|
|
}
|
|
|
|
|
isForcedDisadvantage() {
|
|
|
|
|
return this.items.find(cond => cond.type == "condition" && cond.system.disadvantage)
|
|
|
|
|
return this.items.find(cond => cond.type =="condition" && cond.system.disadvantage)
|
|
|
|
|
}
|
|
|
|
|
isForcedRollAdvantage() {
|
|
|
|
|
return this.items.find(cond => cond.type == "condition" && cond.system.rolladvantage)
|
|
|
|
|
return this.items.find(cond => cond.type =="condition" && cond.system.rolladvantage)
|
|
|
|
|
}
|
|
|
|
|
isForcedRollDisadvantage() {
|
|
|
|
|
return this.items.find(cond => cond.type == "condition" && cond.system.rolldisadvantage)
|
|
|
|
|
return this.items.find(cond => cond.type =="condition" && cond.system.rolldisadvantage)
|
|
|
|
|
}
|
|
|
|
|
isNoAdvantage() {
|
|
|
|
|
return this.items.find(cond => cond.type == "condition" && cond.system.noadvantage)
|
|
|
|
|
return this.items.find(cond => cond.type =="condition" && cond.system.noadvantage)
|
|
|
|
|
}
|
|
|
|
|
isNoAction() {
|
|
|
|
|
return this.items.find(cond => cond.type == "condition" && cond.system.noaction)
|
|
|
|
|
return this.items.find(cond => cond.type =="condition" && cond.system.noaction)
|
|
|
|
|
}
|
|
|
|
|
isAttackDisadvantage() {
|
|
|
|
|
return this.items.find(cond => cond.type == "condition" && cond.system.attackdisadvantage)
|
|
|
|
|
return this.items.find(cond => cond.type =="condition" && cond.system.attackdisadvantage)
|
|
|
|
|
}
|
|
|
|
|
isDefenseDisadvantage() {
|
|
|
|
|
return this.items.find(cond => cond.type == "condition" && cond.system.defensedisadvantage)
|
|
|
|
|
return this.items.find(cond => cond.type =="condition" && cond.system.defensedisadvantage)
|
|
|
|
|
}
|
|
|
|
|
isAttackerAdvantage() {
|
|
|
|
|
return this.items.find(cond => cond.type == "condition" && cond.system.targetadvantage)
|
|
|
|
|
return this.items.find(cond => cond.type =="condition" && cond.system.targetadvantage)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
getCommonRollData(abilityKey = undefined) {
|
|
|
|
|
let noAction = this.isNoAction()
|
|
|
|
|
if (noAction) {
|
|
|
|
|
ui.notifications.warn("You can't do any actions du to the condition : " + noAction.name)
|
|
|
|
|
if ( noAction) {
|
|
|
|
|
ui.notifications.warn("You can't do any actions du to the condition : " + noAction.name )
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -559,24 +555,24 @@ export class CrucibleActor extends Actor {
|
|
|
|
|
rollData.forceRollAdvantage = this.isForcedRollAdvantage()
|
|
|
|
|
rollData.forceRollDisadvantage = this.isForcedRollDisadvantage()
|
|
|
|
|
rollData.noAdvantage = this.isNoAdvantage()
|
|
|
|
|
if (rollData.defenderTokenId) {
|
|
|
|
|
if ( rollData.defenderTokenId) {
|
|
|
|
|
let defenderToken = game.canvas.tokens.get(rollData.defenderTokenId)
|
|
|
|
|
let defender = defenderToken.actor
|
|
|
|
|
|
|
|
|
|
// Distance management
|
|
|
|
|
let token = this.token
|
|
|
|
|
if (!token) {
|
|
|
|
|
let tokens = this.getActiveTokens()
|
|
|
|
|
if ( !token) {
|
|
|
|
|
let tokens =this.getActiveTokens()
|
|
|
|
|
token = tokens[0]
|
|
|
|
|
}
|
|
|
|
|
if (token) {
|
|
|
|
|
if ( token ) {
|
|
|
|
|
const ray = new Ray(token.object?.center || token.center, defenderToken.center)
|
|
|
|
|
rollData.tokensDistance = canvas.grid.measureDistances([{ ray }], { gridSpaces: false })[0] / canvas.grid.grid.options.dimensions.distance
|
|
|
|
|
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.")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if (defender) {
|
|
|
|
|
if (defender ) {
|
|
|
|
|
rollData.forceAdvantage = defender.isAttackerAdvantage()
|
|
|
|
|
rollData.advantageFromTarget = true
|
|
|
|
|
}
|
|
|
|
@ -641,7 +637,7 @@ export class CrucibleActor extends Actor {
|
|
|
|
|
rollData.skill = skill
|
|
|
|
|
rollData.weapon = weapon
|
|
|
|
|
rollData.img = weapon.img
|
|
|
|
|
if (!rollData.forceDisadvantage) { // This is an attack, check if disadvantaged
|
|
|
|
|
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) ) {
|
|
|
|
@ -673,7 +669,7 @@ export class CrucibleActor extends Actor {
|
|
|
|
|
rollData.skill = skill
|
|
|
|
|
rollData.weapon = weapon
|
|
|
|
|
rollData.img = weapon.img
|
|
|
|
|
if (!rollData.forceDisadvantage) { // This is an attack, check if disadvantaged
|
|
|
|
|
if ( !rollData.forceDisadvantage) { // This is an attack, check if disadvantaged
|
|
|
|
|
rollData.forceDisadvantage = this.isDefenseDisadvantage()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -691,16 +687,14 @@ export class CrucibleActor extends Actor {
|
|
|
|
|
let rollData = this.getCommonRollData()
|
|
|
|
|
rollData.defenderTokenId = undefined // Cleanup
|
|
|
|
|
rollData.mode = "rangeddefense"
|
|
|
|
|
if ( attackRollData) {
|
|
|
|
|
rollData.attackRollData = duplicate(attackRollData)
|
|
|
|
|
rollData.effectiveRange = CrucibleUtility.getWeaponRange(attackRollData.weapon)
|
|
|
|
|
rollData.tokensDistance = attackRollData.tokensDistance // QoL copy
|
|
|
|
|
}
|
|
|
|
|
rollData.sizeDice = CrucibleUtility.getSizeDice(this.system.biodata.size)
|
|
|
|
|
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 = 0 //Math.max(0, Math.floor((rollData.tokensDistance - rollData.effectiveRange) + 0.5))
|
|
|
|
|
rollData.hasCover = "none"
|
|
|
|
|
rollData.situational = "none"
|
|
|
|
|
rollData.useshield = false
|
|
|
|
|
rollData.situational = "none"
|
|
|
|
|
rollData.useshield = false
|
|
|
|
|
rollData.shield = this.getEquippedShield()
|
|
|
|
|
this.startRoll(rollData)
|
|
|
|
|
}
|
|
|
|
@ -731,51 +725,51 @@ export class CrucibleActor extends Actor {
|
|
|
|
|
let messages = ["Armor applied"]
|
|
|
|
|
|
|
|
|
|
if (rollData) {
|
|
|
|
|
if (CrucibleUtility.isArmorLight(armor) && CrucibleUtility.isWeaponPenetrating(rollData.attackRollData.weapon)) {
|
|
|
|
|
if (CrucibleUtility.isArmorLight(armor) && CrucibleUtility.isWeaponPenetrating(rollData.attackRollData.weapon) ) {
|
|
|
|
|
return { armorIgnored: true, nbSuccess: 0, messages: ["Armor ignored : Penetrating weapons ignore Light Armors."] }
|
|
|
|
|
}
|
|
|
|
|
if (CrucibleUtility.isWeaponPenetrating(rollData.attackRollData.weapon)) {
|
|
|
|
|
if (CrucibleUtility.isWeaponPenetrating(rollData.attackRollData.weapon) ) {
|
|
|
|
|
messages.push("Armor reduced by 1 (Penetrating weapon)")
|
|
|
|
|
reduce = 1
|
|
|
|
|
}
|
|
|
|
|
if (CrucibleUtility.isWeaponLight(rollData.attackRollData.weapon)) {
|
|
|
|
|
if (CrucibleUtility.isWeaponLight(rollData.attackRollData.weapon) ) {
|
|
|
|
|
messages.push("Armor with advantage (Light weapon)")
|
|
|
|
|
advantage = true
|
|
|
|
|
}
|
|
|
|
|
if (CrucibleUtility.isWeaponHeavy(rollData.attackRollData.weapon)) {
|
|
|
|
|
if (CrucibleUtility.isWeaponHeavy(rollData.attackRollData.weapon) ) {
|
|
|
|
|
messages.push("Armor with disadvantage (Heavy weapon)")
|
|
|
|
|
disadvantage = true
|
|
|
|
|
}
|
|
|
|
|
if (CrucibleUtility.isWeaponHack(rollData.attackRollData.weapon)) {
|
|
|
|
|
if (CrucibleUtility.isWeaponHack(rollData.attackRollData.weapon) ) {
|
|
|
|
|
messages.push("Armor reduced by 1 (Hack weapon)")
|
|
|
|
|
reduce = 1
|
|
|
|
|
}
|
|
|
|
|
if (CrucibleUtility.isWeaponUndamaging(rollData.attackRollData.weapon)) {
|
|
|
|
|
if (CrucibleUtility.isWeaponUndamaging(rollData.attackRollData.weapon) ) {
|
|
|
|
|
messages.push("Armor multiplied by 2 (Undamaging weapon)")
|
|
|
|
|
multiply = 2
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let diceColor = armor.system.absorprionroll
|
|
|
|
|
let armorResult = await CrucibleUtility.getRollTableFromDiceColor(diceColor, false)
|
|
|
|
|
let armorResult = await CrucibleUtility.getRollTableFromDiceColor( diceColor, false )
|
|
|
|
|
console.log("Armor log", armorResult)
|
|
|
|
|
let armorValue = Math.max(0, (Number(armorResult.text) + reduce) * multiply)
|
|
|
|
|
if (advantage || disadvantage) {
|
|
|
|
|
let armorResult2 = await CrucibleUtility.getRollTableFromDiceColor(diceColor, false)
|
|
|
|
|
let armorValue2 = Math.max(0, (Number(armorResult2.text) + reduce) * multiply)
|
|
|
|
|
if (advantage) {
|
|
|
|
|
let armorValue = (Number(armorResult.text) + reduce) * multiply
|
|
|
|
|
if ( advantage || disadvantage) {
|
|
|
|
|
let armorResult2 = await CrucibleUtility.getRollTableFromDiceColor( diceColor, false )
|
|
|
|
|
let armorValue2 = (Number(armorResult2.text) + reduce) * multiply
|
|
|
|
|
if ( advantage) {
|
|
|
|
|
armorValue = (armorValue2 > armorValue) ? armorValue2 : armorValue
|
|
|
|
|
messages.push(`Armor advantage - Roll 1 = ${armorValue} - Roll 2 = ${armorValue2}`)
|
|
|
|
|
}
|
|
|
|
|
if (disadvantage) {
|
|
|
|
|
if ( disadvantage) {
|
|
|
|
|
armorValue = (armorValue2 < armorValue) ? armorValue2 : armorValue
|
|
|
|
|
messages.push(`Armor disadvantage - Roll 1 = ${armorValue} - Roll 2 = ${armorValue2}`)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
armorResult.armorValue = armorValue
|
|
|
|
|
if (!rollData) {
|
|
|
|
|
ChatMessage.create({ content: "Armor result : " + armorValue })
|
|
|
|
|
if ( !rollData) {
|
|
|
|
|
ChatMessage.create( { content: "Armor result : " + armorValue } )
|
|
|
|
|
}
|
|
|
|
|
messages.push("Armor result : " + armorValue)
|
|
|
|
|
messages.push( "Armor result : " + armorValue)
|
|
|
|
|
return { armorIgnored: false, nbSuccess: armorValue, rawArmor: armorResult.text, messages: messages }
|
|
|
|
|
}
|
|
|
|
|
return { armorIgnored: true, nbSuccess: 0, messages: ["No armor equipped."] }
|
|
|
|
|