fvtt-pegasus-rpg/modules/pegasus-actor.js

749 lines
25 KiB
JavaScript
Raw Normal View History

2021-12-02 07:38:59 +01:00
/* -------------------------------------------- */
import { PegasusUtility } from "./pegasus-utility.js";
import { PegasusRollDialog } from "./pegasus-roll-dialog.js";
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
const coverBonusTable = { "nocover": 0, "lightcover": 2, "heavycover": 4, "entrenchedcover": 6 };
2021-12-02 07:38:59 +01:00
/* -------------------------------------------- */
/* -------------------------------------------- */
/**
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
* @extends {Actor}
*/
export class PegasusActor extends Actor {
/* -------------------------------------------- */
/**
* Override the create() function to provide additional SoS functionality.
*
* This overrided create() function adds initial items
* Namely: Basic skills, money,
*
* @param {Object} data Barebones actor data which this function adds onto.
* @param {Object} options (Unused) Additional options which customize the creation workflow.
*
*/
static async create(data, options) {
// Case of compendium global import
if (data instanceof Array) {
return super.create(data, options);
}
// If the created actor has items (only applicable to duplicated actors) bypass the new actor creation logic
if (data.items) {
let actor = super.create(data, options);
return actor;
}
2022-01-14 14:49:16 +01:00
if (data.type == 'character') {
2021-12-02 07:38:59 +01:00
const skills = await PegasusUtility.loadCompendium("fvtt-weapons-of-the-gods.skills");
data.items = skills.map(i => i.toObject());
}
2022-01-14 14:49:16 +01:00
if (data.type == 'npc') {
2021-12-02 07:38:59 +01:00
}
return super.create(data, options);
}
2022-01-14 14:49:16 +01:00
2021-12-02 07:38:59 +01:00
/* -------------------------------------------- */
prepareBaseData() {
}
/* -------------------------------------------- */
async prepareData() {
super.prepareData();
}
/* -------------------------------------------- */
prepareDerivedData() {
if (this.type == 'character') {
let h = 0;
let updates = [];
2022-01-14 14:49:16 +01:00
2021-12-02 07:38:59 +01:00
for (let key in this.data.data.statistics) {
let attr = this.data.data.statistics[key];
}
/*if ( h != this.data.data.secondary.health.max) {
this.data.data.secondary.health.max = h;
updates.push( {'data.secondary.health.max': h} );
}*/
2022-01-14 14:49:16 +01:00
if (updates.length > 0) {
this.update(updates);
2021-12-02 07:38:59 +01:00
}
2022-01-11 23:35:23 +01:00
this.computeNRGHealth();
2021-12-02 07:38:59 +01:00
}
super.prepareDerivedData();
}
/* -------------------------------------------- */
_preUpdate(changed, options, user) {
super._preUpdate(changed, options, user);
}
2021-12-03 18:31:43 +01:00
/* -------------------------------------------- */
getActivePerks() {
2022-01-14 14:49:16 +01:00
let perks = this.data.items.filter(item => item.type == 'perk' && item.data.data.active);
2021-12-03 18:31:43 +01:00
return perks;
2022-01-14 14:49:16 +01:00
}
2021-12-02 07:38:59 +01:00
/* -------------------------------------------- */
2022-01-06 18:22:05 +01:00
getAbilities() {
2022-01-14 14:49:16 +01:00
let ab = this.data.items.filter(item => item.type == 'ability');
2022-01-06 18:22:05 +01:00
return ab;
}
/* -------------------------------------------- */
2021-12-02 07:38:59 +01:00
getPerks() {
2022-01-14 14:49:16 +01:00
let comp = this.data.items.filter(item => item.type == 'perk');
2021-12-02 07:38:59 +01:00
return comp;
}
/* -------------------------------------------- */
2022-01-12 16:25:55 +01:00
getEffects() {
2022-01-14 14:49:16 +01:00
let comp = this.data.items.filter(item => item.type == 'effect');
2022-01-12 16:25:55 +01:00
return comp;
}
/* -------------------------------------------- */
2021-12-02 07:38:59 +01:00
getPowers() {
2022-01-14 14:49:16 +01:00
let comp = this.data.items.filter(item => item.type == 'power');
2021-12-02 07:38:59 +01:00
return comp;
}
/* -------------------------------------------- */
2022-01-22 21:49:34 +01:00
getMoneys() {
let comp = this.data.items.filter(item => item.type == 'money');
return comp;
}
/* -------------------------------------------- */
2021-12-02 07:38:59 +01:00
getArmors() {
2022-01-14 18:20:15 +01:00
let comp = duplicate(this.data.items.filter(item => item.type == 'armor') || []);
2021-12-02 07:38:59 +01:00
return comp;
}
/* -------------------------------------------- */
getShields() {
2022-01-14 14:49:16 +01:00
let comp = this.data.items.filter(item => item.type == 'shield');
2021-12-02 07:38:59 +01:00
return comp;
2022-01-14 14:49:16 +01:00
}
2022-01-08 18:28:01 +01:00
getRace() {
2022-01-14 14:49:16 +01:00
let race = this.data.items.filter(item => item.type == 'race');
return race[0] ?? [];
2022-01-08 18:28:01 +01:00
}
getRole() {
2022-01-14 14:49:16 +01:00
let role = this.data.items.filter(item => item.type == 'role');
return role[0] ?? [];
2021-12-02 07:38:59 +01:00
}
2022-01-14 18:20:15 +01:00
/* -------------------------------------------- */
checkAndPrepareArmor(armor) {
armor.data.resistanceDice = PegasusUtility.getDiceFromLevel(armor.data.resistance);
}
/* -------------------------------------------- */
checkAndPrepareArmors(armors) {
for (let item of armors) {
this.checkAndPrepareArmor(item);
}
return armors;
}
2022-01-14 14:49:16 +01:00
2021-12-02 07:38:59 +01:00
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
checkAndPrepareWeapon(weapon) {
weapon.data.damageDice = PegasusUtility.getDiceFromLevel(weapon.data.damage);
2021-12-02 07:38:59 +01:00
}
/* -------------------------------------------- */
checkAndPrepareWeapons(weapons) {
2022-01-14 14:49:16 +01:00
for (let item of weapons) {
2021-12-02 07:38:59 +01:00
this.checkAndPrepareWeapon(item);
}
return weapons;
}
/* -------------------------------------------- */
getWeapons() {
2022-01-14 14:49:16 +01:00
let comp = duplicate(this.data.items.filter(item => item.type == 'weapon') || []);
2021-12-02 07:38:59 +01:00
return comp;
}
2022-01-11 23:35:23 +01:00
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
getItemById(id) {
let item = this.data.items.find(item => item.id == id);
if (item) {
2022-01-11 23:35:23 +01:00
item = duplicate(item)
if (item.type == 'specialisation') {
item.data.dice = PegasusUtility.getDiceFromLevel(item.data.level);
}
}
2022-01-14 14:49:16 +01:00
return item;
2022-01-11 23:35:23 +01:00
}
2021-12-02 07:38:59 +01:00
/* -------------------------------------------- */
getSpecs() {
2022-01-14 14:49:16 +01:00
let comp = duplicate(this.data.items.filter(item => item.type == 'specialisation') || []);
2021-12-02 20:18:21 +01:00
for (let c of comp) {
c.data.dice = PegasusUtility.getDiceFromLevel(c.data.level);
}
2021-12-02 07:38:59 +01:00
return comp;
}
2022-01-11 23:35:23 +01:00
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
getRelevantSpec(statKey) {
let comp = duplicate(this.data.items.filter(item => item.type == 'specialisation' && item.data.data.statistic == statKey) || []);
2022-01-11 23:35:23 +01:00
for (let c of comp) {
c.data.dice = PegasusUtility.getDiceFromLevel(c.data.level);
}
return comp;
}
2022-01-14 14:49:16 +01:00
2021-12-03 18:31:43 +01:00
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
async activatePerk(perkId) {
let item = this.data.items.find(item => item.id == perkId);
2021-12-03 18:31:43 +01:00
if (item && item.data.data) {
let update = { _id: item.id, "data.active": !item.data.data.active };
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
}
}
2022-01-25 09:14:32 +01:00
2022-01-16 16:12:15 +01:00
/* -------------------------------------------- */
async activatePower(itemId) {
let item = this.data.items.find(item => item.id == itemId);
if (item && item.data.data) {
let update = { _id: item.id, "data.activated": !item.data.data.activated };
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
}
}
2021-12-03 18:31:43 +01:00
2021-12-02 07:38:59 +01:00
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
async equipItem(itemId) {
let item = this.data.items.find(item => item.id == itemId);
2021-12-02 07:38:59 +01:00
if (item && item.data.data) {
let update = { _id: item.id, "data.equipped": !item.data.data.equipped };
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
}
}
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
compareName(a, b) {
if (a.name < b.name) {
2021-12-02 07:38:59 +01:00
return -1;
}
2022-01-14 14:49:16 +01:00
if (a.name > b.name) {
2021-12-02 07:38:59 +01:00
return 1;
}
return 0;
}
/* ------------------------------------------- */
getEquipments() {
2022-01-14 14:49:16 +01:00
return this.data.items.filter(item => item.type == 'shield' || item.type == 'armor' || item.type == "weapon" || item.type == "equipment");
2021-12-02 07:38:59 +01:00
}
2022-01-28 17:27:01 +01:00
/* ------------------------------------------- */
getEquipmentsOnly() {
return duplicate( this.data.items.filter(item => item.type == "equipment") || [] )
}
2022-01-14 14:49:16 +01:00
2021-12-02 07:38:59 +01:00
/* -------------------------------------------- */
getActiveEffects(matching = it => true) {
let array = Array.from(this.getEmbeddedCollection("ActiveEffect").values());
return Array.from(this.getEmbeddedCollection("ActiveEffect").values()).filter(it => matching(it));
}
/* -------------------------------------------- */
getEffectByLabel(label) {
return this.getActiveEffects().find(it => it.data.label == label);
}
/* -------------------------------------------- */
getEffectById(id) {
return this.getActiveEffects().find(it => it.id == id);
}
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
getAttribute(attrKey) {
2021-12-02 07:38:59 +01:00
return this.data.data.attributes[attrKey];
}
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
async equipGear(equipmentId) {
let item = this.data.items.find(item => item.id == equipmentId);
2021-12-02 07:38:59 +01:00
if (item && item.data.data) {
let update = { _id: item.id, "data.equipped": !item.data.data.equipped };
await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity
}
}
/* -------------------------------------------- */
2022-01-28 10:05:54 +01:00
getInitiativeScore( combatId, combatantId) {
2022-01-14 14:49:16 +01:00
if (this.type == 'character') {
2022-01-28 10:05:54 +01:00
this.rollMR(true, combatId, combatantId)
2022-01-14 14:49:16 +01:00
}
2022-01-28 10:05:54 +01:00
console.log("Init required !!!!")
return -1;
2021-12-02 07:38:59 +01:00
}
/* -------------------------------------------- */
getSubActors() {
let subActors = [];
for (let id of this.data.data.subactors) {
subActors.push(duplicate(game.actors.get(id)));
}
return subActors;
}
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
async addSubActor(subActorId) {
let subActors = duplicate(this.data.data.subactors);
subActors.push(subActorId);
await this.update({ 'data.subactors': subActors });
2021-12-02 07:38:59 +01:00
}
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
async delSubActor(subActorId) {
2021-12-02 07:38:59 +01:00
let newArray = [];
for (let id of this.data.data.subactors) {
2022-01-14 14:49:16 +01:00
if (id != subActorId) {
newArray.push(id);
2021-12-02 07:38:59 +01:00
}
}
2022-01-14 14:49:16 +01:00
await this.update({ 'data.subactors': newArray });
2021-12-02 07:38:59 +01:00
}
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
syncRoll(rollData) {
2021-12-02 20:18:21 +01:00
let linkedRollId = PegasusUtility.getDefenseState(this.id);
2022-01-14 14:49:16 +01:00
if (linkedRollId) {
2021-12-02 07:38:59 +01:00
rollData.linkedRollId = linkedRollId;
}
this.lastRollId = rollData.rollId;
2022-01-14 14:49:16 +01:00
PegasusUtility.saveRollData(rollData);
2021-12-02 20:18:21 +01:00
}
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
getStat(statKey) {
2022-01-12 16:25:55 +01:00
let stat
if (statKey == 'mr') {
stat = duplicate(this.data.data.mr);
} else {
stat = duplicate(this.data.data.statistics[statKey]);
}
2021-12-02 20:18:21 +01:00
stat.dice = PegasusUtility.getDiceFromLevel(stat.value);
return stat;
2021-12-02 07:38:59 +01:00
}
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
getOneSpec(specId) {
let spec = this.data.items.find(item => item.type == 'specialisation' && item.id == specId);
2021-12-02 20:18:21 +01:00
if (spec) {
spec = duplicate(spec);
spec.data.dice = PegasusUtility.getDiceFromLevel(spec.data.level);
}
return spec;
}
2022-01-12 16:25:55 +01:00
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
updatePerkRounds(itemId, roundValue) {
let item = this.items.get(itemId)
2022-01-12 16:25:55 +01:00
if (item) {
2022-01-14 14:49:16 +01:00
this.updateEmbeddedDocuments('Item', [{ _id: item.id, 'data.roundcount': roundValue }]);
2022-01-12 16:25:55 +01:00
}
}
2021-12-02 07:38:59 +01:00
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
async deleteAllItemsByType(itemType) {
let items = this.data.items.filter(item => item.type == itemType);
await this.deleteEmbeddedDocuments('Item', items);
2022-01-07 20:40:40 +01:00
}
2022-01-08 10:49:08 +01:00
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
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]);
2022-01-08 10:49:08 +01:00
}
}
/* -------------------------------------------- */
2022-01-17 15:09:52 +01:00
async computeNRGHealth() {
2022-01-28 15:23:14 +01:00
if ( this.isToken) return
2022-01-25 09:14:32 +01:00
if (this.isOwner || game.user.isGM) {
2022-01-19 21:25:59 +01:00
let updates = {}
let phyDiceValue = PegasusUtility.getDiceValue(this.data.data.statistics.phy.value) + this.data.data.secondary.health.bonus + this.data.data.statistics.phy.mod;
if (phyDiceValue != this.data.data.secondary.health.max) {
updates['data.secondary.health.max'] = phyDiceValue
updates['data.secondary.health.value'] = phyDiceValue
}
let mndDiceValue = PegasusUtility.getDiceValue(this.data.data.statistics.mnd.value) + this.data.data.secondary.delirium.bonus + this.data.data.statistics.mnd.mod;
if (mndDiceValue != this.data.data.secondary.delirium.max) {
updates['data.secondary.delirium.max'] = mndDiceValue
updates['data.secondary.delirium.value'] = mndDiceValue
}
2022-01-25 09:14:32 +01:00
let stlDiceValue = PegasusUtility.getDiceValue(this.data.data.statistics.stl.value) + this.data.data.secondary.stealthhealth.bonus + this.data.data.statistics.stl.mod;
2022-01-19 21:25:59 +01:00
if (stlDiceValue != this.data.data.secondary.stealthhealth.max) {
2022-01-25 09:14:32 +01:00
updates['data.secondary.stealthhealth.max'] = stlDiceValue
updates['data.secondary.stealthhealth.value'] = stlDiceValue
2022-01-19 21:25:59 +01:00
}
2022-01-25 09:14:32 +01:00
2022-01-19 21:25:59 +01:00
let socDiceValue = PegasusUtility.getDiceValue(this.data.data.statistics.soc.value) + this.data.data.secondary.socialhealth.bonus + this.data.data.statistics.soc.mod;
if (socDiceValue != this.data.data.secondary.socialhealth.max) {
updates['data.secondary.socialhealth.max'] = socDiceValue
2022-01-25 09:14:32 +01:00
updates['data.secondary.socialhealth.value'] = socDiceValue
2022-01-19 21:25:59 +01:00
}
2022-01-25 09:14:32 +01:00
2022-01-19 21:25:59 +01:00
let nrgValue = PegasusUtility.getDiceValue(this.data.data.statistics.foc.value) + this.data.data.nrg.mod + this.data.data.statistics.foc.mod;
if (nrgValue != this.data.data.nrg.max) {
updates['data.nrg.max'] = nrgValue
updates['data.nrg.value'] = nrgValue
}
2022-01-22 21:49:34 +01:00
nrgValue = PegasusUtility.getDiceValue(this.data.data.statistics.foc.value) + this.data.data.statistics.foc.mod;
2022-01-19 21:25:59 +01:00
if (nrgValue != this.data.data.combat.stunthreshold) {
2022-01-25 09:14:32 +01:00
updates['data.combat.stunthreshold'] = nrgValue
2022-01-19 21:25:59 +01:00
}
2022-01-25 09:14:32 +01:00
2022-01-25 10:37:28 +01:00
let momentum = this.data.data.statistics.foc.value + this.data.data.statistics.foc.mod
2022-01-22 21:49:34 +01:00
if (momentum != this.data.data.momentum.max) {
2022-01-25 09:14:32 +01:00
updates['data.momentum.value'] = 0
updates['data.momentum.max'] = momentum
}
2022-01-28 10:05:54 +01:00
let mrLevel = (this.data.data.statistics.agi.value + this.data.data.statistics.str.value) - this.data.data.statistics.phy.value
2022-01-25 09:14:32 +01:00
mrLevel = (mrLevel < 1) ? 1 : mrLevel;
if (mrLevel != this.data.data.mr.value) {
updates['data.mr.value'] = mrLevel
2022-01-19 21:25:59 +01:00
}
let race = this.getRace()
2022-01-25 09:14:32 +01:00
if (race && race.name && (race.name != this.data.data.biodata.racename)) {
2022-01-19 21:25:59 +01:00
updates['data.biodata.racename'] = race.name
}
let role = this.getRole()
2022-01-25 09:14:32 +01:00
if (role && role.name && (role.name != this.data.data.biodata.rolename)) {
2022-01-19 21:25:59 +01:00
updates['data.biodata.rolename'] = role.name
}
//console.log("UPD", updates, this.data.data.biodata)
await this.update(updates)
}
2022-01-08 10:49:08 +01:00
}
2022-01-07 20:40:40 +01:00
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
async modStat(key, inc = 1) {
let stat = duplicate(this.data.data.statistics[key])
2022-01-07 20:40:40 +01:00
stat.mod += parseInt(inc)
2022-01-14 14:49:16 +01:00
await this.update({ [`data.statistics.${key}`]: stat })
2022-01-07 20:40:40 +01:00
}
2022-01-14 14:49:16 +01:00
2022-01-08 10:49:08 +01:00
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
async valueStat(key, inc = 1) {
2022-01-08 10:49:08 +01:00
key = key.toLowerCase()
2022-01-14 14:49:16 +01:00
let stat = duplicate(this.data.data.statistics[key])
2022-01-08 10:49:08 +01:00
stat.value += parseInt(inc)
2022-01-14 14:49:16 +01:00
await this.update({ [`data.statistics.${key}`]: stat })
2022-01-08 10:49:08 +01:00
}
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
async addIncSpec(spec, inc = 1) {
2022-01-08 10:49:08 +01:00
console.log("Using spec : ", spec, inc)
2022-01-14 14:49:16 +01:00
let specExist = this.data.items.find(item => item.type == 'specialisation' && item.name.toLowerCase() == spec.name.toLowerCase())
2022-01-08 10:49:08 +01:00
if (specExist) {
specExist = duplicate(specExist)
specExist.data.level += inc;
let update = { _id: specExist._id, "data.level": specExist.data.level };
2022-01-14 14:49:16 +01:00
await this.updateEmbeddedDocuments('Item', [update]);
2022-01-08 10:49:08 +01:00
} else {
spec.data.level += inc;
2022-01-14 14:49:16 +01:00
await this.createEmbeddedDocuments('Item', [spec]);
2022-01-08 10:49:08 +01:00
}
}
2022-01-28 10:05:54 +01:00
/* -------------------------------------------- */
async incDecQuantity(objetId, incDec = 0) {
let objetQ = this.data.items.get(objetId)
if (objetQ) {
let newQ = objetQ.data.data.quantity + incDec;
const updated = await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'data.quantity': newQ }]); // pdates one EmbeddedEntity
2022-01-25 10:37:28 +01:00
}
2022-01-28 10:05:54 +01:00
}
2022-01-11 23:35:23 +01:00
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
applyAbility(ability, updates = []) {
if (ability.data.affectedstat != "notapplicable") {
let stat = duplicate(this.data.data.statistics[ability.data.affectedstat])
2022-01-11 23:35:23 +01:00
stat.value += parseInt(ability.data.statlevelincrease)
stat.mod += parseInt(ability.data.statmodifier)
updates[`data.statistics.${ability.data.affectedstat}`] = stat
2022-01-14 14:49:16 +01:00
}
2022-01-11 23:35:23 +01:00
}
2022-01-06 18:22:05 +01:00
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
async applyRace(race) {
2022-01-17 15:09:52 +01:00
let updates = { 'data.biodata.racename': race.name }
2022-01-06 18:22:05 +01:00
let newItems = []
2022-01-14 14:49:16 +01:00
await this.deleteAllItemsByType('race')
2022-01-06 18:22:05 +01:00
newItems.push(race);
for (let ability of race.data.abilities) {
2022-01-11 23:35:23 +01:00
newItems.push(ability);
2022-01-14 14:49:16 +01:00
this.applyAbility(ability, updates)
2022-01-11 23:35:23 +01:00
}
2022-01-14 14:49:16 +01:00
if (race.data.powersgained) {
2022-01-11 23:35:23 +01:00
for (let power of race.data.powersgained) {
newItems.push(power);
2022-01-08 18:28:01 +01:00
}
2022-01-11 23:35:23 +01:00
}
2022-01-14 14:49:16 +01:00
if (race.data.specialisations) {
2022-01-11 23:35:23 +01:00
for (let spec of race.data.specialisations) {
newItems.push(spec);
2022-01-08 18:28:01 +01:00
}
2022-01-11 23:35:23 +01:00
}
2022-01-14 14:49:16 +01:00
if (race.data.attackgained) {
for (let weapon of race.data.attackgained) {
2022-01-11 23:35:23 +01:00
newItems.push(weapon);
2022-01-08 18:28:01 +01:00
}
2022-01-11 23:35:23 +01:00
}
2022-01-14 14:49:16 +01:00
if (race.data.armorgained) {
2022-01-11 23:35:23 +01:00
for (let armor of race.data.armorgained) {
newItems.push(armor);
2022-01-08 18:28:01 +01:00
}
2022-01-06 18:22:05 +01:00
}
2022-01-11 23:35:23 +01:00
2022-01-14 14:49:16 +01:00
await this.update(updates)
2022-01-06 18:22:05 +01:00
await this.createEmbeddedDocuments('Item', newItems)
console.log("Updates", updates, newItems)
console.log("Updated actor", this)
}
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
getIncreaseStatValue(updates, statKey) {
2022-01-07 20:40:40 +01:00
let stat = duplicate(this.data.data.statistics[statKey])
stat.value += 1;
updates[`data.statistics.${statKey}`] = stat
}
/* -------------------------------------------- */
2022-01-14 14:49:16 +01:00
async applyRole(role) {
2022-01-06 18:22:05 +01:00
console.log("ROLE", role)
2022-01-07 20:40:40 +01:00
2022-01-17 15:09:52 +01:00
let updates = { 'data.biodata.rolename': role.name }
2022-01-07 20:40:40 +01:00
let newItems = []
2022-01-14 14:49:16 +01:00
await this.deleteAllItemsByType('role')
2022-01-07 20:40:40 +01:00
newItems.push(role);
2022-01-14 14:49:16 +01:00
this.getIncreaseStatValue(updates, role.data.statincrease1)
this.getIncreaseStatValue(updates, role.data.statincrease2)
2022-01-07 20:40:40 +01:00
2022-01-10 08:00:27 +01:00
//newItems = newItems.concat(duplicate(role.data.specialisationsplus1))
2022-01-08 10:49:08 +01:00
newItems = newItems.concat(duplicate(role.data.specialperk))
2022-01-14 14:49:16 +01:00
await this.update(updates)
2022-01-07 20:40:40 +01:00
await this.createEmbeddedDocuments('Item', newItems)
2022-01-06 18:22:05 +01:00
}
2022-01-14 14:49:16 +01:00
2022-01-28 10:05:54 +01:00
/* -------------------------------------------- */
addHindrancesList( effectsList ) {
if (this.data.data.combat.stunlevel > 0) {
effectsList.push( { label: "Stun Hindrance", type: "hindrance", applied: false, value: this.data.data.combat.stunlevel } )
}
let effects = this.data.items.filter( item => item.type == 'effect' )
for( let effect of effects) {
effect = duplicate(effect)
if (effect.data.hindrance) {
effectsList.push( { label: effect.name, type: "effect", applied: false, effect: effect, value: effect.data.effectlevel } )
}
}
}
/* -------------------------------------------- */
/* ROLL SECTION
/* -------------------------------------------- */
/* -------------------------------------------- */
addEffects( rollData) {
let effects = this.data.items.filter( item => item.type == 'effect' )
for( let effect of effects) {
effect = duplicate(effect)
if ( !effect.data.hindrance
&& effect.data.stataffected != "notapplicable"
2022-01-28 11:41:19 +01:00
&& effect.data.stataffected != "special") {
2022-01-28 10:05:54 +01:00
rollData.effectsList.push( { label: effect.name, type: "effect", applied: false, effect: effect, value: effect.data.effectlevel } )
2022-01-14 14:49:16 +01:00
}
2022-01-28 10:05:54 +01:00
}
}
/* -------------------------------------------- */
2022-01-28 15:23:14 +01:00
addArmorsShields( rollData, statKey = "none", useShield = false) {
if (statKey == 'phy') {
let armors = this.getArmors()
for (let armor of armors) {
rollData.armorsList.push( {label: `Armor ${armor.name}`, type: "other", applied: false, value: armor.data.resistance } )
}
2022-01-28 10:05:54 +01:00
}
2022-01-28 11:41:19 +01:00
if (useShield ) {
2022-01-28 15:23:14 +01:00
let shields = this.data.items.filter(item => item.type == "shield" && item.data.data.equipped)
for (let sh of shields) {
rollData.armorsList.push( {label: `Shield ${sh.name}`, type: "other", applied: false, value: sh.data.data.level } )
}
2022-01-28 11:41:19 +01:00
}
2022-01-28 10:05:54 +01:00
}
2022-01-28 17:27:01 +01:00
addWeapons(rollData, statKey) {
let weapons = this.getWeapons()
for (let weapon of weapons) {
if (weapon.data.equipped && weapon.data.statistic == statKey) {
rollData.weaponsList.push( {label: `Attack ${weapon.name}`, type: "attack", applied: false, weapon: weapon, value: 0 } )
}
2022-01-28 18:15:28 +01:00
if (weapon.data.equipped && weapon.data.enhanced && weapon.data.enhancedstat == statKey) {
rollData.weaponsList.push( {label: `Enhanced Attack ${weapon.name}`, type: "enhanced", applied: false, weapon: weapon, value: weapon.data.enhancedlevel } )
}
2022-01-28 17:27:01 +01:00
if (weapon.data.equipped && weapon.data.damagestatistic == statKey) {
rollData.weaponsList.push( {label: `Damage ${weapon.name}`, type: "damage", applied: false, weapon: weapon, value: weapon.data.damage } )
}
}
}
addEquipments(rollData, statKey) {
let equipments = this.getEquipmentsOnly()
for (let equip of equipments) {
if (equip.data.equipped && equip.data.stataffected == statKey) {
rollData.equipmentsList.push( {label: `Item ${equip.name}`, type: "item", applied: false, equip: equip, value: equip.data.level } )
}
}
}
2022-01-28 10:05:54 +01:00
/* -------------------------------------------- */
2022-01-28 11:41:19 +01:00
getCommonRollData(statKey = undefined, useShield = false) {
2022-01-28 10:05:54 +01:00
let rollData = PegasusUtility.getBasicRollData()
rollData.alias = this.name
rollData.actorImg = this.img
rollData.actorId = this.id
rollData.img = this.img
rollData.activePerks = duplicate(this.getActivePerks())
if ( statKey) {
rollData.statKey = statKey
rollData.stat = this.getStat(statKey)
rollData.statDicesLevel = rollData.stat.value
rollData.statMod = rollData.stat.mod
rollData.specList = this.getRelevantSpec(statKey)
rollData.selectedSpec = "0"
}
this.addEffects( rollData)
2022-01-28 15:23:14 +01:00
this.addArmorsShields(rollData, statKey, useShield)
2022-01-28 17:27:01 +01:00
this.addWeapons(rollData, statKey, useShield)
this.addEquipments(rollData, statKey)
2022-01-28 10:05:54 +01:00
return rollData
}
/* -------------------------------------------- */
async startRoll(rollData) {
this.syncRoll(rollData);
console.log("ROLL DATA", rollData)
let rollDialog = await PegasusRollDialog.create(this, rollData);
console.log(rollDialog);
rollDialog.render(true);
}
/* -------------------------------------------- */
rollPool(statKey, useShield = false) {
let stat = this.getStat(statKey);
if (stat) {
2022-01-28 11:41:19 +01:00
let rollData = this.getCommonRollData(statKey, useShield)
2022-01-28 10:05:54 +01:00
rollData.mode = "stat"
this.startRoll(rollData)
} else {
ui.notifications.warn("Statistic not found !");
}
}
/* -------------------------------------------- */
rollUnarmedAttack() {
let stat = this.getStat('com');
if (stat) {
let rollData = this.getCommonRollData(statKey)
rollData.mode = "stat"
rollData.title = `Unarmed Attack`;
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(statKey)
rollData.mode = "stat"
rollData.title = `Stat ${stat.label}`;
2021-12-02 07:38:59 +01:00
2022-01-28 10:05:54 +01:00
this.startRoll(rollData)
} else {
ui.notifications.warn("Statistic not found !");
}
}
2021-12-02 07:38:59 +01:00
2022-01-28 10:05:54 +01:00
/* -------------------------------------------- */
async rollSpec(specId) {
let spec = this.getOneSpec(specId)
if (spec) {
let rollData = this.getCommonRollData(spec.data.statistic)
rollData.mode = "spec"
rollData.title = `Spec. : ${spec.name} `
rollData.specList = [ spec ]
2022-01-28 11:41:19 +01:00
rollData.selectedSpec = spec._id
rollData.specDicesLevel = spec.data.level
2022-01-28 10:05:54 +01:00
this.startRoll(rollData)
2022-01-14 14:49:16 +01:00
} else {
2022-01-28 10:05:54 +01:00
ui.notifications.warn("Specialisation not found !");
2022-01-14 14:49:16 +01:00
}
}
2022-01-14 18:20:15 +01:00
2022-01-14 14:49:16 +01:00
/* -------------------------------------------- */
2022-01-28 10:05:54 +01:00
async rollMR( isInit = false, combatId = 0, combatantId = 0) {
let mr = duplicate(this.data.data.mr)
if (mr) {
mr.dice = PegasusUtility.getDiceFromLevel(mr.value);
let rollData = this.getCommonRollData("mr")
rollData.mode = "MR"
rollData.isInit = isInit
rollData.combatId = combatId
rollData.combatantId = combatantId
this.startRoll(rollData);
2022-01-14 14:49:16 +01:00
} else {
2022-01-28 10:05:54 +01:00
ui.notifications.warn("MR not found !");
2022-01-14 14:49:16 +01:00
}
}
2022-01-28 10:05:54 +01:00
2022-01-14 18:20:15 +01:00
/* -------------------------------------------- */
async rollArmor(armorId) {
let armor = this.data.items.get(armorId)
if (armor) {
2022-01-28 10:05:54 +01:00
let rollData = this.getCommonRollData(armor.data.statistic)
2022-01-14 18:20:15 +01:00
armor = duplicate(armor);
this.checkAndPrepareArmor(armor);
rollData.mode = "armor"
rollData.armor = armor
rollData.title = `Armor : ${armor.name}`
rollData.isResistance = true;
rollData.otherDicesLevel = armor.data.resistance
this.startRoll(rollData);
} else {
ui.notifications.warn("Armor not found !", weaponId);
}
}
2022-01-14 14:49:16 +01:00
2022-01-14 18:20:15 +01:00
/* -------------------------------------------- */
async rollPower(powerId) {
let power = this.data.items.get(powerId)
if (power) {
2022-01-28 10:05:54 +01:00
power = duplicate(power)
let rollData = this.getCommonRollData(power.data.statistic)
2022-01-14 18:20:15 +01:00
rollData.mode = "power"
rollData.power = power
rollData.title = `Power : ${power.name}`
this.startRoll(rollData);
} else {
ui.notifications.warn("Power not found !", powerId);
}
}
2021-12-02 07:38:59 +01:00
}