2022-12-26 00:33:13 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
import { HeritiersCombat } from "./heritiers-combat.js";
|
|
|
|
import { HeritiersCommands } from "./heritiers-commands.js";
|
|
|
|
|
2023-04-30 20:08:29 +02:00
|
|
|
const __facesAdjacentes = {
|
|
|
|
"d8": {
|
|
|
|
1: [4, 8, 6],
|
|
|
|
2: [7, 5, 3],
|
|
|
|
3: [2, 8, 6],
|
|
|
|
4: [1, 5, 7],
|
|
|
|
5: [2, 4, 8],
|
|
|
|
6: [1, 7, 3],
|
|
|
|
7: [2, 4, 6],
|
|
|
|
8: [1, 3, 5]
|
|
|
|
},
|
|
|
|
"d10": {
|
|
|
|
1: [4, 6, 9, 7],
|
|
|
|
2: [6, 8, 5, 9],
|
|
|
|
3: [7, 5, 8, 10],
|
|
|
|
4: [10, 6, 7, 1],
|
|
|
|
5: [3, 9, 2, 8],
|
|
|
|
6: [1, 4, 2, 9],
|
|
|
|
7: [1, 3, 4, 10],
|
|
|
|
8: [2, 10, 5, 3],
|
|
|
|
9: [1, 5, 6, 2],
|
|
|
|
10: [8, 4, 3, 7]
|
|
|
|
},
|
|
|
|
"d12": {
|
|
|
|
1:[2, 3, 4, 5, 6],
|
|
|
|
2: [1, 6, 8, 12, 3],
|
|
|
|
3: [1, 4, 11, 12, 2],
|
|
|
|
4: [1, 5, 10, 11, 3],
|
|
|
|
5: [1, 6, 9, 10, 4],
|
|
|
|
6: [1, 2, 8, 9, 5],
|
|
|
|
7: [8, 9, 10, 11, 12],
|
|
|
|
8: [2, 6, 9, 7, 12],
|
|
|
|
9: [5, 10, 7, 8, 6],
|
|
|
|
10: [4, 11, 7, 9, 5],
|
|
|
|
11: [7, 10, 4, 3, 12],
|
|
|
|
12: [2, 8, 7, 11, 3]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-26 00:33:13 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
export class HeritiersUtility {
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async init() {
|
|
|
|
Hooks.on('renderChatLog', (log, html, data) => HeritiersUtility.chatListeners(html))
|
|
|
|
Hooks.on("getChatLogEntryContext", (html, options) => HeritiersUtility.chatRollMenu(html, options))
|
|
|
|
|
|
|
|
this.rollDataStore = {}
|
|
|
|
this.defenderStore = {}
|
|
|
|
HeritiersCommands.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);
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2023-04-08 09:55:08 +02:00
|
|
|
static sortByName(table) {
|
2023-01-18 16:16:18 +01:00
|
|
|
return table.sort(function (a, b) {
|
2023-03-11 12:11:27 +01:00
|
|
|
return a.name.localeCompare(b.name);
|
2023-01-18 16:16:18 +01:00
|
|
|
})
|
2022-12-26 00:33:13 +01:00
|
|
|
}
|
2023-04-08 09:55:08 +02:00
|
|
|
|
2023-03-09 00:04:23 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static sortArrayObjectsByName(myArray) {
|
|
|
|
myArray.sort((a, b) => {
|
2023-03-11 12:11:27 +01:00
|
|
|
return a.name.localeCompare(b.name);
|
2023-03-09 00:04:23 +01:00
|
|
|
})
|
|
|
|
}
|
2022-12-26 00:33:13 +01:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getSkills() {
|
|
|
|
return this.skills
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async ready() {
|
2023-01-18 16:16:18 +01:00
|
|
|
const skills = await HeritiersUtility.loadCompendium("fvtt-les-heritiers.competences")
|
2022-12-26 00:33:13 +01:00
|
|
|
this.skills = skills.map(i => i.toObject())
|
|
|
|
|
2024-11-17 22:45:48 +01:00
|
|
|
this.competencesMagie = this.skills.filter(s => s.system.profil == "magie")
|
|
|
|
|
2023-04-30 20:08:29 +02:00
|
|
|
game.settings.register("fvtt-les-heritiers", "heritiers-heritage", {
|
|
|
|
name: "Points d'héritage",
|
|
|
|
hint: "Points d'héritage du groupe",
|
|
|
|
scope: "world",
|
|
|
|
config: true,
|
|
|
|
default: 0,
|
|
|
|
type: Number
|
|
|
|
})
|
2022-12-26 00:33:13 +01:00
|
|
|
}
|
|
|
|
|
2024-11-17 22:45:48 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getSDSortValue(niveau) {
|
|
|
|
if (niveau <= 2) return 12;
|
|
|
|
if (niveau <= 4) return 14;
|
|
|
|
if (niveau <= 6) return 16;
|
|
|
|
return 18;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getCompetencesMagie() {
|
|
|
|
return this.competencesMagie
|
|
|
|
}
|
|
|
|
|
2022-12-26 00:33:13 +01: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 HeritiersUtility.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 = HeritiersUtility.findChatMessageId(event.currentTarget)
|
|
|
|
let message = game.messages.get(messageId)
|
2022-12-26 10:13:05 +01:00
|
|
|
let rollData = message.getFlag("world", "heritiers-roll")
|
2022-12-26 00:33:13 +01:00
|
|
|
let actor = this.getActorFromRollData(rollData)
|
|
|
|
await actor.setPredilectionUsed(rollData.competence._id, predIdx)
|
2024-05-23 11:25:51 +02:00
|
|
|
rollData.competence = foundry.utils.duplicate(actor.getCompetence(rollData.competence._id))
|
2022-12-26 00:33:13 +01:00
|
|
|
HeritiersUtility.rollHeritiers(rollData)
|
|
|
|
})
|
2023-04-30 20:08:29 +02:00
|
|
|
|
|
|
|
html.on("click", '.roll-tricherie-2', async event => {
|
|
|
|
let messageId = HeritiersUtility.findChatMessageId(event.currentTarget)
|
|
|
|
let message = game.messages.get(messageId)
|
|
|
|
let rollData = message.getFlag("world", "heritiers-roll")
|
|
|
|
let actor = this.getActorFromRollData(rollData)
|
|
|
|
if ( await actor.incDecTricherie(-2) ) {
|
|
|
|
rollData.forcedValue = Number($(event.currentTarget).data("dice-value"))
|
|
|
|
HeritiersUtility.rollHeritiers(rollData)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-12-26 00:33:13 +01:00
|
|
|
html.on("click", '.roll-chat-degat', async event => {
|
|
|
|
let messageId = HeritiersUtility.findChatMessageId(event.currentTarget)
|
|
|
|
let message = game.messages.get(messageId)
|
2022-12-26 10:13:05 +01:00
|
|
|
let rollData = message.getFlag("world", "heritiers-roll")
|
2022-12-26 00:33:13 +01:00
|
|
|
let actor = this.getActorFromRollData(rollData)
|
|
|
|
actor.rollArmeDegats(rollData.arme._id, rollData.targetVigueur)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async preloadHandlebarsTemplates() {
|
|
|
|
|
|
|
|
const templatePaths = [
|
|
|
|
'systems/fvtt-les-heritiers/templates/editor-notes-gm.html',
|
|
|
|
'systems/fvtt-les-heritiers/templates/partial-item-header.html',
|
|
|
|
'systems/fvtt-les-heritiers/templates/partial-item-description.html',
|
|
|
|
'systems/fvtt-les-heritiers/templates/partial-item-nav.html',
|
2024-07-13 12:12:38 +02:00
|
|
|
'systems/fvtt-les-heritiers/templates/partial-utile-skills.html'
|
2022-12-26 00:33:13 +01:00
|
|
|
]
|
|
|
|
return loadTemplates(templatePaths);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static removeChatMessageId(messageId) {
|
|
|
|
if (messageId) {
|
|
|
|
game.messages.get(messageId)?.delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static findChatMessageId(current) {
|
|
|
|
return HeritiersUtility.getChatMessageId(HeritiersUtility.findChatMessage(current));
|
|
|
|
}
|
|
|
|
|
|
|
|
static getChatMessageId(node) {
|
|
|
|
return node?.attributes.getNamedItem('data-message-id')?.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static findChatMessage(current) {
|
|
|
|
return HeritiersUtility.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 HeritiersUtility.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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getActorFromRollData(rollData) {
|
|
|
|
let actor = game.actors.get(rollData.actorId)
|
|
|
|
if (rollData.tokenId) {
|
|
|
|
let token = canvas.tokens.placeables.find(t => t.id == rollData.tokenId)
|
|
|
|
if (token) {
|
|
|
|
actor = token.actor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return actor
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static updateRollData(rollData) {
|
|
|
|
|
|
|
|
let id = rollData.rollId;
|
|
|
|
let oldRollData = this.rollDataStore[id] || {};
|
2024-05-23 11:25:51 +02:00
|
|
|
let newRollData = foundry.utils.mergeObject(oldRollData, rollData);
|
2022-12-26 00:33:13 +01:00
|
|
|
this.rollDataStore[id] = newRollData;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static saveRollData(rollData) {
|
|
|
|
game.socket.emit("system.fvtt-les-heritiers", {
|
|
|
|
name: "msg_update_roll", data: rollData
|
|
|
|
}); // Notify all other clients of the roll
|
|
|
|
this.updateRollData(rollData);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getRollData(id) {
|
|
|
|
return this.rollDataStore[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static onSocketMesssage(msg) {
|
|
|
|
if (msg.name == "msg_update_defense_state") {
|
|
|
|
this.updateDefenseState(msg.data.defenderId, msg.data.rollId);
|
|
|
|
}
|
|
|
|
if (msg.name == "msg_update_roll") {
|
|
|
|
this.updateRollData(msg.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static computeMonnaieDetails(valueSC) {
|
|
|
|
let po = Math.floor(valueSC / 400)
|
2023-04-08 09:55:08 +02:00
|
|
|
let pa = Math.floor((valueSC - (po * 400)) / 20)
|
|
|
|
let sc = valueSC - (po * 400) - (pa * 20)
|
2022-12-26 00:33:13 +01:00
|
|
|
return {
|
2023-04-08 09:55:08 +02:00
|
|
|
po: po, pa: pa, sc: sc, valueSC: valueSC
|
2022-12-26 00:33:13 +01:00
|
|
|
}
|
|
|
|
}
|
2023-04-08 09:55:08 +02:00
|
|
|
|
2022-12-26 00:33:13 +01:00
|
|
|
/* -------------------------------------------- */
|
2023-01-20 15:19:04 +01:00
|
|
|
static incDecHeritage() {
|
|
|
|
|
|
|
|
}
|
2023-04-08 09:55:08 +02:00
|
|
|
|
2023-01-20 15:19:04 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static computeResult(actor, rollData) {
|
2023-04-08 09:55:08 +02:00
|
|
|
let isTricherieHeritage = rollData.useHeritage || rollData.useTricherie
|
|
|
|
|
2023-01-20 15:19:04 +01:00
|
|
|
rollData.marge = 0
|
2023-04-08 09:55:08 +02:00
|
|
|
|
|
|
|
if (isTricherieHeritage) {
|
2023-04-08 18:49:54 +02:00
|
|
|
let resTab = [rollData.roll.terms[0].results[0].result, rollData.roll.terms[0].results[1].result, rollData.roll.terms[0].results[2].result]
|
2023-04-08 09:55:08 +02:00
|
|
|
rollData.diceResult = resTab[0] + "," + resTab[1] + "," + resTab[2]
|
2023-04-30 20:08:29 +02:00
|
|
|
let foundryTotal = resTab[0] + resTab[1] + resTab[2]
|
2023-04-08 09:55:08 +02:00
|
|
|
if (resTab[1] == 1) { resTab[1] -= 4 }
|
|
|
|
if (resTab[2] == 1) { resTab[2] -= 6 }
|
|
|
|
if (resTab[2] == 2) { resTab[2] -= 7 }
|
2023-04-30 20:08:29 +02:00
|
|
|
rollData.diceValue = Math.max(Math.max(resTab[0], resTab[1]), resTab[2])
|
|
|
|
rollData.finalResult = rollData.roll.total - foundryTotal + rollData.diceValue
|
2023-04-08 18:49:54 +02:00
|
|
|
|
2023-04-08 09:55:08 +02:00
|
|
|
// Gestion des résultats spéciaux
|
2023-01-20 15:19:04 +01:00
|
|
|
resTab = resTab.sort()
|
2023-04-08 09:55:08 +02:00
|
|
|
if ((resTab[0] == resTab[1]) && (resTab[1] == resTab[2])) {
|
2023-01-20 15:19:04 +01:00
|
|
|
rollData.marge = 7
|
|
|
|
rollData.isSuccess = true
|
2023-04-08 09:55:08 +02:00
|
|
|
rollData.isCriticalSuccess = true
|
|
|
|
rollData.isBrelan = true
|
2023-01-20 15:19:04 +01:00
|
|
|
}
|
2023-04-08 09:55:08 +02:00
|
|
|
if ((resTab[0] + 1 == resTab[1]) && (resTab[1] + 1 == resTab[2])) {
|
2023-01-20 15:19:04 +01:00
|
|
|
rollData.marge = 7
|
|
|
|
rollData.isSuccess = true
|
2023-04-08 09:55:08 +02:00
|
|
|
rollData.isCriticalSuccess = true
|
|
|
|
rollData.isSuite = true
|
|
|
|
}
|
|
|
|
if (rollData.useTricherie) {
|
2023-01-20 15:19:04 +01:00
|
|
|
actor.incDecTricherie(-1)
|
|
|
|
}
|
2023-04-08 09:55:08 +02:00
|
|
|
if (rollData.useHeritage) {
|
2023-01-20 15:19:04 +01:00
|
|
|
this.incDecHeritage()
|
|
|
|
}
|
2023-04-08 18:49:54 +02:00
|
|
|
|
2023-04-08 09:55:08 +02:00
|
|
|
} else {
|
|
|
|
rollData.finalResult = rollData.roll.total
|
2023-04-30 20:08:29 +02:00
|
|
|
let rollValue = rollData.forcedValue || rollData.roll.terms[0].results[0].result
|
|
|
|
rollData.diceResult = rollValue
|
|
|
|
rollData.diceValue = rollValue
|
2023-04-08 09:55:08 +02:00
|
|
|
if (rollData.mainDice.includes("d10")) {
|
2023-04-08 18:49:54 +02:00
|
|
|
if (rollValue == 1) {
|
|
|
|
rollData.finalResult -= 3 + rollValue // substract 3 and the 1 value that has been added
|
2023-04-08 09:55:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rollData.mainDice.includes("d12")) {
|
2023-04-08 18:49:54 +02:00
|
|
|
if (rollValue == 1 || rollValue == 2) {
|
|
|
|
rollData.finalResult -= 5 + rollValue // Remove also the dice result has it has been added already
|
2023-04-08 09:55:08 +02:00
|
|
|
}
|
|
|
|
}
|
2023-04-30 20:08:29 +02:00
|
|
|
if ( !rollData.forcedValue) {
|
2024-05-23 11:25:51 +02:00
|
|
|
rollData.adjacentFaces = foundry.utils.duplicate(__facesAdjacentes[rollData.mainDice][rollData.diceValue])
|
2023-04-30 20:08:29 +02:00
|
|
|
}
|
2023-01-18 16:16:18 +01:00
|
|
|
}
|
2023-04-08 18:49:54 +02:00
|
|
|
}
|
2023-04-08 20:21:09 +02:00
|
|
|
|
2023-04-08 18:49:54 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static computeArmeDegats(rollData, actor) {
|
|
|
|
rollData.degatsArme = rollData.arme.system.degats + rollData.marge
|
2023-04-30 20:08:29 +02:00
|
|
|
if (rollData.attaqueDeuxArmes != 0 && rollData.secondeArme) {
|
2023-04-11 13:26:51 +02:00
|
|
|
let secondeArme = actor.items.get(secondeArme)
|
|
|
|
if (secondeArme) {
|
|
|
|
rollData.degatsArme += secondeArme.system.degats
|
|
|
|
rollData.degatsArme += actor.system.caracteristiques.for.value
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (rollData.arme.system.categorie == "lourde") {
|
|
|
|
rollData.degatsArme += actor.system.caracteristiques.for.value
|
|
|
|
}
|
|
|
|
if (rollData.arme.system.categorie == "blanche" || rollData.arme.system.categorie == "improvise") {
|
|
|
|
rollData.degatsArme += Math.max(0, actor.system.caracteristiques.for.value - 2)
|
|
|
|
}
|
|
|
|
if (rollData.mode == "attaquecharge") {
|
|
|
|
rollData.degatsArme += 3
|
2023-04-30 20:08:29 +02:00
|
|
|
}
|
2023-04-11 13:26:51 +02:00
|
|
|
}
|
|
|
|
if (rollData.attaqueCible == "membre") {
|
|
|
|
rollData.degatsArme -= 2
|
2023-04-08 18:49:54 +02:00
|
|
|
}
|
2023-04-11 13:26:51 +02:00
|
|
|
if (rollData.attaqueCible == "main") {
|
|
|
|
rollData.degatsArme -= 3
|
2022-12-26 00:33:13 +01:00
|
|
|
}
|
2023-04-11 13:26:51 +02:00
|
|
|
if (rollData.attaqueCible == "tete") {
|
|
|
|
rollData.degatsArme *= 3
|
2023-04-09 21:45:46 +02:00
|
|
|
}
|
2022-12-26 00:33:13 +01:00
|
|
|
}
|
|
|
|
|
2023-04-08 18:49:54 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static computeMarge(rollData, seuil) {
|
|
|
|
if (rollData.marge == 0 && seuil >= 0) {
|
|
|
|
rollData.marge = rollData.finalResult - seuil
|
|
|
|
rollData.isSuccess = (rollData.finalResult >= seuil)
|
|
|
|
rollData.isCriticalSuccess = ((rollData.finalResult - seuil) >= 7)
|
|
|
|
rollData.isCriticalFailure = ((rollData.finalResult - seuil) <= -7)
|
2024-03-06 19:00:01 +01:00
|
|
|
// Si compétence > 0 et d8 -> echec critique impossible
|
|
|
|
if (rollData?.competence?.system.niveau > 0 && rollData?.mainDice == "d8") {
|
|
|
|
rollData.isCriticalFailure = false
|
|
|
|
}
|
2023-04-08 18:49:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async displayUneDefense(rollData, actor, nomDefense, valeurDefense) {
|
|
|
|
rollData.defenderMode = nomDefense
|
|
|
|
rollData.defenderValue = valeurDefense
|
|
|
|
rollData.marge = 0
|
|
|
|
this.computeMarge(rollData, valeurDefense)
|
|
|
|
if (rollData.isSuccess) {
|
|
|
|
this.computeArmeDegats(rollData, actor)
|
|
|
|
}
|
|
|
|
this.createChatWithRollMode(rollData.alias, {
|
|
|
|
content: await renderTemplate(`systems/fvtt-les-heritiers/templates/chat-cc-result.html`, rollData)
|
|
|
|
}, rollData, "selfroll")
|
|
|
|
}
|
2023-04-09 21:45:46 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async displayAsssomer(rollData, actor, nomAttaque, etatAssomer, valeurDefense) {
|
|
|
|
rollData.defenderMode = nomAttaque
|
|
|
|
rollData.etatAssommer = etatAssomer
|
|
|
|
rollData.defenderValue = valeurDefense
|
|
|
|
rollData.marge = 0
|
|
|
|
this.computeMarge(rollData, valeurDefense)
|
2023-04-30 20:08:29 +02:00
|
|
|
rollData.dureeAssommer = (rollData.marge) ? rollData.marge * 2 : 1
|
2023-04-09 21:45:46 +02:00
|
|
|
this.createChatWithRollMode(rollData.alias, {
|
|
|
|
content: await renderTemplate(`systems/fvtt-les-heritiers/templates/chat-assommer-result.html`, rollData)
|
|
|
|
}, rollData, "selfroll")
|
|
|
|
}
|
2022-12-26 00:33:13 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async rollHeritiers(rollData) {
|
|
|
|
|
|
|
|
let actor = this.getActorFromRollData(rollData)
|
2023-03-13 09:00:49 +01:00
|
|
|
|
2024-03-23 11:37:15 +01:00
|
|
|
if ( rollData.mode == "pouvoir" && actor.getPouvoirUsage(rollData.pouvoir._id) < rollData.pouvoirPointsUsage) {
|
|
|
|
ui.notifications.warn("Pas assez de points d'usage pour ce pouvoir.")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-01-18 16:16:18 +01:00
|
|
|
//rollData.actionImg = "systems/fvtt-les-heritiers/assets/icons/" + actor.system.attributs[rollData.attrKey].labelnorm + ".webp"
|
2024-08-11 14:40:41 +02:00
|
|
|
if (rollData.caracKey == "pre") rollData.caracKey = "pres"; // Patch tomanage wrong carac key
|
2024-05-23 11:25:51 +02:00
|
|
|
rollData.carac = foundry.utils.duplicate(actor.system.caracteristiques[rollData.caracKey])
|
2022-12-26 00:33:13 +01:00
|
|
|
|
2023-04-30 20:08:29 +02:00
|
|
|
if (rollData.forcedValue) {
|
|
|
|
rollData.diceFormula = rollData.forcedValue
|
2023-04-08 09:55:08 +02:00
|
|
|
} else {
|
2023-04-30 20:08:29 +02:00
|
|
|
if (rollData.useTricherie || rollData.useHeritage) {
|
|
|
|
rollData.diceFormula = "{1d8, 1d10, 1d12}"
|
|
|
|
} else {
|
|
|
|
rollData.diceFormula = "1" + rollData.mainDice + "kh1"
|
|
|
|
}
|
2023-04-08 09:55:08 +02:00
|
|
|
}
|
2023-03-11 12:11:27 +01:00
|
|
|
|
|
|
|
let rangValue = 0
|
|
|
|
if (rollData.rang) {
|
|
|
|
rangValue = rollData.rang.value
|
2023-04-08 09:55:08 +02:00
|
|
|
}
|
2022-12-26 00:33:13 +01:00
|
|
|
if (rollData.competence) {
|
2024-03-06 18:46:53 +01:00
|
|
|
let compmod = 0 // Bonus de compétence à 0 dans Les Heritiers
|
2023-03-08 16:58:11 +01:00
|
|
|
let specBonus = (rollData.useSpecialite) ? 1 : 0
|
2023-03-11 12:11:27 +01:00
|
|
|
rollData.diceFormula += `+${rollData.carac.value}+${rangValue}+${rollData.competence.system.niveau}+${specBonus}+${rollData.bonusMalusContext}+${compmod}`
|
2023-03-09 13:16:19 +01:00
|
|
|
} else if (rollData.pouvoirBase) {
|
2023-04-30 20:08:29 +02:00
|
|
|
rollData.diceFormula += `+${rollData.carac.value}+${rollData.pouvoirBase.value}+${rangValue}+${rollData.bonusMalusContext}`
|
2022-12-26 00:33:13 +01:00
|
|
|
} else {
|
2023-03-11 12:11:27 +01:00
|
|
|
rollData.diceFormula += `+${rollData.carac.value}+${rangValue}+${rollData.bonusMalusContext}`
|
2022-12-26 00:33:13 +01:00
|
|
|
}
|
2023-04-09 21:45:46 +02:00
|
|
|
let ruleMalus = 0
|
|
|
|
for (let malus of rollData.rulesMalus) {
|
|
|
|
ruleMalus += malus.value
|
|
|
|
}
|
|
|
|
rollData.diceFormula += `+${ruleMalus}`
|
2022-12-26 00:33:13 +01:00
|
|
|
|
2023-04-11 13:26:51 +02:00
|
|
|
// Gestion bonus attaque à plusieurs
|
2023-04-10 14:11:47 +02:00
|
|
|
let bonusAttaque = rollData.bonusAttaquePlusieurs
|
|
|
|
if (rollData.attaqueDos) {
|
|
|
|
bonusAttaque = 2
|
2023-04-30 20:08:29 +02:00
|
|
|
if (rollData.bonusAttaquePlusieurs) {
|
2023-04-10 14:11:47 +02:00
|
|
|
bonusAttaque = 3 // Valeur max, cf règle page 197
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rollData.diceFormula += `+${bonusAttaque}`
|
|
|
|
|
2023-04-11 13:26:51 +02:00
|
|
|
// Gestion attaque avec 2 armes
|
|
|
|
if (rollData.attaqueDeuxArmes != 0) {
|
|
|
|
rollData.diceFormula += `+${rollData.attaqueDeuxArmes}`
|
|
|
|
}
|
|
|
|
// Gestion des attaques ciblées
|
|
|
|
if (rollData.attaqueCible != "none") {
|
2023-04-30 20:08:29 +02:00
|
|
|
if (rollData.attaqueCible == "membre") {
|
2023-04-11 13:26:51 +02:00
|
|
|
rollData.diceFormula += `-2`
|
|
|
|
}
|
2023-04-30 20:08:29 +02:00
|
|
|
if (rollData.attaqueCible == "main") {
|
2023-04-11 13:26:51 +02:00
|
|
|
rollData.diceFormula += `-3`
|
|
|
|
}
|
2023-04-30 20:08:29 +02:00
|
|
|
if (rollData.attaqueCible == "tete") {
|
2023-04-11 13:26:51 +02:00
|
|
|
rollData.diceFormula += `-6`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-11 12:36:50 +02:00
|
|
|
if ( !rollData.noRoll) {
|
2024-05-23 11:25:51 +02:00
|
|
|
let myRoll = await new Roll(rollData.diceFormula).roll()
|
2024-04-11 12:36:50 +02:00
|
|
|
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"))
|
2024-05-23 11:25:51 +02:00
|
|
|
rollData.roll = foundry.utils.duplicate(myRoll)
|
2024-04-11 12:36:50 +02:00
|
|
|
console.log(">>>> ", myRoll)
|
|
|
|
this.computeResult(actor, rollData)
|
|
|
|
this.computeMarge(rollData, rollData.sdValue) // Calcul de la marge si seuil présent
|
|
|
|
}
|
2023-04-08 18:49:54 +02:00
|
|
|
|
2023-03-01 22:12:27 +01:00
|
|
|
if (rollData.mode == "init") {
|
2022-12-26 00:33:13 +01:00
|
|
|
actor.setFlag("world", "last-initiative", rollData.finalResult)
|
|
|
|
}
|
|
|
|
|
2024-03-23 11:37:15 +01:00
|
|
|
// Gestion pouvoir et points d'usage
|
2024-04-11 12:36:50 +02:00
|
|
|
if (rollData.mode == "pouvoir" || rollData.mode == "pouvoirpassif") {
|
2024-03-23 11:37:15 +01:00
|
|
|
actor.incDecPointsUsage(rollData.pouvoir._id, -rollData.pouvoirPointsUsage)
|
|
|
|
}
|
|
|
|
|
2022-12-26 00:33:13 +01:00
|
|
|
this.createChatWithRollMode(rollData.alias, {
|
|
|
|
content: await renderTemplate(`systems/fvtt-les-heritiers/templates/chat-generic-result.html`, rollData)
|
|
|
|
}, rollData)
|
|
|
|
|
2023-04-09 21:45:46 +02:00
|
|
|
// Gestion attaque standard
|
2023-04-30 20:08:29 +02:00
|
|
|
if ((rollData.mode == "arme" || rollData.mode == "attaquebrutale" || rollData.mode == "attaquecharge") &&
|
|
|
|
rollData.defenderTokenId && rollData.arme) {
|
|
|
|
if (rollData.arme.system.categorie != "trait" && rollData.arme.system.categorie != "poing" && rollData.arme.system.categorie != "epaule") {
|
2023-04-08 20:21:09 +02:00
|
|
|
await this.displayUneDefense(rollData, actor, "Parade", rollData.defenderParade)
|
|
|
|
await this.displayUneDefense(rollData, actor, "Esquive", rollData.defenderEsquive)
|
|
|
|
} else if (rollData.sdValue) {
|
|
|
|
this.displayUneDefense(rollData, actor, "A Distance", rollData.sdValue)
|
|
|
|
} else {
|
|
|
|
ui.notifications.warn("Pas de difficulté positionnée pour l'attaque à distance.")
|
|
|
|
}
|
2023-04-08 18:49:54 +02:00
|
|
|
}
|
2023-04-09 21:45:46 +02:00
|
|
|
// Gestion assomer
|
|
|
|
if (rollData.mode == "assommer" && rollData.defenderTokenId && rollData.arme) {
|
|
|
|
await this.displayAsssomer(rollData, actor, "Assommer", "Surprise", rollData.defenderResistancePhysique)
|
2023-04-30 20:08:29 +02:00
|
|
|
await this.displayAsssomer(rollData, actor, "Assommer", "Conscient, Résistance+6", rollData.defenderResistancePhysique + 6)
|
|
|
|
await this.displayAsssomer(rollData, actor, "Assommer", "Conscient, Parade", rollData.defenderParade)
|
|
|
|
await this.displayAsssomer(rollData, actor, "Assommer", "Conscient, Esquive", rollData.defenderEsquive + 6)
|
2023-04-09 21:45:46 +02:00
|
|
|
}
|
2023-04-08 18:49:54 +02:00
|
|
|
|
2022-12-26 00:33:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async bonusRollHeritiers(rollData) {
|
|
|
|
rollData.bonusFormula = rollData.addedBonus
|
|
|
|
|
2024-05-23 11:25:51 +02:00
|
|
|
let bonusRoll = await new Roll(rollData.bonusFormula).roll()
|
2022-12-26 00:33:13 +01:00
|
|
|
await this.showDiceSoNice(bonusRoll, game.settings.get("core", "rollMode"));
|
2024-05-23 11:25:51 +02:00
|
|
|
rollData.bonusRoll = foundry.utils.duplicate(bonusRoll)
|
2022-12-26 00:33:13 +01:00
|
|
|
|
|
|
|
rollData.finalResult += rollData.bonusRoll.total
|
|
|
|
|
|
|
|
this.computeResult(rollData)
|
|
|
|
|
|
|
|
this.createChatWithRollMode(rollData.alias, {
|
|
|
|
content: await renderTemplate(`systems/fvtt-les-heritiers/templates/chat-generic-result.html`, rollData)
|
|
|
|
}, rollData)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getUsers(filter) {
|
|
|
|
return game.users.filter(filter).map(user => user._id);
|
|
|
|
}
|
|
|
|
|
2023-04-09 21:45:46 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static isArmeMelee(arme) {
|
2024-03-23 11:37:15 +01:00
|
|
|
return (arme.type == "arme" && (arme.system.categorie == "lourde" || arme.system.categorie == "blanche" || arme.system.categorie == "improvise"))
|
2023-04-09 21:45:46 +02:00
|
|
|
}
|
2022-12-26 00:33:13 +01: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) {
|
2024-05-23 11:25:51 +02:00
|
|
|
let chatGM = foundry.utils.duplicate(chatOptions);
|
2022-12-26 00:33:13 +01:00
|
|
|
chatGM.whisper = this.getUsers(user => user.isGM);
|
|
|
|
chatGM.content = "Blinde message of " + game.user.name + "<br>" + chatOptions.content;
|
|
|
|
console.log("blindMessageToGM", chatGM);
|
|
|
|
game.socket.emit("system.fvtt-les-heritiers", { msg: "msg_gm_chat_message", data: chatGM });
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async searchItem(dataItem) {
|
|
|
|
let item
|
|
|
|
if (dataItem.pack) {
|
|
|
|
let id = dataItem.id || dataItem._id
|
|
|
|
let items = await this.loadCompendium(dataItem.pack, item => item.id == id)
|
|
|
|
item = items[0] || undefined
|
|
|
|
} 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-12-26 10:13:05 +01:00
|
|
|
msg.setFlag("world", "heritiers-roll", rollData)
|
2022-12-26 00:33:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getBasicRollData() {
|
|
|
|
let rollData = {
|
2024-05-23 11:25:51 +02:00
|
|
|
rollId: foundry.utils.randomID(16),
|
2022-12-26 00:33:13 +01:00
|
|
|
rollMode: game.settings.get("core", "rollMode"),
|
2023-01-18 16:16:18 +01:00
|
|
|
sdList: game.system.lesheritiers.config.seuilsDifficulte,
|
2023-04-08 18:49:54 +02:00
|
|
|
sdValue: -1,
|
2023-04-10 14:11:47 +02:00
|
|
|
bonusAttaquePlusieurs: 0,
|
2023-04-11 13:26:51 +02:00
|
|
|
attaqueDeuxArmes: 0,
|
2023-04-10 14:11:47 +02:00
|
|
|
attaqueDos: false,
|
2023-04-09 21:45:46 +02:00
|
|
|
bonusMalusContext: 0,
|
2023-04-11 13:26:51 +02:00
|
|
|
attaqueCible: "none",
|
|
|
|
config: game.system.lesheritiers.config,
|
2023-04-30 20:08:29 +02:00
|
|
|
rulesMalus: []
|
2022-12-26 00:33:13 +01:00
|
|
|
}
|
|
|
|
return rollData
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static updateWithTarget(rollData) {
|
|
|
|
let target = HeritiersUtility.getTarget()
|
|
|
|
if (target) {
|
|
|
|
rollData.defenderTokenId = target.id
|
|
|
|
let defender = game.canvas.tokens.get(rollData.defenderTokenId).actor
|
2023-04-08 18:49:54 +02:00
|
|
|
rollData.defenderName = defender.name
|
|
|
|
rollData.defenderParade = defender.getCurrentParade()
|
|
|
|
rollData.defenderEsquive = defender.getCurrentEsquive()
|
2023-04-09 21:45:46 +02:00
|
|
|
rollData.defenderResistancePhysique = defender.getCurrentResistancePhysique()
|
2022-12-26 00:33:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2023-04-08 18:49:54 +02:00
|
|
|
static createChatWithRollMode(name, chatOptions, rollData = undefined, rollMode = undefined) {
|
2023-04-08 20:21:09 +02:00
|
|
|
if (rollMode == undefined) {
|
2023-04-08 18:49:54 +02:00
|
|
|
rollMode = game.settings.get("core", "rollMode")
|
|
|
|
}
|
2022-12-26 00:33:13 +01:00
|
|
|
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-12-26 10:13:05 +01:00
|
|
|
let rollData = msg.getFlag("world", "heritiers-roll")
|
2022-12-26 00:33:13 +01:00
|
|
|
let actor = this.getActorFromRollData(rollData)
|
|
|
|
actor.changeBonneAventure(changed)
|
|
|
|
rollData.isReroll = true
|
|
|
|
rollData.textBonus = "Bonus de Points d'Aventure"
|
|
|
|
if (addedBonus == "reroll") {
|
|
|
|
HeritiersUtility.rollHeritiers(rollData)
|
|
|
|
} else {
|
|
|
|
rollData.addedBonus = addedBonus
|
|
|
|
HeritiersUtility.bonusRollHeritiers(rollData)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static applyEclatRoll(li, changed, addedBonus) {
|
|
|
|
let msgId = li.data("message-id")
|
|
|
|
let msg = game.messages.get(msgId)
|
|
|
|
if (msg) {
|
2022-12-26 10:13:05 +01:00
|
|
|
let rollData = msg.getFlag("world", "heritiers-roll")
|
2022-12-26 00:33:13 +01:00
|
|
|
let actor = this.getActorFromRollData(rollData)
|
|
|
|
actor.changeEclat(changed)
|
|
|
|
rollData.isReroll = true
|
|
|
|
rollData.textBonus = "Bonus d'Eclat"
|
|
|
|
if (addedBonus == "reroll") {
|
|
|
|
HeritiersUtility.rollHeritiers(rollData)
|
|
|
|
} else {
|
|
|
|
rollData.addedBonus = addedBonus
|
|
|
|
HeritiersUtility.bonusRollHeritiers(rollData)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static chatRollMenu(html, options) {
|
2022-12-26 10:13:05 +01:00
|
|
|
let canApply = li => canvas.tokens.controlled.length && li.find(".heritiers-roll").length
|
2022-12-26 00:33:13 +01:00
|
|
|
let canApplyBA = function (li) {
|
|
|
|
let message = game.messages.get(li.attr("data-message-id"))
|
2022-12-26 10:13:05 +01:00
|
|
|
let rollData = message.getFlag("world", "heritiers-roll")
|
2022-12-26 00:33:13 +01:00
|
|
|
let actor = this.getActorFromRollData(rollData)
|
|
|
|
return (!rollData.isReroll && actor.getBonneAventure() > 0)
|
|
|
|
}
|
|
|
|
let canApplyPE = function (li) {
|
|
|
|
let message = game.messages.get(li.attr("data-message-id"))
|
2022-12-26 10:13:05 +01:00
|
|
|
let rollData = message.getFlag("world", "heritiers-roll")
|
2022-12-26 00:33:13 +01:00
|
|
|
let actor = this.getActorFromRollData(rollData)
|
|
|
|
return (!rollData.isReroll && actor.getEclat() > 0)
|
|
|
|
}
|
|
|
|
options.push(
|
|
|
|
{
|
|
|
|
name: "Ajouer +3 (1 point de Bonne Aventure)",
|
|
|
|
icon: "<i class='fas fa-user-plus'></i>",
|
|
|
|
condition: canApply && canApplyBA,
|
|
|
|
callback: li => HeritiersUtility.applyBonneAventureRoll(li, -1, "+3")
|
|
|
|
}
|
|
|
|
)
|
|
|
|
options.push(
|
|
|
|
{
|
|
|
|
name: "Ajouter +10 (1 Point d'Eclat)",
|
|
|
|
icon: "<i class='fas fa-user-plus'></i>",
|
|
|
|
condition: canApply && canApplyPE,
|
|
|
|
callback: li => HeritiersUtility.applyEclatRoll(li, -1, "+10")
|
|
|
|
}
|
|
|
|
)
|
|
|
|
options.push(
|
|
|
|
{
|
|
|
|
name: "Relancer le dé (1 point d'Eclat)",
|
|
|
|
icon: "<i class='fas fa-user-plus'></i>",
|
|
|
|
condition: canApply && canApplyPE,
|
|
|
|
callback: li => HeritiersUtility.applyEclatRoll(li, -3, "reroll")
|
|
|
|
}
|
|
|
|
)
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************************/
|
|
|
|
static async __create_talents_table() {
|
|
|
|
let compName = "fvtt-les-heritiers.talents-cellule"
|
|
|
|
const compData = await HeritiersUtility.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 });
|
|
|
|
}
|
|
|
|
}
|