-- modmain.lua GLOBAL.setmetatable(env, { __index = function(t, k) return GLOBAL.rawget(GLOBAL, k) end }) -- ========== 定义 FN 表 ========== FN = {} ---添加Actions,写个方法省事点,需要env function FN.AddAction(data, id, str, fn, wilsonAction, wilsonClientAction) local action = Action(data) action.id = id local oldActionStr if type(str) == "function" then -- action.stroverridefn = str --不用这个,这个需要直接返回文本require action.strfn = str oldActionStr = STRINGS.ACTIONS[string.upper(id)] else action.str = str end action.fn = fn env.AddAction(action) --AddAction里面会直接覆盖STRINGS.ACTIONS,真麻烦 STRINGS.ACTIONS[string.upper(id)] = oldActionStr or STRINGS.ACTIONS[string.upper(id)] if wilsonAction then env.AddStategraphActionHandler("wilson", ActionHandler(action, wilsonAction)) end if wilsonClientAction then env.AddStategraphActionHandler("wilson_client", ActionHandler(action, wilsonClientAction)) end return action end if not PrefabFiles then PrefabFiles = {} end TUNING.AAB_CONTAINER_AUTO_PICKUP = GetModConfigData("container_auto_pickup") or 64 TUNING.AAB_CONTAINER_AUTO_PICKUP_COUNT = GetModConfigData("container_auto_pickup_count") or 4 STRINGS.ACTIONS.AAB_CONTAINER_AUTO_PICKUP = { GENERIC = "开启自动拾取", CLOSE = "关闭自动拾取" } table.insert(PrefabFiles, "aab_polly_rogers") require("components/aab_container_auto_pickup") AddPrefabPostInitAny(function(inst) if not TheWorld.ismastersim then return end if inst.components.container then inst:AddComponent("aab_container_auto_pickup") end end) ---------------------------------------------------------------------------------------------------- AddStategraphActionHandler("polly_rogers", ActionHandler(ACTIONS.STORE, "give")) -- 修复科雷的bug,鸟被冻住后就动不了了 AddStategraphPostInit("polly_rogers", function(sg) sg.states["hit"].events["animover"].fn = function(inst) if inst.AnimState:AnimDone() then --科雷把这里错加了一个false inst.sg.statemem.stayonground = true inst.sg:GoToState("idle_ground") end end end) AddComponentAction("USEITEM", "inventoryitem", function(inst, doer, target, actions, right) if right and inst.prefab == "polly_rogershat" and target.replica.container then table.insert(actions, ACTIONS.AAB_CONTAINER_AUTO_PICKUP) end end) --FN.AddAction({ priority = 5 }, "AAB_CONTAINER_AUTO_PICKUP", function(act) -- return act.target:HasTag("aab_container_auto_pickup") and "CLOSE" or nil --end, function(act) -- if act.target and act.target.components.aab_container_auto_pickup then -- act.target.components.aab_container_auto_pickup:SetEnable(not act.target:HasTag("aab_container_auto_pickup")) -- act.invobject.components.stackable:Get():Remove() -- return true -- end --end, "dolongaction", "dolongaction") FN.AddAction( { priority = 5 }, "AAB_CONTAINER_AUTO_PICKUP", function(act) return act.target:HasTag("aab_container_auto_pickup") and "CLOSE" or nil end, function(act) if not act.target or not act.target.components.aab_container_auto_pickup then return false end local target = act.target local current = target:HasTag("aab_container_auto_pickup") target.components.aab_container_auto_pickup:SetEnable(not current) if not current then if not target:HasTag("aab_auto_pickup_initialized") then target:AddTag("aab_auto_pickup_initialized") act.invobject:Remove() end end return true end, "dolongaction", "dolongaction" ) --AddPrefabPostInitAny(function(inst) -- if not TheWorld.ismastersim then return end -- -- 如果实体有容器组件 -- if inst.components.container then -- -- 监听容器被拆毁事件 -- inst:ListenForEvent("onremove", function() -- if inst:HasTag("aab_auto_pickup_initialized") then -- SpawnPrefab("polly_rogershat").Transform:SetPosition(inst:GetPosition():Get()) -- end -- end) -- end --end)