--[[ Изменения script_version: 4 - сохранение поля job_online 5 - сохранение поля was_in_smart_terrain ]] class "se_monster" (cse_alife_monster_base) -------------------- function se_monster:__init (section) super (section) self.ini = nil self.ini_initialized = false self.spawner_present = false self.smart_terrain_conditions = nil self.smart_terrain_conditions_initialized = false self.check_distance = false self.min_distance = 150 -- этот флаг берётся из работы смарта -- true = всегда в онлайне -- false = всегда в офлайне -- condlist = условие, которое отпределяет true или false -- nil = смарту всё равно self.job_online = nil self.job_online_condlist = nil self.m_registred = false db.offline_objects[self.id] = {} end -------------------- function se_monster:get_ini() if not self.ini_initialized then self.ini = self:spawn_ini () self.ini_initialized = true -- if self.ini:section_exist("spawner") then -- self.spawner = xr_logic.parse_condlist(db.actor, "spawner", "cond", self.ini:r_string("spawner", "cond")) -- end end end -------------------- function se_monster:can_switch_offline() if self.group_id ~= 65535 then return true end return cse_alife_monster_base.can_switch_offline(self) end -------------------- function se_monster:can_switch_online() if self.group_id ~= 65535 then return true end return cse_alife_monster_base.can_switch_online(self) end function se_monster:switch_online() cse_alife_monster_base.switch_online(self) end function se_monster:switch_offline() cse_alife_monster_base.switch_offline(self) end ----------------------- function se_monster:STATE_Write(packet) cse_alife_monster_base.STATE_Write (self, packet) if self.online then packet:w_stringZ(tostring(level and level.object_by_id(self.id) and level.object_by_id(self.id):level_vertex_id())) else packet:w_stringZ(tostring(db.offline_objects[self.id] and db.offline_objects[self.id].level_vertex_id)) end packet:w_stringZ(tostring(db.offline_objects[self.id] and db.offline_objects[self.id].active_section)) end -------------------- function se_monster:STATE_Read(packet, size) cse_alife_monster_base.STATE_Read (self, packet, size) if self.script_version > 10 then local old_lvid = packet:r_stringZ() if db.offline_objects[self.id] == nil then db.offline_objects[self.id] = {} end db.offline_objects[self.id].active_section = packet:r_stringZ() if db.offline_objects[self.id].active_section == "nil" then db.offline_objects[self.id].active_section = nil end if old_lvid ~= "nil" then db.offline_objects[self.id].level_vertex_id = tonumber(old_lvid) end end end -------------------- function se_monster:on_before_register() end -------------------- function se_monster:on_register() cse_alife_monster_base.on_register( self ) printf("registering monster %s ", self:name()) self.m_registred = true self.board = sim_board.get_sim_board() -- Проверяем кастомдату обьекта на наличие стори айди. story_objects.check_spawn_ini_for_story_id(self) if db.offline_objects[self.id] == nil then db.offline_objects[self.id] = {} end -- db.offline_objects[self.id].level_vertex_id = self.m_level_vertex_id --' Отключаем старый метод выбора смарттеррейнов. self:brain():can_choose_alife_tasks(false) --' Выбор смарта local obj_ini = self:spawn_ini() local smart = utils.cfg_get_string(obj_ini, "logic", "smart_terrain", self, false, "", "") local smart_obj = self.board:get_smart_by_name(smart) if smart_obj == nil then return end alife():object(smart_obj.id):register_npc(self) end -------------------- function se_monster:on_unregister() local strn_id = self:smart_terrain_id() if strn_id ~= 65535 then local smart = alife():object(strn_id) if smart ~= nil then smart:unregister_npc(self) end end db.offline_objects[self.id] = nil unregister_story_object_by_id(self.id) cse_alife_monster_base.on_unregister(self) end -------------------- function se_monster:on_death(killer) cse_alife_monster_base.on_death(self, killer) smart_terrain.on_death(self) if self.group_id ~= 65535 then local squad = alife():object(self.group_id) if squad == nil then --printf("sim_board squads") --print_table(self.board.squads) abort("There is no squad with ID [%s]", self.group_id) end squad:on_npc_death(self) end end -------------------- function se_monster:update() cse_alife_monster_base.update(self) end