From 81fea8732ddd77d63cec2abde2f4670fa5e05ce1 Mon Sep 17 00:00:00 2001 From: ratkosrb Date: Sat, 12 Dec 2020 21:29:03 +0200 Subject: [PATCH] Send melee attack target in update object packet. Credits to killerwife. Fixes missing melee animation bug with summoned creatures that aggro immediately. --- src/game/Maps/ScriptCommands.cpp | 9 --------- src/game/Objects/Object.cpp | 14 +++++++++++--- src/game/Objects/UpdateData.h | 16 ++++++++-------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/game/Maps/ScriptCommands.cpp b/src/game/Maps/ScriptCommands.cpp index e9eb77910..7b810b12f 100644 --- a/src/game/Maps/ScriptCommands.cpp +++ b/src/game/Maps/ScriptCommands.cpp @@ -402,16 +402,7 @@ bool Map::ScriptCommand_SummonCreature(ScriptInfo const& script, WorldObject* so if (Unit* pAttackTarget = ToUnit(GetTargetByType(pSummoner, ToUnit(target), script.summonCreature.attackTarget))) { if (pCreature->AI()) - { - // Hack: there is a visual bug where the melee animation - // does not play for summoned units if they enter combat - // immediately and their target is within melee range. - // Sending the packet a second time fixes the animation. - if (pCreature->AI()->IsMeleeAttackEnabled()) - pCreature->SendMeleeAttackStart(pAttackTarget); - pCreature->AI()->AttackStart(pAttackTarget); - } } } diff --git a/src/game/Objects/Object.cpp b/src/game/Objects/Object.cpp index f60889a66..360fa13b4 100644 --- a/src/game/Objects/Object.cpp +++ b/src/game/Objects/Object.cpp @@ -283,6 +283,9 @@ void Object::BuildCreateUpdateBlockForPlayer(UpdateData* data, Player* target) c if (target == this) // building packet for yourself updateFlags |= UPDATEFLAG_SELF; + if (IsUnit() && static_cast(this)->HasUnitState(UNIT_STAT_MELEE_ATTACKING) && static_cast(this)->GetVictim()) + updateFlags |= UPDATEFLAG_MELEE_ATTACKING; + if (m_isNewObject) updatetype = UPDATETYPE_CREATE_OBJECT2; #else @@ -290,7 +293,7 @@ void Object::BuildCreateUpdateBlockForPlayer(UpdateData* data, Player* target) c updateFlags |= UPDATEFLAG_SELF; #endif - if (isType(TYPEMASK_GAMEOBJECT) && ((GameObject*)this)->GetGoType() == GAMEOBJECT_TYPE_TRANSPORT) + if (isType(TYPEMASK_GAMEOBJECT) && static_cast(this)->GetGoType() == GAMEOBJECT_TYPE_TRANSPORT) updateFlags |= UPDATEFLAG_TRANSPORT; //DEBUG_LOG("BuildCreateUpdate: update-type: %u, object-type: %u got updateFlags: %X", updatetype, m_objectTypeId, updateFlags); @@ -310,7 +313,12 @@ void Object::BuildCreateUpdateBlockForPlayer(UpdateData* data, Player* target) c buf << uint32(updateFlags); // Flags buf << uint32(1); // AttackCycle (always 1 in sniffs) buf << uint32(0); // TimerId - buf << uint64(0); // VictimGuid + + // VictimGuid + if (IsUnit() && static_cast(this)->HasUnitState(UNIT_STAT_MELEE_ATTACKING) && static_cast(this)->GetVictim()) + buf << uint64(static_cast(this)->GetVictim()->GetGUID()); + else + buf << uint64(0); if (updateFlags & UPDATEFLAG_TRANSPORT) { @@ -470,7 +478,7 @@ void Object::BuildMovementUpdate(ByteBuffer* data, uint8 updateFlags) const *data << uint32(1); } - if (updateFlags & UPDATEFLAG_FULLGUID) + if (updateFlags & UPDATEFLAG_MELEE_ATTACKING) { if (Unit const* me = ToUnit()) { diff --git a/src/game/Objects/UpdateData.h b/src/game/Objects/UpdateData.h index 4982d7025..437498b2b 100644 --- a/src/game/Objects/UpdateData.h +++ b/src/game/Objects/UpdateData.h @@ -44,15 +44,15 @@ enum ObjectUpdateType // checked for 1.12.1 enum ObjectUpdateFlags { - UPDATEFLAG_NONE = 0x0000, - UPDATEFLAG_SELF = 0x0001, - UPDATEFLAG_TRANSPORT = 0x0002, + UPDATEFLAG_NONE = 0x0000, + UPDATEFLAG_SELF = 0x0001, + UPDATEFLAG_TRANSPORT = 0x0002, #if SUPPORTED_CLIENT_BUILD > CLIENT_BUILD_1_8_4 - UPDATEFLAG_FULLGUID = 0x0004, - UPDATEFLAG_HIGHGUID = 0x0008, - UPDATEFLAG_ALL = 0x0010, - UPDATEFLAG_LIVING = 0x0020, - UPDATEFLAG_HAS_POSITION = 0x0040 + UPDATEFLAG_MELEE_ATTACKING = 0x0004, + UPDATEFLAG_HIGHGUID = 0x0008, + UPDATEFLAG_ALL = 0x0010, + UPDATEFLAG_LIVING = 0x0020, + UPDATEFLAG_HAS_POSITION = 0x0040 #endif };