Sync
This commit is contained in:
@@ -108,10 +108,36 @@ export class PegasusActorSheet extends ActorSheet {
|
||||
this.actor.incrementeQuantite( li.data("item-id") );
|
||||
} );
|
||||
|
||||
html.find('.unarmed-attack').click((event) => {
|
||||
this.actor.rollUnarmedAttack();
|
||||
});
|
||||
html.find('.attack-melee').click((event) => {
|
||||
this.actor.rollPool( 'com', true);
|
||||
});
|
||||
html.find('.attack-ranged').click((event) => {
|
||||
this.actor.rollPool( 'agi', true);
|
||||
});
|
||||
html.find('.defense-roll').click((event) => {
|
||||
this.actor.rollPool( 'def', true);
|
||||
});
|
||||
html.find('.damage-melee').click((event) => {
|
||||
this.actor.rollPool( 'str', true);
|
||||
});
|
||||
html.find('.damage-ranged').click((event) => {
|
||||
this.actor.rollPool( 'per', true);
|
||||
});
|
||||
html.find('.damage-resistance').click((event) => {
|
||||
this.actor.rollPool( 'phy', true);
|
||||
});
|
||||
|
||||
html.find('.roll-stat').click((event) => {
|
||||
const statId = $(event.currentTarget).data("stat-key");
|
||||
this.actor.rollStat(statId);
|
||||
});
|
||||
html.find('.roll-mr').click((event) => {
|
||||
this.actor.rollMR();
|
||||
});
|
||||
|
||||
html.find('.roll-spec').click((event) => {
|
||||
const li = $(event.currentTarget).parents(".item");
|
||||
const specId = li.data("item-id");
|
||||
|
||||
@@ -53,7 +53,6 @@ export class PegasusActor extends Actor {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async prepareData() {
|
||||
|
||||
super.prepareData();
|
||||
}
|
||||
|
||||
@@ -74,6 +73,7 @@ export class PegasusActor extends Actor {
|
||||
if ( updates.length > 0 ) {
|
||||
this.update( updates );
|
||||
}
|
||||
this.computeNRGHealth();
|
||||
}
|
||||
|
||||
super.prepareDerivedData();
|
||||
@@ -122,7 +122,7 @@ export class PegasusActor extends Actor {
|
||||
let role = this.data.items.filter( item => item.type == 'role');
|
||||
return role[0]?? [];
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
checkAndPrepareWeapon(item) {
|
||||
let types=[];
|
||||
@@ -146,6 +146,18 @@ export class PegasusActor extends Actor {
|
||||
let comp = duplicate(this.data.items.filter( item => item.type == 'weapon' ) || []);
|
||||
return comp;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getItemById( id) {
|
||||
console.log("Search", id)
|
||||
let item = this.data.items.find( item => item.id == id);
|
||||
if (item ) {
|
||||
item = duplicate(item)
|
||||
if (item.type == 'specialisation') {
|
||||
item.data.dice = PegasusUtility.getDiceFromLevel(item.data.level);
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getSpecs() {
|
||||
@@ -155,6 +167,14 @@ export class PegasusActor extends Actor {
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getRelevantSpec( statKey ) {
|
||||
let comp = duplicate(this.data.items.filter( item => item.type == 'specialisation' && item.data.data.statistic == statKey) || []);
|
||||
for (let c of comp) {
|
||||
c.data.dice = PegasusUtility.getDiceFromLevel(c.data.level);
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async activatePerk(perkId ) {
|
||||
@@ -405,19 +425,20 @@ export class PegasusActor extends Actor {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async rollStat(statKey) {
|
||||
let stat = this.getStat(statKey) ;
|
||||
if (stat) {
|
||||
async rollMR() {
|
||||
let mr = duplicate( this.data.data.mr) ;
|
||||
if (mr) {
|
||||
mr.dice = PegasusUtility.getDiceFromLevel(mr.value);
|
||||
let rollData = {
|
||||
rollId:randomID(16),
|
||||
mode: "stat",
|
||||
mode: "MR",
|
||||
alias: this.name,
|
||||
actorImg: this.img,
|
||||
actorId: this.id,
|
||||
img: this.img,
|
||||
rollMode: game.settings.get("core", "rollMode"),
|
||||
title: `Stat ${stat.label} `,
|
||||
stat: stat,
|
||||
title: `${mr.label} `,
|
||||
stat: mr,
|
||||
activePerks: duplicate(this.getActivePerks()),
|
||||
optionsDiceList: PegasusUtility.getOptionsDiceList(),
|
||||
bonusDicesLevel: 0,
|
||||
@@ -426,42 +447,98 @@ export class PegasusActor extends Actor {
|
||||
}
|
||||
|
||||
this.syncRoll( rollData);
|
||||
|
||||
let rollDialog = await PegasusRollDialog.create( this, rollData);
|
||||
console.log(rollDialog);
|
||||
rollDialog.render( true );
|
||||
} else {
|
||||
ui.notifications.warn("MR not found !");
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getCommonRollData( ) {
|
||||
let rollData = {
|
||||
rollId:randomID(16),
|
||||
alias: this.name,
|
||||
actorImg: this.img,
|
||||
actorId: this.id,
|
||||
img: this.img,
|
||||
rollMode: game.settings.get("core", "rollMode"),
|
||||
activePerks: duplicate(this.getActivePerks()),
|
||||
optionsDiceList: PegasusUtility.getOptionsDiceList(),
|
||||
bonusDicesLevel: 0,
|
||||
hindranceDicesLevel: 0,
|
||||
otherDicesLevel: 0,
|
||||
}
|
||||
return rollData
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async startRoll( rollData) {
|
||||
this.syncRoll( rollData);
|
||||
let rollDialog = await PegasusRollDialog.create( this, rollData);
|
||||
console.log(rollDialog);
|
||||
rollDialog.render( true );
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
rollPool( statKey, useSPec) {
|
||||
let stat = this.getStat(statKey);
|
||||
if (stat) {
|
||||
let rollData = this.getCommonRollData()
|
||||
rollData.mode = "stat"
|
||||
rollData.specList = this.getRelevantSpec( statKey)
|
||||
rollData.selectedSpec = "0"
|
||||
rollData.stat = stat;
|
||||
|
||||
this.startRoll(rollData);
|
||||
} else {
|
||||
ui.notifications.warn("Statistic not found !");
|
||||
}
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
rollUnarmedAttack() {
|
||||
let stat = this.getStat('com');
|
||||
if (stat) {
|
||||
let rollData = this.getCommonRollData()
|
||||
rollData.mode = "stat"
|
||||
rollData.title = `Unarmed Attack`;
|
||||
rollData.stat = stat;
|
||||
rollData.damages = this.getStat('str');
|
||||
|
||||
this.startRoll(rollData);
|
||||
} else {
|
||||
ui.notifications.warn("Statistic not found !");
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
rollStat(statKey) {
|
||||
let stat = this.getStat(statKey) ;
|
||||
if (stat) {
|
||||
let rollData = this.getCommonRollData()
|
||||
rollData.mode = "stat"
|
||||
rollData.title = `Stat ${stat.label}`;
|
||||
rollData.stat = stat;
|
||||
|
||||
this.startRoll(rollData);
|
||||
} else {
|
||||
ui.notifications.warn("Statistic not found !");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async rollSpec( specId ) {
|
||||
let spec = this.getOneSpec( specId)
|
||||
if (spec) {
|
||||
let rollData = {
|
||||
mode: "spec",
|
||||
alias: this.name,
|
||||
actorImg: this.img,
|
||||
actorId: this.id,
|
||||
img: spec.img,
|
||||
rollMode: game.settings.get("core", "rollMode"),
|
||||
title: `Spec. : ${spec.name} `,
|
||||
stat: this.getStat( spec.data.statistic ),
|
||||
spec : spec ,
|
||||
activePerks: duplicate(this.getActivePerks()),
|
||||
optionsDiceList: PegasusUtility.getOptionsDiceList(),
|
||||
bonusDicesLevel: 0,
|
||||
hindranceDicesLevel: 0,
|
||||
otherDicesLevel: 0,
|
||||
}
|
||||
let rollData = this.getCommonRollData()
|
||||
rollData.mode = "spec"
|
||||
rollData.title = `Spec. : ${spec.name} `,
|
||||
rollData.stat = this.getStat( spec.data.statistic )
|
||||
rollData.spec = spec
|
||||
|
||||
this.syncRoll( rollData);
|
||||
|
||||
let rollDialog = await PegasusRollDialog.create( this, rollData);
|
||||
console.log(rollDialog);
|
||||
rollDialog.render( true );
|
||||
this.startRoll(rollData);
|
||||
} else {
|
||||
ui.notifications.warn("Specialisation not found !");
|
||||
}
|
||||
@@ -501,16 +578,33 @@ export class PegasusActor extends Actor {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
computeNRGHealth( ) {
|
||||
let focDiceValue = PegasusUtility.getDiceValue(this.data.data.statistics.foc.value);
|
||||
this.update( {'data.secondary.nrg.max': focDiceValue, 'data.secondary.nrg.value': focDiceValue} )
|
||||
let phyDiceValue = PegasusUtility.getDiceValue(this.data.data.statistics.phy.value);
|
||||
this.update( {'data.secondary.health.max': phyDiceValue, 'data.secondary.health.value': phyDiceValue} )
|
||||
if ( phyDiceValue!=this.data.data.secondary.health.max) {
|
||||
this.update( {'data.secondary.health.max': phyDiceValue, 'data.secondary.health.value': phyDiceValue} )
|
||||
}
|
||||
let mndDiceValue = PegasusUtility.getDiceValue(this.data.data.statistics.mnd.value);
|
||||
this.update( {'data.secondary.delirium.max': mndDiceValue, 'data.secondary.delirium.value': mndDiceValue} )
|
||||
if ( mndDiceValue!=this.data.data.secondary.delirium.max) {
|
||||
this.update( {'data.secondary.delirium.max': mndDiceValue, 'data.secondary.delirium.value': mndDiceValue} )
|
||||
}
|
||||
let stlDiceValue = PegasusUtility.getDiceValue(this.data.data.statistics.stl.value);
|
||||
this.update( {'data.secondary.stealthhealth.max': stlDiceValue, 'data.secondary.stealthhealth.value': stlDiceValue} )
|
||||
if ( stlDiceValue != this.data.data.secondary.stealthhealth.max) {
|
||||
this.update( {'data.secondary.stealthhealth.max': stlDiceValue, 'data.secondary.stealthhealth.value': stlDiceValue} )
|
||||
}
|
||||
let socDiceValue = PegasusUtility.getDiceValue(this.data.data.statistics.soc.value);
|
||||
this.update( {'data.secondary.socialhealth.max': socDiceValue, 'data.secondary.socialhealth.value': socDiceValue} )
|
||||
if ( socDiceValue!=this.data.data.secondary.socialhealth.max) {
|
||||
this.update( {'data.secondary.socialhealth.max': socDiceValue, 'data.secondary.socialhealth.value': socDiceValue} )
|
||||
}
|
||||
|
||||
let nrgValue = PegasusUtility.getDiceValue(this.data.data.statistics.foc.value);
|
||||
if ( nrgValue!= this.data.data.nrg.max) {
|
||||
this.update( {'data.nrg.max': nrgValue, 'data.nrg.value': nrgValue} )
|
||||
}
|
||||
|
||||
let mrLevel = (this.data.data.statistics.agi.value + this.data.data.statistics.str.value) - this.data.data.statistics.phy.value
|
||||
mrLevel = (mrLevel < 1) ? 1 : mrLevel;
|
||||
if ( mrLevel!= this.data.data.mr.value) {
|
||||
this.update( {'data.mr.value': mrLevel } );
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@@ -543,6 +637,15 @@ export class PegasusActor extends Actor {
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
applyAbility( ability, updates = []) {
|
||||
if ( ability.data.affectedstat != "notapplicable") {
|
||||
let stat = duplicate(this.data.data.statistics[ability.data.affectedstat])
|
||||
stat.value += parseInt(ability.data.statlevelincrease)
|
||||
stat.mod += parseInt(ability.data.statmodifier)
|
||||
updates[`data.statistics.${ability.data.affectedstat}`] = stat
|
||||
}
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
async applyRace( race ) {
|
||||
let updates = { 'data.racename':race.name }
|
||||
@@ -551,36 +654,30 @@ export class PegasusActor extends Actor {
|
||||
newItems.push(race);
|
||||
|
||||
for (let ability of race.data.abilities) {
|
||||
console.log("Ability", ability)
|
||||
if ( ability.data.affectedstat == "notapplicable") {
|
||||
newItems.push(ability);
|
||||
} else {
|
||||
let stat = duplicate(this.data.data.statistics[ability.data.affectedstat])
|
||||
stat.value += parseInt(ability.data.statlevelincrease)
|
||||
stat.mod += parseInt(ability.data.statmodifier)
|
||||
updates[`data.statistics.${ability.data.affectedstat}`] = stat
|
||||
}
|
||||
if ( race.data.powersgained) {
|
||||
for (let power of race.data.powersgained) {
|
||||
newItems.push(power);
|
||||
}
|
||||
}
|
||||
if ( race.data.specialisations) {
|
||||
for (let spec of race.data.specialisations) {
|
||||
newItems.push(spec);
|
||||
}
|
||||
}
|
||||
if ( race.data.attackgained) {
|
||||
for (let weapon of race.data.attackgained) {
|
||||
newItems.push(weapon);
|
||||
}
|
||||
}
|
||||
if ( race.data.armorgained) {
|
||||
for (let armor of race.data.armorgained) {
|
||||
newItems.push(armor);
|
||||
}
|
||||
newItems.push(ability);
|
||||
this.applyAbility( ability, updates)
|
||||
}
|
||||
if ( race.data.powersgained) {
|
||||
for (let power of race.data.powersgained) {
|
||||
newItems.push(power);
|
||||
}
|
||||
}
|
||||
if ( race.data.specialisations) {
|
||||
for (let spec of race.data.specialisations) {
|
||||
newItems.push(spec);
|
||||
}
|
||||
}
|
||||
if ( race.data.attackgained) {
|
||||
for (let weapon of race.data.attackgained) {
|
||||
newItems.push(weapon);
|
||||
}
|
||||
}
|
||||
if ( race.data.armorgained) {
|
||||
for (let armor of race.data.armorgained) {
|
||||
newItems.push(armor);
|
||||
}
|
||||
}
|
||||
|
||||
await this.update( updates )
|
||||
await this.createEmbeddedDocuments('Item', newItems)
|
||||
console.log("Updates", updates, newItems)
|
||||
|
||||
@@ -64,6 +64,9 @@ export class PegasusActorCreate {
|
||||
|
||||
if ( step == 'select-race-optionnal') {
|
||||
let ability = this.raceOptionnalAbilities.optionnalabilities.find( item => item._id == itemId);
|
||||
let update = []
|
||||
this.actor.applyAbility( ability, update );
|
||||
this.actor.update( update )
|
||||
this.actor.createEmbeddedDocuments( 'Item', [ability]);
|
||||
PegasusUtility.removeChatMessageId(PegasusUtility.findChatMessageId(event.currentTarget));
|
||||
this.raceOptionnalAbilities.optionnalabilities = this.raceOptionnalAbilities.optionnalabilities.filter( item => item._id != itemId);
|
||||
|
||||
@@ -7,15 +7,12 @@ export class PegasusRollDialog extends Dialog {
|
||||
|
||||
let html
|
||||
let options = { classes: ["WotGdialog"], width: 420, height: 320, 'z-index': 99999 };
|
||||
if ( rollData.mode == "stat") {
|
||||
if ( rollData.mode == "stat" || rollData.mode == "MR") {
|
||||
html = await renderTemplate('systems/fvtt-pegasus-rpg/templates/roll-dialog-stat.html', rollData);
|
||||
options.height = 320;
|
||||
} else if (rollData.mode == "spec") {
|
||||
html = await renderTemplate('systems/fvtt-pegasus-rpg/templates/roll-dialog-spec.html', rollData);
|
||||
options.height = 360;
|
||||
} else if (rollData.mode == "technique") {
|
||||
html = await renderTemplate('systems/fvtt-pegasus-rpg/templates/roll-dialog-technique.html', rollData);
|
||||
options.height = 380;
|
||||
} else if (rollData.mode == "weapon") {
|
||||
html = await renderTemplate('systems/fvtt-pegasus-rpg/templates/roll-dialog-weapon.html', rollData);
|
||||
options.height = 460;
|
||||
@@ -64,7 +61,10 @@ export class PegasusRollDialog extends Dialog {
|
||||
function onLoad() {
|
||||
}
|
||||
$(function () { onLoad(); });
|
||||
|
||||
|
||||
html.find('#specList').change((event) => {
|
||||
this.rollData.selectedSpec = event.currentTarget.value;
|
||||
});
|
||||
html.find('#bonusDicesLevel').change((event) => {
|
||||
this.rollData.bonusDicesLevel = Number(event.currentTarget.value);
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@ import { PegasusActorCreate } from "./pegasus-create-char.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
const __level2Dice = [ "d0", "d4", "d6", "d8", "d10", "d12" ];
|
||||
const __level2DiceValue = [ 0, 4, 6, 8, 10, 12 ];
|
||||
const __name2DiceValue = { "d0": 0, "d4": 4, "d6": 6, "d8": 8, "d10" : 10, "d12": 12 }
|
||||
|
||||
/* -------------------------------------------- */
|
||||
export class PegasusUtility {
|
||||
@@ -49,6 +49,7 @@ export class PegasusUtility {
|
||||
static buildDiceLists() {
|
||||
let maxLevel = game.settings.get("fvtt-pegasus-rpg", "dice-max-level");
|
||||
let diceList = [ "0" ];
|
||||
let diceValues = [0];
|
||||
let diceFoundryList = [ "d0" ];
|
||||
let diceLevel = 1;
|
||||
let concat = "";
|
||||
@@ -182,12 +183,11 @@ export class PegasusUtility {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getDiceValue( level = 0) {
|
||||
let locLevel = level
|
||||
let diceString = this.diceList[level]
|
||||
let diceTab = diceString.split(" ")
|
||||
let diceValue = 0
|
||||
while (locLevel > 0) {
|
||||
let idx = locLevel % __level2Dice.length
|
||||
diceValue += __level2DiceValue[idx]
|
||||
locLevel -= idx
|
||||
for (let dice of diceTab) {
|
||||
diceValue += __name2DiceValue[dice]
|
||||
}
|
||||
return diceValue
|
||||
}
|
||||
@@ -358,11 +358,17 @@ export class PegasusUtility {
|
||||
/* -------------------------------------------- */
|
||||
static async rollPegasus( rollData ) {
|
||||
|
||||
let actor = game.actors.get(rollData.actorId);
|
||||
|
||||
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.selectedSpec && rollData.selectedSpec != "0") {
|
||||
rollData.spec = rollData.specList.find( item => item._id == rollData.selectedSpec);
|
||||
rollData.spec.data.dice = PegasusUtility.getDiceFromLevel(rollData.spec.data.level);
|
||||
}
|
||||
if (rollData.spec) {
|
||||
dicePool[1].level += Number(rollData.spec.data.level);
|
||||
}
|
||||
@@ -395,9 +401,14 @@ export class PegasusUtility {
|
||||
// Final score and keep data
|
||||
rollData.finalScore = myRoll.total + dicePool[0].statmod;
|
||||
console.log("ROLLLL!!!!", rollData);
|
||||
|
||||
let actor = game.actors.get(rollData.actorId);
|
||||
|
||||
|
||||
if (rollData.damages) {
|
||||
let dmgFormula = this.getFoundryDiceFromLevel( rollData.damages.value )
|
||||
let dmgRoll = new Roll(dmgFormula).roll( { async: false} );
|
||||
await this.showDiceSoNice(dmgRoll, game.settings.get("core", "rollMode") );
|
||||
rollData.dmgResult = dmgRoll.total;
|
||||
}
|
||||
|
||||
this.createChatWithRollMode( rollData.alias, {
|
||||
content: await renderTemplate(`systems/fvtt-pegasus-rpg/templates/chat-generic-result.html`, rollData)
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user