fix(Scripts/TheEye): Al'ar phoenix spawn positions in p2 (#18504)

* wip

* wip

* finalise
This commit is contained in:
Dan
2024-03-06 20:51:51 +01:00
committed by GitHub
parent 34993a8f9f
commit 9e7c443f3c
@@ -15,6 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>. * with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <cmath>
#include "CreatureScript.h" #include "CreatureScript.h"
#include "MoveSplineInit.h" #include "MoveSplineInit.h"
#include "ScriptedCreature.h" #include "ScriptedCreature.h"
@@ -85,6 +86,8 @@ enum qruseoftheAshtongue
QUEST_RUSE_OF_THE_ASHTONGUE = 10946, QUEST_RUSE_OF_THE_ASHTONGUE = 10946,
}; };
const float INNER_CIRCLE_RADIUS = 60.0f;
struct boss_alar : public BossAI struct boss_alar : public BossAI
{ {
@@ -136,7 +139,7 @@ struct boss_alar : public BossAI
if (_noQuillTimes++ > 0) if (_noQuillTimes++ > 0)
{ {
me->SetOrientation(alarPoints[_platform].GetOrientation()); me->SetOrientation(alarPoints[_platform].GetOrientation());
SpawnPhoenixes(1, me); SpawnPhoenixes(1, me, false);
} }
me->GetMotionMaster()->MovePoint(POINT_PLATFORM, alarPoints[_platform], false, true); me->GetMotionMaster()->MovePoint(POINT_PLATFORM, alarPoints[_platform], false, true);
_platform = (_platform+1)%4; _platform = (_platform+1)%4;
@@ -244,13 +247,21 @@ struct boss_alar : public BossAI
ScheduleMainSpellAttack(0s); ScheduleMainSpellAttack(0s);
} }
void SpawnPhoenixes(uint8 count, Unit* targetToSpawnAt) void SpawnPhoenixes(uint8 count, Unit* targetToSpawnAt, bool onPosition)
{ {
if (targetToSpawnAt) if (targetToSpawnAt)
{ {
for (uint8 i = 0; i < count; ++i) for (uint8 i = 0; i < count; ++i)
{ {
me->SummonCreature(NPC_EMBER_OF_ALAR, *targetToSpawnAt, TEMPSUMMON_CORPSE_TIMED_DESPAWN, 6000); if (onPosition)
{
Position spawnPosition = DeterminePhoenixPosition(targetToSpawnAt->GetPosition());
me->SummonCreature(NPC_EMBER_OF_ALAR, spawnPosition, TEMPSUMMON_CORPSE_TIMED_DESPAWN, 6000);
}
else
{
me->SummonCreature(NPC_EMBER_OF_ALAR, *targetToSpawnAt, TEMPSUMMON_CORPSE_TIMED_DESPAWN, 6000);
}
} }
} }
} }
@@ -262,7 +273,7 @@ struct boss_alar : public BossAI
{ {
if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0, 10.0f, true)) if (Unit* target = SelectTarget(SelectTargetMethod::Random, 0, 10.0f, true))
{ {
SpawnPhoenixes(2, target); SpawnPhoenixes(2, target, true);
} }
}).Schedule(6s, [this](TaskContext) }).Schedule(6s, [this](TaskContext)
{ {
@@ -366,6 +377,36 @@ struct boss_alar : public BossAI
} }
} }
Position DeterminePhoenixPosition(Position playerPosition)
{
// set finalPosition to playerPosition in case the fraction fails
Position finalPosition = playerPosition;
float playerXPosition = playerPosition.GetPositionX();
float playerYPosition = playerPosition.GetPositionY();
float centreXPosition = alarPoints[POINT_MIDDLE].GetPositionX();
float centreYPosition = alarPoints[POINT_MIDDLE].GetPositionY();
float deltaX = std::abs(playerXPosition-centreXPosition);
float deltaY = std::abs(playerYPosition-centreYPosition);
int8 signMultiplier[2] = {1, 1};
// if fraction has x position 0.0f we get nan as a result
if (float playerFraction = deltaX/deltaY)
{
// player angle based on delta X and delta Y
float playerAngle = std::atan(playerFraction);
float phoenixDeltaYPosition = std::cos(playerAngle)*INNER_CIRCLE_RADIUS;
float phoenixDeltaXPosition = std::sin(playerAngle)*INNER_CIRCLE_RADIUS;
// as calculations are absolute values we have to multiply in the end
// should be negative if player position was further down than centre
if (playerXPosition < centreXPosition)
signMultiplier[0] = -1;
if (playerYPosition < centreYPosition)
signMultiplier[1] = -1;
// phoenix position based on set distance
finalPosition = {centreXPosition+signMultiplier[0]*phoenixDeltaXPosition, centreYPosition+signMultiplier[1]*phoenixDeltaYPosition, 0.0f, 0.0f};
}
return finalPosition;
}
private: private:
bool _canAttackCooldown; bool _canAttackCooldown;
bool _baseAttackOverride; bool _baseAttackOverride;