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

@@ -197,7 +197,7 @@ public:
void KilledUnit(Unit* victim) override
{
if (victim->GetTypeId() != TYPEID_PLAYER)
if (!victim->IsPlayer())
return;
Talk(SAY_SLAY);

View File

@@ -132,7 +132,7 @@ public:
void KilledUnit(Unit* victim) override
{
if (victim->GetTypeId() != TYPEID_PLAYER)
if (!victim->IsPlayer())
return;
Talk(SAY_SLAY);

View File

@@ -162,7 +162,7 @@ public:
void KilledUnit(Unit* victim) override
{
if (victim->GetTypeId() != TYPEID_PLAYER)
if (!victim->IsPlayer())
return;
Talk(SAY_SLAY);

View File

@@ -183,7 +183,7 @@ public:
void KilledUnit(Unit* victim) override
{
if (victim->GetTypeId() != TYPEID_PLAYER)
if (!victim->IsPlayer())
return;
Talk(SAY_SLAY);

View File

@@ -401,7 +401,7 @@ public:
void KilledUnit(Unit* victim) override
{
if (victim->GetTypeId() != TYPEID_PLAYER || urand(0, 2))
if (!victim->IsPlayer() || urand(0, 2))
return;
Talk(SAY_ALGALON_KILL);
@@ -1018,7 +1018,7 @@ public:
void SpellHit(Unit* caster, SpellInfo const* spell) override
{
if (spell->Id != SPELL_CONSTELLATION_PHASE_EFFECT || caster->GetTypeId() != TYPEID_UNIT)
if (spell->Id != SPELL_CONSTELLATION_PHASE_EFFECT || !caster->IsCreature())
return;
if (InstanceScript* instance = me->GetInstanceScript())

View File

@@ -310,7 +310,7 @@ public:
void KilledUnit(Unit* who) override
{
if (who->GetTypeId() != TYPEID_PLAYER)
if (!who->IsPlayer())
return;
if (_phase == 3)
@@ -488,7 +488,7 @@ public:
void KilledUnit(Unit* who) override
{
if (who->GetTypeId() != TYPEID_PLAYER)
if (!who->IsPlayer())
return;
Talk(SAY_MOLGEIM_SLAY);
@@ -706,7 +706,7 @@ public:
void KilledUnit(Unit* who) override
{
if (who->GetTypeId() != TYPEID_PLAYER || urand(0, 2))
if (!who->IsPlayer() || urand(0, 2))
return;
Talk(SAY_BRUNDIR_SLAY);

View File

@@ -194,7 +194,7 @@ public:
void KilledUnit(Unit* victim) override
{
if (victim->GetTypeId() != TYPEID_PLAYER || urand(0, 2))
if (!victim->IsPlayer() || urand(0, 2))
return;
Talk(SAY_SLAY);

View File

@@ -447,7 +447,7 @@ public:
case EVENT_REINSTALL:
for (uint8 i = RAID_MODE(0, 2); i < 4; ++i)
if (Unit* seat = vehicle->GetPassenger(i))
if (seat->GetTypeId() == TYPEID_UNIT)
if (seat->IsCreature())
seat->ToCreature()->AI()->EnterEvadeMode();
Talk(FLAME_LEVIATHAN_EMOTE_REACTIVATE);
return;
@@ -758,7 +758,7 @@ public:
void PassengerBoarded(Unit* who, int8 seatId, bool apply) override
{
if (who->GetTypeId() != TYPEID_PLAYER || !me->GetVehicle())
if (!who->IsPlayer() || !me->GetVehicle())
return;
who->ApplySpellImmune(63847, IMMUNITY_ID, 63847, apply); // SPELL_FLAME_VENTS_TRIGGER
@@ -780,7 +780,7 @@ public:
{
turret->ReplaceAllUnitFlags(UNIT_FLAG_NOT_SELECTABLE);
turret->SetImmuneToAll(true);
if (turret->GetTypeId() == TYPEID_UNIT)
if (turret->IsCreature())
turret->ToCreature()->AI()->EnterEvadeMode();
}
}
@@ -829,7 +829,7 @@ public:
bool CanAIAttack(Unit const* who) const override
{
if (!who || who->GetTypeId() != TYPEID_PLAYER || !who->GetVehicle() || who->GetVehicleBase()->GetEntry() != NPC_SEAT)
if (!who || !who->IsPlayer() || !who->GetVehicle() || who->GetVehicleBase()->GetEntry() != NPC_SEAT)
return false;
return true;
}
@@ -1231,7 +1231,7 @@ public:
{
if (!_lock)
{
if (who->GetTypeId() != TYPEID_PLAYER && !who->IsVehicle())
if (!who->IsPlayer() && !who->IsVehicle())
return;
// MIMIRON
@@ -1753,7 +1753,7 @@ class spell_vehicle_grab_pyrite : public SpellScript
GetCaster()->CastSpell(parent, SPELL_ADD_PYRITE, true);
target->CastSpell(seat, GetEffectValue());
if (target->GetTypeId() == TYPEID_UNIT)
if (target->IsCreature())
target->ToCreature()->DespawnOrUnsummon(1300);
}
}
@@ -1927,7 +1927,7 @@ class spell_demolisher_ride_vehicle : public SpellScript
SpellCastResult CheckCast()
{
if (GetCaster()->GetTypeId() != TYPEID_PLAYER)
if (!GetCaster()->IsPlayer())
return SPELL_CAST_OK;
Unit* target = this->GetExplTargetUnit();

View File

@@ -307,7 +307,7 @@ public:
void KilledUnit(Unit* victim) override
{
if (victim->GetTypeId() != TYPEID_PLAYER || urand(0, 2))
if (!victim->IsPlayer() || urand(0, 2))
return;
Talk(SAY_SLAY);

View File

@@ -486,7 +486,7 @@ class spell_aura_of_despair_aura : public AuraScript
if (Unit* caster = GetCaster())
if (Unit* target = GetTarget())
{
if (target->GetTypeId() != TYPEID_PLAYER)
if (!target->IsPlayer())
return;
target->CastSpell(target, SPELL_AURA_OF_DESPAIR_2, true);
@@ -614,7 +614,7 @@ public:
bool OnCheck(Player* /*player*/, Unit* target, uint32 /*criteria_id*/) override
{
return target && target->GetEntry() == NPC_VEZAX && target->GetTypeId() == TYPEID_UNIT && target->ToCreature()->AI()->GetData(1);
return target && target->GetEntry() == NPC_VEZAX && target->IsCreature() && target->ToCreature()->AI()->GetData(1);
}
};
@@ -625,7 +625,7 @@ public:
bool OnCheck(Player* /*player*/, Unit* target, uint32 /*criteria_id*/) override
{
return target && target->GetEntry() == NPC_VEZAX && target->GetTypeId() == TYPEID_UNIT && target->ToCreature()->AI()->GetData(2);
return target && target->GetEntry() == NPC_VEZAX && target->IsCreature() && target->ToCreature()->AI()->GetData(2);
}
};

View File

@@ -578,7 +578,7 @@ public:
{
if (t->IsPlayer())
return !t->HasAura(SPELL_FLASH_FREEZE_TRAPPED_PLAYER);
else if (t->GetTypeId() == TYPEID_UNIT)
else if (t->IsCreature())
return !t->HasAura(SPELL_FLASH_FREEZE_TRAPPED_NPC);
return true;
@@ -702,7 +702,7 @@ public:
{
if (Unit* s = me->ToTempSummon()->GetSummonerUnit())
{
if ((s->IsPlayer() && !s->HasAura(SPELL_FLASH_FREEZE_TRAPPED_PLAYER)) || (s->GetTypeId() == TYPEID_UNIT && !s->HasAura(SPELL_FLASH_FREEZE_TRAPPED_NPC)))
if ((s->IsPlayer() && !s->HasAura(SPELL_FLASH_FREEZE_TRAPPED_PLAYER)) || (s->IsCreature() && !s->HasAura(SPELL_FLASH_FREEZE_TRAPPED_NPC)))
me->DespawnOrUnsummon(2000);
else if (s->IsPlayer())
if (InstanceScript* instanceScript = me->GetInstanceScript())
@@ -1354,14 +1354,14 @@ class spell_hodir_flash_freeze_aura : public AuraScript
{
Unit* target = GetTarget();
Unit* caster = GetCaster();
if (!target || !caster || caster->GetTypeId() != TYPEID_UNIT)
if (!target || !caster || !caster->IsCreature())
return;
if (Aura* aur = target->GetAura(target->IsPlayer() ? SPELL_FLASH_FREEZE_TRAPPED_PLAYER : SPELL_FLASH_FREEZE_TRAPPED_NPC))
{
if (Unit* caster2 = aur->GetCaster())
{
if (caster2->GetTypeId() == TYPEID_UNIT)
if (caster2->IsCreature())
{
caster2->ToCreature()->DespawnOrUnsummon();
}
@@ -1378,7 +1378,7 @@ class spell_hodir_flash_freeze_aura : public AuraScript
caster->ToCreature()->AI()->JustSummoned(c);
}
}
else if (target->GetTypeId() == TYPEID_UNIT)
else if (target->IsCreature())
{
if( Creature* c = target->SummonCreature(NPC_FLASH_FREEZE_NPC, target->GetPositionX(), target->GetPositionY(), target->GetPositionZ(), 0.0f, TEMPSUMMON_CORPSE_TIMED_DESPAWN, 2000) )
{
@@ -1483,7 +1483,7 @@ public:
bool OnCheck(Player* /*player*/, Unit* target, uint32 /*criteria_id*/) override
{
return target && target->GetEntry() == NPC_HODIR && target->GetTypeId() == TYPEID_UNIT && target->ToCreature()->AI()->GetData(1);
return target && target->GetEntry() == NPC_HODIR && target->IsCreature() && target->ToCreature()->AI()->GetData(1);
}
};
@@ -1494,7 +1494,7 @@ public:
bool OnCheck(Player* /*player*/, Unit* target, uint32 /*criteria_id*/) override
{
return target && target->GetEntry() == NPC_HODIR && target->GetTypeId() == TYPEID_UNIT && target->ToCreature()->AI()->GetData(2);
return target && target->GetEntry() == NPC_HODIR && target->IsCreature() && target->ToCreature()->AI()->GetData(2);
}
};
@@ -1505,7 +1505,7 @@ public:
bool OnCheck(Player* /*player*/, Unit* target, uint32 /*criteria_id*/) override
{
return target && target->GetEntry() == NPC_HODIR && target->GetTypeId() == TYPEID_UNIT && target->ToCreature()->AI()->GetData(3);
return target && target->GetEntry() == NPC_HODIR && target->IsCreature() && target->ToCreature()->AI()->GetData(3);
}
};
@@ -1516,7 +1516,7 @@ public:
bool OnCheck(Player* /*player*/, Unit* target, uint32 /*criteria_id*/) override
{
return target && target->GetEntry() == NPC_HODIR && target->GetTypeId() == TYPEID_UNIT && target->ToCreature()->AI()->GetData(4);
return target && target->GetEntry() == NPC_HODIR && target->IsCreature() && target->ToCreature()->AI()->GetData(4);
}
};

View File

@@ -542,7 +542,7 @@ public:
bool OnCheck(Player* /*player*/, Unit* target, uint32 /*criteria_id*/) override
{
if (!target || target->GetTypeId() != TYPEID_UNIT)
if (!target || !target->IsCreature())
return false;
return !!target->ToCreature()->AI()->GetData(1337);
}

View File

@@ -707,7 +707,7 @@ public:
if (target == _victim && _me->GetThreatMgr().GetThreatListSize() > 1)
return true;
if (target->GetTypeId() != TYPEID_PLAYER)
if (!target->IsPlayer())
return true;
return false;
@@ -724,7 +724,7 @@ class spell_ulduar_stone_grip_cast_target : public SpellScript
bool Load() override
{
if (GetCaster()->GetTypeId() != TYPEID_UNIT)
if (!GetCaster()->IsCreature())
return false;
return true;
}

View File

@@ -1342,7 +1342,7 @@ public:
if( Vehicle* vk = me->GetVehicleKit() )
for (uint8 i = 0; i < 2; ++i)
if (Unit* r = vk->GetPassenger(5 + i))
if (r->GetTypeId() == TYPEID_UNIT)
if (r->IsCreature())
r->ToCreature()->DespawnOrUnsummon(1);
}
@@ -1438,7 +1438,7 @@ public:
exitPos.m_positionZ += 2.0f * Phase;
r->_ExitVehicle(&exitPos);
me->RemoveAurasByType(SPELL_AURA_CONTROL_VEHICLE, r->GetGUID());
if (r->GetTypeId() == TYPEID_UNIT)
if (r->IsCreature())
r->ToCreature()->AI()->SetData(0, 0);
}
}
@@ -2155,7 +2155,7 @@ class spell_mimiron_p3wx2_laser_barrage_aura : public AuraScript
{
if (Unit* caster = GetCaster())
{
if (caster->GetTypeId() != TYPEID_UNIT)
if (!caster->IsCreature())
return;
uint32 diff = getMSTimeDiff(_lastMSTime, GameTime::GetGameTimeMS().count());
if (_lastOrientation == -1.0f)
@@ -2466,7 +2466,7 @@ public:
bool OnCheck(Player* /*player*/, Unit* target, uint32 /*criteria_id*/) override
{
return target && target->GetEntry() == NPC_MIMIRON && target->GetTypeId() == TYPEID_UNIT && target->ToCreature()->AI()->GetData(1);
return target && target->GetEntry() == NPC_MIMIRON && target->IsCreature() && target->ToCreature()->AI()->GetData(1);
}
};
@@ -2477,7 +2477,7 @@ public:
bool OnCheck(Player* /*player*/, Unit* target, uint32 /*criteria_id*/) override
{
return target && target->GetEntry() == NPC_MIMIRON && target->GetTypeId() == TYPEID_UNIT && !target->ToCreature()->AI()->GetData(11);
return target && target->GetEntry() == NPC_MIMIRON && target->IsCreature() && !target->ToCreature()->AI()->GetData(11);
}
};
@@ -2488,7 +2488,7 @@ public:
bool OnCheck(Player* /*player*/, Unit* target, uint32 /*criteria_id*/) override
{
return target && target->GetEntry() == NPC_MIMIRON && target->GetTypeId() == TYPEID_UNIT && !target->ToCreature()->AI()->GetData(12);
return target && target->GetEntry() == NPC_MIMIRON && target->IsCreature() && !target->ToCreature()->AI()->GetData(12);
}
};
@@ -2499,7 +2499,7 @@ public:
bool OnCheck(Player* /*player*/, Unit* target, uint32 /*criteria_id*/) override
{
return target && target->GetEntry() == NPC_MIMIRON && target->GetTypeId() == TYPEID_UNIT && !target->ToCreature()->AI()->GetData(13);
return target && target->GetEntry() == NPC_MIMIRON && target->IsCreature() && !target->ToCreature()->AI()->GetData(13);
}
};

View File

@@ -711,7 +711,7 @@ public:
if (_introSpoken)
return;
if (who->GetTypeId() != TYPEID_PLAYER || me->GetExactDist2d(who) > 15.0f)
if (!who->IsPlayer() || me->GetExactDist2d(who) > 15.0f)
return;
_introSpoken = true;
@@ -1153,7 +1153,7 @@ public:
bool OnCheck(Player* /*player*/, Unit* target, uint32 /*criteria_id*/) override
{
return target && target->GetTypeId() == TYPEID_UNIT && target->GetEntry() == NPC_RAZORSCALE && target->ToCreature()->AI()->GetData(1);
return target && target->IsCreature() && target->GetEntry() == NPC_RAZORSCALE && target->ToCreature()->AI()->GetData(1);
}
};

View File

@@ -427,7 +427,7 @@ public:
{
summons.Summon(cr);
if (Unit* owner = me->GetVehicleBase())
if (owner->GetTypeId() == TYPEID_UNIT)
if (owner->IsCreature())
owner->ToCreature()->AI()->JustSummoned(cr);
}
void DamageTaken(Unit*, uint32& damage, DamageEffectType, SpellSchoolMask) override

View File

@@ -1103,7 +1103,7 @@ public:
if (Creature* algalon = instance->GetCreature(m_uiAlgalonGUID))
algalon->AI()->DoAction(ACTION_FEEDS_ON_TEARS_FAILED);
}
else if (unit->GetTypeId() == TYPEID_UNIT && unit->GetAreaId() == 4656 /*Conservatory of Life*/)
else if (unit->IsCreature() && unit->GetAreaId() == 4656 /*Conservatory of Life*/)
{
if (GameTime::GetGameTime().count() > (m_conspeedatoryAttempt + DAY))
{