Jump to content

Distance calculation for melee-attacks and Following


Schmoozerd

Recommended Posts

Hi guys.

Current Code situation:

every unit has a model, which has some data stored in creature_model_info

These are

- modelid - linked with creature_template.modelid_X (usally 1)

- bounding_radius a float value, used for distance calculation, assumption this is the 'radius' of the modell

- combat_reach a float values, used for spell range check

Scematic of these values:

http://img96.imageshack.us/i/distancecalculations.png/

Atm in clean core spells are checked with GetCombatDistance

       float dist = m_caster->GetCombatDistance(target);

       if(dist > max_range) // max_range is max range of spell (from DBC)
           return SPELL_FAILED_OUT_OF_RANGE;
       if(min_range && dist < min_range) // min_range is min range of spell (from DBC)
           return SPELL_FAILED_TOO_CLOSE;

And melee-range is checked with IsWithinDistInMap ~~> GetDistance, that is takes bounding_radius information into account

       //If we are within range melee the target
       if (m_creature->IsWithinDistInMap(m_creature->getVictim(), ATTACK_DISTANCE))

Also default MoveChase distance is defined by bounding_radius, as the default distance is 0 (which means, the bounding-boxes are near)

My idea is to change this, such that melee-range check is similar to spell range also dependen on combat reach,

this gives in my opinion way better results.

Suggested check:

The icons for spells turn dark-gray if you are out of range, so this is client based, and hence a very good reference.

Example mobs:

- Murmur, Ragnaros, 16441, Maexxna

Base patches:

http://paste2.org/p/1205717 (for core)

http://paste2.org/p/1205718 (for SD2, might give small conflicts, as I wasn't testing on clean)

Problems

* A few mobs like supremus, 16441 have most likely wrong MoveChase behaviour, as of extremely large bounding_radius

* The melee-range now seems to be too big, don't understand which reasons for decreasing there could be!

Any input & feedback is welcome :)

Link to comment
Share on other sites

I have patch for it, lemme look on my branch...

Not sure if you meant it.

This makes players melee attacks based on enemy attack-box (makes for example being possible to hit Thaddius from large distance so Negative / Positive charges arent hitting players on both sides.

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

yes, this does basicly the same as I did (in the player part).

However with this patch the Problem

"The melee-range now seems to be too big, don't understand which reasons for decreasing there could be"

will be worsened even more, as the IsWithinDistInMap check adds the bounding_box values.

I cannot yet tell if the additional check: if < ATTACK_DISTANCE then = ATTACKDISTANCE is important, therefore I haven't explored enough yet

Link to comment
Share on other sites

indeed it seems that it must be taken the maximum of GetCombatDistance and ATTACK_DISTANCE

and it also looks like that in these small distance cases, the combat range is (again) calculated without bounding_box

(I test with 24219, faction changed to 14, values BB=0.748, CR=0.6)

Also some of the model infos which have 0 entries for BB and CR are linked (modelid_other_genger) to some modelids which have reasonablevalues for these fields - so this suggests to also try to implement some additional feature to get the better values

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