Advertisement
Guest User

bind_stalker.script

a guest
Mar 11th, 2013
528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.98 KB | None | 0 0
  1. function init    (obj)
  2.     xr_motivator.AddToMotivator(obj)
  3. end
  4.  
  5. function actor_init    (npc)
  6.     npc:bind_object(actor_binder(npc))
  7. end
  8.  
  9. local game_difficulty_by_num = {
  10.     [0] = "gd_novice",
  11.     [1] = "gd_stalker",
  12.     [2] = "gd_veteran",
  13.     [3] = "gd_master"
  14.     }
  15.  
  16. lasthealth  = 0
  17. lasttime    = 0
  18. post_process = 0
  19. local weapon_hide = false
  20. ----------------------------------------------------------------------------------------------------------------------
  21. class "actor_binder" (object_binder)
  22. ----------------------------------------------------------------------------------------------------------------------
  23. function actor_binder:__init (obj) super(obj)
  24.     self.bCheckStart = false
  25.     self.weather_manager = level_weathers.WeatherManager()
  26.     self.actor_detector = xr_detector.actor_detector()
  27. end
  28. ----------------------------------------------------------------------------------------------------------------------
  29. function actor_binder:net_spawn(data)
  30.     printf("actor net spawn")      
  31.  
  32.     level.show_indicators()
  33.  
  34.     self.bCheckStart = true
  35.     self.weapon_hide = false -- спрятано или нет оружие при разговоре.
  36.     weapon_hide = false -- устанавливаем глобальный дефолтовый флаг.
  37.  
  38.     if object_binder.net_spawn(self,data) == false then
  39.         return false
  40.     end
  41.  
  42.     db.add_actor(self.object)
  43.    
  44.     if self.st.disable_input_time == nil then
  45.         level.enable_input()
  46.     end
  47.  
  48.     self.weather_manager:reset()
  49. --  game_stats.initialize ()
  50.  
  51.     if(actor_stats.add_to_ranking~=nil)then
  52.         actor_stats.add_to_ranking(self.object:id())
  53.     end
  54.  
  55.     --' Загружаем настройки дропа
  56.     death_manager.init_drop_settings()
  57.  
  58.     nightvision.pnv("nightvision_nil",1)
  59.     xr_logic.pstor_store(db.actor, "nv_on", "nil")
  60.    
  61.     return true
  62. end
  63. ----------------------------------------------------------------------------------------------------------------------
  64. function actor_binder:net_destroy()
  65.     if(actor_stats.remove_from_ranking~=nil)then
  66.         actor_stats.remove_from_ranking(self.object:id())
  67.     end
  68. --  game_stats.shutdown ()
  69.     db.del_actor(self.object)
  70.  
  71.     sr_light.clean_up ()
  72.  
  73.     self.object:set_callback(callback.inventory_info, nil)
  74.     self.object:set_callback(callback.article_info, nil)
  75.     self.object:set_callback(callback.on_item_take, nil)
  76.     self.object:set_callback(callback.on_item_drop, nil)
  77.     --self.object:set_callback(callback.actor_sleep, nil)
  78.     self.object:set_callback(callback.task_state, nil)
  79.     self.object:set_callback(callback.level_border_enter, nil)
  80.     self.object:set_callback(callback.level_border_exit, nil)
  81.     self.object:set_callback(callback.take_item_from_box, nil)
  82.  
  83.     if sr_psy_antenna.psy_antenna then
  84.         sr_psy_antenna.psy_antenna:destroy()
  85.         sr_psy_antenna.psy_antenna = false
  86.     end
  87.  
  88.     xr_sound.stop_all_sound_object()
  89.  
  90.     object_binder.net_destroy(self)
  91. end
  92. ----------------------------------------------------------------------------------------------------------------------
  93. function actor_binder:reinit()
  94.     object_binder.reinit(self)
  95.    
  96.     local npc_id = self.object:id()
  97.  
  98.     db.storage[npc_id] = { }
  99.  
  100.     self.st = db.storage[npc_id]
  101.     self.st.pstor = nil
  102.  
  103.     self.next_restrictors_update_time = -10000
  104.  
  105.     self.object:set_callback(callback.inventory_info, self.info_callback, self)
  106.     self.object:set_callback(callback.article_info, self.article_callback, self)
  107.     self.object:set_callback(callback.on_item_take, self.on_item_take, self)
  108.     self.object:set_callback(callback.on_item_drop, self.on_item_drop, self)
  109.     self.object:set_callback(callback.trade_sell_buy_item, self.on_trade, self) -- for game stats
  110.     --self.object:set_callback(callback.actor_sleep, self.sleep_callback, self)
  111.     self.object:set_callback(callback.task_state, self.task_callback, self)
  112.     --self.object:set_callback(callback.map_location_added, self.map_location_added_callback, self)
  113.     self.object:set_callback(callback.level_border_enter, self.level_border_enter, self)
  114.     self.object:set_callback(callback.level_border_exit, self.level_border_exit, self)
  115.     self.object:set_callback(callback.take_item_from_box, self.take_item_from_box, self)
  116. end
  117. ----------------------------------------------------------------------------------------------------------------------
  118. function actor_binder:take_item_from_box(box, item)
  119.     local story_id = box:story_id()
  120.     if story_id == nil then
  121.         return
  122.     end
  123.  
  124.     treasure_manager.take_item_from_box(box, story_id)
  125. --[[   
  126.     local respawner = se_respawn.get_respawner_by_parent(story_id)
  127.     if respawner == nil then
  128.         return
  129.     end
  130.    
  131.     --' Необходимо уменьшить счетчик в респавнере
  132.     respawner:remove_spawned(item:id())
  133.  
  134.     local smart_terrain = db.strn_by_respawn[respawner:name()]
  135.     if smart_terrain == nil then
  136.         return
  137.     end
  138.  
  139.     local npc = smart_terrain.gulag:get_nearest_online_obj(db.actor:position())
  140.     if npc ~= nil then
  141.         xr_sound.set_sound_play(npc, "reac_box")
  142.         xr_gulag.setGulagEnemy(smart_terrain:name() , db.actor)    
  143.     end
  144. ]]
  145. end
  146. ----------------------------------------------------------------------------------------------------------------------
  147. function actor_binder:level_border_enter(npc, info_id)
  148.     self.actor_detector:actor_enter()
  149. end
  150. ----------------------------------------------------------------------------------------------------------------------
  151. function actor_binder:level_border_exit(npc, info_id)
  152.     self.actor_detector:actor_exit()
  153. end
  154. ----------------------------------------------------------------------------------------------------------------------
  155. function actor_binder:info_callback(npc, info_id)
  156.     printf("*INFO*: npc='%s' id='%s'", npc:name(), info_id)
  157.     --' Сюжет
  158.     level_tasks.proceed(self.object)
  159.     -- Отметки на карте
  160.     level_tasks.process_info_portion(info_id)
  161. end
  162. ----------------------------------------------------------------------------------------------------------------------
  163. function actor_binder:on_trade (item, sell_bye, money)
  164.     if sell_bye == true then
  165.        game_stats.money_trade_update (money)
  166.     else      
  167.        game_stats.money_trade_update (-money)
  168.     end  
  169. end
  170. ----------------------------------------------------------------------------------------------------------------------
  171. function actor_binder:article_callback(npc, group, name)
  172.     --printf("article_callback [%s][%s]", group, name)
  173.     if device().precache_frame >1 then return end
  174.    
  175.     if group == "Diary" then
  176.         news_manager.send_encyclopedy("diary", group)
  177.     else
  178.         news_manager.send_encyclopedy("encyclopedy", group)
  179.     end
  180. end
  181. ----------------------------------------------------------------------------------------------------------------------
  182. function actor_binder:on_item_take (obj)
  183.     level_tasks.proceed(self.object)
  184.    
  185.     if obj then
  186.         local takesect = obj:section()
  187.         local takeid = obj:id()
  188.         if string.sub(takesect,1,10) == "wpn_addon_" then
  189.             item_effects.convert_addon(takesect,takeid)
  190.         elseif string.sub(takesect,1,4) == "wpn_" and string.sub(takesect,1,10) ~= "wpn_addon_" then
  191.             item_effects.convert_wpn(takesect,takeid)
  192.         end
  193.     end
  194.     --game_stats.update_take_item (obj, self.object)
  195. end
  196. ----------------------------------------------------------------------------------------------------------------------
  197. function actor_binder:on_item_drop (obj)
  198.     level_tasks.proceed(self.object)
  199.    
  200. ----------------------------------------------Проверка на использование предметов by Kirag-----------
  201.     local objid, sect
  202.     if obj then
  203.         sect = obj:section()
  204.         objid = obj:id()
  205.         xr_logic.pstor_store(db.actor, "dropid", objid)
  206.         xr_logic.pstor_store(db.actor, "dropsect", sect)
  207.     end
  208. ---------------------------------------------------конец предметов--------]]
  209.  
  210.     --game_stats.update_drop_item (obj, self.object)
  211. end
  212. ----------------------------------------------------------------------------------------------------------------------
  213.  
  214. function actor_binder:task_callback(_task, _objective, _state)
  215.     task_manager.task_callback(_task:get_id(), _objective:get_idx(), _state)
  216.     if _objective:get_idx() == 0 then
  217.         if _state == task.fail then
  218.             news_manager.send_task(db.actor, "fail", _task, _objective)
  219.         elseif _state == task.completed then
  220.             task_manager.reward_by_task(_task)
  221.             news_manager.send_task(db.actor, "complete", _task, _objective)
  222.         else
  223.             news_manager.send_task(db.actor, "new", _task, _objective)
  224.         end
  225.     else
  226.         if _task:get_objective(0):get_state() == task.in_progress then
  227.             news_manager.send_task(db.actor, "update", _task, _objective)
  228.         end
  229.     end
  230. end
  231.  
  232. ----------------------------------------------------------------------------------------------------------------------
  233. function actor_binder:map_location_added_callback(spot_type_str, object_id)
  234.     if (false==app_ready()) or (device().precache_frame>1) then return end
  235.     --'news_manager.send_task(db.actor, "new")
  236. end
  237. ----------------------------------------------------------------------------------------------------------------------
  238. function actor_binder:update(delta)
  239.     object_binder.update(self, delta)
  240.  
  241.     -- DEBUG slowdown
  242. --  slowdown.update()
  243.  
  244.     local time = time_global()
  245.    
  246.     game_stats.update (delta, self.object)
  247.  
  248. ----------------------------------------------Проверка на использование предметов by Kirag-----------
  249.     local section, objid
  250.     objid = xr_logic.pstor_retrieve(db.actor, "dropid", -1)
  251.     sect = xr_logic.pstor_retrieve(db.actor, "dropsect", "non_exist")
  252.     if objid ~= -1 then
  253.         local obj = alife():object(objid)
  254.         if not obj then -- объект не существует, занчит использован
  255.             if string.sub(sect,1,3) == "nv_" then
  256.                 item_effects.nv_effect(sect)
  257.             elseif string.sub(sect,1,11) == "fake_addon_" then
  258.                 item_effects.fake_scope_effect(sect)
  259.             end
  260.         end
  261.         xr_logic.pstor_store(db.actor, "dropid", -1)
  262.         xr_logic.pstor_store(db.actor, "dropsect", "non_exist")
  263.     end
  264.    
  265. -- news_manager.send_tip(db.actor, "test_message", nil, nil, 20000)
  266.  
  267.  
  268. ---------------------------------------------------конец предметов--------
  269.  
  270.     item_effects.fake_scope_effect_take_wpn()
  271.  
  272. ---------------------------------------------------ночной прицел--------
  273.  
  274.     nightvision.scope_nv() 
  275. ----------------------------------------------------------------------------------]]   
  276.  
  277.     -- апдейт погоды
  278.     self.weather_manager:update()
  279.    
  280.     -- апдейт схемы детектора
  281.     self.actor_detector:update()
  282.  
  283.     -- апдейт звуковой схемы актера
  284.     xr_sound.update_actor()
  285.    
  286.     --' Проверка потери жизни
  287. --[[
  288.     if self.object.health - lasthealth > 0.001 or
  289.        self.object.health - lasthealth < -0.001 then
  290.         printf("%f | %f", self.object.health, self.object.health - lasthealth, game.time() - lasttime)
  291.         lasthealth = self.object.health
  292.         lasttime = game.time()
  293.     end
  294. ]] 
  295.     -- Обновление отключения ввода с клавиатуры.
  296.     if self.st.disable_input_time ~= nil and
  297.        game.get_game_time():diffSec(self.st.disable_input_time) >= self.st.disable_input_idle
  298.     then
  299.         level.enable_input()
  300.         self.st.disable_input_time = nil
  301.     end
  302.     -- Обновление сна с переносом чувака в указанную позицию
  303.     if self.st.sleep_relocate_time ~= nil and
  304.        game.get_game_time():diffSec(self.st.sleep_relocate_time) >= self.st.sleep_relocate_idle
  305.     then
  306.         self.object:set_actor_position(self.st.sleep_relocate_point)
  307.         local dir = self.st.sleep_relocate_point:sub(self.st.sleep_relocate_look)
  308.         self.object:set_actor_direction(dir:getH())
  309.         self.st.sleep_relocate_time = nil
  310.     end
  311.  
  312.     -- Апдейт прятание оружия игрока во время диалога
  313.     if weapon_hide == true or self.object:is_talking() then
  314.         if self.weapon_hide == false then
  315.             self.object:hide_weapon()
  316.             self.weapon_hide = true
  317.         end
  318.     else
  319.         if self.weapon_hide == true then
  320.             self.object:restore_weapon()
  321.             self.weapon_hide = false
  322.         end
  323.     end
  324.  
  325.     -- обновление рестрикторов, которые под логикой, срабатывает через интервалы времени
  326.     if self.next_restrictors_update_time < time then
  327.         bind_restrictor.actor_update(delta)
  328.  
  329.         self.next_restrictors_update_time = time + 200
  330.  
  331.         task_manager.actor_update()
  332.     end
  333.  
  334.     -- обновление постпроцессов
  335.     if post_process ~= 0 then
  336.         if post_process:update () == true then
  337.            post_process = 0
  338.         end
  339.     end
  340.  
  341.     -- обновление пси-антенны
  342.     if sr_psy_antenna.psy_antenna then
  343.         sr_psy_antenna.psy_antenna:update(delta)
  344.     end
  345.  
  346.     --' Вывод сообщения о большой радиации
  347.     if self.object.radiation >= 0.7 then
  348.         local hud = get_hud()
  349.         local custom_static = hud:GetCustomStatic("cs_radiation_danger")
  350.         if custom_static == nil then
  351.             hud:AddCustomStatic("cs_radiation_danger", true)
  352.             hud:GetCustomStatic("cs_radiation_danger"):wnd():SetTextST("st_radiation_danger")
  353.         end
  354.     else
  355.         local hud = get_hud()
  356.         local custom_static = hud:GetCustomStatic("cs_radiation_danger")
  357.         if custom_static ~= nil then
  358.             hud:RemoveCustomStatic("cs_radiation_danger")
  359.         end
  360.     end
  361.  
  362.  
  363.  
  364.     if self.bCheckStart then
  365.         printf("SET DEFAULT INFOS")    
  366.  
  367.         if not has_alife_info("storyline_actor_start") and
  368.            (level.name() == "l01_escape")
  369.         then
  370.             self.object:give_info_portion("storyline_actor_start")
  371.             _G.g_start_avi = true
  372.             printf("*AVI* RUN START AVI")          
  373.         end
  374.  
  375. --      if not has_alife_info("encyclopedy") then
  376. --          self.object:give_info_portion("encyclopedy")
  377. --      end
  378.  
  379.         if not has_alife_info("global_dialogs") then
  380.             self.object:give_info_portion("global_dialogs")
  381.         end
  382.  
  383.         if not has_alife_info("level_changer_icons") then
  384.             self.object:give_info_portion("level_changer_icons")
  385.         end
  386.  
  387.         level_tasks.add_lchanger_location()
  388.  
  389.         self.bCheckStart = false       
  390.     end    
  391.  
  392. end
  393.  
  394. ----------------------------------------------------------------------------------------------------------------------
  395. function actor_binder:save(packet)
  396.    
  397.     local save_treasure_manager = true
  398.    
  399.     printf("actor_binder:save(): self.object:name()='%s'", self.object:name())
  400.     object_binder.save(self, packet)
  401.  
  402.     --' Сохраняем уровень сложности
  403.     if save_treasure_manager == true then
  404.         packet:w_u8(level.get_game_difficulty() + 128)
  405.     else
  406.         packet:w_u8(level.get_game_difficulty())
  407.     end
  408.  
  409.  
  410.     --' Сохраняем данные об отключенном вводе
  411.     if self.st.disable_input_time == nil then
  412.         packet:w_bool(false)
  413.     else
  414.         packer:w_bool(true)
  415.         utils.w_CTime(packet, self.st.disable_input_time)
  416.     end
  417.  
  418.     xr_logic.pstor_save_all(self.object, packet)
  419.     self.weather_manager:save(packet)
  420.  
  421.     sr_psy_antenna.save( packet )
  422.    
  423.     if save_treasure_manager == true then
  424.         treasure_manager.save(packet)      
  425.     end                                  
  426.  
  427.     task_manager.save(packet)
  428.     self.actor_detector:save(packet)   
  429. end
  430. ----------------------------------------------------------------------------------------------------------------------
  431. function actor_binder:load(reader)
  432.     printf("actor_binder:load(): self.object:name()='%s'", self.object:name())
  433.     object_binder.load(self, reader)
  434.     printf("actor_binder:object_binder.load(): self.object:name()='%s'", self.object:name())
  435.  
  436.     --' Загружаем уровень сложности
  437.     local game_difficulty = reader:r_u8()
  438.    
  439.     local load_treasure_manager = false      
  440.     if game_difficulty >= 128 then          
  441.         game_difficulty = game_difficulty - 128
  442.         load_treasure_manager = true          
  443.     end                                      
  444.  
  445.    
  446.     get_console():execute("g_game_difficulty "..game_difficulty_by_num[game_difficulty])
  447.  
  448.     if reader:r_eof() then
  449.         abort("SAVE FILE IS CORRUPT")
  450.     end
  451.  
  452.     local stored_input_time = reader:r_u8()
  453.     if stored_input_time == true then
  454.         self.st.disable_input_time = utils.r_CTime(reader)
  455.     end
  456.  
  457.     xr_logic.pstor_load_all(self.object, reader)
  458.     self.weather_manager:load(reader)
  459.  
  460.     sr_psy_antenna.load(reader)
  461.    
  462.     if load_treasure_manager == true then
  463.         treasure_manager.load(reader)      
  464.     end                                  
  465.  
  466.    
  467.     task_manager.load(reader)
  468.     self.actor_detector:load(reader)   
  469. end
  470. ----------------------------------------------------------------------------------------------------------------------
  471.  
  472. --старт префетча звуков
  473. --if string.find(command_line(), "-noprefetch") == nil then
  474. --  sound_prefetch.prefetch_sounds()
  475. --end
  476.  
  477.  
  478. -- Weapon functions
  479. function hide_weapon()
  480.     weapon_hide = true
  481. end
  482. function restore_weapon()
  483.     weapon_hide = false
  484. end
  485.  
  486. // this is test for section iteration
  487. /**
  488. local function test_section_iteration(file_name, section_name)
  489.     printf          ("file    : %s",file_name)
  490.     printf          ("section : %s",section_name)
  491.    
  492.     local           file = ini_file(file_name)
  493.     local           n = file:line_count(section_name)
  494.     printf          ("lines   : %d",n)
  495.    
  496.     local           id, value = "", "", result
  497.     for i=0,n-1 do
  498.         result, id, value   = file:r_line(section_name,i,"","")
  499.         printf      ("line %d : %s = %s",i,id,value)
  500.     end
  501. end
  502.  
  503. test_section_iteration("system.ltx","space_restrictor")
  504. /**/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement