AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Guild::BankMoveItemData Class Reference
Inheritance diagram for Guild::BankMoveItemData:
Guild::MoveItemData

Public Member Functions

 BankMoveItemData (Guild *guild, Player *player, uint8 container, uint8 slotId)
 
bool IsBank () const override
 
bool InitItem () override
 
bool HasStoreRights (MoveItemData *pOther) const override
 
bool HasWithdrawRights (MoveItemData *pOther) const override
 
void RemoveItem (CharacterDatabaseTransaction trans, MoveItemData *pOther, uint32 splitedAmount) override
 
ItemStoreItem (CharacterDatabaseTransaction trans, Item *pItem) override
 
void LogBankEvent (CharacterDatabaseTransaction trans, MoveItemData *pFrom, uint32 count) const override
 
void LogAction (MoveItemData *pFrom) const override
 
- Public Member Functions inherited from Guild::MoveItemData
 MoveItemData (Guild *guild, Player *player, uint8 container, uint8 slotId)
 
virtual ~MoveItemData ()
 
virtual bool IsBank () const =0
 
virtual bool InitItem ()=0
 
virtual bool CheckItem (uint32 &splitedAmount)
 
virtual bool HasStoreRights (MoveItemData *) const
 
virtual bool HasWithdrawRights (MoveItemData *) const
 
bool CanStore (Item *pItem, bool swap, bool sendError)
 
bool CloneItem (uint32 count)
 
virtual void RemoveItem (CharacterDatabaseTransaction trans, MoveItemData *pOther, uint32 splitedAmount=0)=0
 
virtual ItemStoreItem (CharacterDatabaseTransaction trans, Item *pItem)=0
 
virtual void LogBankEvent (CharacterDatabaseTransaction trans, MoveItemData *pFrom, uint32 count) const =0
 
virtual void LogAction (MoveItemData *pFrom) const
 
void CopySlots (SlotIds &ids) const
 
ItemGetItem (bool isCloned=false) const
 
uint8 GetContainer () const
 
uint8 GetSlotId () const
 

Protected Member Functions

InventoryResult CanStore (Item *pItem, bool swap) override
 
virtual InventoryResult CanStore (Item *pItem, bool swap)=0
 

Private Member Functions

Item_StoreItem (CharacterDatabaseTransaction trans, BankTab *pTab, Item *pItem, ItemPosCount &pos, bool clone) const
 
bool _ReserveSpace (uint8 slotId, Item *pItem, Item *pItemDest, uint32 &count)
 
void CanStoreItemInTab (Item *pItem, uint8 skipSlotId, bool merge, uint32 &count)
 

Additional Inherited Members

- Protected Attributes inherited from Guild::MoveItemData
Guildm_pGuild
 
Playerm_pPlayer
 
uint8 m_container
 
uint8 m_slotId
 
Itemm_pItem
 
Itemm_pClonedItem
 
ItemPosCountVec m_vec
 

Detailed Description

Constructor & Destructor Documentation

◆ BankMoveItemData()

Guild::BankMoveItemData::BankMoveItemData ( Guild guild,
Player player,
uint8  container,
uint8  slotId 
)
inline
654 :
655 MoveItemData(guild, player, container, slotId) { }
MoveItemData(Guild *guild, Player *player, uint8 container, uint8 slotId)
Definition: Guild.h:592

Member Function Documentation

◆ _ReserveSpace()

bool Guild::BankMoveItemData::_ReserveSpace ( uint8  slotId,
Item pItem,
Item pItemDest,
uint32 count 
)
private
942{
943 uint32 requiredSpace = pItem->GetMaxStackCount();
944 if (pItemDest)
945 {
946 // Make sure source and destination items match and destination item has space for more stacks.
947 if (pItemDest->GetEntry() != pItem->GetEntry() || pItemDest->GetCount() >= pItem->GetMaxStackCount())
948 return false;
949 requiredSpace -= pItemDest->GetCount();
950 }
951 // Let's not be greedy, reserve only required space
952 requiredSpace = std::min(requiredSpace, count);
953
954 // Reserve space
955 ItemPosCount pos(slotId, requiredSpace);
956 if (!pos.isContainedIn(m_vec))
957 {
958 m_vec.push_back(pos);
959 count -= requiredSpace;
960 }
961 return true;
962}
std::uint32_t uint32
Definition: Define.h:107
uint32 GetCount() const
Definition: Item.h:272
uint32 GetMaxStackCount() const
Definition: Item.h:274
uint32 GetEntry() const
Definition: Object.h:115
Definition: Player.h:770
ItemPosCountVec m_vec
Definition: Guild.h:633

References Item::GetCount(), Object::GetEntry(), Item::GetMaxStackCount(), and ItemPosCount::isContainedIn().

◆ _StoreItem()

Item * Guild::BankMoveItemData::_StoreItem ( CharacterDatabaseTransaction  trans,
BankTab pTab,
Item pItem,
ItemPosCount pos,
bool  clone 
) const
private
909{
910 uint8 slotId = uint8(pos.pos);
911 uint32 count = pos.count;
912 if (Item* pItemDest = pTab->GetItem(slotId))
913 {
914 pItemDest->SetCount(pItemDest->GetCount() + count);
915 pItemDest->FSetState(ITEM_CHANGED);
916 pItemDest->SaveToDB(trans);
917 if (!clone)
918 {
919 pItem->RemoveFromWorld();
920 pItem->DeleteFromDB(trans);
921 delete pItem;
922 }
923 return pItemDest;
924 }
925
926 if (clone)
927 pItem = pItem->CloneItem(count);
928 else
929 pItem->SetCount(count);
930
931 if (pItem && pTab->SetItem(trans, slotId, pItem))
932 return pItem;
933
934 return nullptr;
935}
std::uint8_t uint8
Definition: Define.h:109
@ ITEM_CHANGED
Definition: Item.h:210
Definition: Item.h:220
Item * CloneItem(uint32 count, Player const *player=nullptr) const
Definition: Item.cpp:1118
void SetCount(uint32 value)
Definition: Item.h:273
static void DeleteFromDB(CharacterDatabaseTransaction trans, ObjectGuid::LowType itemGuid)
Definition: Item.cpp:518
virtual void RemoveFromWorld()
Definition: Object.cpp:166
uint32 count
Definition: Player.h:774
uint16 pos
Definition: Player.h:773

References Item::CloneItem(), ItemPosCount::count, Item::DeleteFromDB(), Guild::BankTab::GetItem(), ITEM_CHANGED, ItemPosCount::pos, Object::RemoveFromWorld(), Item::SetCount(), and Guild::BankTab::SetItem().

◆ CanStore()

InventoryResult Guild::BankMoveItemData::CanStore ( Item pItem,
bool  swap 
)
overrideprotectedvirtual

Implements Guild::MoveItemData.

985{
986 LOG_DEBUG("guild", "GUILD STORAGE: CanStore() tab = {}, slot = {}, item = {}, count = {}",
987 m_container, m_slotId, pItem->GetEntry(), pItem->GetCount());
988 uint32 count = pItem->GetCount();
989 // Soulbound items cannot be moved
990 if (pItem->IsSoulBound())
992
993 // Prevent swapping limited duration items into guild bank
994 if (pItem->GetTemplate()->Duration > 0)
996
997 // Make sure destination bank tab exists
1000
1001 // Slot explicitely specified. Check it.
1002 if (m_slotId != NULL_SLOT)
1003 {
1004 Item* pItemDest = m_pGuild->_GetItem(m_container, m_slotId);
1005 // Ignore swapped item (this slot will be empty after move)
1006 if ((pItemDest == pItem) || swap)
1007 pItemDest = nullptr;
1008
1009 if (!_ReserveSpace(m_slotId, pItem, pItemDest, count))
1011
1012 if (count == 0)
1013 return EQUIP_ERR_OK;
1014 }
1015
1016 // Slot was not specified or it has not enough space for all the items in stack
1017 // Search for stacks to merge with
1018 if (pItem->GetMaxStackCount() > 1)
1019 {
1020 CanStoreItemInTab(pItem, m_slotId, true, count);
1021 if (count == 0)
1022 return EQUIP_ERR_OK;
1023 }
1024
1025 // Search free slot for item
1026 CanStoreItemInTab(pItem, m_slotId, false, count);
1027 if (count == 0)
1028 return EQUIP_ERR_OK;
1029
1030 return EQUIP_ERR_BANK_FULL;
1031}
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:169
@ EQUIP_ERR_BANK_FULL
Definition: Item.h:98
@ EQUIP_ERR_CANT_DROP_SOULBOUND
Definition: Item.h:71
@ EQUIP_ERR_OK
Definition: Item.h:47
@ EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
Definition: Item.h:62
@ EQUIP_ERR_ITEM_CANT_STACK
Definition: Item.h:66
@ EQUIP_ERR_ITEMS_CANT_BE_SWAPPED
Definition: Item.h:68
@ NULL_SLOT
Definition: Item.h:41
ItemTemplate const * GetTemplate() const
Definition: Item.cpp:544
bool IsSoulBound() const
Definition: Item.h:236
uint32 Duration
Definition: ItemTemplate.h:686
uint8 _GetPurchasedTabsSize() const
Definition: Guild.h:816
Item * _GetItem(uint8 tabId, uint8 slotId) const
Definition: Guild.cpp:2638
uint8 m_slotId
Definition: Guild.h:630
Guild * m_pGuild
Definition: Guild.h:627
uint8 m_container
Definition: Guild.h:629
bool _ReserveSpace(uint8 slotId, Item *pItem, Item *pItemDest, uint32 &count)
Definition: Guild.cpp:941
void CanStoreItemInTab(Item *pItem, uint8 skipSlotId, bool merge, uint32 &count)
Definition: Guild.cpp:964

