AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Guild::BankTab Class Reference

Public Member Functions

 BankTab (uint32 guildId, uint8 tabId)
 
void LoadFromDB (Field *fields)
 
bool LoadItemFromDB (Field *fields)
 
void Delete (CharacterDatabaseTransaction trans, bool removeItemsFromDB=false)
 
void SetInfo (std::string_view name, std::string_view icon)
 
void SetText (std::string_view text)
 
void SendText (const Guild *guild, WorldSession *session) const
 
std::string const & GetName () const
 
std::string const & GetIcon () const
 
std::string const & GetText () const
 
ItemGetItem (uint8 slotId) const
 
bool SetItem (CharacterDatabaseTransaction trans, uint8 slotId, Item *pItem)
 

Private Attributes

uint32 m_guildId
 
uint8 m_tabId
 
std::array< Item *, GUILD_BANK_MAX_SLOTSm_items = {}
 
std::string m_name
 
std::string m_icon
 
std::string m_text
 

Detailed Description

Constructor & Destructor Documentation

◆ BankTab()

Guild::BankTab::BankTab ( uint32  guildId,
uint8  tabId 
)
inline
559 : m_guildId(guildId), m_tabId(tabId)
560 {
561 }
uint8 m_tabId
Definition: Guild.h:580
uint32 m_guildId
Definition: Guild.h:579

Member Function Documentation

◆ Delete()

void Guild::BankTab::Delete ( CharacterDatabaseTransaction  trans,
bool  removeItemsFromDB = false 
)
427{
428 for (uint8 slotId = 0; slotId < GUILD_BANK_MAX_SLOTS; ++slotId)
429 if (Item* pItem = m_items[slotId])
430 {
431 pItem->RemoveFromWorld();
432 if (removeItemsFromDB)
433 pItem->DeleteFromDB(trans);
434 delete pItem;
435 pItem = nullptr;
436 }
437}
std::uint8_t uint8
Definition: Define.h:109
@ GUILD_BANK_MAX_SLOTS
Definition: Guild.h:43
Definition: Item.h:220
std::array< Item *, GUILD_BANK_MAX_SLOTS > m_items
Definition: Guild.h:582

References GUILD_BANK_MAX_SLOTS.

◆ GetIcon()

std::string const & Guild::BankTab::GetIcon ( ) const
inline
572{ return m_icon; }
std::string m_icon
Definition: Guild.h:584

References m_icon.

Referenced by Guild::HandleSetBankTabInfo().

◆ GetItem()

Item * Guild::BankTab::GetItem ( uint8  slotId) const
inline
575{ return slotId < GUILD_BANK_MAX_SLOTS ? m_items[slotId] : nullptr; }

References GUILD_BANK_MAX_SLOTS, and m_items.

Referenced by Guild::BankMoveItemData::_StoreItem().

◆ GetName()

std::string const & Guild::BankTab::GetName ( ) const
inline
571{ return m_name; }
std::string m_name
Definition: Guild.h:583

References m_name.

Referenced by Guild::HandleSetBankTabInfo().

◆ GetText()

std::string const & Guild::BankTab::GetText ( ) const
inline
573{ return m_text; }
std::string m_text
Definition: Guild.h:585

References m_text.

◆ LoadFromDB()

void Guild::BankTab::LoadFromDB ( Field fields)
381{
382 m_name = fields[2].Get<std::string>();
383 m_icon = fields[3].Get<std::string>();
384 m_text = fields[4].Get<std::string>();
385}
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:112

References Field::Get(), and Guild::m_name.

◆ LoadItemFromDB()

