TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Guild::BankMoveItemData Class Reference

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 (SQLTransaction &trans, MoveItemData *pOther, uint32 splitedAmount) override
 
ItemStoreItem (SQLTransaction &trans, Item *pItem) override
 
void LogBankEvent (SQLTransaction &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 CheckItem (uint32 &splitedAmount)
 
bool CanStore (Item *pItem, bool swap, bool sendError)
 
bool CloneItem (uint32 count)
 
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
 

Private Member Functions

Item_StoreItem (SQLTransaction &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
 

Constructor & Destructor Documentation

Guild::BankMoveItemData::BankMoveItemData ( Guild guild,
Player player,
uint8  container,
uint8  slotId 
)
inline
725  :
726  MoveItemData(guild, player, container, slotId) { }
MoveItemData(Guild *guild, Player *player, uint8 container, uint8 slotId)
Definition: Guild.h:663

Member Function Documentation

bool Guild::BankMoveItemData::_ReserveSpace ( uint8  slotId,
Item pItem,
Item pItemDest,
uint32 count 
)
private
950 {
951  uint32 requiredSpace = pItem->GetMaxStackCount();
952  if (pItemDest)
953  {
954  // Make sure source and destination items match and destination item has space for more stacks.
955  if (pItemDest->GetEntry() != pItem->GetEntry() || pItemDest->GetCount() >= pItem->GetMaxStackCount())
956  return false;
957  requiredSpace -= pItemDest->GetCount();
958  }
959  // Let's not be greedy, reserve only required space
960  requiredSpace = std::min(requiredSpace, count);
961 
962  // Reserve space
963  ItemPosCount pos(slotId, requiredSpace);
964  if (!pos.isContainedIn(m_vec))
965  {
966  m_vec.push_back(pos);
967  count -= requiredSpace;
968  }
969  return true;
970 }
uint32 GetCount() const
Definition: Item.h:322
uint32 GetMaxStackCount() const
Definition: Item.h:324
T min(const T &x, const T &y)
Definition: g3dmath.h:305
uint32_t uint32
Definition: Define.h:150
ItemPosCountVec m_vec
Definition: Guild.h:704
uint32 GetEntry() const
Definition: Object.h:107

+ Here is the call graph for this function:

Item * Guild::BankMoveItemData::_StoreItem ( SQLTransaction trans,
BankTab pTab,
Item pItem,
ItemPosCount &  pos,
bool  clone 
) const
private
917 {
918  uint8 slotId = uint8(pos.pos);
919  uint32 count = pos.count;
920  if (Item* pItemDest = pTab->GetItem(slotId))
921  {
922  pItemDest->SetCount(pItemDest->GetCount() + count);
923  pItemDest->FSetState(ITEM_CHANGED);
924  pItemDest->SaveToDB(trans);
925  if (!clone)
926  {
927  pItem->RemoveFromWorld();
928  pItem->DeleteFromDB(trans);
929  delete pItem;
930  }
931  return pItemDest;
932  }
933 
934  if (clone)
935  pItem = pItem->CloneItem(count);
936  else
937  pItem->SetCount(count);
938 
939  if (pItem && pTab->SetItem(trans, slotId, pItem))
940  return pItem;
941 
942  return NULL;
943 }
Item * CloneItem(uint32 count, Player const *player=NULL) const
Definition: Item.cpp:1095
arena_t NULL
Definition: jemalloc_internal.h:624
void SetCount(uint32 value)
Definition: Item.cpp:794
Definition: Item.h:259
uint32_t uint32
Definition: Define.h:150
virtual void RemoveFromWorld()
Definition: Object.cpp:156
uint8_t uint8
Definition: g3dmath.h:164
Definition: Item.h:217
static void DeleteFromDB(SQLTransaction &trans, ObjectGuid::LowType itemGuid)
Definition: Item.cpp:518
uint8_t uint8
Definition: Define.h:152

+ Here is the call graph for this function:

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

Implements Guild::MoveItemData.

993 {
994  TC_LOG_DEBUG("guild", "GUILD STORAGE: CanStore() tab = %u, slot = %u, item = %u, count = %u",
995  m_container, m_slotId, pItem->GetEntry(), pItem->GetCount());
996 
997  uint32 count = pItem->GetCount();
998  // Soulbound items cannot be moved
999  if (pItem->IsSoulBound())
1001 
1002  // Make sure destination bank tab exists
1004  return EQUIP_ERR_WRONG_BAG_TYPE;
1005 
1006  // Slot explicitely specified. Check it.
1007  if (m_slotId != NULL_SLOT)
1008  {
1009  Item* pItemDest = m_pGuild->_GetItem(m_container, m_slotId);
1010  // Ignore swapped item (this slot will be empty after move)
1011  if ((pItemDest == pItem) || swap)
1012  pItemDest = NULL;
1013 
1014  if (!_ReserveSpace(m_slotId, pItem, pItemDest, count))
1015  return EQUIP_ERR_CANT_STACK;
1016 
1017  if (count == 0)
1018  return EQUIP_ERR_OK;
1019  }
1020 
1021  // Slot was not specified or it has not enough space for all the items in stack
1022  // Search for stacks to merge with
1023  if (pItem->GetMaxStackCount() > 1)
1024  {
1025  CanStoreItemInTab(pItem, m_slotId, true, count);
1026  if (count == 0)
1027  return EQUIP_ERR_OK;
1028  }
1029 
1030  // Search free slot for item
1031  CanStoreItemInTab(pItem, m_slotId, false, count);
1032  if (count == 0)
1033  return EQUIP_ERR_OK;
1034 
1035  return EQUIP_ERR_BANK_FULL;
1036 }
Item * _GetItem(uint8 tabId, uint8 slotId) const
Definition: Guild.cpp:3044
uint32 GetCount() const
Definition: Item.h:322
Definition: Unit.h:379
bool IsSoulBound() const
Definition: Item.h:277
uint32 GetMaxStackCount() const
Definition: Item.h:324
arena_t NULL
Definition: jemalloc_internal.h:624
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
Definition: Item.h:63
uint8 _GetPurchasedTabsSize() const
Definition: Guild.h:920
Definition: Item.h:48
Definition: Item.h:259
bool _ReserveSpace(uint8 slotId, Item *pItem, Item *pItemDest, uint32 &count)
Definition: Guild.cpp:949
uint32_t uint32
Definition: Define.h:150
uint8 m_slotId
Definition: Guild.h:701
Definition: Item.h:72
void CanStoreItemInTab(Item *pItem, uint8 skipSlotId, bool merge, uint32 &count)
Definition: Guild.cpp:972
uint8 m_container
Definition: Guild.h:700
uint32 GetEntry() const
Definition: Object.h:107
Definition: Item.h:99
Guild * m_pGuild
Definition: Guild.h:698
Definition: Item.h:67

+ Here is the call graph for this function:

void Guild::BankMoveItemData::CanStoreItemInTab ( Item pItem,
uint8  skipSlotId,
bool  merge,
uint32 count 
)
private
973 {
974  for (uint8 slotId = 0; (slotId < GUILD_BANK_MAX_SLOTS) && (count > 0); ++slotId)
975  {
976  // Skip slot already processed in CanStore (when destination slot was specified)
977  if (slotId == skipSlotId)
978  continue;
979 
980  Item* pItemDest = m_pGuild->_GetItem(m_container, slotId);
981  if (pItemDest == pItem)
982  pItemDest = NULL;
983 
984  // If merge skip empty, if not merge skip non-empty
985  if ((pItemDest != NULL) != merge)
986  continue;
987 
988  _ReserveSpace(slotId, pItem, pItemDest, count);
989  }
990 }
Item * _GetItem(uint8 tabId, uint8 slotId) const
Definition: Guild.cpp:3044
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: Item.h:259
bool _ReserveSpace(uint8 slotId, Item *pItem, Item *pItemDest, uint32 &count)
Definition: Guild.cpp:949
uint8 m_container
Definition: Guild.h:700
uint8_t uint8
Definition: Define.h:152
Guild * m_pGuild
Definition: Guild.h:698
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 }
Definition: Guild.h:185
Player * m_pPlayer
Definition: Guild.h:699
bool _MemberHasTabRights(ObjectGuid guid, uint8 tabId, int32 rights) const
Definition: Guild.cpp:3000
uint8 m_container
Definition: Guild.h:700
#define ASSERT
Definition: Errors.h:55
Guild * m_pGuild
Definition: Guild.h:698

+ Here is the call graph for this function:

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 }
const Member * GetMember(ObjectGuid guid) const
Definition: Guild.h:924
Player * m_pPlayer
Definition: Guild.h:699
int32 _GetMemberRemainingSlots(Member const *member, uint8 tabId) const
Definition: Guild.cpp:2954
int32_t int32
Definition: Define.h:146
uint8 m_container
Definition: Guild.h:700
#define ASSERT
Definition: Errors.h:55
Guild * m_pGuild
Definition: Guild.h:698

