local AddPrefabPostInit = AddPrefabPostInit local AddPlayerPostInit = AddPlayerPostInit local AddComponentPostInit = AddComponentPostInit GLOBAL.setfenv(1, GLOBAL) AddComponentPostInit("combat", function(self) local _DoAttack = self.DoAttack function self:DoAttack(targ, weapon, projectile, stimuli, ...) if weapon == nil then weapon = self:GetWeapon() end if weapon and not stimuli and (weapon.components.weapon == nil or weapon.components.weapon.overridestimulifn == nil) and self.inst.components.electricattacks == nil then stimuli = "blank" end return _DoAttack(self, targ, weapon, projectile, stimuli, ...) end end) local _PlayerDespawn local function OnPlayerDespawn(inst, player, cb) if player.components.playercontroller then player.components.playercontroller:Enable(false) end if player.components.locomotor then player.components.locomotor:StopMoving() player.components.locomotor:Clear() end TheWorld:DoTaskInTime(15, function() _PlayerDespawn(inst, player, cb) end) end AddComponentPostInit("playerspawner", function(self) _PlayerDespawn = self.inst.event_listeners["ms_playerdespawn"][self.inst][1] self.inst.event_listeners.ms_playerdespawn[self.inst][1] = OnPlayerDespawn end) AddComponentPostInit("worldmigrator", function(self) local _Activate = self.Activate function self:Activate(doer, ...) if doer and doer.can_enter_cave and doer.can_enter_cave:value() then return _Activate(self, doer) end return false, "NODESTINATION" end end) local function OnAttack(inst, data) local enemy = data and data.attacker if enemy and enemy:HasTag("player") then if inst.cave_cd then inst.cave_cd:Cancel() inst.cave_cd = nil end inst.cave_cd = inst:DoTaskInTime(60, function() inst.cave_cd:Cancel() inst.cave_cd = nil if inst.can_enter_cave then inst.can_enter_cave:set(true) end end) if inst.can_enter_cave then inst.can_enter_cave:set(false) end end end AddPlayerPostInit(function(inst) inst.can_enter_cave = net_bool(inst.GUID, "can_enter_cave", "can_enter_cave_dirty") inst.can_enter_cave:set(true) if not TheWorld.ismastersim then return end inst:ListenForEvent("attacked", OnAttack) end) local function OnMount(inst, data) if data and data.target and data.target:HasTag("woby") then inst.components.combat.canattack = false inst.components.inventory:FindItems(function(item) if item:HasTag("slingshot") and item.components.aoetargeting then item:DoTaskInTime(0, function () item.components.aoetargeting:SetEnabled(false) end) end end) end end local function OnDismount(inst) inst.components.combat.canattack = true inst.components.inventory:FindItems(function(item) if item:HasTag("slingshot") and item.components.aoetargeting then item.components.aoetargeting:SetEnabled(true) end end) end AddPrefabPostInit("walter", function(inst) if not TheWorld.ismastersim then return end inst:ListenForEvent("mounted", OnMount) inst:ListenForEvent("dismount", OnDismount) inst:RemoveEventCallback("healthdelta", inst.event_listeners.healthdelta[inst][1]) end) AddPrefabPostInit("wortox", function(inst) if not TheNet:IsDedicated() then inst:ListenForEvent("setowner", function(inst) inst:DoTaskInTime(0, function() if inst.components.playeractionpicker ~= nil then local _fn = inst.components.playeractionpicker.pointspecialactionsfn or function(...) return {} end inst.components.playeractionpicker.pointspecialactionsfn = function(inst, ...) local val = _fn(inst, ...) if next(val) then if (inst.replica.sanity and inst.replica.sanity:GetPercent() < 0.33) then return {} end end return val end end end) end) end if not TheWorld.ismastersim then return end local _TryToPortalHop = inst.TryToPortalHop inst.TryToPortalHop = function(inst, souls, ...) if _TryToPortalHop(inst, souls, ...) and inst.components.sanity:GetPercent() >= 0.33 then souls = souls or 1 if inst.components.health then inst.components.health:DoDelta(-5 * souls, nil, nil, true) end if inst.components.sanity then inst.components.sanity:DoDelta(-10 * souls, nil, nil, true) end return true end return false end end) local function OnPickup(inst, pickupguy) local guy = pickupguy or inst.components.inventoryitem:GetGrandOwner() if guy and guy.components.rider and guy.components.rider.mount and guy.components.rider.mount:HasTag("woby") and inst.components.aoetargeting then inst:DoTaskInTime(0, function () inst.components.aoetargeting:SetEnabled(false) end) end end local function OnDropped(inst) if inst.components.aoetargeting then inst.components.aoetargeting:SetEnabled(true) end end local function SlingshotPostInit(inst) if not TheWorld.ismastersim then return end inst.components.inventoryitem:SetOnPutInInventoryFn(OnPickup) inst.components.inventoryitem:SetOnDroppedFn(OnDropped) inst:DoTaskInTime(1, function() OnPickup(inst) end) end local slingshots = { "slingshot", "slingshotex", "slingshot999ex", "slingshot2", "slingshot2ex", } for i, v in ipairs(slingshots) do AddPrefabPostInit(v, SlingshotPostInit) end table.removearrayvalue(TUNING.GAMEMODE_STARTING_ITEMS.DEFAULT.WAXWELL, "waxwelljournal") table.removearrayvalue(TUNING.GAMEMODE_STARTING_ITEMS.DEFAULT.WATHGRITHR, "wathgrithrhat") TUNING.SLINGSHOT_AMMO_HONEY_DURATION = 1.5 local function GetUpvalueHelper(fn, name) local i = 1 while debug.getupvalue(fn, i) and debug.getupvalue(fn, i) ~= name do i = i + 1 end local name, value = debug.getupvalue(fn, i) return value, i end local function GetUpvalue(fn, ...) local prv, i, prv_var = nil, nil, "(the starting point)" for j,var in ipairs({...}) do assert(type(fn) == "function", "We were looking for "..var..", but the value before it, " ..prv_var..", wasn't a function (it was a "..type(fn) .."). Here's the full chain: "..table.concat({"(the starting point)", ...}, ", ")) prv = fn prv_var = var fn, i = GetUpvalueHelper(fn, var) end return fn, i, prv end local COMPONENT_ACTIONS = GetUpvalue(EntityScript.CollectActions, "COMPONENT_ACTIONS") local worldmigrator = COMPONENT_ACTIONS.SCENE.worldmigrator COMPONENT_ACTIONS.SCENE.worldmigrator = function(inst, doer, ...) if doer.can_enter_cave and doer.can_enter_cave:value() then worldmigrator(inst, doer, ...) end end