Viewing old revision of Module:Game
You are viewing an old revision of this page from 3/29/2026, 4:17:45 PM.
View latest versionconst VENDOR_SELL_MODIFIER = 0.38;
const Utils = require("Utils");
function getSellPrice(buyPrice) {
if (buyPrice == 0) return 0;
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?.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
);
}
function getRarityLabel(rarity) {
function getRarity(rarity) {
const args = Utils.resolveArgs(props);
const rarity = String(args["rarity"] ?? args[0]);
switch (rarity) {
case "rare":
case "1":
return { name: "Rare", class: "rarity-rare", color: "#3b82f6" };
case "exotic":
case "2":
return { name: "Exotic", class: "rarity-exotic", color: "#a855f7" };
case "cosmetic":
case "3":
return { name: "Cosmetic", class: "rarity-cosmetic", color: "#ec4899" };
default:
return { name: "Common", class: "rarity-common", color: "#9ca3af" };
}
}
exports = {
getSellPrice,
calculateCreepDrops,
calculateLootTableDrops,
getRarityLabel
}