Skip to content

Commit 1edac37

Browse files
heyitsbenchKitzunujackpozOvahlord
authored
refactor(Core): Make more use of helpers. (azerothcore#19835)
* Init. * Reword. * Update codestyle script. Co-Authored-By: Kitzunu <[email protected]> * 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 <[email protected]> Co-Authored-By: Ovahlord <[email protected]> * Replace instances of `isType` with `IsUnit`. --------- Co-authored-by: Kitzunu <[email protected]> Co-authored-by: Giacomo Pozzoni <[email protected]> Co-authored-by: Ovahlord <[email protected]>
1 parent e3e4133 commit 1edac37

File tree

165 files changed

+725
-719
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+725
-719
lines changed

apps/codestyle/codestyle.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,20 @@ def get_typeid_check(file: io, file_path: str) -> None:
108108
check_failed = False
109109
# Parse all the file
110110
for line_number, line in enumerate(file, start = 1):
111-
if 'GetTypeId() == TYPEID_PLAYER' in line:
112-
print(f"Please use IsPlayer() instead GetTypeId(): {file_path} at line {line_number}")
111+
if 'GetTypeId() == TYPEID_ITEM' in line or 'GetTypeId() != TYPEID_ITEM' in line:
112+
print(f"Please use IsItem() instead of GetTypeId(): {file_path} at line {line_number}")
113113
check_failed = True
114-
if 'GetTypeId() == TYPEID_ITEM' in line:
115-
print(f"Please use IsItem() instead GetTypeId(): {file_path} at line {line_number}")
114+
if 'GetTypeId() == TYPEID_UNIT' in line or 'GetTypeId() != TYPEID_UNIT' in line:
115+
print(f"Please use IsCreature() instead of GetTypeId(): {file_path} at line {line_number}")
116116
check_failed = True
117-
if 'GetTypeId() == TYPEID_DYNOBJECT' in line:
118-
print(f"Please use IsDynamicObject() instead GetTypeId(): {file_path} at line {line_number}")
117+
if 'GetTypeId() == TYPEID_PLAYER' in line or 'GetTypeId() != TYPEID_PLAYER' in line:
118+
print(f"Please use IsPlayer() instead of GetTypeId(): {file_path} at line {line_number}")
119+
check_failed = True
120+
if 'GetTypeId() == TYPEID_GAMEOBJECT' in line or 'GetTypeId() != TYPEID_GAMEOBJECT' in line:
121+
print(f"Please use IsGameObject() instead of GetTypeId(): {file_path} at line {line_number}")
122+
check_failed = True
123+
if 'GetTypeId() == TYPEID_DYNOBJECT' in line or 'GetTypeId() != TYPEID_DYNOBJECT' in line:
124+
print(f"Please use IsDynamicObject() instead of GetTypeId(): {file_path} at line {line_number}")
119125
check_failed = True
120126
# Handle the script error and update the result output
121127
if check_failed:

src/server/game/AI/CoreAI/PassiveAI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void PossessedAI::JustDied(Unit* /*u*/)
6565
void PossessedAI::KilledUnit(Unit* /*victim*/)
6666
{
6767
// We killed a creature, disable victim's loot
68-
//if (victim->GetTypeId() == TYPEID_UNIT)
68+
//if (victim->IsCreature())
6969
// victim->RemoveDynamicFlag(UNIT_DYNFLAG_LOOTABLE);
7070
}
7171

src/server/game/AI/CoreAI/PetAI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ void PetAI::DoAttack(Unit* target, bool chase)
613613

614614
if (_canMeleeAttack())
615615
{
616-
float angle = combatRange == 0.f && target->GetTypeId() != TYPEID_PLAYER && !target->IsPet() ? float(M_PI) : 0.f;
616+
float angle = combatRange == 0.f && !target->IsPlayer() && !target->IsPet() ? float(M_PI) : 0.f;
617617
float tolerance = combatRange == 0.f ? float(M_PI_4) : float(M_PI * 2);
618618
me->GetMotionMaster()->MoveChase(target, ChaseRange(0.f, combatRange), ChaseAngle(angle, tolerance));
619619
}

src/server/game/AI/CoreAI/UnitAI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ bool NonTankTargetSelector::operator()(Unit const* target) const
427427
if (!target)
428428
return false;
429429

430-
if (_playerOnly && target->GetTypeId() != TYPEID_PLAYER)
430+
if (_playerOnly && !target->IsPlayer())
431431
return false;
432432

433433
if (Unit* currentVictim = _source->GetThreatMgr().GetCurrentVictim())

src/server/game/AI/CoreAI/UnitAI.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct DefaultTargetSelector : public Acore::unary_function<Unit*, bool>
7676
if (target == except)
7777
return false;
7878

79-
if (m_playerOnly && (target->GetTypeId() != TYPEID_PLAYER))
79+
if (m_playerOnly && (!target->IsPlayer()))
8080
return false;
8181

8282
if (m_dist > 0.0f && !me->IsWithinCombatRange(target, m_dist))
@@ -148,7 +148,7 @@ struct PowerUsersSelector : public Acore::unary_function<Unit*, bool>
148148
if (target->getPowerType() != _power)
149149
return false;
150150

151-
if (_playerOnly && target->GetTypeId() != TYPEID_PLAYER)
151+
if (_playerOnly && !target->IsPlayer())
152152
return false;
153153

154154
if (_dist > 0.0f && !_me->IsWithinCombatRange(target, _dist))
@@ -170,7 +170,7 @@ struct FarthestTargetSelector : public Acore::unary_function<Unit*, bool>
170170
if (!_me || !target)
171171
return false;
172172

173-
if (_playerOnly && target->GetTypeId() != TYPEID_PLAYER)
173+
if (_playerOnly && !target->IsPlayer())
174174
return false;
175175

176176
if (_maxDist > 0.0f && !_me->IsInRange(target, _minDist, _maxDist))

src/server/game/AI/CreatureAI.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void CreatureAI::DoZoneInCombat(Creature* creature /*= nullptr*/, float maxRange
107107
Map* map = creature->GetMap();
108108
if (!map->IsDungeon()) //use IsDungeon instead of Instanceable, in case battlegrounds will be instantiated
109109
{
110-
LOG_ERROR("entities.unit.ai", "DoZoneInCombat call for map {} that isn't a dungeon (creature entry = {})", map->GetId(), creature->GetTypeId() == TYPEID_UNIT ? creature->ToCreature()->GetEntry() : 0);
110+
LOG_ERROR("entities.unit.ai", "DoZoneInCombat call for map {} that isn't a dungeon (creature entry = {})", map->GetId(), creature->IsCreature() ? creature->ToCreature()->GetEntry() : 0);
111111
return;
112112
}
113113

@@ -175,10 +175,10 @@ void CreatureAI::MoveInLineOfSight(Unit* who)
175175
void CreatureAI::TriggerAlert(Unit const* who) const
176176
{
177177
// If there's no target, or target isn't a player do nothing
178-
if (!who || who->GetTypeId() != TYPEID_PLAYER)
178+
if (!who || !who->IsPlayer())
179179
return;
180180
// If this unit isn't an NPC, is already distracted, is in combat, is confused, stunned or fleeing, do nothing
181-
if (me->GetTypeId() != TYPEID_UNIT || me->IsEngaged() || me->HasUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_STUNNED | UNIT_STATE_FLEEING | UNIT_STATE_DISTRACTED))
181+
if (!me->IsCreature() || me->IsEngaged() || me->HasUnitState(UNIT_STATE_CONFUSED | UNIT_STATE_STUNNED | UNIT_STATE_FLEEING | UNIT_STATE_DISTRACTED))
182182
return;
183183
// Only alert for hostiles!
184184
if (me->IsCivilian() || me->HasReactState(REACT_PASSIVE) || !me->IsHostileTo(who) || !me->_IsTargetAcceptable(who))

src/server/game/AI/ScriptedAI/ScriptedCreature.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class PlayerOrPetCheck
178178
public:
179179
bool operator() (WorldObject* unit) const
180180
{
181-
if (unit->GetTypeId() != TYPEID_PLAYER)
181+
if (!unit->IsPlayer())
182182
if (!unit->ToUnit()->GetOwnerGUID().IsPlayer())
183183
return true;
184184

src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ bool npc_escortAI::AssistPlayerInCombatAgainst(Unit* who)
111111
}
112112

113113
// or if enemy is in evade mode
114-
if (who->GetTypeId() == TYPEID_UNIT && who->ToCreature()->IsInEvadeMode())
114+
if (who->IsCreature() && who->ToCreature()->IsInEvadeMode())
115115
{
116116
return false;
117117
}

src/server/game/AI/SmartScripts/SmartScript.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4217,7 +4217,7 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
42174217
{
42184218
if (!me || !unit)
42194219
return;
4220-
if (e.event.kill.playerOnly && unit->GetTypeId() != TYPEID_PLAYER)
4220+
if (e.event.kill.playerOnly && !unit->IsPlayer())
42214221
return;
42224222
if (e.event.kill.creature && unit->GetEntry() != e.event.kill.creature)
42234223
return;
@@ -4254,7 +4254,7 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
42544254
(hostilityMode == SmartEvent::LOSHostilityMode::NotHostile && !me->IsHostileTo(unit)) ||
42554255
(hostilityMode == SmartEvent::LOSHostilityMode::Hostile && me->IsHostileTo(unit)))
42564256
{
4257-
if (e.event.los.playerOnly && unit->GetTypeId() != TYPEID_PLAYER)
4257+
if (e.event.los.playerOnly && !unit->IsPlayer())
42584258
return;
42594259
RecalcTimer(e, e.event.los.cooldownMin, e.event.los.cooldownMax);
42604260
ProcessAction(e, unit);
@@ -4278,7 +4278,7 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
42784278
(hostilityMode == SmartEvent::LOSHostilityMode::NotHostile && !me->IsHostileTo(unit)) ||
42794279
(hostilityMode == SmartEvent::LOSHostilityMode::Hostile && me->IsHostileTo(unit)))
42804280
{
4281-
if (e.event.los.playerOnly && unit->GetTypeId() != TYPEID_PLAYER)
4281+
if (e.event.los.playerOnly && !unit->IsPlayer())
42824282
return;
42834283
RecalcTimer(e, e.event.los.cooldownMin, e.event.los.cooldownMax);
42844284
ProcessAction(e, unit);
@@ -5269,7 +5269,7 @@ WorldObject* SmartScript::GetLastInvoker(WorldObject* invoker) const
52695269

52705270
bool SmartScript::IsUnit(WorldObject* obj)
52715271
{
5272-
return obj && (obj->GetTypeId() == TYPEID_UNIT || obj->IsPlayer());
5272+
return obj && (obj->IsCreature() || obj->IsPlayer());
52735273
}
52745274

52755275
bool SmartScript::IsPlayer(WorldObject* obj)
@@ -5279,7 +5279,7 @@ bool SmartScript::IsPlayer(WorldObject* obj)
52795279

52805280
bool SmartScript::IsCreature(WorldObject* obj)
52815281
{
5282-
return obj && obj->GetTypeId() == TYPEID_UNIT;
5282+
return obj && obj->IsCreature();
52835283
}
52845284

52855285
bool SmartScript::IsCharmedCreature(WorldObject* obj)
@@ -5295,7 +5295,7 @@ bool SmartScript::IsCharmedCreature(WorldObject* obj)
52955295

52965296
bool SmartScript::IsGameObject(WorldObject* obj)
52975297
{
5298-
return obj && obj->GetTypeId() == TYPEID_GAMEOBJECT;
5298+
return obj && obj->IsGameObject();
52995299
}
53005300

53015301
void SmartScript::IncPhase(uint32 p)

src/server/game/Achievements/AchievementMgr.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,27 +304,27 @@ bool AchievementCriteriaData::Meets(uint32 criteria_id, Player const* source, Un
304304
case ACHIEVEMENT_CRITERIA_DATA_TYPE_NONE:
305305
return true;
306306
case ACHIEVEMENT_CRITERIA_DATA_TYPE_T_CREATURE:
307-
if (!target || target->GetTypeId() != TYPEID_UNIT)
307+
if (!target || !target->IsCreature())
308308
return false;
309309
return target->GetEntry() == creature.id;
310310
case ACHIEVEMENT_CRITERIA_DATA_TYPE_T_PLAYER_CLASS_RACE:
311-
if (!target || target->GetTypeId() != TYPEID_PLAYER)
311+
if (!target || !target->IsPlayer())
312312
return false;
313313
if (classRace.class_id && classRace.class_id != target->ToPlayer()->getClass())
314314
return false;
315315
if (classRace.race_id && classRace.race_id != target->ToPlayer()->getRace())
316316
return false;
317317
return true;
318318
case ACHIEVEMENT_CRITERIA_DATA_TYPE_S_PLAYER_CLASS_RACE:
319-
if (!source || source->GetTypeId() != TYPEID_PLAYER)
319+
if (!source || !source->IsPlayer())
320320
return false;
321321
if (classRace.class_id && classRace.class_id != source->ToPlayer()->getClass())
322322
return false;
323323
if (classRace.race_id && classRace.race_id != source->ToPlayer()->getRace())
324324
return false;
325325
return true;
326326
case ACHIEVEMENT_CRITERIA_DATA_TYPE_T_PLAYER_LESS_HEALTH:
327-
if (!target || target->GetTypeId() != TYPEID_PLAYER)
327+
if (!target || !target->IsPlayer())
328328
return false;
329329
return !target->HealthAbovePct(health.percent);
330330
case ACHIEVEMENT_CRITERIA_DATA_TYPE_T_PLAYER_DEAD:
@@ -371,7 +371,7 @@ bool AchievementCriteriaData::Meets(uint32 criteria_id, Player const* source, Un
371371
return source->GetMap()->GetPlayersCountExceptGMs() <= map_players.maxcount;
372372
case ACHIEVEMENT_CRITERIA_DATA_TYPE_T_TEAM:
373373
{
374-
if (!target || target->GetTypeId() != TYPEID_PLAYER)
374+
if (!target || !target->IsPlayer())
375375
return false;
376376

377377
// DB data compatibility...
@@ -1501,7 +1501,7 @@ void AchievementMgr::UpdateAchievementCriteria(AchievementCriteriaTypes type, ui
15011501
continue;
15021502

15031503
// map specific case (BG in fact) expected player targeted damage/heal
1504-
if (!unit || unit->GetTypeId() != TYPEID_PLAYER)
1504+
if (!unit || !unit->IsPlayer())
15051505
continue;
15061506
}
15071507

0 commit comments

Comments
 (0)