Manage conditions

This commit is contained in:
2022-08-17 17:07:45 +02:00
parent 66f70897ed
commit aab562bed9
5 changed files with 193 additions and 117 deletions

View File

@@ -499,8 +499,43 @@ export class CrucibleActor extends Actor {
}
}
/* -------------------------------------------- */
isForcedAdvantage() {
return this.items.find(cond => cond.type =="condition" && cond.system.advantage)
}
isForcedDisadvantage() {
return this.items.find(cond => cond.type =="condition" && cond.system.disadvantage)
}
isForcedRollAdvantage() {
return this.items.find(cond => cond.type =="condition" && cond.system.rolladvantage)
}
isForcedRollDisadvantage() {
return this.items.find(cond => cond.type =="condition" && cond.system.rolldisadvantage)
}
isNoAdvantage() {
return this.items.find(cond => cond.type =="condition" && cond.system.noadvantage)
}
isNoAction() {
return this.items.find(cond => cond.type =="condition" && cond.system.noaction)
}
isAttackDisadvantage() {
return this.items.find(cond => cond.type =="condition" && cond.system.attackdisadvantage)
}
isDefenseDisadvantage() {
return this.items.find(cond => cond.type =="condition" && cond.system.defensedisadvantage)
}
isAttackerAdvantage() {
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 )
return
}
let rollData = CrucibleUtility.getBasicRollData()
rollData.alias = this.name
rollData.actorImg = this.img
@@ -509,15 +544,27 @@ export class CrucibleActor extends Actor {
rollData.featsDie = this.getFeatsWithDie()
rollData.featsSL = this.getFeatsWithSL()
rollData.armors = this.getArmors()
rollData.conditions = this.getConditions()
rollData.featDieName = "none"
rollData.featSLName = "none"
rollData.rollAdvantage = "none"
rollData.advantage = "none"
rollData.disadvantage = "none"
rollData.forceAdvantage = this.isForcedAdvantage()
rollData.forceDisadvantage = this.isForcedDisadvantage()
rollData.forceRollAdvantage = this.isForcedRollAdvantage()
rollData.forceRollDisadvantage = this.isForcedRollDisadvantage()
rollData.noAdvantage = this.isNoAdvantage()
if ( rollData.defenderTokenId) {
let defender = game.canvas.tokens.get(rollData.defenderTokenId).actor
if (defender ) {
rollData.forceAdvantage = defender.isAttackerAdvantage()
rollData.advantageFromTarget = true
}
}
if (abilityKey) {
rollData.ability = this.getAbility(abilityKey)
//rollData.skillList = this.getRelevantSkill(abilityKey)
rollData.selectedKill = undefined
}
@@ -575,7 +622,9 @@ 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
rollData.forceDisadvantage = this.isAttackDisadvantage()
}
this.startRoll(rollData)
} else {
ui.notifications.warn("Unable to find the relevant skill for weapon " + weapon.name)
@@ -601,6 +650,9 @@ 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
rollData.forceDisadvantage = this.isDefenseDisadvantage()
}
this.startRoll(rollData)
} else {

View File

@@ -532,7 +532,7 @@ export class CrucibleUtility {
// advantage => 8
let advFormula = "+ 0d8cs>=5"
if (rollData.advantage == "advantage1") {
if (rollData.advantage == "advantage1" || rollData.forceAdvantage) {
advFormula = "+ 1d8cs>=5"
}
if (rollData.advantage == "advantage2") {
@@ -542,7 +542,7 @@ export class CrucibleUtility {
// disadvantage => 10
let disFormula = "- 0d8cs>=5"
if (rollData.disadvantage == "disadvantage1") {
if (rollData.disadvantage == "disadvantage1" || rollData.forceDisadvantage) {
disFormula = "- 1d8cs>=5"
}
if (rollData.disadvantage == "disadvantage2") {
@@ -581,7 +581,14 @@ export class CrucibleUtility {
rollData.rollOrder = 0
rollData.roll = myRoll
rollData.nbSuccess = myRoll.total
if (rollData.rollAdvantage != "none") {
if ( rollData.rollAdvantage == "none" && rollData.forceRollAdvantage) {
rollData.rollAdvantage = "roll-advantage"
}
if ( rollData.rollAdvantage == "none" && rollData.forceRollDisadvantage) {
rollData.rollAdvantage = "roll-disadvantage"
}
if (rollData.rollAdvantage != "none" ) {
rollData.rollOrder = 1
rollData.rollType = (rollData.rollAdvantage == "roll-advantage") ? "Advantage": "Disadvantage"