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

@@ -13,7 +13,7 @@ export class VadentisActorSheet extends ActorSheet {
return mergeObject(super.defaultOptions, {
classes: ["vadentis", "sheet", "actor"],
template: "systems/foundryvtt-vadentis/templates/actor-sheet.html",
width: 640,
width: 680,
height: 720,
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "stats" }],
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: null }],
@@ -22,19 +22,17 @@ export class VadentisActorSheet extends ActorSheet {
}
/* -------------------------------------------- */
getData() {
async getData() {
this.actor.calculerSommeStats();
const objectData = VadentisUtility.data(this.object);
let actorData = duplicate(VadentisUtility.templateData(this.object));
let formData = {
let actorData = foundry.utils.duplicate(this.object.system);
let formData = {
title: this.title,
id: objectData.id,
type: objectData.type,
img: objectData.img,
name: objectData.name,
id: this.object.id,
type: this.object.type,
img: this.object.img,
name: this.object.name,
editable: this.isEditable,
cssClass: this.isEditable ? "editable" : "locked",
data: actorData,
@@ -43,28 +41,31 @@ export class VadentisActorSheet extends ActorSheet {
options: this.options,
owner: this.document.isOwner,
editScore: this.options.editScore,
isGM: game.user.isGM
isGM: game.user.isGM,
history: await TextEditor.enrichHTML(this.object.system.history, { async: true }),
notes: await TextEditor.enrichHTML(this.object.system.notes, { async: true }),
gmnotes: await TextEditor.enrichHTML(this.object.system.gmnotes, { async: true }),
}
formData.editScore = this.options.editScore;
formData.donnees = this.actor.getDonnees();
formData.eglises = this.actor.getEglises();
formData.editScore = this.options.editScore;
formData.donnees = this.actor.getDonnees();
formData.eglises = this.actor.getEglises();
formData.competences = this.actor.getCompetences();
formData.sorts = this.actor.getSorts();
formData.devotions = this.actor.getDevotions();
formData.attributs = this.actor.getAttributs();
formData.techniques = this.actor.getTechniques();
formData.armes = this.actor.getArmes();
formData.armures = this.actor.getArmures();
formData.sorts = this.actor.getSorts();
formData.devotions = this.actor.getDevotions();
formData.attributs = this.actor.getAttributs();
formData.techniques = this.actor.getTechniques();
formData.armes = this.actor.getArmes();
formData.armures = this.actor.getArmures();
formData.equipements = this.actor.getEquipements();
formData.monnaies = this.actor.getMonnaies();
formData.optionsBase = VadentisUtility.createDirectOptionList(0, 50);
formData.monnaies = this.actor.getMonnaies();
formData.optionsBase = VadentisUtility.createDirectOptionList(0, 50);
formData.optionsMalus = VadentisUtility.createDirectReverseOptionList(-50, 0);
formData.optionsBonus = VadentisUtility.createDirectOptionList(0, 50);
formData.optionsPV = VadentisUtility.createOptionList(-50, 200);
formData.optionsPE = VadentisUtility.createOptionList(-50, 200);
formData.optionsPA = VadentisUtility.createOptionList(0, 20);
formData.optionsPV = VadentisUtility.createDirectIntegerOptionList(-50, 999);
formData.optionsPE = VadentisUtility.createOptionList(-50, 999);
formData.optionsPA = VadentisUtility.createOptionList(0, 20);
return formData;
@@ -73,13 +74,25 @@ export class VadentisActorSheet extends ActorSheet {
/* -------------------------------------------- */
async checkSort(sortId) {
await Dialog.confirm({
title: "Lancer un sort",
content: "Etes vous certain de vouloir incanter ce sort ?",
title: "Lancer un Sort",
content: "Etes vous certain de vouloir incanter ce Sort ?",
yes: async () => {
this.actor.rollSort(sortId);
},
no: () => {},
});
no: () => { },
});
}
/* -------------------------------------------- */
async checkDevotion(devotionId) {
await Dialog.confirm({
title: "Lancer une Dévotion",
content: "Etes vous certain de vouloir incanter cette Dévotion ?",
yes: async () => {
this.actor.rollDevotion(devotionId);
},
no: () => { },
});
}
/* -------------------------------------------- */
@@ -91,7 +104,7 @@ export class VadentisActorSheet extends ActorSheet {
console.log("Technique ", techniqueId)
this.actor.rollTechnique(techniqueId);
},
no: () => {},
no: () => { },
});
}
@@ -114,38 +127,38 @@ export class VadentisActorSheet extends ActorSheet {
const li = $(ev.currentTarget).parents(".item");
VadentisUtility.confirmDelete(this, li);
});
html.find('.munition-moins').click(event => {
const li = $(event.currentTarget).parents(".item");
const item = this.actor.items.get(li.data("item-id"));
this.actor.decrementeMunition( item );
} );
this.actor.decrementeMunition(item);
});
html.find('.munition-plus').click(event => {
const li = $(event.currentTarget).parents(".item");
const item = this.actor.items.get(li.data("item-id"));
this.actor.incrementeMunition( item );
} );
this.actor.incrementeMunition(item);
});
html.find('.equipement-moins').click(event => {
const li = $(event.currentTarget).parents(".item");
const item = this.actor.items.get(li.data("item-id"));
this.actor.decrementeQuantite( item );
} );
this.actor.decrementeQuantite(item);
});
html.find('.equipement-plus').click(event => {
const li = $(event.currentTarget).parents(".item");
const item = this.actor.items.get(li.data("item-id"));
this.actor.incrementeQuantite( item );
} );
this.actor.incrementeQuantite(item);
});
html.find('.argent-moins').click(event => {
const li = $(event.currentTarget).parents(".item");
const item = this.actor.items.get(li.data("item-id"));
this.actor.decrementeArgent( item );
} );
this.actor.decrementeArgent(item);
});
html.find('.argent-plus').click(event => {
const li = $(event.currentTarget).parents(".item");
const item = this.actor.items.get(li.data("item-id"));
this.actor.incrementeArgent( item );
} );
this.actor.incrementeArgent(item);
});
html.find('.combat-label a').click((event) => {
let combatName = event.currentTarget.attributes.name.value;
@@ -169,17 +182,17 @@ export class VadentisActorSheet extends ActorSheet {
const li = $(event.currentTarget).parents(".item");
const sortId = li.data("item-id");
this.checkSort(sortId);
});
});
html.find('.arme-label a').click((event) => {
const li = $(event.currentTarget).parents(".item");
const armeId = li.data("item-id");
this.actor.rollArme(armeId);
});
});
html.find('.devotion-label a').click((event) => {
const li = $(event.currentTarget).parents(".item");
const devotionId = li.data("item-id");
this.actor.rollDevotion(devotionId);
});
this.checkDevotion(devotionId);
});
html.find('.weapon-label a').click((event) => {
const li = $(event.currentTarget).parents(".item");
const weapon = this.actor.items.get(li.data("item-id"));
@@ -205,7 +218,7 @@ export class VadentisActorSheet extends ActorSheet {
const weapon = this.actor.items.get(li.data("item-id"));
this.actor.rollSortDevotionDamage(weapon, 'damagecritical');
});
html.find('.competence-base').change((event) => {
let skillName = event.currentTarget.attributes.skillname.value;
this.actor.updateCompetence(skillName, "base", parseInt(event.target.value));
@@ -221,15 +234,15 @@ export class VadentisActorSheet extends ActorSheet {
html.find('.lock-unlock-sheet').click((event) => {
this.options.editScore = !this.options.editScore;
this.render(true);
});
});
html.find('.item-link a').click((event) => {
const itemId = $(event.currentTarget).data("item-id");
const item = this.actor.items.get(itemId);
item.sheet.render(true);
});
});
html.find('.item-equip').click(ev => {
const li = $(ev.currentTarget).parents(".item");
this.actor.equiperObject( li.data("item-id") );
this.actor.equiperObject(li.data("item-id"));
this.render(true);
});

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;
}

View File

@@ -8,7 +8,7 @@ export class VadentisCombat extends Combat {
console.log("Initiative is requested !!!");
ids = typeof ids === "string" ? [ids] : ids;
const currentId = this.combatant._id;
//const currentId = this.combatant.id;
for (let cId = 0; cId < ids.length; cId++) {
const c = this.combatants.get(ids[cId]);
let initBonus = c.actor ? c.actor.getInitiativeScore() : 0;

View File

@@ -22,24 +22,24 @@ export class VadentisTokenHud {
let token = canvas.tokens.get(tokenId);
let actor = token.actor;
let combatant = game.combat.data.combatants.find(c => c.tokenId == token.data._id);
//let combatant = game.combat.combatants.find(c => c.tokenId == token._id);
app.hasExtension = true;
let armesList = combatant.actor.getArmes() ;
let sortsList = combatant.actor.getSorts().concat( combatant.actor.getDevotions() );
const hudData = { combatant: combatant, armes: armesList, sorts: sortsList }
let armesList = actor.getArmes() ;
let sortsList = actor.getSorts().concat( actor.getDevotions() );
const hudData = { actor: actor, armes: armesList, sorts: sortsList }
// sort
await VadentisTokenHud._configureSubMenu(html.find('.control-icon.combat'), 'systems/foundryvtt-vadentis/templates/hud-actor-sort.html', hudData,
await VadentisTokenHud._configureSubMenu(html.find('.control-icon[data-action=combat]'), 'systems/foundryvtt-vadentis/templates/hud-actor-sort.html', hudData,
(event) => {
let combatantId = event.currentTarget.attributes['data-combatant-id'].value;
const combatant = game.combat.getCombatant(combatantId);
let actorId = event.currentTarget.attributes['data-actor-id'].value;
const actor = game.actors.get(actorId);
let sortId = event.currentTarget.attributes['data-sort-id'].value;
combatant.actor.rollSortOuDevotion( sortId );
actor.rollSortOuDevotion( sortId );
});
// combat
await VadentisTokenHud._configureSubMenu(html.find('.control-icon.target'), 'systems/foundryvtt-vadentis/templates/hud-actor-attaque.html', hudData,
await VadentisTokenHud._configureSubMenu(html.find('.control-icon[data-action=target]'), 'systems/foundryvtt-vadentis/templates/hud-actor-attaque.html', hudData,
(event) => {
let armeId = event.currentTarget.attributes['data-arme-id'].value;
actor.rollArme(armeId);
@@ -49,7 +49,7 @@ export class VadentisTokenHud {
/* -------------------------------------------- */
static async addTokenHudExtensions(app, html, tokenId) {
html.find('.control-icon.combat').click(event => {
html.find('.control-icon[data-action=combat]').click(event => {
if ( event.currentTarget.className.includes('active')) {
VadentisTokenHud.removeExtensionHud( app, html, tokenId);
} else {
@@ -57,9 +57,9 @@ export class VadentisTokenHud {
}
} );
let combatIcon = html.find('.control-icon.combat');
let combatIcon = html.find('.control-icon[data-action=combat]');
//console.log("COMBAT ICON", combatIcon)
if ( combatIcon[0] && combatIcon[0].className.includes('active') ) {
if ( combatIcon[0]?.className.includes('active') ) {
VadentisTokenHud.addExtensionHud( app, html, tokenId);
}
}

View File

@@ -43,27 +43,38 @@ export class VadentisItemSheet extends ItemSheet {
/* -------------------------------------------- */
async getData() {
const objectData = VadentisUtility.data(this.object);
let itemData = foundry.utils.deepClone(VadentisUtility.templateData(this.object));
let itemData = foundry.utils.deepClone(this.object.system);
let formData = {
title: this.title,
id: this.id,
type: objectData.type,
img: objectData.img,
name: objectData.name,
type: this.object.type,
img: this.object.img,
name: this.object.name,
editable: this.isEditable,
cssClass: this.isEditable ? "editable" : "locked",
data: itemData,
limited: this.object.limited,
options: this.options,
owner: this.document.isOwner,
isGM: game.user.isGM
isGM: game.user.isGM,
}
if (objectData.type == 'sort') {
if (itemData.description) {
formData.description = await TextEditor.enrichHTML(this.object.system.description, { async: true })
}
if (itemData.notes) {
formData.notes = await TextEditor.enrichHTML(this.object.system.notes, { async: true })
}
if (itemData.effect) {
formData.effect = await TextEditor.enrichHTML(this.object.system.effect, { async: true })
}
if (itemData.criticaleffect) {
formData.criticaleffect = await TextEditor.enrichHTML(this.object.system.criticaleffect, { async: true })
}
if (this.object.type == 'sort') {
formData.donnees = await VadentisUtility.getDonnees();
}
if (objectData.type == 'devotion') {
if (this.object.type == 'devotion') {
formData.eglises = await VadentisUtility.getEglises();
}

View File

@@ -19,9 +19,9 @@ export class VadentisUtility {
/* -------------------------------------------- */
static updateCombat( combat, round, diff, id ) {
if (game.user.isGM && combat.data.round != 0 && combat.turns && combat.data.active) {
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.data.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);
@@ -46,6 +46,14 @@ export class VadentisUtility {
return options;
}
/* -------------------------------------------- */
static createDirectIntegerOptionList( min, max) {
let options = {};
for(let i=min; i<=max; i++) {
options[i] = `${i}`;
}
return options;
}
/* -------------------------------------------- */
static createDirectReverseOptionList( min, max) {
let options = {};
for(let i=max; i>=min; i--) {
@@ -64,19 +72,6 @@ export class VadentisUtility {
return undefined;
}
/* -------------------------------------------- */
static templateData(it) {
return VadentisUtility.data(it)?.data ?? {}
}
/* -------------------------------------------- */
static data(it) {
if (it instanceof Actor || it instanceof Item || it instanceof Combatant) {
return it.data;
}
return it;
}
/* -------------------------------------------- */
static processDamageString( formula, actor ) {
let workFormula = formula.toLowerCase();
@@ -90,7 +85,7 @@ export class VadentisUtility {
static async processRoll( formula, rollMode ) {
let myRoll = new Roll(formula);
myRoll.roll( { async: false} );
if (game.modules.get("dice-so-nice") && game.modules.get("dice-so-nice").active) {
if (game.modules.get("dice-so-nice")?.active) {
await game.dice3d.showForRoll(myRoll, game.user, true);
}
return myRoll;
@@ -117,17 +112,17 @@ export class VadentisUtility {
}
let formulaTouche = "1d20+"+attaque;
let formulaFull = attacker.buildTexteFormula( attacker.data.data.combat.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.data.damage}`;
let formula = combatData.arme.data.damage.toLowerCase();
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.data.valuecritical ) {
degats = `critiques : ${combatData.arme.data.criticaldamage}`;
formula = combatData.arme.data.criticaldamage.toLowerCase();
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'