diff --git a/src/module/documents/character.mjs b/src/module/documents/character.mjs
index 7ec909d5..42261274 100644
--- a/src/module/documents/character.mjs
+++ b/src/module/documents/character.mjs
@@ -1,6 +1,7 @@
import {importCharacter} from "../xml-import/xml-import.mjs";
import {LiturgyData} from "../data/miracle/liturgydata.mjs";
import {Zonenruestung, Zonenwunde} from "../data/Trefferzone.js";
+import {PlayerCharacterDataModel} from "../data/character.mjs";
export class Character extends Actor {
@@ -241,6 +242,48 @@ export class Character extends Actor {
return data;
}
+
+ findEquipmentOnSlot(slot, setNumber) {
+ return this.items.get(this.system.heldenausruestung[setNumber ?? this.system.setEquipped]?.[slot])
+ }
+
+ getEquipmentSetUpdateObject() {
+ const updateObject = {}
+ Array.from(this.system.heldenausruestung).forEach((equipmentSet, index) => {
+ updateObject[`system.heldenausruestung.${index}.links`] = equipmentSet.links;
+ updateObject[`system.heldenausruestung.${index}.rechts`] = equipmentSet.rechts;
+ updateObject[`system.heldenausruestung.${index}.brust`] = equipmentSet.brust;
+ updateObject[`system.heldenausruestung.${index}.bauch`] = equipmentSet.bauch;
+ updateObject[`system.heldenausruestung.${index}.ruecken`] = equipmentSet.ruecken;
+ updateObject[`system.heldenausruestung.${index}.kopf`] = equipmentSet.kopf;
+ updateObject[`system.heldenausruestung.${index}.fernkampf`] = equipmentSet.fernkampf;
+ updateObject[`system.heldenausruestung.${index}.munition`] = equipmentSet.munition;
+ updateObject[`system.heldenausruestung.${index}.armlinks`] = equipmentSet.armlinks;
+ updateObject[`system.heldenausruestung.${index}.armrechts`] = equipmentSet.armrechts;
+ updateObject[`system.heldenausruestung.${index}.beinlinks`] = equipmentSet.beinlinks;
+ updateObject[`system.heldenausruestung.${index}.beinrechts`] = equipmentSet.beinrechts;
+
+ })
+ return updateObject;
+ }
+
+
+ isWorn(itemId) {
+
+ const slots = PlayerCharacterDataModel.getSlots()
+ const set = this.system.heldenausruestung[this.system.setEquipped]
+ if (set) {
+ for (const slot of slots) {
+ const equipmentSlotId = set[slot]
+ if (equipmentSlotId === itemId) {
+ return slot
+ }
+ }
+ }
+
+ return false
+ }
+
/**
*
* @param amount
diff --git a/src/module/sheets/actions/action-manager.mjs b/src/module/sheets/actions/action-manager.mjs
index 2aa31643..3e1aee6e 100644
--- a/src/module/sheets/actions/action-manager.mjs
+++ b/src/module/sheets/actions/action-manager.mjs
@@ -68,21 +68,21 @@ export class ActionManager {
type: ActionManager.ATTACK,
cost: ActionManager.REGULAR,
source: ActionManager.DEFAULT,
- eval: () => true
+ eval: () => this.#hatWaffeinHand()
},
{
name: "Schnellschuss",
type: ActionManager.INTERACTION,
cost: ActionManager.CONTINUING,
source: ActionManager.DEFAULT,
- eval: () => true
+ eval: () => this.#hatFernkampfWaffeinHand()
},
{
name: "Schnellschuss (Scharfschütze)",
type: ActionManager.INTERACTION,
cost: ActionManager.CONTINUING,
source: ActionManager.SF,
- eval: () => this.#hatSonderfertigkeit("Scharfschütze")
+ eval: () => this.#hatFernkampfWaffeinHand() && this.#hatSonderfertigkeit("Scharfschütze")
},
{
name: "Abwehraktion",
@@ -110,7 +110,14 @@ export class ActionManager {
type: ActionManager.ATTACK,
cost: ActionManager.REGULAR,
source: ActionManager.SF,
- eval: () => this.#hatSonderfertigkeit("Finte")
+ eval: () => this.#hatFernkampfWaffeinHand() && this.#hatSonderfertigkeit("Finte")
+ },
+ {
+ name: "Wuchtschlag",
+ type: ActionManager.ATTACK,
+ cost: ActionManager.REGULAR,
+ source: ActionManager.DEFAULT,
+ eval: () => true
},
{
name: "Wuchtschlag",
@@ -162,21 +169,21 @@ export class ActionManager {
type: ActionManager.INTERACTION,
cost: ActionManager.CONTINUING,
source: ActionManager.SF,
- eval: () => this.#hatSonderfertigkeit("Schnellladen (Bogen)")
+ eval: () => this.#hatMunition() && this.#hatFernkampfWaffeinHand("Bogen") && this.#hatSonderfertigkeit("Schnellladen (Bogen)")
},
{
name: "Schnellladen (Armbrust)",
type: ActionManager.INTERACTION,
cost: ActionManager.CONTINUING,
source: ActionManager.SF,
- eval: () => this.#hatSonderfertigkeit("Schnellladen (Armbrust)")
+ eval: () => this.#hatMunition() && this.#hatFernkampfWaffeinHand("Armbrust") && this.#hatSonderfertigkeit("Schnellladen (Armbrust)")
},
{
name: "Nachladen",
type: ActionManager.INTERACTION,
cost: ActionManager.CONTINUING,
source: ActionManager.DEFAULT,
- eval: () => true
+ eval: () => this.#hatMunition()
},
{
name: "Talenteinsatz",
@@ -201,6 +208,26 @@ export class ActionManager {
}
]
+
+ #hatWaffeinHand() {
+ const item = this.actor.findEquipmentOnSlot("links") ?? this.actor.findEquipmentOnSlot("rechts")
+ console.log(item)
+ return item
+ }
+
+ #hatMunition() {
+ const item = this.actor.findEquipmentOnSlot("munition")
+ const weapon = this.actor.findEquipmentOnSlot("fernkampf")
+ console.log(item?.system.quantity, weapon)
+ return item
+ }
+
+ #hatFernkampfWaffeinHand(art) {
+ const item = this.actor.findEquipmentOnSlot("fernkampf")
+ console.log(item)
+ return item
+ }
+
#hatSonderfertigkeitBeginnendMit(name) {
return this.actor.system.sonderfertigkeiten?.find(p => p.name.startsWith(name)) != null
}
diff --git a/src/module/sheets/character/equipment.mjs b/src/module/sheets/character/equipment.mjs
index ff08ad0b..47957a1d 100644
--- a/src/module/sheets/character/equipment.mjs
+++ b/src/module/sheets/character/equipment.mjs
@@ -12,22 +12,6 @@ export default {
context.name = context.derived.name ?? actorData.name
context.effects = actorData.effects ?? []
- const isWorn = (itemId, object) => {
-
- const slots = PlayerCharacterDataModel.getSlots()
- const set = object.system.heldenausruestung[object.system.setEquipped]
- if (set) {
- for (const slot of slots) {
- const equipmentSlotId = set[slot]
- if (equipmentSlotId === itemId) {
- return slot
- }
- }
- }
-
- return false
- }
-
context.equipments = []
context.carryingweight = 0
actorData.itemTypes.Equipment.forEach((item, index) => {
@@ -35,7 +19,7 @@ export default {
// worn items are halved weight
let effectiveWeight = item.system.weight ?? 0
- if (isWorn(item._id, context.document)) {
+ if (context.document.isWorn(item._id)) {
effectiveWeight = item.system.weight ? item.system.weight / 2 : 0
}
@@ -46,7 +30,7 @@ export default {
name: item.name,
icon: item.img ?? "",
weight: item.system.weight,
- worn: isWorn(item._id, context.document)
+ worn: context.document.isWorn(item._id)
})
context.carryingweight += item.system.quantity * effectiveWeight;
@@ -156,6 +140,104 @@ export default {
drop: thisObject._onDrop.bind(thisObject)
}
}).bind(thisObject.element);
+
+ new ContextMenu(
+ thisObject.element,
+ ".equipment",
+ [
+ {
+ name: "Abrüsten",
+ icon: '',
+ 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)
+ }
+ },
+ {
+ name: "Ausrüsten",
+ callback: (target) => {
+ //thisObject.deleteEmbeddedDocuments('Item', [event.dataset.id])
+ },
+ 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: '',
+ callback: (target) => {
+ thisObject.deleteEmbeddedDocuments('Item', [target.dataset.id])
+ },
+ condition: (target) => {
+ const {itemId} = target.dataset
+ !thisObject.document.isWorn(itemId)
+ }
+ }
+ ], {jQuery: false});
},
_getTabConfig: (group) => {
group.tabs.push({id: "equipment", group: "sheet", label: "Ausrüstung"})
diff --git a/src/module/sheets/characterSheet.mjs b/src/module/sheets/characterSheet.mjs
index 24652248..a8ff97d8 100644
--- a/src/module/sheets/characterSheet.mjs
+++ b/src/module/sheets/characterSheet.mjs
@@ -118,6 +118,10 @@ class CharacterSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
}
}
+ /**
+ *
+ * @param {MouseEvent} event
+ */
static #openEmbeddedDocument(event) {
const dataset = event.target.parentElement.dataset
const id = dataset.itemId ?? dataset.id
@@ -156,9 +160,6 @@ class CharacterSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
switch (partId) {
case "form":
- const findEquipmentOnSlot = (slot, setNumber, object) => {
- return object.items.get(object.system.heldenausruestung[setNumber]?.[slot])
- }
const actorData = context.document
context.system = actorData.system
@@ -212,9 +213,9 @@ class CharacterSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
context.aupcurrent = actorData.system.aup.aktuell ?? 0
- const fernkampf = findEquipmentOnSlot("fernkampf", actorData.system.setEquipped, actorData)
- const links = findEquipmentOnSlot("links", actorData.system.setEquipped, actorData)
- const rechts = findEquipmentOnSlot("rechts", actorData.system.setEquipped, actorData)
+ const fernkampf = actorData.findEquipmentOnSlot("fernkampf", actorData.system.setEquipped, actorData)
+ const links = actorData.findEquipmentOnSlot("links", actorData.system.setEquipped, actorData)
+ const rechts = actorData.findEquipmentOnSlot("rechts", actorData.system.setEquipped, actorData)
context.attacks = [];
if (fernkampf) {
@@ -224,8 +225,8 @@ class CharacterSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
context.attacks.push({
name: obj.name,
using: fernkampf.name,
- atroll: `1d20cs<${object.system.fk.aktuell + obj.system.at}`,
- at: `${object.system.fk.aktuell + obj.system.at}`,
+ atroll: `1d20cs<${this.document.system.fk.aktuell + obj.system.at}`,
+ at: `${this.document.system.fk.aktuell + obj.system.at}`,
tproll: `${fernkampf.system.rangedAttackDamage}`, // TODO consider adding TP/KK mod and Range mod
tp: `${fernkampf.system.rangedAttackDamage}`,
iniroll: `(${context.inidice})d6 + ${context.inivalue + fernkampf.system.iniModifier ?? 0}`,
@@ -246,9 +247,9 @@ class CharacterSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
context.attacks.push({
name: obj.name,
using: links.name,
- atroll: `1d20cs<${object.system.at.links.aktuell + obj.system.at + links.system.attackModifier}`, // TODO consider adding W/M
+ atroll: `1d20cs<${this.document.system.at.links.aktuell + obj.system.at + links.system.attackModifier}`, // TODO consider adding W/M
at: `${object.system.at.links.aktuell + obj.system.at + links.system.attackModifier}`,
- paroll: `1d20cs<${object.system.pa.links.aktuell + obj.system.pa + links.system.parryModifier}`, // TODO consider adding W/M
+ paroll: `1d20cs<${this.document.system.pa.links.aktuell + obj.system.pa + links.system.parryModifier}`, // TODO consider adding W/M
pa: `${object.system.pa.links.aktuell + obj.system.pa + links.system.parryModifier}`,
tproll: `${links.system.meleeAttackDamage}`, // TODO consider adding TP/KK mod
tp: `${links.system.meleeAttackDamage}`,
@@ -270,9 +271,9 @@ class CharacterSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
context.attacks.push({
name: obj.name,
using: rechts.name,
- atroll: `1d20cs<${object.system.at.rechts.aktuell + obj.system.at + rechts.system.attackModifier}`, // TODO consider adding W/M
+ atroll: `1d20cs<${this.document.system.at.rechts.aktuell + obj.system.at + rechts.system.attackModifier}`, // TODO consider adding W/M
at: `${object.system.at.rechts.aktuell + obj.system.at + rechts.system.attackModifier}`,
- paroll: `1d20cs<${object.system.pa.rechts.aktuell + obj.system.pa + rechts.system.parryModifier}`, // TODO consider adding W/M
+ paroll: `1d20cs<${this.document.system.pa.rechts.aktuell + obj.system.pa + rechts.system.parryModifier}`, // TODO consider adding W/M
pa: `${object.system.pa.rechts.aktuell + obj.system.pa + rechts.system.parryModifier}`,
tproll: `${rechts.system.meleeAttackDamage}`, // TODO consider adding TP/KK mod
tp: `${rechts.system.meleeAttackDamage}`,
@@ -335,31 +336,31 @@ class CharacterSheet extends HandlebarsApplicationMixin(ActorSheetV2) {
break;
case "meta":
- await Meta._prepareContext(context, this.object)
+ await Meta._prepareContext(context, this.document)
break
case "social":
- await Social._prepareContext(context, this.object)
+ await Social._prepareContext(context, this.document)
break
case "attributes":
- await Attributes._prepareContext(context, this.object)
+ await Attributes._prepareContext(context, this.document)
break
case "combat":
- await Combat._prepareContext(context, this.object)
+ await Combat._prepareContext(context, this.document)
break
case "equipment":
- await Equipment._prepareContext(context, this.object)
+ await Equipment._prepareContext(context, this.document)
break
case "skills":
- await Skills._prepareContext(context, this.object)
+ await Skills._prepareContext(context, this.document)
break
case "spells":
- await Spells._prepareContext(context, this.object)
+ await Spells._prepareContext(context, this.document)
break
case "liturgies":
- await Liturgies._prepareContext(context, this.object)
+ await Liturgies._prepareContext(context, this.document)
break
case "effects":
- await Effects._prepareContext(context, this.object)
+ await Effects._prepareContext(context, this.document)
break
}
return context