local UtilLib = require("BenUtils") local BenUtils = UtilLib.new() -- Globals LOOPLICATOR_PRE_ID = 0 LOOPLICATOR_POST_ID = 0 LOOPLICATOR_MULITPLIER = 2 LOOPLICATOR_ROUNDS = 10 LOOPLICATOR_XL_COST = 1 LOOPLICATOR_ALL_MODS = false LOOPLICATOR_NUM_MODS = 3 -- End Globals -- Internal functions ---@param pre number ---@param post number local function SetLooplicatorHookIds(pre, post) ModRef:SetSharedVariable("LooplicatorPreID", pre) ModRef:SetSharedVariable("LooplicatorPostID", post) end local function GetLooplicatorHookIds() local pre = ModRef:GetSharedVariable("LooplicatorPreID") local post = ModRef:GetSharedVariable("LooplicatorPostID") return pre, post end local function GetIsActive() return ModRef:GetSharedVariable("LooplicatorEnabled") end local function SetIsActive(active) ModRef:SetSharedVariable("LooplicatorEnabled", active) end -- End internal functions -- Mod functions ---@param PlayerName string function LooplicatorSettings(PlayerName, ...) print("[BenUtil] Got chat command loopset from " .. PlayerName) ---@class player ACrabPC local player = FindFirstOf("CrabPC") player:ServerSendChatMessage(BenUtils.StringToFString("Looplicator settings:")) player:ServerSendChatMessage(BenUtils.StringToFString(string.format("Enabled: %s", tostring(LOOPLICATOR_POST_ID > 0)))) player:ServerSendChatMessage(BenUtils.StringToFString(string.format("Num of rounds: %d", LOOPLICATOR_ROUNDS))) player:ServerSendChatMessage(BenUtils.StringToFString(string.format("XL cost: %d", LOOPLICATOR_XL_COST))) player:ServerSendChatMessage(BenUtils.StringToFString(string.format("Multiply all mods: %s", tostring(LOOPLICATOR_ALL_MODS)))) player:ServerSendChatMessage(BenUtils.StringToFString(string.format("Num of mods to Multiply: %d", LOOPLICATOR_NUM_MODS))) end function looplicator() local gamestate = FindFirstOf("CrabGS") local player = FindFirstOf("CrabPC") local island_num = gamestate.CurrentIsland if island_num % (LOOPLICATOR_ROUNDS) == 0.00 then gamestate.XLLevel = 1 player:ServerSendChatMessage(BenUtils.StringToFString("Looplicator Challenge Round")) player:ServerSendChatMessage(BenUtils.StringToFString("All Items will double their levels next round")) player:ServerSendChatMessage(BenUtils.StringToFString("If you win that is!")) end -- This checks to see if the last round was divisble by 10 if island_num ~= 1 and (island_num - 1) % LOOPLICATOR_ROUNDS == 0.00 then print("[BenUtils] Triggered Looplicator, doubling levels of all perks") local crabs = FindAllOf("CrabPS") if crabs then if LOOPLICATOR_ALL_MODS then ---@param v ACrabPS for i, v in ipairs(crabs) do ---@param wmod FCrabWeaponMod v.WeaponMods:ForEach(function(index, wmod) ---@class mod FCrabWeaponMod local mod = wmod:get() if mod.InventoryInfo.Level ~= 255 then if mod.InventoryInfo.Level * LOOPLICATOR_MULITPLIER < 255 then mod.InventoryInfo.Level = mod.InventoryInfo.Level * LOOPLICATOR_MULITPLIER else mod.InventoryInfo.Level = 255 end end end) ---@param wmod FCrabAbilityMod v.AbilityMods:ForEach(function(index, wmod) ---@class mod FCrabAbilityMod local mod = wmod:get() if mod.InventoryInfo.Level ~= 255 then if mod.InventoryInfo.Level * LOOPLICATOR_MULITPLIER < 255 then mod.InventoryInfo.Level = mod.InventoryInfo.Level * LOOPLICATOR_MULITPLIER else mod.InventoryInfo.Level = 255 end end end) ---@param wmod FCrabMeleeMod v.MeleeMods:ForEach(function(index, wmod) ---@class mod FCrabMeleeMod local mod = wmod:get() if mod.InventoryInfo.Level ~= 255 then if mod.InventoryInfo.Level * LOOPLICATOR_MULITPLIER < 255 then mod.InventoryInfo.Level = mod.InventoryInfo.Level * LOOPLICATOR_MULITPLIER else mod.InventoryInfo.Level = 255 end end end) ---@param wmod FCrabPerk v.Perks:ForEach(function(index, wmod) ---@class mod FCrabPerk local mod = wmod:get() if mod.InventoryInfo.Level ~= 255 then if mod.InventoryInfo.Level * LOOPLICATOR_MULITPLIER < 255 then mod.InventoryInfo.Level = mod.InventoryInfo.Level * LOOPLICATOR_MULITPLIER else mod.InventoryInfo.Level = 255 end end end) end else ---@type table for i, v in ipairs(crabs) do local mods = {} print(string.format("Crab with ID: %s", v.PlayerNamePrivate:ToString())) ---@param wmod FCrabWeaponMod v.WeaponMods:ForEach(function(index, wmod) ---@class mod FCrabWeaponMod local mod = wmod:get() table.insert(mods, mod) end) ---@param wmod FCrabAbilityMod v.AbilityMods:ForEach(function(index, wmod) ---@class mod FCrabAbilityMod local mod = wmod:get() table.insert(mods, mod) end) ---@param wmod FCrabMeleeMod v.MeleeMods:ForEach(function(index, wmod) ---@class mod FCrabMeleeMod local mod = wmod:get() table.insert(mods, mod) end) ---@param wmod FCrabPerk v.Perks:ForEach(function(index, wmod) ---@class mod FCrabPerk local mod = wmod:get() table.insert(mods, mod) end) -- Shuffle the mods table so the mods are more random BenUtils.ShuffleInPlace(mods) ---@type table local to_upgrade = {} for index, mod in ipairs(mods) do if #to_upgrade < LOOPLICATOR_NUM_MODS then if math.random(2) == 1 then print(string.format("Upgrading mod with index %d", index)) table.insert(to_upgrade, mod) end end end print(string.format("We have %s mods to upgrade", #to_upgrade)) for index, mod in ipairs(to_upgrade) do if mod.InventoryInfo.Level ~= 255 then if mod.InventoryInfo.Level * LOOPLICATOR_MULITPLIER < 255 then mod.InventoryInfo.Level = mod.InventoryInfo.Level * LOOPLICATOR_MULITPLIER else mod.InventoryInfo.Level = 255 end end end end end end end end function ToggleLooplicator() ---@type AcrabPC local player = FindFirstOf("CrabPC") if LOOPLICATOR_POST_ID == 0 and LOOPLICATOR_POST_ID == 0 then LOOPLICATOR_PRE_ID, LOOPLICATOR_POST_ID = RegisterHook("/Script/CrabChampions.CrabPC:ClientOnEnteredPortal", looplicator) player:ServerSendChatMessage(BenUtils.StringToFString("Enabling looplicator")) else UnregisterHook("/Script/CrabChampions.CrabPC:ClientOnEnteredPortal", LOOPLICATOR_PRE_ID, LOOPLICATOR_POST_ID) LOOPLICATOR_PRE_ID = 0 LOOPLICATOR_POST_ID = 0 player:ServerSendChatMessage(BenUtils.StringToFString("Disabling looplicator")) end end -- End mod functions -- Register Hooks and Commands RegisterKeyBind(Key.F3, function() print("[BenUtils] Enabled Looplicator\n") ExecuteInGameThread(function() ToggleLooplicator() end) end) BenUtils.RegisterCommand("looplicator", ToggleLooplicator) BenUtils.RegisterCommand("loopset", LooplicatorSettings) -- End Register Hooks and Commands -- -- Set init values here -- SetIsActive(false) -- -- End init values