fix(Scripts/HyjalSummit): Adjust Doomfire Spirit movement logic. (#19469)

* Init.

Co-Authored-By: Tereneckla <Tereneckla@pm.me>

* Simplify code, add comment.

* Adjust scenario in which distance fails at all ranges.

* Remove unused variable.

* Account for deviation with distance check.

Co-Authored-By: Tereneckla <Tereneckla@pm.me>

* f

Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com>

* Rewrite with initial teleport.

* Whitespace?

* Update function type.

* Drop Doomfire spawn timer.

Verified with le sniff. Teehee.

---------

Co-authored-by: Tereneckla <Tereneckla@pm.me>
Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com>
This commit is contained in:
Benjamin Jackson
2024-07-25 19:50:15 -04:00
committed by GitHub
parent 7c68ba51e7
commit 6c97e45e87

View File

@@ -145,32 +145,35 @@ struct npc_doomfire_spirit : public ScriptedAI
{
npc_doomfire_spirit(Creature* creature) : ScriptedAI(creature){ }
float const turnConstant = 0.785402f;
float fAngle = urand(0, M_PI * 2);
float const turnConstant = 0.785402f; // 45 degree turns, verified with sniffs
void Reset() override
{
scheduler.CancelAll();
ScheduleTimedEvent(0s, [&] {
float nextOrientation = Position::NormalizeOrientation(me->GetOrientation() + irand(-1, 1) * turnConstant);
Position pos = GetFirstRandomAngleCollisionPosition(8.f, nextOrientation); // both orientation and distance verified with sniffs
me->NearTeleportTo(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), nextOrientation);
}, 1600ms);
ScheduleUniqueTimedEvent(10ms, [&] {
TryTeleportInDirection(1.f, M_PI, 1.f, true); //turns around and teleports 1 unit on spawn, assuming same logic as later teleports applies
fAngle = urand(0, M_PI * 2);
ScheduleTimedEvent(10ms, [&] {
float angle = irand(-1, 1) * turnConstant;
TryTeleportInDirection(8.f, angle, 2.f, false);
}, 1600ms);
},1);
}
Position GetFirstRandomAngleCollisionPosition(float dist, float angle)
void TryTeleportInDirection(float dist, float angle, float step, bool alwaysturn)
{
Position pos;
for (uint32 i = 0; i < 10; ++i)
while (dist >= 0)
{
pos = me->WorldObject::GetFirstCollisionPosition(dist, angle);
if (me->GetDistance(pos) > dist * 0.8f) // if at least 80% distance, good enough
if (fabsf(dist - me->GetExactDist2d(pos)) < 0.001) // Account for small deviation
break;
angle += (M_PI / 5); // else try slightly different angle
dist -= step; // Distance drops with each unsuccessful attempt
}
return pos;
if (dist || alwaysturn)
me->NearTeleportTo(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), Position::NormalizeOrientation(me->GetOrientation() + angle));
else // Orientation does not change if not moving, verified with sniffs
me->NearTeleportTo(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), me->GetOrientation());
}
void UpdateAI(uint32 diff) override
@@ -268,10 +271,10 @@ struct boss_archimonde : public BossAI
Talk(SAY_AIR_BURST);
DoCastRandomTarget(SPELL_AIR_BURST);
}, 25s, 40s);
ScheduleTimedEvent(25s, 35s, [&]
ScheduleTimedEvent(8s, [&]
{
DoCastDoomFire();
}, 20s);
}, 8s);
ScheduleTimedEvent(25s, 35s, [&]
{
DoCastRandomTarget(SPELL_GRIP_OF_THE_LEGION);
@@ -400,7 +403,7 @@ struct boss_archimonde : public BossAI
float angle = 2 * M_PI * rand() / RAND_MAX;
float x = me->GetPositionX() + DOOMFIRE_OFFSET * cos(angle);
float y = me->GetPositionY() + DOOMFIRE_OFFSET * sin(angle);
Position spiritPosition = Position(x, y, me->GetPositionZ(), angle);
Position spiritPosition = Position(x, y, me->GetPositionZ(), Position::NormalizeOrientation(angle + M_PI)); //spirit faces archimonde on spawn
Position doomfirePosition = Position(x, y, me->GetPositionZ());
if (Creature* doomfireSpirit = me->SummonCreature(CREATURE_DOOMFIRE_SPIRIT, spiritPosition, TEMPSUMMON_TIMED_DESPAWN, 27000))
{