Jump to content

[11105][Patch] Melee attacks distance


Feanordev

Recommended Posts

Melee attack distance should be calculated considering enemy attack-box (Look @ Thaddius for example, player should be able to hit him from ~15 yards - this code makes it possible)

Without this patch many of PvE fights are not possible.

diff --git a/src/game/Player.cpp b/src/game/Player.cpp
index 3f09b8e..82ae7ae 100644
--- a/src/game/Player.cpp
+++ b/src/game/Player.cpp
@@ -1250,11 +1250,13 @@ void Player::Update( uint32 p_time )
            // default combat reach 10
            // TODO add weapon,skill check

-            float pldistance = ATTACK_DISTANCE;
+            float dist = pVictim->GetTypeId() == TYPEID_PLAYER ? ATTACK_DISTANCE : (GetFloatValue(UNIT_FIELD_COMBATREACH) + pVictim->GetFloatValue(UNIT_FIELD_COMBATREACH));
+            // Check for creatures that somehow have lower combat-reach than minimal attack distance
+            if (dist < ATTACK_DISTANCE) dist = ATTACK_DISTANCE;

            if (isAttackReady(BASE_ATTACK))
            {
-                if(!IsWithinDistInMap(pVictim, pldistance))
+                if(!IsWithinDistInMap(pVictim, dist))
                {
                    setAttackTimer(BASE_ATTACK,100);
                    if(m_swingErrorMsg != 1)                // send single time (client auto repeat)
@@ -1291,7 +1293,7 @@ void Player::Update( uint32 p_time )

            if ( haveOffhandWeapon() && isAttackReady(OFF_ATTACK))
            {
-                if(!IsWithinDistInMap(pVictim, pldistance))
+                if(!IsWithinDistInMap(pVictim, dist))
                {
                    setAttackTimer(OFF_ATTACK,100);
                }

Link to comment
Share on other sites

Yessssss!~! FINALLY!~! THANK YOU!~! :D

BUT! There is one more missing thing: creatures should also follow this rule, right now they follow target on 5yd distance always.

EDIT: OK, I found the thread in general discussion ;p

Tested this patch and it works OK :) Now fighting with Kel'Thuzad will be a lot easier for melee classes ;)

Link to comment
Share on other sites

the melee range for creatures is set in creature_model_info table ...

most of the mobs have it set to 5yrds, i believe this data can be mined from DBC (based on the size of the "red circle" below mobs), but haven't yet found where is this info stored

Link to comment
Share on other sites

After some research and tests, I came up with the following changes:

For core:

http://paste2.org/p/1219177

For further testing (and because of compile errros) for SD2:

http://paste2.org/p/1219179

Changes in Spell:RangeCheck():

I tested the behaviour with spells of rangeIndexes 8 (10y), 140 (6y), and also one spell with 12 (5y-Interaction) (16612),

but _only_ the melee-ranged spells (index 2) behaved with this additional 1.33 offset.

Also I could not see any reason for the additional value in the checks, so I think this is something from the good old times

There is a known problem with this patch:

A mob who has bounding_radius >> combat_reach WILL now be exploitable, as they won't chase to melee-range (so they won't do melee dmg).

This bug is not caused by this patch, this patch only makes this bug more obvious.

If anyone wants to confirm that this patch _is_ correctly (or want to measure a more precise value for the 1.33f melee-range offset), this is how to check (also there are shown my measured values)

http://paste2.org/p/1218554

1) a patch making the test more easy, this is only for debugging purpose

2) use .m as .1 to walk slow enough to get accurate values.

3) the check is the 'color' of the spell's icons, use any spell with a fixed range, and you can go to the place where the range-check changes, and measure the distance to your target by .dist (modifed version's output can be seen in my research datas)

Link to comment
Share on other sites

I backporting [11105] for Mangos-One [s0737]

SD2 : 1964

ACID : 2.0.5

Uptime : 2 hours

Crash log :

Exception code: C0000005 ACCESS_VIOLATION

