Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

Commit

Permalink
v0.2.2
Browse files Browse the repository at this point in the history
* Support for multiple currency values drawn in roll tables
* Suport for avoid equipped items
* BUGFIX: Equipped items do not transfer equipped to the player
* Add Compendium for currency types
  • Loading branch information
rinnocenti committed Jan 28, 2021
1 parent 1ba1e54 commit 7a3bb85
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 33 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v0.2.2

* Support for multiple currency values drawn in roll tables
* Suport for avoid equipped items
* BUGFIX: Equipped items do not transfer equipped to the player
* Add Compendium for currency types

# v.0.2.0

[BREAKING] - New macro, please replace.
Expand Down
6 changes: 5 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
"interactDistance": "Maximum distance to interact (in grids)",
"interactDistanceHint": "the maximum distance for players to interact with the lock in number of grids",
"lootSystem": "Loot System",
"lootSystemHint": "Choose one of the ways to perform the loot (Soon)"
"lootSystemHint": "Choose one of the ways to perform the loot (Soon)",
"lootEquipable": "Loot equipped items",
"lootEquipableHint": "If disabled, the player can not loot equipped items, if enabled the player can loot items equipped but with an additional % of items in that condition",
"lootEquipableAgil": "addict for equipped items (%)",
"lootEquipableAgilHint": "Percentage of additional chance of equipped item in NPC not to looting (ie. too damaged for use)"
}
}
6 changes: 5 additions & 1 deletion lang/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
"removeItem": "Remover os Itens",
"removeItemHint": "Se ativado remove os itens do token (não remove do ator a menos que o token estiver linkado)",
"lootSystem": "Sistema de Pilhagem",
"lootSystemHint": "Escolha uma das formas para realizar a pilhagem (em breve)"
"lootSystemHint": "Escolha uma das formas para realizar a pilhagem (em breve)",
"lootEquipable": "Pilhar equipamentos equipados",
"lootEquipableHint": "Se desativado o jogador não poderá pilhar itens equipados, se ativado o jogador poderá pilhar itens equipados porém com um ágio adicional da arma não estar em condição",
"lootEquipableAgil": "Ágio para itens equipados (%)",
"lootEquipableAgilHint": "Porcentagem de chance adicional do item equipado no NPC não servirem para pilhagem (Foram danificadas)"
}
}
12 changes: 10 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"title": "Innocenti Looting",
"description": "<p>Modules for loot from monsters and Npcs</p>",
"author": "Renato innocenti",
"version": "0.2.0",
"version": "0.2.2",
"minimumCoreVersion": "0.7.0",
"compatibleCoreVersion": "0.7.9",
"systems": [ "dnd5e" ],
Expand All @@ -29,10 +29,18 @@
"packs": [
{
"name": "looting-macros",
"label": "Looting Demo",
"label": "Macro Looting",
"path": "packs/looting-macro.db",
"module": "innocenti-looting",
"entity": "Macro"
},

{
"name": "looting-items",
"label": "Looting Items Currency",
"path": "packs/item-currency.db",
"module": "innocenti-looting",
"entity": "Item"
}
],
"socket": true,
Expand Down
17 changes: 17 additions & 0 deletions packs/item-currency.db

Large diffs are not rendered by default.

