Migration à Foundry v11/v12 + changes requests

This commit is contained in:
2024-04-27 23:28:28 +02:00
parent 0b86c3b159
commit 1e0f982b90
30 changed files with 473 additions and 415 deletions

View File

@@ -31,7 +31,7 @@ export class VadentisActor extends Actor {
return super.create(data, options);
}
// If the created actor has items (only applicable to duplicated actors) bypass the new actor creation logic
if (data.items) {
if (system.items) {
let actor = super.create(data, options);
return actor;
}
@@ -46,55 +46,55 @@ export class VadentisActor extends Actor {
/* -------------------------------------------- */
getCompetences() {
return duplicate( this.data.items.filter( item => item.type == 'competence') || [] );
return duplicate( this.items.filter( item => item.type == 'competence') || [] );
}
/* -------------------------------------------- */
getDonnees() {
return duplicate( this.data.items.filter( item => item.type == 'donnee')|| [] );
return duplicate( this.items.filter( item => item.type == 'donnee')|| [] );
}
/* -------------------------------------------- */
getEglises() {
return duplicate( this.data.items.filter( item => item.type == 'eglise')|| [] );
return duplicate( this.items.filter( item => item.type == 'eglise')|| [] );
}
/* -------------------------------------------- */
getSorts() {
return duplicate( this.data.items.filter( item => item.type == 'sort')|| [] );
return duplicate( this.items.filter( item => item.type == 'sort')|| [] );
}
/* -------------------------------------------- */
getAttributs() {
return duplicate( this.data.items.filter( item => item.type == 'attribut')|| [] );
return duplicate( this.items.filter( item => item.type == 'attribut')|| [] );
}
/* -------------------------------------------- */
getTechniques() {
return duplicate( this.data.items.filter( item => item.type == 'technique') || [] );
return duplicate( this.items.filter( item => item.type == 'technique') || [] );
}
/* -------------------------------------------- */
getDevotions() {
return duplicate(this.data.items.filter( item => item.type == 'devotion')|| [] );
return duplicate(this.items.filter( item => item.type == 'devotion')|| [] );
}
/* -------------------------------------------- */
getEquipements() {
return duplicate(this.data.items.filter( item => item.type == 'equipement' ) || [] );
return duplicate(this.items.filter( item => item.type == 'equipement' ) || [] );
}
/* -------------------------------------------- */
getArmes() {
return duplicate(this.data.items.filter( item => item.type == 'armecc' || item.type == 'tir' ) || [] );
return duplicate(this.items.filter( item => item.type == 'armecc' || item.type == 'tir' ) || [] );
}
/* -------------------------------------------- */
getArmures() {
return duplicate(this.data.items.filter( item => item.type == 'armurebouclier' ) || [] );
return duplicate(this.items.filter( item => item.type == 'armurebouclier' ) || [] );
}
/* -------------------------------------------- */
getMonnaies() {
return duplicate(this.data.items.filter( item => item.type == 'monnaie' ) || [] );
return duplicate(this.items.filter( item => item.type == 'monnaie' ) || [] );
}
/* -------------------------------------------- */
async updateCompetence( name, field, value) {
let competence = this.data.items.find( item => item.type == 'competence' && item.name == name);
let competence = this.items.find( item => item.type == 'competence' && item.name == name);
if (competence) {
let dataPath = 'data.'+field;
let dataPath = 'system.'+field;
await this.updateEmbeddedDocuments( "Item", [{ _id: competence.id, [dataPath]:value }] );
}
}
@@ -103,7 +103,7 @@ export class VadentisActor extends Actor {
async equiperObject( equipementId ) {
let item = this.items.get(equipementId)
if (item) {
let update = { _id: item.id, "data.equipee": !item.data.data.equipee };
let update = { _id: item.id, "system.equipee": !item.system.equipee };
await this.updateEmbeddedDocuments("Item", [ update ] );
}
}
@@ -116,24 +116,24 @@ export class VadentisActor extends Actor {
/* -------------------------------------------- */
calculerSommeStats( ) {
for (const key in this.data.data.combat) {
let combatData = this.data.data.combat[key];
for (const key in this.system.combat) {
let combatData = this.system.combat[key];
combatData.total = combatData.base + combatData.malus + combatData.bonus;
}
for (const key in this.data.data.magie) {
let magieData = this.data.data.magie[key];
for (const key in this.system.magie) {
let magieData = this.system.magie[key];
magieData.total = magieData.base + magieData.malus + magieData.bonus;
}
}
/* -------------------------------------------- */
async processSortDevotion( name, devotionSort ) {
if ( this.data.data.stats.pointsenergie.value == 0) { // Vérification du ~ de points d'énergie
if ( this.system.stats.pointsenergie.value == 0) { // Vérification du ~ de points d'énergie
ChatMessage.create({ content: `${this.name} n'a pas assez de Points d'Energie pour lancer ${name} ${devotionSort.name}` } );
return;
}
let scores = this.data.data.magie[(name =="devotion") ? 'devotion': 'matriseelementaire'];
let scores = this.system.magie[(name =="devotion") ? 'devotion': 'matriseelementaire'];
let statValue = scores.base + scores.malus + scores.bonus;
let formulaFull = this.buildTexteFormula( scores );
let myRoll = await VadentisUtility.processRoll("1d20+"+statValue );
@@ -143,33 +143,33 @@ export class VadentisActor extends Actor {
isSort: true
}
if (myRoll.dice[0].results[0].result > 1 && myRoll.total >= devotionSort.data.difficulty) {
if (myRoll.dice[0].results[0].result > 1 && myRoll.total >= devotionSort.system.difficulty) {
msgData.img = 'systems/foundryvtt-vadentis/images/icons/tchat_sort_réussi.webp';
msgData.msg = `${this.name} a réussi son ${name} et perd ${devotionSort.data.pe} Points d'Energie (lancer : ${formulaFull} => <strong>${myRoll.total} / ${devotionSort.data.difficulty}</strong>).`;
msgData.msg = `${this.name} a réussi son ${name} et perd ${devotionSort.system.pe} Points d'Energie (lancer : ${formulaFull} => <strong>${myRoll.total} / ${devotionSort.system.difficulty}</strong>).`;
let maintain = (devotionSort.data.ismaintain)?"Oui":"Non";
let complex = (devotionSort.data.complexactions)?"Oui":"Non";
let maintain = (devotionSort.system.ismaintain)?"Oui":"Non";
let complex = (devotionSort.system.complexactions)?"Oui":"Non";
msgData.msg += `<br>Peut être maintenu: ${maintain}<br>Actions complexes : ${complex}`;
if ( !devotionSort.data.notes) devotionSort.data.notes = "";
msgData.msg += `<br><strong>Description : </strong>${devotionSort.data.notes.replace(/<\/?[^>]+(>|$)/g, "")}`;
if ( !devotionSort.system.notes) devotionSort.system.notes = "";
msgData.msg += `<br><strong>Description : </strong>${devotionSort.system.notes.replace(/<\/?[^>]+(>|$)/g, "")}`;
let newEnergie = this.data.data.stats.pointsenergie.value - devotionSort.data.pe;
await this.update( {'data.stats.pointsenergie.value': newEnergie });
if (myRoll.dice[0].results[0].result >= devotionSort.data.valuecritical ) { // Critique ?
let newEnergie = this.system.stats.pointsenergie.value - devotionSort.system.pe;
await this.update( {'system.stats.pointsenergie.value': newEnergie });
if (myRoll.dice[0].results[0].result >= devotionSort.system.valuecritical ) { // Critique ?
msgData.img = 'systems/foundryvtt-vadentis/images/icons/tchat_réussite_critique.webp';
msgData.msg += "<br>C'est une <strong>réussite critique</strong> !";
msgData.msg += `<br><strong>Effet critique : </strong>${devotionSort.data.criticaleffect.replace(/<\/?[^>]+(>|$)/g, "")}`;
msgData.msg += `<br><strong>Effet critique : </strong>${devotionSort.system.criticaleffect.replace(/<\/?[^>]+(>|$)/g, "")}`;
} else {
msgData.msg += `<br><strong>Effet : </strong>${devotionSort.data.effect.replace(/<\/?[^>]+(>|$)/g, "")}`;
msgData.msg += `<br><strong>Effet : </strong>${devotionSort.system.effect.replace(/<\/?[^>]+(>|$)/g, "")}`;
}
if ( devotionSort.data.damage != "") {
let formula = devotionSort.data.damage;
if (myRoll.dice[0].results[0].result >= devotionSort.data.valuecritical ) { // Critique ?
msgData.msg += `<br>Et provoque les dégats critiques suivants : [[/roll ${devotionSort.data.damagecritical}]]`;
formula = devotionSort.data.damagecritical;
if ( devotionSort.system.damage != "") {
let formula = devotionSort.system.damage;
if (myRoll.dice[0].results[0].result >= devotionSort.system.valuecritical ) { // Critique ?
msgData.msg += `<br>Et provoque les dégats critiques suivants : [[/roll ${devotionSort.system.damagecritical}]]`;
formula = devotionSort.system.damagecritical;
} else {
msgData.msg += `<br>Et provoque les dégats suivants : [[/roll ${devotionSort.data.damage}]]`;
msgData.msg += `<br>Et provoque les dégats suivants : [[/roll ${devotionSort.system.damage}]]`;
}
}
if ( newEnergie < 0) {
@@ -184,7 +184,7 @@ export class VadentisActor extends Actor {
msgData.msg = `${this.name} a échoué son lancer de ${name}`;
}
}
console.log(devotionSort.data.description, msgData);
console.log(devotionSort.system.description, msgData);
ChatMessage.create({
//whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
content: await renderTemplate(`systems/foundryvtt-vadentis/templates/chat-generic-result.html`, msgData)
@@ -193,7 +193,7 @@ export class VadentisActor extends Actor {
/* -------------------------------------------- */
async rollDamage( weapon, damageType ) {
let formula = VadentisUtility.processDamageString( weapon.data.data[damageType], this );
let formula = VadentisUtility.processDamageString( weapon.system.data[damageType], this );
let degatsRoll = await VadentisUtility.processRoll( formula );
let msgData = {
alias: this.name,
@@ -209,7 +209,7 @@ export class VadentisActor extends Actor {
/* -------------------------------------------- */
async rollSortDevotionDamage( sort, damageType ) {
let formula = VadentisUtility.processDamageString( sort.data.data[damageType], this );
let formula = VadentisUtility.processDamageString( sort.system.data[damageType], this );
let degatsRoll = await VadentisUtility.processRoll( formula );
let msgData = {
alias: this.name,
@@ -226,9 +226,9 @@ export class VadentisActor extends Actor {
/* -------------------------------------------- */
async applyDamage( damageValue ) {
let pvData = this.data.data.stats.pointsvie;
let pvData = this.system.stats.pointsvie;
let newValue = Math.max( pvData.value - damageValue, MIN_PV);
await this.update( {'data.stats.pointsvie.value': newValue });
await this.update( {'system.stats.pointsvie.value': newValue });
let msgData = {
alias: this.name,
@@ -262,22 +262,22 @@ export class VadentisActor extends Actor {
/* -------------------------------------------- */
getInitiativeScore( ) {
let initData = this.data.data.combat.initiative;
let initData = this.system.combat.initiative;
return this._getCombatValue( initData);
}
/* -------------------------------------------- */
getDefenseScore( ) {
let defenseData = this.data.data.combat.defense;
let defenseData = this.system.combat.defense;
return this._getCombatValue( defenseData);
}
/* -------------------------------------------- */
getForceScore( ) {
let forceData = this.data.data.combat.force;
let forceData = this.system.combat.force;
return this._getCombatValue( forceData);
}
/* -------------------------------------------- */
getAttaqueScore( ) {
let attaqueData = this.data.data.combat.attaque;
let attaqueData = this.system.combat.attaque;
return this._getCombatValue( attaqueData);
}
@@ -289,7 +289,7 @@ export class VadentisActor extends Actor {
/* -------------------------------------------- */
async rollSort( sortId ) {
let sort = this.data.items.get( sortId );
let sort = this.items.get( sortId );
if ( sort ) {
sort = duplicate(sort)
this.processSortDevotion( "sort", sort);
@@ -298,7 +298,7 @@ export class VadentisActor extends Actor {
/* -------------------------------------------- */
async rollDevotion( devotionId ) {
let devotion = this.data.items.get( devotionId );
let devotion = this.items.get( devotionId );
if ( devotion ) {
devotion = duplicate(devotion)
this.processSortDevotion( "devotion", devotion);
@@ -307,14 +307,14 @@ export class VadentisActor extends Actor {
/* -------------------------------------------- */
rollSortOuDevotion( sortId ) {
let sort = this.data.items.get( sortId );
let sort = this.items.get( sortId );
this.processSortDevotion( sort.type, sort);
}
/* -------------------------------------------- */
async rollTechnique( techniqueId ) {
let technique = this.data.items.get( techniqueId )
let technique = this.items.get( techniqueId )
if (technique) {
technique = duplicate(technique)
let msgData = {
@@ -322,13 +322,13 @@ export class VadentisActor extends Actor {
img: technique.img,
title: `Technique ${technique.name}`
}
if ( this.data.data.stats.pointsadrenaline.value < technique.data.pacost) { // Vérification du ~ de points d'adrénaline
if ( this.system.stats.pointsadrenaline.value < technique.system.pacost) { // Vérification du ~ de points d'adrénaline
msgData.msg = `${this.name} n'a pas assez de Points d'Adrénaline pour éxecuter sa technique ${technique.name}`;
} else {
let newAdrenaline = this.data.data.stats.pointsadrenaline.value - technique.data.pacost;
await this.update( {'data.stats.pointsadrenaline.value': newAdrenaline });
msgData.msg = `${this.name} execute sa technique ${technique.name}, pour un côut de ${technique.data.pacost} Points d'Adrénaline<br>
Les effets sont : ${technique.data.effect}`;
let newAdrenaline = this.system.stats.pointsadrenaline.value - technique.system.pacost;
await this.update( {'system.stats.pointsadrenaline.value': newAdrenaline });
msgData.msg = `${this.name} execute sa technique ${technique.name}, pour un côut de ${technique.system.pacost} Points d'Adrénaline<br>
Les effets sont : ${technique.system.effect}`;
}
ChatMessage.create({
//whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
@@ -342,7 +342,7 @@ export class VadentisActor extends Actor {
/* -------------------------------------------- */
async rollCompetence( competenceId ) {
console.log(competenceId)
let competence = this.data.items.get( competenceId);
let competence = this.items.get( competenceId);
if ( competence) {
competence = duplicate(competence)
let msgData = {
@@ -352,7 +352,7 @@ export class VadentisActor extends Actor {
title: `Compétence ${competence.name}`
}
let statValue = competence.data.base + competence.data.malus + competence.data.bonus;
let statValue = competence.system.base + competence.system.malus + competence.system.bonus;
let formulaFull = this.buildTexteFormula( competence.data );
let myRoll = await VadentisUtility.processRoll("1d20+"+statValue, msgData.rollMode );
msgData.msg = `${formulaFull} => <strong>${myRoll.total}</strong>`;
@@ -410,74 +410,74 @@ export class VadentisActor extends Actor {
/* -------------------------------------------- */
async rollCombat( combatName ) {
let stat = this.data.data.combat[combatName];
let stat = this.system.combat[combatName];
this.genericRoll( stat, combatName );
}
/* -------------------------------------------- */
rollMagie( magieName ) {
let stat = this.data.data.magie[magieName];
let stat = this.system.magie[magieName];
this.genericRoll( stat, magieName );
}
/* -------------------------------------------- */
async incrementeArgent( arme ) {
let monnaie = this.data.items.find( item => item.type == 'monnaie' && item.name == arme.name);
let monnaie = this.items.find( item => item.type == 'monnaie' && item.name == arme.name);
if (monnaie) {
monnaie = duplicate(monnaie)
let newValeur = monnaie.data.nombre + 1;
await this.updateEmbeddedDocuments( 'Item', [{ _id: monnaie._id, 'data.nombre': newValeur }] );
let newValeur = monnaie.system.nombre + 1;
await this.updateEmbeddedDocuments( 'Item', [{ _id: monnaie._id, 'system.nombre': newValeur }] );
}
}
/* -------------------------------------------- */
async decrementeArgent( arme ) {
let monnaie = this.data.items.find( item => item.type == 'monnaie' && item.name == arme.name);
let monnaie = this.items.find( item => item.type == 'monnaie' && item.name == arme.name);
if (monnaie) {
monnaie = duplicate(monnaie)
let newValeur = monnaie.data.nombre - 1;
let newValeur = monnaie.system.nombre - 1;
newValeur = (newValeur <= 0) ? 0 : newValeur;
await this.updateEmbeddedDocuments( "Item", [{ _id: monnaie._id, 'data.nombre': newValeur }] );
await this.updateEmbeddedDocuments( "Item", [{ _id: monnaie._id, 'system.nombre': newValeur }] );
}
}
/* -------------------------------------------- */
async incrementeMunition( arme ) {
let armeTir = this.data.items.find( item => item.type == 'tir' && item.name == arme.name);
let armeTir = this.items.find( item => item.type == 'tir' && item.name == arme.name);
if (armeTir) {
armeTir = duplicate(armeTir)
let newMunition = armeTir.data.munition + 1;
await this.updateEmbeddedDocuments( "Item", [{ _id: armeTir._id, 'data.munition': newMunition }] );
let newMunition = armeTir.system.munition + 1;
await this.updateEmbeddedDocuments( "Item", [{ _id: armeTir._id, 'system.munition': newMunition }] );
}
}
/* -------------------------------------------- */
async decrementeMunition( arme ) {
let armeTir = this.data.items.find( item => item.type == 'tir' && item.name == arme.name);
let armeTir = this.items.find( item => item.type == 'tir' && item.name == arme.name);
if (armeTir) {
armeTir = duplicate(armeTir)
let newMunition = armeTir.data.munition - 1;
let newMunition = armeTir.system.munition - 1;
newMunition = (newMunition <= 0) ? 0 : newMunition;
await this.updateEmbeddedDocuments( "Item", [{ _id: armeTir._id, 'data.munition': newMunition } ]);
await this.updateEmbeddedDocuments( "Item", [{ _id: armeTir._id, 'system.munition': newMunition } ]);
}
}
/* -------------------------------------------- */
async incrementeQuantite( objet ) {
let objetQ = this.data.items.find( item => item._id == objet._id );
let objetQ = this.items.find( item => item._id == objet._id );
if (objetQ) {
objetQ = duplicate(objetQ)
let newQ = objetQ.data.quantite + 1;
await this.updateEmbeddedDocuments( "Item", [{ _id: objetQ._id, 'data.quantite': newQ } ] );
let newQ = objetQ.system.quantite + 1;
await this.updateEmbeddedDocuments( "Item", [{ _id: objetQ._id, 'system.quantite': newQ } ] );
}
}
/* -------------------------------------------- */
async decrementeQuantite( objet ) {
let objetQ = this.data.items.find( item => item._id == objet._id );
let objetQ = this.items.find( item => item._id == objet._id );
if (objetQ) {
objetQ = duplicate(objetQ)
let newQ = objetQ.data.quantite - 1;
let newQ = objetQ.system.quantite - 1;
newQ = (newQ <= 0) ? 0 : newQ;
await this.updateEmbeddedDocuments( "Item", [{ _id: objetQ._id, 'data.quantite': newQ } ]);
await this.updateEmbeddedDocuments( "Item", [{ _id: objetQ._id, 'system.quantite': newQ } ]);
}
}
@@ -486,10 +486,10 @@ export class VadentisActor extends Actor {
let target = VadentisUtility.getTarget();
if ( target ) {
let arme = this.data.items.find( item => (item.type == 'armecc' || item.type == 'tir') && item.id == armeId);
let arme = this.items.find( item => (item.type == 'armecc' || item.type == 'tir') && item.id == armeId);
if (arme) {
arme = duplicate(arme)
if ( arme.type == 'tir' && arme.data.munition <= 0 ) {
if ( arme.type == 'tir' && arme.system.munition <= 0 ) {
ui.notifications.warn("Vous n'avez plus de munitions avec cette arme.");
return;
}