Sync v9
This commit is contained in:
@@ -3,7 +3,7 @@ import { PegasusUtility } from "./pegasus-utility.js";
|
||||
import { PegasusRollDialog } from "./pegasus-roll-dialog.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
const coverBonusTable = { "nocover": 0, "lightcover": 2, "heavycover": 4, "entrenchedcover": 6};
|
||||
const coverBonusTable = { "nocover": 0, "lightcover": 2, "heavycover": 4, "entrenchedcover": 6 };
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* -------------------------------------------- */
|
||||
@@ -37,16 +37,16 @@ export class PegasusActor extends Actor {
|
||||
return actor;
|
||||
}
|
||||
|
||||
if ( data.type == 'character') {
|
||||
if (data.type == 'character') {
|
||||
const skills = await PegasusUtility.loadCompendium("fvtt-weapons-of-the-gods.skills");
|
||||
data.items = skills.map(i => i.toObject());
|
||||
}
|
||||
if ( data.type == 'npc') {
|
||||
if (data.type == 'npc') {
|
||||
}
|
||||
|
||||
return super.create(data, options);
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
prepareBaseData() {
|
||||
}
|
||||
@@ -62,7 +62,7 @@ export class PegasusActor extends Actor {
|
||||
if (this.type == 'character') {
|
||||
let h = 0;
|
||||
let updates = [];
|
||||
|
||||
|
||||
for (let key in this.data.data.statistics) {
|
||||
let attr = this.data.data.statistics[key];
|
||||
}
|
||||
@@ -70,8 +70,8 @@ export class PegasusActor extends Actor {
|
||||
this.data.data.secondary.health.max = h;
|
||||
updates.push( {'data.secondary.health.max': h} );
|
||||
}*/
|
||||
if ( updates.length > 0 ) {
|
||||
this.update( updates );
|
||||
if (updates.length > 0) {
|
||||
this.update(updates);
|
||||
}
|
||||
this.computeNRGHealth();
|
||||
}
|
||||
@@ -86,61 +86,56 @@ export class PegasusActor extends Actor {
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getActivePerks() {
|
||||
let perks = this.data.items.filter( item => item.type == 'perk' && item.data.data.active);
|
||||
let perks = this.data.items.filter(item => item.type == 'perk' && item.data.data.active);
|
||||
return perks;
|
||||
}
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getAbilities() {
|
||||
let ab = this.data.items.filter( item => item.type == 'ability');
|
||||
let ab = this.data.items.filter(item => item.type == 'ability');
|
||||
return ab;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getPerks() {
|
||||
let comp = this.data.items.filter( item => item.type == 'perk');
|
||||
let comp = this.data.items.filter(item => item.type == 'perk');
|
||||
return comp;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getEffects() {
|
||||
let comp = this.data.items.filter( item => item.type == 'effect');
|
||||
let comp = this.data.items.filter(item => item.type == 'effect');
|
||||
return comp;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getPowers() {
|
||||
let comp = this.data.items.filter( item => item.type == 'power');
|
||||
let comp = this.data.items.filter(item => item.type == 'power');
|
||||
return comp;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getArmors() {
|
||||
let comp = this.data.items.filter( item => item.type == 'armor');
|
||||
let comp = this.data.items.filter(item => item.type == 'armor');
|
||||
return comp;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getShields() {
|
||||
let comp = this.data.items.filter( item => item.type == 'shield');
|
||||
let comp = this.data.items.filter(item => item.type == 'shield');
|
||||
return comp;
|
||||
}
|
||||
}
|
||||
getRace() {
|
||||
let race = this.data.items.filter( item => item.type == 'race');
|
||||
return race[0]?? [];
|
||||
let race = this.data.items.filter(item => item.type == 'race');
|
||||
return race[0] ?? [];
|
||||
}
|
||||
getRole() {
|
||||
let role = this.data.items.filter( item => item.type == 'role');
|
||||
return role[0]?? [];
|
||||
let role = this.data.items.filter(item => item.type == 'role');
|
||||
return role[0] ?? [];
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
checkAndPrepareWeapon(item) {
|
||||
let types=[];
|
||||
let specs=[];
|
||||
let stats=[];
|
||||
item.data.specs = specs;
|
||||
item.data.stats = stats;
|
||||
item.data.typeText = types.join('/');
|
||||
checkAndPrepareWeapon(weapon) {
|
||||
weapon.data.damageDice = PegasusUtility.getDiceFromLevel(weapon.data.damage);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
checkAndPrepareWeapons(weapons) {
|
||||
for ( let item of weapons) {
|
||||
for (let item of weapons) {
|
||||
this.checkAndPrepareWeapon(item);
|
||||
}
|
||||
return weapons;
|
||||
@@ -148,42 +143,41 @@ export class PegasusActor extends Actor {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getWeapons() {
|
||||
let comp = duplicate(this.data.items.filter( item => item.type == 'weapon' ) || []);
|
||||
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 ) {
|
||||
getItemById(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;
|
||||
return item;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getSpecs() {
|
||||
let comp = duplicate(this.data.items.filter( item => item.type == 'specialisation') || []);
|
||||
let comp = duplicate(this.data.items.filter(item => item.type == 'specialisation') || []);
|
||||
for (let c of comp) {
|
||||
c.data.dice = PegasusUtility.getDiceFromLevel(c.data.level);
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getRelevantSpec( statKey ) {
|
||||
let comp = duplicate(this.data.items.filter( item => item.type == 'specialisation' && item.data.data.statistic == statKey) || []);
|
||||
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 ) {
|
||||
let item = this.data.items.find( item => item.id == perkId );
|
||||
async activatePerk(perkId) {
|
||||
let item = this.data.items.find(item => item.id == perkId);
|
||||
if (item && item.data.data) {
|
||||
let update = { _id: item.id, "data.active": !item.data.data.active };
|
||||
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
|
||||
@@ -191,8 +185,8 @@ export class PegasusActor extends Actor {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async equipItem(itemId ) {
|
||||
let item = this.data.items.find( item => item.id == itemId );
|
||||
async equipItem(itemId) {
|
||||
let item = this.data.items.find(item => item.id == itemId);
|
||||
if (item && item.data.data) {
|
||||
let update = { _id: item.id, "data.equipped": !item.data.data.equipped };
|
||||
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
|
||||
@@ -200,11 +194,11 @@ export class PegasusActor extends Actor {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
compareName( a, b) {
|
||||
if ( a.name < b.name ) {
|
||||
compareName(a, b) {
|
||||
if (a.name < b.name) {
|
||||
return -1;
|
||||
}
|
||||
if ( a.name > b.name ) {
|
||||
if (a.name > b.name) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -212,9 +206,9 @@ export class PegasusActor extends Actor {
|
||||
|
||||
/* ------------------------------------------- */
|
||||
getEquipments() {
|
||||
return this.data.items.filter( item => item.type == 'shield' || item.type == 'armor' || item.type == "weapon" || item.type == "equipment");
|
||||
return this.data.items.filter(item => item.type == 'shield' || item.type == 'armor' || item.type == "weapon" || item.type == "equipment");
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getActiveEffects(matching = it => true) {
|
||||
let array = Array.from(this.getEmbeddedCollection("ActiveEffect").values());
|
||||
@@ -230,28 +224,28 @@ export class PegasusActor extends Actor {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getAttribute( attrKey ) {
|
||||
getAttribute(attrKey) {
|
||||
return this.data.data.attributes[attrKey];
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
|
||||
async equipGear( equipmentId ) {
|
||||
let item = this.data.items.find( item => item.id == equipmentId );
|
||||
async equipGear(equipmentId) {
|
||||
let item = this.data.items.find(item => item.id == equipmentId);
|
||||
if (item && item.data.data) {
|
||||
let update = { _id: item.id, "data.equipped": !item.data.data.equipped };
|
||||
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
|
||||
}
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getInitiativeScore( ) {
|
||||
if ( this.type == 'character') {
|
||||
getInitiativeScore() {
|
||||
if (this.type == 'character') {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getArmorModifier( ) {
|
||||
getArmorModifier() {
|
||||
let armors = this.getArmors();
|
||||
let modifier = 0;
|
||||
for (let armor of armors) {
|
||||
@@ -265,85 +259,85 @@ export class PegasusActor extends Actor {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async applyDamageLoss( damage) {
|
||||
async applyDamageLoss(damage) {
|
||||
let chatData = {
|
||||
user: game.user.id,
|
||||
alias : this.name,
|
||||
alias: this.name,
|
||||
rollMode: game.settings.get("core", "rollMode"),
|
||||
whisper: [game.user.id].concat( ChatMessage.getWhisperRecipients('GM') ),
|
||||
};
|
||||
whisper: [game.user.id].concat(ChatMessage.getWhisperRecipients('GM')),
|
||||
};
|
||||
//console.log("Apply damage chat", chatData );
|
||||
|
||||
if (damage > 0 ) {
|
||||
if (damage > 0) {
|
||||
let health = duplicate(this.data.data.secondary.health);
|
||||
health.value -= damage;
|
||||
if (health.value < 0 ) health.value = 0;
|
||||
this.update( { "data.secondary.health.value": health.value});
|
||||
chatData.content = `${this.name} looses ${damage} health. New health value is : ${health.value}` ;
|
||||
if (health.value < 0) health.value = 0;
|
||||
this.update({ "data.secondary.health.value": health.value });
|
||||
chatData.content = `${this.name} looses ${damage} health. New health value is : ${health.value}`;
|
||||
} else {
|
||||
chatData.content = `No health loss for ${this.name} !`;
|
||||
chatData.content = `No health loss for ${this.name} !`;
|
||||
}
|
||||
await ChatMessage.create( chatData );
|
||||
await ChatMessage.create(chatData);
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
processNoDefense( attackRollData) {
|
||||
processNoDefense(attackRollData) {
|
||||
let defenseRollData = {
|
||||
mode : "nodefense",
|
||||
mode: "nodefense",
|
||||
finalScore: 0,
|
||||
defenderName: this.name,
|
||||
attackerName: attackRollData.alias,
|
||||
defenderName: this.name,
|
||||
attackerName: attackRollData.alias,
|
||||
armorModifier: this.getArmorModifier(),
|
||||
actorId: this.id,
|
||||
alias: this.name,
|
||||
result: 0,
|
||||
|
||||
}
|
||||
this.syncRoll( defenseRollData );
|
||||
this.processDefenseResult(defenseRollData, attackRollData);
|
||||
this.syncRoll(defenseRollData);
|
||||
this.processDefenseResult(defenseRollData, attackRollData);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async processApplyDamage(defenseRollData, attackRollData) { // Processed by the defender actor
|
||||
if ( attackRollData && attackRollData ) {
|
||||
if (attackRollData && attackRollData) {
|
||||
let result = attackRollData.finalScore;
|
||||
defenseRollData.damageDices = WotGUtility.getDamageDice( result );
|
||||
defenseRollData.damageDices = WotGUtility.getDamageDice(result);
|
||||
defenseRollData.damageRoll = await this.rollDamage(defenseRollData);
|
||||
chatData.damages = true;
|
||||
chatData.damageDices = defenseRollData.damageDices;
|
||||
|
||||
WotGUtility.createChatWithRollMode( this.name, {
|
||||
WotGUtility.createChatWithRollMode(this.name, {
|
||||
content: await renderTemplate(`systems/fvtt-weapons-of-the-gods/templates/chat-opposed-damages.html`, chatData)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async processDefenseResult(defenseRollData, attackRollData) { // Processed by the defenser
|
||||
|
||||
if ( defenseRollData && attackRollData) {
|
||||
if (defenseRollData && attackRollData) {
|
||||
|
||||
let result = attackRollData.finalScore - defenseRollData.finalScore;
|
||||
defenseRollData.defenderName = this.name,
|
||||
defenseRollData.attackerName = attackRollData.alias
|
||||
defenseRollData.result= result
|
||||
defenseRollData.defenderName = this.name,
|
||||
defenseRollData.attackerName = attackRollData.alias
|
||||
defenseRollData.result = result
|
||||
defenseRollData.damages = false
|
||||
defenseRollData.damageDices = 0;
|
||||
|
||||
if ( result > 0 ) {
|
||||
defenseRollData.damageDices = WotGUtility.getDamageDice( result );
|
||||
if (result > 0) {
|
||||
defenseRollData.damageDices = WotGUtility.getDamageDice(result);
|
||||
defenseRollData.damageRoll = await this.rollDamage(defenseRollData, attackRollData);
|
||||
defenseRollData.damages = true;
|
||||
defenseRollData.finalDamage = defenseRollData.damageRoll.total;
|
||||
WotGUtility.updateRollData( defenseRollData);
|
||||
WotGUtility.updateRollData(defenseRollData);
|
||||
console.log("DAMAGE ROLL OBJECT", defenseRollData);
|
||||
WotGUtility.createChatWithRollMode( this.name, {
|
||||
WotGUtility.createChatWithRollMode(this.name, {
|
||||
content: await renderTemplate(`systems/fvtt-weapons-of-the-gods/templates/chat-opposed-damage.html`, defenseRollData)
|
||||
});
|
||||
} else {
|
||||
WotGUtility.updateRollData( defenseRollData );
|
||||
WotGUtility.createChatWithRollMode( this.name, {
|
||||
WotGUtility.updateRollData(defenseRollData);
|
||||
WotGUtility.createChatWithRollMode(this.name, {
|
||||
content: await renderTemplate(`systems/fvtt-weapons-of-the-gods/templates/chat-opposed-fail.html`, defenseRollData)
|
||||
});
|
||||
}
|
||||
@@ -351,15 +345,15 @@ export class PegasusActor extends Actor {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async rollDamage( defenseRollData, attackRollData ) {
|
||||
async rollDamage(defenseRollData, attackRollData) {
|
||||
let weaponDamage = 0;
|
||||
if (attackRollData.weapon?.data?.damage) {
|
||||
weaponDamage = Number(attackRollData.weapon.data.damage);
|
||||
}
|
||||
let formula = defenseRollData.damageDices+"d10+"+defenseRollData.armorModifier + "+" + weaponDamage;
|
||||
let formula = defenseRollData.damageDices + "d10+" + defenseRollData.armorModifier + "+" + weaponDamage;
|
||||
console.log("ROLL : ", formula);
|
||||
let myRoll = new Roll(formula).roll( { async: false} );
|
||||
await WotGUtility.showDiceSoNice(myRoll, game.settings.get("core", "rollMode") );
|
||||
let myRoll = new Roll(formula).roll({ async: false });
|
||||
await WotGUtility.showDiceSoNice(myRoll, game.settings.get("core", "rollMode"));
|
||||
return myRoll;
|
||||
}
|
||||
|
||||
@@ -372,48 +366,48 @@ export class PegasusActor extends Actor {
|
||||
return subActors;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
async addSubActor( subActorId) {
|
||||
let subActors = duplicate( this.data.data.subactors);
|
||||
subActors.push( subActorId);
|
||||
await this.update( { 'data.subactors': subActors } );
|
||||
async addSubActor(subActorId) {
|
||||
let subActors = duplicate(this.data.data.subactors);
|
||||
subActors.push(subActorId);
|
||||
await this.update({ 'data.subactors': subActors });
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
async delSubActor( subActorId) {
|
||||
async delSubActor(subActorId) {
|
||||
let newArray = [];
|
||||
for (let id of this.data.data.subactors) {
|
||||
if ( id != subActorId) {
|
||||
newArray.push( id);
|
||||
if (id != subActorId) {
|
||||
newArray.push(id);
|
||||
}
|
||||
}
|
||||
await this.update( { 'data.subactors': newArray } );
|
||||
await this.update({ 'data.subactors': newArray });
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
setDefenseMode( rollData ) {
|
||||
setDefenseMode(rollData) {
|
||||
console.log("DEFENSE MODE IS SET FOR", this.name);
|
||||
this.data.defenseRollData = rollData;
|
||||
this.data.defenseDefenderId = rollData.defenderId;
|
||||
this.data.defenseAttackerId = rollData.attackerId;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
clearDefenseMode( ) {
|
||||
clearDefenseMode() {
|
||||
this.data.defenseDefenderId = undefined;
|
||||
this.data.defenseAttackerId = undefined;
|
||||
this.data.defenseRollData = undefined;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
syncRoll( rollData ) {
|
||||
syncRoll(rollData) {
|
||||
let linkedRollId = PegasusUtility.getDefenseState(this.id);
|
||||
if ( linkedRollId) {
|
||||
if (linkedRollId) {
|
||||
rollData.linkedRollId = linkedRollId;
|
||||
}
|
||||
this.lastRollId = rollData.rollId;
|
||||
PegasusUtility.saveRollData( rollData );
|
||||
PegasusUtility.saveRollData(rollData);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getStat( statKey) {
|
||||
getStat(statKey) {
|
||||
let stat
|
||||
if (statKey == 'mr') {
|
||||
stat = duplicate(this.data.data.mr);
|
||||
@@ -425,8 +419,8 @@ export class PegasusActor extends Actor {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getOneSpec( specId) {
|
||||
let spec = this.data.items.find( item => item.type == 'specialisation' && item.id == specId);
|
||||
getOneSpec(specId) {
|
||||
let spec = this.data.items.find(item => item.type == 'specialisation' && item.id == specId);
|
||||
if (spec) {
|
||||
spec = duplicate(spec);
|
||||
spec.data.dice = PegasusUtility.getDiceFromLevel(spec.data.level);
|
||||
@@ -435,22 +429,22 @@ export class PegasusActor extends Actor {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
updatePerkRounds( itemId, roundValue) {
|
||||
let item = this.items.get( itemId)
|
||||
updatePerkRounds(itemId, roundValue) {
|
||||
let item = this.items.get(itemId)
|
||||
if (item) {
|
||||
this.updateEmbeddedDocuments( 'Item', [ { _id: item.id, 'data.roundcount': roundValue }] );
|
||||
this.updateEmbeddedDocuments('Item', [{ _id: item.id, 'data.roundcount': roundValue }]);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async rollMR() {
|
||||
let mr = duplicate( this.data.data.mr) ;
|
||||
let mr = duplicate(this.data.data.mr);
|
||||
if (mr) {
|
||||
mr.dice = PegasusUtility.getDiceFromLevel(mr.value);
|
||||
let rollData = {
|
||||
rollId:randomID(16),
|
||||
rollId: randomID(16),
|
||||
mode: "MR",
|
||||
alias: this.name,
|
||||
alias: this.name,
|
||||
actorImg: this.img,
|
||||
actorId: this.id,
|
||||
img: this.img,
|
||||
@@ -459,32 +453,32 @@ export class PegasusActor extends Actor {
|
||||
stat: mr,
|
||||
activePerks: duplicate(this.getActivePerks()),
|
||||
optionsDiceList: PegasusUtility.getOptionsDiceList(),
|
||||
bonusDicesLevel: 0,
|
||||
bonusDicesLevel: 0,
|
||||
hindranceDicesLevel: 0,
|
||||
otherDicesLevel: 0,
|
||||
}
|
||||
|
||||
this.syncRoll( rollData);
|
||||
let rollDialog = await PegasusRollDialog.create( this, rollData);
|
||||
this.syncRoll(rollData);
|
||||
let rollDialog = await PegasusRollDialog.create(this, rollData);
|
||||
console.log(rollDialog);
|
||||
rollDialog.render( true );
|
||||
rollDialog.render(true);
|
||||
} else {
|
||||
ui.notifications.warn("MR not found !");
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getCommonRollData( ) {
|
||||
/* -------------------------------------------- */
|
||||
getCommonRollData() {
|
||||
let rollData = {
|
||||
rollId:randomID(16),
|
||||
alias: this.name,
|
||||
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,
|
||||
bonusDicesLevel: 0,
|
||||
hindranceDicesLevel: 0,
|
||||
otherDicesLevel: 0,
|
||||
}
|
||||
@@ -492,23 +486,23 @@ export class PegasusActor extends Actor {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async startRoll( rollData) {
|
||||
this.syncRoll( rollData);
|
||||
let rollDialog = await PegasusRollDialog.create( this, rollData);
|
||||
async startRoll(rollData) {
|
||||
this.syncRoll(rollData);
|
||||
let rollDialog = await PegasusRollDialog.create(this, rollData);
|
||||
console.log(rollDialog);
|
||||
rollDialog.render( true );
|
||||
rollDialog.render(true);
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
rollPool( statKey, useSPec) {
|
||||
rollPool(statKey, useSPec) {
|
||||
let stat = this.getStat(statKey);
|
||||
if (stat) {
|
||||
let rollData = this.getCommonRollData()
|
||||
rollData.mode = "stat"
|
||||
rollData.specList = this.getRelevantSpec( statKey)
|
||||
rollData.mode = "stat"
|
||||
rollData.specList = this.getRelevantSpec(statKey)
|
||||
rollData.selectedSpec = "0"
|
||||
rollData.stat = stat;
|
||||
rollData.stat = stat;
|
||||
|
||||
this.startRoll(rollData);
|
||||
} else {
|
||||
@@ -516,13 +510,13 @@ export class PegasusActor extends Actor {
|
||||
}
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
rollUnarmedAttack() {
|
||||
rollUnarmedAttack() {
|
||||
let stat = this.getStat('com');
|
||||
if (stat) {
|
||||
let rollData = this.getCommonRollData()
|
||||
rollData.mode = "stat"
|
||||
rollData.mode = "stat"
|
||||
rollData.title = `Unarmed Attack`;
|
||||
rollData.stat = stat;
|
||||
rollData.stat = stat;
|
||||
rollData.damages = this.getStat('str');
|
||||
|
||||
this.startRoll(rollData);
|
||||
@@ -532,28 +526,28 @@ export class PegasusActor extends Actor {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
rollStat(statKey) {
|
||||
let stat = this.getStat(statKey) ;
|
||||
rollStat(statKey) {
|
||||
let stat = this.getStat(statKey);
|
||||
if (stat) {
|
||||
let rollData = this.getCommonRollData()
|
||||
rollData.mode = "stat"
|
||||
rollData.mode = "stat"
|
||||
rollData.title = `Stat ${stat.label}`;
|
||||
rollData.stat = stat;
|
||||
rollData.stat = stat;
|
||||
|
||||
this.startRoll(rollData);
|
||||
} else {
|
||||
ui.notifications.warn("Statistic not found !");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async rollSpec( specId ) {
|
||||
let spec = this.getOneSpec( specId)
|
||||
async rollSpec(specId) {
|
||||
let spec = this.getOneSpec(specId)
|
||||
if (spec) {
|
||||
let rollData = this.getCommonRollData()
|
||||
rollData.mode = "spec"
|
||||
let rollData = this.getCommonRollData()
|
||||
rollData.mode = "spec"
|
||||
rollData.title = `Spec. : ${spec.name} `,
|
||||
rollData.stat = this.getStat( spec.data.statistic )
|
||||
rollData.stat = this.getStat(spec.data.statistic)
|
||||
rollData.spec = spec
|
||||
|
||||
this.startRoll(rollData);
|
||||
@@ -563,238 +557,229 @@ export class PegasusActor extends Actor {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
updateWithTarget( rollData) {
|
||||
let objectDefender
|
||||
let target = WotGUtility.getTarget();
|
||||
if ( !target) {
|
||||
ui.notifications.warn("You are using a Weapon without a Target.");
|
||||
} else {
|
||||
let defenderActor = game.actors.get(target.data.actorId);
|
||||
objectDefender = WotGUtility.data(defenderActor);
|
||||
objectDefender = mergeObject(objectDefender, target.data.actorData);
|
||||
rollData.defender = objectDefender;
|
||||
rollData.attackerId = this.id;
|
||||
rollData.defenderId = objectDefender._id;
|
||||
|
||||
console.log("ROLLDATA DEFENDER !!!", rollData);
|
||||
}
|
||||
async deleteAllItemsByType(itemType) {
|
||||
let items = this.data.items.filter(item => item.type == itemType);
|
||||
await this.deleteEmbeddedDocuments('Item', items);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async deleteAllItemsByType( itemType) {
|
||||
let items = this.data.items.filter( item => item.type == itemType);
|
||||
await this.deleteEmbeddedDocuments( 'Item', items);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async addItemWithoutDuplicate( newItem ) {
|
||||
let item = this.data.items.find( item => item.type == newItem.type && item.name.toLowerCase() == newItem.name.toLowerCase() )
|
||||
if ( !item ) {
|
||||
await this.createEmbeddedDocuments( 'Item', [newItem]);
|
||||
async addItemWithoutDuplicate(newItem) {
|
||||
let item = this.data.items.find(item => item.type == newItem.type && item.name.toLowerCase() == newItem.name.toLowerCase())
|
||||
if (!item) {
|
||||
await this.createEmbeddedDocuments('Item', [newItem]);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
computeNRGHealth( ) {
|
||||
computeNRGHealth() {
|
||||
let phyDiceValue = PegasusUtility.getDiceValue(this.data.data.statistics.phy.value);
|
||||
if ( phyDiceValue!=this.data.data.secondary.health.max) {
|
||||
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);
|
||||
if ( mndDiceValue!=this.data.data.secondary.delirium.max) {
|
||||
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);
|
||||
if ( stlDiceValue != this.data.data.secondary.stealthhealth.max) {
|
||||
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);
|
||||
if ( socDiceValue!=this.data.data.secondary.socialhealth.max) {
|
||||
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} )
|
||||
if (nrgValue != this.data.data.nrg.max) {
|
||||
this.update({ 'data.nrg.max': nrgValue, 'data.nrg.value': nrgValue })
|
||||
}
|
||||
if ( nrgValue!= this.data.data.combat.stunthreshold) {
|
||||
this.update( {'data.combat.stunthreshold': nrgValue } )
|
||||
if (nrgValue != this.data.data.combat.stunthreshold) {
|
||||
this.update({ 'data.combat.stunthreshold': 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 } );
|
||||
if (mrLevel != this.data.data.mr.value) {
|
||||
this.update({ 'data.mr.value': mrLevel });
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async modStat( key, inc=1) {
|
||||
let stat = duplicate(this.data.data.statistics[key])
|
||||
async modStat(key, inc = 1) {
|
||||
let stat = duplicate(this.data.data.statistics[key])
|
||||
stat.mod += parseInt(inc)
|
||||
await this.update( { [`data.statistics.${key}`] : stat } )
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async valueStat( key, inc=1) {
|
||||
key = key.toLowerCase()
|
||||
let stat = duplicate( this.data.data.statistics[key] )
|
||||
stat.value += parseInt(inc)
|
||||
await this.update( { [`data.statistics.${key}`] : stat } )
|
||||
await this.update({ [`data.statistics.${key}`]: stat })
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async addIncSpec( spec, inc=1) {
|
||||
async valueStat(key, inc = 1) {
|
||||
key = key.toLowerCase()
|
||||
let stat = duplicate(this.data.data.statistics[key])
|
||||
stat.value += parseInt(inc)
|
||||
await this.update({ [`data.statistics.${key}`]: stat })
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async addIncSpec(spec, inc = 1) {
|
||||
console.log("Using spec : ", spec, inc)
|
||||
let specExist = this.data.items.find( item => item.type == 'specialisation' && item.name.toLowerCase() == spec.name.toLowerCase())
|
||||
let specExist = this.data.items.find(item => item.type == 'specialisation' && item.name.toLowerCase() == spec.name.toLowerCase())
|
||||
if (specExist) {
|
||||
specExist = duplicate(specExist)
|
||||
specExist.data.level += inc;
|
||||
let update = { _id: specExist._id, "data.level": specExist.data.level };
|
||||
await this.updateEmbeddedDocuments('Item', [ update ]);
|
||||
await this.updateEmbeddedDocuments('Item', [update]);
|
||||
} else {
|
||||
spec.data.level += inc;
|
||||
await this.createEmbeddedDocuments( 'Item', [ spec ]);
|
||||
await this.createEmbeddedDocuments('Item', [spec]);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
applyAbility( ability, updates = []) {
|
||||
if ( ability.data.affectedstat != "notapplicable") {
|
||||
let stat = duplicate(this.data.data.statistics[ability.data.affectedstat])
|
||||
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 }
|
||||
async applyRace(race) {
|
||||
let updates = { 'data.racename': race.name }
|
||||
let newItems = []
|
||||
await this.deleteAllItemsByType( 'race')
|
||||
await this.deleteAllItemsByType('race')
|
||||
newItems.push(race);
|
||||
|
||||
for (let ability of race.data.abilities) {
|
||||
newItems.push(ability);
|
||||
this.applyAbility( ability, updates)
|
||||
this.applyAbility(ability, updates)
|
||||
}
|
||||
if ( race.data.powersgained) {
|
||||
if (race.data.powersgained) {
|
||||
for (let power of race.data.powersgained) {
|
||||
newItems.push(power);
|
||||
}
|
||||
}
|
||||
if ( race.data.specialisations) {
|
||||
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) {
|
||||
if (race.data.attackgained) {
|
||||
for (let weapon of race.data.attackgained) {
|
||||
newItems.push(weapon);
|
||||
}
|
||||
}
|
||||
if ( race.data.armorgained) {
|
||||
if (race.data.armorgained) {
|
||||
for (let armor of race.data.armorgained) {
|
||||
newItems.push(armor);
|
||||
}
|
||||
}
|
||||
|
||||
await this.update( updates )
|
||||
await this.update(updates)
|
||||
await this.createEmbeddedDocuments('Item', newItems)
|
||||
console.log("Updates", updates, newItems)
|
||||
console.log("Updated actor", this)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getIncreaseStatValue( updates, statKey) {
|
||||
getIncreaseStatValue(updates, statKey) {
|
||||
let stat = duplicate(this.data.data.statistics[statKey])
|
||||
stat.value += 1;
|
||||
updates[`data.statistics.${statKey}`] = stat
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async applyRole( role ) {
|
||||
async applyRole(role) {
|
||||
console.log("ROLE", role)
|
||||
|
||||
let updates = { 'data.rolename': role.name }
|
||||
let newItems = []
|
||||
await this.deleteAllItemsByType( 'role')
|
||||
await this.deleteAllItemsByType('role')
|
||||
newItems.push(role);
|
||||
|
||||
this.getIncreaseStatValue( updates, role.data.statincrease1)
|
||||
this.getIncreaseStatValue( updates, role.data.statincrease2)
|
||||
this.getIncreaseStatValue(updates, role.data.statincrease1)
|
||||
this.getIncreaseStatValue(updates, role.data.statincrease2)
|
||||
|
||||
//newItems = newItems.concat(duplicate(role.data.specialisationsplus1))
|
||||
newItems = newItems.concat(duplicate(role.data.specialperk))
|
||||
|
||||
await this.update( updates )
|
||||
await this.update(updates)
|
||||
await this.createEmbeddedDocuments('Item', newItems)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async rollPower( powId ) {
|
||||
let power = this.data.items.find( item => item.type == 'power' && item.id == powId);
|
||||
if (power) {
|
||||
let rollData = {
|
||||
mode: "power",
|
||||
alias: this.name,
|
||||
actorImg: this.img,
|
||||
actorId: this.id,
|
||||
img: power.img,
|
||||
rollMode: game.settings.get("core", "rollMode"),
|
||||
title: `Power ${power.name} `,
|
||||
power: duplicate(power),
|
||||
activePerks: duplicate(this.getActivePerks()),
|
||||
optionsDiceList: PegasusUtility.getOptionsDiceList(),
|
||||
bonusDicesLevel: 0,
|
||||
hindranceDicesLevel: 0,
|
||||
otherDicesLevel: 0,
|
||||
}
|
||||
|
||||
this.updateWithTarget(rollData);
|
||||
|
||||
this.syncRoll( rollData);
|
||||
|
||||
let rollDialog = await PegasusRollDialog.create( this, rollData);
|
||||
console.log(rollDialog);
|
||||
rollDialog.render( true );
|
||||
} else {
|
||||
ui.notifications.warn("Technique not found !");
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async rollWeapon( weaponId ) {
|
||||
let weapon = this.data.items.find( item => item.id == weaponId);
|
||||
console.log("WEAPON :", weaponId, weapon );
|
||||
|
||||
if ( weapon ) {
|
||||
|
||||
weapon = duplicate(weapon);
|
||||
this.checkAndPrepareWeapon( weapon );
|
||||
async rollPower(powId) {
|
||||
let power = this.data.items.find(item => item.type == 'power' && item.id == powId);
|
||||
if (power) {
|
||||
let rollData = {
|
||||
mode: 'weapon',
|
||||
actorType: this.type,
|
||||
alias: this.name,
|
||||
mode: "power",
|
||||
alias: this.name,
|
||||
actorImg: this.img,
|
||||
actorId: this.id,
|
||||
img: weapon.img,
|
||||
img: power.img,
|
||||
rollMode: game.settings.get("core", "rollMode"),
|
||||
title: "Attack : " + weapon.name,
|
||||
weapon: weapon,
|
||||
title: `Power ${power.name} `,
|
||||
power: duplicate(power),
|
||||
activePerks: duplicate(this.getActivePerks()),
|
||||
optionsDiceList: PegasusUtility.getOptionsDiceList(),
|
||||
bonusDicesLevel: 0,
|
||||
bonusDicesLevel: 0,
|
||||
hindranceDicesLevel: 0,
|
||||
otherDicesLevel: 0,
|
||||
}
|
||||
}
|
||||
|
||||
this.updateWithTarget(rollData);
|
||||
|
||||
this.syncRoll( rollData);
|
||||
this.syncRoll(rollData);
|
||||
|
||||
let rollDialog = await PegasusRollDialog.create( this, rollData);
|
||||
console.log("WEAPON ROLL", rollData);
|
||||
rollDialog.render( true );
|
||||
let rollDialog = await PegasusRollDialog.create(this, rollData);
|
||||
console.log(rollDialog);
|
||||
rollDialog.render(true);
|
||||
} else {
|
||||
ui.notifications.warn("Technique not found !");
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
updateWithTarget(rollData) {
|
||||
let objectDefender
|
||||
let target = PegasusUtility.getTarget();
|
||||
if (!target) {
|
||||
ui.notifications.warn("You are using a Weapon without a Target.");
|
||||
} else {
|
||||
let defenderActor = game.actors.get(target.data.actorId);
|
||||
objectDefender = PegasusUtility.data(defenderActor);
|
||||
objectDefender = mergeObject(objectDefender, target.data.actorData);
|
||||
rollData.defender = objectDefender;
|
||||
rollData.attackerId = this.id;
|
||||
rollData.defenderId = objectDefender._id;
|
||||
//console.log("ROLLDATA DEFENDER !!!", rollData);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async rollWeapon(weaponId, damage=false) {
|
||||
let weapon = this.data.items.get(weaponId)
|
||||
|
||||
if (weapon) {
|
||||
let rollData = this.getCommonRollData()
|
||||
|
||||
weapon = duplicate(weapon);
|
||||
this.checkAndPrepareWeapon(weapon);
|
||||
|
||||
rollData.mode = "weapon"
|
||||
rollData.img = weapon.img
|
||||
rollData.weapon = weapon
|
||||
rollData.title = `Weapon : ${weapon.name}`
|
||||
rollData.stat = this.getStat(weapon.data.statistic)
|
||||
rollData.specList = this.getRelevantSpec(weapon.data.statistic)
|
||||
rollData.activePerks = duplicate(this.getActivePerks())
|
||||
if (damage) {
|
||||
rollData.isDamage = true;
|
||||
rollData.otherDicesLevel = weapon.data.damage
|
||||
}
|
||||
|
||||
//this.updateWithTarget(rollData);
|
||||
this.startRoll(rollData);
|
||||
} else {
|
||||
ui.notifications.warn("Weapon not found !", weaponId);
|
||||
}
|
||||
|
Reference in New Issue
Block a user