* Unsummon pet if direct control spell expire out of visibility range from owner (base on VladimirMangos changes)

* Move repeating code to separate method

--HG--
branch : trunk
This commit is contained in:
azazel
2010-08-12 12:14:32 +06:00
parent c7b48c1ca9
commit c6b4309f1e
4 changed files with 90 additions and 113 deletions
+66 -99
View File
@@ -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,55 +19751,9 @@ 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))
{
if (pProto->BuyCount * count != 1)
@@ -19745,58 +19761,9 @@ 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
{
SendEquipError(EQUIP_ERR_ITEM_DOESNT_GO_TO_SLOT, NULL, NULL);
+1
View File
@@ -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;
@@ -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,26 +3931,37 @@ void AuraEffect::HandleModPossessPet(AuraApplication const * aurApp, uint8 mode,
//if (caster->ToPlayer()->GetPet() != target)
// return;
if (apply)
{
if (caster->ToPlayer()->GetPet() != target)
Unit* target = aurApp->GetTarget();
if (target->GetTypeId() != TYPEID_UNIT || !target->ToCreature()->isPet())
return;
target->SetCharmedBy(caster, CHARM_TYPE_POSSESS);
Pet* pet = target->ToPet();
if (apply)
{
if (caster->ToPlayer()->GetPet() != pet)
return;
pet->SetCharmedBy(caster, CHARM_TYPE_POSSESS);
}
else
{
target->RemoveCharmedBy(caster);
pet->RemoveCharmedBy(caster);
if (!pet->IsWithinDistInMap(caster, pet->GetMap()->GetVisibilityDistance()))
pet->Remove(PET_SAVE_NOT_IN_SLOT, true);
else
{
// Reinitialize the pet bar and make the pet come back to the owner
caster->ToPlayer()->PetSpellInitialize();
if (!target->getVictim())
if (!pet->getVictim())
{
target->GetMotionMaster()->MoveFollow(caster, PET_FOLLOW_DIST, target->GetFollowAngle());
pet->GetMotionMaster()->MoveFollow(caster, PET_FOLLOW_DIST, pet->GetFollowAngle());
//if (target->GetCharmInfo())
// target->GetCharmInfo()->SetCommandState(COMMAND_FOLLOW);
}
}
}
}
void AuraEffect::HandleModCharm(AuraApplication const * aurApp, uint8 mode, bool apply) const