1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
/*
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "WorldSession.h"
#include "BankPackets.h"
#include "Creature.h"
#include "DB2Stores.h"
#include "GossipDef.h"
#include "Item.h"
#include "Log.h"
#include "NPCPackets.h"
#include "Player.h"
void WorldSession::HandleAutoBankItemOpcode(WorldPackets::Bank::AutoBankItem& packet)
{
TC_LOG_DEBUG("network", "STORAGE: receive bag = {}, slot = {}", packet.Bag, packet.Slot);
if (!CanUseBank())
{
TC_LOG_ERROR("network", "WORLD: HandleAutoBankItemOpcode - Unit ({}) not found or you can't interact with him.", _player->PlayerTalkClass->GetInteractionData().SourceGuid.ToString());
return;
}
if (packet.BankType != BankType::Character)
return;
Item* item = _player->GetItemByPos(packet.Bag, packet.Slot);
if (!item)
return;
ItemPosCountVec dest;
InventoryResult msg = _player->CanBankItem(NULL_BAG, NULL_SLOT, dest, item, false);
if (msg != EQUIP_ERR_OK)
{
_player->SendEquipError(msg, item, nullptr);
return;
}
if (dest.size() == 1 && dest[0].pos == item->GetPos())
{
_player->SendEquipError(EQUIP_ERR_CANT_SWAP, item, nullptr);
return;
}
_player->RemoveItem(packet.Bag, packet.Slot, true);
_player->ItemRemovedQuestCheck(item->GetEntry(), item->GetCount());
_player->BankItem(dest, item, true);
}
void WorldSession::HandleBankerActivateOpcode(WorldPackets::Bank::BankerActivate const& bankerActivate)
{
if (bankerActivate.InteractionType != PlayerInteractionType::Banker)
return;
Creature* unit = GetPlayer()->GetNPCIfCanInteractWith(bankerActivate.Banker, UNIT_NPC_FLAG_ACCOUNT_BANKER | UNIT_NPC_FLAG_BANKER, UNIT_NPC_FLAG_2_NONE);
if (!unit)
{
TC_LOG_ERROR("network", "WORLD: HandleBankerActivateOpcode - {} not found or you can not interact with him.", bankerActivate.Banker);
return;
}
switch (bankerActivate.InteractionType)
{
case PlayerInteractionType::Banker:
if (!unit->HasNpcFlag(UNIT_NPC_FLAG_ACCOUNT_BANKER | UNIT_NPC_FLAG_BANKER)) // Classic only - the banker check has been adjusted
return;
break;
case PlayerInteractionType::CharacterBanker:
if (!unit->HasNpcFlag(UNIT_NPC_FLAG_BANKER))
return;
break;
case PlayerInteractionType::AccountBanker:
if (!unit->HasNpcFlag(UNIT_NPC_FLAG_ACCOUNT_BANKER))
return;
break;
default:
break;
}
// remove fake death
if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
// set currentBankerGUID for other bank action
SendShowBank(bankerActivate.Banker, bankerActivate.InteractionType);
}
void WorldSession::HandleAutoStoreBankItemOpcode(WorldPackets::Bank::AutoStoreBankItem& packet)
{
TC_LOG_DEBUG("network", "STORAGE: receive bag = {}, slot = {}", packet.Bag, packet.Slot);
if (!CanUseBank())
{
TC_LOG_ERROR("network", "WORLD: HandleAutoStoreBankItemOpcode - Unit ({}) not found or you can't interact with him.", _player->PlayerTalkClass->GetInteractionData().SourceGuid.ToString());
return;
}
Item* item = _player->GetItemByPos(packet.Bag, packet.Slot);
if (!item)
return;
if (_player->IsBankPos(packet.Bag, packet.Slot)) // moving from bank to inventory
{
ItemPosCountVec dest;
InventoryResult msg = _player->CanStoreItem(NULL_BAG, NULL_SLOT, dest, item, false);
if (msg != EQUIP_ERR_OK)
{
_player->SendEquipError(msg, item, nullptr);
return;
}
_player->RemoveItem(packet.Bag, packet.Slot, true);
if (Item const* storedItem = _player->StoreItem(dest, item, true))
_player->ItemAddedQuestCheck(storedItem->GetEntry(), storedItem->GetCount());
}
else // moving from inventory to bank
{
ItemPosCountVec dest;
InventoryResult msg = _player->CanBankItem(NULL_BAG, NULL_SLOT, dest, item, false);
if (msg != EQUIP_ERR_OK)
{
_player->SendEquipError(msg, item, nullptr);
return;
}
_player->RemoveItem(packet.Bag, packet.Slot, true);
_player->BankItem(dest, item, true);
}
}
void WorldSession::HandleBuyBankSlotOpcode(WorldPackets::Bank::BuyBankSlot& packet)
{
if (!CanUseBank(packet.Guid))
{
TC_LOG_ERROR("network", "WORLD: HandleBuyBankSlotOpcode - {} not found or you can't interact with him.", packet.Guid.ToString());
return;
}
uint32 slot = _player->GetBankBagSlotCount();
// next slot
++slot;
TC_LOG_INFO("network", "PLAYER: Buy bank bag slot, slot number = {}", slot);
BankBagSlotPricesEntry const* slotEntry = sBankBagSlotPricesStore.LookupEntry(slot);
if (!slotEntry)
return;
uint32 price = slotEntry->Cost;
if (!_player->HasEnoughMoney(uint64(price)))
return;
_player->SetBankBagSlotCount(slot);
_player->ModifyMoney(-int64(price));
_player->UpdateCriteria(CriteriaType::BankSlotsPurchased);
}
void WorldSession::SendShowBank(ObjectGuid guid, PlayerInteractionType interactionType)
{
_player->PlayerTalkClass->GetInteractionData().Reset();
_player->PlayerTalkClass->GetInteractionData().SourceGuid = guid;
WorldPackets::NPC::NPCInteractionOpenResult npcInteraction;
npcInteraction.Npc = guid;
npcInteraction.InteractionType = interactionType;
npcInteraction.Success = true;
SendPacket(npcInteraction.Write());
}
|