--[[ Изменения script_version: 3 - сохранение поля job_online 5 - сохранение поля was_in_smart_terrain 6 - сохранение поля death_droped ]] -- nv170413 some optimization updates for ZRP 1.09, use global actor local math_ceil = math.ceil local math_floor = math.floor local math_mod = math.mod local math_random = math.random class "se_stalker" (cse_alife_human_stalker) -------------------- function se_stalker:__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 -- этот флаг берётся из работы смарта -- true = всегда в онлайне -- false = всегда в офлайне -- condlist = условие, которое отпределяет true или false -- nil = смарту всё равно self.job_online = nil self.job_online_condlist = nil -- посещал ли сталкер хоть один smart_terrain self.was_in_smart_terrain = false self.death_droped = false --'Генерил ли персонаж выпадаемые предметы или нет. --' Test for dima self.dont_spawn_online = false --' Вызывался ли генератор ссылок на тайники. self.treasure_processed = false ----- Live stalker ranking addon - BEGIN ----- self.rank_updated = false ----- Live stalker ranking addon - END ----- end -------------------- function se_stalker:get_ini() if not self.ini_initialized then self.ini = self:spawn_ini () self.ini_initialized = true if self.ini:section_exist("spawner") then -- swap the calls for xr_logic.parse_condlist_q(src) and xr_logic.parse_condlist(db.actor, etc) to see more details about your error -- self.spawner = xr_logic.parse_condlist(db.actor, "spawner", "cond", self.ini:r_string("spawner", "cond")) self.spawner = xr_logic.parse_condlist_q(self.ini:r_string("spawner", "cond")) end end end -------------------- function se_stalker:get_job_online() if self.job_online_condlist == nil then return self.job_online else return xr_logic.pick_section_from_condlist(db.actor_proxy, self, self.job_online) ~= nil end end -------------------- function se_stalker:can_switch_offline () if self:get_job_online() ~= nil then return not self:get_job_online() else return cse_alife_human_stalker.can_switch_offline (self) end end -------------------- function se_stalker:can_switch_online () if self.dont_spawn_online == true then return false end if self:get_job_online() ~= nil then return self:get_job_online() end if self.ini == nil or self.spawner == nil then return cse_alife_human_stalker.can_switch_online(self) end if actor ~= nil and actor:alive () == false then return self.online end if self.online == false then return (xr_logic.pick_section_from_condlist(actor, self, self.spawner) ~= nil) and cse_alife_human_stalker.can_switch_online(self) else -- if xr_logic.pick_section_from_condlist(actor, self, self.spawner) ~= nil then -- return true -- end -- return false return xr_logic.pick_section_from_condlist(actor, self, self.spawner) ~= nil end end -------------------- function se_stalker:STATE_Write (packet) cse_alife_human_stalker.STATE_Write (self, packet) if self.job_online == true then packet:w_u8(0) elseif self.job_online == false then packet:w_u8(1) elseif self.job_online == nil then packet:w_u8(2) else packet:w_u8(3) packet:w_stringZ(self.job_online_condlist) end packet:w_bool(self.was_in_smart_terrain) --' Коряво, но желательна хоть такая совместимость. local flags = 0 if self.death_droped then flags = bit_or(flags, 1) end if self.treasure_processed then flags = bit_or(flags, 2) end packet:w_u8(flags) end -------------------- function se_stalker:STATE_Read (packet, size) cse_alife_human_stalker.STATE_Read (self, packet, size) if self.script_version >= 3 then local t = packet:r_u8() if t == 0 then self.job_online = true elseif t == 1 then self.job_online = false elseif t == 2 then self.job_online = nil else self.job_online_condlist = packet:r_stringZ() -- swap the calls for xr_logic.parse_condlist_q(src) and xr_logic.parse_condlist(nil, etc) to see more details about your error -- self.job_online = xr_logic.parse_condlist(nil, "se_stalker:STATE_Read", "job_online", self.job_online_condlist) self.job_online = xr_logic.parse_condlist_q(self.job_online_condlist) end end if self.script_version >= 5 then self.was_in_smart_terrain = packet:r_bool() end if self.script_version >= 6 then local flags = packet:r_u8() self.death_droped = bit_and(flags, 1) ~= 0 self.treasure_processed = bit_and(flags, 2) ~= 0 end end -------------------- function se_stalker:on_before_register() self:fill_exclusives() end -------------------- function se_stalker:on_register() cse_alife_human_stalker.on_register( self ) -- if(actor_stats.add_to_ranking~=nil)then local community = self:community() if not (community == "zombied" or community == "monolith") -- or community == "arena_enemy") -- nv150306 not used in vanilla then actor_stats.add_to_ranking(self.id) end -- end -- nv170521 added extra parameter to speed up processing --' Регистрация в таскменеджере task_manager.get_random_task():register_target(self, clsid_script_stalker) if self:alive() and self:smart_terrain_id() == 65535 then self:brain():update() end --' Нарисовать мапспот с собой --' if sim_statistic.show_stalker_spot == true and self:alive() then --' local community, rank = sim_statistic.getNpcType(self) --' level.map_add_object_spot_ser(self.id, "alife_presentation_"..community, self:name().." "..community) --' end end -------------------- function se_stalker:on_unregister() cse_alife_human_stalker.on_unregister(self) --' Убрать мапспот с собой --' if sim_statistic.show_stalker_spot == true then --' local community, rank = sim_statistic.getNpcType(self) --' level.map_remove_object_spot(self.id, "alife_presentation_"..community) --' end smart_terrain.unregister_npc(self) -- nv170521 added extra parameter to speed up processing --' Отрегистрация в таскменеджере task_manager.get_random_task():unregister_target(self, clsid_script_stalker) -- if(actor_stats.remove_from_ranking~=nil)then local community = self:community() if community == "zombied" or community == "monolith" -- or community == "arena_enemy" -- nv150306 not used in vanilla then return end actor_stats.remove_from_ranking(self.id) -- end end -------------------- function se_stalker:on_spawn() cse_alife_human_stalker.on_spawn(self) ----- Live stalker ranking addon - BEGIN ----- if not actor or actor:character_rank() < 900 then local community = self:community() if community ~= "monolith" and community ~= "zombied" and community ~= "trader" then --and community ~= "arena_enemy" then if self:rank() > 600 then self:set_rank(math_ceil(((self:rank() - 600) * 0.7) + 600)) end end end ----- Live stalker ranking addon - END ----- end -------------------- function se_stalker:on_death(killer) cse_alife_human_stalker.on_death(self, killer) --[[ --nv150425 not currently used --' Убрать мапспот с собой if sim_statistic.show_stalker_spot == true then local community, rank = sim_statistic.getNpcType(self) level.map_remove_object_spot(self.id, "alife_presentation_"..community) end --]] ----- Live stalker ranking addon - BEGIN ----- if IsStalker(killer) and killer:clsid() ~= clsid_actor then --access tweak local community = killer:community() if community ~= "monolith" and community ~= "zombied" then --and community ~= "arena_enemy" then killer:set_rank(killer:rank() + math_ceil(self:rank() / 300)) end end ----- Live stalker ranking addon - END ----- end -------------------- function se_stalker:fill_exclusives() self:get_ini() self.smart_terrain_conditions = smart_terrain.read_smart_terrain_conditions( self ) if self.smart_terrain_conditions then for name, condlist in pairs(self.smart_terrain_conditions) do smart_terrain.exclusives[name] = (smart_terrain.exclusives[name] or 0) + 1 end end end ----- Live stalker ranking addon - BEGIN ----- function se_stalker:update() cse_alife_human_stalker.update(self) if self:alive() then local community = self:community() if community == "stalker" or community == "dolg" or community == "freedom" or community == "military" or community == "bandit" or community == "killer" then if math_mod(level.get_time_hours(), 3) == 0 and level.get_time_minutes() < 15 then if not self.rank_updated then local game_days = level.get_time_days() if game_days > 20 then game_days = 20 end local rank_gain = (game_days + math_floor(game_days / 6)) * (0.7 + level.get_game_difficulty() * 0.13) local rank_level = math_floor(self:rank() / 300) local full_prob, bonus_prob if rank_level == 0 then full_prob = 64 bonus_prob = 7 elseif rank_level == 1 then full_prob = 74 bonus_prob = 9 elseif rank_level == 2 then full_prob = 82 bonus_prob = 12 else full_prob = 88 bonus_prob = 17 end if math_random(100) <= full_prob then if math_random (100) <= bonus_prob then rank_gain = rank_gain * 1.25 end else rank_gain = rank_gain / 2 end if rank_gain - math_floor(rank_gain) > 0.5 then rank_gain = math_ceil(rank_gain) else rank_gain = math_floor(rank_gain) end rank_gain = rank_gain + math_random(-1, math_ceil(game_days / 10)) self:set_rank(self:rank() + rank_gain) self.rank_updated = true end elseif self.rank_updated then self.rank_updated = false end end end end ----- Live stalker ranking addon - END ----- --'Торговец class "se_trader" (cse_alife_trader) function se_trader:__init (section) super (section) end function se_trader:keep_saved_data_anyway() return true end