References ItemTemplate::Duration, EQUIP_ERR_BANK_FULL, EQUIP_ERR_CANT_DROP_SOULBOUND, EQUIP_ERR_ITEM_CANT_STACK, EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG, EQUIP_ERR_ITEMS_CANT_BE_SWAPPED, EQUIP_ERR_OK, Item::GetCount(), Object::GetEntry(), Item::GetMaxStackCount(), Item::GetTemplate(), Item::IsSoulBound(), LOG_DEBUG, and NULL_SLOT.

◆ CanStoreItemInTab()

void Guild::BankMoveItemData::CanStoreItemInTab ( Item pItem,
uint8  skipSlotId,
bool  merge,
uint32 count 
)
private
965{
966 for (uint8 slotId = 0; (slotId < GUILD_BANK_MAX_SLOTS) && (count > 0); ++slotId)
967 {
968 // Skip slot already processed in CanStore (when destination slot was specified)
969 if (slotId == skipSlotId)
970 continue;
971
972 Item* pItemDest = m_pGuild->_GetItem(m_container, slotId);
973 if (pItemDest == pItem)
974 pItemDest = nullptr;
975
976 // If merge skip empty, if not merge skip non-empty
977 if ((pItemDest != nullptr) != merge)
978 continue;
979
980 _ReserveSpace(slotId, pItem, pItemDest, count);
981 }
982}
@ GUILD_BANK_MAX_SLOTS
Definition: Guild.h:43

References GUILD_BANK_MAX_SLOTS.

◆ HasStoreRights()

bool Guild::BankMoveItemData::HasStoreRights ( MoveItemData pOther) const
overridevirtual

Reimplemented from Guild::MoveItemData.

827{
828 ASSERT(pOther);
829 // Do not check rights if item is being swapped within the same bank tab
830 if (pOther->IsBank() && pOther->GetContainer() == m_container)
831 return true;
833}
#define ASSERT
Definition: Errors.h:68
@ GUILD_BANK_RIGHT_DEPOSIT_ITEM
Definition: Guild.h:191
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:112
bool _MemberHasTabRights(ObjectGuid guid, uint8 tabId, uint32 rights) const
Definition: Guild.cpp:2594
Player * m_pPlayer
Definition: Guild.h:628

References ASSERT, Guild::MoveItemData::GetContainer(), GUILD_BANK_RIGHT_DEPOSIT_ITEM, and Guild::MoveItemData::IsBank().

◆ HasWithdrawRights()

bool Guild::BankMoveItemData::HasWithdrawRights ( MoveItemData pOther) const
overridevirtual

Reimplemented from Guild::MoveItemData.

836{
837 ASSERT(pOther);
838 // Do not check rights if item is being swapped within the same bank tab
839 if (pOther->IsBank() && pOther->GetContainer() == m_container)
840 return true;
841
842 int32 slots = 0;
843 if (Member const* member = m_pGuild->GetMember(m_pPlayer->GetGUID()))
845
846 return slots != 0;
847}
std::int32_t int32
Definition: Define.h:103
int32 _GetMemberRemainingSlots(Member const &member, uint8 tabId) const
Definition: Guild.cpp:2554
const Member * GetMember(ObjectGuid guid) const
Definition: Guild.h:381

References ASSERT, Guild::MoveItemData::GetContainer(), and Guild::MoveItemData::IsBank().

◆ InitItem()

bool Guild::BankMoveItemData::InitItem ( )
overridevirtual

Implements Guild::MoveItemData.

821{
823 return (m_pItem != nullptr);
824}
Item * m_pItem
Definition: Guild.h:631

◆ IsBank()

bool Guild::BankMoveItemData::IsBank ( ) const
inlineoverridevirtual

Implements Guild::MoveItemData.

