diff options
| author | Duarte Duarte <dnpd.dd@gmail.com> | 2015-02-12 02:37:42 +0000 |
|---|---|---|
| committer | Duarte Duarte <dnpd.dd@gmail.com> | 2015-02-12 02:37:42 +0000 |
| commit | 20aa605485a0772910766255a8e5e4ba2f2d92bc (patch) | |
| tree | 9dcde00afcaa7cb6638e0fb813ef48bc7ab8f8ff /src/server/game/Handlers/SpellHandler.cpp | |
| parent | 6678635cc7e4df00a265d19653dbbfc2ef5c8eec (diff) | |
Core/Packets: Update and enable CMSG_USE_ITEM
Ref #14115
Diffstat (limited to 'src/server/game/Handlers/SpellHandler.cpp')
| -rw-r--r-- | src/server/game/Handlers/SpellHandler.cpp | 116 |
1 files changed, 28 insertions, 88 deletions
diff --git a/src/server/game/Handlers/SpellHandler.cpp b/src/server/game/Handlers/SpellHandler.cpp index 25fe4df4dd7..3a173e4e582 100644 --- a/src/server/game/Handlers/SpellHandler.cpp +++ b/src/server/game/Handlers/SpellHandler.cpp @@ -38,121 +38,63 @@ #include "SpellPackets.h" #include "GameObjectPackets.h" -void WorldSession::HandleClientCastFlags(WorldPacket& recvPacket, uint8 castFlags, SpellCastTargets& targets) +void WorldSession::HandleUseItemOpcode(WorldPackets::Spells::UseItem& packet) { - // some spell cast packet including more data (for projectiles?) - if (castFlags & 0x02) - { - // not sure about these two - float elevation, speed; - recvPacket >> elevation; - recvPacket >> speed; - - targets.SetElevation(elevation); - targets.SetSpeed(speed); - - uint8 hasMovementData; - recvPacket >> hasMovementData; - //if (hasMovementData) - // HandleMovementOpcodes(recvPacket); - } - else if (castFlags & 0x8) // Archaeology - { - uint32 count, entry, usedCount; - uint8 type; - recvPacket >> count; - for (uint32 i = 0; i < count; ++i) - { - recvPacket >> type; - switch (type) - { - case 2: // Keystones - recvPacket >> entry; // Item id - recvPacket >> usedCount; // Item count - break; - case 1: // Fragments - recvPacket >> entry; // Currency id - recvPacket >> usedCount; // Currency count - break; - } - } - } -} - -void WorldSession::HandleUseItemOpcode(WorldPacket& recvPacket) -{ - /// @todo add targets.read() check - Player* pUser = _player; + Player* user = _player; // ignore for remote control state - if (pUser->m_mover != pUser) + if (user->m_mover != user) return; - uint8 bagIndex, slot, castFlags; - uint8 castCount; // next cast if exists (single or not) - ObjectGuid itemGUID; - uint32 glyphIndex; // something to do with glyphs? - uint32 spellId; // cast spell id - - recvPacket >> bagIndex >> slot >> castCount >> spellId >> itemGUID >> glyphIndex >> castFlags; - - if (glyphIndex >= MAX_GLYPH_SLOT_INDEX) - { - pUser->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL); - return; - } - - Item* pItem = pUser->GetUseableItemByPos(bagIndex, slot); - if (!pItem) + Item* item = user->GetUseableItemByPos(packet.PackSlot, packet.Slot); + if (!item) { - pUser->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL); + user->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL); return; } - if (pItem->GetGUID() != itemGUID) + if (item->GetGUID() != packet.CastItem) { - pUser->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL); + user->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL); return; } - TC_LOG_DEBUG("network", "WORLD: CMSG_USE_ITEM packet, bagIndex: %u, slot: %u, castCount: %u, spellId: %u, Item: %u, glyphIndex: %u, data length = %i", bagIndex, slot, castCount, spellId, pItem->GetEntry(), glyphIndex, (uint32)recvPacket.size()); - - ItemTemplate const* proto = pItem->GetTemplate(); + ItemTemplate const* proto = item->GetTemplate(); if (!proto) { - pUser->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, pItem, NULL); + user->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, item, NULL); return; } // some item classes can be used only in equipped state - if (proto->GetInventoryType() != INVTYPE_NON_EQUIP && !pItem->IsEquipped()) + if (proto->GetInventoryType() != INVTYPE_NON_EQUIP && !item->IsEquipped()) { - pUser->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, pItem, NULL); + user->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, item, NULL); return; } - InventoryResult msg = pUser->CanUseItem(pItem); + InventoryResult msg = user->CanUseItem(item); if (msg != EQUIP_ERR_OK) { - pUser->SendEquipError(msg, pItem, NULL); + user->SendEquipError(msg, item, NULL); return; } // only allow conjured consumable, bandage, poisons (all should have the 2^21 item flag set in DB) - if (proto->GetClass() == ITEM_CLASS_CONSUMABLE && !(proto->GetFlags() & ITEM_PROTO_FLAG_USEABLE_IN_ARENA) && pUser->InArena()) + if (proto->GetClass() == ITEM_CLASS_CONSUMABLE && !(proto->GetFlags() & ITEM_PROTO_FLAG_USEABLE_IN_ARENA) && user->InArena()) { - pUser->SendEquipError(EQUIP_ERR_NOT_DURING_ARENA_MATCH, pItem, NULL); + user->SendEquipError(EQUIP_ERR_NOT_DURING_ARENA_MATCH, item, NULL); return; } // don't allow items banned in arena - if (proto->GetFlags() & ITEM_PROTO_FLAG_NOT_USEABLE_IN_ARENA && pUser->InArena()) + if (proto->GetFlags() & ITEM_PROTO_FLAG_NOT_USEABLE_IN_ARENA && user->InArena()) { - pUser->SendEquipError(EQUIP_ERR_NOT_DURING_ARENA_MATCH, pItem, NULL); + user->SendEquipError(EQUIP_ERR_NOT_DURING_ARENA_MATCH, item, NULL); return; } - if (pUser->IsInCombat()) + if (user->IsInCombat()) { for (uint32 i = 0; i < proto->Effects.size(); ++i) { @@ -160,7 +102,7 @@ void WorldSession::HandleUseItemOpcode(WorldPacket& recvPacket) { if (!spellInfo->CanBeUsedInCombat()) { - pUser->SendEquipError(EQUIP_ERR_NOT_IN_COMBAT, pItem, NULL); + user->SendEquipError(EQUIP_ERR_NOT_IN_COMBAT, item, NULL); return; } } @@ -168,24 +110,22 @@ void WorldSession::HandleUseItemOpcode(WorldPacket& recvPacket) } // check also BIND_WHEN_PICKED_UP and BIND_QUEST_ITEM for .additem or .additemset case by GM (not binded at adding to inventory) - if (pItem->GetTemplate()->GetBonding() == BIND_WHEN_USE || pItem->GetTemplate()->GetBonding() == BIND_WHEN_PICKED_UP || pItem->GetTemplate()->GetBonding() == BIND_QUEST_ITEM) + if (item->GetTemplate()->GetBonding() == BIND_WHEN_USE || item->GetTemplate()->GetBonding() == BIND_WHEN_PICKED_UP || item->GetTemplate()->GetBonding() == BIND_QUEST_ITEM) { - if (!pItem->IsSoulBound()) + if (!item->IsSoulBound()) { - pItem->SetState(ITEM_CHANGED, pUser); - pItem->SetBinding(true); + item->SetState(ITEM_CHANGED, user); + item->SetBinding(true); } } - SpellCastTargets targets; - targets.Read(recvPacket, pUser); - HandleClientCastFlags(recvPacket, castFlags, targets); + SpellCastTargets targets(user, packet.Cast); // Note: If script stop casting it must send appropriate data to client to prevent stuck item in gray state. - if (!sScriptMgr->OnItemUse(pUser, pItem, targets)) + if (!sScriptMgr->OnItemUse(user, item, targets)) { // no script or script not process request by self - pUser->CastItemUseSpell(pItem, targets, castCount, glyphIndex); + user->CastItemUseSpell(item, targets, packet.Cast.CastID, packet.Cast.Misc); } } @@ -366,7 +306,7 @@ void WorldSession::HandleCastSpellOpcode(WorldPackets::Spells::CastSpell& cast) return; // client provided targets - SpellCastTargets targets(caster, cast.Cast.Target); + SpellCastTargets targets(caster, cast.Cast); // auto-selection buff level base at target level (in spellInfo) if (targets.GetUnitTarget()) |
