AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
LootTemplate Class Reference

#include "LootMgr.h"

Classes

class  LootGroup
 

Public Member Functions

 LootTemplate ()=default
 
 ~LootTemplate ()
 
void AddEntry (LootStoreItem *item)
 
void Process (Loot &loot, LootStore const &store, uint16 lootMode, Player const *player, uint8 groupId=0, bool isTopLevel=true) const
 
void CopyConditions (ConditionList conditions)
 
bool CopyConditions (LootItem *li, uint32 conditionLootId=0) const
 
bool HasQuestDrop (LootTemplateMap const &store) const
 
bool HasQuestDropForPlayer (LootTemplateMap const &store, Player const *player) const
 
void Verify (LootStore const &store, uint32 Id) const
 
void CheckLootRefs (LootStore const &lootstore, uint32 Id, LootIdSet *ref_set) const
 
bool addConditionItem (Condition *cond)
 
bool isReference (uint32 id) const
 

Private Types

typedef std::vector< LootGroup * > LootGroups
 

Private Member Functions

 LootTemplate (LootTemplate const &)
 
LootTemplateoperator= (LootTemplate const &)
 

Private Attributes

LootStoreItemList Entries
 
LootGroups Groups
 

Detailed Description

Member Typedef Documentation

◆ LootGroups

typedef std::vector<LootGroup*> LootTemplate::LootGroups
private

Constructor & Destructor Documentation

◆ LootTemplate() [1/2]

LootTemplate::LootTemplate ( )
default

◆ ~LootTemplate()

LootTemplate::~LootTemplate ( )
1519{
1520 while (!Entries.empty())
1521 {
1522 delete Entries.back();
1523 Entries.pop_back();
1524 }
1525
1526 for (std::size_t i = 0; i < Groups.size(); ++i)
1527 delete Groups[i];
1528 Groups.clear();
1529}
Groups
Definition boss_moroes.cpp:55
Entries
Definition zone_howling_fjord.cpp:72

◆ LootTemplate() [2/2]

LootTemplate::LootTemplate ( LootTemplate const &  )
private

Member Function Documentation

◆ addConditionItem()

bool LootTemplate::addConditionItem ( Condition cond)
1840{
1841 if (!cond || !cond->isLoaded())//should never happen, checked at loading
1842 {
1843 LOG_ERROR("condition", "LootTemplate::addConditionItem: condition is null");
1844 return false;
1845 }
1846
1847 if (!Entries.empty())
1848 {
1849 for (LootStoreItemList::iterator i = Entries.begin(); i != Entries.end(); ++i)
1850 {
1851 if ((*i)->itemid == uint32(cond->SourceEntry))
1852 {
1853 (*i)->conditions.push_back(cond);
1854 return true;
1855 }
1856 }
1857 }
1858
1859 if (!Groups.empty())
1860 {
1861 for (LootGroups::iterator groupItr = Groups.begin(); groupItr != Groups.end(); ++groupItr)
1862 {
1863 LootGroup* group = *groupItr;
1864 if (!group)
1865 continue;
1866
1867 LootStoreItemList* itemList = group->GetExplicitlyChancedItemList();
1868 if (!itemList->empty())
1869 {
1870 for (LootStoreItemList::iterator i = itemList->begin(); i != itemList->end(); ++i)
1871 {
1872 if ((*i)->itemid == uint32(cond->SourceEntry))
1873 {
1874 (*i)->conditions.push_back(cond);
1875 return true;
1876 }
1877 }
1878 }
1879
1880 itemList = group->GetEqualChancedItemList();
1881 if (!itemList->empty())
1882 {
1883 for (LootStoreItemList::iterator i = itemList->begin(); i != itemList->end(); ++i)
1884 {
1885 if ((*i)->itemid == uint32(cond->SourceEntry))
1886 {
1887 (*i)->conditions.push_back(cond);
1888 return true;
1889 }
1890 }
1891 }
1892 }
1893 }
1894 return false;
1895}
std::uint32_t uint32
Definition Define.h:107
#define LOG_ERROR(filterType__,...)
Definition Log.h:145
std::list< LootStoreItem * > LootStoreItemList
Definition LootMgr.h:201
bool isLoaded() const
Definition ConditionMgr.h:236
int32 SourceEntry
Definition ConditionMgr.h:201

