Viewing old revision of Module:Game
You are viewing an old revision of this page from 3/17/2026, 4:59:09 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?.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 dyeToRGB(dye, base = { r: 255, g: 255, b: 255 }) {
let { _hue = 0, _saturation = 0, _brightness = 0, _contrast = 1 } = dye;
// Convert hue (0–360), saturation (0–1), value=1 into RGB
const h = ((_hue % 360) + 360) % 360;
const s = Math.max(0, Math.min(1, _saturation));
const v = 1;
const c = v * s;
const x = c * (1 - Math.abs((h / 60) % 2 - 1));
const m = v - c;
let r = 0, g = 0, b = 0;
if (h < 60) [r, g, b] = [c, x, 0];
else if (h < 120) [r, g, b] = [x, c, 0];
else if (h < 180) [r, g, b] = [0, c, x];
else if (h < 240) [r, g, b] = [0, x, c];
else if (h < 300) [r, g, b] = [x, 0, c];
else [r, g, b] = [c, 0, x];
r = (r + m) * 255;
g = (g + m) * 255;
b = (b + m) * 255;
// Apply brightness (-1..1)
r += 255 * _brightness;
g += 255 * _brightness;
b += 255 * _brightness;
// Apply contrast
r = (r - 128) * _contrast + 128;
g = (g - 128) * _contrast + 128;
b = (b - 128) * _contrast + 128;
// Clamp
r = Math.max(0, Math.min(255, Math.round(r)));
g = Math.max(0, Math.min(255, Math.round(g)));
b = Math.max(0, Math.min(255, Math.round(b)));
return `rgb(${r}, ${g}, ${b})`;
}
exports = {
getSellPrice,
calculateCreepDrops,
calculateLootTableDrops,
dyeToRGB
}