local ____lualib = require("lualib_bundle") local __TS__ArraySplice = ____lualib.__TS__ArraySplice local __TS__ArrayMap = ____lualib.__TS__ArrayMap local Set = ____lualib.Set local __TS__New = ____lualib.__TS__New local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter local ____exports = {} local ____constants = require("equipment.constants") local EQUIPMENT_SLOTS = ____constants.EQUIPMENT_SLOTS local EQUIPMENT_STAT_POOL = ____constants.EQUIPMENT_STAT_POOL local ____balance = require("equipment.balance") local getDifficultyBaseRarity = ____balance.getDifficultyBaseRarity local getRarityBaseStatCount = ____balance.getRarityBaseStatCount local maybeUpgradeRarityAtDrop = ____balance.maybeUpgradeRarityAtDrop local function rollSlot(self) return EQUIPMENT_SLOTS[RandomInt(0, #EQUIPMENT_SLOTS - 1) + 1] end local function rollStatValuePct(self, rarity) repeat local ____switch4 = rarity local ____cond4 = ____switch4 == "uncommon" if ____cond4 then return RandomInt(1, 5) end ____cond4 = ____cond4 or ____switch4 == "rare" if ____cond4 then return RandomInt(3, 8) end ____cond4 = ____cond4 or ____switch4 == "epic" if ____cond4 then return RandomInt(6, 12) end ____cond4 = ____cond4 or ____switch4 == "legendary" if ____cond4 then return RandomInt(10, 16) end do return RandomInt(1, 5) end until true end local function pickUniqueStatKeys(self, count) local pool = {unpack(EQUIPMENT_STAT_POOL)} local result = {} local capped = math.max( 1, math.min(count, #pool) ) while #result < capped and #pool > 0 do local idx = RandomInt(0, #pool - 1) local picked = unpack(__TS__ArraySplice(pool, idx, 1)) result[#result + 1] = picked end return result end function ____exports.rollInitialStatsByRarity(self, rarity) local statCount = getRarityBaseStatCount(nil, rarity) return __TS__ArrayMap( pickUniqueStatKeys(nil, statCount), function(____, statKey) return { statKey = statKey, valuePct = rollStatValuePct(nil, rarity) } end ) end function ____exports.rollRandomUpgradeDeltaPct(self) return RandomInt(1, 3) end function ____exports.rollAdditionalStatForStageFive(self, existingStats, rarity) local used = __TS__New( Set, __TS__ArrayMap( existingStats, function(____, x) return x.statKey end ) ) local available = __TS__ArrayFilter( EQUIPMENT_STAT_POOL, function(____, k) return not used:has(k) end ) if #available <= 0 then return nil end local picked = available[RandomInt(0, #available - 1) + 1] return { statKey = picked, valuePct = rollStatValuePct(nil, rarity) } end function ____exports.rollPostMatchItem(self, playerId, difficultyKey) local steamId = PlayerResource:GetSteamAccountID(playerId) local baseRarity = getDifficultyBaseRarity(nil, difficultyKey) local rarity = maybeUpgradeRarityAtDrop(nil, baseRarity, difficultyKey) local slotType = rollSlot(nil) local now = math.floor(GameRules:GetGameTime() * 1000) local instanceId = (((tostring(steamId) .. "_") .. tostring(now)) .. "_") .. tostring(RandomInt(1000, 9999)) return { instanceId = instanceId, templateId = (("equip_" .. slotType) .. "_") .. rarity, slotType = slotType, rarity = rarity, upgradeStage = 0, stats = ____exports.rollInitialStatsByRarity(nil, rarity), createdAt = now } end return ____exports