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

@@ -221,7 +221,7 @@ public:
void IsSummonedBy(WorldObject* summoner) override
{
if (summoner->GetTypeId() != TYPEID_UNIT)
if (!summoner->IsCreature())
{
return;
}

View File

@@ -212,7 +212,7 @@ struct ClassCallSelector : public Acore::unary_function<Unit*, bool>
bool operator()(Unit const* target) const
{
if (!_me || !target || target->GetTypeId() != TYPEID_PLAYER)
if (!_me || !target || !target->IsPlayer())
{
return false;
}
@@ -1114,7 +1114,7 @@ class spell_class_call_polymorph : public SpellScript
{
targets.remove_if([&](WorldObject const* target) -> bool
{
return target->GetTypeId() != TYPEID_PLAYER || target->ToPlayer()->IsGameMaster() || target->ToPlayer()->HasAura(SPELL_POLYMORPH);
return !target->IsPlayer() || target->ToPlayer()->IsGameMaster() || target->ToPlayer()->HasAura(SPELL_POLYMORPH);
});
if (!targets.empty())

View File

@@ -110,7 +110,7 @@ public:
bool CanAIAttack(Unit const* target) const override
{
if (target->GetTypeId() == TYPEID_UNIT && !secondPhase)
if (target->IsCreature() && !secondPhase)
{
return false;
}

View File

@@ -587,7 +587,7 @@ class spell_hate_to_zero : public SpellScript
bool Load() override
{
return GetCaster()->GetTypeId() == TYPEID_UNIT;
return GetCaster()->IsCreature();
}
void HandleHit(SpellEffIndex /*effIndex*/)

View File

@@ -129,7 +129,7 @@ class spell_mc_play_dead_aura : public AuraScript
bool Load() override
{
return GetCaster()->GetTypeId() == TYPEID_UNIT;
return GetCaster()->IsCreature();
}
void HandleEffectApply(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)

View File

@@ -155,7 +155,7 @@ struct boss_priestess_delrissa : public ScriptedAI
void KilledUnit(Unit* victim) override
{
if (victim->GetTypeId() != TYPEID_PLAYER)
if (!victim->IsPlayer())
return;
if (PlayersKilled < SAY_DEATH)

View File

@@ -678,7 +678,7 @@ public:
void MoveInLineOfSight(Unit* who) override
{
if (PlayerGUID || who->GetTypeId() != TYPEID_PLAYER || !who->IsWithinDist(me, INTERACTION_DISTANCE))
if (PlayerGUID || !who->IsPlayer() || !who->IsWithinDist(me, INTERACTION_DISTANCE))
return;
if (MeetQuestCondition(who->ToPlayer()))

View File

@@ -458,7 +458,7 @@ public:
{
Position pos = LightOfDawnFightPos[urand(0, 9)];
if (Unit* target = cr->SelectNearbyTarget(nullptr, 10.0f))
if (target->GetTypeId() == TYPEID_UNIT)
if (target->IsCreature())
target->GetMotionMaster()->MoveCharge(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), me->GetSpeed(MOVE_RUN));
cr->GetMotionMaster()->MoveCharge(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), me->GetSpeed(MOVE_RUN));
}

View File

@@ -389,7 +389,7 @@ public:
void IsSummonedBy(WorldObject* summoner) override
{
if (summoner->GetTypeId() != TYPEID_UNIT)
if (!summoner->IsCreature())
{
return;
}

View File

@@ -64,7 +64,7 @@ public:
void OnUnitDeath(Unit* unit) override
{
if (unit->GetTypeId() == TYPEID_UNIT && unit->GetCreatureType() == CREATURE_TYPE_DRAGONKIN && unit->GetEntry() != NPC_SHADE_OF_ERANIKUS)
if (unit->IsCreature() && unit->GetCreatureType() == CREATURE_TYPE_DRAGONKIN && unit->GetEntry() != NPC_SHADE_OF_ERANIKUS)
_dragonkinList.remove(unit->GetGUID());
if (unit->GetEntry() == NPC_JAMMAL_AN_THE_PROPHET)
{

View File

@@ -533,7 +533,7 @@ class DoorsGuidCheck
public:
bool operator()(WorldObject* object) const
{
if (object->GetTypeId() != TYPEID_UNIT)
if (!object->IsCreature())
return true;
Creature* cr = object->ToCreature();

View File

@@ -1088,7 +1088,7 @@ class spell_kiljaeden_sinister_reflection_clone : public SpellScript
WorldObject* target = targets.front();
targets.clear();
if (target && target->GetTypeId() == TYPEID_UNIT)
if (target && target->IsCreature())
{
target->ToCreature()->AI()->SetData(1, GetCaster()->getClass());
targets.push_back(target);
@@ -1133,7 +1133,7 @@ class spell_kiljaeden_darkness_aura : public AuraScript
void HandleRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
{
if (GetUnitOwner()->GetTypeId() == TYPEID_UNIT)
if (GetUnitOwner()->IsCreature())
GetUnitOwner()->ToCreature()->AI()->DoAction(ACTION_NO_KILL_TALK);
GetUnitOwner()->CastSpell(GetUnitOwner(), SPELL_DARKNESS_OF_A_THOUSAND_SOULS_DAMAGE, true);

View File

@@ -393,7 +393,7 @@ class spell_entropius_negative_energy : public SpellScript
bool Load() override
{
return GetCaster()->GetTypeId() == TYPEID_UNIT;
return GetCaster()->IsCreature();
}
void FilterTargets(std::list<WorldObject*>& targets)

View File

@@ -183,7 +183,7 @@ public:
bool Load() override
{
return GetUnitOwner()->GetTypeId() == TYPEID_UNIT && GetUnitOwner()->GetMapId() == MAP_ULDAMAN;
return GetUnitOwner()->IsCreature() && GetUnitOwner()->GetMapId() == MAP_ULDAMAN;
}
void HandleEffectApply(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)

View File

@@ -209,7 +209,7 @@ public:
void KilledUnit(Unit* victim) override
{
if (victim->GetTypeId() != TYPEID_PLAYER)
if (!victim->IsPlayer())
return;
reviveGUID = victim->GetGUID();
@@ -449,7 +449,7 @@ public:
{
if (!me || !target)
return false;
if (target->GetTypeId() != TYPEID_PLAYER || !me->IsWithinLOSInMap(target))
if (!target->IsPlayer() || !me->IsWithinLOSInMap(target))
return false;
return true;
}))
@@ -540,7 +540,7 @@ public:
void JustEngagedWith(Unit* who) override
{
if (who->GetTypeId() != TYPEID_PLAYER)
if (!who->IsPlayer())
return;
_scheduler.Schedule(6s, 12s, [this](TaskContext context)
@@ -557,7 +557,7 @@ public:
void KilledUnit(Unit* victim) override
{
if (victim->GetTypeId() != TYPEID_PLAYER)
if (!victim->IsPlayer())
return;
reviveGUID = victim->GetGUID();

View File

@@ -217,7 +217,7 @@ private:
{
Unit* target = SelectTarget(SelectTargetMethod::Random, 0, [this](Unit* target) -> bool
{
if (target->GetTypeId() != TYPEID_PLAYER || target->getPowerType() != Powers::POWER_MANA)
if (!target->IsPlayer() || target->getPowerType() != Powers::POWER_MANA)
return false;
if (me->IsWithinMeleeRange(target) || me->GetVictim() == target)
return false;

View File

@@ -239,7 +239,7 @@ public:
{
if (Unit* summoner = me->ToTempSummon()->GetSummonerUnit())
{
if (summoner->GetTypeId() == TYPEID_UNIT && summoner->IsAlive() && !summoner->IsInCombat())
if (summoner->IsCreature() && summoner->IsAlive() && !summoner->IsInCombat())
summoner->ToCreature()->AI()->AttackStart(who);
}
}
@@ -253,7 +253,7 @@ public:
{
if (Unit* summoner = me->ToTempSummon()->GetSummonerUnit())
{
if (summoner->GetTypeId() == TYPEID_UNIT && summoner->IsAlive())
if (summoner->IsCreature() && summoner->IsAlive())
summoner->ToCreature()->DisappearAndDie();
}
}
@@ -267,7 +267,7 @@ public:
if (me->IsSummon())
{
Unit* summoner = me->ToTempSummon()->GetSummonerUnit();
if (summoner && summoner->GetTypeId() == TYPEID_UNIT && summoner->IsAIEnabled)
if (summoner && summoner->IsCreature() && summoner->IsAIEnabled)
{
npc_lord_gregor_lescovar::npc_lord_gregor_lescovarAI* ai =
CAST_AI(npc_lord_gregor_lescovar::npc_lord_gregor_lescovarAI, summoner->GetAI());

View File

@@ -140,7 +140,7 @@ public:
void MoveInLineOfSight(Unit* who) override
{
if (!who || who->GetTypeId() != TYPEID_PLAYER)
if (!who || !who->IsPlayer())
return;
if (me->FindNearestGameObject(GO_BEACON_TORCH, 10.0f))