+ Here is the call graph for this function:

bool Guild::BankMoveItemData::InitItem ( )
overridevirtual

Implements Guild::MoveItemData.

821 {
823  return (m_pItem != NULL);
824 }
Item * _GetItem(uint8 tabId, uint8 slotId) const
Definition: Guild.cpp:3044
arena_t NULL
Definition: jemalloc_internal.h:624
Item * m_pItem
Definition: Guild.h:702
uint8 m_slotId
Definition: Guild.h:701
uint8 m_container
Definition: Guild.h:700
Guild * m_pGuild
Definition: Guild.h:698
bool Guild::BankMoveItemData::IsBank ( ) const
inlineoverridevirtual

Implements Guild::MoveItemData.

728 { return true; }
void Guild::BankMoveItemData::LogAction ( MoveItemData pFrom) const
overridevirtual
Todo:
Move this to scripts

Reimplemented from Guild::MoveItemData.

904 {
906  if (!pFrom->IsBank() && m_pPlayer->GetSession()->HasPermission(rbac::RBAC_PERM_LOG_GM_TRADE))
907  {
908  sLog->outCommand(m_pPlayer->GetSession()->GetAccountId(),
909  "GM %s (%s) (Account: %u) deposit item: %s (Entry: %d Count: %u) to guild bank named: %s (Guild ID: " UI64FMTD ")",
910  m_pPlayer->GetName().c_str(), m_pPlayer->GetGUID().ToString().c_str(), m_pPlayer->GetSession()->GetAccountId(),
911  pFrom->GetItem()->GetTemplate()->GetDefaultLocaleName(), pFrom->GetItem()->GetEntry(), pFrom->GetItem()->GetCount(),
912  m_pGuild->GetName().c_str(), m_pGuild->GetId());
913  }
914 }
std::string const & GetName() const
Definition: Guild.h:766
#define sLog
Definition: Log.h:154
Player * m_pPlayer
Definition: Guild.h:699
#define UI64FMTD
Definition: Define.h:137
ObjectGuid::LowType GetId() const
Definition: Guild.h:763
Definition: RBAC.h:63
virtual void LogAction(MoveItemData *pFrom) const
Definition: Guild.cpp:745
Guild * m_pGuild
Definition: Guild.h:698

