Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void LootMgr::PushLoot(StoreLootList* list, Loot* loot, uint32 type)
- {
- uint32 i;
- uint32 count;
- if(type >= NUM_LOOT_TYPES)
- return;
- for(uint32 x = 0; x < list->count; x++)
- {
- if(list->items[x].item.itemproto) // this check is needed until loot DB is fixed
- {
- float chance = 0.0f;
- switch(type)
- {
- case LOOT_NORMAL10:
- chance = list->items[x].chance;
- break;
- case LOOT_NORMAL25:
- chance = list->items[x].chance2;
- break;
- case LOOT_HEROIC10:
- chance = list->items[x].chance3;
- break;
- case LOOT_HEROIC25:
- chance = list->items[x].chance4;
- break;
- }
- bool skip = false;
- for (int _xx = 0; _xx < loot->items.size(); ++_xx)
- {
- if (loot->items[_xx].item.itemproto->ItemId == list->items[x].item.itemproto->ItemId)
- {
- skip = true;
- break;
- }
- }
- if (skip)
- continue;
- // drop chance cannot be larger than 100% or smaller than 0%
- if(chance <= 0.0f || chance > 100.0f)
- continue;
- ItemPrototype* itemproto = list->items[x].item.itemproto;
- if(Rand(chance * sWorld.getRate(RATE_DROP0 + itemproto->Quality))) //|| itemproto->Class == ITEM_CLASS_QUEST)
- {
- if(list->items[x].mincount == list->items[x].maxcount)
- count = list->items[x].maxcount;
- else
- count = RandomUInt(list->items[x].maxcount - list->items[x].mincount) + list->items[x].mincount;
- for(i = 0; i < loot->items.size(); ++i)
- {
- //itemid rand match a already placed item, if item is stackable and unique(stack), increment it, otherwise skips
- if((loot->items[i].item.itemproto == list->items[x].item.itemproto) && itemproto->MaxCount && ((loot->items[i].iItemsCount + count) < itemproto->MaxCount))
- {
- if(itemproto->Unique && ((loot->items[i].iItemsCount + count) < itemproto->Unique))
- {
- loot->items[i].iItemsCount += count;
- break;
- }
- else if(!itemproto->Unique)
- {
- loot->items[i].iItemsCount += count;
- break;
- }
- }
- }
- if(i != loot->items.size())
- continue;
- __LootItem itm;
- itm.item = list->items[x].item;
- itm.iItemsCount = count;
- itm.roll = NULL;
- itm.passed = false;
- itm.ffa_loot = list->items[x].ffa_loot;
- itm.has_looted.clear();
- if(itemproto->Quality > 1 && itemproto->ContainerSlots == 0)
- {
- itm.iRandomProperty = GetRandomProperties(itemproto);
- itm.iRandomSuffix = GetRandomSuffix(itemproto);
- }
- else
- {
- // save some calls :P
- itm.iRandomProperty = NULL;
- itm.iRandomSuffix = NULL;
- }
- loot->items.push_back(itm);
- }
- if ((list->count - 1) > 2 &&
- loot->items.size() < 3 &&
- x != (list->count - 1) &&
- list->items[0].chance2 != 0)
- x = 0;
- }
- }
- if(loot->items.size() > 16)
- {
- std::vector<__LootItem>::iterator item_to_remove;
- std::vector<__LootItem>::iterator itr;
- uint32 item_quality;
- bool quest_item;
- while(loot->items.size() > 16)
- {
- item_to_remove = loot->items.begin();
- item_quality = 0;
- quest_item = false;
- for(itr = loot->items.begin(); itr != loot->items.end(); ++itr)
- {
- item_quality = (*itr).item.itemproto->Quality;
- quest_item = (*itr).item.itemproto->Class == ITEM_CLASS_QUEST;
- if((*item_to_remove).item.itemproto->Quality > item_quality && !quest_item)
- {
- item_to_remove = itr;
- }
- }
- loot->items.erase(item_to_remove);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment