2022-10-22 11:09:48 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
import { HawkmoonCombat } from "./hawkmoon-combat.js";
|
|
|
|
import { HawkmoonCommands } from "./hawkmoon-commands.js";
|
|
|
|
|
2023-04-24 22:20:47 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
const __distanceDifficulte = { "porteecourte": 5, "porteemoyenne": 9, "porteelongue": 14}
|
|
|
|
const __tireurDeplacement = { immobile: 0, lent: 3, rapide: 5}
|
|
|
|
const __cibleCouvert = { aucun: 0, leger: 5, complet: 10}
|
|
|
|
const __tailleCible = { normal: 0, main: 10, enfant: 3, maison: -10}
|
|
|
|
|
2022-10-22 11:09:48 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
export class HawkmoonUtility {
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async init() {
|
|
|
|
Hooks.on('renderChatLog', (log, html, data) => HawkmoonUtility.chatListeners(html))
|
|
|
|
Hooks.on("getChatLogEntryContext", (html, options) => HawkmoonUtility.chatRollMenu(html, options))
|
|
|
|
|
|
|
|
Hooks.on("getCombatTrackerEntryContext", (html, options) => {
|
|
|
|
HawkmoonUtility.pushInitiativeOptions(html, options);
|
|
|
|
})
|
|
|
|
|
|
|
|
this.rollDataStore = {}
|
|
|
|
this.defenderStore = {}
|
2022-10-25 17:54:13 +02:00
|
|
|
HawkmoonCommands.init()
|
2022-10-22 11:09:48 +02:00
|
|
|
|
|
|
|
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-11-10 23:43:51 +01:00
|
|
|
game.settings.register("fvtt-hawkmoon-cyd", "hawkmoon-pause-logo", {
|
|
|
|
name: "Logo de pause",
|
|
|
|
scope: "world",
|
|
|
|
config: true,
|
|
|
|
requiresReload: true,
|
|
|
|
default: "logo_pause_resistance",
|
|
|
|
type: String,
|
|
|
|
choices: { // If choices are defined, the resulting setting will be a select menu
|
|
|
|
"hawkmoon_logo": "Hawmoon (Texte)",
|
|
|
|
"logo_pause_resistance": "Résistance",
|
|
|
|
"logo_pause_hawkmoon_stone": "Hawkmoon (Pierre)",
|
|
|
|
"logo_pause_hawkmoon_violet": "Hawkmoon (Violet)",
|
2022-11-20 11:55:03 +01:00
|
|
|
"logo_pause_hawkmoon_beige": "Hawkmoon (Beige)",
|
2022-11-10 23:43:51 +01:00
|
|
|
"logo_pause_hawkmoon_rouge": "Hawkmoon (Rouge)"
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2022-10-22 11:09:48 +02:00
|
|
|
}
|
|
|
|
|
2023-03-19 18:58:28 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static sortArrayObjectsByName(myArray) {
|
|
|
|
myArray.sort((a, b) => {
|
|
|
|
return a.name.localeCompare(b.name);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-10-22 11:09:48 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getModificateurOptions() {
|
|
|
|
let opt = []
|
|
|
|
for (let i = -15; i <= 15; i++) {
|
|
|
|
opt.push(`<option value="${i}">${i}</option>`)
|
|
|
|
}
|
|
|
|
return opt.concat("\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getPointAmeOptions() {
|
|
|
|
let opt = []
|
|
|
|
for (let i = 1; i <= 20; i++) {
|
|
|
|
opt.push(`<option value="${i}">${i}</option>`)
|
|
|
|
}
|
|
|
|
return opt.concat("\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getAttributs() {
|
|
|
|
return { adr: "Adresse", pui: "Puissance", cla: "Clairvoyance", pre: "Présence", tre: "Trempe" }
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static pushInitiativeOptions(html, options) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getSkills() {
|
|
|
|
return this.skills
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async ready() {
|
|
|
|
const skills = await HawkmoonUtility.loadCompendium("fvtt-hawkmoon-cyd.skills")
|
|
|
|
this.skills = skills.map(i => i.toObject())
|
2022-12-03 23:13:08 +01:00
|
|
|
|
2022-11-10 23:43:51 +01:00
|
|
|
// Setup pause logo
|
|
|
|
let logoPause = "systems/fvtt-hawkmoon-cyd/assets/logos/" + game.settings.get("fvtt-hawkmoon-cyd", "hawkmoon-pause-logo") + ".webp"
|
|
|
|
let logoImg = document.querySelector('#pause').children[0]
|
|
|
|
logoImg.setAttribute('style', `content: url(${logoPause})`)
|
2022-10-22 11:09:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async loadCompendiumData(compendium) {
|
|
|
|
const pack = game.packs.get(compendium);
|
|
|
|
return await pack?.getDocuments() ?? [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async loadCompendium(compendium, filter = item => true) {
|
|
|
|
let compendiumData = await HawkmoonUtility.loadCompendiumData(compendium);
|
|
|
|
return compendiumData.filter(filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getOptionsStatusList() {
|
|
|
|
return this.optionsStatusList;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async chatListeners(html) {
|
|
|
|
|
|
|
|
html.on("click", '.predilection-reroll', async event => {
|
|
|
|
let predIdx = $(event.currentTarget).data("predilection-index")
|
|
|
|
let messageId = HawkmoonUtility.findChatMessageId(event.currentTarget)
|
|
|
|
let message = game.messages.get(messageId)
|
2022-10-25 17:54:13 +02:00
|
|
|
let rollData = message.getFlag("world", "hawkmoon-roll")
|
2022-11-30 12:15:45 +01:00
|
|
|
let actor = this.getActorFromRollData(rollData)
|
2022-10-22 11:09:48 +02:00
|
|
|
await actor.setPredilectionUsed(rollData.competence._id, predIdx)
|
|
|
|
rollData.competence = duplicate(actor.getCompetence(rollData.competence._id))
|
|
|
|
HawkmoonUtility.rollHawkmoon(rollData)
|
|
|
|
})
|
2022-11-13 23:01:41 +01:00
|
|
|
|
|
|
|
html.on("click", '.roll-chat-degat', async event => {
|
|
|
|
let messageId = HawkmoonUtility.findChatMessageId(event.currentTarget)
|
|
|
|
let message = game.messages.get(messageId)
|
|
|
|
let rollData = message.getFlag("world", "hawkmoon-roll")
|
2022-11-30 12:15:45 +01:00
|
|
|
let actor = this.getActorFromRollData(rollData)
|
2023-04-24 22:20:47 +02:00
|
|
|
actor.rollArmeDegats(rollData.arme._id, rollData.targetVigueur, rollData)
|
2022-11-13 23:01:41 +01:00
|
|
|
})
|
2023-12-28 18:40:46 +01:00
|
|
|
html.on("click", '.roll-chat-degat-devastateur', async event => {
|
|
|
|
let messageId = HawkmoonUtility.findChatMessageId(event.currentTarget)
|
|
|
|
let message = game.messages.get(messageId)
|
|
|
|
let rollData = message.getFlag("world", "hawkmoon-roll")
|
|
|
|
let actor = this.getActorFromRollData(rollData)
|
|
|
|
rollData.applyCoupDevastateur = true
|
|
|
|
actor.rollArmeDegats(rollData.arme._id, rollData.targetVigueur, rollData)
|
|
|
|
})
|
|
|
|
|
2022-10-22 11:09:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async preloadHandlebarsTemplates() {
|
|
|
|
|
|
|
|
const templatePaths = [
|
|
|
|
'systems/fvtt-hawkmoon-cyd/templates/editor-notes-gm.html',
|
2022-11-14 15:27:19 +01:00
|
|
|
'systems/fvtt-hawkmoon-cyd/templates/partial-item-header.html',
|
2022-10-22 11:09:48 +02:00
|
|
|
'systems/fvtt-hawkmoon-cyd/templates/partial-item-description.html',
|
2022-10-23 21:26:18 +02:00
|
|
|
'systems/fvtt-hawkmoon-cyd/templates/partial-item-nav.html',
|
2022-10-24 15:39:09 +02:00
|
|
|
'systems/fvtt-hawkmoon-cyd/templates/partial-list-niveau.html',
|
2023-03-13 23:58:43 +01:00
|
|
|
'systems/fvtt-hawkmoon-cyd/templates/partial-list-niveau-creature.html',
|
2022-10-25 17:54:13 +02:00
|
|
|
'systems/fvtt-hawkmoon-cyd/templates/partial-item-prix.html',
|
|
|
|
'systems/fvtt-hawkmoon-cyd/templates/partial-sante-etat.html',
|
2022-10-26 12:12:30 +02:00
|
|
|
'systems/fvtt-hawkmoon-cyd/templates/partial-automation.html',
|
2022-12-03 23:13:08 +01:00
|
|
|
'systems/fvtt-hawkmoon-cyd/templates/hud-adversites.html',
|
2022-10-22 11:09:48 +02:00
|
|
|
]
|
|
|
|
return loadTemplates(templatePaths);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static removeChatMessageId(messageId) {
|
|
|
|
if (messageId) {
|
|
|
|
game.messages.get(messageId)?.delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static findChatMessageId(current) {
|
|
|
|
return HawkmoonUtility.getChatMessageId(HawkmoonUtility.findChatMessage(current));
|
|
|
|
}
|
|
|
|
|
|
|
|
static getChatMessageId(node) {
|
|
|
|
return node?.attributes.getNamedItem('data-message-id')?.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static findChatMessage(current) {
|
|
|
|
return HawkmoonUtility.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 HawkmoonUtility.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() {
|
|
|
|
if (game.user.targets && game.user.targets.size == 1) {
|
|
|
|
for (let target of game.user.targets) {
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2022-12-03 23:13:08 +01:00
|
|
|
static getActorFromRollData(rollData) {
|
|
|
|
let actor = game.actors.get(rollData.actorId)
|
2022-11-30 12:15:45 +01:00
|
|
|
if (rollData.tokenId) {
|
|
|
|
let token = canvas.tokens.placeables.find(t => t.id == rollData.tokenId)
|
|
|
|
if (token) {
|
|
|
|
actor = token.actor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return actor
|
2022-10-22 11:09:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static updateRollData(rollData) {
|
|
|
|
|
|
|
|
let id = rollData.rollId;
|
|
|
|
let oldRollData = this.rollDataStore[id] || {};
|
|
|
|
let newRollData = mergeObject(oldRollData, rollData);
|
|
|
|
this.rollDataStore[id] = newRollData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static onSocketMesssage(msg) {
|
2023-12-28 18:40:46 +01:00
|
|
|
if (msg.name == "msg_apply_combativite") {
|
|
|
|
let defender = game.canvas.tokens.get(rollData.defenderTokenId).actor
|
|
|
|
defender.changeEtatCombativite(msg.data.value)
|
2022-10-22 11:09:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
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-12-03 23:57:30 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static computeMonnaieDetails(valueSC) {
|
|
|
|
let po = Math.floor(valueSC / 400)
|
2023-03-19 18:58:28 +01:00
|
|
|
let pa = Math.floor((valueSC - (po * 400)) / 20)
|
|
|
|
let sc = valueSC - (po * 400) - (pa * 20)
|
2022-12-03 23:57:30 +01:00
|
|
|
return {
|
2023-05-25 07:23:25 +02:00
|
|
|
po, pa, sc, valueSC
|
2022-12-03 23:57:30 +01:00
|
|
|
}
|
|
|
|
}
|
2023-03-19 18:58:28 +01:00
|
|
|
|
2022-10-22 11:09:48 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static computeResult(rollData) {
|
2022-11-13 23:01:41 +01:00
|
|
|
rollData.diceResult = rollData.roll.terms[0].results[0].result
|
2022-12-03 23:13:08 +01:00
|
|
|
if (rollData.mainDice.includes("d20")) {
|
2022-10-22 11:09:48 +02:00
|
|
|
let diceValue = rollData.roll.terms[0].results[0].result
|
|
|
|
if (diceValue % 2 == 1) {
|
|
|
|
//console.log("PAIR/IMP2", diceValue)
|
|
|
|
rollData.finalResult -= rollData.roll.terms[0].results[0].result // Substract value
|
|
|
|
if (diceValue == 1 || diceValue == 11) {
|
|
|
|
rollData.isDramatique = true
|
|
|
|
rollData.isSuccess = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//console.log("Result : ", rollData)
|
|
|
|
if (rollData.difficulte > 0 && !rollData.isDramatique) {
|
|
|
|
rollData.isSuccess = (rollData.finalResult >= rollData.difficulte)
|
|
|
|
rollData.isHeroique = ((rollData.finalResult - rollData.difficulte) >= 10)
|
|
|
|
rollData.isDramatique = ((rollData.finalResult - rollData.difficulte) <= -10)
|
|
|
|
}
|
2022-12-03 23:13:08 +01:00
|
|
|
|
2022-10-22 11:09:48 +02:00
|
|
|
}
|
2023-12-28 18:40:46 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static applyCombativite(rollData, value) {
|
|
|
|
if (game.user.isGM) {
|
|
|
|
let defender = game.canvas.tokens.get(rollData.defenderTokenId).actor
|
|
|
|
defender.changeEtatCombativite(value)
|
|
|
|
} else {
|
|
|
|
game.socket.emit("system.fvtt-hawkmoon-cyd", { msg: "msg_apply_combativite", data: { defenderTokenId: rollData.defenderTokenId, value } });
|
|
|
|
}
|
|
|
|
}
|
2022-10-22 11:09:48 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async rollHawkmoon(rollData) {
|
|
|
|
|
2022-11-30 12:15:45 +01:00
|
|
|
let actor = this.getActorFromRollData(rollData)
|
2022-10-22 11:09:48 +02:00
|
|
|
if (rollData.attrKey == "tochoose") { // No attr selected, force address
|
|
|
|
rollData.attrKey = "adr"
|
|
|
|
}
|
|
|
|
if (!rollData.attr) {
|
|
|
|
rollData.actionImg = "systems/fvtt-hawkmoon-cyd/assets/icons/" + actor.system.attributs[rollData.attrKey].labelnorm + ".webp"
|
|
|
|
rollData.attr = duplicate(actor.system.attributs[rollData.attrKey])
|
|
|
|
}
|
2023-12-28 18:40:46 +01:00
|
|
|
if (rollData.attrKey2 != "none") {
|
|
|
|
rollData.attr2 = duplicate(actor.system.attributs[rollData.attrKey2])
|
|
|
|
}
|
2022-10-22 11:09:48 +02:00
|
|
|
|
2022-12-03 23:13:08 +01:00
|
|
|
if (rollData.maitriseId != "none") {
|
|
|
|
rollData.selectedMaitrise = rollData.maitrises.find(p => p.id == rollData.maitriseId)
|
2022-10-25 17:54:13 +02:00
|
|
|
rollData.diceFormula = "2" + rollData.mainDice + "kh"
|
|
|
|
} else {
|
|
|
|
rollData.diceFormula = "1" + rollData.mainDice
|
2022-10-22 11:09:48 +02:00
|
|
|
}
|
2022-10-25 17:54:13 +02:00
|
|
|
|
2022-10-22 11:09:48 +02:00
|
|
|
//console.log("BEFORE COMP", rollData)
|
|
|
|
if (rollData.competence) {
|
2023-12-21 21:02:11 +01:00
|
|
|
rollData.predilections = duplicate(rollData.competence.system.predilections || [])
|
2022-10-22 11:09:48 +02:00
|
|
|
let compmod = (rollData.competence.system.niveau == 0) ? -3 : 0
|
|
|
|
rollData.diceFormula += `+${rollData.attr.value}+${rollData.competence.system.niveau}+${rollData.modificateur}+${compmod}`
|
2023-12-28 18:40:46 +01:00
|
|
|
|
2022-12-03 23:13:08 +01:00
|
|
|
if (rollData.selectedTalents && rollData.selectedTalents.length > 0) {
|
2022-10-28 21:44:49 +02:00
|
|
|
for (let id of rollData.selectedTalents) {
|
2022-11-05 10:03:23 +01:00
|
|
|
let talent = rollData.talents.find(t => t._id == id)
|
|
|
|
let bonusOK = true
|
2022-12-03 23:13:08 +01:00
|
|
|
if (talent.system.baCost) {
|
|
|
|
bonusOK = actor.checkBonneAventure(talent.system.baCost)
|
|
|
|
if (bonusOK) {
|
|
|
|
actor.changeBonneAventure(-talent.system.baCost)
|
2022-11-05 10:03:23 +01:00
|
|
|
} else {
|
|
|
|
ui.notifications.warn("Vous n'avez pas assez de points de Bonne Aventure !")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bonusOK) {
|
|
|
|
rollData.diceFormula += `+${talent.system.bonus}`
|
2022-10-28 21:44:49 +02:00
|
|
|
}
|
|
|
|
}
|
2022-12-03 23:13:08 +01:00
|
|
|
}
|
2022-11-29 10:54:56 +01:00
|
|
|
rollData.diceFormula += `+${rollData.bonusMalusContext}`
|
2023-12-28 18:40:46 +01:00
|
|
|
} else if (rollData.attr2) {
|
|
|
|
rollData.diceFormula += `+${rollData.attr.value}+${rollData.attr2.value}+${rollData.modificateur}+${rollData.bonusMalusContext}`
|
2022-10-22 11:09:48 +02:00
|
|
|
} else {
|
2022-11-29 10:54:56 +01:00
|
|
|
rollData.diceFormula += `+${rollData.attr.value}*${rollData.multiplier}+${rollData.modificateur}+${rollData.bonusMalusContext}`
|
2022-10-22 11:09:48 +02:00
|
|
|
}
|
2023-12-28 18:40:46 +01:00
|
|
|
|
2023-04-24 22:20:47 +02:00
|
|
|
// Bonus arme naturelle en défense
|
|
|
|
if (rollData.bonusArmeNaturelle) {
|
|
|
|
rollData.diceFormula += `+${rollData.bonusArmeNaturelle}`
|
|
|
|
}
|
|
|
|
if (rollData.defenseurAuSol) {
|
|
|
|
rollData.diceFormula += `+3`
|
|
|
|
}
|
|
|
|
if (rollData.defenseurAveugle) {
|
|
|
|
rollData.diceFormula += `+10`
|
|
|
|
}
|
|
|
|
if (rollData.defenseurDeDos) {
|
|
|
|
rollData.diceFormula += `+5`
|
|
|
|
}
|
|
|
|
if (rollData.defenseurRestreint) {
|
|
|
|
rollData.diceFormula += `+3`
|
|
|
|
}
|
|
|
|
if (rollData.defenseurImmobilise) {
|
|
|
|
rollData.diceFormula += `+5`
|
|
|
|
}
|
|
|
|
|
2023-05-25 07:23:25 +02:00
|
|
|
if (rollData.arme?.system.isDistance) {
|
2023-04-24 22:20:47 +02:00
|
|
|
rollData.difficulte = __distanceDifficulte[rollData.distanceTir]
|
|
|
|
rollData.difficulte += __tireurDeplacement[rollData.tireurDeplacement]
|
|
|
|
rollData.difficulte += __cibleCouvert[rollData.cibleCouvert]
|
|
|
|
rollData.difficulte += __tailleCible[rollData.tailleCible]
|
|
|
|
rollData.difficulte += rollData.cibleDeplace ? 3 : 0
|
|
|
|
rollData.difficulte += rollData.cibleCaC ? 3 : 0
|
|
|
|
}
|
2023-05-25 07:23:25 +02:00
|
|
|
if (rollData.attaqueDesarme) {
|
|
|
|
rollData.difficulte += 10
|
|
|
|
}
|
|
|
|
|
2022-11-10 11:04:05 +01:00
|
|
|
// Ajout adversités
|
|
|
|
rollData.diceFormula += `-${rollData.nbAdversites}`
|
2022-10-28 21:44:49 +02:00
|
|
|
|
2022-10-22 11:09:48 +02:00
|
|
|
if (rollData.arme && rollData.arme.type == "arme") {
|
|
|
|
rollData.diceFormula += `+${rollData.arme.system.bonusmaniementoff}`
|
|
|
|
}
|
|
|
|
|
|
|
|
let myRoll = new Roll(rollData.diceFormula).roll({ async: false })
|
|
|
|
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
|
2023-05-25 07:23:25 +02:00
|
|
|
rollData.roll = duplicate(myRoll)
|
2022-10-22 11:09:48 +02:00
|
|
|
console.log(">>>> ", myRoll)
|
|
|
|
|
|
|
|
rollData.finalResult = myRoll.total
|
|
|
|
this.computeResult(rollData)
|
2022-11-13 23:01:41 +01:00
|
|
|
if (rollData.isInit) {
|
2022-11-30 12:15:45 +01:00
|
|
|
actor.setFlag("world", "last-initiative", rollData.finalResult)
|
2022-11-13 23:01:41 +01:00
|
|
|
}
|
2022-10-22 11:09:48 +02:00
|
|
|
|
|
|
|
this.createChatWithRollMode(rollData.alias, {
|
|
|
|
content: await renderTemplate(`systems/fvtt-hawkmoon-cyd/templates/chat-generic-result.html`, rollData)
|
|
|
|
}, rollData)
|
|
|
|
|
2023-12-28 18:40:46 +01:00
|
|
|
if (rollData.arme && rollData.isSuccess && rollData.defenderTokenId) {
|
|
|
|
this.applyCombativite(rollData, 1)
|
|
|
|
}
|
|
|
|
|
2022-10-22 11:09:48 +02:00
|
|
|
}
|
|
|
|
|
2023-12-28 18:40:46 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getCombativiteList(nbActivite) {
|
|
|
|
let list = [ { value: 0, label: "Combatif"}]
|
|
|
|
for (let i = 1; i < nbActivite-2; i++) {
|
|
|
|
list.push({ value: i, label:"Eprouvé " + i} )
|
|
|
|
}
|
|
|
|
list[nbActivite-2] = { value: nbActivite-2, label:"Affaibli"}
|
|
|
|
list[nbActivite-1] = { value: nbActivite-1, label:"Très Affaibli"}
|
|
|
|
list[nbActivite] = { value: nbActivite, label:"Vaincu"}
|
|
|
|
return list
|
|
|
|
|
|
|
|
}
|
2022-10-22 11:09:48 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async bonusRollHawkmoon(rollData) {
|
|
|
|
rollData.bonusFormula = rollData.addedBonus
|
|
|
|
|
|
|
|
let bonusRoll = new Roll(rollData.bonusFormula).roll({ async: false })
|
|
|
|
await this.showDiceSoNice(bonusRoll, game.settings.get("core", "rollMode"));
|
2023-05-25 07:23:25 +02:00
|
|
|
rollData.bonusRoll = duplicate(bonusRoll)
|
2022-10-22 11:09:48 +02:00
|
|
|
|
|
|
|
rollData.finalResult += rollData.bonusRoll.total
|
|
|
|
|
|
|
|
this.computeResult(rollData)
|
|
|
|
|
|
|
|
this.createChatWithRollMode(rollData.alias, {
|
|
|
|
content: await renderTemplate(`systems/fvtt-hawkmoon-cyd/templates/chat-generic-result.html`, rollData)
|
|
|
|
}, rollData)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getUsers(filter) {
|
2022-12-21 19:15:03 +01:00
|
|
|
return game.users.filter(filter).map(user => user._id);
|
2022-10-22 11:09:48 +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-11-13 23:01:41 +01:00
|
|
|
game.socket.emit("system.fvtt-hawkmoon-cyd", { msg: "msg_gm_chat_message", data: chatGM });
|
2022-10-22 11:09:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async searchItem(dataItem) {
|
2022-10-28 21:44:49 +02:00
|
|
|
let item
|
2022-10-22 11:09:48 +02:00
|
|
|
if (dataItem.pack) {
|
2022-10-28 21:44:49 +02:00
|
|
|
let id = dataItem.id || dataItem._id
|
|
|
|
let items = await this.loadCompendium(dataItem.pack, item => item.id == id)
|
|
|
|
item = items[0] || undefined
|
2022-10-22 11:09:48 +02:00
|
|
|
} 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 async createChatMessage(name, rollMode, chatOptions, rollData = undefined) {
|
|
|
|
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
|
|
|
|
let msg = await ChatMessage.create(chatOptions)
|
|
|
|
console.log("=======>", rollData)
|
2022-10-25 17:54:13 +02:00
|
|
|
msg.setFlag("world", "hawkmoon-roll", rollData)
|
2022-10-22 11:09:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getBasicRollData() {
|
|
|
|
let rollData = {
|
|
|
|
rollId: randomID(16),
|
|
|
|
rollMode: game.settings.get("core", "rollMode"),
|
|
|
|
modificateursOptions: this.getModificateurOptions(),
|
|
|
|
pointAmeOptions: this.getPointAmeOptions(),
|
|
|
|
difficulte: 0,
|
|
|
|
modificateur: 0,
|
2023-04-24 22:20:47 +02:00
|
|
|
bonusMalusContext: 0,
|
|
|
|
bonusArmeNaturelle: 0,
|
|
|
|
defenseurAveugle: false,
|
|
|
|
defenseurDeDos: false,
|
|
|
|
defenseurAuSol: false,
|
|
|
|
defenseurRestreint: false,
|
|
|
|
defenseurImmobilise: false,
|
|
|
|
tailleCible: "normal",
|
|
|
|
tireurDeplacement: "immobile",
|
|
|
|
cibleCouvert: "aucun",
|
2023-05-25 07:23:25 +02:00
|
|
|
distanceTir: "porteemoyenne",
|
|
|
|
attaqueCharge: false,
|
|
|
|
attaqueDesarme: false
|
2022-10-22 11:09:48 +02:00
|
|
|
}
|
|
|
|
return rollData
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static updateWithTarget(rollData) {
|
|
|
|
let target = HawkmoonUtility.getTarget()
|
|
|
|
if (target) {
|
|
|
|
rollData.defenderTokenId = target.id
|
|
|
|
let defender = game.canvas.tokens.get(rollData.defenderTokenId).actor
|
|
|
|
rollData.armeDefense = defender.getBestDefenseValue()
|
2022-11-13 23:01:41 +01:00
|
|
|
rollData.targetVigueur = defender.getVigueur()
|
2023-04-24 22:20:47 +02:00
|
|
|
rollData.protectionDefenseur = defender.getProtection()
|
2022-12-03 23:13:08 +01:00
|
|
|
if (rollData.armeDefense) {
|
2022-10-22 11:09:48 +02:00
|
|
|
rollData.difficulte = rollData.armeDefense.system.totalDefensif
|
2023-04-24 22:20:47 +02:00
|
|
|
if ( !rollData.arme.system.armenaturelle && !rollData.arme.system.armefortune ){
|
|
|
|
if (rollData.armeDefense.system.armenaturelle || rollData.armeDefense.system.armefortune) {
|
|
|
|
rollData.bonusArmeNaturelle = 3
|
|
|
|
}
|
|
|
|
}
|
2022-10-22 11:09:48 +02:00
|
|
|
} else {
|
|
|
|
ui.notifications.warn("Aucune arme de défense équipée, difficulté manuelle à positionner.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static createChatWithRollMode(name, chatOptions, rollData = undefined) {
|
|
|
|
this.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions, rollData)
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static applyBonneAventureRoll(li, changed, addedBonus) {
|
|
|
|
let msgId = li.data("message-id")
|
|
|
|
let msg = game.messages.get(msgId)
|
|
|
|
if (msg) {
|
2022-10-25 17:54:13 +02:00
|
|
|
let rollData = msg.getFlag("world", "hawkmoon-roll")
|
2022-11-30 12:15:45 +01:00
|
|
|
let actor = this.getActorFromRollData(rollData)
|
2022-10-22 11:09:48 +02:00
|
|
|
actor.changeBonneAventure(changed)
|
|
|
|
rollData.isReroll = true
|
|
|
|
rollData.textBonus = "Bonus de Points d'Aventure"
|
|
|
|
if (addedBonus == "reroll") {
|
|
|
|
HawkmoonUtility.rollHawkmoon(rollData)
|
|
|
|
} else {
|
|
|
|
rollData.addedBonus = addedBonus
|
|
|
|
HawkmoonUtility.bonusRollHawkmoon(rollData)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static applyEclatRoll(li, changed, addedBonus) {
|
|
|
|
let msgId = li.data("message-id")
|
|
|
|
let msg = game.messages.get(msgId)
|
|
|
|
if (msg) {
|
2022-10-25 17:54:13 +02:00
|
|
|
let rollData = msg.getFlag("world", "hawkmoon-roll")
|
2022-11-30 12:15:45 +01:00
|
|
|
let actor = this.getActorFromRollData(rollData)
|
2022-10-22 11:09:48 +02:00
|
|
|
actor.changeEclat(changed)
|
|
|
|
rollData.isReroll = true
|
|
|
|
rollData.textBonus = "Bonus d'Eclat"
|
2022-10-25 17:54:13 +02:00
|
|
|
if (addedBonus == "reroll") {
|
|
|
|
HawkmoonUtility.rollHawkmoon(rollData)
|
|
|
|
} else {
|
|
|
|
rollData.addedBonus = addedBonus
|
|
|
|
HawkmoonUtility.bonusRollHawkmoon(rollData)
|
|
|
|
}
|
2022-10-22 11:09:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static chatRollMenu(html, options) {
|
2022-10-25 17:54:13 +02:00
|
|
|
let canApply = li => canvas.tokens.controlled.length && li.find(".hawkmoon-roll").length
|
|
|
|
let canApplyBA = function (li) {
|
2022-10-22 11:09:48 +02:00
|
|
|
let message = game.messages.get(li.attr("data-message-id"))
|
2022-10-25 17:54:13 +02:00
|
|
|
let rollData = message.getFlag("world", "hawkmoon-roll")
|
2022-11-30 12:15:45 +01:00
|
|
|
let actor = this.getActorFromRollData(rollData)
|
2022-12-03 23:13:08 +01:00
|
|
|
return (!rollData.isReroll && actor.getBonneAventure() > 0)
|
2022-10-22 11:09:48 +02:00
|
|
|
}
|
2022-10-25 17:54:13 +02:00
|
|
|
let canApplyPE = function (li) {
|
2022-10-22 11:09:48 +02:00
|
|
|
let message = game.messages.get(li.attr("data-message-id"))
|
2022-10-25 17:54:13 +02:00
|
|
|
let rollData = message.getFlag("world", "hawkmoon-roll")
|
2022-11-30 12:15:45 +01:00
|
|
|
let actor = this.getActorFromRollData(rollData)
|
2022-12-03 23:13:08 +01:00
|
|
|
return (!rollData.isReroll && actor.getEclat() > 0)
|
2022-10-22 11:09:48 +02:00
|
|
|
}
|
|
|
|
options.push(
|
|
|
|
{
|
|
|
|
name: "Ajouer +3 (1 point de Bonne Aventure)",
|
|
|
|
icon: "<i class='fas fa-user-plus'></i>",
|
2022-10-25 17:54:13 +02:00
|
|
|
condition: canApply && canApplyBA,
|
2022-10-22 11:09:48 +02:00
|
|
|
callback: li => HawkmoonUtility.applyBonneAventureRoll(li, -1, "+3")
|
|
|
|
}
|
|
|
|
)
|
|
|
|
options.push(
|
|
|
|
{
|
|
|
|
name: "Ajouter +10 (1 Point d'Eclat)",
|
|
|
|
icon: "<i class='fas fa-user-plus'></i>",
|
2022-10-25 17:54:13 +02:00
|
|
|
condition: canApply && canApplyPE,
|
2022-10-22 11:09:48 +02:00
|
|
|
callback: li => HawkmoonUtility.applyEclatRoll(li, -1, "+10")
|
|
|
|
}
|
|
|
|
)
|
|
|
|
options.push(
|
|
|
|
{
|
2022-10-25 17:54:13 +02:00
|
|
|
name: "Relancer le dé (1 point d'Eclat)",
|
2022-10-22 11:09:48 +02:00
|
|
|
icon: "<i class='fas fa-user-plus'></i>",
|
2022-10-25 17:54:13 +02:00
|
|
|
condition: canApply && canApplyPE,
|
|
|
|
callback: li => HawkmoonUtility.applyEclatRoll(li, -3, "reroll")
|
2022-10-22 11:09:48 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
return options
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-12-03 23:13:08 +01:00
|
|
|
/************************************************************************************/
|
|
|
|
static async __create_talents_table() {
|
|
|
|
let compName = "fvtt-hawkmoon-cyd.talents-cellule"
|
|
|
|
const compData = await HawkmoonUtility.loadCompendium(compName)
|
|
|
|
let talents = compData.map(i => i.toObject())
|
|
|
|
|
|
|
|
let htmlTab = "<table border='1'><tbody>";
|
|
|
|
for (let entryData of talents) {
|
|
|
|
console.log(entryData)
|
|
|
|
htmlTab += `<tr><td>@UUID[Compendium.${compName}.${entryData._id}]{${entryData.name}}</td>`
|
|
|
|
htmlTab += `<td>${entryData.system.description}</td>`;
|
|
|
|
//htmlTab += `<td>${entryData.system.resumebonus}</td>`;
|
|
|
|
htmlTab += "</tr>\n";
|
|
|
|
}
|
|
|
|
htmlTab += "</table>";
|
|
|
|
await JournalEntry.create({ name: 'Liste des Talents de Cellule', content: htmlTab });
|
|
|
|
}
|
|
|
|
}
|