Skip to content

Commit

Permalink
Merge pull request #6 from DanielBoettner/rolltablefixes_08
Browse files Browse the repository at this point in the history
Rolltablefixes 08
  • Loading branch information
DanielBoettner authored Jun 17, 2021
2 parents c0629f0 + 4c959a1 commit 8dd972e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ Also recommended is the use of [better rolltables](https://github.com/ultrakorne

### Example of filled inventory
On the left is the sheet of a token that was droped on the scene.
The right sheet is directly from the actor.
The right hand sheet is directly from the actor.

![image](https://github.com/DanielBoettner/fvtt-loot-populator-npc-5e/blob/master/SheetExample.png)

### Features

Allows you to have automated random loot on NPCs when dropping them on the scene.
If installed, it will make use of better rolltables.
If installed and activated, it can make use of better rolltables.

### Compatibility:
- Tested with FVTT v0.7.9 and the DND5E system only.
- FoundryVTT v0.7.10
- FoundryVTT v0.8.6+
- Tested with DnD5e system only.

### Installation Instructions

Expand Down
6 changes: 3 additions & 3 deletions module.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "lootpopulatornpc5e",
"title": "LootPopulator NPC 5e",
"description": "A module to auto populate loot on NPCs",
"version": "0.0.5",
"description": "A module to automatically populate loot on monsters and npcs when places on the map.",
"version": "0.1.0",
"minimumCoreVersion": "0.8.5",
"compatibleCoreVersion": "0.8.6",
"compatibleCoreVersion": "0.8.7",
"author": "Daniel Böttner",
"systems": ["dnd5e"],
"includes": [
Expand Down
31 changes: 27 additions & 4 deletions scripts/populateLoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ export class LootPopulator {
newItem = game.items.get(rollResult.results[0].data.resultId);
} else {
const items = game.packs.get(rollResult.results[0].data.collection);
newItem = await items.getEntity(rollResult.results[0].data.resultId);
newItem = await items.getDocument(rollResult.results[0].data.resultId);
}

newItem = this.rollSubTables(newItem);

if (!newItem || newItem === null) {
return;
}
Expand Down Expand Up @@ -161,12 +163,14 @@ export class LootPopulator {

if (rolltable.results[index].collection === "Item") {
newItem = game.items.get(rolltable.results[index].resultId);
}
else {
} else {
//Try to find it in the compendium
const items = game.packs.get(rolltable.results[index].data.collection);
newItem = await items.getEntity(rollResult.results[0].data.resultId);
newItem = await items.getDocument(rollResult.results[0].data.resultId);
}

newItem = this.rollSubTables(newItem,index);

if (!newItem || newItem === null) {
return ui.notifications.error(this.moduleNamespace + `: No item found "${rolltable.results[index].resultId}".`);
}
Expand Down Expand Up @@ -248,6 +252,25 @@ export class LootPopulator {
}
}

asycn _rollSubTables(item, index = 0){
if (item instanceof RollTable){
let subTableResults = await item.roll();

if(subTableResults.results[index].data.collection === "Item"){
item = game.items.get(subTableResults.results[index].data.resultId);
} else {
let itemCollection = game.packs.get(subTableResults.results[index].data.collection);
item = await itemCollection.getDocument(subTableResults.results[index].data.resultId);
}

if (item instanceof RollTable){
item = await _getItemFromRoll(item,index);
}
}

return item;
}

_getSetting(setting){
return game.settings.get(this.moduleNamespace,setting);
}
Expand Down

0 comments on commit 8dd972e

Please sign in to comment.