bool Guild::BankTab::LoadItemFromDB ( Field fields)
388{
389 uint8 slotId = fields[13].Get<uint8>();
390 ObjectGuid::LowType itemGuid = fields[14].Get<uint32>();
391 uint32 itemEntry = fields[15].Get<uint32>();
392 if (slotId >= GUILD_BANK_MAX_SLOTS)
393 {
394 LOG_ERROR("guild", "Invalid slot for item (GUID: {}, id: {}) in guild bank, skipped.", itemGuid, itemEntry);
395 return false;
396 }
397
398 ItemTemplate const* proto = sObjectMgr->GetItemTemplate(itemEntry);
399 if (!proto)
400 {
401 LOG_ERROR("guild", "Unknown item (GUID: {}, id: {}) in guild bank, skipped.", itemGuid, itemEntry);
402 return false;
403 }
404
405 Item* pItem = NewItemOrBag(proto);
406 if (!pItem->LoadFromDB(itemGuid, ObjectGuid::Empty, fields, itemEntry))
407 {
408 LOG_ERROR("guild", "Item (GUID {}, id: {}) not found in item_instance, deleting from guild bank!", itemGuid, itemEntry);
409
411 stmt->SetData(0, m_guildId);
412 stmt->SetData (1, m_tabId);
413 stmt->SetData (2, slotId);
414 CharacterDatabase.Execute(stmt);
415
416 delete pItem;
417 return false;
418 }
419
420 pItem->AddToWorld();
421 m_items[slotId] = pItem;
422 return true;
423}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
std::uint32_t uint32
Definition: Define.h:107
#define sObjectMgr
Definition: ObjectMgr.h:1635
Item * NewItemOrBag(ItemTemplate const *proto)
Definition: Bag.h:67
@ CHAR_DEL_NONEXISTENT_GUILD_BANK_ITEM
Definition: CharacterDatabase.h:33
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
Definition: PreparedStatement.h:157
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition: PreparedStatement.h:77
virtual bool LoadFromDB(ObjectGuid::LowType guid, ObjectGuid owner_guid, Field *fields, uint32 entry)
Definition: Item.cpp:419
Definition: ItemTemplate.h:619
virtual void AddToWorld()
Definition: Object.cpp:152
static ObjectGuid const Empty
Definition: ObjectGuid.h:120
uint32 LowType
Definition: ObjectGuid.h:122

References Object::AddToWorld(), CHAR_DEL_NONEXISTENT_GUILD_BANK_ITEM, CharacterDatabase, ObjectGuid::Empty, Field::Get(), GUILD_BANK_MAX_SLOTS, Item::LoadFromDB(), LOG_ERROR, NewItemOrBag(), PreparedStatementBase::SetData(), and sObjectMgr.

◆ SendText()

void Guild::BankTab::SendText ( const Guild guild,
WorldSession session 
) const
503{
505 textQuery.Tab = m_tabId;
506 textQuery.Text = m_text;
507
508 if (session)
509 {
510 LOG_DEBUG("guild", "MSG_QUERY_GUILD_BANK_TEXT [{}]: Tabid: {}, Text: {}"
511 , session->GetPlayerInfo(), m_tabId, m_text);
512 session->SendPacket(textQuery.Write());
513 }
514 else
515 {
516 LOG_DEBUG("guild", "MSG_QUERY_GUILD_BANK_TEXT [Broadcast]: Tabid: {}, Text: {}", m_tabId, m_text);
517 guild->BroadcastPacket(textQuery.Write());
518 }
519}
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:169
void BroadcastPacket(WorldPacket const *packet) const
Definition: Guild.cpp:2135
Definition: GuildPackets.h:567
uint8 Tab
Definition: GuildPackets.h:573
WorldPacket const * Write() override
Definition: GuildPackets.cpp:424
std::string Text
Definition: GuildPackets.h:574
void SendPacket(WorldPacket const *packet)
Send a packet to the client.
Definition: WorldSession.cpp:214
std::string GetPlayerInfo() const
Definition: WorldSession.cpp:191

References Guild::BroadcastPacket(), WorldSession::GetPlayerInfo(), LOG_DEBUG, WorldSession::SendPacket(), WorldPackets::Guild::GuildBankTextQueryResult::Tab, WorldPackets::Guild::GuildBankTextQueryResult::Text, and WorldPackets::Guild::GuildBankTextQueryResult::Write().

◆ SetInfo()

