jopeek / fvtt-loot-sheet-npc-5e

FVTT - Loot Sheet NPC 5E
MIT License
44 stars 86 forks source link

[BUG] Incompatible with MonsterBlocks module, throws exception preventing Creature sheet from opening #388

Closed FeistyMango closed 1 year ago

FeistyMango commented 1 year ago

Describe the bug There appears to be an incompatibility issue when both these modules are included. My guess based on where the exception is thrown, the MonsterBlocks module (which allows you to open monster sheets), does not have some of the predicted/expected property values and so it throws an exception since it wasn't coded to have a safe guard in that situation. It appears that the monster sheet contains abilities/features that are represented as items, and when the getData() is being invoked when the sheet is being opened, it makes the assumption that all items have a price or value.

Here is the ability the creature has that causes the exception:

{
  "name": "Keen Hearing and Smell",
  "type": "feat",
  "system": {
    "description": {
      "value": "<section class=\"secret\">\n<p><em><strong>Keen Hearing and Smell.</strong></em> The wolf has advantage on Wisdom (Perception) checks that rely on hearing or smell.</p>\n</section>\nThe Dire Wolf uses Keen Hearing and Smell.",
      "chat": "",
      "unidentified": ""
    },
    "source": "Basic Rules pg 123",
    "activation": {
      "type": "",
      "cost": null,
      "condition": ""
    },
    "duration": {
      "value": "",
      "units": ""
    },
    "target": {
      "value": null,
      "width": null,
      "units": "",
      "type": ""
    },
    "range": {
      "value": null,
      "long": null,
      "units": ""
    },
    "uses": {
      "value": null,
      "max": "",
      "per": null,
      "recovery": ""
    },
    "consume": {
      "type": "",
      "target": null,
      "amount": null
    },
    "ability": null,
    "actionType": null,
    "attackBonus": "",
    "chatFlavor": "",
    "critical": {
      "threshold": null,
      "damage": ""
    },
    "damage": {
      "parts": [],
      "versatile": ""
    },
    "formula": "",
    "save": {
      "ability": "",
      "dc": null,
      "scaling": "flat"
    },
    "type": {
      "value": "",
      "subtype": ""
    },
    "requirements": "",
    "recharge": {
      "value": null,
      "charged": false
    }
  },
  "effects": [],
  "flags": {
    "ddbimporter": {
      "dndbeyond": {},
      "parentId": "e5g9hsovFnFMrgjY"
    },
    "monsterMunch": {
      "titleHTML": "<em><strong>Keen Hearing and Smell.</strong></em>",
      "fullName": "Keen Hearing and Smell.",
      "actionCopy": false
    }
  },
  "_id": "f2aDqcO5kPjSGikg",
  "img": "icons/svg/item-bag.svg",
  "folder": null,
  "sort": 0,
  "ownership": {
    "default": 0
  },
  "_stats": {
    "systemId": null,
    "systemVersion": null,
    "coreVersion": null,
    "createdTime": null,
    "modifiedTime": null,
    "lastModifiedBy": null
  }
}

Line of code that throws the error: let priceInGp = item.data.data.price.value;

foundry.js:747 TypeError: An error occurred while rendering LootSheet5eNPC 233. Cannot read properties of undefined (reading 'value')
[Detected 1 package: lootsheet-simple]
    at lootsheet-simple.js:184:46
    at Array.forEach (<anonymous>)
    at LootSheet5eNPC.getData (lootsheet-simple.js:182:36)
    at async LootSheet5eNPC._render (foundry.js:5108:18)
    at async LootSheet5eNPC._render (foundry.js:5822:5)

To Reproduce Steps to reproduce the behavior:

  1. Install https://github.com/zeel01/MonsterBlocks
  2. Install loot-sheet-npc-5
  3. Attempt to open a monster/creature sheet, it won't open and you get an exception in the error console

Expected behavior Should be able to open the monster/creature sheet

Screenshots image

Desktop (please complete the following information):

FeistyMango commented 1 year ago

Here is my proposed fix to add intergration support that would fix the root issue that causes this bug to manifest. The real issue is that Stat Blocks imported from DND Beyond represent features and melee skills/abilities as Items. Since these items do not include prices, it throws an exception as described above. I added logic to filter them out completely from the loot tables since they are not appropriate to even see on a loot table.

See PR: https://github.com/jopeek/fvtt-loot-sheet-npc-5e/pull/389