Skip to content

Commit

Permalink
[core] Don't rotate mobs that shouldn't always rotate during TP moves
Browse files Browse the repository at this point in the history
  • Loading branch information
WinterSolstice8 committed May 3, 2024
1 parent 3a14022 commit 59806fc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
7 changes: 2 additions & 5 deletions src/map/ai/states/ability_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ CAbilityState::CAbilityState(CBattleEntity* PEntity, uint16 targid, uint16 abili
m_PEntity->PAI->EventHandler.triggerListener("ABILITY_START", CLuaBaseEntity(m_PEntity), CLuaAbility(PAbility));

// face toward target
m_PEntity->loc.p.rotation = worldAngle(m_PEntity->loc.p, PTarget->loc.p);
m_PEntity->updatemask |= UPDATE_POS;
m_PEntity->loc.zone->UpdateEntityPacket(m_PEntity, ENTITY_UPDATE, UPDATE_POS);
battleutils::turnTowardsTarget(m_PEntity, PTarget);
}
else
{
Expand Down Expand Up @@ -118,8 +116,7 @@ bool CAbilityState::Update(time_point tick)
CBaseEntity* PTarget = GetTarget();
if (PTarget)
{
m_PEntity->loc.p.rotation = worldAngle(m_PEntity->loc.p, PTarget->loc.p);
m_PEntity->loc.zone->UpdateEntityPacket(m_PEntity, ENTITY_UPDATE, UPDATE_POS);
battleutils::turnTowardsTarget(m_PEntity, PTarget);
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/map/ai/states/mobskill_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ CMobSkillState::CMobSkillState(CBattleEntity* PEntity, uint16 targid, uint16 wsi
actionTarget.messageID = 43;
m_PEntity->loc.zone->PushPacket(m_PEntity, CHAR_INRANGE_SELF, new CActionPacket(action));

// face toward target
m_PEntity->loc.p.rotation = worldAngle(m_PEntity->loc.p, PTarget->loc.p);
m_PEntity->loc.zone->UpdateEntityPacket(m_PEntity, ENTITY_UPDATE, UPDATE_POS);
// face toward target // TODO : add force param to turnTowardsTarget on certain TP moves like Petro Eyes
battleutils::turnTowardsTarget(m_PEntity, PTarget);
}
m_PEntity->PAI->EventHandler.triggerListener("WEAPONSKILL_STATE_ENTER", CLuaBaseEntity(m_PEntity), m_PSkill->getID());
SpendCost();
Expand Down Expand Up @@ -113,14 +112,13 @@ void CMobSkillState::SpendCost()

bool CMobSkillState::Update(time_point tick)
{
// Rotate towards target during ability
// Rotate towards target during ability // TODO : add force param to turnTowardsTarget on certain TP moves like Petro Eyes
if (m_castTime > 0s && tick < GetEntryTime() + m_castTime)
{
CBaseEntity* PTarget = GetTarget();
if (PTarget)
{
m_PEntity->loc.p.rotation = worldAngle(m_PEntity->loc.p, PTarget->loc.p);
m_PEntity->loc.zone->UpdateEntityPacket(m_PEntity, ENTITY_UPDATE, UPDATE_POS);
battleutils::turnTowardsTarget(m_PEntity, PTarget);
}
}

Expand Down
23 changes: 23 additions & 0 deletions src/map/utils/battleutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5984,6 +5984,29 @@ namespace battleutils
}
}

// turn towards target unless mob behavior ignores this (but can be forced to anyway)
void turnTowardsTarget(CBaseEntity* PEntity, CBaseEntity* PTarget, bool force)
{
// Quick rejects
if (!PEntity || !PTarget)
{
return;
}

CMobEntity* PMob = dynamic_cast<CMobEntity*>(PEntity);

// Big mobs typically should ignore this -- Such as dragons/wyrms or other big things.
// Some TP moves like Petro Eyes from normal dragons _also_ ignore their standard behavior, so we must allow it sometimes.
if (PMob && (PMob->m_Behaviour & BEHAVIOUR_NO_TURN) && !force)
{
return;
}

PEntity->loc.p.rotation = worldAngle(PEntity->loc.p, PTarget->loc.p);
PEntity->updatemask |= UPDATE_POS;
PEntity->loc.zone->UpdateEntityPacket(PTarget, ENTITY_UPDATE, UPDATE_POS);
}

/************************************************************************
* *
* Get the Snapshot shot time reduction *
Expand Down
2 changes: 2 additions & 0 deletions src/map/utils/battleutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ namespace battleutils
void DoWildCardToEntity(CCharEntity* PCaster, CCharEntity* PTarget, uint8 roll);
bool DoRandomDealToEntity(CCharEntity* PChar, CCharEntity* PTarget);

void turnTowardsTarget(CBaseEntity* PEntity, CBaseEntity* PTarget, bool force = false);

void AddTraits(CBattleEntity* PEntity, TraitList_t* TraitList, uint8 level);
bool HasClaim(CBattleEntity* PEntity, CBattleEntity* PTarget);

Expand Down

0 comments on commit 59806fc

Please sign in to comment.