Created
February 12, 2018 10:08
-
-
Save Langerz82/d47cfba2a176ed4bd52f00d1c845c57c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git src/server/game/Entities/Unit/Unit.cpp src/server/game/Entities/Unit/Unit.cpp | |
index aafef41809..64dcf13ecd 100644 | |
--- src/server/game/Entities/Unit/Unit.cpp | |
+++ src/server/game/Entities/Unit/Unit.cpp | |
@@ -14438,3 +14438,36 @@ float Unit::GetCollisionHeight() const | |
float const collisionHeight = scaleMod * modelData->CollisionHeight * modelData->Scale * displayInfo->scale; | |
return collisionHeight == 0.0f ? DEFAULT_COLLISION_HEIGHT : collisionHeight; | |
} | |
+ | |
+std::pair<float, float> Unit::GetAheadDistance() | |
+{ | |
+ float displacementRunning = 2.0f; | |
+ float displacementWalking = 1.0f; | |
+ float desty; | |
+ float destx; | |
+ | |
+ float tO = GetOrientation(); | |
+ float angle = tO; | |
+ if (m_movementInfo.HasMovementFlag(MOVEMENTFLAG_STRAFE_LEFT)) | |
+ angle += (float) M_PI / 2; | |
+ else if (m_movementInfo.HasMovementFlag(MOVEMENTFLAG_STRAFE_RIGHT)) | |
+ angle -= (float) M_PI / 2; | |
+ | |
+ float disp = isMoving() ? (IsWalking() ? displacementWalking : displacementRunning) : 0.0f; | |
+ destx = GetPositionX() + disp * std::cos(angle); | |
+ desty = GetPositionY() + disp * std::sin(angle); | |
+ return std::pair<float,float>(destx, desty); | |
+} | |
+ | |
+bool Unit::CompareAheadRange(Unit* target, float range) | |
+{ | |
+ std::pair<float, float> t1 = target->GetAheadDistance(); | |
+ std::pair<float, float> t2 = this->GetAheadDistance(); | |
+ | |
+ float destxProduct = (t1.first - t2.first); | |
+ float destyProduct = (t1.second - t2.second); | |
+ | |
+ float diff = sqrtf(destxProduct * destxProduct + destyProduct * destyProduct); | |
+ return (diff <= range); | |
+} | |
+ | |
diff --git src/server/game/Entities/Unit/Unit.h src/server/game/Entities/Unit/Unit.h | |
index c05c84dc6d..37cadfd410 100644 | |
--- src/server/game/Entities/Unit/Unit.h | |
+++ src/server/game/Entities/Unit/Unit.h | |
@@ -1714,6 +1714,8 @@ class TC_GAME_API Unit : public WorldObject | |
virtual void Whisper(uint32 textId, Player* target, bool isBossWhisper = false); | |
float GetCollisionHeight() const override; | |
+ std::pair<float, float> GetAheadDistance(); | |
+ bool CompareAheadRange(Unit * target, float range); | |
protected: | |
explicit Unit (bool isWorldObject); | |
diff --git src/server/game/Spells/Spell.cpp src/server/game/Spells/Spell.cpp | |
index 8c186064ff..63cee121b1 100644 | |
--- src/server/game/Spells/Spell.cpp | |
+++ src/server/game/Spells/Spell.cpp | |
@@ -6095,17 +6095,14 @@ SpellCastResult Spell::CheckRange(bool strict) const | |
if (m_spellInfo->RangeEntry && m_spellInfo->RangeEntry->type != SPELL_RANGE_MELEE && !strict) | |
maxRange += std::min(MAX_SPELL_RANGE_TOLERANCE, maxRange*0.1f); // 10% but no more than MAX_SPELL_RANGE_TOLERANCE | |
- // get square values for sqr distance checks | |
- minRange *= minRange; | |
- maxRange *= maxRange; | |
Unit* target = m_targets.GetUnitTarget(); | |
if (target && target != m_caster) | |
{ | |
- if (m_caster->GetExactDistSq(target) > maxRange) | |
+ if (!m_caster->CompareAheadRange(target, maxRange)) | |
return SPELL_FAILED_OUT_OF_RANGE; | |
- if (minRange > 0.0f && m_caster->GetExactDistSq(target) < minRange) | |
+ if (minRange > 0.0f && m_caster->CompareAheadRange(target, minRange)) | |
return SPELL_FAILED_OUT_OF_RANGE; | |
if (m_caster->GetTypeId() == TYPEID_PLAYER && | |
@@ -6113,6 +6110,10 @@ SpellCastResult Spell::CheckRange(bool strict) const | |
return SPELL_FAILED_UNIT_NOT_INFRONT; | |
} | |
+ // get square values for sqr distance checks | |
+ minRange *= minRange; | |
+ maxRange *= maxRange; | |
+ | |
if (m_targets.HasDst() && !m_targets.HasTraj()) | |
{ | |
if (m_caster->GetExactDistSq(m_targets.GetDstPos()) > maxRange) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment