Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------- FIX WORLD MENU -------------------------------
- require "ISUI/ISWorldObjectContextMenu"
- local function predicateNotBroken(item)
- return not item:isBroken()
- end
- local old_getNumPlanks = nil
- local is_active_inject = nil -- true(active) / false(done) / nil(disabled)
- local temp_worldobjects = nil
- local temp_player = nil
- local temp_test = nil
- local temp_context = nil
- local function fn_getNumPlanks(self)
- local num = old_getNumPlanks(self)
- if is_active_inject == nil or temp_test then
- --print('INJECTED - idle')
- return num
- end
- if is_active_inject == false then
- --print('INJECTED - already done')
- return 0
- end
- --print('INJECTED - active')
- local playerObj = getSpecificPlayer(temp_player)
- local playerInv = playerObj:getInventory()
- local hasHammer = playerInv:containsTypeEvalRecurse("Hammer", predicateNotBroken) or playerInv:containsTypeEvalRecurse("HammerStone", predicateNotBroken)
- local hasCrowbar = playerInv:containsTypeEvalRecurse("Crowbar", predicateNotBroken)
- if thump ~= nil and not invincibleWindow and thump:getCanBarricade() then --print('thump')
- local ignoreObject = false;
- for _,v in pairs(temp_worldobjects) do
- if instanceof(v,"IsoWindow") and thump~=v then
- ignoreObject = true;
- break
- end
- end
- if not ignoreObject then
- local barricade = thump:getBarricadeForCharacter(playerObj)
- if (barricade and num > 0) and (hasHammer or hasCrowbar) then
- temp_context:addOption(getText("ContextMenu_Unbarricade"), temp_worldobjects, ISWorldObjectContextMenu.onUnbarricade, thump, temp_player);
- end
- end
- end
- if window ~= nil and not invincibleWindow then --print('window')
- local barricade = window:getBarricadeForCharacter(playerObj)
- if (barricade and num > 0) and (hasHammer or hasCrowbar) then
- temp_context:addOption(getText("ContextMenu_Unbarricade"), temp_worldobjects, ISWorldObjectContextMenu.onUnbarricade, window, temp_player);
- end
- end
- if door ~= nil then --print('door')
- local barricade = door:getBarricadeForCharacter(playerObj)
- if (barricade and num > 0) and (hasHammer or hasCrowbar) then
- temp_context:addOption(getText("ContextMenu_Unbarricade"), temp_worldobjects, ISWorldObjectContextMenu.onUnbarricade, door, temp_player);
- end
- end
- is_active_inject = false --done
- return 0
- end
- local old_createMenu = ISWorldObjectContextMenu.createMenu
- ISWorldObjectContextMenu.createMenu = function(player, worldobjects, x, y, test)
- --print('WORLD MENU')
- is_active_inject = true
- temp_worldobjects = worldobjects
- temp_player = player
- temp_test = test
- --local hasCrowbar = playerInv:containsTypeEvalRecurse("Crowbar", predicateNotBroken)
- --if thump ~= nil and not invincibleWindow then
- --if thump:getCanBarricade() then
- --local barricade = thump:getBarricadeForCharacter(playerObj)
- local context = old_createMenu(player, worldobjects, x, y, test)
- is_active_inject = nil
- return context
- end
- --Create permanent inject
- local is_planks_injected = nil
- local function fnPlanksInject(player, context) --, worldobjects, test)
- local obj = window or thump or door
- if not (obj and obj.getBarricadeForCharacter) then
- return
- end
- temp_context = context
- local playerObj = getSpecificPlayer(player)
- local barricade = obj:getBarricadeForCharacter(playerObj)
- if not barricade or is_planks_injected then
- return
- end
- is_planks_injected = true
- local m = getmetatable(barricade)
- old_getNumPlanks = m.__index.getNumPlanks
- m.__index.getNumPlanks = fn_getNumPlanks
- end
- Events.OnPreFillWorldObjectContextMenu.Add(fnPlanksInject)
- --Overwrite, sadly
- ISWorldObjectContextMenu.onUnbarricade = function(worldobjects, window, player)
- local playerObj = getSpecificPlayer(player)
- local playerInv = playerObj:getInventory()
- local tool = playerObj:getPrimaryHandItem()
- if luautils.walkAdjWindowOrDoor(playerObj, window:getSquare(), window) then
- local tool_type = tool and tool:getType()
- local is_hammer = tool_type == "Hammer" or tool_type == "HammerStone"
- local is_equipped_crowbar = tool_type == "Crowbar"
- if not is_equipped_crowbar and playerInv:contains("Crowbar") then
- local crowbar = playerInv:FindAndReturn("Crowbar")
- if crowbar:getCondition() > 0 then
- ISWorldObjectContextMenu.equip(playerObj, tool, "Crowbar", true);
- is_equipped_crowbar = true
- end
- end
- if not is_equipped_crowbar and not is_hammer then
- if playerInv:containsTypeEvalRecurse("Crowbar", predicateNotBroken) then
- ISWorldObjectContextMenu.equip(playerObj, tool, "Crowbar", true);
- is_equipped_crowbar = true
- elseif playerInv:containsTypeEvalRecurse("Hammer", predicateNotBroken) then
- ISWorldObjectContextMenu.equip(playerObj, tool, "Hammer", true);
- elseif playerInv:containsTypeEvalRecurse("HammerStone", predicateNotBroken) then
- ISWorldObjectContextMenu.equip(playerObj, tool, "HammerStone", true);
- end
- end
- local work_time = is_equipped_crowbar and 50
- or (600 - playerObj:getPerkLevel(Perks.Woodwork) * 30)
- ISTimedActionQueue.add(ISUnbarricadeAction:new(playerObj, window, work_time ));
- end
- end
- -------------------------- FIX ACTION -------------------------
- require "TimedActions/ISUnbarricadeAction"
- --Overwrite, sadly
- function ISUnbarricadeAction:isValid()
- if not instanceof(self.item, "BarricadeAble") or not self.item:getBarricadeForCharacter(self.character) then
- return false
- end
- local barricade = self.item:getBarricadeForCharacter(self.character)
- if barricade:isMetal() or barricade:isMetalBar() then
- if not self.character:hasEquipped("BlowTorch") then
- return false
- end
- else
- if barricade:getNumPlanks() == 0 then
- return false
- end
- if not self.character:hasEquipped("Hammer") and not self.character:hasEquipped("Crowbar") and not self.character:hasEquipped("HammerStone") then
- return false
- end
- end
- return true;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement