Fix socket gems

This commit is contained in:
Yaki Khadafi 2015-02-03 05:53:57 +00:00 committed by Antz
parent 87f092ed3d
commit 13316a27d1
5 changed files with 35 additions and 11 deletions

View file

@ -1063,12 +1063,23 @@ bool Item::IsTargetValidForItemUse(Unit* pUnitTarget)
return false; return false;
} }
void Item::SetEnchantment(EnchantmentSlot slot, uint32 id, uint32 duration, uint32 charges)
void Item::SetEnchantment(EnchantmentSlot slot, uint32 id, uint32 duration, uint32 charges, ObjectGuid casterGuid /*= ObjectGuid()*/)
{ {
// Better lost small time at check in comparison lost time at item save to DB. // Better lost small time at check in comparison lost time at item save to DB.
if ((GetEnchantmentId(slot) == id) && (GetEnchantmentDuration(slot) == duration) && (GetEnchantmentCharges(slot) == charges)) if ((GetEnchantmentId(slot) == id) && (GetEnchantmentDuration(slot) == duration) && (GetEnchantmentCharges(slot) == charges))
return; return;
if (slot < MAX_INSPECTED_ENCHANTMENT_SLOT)
{
Player* owner = GetOwner();
if (uint32 oldEnchant = GetEnchantmentId(slot))
owner->GetSession()->SendEnchantmentLog(GetOwnerGuid(), ObjectGuid(), GetEntry(), oldEnchant);
if (id)
owner->GetSession()->SendEnchantmentLog(GetOwnerGuid(), casterGuid, GetEntry(), id);
}
SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1 + slot * MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_ID_OFFSET, id); SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1 + slot * MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_ID_OFFSET, id);
SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1 + slot * MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_DURATION_OFFSET, duration); SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1 + slot * MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_DURATION_OFFSET, duration);
SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1 + slot * MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_CHARGES_OFFSET, charges); SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1 + slot * MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_CHARGES_OFFSET, charges);
@ -1103,6 +1114,16 @@ void Item::ClearEnchantment(EnchantmentSlot slot)
SetState(ITEM_CHANGED); SetState(ITEM_CHANGED);
} }
void Item::SendUpdateSockets()
{
WorldPacket data(SMSG_SOCKET_GEMS, 8 + 4 + 4 + 4 + 4);
data << GetObjectGuid();
for (uint32 i = SOCK_ENCHANTMENT_SLOT; i <= BONUS_ENCHANTMENT_SLOT; ++i)
data << uint32(GetEnchantmentId(EnchantmentSlot(i)));
GetOwner()->SendDirectMessage(&data);
}
bool Item::GemsFitSockets() const bool Item::GemsFitSockets() const
{ {
bool fits = true; bool fits = true;

View file

@ -346,13 +346,14 @@ class Item : public Object
void SetItemRandomProperties(int32 randomPropId); void SetItemRandomProperties(int32 randomPropId);
bool UpdateItemSuffixFactor(); bool UpdateItemSuffixFactor();
static int32 GenerateItemRandomPropertyId(uint32 item_id); static int32 GenerateItemRandomPropertyId(uint32 item_id);
void SetEnchantment(EnchantmentSlot slot, uint32 id, uint32 duration, uint32 charges); void SetEnchantment(EnchantmentSlot slot, uint32 id, uint32 duration, uint32 charges, ObjectGuid casterGuid = ObjectGuid());
void SetEnchantmentDuration(EnchantmentSlot slot, uint32 duration); void SetEnchantmentDuration(EnchantmentSlot slot, uint32 duration);
void SetEnchantmentCharges(EnchantmentSlot slot, uint32 charges); void SetEnchantmentCharges(EnchantmentSlot slot, uint32 charges);
void ClearEnchantment(EnchantmentSlot slot); void ClearEnchantment(EnchantmentSlot slot);
uint32 GetEnchantmentId(EnchantmentSlot slot) const { return GetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1 + slot * MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_ID_OFFSET);} uint32 GetEnchantmentId(EnchantmentSlot slot) const { return GetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1 + slot * MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_ID_OFFSET);}
uint32 GetEnchantmentDuration(EnchantmentSlot slot) const { return GetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1 + slot * MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_DURATION_OFFSET);} uint32 GetEnchantmentDuration(EnchantmentSlot slot) const { return GetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1 + slot * MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_DURATION_OFFSET);}
uint32 GetEnchantmentCharges(EnchantmentSlot slot) const { return GetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1 + slot * MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_CHARGES_OFFSET);} uint32 GetEnchantmentCharges(EnchantmentSlot slot) const { return GetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1 + slot * MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_CHARGES_OFFSET);}
void SendUpdateSockets();
std::string const& GetText() const { return m_text; } std::string const& GetText() const { return m_text; }
void SetText(std::string const& text) { m_text = text; } void SetText(std::string const& text) { m_text = text; }

View file

@ -376,7 +376,7 @@ class WorldSession
AuctionHouseEntry const* GetCheckedAuctionHouseForAuctioneer(ObjectGuid guid); AuctionHouseEntry const* GetCheckedAuctionHouseForAuctioneer(ObjectGuid guid);
// Item Enchantment // Item Enchantment
void SendEnchantmentLog(ObjectGuid targetGuid, ObjectGuid casterGuid, uint32 itemId, uint32 spellId); void SendEnchantmentLog(ObjectGuid targetGuid, ObjectGuid casterGuid, uint32 itemId, uint32 enchantId);
void SendItemEnchantTimeUpdate(ObjectGuid playerGuid, ObjectGuid itemGuid, uint32 slot, uint32 duration); void SendItemEnchantTimeUpdate(ObjectGuid playerGuid, ObjectGuid itemGuid, uint32 slot, uint32 duration);
// Taxi // Taxi

View file

@ -907,13 +907,13 @@ void WorldSession::HandleSetAmmoOpcode(WorldPacket& recv_data)
GetPlayer()->SetAmmo(item); GetPlayer()->SetAmmo(item);
} }
void WorldSession::SendEnchantmentLog(ObjectGuid targetGuid, ObjectGuid casterGuid, uint32 itemId, uint32 spellId) void WorldSession::SendEnchantmentLog(ObjectGuid targetGuid, ObjectGuid casterGuid, uint32 itemId, uint32 enchantId)
{ {
WorldPacket data(SMSG_ENCHANTMENTLOG, (8 + 8 + 4 + 4 + 1)); // last check 2.0.10 WorldPacket data(SMSG_ENCHANTMENTLOG, (8 + 8 + 4 + 4 + 1)); // last check 2.0.10
data << targetGuid.WriteAsPacked(); data << targetGuid.WriteAsPacked();
data << casterGuid.WriteAsPacked(); data << casterGuid.WriteAsPacked();
data << uint32(itemId); data << uint32(itemId);
data << uint32(spellId); data << uint32(enchantId);
SendPacket(&data); SendPacket(&data);
} }
@ -1225,7 +1225,7 @@ void WorldSession::HandleSocketOpcode(WorldPacket& recv_data)
if (GemEnchants[i]) if (GemEnchants[i])
{ {
uint32 count = 1; uint32 count = 1;
itemTarget->SetEnchantment(EnchantmentSlot(SOCK_ENCHANTMENT_SLOT + i), GemEnchants[i], 0, 0); itemTarget->SetEnchantment(EnchantmentSlot(SOCK_ENCHANTMENT_SLOT + i), GemEnchants[i], 0, 0, _player->GetObjectGuid());
if (Item* guidItem = gemGuids[i] ? _player->GetItemByGuid(gemGuids[i]) : NULL) if (Item* guidItem = gemGuids[i] ? _player->GetItemByGuid(gemGuids[i]) : NULL)
_player->DestroyItemCount(guidItem, count, true); _player->DestroyItemCount(guidItem, count, true);
} }
@ -1238,12 +1238,14 @@ void WorldSession::HandleSocketOpcode(WorldPacket& recv_data)
if (SocketBonusActivated != SocketBonusToBeActivated) // if there was a change... if (SocketBonusActivated != SocketBonusToBeActivated) // if there was a change...
{ {
_player->ApplyEnchantment(itemTarget, BONUS_ENCHANTMENT_SLOT, false); _player->ApplyEnchantment(itemTarget, BONUS_ENCHANTMENT_SLOT, false);
itemTarget->SetEnchantment(BONUS_ENCHANTMENT_SLOT, (SocketBonusToBeActivated ? itemTarget->GetProto()->socketBonus : 0), 0, 0); itemTarget->SetEnchantment(BONUS_ENCHANTMENT_SLOT, (SocketBonusToBeActivated ? itemTarget->GetProto()->socketBonus : 0), 0, 0, _player->GetObjectGuid());
_player->ApplyEnchantment(itemTarget, BONUS_ENCHANTMENT_SLOT, true); _player->ApplyEnchantment(itemTarget, BONUS_ENCHANTMENT_SLOT, true);
// it is not displayed, client has an inbuilt system to determine if the bonus is activated // it is not displayed, client has an inbuilt system to determine if the bonus is activated
} }
_player->ToggleMetaGemsActive(slot, true); // turn on all metagems (except for target item) _player->ToggleMetaGemsActive(slot, true); // turn on all metagems (except for target item)
itemTarget->SendUpdateSockets();
} }
void WorldSession::HandleCancelTempEnchantmentOpcode(WorldPacket& recv_data) void WorldSession::HandleCancelTempEnchantmentOpcode(WorldPacket& recv_data)

View file

@ -6159,7 +6159,7 @@ void Spell::EffectEnchantItemPerm(SpellEffectEntry const* effect)
// remove old enchanting before applying new if equipped // remove old enchanting before applying new if equipped
item_owner->ApplyEnchantment(itemTarget, PERM_ENCHANTMENT_SLOT, false); item_owner->ApplyEnchantment(itemTarget, PERM_ENCHANTMENT_SLOT, false);
itemTarget->SetEnchantment(PERM_ENCHANTMENT_SLOT, enchant_id, 0, 0); itemTarget->SetEnchantment(PERM_ENCHANTMENT_SLOT, enchant_id, 0, 0, m_caster->GetObjectGuid());
// add new enchanting if equipped // add new enchanting if equipped
item_owner->ApplyEnchantment(itemTarget, PERM_ENCHANTMENT_SLOT, true); item_owner->ApplyEnchantment(itemTarget, PERM_ENCHANTMENT_SLOT, true);
@ -6217,7 +6217,7 @@ void Spell::EffectEnchantItemPrismatic(SpellEffectEntry const* effect)
// remove old enchanting before applying new if equipped // remove old enchanting before applying new if equipped
item_owner->ApplyEnchantment(itemTarget, PRISMATIC_ENCHANTMENT_SLOT, false); item_owner->ApplyEnchantment(itemTarget, PRISMATIC_ENCHANTMENT_SLOT, false);
itemTarget->SetEnchantment(PRISMATIC_ENCHANTMENT_SLOT, enchant_id, 0, 0); itemTarget->SetEnchantment(PRISMATIC_ENCHANTMENT_SLOT, enchant_id, 0, 0, m_caster->GetObjectGuid());
// add new enchanting if equipped // add new enchanting if equipped
item_owner->ApplyEnchantment(itemTarget, PRISMATIC_ENCHANTMENT_SLOT, true); item_owner->ApplyEnchantment(itemTarget, PRISMATIC_ENCHANTMENT_SLOT, true);
@ -6335,7 +6335,7 @@ void Spell::EffectEnchantItemTmp(SpellEffectEntry const* effect)
// remove old enchanting before applying new if equipped // remove old enchanting before applying new if equipped
item_owner->ApplyEnchantment(itemTarget, TEMP_ENCHANTMENT_SLOT, false); item_owner->ApplyEnchantment(itemTarget, TEMP_ENCHANTMENT_SLOT, false);
itemTarget->SetEnchantment(TEMP_ENCHANTMENT_SLOT, enchant_id, duration * 1000, 0); itemTarget->SetEnchantment(TEMP_ENCHANTMENT_SLOT, enchant_id, duration * 1000, 0, m_caster->GetObjectGuid());
// add new enchanting if equipped // add new enchanting if equipped
item_owner->ApplyEnchantment(itemTarget, TEMP_ENCHANTMENT_SLOT, true); item_owner->ApplyEnchantment(itemTarget, TEMP_ENCHANTMENT_SLOT, true);
@ -9736,7 +9736,7 @@ void Spell::EffectEnchantHeldItem(SpellEffectEntry const* effect)
return; return;
// Apply the temporary enchantment // Apply the temporary enchantment
item->SetEnchantment(slot, enchant_id, duration * IN_MILLISECONDS, 0); item->SetEnchantment(slot, enchant_id, duration * IN_MILLISECONDS, 0, m_caster->GetObjectGuid());
item_owner->ApplyEnchantment(item, slot, true); item_owner->ApplyEnchantment(item, slot, true);
} }
} }