--[[ scheme_type: generic author: Alundaio modified: Ravlik (aka Misery) modified data: 26 Oct., 2024 --]] -------------------------------------- actid = 188120 evaid = 188120 -------------------------------------- local is_box = { --["dynamics\\box\\box_1a"] = true, --["dynamics\\box\\box_1b"] = true, --["dynamics\\box\\box_1c"] = true, ["dynamics\\box\\box_wood_01"] = true, ["dynamics\\box\\box_wood_02"] = true } selected = {} ----------------------------------------------------------------------------------------- -- EVALUATOR NPC vs BOX ----------------------------------------------------------------------------------------- class "evaluator_npc_vs_box" (property_evaluator) function evaluator_npc_vs_box:__init(npc,name,storage) super (nil, name) self.st = storage end function evaluator_npc_vs_box:evaluate() --alun_utils.debug_write("eva_npc_vs_box") local npc = self.object if not (npc:alive()) then return false end if (IsWounded(npc)) then return false end if not (npc:active_item()) then return false end if state_mgr.is_npc_in_combat(npc) then --Ravlik, block scheme if npc in combat return false end local ret = false local itr = function(id) if not (ret) then local obj = id and db.storage[id] and db.storage[id].object if (obj and is_box[obj:get_visual_name()] and obj:position():distance_to_sqr(npc:position()) < 3) then ret = true end end end npc:iterate_feel_touch(itr) return ret end ----------------------------------------------------------------------------------------- -- ACTION NPC vs BOX ----------------------------------------------------------------------------------------- class "action_npc_vs_box" (action_base) function action_npc_vs_box:__init (npc,name,storage) super (nil,name) self.st = storage end function action_npc_vs_box:initialize() action_base.initialize(self) local npc = self.object npc:set_desired_position() npc:set_desired_direction() local bw = self.object:best_weapon() if (bw) then self.object:set_item(object.aim1,bw) end end function action_npc_vs_box:execute() action_base.execute(self) local obj local itr = function(id) if not (obj) then local o = id and db.storage[id] and db.storage[id].object if (o and is_box[o:get_visual_name()]) then obj = o end end end self.object:iterate_feel_touch(itr) if not (obj) then return end self.st.__tmr = self.st.__tmr or time_global()+8000 if (time_global() > self.st.__tmr) then local se_obj = alife_object(obj:id()) if (se_obj) then alife():release(se_obj,true) end self.st.__tmr = nil end local pos = vector():set(obj:position()) pos.y = pos.y + 0.4 local st = db.storage[self.object:id()].state_mgr self.object:clear_animations() st:set_state("idle", nil, nil, nil, {fast_set = true}) st.animation:set_state(nil, true) st.animation:set_control() st.animstate:set_state(nil,true) st.animstate:set_control() self.object:set_mental_state(anim.danger) self.object:set_body_state(move.crouch) self.object:set_movement_type(move.stand) self.object:set_sight(look.fire_point,pos) local bw = self.object:best_weapon() if (bw) then if (self.object:is_body_turning()) then self.object:set_item(object.aim1,bw) else self.object:set_item(object.fire1,bw,1,30) end end end function action_npc_vs_box:finalize() action_base.finalize(self) local bw = self.object:best_weapon() if (bw) then self.object:set_item(object.idle,bw) end self.st.__tmr = nil self.object:set_sight(look.direction, self.object:direction() , 0) self.object:set_desired_position() self.object:set_desired_direction() end --------------------------------------------------------- ---------------------- binder --------------------------- function setup_generic_scheme(npc,ini,scheme,section,stype,temp) local st = xr_logic.assign_storage_and_bind(npc,ini,"npc_vs_box",section,temp) end function add_to_binder(npc,ini,scheme,section,storage,temp) local manager = npc:motivation_action_manager() if (not npc:alive()) or (npc:character_community() == "zombied" or npc:section() == "actor_visual_stalker") then manager:add_evaluator(evaid,property_evaluator_const(false)) --temp.needs_configured = false else manager:add_evaluator(evaid,evaluator_npc_vs_box(npc,"eva_npc_vs_box",storage)) end temp.action = action_npc_vs_box(npc,"act_npc_vs_box",storage) temp.action:add_precondition(world_property(stalker_ids.property_alive,true)) temp.action:add_precondition(world_property(stalker_ids.property_danger, false)) temp.action:add_precondition(world_property(stalker_ids.property_anomaly,false)) temp.action:add_precondition(world_property(evaid,true)) temp.action:add_effect(world_property(evaid,false)) manager:add_action(actid,temp.action) end function configure_actions(npc,ini,scheme,section,stype,temp) --temp.action:add_precondition(world_property(xr_evaluators_id.state_mgr + 1,true)) temp.action:add_precondition(world_property(xr_evaluators_id.sidor_wounded_base,false)) temp.action:add_precondition(world_property(xr_evaluators_id.wounded_exist,false)) --[[ if (_G.schemes["rx_ff"]) then temp.action:add_precondition(world_property(rx_ff.evaid,false)) end --]] if (_G.schemes["gl"]) then temp.action:add_precondition(world_property(rx_gl.evid_gl_reload,false)) end --[[ if (_G.schemes["facer"]) then temp.action:add_precondition(world_property(xrs_facer.evid_facer,false)) temp.action:add_precondition(world_property(xrs_facer.evid_steal_up_facer,false)) end --]] local manager = npc:motivation_action_manager() local action local p = { stalker_ids.action_combat_planner, --xr_actions_id.state_mgr + 1, xr_actions_id.state_mgr + 2, xr_actions_id.alife } for i=1,#p do action = manager:action(p[i]) if (action) then action:add_precondition(world_property(evaid,false)) end end end function disable_generic_scheme(npc,scheme,stype) local st = db.storage[npc:id()][scheme] if st then st.enabled = false end end function npc_add_precondition(action) action:add_precondition(world_property(evaid,false)) end