aboutsummaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authormegamage <none@none>2009-08-24 20:18:16 -0500
committermegamage <none@none>2009-08-24 20:18:16 -0500
commit0d5028eea43dab5a2a96af5939243bae2e8a5d87 (patch)
treec7bd7aa7e8e2b271528ccdc10b1fb9867de7a373 /src/game
parent0175da87e47a7a6baeb4f6a5776e8dadde5d15b2 (diff)
[8407] Extract from guild bank handler functions for 3 cases and move code to Guild class. Author: VladimirMangos
This mostly just move code and caller updates to use it from new place. More code chnages possible later. --HG-- branch : trunk
Diffstat (limited to 'src/game')
-rw-r--r--src/game/Guild.cpp412
-rw-r--r--src/game/Guild.h17
-rw-r--r--src/game/GuildHandler.cpp408
-rw-r--r--src/game/WorldSession.h1
4 files changed, 428 insertions, 410 deletions
diff --git a/src/game/Guild.cpp b/src/game/Guild.cpp
index 37d5db941f7..77a667d7f37 100644
--- a/src/game/Guild.cpp
+++ b/src/game/Guild.cpp
@@ -1989,6 +1989,418 @@ void Guild::SendGuildBankTabText(WorldSession *session, uint8 TabId)
}
+void Guild::SwapItems(Player * pl, uint8 BankTab, uint8 BankTabSlot, uint8 BankTabDst, uint8 BankTabSlotDst, uint32 SplitedAmount )
+{
+ // empty operation
+ if(BankTab==BankTabDst && BankTabSlot==BankTabSlotDst)
+ return;
+
+ Item *pItemSrc = GetItem(BankTab, BankTabSlot);
+ if (!pItemSrc) // may prevent crash
+ return;
+
+ if(SplitedAmount > pItemSrc->GetCount())
+ return; // cheating?
+ else if(SplitedAmount == pItemSrc->GetCount())
+ SplitedAmount = 0; // no split
+
+ Item *pItemDst = GetItem(BankTabDst, BankTabSlotDst);
+
+ if(BankTab!=BankTabDst)
+ {
+ // check dest pos rights (if different tabs)
+ if(!IsMemberHaveRights(pl->GetGUIDLow(), BankTabDst, GUILD_BANK_RIGHT_DEPOSIT_ITEM))
+ return;
+
+ // check source pos rights (if different tabs)
+ uint32 remRight = GetMemberSlotWithdrawRem(pl->GetGUIDLow(), BankTab);
+ if(remRight <= 0)
+ return;
+ }
+
+ if (SplitedAmount)
+ { // Bank -> Bank item split (in empty or non empty slot
+ GuildItemPosCountVec dest;
+ uint8 msg = CanStoreItem(BankTabDst,BankTabSlotDst,dest,SplitedAmount,pItemSrc,false);
+ if( msg != EQUIP_ERR_OK )
+ {
+ pl->SendEquipError( msg, pItemSrc, NULL );
+ return;
+ }
+
+ Item *pNewItem = pItemSrc->CloneItem( SplitedAmount );
+ if( !pNewItem )
+ {
+ pl->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, pItemSrc, NULL );
+ return;
+ }
+
+ CharacterDatabase.BeginTransaction();
+ LogBankEvent(GUILD_BANK_LOG_MOVE_ITEM, BankTab, pl->GetGUIDLow(), pItemSrc->GetEntry(), SplitedAmount, BankTabDst);
+
+ pl->ItemRemovedQuestCheck( pItemSrc->GetEntry(), SplitedAmount );
+ pItemSrc->SetCount( pItemSrc->GetCount() - SplitedAmount );
+ pItemSrc->FSetState(ITEM_CHANGED);
+ pItemSrc->SaveToDB(); // not in inventory and can be save standalone
+ StoreItem(BankTabDst,dest,pNewItem);
+ CharacterDatabase.CommitTransaction();
+ }
+ else // non split
+ {
+ GuildItemPosCountVec gDest;
+ uint8 msg = CanStoreItem(BankTabDst,BankTabSlotDst,gDest,pItemSrc->GetCount(),pItemSrc,false);
+ if( msg == EQUIP_ERR_OK ) // merge to
+ {
+ CharacterDatabase.BeginTransaction();
+ LogBankEvent(GUILD_BANK_LOG_MOVE_ITEM, BankTab, pl->GetGUIDLow(), pItemSrc->GetEntry(), pItemSrc->GetCount(), BankTabDst);
+
+ RemoveItem(BankTab, BankTabSlot);
+ StoreItem(BankTabDst, gDest, pItemSrc);
+ CharacterDatabase.CommitTransaction();
+ }
+ else // swap
+ {
+ gDest.clear();
+ msg = CanStoreItem(BankTabDst,BankTabSlotDst,gDest,pItemSrc->GetCount(),pItemSrc,true);
+ if( msg != EQUIP_ERR_OK )
+ {
+ pl->SendEquipError( msg, pItemSrc, NULL );
+ return;
+ }
+
+ GuildItemPosCountVec gSrc;
+ msg = CanStoreItem(BankTab,BankTabSlot,gSrc,pItemDst->GetCount(),pItemDst,true);
+ if( msg != EQUIP_ERR_OK )
+ {
+ pl->SendEquipError( msg, pItemDst, NULL );
+ return;
+ }
+
+ if(BankTab!=BankTabDst)
+ {
+ // check source pos rights (item swapped to src)
+ if(!IsMemberHaveRights(pl->GetGUIDLow(), BankTab, GUILD_BANK_RIGHT_DEPOSIT_ITEM))
+ return;
+
+ // check dest pos rights (item swapped to src)
+ uint32 remRightDst = GetMemberSlotWithdrawRem(pl->GetGUIDLow(), BankTabDst);
+ if(remRightDst <= 0)
+ return;
+ }
+
+ CharacterDatabase.BeginTransaction();
+ LogBankEvent(GUILD_BANK_LOG_MOVE_ITEM, BankTab, pl->GetGUIDLow(), pItemSrc->GetEntry(), pItemSrc->GetCount(), BankTabDst);
+ LogBankEvent(GUILD_BANK_LOG_MOVE_ITEM, BankTabDst, pl->GetGUIDLow(), pItemDst->GetEntry(), pItemDst->GetCount(), BankTab);
+
+ RemoveItem(BankTab, BankTabSlot);
+ RemoveItem(BankTabDst, BankTabSlotDst);
+ StoreItem(BankTab, gSrc, pItemDst);
+ StoreItem(BankTabDst, gDest, pItemSrc);
+ CharacterDatabase.CommitTransaction();
+ }
+ }
+ DisplayGuildBankContentUpdate(BankTab,BankTabSlot,BankTab==BankTabDst ? BankTabSlotDst : -1);
+ if(BankTab!=BankTabDst)
+ DisplayGuildBankContentUpdate(BankTabDst,BankTabSlotDst);
+}
+
+
+void Guild::MoveFromBankToChar( Player * pl, uint8 BankTab, uint8 BankTabSlot, uint8 PlayerBag, uint8 PlayerSlot, uint32 SplitedAmount)
+{
+ Item *pItemBank = GetItem(BankTab, BankTabSlot);
+ Item *pItemChar = pl->GetItemByPos(PlayerBag, PlayerSlot);
+
+ if (!pItemBank) // Problem to get bank item
+ return;
+
+ if(SplitedAmount > pItemBank->GetCount())
+ return; // cheating?
+ else if(SplitedAmount == pItemBank->GetCount())
+ SplitedAmount = 0; // no split
+
+ if (SplitedAmount)
+ { // Bank -> Char split to slot (patly move)
+ Item *pNewItem = pItemBank->CloneItem( SplitedAmount );
+ if( !pNewItem )
+ {
+ pl->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, pItemBank, NULL );
+ return;
+ }
+
+ ItemPosCountVec dest;
+ uint8 msg = pl->CanStoreItem(PlayerBag, PlayerSlot, dest, pNewItem, false);
+ if( msg != EQUIP_ERR_OK )
+ {
+ pl->SendEquipError( msg, pNewItem, NULL );
+ delete pNewItem;
+ return;
+ }
+
+ // check source pos rights (item moved to inventory)
+ uint32 remRight = GetMemberSlotWithdrawRem(pl->GetGUIDLow(), BankTab);
+ if(remRight <= 0)
+ {
+ delete pNewItem;
+ return;
+ }
+
+ CharacterDatabase.BeginTransaction();
+ LogBankEvent(GUILD_BANK_LOG_WITHDRAW_ITEM, BankTab, pl->GetGUIDLow(), pItemBank->GetEntry(), SplitedAmount);
+
+ pItemBank->SetCount(pItemBank->GetCount()-SplitedAmount);
+ pItemBank->FSetState(ITEM_CHANGED);
+ pItemBank->SaveToDB(); // not in inventory and can be save standalone
+ pl->MoveItemToInventory(dest,pNewItem,true);
+ pl->SaveInventoryAndGoldToDB();
+
+ MemberItemWithdraw(BankTab, pl->GetGUIDLow());
+ CharacterDatabase.CommitTransaction();
+ }
+ else // Bank -> Char swap with slot (move)
+ {
+ ItemPosCountVec dest;
+ uint8 msg = pl->CanStoreItem(PlayerBag, PlayerSlot, dest, pItemBank, false);
+ if( msg == EQUIP_ERR_OK ) // merge case
+ {
+ // check source pos rights (item moved to inventory)
+ uint32 remRight = GetMemberSlotWithdrawRem(pl->GetGUIDLow(), BankTab);
+ if(remRight <= 0)
+ return;
+
+ CharacterDatabase.BeginTransaction();
+ LogBankEvent(GUILD_BANK_LOG_WITHDRAW_ITEM, BankTab, pl->GetGUIDLow(), pItemBank->GetEntry(), pItemBank->GetCount());
+
+ RemoveItem(BankTab, BankTabSlot);
+ pl->MoveItemToInventory(dest,pItemBank,true);
+ pl->SaveInventoryAndGoldToDB();
+
+ MemberItemWithdraw(BankTab, pl->GetGUIDLow());
+ CharacterDatabase.CommitTransaction();
+ }
+ else // Bank <-> Char swap items
+ {
+ // check source pos rights (item swapped to bank)
+ if(!IsMemberHaveRights(pl->GetGUIDLow(), BankTab, GUILD_BANK_RIGHT_DEPOSIT_ITEM))
+ return;
+
+ if(pItemChar)
+ {
+ if(!pItemChar->CanBeTraded())
+ {
+ pl->SendEquipError( EQUIP_ERR_ITEMS_CANT_BE_SWAPPED, pItemChar, NULL );
+ return;
+ }
+ }
+
+ ItemPosCountVec iDest;
+ msg = pl->CanStoreItem(PlayerBag, PlayerSlot, iDest, pItemBank, true);
+ if( msg != EQUIP_ERR_OK )
+ {
+ pl->SendEquipError( msg, pItemBank, NULL );
+ return;
+ }
+
+ GuildItemPosCountVec gDest;
+ if(pItemChar)
+ {
+ msg = CanStoreItem(BankTab,BankTabSlot,gDest,pItemChar->GetCount(),pItemChar,true);
+ if( msg != EQUIP_ERR_OK )
+ {
+ pl->SendEquipError( msg, pItemChar, NULL );
+ return;
+ }
+ }
+
+ // check source pos rights (item moved to inventory)
+ uint32 remRight = GetMemberSlotWithdrawRem(pl->GetGUIDLow(), BankTab);
+ if(remRight <= 0)
+ return;
+
+ if(pItemChar)
+ {
+ // logging item move to bank
+ if(pl->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE))
+ {
+ sLog.outCommand(pl->GetSession()->GetAccountId(),"GM %s (Account: %u) deposit item: %s (Entry: %d Count: %u) to guild bank (Guild ID: %u )",
+ pl->GetName(),pl->GetSession()->GetAccountId(),
+ pItemChar->GetProto()->Name1,pItemChar->GetEntry(),pItemChar->GetCount(),
+ m_Id);
+ }
+ }
+
+ CharacterDatabase.BeginTransaction();
+ LogBankEvent(GUILD_BANK_LOG_WITHDRAW_ITEM, BankTab, pl->GetGUIDLow(), pItemBank->GetEntry(), pItemBank->GetCount());
+ if(pItemChar)
+ LogBankEvent(GUILD_BANK_LOG_DEPOSIT_ITEM, BankTab, pl->GetGUIDLow(), pItemChar->GetEntry(), pItemChar->GetCount());
+
+ RemoveItem(BankTab, BankTabSlot);
+ if(pItemChar)
+ {
+ pl->MoveItemFromInventory(PlayerBag, PlayerSlot, true);
+ pItemChar->DeleteFromInventoryDB();
+ }
+
+ if(pItemChar)
+ StoreItem(BankTab, gDest, pItemChar);
+ pl->MoveItemToInventory(iDest,pItemBank,true);
+ pl->SaveInventoryAndGoldToDB();
+
+ MemberItemWithdraw(BankTab, pl->GetGUIDLow());
+ CharacterDatabase.CommitTransaction();
+ }
+ }
+ DisplayGuildBankContentUpdate(BankTab,BankTabSlot);
+}
+
+
+void Guild::MoveFromCharToBank( Player * pl, uint8 PlayerBag, uint8 PlayerSlot, uint8 BankTab, uint8 BankTabSlot, uint32 SplitedAmount )
+{
+ Item *pItemBank = GetItem(BankTab, BankTabSlot);
+ Item *pItemChar = pl->GetItemByPos(PlayerBag, PlayerSlot);
+
+ if (!pItemChar) // Problem to get item from player
+ return;
+
+ if(!pItemChar->CanBeTraded())
+ {
+ pl->SendEquipError( EQUIP_ERR_ITEMS_CANT_BE_SWAPPED, pItemChar, NULL );
+ return;
+ }
+
+ // check source pos rights (item moved to bank)
+ if(!IsMemberHaveRights(pl->GetGUIDLow(), BankTab, GUILD_BANK_RIGHT_DEPOSIT_ITEM))
+ return;
+
+ if(SplitedAmount > pItemChar->GetCount())
+ return; // cheating?
+ else if(SplitedAmount == pItemChar->GetCount())
+ SplitedAmount = 0; // no split
+
+ if (SplitedAmount)
+ { // Char -> Bank split to empty or non-empty slot (partly move)
+ GuildItemPosCountVec dest;
+ uint8 msg = CanStoreItem(BankTab,BankTabSlot,dest,SplitedAmount,pItemChar,false);
+ if( msg != EQUIP_ERR_OK )
+ {
+ pl->SendEquipError( msg, pItemChar, NULL );
+ return;
+ }
+
+ Item *pNewItem = pItemChar->CloneItem( SplitedAmount );
+ if( !pNewItem )
+ {
+ pl->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, pItemChar, NULL );
+ return;
+ }
+
+ // logging item move to bank (before items merge
+ if(pl->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE))
+ {
+ sLog.outCommand(pl->GetSession()->GetAccountId(),"GM %s (Account: %u) deposit item: %s (Entry: %d Count: %u) to guild bank (Guild ID: %u )",
+ pl->GetName(),pl->GetSession()->GetAccountId(),
+ pItemChar->GetProto()->Name1,pItemChar->GetEntry(),SplitedAmount,m_Id);
+ }
+
+ CharacterDatabase.BeginTransaction();
+ LogBankEvent(GUILD_BANK_LOG_DEPOSIT_ITEM, BankTab, pl->GetGUIDLow(), pItemChar->GetEntry(), SplitedAmount);
+
+ pl->ItemRemovedQuestCheck( pItemChar->GetEntry(), SplitedAmount );
+ pItemChar->SetCount(pItemChar->GetCount()-SplitedAmount);
+ pItemChar->SetState(ITEM_CHANGED);
+ pl->SaveInventoryAndGoldToDB();
+ StoreItem(BankTab, dest, pNewItem);
+ CharacterDatabase.CommitTransaction();
+
+ DisplayGuildBankContentUpdate(BankTab,dest);
+ }
+ else // Char -> Bank swap with empty or non-empty (move)
+ {
+ GuildItemPosCountVec dest;
+ uint8 msg = CanStoreItem(BankTab,BankTabSlot,dest,pItemChar->GetCount(),pItemChar,false);
+ if( msg == EQUIP_ERR_OK ) // merge
+ {
+ // logging item move to bank
+ if(pl->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE))
+ {
+ sLog.outCommand(pl->GetSession()->GetAccountId(),"GM %s (Account: %u) deposit item: %s (Entry: %d Count: %u) to guild bank (Guild ID: %u )",
+ pl->GetName(),pl->GetSession()->GetAccountId(),
+ pItemChar->GetProto()->Name1,pItemChar->GetEntry(),pItemChar->GetCount(),
+ m_Id);
+ }
+
+ CharacterDatabase.BeginTransaction();
+ LogBankEvent(GUILD_BANK_LOG_DEPOSIT_ITEM, BankTab, pl->GetGUIDLow(), pItemChar->GetEntry(), pItemChar->GetCount());
+
+ pl->MoveItemFromInventory(PlayerBag, PlayerSlot, true);
+ pItemChar->DeleteFromInventoryDB();
+
+ StoreItem(BankTab,dest,pItemChar);
+ pl->SaveInventoryAndGoldToDB();
+ CharacterDatabase.CommitTransaction();
+
+ DisplayGuildBankContentUpdate(BankTab,dest);
+ }
+ else // Char <-> Bank swap items (posible NULL bank item)
+ {
+ ItemPosCountVec iDest;
+ if(pItemBank)
+ {
+ msg = pl->CanStoreItem(PlayerBag, PlayerSlot, iDest, pItemBank, true);
+ if( msg != EQUIP_ERR_OK )
+ {
+ pl->SendEquipError( msg, pItemBank, NULL );
+ return;
+ }
+ }
+
+ GuildItemPosCountVec gDest;
+ msg = CanStoreItem(BankTab,BankTabSlot,gDest,pItemChar->GetCount(),pItemChar,true);
+ if( msg != EQUIP_ERR_OK )
+ {
+ pl->SendEquipError( msg, pItemChar, NULL );
+ return;
+ }
+
+ if(pItemBank)
+ {
+ // check bank pos rights (item swapped with inventory)
+ uint32 remRight = GetMemberSlotWithdrawRem(pl->GetGUIDLow(), BankTab);
+ if(remRight <= 0)
+ return;
+ }
+
+ // logging item move to bank
+ if(pl->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE))
+ {
+ sLog.outCommand(pl->GetSession()->GetAccountId(),"GM %s (Account: %u) deposit item: %s (Entry: %d Count: %u) to guild bank (Guild ID: %u )",
+ pl->GetName(),pl->GetSession()->GetAccountId(),
+ pItemChar->GetProto()->Name1,pItemChar->GetEntry(),pItemChar->GetCount(),
+ m_Id);
+ }
+
+ CharacterDatabase.BeginTransaction();
+ if(pItemBank)
+ LogBankEvent(GUILD_BANK_LOG_WITHDRAW_ITEM, BankTab, pl->GetGUIDLow(), pItemBank->GetEntry(), pItemBank->GetCount());
+ LogBankEvent(GUILD_BANK_LOG_DEPOSIT_ITEM, BankTab, pl->GetGUIDLow(), pItemChar->GetEntry(), pItemChar->GetCount());
+
+ pl->MoveItemFromInventory(PlayerBag, PlayerSlot, true);
+ pItemChar->DeleteFromInventoryDB();
+ if(pItemBank)
+ RemoveItem(BankTab, BankTabSlot);
+
+ StoreItem(BankTab,gDest,pItemChar);
+ if(pItemBank)
+ pl->MoveItemToInventory(iDest,pItemBank,true);
+ pl->SaveInventoryAndGoldToDB();
+ if(pItemBank)
+ MemberItemWithdraw(BankTab, pl->GetGUIDLow());
+ CharacterDatabase.CommitTransaction();
+
+ DisplayGuildBankContentUpdate(BankTab,gDest);
+ }
+ }
+}
+
bool GuildItemPosCount::isContainedIn(GuildItemPosCountVec const &vec) const
{
for(GuildItemPosCountVec::const_iterator itr = vec.begin(); itr != vec.end();++itr)
diff --git a/src/game/Guild.h b/src/game/Guild.h
index 4d66ad10b4a..f9696493cc6 100644
--- a/src/game/Guild.h
+++ b/src/game/Guild.h
@@ -382,14 +382,11 @@ class Guild
// ** Guild bank **
// Content & item deposit/withdraw
void DisplayGuildBankContent(WorldSession *session, uint8 TabId);
- void DisplayGuildBankContentUpdate(uint8 TabId, int32 slot1, int32 slot2 = -1);
- void DisplayGuildBankContentUpdate(uint8 TabId, GuildItemPosCountVec const& slots);
void DisplayGuildBankMoneyUpdate();
- Item* GetItem(uint8 TabId, uint8 SlotId);
- uint8 CanStoreItem( uint8 tab, uint8 slot, GuildItemPosCountVec& dest, uint32 count, Item *pItem, bool swap = false) const;
- Item* StoreItem( uint8 tab, GuildItemPosCountVec const& pos, Item *pItem );
- void RemoveItem(uint8 tab, uint8 slot );
+ void SwapItems( Player * pl, uint8 BankTab, uint8 BankTabSlot, uint8 BankTabDst, uint8 BankTabSlotDst, uint32 SplitedAmount);
+ void MoveFromBankToChar( Player * pl, uint8 BankTab, uint8 BankTabSlot, uint8 PlayerBag, uint8 PlayerSlot, uint32 SplitedAmount);
+ void MoveFromCharToBank( Player * pl, uint8 PlayerBag, uint8 PlayerSlot, uint8 BankTab, uint8 BankTabSlot, uint32 SplitedAmount);
// Tabs
void DisplayGuildBankTabsInfo(WorldSession *session);
@@ -472,6 +469,14 @@ class Guild
uint8 m_PurchasedTabs;
private:
+ // used only from high level Swap/Move functions
+ Item* GetItem(uint8 TabId, uint8 SlotId);
+ uint8 CanStoreItem( uint8 tab, uint8 slot, GuildItemPosCountVec& dest, uint32 count, Item *pItem, bool swap = false) const;
+ Item* StoreItem( uint8 tab, GuildItemPosCountVec const& pos, Item *pItem );
+ void RemoveItem(uint8 tab, uint8 slot );
+ void DisplayGuildBankContentUpdate(uint8 TabId, int32 slot1, int32 slot2 = -1);
+ void DisplayGuildBankContentUpdate(uint8 TabId, GuildItemPosCountVec const& slots);
+
// internal common parts for CanStore/StoreItem functions
void AppendDisplayGuildBankSlot( WorldPacket& data, GuildBankTab const *tab, int32 slot );
uint8 _CanStoreItem_InSpecificSlot( uint8 tab, uint8 slot, GuildItemPosCountVec& dest, uint32& count, bool swap, Item *pSrcItem ) const;
diff --git a/src/game/GuildHandler.cpp b/src/game/GuildHandler.cpp
index 3894dc7adef..70fb1880789 100644
--- a/src/game/GuildHandler.cpp
+++ b/src/game/GuildHandler.cpp
@@ -1098,117 +1098,7 @@ void WorldSession::HandleGuildBankSwapItems( WorldPacket & recv_data )
// Bank <-> Bank
if (BankToBank)
{
- // empty operation
- if(BankTab==BankTabDst && BankTabSlot==BankTabSlotDst)
- return;
-
- Item *pItemSrc = pGuild->GetItem(BankTab, BankTabSlot);
- if (!pItemSrc) // may prevent crash
- return;
-
- if(SplitedAmount > pItemSrc->GetCount())
- return; // cheating?
- else if(SplitedAmount == pItemSrc->GetCount())
- SplitedAmount = 0; // no split
-
- Item *pItemDst = pGuild->GetItem(BankTabDst, BankTabSlotDst);
-
- if(BankTab!=BankTabDst)
- {
- // check dest pos rights (if different tabs)
- if(!pGuild->IsMemberHaveRights(pl->GetGUIDLow(), BankTabDst, GUILD_BANK_RIGHT_DEPOSIT_ITEM))
- return;
-
- // check source pos rights (if different tabs)
- uint32 remRight = pGuild->GetMemberSlotWithdrawRem(pl->GetGUIDLow(), BankTab);
- if(remRight <= 0)
- return;
- }
-
- if (SplitedAmount)
- { // Bank -> Bank item split (in empty or non empty slot
- GuildItemPosCountVec dest;
- uint8 msg = pGuild->CanStoreItem(BankTabDst,BankTabSlotDst,dest,SplitedAmount,pItemSrc,false);
- if( msg != EQUIP_ERR_OK )
- {
- pl->SendEquipError( msg, pItemSrc, NULL );
- return;
- }
-
- Item *pNewItem = pItemSrc->CloneItem( SplitedAmount );
- if( !pNewItem )
- {
- pl->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, pItemSrc, NULL );
- return;
- }
-
- CharacterDatabase.BeginTransaction();
- pGuild->LogBankEvent(GUILD_BANK_LOG_MOVE_ITEM, BankTab, pl->GetGUIDLow(), pItemSrc->GetEntry(), SplitedAmount, BankTabDst);
-
- pl->ItemRemovedQuestCheck( pItemSrc->GetEntry(), SplitedAmount );
- pItemSrc->SetCount( pItemSrc->GetCount() - SplitedAmount );
- pItemSrc->FSetState(ITEM_CHANGED);
- pItemSrc->SaveToDB(); // not in inventory and can be save standalone
- pGuild->StoreItem(BankTabDst,dest,pNewItem);
- CharacterDatabase.CommitTransaction();
- }
- else // non split
- {
- GuildItemPosCountVec gDest;
- uint8 msg = pGuild->CanStoreItem(BankTabDst,BankTabSlotDst,gDest,pItemSrc->GetCount(),pItemSrc,false);
- if( msg == EQUIP_ERR_OK ) // merge to
- {
- CharacterDatabase.BeginTransaction();
- pGuild->LogBankEvent(GUILD_BANK_LOG_MOVE_ITEM, BankTab, pl->GetGUIDLow(), pItemSrc->GetEntry(), pItemSrc->GetCount(), BankTabDst);
-
- pGuild->RemoveItem(BankTab, BankTabSlot);
- pGuild->StoreItem(BankTabDst, gDest, pItemSrc);
- CharacterDatabase.CommitTransaction();
- }
- else // swap
- {
- gDest.clear();
- msg = pGuild->CanStoreItem(BankTabDst,BankTabSlotDst,gDest,pItemSrc->GetCount(),pItemSrc,true);
- if( msg != EQUIP_ERR_OK )
- {
- pl->SendEquipError( msg, pItemSrc, NULL );
- return;
- }
-
- GuildItemPosCountVec gSrc;
- msg = pGuild->CanStoreItem(BankTab,BankTabSlot,gSrc,pItemDst->GetCount(),pItemDst,true);
- if( msg != EQUIP_ERR_OK )
- {
- pl->SendEquipError( msg, pItemDst, NULL );
- return;
- }
-
- if(BankTab!=BankTabDst)
- {
- // check source pos rights (item swapped to src)
- if(!pGuild->IsMemberHaveRights(pl->GetGUIDLow(), BankTab, GUILD_BANK_RIGHT_DEPOSIT_ITEM))
- return;
-
- // check dest pos rights (item swapped to src)
- uint32 remRightDst = pGuild->GetMemberSlotWithdrawRem(pl->GetGUIDLow(), BankTabDst);
- if(remRightDst <= 0)
- return;
- }
-
- CharacterDatabase.BeginTransaction();
- pGuild->LogBankEvent(GUILD_BANK_LOG_MOVE_ITEM, BankTab, pl->GetGUIDLow(), pItemSrc->GetEntry(), pItemSrc->GetCount(), BankTabDst);
- pGuild->LogBankEvent(GUILD_BANK_LOG_MOVE_ITEM, BankTabDst, pl->GetGUIDLow(), pItemDst->GetEntry(), pItemDst->GetCount(), BankTab);
-
- pGuild->RemoveItem(BankTab, BankTabSlot);
- pGuild->RemoveItem(BankTabDst, BankTabSlotDst);
- pGuild->StoreItem(BankTab, gSrc, pItemDst);
- pGuild->StoreItem(BankTabDst, gDest, pItemSrc);
- CharacterDatabase.CommitTransaction();
- }
- }
- pGuild->DisplayGuildBankContentUpdate(BankTab,BankTabSlot,BankTab==BankTabDst ? BankTabSlotDst : -1);
- if(BankTab!=BankTabDst)
- pGuild->DisplayGuildBankContentUpdate(BankTabDst,BankTabSlotDst);
+ pGuild->SwapItems(pl, BankTab, BankTabSlot, BankTabDst, BankTabSlotDst, SplitedAmount);
return;
}
@@ -1221,301 +1111,11 @@ void WorldSession::HandleGuildBankSwapItems( WorldPacket & recv_data )
return;
}
- Item *pItemBank = pGuild->GetItem(BankTab, BankTabSlot);
- Item *pItemChar = GetPlayer()->GetItemByPos(PlayerBag, PlayerSlot);
- if (!pItemChar && !pItemBank) // Nothing to do
- return;
-
- if (!pItemChar && !ToChar) // Problem to get item from player
- return;
-
- if (!pItemBank && ToChar) // Problem to get bank item
- return;
-
// BankToChar swap or char to bank remaining
-
if (ToChar) // Bank -> Char cases
- {
- if(SplitedAmount > pItemBank->GetCount())
- return; // cheating?
- else if(SplitedAmount == pItemBank->GetCount())
- SplitedAmount = 0; // no split
-
- if (SplitedAmount)
- { // Bank -> Char split to slot (patly move)
- Item *pNewItem = pItemBank->CloneItem( SplitedAmount );
- if( !pNewItem )
- {
- pl->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, pItemBank, NULL );
- return;
- }
-
- ItemPosCountVec dest;
- uint8 msg = pl->CanStoreItem(PlayerBag, PlayerSlot, dest, pNewItem, false);
- if( msg != EQUIP_ERR_OK )
- {
- pl->SendEquipError( msg, pNewItem, NULL );
- delete pNewItem;
- return;
- }
-
- // check source pos rights (item moved to inventory)
- uint32 remRight = pGuild->GetMemberSlotWithdrawRem(pl->GetGUIDLow(), BankTab);
- if(remRight <= 0)
- {
- delete pNewItem;
- return;
- }
-
- CharacterDatabase.BeginTransaction();
- pGuild->LogBankEvent(GUILD_BANK_LOG_WITHDRAW_ITEM, BankTab, pl->GetGUIDLow(), pItemBank->GetEntry(), SplitedAmount);
-
- pItemBank->SetCount(pItemBank->GetCount()-SplitedAmount);
- pItemBank->FSetState(ITEM_CHANGED);
- pItemBank->SaveToDB(); // not in inventory and can be save standalone
- pl->MoveItemToInventory(dest,pNewItem,true);
- pl->SaveInventoryAndGoldToDB();
-
- pGuild->MemberItemWithdraw(BankTab, pl->GetGUIDLow());
- CharacterDatabase.CommitTransaction();
- }
- else // Bank -> Char swap with slot (move)
- {
- ItemPosCountVec dest;
- uint8 msg = pl->CanStoreItem(PlayerBag, PlayerSlot, dest, pItemBank, false);
- if( msg == EQUIP_ERR_OK ) // merge case
- {
- // check source pos rights (item moved to inventory)
- uint32 remRight = pGuild->GetMemberSlotWithdrawRem(pl->GetGUIDLow(), BankTab);
- if(remRight <= 0)
- return;
-
- CharacterDatabase.BeginTransaction();
- pGuild->LogBankEvent(GUILD_BANK_LOG_WITHDRAW_ITEM, BankTab, pl->GetGUIDLow(), pItemBank->GetEntry(), pItemBank->GetCount());
-
- pGuild->RemoveItem(BankTab, BankTabSlot);
- pl->MoveItemToInventory(dest,pItemBank,true);
- pl->SaveInventoryAndGoldToDB();
-
- pGuild->MemberItemWithdraw(BankTab, pl->GetGUIDLow());
- CharacterDatabase.CommitTransaction();
- }
- else // Bank <-> Char swap items
- {
- // check source pos rights (item swapped to bank)
- if(!pGuild->IsMemberHaveRights(pl->GetGUIDLow(), BankTab, GUILD_BANK_RIGHT_DEPOSIT_ITEM))
- return;
-
- if(pItemChar)
- {
- if(!pItemChar->CanBeTraded())
- {
- _player->SendEquipError( EQUIP_ERR_ITEMS_CANT_BE_SWAPPED, pItemChar, NULL );
- return;
- }
- }
-
- ItemPosCountVec iDest;
- msg = pl->CanStoreItem(PlayerBag, PlayerSlot, iDest, pItemBank, true);
- if( msg != EQUIP_ERR_OK )
- {
- pl->SendEquipError( msg, pItemBank, NULL );
- return;
- }
-
- GuildItemPosCountVec gDest;
- if(pItemChar)
- {
- msg = pGuild->CanStoreItem(BankTab,BankTabSlot,gDest,pItemChar->GetCount(),pItemChar,true);
- if( msg != EQUIP_ERR_OK )
- {
- pl->SendEquipError( msg, pItemChar, NULL );
- return;
- }
- }
-
- // check source pos rights (item moved to inventory)
- uint32 remRight = pGuild->GetMemberSlotWithdrawRem(pl->GetGUIDLow(), BankTab);
- if(remRight <= 0)
- return;
-
- if(pItemChar)
- {
- // logging item move to bank
- if(_player->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE))
- {
- sLog.outCommand(_player->GetSession()->GetAccountId(),"GM %s (Account: %u) deposit item: %s (Entry: %d Count: %u) to guild bank (Guild ID: %u )",
- _player->GetName(),_player->GetSession()->GetAccountId(),
- pItemChar->GetProto()->Name1,pItemChar->GetEntry(),pItemChar->GetCount(),
- GuildId);
- }
- }
-
- CharacterDatabase.BeginTransaction();
- pGuild->LogBankEvent(GUILD_BANK_LOG_WITHDRAW_ITEM, BankTab, pl->GetGUIDLow(), pItemBank->GetEntry(), pItemBank->GetCount());
- if(pItemChar)
- pGuild->LogBankEvent(GUILD_BANK_LOG_DEPOSIT_ITEM, BankTab, pl->GetGUIDLow(), pItemChar->GetEntry(), pItemChar->GetCount());
-
- pGuild->RemoveItem(BankTab, BankTabSlot);
- if(pItemChar)
- {
- pl->MoveItemFromInventory(PlayerBag, PlayerSlot, true);
- pItemChar->DeleteFromInventoryDB();
- }
-
- if(pItemChar)
- pGuild->StoreItem(BankTab, gDest, pItemChar);
- pl->MoveItemToInventory(iDest,pItemBank,true);
- pl->SaveInventoryAndGoldToDB();
-
- pGuild->MemberItemWithdraw(BankTab, pl->GetGUIDLow());
- CharacterDatabase.CommitTransaction();
- }
- }
- pGuild->DisplayGuildBankContentUpdate(BankTab,BankTabSlot);
- return;
- } // End "To char" part
-
- // Char -> Bank cases
-
- if(!pItemChar->CanBeTraded())
- {
- _player->SendEquipError( EQUIP_ERR_ITEMS_CANT_BE_SWAPPED, pItemChar, NULL );
- return;
- }
-
- // check source pos rights (item moved to bank)
- if(!pGuild->IsMemberHaveRights(pl->GetGUIDLow(), BankTab, GUILD_BANK_RIGHT_DEPOSIT_ITEM))
- return;
-
- if(SplitedAmount > pItemChar->GetCount())
- return; // cheating?
- else if(SplitedAmount == pItemChar->GetCount())
- SplitedAmount = 0; // no split
-
- if (SplitedAmount)
- { // Char -> Bank split to empty or non-empty slot (partly move)
- GuildItemPosCountVec dest;
- uint8 msg = pGuild->CanStoreItem(BankTab,BankTabSlot,dest,SplitedAmount,pItemChar,false);
- if( msg != EQUIP_ERR_OK )
- {
- pl->SendEquipError( msg, pItemChar, NULL );
- return;
- }
-
- Item *pNewItem = pItemChar->CloneItem( SplitedAmount );
- if( !pNewItem )
- {
- pl->SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND, pItemChar, NULL );
- return;
- }
-
- // logging item move to bank (before items merge
- if(_player->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE))
- {
- sLog.outCommand(_player->GetSession()->GetAccountId(),"GM %s (Account: %u) deposit item: %s (Entry: %d Count: %u) to guild bank (Guild ID: %u )",
- _player->GetName(),_player->GetSession()->GetAccountId(),
- pItemChar->GetProto()->Name1,pItemChar->GetEntry(),SplitedAmount,GuildId);
- }
-
- CharacterDatabase.BeginTransaction();
- pGuild->LogBankEvent(GUILD_BANK_LOG_DEPOSIT_ITEM, BankTab, pl->GetGUIDLow(), pItemChar->GetEntry(), SplitedAmount);
-
- pl->ItemRemovedQuestCheck( pItemChar->GetEntry(), SplitedAmount );
- pItemChar->SetCount(pItemChar->GetCount()-SplitedAmount);
- pItemChar->SetState(ITEM_CHANGED);
- pl->SaveInventoryAndGoldToDB();
- pGuild->StoreItem(BankTab, dest, pNewItem);
- CharacterDatabase.CommitTransaction();
-
- pGuild->DisplayGuildBankContentUpdate(BankTab,dest);
- }
- else // Char -> Bank swap with empty or non-empty (move)
- {
- GuildItemPosCountVec dest;
- uint8 msg = pGuild->CanStoreItem(BankTab,BankTabSlot,dest,pItemChar->GetCount(),pItemChar,false);
- if( msg == EQUIP_ERR_OK ) // merge
- {
- // logging item move to bank
- if(_player->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE))
- {
- sLog.outCommand(_player->GetSession()->GetAccountId(),"GM %s (Account: %u) deposit item: %s (Entry: %d Count: %u) to guild bank (Guild ID: %u )",
- _player->GetName(),_player->GetSession()->GetAccountId(),
- pItemChar->GetProto()->Name1,pItemChar->GetEntry(),pItemChar->GetCount(),
- GuildId);
- }
-
- CharacterDatabase.BeginTransaction();
- pGuild->LogBankEvent(GUILD_BANK_LOG_DEPOSIT_ITEM, BankTab, pl->GetGUIDLow(), pItemChar->GetEntry(), pItemChar->GetCount());
-
- pl->MoveItemFromInventory(PlayerBag, PlayerSlot, true);
- pItemChar->DeleteFromInventoryDB();
-
- pGuild->StoreItem(BankTab,dest,pItemChar);
- pl->SaveInventoryAndGoldToDB();
- CharacterDatabase.CommitTransaction();
-
- pGuild->DisplayGuildBankContentUpdate(BankTab,dest);
- }
- else // Char <-> Bank swap items (posible NULL bank item)
- {
- ItemPosCountVec iDest;
- if(pItemBank)
- {
- msg = pl->CanStoreItem(PlayerBag, PlayerSlot, iDest, pItemBank, true);
- if( msg != EQUIP_ERR_OK )
- {
- pl->SendEquipError( msg, pItemBank, NULL );
- return;
- }
- }
-
- GuildItemPosCountVec gDest;
- msg = pGuild->CanStoreItem(BankTab,BankTabSlot,gDest,pItemChar->GetCount(),pItemChar,true);
- if( msg != EQUIP_ERR_OK )
- {
- pl->SendEquipError( msg, pItemChar, NULL );
- return;
- }
-
- if(pItemBank)
- {
- // check bank pos rights (item swapped with inventory)
- uint32 remRight = pGuild->GetMemberSlotWithdrawRem(pl->GetGUIDLow(), BankTab);
- if(remRight <= 0)
- return;
- }
-
- // logging item move to bank
- if(_player->GetSession()->GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE))
- {
- sLog.outCommand(_player->GetSession()->GetAccountId(),"GM %s (Account: %u) deposit item: %s (Entry: %d Count: %u) to guild bank (Guild ID: %u )",
- _player->GetName(),_player->GetSession()->GetAccountId(),
- pItemChar->GetProto()->Name1,pItemChar->GetEntry(),pItemChar->GetCount(),
- GuildId);
- }
-
- CharacterDatabase.BeginTransaction();
- if(pItemBank)
- pGuild->LogBankEvent(GUILD_BANK_LOG_WITHDRAW_ITEM, BankTab, pl->GetGUIDLow(), pItemBank->GetEntry(), pItemBank->GetCount());
- pGuild->LogBankEvent(GUILD_BANK_LOG_DEPOSIT_ITEM, BankTab, pl->GetGUIDLow(), pItemChar->GetEntry(), pItemChar->GetCount());
-
- pl->MoveItemFromInventory(PlayerBag, PlayerSlot, true);
- pItemChar->DeleteFromInventoryDB();
- if(pItemBank)
- pGuild->RemoveItem(BankTab, BankTabSlot);
-
- pGuild->StoreItem(BankTab,gDest,pItemChar);
- if(pItemBank)
- pl->MoveItemToInventory(iDest,pItemBank,true);
- pl->SaveInventoryAndGoldToDB();
- if(pItemBank)
- pGuild->MemberItemWithdraw(BankTab, pl->GetGUIDLow());
- CharacterDatabase.CommitTransaction();
-
- pGuild->DisplayGuildBankContentUpdate(BankTab,gDest);
- }
- }
+ pGuild->MoveFromBankToChar(pl, BankTab, BankTabSlot, PlayerBag, PlayerSlot, SplitedAmount);
+ else // Char -> Bank cases
+ pGuild->MoveFromCharToBank(pl, PlayerBag, PlayerSlot, BankTab, BankTabSlot, SplitedAmount);
}
void WorldSession::HandleGuildBankBuyTab( WorldPacket & recv_data )
diff --git a/src/game/WorldSession.h b/src/game/WorldSession.h
index 948c0f678ee..27c0c3e472d 100644
--- a/src/game/WorldSession.h
+++ b/src/game/WorldSession.h
@@ -686,6 +686,7 @@ class TRINITY_DLL_SPEC WorldSession
void HandleGuildBankDepositMoney(WorldPacket& recv_data);
void HandleGuildBankWithdrawMoney(WorldPacket& recv_data);
void HandleGuildBankSwapItems(WorldPacket& recv_data);
+
void HandleGuildBankUpdateTab(WorldPacket& recv_data);
void HandleGuildBankBuyTab(WorldPacket& recv_data);
void HandleQueryGuildBankTabText(WorldPacket& recv_data);