feat(Core/CreatureAI): improve npc position during the combat (#3369)

+ tangent equation to find correct angle and distance when moving

+ implemented proper backward

* Improved performance + random angle margin

* chore: add tollerance calculation in instance

* improved LOS checks with movements

* implemented collisions using raycast (imported by TC)

+ improved collision detection for CanReachPositionAndGetCoords

+ improved collision check

+ set correct flags for the backward movement

+ first implementation of slope angle (to improve)

Co-authored-by: Yehonal <yehonal.azeroth@gmail.com>
This commit is contained in:
Stefano Borzì
2021-01-04 20:23:08 +01:00
committed by GitHub
parent 039e143d48
commit b2761626fe
22 changed files with 1411 additions and 766 deletions

View File

@@ -1255,6 +1255,26 @@ private:
GlobalCooldownMgr _GlobalCooldownMgr;
};
struct AttackPosition {
AttackPosition(Position pos) : _pos(pos), _taken(false) {}
bool operator==(const int val)
{
return !val;
};
int operator=(const int val)
{
if (!val)
{
// _pos = NULL;
_taken = false;
return 0; // NULL
}
return 0; // NULL
};
Position _pos;
bool _taken;
};
// for clearing special attacks
#define REACTIVE_TIMER_START 5000
@@ -1405,6 +1425,7 @@ public:
virtual void SetCanDualWield(bool value) { m_canDualWield = value; }
[[nodiscard]] float GetCombatReach() const override { return m_floatValues[UNIT_FIELD_COMBATREACH]; }
[[nodiscard]] float GetMeleeReach() const { float reach = m_floatValues[UNIT_FIELD_COMBATREACH]; return reach > MIN_MELEE_REACH ? reach : MIN_MELEE_REACH; }
[[nodiscard]] bool IsWithinRange(Unit const* obj, float dist) const;
bool IsWithinCombatRange(const Unit* obj, float dist2compare) const;
bool IsWithinMeleeRange(const Unit* obj, float dist = MELEE_RANGE) const;
bool GetRandomContactPoint(const Unit* target, float& x, float& y, float& z, bool force = false) const;
@@ -1434,6 +1455,7 @@ public:
bool AttackStop();
void RemoveAllAttackers();
[[nodiscard]] AttackerSet const& getAttackers() const { return m_attackers; }
[[nodiscard]] Position* GetMeleeAttackPoint(Unit* attacker);
[[nodiscard]] bool isAttackingPlayer() const;
[[nodiscard]] Unit* GetVictim() const { return m_attacking; }
@@ -2174,7 +2196,7 @@ public:
uint32 GetDisplayId() { return GetUInt32Value(UNIT_FIELD_DISPLAYID); }
virtual void SetDisplayId(uint32 modelId);
uint32 GetNativeDisplayId() { return GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID); }
[[nodiscard]] uint32 GetNativeDisplayId() const { return GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID); }
void RestoreDisplayId();
void SetNativeDisplayId(uint32 modelId) { SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID, modelId); }
void setTransForm(uint32 spellid) { m_transform = spellid;}
@@ -2451,6 +2473,8 @@ public:
// Movement info
Movement::MoveSpline* movespline;
[[nodiscard]] float GetCollisionHeight() const override;
protected:
explicit Unit (bool isWorldObject);
@@ -2566,6 +2590,7 @@ private:
HostileRefManager m_HostileRefManager;
FollowerRefManager m_FollowingRefManager;
Unit* m_comboTarget;
ComboPointHolderSet m_ComboPointHolders;