From f8ebc048d327400f22ffd2c21d3210f3a07131e6 Mon Sep 17 00:00:00 2001 From: AngryBeaver Date: Tue, 18 Oct 2022 22:23:46 +0200 Subject: [PATCH] individual anyOf --- module.json | 2 +- package.json | 2 +- src/Crafting.ts | 10 +++++++++- src/Recipe.ts | 2 +- src/apps/RecipeSheet.ts | 4 +++- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/module.json b/module.json index 0b7f187..f1fb214 100644 --- a/module.json +++ b/module.json @@ -2,7 +2,7 @@ "title": "Beaver's Crafting System", "description": "A Crafting Module for DnD", "id": "beavers-crafting", - "version": "0.3.0", + "version": "0.3.1", "authors": [ { "name": "angryBeaver", diff --git a/package.json b/package.json index be1b9fc..42fae09 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "beavers-crafting", "title": "Beaver's Crafting", - "version": "0.3.0", + "version": "0.3.1", "description": "Crafting", "devDir": "C:\\Users\\User\\AppData\\Local\\FoundryVTT\\Data\\modules", "main": "src/main.js", diff --git a/src/Crafting.ts b/src/Crafting.ts index a683927..ae3a074 100644 --- a/src/Crafting.ts +++ b/src/Crafting.ts @@ -63,7 +63,15 @@ export class Crafting { const item = await fromUuid(component.uuid); const anyOf = new AnyOf(item); let results = await anyOf.filter(this.actor.items); - results = results.filter(c=>c.quantity >= component.quantity); + results = results.filter(c=>{ + let quantity = c.quantity; + toAdd.forEach(a=>{ + if(a.id === c.id){ + quantity = quantity-a.quantity; + } + }); + return quantity >= component.quantity + }); if(results.length >= 0) { const result = results[Math.floor(Math.random() * results.length)]; result.quantity = component.quantity; diff --git a/src/Recipe.ts b/src/Recipe.ts index 88f3194..d5c2b4e 100644 --- a/src/Recipe.ts +++ b/src/Recipe.ts @@ -113,7 +113,7 @@ export class DefaultComponent implements Component { constructor(entity, uuid, type) { this.id = entity.id; - this.uuid = uuid; + this.uuid = entity.uuid; this.type = type; this.name = entity.name; this.img = entity.img; diff --git a/src/apps/RecipeSheet.ts b/src/apps/RecipeSheet.ts index 09f023a..36d6db4 100644 --- a/src/apps/RecipeSheet.ts +++ b/src/apps/RecipeSheet.ts @@ -117,10 +117,12 @@ export class RecipeSheet { if (entity) { if (isIngredient) { let type = data.type; + let uuid = data.uuid; if(isAnyOf(entity)){ type = Settings.ANYOF_SUBTYPE; + uuid = foundry.utils.randomID(); } - this.recipe.addIngredient(entity, data.uuid,type); + this.recipe.addIngredient(entity, uuid,type); } if (isResult) { this.recipe.addResult(entity, data.uuid, data.type);