2022-03-13 16:17:04 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
import { Imperium5Utility } from "./imperium5-utility.js";
|
|
|
|
import { Imperium5RollDialog } from "./imperium5-roll-dialog.js";
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/**
|
|
|
|
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
|
|
|
|
* @extends {Actor}
|
|
|
|
*/
|
2022-03-19 09:30:00 +01:00
|
|
|
export class Imperium5Actor extends Actor {
|
2022-03-13 16:17:04 +01:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.type == 'character') {
|
2022-03-19 09:30:00 +01:00
|
|
|
|
2022-03-13 16:17:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return super.create(data, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
prepareBaseData() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async prepareData() {
|
|
|
|
super.prepareData();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
prepareDerivedData() {
|
|
|
|
|
|
|
|
if (this.type == 'character') {
|
2022-03-19 09:30:00 +01:00
|
|
|
//this.data.data.encCapacity = this.getEncumbranceCapacity()
|
|
|
|
//this.buildContainerTree()
|
2022-03-13 16:17:04 +01:00
|
|
|
}
|
2022-03-19 09:30:00 +01:00
|
|
|
console.log("Acteur : ", this)
|
2022-03-13 16:17:04 +01:00
|
|
|
super.prepareDerivedData();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_preUpdate(changed, options, user) {
|
|
|
|
|
|
|
|
super._preUpdate(changed, options, user);
|
|
|
|
}
|
2022-03-19 09:30:00 +01:00
|
|
|
|
2022-03-13 16:17:04 +01:00
|
|
|
/* -------------------------------------------- */
|
2022-03-19 09:30:00 +01:00
|
|
|
getArchetype() {
|
|
|
|
let item = duplicate( this.data.items.find( it => it.type == "archetype") || [])
|
|
|
|
return item
|
2022-03-13 16:17:04 +01:00
|
|
|
}
|
2022-03-19 09:30:00 +01:00
|
|
|
getSpecialites() {
|
|
|
|
let item = duplicate(this.data.items.filter( it => it.type == "specialite") || [] )
|
|
|
|
return item
|
2022-03-13 16:17:04 +01:00
|
|
|
}
|
2022-03-19 09:30:00 +01:00
|
|
|
getFamiliarites() {
|
|
|
|
let item = duplicate(this.data.items.filter( it => it.type == "familiarite") || [] )
|
|
|
|
return item
|
2022-03-13 16:17:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
getItemById(id) {
|
2022-03-19 09:30:00 +01:00
|
|
|
let item = this.data.items.find(item => item.id == id)
|
2022-03-13 16:17:04 +01:00
|
|
|
if (item) {
|
|
|
|
item = duplicate(item)
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
compareName(a, b) {
|
|
|
|
if (a.name < b.name) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.name > b.name) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
getInitiativeScore(combatId, combatantId) {
|
|
|
|
if (this.type == 'character') {
|
|
|
|
this.rollMR(true, combatId, combatantId)
|
|
|
|
}
|
|
|
|
console.log("Init required !!!!")
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
getSubActors() {
|
|
|
|
let subActors = [];
|
|
|
|
for (let id of this.data.data.subactors) {
|
|
|
|
subActors.push(duplicate(game.actors.get(id)))
|
|
|
|
}
|
|
|
|
return subActors;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async addSubActor(subActorId) {
|
|
|
|
let subActors = duplicate(this.data.data.subactors);
|
|
|
|
subActors.push(subActorId);
|
|
|
|
await this.update({ 'data.subactors': subActors });
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async delSubActor(subActorId) {
|
|
|
|
let newArray = [];
|
|
|
|
for (let id of this.data.data.subactors) {
|
|
|
|
if (id != subActorId) {
|
|
|
|
newArray.push(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await this.update({ 'data.subactors': newArray });
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
syncRoll(rollData) {
|
2022-03-19 09:30:00 +01:00
|
|
|
let linkedRollId = Imperium5Utility.getDefenseState(this.id);
|
2022-03-13 16:17:04 +01:00
|
|
|
if (linkedRollId) {
|
|
|
|
rollData.linkedRollId = linkedRollId;
|
|
|
|
}
|
|
|
|
this.lastRollId = rollData.rollId;
|
2022-03-19 09:30:00 +01:00
|
|
|
Imperium5Utility.saveRollData(rollData);
|
2022-03-13 16:17:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async deleteAllItemsByType(itemType) {
|
|
|
|
let items = this.data.items.filter(item => item.type == itemType);
|
|
|
|
await this.deleteEmbeddedDocuments('Item', items);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async addItemWithoutDuplicate(newItem) {
|
|
|
|
let item = this.data.items.find(item => item.type == newItem.type && item.name.toLowerCase() == newItem.name.toLowerCase())
|
|
|
|
if (!item) {
|
|
|
|
await this.createEmbeddedDocuments('Item', [newItem]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async incDecQuantity(objetId, incDec = 0) {
|
|
|
|
let objetQ = this.data.items.get(objetId)
|
|
|
|
if (objetQ) {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/* 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" || effect.data.specaffected.length > 0)
|
|
|
|
&& effect.data.stataffected != "special") {
|
|
|
|
if (effect.data.effectstatlevel) {
|
|
|
|
effect.data.effectlevel = this.data.data.statistics[effect.data.effectstat].value
|
|
|
|
}
|
|
|
|
rollData.effectsList.push({ label: effect.name, type: "effect", applied: false, effect: effect, value: effect.data.effectlevel })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
getCommonRollData(statKey = undefined, useShield = false) {
|
2022-03-19 09:30:00 +01:00
|
|
|
let rollData = Imperium5Utility.getBasicRollData()
|
2022-03-13 16:17:04 +01:00
|
|
|
rollData.alias = this.name
|
|
|
|
rollData.actorImg = this.img
|
|
|
|
rollData.actorId = this.id
|
|
|
|
rollData.img = this.img
|
|
|
|
|
|
|
|
return rollData
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async startRoll(rollData) {
|
2022-03-19 09:30:00 +01:00
|
|
|
this.syncRoll(rollData)
|
|
|
|
let rollDialog = await Imperium5RollDialog.create(this, rollData)
|
|
|
|
console.log(rollDialog)
|
|
|
|
rollDialog.render(true)
|
2022-03-13 16:17:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|