refactor(Core): Make more use of helpers. (#19835)

* Init.

* Reword.

* Update codestyle script.

Co-Authored-By: Kitzunu <24550914+Kitzunu@users.noreply.github.com>

* Add gameobject type ID check, reorder checks.

* Add helper/codestyle check for unit type.

* `IsUnit()` -> `IsCreature()`

* Add `IsUnit()` method.

* Use type mask.

https: //github.com/TrinityCore/TrinityCore/commit/cc71da35b5dc74abf71f8691161525a23d870bb5
Co-Authored-By: Giacomo Pozzoni <giacomopoz@gmail.com>
Co-Authored-By: Ovahlord <18347559+Ovahlord@users.noreply.github.com>

* Replace instances of `isType` with `IsUnit`.

---------

Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com>
Co-authored-by: Giacomo Pozzoni <giacomopoz@gmail.com>
Co-authored-by: Ovahlord <18347559+Ovahlord@users.noreply.github.com>
This commit is contained in:
Benjamin Jackson
2024-09-03 13:41:31 -04:00
committed by GitHub
parent e3e4133e88
commit 1edac37ac3
165 changed files with 725 additions and 719 deletions

View File

@@ -244,7 +244,7 @@ void MotionMaster::MoveRandom(float wanderDistance)
if (_owner->HasUnitFlag(UNIT_FLAG_DISABLE_MOVE))
return;
if (_owner->GetTypeId() == TYPEID_UNIT)
if (_owner->IsCreature())
{
LOG_DEBUG("movement.motionmaster", "Creature ({}) start moving random", _owner->GetGUID().ToString());
Mutate(new RandomMovementGenerator<Creature>(wanderDistance), MOTION_SLOT_IDLE);
@@ -260,12 +260,12 @@ void MotionMaster::MoveTargetedHome(bool walk /*= false*/)
{
Clear(false);
if (_owner->GetTypeId() == TYPEID_UNIT && !_owner->ToCreature()->GetCharmerOrOwnerGUID())
if (_owner->IsCreature() && !_owner->ToCreature()->GetCharmerOrOwnerGUID())
{
LOG_DEBUG("movement.motionmaster", "Creature ({}) targeted home", _owner->GetGUID().ToString());
Mutate(new HomeMovementGenerator<Creature>(walk), MOTION_SLOT_ACTIVE);
}
else if (_owner->GetTypeId() == TYPEID_UNIT && _owner->ToCreature()->GetCharmerOrOwnerGUID())
else if (_owner->IsCreature() && _owner->ToCreature()->GetCharmerOrOwnerGUID())
{
_owner->ClearUnitState(UNIT_STATE_EVADE);
@@ -645,7 +645,7 @@ void MotionMaster::MoveFall(uint32 id /*=0*/, bool addFlagForNPC)
_owner->m_movementInfo.SetFallTime(0);
_owner->ToPlayer()->SetFallInformation(GameTime::GetGameTime().count(), _owner->GetPositionZ());
}
else if (_owner->GetTypeId() == TYPEID_UNIT && addFlagForNPC) // pussywizard
else if (_owner->IsCreature() && addFlagForNPC) // pussywizard
{
_owner->RemoveUnitMovementFlag(MOVEMENTFLAG_MASK_MOVING);
_owner->RemoveUnitMovementFlag(MOVEMENTFLAG_FLYING | MOVEMENTFLAG_CAN_FLY);

View File

@@ -72,7 +72,7 @@ bool RotateMovementGenerator::Update(Unit* owner, uint32 diff)
void RotateMovementGenerator::Finalize(Unit* unit)
{
unit->ClearUnitState(UNIT_STATE_ROTATING);
if (unit->GetTypeId() == TYPEID_UNIT)
if (unit->IsCreature())
unit->ToCreature()->AI()->MovementInform(ROTATE_MOTION_TYPE, 0);
}
@@ -90,7 +90,7 @@ void DistractMovementGenerator::Finalize(Unit* owner)
owner->ClearUnitState(UNIT_STATE_DISTRACTED);
// If this is a creature, then return orientation to original position (for idle movement creatures)
if (owner->GetTypeId() == TYPEID_UNIT && owner->ToCreature())
if (owner->IsCreature() && owner->ToCreature())
{
float angle = owner->ToCreature()->GetHomePosition().GetOrientation();
owner->SetFacingTo(angle);

View File

@@ -636,7 +636,7 @@ void PathGenerator::CreateFilter()
uint16 includeFlags = 0;
uint16 excludeFlags = 0;
if (_source->GetTypeId() == TYPEID_UNIT)
if (_source->IsCreature())
{
Creature* creature = (Creature*)_source;
if (creature->CanWalk())

View File

@@ -231,10 +231,10 @@ bool EffectMovementGenerator::Update(Unit* unit, uint32)
void EffectMovementGenerator::Finalize(Unit* unit)
{
if (unit->GetTypeId() != TYPEID_UNIT)
if (!unit->IsCreature())
return;
if (unit->GetTypeId() == TYPEID_UNIT && unit->HasUnitMovementFlag(MOVEMENTFLAG_FALLING) && unit->movespline->isFalling()) // pussywizard
if (unit->IsCreature() && unit->HasUnitMovementFlag(MOVEMENTFLAG_FALLING) && unit->movespline->isFalling()) // pussywizard
unit->RemoveUnitMovementFlag(MOVEMENTFLAG_FALLING);
// Need restore previous movement since we have no proper states system

View File

@@ -305,7 +305,7 @@ void ChaseMovementGenerator<T>::DoReset(T* owner)
template<class T>
void ChaseMovementGenerator<T>::MovementInform(T* owner)
{
if (owner->GetTypeId() != TYPEID_UNIT)
if (!owner->IsCreature())
return;
// Pass back the GUIDLow of the target. If it is pet's owner then PetAI will handle
@@ -385,7 +385,7 @@ bool FollowMovementGenerator<T>::PositionOkay(Unit* target, bool isPlayerPet, bo
float exactDistSq = target->GetExactDistSq(_lastTargetPosition->GetPositionX(), _lastTargetPosition->GetPositionY(), _lastTargetPosition->GetPositionZ());
float distanceTolerance = 0.25f;
// For creatures, increase tolerance
if (target->GetTypeId() == TYPEID_UNIT)
if (target->IsCreature())
{
distanceTolerance += _range + _range;
}
@@ -554,7 +554,7 @@ void FollowMovementGenerator<T>::DoReset(T* owner)
template<class T>
void FollowMovementGenerator<T>::MovementInform(T* owner)
{
if (owner->GetTypeId() != TYPEID_UNIT)
if (!owner->IsCreature())
return;
// Pass back the GUIDLow of the target. If it is pet's owner then PetAI will handle