References LootTemplate::LootGroup::GetEqualChancedItemList(), LootTemplate::LootGroup::GetExplicitlyChancedItemList(), Condition::isLoaded(), LOG_ERROR, and Condition::SourceEntry.

Referenced by ConditionMgr::addToLootTemplate().

◆ AddEntry()

void LootTemplate::AddEntry ( LootStoreItem item)
1533{
1534 if (item->groupid > 0) // Group and grouped reference
1535 {
1536 if (item->groupid >= Groups.size())
1537 {
1538 Groups.resize(item->groupid, nullptr); // Adds new group the the loot template if needed
1539 }
1540
1541 if (!Groups[item->groupid - 1])
1542 {
1543 Groups[item->groupid - 1] = new LootGroup();
1544 }
1545
1546 Groups[item->groupid - 1]->AddEntry(item); // Adds new entry to the group
1547 }
1548 else // Non-grouped entries
1549 Entries.push_back(item);
1550}
uint8 groupid
Definition LootMgr.h:134

References LootStoreItem::groupid.

◆ CheckLootRefs()

void LootTemplate::CheckLootRefs ( LootStore const &  lootstore,
uint32  Id,
LootIdSet ref_set 
) const
1818{
1819 for (LootStoreItemList::const_iterator ieItr = Entries.begin(); ieItr != Entries.end(); ++ieItr)
1820 {
1821 LootStoreItem* item = *ieItr;
1822 if (item->reference)
1823 {
1824 if (item->mincount != item->maxcount)
1825 LootTemplates_Reference.ReportInvalidCount(std::abs(item->reference), lootstore.GetName(), Id, item->itemid, item->mincount, item->maxcount);
1826
1827 if (!LootTemplates_Reference.GetLootFor(std::abs(item->reference)))
1828 LootTemplates_Reference.ReportNonExistingId(std::abs(item->reference), lootstore.GetName(), item->itemid);
1829 else if (ref_set)
1830 ref_set->erase(std::abs(item->reference));
1831 }
1832 }
1833
1834 for (LootGroups::const_iterator grItr = Groups.begin(); grItr != Groups.end(); ++grItr)
1835 if (LootGroup* group = *grItr)
1836 group->CheckLootRefs(lootstore, Id, ref_set);
1837}
LootStore LootTemplates_Reference
LootTemplate const * GetLootFor(uint32 loot_id) const
Definition LootMgr.cpp:247
void ReportInvalidCount(uint32 lootId, const char *ownerType, uint32 ownerId, uint32 itemId, uint8 minCount, uint8 maxCount) const
Definition LootMgr.cpp:300
void ReportNonExistingId(uint32 lootId) const
Definition LootMgr.cpp:290
Definition LootMgr.h:128
int32 reference
Definition LootMgr.h:130
uint32 itemid
Definition LootMgr.h:129
uint8 maxcount
Definition LootMgr.h:136
uint8 mincount
Definition LootMgr.h:135

References LootStore::GetLootFor(), LootStore::GetName(), LootStoreItem::itemid, LootTemplates_Reference, LootStoreItem::maxcount, LootStoreItem::mincount, LootStoreItem::reference, LootStore::ReportInvalidCount(), and LootStore::ReportNonExistingId().

◆ CopyConditions() [1/2]

void LootTemplate::CopyConditions ( ConditionList  conditions)
1553{
1554 for (LootStoreItemList::iterator i = Entries.begin(); i != Entries.end(); ++i)
1555 (*i)->conditions.clear();
1556
1557 for (LootGroups::iterator i = Groups.begin(); i != Groups.end(); ++i)
1558 if (LootGroup* group = *i)
1559 group->CopyConditions(conditions);
1560}

◆ CopyConditions() [2/2]

bool LootTemplate::CopyConditions ( LootItem li,
uint32  conditionLootId = 0 
) const
1563{
1564 for (LootStoreItemList::const_iterator _iter = Entries.begin(); _iter != Entries.end(); ++_iter)
1565 {
1566 LootStoreItem* item = *_iter;
1567 if (item->reference)
1568 {
1569 if (LootTemplate const* Referenced = LootTemplates_Reference.GetLootFor(std::abs(item->reference)))
1570 {
1571 if (Referenced->CopyConditions(li, conditionLootId))
1572 {
1573 return true;
1574 }
1575 }
1576 }
1577 else
1578 {
1579 if (item->itemid != li->itemid)
1580 {
1581 continue;
1582 }
1583
1584 if (!item->conditions.empty() && conditionLootId && conditionLootId != item->conditions.front()->SourceGroup)
1585 {
1586 continue;
1587 }
1588
1589 li->conditions = item->conditions;
1590 return true;
1591 }
1592 }
1593
1594 for (LootGroups::const_iterator groupItr = Groups.begin(); groupItr != Groups.end(); ++groupItr)
1595 {
1596 LootGroup* group = *groupItr;
1597 if (!group)
1598 continue;
1599
1600 LootStoreItemList* itemList = group->GetExplicitlyChancedItemList();
1601 for (LootStoreItemList::iterator i = itemList->begin(); i != itemList->end(); ++i)
1602 {
1603 LootStoreItem* item = *i;
1604 if (item->reference)
1605 {
1606 if (LootTemplate const* Referenced = LootTemplates_Reference.GetLootFor(std::abs(item->reference)))
1607 {
1608 if (Referenced->CopyConditions(li, conditionLootId))
1609 {
1610 return true;
1611 }
1612 }
1613 }
1614 else
1615 {
1616 if (item->itemid != li->itemid)
1617 {
1618 continue;
1619 }
1620
1621 if (!item->conditions.empty() && conditionLootId && conditionLootId != item->conditions.front()->SourceGroup)
1622 {
1623 continue;
1624 }
1625
1626 li->conditions = item->conditions;
1627 return true;
1628 }
1629 }
1630
1631 itemList = group->GetEqualChancedItemList();
1632 for (LootStoreItemList::iterator i = itemList->begin(); i != itemList->end(); ++i)
1633 {
1634 LootStoreItem* item = *i;
1635 if (item->reference)
1636 {
1637 if (LootTemplate const* Referenced = LootTemplates_Reference.GetLootFor(std::abs(item->reference)))
1638 {
1639 if (Referenced->CopyConditions(li, conditionLootId))
1640 {
1641 return true;
1642 }
1643 }
1644 }
1645 else
1646 {
1647 if (item->itemid != li->itemid)
1648 {
1649 continue;
1650 }
1651
1652 if (!item->conditions.empty() && conditionLootId && conditionLootId != item->conditions.front()->SourceGroup)
1653 {
1654 continue;
1655 }
1656
1657 li->conditions = item->conditions;
1658 return true;
1659 }
1660 }
1661 }
1662
1663 return false;
1664}
Definition LootMgr.h:245
uint32 itemid
Definition LootMgr.h:155
ConditionList conditions
Definition LootMgr.h:159
ConditionList conditions
Definition LootMgr.h:137

References LootStoreItem::conditions, LootItem::conditions, LootTemplate::LootGroup::GetEqualChancedItemList(), LootTemplate::LootGroup::GetExplicitlyChancedItemList(), LootStore::GetLootFor(), LootStoreItem::itemid, LootItem::itemid, LootTemplates_Reference, and LootStoreItem::reference.

◆ HasQuestDrop()

bool LootTemplate::HasQuestDrop ( LootTemplateMap const &  store) const
1740{
1741 for (LootStoreItemList::const_iterator i = Entries.begin(); i != Entries.end(); ++i)
1742 {
1743 LootStoreItem* item = *i;
1744 if (item->reference) // References
1745 {
1746 LootTemplateMap::const_iterator Referenced = store.find(std::abs(item->reference));
1747 if (Referenced == store.end())
1748 continue; // Error message [should be] already printed at loading stage
1749
1750 if (Referenced->second->HasQuestDrop(store))
1751 return true;
1752 }
1753 else if (item->needs_quest)
1754 return true; // quest drop found
1755 }
1756
1757 // Now processing groups
1758 for (LootGroups::const_iterator i = Groups.begin(); i != Groups.end(); ++i)
1759 {
1760 if (LootGroup* group = *i)
1761 {
1762 if (group->HasQuestDrop(store))
1763 {
1764 return true;
1765 }
1766 }
1767 }
1768
1769 return false;
1770}
bool needs_quest
Definition LootMgr.h:132

References LootStoreItem::needs_quest, and LootStoreItem::reference.

◆ HasQuestDropForPlayer()

bool LootTemplate::HasQuestDropForPlayer ( LootTemplateMap const &  store,
Player const *  player 
) const
1774{
1775 // Checking non-grouped entries
1776 for (LootStoreItemList::const_iterator i = Entries.begin(); i != Entries.end(); ++i)
1777 {
1778 LootStoreItem* item = *i;
1779 if (item->reference) // References processing
1780 {
1781 LootTemplateMap::const_iterator Referenced = store.find(std::abs(item->reference));
1782 if (Referenced == store.end())
1783 continue; // Error message already printed at loading stage
1784 if (Referenced->second->HasQuestDropForPlayer(store, player))
1785 return true;
1786 }
1787 else if (player->HasQuestForItem(item->itemid))
1788 return true; // active quest drop found
1789 }
1790
1791 // Now checking groups
1792 for (LootGroups::const_iterator i = Groups.begin(); i != Groups.end(); ++i)
1793 {
1794 if (LootGroup* group = *i)
1795 {
1796 if (group->HasQuestDropForPlayer(player, store))
1797 {
1798 return true;
1799 }
1800 }
1801 }
1802
1803 return false;
1804}

References Player::HasQuestForItem(), LootStoreItem::itemid, and LootStoreItem::reference.

◆ isReference()

bool LootTemplate::isReference ( uint32  id) const
1898{
1899 for (LootStoreItemList::const_iterator ieItr = Entries.begin(); ieItr != Entries.end(); ++ieItr)
1900 {
1901 if ((*ieItr)->itemid == id && (*ieItr)->reference)
1902 {
1903 return true;
1904 }
1905 }
1906
1907 return false;//not found or not reference
1908}

Referenced by ConditionMgr::isSourceTypeValid().

◆ operator=()

LootTemplate & LootTemplate::operator= ( LootTemplate const &  )
private

◆ Process()

void LootTemplate::Process ( Loot loot,
LootStore const &  store,
uint16  lootMode,
Player const *  player,
uint8  groupId = 0,
bool  isTopLevel = true 
) const
1668{
1669 bool rate = store.IsRatesAllowed();
1670
1671 if (groupId) // Group reference uses own processing of the group
1672 {
1673 if (groupId > Groups.size())
1674 return; // Error message already printed at loading stage
1675
1676 if (!Groups[groupId - 1])
1677 return;
1678
1679 // Rate.Drop.Item.GroupAmount is only in effect for the top loot template level
1680 if (isTopLevel)
1681 {
1682 Groups[groupId - 1]->Process(loot, player, store, lootMode, sWorld->getRate(RATE_DROP_ITEM_GROUP_AMOUNT));
1683 }
1684 else
1685 {
1686 Groups[groupId - 1]->Process(loot, player, store, lootMode, 0);
1687 }
1688 return;
1689 }
1690
1691 // Rolling non-grouped items
1692 for (LootStoreItemList::const_iterator i = Entries.begin(); i != Entries.end(); ++i)
1693 {
1694 LootStoreItem* item = *i;
1695 if (!(item->lootmode & lootMode)) // Do not add if mode mismatch
1696 continue;
1697 if (!item->Roll(rate, player, loot, store))
1698 continue; // Bad luck for the entry
1699
1700 if (item->reference) // References processing
1701 {
1702 LootTemplate const* Referenced = LootTemplates_Reference.GetLootFor(std::abs(item->reference));
1703 if (!Referenced)
1704 continue; // Error message already printed at loading stage
1705
1706 uint32 maxcount = uint32(float(item->maxcount) * sWorld->getRate(RATE_DROP_ITEM_REFERENCED_AMOUNT));
1707 sScriptMgr->OnAfterRefCount(player, loot, rate, lootMode, item, maxcount, store);
1708 for (uint32 loop = 0; loop < maxcount; ++loop) // Ref multiplicator
1709 // we're no longer in the top level, so isTopLevel is false
1710 Referenced->Process(loot, store, lootMode, player, item->groupid, false);
1711 }
1712 else
1713 {
1714 // Plain entries (not a reference, not grouped)
1715 sScriptMgr->OnBeforeDropAddItem(player, loot, rate, lootMode, item, store);
1716 loot.AddItem(*item); // Chance is already checked, just add
1717 }
1718 }
1719
1720 // Now processing groups
1721 for (LootGroups::const_iterator i = Groups.begin(); i != Groups.end(); ++i)
1722 if (LootGroup* group = *i)
1723 {
1724 // Rate.Drop.Item.GroupAmount is only in effect for the top loot template level
1725 if (isTopLevel)
1726 {
1727 uint32 groupAmount = sWorld->getRate(RATE_DROP_ITEM_GROUP_AMOUNT);
1728 sScriptMgr->OnAfterCalculateLootGroupAmount(player, loot, lootMode, groupAmount, store);
1729 group->Process(loot, player, store, lootMode, groupAmount);
1730 }
1731 else
1732 {
1733 group->Process(loot, player, store, lootMode, 0);
1734 }
1735 }
1736}
#define sScriptMgr
Definition ScriptMgr.h:737
@ RATE_DROP_ITEM_REFERENCED_AMOUNT
Definition WorldConfig.h:408
@ RATE_DROP_ITEM_GROUP_AMOUNT
Definition WorldConfig.h:409
void Process(Loot &loot, LootStore const &store, uint16 lootMode, Player const *player, uint8 groupId=0, bool isTopLevel=true) const
Definition LootMgr.cpp:1667
#define sWorld
Definition World.h:317
bool Roll(bool rate, Player const *player, Loot &loot, LootStore const &store) const
Definition LootMgr.cpp:311
uint16 lootmode
Definition LootMgr.h:133
void AddItem(LootStoreItem const &item)
Definition LootMgr.cpp:481

References Loot::AddItem(), LootStore::GetLootFor(), LootStoreItem::groupid, LootStore::IsRatesAllowed(), LootStoreItem::lootmode, LootTemplates_Reference, LootStoreItem::maxcount, Process(), RATE_DROP_ITEM_GROUP_AMOUNT, RATE_DROP_ITEM_REFERENCED_AMOUNT, LootStoreItem::reference, LootStoreItem::Roll(), sScriptMgr, and sWorld.

Referenced by Loot::FillLoot(), debug_commandscript::GenerateLoot(), Process(), and LootTemplate::LootGroup::Process().

◆ Verify()

void LootTemplate::Verify ( LootStore const &  store,
uint32  Id 
) const
Todo:
: References validity checks
1808{
1809 // Checking group chances
1810 for (uint32 i = 0; i < Groups.size(); ++i)
1811 if (Groups[i])
1812 Groups[i]->Verify(lootstore, id, i + 1);
1813
1815}

Member Data Documentation

◆ Entries

LootStoreItemList LootTemplate::Entries
private

◆ Groups

LootGroups LootTemplate::Groups
private

The documentation for this class was generated from the following files: