2020-11-28 19:12:19 +01:00
|
|
|
import KHDiceRoller from "../helpers/dice-helper.js"
|
2020-11-30 06:23:35 +01:00
|
|
|
import ActorHelpers from "../helpers/actor-helper.js";
|
2020-11-28 19:12:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Extend the basic ActorSheet with some very simple modifications
|
|
|
|
* @extends {ActorSheet}
|
|
|
|
*/
|
|
|
|
export class ActorSheetKH extends ActorSheet {
|
|
|
|
khRoller = new KHDiceRoller();
|
|
|
|
|
|
|
|
/** @override */
|
|
|
|
static get defaultOptions() {
|
2020-11-30 06:23:35 +01:00
|
|
|
if(game.settings.get("kopparhavet", "gameSystem") === "hjaltarnas-tid") {
|
|
|
|
return mergeObject(super.defaultOptions, {
|
|
|
|
classes: ["kopparhavet", "sheet", "actor"],
|
|
|
|
template: "systems/kopparhavet/templates/actors/ht-character-sheet.html",
|
|
|
|
width: 710,
|
|
|
|
height: 650,
|
|
|
|
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "main" }],
|
|
|
|
scrollY: [".skills-tab .skills", ".talent-tab .items"],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-28 19:12:19 +01:00
|
|
|
return mergeObject(super.defaultOptions, {
|
|
|
|
classes: ["kopparhavet", "sheet", "actor"],
|
|
|
|
template: "systems/kopparhavet/templates/actors/character-sheet.html",
|
|
|
|
width: 710,
|
|
|
|
height: 650,
|
2020-11-30 06:23:35 +01:00
|
|
|
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "main" }],
|
2020-11-28 19:12:19 +01:00
|
|
|
scrollY: [".skills-tab .skills", ".talent-tab .items"],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @override */
|
|
|
|
get template() {
|
|
|
|
const path = "systems/kopparhavet/templates/actors";
|
2020-11-30 06:23:35 +01:00
|
|
|
let prefix = "";
|
|
|
|
|
|
|
|
if(game.settings.get("kopparhavet", "gameSystem") === "hjaltarnas-tid") {
|
|
|
|
prefix = "ht-";
|
|
|
|
}
|
|
|
|
|
|
|
|
return `${path}/${prefix}${this.actor.data.type}-sheet.html`;
|
2020-11-28 19:12:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
|
|
|
/** @override */
|
|
|
|
getData() {
|
|
|
|
const data = super.getData();
|
|
|
|
data.dtypes = ["String", "Number", "Boolean"];
|
|
|
|
|
|
|
|
// Prepare items.
|
|
|
|
this._prepareCharacterItems(data);
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Organize and classify Items for Character sheets.
|
|
|
|
* @param {Object} actorData The actor to prepare.
|
|
|
|
* @return {undefined}
|
|
|
|
*/
|
|
|
|
_prepareCharacterItems(sheetData) {
|
|
|
|
const actorData = sheetData.actor;
|
|
|
|
|
|
|
|
// Initialize containers.
|
|
|
|
const skills = [];
|
|
|
|
const talents = [];
|
|
|
|
const weapons = [];
|
|
|
|
const armor = [];
|
|
|
|
const gear = [];
|
|
|
|
const spells = [];
|
|
|
|
const attacks = [];
|
2020-12-04 20:50:46 +01:00
|
|
|
const shipweapons = [];
|
|
|
|
const shiptalents = [];
|
2020-11-28 19:12:19 +01:00
|
|
|
|
|
|
|
// Iterate through items, allocating to containers
|
|
|
|
for (let i of sheetData.items) {
|
|
|
|
i.img = i.img || DEFAULT_TOKEN;
|
|
|
|
|
|
|
|
// Append to gear.
|
|
|
|
if (i.type === "skill") {
|
|
|
|
i.hasBase = i.data.type.value === "base";
|
|
|
|
i.hasAdventure = i.data.type.value === "adventure";
|
|
|
|
i.hasCombat = i.data.type.value === "combat";
|
|
|
|
|
|
|
|
skills.push(i);
|
|
|
|
} else if (i.type === "talent") {
|
|
|
|
talents.push(i);
|
|
|
|
} else if (i.type === "weapon") {
|
|
|
|
weapons.push(i);
|
|
|
|
} else if (i.type === "armor") {
|
|
|
|
armor.push(i);
|
|
|
|
} else if (i.type === "gear") {
|
|
|
|
gear.push(i);
|
|
|
|
} else if (i.type === "spell") {
|
|
|
|
spells.push(i);
|
|
|
|
} else if (i.type === "adversaryAttack") {
|
|
|
|
attacks.push(i);
|
2020-12-04 20:50:46 +01:00
|
|
|
} else if (i.type === "shiptalent") {
|
|
|
|
shiptalents.push(i);
|
|
|
|
} else if (i.type === "shipweapon") {
|
|
|
|
shipweapons.push(i);
|
2020-11-28 19:12:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-29 14:43:53 +01:00
|
|
|
skills.sort((a,b) => (a.name > b.name) ? 1 : ((b.name > a.name) ? -1 : 0));
|
|
|
|
|
2020-11-28 19:12:19 +01:00
|
|
|
// Assign and return
|
|
|
|
actorData.skills = skills;
|
|
|
|
actorData.talents = talents;
|
|
|
|
actorData.weapons = weapons;
|
|
|
|
actorData.armor = armor;
|
|
|
|
actorData.gear = gear;
|
|
|
|
actorData.spells = spells;
|
|
|
|
actorData.attacks = attacks;
|
2020-12-04 20:50:46 +01:00
|
|
|
actorData.shiptalents = shiptalents;
|
|
|
|
actorData.shipweapons = shipweapons;
|
2020-11-28 19:12:19 +01:00
|
|
|
}
|
|
|
|
|
2020-12-04 20:50:46 +01:00
|
|
|
|
2020-11-28 19:12:19 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
|
|
|
/** @override */
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
|
|
|
|
|
|
|
/* Send item Details to chat */
|
|
|
|
new ContextMenu(html, "li.item", [
|
|
|
|
{
|
|
|
|
name: game.i18n.localize("MENU.SENTTOCHAT"),
|
|
|
|
icon: '<i class="far fa-comment"></i>',
|
|
|
|
callback: (li) => {
|
|
|
|
let itemId = li.data("itemId");
|
|
|
|
this._itemDetailsToChat(itemId);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
new ContextMenu(html, "div.item", [
|
|
|
|
{
|
|
|
|
name: game.i18n.localize("MENU.SENTTOCHAT"),
|
|
|
|
icon: '<i class="far fa-comment"></i>',
|
|
|
|
callback: (li) => {
|
|
|
|
let itemId = li.data("itemId");
|
|
|
|
this._itemDetailsToChat(itemId);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
2020-12-01 17:30:39 +01:00
|
|
|
new ContextMenu(html, "li.item-weapon", [
|
|
|
|
{
|
|
|
|
name: game.i18n.localize("MENU.SHOWROLLDIALOG"),
|
|
|
|
icon: '<i class="far dice"></i>',
|
|
|
|
callback: (li) => {
|
|
|
|
let itemId = li.data("itemId");
|
2021-07-28 13:08:19 +02:00
|
|
|
let _item = this.actor.items.find((element) => element.id == itemId);
|
2020-12-01 17:30:39 +01:00
|
|
|
|
|
|
|
// Retrieve skill based on name
|
|
|
|
let skill = this.actor.items.find((element) => element.name === _item.data.data.skill.value);
|
|
|
|
|
|
|
|
let skillName = skill.name
|
|
|
|
let skillValue = skill.data.data.value
|
|
|
|
let showValue = false
|
|
|
|
|
|
|
|
if(this.actor.data.type === "character") {
|
|
|
|
showValue = true
|
|
|
|
}
|
|
|
|
|
|
|
|
this.khRoller.rollSkillDialogInChat(skillName, skillValue, showValue, this.actor)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: game.i18n.localize("MENU.SENTTOCHAT"),
|
|
|
|
icon: '<i class="far fa-comment"></i>',
|
|
|
|
callback: (li) => {
|
|
|
|
let itemId = li.data("itemId");
|
|
|
|
this._itemDetailsToChat(itemId);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
new ContextMenu(html, "li.item-skill", [
|
|
|
|
{
|
|
|
|
name: game.i18n.localize("MENU.SHOWROLLDIALOG"),
|
|
|
|
icon: '<i class="far dice"></i>',
|
|
|
|
callback: (li) => {
|
|
|
|
let itemId = li.data("itemId");
|
2021-07-28 13:08:19 +02:00
|
|
|
let _item = this.actor.items.find((element) => element.id == itemId);
|
2020-12-01 17:30:39 +01:00
|
|
|
|
|
|
|
let skillName = _item.name
|
|
|
|
let skillValue = _item.data.data.value
|
|
|
|
let showValue = false
|
|
|
|
|
|
|
|
if(this.actor.data.type === "character") {
|
|
|
|
showValue = true
|
|
|
|
}
|
|
|
|
|
|
|
|
this.khRoller.rollSkillDialogInChat(skillName, skillValue, showValue, this.actor)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: game.i18n.localize("MENU.SENTTOCHAT"),
|
|
|
|
icon: '<i class="far fa-comment"></i>',
|
|
|
|
callback: (li) => {
|
|
|
|
let itemId = li.data("itemId");
|
|
|
|
this._itemDetailsToChat(itemId);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
new ContextMenu(html, "li.item-spell", [
|
|
|
|
{
|
|
|
|
name: game.i18n.localize("MENU.SHOWROLLDIALOG"),
|
|
|
|
icon: '<i class="far dice"></i>',
|
|
|
|
callback: (li) => {
|
2021-07-28 13:08:19 +02:00
|
|
|
let itemId = li.data("item-id");
|
|
|
|
let _item = this.actor.items.find((element) => element.id == itemId);
|
2020-12-01 17:30:39 +01:00
|
|
|
|
|
|
|
if (!_item) {
|
|
|
|
_item = game.items.get(itemId);
|
|
|
|
|
|
|
|
if (!_item) {
|
2021-07-28 13:08:19 +02:00
|
|
|
console.log("IMPORT ERROR 1")
|
2020-12-01 17:30:39 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let showValue = false
|
|
|
|
let difficulty = 0
|
|
|
|
|
|
|
|
if(this.actor.data.type === "character") {
|
|
|
|
showValue = true
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (_item.data.data.difficulty.value) {
|
|
|
|
case "simple":
|
|
|
|
difficulty = 5
|
|
|
|
break;
|
|
|
|
case "easy":
|
|
|
|
difficulty = 2
|
|
|
|
break;
|
|
|
|
case "hard":
|
|
|
|
difficulty = -2
|
|
|
|
break;
|
|
|
|
case "daunting":
|
|
|
|
difficulty = -5
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_item.data.data.roll.value === "roll" || _item.data.data.roll.value === "attackroll") {
|
|
|
|
// Retrieve skill based on name
|
|
|
|
let skill = this.actor.items.find((element) => element.name === _item.data.data.roll.skill);
|
|
|
|
|
|
|
|
let skillName = _item.name
|
|
|
|
let skillValue = skill.data.data.value
|
|
|
|
|
|
|
|
if(this.actor.data.type === "character") {
|
|
|
|
skillName = _item.name + " (" + skill.name + ")"
|
|
|
|
}
|
|
|
|
|
|
|
|
this.khRoller.rollSkillDialogInChat(skillName, skillValue, showValue, this.actor, difficulty)
|
|
|
|
} else if(_item.data.data.roll.value === "opposite") {
|
|
|
|
// Retrieve skill based on name
|
|
|
|
let skill = this.actor.items.find((element) => element.name === _item.data.data.roll.skill);
|
|
|
|
|
|
|
|
let skillName = _item.name
|
|
|
|
let skillValue = skill.data.data.value
|
|
|
|
|
|
|
|
if(this.actor.data.type === "character") {
|
|
|
|
skillName = _item.name + " (" + skill.name + ")"
|
|
|
|
}
|
|
|
|
|
2021-03-19 05:22:29 +01:00
|
|
|
let opposite = []
|
|
|
|
// Retrieve skill based on name
|
|
|
|
|
|
|
|
if(_item.data.data.roll.oppositeskill !== "") {
|
|
|
|
let skill1 = this.actor.items.find((element) => element.name === _item.data.data.roll.oppositeskill);
|
|
|
|
opposite.push(skill1.name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_item.data.data.roll.oppositeskilltwo !== "") {
|
|
|
|
let skill2 = this.actor.items.find((element) => element.name === _item.data.data.roll.oppositeskilltwo);
|
|
|
|
opposite.push(skill2.name)
|
|
|
|
}
|
|
|
|
|
|
|
|
this.khRoller.rollSkillDialogInChat(skillName, skillValue, showValue, this.actor, difficulty, opposite)
|
2020-12-01 17:30:39 +01:00
|
|
|
} else if(_item.data.data.roll.value === "ritual") {
|
2021-03-19 05:22:29 +01:00
|
|
|
let skills = []
|
|
|
|
|
|
|
|
if(_item.data.data.roll.ritual.skillone !== "") {
|
|
|
|
let skill1 = this.actor.items.find((element) => element.name === _item.data.data.roll.ritual.skillone);
|
|
|
|
|
|
|
|
skills.push({
|
|
|
|
name: skill1.name,
|
|
|
|
value: skill1.data.data.value
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_item.data.data.roll.ritual.skilltwo !== "") {
|
|
|
|
let skill2 = this.actor.items.find((element) => element.name === _item.data.data.roll.ritual.skilltwo);
|
|
|
|
|
|
|
|
skills.push({
|
|
|
|
name: skill2.name,
|
|
|
|
value: skill2.data.data.value
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_item.data.data.roll.ritual.skillthree !== "") {
|
|
|
|
let skill3 = this.actor.items.find((element) => element.name === _item.data.data.roll.ritual.skillthree);
|
|
|
|
|
|
|
|
skills.push({
|
|
|
|
name: skill3.name,
|
|
|
|
value: skill3.data.data.value
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_item.data.data.roll.ritual.skillfour !== "") {
|
|
|
|
let skill4 = this.actor.items.find((element) => element.name === _item.data.data.roll.ritual.skillfour);
|
|
|
|
|
|
|
|
skills.push({
|
|
|
|
name: skill4.name,
|
|
|
|
value: skill4.data.data.value
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_item.data.data.roll.ritual.skillfive !== "") {
|
|
|
|
let skill5 = this.actor.items.find((element) => element.name === _item.data.data.roll.ritual.skillfive);
|
|
|
|
|
|
|
|
skills.push({
|
|
|
|
name: skill5.name,
|
|
|
|
value: skill5.data.data.value
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.khRoller.rollSkillChallangeDialogInChat(_item.name, skills, showValue, this.actor, difficulty)
|
2020-12-01 17:30:39 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: game.i18n.localize("MENU.SENTTOCHAT"),
|
|
|
|
icon: '<i class="far fa-comment"></i>',
|
|
|
|
callback: (li) => {
|
|
|
|
let itemId = li.data("itemId");
|
|
|
|
this._itemDetailsToChat(itemId);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
new ContextMenu(html, "li.item-attack", [
|
|
|
|
{
|
|
|
|
name: game.i18n.localize("MENU.SHOWROLLDIALOG"),
|
|
|
|
icon: '<i class="far dice"></i>',
|
|
|
|
callback: (li) => {
|
|
|
|
let skillValue = li.data("ability");
|
|
|
|
let skillName = "ITEM.ATTACK";
|
|
|
|
let showValue = false
|
|
|
|
|
|
|
|
if(this.actor.data.type === "character") {
|
|
|
|
showValue = true
|
|
|
|
}
|
|
|
|
|
|
|
|
this.khRoller.rollSkillDialogInChat(skillName, skillValue, showValue, this.actor)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: game.i18n.localize("MENU.SENTTOCHAT"),
|
|
|
|
icon: '<i class="far fa-comment"></i>',
|
|
|
|
callback: (li) => {
|
|
|
|
let itemId = li.data("itemId");
|
|
|
|
this._itemDetailsToChat(itemId);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
new ContextMenu(html, "li.item-defence", [
|
|
|
|
{
|
|
|
|
name: game.i18n.localize("MENU.SHOWROLLDIALOG"),
|
|
|
|
icon: '<i class="far dice"></i>',
|
|
|
|
callback: (li) => {
|
|
|
|
const skillValue = li.data("defence");
|
|
|
|
|
|
|
|
let skillName = "ADVERSARY.DEFENCE";
|
|
|
|
|
|
|
|
this.khRoller.rollSkillDialogInChat(skillName, skillValue, false, this.actor)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2020-11-28 19:12:19 +01:00
|
|
|
html.find(".feature").click(async (ev) => {
|
|
|
|
const featureName = $(ev.currentTarget).data("feature");
|
|
|
|
const featureValue = this.actor.data.data.feature[featureName].value;
|
|
|
|
if (featureName === "one") {
|
|
|
|
this.actor.update({ "data.feature.one.value": !featureValue });
|
|
|
|
} else if (featureName === "two") {
|
|
|
|
this.actor.update({ "data.feature.two.value": !featureValue });
|
|
|
|
} else if (featureName === "three") {
|
|
|
|
this.actor.update({ "data.feature.three.value": !featureValue });
|
|
|
|
} else if (featureName === "four") {
|
|
|
|
this.actor.update({ "data.feature.four.value": !featureValue });
|
|
|
|
}
|
|
|
|
this._render();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Delete Inventory Item
|
|
|
|
html.find(".item-delete").click((ev) => {
|
2020-12-01 17:30:39 +01:00
|
|
|
let parent = $(ev.currentTarget).data("parent")
|
|
|
|
const li = $(ev.currentTarget).parents(parent);
|
2021-07-28 13:08:19 +02:00
|
|
|
const item = this.actor.items.get(li.data("itemId"));
|
2020-12-01 17:30:39 +01:00
|
|
|
|
|
|
|
if(item) {
|
|
|
|
if (item.type === "armor") {
|
|
|
|
let initValue = -1
|
|
|
|
|
|
|
|
if (item.data.data.equipable.equipped) {
|
|
|
|
initValue = 4
|
|
|
|
|
|
|
|
this.actor.items.map((i) => {
|
|
|
|
if (i.type === "armor") {
|
2021-07-28 13:08:19 +02:00
|
|
|
if (i.id !== item.id && i.data.data.equipable.equipped && i.data?.data?.modifications) {
|
2020-12-01 17:30:39 +01:00
|
|
|
for (let k of Object.keys(i.data.data.modifications)) {
|
|
|
|
if (i.data.data.modifications[k].modtype === "init") {
|
|
|
|
initValue = i.data.data.modifications[k].value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (initValue > 0) {
|
|
|
|
this.actor.update({["data.combat.init"]: initValue});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-28 19:12:19 +01:00
|
|
|
|
|
|
|
this.actor.deleteOwnedItem(li.data("itemId"));
|
|
|
|
|
|
|
|
li.slideUp(200, () => this.render(false));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Edit Inventory Item
|
|
|
|
html.find(".item-edit").click(async (ev) => {
|
2020-12-01 17:30:39 +01:00
|
|
|
let parent = $(ev.currentTarget).data("parent")
|
|
|
|
let li = $(ev.currentTarget).parents(parent);
|
2020-11-28 19:12:19 +01:00
|
|
|
let itemId = li.data("itemId");
|
2021-07-28 13:08:19 +02:00
|
|
|
let item = this.actor.items.get(itemId);
|
2020-11-28 19:12:19 +01:00
|
|
|
|
|
|
|
if (!item) {
|
|
|
|
item = game.items.get(itemId);
|
|
|
|
|
|
|
|
if (!item) {
|
2021-07-28 13:08:19 +02:00
|
|
|
console.log("IMPORT ERROR 2")
|
2020-11-28 19:12:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item?.sheet) {
|
|
|
|
item.sheet.render(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/* Roll spell cost */
|
|
|
|
html.find(".roll-spell-cost").click((ev) => {
|
2020-12-01 17:30:39 +01:00
|
|
|
const li = $(ev.currentTarget).parents(".item-spell");
|
2020-11-28 19:12:19 +01:00
|
|
|
let itemId = li.data("itemId");
|
2021-07-28 13:08:19 +02:00
|
|
|
let spell = this.actor.items.get(itemId);
|
2020-11-28 19:12:19 +01:00
|
|
|
|
|
|
|
if (!spell) {
|
|
|
|
spell = game.items.get(itemId);
|
|
|
|
|
|
|
|
if (!spell) {
|
2021-07-28 13:08:19 +02:00
|
|
|
console.log("IMPORT ERROR 3")
|
2020-11-28 19:12:19 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let cost = spell.data.data.cost.value;
|
|
|
|
|
|
|
|
let regex = /([0-9]*)t([0-9]*)/g;
|
|
|
|
let regexMatch;
|
|
|
|
|
|
|
|
while (regexMatch = regex.exec(cost.toLowerCase())) {
|
|
|
|
this.khRoller.rollSpellCostInChat(regexMatch[1], this.actor)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-12-01 17:30:39 +01:00
|
|
|
html.find(".roll-spell-skill").click((ev) => {
|
|
|
|
const li = $(ev.currentTarget).parents(".item-spell");
|
2021-07-28 13:08:19 +02:00
|
|
|
let itemId = li.data("item-id");
|
|
|
|
let spell = this.actor.items.get(itemId);
|
2020-12-01 17:30:39 +01:00
|
|
|
|
|
|
|
if (!spell) {
|
|
|
|
spell = game.items.get(itemId);
|
|
|
|
|
|
|
|
if (!spell) {
|
2021-07-28 13:08:19 +02:00
|
|
|
console.log("IMPORT ERROR 4")
|
2020-12-01 17:30:39 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let showValue = false
|
|
|
|
let difficulty = 0
|
|
|
|
|
|
|
|
if(this.actor.data.type === "character") {
|
|
|
|
showValue = true
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (spell.data.data.difficulty.value) {
|
|
|
|
case "simple":
|
|
|
|
difficulty = 5
|
|
|
|
break;
|
|
|
|
case "easy":
|
|
|
|
difficulty = 2
|
|
|
|
break;
|
|
|
|
case "hard":
|
|
|
|
difficulty = -2
|
|
|
|
break;
|
|
|
|
case "daunting":
|
|
|
|
difficulty = -5
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(spell.data.data.roll.value === "roll" || spell.data.data.roll.value === "attackroll") {
|
|
|
|
// Retrieve skill based on name
|
|
|
|
let skill = this.actor.items.find((element) => element.name === spell.data.data.roll.skill);
|
|
|
|
|
|
|
|
let skillName = spell.name
|
|
|
|
let skillValue = skill.data.data.value
|
|
|
|
|
|
|
|
if(this.actor.data.type === "character") {
|
|
|
|
skillName = spell.name + " (" + skill.name + ")"
|
|
|
|
}
|
|
|
|
|
|
|
|
this.khRoller.rollSkillInChat(skillName, skillValue, showValue, this.actor, difficulty)
|
|
|
|
} else if(spell.data.data.roll.value === "opposite") {
|
2021-03-19 05:22:29 +01:00
|
|
|
let opposite = []
|
2020-12-01 17:30:39 +01:00
|
|
|
// Retrieve skill based on name
|
|
|
|
let skill = this.actor.items.find((element) => element.name === spell.data.data.roll.skill);
|
|
|
|
|
2021-03-19 05:22:29 +01:00
|
|
|
if(spell.data.data.roll.oppositeskill !== "") {
|
|
|
|
let skill1 = this.actor.items.find((element) => element.name === spell.data.data.roll.oppositeskill);
|
|
|
|
opposite.push(skill1.name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if(spell.data.data.roll.oppositeskilltwo !== "") {
|
|
|
|
let skill2 = this.actor.items.find((element) => element.name === spell.data.data.roll.oppositeskilltwo);
|
|
|
|
opposite.push(skill2.name)
|
|
|
|
}
|
|
|
|
|
2020-12-01 17:30:39 +01:00
|
|
|
let skillName = spell.name
|
|
|
|
let skillValue = skill.data.data.value
|
|
|
|
|
|
|
|
if(this.actor.data.type === "character") {
|
|
|
|
skillName = spell.name + " (" + skill.name + ")"
|
|
|
|
}
|
|
|
|
|
2021-03-19 05:22:29 +01:00
|
|
|
this.khRoller.rollSkillInChat(skillName, skillValue, showValue, this.actor, difficulty, opposite)
|
2020-12-01 17:30:39 +01:00
|
|
|
} else if(spell.data.data.roll.value === "ritual") {
|
2021-03-19 05:22:29 +01:00
|
|
|
let skill1, skill2, skill3, skill4, skill5;
|
|
|
|
let skills = []
|
|
|
|
|
|
|
|
// Retrieve skill based on name
|
|
|
|
if(spell.data.data.roll.ritual.skillone !== "") {
|
|
|
|
skill1 = this.actor.items.find((element) => element.name === spell.data.data.roll.ritual.skillone);
|
|
|
|
|
|
|
|
skills.push({
|
|
|
|
name: skill1.name,
|
|
|
|
value: skill1.data.data.value
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if(spell.data.data.roll.ritual.skilltwo !== "") {
|
|
|
|
skill2 = this.actor.items.find((element) => element.name === spell.data.data.roll.ritual.skilltwo);
|
|
|
|
|
|
|
|
skills.push({
|
|
|
|
name: skill2.name,
|
|
|
|
value: skill2.data.data.value
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if(spell.data.data.roll.ritual.skillthree !== "") {
|
|
|
|
skill3 = this.actor.items.find((element) => element.name === spell.data.data.roll.ritual.skillthree);
|
|
|
|
|
|
|
|
skills.push({
|
|
|
|
name: skill3.name,
|
|
|
|
value: skill3.data.data.value
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if(spell.data.data.roll.ritual.skillfour !== "") {
|
|
|
|
skill4 = this.actor.items.find((element) => element.name === spell.data.data.roll.ritual.skillfour);
|
|
|
|
|
|
|
|
skills.push({
|
|
|
|
name: skill4.name,
|
|
|
|
value: skill4.data.data.value
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if(spell.data.data.roll.ritual.skillfive !== "") {
|
|
|
|
skill5 = this.actor.items.find((element) => element.name === spell.data.data.roll.ritual.skillfive);
|
|
|
|
|
|
|
|
skills.push({
|
|
|
|
name: skill5.name,
|
|
|
|
value: skill5.data.data.value
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
let skillName = spell.name
|
|
|
|
|
|
|
|
this.khRoller.rollSkillRitualInChat(skillName, skills, showValue, this.actor, difficulty)
|
2020-12-01 17:30:39 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-11-28 19:12:19 +01:00
|
|
|
/* Roll skill */
|
|
|
|
html.find(".roll-skill").click((ev) => {
|
2020-12-01 17:30:39 +01:00
|
|
|
const li = $(ev.currentTarget).parents(".item-skill");
|
2021-07-28 13:08:19 +02:00
|
|
|
let itemId = li.data("item-id");
|
|
|
|
let _item = this.actor.items.find((element) => element.id === itemId);
|
|
|
|
|
|
|
|
console.log(li)
|
|
|
|
console.log(li.data)
|
|
|
|
console.log(itemId)
|
|
|
|
console.log(_item)
|
2020-11-28 19:12:19 +01:00
|
|
|
|
|
|
|
let skillName = _item.name
|
|
|
|
let skillValue = _item.data.data.value
|
|
|
|
let showValue = false
|
|
|
|
|
|
|
|
if(this.actor.data.type === "character") {
|
|
|
|
showValue = true
|
|
|
|
}
|
|
|
|
|
|
|
|
this.khRoller.rollSkillInChat(skillName, skillValue, showValue, this.actor)
|
|
|
|
});
|
|
|
|
|
|
|
|
/* Roll weapon skill */
|
|
|
|
html.find(".roll-weapon-skill").click((ev) => {
|
2020-12-01 17:30:39 +01:00
|
|
|
const li = $(ev.currentTarget).parents(".item-weapon");
|
2020-11-28 19:12:19 +01:00
|
|
|
let itemId = li.data("itemId");
|
2021-07-28 13:08:19 +02:00
|
|
|
let weapon = this.actor.items.get(itemId);
|
2020-11-28 19:12:19 +01:00
|
|
|
|
|
|
|
if (!weapon) {
|
|
|
|
weapon = game.items.get(itemId);
|
|
|
|
|
|
|
|
if (!weapon) {
|
2021-07-28 13:08:19 +02:00
|
|
|
console.log("IMPORT ERROR 5")
|
2020-11-28 19:12:19 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve skill based on name
|
|
|
|
let skill = this.actor.items.find((element) => element.name === weapon.data.data.skill.value);
|
|
|
|
|
|
|
|
let skillName = skill.name
|
|
|
|
let skillValue = skill.data.data.value
|
|
|
|
let showValue = false
|
|
|
|
|
|
|
|
if(this.actor.data.type === "character") {
|
|
|
|
showValue = true
|
|
|
|
}
|
|
|
|
|
|
|
|
this.khRoller.rollSkillInChat(skillName, skillValue, showValue, this.actor)
|
|
|
|
});
|
|
|
|
|
|
|
|
/* Roll weapon damage */
|
|
|
|
html.find(".roll-damage").click((ev) => {
|
2020-12-01 17:30:39 +01:00
|
|
|
const li = $(ev.currentTarget).parents(".item-weapon");
|
2020-11-28 19:12:19 +01:00
|
|
|
let itemId = li.data("itemId");
|
2021-07-28 13:08:19 +02:00
|
|
|
let weapon = this.actor.items.get(itemId);
|
2020-11-28 19:12:19 +01:00
|
|
|
|
|
|
|
if (!weapon) {
|
|
|
|
weapon = game.items.get(itemId);
|
|
|
|
|
|
|
|
if (!weapon) {
|
2021-07-28 13:08:19 +02:00
|
|
|
console.log("IMPORT ERROR 6")
|
2020-11-28 19:12:19 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let damage = weapon.data.data.damage.value;
|
|
|
|
|
|
|
|
let regex = /([0-9]*)t([0-9]*)/g;
|
|
|
|
let regexMatch;
|
|
|
|
|
|
|
|
while (regexMatch = regex.exec(damage.toLowerCase())) {
|
|
|
|
this.khRoller.rollDamageInChat(regexMatch[1], this.actor)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/* Roll armor */
|
|
|
|
html.find(".roll-armor").click((ev) => {
|
|
|
|
const li = $(ev.currentTarget).parents(".item");
|
|
|
|
let itemId = li.data("itemId");
|
2021-07-28 13:08:19 +02:00
|
|
|
let armor = this.actor.items.get(itemId);
|
2020-11-28 19:12:19 +01:00
|
|
|
|
|
|
|
if (!armor) {
|
|
|
|
armor = game.items.get(itemId);
|
|
|
|
|
|
|
|
if (!armor) {
|
2021-07-28 13:08:19 +02:00
|
|
|
console.log("IMPORT ERROR 7")
|
2020-11-28 19:12:19 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let defence = armor.data.data.defence.value;
|
|
|
|
let hasHelmet = false;
|
|
|
|
|
2020-11-30 06:23:35 +01:00
|
|
|
if(game.settings.get("kopparhavet", "gameSystem") === "kopparhavet") {
|
|
|
|
this.actor.items.map((i) => {
|
|
|
|
if (i.type === "armor") {
|
|
|
|
if (i.data.data.equipable.equipped && i.data.data.helmet.value) {
|
|
|
|
if (CONFIG.KH.armor_types[i.data.data.type.value]?.ac >= CONFIG.KH.armor_types[armor.data.data.type.value]?.ac) {
|
|
|
|
hasHelmet = true
|
|
|
|
}
|
2020-11-28 19:12:19 +01:00
|
|
|
}
|
|
|
|
}
|
2020-11-30 06:23:35 +01:00
|
|
|
});
|
|
|
|
}
|
2020-11-28 19:12:19 +01:00
|
|
|
|
|
|
|
let regex = /([0-9]*)t([0-9]*)/g;
|
|
|
|
let regexMatch;
|
|
|
|
|
|
|
|
while (regexMatch = regex.exec(defence.toLowerCase())) {
|
|
|
|
this.khRoller.rollArmorInChat(regexMatch[1], hasHelmet, this.actor)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/* Toggle item equipped */
|
|
|
|
html.find(".items .item a.toggle-equipped").click(this._toggleEquippedItem.bind(this));
|
2020-12-01 17:30:39 +01:00
|
|
|
html.find(".items .item-weapon a.toggle-equipped").click(this._toggleEquippedItem.bind(this));
|
2020-11-28 19:12:19 +01:00
|
|
|
|
|
|
|
/* Handle increase of items in inventory */
|
|
|
|
html.find(".item-quantity .quantity.increase").click(this._increaseQuantity.bind((this)));
|
|
|
|
|
|
|
|
/* Handle decrease of items in inventory */
|
|
|
|
html.find(".item-quantity .quantity.decrease").click(this._decreaseQuantity.bind(this));
|
|
|
|
|
|
|
|
/* CHANGE SKILL VALUE */
|
|
|
|
html.find(".skill-value").change(this._onChangeSkillValue.bind(this));
|
|
|
|
html.find(".click-skill").click(this._onClickSkill.bind(this));
|
|
|
|
|
|
|
|
/* Adversary specific */
|
|
|
|
html.find(".roll-adversary-attack").click((ev) => {
|
2020-12-01 17:30:39 +01:00
|
|
|
const li = $(ev.currentTarget).parents(".item-attack");
|
2020-11-28 19:12:19 +01:00
|
|
|
let skillValue = li.data("ability");
|
|
|
|
|
|
|
|
let skillName = "ITEM.ATTACK";
|
|
|
|
|
|
|
|
this.khRoller.rollSkillInChat(skillName, skillValue, false, this.actor)
|
|
|
|
});
|
|
|
|
|
2020-12-01 17:30:39 +01:00
|
|
|
html.find(".roll-attack-damage").click((ev) => {
|
|
|
|
const li = $(ev.currentTarget).parents(".item-attack");
|
|
|
|
let itemId = li.data("itemId");
|
2021-07-28 13:08:19 +02:00
|
|
|
let weapon = this.actor.items.get(itemId);
|
2020-12-01 17:30:39 +01:00
|
|
|
|
|
|
|
if (!weapon) {
|
|
|
|
weapon = game.items.get(itemId);
|
|
|
|
|
|
|
|
if (!weapon) {
|
2021-07-28 13:08:19 +02:00
|
|
|
console.log("IMPORT ERROR 8")
|
2020-12-01 17:30:39 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let damage = weapon.data.data.damage.value;
|
|
|
|
|
|
|
|
let regex = /([0-9]*)t([0-9]*)/g;
|
|
|
|
let regexMatch;
|
|
|
|
|
|
|
|
while (regexMatch = regex.exec(damage.toLowerCase())) {
|
|
|
|
this.khRoller.rollDamageInChat(regexMatch[1], this.actor)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-11-28 19:12:19 +01:00
|
|
|
html.find(".roll-defence").click((ev) => {
|
|
|
|
const skillValue = $(ev.currentTarget).data("defence");
|
|
|
|
|
|
|
|
let skillName = "ADVERSARY.DEFENCE";
|
|
|
|
|
|
|
|
this.khRoller.rollSkillInChat(skillName, skillValue, false, this.actor)
|
|
|
|
});
|
|
|
|
|
|
|
|
html.find(".adversary-helmet-click").click((ev) => {
|
|
|
|
ev.preventDefault();
|
|
|
|
|
|
|
|
let helmetValue = this.actor.data.data.combat.helmet;
|
|
|
|
|
|
|
|
if(helmetValue === undefined || helmetValue === null) {
|
|
|
|
helmetValue = false
|
|
|
|
}
|
|
|
|
|
|
|
|
this.actor.update({ "data.combat.helmet": !helmetValue });
|
|
|
|
});
|
|
|
|
|
|
|
|
html.find(".roll-adversary-armor").click((ev) => {
|
|
|
|
const armor = $(ev.currentTarget).data("armor");
|
|
|
|
|
|
|
|
let hasHelmet = this.actor.data.data.combat.helmet;
|
|
|
|
|
|
|
|
if(hasHelmet === undefined || hasHelmet === null) {
|
|
|
|
hasHelmet = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let regex = /([0-9]*)t([0-9]*)/g;
|
|
|
|
let regexMatch;
|
|
|
|
|
|
|
|
while (regexMatch = regex.exec(armor.toLowerCase())) {
|
|
|
|
this.khRoller.rollArmorInChat(regexMatch[1], hasHelmet, this.actor)
|
|
|
|
}
|
|
|
|
});
|
2020-11-30 06:23:35 +01:00
|
|
|
|
|
|
|
// Add or Remove relationship
|
|
|
|
html.find(".learning-control").click(this._onClickLearningControl.bind(this));
|
|
|
|
html.find(".learning-click").click(this._onClickLearingLearned.bind(this));
|
|
|
|
|
|
|
|
/* Hjältarnas Tid specefic */
|
|
|
|
if(game.settings.get("kopparhavet", "gameSystem") === "hjaltarnas-tid") {
|
|
|
|
// Add or Remove relationship
|
|
|
|
html.find(".relation-control").click(this._onClickRelationshipControl.bind(this));
|
|
|
|
html.find(".relation-click").click(this._onClickRelationshipUsed.bind(this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async _onClickLearingLearned(event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
const li1 = $(event.currentTarget);
|
|
|
|
const li2 = $(event.currentTarget).parents(".learning");
|
|
|
|
let box = li1.data("num")
|
|
|
|
let learingKey = li2.data("attribute");
|
|
|
|
|
|
|
|
const clickedValue = (this.actor.data.data.learning[learingKey][box] == undefined ? false : this.actor.data.data.learning[learingKey][box]);
|
|
|
|
let dataName = "data.learning." + learingKey + "." + box
|
|
|
|
let tempData = {}
|
|
|
|
|
|
|
|
tempData[dataName] = !clickedValue
|
|
|
|
|
|
|
|
this.actor.update(tempData);
|
|
|
|
|
|
|
|
this._render();
|
|
|
|
}
|
|
|
|
|
|
|
|
async _onClickLearningControl(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
const a = event.currentTarget;
|
|
|
|
const action = a.dataset.action;
|
|
|
|
const attrs = this.object.data.data.learning;
|
|
|
|
const form = this.form;
|
|
|
|
|
|
|
|
// Add new modification
|
|
|
|
if (action === "create") {
|
|
|
|
const nk = new Date().getTime();
|
|
|
|
let newKey = document.createElement("div");
|
|
|
|
|
|
|
|
newKey.innerHTML = `<input class="learning-key" type="text" name="data.learning.attr${nk}.key" value="attr${nk}" style="display: none;" /><input class="learning-key" type="text" name="data.learning.attr${nk}.value" value="" style="display: none;" />`;
|
|
|
|
|
|
|
|
form.appendChild(newKey);
|
|
|
|
await this._onSubmit(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove existing modification
|
|
|
|
else if (action === "delete") {
|
|
|
|
const li = a.closest(".learning");
|
|
|
|
li.parentElement.removeChild(li);
|
|
|
|
await this._onSubmit(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async _onClickRelationshipControl(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
const a = event.currentTarget;
|
|
|
|
const action = a.dataset.action;
|
|
|
|
const attrs = this.object.data.data.relationships;
|
|
|
|
const form = this.form;
|
|
|
|
|
|
|
|
// Add new modification
|
|
|
|
if (action === "create") {
|
|
|
|
const nk = new Date().getTime();
|
|
|
|
let newKey = document.createElement("div");
|
|
|
|
|
|
|
|
newKey.innerHTML = `<input class="relation-key" type="text" name="data.relationships.attr${nk}.key" value="attr${nk}" style="display: none;" /><input class="relation-key" type="text" name="data.relationships.attr${nk}.value" value="" style="display: none;" />`;
|
|
|
|
|
|
|
|
form.appendChild(newKey);
|
|
|
|
await this._onSubmit(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove existing modification
|
|
|
|
else if (action === "delete") {
|
|
|
|
const li = a.closest(".relation");
|
|
|
|
li.parentElement.removeChild(li);
|
|
|
|
await this._onSubmit(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async _onClickRelationshipUsed(event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
const li = $(event.currentTarget).parents(".relation");
|
|
|
|
let relationshipKey = li.data("attribute");
|
|
|
|
|
|
|
|
const clickedValue = (this.actor.data.data.relationships[relationshipKey].check == undefined ? false : this.actor.data.data.relationships[relationshipKey].check);
|
|
|
|
let dataName = "data.relationships." + relationshipKey + ".check"
|
|
|
|
let tempData = {}
|
|
|
|
|
|
|
|
tempData[dataName] = !clickedValue
|
|
|
|
|
|
|
|
this.actor.update(tempData);
|
|
|
|
|
|
|
|
this._render();
|
2020-11-28 19:12:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async _toggleEquippedItem(event) {
|
|
|
|
const li = $(event.currentTarget);
|
2021-07-28 13:08:19 +02:00
|
|
|
const item = this.actor.items.get(li.data("itemId"));
|
2020-11-28 19:12:19 +01:00
|
|
|
const actor = this.actor;
|
|
|
|
|
2020-12-01 17:30:39 +01:00
|
|
|
if(item) {
|
2020-11-28 19:12:19 +01:00
|
|
|
if(item.type === "armor") {
|
|
|
|
let initValue = -1
|
|
|
|
|
|
|
|
if(item.data.data.equipable.equipped) {
|
|
|
|
initValue = 4
|
|
|
|
|
|
|
|
actor.items.map((i) => {
|
|
|
|
if(i.type === "armor") {
|
2021-07-28 13:08:19 +02:00
|
|
|
if(i.id !== item.id && i.data.data.equipable.equipped && i.data?.data?.modifications) {
|
2020-11-28 19:12:19 +01:00
|
|
|
for(let k of Object.keys(i.data.data.modifications)) {
|
|
|
|
if(i.data.data.modifications[k].modtype === "init") {
|
|
|
|
initValue = i.data.data.modifications[k].value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if (item.data?.data?.modifications) {
|
|
|
|
for(let k of Object.keys(item.data.data.modifications)) {
|
|
|
|
if(item.data.data.modifications[k].modtype === "init") {
|
|
|
|
initValue = item.data.data.modifications[k].value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(initValue > 0) {
|
|
|
|
actor.update({ ["data.combat.init"]: initValue });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
item.update({ ["data.equipable.equipped"]: !item.data.data.equipable.equipped });
|
|
|
|
} else {
|
|
|
|
console.log("Could not find item")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async _increaseQuantity(event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
const li = $(event.currentTarget).parents(".item");
|
|
|
|
let itemId = li.data("itemId");
|
2021-07-28 13:08:19 +02:00
|
|
|
let item = this.actor.items.get(itemId);
|
2020-11-28 19:12:19 +01:00
|
|
|
|
|
|
|
if (!item) {
|
2021-07-28 13:08:19 +02:00
|
|
|
console.log("IMPORT ERROR 9")
|
2020-11-28 19:12:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
item.update({ ["data.quantity.value"]: item.data.data.quantity.value + 1 });
|
|
|
|
}
|
|
|
|
|
|
|
|
async _decreaseQuantity(event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
const li = $(event.currentTarget).parents(".item");
|
|
|
|
let itemId = li.data("itemId");
|
2021-07-28 13:08:19 +02:00
|
|
|
let item = this.actor.items.get(itemId);
|
2020-11-28 19:12:19 +01:00
|
|
|
|
|
|
|
if (!item) {
|
2021-07-28 13:08:19 +02:00
|
|
|
console.log("IMPORT ERROR 10")
|
2020-11-28 19:12:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
let count = item.data.data.quantity.value - 1 > 0 ? item.data.data.quantity.value - 1 : 0;
|
|
|
|
|
|
|
|
item.update({ ["data.quantity.value"]: count });
|
|
|
|
}
|
|
|
|
|
|
|
|
async _onChangeSkillValue(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
const itemId = $(event.currentTarget).data("item-id");
|
2021-07-28 13:08:19 +02:00
|
|
|
let _item = this.actor.items.find((element) => element.id == itemId);
|
2020-11-28 19:12:19 +01:00
|
|
|
|
|
|
|
if (_item) {
|
|
|
|
let update = {
|
2021-07-28 13:08:19 +02:00
|
|
|
_id: _item.id,
|
2020-11-28 19:12:19 +01:00
|
|
|
data: { value: $(event.currentTarget).val() },
|
|
|
|
};
|
2021-07-28 13:08:19 +02:00
|
|
|
await this.actor.updateEmbeddedEntity("Item", [update]);
|
2020-11-28 19:12:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async _onClickSkill(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
const itemId = $(event.currentTarget).data("item-id");
|
2021-07-28 13:08:19 +02:00
|
|
|
let _item = this.actor.items.find((element) => element.id == itemId);
|
|
|
|
|
|
|
|
console.log(_item)
|
|
|
|
console.log(itemId)
|
2020-11-28 19:12:19 +01:00
|
|
|
|
|
|
|
if (_item) {
|
|
|
|
let newVal = true;
|
|
|
|
|
2021-07-28 13:08:19 +02:00
|
|
|
if(_item.data.used !== undefined) {
|
|
|
|
newVal = !_item.data.used;
|
2020-11-28 19:12:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
let update = {
|
2021-07-28 13:08:19 +02:00
|
|
|
_id: _item.id,
|
2020-11-28 19:12:19 +01:00
|
|
|
data: { used: newVal },
|
|
|
|
};
|
2021-07-28 13:08:19 +02:00
|
|
|
await this.actor.updateEmbeddedEntity("Item", [update]);
|
2020-11-28 19:12:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-30 06:23:35 +01:00
|
|
|
/** @override */
|
|
|
|
_updateObject(event, formData) {
|
|
|
|
const actorUpdate = ActorHelpers.actorUpdate.bind(this);
|
|
|
|
|
|
|
|
actorUpdate(event, formData);
|
|
|
|
}
|
|
|
|
|
2020-11-28 19:12:19 +01:00
|
|
|
/**
|
|
|
|
* Send details of an item to chat.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
async _itemDetailsToChat(itemId) {
|
2021-07-28 13:08:19 +02:00
|
|
|
let item = this.actor.items.get(itemId);
|
2020-11-28 19:12:19 +01:00
|
|
|
|
|
|
|
if (!item) {
|
|
|
|
item = game.items.get(itemId);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!item) {
|
2021-07-28 13:08:19 +02:00
|
|
|
console.log("IMPORT ERROR 11")
|
2020-11-28 19:12:19 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const itemDetails = item?.getItemDetails();
|
|
|
|
const html = await renderTemplate("systems/kopparhavet/templates/chat/item-card.html", itemDetails);
|
|
|
|
|
|
|
|
const messageData = {
|
2021-07-28 13:08:19 +02:00
|
|
|
user: game.user.id,
|
2020-11-28 19:12:19 +01:00
|
|
|
type: CONST.CHAT_MESSAGE_TYPES.OTHER,
|
|
|
|
content: html,
|
|
|
|
speaker: {
|
2021-07-28 13:08:19 +02:00
|
|
|
actor: this.actor.id,
|
2020-11-28 19:12:19 +01:00
|
|
|
token: this.actor.token,
|
|
|
|
alias: this.actor.name,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
ChatMessage.create(messageData);
|
|
|
|
}
|
|
|
|
}
|