fix(Core): Boss encounter disengage improvement (#4954)

This commit is contained in:
Cláudio Costa
2021-04-06 13:15:56 +01:00
committed by GitHub
parent c0cb2eae38
commit 042cec82f4
2 changed files with 53 additions and 17 deletions

View File

@@ -197,6 +197,51 @@ struct ScriptedAI : public CreatureAI
// Called when AI is temporarily replaced or put back when possess is applied or removed
void OnPossess(bool /*apply*/) {}
enum class Axis
{
AXIS_X,
AXIS_Y
};
/* This is called for bosses whenever an encounter is happening.
* - Arguments:
* - Position has to be passed as a constant pointer (&Position)
* - Axis is the X or Y axis that is used to decide the position threshold
* - Above decides if the boss position should be above the passed position
* or below.
* Example:
* Hodir is in room until his Y position is below the Door position:
* IsInRoom(doorPosition, AXIS_Y, false);
*/
bool IsInRoom(const Position* pos, Axis axis, bool above)
{
if (!pos)
{
return true;
}
switch (axis)
{
case Axis::AXIS_X:
if ((!above && me->GetPositionX() < pos->GetPositionX()) || me->GetPositionX() > pos->GetPositionX())
{
EnterEvadeMode();
return false;
}
break;
case Axis::AXIS_Y:
if ((!above && me->GetPositionY() < pos->GetPositionY()) || me->GetPositionY() > pos->GetPositionY())
{
EnterEvadeMode();
return false;
}
break;
}
return true;
}
// *************
// Variables
// *************