aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/server/game/Entities/Player/Player.cpp165
-rw-r--r--src/server/game/Entities/Player/Player.h1
-rw-r--r--src/server/game/Entities/Unit/Unit.cpp4
-rw-r--r--src/server/game/Spells/Auras/SpellAuraEffects.cpp33
4 files changed, 90 insertions, 113 deletions
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index 907532833bd..a0d830ff7e8 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -19568,6 +19568,68 @@ void Player::InitDisplayIds()
}
}
+inline bool Player::_StoreOrEquipNewItem(uint32 vendorslot, uint32 item, uint8 count, uint8 bag, uint8 slot, int32 price, ItemPrototype const *pProto, Creature *pVendor, VendorItem const* crItem, bool bStore)
+{
+ ItemPosCountVec vDest;
+ uint16 uiDest;
+ uint8 msg = bStore ?
+ CanStoreNewItem(bag, slot, vDest, item, pProto->BuyCount * count) :
+ CanEquipNewItem(slot, uiDest, item, false);
+ if (msg != EQUIP_ERR_OK)
+ {
+ SendEquipError(msg, NULL, NULL, item);
+ return false;
+ }
+
+ ModifyMoney(-price);
+
+ if (crItem->ExtendedCost) // case for new honor system
+ {
+ ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(crItem->ExtendedCost);
+ if (iece->reqhonorpoints)
+ ModifyHonorPoints(- int32(iece->reqhonorpoints * count));
+
+ if (iece->reqarenapoints)
+ ModifyArenaPoints(- int32(iece->reqarenapoints * count));
+
+ for (uint8 i = 0; i < 5; ++i)
+ {
+ if (iece->reqitem[i])
+ DestroyItemCount(iece->reqitem[i], (iece->reqitemcount[i] * count), true);
+ }
+ }
+
+ Item* it = bStore ?
+ StoreNewItem(vDest, item, true) :
+ EquipNewItem(uiDest, item, true);
+ if (it)
+ {
+ uint32 new_count = pVendor->UpdateVendorItemCurrentCount(crItem,pProto->BuyCount * count);
+
+ WorldPacket data(SMSG_BUY_ITEM, (8+4+4+4));
+ data << uint64(pVendor->GetGUID());
+ data << uint32(vendorslot + 1); // numbered from 1 at client
+ data << int32(crItem->maxcount > 0 ? new_count : 0xFFFFFFFF);
+ data << uint32(count);
+ GetSession()->SendPacket(&data);
+ SendNewItem(it, pProto->BuyCount * count, true, false, false);
+
+ if (!bStore)
+ AutoUnequipOffhandIfNeed();
+
+ if (pProto->Flags & ITEM_PROTO_FLAG_REFUNDABLE && crItem->ExtendedCost && pProto->GetMaxStackSize() == 1)
+ {
+ it->SetFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_REFUNDABLE);
+ it->SetRefundRecipient(GetGUIDLow());
+ it->SetPaidMoney(price);
+ it->SetPaidExtendedCost(crItem->ExtendedCost);
+ it->SaveRefundDataToDB();
+ AddRefundReference(it->GetGUIDLow());
+ }
+ }
+ return true;
+}
+
// Return true is the bought item has a max count to force refresh of window by caller
bool Player::BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32 item, uint8 count, uint8 bag, uint8 slot)
{
@@ -19605,13 +19667,13 @@ bool Player::BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32
if (vendorslot >= vItems->GetItemCount())
{
- SendBuyError( BUY_ERR_CANT_FIND_ITEM, pCreature, item, 0);
+ SendBuyError(BUY_ERR_CANT_FIND_ITEM, pCreature, item, 0);
return false;
}
VendorItem const* crItem = vItems->GetItem(vendorslot);
// store diff item (cheating)
- if(!crItem || crItem->item != item)
+ if (!crItem || crItem->item != item)
{
SendBuyError(BUY_ERR_CANT_FIND_ITEM, pCreature, item, 0);
return false;
@@ -19689,54 +19751,8 @@ bool Player::BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32
if ((bag == NULL_BAG && slot == NULL_SLOT) || IsInventoryPos(bag, slot))
{
- ItemPosCountVec dest;
- uint8 msg = CanStoreNewItem(bag, slot, dest, item, pProto->BuyCount * count);
- if (msg != EQUIP_ERR_OK)
- {
- SendEquipError(msg, NULL, NULL, item);
+ if (!_StoreOrEquipNewItem(vendorslot, item, count, bag, slot, price, pProto, pCreature, crItem, true))
return false;
- }
-
- ModifyMoney(-(int32)price);
-
- if (crItem->ExtendedCost) // case for new honor system
- {
- ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(crItem->ExtendedCost);
- if (iece->reqhonorpoints)
- ModifyHonorPoints(- int32(iece->reqhonorpoints * count));
-
- if (iece->reqarenapoints)
- ModifyArenaPoints(- int32(iece->reqarenapoints * count));
-
- for (uint8 i = 0; i < 5; ++i)
- {
- if (iece->reqitem[i])
- DestroyItemCount(iece->reqitem[i], (iece->reqitemcount[i] * count), true);
- }
- }
-
- if (Item *it = StoreNewItem(dest, item, true))
- {
- uint32 new_count = pCreature->UpdateVendorItemCurrentCount(crItem,pProto->BuyCount * count);
-
- WorldPacket data(SMSG_BUY_ITEM, (8+4+4+4));
- data << uint64(pCreature->GetGUID());
- data << uint32(vendorslot+1); // numbered from 1 at client
- data << int32(crItem->maxcount > 0 ? new_count : 0xFFFFFFFF);
- data << uint32(count);
- GetSession()->SendPacket(&data);
- SendNewItem(it, pProto->BuyCount*count, true, false, false);
-
- if (pProto->Flags & ITEM_PROTO_FLAG_REFUNDABLE && crItem->ExtendedCost && pProto->GetMaxStackSize() == 1)
- {
- it->SetFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_REFUNDABLE);
- it->SetRefundRecipient(GetGUIDLow());
- it->SetPaidMoney(price);
- it->SetPaidExtendedCost(crItem->ExtendedCost);
- it->SaveRefundDataToDB();
- AddRefundReference(it->GetGUIDLow());
- }
- }
}
else if (IsEquipmentPos(bag, slot))
{
@@ -19745,57 +19761,8 @@ bool Player::BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32
SendEquipError(EQUIP_ERR_ITEM_CANT_BE_EQUIPPED, NULL, NULL);
return false;
}
-
- uint16 dest;
- uint8 msg = CanEquipNewItem(slot, dest, item, false);
- if (msg != EQUIP_ERR_OK)
- {
- SendEquipError(msg, NULL, NULL, item);
+ if (!_StoreOrEquipNewItem(vendorslot, item, count, bag, slot, price, pProto, pCreature, crItem, false))
return false;
- }
-
- ModifyMoney(-(int32)price);
- if (crItem->ExtendedCost) // case for new honor system
- {
- ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(crItem->ExtendedCost);
- if (iece->reqhonorpoints)
- ModifyHonorPoints(- int32(iece->reqhonorpoints * count));
-
- if (iece->reqarenapoints)
- ModifyArenaPoints(- int32(iece->reqarenapoints * count));
-
- for (uint8 i = 0; i < 5; ++i)
- {
- if (iece->reqitem[i])
- DestroyItemCount(iece->reqitem[i], iece->reqitemcount[i] * count, true);
- }
- }
-
- if (Item *it = EquipNewItem(dest, item, true))
- {
- uint32 new_count = pCreature->UpdateVendorItemCurrentCount(crItem,pProto->BuyCount * count);
-
- WorldPacket data(SMSG_BUY_ITEM, (8+4+4+4));
- data << uint64(pCreature->GetGUID());
- data << uint32(vendorslot + 1); // numbered from 1 at client
- data << int32(crItem->maxcount > 0 ? new_count : 0xFFFFFFFF);
- data << uint32(count);
- GetSession()->SendPacket(&data);
-
- SendNewItem(it, pProto->BuyCount*count, true, false, false);
-
- AutoUnequipOffhandIfNeed();
-
- if (pProto->Flags & ITEM_PROTO_FLAG_REFUNDABLE && crItem->ExtendedCost && pProto->GetMaxStackSize() == 1)
- {
- it->SetFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_REFUNDABLE);
- it->SetRefundRecipient(GetGUIDLow());
- it->SetPaidMoney(price);
- it->SetPaidExtendedCost(crItem->ExtendedCost);
- it->SaveRefundDataToDB();
- AddRefundReference(it->GetGUIDLow());
- }
- }
}
else
{
diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h
index 66ba48fee8b..d1a8514c6b9 100644
--- a/src/server/game/Entities/Player/Player.h
+++ b/src/server/game/Entities/Player/Player.h
@@ -1247,6 +1247,7 @@ class Player : public Unit, public GridObject<Player>
}
void SendNewItem(Item *item, uint32 count, bool received, bool created, bool broadcast = false);
bool BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32 item, uint8 count, uint8 bag, uint8 slot);
+ bool _StoreOrEquipNewItem(uint32 vendorslot, uint32 item, uint8 count, uint8 bag, uint8 slot, int32 price, ItemPrototype const *pProto, Creature *pVendor, VendorItem const* crItem, bool bStore);
float GetReputationPriceDiscount(Creature const* pCreature) const;
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp
index 5110330c7a7..9aefb5225f5 100644
--- a/src/server/game/Entities/Unit/Unit.cpp
+++ b/src/server/game/Entities/Unit/Unit.cpp
@@ -15409,8 +15409,8 @@ bool Unit::SetCharmedBy(Unit* charmer, CharmType type)
}
// Set charmed
- Map* pMap = GetMap();
- if (!IsVehicle() || (IsVehicle() && pMap && !pMap->IsBattleground()))
+ Map* pMap = GetMap();
+ if (!IsVehicle() || (IsVehicle() && pMap && !pMap->IsBattleground()))
setFaction(charmer->getFaction());
charmer->SetCharm(this, true);
diff --git a/src/server/game/Spells/Auras/SpellAuraEffects.cpp b/src/server/game/Spells/Auras/SpellAuraEffects.cpp
index 3ac1fef62c9..fcde15bb9fa 100644
--- a/src/server/game/Spells/Auras/SpellAuraEffects.cpp
+++ b/src/server/game/Spells/Auras/SpellAuraEffects.cpp
@@ -3923,9 +3923,7 @@ void AuraEffect::HandleModPossessPet(AuraApplication const * aurApp, uint8 mode,
if (!(mode & AURA_EFFECT_HANDLE_REAL))
return;
- Unit * target = aurApp->GetTarget();
-
- Unit * caster = GetCaster();
+ Unit* caster = GetCaster();
if (!caster || caster->GetTypeId() != TYPEID_PLAYER)
return;
@@ -3933,24 +3931,35 @@ void AuraEffect::HandleModPossessPet(AuraApplication const * aurApp, uint8 mode,
//if (caster->ToPlayer()->GetPet() != target)
// return;
+ Unit* target = aurApp->GetTarget();
+ if (target->GetTypeId() != TYPEID_UNIT || !target->ToCreature()->isPet())
+ return;
+
+ Pet* pet = target->ToPet();
+
if (apply)
{
- if (caster->ToPlayer()->GetPet() != target)
+ if (caster->ToPlayer()->GetPet() != pet)
return;
- target->SetCharmedBy(caster, CHARM_TYPE_POSSESS);
+ pet->SetCharmedBy(caster, CHARM_TYPE_POSSESS);
}
else
{
- target->RemoveCharmedBy(caster);
+ pet->RemoveCharmedBy(caster);
- // Reinitialize the pet bar and make the pet come back to the owner
- caster->ToPlayer()->PetSpellInitialize();
- if (!target->getVictim())
+ if (!pet->IsWithinDistInMap(caster, pet->GetMap()->GetVisibilityDistance()))
+ pet->Remove(PET_SAVE_NOT_IN_SLOT, true);
+ else
{
- target->GetMotionMaster()->MoveFollow(caster, PET_FOLLOW_DIST, target->GetFollowAngle());
- //if (target->GetCharmInfo())
- // target->GetCharmInfo()->SetCommandState(COMMAND_FOLLOW);
+ // Reinitialize the pet bar and make the pet come back to the owner
+ caster->ToPlayer()->PetSpellInitialize();
+ if (!pet->getVictim())
+ {
+ pet->GetMotionMaster()->MoveFollow(caster, PET_FOLLOW_DIST, pet->GetFollowAngle());
+ //if (target->GetCharmInfo())
+ // target->GetCharmInfo()->SetCommandState(COMMAND_FOLLOW);
+ }
}
}
}