Address   Frame     Function      SourceFile
0000000140002FB9  000000000A594F70  Object::GetFloatValue+39  d:\\[s0737]_1964\\src\\game\\object.h line 159
00000001400A607D  000000000A598050  Unit::CanReachWithMeleeAttack+AD  d:\\[s0737]_1964\\src\\game\\unit.cpp line 462
000000000A07B412  000000000A598080  ?getCurrentVictim@ThreatManager@@QEAAPEAVHostileReference@@XZ+15D2
0000000009F77C4B  000000000A598150  ?getLevel@Unit@@QEBAIXZ+30CB
00000001400FB34E  000000000A59C3C0  Creature::Update+99E  d:\\[s0737]_1964\\src\\game\\creature.cpp line 554
000000014015E4A5  000000000A59C450  MaNGOS::ObjectUpdater::Visit+F5  d:\\[s0737]_1964\\src\\game\\gridnotifiersimpl.h line 45
000000014015E39D  000000000A59C4C0  VisitorHelper<MaNGOS::ObjectUpdater,Creature>+1D  d:\\[s0737]_1964\\src\\framework\\gamesystem\\typecontainervisitor.h line 51
000000014015DCCD  000000000A59C4F0  VisitorHelper<MaNGOS::ObjectUpdater,Creature,TypeList<DynamicObject,TypeList<Corpse,TypeNull> > >+1D  d:\\[s0737]_1964\\src\\framework\\gamesystem\\typecontainervisitor.h line 58
000000014015D470  000000000A59C520  VisitorHelper<MaNGOS::ObjectUpdater,GameObject,TypeList<Creature,TypeList<DynamicObject,TypeList<Corpse,TypeNull> > > >+30  d:\\[s0737]_1964\\src\\framework\\gamesystem\\typecontainervisitor.h line 59
000000014015C95D  000000000A59C550  VisitorHelper<MaNGOS::ObjectUpdater,TypeList<GameObject,TypeList<Creature,TypeList<DynamicObject,TypeList<Corpse,TypeNull> > > > >+1D  d:\\[s0737]_1964\\src\\framework\\gamesystem\\typecontainervisitor.h line 66
0000000140152D02  000000000A59E5D0  Map::Visit<MaNGOS::ObjectUpdater,TypeMapContainer<TypeList<GameObject,TypeList<Creature,TypeList<DynamicObject,TypeList<Corpse,TypeNull> > > > > >+122  d:\\[s0737]_1964\\src\\game\\map.h line 567
0000000140135F57  000000000A59FA60  Map::Update+4E7  d:\\[s0737]_1964\\src\\game\\map.cpp line 625
000000014013F29D  000000000A59FA90  InstanceMap::Update+1D  d:\\[s0737]_1964\\src\\game\\map.cpp line 2258
000000014059DA4D  000000000A59FB10  MapInstanced::Update+16D  d:\\[s0737]_1964\\src\\game\\mapinstanced.cpp line 64
0000000140353CBF  000000000A59FC00  MapManager::Update+19F  d:\\[s0737]_1964\\src\\game\\mapmanager.cpp line 253
00000001402DB1B5  000000000A59FDC0  World::Update+6C5  d:\\[s0737]_1964\\src\\game\\world.cpp line 1422
000000014006B9A6  000000000A59FE80  WorldRunnable::run+A6  d:\\[s0737]_1964\\src\\mangosd\\worldrunnable.cpp line 61
000000014030E983  000000000A59FED0  ACE_Based::Thread::ThreadTask+23  d:\\[s0737]_1964\\src\\shared\\threading.cpp line 190
00000000006F24AB  000000000A59FF10  ?invoke@ACE_OS_Thread_Adapter@@UEAAKXZ+5B
0000000078622FDF  000000000A59FF40  _endthreadex+47
0000000078623080  000000000A59FF70  _endthreadex+E8
0000000077D6B71A  000000000A59FFA0  BaseThreadStart+3A

Local Variables And Parameters

Call stack:
Address   Frame     Function      SourceFile
0000000140002FB9  000000000A594F70  Object::GetFloatValue+39  d:\\[s0737]_1964\\src\\game\\object.h line 159
   Local  <user defined> 'this'
   Local  unsigned int 'index' = 4000

00000001400A607D  000000000A598050  Unit::CanReachWithMeleeAttack+AD  d:\\[s0737]_1964\\src\\game\\unit.cpp line 462
   Local  <user defined> 'this'
   Local  <user defined> 'pVictim'
   Local  float 'flat_mod' = -2553351.250000
   Local  float 'dx' = 0.000000
   Local  float 'reach' = 0.000000
   Local  float 'dz' = 0.000000
   Local  float 'dy' = 0.000000

000000000A07B412  000000000A598080  ?getCurrentVictim@ThreatManager@@QEAAPEAVHostileReference@@XZ+15D2

0000000009F77C4B  000000000A598150  ?getLevel@Unit@@QEBAIXZ+30CB

00000001400FB34E  000000000A59C3C0  Creature::Update+99E  d:\\[s0737]_1964\\src\\game\\creature.cpp line 554
   Local  <user defined> 'this'
punting on symbol diff

000000014015E4A5  000000000A59C450  MaNGOS::ObjectUpdater::Visit+F5  d:\\[s0737]_1964\\src\\game\\gridnotifiersimpl.h line 45
   Local  <user defined> 'iter'
   Local  <user defined> 'this'
   Local  <user defined> 'm'


Link to comment
Share on other sites

Program received signal SIGABRT, Aborted.
[switching to Thread 0x418f0950 (LWP 5529)]
0x00007f5f1a774ed5 in raise () from /lib/libc.so.6
#0  0x00007f5f1a774ed5 in raise () from /lib/libc.so.6
#1  0x00007f5f1a7763f3 in abort () from /lib/libc.so.6
#2  0x00007f5f1a76ddc9 in __assert_fail () from /lib/libc.so.6
#3  0x000000000082f039 in Unit::CanReachWithMeleeAttack (this=0x7f5edf792080, pVictim=<value optimized out>, flat_mod=0)
   at ../../../src/game/Unit.cpp:531
#4  0x0000000000893c77 in CreatureEventAI::DoMeleeAttackIfReady (this=0x7f5edf7eafc0)
   at ../../../src/game/CreatureEventAI.cpp:1374
#5  0x000000000057ff24 in Creature::Update (this=0x7f5edf792080, update_diff=100, diff=100)
   at ../../../src/game/Creature.cpp:562
#6  0x0000000000691051 in VisitorHelper<MaNGOS::ObjectUpdater, Creature> (v=@0x418f0050, c=<value optimized out>)
   at ../../../src/game/Object.h:417
#7  0x000000000068f01d in Map::Update (this=0x3570000, t_diff=@0x7f5eb1ac1b18)
   at ../../../src/game/../framework/GameSystem/TypeContainerVisitor.h:57
#8  0x000000000068f8c9 in InstanceMap::Update (this=0x1567, t_diff=@0x1599) at ../../../src/game/Map.cpp:1431
#9  0x000000000069f1d2 in MapUpdateRequest::call (this=0x7f5eb1ac1af8) at ../../../src/game/MapUpdater.cpp:47

also mangos problem

Link to comment
Share on other sites

  • 3 weeks later...

If I'm thinking right, such distance check must be also implemented for AoE spells. Currently, if melee character is attacking from far distance and uses an AoE spell (warrior with Whirlwind i.e.) then this spell will not strike the target, even though melee attacks do hit it.

Link to comment
Share on other sites

possible, though more difficult to prove that AoE spells also work with combat-reach (and not bounding_radius)

Also If I am not mistaken this will need to change quite much stuff around (targeting mechanics) - also it is not clear if

- there exist "melee" aoe spells

- such AoE spells indeed behave as an exception(*) as melee spells do.

This needs to be clearified, and then this should be a nice new patch :)

(*) if you want to research, about the melee-range exception:

normal spells have as range combat_reach + spell-range. (+ some small offset for checking)

melee spells have as range: combat_reach + offset (rounded up to 5y)

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use