2021-06-01 06:56:25 +00:00
|
|
|
import { BladesHelpers } from "./blades-helpers.js";
|
|
|
|
|
2020-04-23 16:11:04 +00:00
|
|
|
/**
|
|
|
|
* Extend the basic Item
|
|
|
|
* @extends {Item}
|
|
|
|
*/
|
|
|
|
export class BladesItem extends Item {
|
2020-05-04 10:10:57 +00:00
|
|
|
|
2021-06-01 06:56:25 +00:00
|
|
|
/** @override */
|
|
|
|
async _preCreate( data, options, user ) {
|
|
|
|
await super._preCreate( data, options, user );
|
|
|
|
|
|
|
|
let removeItems = [];
|
|
|
|
if( user.id === game.user.id ) {
|
|
|
|
let actor = this.parent ? this.parent : null;
|
|
|
|
if( actor?.documentName === "Actor" ) {
|
|
|
|
removeItems = BladesHelpers.removeDuplicatedItemType( data, actor );
|
|
|
|
}
|
|
|
|
if( removeItems.length !== 0 ) {
|
|
|
|
await actor.deleteEmbeddedDocuments( "Item", removeItems );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
2020-05-04 10:10:57 +00:00
|
|
|
/* override */
|
|
|
|
prepareData() {
|
|
|
|
|
|
|
|
super.prepareData();
|
2021-10-22 00:42:46 +00:00
|
|
|
|
2022-09-03 15:44:26 +00:00
|
|
|
const item_data = this.system;
|
2020-05-04 10:10:57 +00:00
|
|
|
|
2022-09-03 15:44:26 +00:00
|
|
|
if (this.type === "cohort") {
|
2021-10-22 00:42:46 +00:00
|
|
|
|
2022-09-03 15:44:26 +00:00
|
|
|
this._prepareCohort(item_data);
|
2021-10-22 00:42:46 +00:00
|
|
|
|
2020-05-04 10:10:57 +00:00
|
|
|
}
|
2021-08-07 18:28:16 +00:00
|
|
|
|
2022-09-03 15:44:26 +00:00
|
|
|
if (this.type === "faction") {
|
|
|
|
if( !item_data.goal_1_clock_value ){ this.system.goal_1_clock_value = 0 }
|
|
|
|
if( item_data.goal_1_clock_max === 0 ){ this.system.goal_1_clock_max = 4 }
|
|
|
|
if( !item_data.goal_2_clock_value ){ this.system.goal_2_clock_value = 0 }
|
|
|
|
if( item_data.goal_2_clock_max === 0 ){ this.system.goal_2_clock_max = 4 }
|
|
|
|
this.system.size_list_1 = BladesHelpers.createListOfClockSizes( game.system.bladesClocks.sizes, this.system.goal_1_clock_max, parseInt( this.system.goal_1_clock_max ) );
|
|
|
|
this.system.size_list_2 = BladesHelpers.createListOfClockSizes( game.system.bladesClocks.sizes, this.system.goal_2_clock_max, parseInt( this.system.goal_2_clock_max ) );
|
2021-08-07 18:28:16 +00:00
|
|
|
}
|
|
|
|
|
2020-05-04 10:10:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepares Cohort data
|
|
|
|
*
|
2021-10-22 00:42:46 +00:00
|
|
|
* @param {object} data
|
2020-05-04 10:10:57 +00:00
|
|
|
*/
|
2022-09-03 15:44:26 +00:00
|
|
|
_prepareCohort(item_data) {
|
2020-05-04 10:10:57 +00:00
|
|
|
|
|
|
|
let quality = 0;
|
|
|
|
let scale = 0;
|
|
|
|
|
|
|
|
// Adds Scale and Quality
|
2022-09-03 15:44:26 +00:00
|
|
|
if (this.actor?.system) {
|
|
|
|
switch (item_data.cohort) {
|
2020-05-04 10:10:57 +00:00
|
|
|
case "Gang":
|
2022-09-03 15:44:26 +00:00
|
|
|
scale = parseInt(this.actor.system.tier);
|
|
|
|
quality = parseInt(this.actor.system.tier);
|
2020-05-04 10:10:57 +00:00
|
|
|
break;
|
|
|
|
case "Expert":
|
2021-10-22 00:42:46 +00:00
|
|
|
scale = 0;
|
2022-09-03 15:44:26 +00:00
|
|
|
quality = parseInt(this.actor.system.tier) + 1;
|
2020-05-04 10:10:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-03 15:44:26 +00:00
|
|
|
this.system.scale = scale;
|
|
|
|
this.system.quality = quality;
|
2020-05-04 12:33:08 +00:00
|
|
|
}
|
2020-04-23 16:11:04 +00:00
|
|
|
}
|