Viewing old revision of Module:Game
You are viewing an old revision of this page from 3/2/2026, 1:47:39 PM.
View latest versionconst VENDOR_SELL_MODIFIER = 0.38;
const Utils = require("Utils");
function getSellPrice(buyPrice) {
return buyPrice ? Math.floor(Math.max(buyPrice * VENDOR_SELL_MODIFIER, 1)) : "N/A";
}
async function calculateItemDropFromList(dropList, itemGuid, options = {}) {
if (!Array.isArray(dropList) || !itemGuid) {
return null;
}
const entry = dropList.find(e => e?.guid === itemGuid);
if (!entry) return null;
const dropChance = Number(entry.dropChance) || 0;
// 🔹 Creep-style quantity (Unity Random.Range)
if (entry.dropQuantity !== undefined) {
const dropQuantity = Number(entry.dropQuantity) || 1;
// Unity Random.Range(1, dropQuantity)
const maxActual = Math.max(1, dropQuantity - 1);
const averageQuantity =
maxActual > 1 ? (1 + maxActual) / 2 : 1;
return {
dropChance,
quantityMin: 1,
quantityMax: maxActual,
averageQuantity,
effectiveDrop: dropChance * averageQuantity
};
}
// 🔹 Loot-table fixed quantity
const quantity = Number(entry.quantity) || 1;
return {
dropChance,
quantityMin: quantity,
quantityMax: quantity,
averageQuantity: quantity,
effectiveDrop: dropChance * quantity
};
}
async function calculateCreepDrops(creep, itemGuid, options = {}) {
if (
!creep ||
!itemGuid ||
!creep.loot ||
!Array.isArray(creep.loot.items)
) {
return null;
}
const lootEntry = creep.loot.items.find(
entry => entry?.guid === itemGuid
);
if (!lootEntry) return null;
const item = await Utils.resolveItemByGuid(itemGuid, options);
if (!item) return null;
const dropChance = Number(lootEntry.dropChance) || 0;
const dropQuantity = Number(lootEntry.dropQuantity) || 1;
// Unity Random.Range(1, dropQuantity)
const maxActual = Math.max(1, dropQuantity - 1);
const averageQuantity = maxActual > 1
? (1 + maxActual) / 2
: 1;
return {
creepId: creep.id ?? null,
creepName: creep.name ?? null,
itemGuid,
itemName: item.name ?? lootEntry.name ?? null,
dropChance,
quantityMin: 1,
quantityMax: maxActual,
averageQuantity,
effectiveDrop: dropChance * averageQuantity
};
}
async function calculateCreepDrops(creep, itemGuid, options = {}) {
if (!creep?.loot?.items) return null;
return calculateItemDropFromList(
creep.loot.items,
itemGuid,
options
);
}
async function calculateLootTableDrops(table, itemGuid, options = {}) {
if (!table?.drops) return null;
return calculateItemDropFromList(
table.drops,
itemGuid,
options
);
}
exports = {
getSellPrice,
calculateCreepDrops,
calculateLootTableDrops
}