stoneharry

Untitled

Sep 20th, 2013
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.43 KB | None | 0 0
  1. void LootMgr::PushLoot(StoreLootList* list, Loot* loot, uint32 type)
  2. {
  3.     uint32 i;
  4.     uint32 count;
  5.  
  6.     if(type >= NUM_LOOT_TYPES)
  7.         return;
  8.  
  9.     for(uint32 x = 0; x < list->count; x++)
  10.     {
  11.         if(list->items[x].item.itemproto)  // this check is needed until loot DB is fixed
  12.         {
  13.             float chance = 0.0f;
  14.  
  15.             switch(type)
  16.             {
  17.                 case LOOT_NORMAL10:
  18.                     chance = list->items[x].chance;
  19.                     break;
  20.  
  21.                 case LOOT_NORMAL25:
  22.                     chance = list->items[x].chance2;
  23.                     break;
  24.  
  25.                 case LOOT_HEROIC10:
  26.                     chance = list->items[x].chance3;
  27.                     break;
  28.  
  29.                 case LOOT_HEROIC25:
  30.                     chance = list->items[x].chance4;
  31.                     break;
  32.             }
  33.  
  34.             bool skip = false;
  35.             for (int _xx = 0; _xx < loot->items.size(); ++_xx)
  36.             {
  37.                 if (loot->items[_xx].item.itemproto->ItemId == list->items[x].item.itemproto->ItemId)
  38.                 {
  39.                     skip = true;
  40.                     break;
  41.                 }
  42.             }
  43.             if (skip)
  44.                 continue;
  45.  
  46.             // drop chance cannot be larger than 100% or smaller than 0%
  47.             if(chance <= 0.0f || chance > 100.0f)
  48.                 continue;
  49.  
  50.             ItemPrototype* itemproto = list->items[x].item.itemproto;
  51.             if(Rand(chance * sWorld.getRate(RATE_DROP0 + itemproto->Quality)))      //|| itemproto->Class == ITEM_CLASS_QUEST)
  52.             {
  53.                 if(list->items[x].mincount == list->items[x].maxcount)
  54.                     count = list->items[x].maxcount;
  55.                 else
  56.                     count = RandomUInt(list->items[x].maxcount - list->items[x].mincount) + list->items[x].mincount;
  57.  
  58.                 for(i = 0; i < loot->items.size(); ++i)
  59.                 {
  60.                     //itemid rand match a already placed item, if item is stackable and unique(stack), increment it, otherwise skips
  61.                     if((loot->items[i].item.itemproto == list->items[x].item.itemproto) && itemproto->MaxCount && ((loot->items[i].iItemsCount + count) < itemproto->MaxCount))
  62.                     {
  63.                         if(itemproto->Unique && ((loot->items[i].iItemsCount + count) < itemproto->Unique))
  64.                         {
  65.                             loot->items[i].iItemsCount += count;
  66.                             break;
  67.                         }
  68.                         else if(!itemproto->Unique)
  69.                         {
  70.                             loot->items[i].iItemsCount += count;
  71.                             break;
  72.                         }
  73.                     }
  74.                 }
  75.  
  76.                 if(i != loot->items.size())
  77.                     continue;
  78.  
  79.                 __LootItem itm;
  80.                 itm.item = list->items[x].item;
  81.                 itm.iItemsCount = count;
  82.                 itm.roll = NULL;
  83.                 itm.passed = false;
  84.                 itm.ffa_loot = list->items[x].ffa_loot;
  85.                 itm.has_looted.clear();
  86.  
  87.                 if(itemproto->Quality > 1 && itemproto->ContainerSlots == 0)
  88.                 {
  89.                     itm.iRandomProperty = GetRandomProperties(itemproto);
  90.                     itm.iRandomSuffix = GetRandomSuffix(itemproto);
  91.                 }
  92.                 else
  93.                 {
  94.                     // save some calls :P
  95.                     itm.iRandomProperty = NULL;
  96.                     itm.iRandomSuffix = NULL;
  97.                 }
  98.  
  99.                 loot->items.push_back(itm);
  100.             }
  101.             if ((list->count - 1) > 2 &&
  102.                 loot->items.size() < 3 &&
  103.                 x != (list->count - 1) &&
  104.                 list->items[0].chance2 != 0)
  105.                 x = 0;
  106.         }
  107.     }
  108.  
  109.     if(loot->items.size() > 16)
  110.     {
  111.         std::vector<__LootItem>::iterator item_to_remove;
  112.         std::vector<__LootItem>::iterator itr;
  113.         uint32 item_quality;
  114.         bool quest_item;
  115.         while(loot->items.size() > 16)
  116.         {
  117.             item_to_remove = loot->items.begin();
  118.             item_quality = 0;
  119.             quest_item = false;
  120.             for(itr = loot->items.begin(); itr != loot->items.end(); ++itr)
  121.             {
  122.                 item_quality = (*itr).item.itemproto->Quality;
  123.                 quest_item = (*itr).item.itemproto->Class == ITEM_CLASS_QUEST;
  124.                 if((*item_to_remove).item.itemproto->Quality > item_quality && !quest_item)
  125.                 {
  126.                     item_to_remove = itr;
  127.                 }
  128.             }
  129.             loot->items.erase(item_to_remove);
  130.         }
  131.     }
  132.  
  133. }
Advertisement
Add Comment
Please, Sign In to add comment