657{ return true; }

◆ LogAction()

void Guild::BankMoveItemData::LogAction ( MoveItemData pFrom) const
overridevirtual

Reimplemented from Guild::MoveItemData.

904{
906}
virtual void LogAction(MoveItemData *pFrom) const
Definition: Guild.cpp:745

References Guild::MoveItemData::LogAction().

◆ LogBankEvent()

void Guild::BankMoveItemData::LogBankEvent ( CharacterDatabaseTransaction  trans,
MoveItemData pFrom,
uint32  count 
) const
overridevirtual

Implements Guild::MoveItemData.

891{
892 ASSERT(pFrom->GetItem());
893 if (pFrom->IsBank())
894 // Bank -> Bank
895 m_pGuild->_LogBankEvent(trans, GUILD_BANK_LOG_MOVE_ITEM, pFrom->GetContainer(), m_pPlayer->GetGUID(),
896 pFrom->GetItem()->GetEntry(), count, m_container);
897 else
898 // Char -> Bank
900 pFrom->GetItem()->GetEntry(), count);
901}
@ GUILD_BANK_LOG_MOVE_ITEM
Definition: Guild.h:199
@ GUILD_BANK_LOG_DEPOSIT_ITEM
Definition: Guild.h:197
uint32 GetEntry() const
Definition: ObjectGuid.h:144
void _LogBankEvent(CharacterDatabaseTransaction trans, GuildBankEventLogTypes eventType, uint8 tabId, ObjectGuid playerGuid, uint32 itemOrMoney, uint16 itemStackCount=0, uint8 destTabId=0)
Definition: Guild.cpp:2617

References ASSERT, Guild::MoveItemData::GetContainer(), Object::GetEntry(), Guild::MoveItemData::GetItem(), GUILD_BANK_LOG_DEPOSIT_ITEM, GUILD_BANK_LOG_MOVE_ITEM, and Guild::MoveItemData::IsBank().

◆ RemoveItem()

void Guild::BankMoveItemData::RemoveItem ( CharacterDatabaseTransaction  trans,
MoveItemData pOther,
uint32  splitedAmount 
)
overridevirtual

Implements Guild::MoveItemData.

850{
852 if (splitedAmount)
853 {
854 m_pItem->SetCount(m_pItem->GetCount() - splitedAmount);
856 m_pItem->SaveToDB(trans);
857 }
858 else
859 {
861 m_pItem = nullptr;
862 }
863 // Decrease amount of player's remaining items (if item is moved to different tab or to player)
864 if (!pOther->IsBank() || pOther->GetContainer() != m_container)
866}
virtual void SaveToDB(CharacterDatabaseTransaction trans)
Definition: Item.cpp:336
void FSetState(ItemUpdateState state)
Definition: Item.h:330
void _RemoveItem(CharacterDatabaseTransaction trans, uint8 tabId, uint8 slotId)
Definition: Guild.cpp:2645
void _UpdateMemberWithdrawSlots(CharacterDatabaseTransaction trans, ObjectGuid guid, uint8 tabId)
Definition: Guild.cpp:2583

References ASSERT, Guild::MoveItemData::GetContainer(), Guild::MoveItemData::IsBank(), and ITEM_CHANGED.

◆ StoreItem()

Item * Guild::BankMoveItemData::StoreItem ( CharacterDatabaseTransaction  trans,
Item pItem 
)
overridevirtual

Implements Guild::MoveItemData.

869{
870 if (!pItem)
871 return nullptr;
872
873 BankTab* pTab = m_pGuild->GetBankTab(m_container);
874 if (!pTab)
875 return nullptr;
876
877 Item* pLastItem = pItem;
878 for (ItemPosCountVec::const_iterator itr = m_vec.begin(); itr != m_vec.end(); )
879 {
880 ItemPosCount pos(*itr);
881 ++itr;
882
883 LOG_DEBUG("guild", "GUILD STORAGE: StoreItem tab = {}, slot = {}, item = {}, count = {}",
884 m_container, m_slotId, pItem->GetEntry(), pItem->GetCount());
885 pLastItem = _StoreItem(trans, pTab, pItem, pos, itr != m_vec.end());
886 }
887 return pLastItem;
888}
BankTab * GetBankTab(uint8 tabId)
Definition: Guild.h:817
Item * _StoreItem(CharacterDatabaseTransaction trans, BankTab *pTab, Item *pItem, ItemPosCount &pos, bool clone) const
Definition: Guild.cpp:908

References Item::GetCount(), Object::GetEntry(), and LOG_DEBUG.