+ Here is the call graph for this function:

void Guild::BankMoveItemData::LogBankEvent ( SQLTransaction 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().GetCounter(),
896  pFrom->GetItem()->GetEntry(), count, m_container);
897  else
898  // Char -> Bank
899  m_pGuild->_LogBankEvent(trans, GUILD_BANK_LOG_DEPOSIT_ITEM, m_container, m_pPlayer->GetGUID().GetCounter(),
900  pFrom->GetItem()->GetEntry(), count);
901 }
Definition: Guild.h:193
Definition: Guild.h:191
Player * m_pPlayer
Definition: Guild.h:699
uint8 m_container
Definition: Guild.h:700
#define ASSERT
Definition: Errors.h:55
void _LogBankEvent(SQLTransaction &trans, GuildBankEventLogTypes eventType, uint8 tabId, ObjectGuid::LowType playerGuid, uint64 itemOrMoney, uint16 itemStackCount=0, uint8 destTabId=0)
Definition: Guild.cpp:3023
Guild * m_pGuild
Definition: Guild.h:698

+ Here is the call graph for this function:

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

Implements Guild::MoveItemData.

850 {
851  ASSERT(m_pItem);
852  if (splitedAmount)
853  {
854  m_pItem->SetCount(m_pItem->GetCount() - splitedAmount);
856  m_pItem->SaveToDB(trans);
857  }
858  else
859  {
861  m_pItem = NULL;
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 }
uint32 GetCount() const
Definition: Item.h:322
void _UpdateMemberWithdrawSlots(SQLTransaction &trans, ObjectGuid guid, uint8 tabId)
Definition: Guild.cpp:2989
void FSetState(ItemUpdateState state)
Definition: Item.h:377
void _RemoveItem(SQLTransaction &trans, uint8 tabId, uint8 slotId)
Definition: Guild.cpp:3051
arena_t NULL
Definition: jemalloc_internal.h:624
void SetCount(uint32 value)
Definition: Item.cpp:794
Item * m_pItem
Definition: Guild.h:702
virtual void SaveToDB(SQLTransaction &trans)
Definition: Item.cpp:311
Player * m_pPlayer
Definition: Guild.h:699
uint8 m_slotId
Definition: Guild.h:701
Definition: Item.h:217
uint8 m_container
Definition: Guild.h:700
#define ASSERT
Definition: Errors.h:55
Guild * m_pGuild
Definition: Guild.h:698

+ Here is the call graph for this function:

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

Implements Guild::MoveItemData.

869 {
870  if (!pItem)
871  return NULL;
872 
873  BankTab* pTab = m_pGuild->GetBankTab(m_container);
874  if (!pTab)
875  return NULL;
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  TC_LOG_DEBUG("guild", "GUILD STORAGE: StoreItem tab = %u, slot = %u, item = %u, count = %u",
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 }
uint32 GetCount() const
Definition: Item.h:322
arena_t NULL
Definition: jemalloc_internal.h:624
BankTab * GetBankTab(uint8 tabId)
Definition: Guild.h:921
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
Item * _StoreItem(SQLTransaction &trans, BankTab *pTab, Item *pItem, ItemPosCount &pos, bool clone) const
Definition: Guild.cpp:916
Definition: Item.h:259
uint8 m_slotId
Definition: Guild.h:701
ItemPosCountVec m_vec
Definition: Guild.h:704
uint8 m_container
Definition: Guild.h:700
uint32 GetEntry() const
Definition: Object.h:107
Guild * m_pGuild
Definition: Guild.h:698

+ Here is the call graph for this function:


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