refactor(Core): SetTimedFacingToObject (#23142)

This commit is contained in:
天鹭
2025-10-17 02:29:31 +08:00
committed by GitHub
parent edfc494635
commit 1946543ae2
3 changed files with 17 additions and 39 deletions

View File

@@ -20115,24 +20115,6 @@ private:
AuraType _auraType;
};
class ResetToHomeOrientation : public BasicEvent
{
public:
ResetToHomeOrientation(Creature& self) : _self(self) { }
bool Execute(uint64 /*eventTime*/, uint32 /*updateTime*/) override
{
if (_self.IsInWorld() && _self.FindMap() && _self.IsAlive() && !_self.IsInCombat())
{
_self.SetFacingTo(_self.GetHomePosition().GetOrientation());
}
return true;
}
private:
Creature& _self;
};
void Unit::CastDelayedSpellWithPeriodicAmount(Unit* caster, uint32 spellId, AuraType auraType, int32 addAmount, uint8 effectIndex)
{
AuraEffect* aurEff = nullptr;
@@ -20358,7 +20340,7 @@ void Unit::SetFacingTo(float ori)
init.Launch();
}
void Unit::SetFacingToObject(WorldObject* object)
void Unit::SetFacingToObject(WorldObject* object, Milliseconds timed /*= 0ms*/)
{
// never face when already moving
if (!IsStopped())
@@ -20369,24 +20351,20 @@ void Unit::SetFacingToObject(WorldObject* object)
init.MoveTo(GetPositionX(), GetPositionY(), GetPositionZ());
init.SetFacing(GetAngle(object)); // when on transport, GetAngle will still return global coordinates (and angle) that needs transforming
init.Launch();
}
void Unit::SetTimedFacingToObject(WorldObject* object, uint32 time)
if (timed > 0ms)
{
// never face when already moving
if (!IsStopped() || !time)
return;
/// @todo figure out under what conditions creature will move towards object instead of facing it where it currently is.
Movement::MoveSplineInit init(this);
init.MoveTo(GetPositionX(), GetPositionY(), GetPositionZ());
init.SetFacing(GetAngle(object)); // when on transport, GetAngle will still return global coordinates (and angle) that needs transforming
init.Launch();
if (Creature* c = ToCreature())
c->m_Events.AddEvent(new ResetToHomeOrientation(*c), c->m_Events.CalculateTime(time));
{
c->m_Events.AddEventAtOffset([c]()
{
if (c->IsInWorld() && c->FindMap() && c->IsAlive() && !c->IsInCombat())
c->SetFacingTo(c->GetHomePosition().GetOrientation());
}, timed);
}
else
LOG_ERROR("entities.unit", "Unit::SetTimedFacingToObject called on non-creature unit {}. This should never happen.", GetEntry());
LOG_ERROR("entities.unit", "Unit::SetFacingToObject called on non-creature unit {}. This should never happen.", GetEntry());
}
}
bool Unit::SetWalk(bool enable)

View File

@@ -1919,8 +1919,8 @@ public:
void SetInFront(WorldObject const* target);
void SetFacingTo(float ori);
void SetFacingToObject(WorldObject* object);
void SetTimedFacingToObject(WorldObject* object, uint32 time); // Reset to home orientation after given time
// <timed>Reset to home orientation after given time
void SetFacingToObject(WorldObject* object, Milliseconds timed = 0ms);
bool isInAccessiblePlaceFor(Creature const* c) const;
bool isInFrontInMap(Unit const* target, float distance, float arc = M_PI) const;

View File

@@ -1269,7 +1269,7 @@ class spell_chapter5_return_to_capital : public SpellScript
if (creature)
{
creature->PauseMovement(5000);
creature->SetTimedFacingToObject(player, 30000);
creature->SetFacingToObject(player, 30s);
if (roll_chance_i(30))
{