Divergent/mods/Animated Lead Box/gamedata/scripts/zzz_af_box_anim.script

97 lines
2.6 KiB
Plaintext

local original = actor_effects.play_item_fx
function actor_effects.play_item_fx(item)
if item == "container_tool_lead_box_dummy" or item == "lead_box_dummy" then
return
end
original(item)
end
anim_item = nil
active_slot = nil
af = nil
banned_af = {
"af_monolith"
}
function use_box()
game.only_allow_movekeys(true)
if zzz_ea_addon_backpack then
zzz_ea_addon_backpack.actor_on_item_use(db.actor)
end
-- Patch for FDDA Backpack Animations
if zzz_ea_addon_backpack and zzz_ea_addon_backpack.anim_enabled then
zzz_ea_addon_backpack.det_active = nil
active_slot = zzz_ea_addon_backpack.active_slot
else
active_slot = db.actor:active_slot()
end
get_hud():HideActorMenu()
anim_item = "lead_box_"..af.."_hud"
give_object_to_actor(anim_item)
level.add_call( function () return db.actor:object(anim_item) end, function ()
db.actor:activate_slot(14)
end)
end
local originalItms = itms_manager.use_arty_container
function itms_manager.use_arty_container(obj)
if (string.find(obj:section(), "(lead.-_box)",3)) then
break_arty = obj:section():gsub("_lead_box", "")
af = "holst_"..break_arty
use_box(break_arty)
end
originalItms(obj)
end
function ActorMenu_on_item_drag_drop(obj_1, obj_2, slot_from, slot_to)
local bannedSet = {}
for _, obj_1 in ipairs(banned_af) do
bannedSet[obj_1] = true
end
if bannedSet[obj_1:section()] then
return
end
if obj_2:section() == "lead_box" and ini_sys:r_string_ex(obj_1:section(),"kind") == "i_arty" then
if (ini_sys:r_string_ex(obj_1:section(),"class") == "ARTEFACT") or (ini_sys:r_string_ex(obj_1:section(),"class") == "SCRPTART") then
af = obj_1:section()
use_box(af)
end
end
end
function actor_on_hud_animation_end(item,section,motion,state,slot)
if motion == "anm_show" and item:section() == anim_item then
alife():release(alife():object(db.actor:object(anim_item):id()), true)
db.actor:activate_slot(0)
level.add_call( function () return db.actor:active_slot() == 0 end, function ()
db.actor:activate_slot(active_slot)
anim_item = nil
af = nil
active_slot = nil
game.only_allow_movekeys(false)
end)
end
end
function actor_on_first_update()
local active_item = db.actor:active_item()
if active_item and string.find(active_item:section(), "lead_box") then
alife():release(alife():object(db.actor:object(active_item:section()):id()), true)
end
end
function on_game_start()
RegisterScriptCallback("actor_on_hud_animation_end",actor_on_hud_animation_end)
RegisterScriptCallback("ActorMenu_on_item_drag_drop",ActorMenu_on_item_drag_drop)
RegisterScriptCallback("actor_on_first_update",actor_on_first_update)
end