Initial import

This commit is contained in:
2021-12-02 20:18:21 +01:00
parent 522cad2ff8
commit b3f0af8c12
14 changed files with 201 additions and 286 deletions

View File

@ -1,4 +1,5 @@
/* -------------------------------------------- */
const __level2Dice = [ "d0", "d4", "d6", "d8", "d10", "d12" ];
/* -------------------------------------------- */
export class PegasusUtility {
@ -9,6 +10,10 @@ export class PegasusUtility {
Hooks.on('renderChatLog', (log, html, data) => PegasusUtility.chatListeners(html));
this.rollDataStore = {}
this.defenderStore = {}
this.diceList = [];
this.diceFoundryList = [];
this.optionsDiceList = "";
this.buildDiceLists();
}
/* -------------------------------------------- */
static getSpecs( ) {
@ -21,6 +26,47 @@ export class PegasusUtility {
this.specs = specs.map(i => i.toObject());
}
/* -------------------------------------------- */
static buildDiceLists() {
let maxLevel = game.settings.get("fvtt-pegasus-rpg", "dice-max-level");
let diceList = [ "0" ];
let diceFoundryList = [ "d0" ];
let diceLevel = 1;
let concat = "";
let concatFoundry = "";
let optionsDiceList = '<option value="0">0</option>';
let optionsLevel = '<option value="0">0</option>';
for(let i=1; i<=maxLevel;i++) {
let currentDices = concat + __level2Dice[diceLevel];
diceList.push( currentDices );
diceFoundryList.push( concatFoundry + __level2Dice[diceLevel] + "x" );
if ( __level2Dice[diceLevel] == "d12") {
concat = concat + "d12 ";
concatFoundry = concatFoundry + "d12x, ";
diceLevel = 1;
} else {
diceLevel++;
}
optionsDiceList += `<option value="${i}">${currentDices}</option>`;
optionsLevel += `<option value="${i}">${i}</option>`;
}
this.diceList = diceList;
this.diceFoundryList = diceFoundryList;
this.optionsDiceList = optionsDiceList;
this.optionsLevel = optionsLevel;
console.log("Defautl dice List", diceList, diceFoundryList);
}
/* -------------------------------------------- */
static getOptionsDiceList() {
return this.optionsDiceList;
}
/* -------------------------------------------- */
static getOptionsLevel() {
return this.optionsLevel;
}
/* -------------------------------------------- */
static computeAttackDefense(defenseRollId) {
let defenseRollData = this.getRollData(defenseRollId );
@ -43,14 +89,6 @@ export class PegasusUtility {
defender.processNoDefense( attackRollData ) ;
}
/* -------------------------------------------- */
static reduceDamageWithChi( defenseRollId) {
let defenseRollData = this.getRollData(defenseRollId );
let attackRollData = this.getRollData(defenseRollData.linkedRollId);
let defender = game.actors.get( defenseRollData.actorId);
defender.reduceDamageWithChi(defenseRollData, attackRollData);
}
/* -------------------------------------------- */
static async chatListeners(html) {
@ -103,28 +141,19 @@ export class PegasusUtility {
}
return it;
}
/* -------------------------------------------- */
static getChiList() {
let chi = [];
chi.push( { name: "Jade" });
chi.push( { name: "Crimson" });
chi.push( { name: "Gold" });
chi.push( { name: "White" });
chi.push( { name: "Silver" });
return chi;
static getDiceFromLevel(level = 0) {
level = Number(level)
return this.diceList[level];
}
/* -------------------------------------------- */
static getskillChiList( ) {
let skillsName = [];
let skills = this.getSkills();
console.log("SKILLS", skills);
for (let skill of skills) {
skillsName.push( { name: skill.name });
}
skillsName = skillsName.concat( this.getChiList() );
return skillsName;
static getFoundryDiceFromLevel(level = 0) {
level = Number(level)
console.log(this.diceFoundryList);
return this.diceFoundryList[level];
}
/* -------------------------------------------- */
static createDirectOptionList( min, max) {
let options = {};
@ -142,29 +171,6 @@ export class PegasusUtility {
}
return options;
}
/* -------------------------------------------- */
static getNegativeModifiers(min, max) {
let options = ""
options += `<option value="0">0</option>`
options += `<option value="-5">-5</option>`
options += `<option value="-10">-10</option>`
return options;
}
/* -------------------------------------------- */
static getPositiveModifiers(min, max) {
let options = ""
options += `<option value="0">0</option>`
options += `<option value="5">+5</option>`
options += `<option value="10">+10</option>`
options += `<option value="15">+15</option>`
options += `<option value="20">+20</option>`
options += `<option value="30">+30</option>`
options += `<option value="40">+40</option>`
options += `<option value="50">+60</option>`
options += `<option value="60">+50</option>`
options += `<option value="70">+70</option>`
return options;
}
/* -------------------------------------------- */
static getTarget() {
@ -300,93 +306,50 @@ export class PegasusUtility {
/* -------------------------------------------- */
static async rollWotG( rollData ) {
static async rollPegasus( rollData ) {
if (rollData.mode == "chidamage" ) {
let defender = game.actors.get( rollData.actorId);
defender.rollChiDamage(rollData);
return;
let dicePool = [ {name:"stat", level: 0, statmod: 0}, {name: "spec", level: 0}, {name:"bonus", level: 0}, {name:"hindrance", level: 0}, {name:"other", level:0} ];
if (rollData.stat) {
dicePool[0].level += Number(rollData.stat.value);
dicePool[0].statmod = Number(rollData.stat.mod);
}
if (rollData.spec) {
dicePool[1].level += Number(rollData.spec.data.level);
}
if (rollData.bonusDicesLevel) {
dicePool[2].level += Number(rollData.bonusDicesLevel);
}
if (rollData.hindranceDicesLevel) {
dicePool[3].level += Number(rollData.hindranceDicesLevel);
}
if (rollData.otherDicesLevel) {
dicePool[4].level += Number(rollData.otherDicesLevel);
}
let nbDice = 0;
if ( rollData.mode == 'skill' || rollData.mode == 'technique') {
nbDice = rollData.skill?.data.level || 0;
let diceFormulaTab = [];
for (let diceGroup of dicePool) {
diceFormulaTab.push( this.getFoundryDiceFromLevel( diceGroup.level) )
}
if ( rollData.mode == 'weapon' ) {
rollData.skill = rollData.weapon.data.skills[rollData.skillKey];
rollData.skillAttr = rollData.weapon.data.skills[rollData.skillKey].data.attr;
nbDice = rollData.skill?.data.level || 0;
}
if ( rollData.mode == 'technique') {
// Compute number of dice
if (rollData.attr ) {
rollData.skillAttr = rollData.attr;
}
if (rollData.chi ) {
rollData.skillAttr = rollData.chi;
nbDice = rollData.skillAttr.value || 0;
}
}
if ( rollData.skill && rollData.skillAttr.value >= rollData.skill.data.level) {
nbDice++;
}
if ( nbDice == 0) nbDice = 1;
nbDice += rollData.specialtiesBonus;
// Build dice formula
let diceTab = [];
for(let i=0; i<nbDice; i++) {
diceTab[i] = "1d10";
}
let formula = "{"+ diceTab.join(',') + '}';
let diceFormula = '{' + diceFormulaTab.join(', ') + '}kh';
console.log(diceFormula);
// Performs roll
let myRoll = rollData.roll;
if ( !myRoll ) { // New rolls only of no rerolls
myRoll = new Roll(formula).roll( { async: false} );
console.log("ROLL : ", formula);
myRoll = new Roll(diceFormula).roll( { async: false} );
console.log("ROLL : ", diceFormula);
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode") );
rollData.roll = myRoll
}
// Build the list of dices per number of occurence
let sortedRoll = [];
let bestScore = 0;
let diceResults = [];
for (let i=0; i<10; i++) {
sortedRoll[i] = 0;
}
for (let i=0; i<nbDice; i++) {
let dice1 = duplicate(myRoll.dice[i]);
if (dice1.results[0].result == 10) dice1.results[0].result = 0;
dice1.results[0].diceIndex = i;
diceResults.push( dice1.results[0] );
let nbFound = 1;
for (let j=0; j<nbDice; j++) {
if (j!=i) {
let dice2 = myRoll.dice[j];
if (dice2.results[0].result == 10) dice2.results[0].result = 0;
if (dice1.results[0].result == dice2.results[0].result) {
nbFound++;
}
}
}
let score = (nbFound * 10) + dice1.results[0].result;
if (score > bestScore) bestScore = score;
sortedRoll[dice1.results[0].result] = nbFound;
}
// Final score and keep data
rollData.nbDice = nbDice;
rollData.bestScore = bestScore;
rollData.diceResults = diceResults;
rollData.finalScore = bestScore + rollData.negativeModifier + rollData.positiveModifier;
rollData.finalScore = myRoll.total + dicePool[0].statmod;
console.log("ROLLLL!!!!", rollData);
let actor = game.actors.get(rollData.actorId);
this.createChatWithRollMode( rollData.alias, {
content: await renderTemplate(`systems/fvtt-weapons-of-the-gods/templates/chat-generic-result.html`, rollData)
content: await renderTemplate(`systems/fvtt-pegasus-rpg/templates/chat-generic-result.html`, rollData)
});
if ( rollData.defender ) {
@ -401,34 +364,6 @@ export class PegasusUtility {
return Math.floor(result/5) + 1;
}
/* -------------------------------------------- */
static removeDice( rollData, diceIndex) {
let diceResults = rollData.diceResults;
diceResults.splice( diceIndex, 1);
rollData.diceResults = diceResults;
rollData.nbDice = diceResults.length;
this.updateRoll(rollData);
}
/* -------------------------------------------- */
static addDice(rollId, diceValue) {
let rollData = this.getRollData( rollId );
let diceResults = rollData.diceResults;
let newResult = duplicate(diceResults[0]);
newResult.result = diceValue;
diceResults.push( newResult);
rollData.diceResults = diceResults;
rollData.nbDice = diceResults.length;
this.updateRoll(rollData);
}
/* ------------------------- ------------------- */
static async updateRoll( rollData) {
@ -550,18 +485,6 @@ export class PegasusUtility {
this.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions);
}
/* -------------------------------------------- */
static buildDifficultyOptions( ) {
let options = ""
options += `<option value="0">None</option>`
options += `<option value="8">Easy</option>`
options += `<option value="12">Moderate</option>`
options += `<option value="16">Difficult</option>`
options += `<option value="18">Very Difficult</option>`
return options;
}
/* -------------------------------------------- */
static async confirmDelete(actorSheet, li) {
let itemId = li.data("item-id");