*Implement spell casting on transports (no more out of range error, etc)

*Add MO transports to ObjectAccessor storage
*Add functions Position::RelocateOffset and Position::GetPositionOffsetTo to help offset manipulations - BIG thanks to azazelkon for creating formulas!
*Add function to output debug info for MovementInfo and SpellCastTargets
*Throw ByteBufferException on incorrect packGUID read
*Add rfinish function to finish bytebuffer read.

--HG--
branch : trunk
This commit is contained in:
QAston
2010-08-08 20:32:14 +02:00
parent 48c4d4551c
commit 617a56ba29
19 changed files with 434 additions and 235 deletions
@@ -1257,8 +1257,7 @@ void WorldSession::HandleEquipmentSetSave(WorldPacket &recv_data)
sLog.outDebug("CMSG_EQUIPMENT_SET_SAVE");
uint64 setGuid;
if (!recv_data.readPackGUID(setGuid))
return;
recv_data.readPackGUID(setGuid);
uint32 index;
recv_data >> index;
@@ -1281,8 +1280,7 @@ void WorldSession::HandleEquipmentSetSave(WorldPacket &recv_data)
for (uint32 i = 0; i < EQUIPMENT_SLOT_END; ++i)
{
uint64 itemGuid;
if (!recv_data.readPackGUID(itemGuid))
return;
recv_data.readPackGUID(itemGuid);
Item *item = _player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
@@ -1303,8 +1301,7 @@ void WorldSession::HandleEquipmentSetDelete(WorldPacket &recv_data)
sLog.outDebug("CMSG_EQUIPMENT_SET_DELETE");
uint64 setGuid;
if (!recv_data.readPackGUID(setGuid))
return;
recv_data.readPackGUID(setGuid);
_player->DeleteEquipmentSet(setGuid);
}
@@ -1317,8 +1314,7 @@ void WorldSession::HandleEquipmentSetUse(WorldPacket &recv_data)
for (uint32 i = 0; i < EQUIPMENT_SLOT_END; ++i)
{
uint64 itemGuid;
if (!recv_data.readPackGUID(itemGuid))
return;
recv_data.readPackGUID(itemGuid);
uint8 srcbag, srcslot;
recv_data >> srcbag >> srcslot;
@@ -1090,11 +1090,7 @@ void WorldSession::HandleMoveTimeSkippedOpcode(WorldPacket & recv_data)
DEBUG_LOG("WORLD: Time Lag/Synchronization Resent/Update");
uint64 guid;
if (!recv_data.readPackGUID(guid))
{
recv_data.rpos(recv_data.wpos());
return;
}
recv_data.readPackGUID(guid);
recv_data.read_skip<uint32>();
/*
uint64 guid;
@@ -1651,8 +1647,8 @@ void WorldSession::HandleMoveSetCanFlyAckOpcode(WorldPacket & recv_data)
//recv_data.hexlike();
uint64 guid; // guid - unused
if (!recv_data.readPackGUID(guid))
return;
recv_data.readPackGUID(guid);
recv_data.read_skip<uint32>(); // unk
@@ -1684,8 +1680,7 @@ void WorldSession::HandleSetTaxiBenchmarkOpcode(WorldPacket & recv_data)
void WorldSession::HandleQueryInspectAchievements(WorldPacket & recv_data)
{
uint64 guid;
if (!recv_data.readPackGUID(guid))
return;
recv_data.readPackGUID(guid);
Player *player = sObjectMgr.GetPlayer(guid);
if (!player)
@@ -195,8 +195,7 @@ void WorldSession::HandleMoveTeleportAck(WorldPacket& recv_data)
sLog.outDebug("MSG_MOVE_TELEPORT_ACK");
uint64 guid;
if (!recv_data.readPackGUID(guid))
return;
recv_data.readPackGUID(guid);
uint32 flags, time;
recv_data >> flags >> time;
@@ -264,8 +263,7 @@ void WorldSession::HandleMovementOpcodes(WorldPacket & recv_data)
/* extract packet */
uint64 guid;
if (!recv_data.readPackGUID(guid))
return;
recv_data.readPackGUID(guid);
MovementInfo movementInfo;
movementInfo.guid = guid;
@@ -424,8 +422,7 @@ void WorldSession::HandleForceSpeedChangeAck(WorldPacket &recv_data)
uint32 unk1;
float newspeed;
if (!recv_data.readPackGUID(guid))
return;
recv_data.readPackGUID(guid);
// now can skip not our packet
if (_player->GetGUID() != guid)
@@ -525,8 +522,7 @@ void WorldSession::HandleMoveNotActiveMover(WorldPacket &recv_data)
sLog.outDebug("WORLD: Recvd CMSG_MOVE_NOT_ACTIVE_MOVER");
uint64 old_mover_guid;
if (!recv_data.readPackGUID(old_mover_guid))
return;
recv_data.readPackGUID(old_mover_guid);
/*if (_player->m_mover->GetGUID() == old_mover_guid)
{
@@ -558,8 +554,7 @@ void WorldSession::HandleDismissControlledVehicle(WorldPacket &recv_data)
uint64 guid;
if (!recv_data.readPackGUID(guid))
return;
recv_data.readPackGUID(guid);
MovementInfo mi;
mi.guid = guid;
@@ -592,14 +587,12 @@ void WorldSession::HandleChangeSeatsOnControlledVehicle(WorldPacket &recv_data)
case CMSG_CHANGE_SEATS_ON_CONTROLLED_VEHICLE:
{
uint64 guid; // current vehicle guid
if (!recv_data.readPackGUID(guid))
return;
recv_data.readPackGUID(guid);
ReadMovementInfo(recv_data, &vehicle_base->m_movementInfo);
uint64 accessory; // accessory guid
if (!recv_data.readPackGUID(accessory))
return;
recv_data.readPackGUID(accessory);
int8 seatId;
recv_data >> seatId;
@@ -620,8 +613,7 @@ void WorldSession::HandleChangeSeatsOnControlledVehicle(WorldPacket &recv_data)
case CMSG_REQUEST_VEHICLE_SWITCH_SEAT:
{
uint64 guid; // current vehicle guid
if (!recv_data.readPackGUID(guid))
return;
recv_data.readPackGUID(guid);
int8 seatId;
recv_data >> seatId;
@@ -693,8 +685,7 @@ void WorldSession::HandleMoveKnockBackAck(WorldPacket & recv_data)
sLog.outDebug("CMSG_MOVE_KNOCK_BACK_ACK");
uint64 guid; // guid - unused
if (!recv_data.readPackGUID(guid))
return;
recv_data.readPackGUID(guid);
recv_data.read_skip<uint32>(); // unk
@@ -707,8 +698,7 @@ void WorldSession::HandleMoveHoverAck(WorldPacket& recv_data)
sLog.outDebug("CMSG_MOVE_HOVER_ACK");
uint64 guid; // guid - unused
if (!recv_data.readPackGUID(guid))
return;
recv_data.readPackGUID(guid);
recv_data.read_skip<uint32>(); // unk
@@ -723,8 +713,7 @@ void WorldSession::HandleMoveWaterWalkAck(WorldPacket& recv_data)
sLog.outDebug("CMSG_MOVE_WATER_WALK_ACK");
uint64 guid; // guid - unused
if (!recv_data.readPackGUID(guid))
return;
recv_data.readPackGUID(guid);
recv_data.read_skip<uint32>(); // unk
@@ -692,12 +692,13 @@ void WorldSession::HandlePetCastSpellOpcode(WorldPacket& recvPacket)
sLog.outDetail("WORLD: CMSG_PET_CAST_SPELL");
uint64 guid;
uint32 spellid;
uint8 cast_count;
uint8 castCount;
uint32 spellId;
uint8 castFlags;
recvPacket >> guid >> cast_count >> spellid;
recvPacket >> guid >> castCount >> spellId >> castFlags;
sLog.outDebug("WORLD: CMSG_PET_CAST_SPELL, cast_count: %u, spellid %u", cast_count, spellid);
sLog.outDebug("WORLD: CMSG_PET_CAST_SPELL, guid: " UI64FMTD ", castCount: %u, spellId %u, castFlags %u", guid, castCount, spellId, castFlags);
// This opcode is also sent from charmed and possessed units (players and creatures)
if (!_player->GetGuardianPet() && !_player->GetCharm())
@@ -711,32 +712,32 @@ void WorldSession::HandlePetCastSpellOpcode(WorldPacket& recvPacket)
return;
}
SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellid);
SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
if (!spellInfo)
{
sLog.outError("WORLD: unknown PET spell id %i", spellid);
sLog.outError("WORLD: unknown PET spell id %i", spellId);
return;
}
if (spellInfo->StartRecoveryCategory > 0) //Check if spell is affected by GCD
if (spellInfo->StartRecoveryCategory > 0) // Check if spell is affected by GCD
if (caster->GetTypeId() == TYPEID_UNIT && caster->ToCreature()->GetGlobalCooldown() > 0)
{
caster->SendPetCastFail(spellid, SPELL_FAILED_NOT_READY);
caster->SendPetCastFail(spellId, SPELL_FAILED_NOT_READY);
return;
}
// do not cast not learned spells
if (!caster->HasSpell(spellid) || IsPassiveSpell(spellid))
if (!caster->HasSpell(spellId) || IsPassiveSpell(spellId))
return;
SpellCastTargets targets;
if (!targets.read(&recvPacket,caster))
return;
targets.read(recvPacket, caster);
HandleClientCastFlags(recvPacket, castFlags, targets);
caster->clearUnitState(UNIT_STAT_FOLLOW);
Spell *spell = new Spell(caster, spellInfo, spellid == 33395); // water elemental can cast freeze as triggered
spell->m_cast_count = spellid == 33395 ? 0 : cast_count; // probably pending spell cast
Spell *spell = new Spell(caster, spellInfo, spellId == 33395); // water elemental can cast freeze as triggered
spell->m_cast_count = spellId == 33395 ? 0 : castCount; // probably pending spell cast
spell->m_targets = targets;
// TODO: need to check victim?
@@ -750,7 +751,7 @@ void WorldSession::HandlePetCastSpellOpcode(WorldPacket& recvPacket)
if (caster->GetTypeId() == TYPEID_UNIT)
{
Creature* pet = caster->ToCreature();
pet->AddCreatureSpellCooldown(spellid);
pet->AddCreatureSpellCooldown(spellId);
if (pet->isPet())
{
Pet* p = (Pet*)pet;
@@ -767,16 +768,16 @@ void WorldSession::HandlePetCastSpellOpcode(WorldPacket& recvPacket)
}
else
{
caster->SendPetCastFail(spellid, result);
caster->SendPetCastFail(spellId, result);
if (caster->GetTypeId() == TYPEID_PLAYER)
{
if (!caster->ToPlayer()->HasSpellCooldown(spellid))
GetPlayer()->SendClearCooldown(spellid, caster);
if (!caster->ToPlayer()->HasSpellCooldown(spellId))
GetPlayer()->SendClearCooldown(spellId, caster);
}
else
{
if (!caster->ToCreature()->HasSpellCooldown(spellid))
GetPlayer()->SendClearCooldown(spellid, caster);
if (!caster->ToCreature()->HasSpellCooldown(spellId))
GetPlayer()->SendClearCooldown(spellId, caster);
}
spell->finish(false);
@@ -33,6 +33,31 @@
#include "CreatureAI.h"
#include "ScriptMgr.h"
void WorldSession::HandleClientCastFlags(WorldPacket& recvPacket, uint8 castFlags, SpellCastTargets & targets)
{
// some spell cast packet including more data (for projectiles?)
if (castFlags & 0x02)
{
// not sure about these two
recvPacket >> targets.m_elevation;
recvPacket >> targets.m_speed;
uint8 hasMovementData;
recvPacket >> hasMovementData;
if (hasMovementData)
{
recvPacket.rfinish();
// movement packet for caster of the spell
/*recvPacket.read_skip<uint32>(); // MSG_MOVE_STOP - hardcoded in client
uint64 guid;
recvPacket.readPackGUID(guid);
MovementInfo movementInfo;
movementInfo.guid = guid;
ReadMovementInfo(recvPacket, &movementInfo);*/
}
}
}
void WorldSession::HandleUseItemOpcode(WorldPacket& recvPacket)
{
// TODO: add targets.read() check
@@ -42,13 +67,13 @@ void WorldSession::HandleUseItemOpcode(WorldPacket& recvPacket)
if (pUser->m_mover != pUser)
return;
uint8 bagIndex, slot;
uint8 cast_count; // next cast if exists (single or not)
uint64 item_guid;
uint8 bagIndex, slot, castFlags;
uint8 castCount; // next cast if exists (single or not)
uint64 itemGUID;
uint32 glyphIndex; // something to do with glyphs?
uint32 spellid; // casted spell id
uint32 spellId; // casted spell id
recvPacket >> bagIndex >> slot >> cast_count >> spellid >> item_guid >> glyphIndex;
recvPacket >> bagIndex >> slot >> castCount >> spellId >> itemGUID >> glyphIndex >> castFlags;
if (glyphIndex >= MAX_GLYPH_SLOT_INDEX)
{
@@ -63,13 +88,13 @@ void WorldSession::HandleUseItemOpcode(WorldPacket& recvPacket)
return;
}
if (pItem->GetGUID() != item_guid)
if (pItem->GetGUID() != itemGUID)
{
pUser->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL);
return;
}
sLog.outDetail("WORLD: CMSG_USE_ITEM packet, bagIndex: %u, slot: %u, cast_count: %u, spellid: %u, Item: %u, glyphIndex: %u, data length = %i", bagIndex, slot, cast_count, spellid, pItem->GetEntry(), glyphIndex, (uint32)recvPacket.size());
sLog.outDetail("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());
ItemPrototype const *proto = pItem->GetProto();
if (!proto)
@@ -132,10 +157,8 @@ void WorldSession::HandleUseItemOpcode(WorldPacket& recvPacket)
}
SpellCastTargets targets;
if (!targets.read(&recvPacket, pUser))
return;
targets.Update(pUser);
targets.read(recvPacket, pUser);
HandleClientCastFlags(recvPacket, castFlags, targets);
if (!pItem->IsTargetValidForItemUse(targets.getUnitTarget()))
{
@@ -143,23 +166,23 @@ void WorldSession::HandleUseItemOpcode(WorldPacket& recvPacket)
pUser->SendEquipError(EQUIP_ERR_NONE, pItem, NULL);
// send spell error
if (SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid))
if (SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellId))
{
// for implicit area/coord target spells
if (!targets.getUnitTarget())
Spell::SendCastResult(_player,spellInfo,cast_count,SPELL_FAILED_NO_VALID_TARGETS);
Spell::SendCastResult(_player,spellInfo,castCount,SPELL_FAILED_NO_VALID_TARGETS);
// for explicit target spells
else
Spell::SendCastResult(_player,spellInfo,cast_count,SPELL_FAILED_BAD_TARGETS);
Spell::SendCastResult(_player,spellInfo,castCount,SPELL_FAILED_BAD_TARGETS);
}
return;
}
//Note: If script stop casting it must send appropriate data to client to prevent stuck item in gray state.
// 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))
{
// no script or script not process request by self
pUser->CastItemUseSpell(pItem,targets,cast_count,glyphIndex);
pUser->CastItemUseSpell(pItem,targets,castCount,glyphIndex);
}
}
@@ -293,26 +316,25 @@ void WorldSession::HandleGameobjectReportUse(WorldPacket& recvPacket)
void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket)
{
uint32 spellId;
uint8 cast_count;
recvPacket >> cast_count;
recvPacket >> spellId;
uint8 castCount, castFlags;
recvPacket >> castCount >> spellId >> castFlags;
sLog.outDebug("WORLD: got cast spell packet, castCount: %u, spellId: %u, castFlags: %u, data length = %u", castCount, spellId, castFlags, (uint32)recvPacket.size());
// ignore for remote control state (for player case)
Unit* mover = _player->m_mover;
if (mover != _player && mover->GetTypeId() == TYPEID_PLAYER)
{
recvPacket.rpos(recvPacket.wpos()); // prevent spam at ignore packet
recvPacket.rfinish(); // prevent spam at ignore packet
return;
}
sLog.outDebug("WORLD: got cast spell packet, spellId - %u, cast_count: %u, data length = %i", spellId, cast_count, (uint32)recvPacket.size());
SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
if (!spellInfo)
{
sLog.outError("WORLD: unknown spell id %u", spellId);
recvPacket.rpos(recvPacket.wpos()); // prevent spam at ignore packet
recvPacket.rfinish(); // prevent spam at ignore packet
return;
}
@@ -322,7 +344,7 @@ void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket)
if (!mover->ToPlayer()->HasActiveSpell (spellId) || IsPassiveSpell(spellId))
{
//cheater? kick? ban?
recvPacket.rpos(recvPacket.wpos()); // prevent spam at ignore packet
recvPacket.rfinish(); // prevent spam at ignore packet
return;
}
}
@@ -332,7 +354,7 @@ void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket)
if ((mover->GetTypeId() == TYPEID_UNIT && !mover->ToCreature()->HasSpell(spellId)) || IsPassiveSpell(spellId))
{
//cheater? kick? ban?
recvPacket.rpos(recvPacket.wpos()); // prevent spam at ignore packet
recvPacket.rfinish(); // prevent spam at ignore packet
return;
}
}
@@ -345,15 +367,15 @@ void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket)
// can't use our own spells when we're in possession of another unit,
if (_player->isPossessing())
{
recvPacket.rfinish(); // prevent spam at ignore packet
return;
}
// client provided targets
SpellCastTargets targets;
if (!targets.read(&recvPacket,mover))
{
recvPacket.rpos(recvPacket.wpos()); // prevent spam at ignore packet
return;
}
targets.read(recvPacket, mover);
HandleClientCastFlags(recvPacket, castFlags, targets);
// auto-selection buff level base at target level (in spellInfo)
if (targets.getUnitTarget())
@@ -366,7 +388,7 @@ void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket)
}
Spell *spell = new Spell(mover, spellInfo, false);
spell->m_cast_count = cast_count; // set count of casts
spell->m_cast_count = castCount; // set count of casts
spell->prepare(&targets);
}
@@ -202,9 +202,8 @@ void WorldSession::HandleMoveSplineDoneOpcode(WorldPacket& recv_data)
{
sLog.outDebug("WORLD: Received CMSG_MOVE_SPLINE_DONE");
uint64 guid; // used only for proper packet read
if (!recv_data.readPackGUID(guid))
return;
uint64 guid; // used only for proper packet read
recv_data.readPackGUID(guid);
MovementInfo movementInfo; // used only for proper packet read
ReadMovementInfo(recv_data, &movementInfo);
+1 -2
View File
@@ -721,8 +721,7 @@ void WorldSession::ReadMovementInfo(WorldPacket &data, MovementInfo *mi)
if (mi->flags & MOVEMENTFLAG_ONTRANSPORT)
{
if (!data.readPackGUID(mi->t_guid))
return;
data.readPackGUID(mi->t_guid);
data >> mi->t_pos.PositionXYZOStream();
data >> mi->t_time;
+5 -1
View File
@@ -47,6 +47,7 @@ class WorldSocket;
class QueryResult;
class LoginQueryHolder;
class CharacterHandler;
class SpellCastTargets;
struct AreaTableEntry;
enum AccountDataType
@@ -211,7 +212,10 @@ class WorldSession
void SendPetitionQueryOpcode(uint64 petitionguid);
//pet
// Spell
void HandleClientCastFlags(WorldPacket& recvPacket, uint8 castFlags, SpellCastTargets & targets);
// Pet
void SendPetNameQuery(uint64 guid, uint32 petnumber);
void SendStablePet(uint64 guid);
void SendStableResult(uint8 guid);