mirror of
https://github.com/mangosfour/server.git
synced 2025-12-15 19:37:02 +00:00
[8407] Extract from guild bank handler functions for 3 cases and move code to Guild class.
This mostly just move code and caller updates to use it from new place. More code chnages possible later.
This commit is contained in:
parent
f3930cb06f
commit
5ceb0919e7
5 changed files with 429 additions and 411 deletions
|
|
@ -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 )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue