class "evaluator_combat_enemy" (property_evaluator) function evaluator_combat_enemy:__init(storage, name) super(nil, name) self.st = storage --' Таймер ожидания выхода из боя self.st.timer = time_global() end function evaluator_combat_enemy:evaluate() local best_enemy = self.object:best_enemy() if best_enemy ~= nil and not xr_combat_ignore.is_enemy(self.object, best_enemy, db.storage[self.object:id()].combat_ignore, true) then return false end if best_enemy ~= nil and self.st.timer ~= nil then self.st.last_best_enemy_id = best_enemy:id() self.st.last_best_enemy_name = best_enemy:name() self.st.timer = nil return true end if best_enemy == nil and self.st.timer == nil then --printf("object name is [%s]", self.object:name()) local overrides = db.storage[self.object:id()].overrides local min = (overrides and overrides.min_post_combat_time*1000) or 10000 local max = (overrides and overrides.max_post_combat_time*1000) or 15000 if self.st.last_best_enemy_id == db.actor:id() then self.st.timer = time_global() else self.st.timer = time_global() + math.random(min, max) end end if self.st.timer == nil then return best_enemy ~= nil end if time_global() < self.st.timer then return true end if self.st.animation == nil then return false end self.st.animation:set_state(nil) return self.st.animation.states.anim_marker ~= nil end ---------------------------------------------------------------------------------------------------------------------- class "action_post_combat_wait" (action_base) function action_post_combat_wait:__init(npc, storage, action_name) super(nil, action_name) self.st = storage end function action_post_combat_wait:initialize() action_base.initialize(self) -- state_mgr.set_state(self.object, "hide") self.object:set_item(object.idle, self.object:best_weapon()) 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.danger, nil, 0) self.anim_st = { animstate = { states = {anim_marker = nil } } } self.st.animation = state_mgr_animation.animation(self.object, self.anim_st, "state_mgr_animation_list") self.anim_started = false end function action_post_combat_wait:execute() action_base.execute(self) if not self.object:in_smart_cover() then if self.anim_started == false and not weapon_locked(self.object) then self.anim_started = true self.st.animation:set_state("hide") self.st.animation:set_control() end end xr_sound.set_sound_play(self.object:id(), "post_combat_wait") end function action_post_combat_wait:finalize() xr_sound.set_sound_play(self.object:id(), "post_combat_relax") if self.anim_started == true then self.st.animation:set_state(nil, true) end self.st.animation = nil action_base.finalize(self) end function weapon_locked(npc) local weapon_strapped = npc:weapon_strapped() local weapon_unstrapped = npc:weapon_unstrapped() --log(string.format("%s [%s] [%s]", self.object:name(), tostring(weapon_strapped), tostring(weapon_unstrapped))) if not (weapon_unstrapped or weapon_strapped) then return true end local bestweapon = npc:best_weapon() if bestweapon == nil then return false end if npc:active_item() == nil then return false end local weapon_going_to_be_strapped = npc:is_weapon_going_to_be_strapped(bestweapon) if weapon_going_to_be_strapped and not weapon_strapped then return true end if not weapon_going_to_be_strapped and not weapon_unstrapped then return true end return false end function add_post_combat_idle(npc) local manager = npc:motivation_action_manager() local combat_action = manager:action(stalker_ids.action_combat_planner) --combat_action:show("") local combat_action_planner = cast_planner(combat_action) db.storage[npc:id()].post_combat_wait = {} local storage = db.storage[npc:id()].post_combat_wait manager:remove_evaluator(stalker_ids.property_enemy) manager:add_evaluator(stalker_ids.property_enemy, evaluator_combat_enemy(storage, "evaluator_combat_enemy")) combat_action_planner:remove_evaluator(stalker_ids.property_enemy) combat_action_planner:add_evaluator(stalker_ids.property_enemy, evaluator_combat_enemy(storage, "evaluator_combat_enemy")) combat_action_planner:remove_action(stalker_ids.action_post_combat_wait) local new_action = this.action_post_combat_wait(npc, storage, "action_post_combat_wait") new_action:add_precondition(world_property(stalker_ids.property_enemy, true)) new_action:add_precondition(world_property(stalker_ids.property_pure_enemy, false)) new_action:add_precondition(world_property(stalker_ids.property_critically_wounded, false)) new_action:add_precondition(world_property(stalker_ids.property_danger_grenade, false)) new_action:add_effect(world_property(stalker_ids.property_enemy, false)) combat_action_planner:add_action(stalker_ids.action_post_combat_wait, new_action) end