70 changes: 41 additions & 29 deletions scripts/ActionLoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ActionLoot {
// Morto - lootiar
titleChat = game.i18n.localize('Looting.MsgChat.looting');
if (entity.getFlag(SETTINGS.MODULE_NAME, SETTINGS.LOOT)) return ui.notifications.warn(game.i18n.format("Looting.Errors.invalidCheck", { token: entity.name })); // já foi lootiado.
await this.LootNPC(entity.actor, this.actor);
await this.LootNPC(entity.actor, this.actor);
} else {
// vivo - Roubar
if (entity.actor.getFlag(SETTINGS.MODULE_LOOT_SHEET, SETTINGS.LOOT_SHEET)) return; // não é um bau ou mercador.
Expand Down Expand Up @@ -93,7 +93,7 @@ export class ActionLoot {
// tipos de loot
if (game.settings.get(SETTINGS.MODULE_NAME, "lootSystem") == "mode1") {
this.loots = await this.InventoryChancesLoot(target.items);
for (var coin in this.lootCurrency) {
for (let coin in this.lootCurrency) {
this.data.currency[coin] = this.data.currency[coin] + this.lootCurrency[coin];
}
} else if (game.settings.get(SETTINGS.MODULE_NAME, "lootSystem") == "mode2") {
Expand Down Expand Up @@ -125,27 +125,35 @@ export class ActionLoot {
}

async InventoryChancesLoot(actoritems, check = false) {
let tables=[];
let tables = [];
let ac = await actoritems.filter(item => {
if (item == null || item == undefined) return;
if (item.type == "class" || item.type == "spell" || item.type == "feat") return;
let agio = (game.settings.get(SETTINGS.MODULE_NAME, "lootEquipable")) ? game.settings.get(SETTINGS.MODULE_NAME, "lootEquipableAgil") : 0;
// weapon equipment consumable
if (!game.settings.get(SETTINGS.MODULE_NAME, "lootEquipable") && item.data.data.equipped) return;
if (item.type === "weapon") {
if (item.data.data.weaponType == "siege" || item.data.data.weaponType == "natural") return;
if (!check && (Math.floor(Math.random() * 100) + 1) <= game.settings.get(SETTINGS.MODULE_NAME, "perWeapons")) return;
if (!check && (Math.floor(Math.random() * 100) + 1) <= game.settings.get(SETTINGS.MODULE_NAME, "perWeapons") + agio) return;
item.data.data.equipped = false;
}
if (item.type === "equipment") {
if (item.data.data.equipmentType == "vehicle" || item.data.data.equipmentType == "natural") return;
if (!check && (Math.floor(Math.random() * 100) + 1) <= game.settings.get(SETTINGS.MODULE_NAME, "perEquipment")) return;
if (!check && (Math.floor(Math.random() * 100) + 1) <= game.settings.get(SETTINGS.MODULE_NAME, "perEquipment") + agio) return;
item.data.data.equipped = false;
}
if (item.type === "consumable") {
if (!check && (Math.floor(Math.random() * 100) + 1) <= game.settings.get(SETTINGS.MODULE_NAME, "perConsumable")) return;
if (!check && (Math.floor(Math.random() * 100) + 1) <= game.settings.get(SETTINGS.MODULE_NAME, "perConsumable") + agio) return;
}
if (item.type === "loot") {
if (this.ConvertItens2Coins(item)) return;
let matches = item.name.match(/Table:([\w\s\S]+)/gis);
//if (this.ConvertItens2Coins(item)) return;
let matches = item.name.match(/\([a-z]{1,2}\)$/gs);
if (matches) {
let t = matches[0].split('Table:');
this.ConvertItens2Coins(coin, item);
}
let tmatches = item.name.match(/Table:([\w\s\S]+)/gis);
if (tmatches) {
let t = tmatches[0].split('Table:');
tables.push(t[1].trim());
return;
}
Expand All @@ -162,19 +170,24 @@ export class ActionLoot {
return ac;
}


async ConvertItems2TableLoot(tableroll) {
let nItems = [];
let table = game.tables.getName(tableroll);
if (this.betterTables && this.betterTables.active) {
//Bettertable
let re = await table.roll();
let result = await re.results;
//console.log(result);
for (let r of result) {
let packs = game.packs.get(r.collection);
let entity = (packs) ? await packs.getEntity(r.resultId) : game.items.get(r.resultId);
if (this.ConvertItens2Coins(entity)) return;
nItems.push(entity);
let matches = entity.name.match(/\([a-z]{1,2}\)$/gs);
if (matches) {
let coin = matches[0].substring(1, matches[0].length - 1);
this.ConvertItens2Coins(coin, entity);
} else {
nItems.push(entity);
}
}
} else {
//Vanilla
Expand All @@ -183,29 +196,28 @@ export class ActionLoot {
for (let r of result) {
let packs = game.packs.get(r.collection);
let entity = (packs) ? await packs.getEntity(r.resultId) : game.items.get(r.resultId);
if (this.ConvertItens2Coins(entity)) return;
nItems.push(entity);
let matches = entity.name.match(/\([a-z]{1,2}\)$/gs);
if (matches) {
let coin = matches[0].substring(1, matches[0].length - 1);
this.ConvertItens2Coins(coin, entity);
} else {
nItems.push(entity);
}
}
}
// console.log("items", nItems);
console.log("items", nItems);
console.log(this.lootCurrency);
return nItems;
}

ConvertItens2Coins(item) {
let matches = item.name.match(/\([a-z]{1,2}\)$/gs);
if (matches) {
let coin = matches[0].substring(1, matches[0].length - 1);
if (!this.lootCurrency[`${coin}`]) this.lootCurrency[`${coin}`] = 0;
if (item.data.data.source.match(/[dkfhxo]{1}[0-9\s\+\-\*\/]+/gs)) {
let r = new Roll(item.data.data.source);
this.lootCurrency[`${coin}`] += r.evaluate().total;
} else {
this.lootCurrency[`${coin}`] += item.data.data.quantity;
}
Object.keys(this.lootCurrency).sort()
return true;
ConvertItens2Coins(coin, item) {
if (!this.lootCurrency[`${coin}`]) this.lootCurrency[`${coin}`] = 0;
if (item.data.data.source.match(/[dkfhxo]{1}[0-9\s\+\-\*\/]+/gs)) {
let r = new Roll(item.data.data.source);
this.lootCurrency[`${coin}`] += r.evaluate().total;
} else {
this.lootCurrency[`${coin}`] += item.data.data.quantity;
}
return false;
}

ResultChat(titleChat, items, targetName, currency) {
Expand Down
16 changes: 16 additions & 0 deletions scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,20 @@ Hooks.once("init", () => {
default: true,
type: Boolean
});
game.settings.register(SETTINGS.MODULE_NAME, "lootEquipable", {
name: game.i18n.localize('Looting.Settings.lootEquipable'),
hint: game.i18n.localize('Looting.Settings.lootEquipableHint'),
scope: "world",
config: true,
default: true,
type: Boolean
});
game.settings.register(SETTINGS.MODULE_NAME, "lootEquipableAgil", {
name: game.i18n.localize('Looting.Settings.lootEquipableAgil'),
hint: game.i18n.localize('Looting.Settings.lootEquipableAgilHint'),
scope: "world",
config: true,
default: "5",
type: Number
});
});

0 comments on commit 7a3bb85

Please sign in to comment.