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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
|
/*
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* 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 "Common.h"
#include "Log.h"
#include "Corpse.h"
#include "Creature.h"
#include "GameObject.h"
#include "Group.h"
#include "GuildMgr.h"
#include "LootMgr.h"
#include "ObjectAccessor.h"
#include "Object.h"
#include "Player.h"
#include "WorldPacket.h"
#include "LootPackets.h"
#include "WorldSession.h"
void WorldSession::HandleAutostoreLootItemOpcode(WorldPackets::Loot::LootItem& packet)
{
Player* player = GetPlayer();
ObjectGuid lguid = player->GetLootGUID();
/// @todo Implement looting by LootObject guid
for (WorldPackets::Loot::LootRequest const& req : packet.Loot)
{
Loot* loot = NULL;
if (lguid.IsGameObject())
{
GameObject* go = player->GetMap()->GetGameObject(lguid);
// not check distance for GO in case owned GO (fishing bobber case, for example) or Fishing hole GO
if (!go || ((go->GetOwnerGUID() != _player->GetGUID() && go->GetGoType() != GAMEOBJECT_TYPE_FISHINGHOLE) && !go->IsWithinDistInMap(_player, INTERACTION_DISTANCE)))
{
player->SendLootRelease(lguid);
continue;
}
loot = &go->loot;
}
else if (lguid.IsItem())
{
Item* pItem = player->GetItemByGuid(lguid);
if (!pItem)
{
player->SendLootRelease(lguid);
continue;
}
loot = &pItem->loot;
}
else if (lguid.IsCorpse())
{
Corpse* bones = ObjectAccessor::GetCorpse(*player, lguid);
if (!bones)
{
player->SendLootRelease(lguid);
continue;
}
loot = &bones->loot;
}
else
{
Creature* creature = GetPlayer()->GetMap()->GetCreature(lguid);
bool lootAllowed = creature && creature->IsAlive() == (player->getClass() == CLASS_ROGUE && creature->loot.loot_type == LOOT_PICKPOCKETING);
if (!lootAllowed || !creature->IsWithinDistInMap(_player, INTERACTION_DISTANCE))
{
player->SendLootError(lguid, lootAllowed ? LOOT_ERROR_TOO_FAR : LOOT_ERROR_DIDNT_KILL);
continue;
}
loot = &creature->loot;
}
// Since 6.x client sends loot starting from 1 hence the -1
player->StoreLootItem(req.LootListID-1, loot);
// If player is removing the last LootItem, delete the empty container.
if (loot->isLooted() && lguid.IsItem())
player->GetSession()->DoLootRelease(lguid);
}
}
void WorldSession::HandleLootMoneyOpcode(WorldPackets::Loot::LootMoney& /*packet*/)
{
Player* player = GetPlayer();
ObjectGuid guid = player->GetLootGUID();
if (!guid)
return;
Loot* loot = NULL;
bool shareMoney = true;
switch (guid.GetHigh())
{
case HighGuid::GameObject:
{
GameObject* go = GetPlayer()->GetMap()->GetGameObject(guid);
// do not check distance for GO if player is the owner of it (ex. fishing bobber)
if (go && ((go->GetOwnerGUID() == player->GetGUID() || go->IsWithinDistInMap(player, INTERACTION_DISTANCE))))
loot = &go->loot;
break;
}
case HighGuid::Corpse: // remove insignia ONLY in BG
{
Corpse* bones = ObjectAccessor::GetCorpse(*player, guid);
if (bones && bones->IsWithinDistInMap(player, INTERACTION_DISTANCE))
{
loot = &bones->loot;
shareMoney = false;
}
break;
}
case HighGuid::Item:
{
if (Item* item = player->GetItemByGuid(guid))
{
loot = &item->loot;
shareMoney = false;
}
break;
}
case HighGuid::Creature:
case HighGuid::Vehicle:
{
Creature* creature = player->GetMap()->GetCreature(guid);
bool lootAllowed = creature && creature->IsAlive() == (player->getClass() == CLASS_ROGUE && creature->loot.loot_type == LOOT_PICKPOCKETING);
if (lootAllowed && creature->IsWithinDistInMap(player, INTERACTION_DISTANCE))
{
loot = &creature->loot;
if (creature->IsAlive())
shareMoney = false;
}
else
player->SendLootError(guid, lootAllowed ? LOOT_ERROR_TOO_FAR : LOOT_ERROR_DIDNT_KILL);
break;
}
default:
return; // unlootable type
}
if (loot)
{
loot->NotifyMoneyRemoved();
if (shareMoney && player->GetGroup()) //item, pickpocket and players can be looted only single player
{
Group* group = player->GetGroup();
std::vector<Player*> playersNear;
for (GroupReference* itr = group->GetFirstMember(); itr != NULL; itr = itr->next())
{
Player* member = itr->GetSource();
if (!member)
continue;
if (player->IsAtGroupRewardDistance(member))
playersNear.push_back(member);
}
uint32 goldPerPlayer = uint32((loot->gold) / (playersNear.size()));
for (std::vector<Player*>::const_iterator i = playersNear.begin(); i != playersNear.end(); ++i)
{
(*i)->ModifyMoney(goldPerPlayer);
(*i)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LOOT_MONEY, goldPerPlayer);
if (Guild* guild = sGuildMgr->GetGuildById((*i)->GetGuildId()))
if (uint32 guildGold = CalculatePct(goldPerPlayer, (*i)->GetTotalAuraModifier(SPELL_AURA_DEPOSIT_BONUS_MONEY_IN_GUILD_BANK_ON_LOOT)))
guild->HandleMemberDepositMoney(this, guildGold, true);
WorldPackets::Loot::LootMoneyNotify packet;
packet.Money = goldPerPlayer;
packet.SoleLooter = playersNear.size() <= 1 ? true : false;
(*i)->SendDirectMessage(packet.Write());
}
}
else
{
player->ModifyMoney(loot->gold);
player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LOOT_MONEY, loot->gold);
if (Guild* guild = sGuildMgr->GetGuildById(player->GetGuildId()))
if (uint32 guildGold = CalculatePct(loot->gold, player->GetTotalAuraModifier(SPELL_AURA_DEPOSIT_BONUS_MONEY_IN_GUILD_BANK_ON_LOOT)))
guild->HandleMemberDepositMoney(this, guildGold, true);
WorldPackets::Loot::LootMoneyNotify packet;
packet.Money = loot->gold;
packet.SoleLooter = true; // "You loot..."
SendPacket(packet.Write());
}
loot->gold = 0;
// Delete the money loot record from the DB
if (!loot->containerID.IsEmpty())
loot->DeleteLootMoneyFromContainerItemDB();
// Delete container if empty
if (loot->isLooted() && guid.IsItem())
player->GetSession()->DoLootRelease(guid);
}
}
void WorldSession::HandleLootOpcode(WorldPackets::Loot::LootUnit& packet)
{
// Check possible cheat
if (!GetPlayer()->IsAlive() || !packet.Unit.IsCreatureOrVehicle())
return;
GetPlayer()->SendLoot(packet.Unit, LOOT_CORPSE);
// interrupt cast
if (GetPlayer()->IsNonMeleeSpellCast(false))
GetPlayer()->InterruptNonMeleeSpells(false);
}
void WorldSession::HandleLootReleaseOpcode(WorldPackets::Loot::LootRelease& packet)
{
// cheaters can modify lguid to prevent correct apply loot release code and re-loot
// use internal stored guid
ObjectGuid lguid = GetPlayer()->GetLootGUID();
if (!lguid.IsEmpty())
if (lguid == packet.Unit)
DoLootRelease(lguid);
}
void WorldSession::DoLootRelease(ObjectGuid lguid)
{
Player *player = GetPlayer();
Loot *loot;
player->SetLootGUID(ObjectGuid::Empty);
player->SendLootRelease(lguid);
player->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_LOOTING);
if (!player->IsInWorld())
return;
if (lguid.IsGameObject())
{
GameObject* go = GetPlayer()->GetMap()->GetGameObject(lguid);
// not check distance for GO in case owned GO (fishing bobber case, for example) or Fishing hole GO
if (!go || ((go->GetOwnerGUID() != _player->GetGUID() && go->GetGoType() != GAMEOBJECT_TYPE_FISHINGHOLE) && !go->IsWithinDistInMap(_player, INTERACTION_DISTANCE)))
return;
loot = &go->loot;
if (go->GetGoType() == GAMEOBJECT_TYPE_DOOR)
{
// locked doors are opened with spelleffect openlock, prevent remove its as looted
go->UseDoorOrButton();
}
else if (loot->isLooted() || go->GetGoType() == GAMEOBJECT_TYPE_FISHINGNODE)
{
if (go->GetGoType() == GAMEOBJECT_TYPE_FISHINGHOLE)
{ // The fishing hole used once more
go->AddUse(); // if the max usage is reached, will be despawned in next tick
if (go->GetUseCount() >= go->GetGOValue()->FishingHole.MaxOpens)
go->SetLootState(GO_JUST_DEACTIVATED);
else
go->SetLootState(GO_READY);
}
else
go->SetLootState(GO_JUST_DEACTIVATED);
loot->clear();
}
else
{
// not fully looted object
go->SetLootState(GO_ACTIVATED, player);
// if the round robin player release, reset it.
if (player->GetGUID() == loot->roundRobinPlayer)
loot->roundRobinPlayer.Clear();
}
}
else if (lguid.IsCorpse()) // ONLY remove insignia at BG
{
Corpse* corpse = ObjectAccessor::GetCorpse(*player, lguid);
if (!corpse || !corpse->IsWithinDistInMap(_player, INTERACTION_DISTANCE))
return;
loot = &corpse->loot;
if (loot->isLooted())
{
loot->clear();
corpse->RemoveFlag(CORPSE_FIELD_DYNAMIC_FLAGS, CORPSE_DYNFLAG_LOOTABLE);
}
}
else if (lguid.IsItem())
{
Item* pItem = player->GetItemByGuid(lguid);
if (!pItem)
return;
ItemTemplate const* proto = pItem->GetTemplate();
// destroy only 5 items from stack in case prospecting and milling
if (proto->GetFlags() & (ITEM_FLAG_PROSPECTABLE | ITEM_FLAG_MILLABLE))
{
pItem->m_lootGenerated = false;
pItem->loot.clear();
uint32 count = pItem->GetCount();
// >=5 checked in spell code, but will work for cheating cases also with removing from another stacks.
if (count > 5)
count = 5;
player->DestroyItemCount(pItem, count, true);
}
else
{
// Only delete item if no loot or money (unlooted loot is saved to db) or if it isn't an openable item
if (pItem->loot.isLooted() || !(proto->GetFlags() & ITEM_FLAG_OPENABLE))
player->DestroyItem(pItem->GetBagSlot(), pItem->GetSlot(), true);
}
return; // item can be looted only single player
}
else
{
Creature* creature = GetPlayer()->GetMap()->GetCreature(lguid);
bool lootAllowed = creature && creature->IsAlive() == (player->getClass() == CLASS_ROGUE && creature->loot.loot_type == LOOT_PICKPOCKETING);
if (!lootAllowed || !creature->IsWithinDistInMap(_player, INTERACTION_DISTANCE))
return;
loot = &creature->loot;
if (loot->isLooted())
{
creature->RemoveFlag(OBJECT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE);
// skip pickpocketing loot for speed, skinning timer reduction is no-op in fact
if (!creature->IsAlive())
creature->AllLootRemovedFromCorpse();
loot->clear();
}
else
{
// if the round robin player release, reset it.
if (player->GetGUID() == loot->roundRobinPlayer)
{
loot->roundRobinPlayer.Clear();
if (Group* group = player->GetGroup())
{
group->SendLooter(creature, NULL);
// force update of dynamic flags, otherwise other group's players still not able to loot.
creature->ForceValuesUpdateAtIndex(OBJECT_DYNAMIC_FLAGS);
}
}
}
}
//Player is not looking at loot list, he doesn't need to see updates on the loot list
loot->RemoveLooter(player->GetGUID());
}
void WorldSession::HandleLootMasterGiveOpcode(WorldPacket& recvData)
{
uint8 slotid;
ObjectGuid lootguid, target_playerguid;
recvData >> lootguid >> slotid >> target_playerguid;
if (!_player->GetGroup() || _player->GetGroup()->GetMasterLooterGuid() != _player->GetGUID() || _player->GetGroup()->GetLootMethod() != MASTER_LOOT)
{
_player->SendLootError(lootguid, LOOT_ERROR_DIDNT_KILL);
return;
}
Player* target = ObjectAccessor::FindPlayer(target_playerguid);
if (!target)
{
_player->SendLootError(lootguid, LOOT_ERROR_PLAYER_NOT_FOUND);
return;
}
TC_LOG_DEBUG("network", "WorldSession::HandleLootMasterGiveOpcode (CMSG_LOOT_MASTER_GIVE, 0x02A3) Target = [%s].", target->GetName().c_str());
if (_player->GetLootGUID() != lootguid)
{
_player->SendLootError(lootguid, LOOT_ERROR_DIDNT_KILL);
return;
}
if (!_player->IsInRaidWith(target) || !_player->IsInMap(target))
{
_player->SendLootError(lootguid, LOOT_ERROR_MASTER_OTHER);
TC_LOG_INFO("loot", "MasterLootItem: Player %s tried to give an item to ineligible player %s !", GetPlayer()->GetName().c_str(), target->GetName().c_str());
return;
}
Loot* loot = NULL;
if (GetPlayer()->GetLootGUID().IsCreatureOrVehicle())
{
Creature* creature = GetPlayer()->GetMap()->GetCreature(lootguid);
if (!creature)
return;
loot = &creature->loot;
}
else if (GetPlayer()->GetLootGUID().IsGameObject())
{
GameObject* pGO = GetPlayer()->GetMap()->GetGameObject(lootguid);
if (!pGO)
return;
loot = &pGO->loot;
}
if (!loot)
return;
if (slotid >= loot->items.size() + loot->quest_items.size())
{
TC_LOG_DEBUG("loot", "MasterLootItem: Player %s might be using a hack! (slot %d, size %lu)",
GetPlayer()->GetName().c_str(), slotid, (unsigned long)loot->items.size());
return;
}
LootItem& item = slotid >= loot->items.size() ? loot->quest_items[slotid - loot->items.size()] : loot->items[slotid];
ItemPosCountVec dest;
InventoryResult msg = target->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, item.itemid, item.count);
if (item.follow_loot_rules && !item.AllowedForPlayer(target))
msg = EQUIP_ERR_CANT_EQUIP_EVER;
if (msg != EQUIP_ERR_OK)
{
if (msg == EQUIP_ERR_ITEM_MAX_COUNT)
_player->SendLootError(lootguid, LOOT_ERROR_MASTER_UNIQUE_ITEM);
else if (msg == EQUIP_ERR_INV_FULL)
_player->SendLootError(lootguid, LOOT_ERROR_MASTER_INV_FULL);
else
_player->SendLootError(lootguid, LOOT_ERROR_MASTER_OTHER);
target->SendEquipError(msg, NULL, NULL, item.itemid);
return;
}
// now move item from loot to target inventory
Item* newitem = target->StoreNewItem(dest, item.itemid, true, item.randomPropertyId, item.GetAllowedLooters(), item.BonusListIDs);
target->SendNewItem(newitem, uint32(item.count), false, false, true);
target->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LOOT_ITEM, item.itemid, item.count);
target->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LOOT_TYPE, item.itemid, item.count, loot->loot_type);
target->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LOOT_EPIC_ITEM, item.itemid, item.count);
// mark as looted
item.count = 0;
item.is_looted = true;
loot->NotifyItemRemoved(slotid);
--loot->unlootedCount;
}
void WorldSession::HandleSetLootSpecialization(WorldPackets::Loot::SetLootSpecialization& packet)
{
if (packet.SpecID)
{
if (ChrSpecializationEntry const* chrSpec = sChrSpecializationStore.LookupEntry(packet.SpecID))
{
if (chrSpec->ClassID == GetPlayer()->getClass())
GetPlayer()->SetLootSpecId(packet.SpecID);
}
}
else
GetPlayer()->SetLootSpecId(packet.SpecID);
}
|