ATLYSS TechPendium

Viewing old revision of Module:Game

You are viewing an old revision of this page from 3/21/2026, 5:35:08 PM.

View latest version
This Module contains Internal Wiki logic and must be loaded using require keyword inside other logic modules.
Note that require supports only static imports.
This module can't be {{#invoke}}-ed.
const 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
    );
}

exports = {
  getSellPrice,
  calculateCreepDrops,
  calculateLootTableDrops
}
Last Edited by LiveGobe on 3/21/2026, 5:35:08 PM

This page categories: