Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. void CItem::PutAttributeWithLevel(BYTE bLevel)
  2. {
  3.     int iAttributeSet = GetAttributeSetIndex();
  4.     if (iAttributeSet < 0)
  5.         return;
  6.  
  7.     if (bLevel > ITEM_ATTRIBUTE_MAX_LEVEL)
  8.         return;
  9.  
  10.     std::vector<int> avail;
  11.  
  12.     int total = 0;
  13.  
  14.    
  15.     for (int i = 0; i < MAX_APPLY_NUM; ++i)
  16.     {
  17.         const TItemAttrTable & r = g_map_itemAttr[i];
  18.  
  19.         if (r.bMaxLevelBySet[iAttributeSet] && !HasAttr(i))
  20.         {
  21.             avail.push_back(i);
  22.             total += r.dwProb;
  23.         }
  24.     }
  25.  
  26.    
  27.     unsigned int prob = number(1, total);
  28.     int attr_idx = APPLY_NONE;
  29.  
  30.     for (DWORD i = 0; i < avail.size(); ++i)
  31.     {
  32.         const TItemAttrTable & r = g_map_itemAttr[avail[i]];
  33.  
  34.         if (prob <= r.dwProb)
  35.         {
  36.             attr_idx = avail[i];
  37.             break;
  38.         }
  39.  
  40.         prob -= r.dwProb;
  41.     }
  42.  
  43.     if (!attr_idx)
  44.     {
  45.         sys_err("Cannot put item attribute %d %d", iAttributeSet, bLevel);
  46.         return;
  47.     }
  48.  
  49.     const TItemAttrTable & r = g_map_itemAttr[attr_idx];
  50.  
  51.    
  52.     if (bLevel > r.bMaxLevelBySet[iAttributeSet])
  53.         bLevel = r.bMaxLevelBySet[iAttributeSet];
  54.  
  55.     AddAttr(attr_idx, bLevel);
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement