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

1557 lines
56 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 };
2022-07-10 10:22:04 +02:00
const statThreatLevel = ["agi", "str", "phy", "com", "def", "per"]
2022-07-19 20:51:48 +02:00
const __subkey2title = {
"melee-dmg": "Melee Damage", "melee-atk": "Melee Attack", "ranged-atk": "Ranged Attack",
"ranged-dmg": "Ranged Damage", "dmg-res": "Damare Resistance"
}
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
}
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') {
2022-01-11 23:35:23 +01:00
this.computeNRGHealth();
2022-03-06 20:07:41 +01:00
this.data.data.encCapacity = this.getEncumbranceCapacity()
this.buildContainerTree()
2021-12-02 07:38:59 +01:00
}
super.prepareDerivedData();
}
/* -------------------------------------------- */
_preUpdate(changed, options, user) {
super._preUpdate(changed, options, user);
}
2022-03-06 20:07:41 +01:00
/* -------------------------------------------- */
getEncumbranceCapacity() {
return this.data.data.statistics.str.value * 25
}
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;
}
/* -------------------------------------------- */
2022-07-19 00:18:46 +02:00
getVirtues() {
let comp = this.data.items.filter(item => item.type == 'virtue');
return comp;
}
/* -------------------------------------------- */
getVices() {
let comp = this.data.items.filter(item => item.type == 'vice');
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-03-09 18:12:40 +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-03-09 18:12:40 +01:00
let race = this.data.items.filter(item => item.type == 'race')
2022-01-14 14:49:16 +01:00
return race[0] ?? [];
2022-01-08 18:28:01 +01:00
}
getRole() {
2022-03-09 18:12:40 +01:00
let role = this.data.items.filter(item => item.type == 'role')
2022-01-14 14:49:16 +01:00
return role[0] ?? [];
2021-12-02 07:38:59 +01:00
}
2022-01-14 18:20:15 +01:00
/* -------------------------------------------- */
2022-03-09 18:12:40 +01:00
checkAndPrepareEquipment(item) {
2022-07-10 10:22:04 +02:00
if (item.data.resistance) {
2022-03-09 18:12:40 +01:00
item.data.resistanceDice = PegasusUtility.getDiceFromLevel(item.data.resistance)
}
2022-07-10 10:22:04 +02:00
if (item.data.idr) {
2022-03-09 18:12:40 +01:00
item.data.idrDice = PegasusUtility.getDiceFromLevel(item.data.idr)
}
2022-07-10 10:22:04 +02:00
if (item.data.damage) {
2022-03-09 18:12:40 +01:00
item.data.damageDice = PegasusUtility.getDiceFromLevel(item.data.damage)
}
2022-07-10 10:22:04 +02:00
if (item.data.level) {
2022-03-09 18:12:40 +01:00
item.data.levelDice = PegasusUtility.getDiceFromLevel(item.data.level)
2022-01-14 18:20:15 +01:00
}
}
2022-01-14 14:49:16 +01:00
2021-12-02 07:38:59 +01:00
/* -------------------------------------------- */
2022-03-09 18:12:40 +01:00
checkAndPrepareEquipments(listItem) {
for (let item of listItem) {
this.checkAndPrepareEquipment(item)
2021-12-02 07:38:59 +01:00
}
2022-03-09 18:12:40 +01:00
return listItem
2021-12-02 07:38:59 +01:00
}
/* -------------------------------------------- */
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-02-10 21:58:19 +01:00
/* -------------------------------------------- */
async manageWorstFear(flag) {
if (flag) {
2022-02-13 21:58:19 +01:00
let effect = await PegasusUtility.getEffectFromCompendium("Worst Fear")
2022-02-10 21:58:19 +01:00
effect.data.worstfear = true
2022-02-13 21:58:19 +01:00
this.createEmbeddedDocuments('Item', [effect])
2022-02-10 21:58:19 +01:00
} else {
2022-02-13 21:58:19 +01:00
let effect = this.data.items.find(item => item.type == "effect" && item.data.data.worstfear)
2022-02-10 21:58:19 +01:00
if (effect) {
2022-02-13 21:58:19 +01:00
this.deleteEmbeddedDocuments('Item', [effect.id])
2022-02-10 21:58:19 +01:00
}
}
}
/* -------------------------------------------- */
async manageDesires(flag) {
if (flag) {
2022-02-13 21:58:19 +01:00
let effect = await PegasusUtility.getEffectFromCompendium("Desires")
2022-02-10 21:58:19 +01:00
effect.data.desires = true
2022-02-13 21:58:19 +01:00
this.createEmbeddedDocuments('Item', [effect])
2022-02-10 21:58:19 +01:00
} else {
2022-02-13 21:58:19 +01:00
let effect = this.data.items.find(item => item.type == "effect" && item.data.data.desires)
2022-02-10 21:58:19 +01:00
if (effect) {
2022-02-13 21:58:19 +01:00
this.deleteEmbeddedDocuments('Item', [effect.id])
2022-02-10 21:58:19 +01:00
}
}
}
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-07-19 00:18:46 +02:00
/* -------------------------------------------- */
async activateViceOrVirtue(itemId) {
let item = this.data.items.find(item => item.id == itemId)
if (item && item.data.data) {
let nrg = duplicate(this.data.data.nrg)
if (!item.data.data.activated) { // Current value
let effects = []
for (let effect of item.data.data.effectsgained) {
effect.data.powerId = itemId // Link to the perk, in order to dynamically remove them
effects.push(effect)
}
if (effects.length) {
await this.createEmbeddedDocuments('Item', effects)
}
} else {
let toRem = []
for (let item of this.data.items) {
if (item.type == 'effect' && item.data.data.powerId == itemId) {
toRem.push(item.id)
}
}
if (toRem.length) {
await this.deleteEmbeddedDocuments('Item', toRem)
}
}
let update = { _id: item.id, "data.activated": !item.data.data.activated }
await this.updateEmbeddedDocuments('Item', [update]) // Updates one EmbeddedEntity
}
}
2022-01-16 16:12:15 +01:00
/* -------------------------------------------- */
async activatePower(itemId) {
2022-02-10 21:58:19 +01:00
let item = this.data.items.find(item => item.id == itemId)
2022-01-16 16:12:15 +01:00
if (item && item.data.data) {
2022-02-10 21:58:19 +01:00
let nrg = duplicate(this.data.data.nrg)
2022-02-13 21:58:19 +01:00
if (!item.data.data.activated) { // Current value
if (item.data.data.costspent > nrg.value || item.data.data.costspent > nrg.max) {
return ui.notifications.warn("Not enough NRG to activate the Power " + item.name)
2022-02-10 21:58:19 +01:00
}
2022-02-13 21:58:19 +01:00
nrg.activated += item.data.data.costspent
nrg.value -= item.data.data.costspent
nrg.max -= item.data.data.costspent
2022-02-14 15:19:26 +01:00
await this.update({ 'data.nrg': nrg })
2022-02-10 21:58:19 +01:00
let effects = []
for (let effect of item.data.data.effectsgained) {
effect.data.powerId = itemId // Link to the perk, in order to dynamically remove them
effects.push(effect)
}
if (effects.length) {
await this.createEmbeddedDocuments('Item', effects)
}
} else {
2022-02-13 21:58:19 +01:00
nrg.activated -= item.data.data.costspent
nrg.max += item.data.data.costspent
2022-02-14 15:19:26 +01:00
await this.update({ 'data.nrg': nrg })
2022-02-10 21:58:19 +01:00
let toRem = []
2022-02-13 21:58:19 +01:00
for (let item of this.data.items) {
2022-02-10 21:58:19 +01:00
if (item.type == 'effect' && item.data.data.powerId == itemId) {
2022-02-13 21:58:19 +01:00
toRem.push(item.id)
2022-02-10 21:58:19 +01:00
}
}
if (toRem.length) {
await this.deleteEmbeddedDocuments('Item', toRem)
}
2022-02-13 21:58:19 +01:00
}
2022-02-10 21:58:19 +01:00
let update = { _id: item.id, "data.activated": !item.data.data.activated }
await this.updateEmbeddedDocuments('Item', [update]) // Updates one EmbeddedEntity
2022-01-16 16:12:15 +01:00
}
}
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() {
2022-02-10 21:58:19 +01:00
return duplicate(this.data.items.filter(item => item.type == "equipment") || [])
2022-01-28 17:27:01 +01:00
}
2022-01-14 14:49:16 +01:00
2022-03-12 16:35:32 +01:00
/* ------------------------------------------- */
computeThreatLevel() {
let tl = 0
2022-07-10 10:22:04 +02:00
for (let key of statThreatLevel) { // Init with concerned stats
tl += PegasusUtility.getDiceValue(this.data.data.statistics[key].value)
2022-03-12 16:35:32 +01:00
}
2022-07-10 10:22:04 +02:00
let powers = duplicate(this.getPowers() || [])
if (powers.length > 0) { // Then add some mental ones of powers
tl += PegasusUtility.getDiceValue(this.data.data.statistics.foc.value)
tl += PegasusUtility.getDiceValue(this.data.data.statistics.mnd.value)
2022-03-12 16:35:32 +01:00
}
2022-07-10 10:22:04 +02:00
tl += PegasusUtility.getDiceValue(this.data.data.mr.value)
let specThreat = this.data.items.filter(it => it.type == "specialisation" && it.data.data.isthreatlevel) || []
2022-03-12 16:35:32 +01:00
for (let spec of specThreat) {
2022-07-10 10:22:04 +02:00
tl += PegasusUtility.getDiceValue(spec.data.data.level)
2022-03-12 16:35:32 +01:00
}
tl += this.data.data.nrg.absolutemax + this.data.data.secondary.health.max + this.data.data.secondary.delirium.max
tl += this.getPerks().length * 5
let weapons = this.getWeapons()
2022-07-10 10:22:04 +02:00
for (let weapon of weapons) {
2022-03-12 16:35:32 +01:00
tl += PegasusUtility.getDiceValue(weapon.data.damage)
}
let armors = this.getArmors()
2022-07-10 10:22:04 +02:00
for (let armor of armors) {
2022-03-12 16:35:32 +01:00
tl += PegasusUtility.getDiceValue(armor.data.resistance)
}
2022-03-14 20:54:13 +01:00
let shields = duplicate(this.getShields())
2022-07-10 10:22:04 +02:00
for (let shield of shields) {
2022-03-12 16:35:32 +01:00
tl += PegasusUtility.getDiceValue(shield.data.level)
}
2022-03-14 14:09:26 +01:00
let abilities = duplicate(this.getAbilities())
for (let ability of abilities) {
tl += ability.data.threatlevel
}
2022-03-12 16:35:32 +01:00
let equipments = this.getEquipmentsOnly()
for (let equip of equipments) {
tl += equip.data.threatlevel
}
2022-07-10 10:22:04 +02:00
if (tl != this.data.data.biodata.threatlevel) {
this.update({ 'data.biodata.threatlevel': tl })
2022-03-12 16:35:32 +01:00
}
}
2022-03-06 20:07:41 +01:00
/* ------------------------------------------- */
async buildContainerTree() {
2022-03-07 16:00:53 +01:00
let equipments = duplicate(this.data.items.filter(item => item.type == "equipment") || [])
2022-03-06 20:07:41 +01:00
for (let equip1 of equipments) {
2022-03-07 16:00:53 +01:00
if (equip1.data.iscontainer) {
2022-03-06 20:07:41 +01:00
equip1.data.contents = []
equip1.data.contentsEnc = 0
for (let equip2 of equipments) {
2022-03-07 16:00:53 +01:00
if (equip1._id != equip2._id && equip2.data.containerid == equip1._id) {
2022-03-06 20:07:41 +01:00
equip1.data.contents.push(equip2)
2022-03-12 16:35:32 +01:00
let q = equip2.data.quantity ?? 1
2022-07-10 10:22:04 +02:00
equip1.data.contentsEnc += q * equip2.data.weight
2022-03-06 20:07:41 +01:00
}
}
}
}
2022-03-07 16:00:53 +01:00
// Compute whole enc
2022-03-06 20:07:41 +01:00
let enc = 0
2022-03-07 16:00:53 +01:00
for (let item of equipments) {
2022-07-10 10:22:04 +02:00
item.data.idrDice = PegasusUtility.getDiceFromLevel(Number(item.data.idr))
2022-03-06 20:07:41 +01:00
if (item.data.equipped) {
2022-03-07 16:00:53 +01:00
if (item.data.iscontainer) {
2022-03-06 20:07:41 +01:00
enc += item.data.contentsEnc
2022-03-09 18:12:40 +01:00
} else if (item.data.containerid == "") {
2022-03-12 16:35:32 +01:00
let q = item.data.quantity ?? 1
enc += q * item.data.weight
2022-03-06 20:07:41 +01:00
}
}
}
2022-03-07 16:00:53 +01:00
for (let item of this.data.items) { // Process items/shields/armors
if ((item.type == "weapon" || item.type == "shield" || item.type == "armor") && item.data.data.equipped) {
2022-03-12 16:35:32 +01:00
let q = item.data.data.quantity ?? 1
enc += q * item.data.data.weight
2022-03-07 16:00:53 +01:00
}
}
// Store local values
2022-03-06 20:07:41 +01:00
this.encCurrent = enc
2022-03-07 16:00:53 +01:00
this.containersTree = equipments.filter(item => item.data.containerid == "") // Returns the root of equipements without container
2022-03-06 20:07:41 +01:00
// Manages slow effect
2022-03-07 16:00:53 +01:00
let overCapacity = Math.floor(this.encCurrent / this.getEncumbranceCapacity())
this.encHindrance = Math.floor(this.encCurrent / this.getEncumbranceCapacity())
2022-03-06 20:07:41 +01:00
//console.log("Capacity", overCapacity, this.encCurrent / this.getEncumbranceCapacity() )
let effect = this.data.items.find(item => item.type == "effect" && item.data.data.slow)
2022-03-07 16:00:53 +01:00
if (overCapacity >= 4) {
if (!effect) {
2022-03-06 20:07:41 +01:00
effect = await PegasusUtility.getEffectFromCompendium("Slowed")
effect.data.slow = true
this.createEmbeddedDocuments('Item', [effect])
}
} else {
if (effect) {
this.deleteEmbeddedDocuments('Item', [effect.id])
}
}
}
2022-07-10 10:22:04 +02:00
/* -------------------------------------------- */
modifyStun(incDec) {
let combat = duplicate(this.data.data.combat)
combat.stunlevel += incDec
if (combat.stunlevel >= 0) {
this.update({ 'data.combat': combat })
let chatData = {
user: game.user.id,
rollMode: game.settings.get("core", "rollMode"),
whisper: [game.user.id].concat(ChatMessage.getWhisperRecipients('GM'))
}
if (incDec > 0) {
chatData.content = `<div>${this.name} suffered a Stun level.</div`
} else {
chatData.content = `<div>${this.name} recovered a Stun level.</div`
}
ChatMessage.create(chatData)
} else {
ui.notifications.warn("Stun level cannot go below 0")
}
let stunAbove = combat.stunlevel - combat.stunthreshold
if (incDec > 0 && stunAbove > 0) {
let delirium = duplicate(this.data.data.secondary.delirium)
delirium.value -= incDec
this.update({ 'data.secondary.delirium': delirium })
}
}
2022-03-06 20:07:41 +01:00
/* -------------------------------------------- */
2022-03-07 16:00:53 +01:00
modifyMomentum(incDec) {
2022-03-06 20:07:41 +01:00
let momentum = duplicate(this.data.data.momentum)
momentum.value += incDec
2022-07-20 23:53:37 +02:00
this.update({ 'data.momentum': momentum })
let chatData = {
user: game.user.id,
rollMode: game.settings.get("core", "rollMode"),
whisper: [game.user.id].concat(ChatMessage.getWhisperRecipients('GM'))
}
if (incDec > 0) {
chatData.content = `<div>${this.name} has gained a Momentum</div`
2022-07-10 10:22:04 +02:00
} else {
2022-07-20 23:53:37 +02:00
chatData.content = `<div>${this.name} has used a Momentum</div`
}
ChatMessage.create(chatData)
if (incDec < 0 && momentum.value >= 0) {
PegasusUtility.showMomentumDialog(this.id)
2022-03-06 20:07:41 +01:00
}
}
2022-03-07 16:00:53 +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-30 09:44:37 +01:00
2022-03-06 20:07:41 +01:00
/* -------------------------------------------- */
2022-03-07 16:00:53 +01:00
async addObjectToContainer(itemId, containerId) {
let container = this.data.items.find(item => item.id == containerId && item.data.data.iscontainer)
let object = this.data.items.find(item => item.id == itemId)
if (container) {
if (object.data.data.iscontainer) {
2022-03-06 20:07:41 +01:00
ui.notifications.warn("Only 1 level of container allowed")
return
}
2022-03-07 16:00:53 +01:00
let alreadyInside = this.data.items.filter(item => item.data.data.containerid && item.data.data.containerid == containerId);
if (alreadyInside.length >= container.data.data.containercapacity) {
2022-03-06 20:07:41 +01:00
ui.notifications.warn("Container is already full !")
return
2022-03-07 16:00:53 +01:00
} else {
await this.updateEmbeddedDocuments("Item", [{ _id: object.id, 'data.containerid': containerId }])
2022-03-06 20:07:41 +01:00
}
2022-03-07 16:00:53 +01:00
} else if (object && object.data.data.containerid) { // remove from container
2022-03-06 20:07:41 +01:00
console.log("Removeing: ", object)
2022-03-07 16:00:53 +01:00
await this.updateEmbeddedDocuments("Item", [{ _id: object.id, 'data.containerid': "" }]);
2022-03-06 20:07:41 +01:00
}
}
2022-07-19 20:51:48 +02:00
/* -------------------------------------------- */
2022-07-20 23:53:37 +02:00
checkVirtue(virtue) {
2022-07-19 20:51:48 +02:00
let vices = this.getVices()
for (let vice of vices) {
let nonVirtues = vice.data.data.unavailablevirtue
for (let blockedVirtue of nonVirtues) {
if (blockedVirtue.name.toLowerCase() == virtue.name.toLowerCase()) {
return false
2022-07-20 23:53:37 +02:00
}
2022-07-19 20:51:48 +02:00
}
}
return true
}
/* -------------------------------------------- */
2022-07-20 23:53:37 +02:00
checkVice(vice) {
2022-07-19 20:51:48 +02:00
let virtues = this.getVirtues()
for (let virtue of virtues) {
let nonVices = virtue.data.data.unavailablevice
for (let blockedVice of nonVices) {
if (blockedVice.name.toLowerCase() == vice.name.toLowerCase()) {
return false
2022-07-20 23:53:37 +02:00
}
2022-07-19 20:51:48 +02:00
}
}
return true
}
2022-03-06 20:07:41 +01:00
2021-12-02 07:38:59 +01:00
/* -------------------------------------------- */
2022-02-10 21:58:19 +01:00
async preprocessItem(event, item, onDrop = false) {
if (item.data.type == 'race') {
2022-01-30 09:44:37 +01:00
this.applyRace(item.data)
2022-03-16 15:08:34 +01:00
} else if (item.data.type == 'role') {
this.applyRole(item.data)
2022-02-10 21:58:19 +01:00
} else if (item.data.type == 'ability') {
2022-01-30 09:44:37 +01:00
this.applyAbility(item.data, [], true)
2022-02-10 21:58:19 +01:00
if (!onDrop) {
await this.createEmbeddedDocuments('Item', [item.data])
2022-02-10 15:53:42 +01:00
}
2022-01-30 09:44:37 +01:00
} else {
2022-02-10 21:58:19 +01:00
if (!onDrop) {
await this.createEmbeddedDocuments('Item', [item.data])
2022-01-30 09:44:37 +01:00
}
}
2022-07-19 20:51:48 +02:00
// Check virtue/vice validity
2022-07-20 23:53:37 +02:00
if (item.data.type == "virtue") {
if (!this.checkVirtue(item)) {
2022-07-19 20:51:48 +02:00
ui.notifications.info("Virtue is not allowed due to Vice.")
return false
2022-07-20 23:53:37 +02:00
}
2022-07-19 20:51:48 +02:00
}
2022-07-20 23:53:37 +02:00
if (item.data.type == "vice") {
if (!this.checkVice(item)) {
2022-07-19 20:51:48 +02:00
ui.notifications.info("Vice is not allowed due to Virtue.")
return false
2022-07-20 23:53:37 +02:00
}
2022-07-19 20:51:48 +02:00
}
2022-03-06 20:07:41 +01:00
let dropID = $(event.target).parents(".item").attr("data-item-id") // Only relevant if container drop
let objectID = item.id || item._id
2022-03-07 16:00:53 +01:00
this.addObjectToContainer(objectID, dropID)
2022-07-19 20:51:48 +02:00
return true
2022-01-30 09:44:37 +01:00
}
2021-12-02 07:38:59 +01:00
2022-01-30 09:44:37 +01:00
/* -------------------------------------------- */
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-02-10 21:58:19 +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) {
2022-03-07 16:00:53 +01:00
subActors.push(duplicate(game.actors.get(id)))
2021-12-02 07:38:59 +01:00
}
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) {
2022-02-10 21:58:19 +01:00
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-02-10 21:58:19 +01:00
specPowerActivate(specId) {
let spec = this.getOneSpec(specId)
if (spec) {
let powers = []
for (let power of spec.data.powers) {
power.data.specId = specId
powers.push(power)
}
if (powers.length > 0) {
this.createEmbeddedDocuments('Item', powers)
}
this.updateEmbeddedDocuments('Item', [{ _id: specId, 'data.powersactivated': true }])
}
}
/* -------------------------------------------- */
specPowerDeactivate(specId) {
let toRem = []
for (let power of this.data.items) {
if (power.type == "power" && power.data.data.specId && power.data.data.specId == specId) {
toRem.push(power.id)
}
}
if (toRem.length > 0) {
this.deleteEmbeddedDocuments('Item', toRem)
}
this.updateEmbeddedDocuments('Item', [{ _id: specId, 'data.powersactivated': false }])
}
2022-02-16 17:43:51 +01:00
/* -------------------------------------------- */
equipActivate(itemId) {
let item = this.items.get(itemId)
if (item) {
let effects = []
for (let effect of item.data.data.effects) {
effect.data.itemId = itemId // Keep link
effects.push(effect)
}
if (effects.length > 0) {
2022-03-07 16:00:53 +01:00
this.createEmbeddedDocuments('Item', effects)
2022-02-16 17:43:51 +01:00
}
this.updateEmbeddedDocuments('Item', [{ _id: itemId, 'data.activated': true }])
}
}
/* -------------------------------------------- */
equipDeactivate(itemId) {
let toRem = []
for (let item of this.data.items) {
if (item.data.data.itemId && item.data.data.itemId == itemId) {
toRem.push(item.id)
}
}
if (toRem.length > 0) {
this.deleteEmbeddedDocuments('Item', toRem)
}
this.updateEmbeddedDocuments('Item', [{ _id: itemId, 'data.activated': false }])
}
2022-02-10 21:58:19 +01:00
/* -------------------------------------------- */
async perkEffectUsed(itemId) {
2022-02-10 19:03:09 +01:00
let effect = this.items.get(itemId)
if (effect) {
PegasusUtility.createChatWithRollMode(effect.name, {
content: await renderTemplate(`systems/fvtt-pegasus-rpg/templates/chat-effect-used.html`, effect.data)
});
2022-02-10 21:58:19 +01:00
this.deleteEmbeddedDocuments('Item', [effect.id])
}
}
/* -------------------------------------------- */
disableWeaverPerk(perk) {
if (perk.data.data.isweaver) {
for (let spec of this.data.items) {
if (spec.type == 'specialisation' && spec.data.data.ispowergroup) {
this.specPowerDeactivate(spec.id)
}
}
}
}
/* -------------------------------------------- */
enableWeaverPerk(perk) {
if (perk.data.data.isweaver) {
for (let spec of this.data.items) {
if (spec.type == 'specialisation' && spec.data.data.ispowergroup) {
this.specPowerActivate(spec.id)
}
}
2022-02-10 19:03:09 +01:00
}
}
2022-02-13 21:58:19 +01:00
/* -------------------------------------------- */
async cleanPerkEffects(itemId) {
let effects = []
for (let item of this.data.items) {
if (item.type == "effect" && item.data.data.perkId == itemId) {
effects.push(item.id)
}
}
2022-02-16 12:14:34 +01:00
if (effects.length > 0) {
2022-02-16 14:13:16 +01:00
console.log("DELET!!!!", effects, this)
2022-02-13 21:58:19 +01:00
await this.deleteEmbeddedDocuments('Item', effects)
}
}
/* -------------------------------------------- */
async updatePerkUsed(itemId, index, checked) {
let item = this.items.get(itemId)
if (item && index) {
let key = "data.used" + index
2022-02-16 14:13:16 +01:00
await this.updateEmbeddedDocuments('Item', [{ _id: itemId, [`${key}`]: checked }])
2022-02-13 21:58:19 +01:00
item = this.items.get(itemId) // Refresh
if (item.data.data.nbuse == "next1action" && item.data.data.used1) {
this.cleanPerkEffects(itemId)
}
if (item.data.data.nbuse == "next2action" && item.data.data.used1 && item.data.data.used2) {
this.cleanPerkEffects(itemId)
}
if (item.data.data.nbuse == "next3action" && item.data.data.used1 && item.data.data.used2 && item.data.data.used3) {
this.cleanPerkEffects(itemId)
}
}
}
/* -------------------------------------------- */
async updatePowerSpentCost(itemId, value) {
let item = this.items.get(itemId)
if (item && value) {
value = Number(value) || 0
await this.updateEmbeddedDocuments('Item', [{ _id: itemId, 'data.costspent': value }])
}
}
2022-07-20 23:53:37 +02:00
/* -------------------------------------------- */
async cleanupPerksIfTrauma() {
2022-07-28 18:45:04 +02:00
if (this.getTraumaState() == "severetrauma") {
2022-07-20 23:53:37 +02:00
for (let perk of this.data.items) {
if (perk.type == "perk") {
this.cleanPerkEffects(perk.id)
2022-07-21 22:52:17 +02:00
this.updateEmbeddedDocuments('Item', [{ _id: perk.id, 'data.status': "ready", 'data.used1': false, 'data.used2': false, 'data.used3': false }])
2022-07-28 18:45:04 +02:00
ChatMessage.create({ content: `Perk ${perk.name} has been deactivated due to Severe Trauma state !` })
2022-07-20 23:53:37 +02:00
}
}
}
}
2022-07-28 18:45:04 +02:00
2022-07-26 22:38:04 +02:00
/* -------------------------------------------- */
2022-07-28 18:45:04 +02:00
incDecNRG(value) {
2022-07-26 22:38:04 +02:00
let nrg = duplicate(this.data.data.nrg)
nrg.value += value
if (nrg.value >= 0 && nrg.value <= nrg.max) {
this.update({ 'data.nrg': nrg })
}
}
2022-02-10 19:03:09 +01:00
/* -------------------------------------------- */
async updatePerkStatus(itemId, status) {
2022-01-14 14:49:16 +01:00
let item = this.items.get(itemId)
2022-01-12 16:25:55 +01:00
if (item) {
2022-02-10 19:03:09 +01:00
if (item.data.data.status == status) return;// Ensure we are really changing the status
2022-02-10 21:58:19 +01:00
2022-07-10 10:22:04 +02:00
// Severe Trauma management
if (this.getTraumaState() == "severetrauma") {
2022-07-30 22:44:44 +02:00
if ( !this.severeTraumaMessage) {
let chatData = {
user: game.user.id,
rollMode: game.settings.get("core", "rollMode"),
whisper: [game.user.id].concat(ChatMessage.getWhisperRecipients('GM'))
}
chatData.content = `<div>${this.name} is suffering from Severe Trauma and cannot use Perks at this time.</div`
ChatMessage.create(chatData)
this.severeTraumaMessage = true
2022-07-10 10:22:04 +02:00
}
2022-07-21 22:52:17 +02:00
this.updateEmbeddedDocuments('Item', [{ _id: itemId, 'data.status': "ready", 'data.used1': false, 'data.used2': false, 'data.used3': false }])
2022-07-10 10:22:04 +02:00
return
}
2022-02-10 19:03:09 +01:00
let updateOK = true
2022-02-10 21:58:19 +01:00
if (status == "ready") {
2022-02-16 14:13:16 +01:00
await this.cleanPerkEffects(itemId)
await this.updateEmbeddedDocuments('Item', [{ _id: itemId, 'data.used1': false, 'data.used2': false, 'data.used3': false }])
2022-02-10 21:58:19 +01:00
if (item.data.data.features.nrgcost.flag) {
2022-02-10 19:03:09 +01:00
let nrg = duplicate(this.data.data.nrg)
nrg.activated -= item.data.data.features.nrgcost.value
2022-02-14 15:19:26 +01:00
nrg.max += item.data.data.features.nrgcost.value
await this.update({ 'data.nrg': nrg })
2022-02-10 19:03:09 +01:00
}
if (item.data.data.features.bonushealth.flag) {
let health = duplicate(this.data.data.secondary.health)
2022-02-16 12:14:34 +01:00
health.value -= Number(item.data.data.features.bonushealth.value) || 0
health.max -= Number(item.data.data.features.bonushealth.value) || 0
2022-02-16 14:13:16 +01:00
await this.update({ 'data.secondary.health': health })
2022-02-10 19:03:09 +01:00
}
if (item.data.data.features.bonusdelirium.flag) {
2022-02-14 15:19:26 +01:00
let delirium = duplicate(this.data.data.secondary.delirium)
2022-02-16 12:14:34 +01:00
delirium.value -= Number(item.data.data.features.bonusdelirium.value) || 0
delirium.max -= Number(item.data.data.features.bonusdelirium.value) || 0
2022-02-16 14:13:16 +01:00
await this.update({ 'data.secondary.delirium': delirium })
2022-02-10 19:03:09 +01:00
}
if (item.data.data.features.bonusnrg.flag) {
let nrg = duplicate(this.data.data.nrg)
2022-02-16 12:14:34 +01:00
nrg.value -= Number(item.data.data.features.bonusnrg.value) || 0
nrg.max -= Number(item.data.data.features.bonusnrg.value) || 0
2022-02-16 14:13:16 +01:00
await this.update({ 'data.nrg': nrg })
2022-02-10 19:03:09 +01:00
}
2022-02-10 21:58:19 +01:00
this.disableWeaverPerk(item)
2022-02-16 17:43:51 +01:00
PegasusUtility.createChatWithRollMode(item.name, {
content: await renderTemplate(`systems/fvtt-pegasus-rpg/templates/chat-perk-ready.html`, { name: this.name, perk: item })
2022-07-26 22:38:04 +02:00
})
2022-02-10 19:03:09 +01:00
}
2022-02-10 21:58:19 +01:00
if (status == "activated") {
2022-02-10 19:03:09 +01:00
// Add effects linked to the perk
let effects = []
2022-02-10 21:58:19 +01:00
for (let effect of item.data.data.effectsgained) {
2022-02-10 19:03:09 +01:00
effect.data.perkId = itemId // Link to the perk, in order to dynamically remove them
effect.data.isUsed = false // Flag to indicate removal when used in a roll window
2022-02-10 21:58:19 +01:00
effects.push(effect)
2022-02-10 19:03:09 +01:00
}
2022-02-10 21:58:19 +01:00
if (effects.length) {
await this.createEmbeddedDocuments('Item', effects)
2022-02-10 19:03:09 +01:00
}
// Manage additional flags
2022-02-10 21:58:19 +01:00
if (item.data.data.features.nrgcost.flag) {
2022-02-16 14:13:16 +01:00
if ((this.data.data.nrg.value >= item.data.data.features.nrgcost.value) && (this.data.data.nrg.max >= item.data.data.features.nrgcost.value)) {
2022-02-10 19:03:09 +01:00
let nrg = duplicate(this.data.data.nrg)
nrg.activated += item.data.data.features.nrgcost.value
nrg.value -= item.data.data.features.nrgcost.value
2022-02-14 15:19:26 +01:00
nrg.max -= item.data.data.features.nrgcost.value
2022-02-16 14:13:16 +01:00
await this.update({ 'data.nrg': nrg })
2022-02-10 19:03:09 +01:00
} else {
updateOK = false
ui.notifications.warn("Not enough NRG to activate the Perk " + item.name)
}
}
if (item.data.data.features.bonushealth.flag) {
let health = duplicate(this.data.data.secondary.health)
2022-02-16 12:14:34 +01:00
health.value += Number(item.data.data.features.bonushealth.value) || 0
health.max += Number(item.data.data.features.bonushealth.value) || 0
2022-02-16 14:13:16 +01:00
await this.update({ 'data.secondary.health': health })
2022-02-10 19:03:09 +01:00
}
if (item.data.data.features.bonusdelirium.flag) {
2022-02-14 15:19:26 +01:00
let delirium = duplicate(this.data.data.secondary.delirium)
2022-02-16 12:14:34 +01:00
delirium.value += Number(item.data.data.features.bonusdelirium.value) || 0
delirium.max += Number(item.data.data.features.bonusdelirium.value) || 0
2022-02-16 14:13:16 +01:00
await this.update({ 'data.secondary.delirium': delirium })
2022-02-10 19:03:09 +01:00
}
if (item.data.data.features.bonusnrg.flag) {
let nrg = duplicate(this.data.data.nrg)
2022-02-16 12:14:34 +01:00
nrg.value += Number(item.data.data.features.bonusnrg.value) || 0
nrg.max += Number(item.data.data.features.bonusnrg.value) || 0
2022-02-16 14:13:16 +01:00
await this.update({ 'data.nrg': nrg })
2022-02-10 19:03:09 +01:00
}
2022-07-26 22:38:04 +02:00
PegasusUtility.createChatWithRollMode(item.name, {
content: await renderTemplate(`systems/fvtt-pegasus-rpg/templates/chat-perk-activated.html`, { name: this.name, perk: item })
})
2022-02-10 21:58:19 +01:00
this.enableWeaverPerk(item)
2022-02-10 19:03:09 +01:00
}
if (updateOK) {
2022-02-16 14:13:16 +01:00
await this.updateEmbeddedDocuments('Item', [{ _id: item.id, 'data.status': status }])
2022-02-10 19:03:09 +01:00
}
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-07-10 10:22:04 +02:00
/* -------------------------------------------- */
getTraumaState() {
this.traumaState = "none"
2022-07-19 20:51:48 +02:00
let negDelirium = -Math.floor((this.data.data.secondary.delirium.max + 1) / 2)
2022-07-10 10:22:04 +02:00
if (this.type == "character") {
2022-07-19 20:51:48 +02:00
if (this.data.data.secondary.delirium.value <= 0 && this.data.data.secondary.delirium.value >= negDelirium) {
2022-07-10 10:22:04 +02:00
this.traumaState = "trauma"
}
2022-07-19 20:51:48 +02:00
if (this.data.data.secondary.delirium.value < negDelirium) {
2022-07-10 10:22:04 +02:00
this.traumaState = "severetrauma"
}
}
return this.traumaState
}
2022-07-13 22:47:07 +02:00
/* -------------------------------------------- */
getLevelRemaining() {
return this.data.data.biodata.currentlevelremaining
}
/* -------------------------------------------- */
2022-07-19 00:18:46 +02:00
modifyHeroLevelRemaining(incDec) {
2022-07-13 22:47:07 +02:00
let biodata = duplicate(this.data.data.biodata)
2022-07-19 00:18:46 +02:00
biodata.currentlevelremaining = Math.max(biodata.currentlevelremaining + incDec, 0)
this.update({ "data.biodata": biodata })
2022-07-19 21:56:59 +02:00
ChatMessage.create({ content: `${this.name} has used a Hero Level to reroll !` })
2022-07-13 22:47:07 +02:00
return biodata.currentlevelremaining
}
2022-01-08 10:49:08 +01:00
/* -------------------------------------------- */
2022-02-16 14:13:16 +01:00
async computeNRGHealth() {
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
2022-02-16 14:13:16 +01:00
}
if (this.computeValue) {
updates['data.secondary.health.value'] = phyDiceValue
2022-01-19 21:25:59 +01:00
}
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
2022-02-16 14:13:16 +01:00
}
if (this.computeValue) {
updates['data.secondary.delirium.value'] = mndDiceValue
2022-01-19 21:25:59 +01:00
}
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
2022-02-16 14:13:16 +01:00
}
if (this.computeValue) {
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-02-16 14:13:16 +01:00
}
if (this.computeValue) {
updates['data.secondary.socialhealth.value'] = socDiceValue
2022-01-19 21:25:59 +01:00
}
2022-07-28 18:45:04 +02:00
2022-03-09 18:12:40 +01:00
let nrgValue = PegasusUtility.getDiceValue(this.data.data.statistics.foc.value) + this.data.data.nrg.mod + this.data.data.statistics.foc.mod
2022-02-14 15:19:26 +01:00
if (nrgValue != this.data.data.nrg.absolutemax) {
updates['data.nrg.absolutemax'] = nrgValue
2022-01-19 21:25:59 +01:00
}
2022-02-16 14:13:16 +01:00
if (this.computeValue) {
updates['data.nrg.max'] = nrgValue
updates['data.nrg.value'] = nrgValue
}
2022-02-25 17:11:31 +01:00
nrgValue = PegasusUtility.getDiceValue(this.data.data.statistics.mnd.value) + this.data.data.statistics.mnd.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
}
2022-07-28 18:45:04 +02:00
let moralitythreshold = - (Number(PegasusUtility.getDiceValue(this.data.data.statistics.foc.value)) + Number(this.data.data.statistics.foc.mod))
2022-07-21 22:52:17 +02:00
if (moralitythreshold != this.data.data.biodata.moralitythreshold) {
updates['data.biodata.moralitythreshold'] = moralitythreshold
}
2022-07-30 22:44:44 +02:00
if ( !this.isToken) {
if (this.warnMorality != this.data.data.biodata.morality && this.data.data.biodata.morality < 0) {
console.log("CHAR", this)
ChatMessage.create({ content: "WARNING: Your character is dangerously close to becoming corrupted and defeated. Start on a path of redemption!" })
}
if (this.warnMorality != this.data.data.biodata.morality) {
this.warnMorality = this.data.data.biodata.morality
}
2022-07-21 22:52:17 +02:00
}
2022-07-30 22:44:44 +02:00
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
}
2022-07-28 18:45:04 +02:00
if (Object.entries(updates).length > 0) {
await this.update(updates)
this.computeThreatLevel()
}
2022-01-19 21:25:59 +01:00
}
2022-02-10 15:53:42 +01:00
2022-02-16 14:13:16 +01:00
if (this.isOwner || game.user.isGM) {
// Update current hindrance level
let hindrance = this.data.data.combat.hindrancedice
if (this.data.data.secondary.health.value < 0) {
2022-07-28 18:45:04 +02:00
if (this.data.data.secondary.health.value < -Math.floor((this.data.data.secondary.health.max + 1) / 2)) { // Severe wounded
2022-07-10 10:22:04 +02:00
hindrance += 3
} else {
hindrance += 1
}
2022-02-16 14:13:16 +01:00
}
this.data.data.combat.hindrancedice = hindrance
2022-07-10 10:22:04 +02:00
this.getTraumaState()
2022-07-20 23:53:37 +02:00
this.cleanupPerksIfTrauma()
2022-02-10 15:53:42 +01:00
}
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) {
2022-03-12 16:35:32 +01:00
let newQ = objetQ.data.data.quantity + incDec
if (newQ >= 0) {
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-03-09 18:12:40 +01:00
/* -------------------------------------------- */
async incDecAmmo(objetId, incDec = 0) {
let objetQ = this.data.items.get(objetId)
if (objetQ) {
let newQ = objetQ.data.data.ammocurrent + incDec;
2022-07-10 10:22:04 +02:00
if (newQ >= 0 && newQ <= objetQ.data.data.ammomax) {
2022-03-09 18:12:40 +01:00
const updated = await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'data.ammocurrent': newQ }]); // pdates one EmbeddedEntity
}
}
}
2022-01-28 10:05:54 +01:00
2022-01-11 23:35:23 +01:00
/* -------------------------------------------- */
2022-02-10 15:53:42 +01:00
async applyAbility(ability, updates = [], directUpdate = false) {
// manage stat bonus
2022-01-14 14:49:16 +01:00
if (ability.data.affectedstat != "notapplicable") {
let stat = duplicate(this.data.data.statistics[ability.data.affectedstat])
2022-02-10 15:53:42 +01:00
stat.mod += Number(ability.data.statmodifier)
2022-01-11 23:35:23 +01:00
updates[`data.statistics.${ability.data.affectedstat}`] = stat
2022-02-10 15:53:42 +01:00
}
// manage status bonus
if (ability.data.statusaffected != "notapplicable") {
2022-02-10 21:58:19 +01:00
if (ability.data.statusaffected == 'nrg') {
let nrg = duplicate(this.data.data.nrg)
2022-02-10 15:53:42 +01:00
nrg.mod += Number(ability.data.statusmodifier)
updates[`data.nrg`] = nrg
}
2022-02-10 21:58:19 +01:00
if (ability.data.statusaffected == 'health') {
let health = duplicate(this.data.data.secondary.health)
2022-02-10 15:53:42 +01:00
health.bonus += Number(ability.data.statusmodifier)
updates[`data.secondary.health`] = health
}
2022-02-10 21:58:19 +01:00
if (ability.data.statusaffected == 'delirium') {
let delirium = duplicate(this.data.data.secondary.delirium)
2022-02-10 15:53:42 +01:00
delirium.bonus += Number(ability.data.statusmodifier)
updates[`data.secondary.delirium`] = delirium
}
}
2022-02-10 21:58:19 +01:00
if (directUpdate) {
2022-02-10 15:53:42 +01:00
await this.update(updates)
}
let newItems = []
if (ability.data.effectsgained) {
for (let effect of ability.data.effectsgained) {
newItems.push(effect);
}
}
if (ability.data.powersgained) {
for (let power of ability.data.powersgained) {
newItems.push(power);
}
}
if (ability.data.specialisations) {
for (let spec of ability.data.specialisations) {
newItems.push(spec);
2022-01-30 09:44:37 +01:00
}
2022-01-14 14:49:16 +01:00
}
2022-02-10 15:53:42 +01:00
if (ability.data.attackgained) {
for (let weapon of ability.data.attackgained) {
newItems.push(weapon);
}
}
if (ability.data.armorgained) {
for (let armor of ability.data.armorgained) {
newItems.push(armor);
}
2022-02-10 21:58:19 +01:00
}
2022-03-16 15:08:34 +01:00
console.log("Ability : adding", newItems)
2022-02-10 15:53:42 +01:00
await this.createEmbeddedDocuments('Item', newItems)
2022-01-11 23:35:23 +01:00
}
2022-02-10 15:53:42 +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-30 09:44:37 +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-02-10 15:53:42 +01:00
if (race.data.perksgained) {
for (let power of race.data.perks) {
2022-01-11 23:35:23 +01:00
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
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-03-16 11:12:14 +01:00
newItems.push(role)
2022-01-07 20:40:40 +01:00
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-07-10 10:22:04 +02:00
if (role.data.specialability.length > 0) {
2022-03-16 15:08:34 +01:00
console.log("Adding ability", role.data.specialability)
2022-07-10 10:22:04 +02:00
newItems = newItems.concat(duplicate(role.data.specialability)) // Add new ability
2022-03-16 15:08:34 +01:00
this.applyAbility(role.data.specialability[0], newItems)
}
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-03-16 15:08:34 +01:00
2022-01-06 18:22:05 +01:00
}
2022-01-14 14:49:16 +01:00
2022-01-28 10:05:54 +01:00
/* -------------------------------------------- */
2022-02-10 21:58:19 +01:00
addHindrancesList(effectsList) {
2022-01-28 10:05:54 +01:00
if (this.data.data.combat.stunlevel > 0) {
2022-07-28 18:45:04 +02:00
effectsList.push({ label: "Stun Hindrance", type: "hindrance", foreign: true, actorId: this.id, applied: false, value: this.data.data.combat.stunlevel })
2022-01-28 10:05:54 +01:00
}
2022-02-10 15:53:42 +01:00
if (this.data.data.combat.hindrancedice > 0) {
2022-07-20 23:53:37 +02:00
effectsList.push({ label: "Wounds Hindrance", type: "hindrance", foreign: true, actorId: this.id, applied: false, value: this.data.data.combat.hindrancedice })
2022-02-10 15:53:42 +01:00
}
2022-03-07 16:00:53 +01:00
let overCapacity = Math.floor(this.encCurrent / this.getEncumbranceCapacity())
if (overCapacity > 0) {
2022-07-20 23:53:37 +02:00
effectsList.push({ label: "Encumbrance Hindrance", type: "hindrance", foreign: true, actorId: this.id, applied: false, value: overCapacity })
2022-03-06 20:07:41 +01:00
}
2022-07-21 22:52:17 +02:00
if (this.data.data.biodata.morality <= 0) {
2022-07-28 18:45:04 +02:00
effectsList.push({ label: "Morality Hindrance", type: "hindrance", foreign: true, actorId: this.id, applied: false, value: 3 })
2022-07-21 22:52:17 +02:00
}
2022-02-10 21:58:19 +01:00
let effects = this.data.items.filter(item => item.type == 'effect')
for (let effect of effects) {
2022-01-28 10:05:54 +01:00
effect = duplicate(effect)
if (effect.data.hindrance) {
2022-07-20 23:53:37 +02:00
effectsList.push({ label: effect.name, type: "effect", foreign: true, actorId: this.id, applied: false, effect: effect, value: effect.data.effectlevel })
2022-01-28 10:05:54 +01:00
}
}
}
/* -------------------------------------------- */
/* ROLL SECTION
/* -------------------------------------------- */
/* -------------------------------------------- */
2022-02-10 21:58:19 +01:00
addEffects(rollData) {
let effects = this.data.items.filter(item => item.type == 'effect')
for (let effect of effects) {
2022-01-28 10:05:54 +01:00
effect = duplicate(effect)
2022-02-10 21:58:19 +01:00
if (!effect.data.hindrance
2022-02-16 14:13:16 +01:00
&& (effect.data.stataffected != "notapplicable" || effect.data.specaffected.length > 0)
2022-02-10 21:58:19 +01:00
&& effect.data.stataffected != "special") {
2022-02-16 14:13:16 +01:00
if (effect.data.effectstatlevel) {
2022-02-17 19:17:24 +01:00
effect.data.effectlevel = this.data.data.statistics[effect.data.effectstat].value
2022-02-16 14:13:16 +01:00
}
2022-07-10 10:22:04 +02:00
if (this.getTraumaState() == "none") {
rollData.effectsList.push({ label: effect.name, type: "effect", applied: false, effect: effect, value: effect.data.effectlevel })
} else {
if (!effect.data.bonusdice) { // Do not push bonus dice effect when TraumaState is activated
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-02-10 15:53:42 +01:00
2022-01-28 10:05:54 +01:00
/* -------------------------------------------- */
2022-02-10 21:58:19 +01:00
addArmorsShields(rollData, statKey = "none", useShield = false) {
2022-01-28 15:23:14 +01:00
if (statKey == 'phy') {
let armors = this.getArmors()
for (let armor of armors) {
2022-07-19 20:51:48 +02:00
rollData.armorsList.push({ label: `Armor ${armor.name}`, type: "armor", applied: false, value: armor.data.resistance })
2022-01-28 15:23:14 +01:00
}
2022-01-28 10:05:54 +01:00
}
2022-02-10 21:58: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) {
2022-07-19 20:51:48 +02:00
rollData.armorsList.push({ label: `Shield ${sh.name}`, type: "shield", applied: false, value: sh.data.data.level })
2022-01-28 15:23:14 +01:00
}
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) {
2022-02-10 21:58:19 +01:00
let weapons = this.getWeapons()
2022-01-28 17:27:01 +01:00
for (let weapon of weapons) {
if (weapon.data.equipped && weapon.data.statistic == statKey) {
2022-07-19 20:51:48 +02:00
rollData.weaponsList.push({ label: `Attack ${weapon.name}`, type: "attack", applied: false, weapon: weapon, value: 0, damageDice: PegasusUtility.getDiceFromLevel(0) })
2022-01-28 17:27:01 +01:00
}
2022-02-10 21:58:19 +01:00
if (weapon.data.equipped && weapon.data.enhanced && weapon.data.enhancedstat == statKey) {
2022-07-19 20:51:48 +02:00
rollData.weaponsList.push({ label: `Enhanced Attack ${weapon.name}`, type: "enhanced", applied: false, weapon: weapon, value: weapon.data.enhancedlevel, damageDice: PegasusUtility.getDiceFromLevel(weapon.data.enhancedlevel) })
2022-01-28 18:15:28 +01:00
}
2022-01-28 17:27:01 +01:00
if (weapon.data.equipped && weapon.data.damagestatistic == statKey) {
2022-07-19 20:51:48 +02:00
rollData.weaponsList.push({ label: `Damage ${weapon.name}`, type: "damage", applied: false, weapon: weapon, value: weapon.data.damage, damageDice: PegasusUtility.getDiceFromLevel(weapon.data.damage) })
2022-01-28 17:27:01 +01:00
}
}
}
addEquipments(rollData, statKey) {
2022-02-10 21:58:19 +01:00
let equipments = this.getEquipmentsOnly()
2022-01-28 17:27:01 +01:00
for (let equip of equipments) {
if (equip.data.equipped && equip.data.stataffected == statKey) {
2022-02-10 21:58:19 +01:00
rollData.equipmentsList.push({ label: `Item ${equip.name}`, type: "item", applied: false, equip: equip, value: equip.data.level })
2022-01-28 17:27:01 +01:00
}
}
}
2022-01-28 10:05:54 +01:00
/* -------------------------------------------- */
2022-07-20 23:53:37 +02:00
getCommonRollData(statKey = undefined, useShield = false, isInit = false) {
let rollData = PegasusUtility.getBasicRollData(isInit)
2022-01-28 10:05:54 +01:00
rollData.alias = this.name
rollData.actorImg = this.img
rollData.actorId = this.id
rollData.img = this.img
2022-07-10 10:22:04 +02:00
rollData.traumaState = this.getTraumaState()
2022-07-13 22:47:07 +02:00
rollData.levelRemaining = this.getLevelRemaining()
2022-01-28 10:05:54 +01:00
rollData.activePerks = duplicate(this.getActivePerks())
2022-07-10 10:22:04 +02:00
rollData.diceList = PegasusUtility.getDiceList()
rollData.dicePool = []
2022-02-10 21:58:19 +01:00
if (statKey) {
2022-01-28 10:05:54 +01:00
rollData.statKey = statKey
rollData.stat = this.getStat(statKey)
rollData.statDicesLevel = rollData.stat.value
2022-02-10 21:58:19 +01:00
rollData.statMod = rollData.stat.mod
2022-01-28 10:05:54 +01:00
rollData.specList = this.getRelevantSpec(statKey)
rollData.selectedSpec = "0"
2022-03-09 18:12:40 +01:00
if (statKey.toLowerCase() == "mr") {
rollData.img = "systems/fvtt-pegasus-rpg/images/icons/MR.webp"
} else {
2022-07-10 10:22:04 +02:00
rollData.img = `systems/fvtt-pegasus-rpg/images/icons/${rollData.stat.abbrev}.webp`
2022-03-09 18:12:40 +01:00
}
2022-07-10 10:22:04 +02:00
let diceKey = PegasusUtility.getDiceFromLevel(rollData.stat.value)
2022-07-28 18:45:04 +02:00
let diceList = diceKey.split(" ")
let mod = rollData.stat.mod
for (let myDice of diceList) {
myDice = myDice.trim()
let newDice = {
name: "stat", key: myDice, level: PegasusUtility.getLevelFromDice(myDice), mod: mod,
img: `systems/fvtt-pegasus-rpg/images/dice/${myDice}.webp`
}
rollData.dicePool.push(newDice)
mod = 0 // Only first dice has modifier
}
2022-02-10 21:58:19 +01:00
}
2022-01-28 10:05:54 +01:00
2022-07-20 23:53:37 +02:00
this.addEffects(rollData, isInit)
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-07-19 00:18:46 +02:00
console.log("ROLLDATA", rollData)
2022-02-10 21:58:19 +01:00
2022-01-28 10:05:54 +01:00
return rollData
}
2022-07-13 22:47:07 +02:00
/* -------------------------------------------- */
2022-07-19 00:18:46 +02:00
getLevelRemainingList() {
2022-07-13 22:47:07 +02:00
let options = []
2022-07-19 00:18:46 +02:00
for (let i = 0; i <= this.data.data.biodata.maxlevelremaining; i++) {
options.push(`<option value="${i}">${i}</option>`)
2022-07-13 22:47:07 +02:00
}
return options.join("\n")
}
2022-07-26 22:58:33 +02:00
/* -------------------------------------------- */
getMaxLevelRemainingList() {
let options = []
for (let i = 0; i <= 12; i++) {
options.push(`<option value="${i}">${i}</option>`)
}
return options.join("\n")
}
2022-01-28 10:05:54 +01:00
/* -------------------------------------------- */
async startRoll(rollData) {
this.syncRoll(rollData);
2022-02-16 14:13:16 +01:00
//console.log("ROLL DATA", rollData)
2022-07-19 00:18:46 +02:00
let rollDialog = await PegasusRollDialog.create(this, rollData)
console.log(rollDialog)
2022-01-28 10:05:54 +01:00
rollDialog.render(true);
}
2022-02-25 14:53:19 +01:00
/* -------------------------------------------- */
2022-03-07 16:00:53 +01:00
powerDmgRoll(itemId) {
2022-02-25 14:53:19 +01:00
let power = this.data.items.get(itemId)
2022-03-07 16:00:53 +01:00
if (power) {
2022-02-25 14:53:19 +01:00
power = duplicate(power)
2022-07-13 22:47:07 +02:00
this.rollPool(power.data.dmgstatistic, false, "power-dmg")
2022-02-25 14:53:19 +01:00
}
}
2022-03-07 16:00:53 +01:00
2022-01-28 10:05:54 +01:00
/* -------------------------------------------- */
2022-07-10 10:22:04 +02:00
rollPool(statKey, useShield = false, subKey = "none") {
2022-02-25 14:53:19 +01:00
let stat = this.getStat(statKey)
2022-01-28 10:05:54 +01:00
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"
2022-07-10 10:22:04 +02:00
rollData.subKey = subKey
2022-07-19 20:51:48 +02:00
let def = stat.label
if (subKey) {
def = __subkey2title[subKey]
}
rollData.title = `Roll : ${def} `
2022-03-09 18:12:40 +01:00
rollData.img = "icons/dice/d12black.svg"
2022-07-13 22:47:07 +02:00
if (subKey == "melee-dmg" || subKey == "ranged-dmg" || subKey == "power-dmg") {
rollData.isDamage = true
}
2022-01-28 10:05:54 +01:00
this.startRoll(rollData)
} else {
ui.notifications.warn("Statistic not found !");
}
}
/* -------------------------------------------- */
rollUnarmedAttack() {
2022-02-25 14:53:19 +01:00
let stat = this.getStat('com')
2022-01-28 10:05:54 +01:00
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} `
2022-02-10 21:58:19 +01:00
rollData.specList = [spec]
2022-01-28 11:41:19 +01:00
rollData.selectedSpec = spec._id
2022-02-16 12:14:34 +01:00
rollData.specName = spec.name
2022-03-06 20:07:41 +01:00
rollData.img = spec.img
2022-01-28 11:41:19 +01:00
rollData.specDicesLevel = spec.data.level
2022-07-13 22:47:07 +02:00
PegasusUtility.updateSpecDicePool(rollData)
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-02-10 21:58:19 +01:00
async rollMR(isInit = false, combatId = 0, combatantId = 0) {
2022-01-28 10:05:54 +01:00
let mr = duplicate(this.data.data.mr)
if (mr) {
mr.dice = PegasusUtility.getDiceFromLevel(mr.value);
2022-07-20 23:53:37 +02:00
let rollData = this.getCommonRollData("mr", false, isInit)
2022-01-28 10:05:54 +01:00
rollData.mode = "MR"
2022-03-09 18:12:40 +01:00
rollData.img = "systems/fvtt-pegasus-rpg/images/icons/MR.webp"
2022-01-28 10:05:54 +01:00
rollData.isInit = isInit
rollData.combatId = combatId
rollData.combatantId = combatantId
2022-03-09 18:12:40 +01:00
console.log("MR ROLL", rollData)
2022-07-10 10:22:04 +02:00
if (isInit) {
rollData.title = "MR / Initiative"
}
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("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);
2022-03-09 18:12:40 +01:00
this.checkAndPrepareEquipment(armor);
2022-01-14 18:20:15 +01:00
rollData.mode = "armor"
rollData.armor = armor
rollData.title = `Armor : ${armor.name}`
rollData.isResistance = true;
2022-03-06 20:07:41 +01:00
rollData.img = armor.img
2022-07-13 22:47:07 +02:00
rollData.damageDiceLevel = armor.data.resistance
2022-01-14 18:20:15 +01:00
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}`
2022-03-06 20:07:41 +01:00
rollData.img = power.img
2022-01-14 18:20:15 +01:00
this.startRoll(rollData);
} else {
ui.notifications.warn("Power not found !", powerId);
}
}
2021-12-02 07:38:59 +01:00
}