Move to new compendiums

This commit is contained in:
2024-11-19 23:54:30 +01:00
parent ad488bb36d
commit 434a18b284
90 changed files with 367 additions and 360 deletions

View File

@@ -10,7 +10,7 @@ export class VadentisActorSheet extends ActorSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["vadentis", "sheet", "actor"],
template: "systems/foundryvtt-vadentis/templates/actor-sheet.html",
width: 680,

View File

@@ -30,7 +30,7 @@ export class VadentisActor extends Actor {
if (data instanceof Array) {
return super.create(data, options);
}
// If the created actor has items (only applicable to duplicated actors) bypass the new actor creation logic
// If the created actor has items (only applicable to foundry.utils.duplicated actors) bypass the new actor creation logic
if (data.items) {
let actor = super.create(data, options);
return actor;
@@ -46,48 +46,48 @@ export class VadentisActor extends Actor {
/* -------------------------------------------- */
getCompetences() {
return duplicate( this.items.filter( item => item.type == 'competence') || [] );
return foundry.utils.duplicate( this.items.filter( item => item.type == 'competence') || [] );
}
/* -------------------------------------------- */
getDonnees() {
return duplicate( this.items.filter( item => item.type == 'donnee')|| [] );
return foundry.utils.duplicate( this.items.filter( item => item.type == 'donnee')|| [] );
}
/* -------------------------------------------- */
getEglises() {
return duplicate( this.items.filter( item => item.type == 'eglise')|| [] );
return foundry.utils.duplicate( this.items.filter( item => item.type == 'eglise')|| [] );
}
/* -------------------------------------------- */
getSorts() {
return duplicate( this.items.filter( item => item.type == 'sort')|| [] );
return foundry.utils.duplicate( this.items.filter( item => item.type == 'sort')|| [] );
}
/* -------------------------------------------- */
getAttributs() {
return duplicate( this.items.filter( item => item.type == 'attribut')|| [] );
return foundry.utils.duplicate( this.items.filter( item => item.type == 'attribut')|| [] );
}
/* -------------------------------------------- */
getTechniques() {
return duplicate( this.items.filter( item => item.type == 'technique') || [] );
return foundry.utils.duplicate( this.items.filter( item => item.type == 'technique') || [] );
}
/* -------------------------------------------- */
getDevotions() {
return duplicate(this.items.filter( item => item.type == 'devotion')|| [] );
return foundry.utils.duplicate(this.items.filter( item => item.type == 'devotion')|| [] );
}
/* -------------------------------------------- */
getEquipements() {
return duplicate(this.items.filter( item => item.type == 'equipement' ) || [] );
return foundry.utils.duplicate(this.items.filter( item => item.type == 'equipement' ) || [] );
}
/* -------------------------------------------- */
getArmes() {
return duplicate(this.items.filter( item => item.type == 'armecc' || item.type == 'tir' ) || [] );
return foundry.utils.duplicate(this.items.filter( item => item.type == 'armecc' || item.type == 'tir' ) || [] );
}
/* -------------------------------------------- */
getArmures() {
return duplicate(this.items.filter( item => item.type == 'armurebouclier' ) || [] );
return foundry.utils.duplicate(this.items.filter( item => item.type == 'armurebouclier' ) || [] );
}
/* -------------------------------------------- */
getMonnaies() {
return duplicate(this.items.filter( item => item.type == 'monnaie' ) || [] );
return foundry.utils.duplicate(this.items.filter( item => item.type == 'monnaie' ) || [] );
}
/* -------------------------------------------- */
@@ -291,7 +291,7 @@ export class VadentisActor extends Actor {
async rollSort( sortId ) {
let sort = this.items.get( sortId );
if ( sort ) {
sort = duplicate(sort)
sort = foundry.utils.duplicate(sort)
this.processSortDevotion( "sort", sort);
}
}
@@ -300,7 +300,7 @@ export class VadentisActor extends Actor {
async rollDevotion( devotionId ) {
let devotion = this.items.get( devotionId );
if ( devotion ) {
devotion = duplicate(devotion)
devotion = foundry.utils.duplicate(devotion)
this.processSortDevotion( "devotion", devotion);
}
}
@@ -316,7 +316,7 @@ export class VadentisActor extends Actor {
async rollTechnique( techniqueId ) {
let technique = this.items.get( techniqueId )
if (technique) {
technique = duplicate(technique)
technique = foundry.utils.duplicate(technique)
let msgData = {
alias: this.name,
img: technique.img,
@@ -344,7 +344,7 @@ export class VadentisActor extends Actor {
console.log(competenceId)
let competence = this.items.get( competenceId);
if ( competence) {
competence = duplicate(competence)
competence = foundry.utils.duplicate(competence)
let msgData = {
alias: this.name,
img: competence.img,
@@ -424,7 +424,7 @@ export class VadentisActor extends Actor {
async incrementeArgent( arme ) {
let monnaie = this.items.find( item => item.type == 'monnaie' && item.name == arme.name);
if (monnaie) {
monnaie = duplicate(monnaie)
monnaie = foundry.utils.duplicate(monnaie)
let newValeur = monnaie.system.nombre + 1;
await this.updateEmbeddedDocuments( 'Item', [{ _id: monnaie._id, 'system.nombre': newValeur }] );
}
@@ -433,7 +433,7 @@ export class VadentisActor extends Actor {
async decrementeArgent( arme ) {
let monnaie = this.items.find( item => item.type == 'monnaie' && item.name == arme.name);
if (monnaie) {
monnaie = duplicate(monnaie)
monnaie = foundry.utils.duplicate(monnaie)
let newValeur = monnaie.system.nombre - 1;
newValeur = (newValeur <= 0) ? 0 : newValeur;
await this.updateEmbeddedDocuments( "Item", [{ _id: monnaie._id, 'system.nombre': newValeur }] );
@@ -444,7 +444,7 @@ export class VadentisActor extends Actor {
async incrementeMunition( arme ) {
let armeTir = this.items.find( item => item.type == 'tir' && item.name == arme.name);
if (armeTir) {
armeTir = duplicate(armeTir)
armeTir = foundry.utils.duplicate(armeTir)
let newMunition = armeTir.system.munition + 1;
await this.updateEmbeddedDocuments( "Item", [{ _id: armeTir._id, 'system.munition': newMunition }] );
}
@@ -453,7 +453,7 @@ export class VadentisActor extends Actor {
async decrementeMunition( arme ) {
let armeTir = this.items.find( item => item.type == 'tir' && item.name == arme.name);
if (armeTir) {
armeTir = duplicate(armeTir)
armeTir = foundry.utils.duplicate(armeTir)
let newMunition = armeTir.system.munition - 1;
newMunition = (newMunition <= 0) ? 0 : newMunition;
await this.updateEmbeddedDocuments( "Item", [{ _id: armeTir._id, 'system.munition': newMunition } ]);
@@ -464,7 +464,7 @@ export class VadentisActor extends Actor {
async incrementeQuantite( objet ) {
let objetQ = this.items.find( item => item._id == objet._id );
if (objetQ) {
objetQ = duplicate(objetQ)
objetQ = foundry.utils.duplicate(objetQ)
let newQ = objetQ.system.quantite + 1;
await this.updateEmbeddedDocuments( "Item", [{ _id: objetQ._id, 'system.quantite': newQ } ] );
}
@@ -474,7 +474,7 @@ export class VadentisActor extends Actor {
async decrementeQuantite( objet ) {
let objetQ = this.items.find( item => item._id == objet._id );
if (objetQ) {
objetQ = duplicate(objetQ)
objetQ = foundry.utils.duplicate(objetQ)
let newQ = objetQ.system.quantite - 1;
newQ = (newQ <= 0) ? 0 : newQ;
await this.updateEmbeddedDocuments( "Item", [{ _id: objetQ._id, 'system.quantite': newQ } ]);
@@ -488,7 +488,7 @@ export class VadentisActor extends Actor {
if ( target ) {
let arme = this.items.find( item => (item.type == 'armecc' || item.type == 'tir') && item.id == armeId);
if (arme) {
arme = duplicate(arme)
arme = foundry.utils.duplicate(arme)
if ( arme.type == 'tir' && arme.system.munition <= 0 ) {
ui.notifications.warn("Vous n'avez plus de munitions avec cette arme.");
return;
@@ -496,7 +496,7 @@ export class VadentisActor extends Actor {
let combatData = {
attackerActorId: this.id,
targetActorId: target.actor.id,
arme: duplicate(arme)
arme: foundry.utils.duplicate(arme)
}
if (game.user.isGM) {
VadentisUtility.performAttack( combatData);

View File

@@ -23,7 +23,7 @@ export class VadentisCombat extends Combat {
// Send a chat message
let rollMode = messageOptions.rollMode || game.settings.get("core", "rollMode");
let messageData = mergeObject(
let messageData = foundry.utils.mergeObject(
{
speaker: {
scene: canvas.scene.id,

View File

@@ -8,7 +8,7 @@ export class VadentisItemSheet extends ItemSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["foundryvtt-vadentis", "sheet", "item"],
template: "systems/foundryvtt-vadentis/templates/item-sheet.html",
width: 550,

View File

@@ -1,12 +1,19 @@
/* -------------------------------------------- */
/* -------------------------------------------- */
import { VadentisCombat } from "./vadentis-combat.js";
/* -------------------------------------------- */
export class VadentisUtility {
/* -------------------------------------------- */
/* -------------------------------------------- */
export class VadentisUtility {
/* -------------------------------------------- */
static async preloadHandlebarsTemplates() {
// Handle v12 removal of this helper
Handlebars.registerHelper('select', function (selected, options) {
const escapedValue = RegExp.escape(Handlebars.escapeExpression(selected));
const rgx = new RegExp(' value=[\"\']' + escapedValue + '[\"\']');
const html = options.fn(this);
return html.replace(rgx, "$& selected");
});
const templatePaths = [
'systems/foundryvtt-vadentis/templates/actor-sheet.html',
'systems/foundryvtt-vadentis/templates/item-sheet.html',
@@ -14,77 +21,77 @@ export class VadentisUtility {
'systems/foundryvtt-vadentis/templates/hud-actor-attaque.html',
'systems/foundryvtt-vadentis/templates/hud-actor-sort.html'
]
return loadTemplates(templatePaths);
return loadTemplates(templatePaths);
}
/* -------------------------------------------- */
static updateCombat( combat, round, diff, id ) {
static updateCombat(combat, round, diff, id) {
if (game.user.isGM && combat.round != 0 && combat.turns && combat.active) {
let turn = combat.turns.find(t => t.tokenId == combat.current.tokenId);
ChatMessage.create( { content: `Round ${combat.round} : C'est au tour de ${turn.actor.name}<br>` } );
ChatMessage.create({ content: `Round ${combat.round} : C'est au tour de ${turn.actor.name}<br>` });
canvas.tokens.get(turn.token._id).control();
canvas.tokens.cycleTokens(1, true);
}
}
}
/* -------------------------------------------- */
static createOptionList( min, max) {
static createOptionList(min, max) {
let options = ""
for(let i=min; i<=max; i++) {
for (let i = min; i <= max; i++) {
options += `<option value="${i}">${i}</option>\n`;
}
return options;
}
/* -------------------------------------------- */
static createDirectOptionList( min, max) {
static createDirectOptionList(min, max) {
let options = {};
for(let i=min; i<=max; i++) {
for (let i = min; i <= max; i++) {
options[`${i}`] = `${i}`;
}
return options;
}
/* -------------------------------------------- */
static createDirectIntegerOptionList( min, max) {
static createDirectIntegerOptionList(min, max) {
let options = {};
for(let i=min; i<=max; i++) {
for (let i = min; i <= max; i++) {
options[i] = `${i}`;
}
return options;
}
/* -------------------------------------------- */
static createDirectReverseOptionList( min, max) {
static createDirectReverseOptionList(min, max) {
let options = {};
for(let i=max; i>=min; i--) {
for (let i = max; i >= min; i--) {
options[`${i}`] = `${i}`;
}
return options;
}
/* -------------------------------------------- */
static getTarget() {
if (game.user.targets && game.user.targets.size == 1) {
for (let target of game.user.targets) {
return target;
for (let target of game.user.targets) {
return target;
}
}
return undefined;
}
/* -------------------------------------------- */
static processDamageString( formula, actor ) {
static processDamageString(formula, actor) {
let workFormula = formula.toLowerCase();
if ( workFormula.includes('bonus de force')) {
if (workFormula.includes('bonus de force')) {
workFormula = workFormula.replace('bonus de force', actor.getForceScore());
}
return workFormula;
}
}
/* -------------------------------------------- */
static async processRoll( formula, rollMode ) {
static async processRoll(formula, rollMode) {
let myRoll = new Roll(formula);
myRoll.roll( { async: false} );
await myRoll.roll();
if (game.modules.get("dice-so-nice")?.active) {
await game.dice3d.showForRoll(myRoll, game.user, true);
}
@@ -92,48 +99,48 @@ export class VadentisUtility {
}
/* -------------------------------------------- */
static async performAttack( combatData) {
static async performAttack(combatData) {
let attacker = game.actors.get(combatData.attackerActorId);
let defender = game.actors.get(combatData.targetActorId);
console.log("ATTACK !!", attacker, defender);
if( attacker && defender) {
let defense = defender.getDefenseScore();
if (attacker && defender) {
let defense = defender.getDefenseScore();
let attaque = attacker.getAttaqueScore();
let msgData = {
alias: this.name,
alias: this.name,
title: `${attacker.name} attaque ${defender.name}`
}
let tirMsg = "";
if ( combatData.arme.type == 'tir') {
if (combatData.arme.type == 'tir') {
attacker.decrementeMunition(combatData.arme);
tirMsg += `<br>C'est un tir, les munitions de l'attaquant ont été décrémentées`;
}
let formulaTouche = "1d20+"+attaque;
let formulaFull = attacker.buildTexteFormula( attacker.system.combat.attaque );
let formulaTouche = "1d20+" + attaque;
let formulaFull = attacker.buildTexteFormula(attacker.system.combat.attaque);
let myRoll = await this.processRoll(formulaTouche);
if (myRoll.dice[0].results[0].result > 1 && myRoll.total >= defense) { // Success !
let degats = `normaux : ${combatData.arme.system.damage}`;
let formula = combatData.arme.system.damage.toLowerCase();
msgData.msg = `${attacker.name} a réussi son attaque sur ${defender.name} (${formulaFull} => ${myRoll.total} / ${defense}) !<br> Les dégâts sont ${degats}.`;
msgData.msg += tirMsg;
if ( myRoll.dice[0].results[0].result >= combatData.arme.system.valuecritical ) {
if (myRoll.dice[0].results[0].result >= combatData.arme.system.valuecritical) {
degats = `critiques : ${combatData.arme.system.criticaldamage}`;
formula = combatData.arme.system.criticaldamage.toLowerCase();
msgData.msg += `<br>C'est une <strong>réussite critique</strong> !`;
}
}
msgData.img = 'systems/foundryvtt-vadentis/images/icons/tchat_attaque_réussie.webp'
formula = this.processDamageString( formula, attacker );
formula = this.processDamageString(formula, attacker);
let degatsRoll = await this.processRoll(formula);
msgData.msg +=`<br>Les dégats infligés sont de <strong>${degatsRoll.total}</strong> (${formula}).`;
defender.applyDamage( degatsRoll.total );
msgData.msg += `<br>Les dégats infligés sont de <strong>${degatsRoll.total}</strong> (${formula}).`;
defender.applyDamage(degatsRoll.total);
} else { //Echec
msgData.img = 'systems/foundryvtt-vadentis/images/icons/tchat_attaque_échouée.webp';
if ( myRoll.dice[0].results[0].result == 1) {
if (myRoll.dice[0].results[0].result == 1) {
msgData.msg = `${attacker.name} a fait un <strong>échec critique</strong> et a raté son attaque sur ${defender.name} (${myRoll.total} / ${defense}) !`;
} else {
msgData.msg = `${attacker.name} a raté son attaque sur ${defender.name} (${myRoll.total} / ${defense}) !`;
@@ -143,38 +150,38 @@ export class VadentisUtility {
ChatMessage.create({
//whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
content: await renderTemplate(`systems/foundryvtt-vadentis/templates/chat-generic-result.html`, msgData)
});
});
} else {
ui.notifications.warn("Impossible de trouver l'attaquant et le défenseur.")
}
}
/* -------------------------------------------- */
static buildJetText( stat) {
static buildJetText(stat) {
let name = stat.label;
let title = `Jet de ${name}`;
if ( name.toLowerCase().substr(0,1).match(/[aeoiou]/g) ) {
if (name.toLowerCase().substr(0, 1).match(/[aeoiou]/g)) {
title = `Jet d'${name}`;
}
}
return title;
}
/* -------------------------------------------- */
static registerChatCallbacks( ) {
static registerChatCallbacks() {
}
/* -------------------------------------------- */
static fillRange (start, end) {
static fillRange(start, end) {
return Array(end - start + 1).fill().map((item, index) => start + index);
}
/* -------------------------------------------- */
static onSocketMesssage( msg ) {
if( !game.user.isGM ) return; // Only GM
if (msg.name == 'msg_attack' ) {
this.performAttack( msg.data );
/* -------------------------------------------- */
static onSocketMesssage(msg) {
if (!game.user.isGM) return; // Only GM
if (msg.name == 'msg_attack') {
this.performAttack(msg.data);
}
}
@@ -185,7 +192,7 @@ export class VadentisUtility {
await pack.getIndex().then(index => competences = index);
return competences;
}
/* -------------------------------------------- */
static async loadCompendium(compendium, filter = item => true) {
let compendiumItems = await SoSUtility.loadCompendiumNames(compendium);
@@ -204,11 +211,11 @@ export class VadentisUtility {
}
/* -------------------------------------------- */
static getDonnees( ) {
static getDonnees() {
return this.loadCompendiumNames('foundryvtt-vadentis.donnees');
}
/* -------------------------------------------- */
static getEglises( ) {
static getEglises() {
return this.loadCompendiumNames('foundryvtt-vadentis.croyances');
}
@@ -218,26 +225,26 @@ export class VadentisUtility {
let msgTxt = "<p>Etes vous certain de souhaiter supprimer cet item ?";
let buttons = {
delete: {
icon: '<i class="fas fa-check"></i>',
label: "Oui, à supprimer",
callback: () => {
actorSheet.actor.deleteEmbeddedDocuments('Item', [ itemId] );
li.slideUp(200, () => actorSheet.render(false));
}
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: "Annuler"
icon: '<i class="fas fa-check"></i>',
label: "Oui, à supprimer",
callback: () => {
actorSheet.actor.deleteEmbeddedDocuments('Item', [itemId]);
li.slideUp(200, () => actorSheet.render(false));
}
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: "Annuler"
}
msgTxt += "</p>";
let d = new Dialog({
title: "Confirmer la suppression",
content: msgTxt,
buttons: buttons,
default: "cancel"
});
d.render(true);
}
msgTxt += "</p>";
let d = new Dialog({
title: "Confirmer la suppression",
content: msgTxt,
buttons: buttons,
default: "cancel"
});
d.render(true);
}
}