248 lines
12 KiB
JavaScript
248 lines
12 KiB
JavaScript
import {PlayerCharacterDataModel} from "../../data/character.mjs";
|
|
|
|
export default {
|
|
_prepareContext: (context) => {
|
|
|
|
const actorData = context.document
|
|
context.spells = []
|
|
context.system = actorData.system
|
|
context.flags = actorData.flags
|
|
context.derived = context.document.system
|
|
context.originalName = actorData.name
|
|
context.name = context.derived.name ?? actorData.name
|
|
context.effects = actorData.effects ?? []
|
|
|
|
context.equipments = []
|
|
context.carryingweight = 0
|
|
actorData.itemTypes.Equipment.forEach((item, index) => {
|
|
|
|
// worn items are halved weight
|
|
|
|
let effectiveWeight = item.system.weight ?? 0
|
|
if (context.document.isWorn(item._id)) {
|
|
effectiveWeight = item.system.weight ? item.system.weight / 2 : 0
|
|
}
|
|
|
|
context.equipments.push({
|
|
index: index,
|
|
id: item._id,
|
|
quantity: item.system.quantity,
|
|
name: item.name,
|
|
icon: item.img ?? "",
|
|
weight: item.system.weight,
|
|
worn: context.document.isWorn(item._id)
|
|
})
|
|
context.carryingweight += item.system.quantity * effectiveWeight;
|
|
|
|
})
|
|
context.maxcarryingcapacity = actorData.system.attribute.kk.aktuell
|
|
context.carryingpercentage = Math.min((context.carryingweight / context.maxcarryingcapacity) * 100, 100);
|
|
|
|
const maxSets = 3
|
|
const romanNumerals = ["I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X"]
|
|
context.sets = []
|
|
for (let setIndex = 0; setIndex < maxSets; setIndex++) {
|
|
|
|
context.sets.push({
|
|
tab: "set" + (setIndex + 1),
|
|
name: romanNumerals[setIndex],
|
|
index: setIndex,
|
|
slots: [
|
|
{
|
|
target: "links",
|
|
id: actorData.system.heldenausruestung[setIndex]?.links,
|
|
name: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.links)?.name,
|
|
icon: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.links)?.img
|
|
},
|
|
{
|
|
target: "rechts",
|
|
id: actorData.system.heldenausruestung[setIndex]?.rechts,
|
|
name: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.rechts)?.name,
|
|
icon: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.rechts)?.img
|
|
},
|
|
{
|
|
target: "brust",
|
|
id: actorData.system.heldenausruestung[setIndex]?.brust,
|
|
name: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.brust)?.name,
|
|
icon: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.brust)?.img
|
|
},
|
|
{
|
|
target: "ruecken",
|
|
id: actorData.system.heldenausruestung[setIndex]?.ruecken,
|
|
name: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.ruecken)?.name,
|
|
icon: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.ruecken)?.img
|
|
},
|
|
{
|
|
target: "kopf",
|
|
id: actorData.system.heldenausruestung[setIndex]?.kopf,
|
|
name: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.kopf)?.name,
|
|
icon: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.kopf)?.img
|
|
},
|
|
{
|
|
target: "fernkampf",
|
|
id: actorData.system.heldenausruestung[setIndex]?.fernkampf,
|
|
name: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.fernkampf)?.name,
|
|
icon: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.fernkampf)?.img
|
|
},
|
|
{
|
|
target: "munition",
|
|
id: actorData.system.heldenausruestung[setIndex]?.munition,
|
|
name: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.munition)?.name,
|
|
icon: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.munition)?.img
|
|
},
|
|
{
|
|
target: "armlinks",
|
|
id: actorData.system.heldenausruestung[setIndex]?.armlinks,
|
|
name: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.armlinks)?.name,
|
|
icon: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.armlinks)?.img
|
|
},
|
|
{
|
|
target: "armrechts",
|
|
id: actorData.system.heldenausruestung[setIndex]?.armrechts,
|
|
name: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.armrechts)?.name,
|
|
icon: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.armrechts)?.img
|
|
},
|
|
{
|
|
target: "bauch",
|
|
id: actorData.system.heldenausruestung[setIndex]?.bauch,
|
|
name: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.bauch)?.name,
|
|
icon: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.bauch)?.img
|
|
},
|
|
{
|
|
target: "beinlinks",
|
|
id: actorData.system.heldenausruestung[setIndex]?.beinlinks,
|
|
name: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.beinlinks)?.name,
|
|
icon: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.beinlinks)?.img
|
|
},
|
|
{
|
|
target: "beinrechts",
|
|
id: actorData.system.heldenausruestung[setIndex]?.beinrechts,
|
|
name: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.beinrechts)?.name,
|
|
icon: actorData.items.get(actorData.system.heldenausruestung[setIndex]?.beinrechts)?.img
|
|
}
|
|
]
|
|
})
|
|
}
|
|
|
|
return context
|
|
},
|
|
_onRender: (context, options, thisObject) => {
|
|
|
|
new foundry.applications.ux.DragDrop.implementation({
|
|
dragSelector: ".inventory-table .equipment",
|
|
dropSelector: ".inventory-table",
|
|
permissions: {
|
|
dragstart: thisObject._canDragStart.bind(thisObject),
|
|
drop: thisObject._canDragDrop.bind(thisObject)
|
|
},
|
|
callbacks: {
|
|
dragstart: thisObject._onDragStart.bind(thisObject),
|
|
drop: thisObject._onDrop.bind(thisObject),
|
|
dragover: thisObject._onDragOver.bind(thisObject)
|
|
}
|
|
}).bind(thisObject.element);
|
|
|
|
new ContextMenu(
|
|
thisObject.element,
|
|
".equipment",
|
|
[
|
|
{
|
|
name: "Abrüsten",
|
|
icon: '<i class="fa-solid fa-suitcase"></i>',
|
|
callback: (target) => {
|
|
const {itemId} = target.dataset
|
|
const itemSlot = thisObject.document.isWorn(itemId)
|
|
const updateObject = thisObject.document.getEquipmentSetUpdateObject()
|
|
delete updateObject[`system.heldenausruestung.${thisObject.document.system.setEquipped}.${itemSlot}`]
|
|
thisObject.document.update(updateObject)
|
|
},
|
|
condition: (target) => {
|
|
const {itemId} = target.dataset
|
|
const itemIsWorn = thisObject.document.isWorn(itemId)
|
|
return itemIsWorn
|
|
}
|
|
},
|
|
{
|
|
name: "Ausrüsten (Munition)",
|
|
|
|
callback: (target) => {
|
|
const updateObject = thisObject.document.getEquipmentSetUpdateObject()
|
|
updateObject[`system.heldenausruestung.${thisObject.document.system.setEquipped}.munition`] = target.dataset.itemId
|
|
thisObject.document.update(updateObject)
|
|
},
|
|
condition: (target) => {
|
|
const {itemId} = target.dataset
|
|
const item = thisObject.document.items.get(itemId)
|
|
console.log(item.system.category)
|
|
return !thisObject.document.isWorn(itemId) && item.system.category.indexOf("Munition") != -1
|
|
}
|
|
},
|
|
{
|
|
name: "Ausrüsten",
|
|
callback: (target) => {
|
|
const updateObject = thisObject.document.getEquipmentSetUpdateObject()
|
|
|
|
},
|
|
condition: (target) => {
|
|
const {itemId} = target.dataset
|
|
const item = thisObject.document.items.get(itemId)
|
|
return !thisObject.document.isWorn(itemId) && item.system.category.indexOf("Rüstung") != -1
|
|
}
|
|
},
|
|
{
|
|
name: "Ausrüsten (Rechte Hand)",
|
|
callback: (target) => {
|
|
const updateObject = thisObject.document.getEquipmentSetUpdateObject()
|
|
updateObject[`system.heldenausruestung.${thisObject.document.system.setEquipped}.rechts`] = target.dataset.itemId
|
|
thisObject.document.update(updateObject)
|
|
},
|
|
condition: (target) => {
|
|
const {itemId} = target.dataset
|
|
const item = thisObject.document.items.get(itemId)
|
|
return !thisObject.document.isWorn(itemId) && item.system.category.indexOf("Nahkampfwaffe") != -1
|
|
}
|
|
},
|
|
{
|
|
name: "Ausrüsten (Linke Hand)",
|
|
callback: (target) => {
|
|
const updateObject = thisObject.document.getEquipmentSetUpdateObject()
|
|
updateObject[`system.heldenausruestung.${thisObject.document.system.setEquipped}.links`] = target.dataset.itemId
|
|
thisObject.document.update(updateObject)
|
|
},
|
|
condition: (target) => {
|
|
const {itemId} = target.dataset
|
|
const item = thisObject.document.items.get(itemId)
|
|
return !thisObject.document.isWorn(itemId) && item.system.category.indexOf("Nahkampfwaffe") != -1
|
|
}
|
|
},
|
|
{
|
|
name: "Ausrüsten (Fernkampf)",
|
|
callback: (target) => {
|
|
const updateObject = thisObject.document.getEquipmentSetUpdateObject()
|
|
updateObject[`system.heldenausruestung.${thisObject.document.system.setEquipped}.fernkampf`] = target.dataset.itemId
|
|
thisObject.document.update(updateObject)
|
|
},
|
|
condition: (target) => {
|
|
const {itemId} = target.dataset
|
|
const item = thisObject.document.items.get(itemId)
|
|
return !thisObject.document.isWorn(itemId) && item.system.category.indexOf("Fernkampfwaffe") != -1
|
|
}
|
|
},
|
|
{
|
|
name: "Aus dem Inventar entfernen",
|
|
icon: '<i class="fa-solid fa-trash"></i>',
|
|
callback: (target) => {
|
|
thisObject.document.deleteEmbeddedDocuments('Item', [target.dataset.itemId])
|
|
},
|
|
condition: (target) => {
|
|
const {itemId} = target.dataset
|
|
return !thisObject.document.isWorn(itemId)
|
|
}
|
|
}
|
|
], {jQuery: false});
|
|
},
|
|
_getTabConfig: (group) => {
|
|
group.tabs.push({id: "equipment", group: "sheet", label: "Ausrüstung"})
|
|
},
|
|
template: `systems/DSA_4-1/templates/actor/character/tab-equipment.hbs`
|
|
} |