Advertisement
Guest User

treasure_manager excerpt

a guest
Mar 27th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.41 KB | None | 0 0
  1. function CTreasure:use(npc)
  2.     printf("TREASURE USE")
  3.  
  4.     local se_obj = alife():object(npc:id())
  5.     if se_obj.treasure_processed == true then
  6.         return
  7.     end
  8.     se_obj.treasure_processed = true
  9.    
  10.     npc_rank_name_for_tr = ranks.get_obj_rank_name(npc)
  11.    
  12.     --' Íóæíî ðàíäîìíî âûáðàòü îäèí èç òàéíèêîâ.
  13.     local avail = {}
  14.     local tr_sum = 0
  15.     for k,v in pairs(self.treasure_info) do
  16.  
  17.         if v.done == false then
  18.             local treasure_prob = xr_logic.pick_section_from_condlist(db.actor, npc, v.condlist)
  19.        
  20.             if treasure_prob == "" or treasure_prob == nil then
  21.                 treasure_prob = 0
  22.             end
  23.  
  24.             if tonumber(treasure_prob) >= 0 and
  25.             v.community[npc:character_community()] == true and
  26.             v.active == false
  27.             then
  28.                 if tonumber(treasure_prob) == 100 then
  29.                
  30.                     self:give_treasure(k)
  31.                 else
  32.                     table.insert(avail, {k = k, prob = treasure_prob})
  33.                     tr_sum = tr_sum + treasure_prob
  34.            
  35.                 end
  36.             end
  37.         end
  38.     end
  39.  
  40.     if tr_sum == 0 or
  41.         amk.real_rand(100) < opt.tr_v -- 65 (à äëÿ òåñòà è âñå 10)
  42.     then
  43.         return
  44.     end
  45.  
  46.     local tr_w = amk.real_rand(tr_sum)
  47.    
  48.     for k,v in pairs(avail) do
  49.        
  50.         tr_w = tr_w - v.prob
  51.         if tr_w <= 0 then
  52.        
  53.             self:give_treasure(v.k)
  54.             break
  55.         end
  56.     end
  57.  
  58.    
  59.     if (npc and db.actor) then
  60.         if has_alife_info("ui_car_body") then
  61.             npc_community_loot = npc:character_community()
  62.             npc_rank_loot = npc:rank()
  63.         end
  64.     end
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement