feat(Core/SendListInventory): Add multivendor function (#3172)

This commit is contained in:
IntelligentQuantum
2020-08-20 13:30:11 +04:30
committed by GitHub
parent 07c9debb0d
commit 5d284f02a7
6 changed files with 21 additions and 10 deletions
+3 -3
View File
@@ -14859,7 +14859,7 @@ void Player::PrepareGossipMenu(WorldObject* source, uint32 menuId /*= 0*/, bool
break; break;
case GOSSIP_OPTION_VENDOR: case GOSSIP_OPTION_VENDOR:
{ {
VendorItemData const* vendorItems = creature->GetVendorItems(); VendorItemData const* vendorItems = itr->second.ActionMenuID ? sObjectMgr->GetNpcVendorItemList(itr->second.ActionMenuID) : creature->GetVendorItems();
if (!vendorItems || vendorItems->Empty()) if (!vendorItems || vendorItems->Empty())
{ {
sLog->outErrorDb("Creature %u (Entry: %u) have UNIT_NPC_FLAG_VENDOR but have empty trading item list.", creature->GetGUIDLow(), creature->GetEntry()); sLog->outErrorDb("Creature %u (Entry: %u) have UNIT_NPC_FLAG_VENDOR but have empty trading item list.", creature->GetGUIDLow(), creature->GetEntry());
@@ -15087,7 +15087,7 @@ void Player::OnGossipSelect(WorldObject* source, uint32 gossipListId, uint32 men
break; break;
case GOSSIP_OPTION_VENDOR: case GOSSIP_OPTION_VENDOR:
case GOSSIP_OPTION_ARMORER: case GOSSIP_OPTION_ARMORER:
GetSession()->SendListInventory(guid); GetSession()->SendListInventory(guid, menuItemData->GossipActionMenuId);
break; break;
case GOSSIP_OPTION_STABLEPET: case GOSSIP_OPTION_STABLEPET:
GetSession()->SendStablePet(guid); GetSession()->SendStablePet(guid);
@@ -22089,7 +22089,7 @@ bool Player::BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32
return false; return false;
} }
VendorItemData const* vItems = creature->GetVendorItems(); VendorItemData const* vItems = GetSession()->GetCurrentVendor() ? sObjectMgr->GetNpcVendorItemList(GetSession()->GetCurrentVendor()) : creature->GetVendorItems();
if (!vItems || vItems->Empty()) if (!vItems || vItems->Empty())
{ {
SendBuyError(BUY_ERR_CANT_FIND_ITEM, creature, item, 0); SendBuyError(BUY_ERR_CANT_FIND_ITEM, creature, item, 0);
+3 -1
View File
@@ -8512,8 +8512,9 @@ bool ObjectMgr::RemoveVendorItem(uint32 entry, uint32 item, bool persist /*= tru
return true; return true;
} }
bool ObjectMgr::IsVendorItemValid(uint32 vendor_entry, uint32 item_id, int32 maxcount, uint32 incrtime, uint32 ExtendedCost, Player* player, std::set<uint32>* skip_vendors, uint32 ORnpcflag) const bool ObjectMgr::IsVendorItemValid(uint32 vendor_entry, uint32 item_id, int32 maxcount, uint32 incrtime, uint32 ExtendedCost, Player* player, std::set<uint32>* /*skip_vendors*/, uint32 /*ORnpcflag*/) const
{ {
/*
CreatureTemplate const* cInfo = sObjectMgr->GetCreatureTemplate(vendor_entry); CreatureTemplate const* cInfo = sObjectMgr->GetCreatureTemplate(vendor_entry);
if (!cInfo) if (!cInfo)
{ {
@@ -8538,6 +8539,7 @@ bool ObjectMgr::IsVendorItemValid(uint32 vendor_entry, uint32 item_id, int32 max
} }
return false; return false;
} }
*/
if (!sObjectMgr->GetItemTemplate(item_id)) if (!sObjectMgr->GetItemTemplate(item_id))
{ {
+4 -2
View File
@@ -887,7 +887,7 @@ void WorldSession::HandleListInventoryOpcode(WorldPacket & recvData)
SendListInventory(guid); SendListInventory(guid);
} }
void WorldSession::SendListInventory(uint64 vendorGuid) void WorldSession::SendListInventory(uint64 vendorGuid, uint32 vendorEntry)
{ {
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS) #if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Sent SMSG_LIST_INVENTORY"); sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Sent SMSG_LIST_INVENTORY");
@@ -911,7 +911,9 @@ void WorldSession::SendListInventory(uint64 vendorGuid)
if (vendor->HasUnitState(UNIT_STATE_MOVING)) if (vendor->HasUnitState(UNIT_STATE_MOVING))
vendor->StopMoving(); vendor->StopMoving();
VendorItemData const* items = vendor->GetVendorItems(); SetCurrentVendor(vendorEntry);
VendorItemData const* items = vendorEntry ? sObjectMgr->GetNpcVendorItemList(vendorEntry) : vendor->GetVendorItems();
if (!items) if (!items)
{ {
WorldPacket data(SMSG_LIST_INVENTORY, 8 + 1 + 1); WorldPacket data(SMSG_LIST_INVENTORY, 8 + 1 + 1);
+1
View File
@@ -112,6 +112,7 @@ WorldSession::WorldSession(uint32 id, WorldSocket* sock, AccountTypes sec, uint8
m_TutorialsChanged(false), m_TutorialsChanged(false),
recruiterId(recruiter), recruiterId(recruiter),
isRecruiter(isARecruiter), isRecruiter(isARecruiter),
m_currentVendorEntry(0),
m_currentBankerGUID(0), m_currentBankerGUID(0),
timeWhoCommandAllowed(0), timeWhoCommandAllowed(0),
_calendarEventCreationCooldown(0) _calendarEventCreationCooldown(0)
+5 -1
View File
@@ -226,6 +226,9 @@ class WorldSession
std::string const& GetPlayerName() const; std::string const& GetPlayerName() const;
std::string GetPlayerInfo() const; std::string GetPlayerInfo() const;
uint32 GetCurrentVendor() const { return m_currentVendorEntry; }
void SetCurrentVendor(uint32 vendorEntry) { m_currentVendorEntry = vendorEntry; }
uint32 GetGuidLow() const; uint32 GetGuidLow() const;
void SetSecurity(AccountTypes security) { _security = security; } void SetSecurity(AccountTypes security) { _security = security; }
std::string const& GetRemoteAddress() { return m_Address; } std::string const& GetRemoteAddress() { return m_Address; }
@@ -270,7 +273,7 @@ class WorldSession
void SendTrainerList(uint64 guid); void SendTrainerList(uint64 guid);
void SendTrainerList(uint64 guid, std::string const& strTitle); void SendTrainerList(uint64 guid, std::string const& strTitle);
void SendListInventory(uint64 guid); void SendListInventory(uint64 guid, uint32 vendorEntry = 0);
void SendShowBank(uint64 guid); void SendShowBank(uint64 guid);
bool CanOpenMailBox(uint64 guid); bool CanOpenMailBox(uint64 guid);
void SendShowMailBox(uint64 guid); void SendShowMailBox(uint64 guid);
@@ -1031,6 +1034,7 @@ class WorldSession
uint32 recruiterId; uint32 recruiterId;
bool isRecruiter; bool isRecruiter;
ACE_Based::LockedQueue<WorldPacket*, ACE_Thread_Mutex> _recvQueue; ACE_Based::LockedQueue<WorldPacket*, ACE_Thread_Mutex> _recvQueue;
uint32 m_currentVendorEntry;
uint64 m_currentBankerGUID; uint64 m_currentBankerGUID;
time_t timeWhoCommandAllowed; time_t timeWhoCommandAllowed;
uint32 _offlineTime; uint32 _offlineTime;
+4 -2
View File
@@ -295,7 +295,8 @@ public:
return false; return false;
} }
uint32 vendor_entry = vendor->GetEntry(); char* addMulti = strtok(nullptr, " ");
uint32 vendor_entry = addMulti ? handler->GetSession()->GetCurrentVendor() : vendor->GetEntry();
if (!sObjectMgr->IsVendorItemValid(vendor_entry, itemId, maxcount, incrtime, extendedcost, handler->GetSession()->GetPlayer())) if (!sObjectMgr->IsVendorItemValid(vendor_entry, itemId, maxcount, incrtime, extendedcost, handler->GetSession()->GetPlayer()))
{ {
@@ -518,7 +519,8 @@ public:
} }
uint32 itemId = atol(pitem); uint32 itemId = atol(pitem);
if (!sObjectMgr->RemoveVendorItem(vendor->GetEntry(), itemId)) char* addMulti = strtok(NULL, " ");
if (!sObjectMgr->RemoveVendorItem(addMulti ? handler->GetSession()->GetCurrentVendor() : vendor->GetEntry(), itemId))
{ {
handler->PSendSysMessage(LANG_ITEM_NOT_IN_LIST, itemId); handler->PSendSysMessage(LANG_ITEM_NOT_IN_LIST, itemId);
handler->SetSentErrorMessage(true); handler->SetSentErrorMessage(true);