2022-07-19 23:16:03 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
import { CrucibleCombat } from "./crucible-combat.js";
|
|
|
|
import { CrucibleCommands } from "./crucible-commands.js";
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
const __level2Dice = ["d0", "d4", "d6", "d8", "d10", "d12"];
|
|
|
|
const __name2DiceValue = { "0": 0, "d0": 0, "d4": 4, "d6": 6, "d8": 8, "d10": 10, "d12": 12 }
|
2022-08-06 17:06:05 +02:00
|
|
|
const __skillLevel2Dice = ["0d8", "1d8", "2d8", "3d8", "4d8", '6d8', "8d8", "10d8"]
|
|
|
|
const __color2RollTable = {
|
|
|
|
blue: "Blue Armor Die", black: "Black Armor Die", green: "Green Armor Die", purple: "Purple Armor Die",
|
|
|
|
white: "White Armor Die", red: "Red Armor Die", blackgreen: "Black & Green Armor Dice"
|
|
|
|
}
|
2022-08-17 22:51:52 +02:00
|
|
|
const __size2Dice = [ { nb: 0, dice: "d0" }, { nb: 5, dice: "d8" }, { nb: 3, dice: "d8" }, { nb: 2, dice: "d8" }, { nb: 1, dice: "d8" }, { nb: 1, dice: "d6" }, { nb: 1, noAddFirst: true, dice: "d6" }]
|
2022-07-19 23:16:03 +02:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
export class CrucibleUtility {
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async init() {
|
|
|
|
Hooks.on('renderChatLog', (log, html, data) => CrucibleUtility.chatListeners(html));
|
2022-08-14 10:10:26 +02:00
|
|
|
/*Hooks.on("dropCanvasData", (canvas, data) => {
|
2022-07-19 23:16:03 +02:00
|
|
|
CrucibleUtility.dropItemOnToken(canvas, data)
|
2022-08-14 10:10:26 +02:00
|
|
|
});*/
|
2022-07-19 23:16:03 +02:00
|
|
|
|
2022-08-06 17:06:05 +02:00
|
|
|
this.rollDataStore = {}
|
|
|
|
this.defenderStore = {}
|
2022-07-31 08:51:47 +02:00
|
|
|
|
2022-07-19 23:16:03 +02:00
|
|
|
CrucibleCommands.init();
|
|
|
|
|
|
|
|
Handlebars.registerHelper('count', function (list) {
|
|
|
|
return list.length;
|
|
|
|
})
|
|
|
|
Handlebars.registerHelper('includes', function (array, val) {
|
|
|
|
return array.includes(val);
|
|
|
|
})
|
|
|
|
Handlebars.registerHelper('upper', function (text) {
|
|
|
|
return text.toUpperCase();
|
|
|
|
})
|
|
|
|
Handlebars.registerHelper('lower', function (text) {
|
|
|
|
return text.toLowerCase()
|
|
|
|
})
|
|
|
|
Handlebars.registerHelper('upperFirst', function (text) {
|
|
|
|
if (typeof text !== 'string') return text
|
|
|
|
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
|
|
})
|
|
|
|
Handlebars.registerHelper('notEmpty', function (list) {
|
|
|
|
return list.length > 0;
|
|
|
|
})
|
|
|
|
Handlebars.registerHelper('mul', function (a, b) {
|
|
|
|
return parseInt(a) * parseInt(b);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-08-14 10:10:26 +02:00
|
|
|
/*-------------------------------------------- */
|
|
|
|
static upperFirst(text) {
|
|
|
|
if (typeof text !== 'string') return text
|
|
|
|
return text.charAt(0).toUpperCase() + text.slice(1)
|
|
|
|
}
|
2022-08-17 22:51:52 +02:00
|
|
|
|
2022-07-19 23:16:03 +02:00
|
|
|
/*-------------------------------------------- */
|
|
|
|
static getSkills() {
|
2022-07-31 08:51:47 +02:00
|
|
|
return duplicate(this.skills)
|
|
|
|
}
|
|
|
|
/*-------------------------------------------- */
|
|
|
|
static getWeaponSkills() {
|
|
|
|
return duplicate(this.weaponSkills)
|
2022-07-19 23:16:03 +02:00
|
|
|
}
|
2022-08-04 10:25:40 +02:00
|
|
|
/*-------------------------------------------- */
|
|
|
|
static getShieldSkills() {
|
|
|
|
return duplicate(this.shieldSkills)
|
|
|
|
}
|
2022-08-06 17:06:05 +02:00
|
|
|
|
2022-07-19 23:16:03 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async ready() {
|
2022-07-31 09:16:17 +02:00
|
|
|
const skills = await CrucibleUtility.loadCompendium("fvtt-crucible-rpg.skills")
|
|
|
|
this.skills = skills.map(i => i.toObject())
|
2022-08-16 22:29:27 +02:00
|
|
|
this.weaponSkills = duplicate(this.skills.filter(item => item.system.isweaponskill))
|
|
|
|
this.shieldSkills = duplicate(this.skills.filter(item => item.system.isshieldskill))
|
2022-08-05 10:04:42 +02:00
|
|
|
|
|
|
|
const rollTables = await CrucibleUtility.loadCompendium("fvtt-crucible-rpg.rolltables")
|
|
|
|
this.rollTables = rollTables.map(i => i.toObject())
|
|
|
|
|
2022-07-19 23:16:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async loadCompendiumData(compendium) {
|
2022-08-05 10:04:42 +02:00
|
|
|
const pack = game.packs.get(compendium)
|
|
|
|
return await pack?.getDocuments() ?? []
|
2022-07-19 23:16:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async loadCompendium(compendium, filter = item => true) {
|
2022-08-05 10:04:42 +02:00
|
|
|
let compendiumData = await CrucibleUtility.loadCompendiumData(compendium)
|
|
|
|
return compendiumData.filter(filter)
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2022-08-14 10:10:26 +02:00
|
|
|
static isArmorLight(armor) {
|
2022-08-16 22:29:27 +02:00
|
|
|
if (armor && (armor.system.armortype.includes("light") || armor.system.armortype.includes("clothes"))) {
|
2022-08-14 10:10:26 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static isWeaponPenetrating(weapon) {
|
2022-08-16 22:29:27 +02:00
|
|
|
if (weapon && weapon.system.qualities.toLowerCase().includes("penetrating")) {
|
2022-08-14 10:10:26 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static isWeaponLight(weapon) {
|
2022-08-16 22:29:27 +02:00
|
|
|
if (weapon && weapon.system.qualities.toLowerCase().includes("light")) {
|
2022-08-14 10:10:26 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static isWeaponHeavy(weapon) {
|
2022-08-16 22:29:27 +02:00
|
|
|
if (weapon && weapon.system.qualities.toLowerCase().includes("heavy")) {
|
2022-08-14 10:10:26 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static isWeaponHack(weapon) {
|
2022-08-16 22:29:27 +02:00
|
|
|
if (weapon && weapon.system.qualities.toLowerCase().includes("hack")) {
|
2022-08-14 10:10:26 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static isWeaponUndamaging(weapon) {
|
2022-08-16 22:29:27 +02:00
|
|
|
if (weapon && weapon.system.qualities.toLowerCase().includes("undamaging")) {
|
2022-08-14 10:10:26 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static isWeaponDangerous(weapon) {
|
2022-08-16 22:29:27 +02:00
|
|
|
if (weapon && weapon.system.qualities.toLowerCase().includes("dangerous")) {
|
2022-08-14 10:10:26 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static isWeaponDeadly(weapon) {
|
2022-08-16 22:29:27 +02:00
|
|
|
if (weapon && weapon.system.qualities.toLowerCase().includes("deadly")) {
|
2022-08-14 10:10:26 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2022-08-17 22:51:52 +02:00
|
|
|
static getWeaponRange(weapon) {
|
|
|
|
if (weapon && weapon.system.isranged) {
|
|
|
|
let rangeValue = weapon.system.range.replace(/[^0-9]/g, '')
|
|
|
|
return Number(rangeValue)
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
static getWeaponMaxRange(weapon) {
|
|
|
|
if (weapon && weapon.system.isranged) {
|
|
|
|
let rangeValue = weapon.system.maxrange.replace(/[^0-9]/g, '')
|
|
|
|
return Number(rangeValue)
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2022-08-14 10:10:26 +02:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async getRollTableFromDiceColor(diceColor, displayChat = true) {
|
2022-08-05 10:04:42 +02:00
|
|
|
let rollTableName = __color2RollTable[diceColor]
|
|
|
|
if (rollTableName) {
|
|
|
|
const pack = game.packs.get("fvtt-crucible-rpg.rolltables")
|
|
|
|
const index = await pack.getIndex()
|
|
|
|
const entry = index.find(e => e.name === rollTableName)
|
|
|
|
let table = await pack.getDocument(entry._id)
|
2022-08-14 10:10:26 +02:00
|
|
|
const draw = await table.draw({ displayChat: displayChat, rollMode: "gmroll" })
|
2022-08-05 10:04:42 +02:00
|
|
|
return draw.results.length > 0 ? draw.results[0] : undefined
|
2022-08-06 17:06:05 +02:00
|
|
|
}
|
2022-07-19 23:16:03 +02:00
|
|
|
}
|
2022-08-17 22:51:52 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getSizeDice(sizeValue) {
|
|
|
|
return __size2Dice[sizeValue]
|
|
|
|
}
|
2022-07-19 23:16:03 +02:00
|
|
|
|
2022-08-14 10:10:26 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async getCritical(level, weapon) {
|
|
|
|
const pack = game.packs.get("fvtt-crucible-rpg.rolltables")
|
|
|
|
|
2022-08-16 22:29:27 +02:00
|
|
|
let tableName = "Crit " + level + " (" + this.upperFirst(weapon.system.damage) + ")"
|
2022-08-14 10:10:26 +02:00
|
|
|
const index = await pack.getIndex()
|
|
|
|
const entry = index.find(e => e.name === tableName)
|
|
|
|
let table = await pack.getDocument(entry._id)
|
|
|
|
const draw = await table.draw({ displayChat: false, rollMode: "gmroll" })
|
|
|
|
return draw.results.length > 0 ? draw.results[0] : undefined
|
|
|
|
}
|
|
|
|
|
2022-07-19 23:16:03 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async chatListeners(html) {
|
|
|
|
|
|
|
|
html.on("click", '.view-item-from-chat', event => {
|
|
|
|
game.system.crucible.creator.openItemView(event)
|
|
|
|
})
|
2022-08-06 17:06:05 +02:00
|
|
|
html.on("click", '.roll-defense-melee', event => {
|
|
|
|
let rollId = $(event.currentTarget).data("roll-id")
|
2022-08-14 10:10:26 +02:00
|
|
|
let rollData = CrucibleUtility.getRollData(rollId)
|
2022-08-06 17:06:05 +02:00
|
|
|
rollData.defenseWeaponId = $(event.currentTarget).data("defense-weapon-id")
|
2022-08-14 10:10:26 +02:00
|
|
|
let actor = game.canvas.tokens.get(rollData.defenderTokenId).actor
|
|
|
|
if (actor && (game.user.isGM || actor.isOwner)) {
|
|
|
|
actor.rollDefenseMelee(rollData)
|
|
|
|
}
|
2022-08-06 17:06:05 +02:00
|
|
|
})
|
2022-08-17 22:51:52 +02:00
|
|
|
html.on("click", '.roll-defense-ranged', event => {
|
|
|
|
let rollId = $(event.currentTarget).data("roll-id")
|
|
|
|
let rollData = CrucibleUtility.getRollData(rollId)
|
|
|
|
let defender = game.canvas.tokens.get(rollData.defenderTokenId).actor
|
|
|
|
if (defender && (game.user.isGM || defender.isOwner)) {
|
|
|
|
defender.rollDefenseRanged(rollData)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-07-19 23:16:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async preloadHandlebarsTemplates() {
|
|
|
|
|
|
|
|
const templatePaths = [
|
|
|
|
'systems/fvtt-crucible-rpg/templates/editor-notes-gm.html',
|
2022-07-26 21:40:42 +02:00
|
|
|
'systems/fvtt-crucible-rpg/templates/partial-roll-select.html',
|
2022-07-25 19:13:52 +02:00
|
|
|
'systems/fvtt-crucible-rpg/templates/partial-actor-ability-block.html',
|
|
|
|
'systems/fvtt-crucible-rpg/templates/partial-actor-status.html',
|
2022-07-23 10:06:51 +02:00
|
|
|
'systems/fvtt-crucible-rpg/templates/partial-options-abilities.html',
|
2022-07-19 23:16:03 +02:00
|
|
|
'systems/fvtt-crucible-rpg/templates/partial-item-nav.html',
|
|
|
|
'systems/fvtt-crucible-rpg/templates/partial-item-description.html',
|
|
|
|
'systems/fvtt-crucible-rpg/templates/partial-actor-equipment.html'
|
|
|
|
]
|
|
|
|
return loadTemplates(templatePaths);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static removeChatMessageId(messageId) {
|
|
|
|
if (messageId) {
|
|
|
|
game.messages.get(messageId)?.delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static findChatMessageId(current) {
|
|
|
|
return CrucibleUtility.getChatMessageId(CrucibleUtility.findChatMessage(current));
|
|
|
|
}
|
|
|
|
|
|
|
|
static getChatMessageId(node) {
|
|
|
|
return node?.attributes.getNamedItem('data-message-id')?.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static findChatMessage(current) {
|
|
|
|
return CrucibleUtility.findNodeMatching(current, it => it.classList.contains('chat-message') && it.attributes.getNamedItem('data-message-id'));
|
|
|
|
}
|
|
|
|
|
|
|
|
static findNodeMatching(current, predicate) {
|
|
|
|
if (current) {
|
|
|
|
if (predicate(current)) {
|
|
|
|
return current;
|
|
|
|
}
|
|
|
|
return CrucibleUtility.findNodeMatching(current.parentElement, predicate);
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static createDirectOptionList(min, max) {
|
|
|
|
let options = {};
|
|
|
|
for (let i = min; i <= max; i++) {
|
|
|
|
options[`${i}`] = `${i}`;
|
|
|
|
}
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static buildListOptions(min, max) {
|
|
|
|
let options = ""
|
|
|
|
for (let i = min; i <= max; i++) {
|
|
|
|
options += `<option value="${i}">${i}</option>`
|
|
|
|
}
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getTarget() {
|
2022-08-14 10:10:26 +02:00
|
|
|
if (game.user.targets) {
|
2022-07-19 23:16:03 +02:00
|
|
|
for (let target of game.user.targets) {
|
2022-08-14 10:10:26 +02:00
|
|
|
return target
|
2022-07-19 23:16:03 +02:00
|
|
|
}
|
|
|
|
}
|
2022-08-14 10:10:26 +02:00
|
|
|
return undefined
|
2022-07-19 23:16:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static updateRollData(rollData) {
|
|
|
|
|
|
|
|
let id = rollData.rollId
|
|
|
|
let oldRollData = this.rollDataStore[id] || {}
|
|
|
|
let newRollData = mergeObject(oldRollData, rollData)
|
|
|
|
this.rollDataStore[id] = newRollData
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static saveRollData(rollData) {
|
|
|
|
game.socket.emit("system.crucible-rpg", {
|
|
|
|
name: "msg_update_roll", data: rollData
|
|
|
|
}); // Notify all other clients of the roll
|
|
|
|
this.updateRollData(rollData)
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getRollData(id) {
|
|
|
|
return this.rollDataStore[id]
|
|
|
|
}
|
|
|
|
|
2022-08-06 17:06:05 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async displayDefenseMessage(rollData) {
|
2022-08-17 22:51:52 +02:00
|
|
|
if (rollData.mode == "weapon" && rollData.defenderTokenId) {
|
2022-08-06 17:06:05 +02:00
|
|
|
let defender = game.canvas.tokens.get(rollData.defenderTokenId).actor
|
|
|
|
if (game.user.isGM || (game.user.character && game.user.character.id == defender.id)) {
|
|
|
|
rollData.defender = defender
|
|
|
|
rollData.defenderWeapons = defender.getEquippedWeapons()
|
2022-08-17 22:51:52 +02:00
|
|
|
rollData.isRangedAttack = rollData.weapon?.system.isranged
|
2022-08-06 17:06:05 +02:00
|
|
|
this.createChatWithRollMode(defender.name, {
|
2022-08-16 22:29:27 +02:00
|
|
|
name: defender.name,
|
2022-08-06 17:06:05 +02:00
|
|
|
alias: defender.name,
|
2022-08-16 22:29:27 +02:00
|
|
|
//user: defender.id,
|
2022-08-06 17:06:05 +02:00
|
|
|
content: await renderTemplate(`systems/fvtt-crucible-rpg/templates/chat-request-defense.html`, rollData),
|
|
|
|
whisper: [defender.id].concat(ChatMessage.getWhisperRecipients('GM')),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-10 14:41:40 +02:00
|
|
|
/* -------------------------------------------- */
|
2022-08-14 10:10:26 +02:00
|
|
|
static getSuccessResult(rollData) {
|
|
|
|
if (rollData.sumSuccess <= -3) {
|
2022-08-26 13:23:06 +02:00
|
|
|
if (rollData.attackRollData.weapon.system.isranged ) {
|
|
|
|
return { result: "miss", fumble: true, hpLossType: "melee" }
|
|
|
|
} else {
|
|
|
|
return { result: "miss", fumble: true, attackerHPLoss: "2d3", hpLossType: "melee" }
|
|
|
|
}
|
2022-08-14 10:10:26 +02:00
|
|
|
}
|
|
|
|
if (rollData.sumSuccess == -2) {
|
2022-08-26 13:23:06 +02:00
|
|
|
if (rollData.attackRollData.weapon.system.isranged ) {
|
|
|
|
return { result: "miss", dangerous_fumble: true }
|
|
|
|
} else {
|
|
|
|
return { result: "miss", dangerous_fumble: true, attackerHPLoss: "1d3", hpLossType: "melee" }
|
|
|
|
}
|
2022-08-14 10:10:26 +02:00
|
|
|
}
|
|
|
|
if (rollData.sumSuccess == -1) {
|
|
|
|
return { result: "miss" }
|
|
|
|
}
|
|
|
|
if (rollData.sumSuccess == 0) {
|
2022-08-16 22:29:27 +02:00
|
|
|
if (rollData.attackRollData.weapon.system.isranged) {
|
2022-08-14 10:10:26 +02:00
|
|
|
return { result: "target_space", aoe: true }
|
|
|
|
} else {
|
|
|
|
return { result: "clash", hack_vs_shields: true }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rollData.sumSuccess == 1) {
|
|
|
|
return { result: "hit", defenderDamage: "1", entangle: true, knockback: true }
|
|
|
|
}
|
|
|
|
if (rollData.sumSuccess == 2) {
|
|
|
|
return { result: "hit", defenderDamage: "2", critical_1: true, entangle: true, knockback: true, penetrating_impale: true, hack_armors: true }
|
|
|
|
}
|
|
|
|
if (rollData.sumSuccess >= 3) {
|
|
|
|
return { result: "hit", defenderDamage: "3", critical_2: true, entangle: true, knockback: true, penetrating_impale: true, hack_armors: true }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async getFumble(weapon) {
|
|
|
|
const pack = game.packs.get("fvtt-crucible-rpg.rolltables")
|
|
|
|
const index = await pack.getIndex()
|
|
|
|
let entry
|
|
|
|
|
|
|
|
if (weapon.isranged) {
|
|
|
|
entry = index.find(e => e.name === "Fumble! (ranged)")
|
|
|
|
}
|
|
|
|
if (!weapon.isranged) {
|
|
|
|
entry = index.find(e => e.name === "Fumble! (melee)")
|
|
|
|
}
|
|
|
|
let table = await pack.getDocument(entry._id)
|
|
|
|
const draw = await table.draw({ displayChat: false, rollMode: "gmroll" })
|
|
|
|
return draw.results.length > 0 ? draw.results[0] : undefined
|
2022-08-10 14:41:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2022-08-14 10:10:26 +02:00
|
|
|
static async processSuccessResult(rollData) {
|
|
|
|
if (game.user.isGM) { // Only GM process this
|
|
|
|
let result = rollData.successDetails
|
|
|
|
let attacker = game.actors.get(rollData.actorId)
|
|
|
|
let defender = game.canvas.tokens.get(rollData.attackRollData.defenderTokenId).actor
|
|
|
|
|
|
|
|
if (attacker && result.attackerHPLoss) {
|
|
|
|
result.attackerHPLossValue = await attacker.incDecHP("-" + result.attackerHPLoss)
|
|
|
|
}
|
|
|
|
if (attacker && defender && result.defenderDamage) {
|
2022-08-16 22:29:27 +02:00
|
|
|
let dmgDice = (rollData.attackRollData.weapon.system.isranged) ? "d6" : "d8"
|
2022-08-14 10:10:26 +02:00
|
|
|
result.damageWeaponFormula = result.defenderDamage + dmgDice
|
|
|
|
result.defenderHPLossValue = await defender.incDecHP("-" + result.damageWeaponFormula)
|
|
|
|
}
|
|
|
|
if (result.fumble || (result.dangerous_fumble && CrucibleUtility.isWeaponDangerous(rollData.attackRollData.weapon))) {
|
|
|
|
result.fumbleDetails = await this.getFumble(rollData.weapon)
|
|
|
|
}
|
|
|
|
if (result.critical_1 || result.critical_2) {
|
|
|
|
let isDeadly = CrucibleUtility.isWeaponDeadly(rollData.attackRollData.weapon)
|
2022-08-17 22:51:52 +02:00
|
|
|
result.critical = await this.getCritical((result.critical_1) ? "I" : "II", rollData.attackRollData.weapon)
|
2022-08-16 22:29:27 +02:00
|
|
|
result.criticalText = result.critical.text
|
2022-08-14 10:10:26 +02:00
|
|
|
}
|
|
|
|
this.createChatWithRollMode(rollData.alias, {
|
|
|
|
content: await renderTemplate(`systems/fvtt-crucible-rpg/templates/chat-attack-defense-result.html`, rollData)
|
|
|
|
})
|
|
|
|
console.log("Results processed", rollData)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async processAttackDefense(rollData) {
|
|
|
|
if (rollData.attackRollData) {
|
|
|
|
//console.log("Defender token, ", rollData, rollData.defenderTokenId)
|
|
|
|
let defender = game.canvas.tokens.get(rollData.attackRollData.defenderTokenId).actor
|
2022-08-10 14:41:40 +02:00
|
|
|
let sumSuccess = rollData.attackRollData.nbSuccess - rollData.nbSuccess
|
2022-08-14 10:10:26 +02:00
|
|
|
if (sumSuccess > 0) {
|
|
|
|
let armorResult = await defender.rollArmorDie(rollData)
|
|
|
|
rollData.armorResult = armorResult
|
|
|
|
sumSuccess += rollData.armorResult.nbSuccess
|
|
|
|
if (sumSuccess < 0) { // Never below 0
|
|
|
|
sumSuccess = 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rollData.sumSuccess = sumSuccess
|
|
|
|
rollData.successDetails = this.getSuccessResult(rollData)
|
|
|
|
if (game.user.isGM) {
|
|
|
|
this.processSuccessResult(rollData)
|
|
|
|
} else {
|
|
|
|
game.socket.emit("system.fvtt-crucible-rpg", { msg: "msg_gm_process_attack_defense", data: rollData });
|
|
|
|
}
|
2022-08-10 14:41:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-19 23:16:03 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async onSocketMesssage(msg) {
|
|
|
|
console.log("SOCKET MESSAGE", msg.name)
|
|
|
|
if (msg.name == "msg_update_roll") {
|
|
|
|
this.updateRollData(msg.data)
|
|
|
|
}
|
2022-08-14 10:10:26 +02:00
|
|
|
if (msg.name == "msg_gm_process_attack_defense") {
|
|
|
|
this.processSuccessResult(msg.data)
|
|
|
|
}
|
2022-07-19 23:16:03 +02:00
|
|
|
if (msg.name == "msg_gm_item_drop" && game.user.isGM) {
|
|
|
|
let actor = game.actors.get(msg.data.actorId)
|
|
|
|
let item
|
|
|
|
if (msg.data.isPack) {
|
|
|
|
item = await fromUuid("Compendium." + msg.data.isPack + "." + msg.data.itemId)
|
|
|
|
} else {
|
|
|
|
item = game.items.get(msg.data.itemId)
|
|
|
|
}
|
|
|
|
this.addItemDropToActor(actor, item)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static chatDataSetup(content, modeOverride, isRoll = false, forceWhisper) {
|
|
|
|
let chatData = {
|
|
|
|
user: game.user.id,
|
|
|
|
rollMode: modeOverride || game.settings.get("core", "rollMode"),
|
|
|
|
content: content
|
|
|
|
};
|
|
|
|
|
|
|
|
if (["gmroll", "blindroll"].includes(chatData.rollMode)) chatData["whisper"] = ChatMessage.getWhisperRecipients("GM").map(u => u.id);
|
|
|
|
if (chatData.rollMode === "blindroll") chatData["blind"] = true;
|
|
|
|
else if (chatData.rollMode === "selfroll") chatData["whisper"] = [game.user];
|
|
|
|
|
|
|
|
if (forceWhisper) { // Final force !
|
|
|
|
chatData["speaker"] = ChatMessage.getSpeaker();
|
|
|
|
chatData["whisper"] = ChatMessage.getWhisperRecipients(forceWhisper);
|
|
|
|
}
|
|
|
|
|
|
|
|
return chatData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async showDiceSoNice(roll, rollMode) {
|
|
|
|
if (game.modules.get("dice-so-nice")?.active) {
|
|
|
|
if (game.dice3d) {
|
|
|
|
let whisper = null;
|
|
|
|
let blind = false;
|
|
|
|
rollMode = rollMode ?? game.settings.get("core", "rollMode");
|
|
|
|
switch (rollMode) {
|
|
|
|
case "blindroll": //GM only
|
|
|
|
blind = true;
|
|
|
|
case "gmroll": //GM + rolling player
|
|
|
|
whisper = this.getUsers(user => user.isGM);
|
|
|
|
break;
|
|
|
|
case "roll": //everybody
|
|
|
|
whisper = this.getUsers(user => user.active);
|
|
|
|
break;
|
|
|
|
case "selfroll":
|
|
|
|
whisper = [game.user.id];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
await game.dice3d.showForRoll(roll, game.user, true, whisper, blind);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-01 21:39:17 +02:00
|
|
|
/* -------------------------------------------- */
|
2022-08-06 17:06:05 +02:00
|
|
|
static updateSkill(skill) {
|
2022-08-16 22:29:27 +02:00
|
|
|
skill.system.level = skill.system.background + skill.system.basic + skill.system.class + skill.system.explevel
|
|
|
|
if (skill.system.level > 7) { skill.system.level = 7 }
|
|
|
|
skill.system.skilldice = __skillLevel2Dice[skill.system.level]
|
2022-08-01 21:39:17 +02:00
|
|
|
}
|
2022-07-19 23:16:03 +02:00
|
|
|
|
2022-08-17 22:51:52 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getDiceFromCover(cover) {
|
|
|
|
if (cover == "cover50") return 1
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getDiceFromSituational(cover) {
|
|
|
|
if (cover == "prone") return 1
|
|
|
|
if (cover == "dodge") return 1
|
|
|
|
if (cover == "moving") return 1
|
|
|
|
if (cover == "engaged") return 1
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2022-07-19 23:16:03 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async rollCrucible(rollData) {
|
|
|
|
|
|
|
|
let actor = game.actors.get(rollData.actorId)
|
|
|
|
|
2022-08-17 22:51:52 +02:00
|
|
|
// ability/save/size => 0
|
2022-08-03 09:34:33 +02:00
|
|
|
let diceFormula
|
|
|
|
let startFormula = "0d6cs>=5"
|
2022-08-06 17:06:05 +02:00
|
|
|
if (rollData.ability) {
|
2022-08-03 09:34:33 +02:00
|
|
|
startFormula = String(rollData.ability.value) + "d6cs>=5"
|
|
|
|
}
|
2022-08-06 17:06:05 +02:00
|
|
|
if (rollData.save) {
|
2022-08-03 09:34:33 +02:00
|
|
|
startFormula = String(rollData.save.value) + "d6cs>=5"
|
|
|
|
}
|
2022-08-17 22:51:52 +02:00
|
|
|
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"
|
|
|
|
}
|
2022-08-03 09:34:33 +02:00
|
|
|
diceFormula = startFormula
|
2022-08-02 23:33:43 +02:00
|
|
|
|
|
|
|
// skill => 2
|
|
|
|
// feat => 4
|
|
|
|
// bonus => 6
|
2022-07-25 21:33:00 +02:00
|
|
|
if (rollData.skill) {
|
2022-08-16 22:29:27 +02:00
|
|
|
let level = rollData.skill.system.level
|
|
|
|
if (rollData.skill.system.issl2) {
|
2022-08-01 21:39:17 +02:00
|
|
|
rollData.hasSLBonus = true
|
|
|
|
level += 2
|
2022-08-06 17:06:05 +02:00
|
|
|
if (level > 7) { level = 7 }
|
2022-07-30 22:54:08 +02:00
|
|
|
}
|
2022-08-16 22:29:27 +02:00
|
|
|
rollData.skill.system.skilldice = __skillLevel2Dice[level]
|
|
|
|
diceFormula += "+" + String(rollData.skill.system.skilldice) + "cs>=5"
|
2022-08-02 23:33:43 +02:00
|
|
|
|
2022-08-16 22:29:27 +02:00
|
|
|
if (rollData.skill.system.skilltype == "complex" && rollData.skill.system.level == 0) {
|
2022-07-31 19:48:23 +02:00
|
|
|
rollData.complexSkillDisadvantage = true
|
|
|
|
rollData.rollAdvantage = "roll-disadvantage"
|
|
|
|
}
|
2022-08-01 21:39:17 +02:00
|
|
|
|
2022-08-16 22:29:27 +02:00
|
|
|
if (rollData.skill.system.isfeatdie) {
|
2022-08-01 21:39:17 +02:00
|
|
|
rollData.hasFeatDie = true
|
|
|
|
diceFormula += "+ 1d10cs>=5"
|
2022-08-02 23:33:43 +02:00
|
|
|
} else {
|
|
|
|
diceFormula += `+ 0d10cs>=5`
|
2022-08-01 21:39:17 +02:00
|
|
|
}
|
2022-08-16 22:29:27 +02:00
|
|
|
if (rollData.skill.system.bonusdice != "none") {
|
|
|
|
rollData.hasBonusDice = rollData.skill.system.bonusdice
|
2022-08-01 21:39:17 +02:00
|
|
|
diceFormula += `+ ${rollData.hasBonusDice}cs>=5`
|
2022-08-02 23:33:43 +02:00
|
|
|
} else {
|
|
|
|
diceFormula += `+ 0d6cs>=5`
|
2022-08-01 21:39:17 +02:00
|
|
|
}
|
2022-08-06 17:06:05 +02:00
|
|
|
} else {
|
2022-08-02 23:33:43 +02:00
|
|
|
diceFormula += `+ 0d8cs=>5 + 0d10cs>=5 + 0d6cs>=5`
|
2022-07-19 23:16:03 +02:00
|
|
|
}
|
2022-08-06 17:06:05 +02:00
|
|
|
|
2022-08-02 23:33:43 +02:00
|
|
|
// advantage => 8
|
|
|
|
let advFormula = "+ 0d8cs>=5"
|
2022-08-17 17:07:45 +02:00
|
|
|
if (rollData.advantage == "advantage1" || rollData.forceAdvantage) {
|
2022-08-02 23:33:43 +02:00
|
|
|
advFormula = "+ 1d8cs>=5"
|
2022-07-26 21:40:42 +02:00
|
|
|
}
|
2022-08-06 17:06:05 +02:00
|
|
|
if (rollData.advantage == "advantage2") {
|
2022-08-02 23:33:43 +02:00
|
|
|
advFormula = "+ 2d8cs>=5"
|
2022-07-31 19:32:54 +02:00
|
|
|
}
|
2022-08-02 23:33:43 +02:00
|
|
|
diceFormula += advFormula
|
|
|
|
|
|
|
|
// disadvantage => 10
|
|
|
|
let disFormula = "- 0d8cs>=5"
|
2022-08-17 17:07:45 +02:00
|
|
|
if (rollData.disadvantage == "disadvantage1" || rollData.forceDisadvantage) {
|
2022-08-02 23:33:43 +02:00
|
|
|
disFormula = "- 1d8cs>=5"
|
2022-07-26 21:40:42 +02:00
|
|
|
}
|
2022-08-06 17:06:05 +02:00
|
|
|
if (rollData.disadvantage == "disadvantage2") {
|
2022-08-02 23:33:43 +02:00
|
|
|
disFormula = "- 2d8cs>=5"
|
2022-07-31 19:32:54 +02:00
|
|
|
}
|
2022-08-02 23:33:43 +02:00
|
|
|
diceFormula += disFormula
|
|
|
|
|
|
|
|
// armor => 12
|
2022-08-01 21:39:17 +02:00
|
|
|
let skillArmorPenalty = 0
|
|
|
|
for (let armor of rollData.armors) {
|
2022-08-16 22:29:27 +02:00
|
|
|
if (armor.system.equipped) {
|
|
|
|
skillArmorPenalty += armor.system.skillpenalty
|
2022-08-04 16:28:10 +02:00
|
|
|
}
|
2022-07-30 22:54:08 +02:00
|
|
|
}
|
2022-08-16 22:29:27 +02:00
|
|
|
if (rollData.skill && rollData.skill.system.armorpenalty && skillArmorPenalty > 0) {
|
2022-08-01 21:39:17 +02:00
|
|
|
rollData.skillArmorPenalty = skillArmorPenalty
|
2022-08-02 23:33:43 +02:00
|
|
|
diceFormula += `- ${skillArmorPenalty}d8cs>=5`
|
|
|
|
} else {
|
|
|
|
diceFormula += `- 0d8cs>=5`
|
2022-08-01 21:39:17 +02:00
|
|
|
}
|
|
|
|
|
2022-08-10 14:41:40 +02:00
|
|
|
// shield => 14
|
2022-08-14 10:10:26 +02:00
|
|
|
if (rollData.useshield && rollData.shield) {
|
2022-08-16 22:29:27 +02:00
|
|
|
diceFormula += "+ 1" + String(rollData.shield.system.shielddie) + "cs>=5"
|
2022-08-10 14:41:40 +02:00
|
|
|
} else {
|
|
|
|
diceFormula += " + 0d6cs>=5"
|
|
|
|
}
|
|
|
|
|
2022-07-19 23:16:03 +02:00
|
|
|
// Performs roll
|
2022-08-03 09:34:33 +02:00
|
|
|
console.log("Roll formula", diceFormula)
|
2022-07-19 23:16:03 +02:00
|
|
|
let myRoll = rollData.roll
|
2022-07-25 21:33:00 +02:00
|
|
|
if (!myRoll) { // New rolls only of no rerolls
|
2022-07-19 23:16:03 +02:00
|
|
|
myRoll = new Roll(diceFormula).roll({ async: false })
|
|
|
|
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
|
|
|
|
}
|
2022-08-10 14:41:40 +02:00
|
|
|
rollData.rollOrder = 0
|
2022-07-30 23:29:55 +02:00
|
|
|
rollData.roll = myRoll
|
2022-07-25 21:33:00 +02:00
|
|
|
rollData.nbSuccess = myRoll.total
|
2022-08-17 17:07:45 +02:00
|
|
|
|
2022-08-17 22:51:52 +02:00
|
|
|
if (rollData.rollAdvantage == "none" && rollData.forceRollAdvantage) {
|
2022-08-17 17:07:45 +02:00
|
|
|
rollData.rollAdvantage = "roll-advantage"
|
2022-08-17 22:51:52 +02:00
|
|
|
}
|
|
|
|
if (rollData.rollAdvantage == "none" && rollData.forceRollDisadvantage) {
|
2022-08-17 17:07:45 +02:00
|
|
|
rollData.rollAdvantage = "roll-disadvantage"
|
2022-08-17 22:51:52 +02:00
|
|
|
}
|
|
|
|
if (rollData.rollAdvantage != "none") {
|
2022-08-14 10:10:26 +02:00
|
|
|
|
2022-08-10 14:41:40 +02:00
|
|
|
rollData.rollOrder = 1
|
2022-08-17 22:51:52 +02:00
|
|
|
rollData.rollType = (rollData.rollAdvantage == "roll-advantage") ? "Advantage" : "Disadvantage"
|
2022-08-10 14:41:40 +02:00
|
|
|
this.createChatWithRollMode(rollData.alias, {
|
|
|
|
content: await renderTemplate(`systems/fvtt-crucible-rpg/templates/chat-generic-result.html`, rollData)
|
|
|
|
})
|
|
|
|
|
|
|
|
rollData.rollOrder = 2
|
2022-07-30 23:29:55 +02:00
|
|
|
let myRoll2 = new Roll(diceFormula).roll({ async: false })
|
2022-08-10 14:41:40 +02:00
|
|
|
await this.showDiceSoNice(myRoll2, game.settings.get("core", "rollMode"))
|
2022-08-17 22:51:52 +02:00
|
|
|
|
2022-08-10 14:41:40 +02:00
|
|
|
rollData.roll = myRoll2 // Tmp switch to display the proper results
|
2022-08-16 22:29:27 +02:00
|
|
|
rollData.nbSuccess = myRoll2.total
|
2022-08-10 14:41:40 +02:00
|
|
|
this.createChatWithRollMode(rollData.alias, {
|
|
|
|
content: await renderTemplate(`systems/fvtt-crucible-rpg/templates/chat-generic-result.html`, rollData)
|
|
|
|
})
|
|
|
|
rollData.roll = myRoll // Revert the tmp switch
|
2022-08-16 22:29:27 +02:00
|
|
|
rollData.nbSuccess = myRoll.total
|
|
|
|
|
2022-07-31 19:32:54 +02:00
|
|
|
if (rollData.rollAdvantage == "roll-advantage") {
|
2022-08-06 17:06:05 +02:00
|
|
|
if (myRoll2.total > rollData.nbSuccess) {
|
2022-08-10 14:41:40 +02:00
|
|
|
hasChanged = true
|
2022-07-31 19:32:54 +02:00
|
|
|
rollData.roll = myRoll2
|
|
|
|
rollData.nbSuccess = myRoll2.total
|
|
|
|
}
|
|
|
|
} else {
|
2022-08-06 17:06:05 +02:00
|
|
|
if (myRoll2.total < rollData.nbSuccess) {
|
2022-07-31 19:32:54 +02:00
|
|
|
rollData.roll = myRoll2
|
|
|
|
rollData.nbSuccess = myRoll2.total
|
|
|
|
}
|
2022-07-30 23:29:55 +02:00
|
|
|
}
|
2022-08-10 14:41:40 +02:00
|
|
|
rollData.rollOrder = 3
|
2022-07-30 23:29:55 +02:00
|
|
|
}
|
2022-08-14 10:10:26 +02:00
|
|
|
rollData.nbSuccess = Math.max(0, rollData.nbSuccess)
|
2022-08-10 14:41:40 +02:00
|
|
|
|
|
|
|
rollData.isFirstRollAdvantage = false
|
2022-07-30 23:29:55 +02:00
|
|
|
// Manage exp
|
2022-08-16 22:29:27 +02:00
|
|
|
if (rollData.skill && rollData.skill.system.level > 0) {
|
2022-07-30 23:29:55 +02:00
|
|
|
let nbSkillSuccess = rollData.roll.terms[2].total
|
2022-08-16 22:29:27 +02:00
|
|
|
if (nbSkillSuccess == 0 || nbSkillSuccess == rollData.skill.system.level) {
|
|
|
|
actor.incrementSkillExp(rollData.skill.id, 1)
|
2022-07-30 23:29:55 +02:00
|
|
|
}
|
|
|
|
}
|
2022-07-19 23:16:03 +02:00
|
|
|
|
2022-08-06 17:06:05 +02:00
|
|
|
this.saveRollData(rollData)
|
|
|
|
actor.lastRoll = rollData
|
|
|
|
|
2022-07-19 23:16:03 +02:00
|
|
|
this.createChatWithRollMode(rollData.alias, {
|
|
|
|
content: await renderTemplate(`systems/fvtt-crucible-rpg/templates/chat-generic-result.html`, rollData)
|
2022-07-25 21:33:00 +02:00
|
|
|
})
|
|
|
|
console.log("Rolldata result", rollData)
|
2022-07-19 23:16:03 +02:00
|
|
|
|
2022-08-06 17:06:05 +02:00
|
|
|
// Message response
|
|
|
|
this.displayDefenseMessage(rollData)
|
|
|
|
|
2022-08-10 14:41:40 +02:00
|
|
|
// Manage defense result
|
|
|
|
this.processAttackDefense(rollData)
|
2022-07-19 23:16:03 +02:00
|
|
|
}
|
|
|
|
|
2022-07-31 19:32:54 +02:00
|
|
|
/* -------------------------------------------- */
|
2022-08-06 17:06:05 +02:00
|
|
|
static sortArrayObjectsByName(myArray) {
|
2022-07-31 19:32:54 +02:00
|
|
|
myArray.sort((a, b) => {
|
|
|
|
let fa = a.name.toLowerCase();
|
|
|
|
let fb = b.name.toLowerCase();
|
|
|
|
if (fa < fb) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (fa > fb) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
})
|
|
|
|
}
|
2022-07-31 19:42:51 +02:00
|
|
|
|
2022-07-19 23:16:03 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getUsers(filter) {
|
2022-08-16 22:29:27 +02:00
|
|
|
return game.users.filter(filter).map(user => user.id);
|
2022-07-19 23:16:03 +02:00
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getWhisperRecipients(rollMode, name) {
|
|
|
|
switch (rollMode) {
|
|
|
|
case "blindroll": return this.getUsers(user => user.isGM);
|
|
|
|
case "gmroll": return this.getWhisperRecipientsAndGMs(name);
|
|
|
|
case "selfroll": return [game.user.id];
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getWhisperRecipientsAndGMs(name) {
|
|
|
|
let recep1 = ChatMessage.getWhisperRecipients(name) || [];
|
|
|
|
return recep1.concat(ChatMessage.getWhisperRecipients('GM'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static blindMessageToGM(chatOptions) {
|
|
|
|
let chatGM = duplicate(chatOptions);
|
|
|
|
chatGM.whisper = this.getUsers(user => user.isGM);
|
|
|
|
chatGM.content = "Blinde message of " + game.user.name + "<br>" + chatOptions.content;
|
|
|
|
console.log("blindMessageToGM", chatGM);
|
2022-08-14 10:10:26 +02:00
|
|
|
game.socket.emit("system.fvtt-crucible-rpg", { msg: "msg_gm_chat_message", data: chatGM });
|
2022-07-19 23:16:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async searchItem(dataItem) {
|
|
|
|
let item
|
|
|
|
if (dataItem.pack) {
|
|
|
|
item = await fromUuid("Compendium." + dataItem.pack + "." + dataItem.id)
|
|
|
|
} else {
|
|
|
|
item = game.items.get(dataItem.id)
|
|
|
|
}
|
|
|
|
return item
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static split3Columns(data) {
|
|
|
|
|
|
|
|
let array = [[], [], []];
|
|
|
|
if (data == undefined) return array;
|
|
|
|
|
|
|
|
let col = 0;
|
|
|
|
for (let key in data) {
|
|
|
|
let keyword = data[key];
|
|
|
|
keyword.key = key; // Self-reference
|
|
|
|
array[col].push(keyword);
|
|
|
|
col++;
|
|
|
|
if (col == 3) col = 0;
|
|
|
|
}
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static createChatMessage(name, rollMode, chatOptions) {
|
|
|
|
switch (rollMode) {
|
|
|
|
case "blindroll": // GM only
|
|
|
|
if (!game.user.isGM) {
|
|
|
|
this.blindMessageToGM(chatOptions);
|
|
|
|
|
|
|
|
chatOptions.whisper = [game.user.id];
|
|
|
|
chatOptions.content = "Message only to the GM";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
chatOptions.whisper = this.getUsers(user => user.isGM);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
chatOptions.whisper = this.getWhisperRecipients(rollMode, name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
chatOptions.alias = chatOptions.alias || name;
|
|
|
|
ChatMessage.create(chatOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getBasicRollData() {
|
|
|
|
let rollData = {
|
|
|
|
rollId: randomID(16),
|
|
|
|
rollMode: game.settings.get("core", "rollMode"),
|
2022-07-26 21:40:42 +02:00
|
|
|
advantage: "none"
|
2022-07-19 23:16:03 +02:00
|
|
|
}
|
|
|
|
CrucibleUtility.updateWithTarget(rollData)
|
|
|
|
return rollData
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static updateWithTarget(rollData) {
|
2022-08-06 17:06:05 +02:00
|
|
|
let target = CrucibleUtility.getTarget()
|
2022-07-19 23:16:03 +02:00
|
|
|
if (target) {
|
2022-08-06 17:06:05 +02:00
|
|
|
rollData.defenderTokenId = target.id
|
2022-07-19 23:16:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static createChatWithRollMode(name, chatOptions) {
|
2022-08-06 17:06:05 +02:00
|
|
|
this.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions)
|
2022-07-19 23:16:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async confirmDelete(actorSheet, li) {
|
|
|
|
let itemId = li.data("item-id");
|
|
|
|
let msgTxt = "<p>Are you sure to remove this Item ?";
|
|
|
|
let buttons = {
|
|
|
|
delete: {
|
|
|
|
icon: '<i class="fas fa-check"></i>',
|
|
|
|
label: "Yes, remove it",
|
|
|
|
callback: () => {
|
|
|
|
actorSheet.actor.deleteEmbeddedDocuments("Item", [itemId]);
|
|
|
|
li.slideUp(200, () => actorSheet.render(false));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
cancel: {
|
|
|
|
icon: '<i class="fas fa-times"></i>',
|
|
|
|
label: "Cancel"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
msgTxt += "</p>";
|
|
|
|
let d = new Dialog({
|
|
|
|
title: "Confirm removal",
|
|
|
|
content: msgTxt,
|
|
|
|
buttons: buttons,
|
|
|
|
default: "cancel"
|
|
|
|
});
|
|
|
|
d.render(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|