diff --git a/TODO b/TODO index 56fb6a2..2f23eee 100644 --- a/TODO +++ b/TODO @@ -11,4 +11,5 @@ - Add Crew XP cheetsheet - Add Usage documentation to README.md - Add Turf Validation (<= 6 max) -- Add turf connection validation \ No newline at end of file +- Add turf connection validation +- Document usage of "logic" item property (crew_upgrades) \ No newline at end of file diff --git a/module/blades-helpers.js b/module/blades-helpers.js index a91c103..4b867e8 100644 --- a/module/blades-helpers.js +++ b/module/blades-helpers.js @@ -89,4 +89,62 @@ export class BladesHelpers { } + /** + * Add item modification if logic exists. + * @param {Object} item_data + * @param {Entity} entity + */ + static callItemLogic(item_data, entity) { + + if ('logic' in item_data.data) { + let logic = JSON.parse(item_data.data.logic); + + // Different logic behav. dep on operator. + switch (logic.operator) { + + // Add when creating. + case "addition": + entity.update({ + [logic.attribute]: Number(BladesHelpers.getNestedProperty(entity, "data." + logic.attribute)) + logic.value + }); + break; + + } + + } + + } + + /** + * Undo Item modifications when item is removed. + * @param {Object} item_data + * @param {Entity} entity + */ + static undoItemLogic(item_data, entity) { + + if ('logic' in item_data.data) { + let logic = JSON.parse(item_data.data.logic) + + // Different logic behav. dep on operator. + switch (logic.operator) { + + // Subtract when removing. + case "addition": + entity.update({ + [logic.attribute]: Number(BladesHelpers.getNestedProperty(entity, "data." + logic.attribute)) - logic.value + }); + break; + + } + } + + } + + + static getNestedProperty(obj, property) { + return property.split('.').reduce((r, e) => { + return r[e]; + }, obj); + } + } diff --git a/module/blades.js b/module/blades.js index 54bfa95..082d3aa 100644 --- a/module/blades.js +++ b/module/blades.js @@ -90,3 +90,14 @@ Hooks.once("init", async function() { }); }); + +/* + * Hooks + */ +Hooks.on("createOwnedItem", (parent, child, options, userId) => { + BladesHelpers.callItemLogic(child, parent); +}); + +Hooks.on("deleteOwnedItem", (parent, child, options, userId) => { + BladesHelpers.undoItemLogic(child, parent); +}); diff --git a/module/crew-sheet.js b/module/crew-sheet.js index de12734..e8121f1 100644 --- a/module/crew-sheet.js +++ b/module/crew-sheet.js @@ -128,6 +128,7 @@ export class BladesCrewSheet extends ActorSheet { if (item) { const actor = this.actor; BladesHelpers.removeDuplicatedItemType(item.data.type, actor); + BladesHelpers.callItemLogic(item, actor); } // Call parent on drop logic @@ -137,4 +138,5 @@ export class BladesCrewSheet extends ActorSheet { } /* -------------------------------------------- */ + } diff --git a/packs/crew_upgrades.db b/packs/crew_upgrades.db new file mode 100644 index 0000000..a69e4d6 --- /dev/null +++ b/packs/crew_upgrades.db @@ -0,0 +1 @@ +{"_id":"M7k3sdhua5qmJ93M","name":"Vault 1","permission":{"default":0,"BwbqQh8sHfeKmUax":3},"type":"crew_upgrade","data":{"description":"Adds the Vault providing additional 4 Coin space","logic":"{\"attribute\":\"data.vault.max\",\"operator\":\"addition\",\"value\":4,\"requirement\":\"\"}","crew_type":""},"folder":null,"sort":300000,"flags":{}} \ No newline at end of file diff --git a/system.json b/system.json index d08170f..0f714a0 100644 --- a/system.json +++ b/system.json @@ -3,8 +3,8 @@ "title": "Blades in the Dark", "description": "GBlades in the dark game system.", "version": 0.1, - "minimumCoreVersion": "0.5.2", - "compatibleCoreVersion": "0.5.3", + "minimumCoreVersion": "0.5.3", + "compatibleCoreVersion": "0.5.5", "templateVersion": 1, "author": "megastruktur", "esmodules": ["module/blades.js"], @@ -70,6 +70,13 @@ "system": "blades-in-the-dark", "path": "./packs/crew_types.db", "entity": "Item" + }, + { + "name": "Crew Upgrades", + "label": "Crew Upgrades", + "system": "blades-in-the-dark", + "path": "./packs/crew_upgrades.db", + "entity": "Item" } ] } diff --git a/template.json b/template.json index 3e2c298..f8277d8 100644 --- a/template.json +++ b/template.json @@ -72,7 +72,11 @@ "experience": [0], "hold_types": ["weak", "strong"], "coins": [0], - "vault": [0], + "vault": { + "value": [0], + "max": 0, + "default": 0 + }, "turfs": [8], "features": [], "heat": [0], @@ -80,7 +84,7 @@ } }, "Item": { - "types": ["item", "class", "ability", "heritage", "background", "vice", "crew_upgrade", "cohort", "crew_type", "crew_feature"], + "types": ["item", "class", "ability", "heritage", "background", "vice", "crew_upgrade", "cohort", "crew_type", "crew_feature", "crew_upgrade"], "templates": { "default": { "description": "" @@ -89,6 +93,9 @@ "description": "", "class": "", "price": 1 + }, + "logic": { + "logic": "" } }, "item": { @@ -117,9 +124,6 @@ "ability": { "templates": ["ability"] }, - "crew_upgrade": { - "templates": ["ability"] - }, "heritage": { "templates": ["default"] }, @@ -137,6 +141,10 @@ "crew_feature": { "templates": ["default"] }, + "crew_upgrade": { + "templates": ["default", "logic"], + "crew_type": "" + }, "crew_type": { "description": "", "turfs": { diff --git a/templates/crew-sheet.html b/templates/crew-sheet.html index 6e813fd..860c3b3 100644 --- a/templates/crew-sheet.html +++ b/templates/crew-sheet.html @@ -155,7 +155,7 @@ {{!-- Crew Type --}} -