void Guild::BankTab::SetInfo ( std::string_view  name,
std::string_view  icon 
)
440{
441 if ((m_name == name) && (m_icon == icon))
442 return;
443
444 m_name = name;
445 m_icon = icon;
446
448 stmt->SetData(0, m_name);
449 stmt->SetData(1, m_icon);
450 stmt->SetData(2, m_guildId);
451 stmt->SetData (3, m_tabId);
452 CharacterDatabase.Execute(stmt);
453}
@ CHAR_UPD_GUILD_BANK_TAB_INFO
Definition: CharacterDatabase.h:174

References CHAR_UPD_GUILD_BANK_TAB_INFO, CharacterDatabase, Guild::m_name, and PreparedStatementBase::SetData().

Referenced by Guild::HandleSetBankTabInfo().

◆ SetItem()

bool Guild::BankTab::SetItem ( CharacterDatabaseTransaction  trans,
uint8  slotId,
Item pItem 
)
473{
474 if (slotId >= GUILD_BANK_MAX_SLOTS)
475 return false;
476
477 m_items[slotId] = item;
478
480 stmt->SetData(0, m_guildId);
481 stmt->SetData (1, m_tabId);
482 stmt->SetData (2, slotId);
483 CharacterDatabase.ExecuteOrAppend(trans, stmt);
484
485 if (item)
486 {
487 stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_GUILD_BANK_ITEM);
488 stmt->SetData(0, m_guildId);
489 stmt->SetData (1, m_tabId);
490 stmt->SetData (2, slotId);
491 stmt->SetData(3, item->GetGUID().GetCounter());
492 CharacterDatabase.ExecuteOrAppend(trans, stmt);
493
494 item->SetGuidValue(ITEM_FIELD_CONTAINED, ObjectGuid::Empty);
495 item->SetGuidValue(ITEM_FIELD_OWNER, ObjectGuid::Empty);
496 item->FSetState(ITEM_NEW);
497 item->SaveToDB(trans); // Not in inventory and can be saved standalone
498 }
499 return true;
500}
@ ITEM_NEW
Definition: Item.h:211
@ ITEM_FIELD_OWNER
Definition: UpdateFields.h:35
@ ITEM_FIELD_CONTAINED
Definition: UpdateFields.h:36
@ CHAR_DEL_GUILD_BANK_ITEM
Definition: CharacterDatabase.h:154
@ CHAR_INS_GUILD_BANK_ITEM
Definition: CharacterDatabase.h:153

References CHAR_DEL_GUILD_BANK_ITEM, CharacterDatabase, GUILD_BANK_MAX_SLOTS, and PreparedStatementBase::SetData().

Referenced by Guild::BankMoveItemData::_StoreItem().

◆ SetText()

void Guild::BankTab::SetText ( std::string_view  text)
456{
457 if (m_text == text)
458 return;
459
460 m_text = text;
461 utf8truncate(m_text, MAX_GUILD_BANK_TAB_TEXT_LEN); // DB and client size limitation
462
464 stmt->SetData(0, m_text);
465 stmt->SetData(1, m_guildId);
466 stmt->SetData (2, m_tabId);
467 CharacterDatabase.Execute(stmt);
468}
void utf8truncate(std::string &utf8str, std::size_t len)
Definition: Util.cpp:258
#define MAX_GUILD_BANK_TAB_TEXT_LEN
Definition: Guild.cpp:40
@ CHAR_UPD_GUILD_BANK_TAB_TEXT
Definition: CharacterDatabase.h:178

References CHAR_UPD_GUILD_BANK_TAB_TEXT, CharacterDatabase, MAX_GUILD_BANK_TAB_TEXT_LEN, PreparedStatementBase::SetData(), and utf8truncate().

Member Data Documentation

◆ m_guildId

uint32 Guild::BankTab::m_guildId
private

◆ m_icon

std::string Guild::BankTab::m_icon
private

Referenced by GetIcon().

◆ m_items

std::array<Item*, GUILD_BANK_MAX_SLOTS> Guild::BankTab::m_items = {}
private

Referenced by GetItem().

◆ m_name

std::string Guild::BankTab::m_name
private

Referenced by GetName().

◆ m_tabId

uint8 Guild::BankTab::m_tabId
private

◆ m_text

std::string Guild::BankTab::m_text
private

Referenced by GetText().