Merge branch 'stabilisation-v1.2' into 'v1.2'

Stabilisation v1.2

See merge request LeRatierBretonnien/foundryvtt-reve-de-dragon!122
This commit is contained in:
Leratier Bretonnien 2021-01-21 07:28:27 +00:00
commit 2a8602d23a
7 changed files with 124 additions and 60 deletions

View File

@ -41,7 +41,7 @@ export class RdDActorSheet extends ActorSheet {
data.itemsByType = RdDItem.buildItemsClassification(data.items); data.itemsByType = RdDItem.buildItemsClassification(data.items);
// Competence per category // Competence per category
let competenceXPTotal = 0; data.data.competenceXPTotal = 0;
data.competenceByCategory = RdDItem.classify( data.competenceByCategory = RdDItem.classify(
data.itemsByType.competence, data.itemsByType.competence,
item => item.data.categorie, item => item.data.categorie,
@ -51,11 +51,10 @@ export class RdDActorSheet extends ActorSheet {
//this.actor.checkCompetenceXP(item.name); // Petite vérification experience //this.actor.checkCompetenceXP(item.name); // Petite vérification experience
item.data.showCompetence = !data.data.showCompNiveauBase || (Number(item.data.niveau) != Number(RdDUtility.getLevelCategory(item.data.categorie))); item.data.showCompetence = !data.data.showCompNiveauBase || (Number(item.data.niveau) != Number(RdDUtility.getLevelCategory(item.data.categorie)));
// Ignorer les compétences 'troncs' à ce stade // Ignorer les compétences 'troncs' à ce stade
competenceXPTotal += RdDItemCompetence.isTronc(item.name) ? 0 : RdDItemCompetence.computeCompetenceXPCost(item); data.data.competenceXPTotal += RdDItemCompetence.computeCompetenceXPCost(item);
return item; return item;
}); });
competenceXPTotal += RdDItemCompetence.computeCompetenceTroncXP(data.itemsByType.competence); data.data.competenceXPTotal -= RdDItemCompetence.computeEconomieCompetenceTroncXP(data.itemsByType.competence);
data.data.competenceXPTotal = competenceXPTotal;
// Compute current carac sum // Compute current carac sum
let sum = 0; let sum = 0;

View File

@ -2111,8 +2111,10 @@ export class RdDActor extends Actor {
} }
} }
if (mode != 'visu') {
// Notification au MJ // Notification au MJ
ChatMessage.create({ content: this.name + " est monté dans les TMR en mode : " + mode, whisper: ChatMessage.getWhisperRecipients("GM") }); ChatMessage.create({ content: this.name + " est monté dans les TMR en mode : " + mode, whisper: ChatMessage.getWhisperRecipients("GM") });
}
let data = { let data = {
fatigue: { fatigue: {

View File

@ -3,6 +3,20 @@ const competenceTroncs = [["Esquive", "Dague", "Corps à corps"],
["Epée à 1 main", "Epée à 2 mains", "Hache à 1 main", "Hache à 2 mains", "Lance", "Masse à 1 main", "Masse à 2 mains"]]; ["Epée à 1 main", "Epée à 2 mains", "Hache à 1 main", "Hache à 2 mains", "Lance", "Masse à 1 main", "Masse à 2 mains"]];
const competence_xp_par_niveau = [5, 5, 5, 10, 10, 10, 10, 15, 15, 15, 15, 20, 20, 20, 20, 30, 30, 40, 40, 60, 60, 100, 100, 100, 100, 100, 100, 100, 100, 100]; const competence_xp_par_niveau = [5, 5, 5, 10, 10, 10, 10, 15, 15, 15, 15, 20, 20, 20, 20, 30, 30, 40, 40, 60, 60, 100, 100, 100, 100, 100, 100, 100, 100, 100];
const competence_niveau_max = competence_xp_par_niveau.length - 10;
function _buildCumulXP() {
let cumulXP = { "-11": 0 };
let cumul = 0;
for (let i = 0; i <= competence_xp_par_niveau.length; i++) {
let level = i - 10;
cumul += competence_xp_par_niveau[i];
cumulXP[level] = cumul;
}
return cumulXP;
}
const competence_xp_cumul = _buildCumulXP();
export class RdDItemCompetence extends Item { export class RdDItemCompetence extends Item {
@ -43,44 +57,25 @@ export class RdDItemCompetence extends Item {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static computeCompetenceXPCost(competence) { static computeCompetenceXPCost(competence) {
let minLevel = competence.data.base; let xp = RdDItemCompetence.getDeltaXp(competence.data.base, competence.data.niveau ?? competence.data.base);
if (minLevel == competence.data.niveau) return 0; xp += competence.data.xp ?? 0;
if (competence.data.niveau < -10) return 0; xp += competence.data.xp_sort ?? 0;
let xp = 0;
for (let i = minLevel + 1; i <= competence.data.niveau; i++) {
xp += competence_xp_par_niveau[i + 10];
//console.log(i, i+10, competence_xp_par_niveau[i+10]);
}
if (competence.data.categorie == 'draconic') {
xp += competence.data.xp_sort;
}
return xp; return xp;
} }
/* -------------------------------------------- */ static computeEconomieCompetenceTroncXP(competences) {
static computeCompetenceTroncXP(competences) { let economie = 0;
let xp = 0;
for (let troncList of competenceTroncs) { for (let troncList of competenceTroncs) {
let minNiveau = 0; let list = troncList.map(name => RdDItemCompetence.findCompetence(competences, name))
for (let troncName of troncList) { .sort( (c1, c2) => c2.data.niveau - c1.data.niveau); // tri du plus haut au plus bas
let comp = RdDItemCompetence.findCompetence(competences, troncName); list.splice(0,1); // ignorer la plus élevée
if (comp) { list.forEach(c => {
minNiveau = Math.min(comp.data.niveau, minNiveau); economie += RdDItemCompetence.getDeltaXp(c.data.base, Math.min(c.data.niveau, 0) );
});
} }
return economie;
} }
minNiveau = Math.max(minNiveau, 0); // Clamp à 0, pour le tronc commun
let minNiveauXP = competence_xp_par_niveau[minNiveau + 10];
xp += minNiveauXP;
for (let troncName of troncList) {
let comp = RdDItemCompetence.findCompetence(competences, troncName);
if (comp) {
xp += competence_xp_par_niveau[comp.data.niveau + 10] - minNiveauXP;
}
}
}
return xp;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static findCompetence(list, name) { static findCompetence(list, name) {
name = name.toLowerCase(); name = name.toLowerCase();
@ -89,7 +84,24 @@ export class RdDItemCompetence extends Item {
/* -------------------------------------------- */ /* -------------------------------------------- */
static getCompetenceNextXp(niveau) { static getCompetenceNextXp(niveau) {
return competence_xp_par_niveau[niveau + 10]; return RdDItemCompetence.getCompetenceXp(niveau + 1);
}
static getCompetenceXp(niveau) {
RdDItemCompetence._valideNiveau(niveau);
return niveau < -10 ? 0 : competence_xp_par_niveau[niveau + 10];
}
static getDeltaXp(from, to) {
RdDItemCompetence._valideNiveau(from);
RdDItemCompetence._valideNiveau(to);
return competence_xp_cumul[to] - competence_xp_cumul[from];
}
static _valideNiveau(niveau){
if (niveau < -11 || niveau > competence_niveau_max) {
console.warn("Niveau en dehors des niveaux de compétences: [-11, " + competence_niveau_max + "]", niveau)
}
} }
} }

View File

@ -2,6 +2,7 @@
import { ChatUtility } from "./chat-utility.js"; import { ChatUtility } from "./chat-utility.js";
import { DeDraconique } from "./de-draconique.js"; import { DeDraconique } from "./de-draconique.js";
import { RdDItemCompetence } from "./item-competence.js";
import { Misc } from "./misc.js"; import { Misc } from "./misc.js";
import { RdDDice } from "./rdd-dice.js"; import { RdDDice } from "./rdd-dice.js";
import { RdDResolutionTable } from "./rdd-resolution-table.js"; import { RdDResolutionTable } from "./rdd-resolution-table.js";
@ -30,8 +31,21 @@ export class RdDCommands {
rddCommands.registerCommand({ path: ["/tmra"], func: (content, msg, params) => TMRUtility.getTMRAleatoire(), descr: "Tire une case aléatoire des Terres médianes" }); rddCommands.registerCommand({ path: ["/tmra"], func: (content, msg, params) => TMRUtility.getTMRAleatoire(), descr: "Tire une case aléatoire des Terres médianes" });
rddCommands.registerCommand({ rddCommands.registerCommand({
path: ["/tmrr"], func: (content, msg, params) => rddCommands.getRencontreTMR(params), path: ["/tmrr"], func: (content, msg, params) => rddCommands.getRencontreTMR(msg, params),
descr: "Syntaxe: <strong>/tmrr case jet</strong><br>Détermine quelle est la rencontre dans la case pour le jet<br>Exemple: <strong>/tmrr forêt 50</strong>" descr: "Exemple: <strong>/tmrr forêt 47</strong><br>Détermine quelle est la rencontre dans une case 'forêt' pour un jet de dé de 47"
});
rddCommands.registerCommand({
path: ["/xp", "comp"], func: (content, msg, params) => rddCommands.getCoutXpComp(msg, params),
descr: `Détermine le coût d'expérience pour augmenter une compétence. Exemples:
<br>/xp comp -6 1: pour passer de -6 à +1
<br>/xp comp +4: pour atteindre le niveau 4 (depuis +3)`
});
rddCommands.registerCommand({
path: ["/xp", "carac"], func: (content, msg, params) => rddCommands.getCoutXpCarac(msg, params),
descr: `Détermine le coût d'expérience pour augmenter une caractéristique. Exemples:
<br>/xp carac 15: coût pour atteindre 15 (depuis 14)`
}); });
rddCommands.registerCommand({ rddCommands.registerCommand({
@ -129,8 +143,9 @@ export class RdDCommands {
} }
} }
if (command && command.func) { if (command && command.func) {
if (command.func(content, msg, params) === false) { const result = command.func(content, msg, params);
this._displayHelp(msg, `${path}: ${command.descr}`); if (result == false) {
RdDCommands._chatAnswer(msg, command.descr);
} }
return true; return true;
} }
@ -142,8 +157,13 @@ export class RdDCommands {
let list = [] let list = []
this._buildSubTableHelp(list, table || this.commandsTable); this._buildSubTableHelp(list, table || this.commandsTable);
const messageAide = list.reduce((a, b) => a + '</li><li class="list-item">' + b); const messageAide = list.reduce((a, b) => a + '</li><li class="list-item">' + b);
RdDCommands._chatAnswer(msg, `Commandes disponibles<ul class="alterne-list"><li class="list-item">${messageAide}</li></ul>`);
}
/* -------------------------------------------- */
static _chatAnswer(msg, content) {
msg.whisper = [game.user._id]; msg.whisper = [game.user._id];
msg.content = `Commandes disponibles<ul class="alterne-list"><li class="list-item">${messageAide}</li></ul>`; msg.content = content;
ChatMessage.create(msg); ChatMessage.create(msg);
} }
@ -161,7 +181,7 @@ export class RdDCommands {
return list.sort(); return list.sort();
} }
/* -------------------------------------------- */
getRencontreTMR(params) { getRencontreTMR(params) {
if (params.length == 2) { if (params.length == 2) {
return TMRUtility.getRencontre(params[0], params[1]) return TMRUtility.getRencontre(params[0], params[1])
@ -171,6 +191,7 @@ export class RdDCommands {
} }
} }
/* -------------------------------------------- */
async rollRdd(msg, params) { async rollRdd(msg, params) {
if (params.length == 0) { if (params.length == 0) {
RdDRollResolutionTable.open(); RdDRollResolutionTable.open();
@ -188,6 +209,7 @@ export class RdDCommands {
} }
} }
/* -------------------------------------------- */
async rollRdDNumeric(msg, carac, diff, significative = false) { async rollRdDNumeric(msg, carac, diff, significative = false) {
let rollData = { let rollData = {
caracValue: carac, caracValue: carac,
@ -197,15 +219,38 @@ export class RdDCommands {
show: { title: "Table de résolution" } show: { title: "Table de résolution" }
}; };
await RdDResolutionTable.rollData(rollData); await RdDResolutionTable.rollData(rollData);
msg.content = await RdDResolutionTable.buildRollDataHtml(rollData); RdDCommands._chatAnswer(msg, await RdDResolutionTable.buildRollDataHtml(rollData));
ChatUtility.createChatWithRollMode(game.user.name, msg);
} }
/* -------------------------------------------- */
async rollDeDraconique(msg) { async rollDeDraconique(msg) {
let ddr = new DeDraconique().evaluate(); let ddr = new DeDraconique().evaluate();
await RdDDice.show(ddr, rollMode); await RdDDice.show(ddr, rollMode);
msg.content = `Lancer d'un Dé draconique: ${ddr.total}`; RdDCommands._chatAnswer(msg, `Lancer d'un Dé draconique: ${ddr.total}`);
ChatUtility.createChatWithRollMode(game.user.name, msg); }
/* -------------------------------------------- */
getCoutXpComp(msg, params) {
if (params && (params.length == 1 || params.length == 2)) {
let to = params.length == 1 ? Number(params[0]) : Number(params[1]);
let from = params.length == 1 ? to - 1 : Number(params[0]);
RdDCommands._chatAnswer(msg, `Coût pour passer une compétence de ${from} à ${to}: ${RdDItemCompetence.getDeltaXp(from, to)}`);
}
else {
return false;
} }
} }
/* -------------------------------------------- */
getCoutXpCarac(msg, params) {
if (params && params.length == 1) {
let to = Number(params[0]);
RdDCommands._chatAnswer(msg, `Coût pour passer une caractéristique de ${to - 1} à ${to}: ${RdDUtility.getCaractXp(to)}`);
}
else {
return false;
}
}
}

View File

@ -61,8 +61,9 @@ export class RdDTMRDialog extends Dialog {
this.actor.santeIncDec("fatigue", this.nbFatigue).then(super.close()); // moving 1 cell costs 1 fatigue this.actor.santeIncDec("fatigue", this.nbFatigue).then(super.close()); // moving 1 cell costs 1 fatigue
this.actor.tmrApp = undefined; // Cleanup reference this.actor.tmrApp = undefined; // Cleanup reference
this.actor.setStatusDemiReve(false); this.actor.setStatusDemiReve(false);
if (! this.viewOnly) {
this._tellToGM(this.actor.name + " a quitté les terres médianes") this._tellToGM(this.actor.name + " a quitté les terres médianes");
}
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -405,8 +405,13 @@ export class RdDUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static getCaracNextXp(value) { static getCaracNextXp(value) {
const nextValue = Number(value) + 1;
// xp est le coût pour atteindre cette valeur, on regarde donc le coût de la valeur+1 // xp est le coût pour atteindre cette valeur, on regarde donc le coût de la valeur+1
return tableCaracDerivee[Number(value)+1].xp; return RdDUtility.getCaractXp(nextValue);
}
static getCaractXp(targetValue) {
return tableCaracDerivee[targetValue].xp;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -352,7 +352,7 @@
<span class="competence-label"><a>{{comp.name}}</a></span> <span class="competence-label"><a>{{comp.name}}</a></span>
{{/if}} {{/if}}
<input class="competence-value" type="text" compname="{{comp.name}}" value="{{numberFormat comp.data.niveau decimals=0 sign=true}}" data-dtype="number" {{#unless @root.data.editCaracComp}}disabled{{/unless}}/> <input class="competence-value" type="text" compname="{{comp.name}}" value="{{numberFormat comp.data.niveau decimals=0 sign=true}}" data-dtype="number" {{#unless @root.data.editCaracComp}}disabled{{/unless}}/>
<input class="competence-xp" type="text" name="data.competenceByCategory.melee[{{key}}].data.xp" compname="{{comp.name}}" value="{{comp.data.xp}}" data-dtype="number" {{#unless @root.data.editCaracComp}}disabled{{/unless}}/> <input class="competence-xp" type="text" compname="{{comp.name}}" value="{{comp.data.xp}}" data-dtype="number" {{#unless @root.data.editCaracComp}}disabled{{/unless}}/>
<div class="item-controls"> <div class="item-controls">
<a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a> <a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a>
<a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a> <a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
@ -387,7 +387,7 @@
<span class="competence-label"><a>{{comp.name}}</a></span> <span class="competence-label"><a>{{comp.name}}</a></span>
{{/if}} {{/if}}
<input class="competence-value" type="text" compname="{{comp.name}}" value="{{numberFormat comp.data.niveau decimals=0 sign=true}}" data-dtype="number" {{#unless @root.data.editCaracComp}}disabled{{/unless}}/> <input class="competence-value" type="text" compname="{{comp.name}}" value="{{numberFormat comp.data.niveau decimals=0 sign=true}}" data-dtype="number" {{#unless @root.data.editCaracComp}}disabled{{/unless}}/>
<input class="competence-xp" type="text" name="data.competenceByCategory.tir[{{key}}].data.xp" compname="{{comp.name}}" value="{{comp.data.xp}}" data-dtype="number" {{#unless @root.data.editCaracComp}}disabled{{/unless}}/> <input class="competence-xp" type="text" compname="{{comp.name}}" value="{{comp.data.xp}}" data-dtype="number" {{#unless @root.data.editCaracComp}}disabled{{/unless}}/>
<div class="item-controls"> <div class="item-controls">
<a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a> <a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a>
<a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a> <a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
@ -422,7 +422,7 @@
<span class="competence-label"><a>{{comp.name}}</a></span> <span class="competence-label"><a>{{comp.name}}</a></span>
{{/if}} {{/if}}
<input class="competence-value" type="text" compname="{{comp.name}}" value="{{numberFormat comp.data.niveau decimals=0 sign=true}}" data-dtype="number"{{#unless @root.data.editCaracComp}}disabled{{/unless}}/> <input class="competence-value" type="text" compname="{{comp.name}}" value="{{numberFormat comp.data.niveau decimals=0 sign=true}}" data-dtype="number"{{#unless @root.data.editCaracComp}}disabled{{/unless}}/>
<input class="competence-xp" type="text" name="data.competenceByCategory.lancer[{{key}}].data.xp" compname="{{comp.name}}" value="{{comp.data.xp}}" data-dtype="number" {{#unless @root.data.editCaracComp}}disabled{{/unless}}/> <input class="competence-xp" type="text" compname="{{comp.name}}" value="{{comp.data.xp}}" data-dtype="number" {{#unless @root.data.editCaracComp}}disabled{{/unless}}/>
<div class="item-controls"> <div class="item-controls">
<a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a> <a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a>
<a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a> <a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
@ -457,7 +457,7 @@
<span class="competence-label"><a>{{comp.name}}</a></span> <span class="competence-label"><a>{{comp.name}}</a></span>
{{/if}} {{/if}}
<input class="competence-value" type="text" compname="{{comp.name}}" value="{{numberFormat comp.data.niveau decimals=0 sign=true}}" data-dtype="number" {{#unless @root.data.editCaracComp}}disabled{{/unless}}/> <input class="competence-value" type="text" compname="{{comp.name}}" value="{{numberFormat comp.data.niveau decimals=0 sign=true}}" data-dtype="number" {{#unless @root.data.editCaracComp}}disabled{{/unless}}/>
<input class="competence-xp" type="text" name="data.competenceByCategory.connaissance[{{key}}].data.xp" compname="{{comp.name}}" value="{{comp.data.xp}}" data-dtype="number" {{#unless @root.data.editCaracComp}}disabled{{/unless}}/> <input class="competence-xp" type="text" compname="{{comp.name}}" value="{{comp.data.xp}}" data-dtype="number" {{#unless @root.data.editCaracComp}}disabled{{/unless}}/>
<div class="item-controls"> <div class="item-controls">
<a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a> <a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a>
<a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a> <a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
@ -492,8 +492,8 @@
<span class="competence-label"><a>{{comp.name}}</a></span> <span class="competence-label"><a>{{comp.name}}</a></span>
{{/if}} {{/if}}
<input class="competence-value" type="text" compname="{{comp.name}}" value="{{numberFormat comp.data.niveau decimals=0 sign=true}}" data-dtype="number" {{#unless @root.data.editCaracComp}}disabled{{/unless}}/> <input class="competence-value" type="text" compname="{{comp.name}}" value="{{numberFormat comp.data.niveau decimals=0 sign=true}}" data-dtype="number" {{#unless @root.data.editCaracComp}}disabled{{/unless}}/>
<input class="competence-xp" type="text" name="data.competenceByCategory.draconic[{{key}}].data.xp" compname="{{comp.name}}" value="{{comp.data.xp}}" data-dtype="number" {{#unless @root.data.editCaracComp}}disabled{{/unless}}/> <input class="competence-xp" type="text" compname="{{comp.name}}" value="{{comp.data.xp}}" data-dtype="number" {{#unless @root.data.editCaracComp}}disabled{{/unless}}/>
<input class="competence-xp-sort" type="text" name="data.competenceByCategory.draconic[{{key}}].data.xp_sort" compname="{{comp.name}}" value="{{comp.data.xp_sort}}" data-dtype="number" {{#unless @root.data.editCaracComp}}disabled{{/unless}}/> <input class="competence-xp-sort" type="text" compname="{{comp.name}}" value="{{comp.data.xp_sort}}" data-dtype="number" {{#unless @root.data.editCaracComp}}disabled{{/unless}}/>
<div class="item-controls"> <div class="item-controls">
<a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a> <a class="item-control item-edit" title="Edit Item"><i class="fas fa-edit"></i></a>
<a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a> <a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>