This commit is contained in:
2022-11-27 16:06:26 +01:00
parent 56ff013178
commit c5a962936c
13 changed files with 322 additions and 702 deletions

View File

@ -2,6 +2,9 @@
import { Avd12Combat } from "./avd12-combat.js";
import { Avd12Commands } from "./avd12-commands.js";
/* -------------------------------------------- */
const __ALLOWED_MODULE_TYPES = { "action": 1, "reaction": 1, "freeaction": 1, "trait": 1 }
/* -------------------------------------------- */
export class Avd12Utility {
@ -65,6 +68,11 @@ export class Avd12Utility {
return duplicate(this.shieldSkills)
}
/* -------------------------------------------- */
static isModuleItemAllowed(type) {
return __ALLOWED_MODULE_TYPES[type]
}
/* -------------------------------------------- */
static buildBonusList() {
let bonusList = []
@ -466,95 +474,17 @@ export class Avd12Utility {
let actor = game.actors.get(rollData.actorId)
// ability/save/size => 0
let diceFormula
let startFormula = "0d6cs>=5"
if (rollData.ability) {
startFormula = String(rollData.ability.value) + "d6cs>=5"
}
if (rollData.save) {
startFormula = String(rollData.save.value) + "d6cs>=5"
}
if (rollData.sizeDice) {
let nb = rollData.sizeDice.nb + rollData.distanceBonusDice + this.getDiceFromCover(rollData.hasCover) + this.getDiceFromSituational(rollData.situational)
startFormula = String(nb) + String(rollData.sizeDice.dice) + "cs>=5"
}
diceFormula = startFormula
// skill => 2
// feat => 4
// bonus => 6
// Build the dice formula
let diceFormula = "1d12"
if (rollData.skill) {
let level = rollData.skill.system.level
if (rollData.skill.system.issl2) {
rollData.hasSLBonus = true
level += 2
if (level > 7) { level = 7 }
}
rollData.skill.system.skilldice = __skillLevel2Dice[level]
diceFormula += "+" + String(rollData.skill.system.skilldice) + "cs>=5"
if (rollData.skill.system.skilltype == "complex" && rollData.skill.system.level == 0) {
rollData.complexSkillDisadvantage = true
rollData.rollAdvantage = "roll-disadvantage"
}
if (rollData.skill.system.isfeatdie) {
rollData.hasFeatDie = true
diceFormula += "+ 1d10cs>=5"
} else {
diceFormula += `+ 0d10cs>=5`
}
if (rollData.skill.system.bonusdice != "none") {
rollData.hasBonusDice = rollData.skill.system.bonusdice
diceFormula += `+ ${rollData.hasBonusDice}cs>=5`
} else {
diceFormula += `+ 0d6cs>=5`
}
} else {
diceFormula += `+ 0d8cs=>5 + 0d10cs>=5 + 0d6cs>=5`
diceFormula += "+"+rollData.skill.finalvalue
}
// advantage => 8
let advFormula = "+ 0d8cs>=5"
if (rollData.advantage == "advantage1" || rollData.forceAdvantage) {
advFormula = "+ 1d8cs>=5"
}
if (rollData.advantage == "advantage2") {
advFormula = "+ 2d8cs>=5"
}
diceFormula += advFormula
// disadvantage => 10
let disFormula = "- 0d8cs>=5"
if (rollData.disadvantage == "disadvantage1" || rollData.forceDisadvantage) {
disFormula = "- 1d8cs>=5"
}
if (rollData.disadvantage == "disadvantage2") {
disFormula = "- 2d8cs>=5"
}
diceFormula += disFormula
// armor => 12
let skillArmorPenalty = 0
for (let armor of rollData.armors) {
if (armor.system.equipped) {
skillArmorPenalty += armor.system.skillpenalty
}
}
if (rollData.skill && rollData.skill.system.armorpenalty && skillArmorPenalty > 0) {
rollData.skillArmorPenalty = skillArmorPenalty
diceFormula += `- ${skillArmorPenalty}d8cs>=5`
} else {
diceFormula += `- 0d8cs>=5`
}
// shield => 14
if (rollData.useshield && rollData.shield) {
diceFormula += "+ 1" + String(rollData.shield.system.shielddie) + "cs>=5"
} else {
diceFormula += " + 0d6cs>=5"
diceFormula += "+"+rollData.bonusMalusRoll
if (rollData.skill && rollData.skill.good) {
diceFormula += "+1d4"
}
rollData.diceFormula = diceFormula
// Performs roll
console.log("Roll formula", diceFormula)
@ -563,74 +493,21 @@ export class Avd12Utility {
myRoll = new Roll(diceFormula).roll({ async: false })
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
}
rollData.rollOrder = 0
rollData.roll = myRoll
rollData.nbSuccess = myRoll.total
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"
this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-avd12/templates/chat-generic-result.html`, rollData)
})
rollData.rollOrder = 2
let myRoll2 = new Roll(diceFormula).roll({ async: false })
await this.showDiceSoNice(myRoll2, game.settings.get("core", "rollMode"))
rollData.roll = myRoll2 // Tmp switch to display the proper results
rollData.nbSuccess = myRoll2.total
this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-avd12/templates/chat-generic-result.html`, rollData)
})
rollData.roll = myRoll // Revert the tmp switch
rollData.nbSuccess = myRoll.total
if (rollData.rollAdvantage == "roll-advantage") {
if (myRoll2.total > rollData.nbSuccess) {
hasChanged = true
rollData.roll = myRoll2
rollData.nbSuccess = myRoll2.total
}
} else {
if (myRoll2.total < rollData.nbSuccess) {
rollData.roll = myRoll2
rollData.nbSuccess = myRoll2.total
}
}
rollData.rollOrder = 3
}
rollData.nbSuccess = Math.max(0, rollData.nbSuccess)
rollData.isFirstRollAdvantage = false
// Manage exp
if (rollData.skill && rollData.skill.system.level > 0) {
let nbSkillSuccess = rollData.roll.terms[2].total
if (nbSkillSuccess == 0 || nbSkillSuccess == rollData.skill.system.level) {
actor.incrementSkillExp(rollData.skill.id, 1)
rollData.isSuccess = false
if ( rollData.targetCheck != "none") {
if( myRoll.total >= Number(rollData.targetCheck)) {
rollData.isSuccess = true
}
}
this.saveRollData(rollData)
actor.lastRoll = rollData
this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-avd12/templates/chat-generic-result.html`, rollData)
let msg = await this.createChatWithRollMode(rollData.alias, {
content: await renderTemplate(`systems/fvtt-avd12/templates/chat/chat-generic-result.hbs`, rollData)
})
msg.setFlag("world", "rolldata", rollData)
console.log("Rolldata result", rollData)
// Message response
this.displayDefenseMessage(rollData)
// Manage defense result
this.processAttackDefense(rollData)
}
/* -------------------------------------------- */
@ -724,15 +601,16 @@ export class Avd12Utility {
break;
}
chatOptions.alias = chatOptions.alias || name;
ChatMessage.create(chatOptions);
return ChatMessage.create(chatOptions);
}
/* -------------------------------------------- */
static getBasicRollData() {
let rollData = {
rollId: randomID(16),
rollMode: game.settings.get("core", "rollMode"),
advantage: "none"
bonusMalusRoll: 0,
targetCheck : "none",
rollMode: game.settings.get("core", "rollMode")
}
Avd12Utility.updateWithTarget(rollData)
return rollData
@ -748,7 +626,7 @@ export class Avd12Utility {
/* -------------------------------------------- */
static createChatWithRollMode(name, chatOptions) {
this.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions)
return this.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions)
}
/* -------------------------------------------- */