This commit is contained in:
2022-01-11 23:35:23 +01:00
parent 1e4b639ec6
commit 3384157580
13 changed files with 361 additions and 162 deletions

View File

@ -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)