mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-29 16:43:47 +00:00
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:
@@ -130,7 +130,7 @@ void KillRewarder::_InitXP(Player* player)
|
||||
_xp = Acore::XP::Gain(player, _victim, _isBattleGround);
|
||||
|
||||
if (_xp && !_isBattleGround && _victim) // pussywizard: npcs with relatively low hp give lower exp
|
||||
if (_victim->GetTypeId() == TYPEID_UNIT)
|
||||
if (_victim->IsCreature())
|
||||
if (const CreatureTemplate* ct = _victim->ToCreature()->GetCreatureTemplate())
|
||||
if (ct->ModHealth <= 0.75f && ct->ModHealth >= 0.0f)
|
||||
_xp = uint32(_xp * ct->ModHealth);
|
||||
|
||||
@@ -2385,7 +2385,7 @@ void Player::GiveXP(uint32 xp, Unit* victim, float group_rate, bool isLFGReward)
|
||||
return;
|
||||
}
|
||||
|
||||
if (victim && victim->GetTypeId() == TYPEID_UNIT && !victim->ToCreature()->hasLootRecipient())
|
||||
if (victim && victim->IsCreature() && !victim->ToCreature()->hasLootRecipient())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -6023,7 +6023,7 @@ bool Player::RewardHonor(Unit* uVictim, uint32 groupsize, int32 honor, bool awar
|
||||
// do not reward honor in arenas, but enable onkill spellproc
|
||||
if (InArena())
|
||||
{
|
||||
if (!uVictim || uVictim == this || uVictim->GetTypeId() != TYPEID_PLAYER)
|
||||
if (!uVictim || uVictim == this || !uVictim->IsPlayer())
|
||||
return false;
|
||||
|
||||
if (GetBgTeamId() == uVictim->ToPlayer()->GetBgTeamId())
|
||||
@@ -9256,7 +9256,7 @@ void Player::StopCastingCharm(Aura* except /*= nullptr*/)
|
||||
return;
|
||||
}
|
||||
|
||||
if (charm->GetTypeId() == TYPEID_UNIT)
|
||||
if (charm->IsCreature())
|
||||
{
|
||||
if (charm->ToCreature()->HasUnitTypeMask(UNIT_MASK_PUPPET))
|
||||
{
|
||||
@@ -9611,7 +9611,7 @@ void Player::CharmSpellInitialize()
|
||||
}
|
||||
|
||||
uint8 addlist = 0;
|
||||
if (charm->GetTypeId() != TYPEID_PLAYER)
|
||||
if (!charm->IsPlayer())
|
||||
{
|
||||
//CreatureInfo const* cinfo = charm->ToCreature()->GetCreatureTemplate();
|
||||
//if (cinfo && cinfo->type == CREATURE_TYPE_DEMON && getClass() == CLASS_WARLOCK)
|
||||
@@ -9627,7 +9627,7 @@ void Player::CharmSpellInitialize()
|
||||
data << uint16(0);
|
||||
data << uint32(0);
|
||||
|
||||
if (charm->GetTypeId() != TYPEID_PLAYER)
|
||||
if (!charm->IsPlayer())
|
||||
data << uint8(charm->ToCreature()->GetReactState()) << uint8(charmInfo->GetCommandState()) << uint16(0);
|
||||
else
|
||||
data << uint32(0);
|
||||
@@ -12622,7 +12622,7 @@ bool Player::isHonorOrXPTarget(Unit* victim) const
|
||||
return false;
|
||||
}
|
||||
|
||||
if (victim->GetTypeId() == TYPEID_UNIT)
|
||||
if (victim->IsCreature())
|
||||
{
|
||||
if (victim->IsTotem() || victim->IsCritter() || victim->IsPet() || (victim->ToCreature()->GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_NO_XP))
|
||||
{
|
||||
@@ -12684,7 +12684,7 @@ void Player::RewardPlayerAndGroupAtEvent(uint32 creature_id, WorldObject* pRewar
|
||||
if (!pRewardSource)
|
||||
return;
|
||||
|
||||
ObjectGuid creature_guid = (pRewardSource->GetTypeId() == TYPEID_UNIT) ? pRewardSource->GetGUID() : ObjectGuid::Empty;
|
||||
ObjectGuid creature_guid = (pRewardSource->IsCreature()) ? pRewardSource->GetGUID() : ObjectGuid::Empty;
|
||||
|
||||
// prepare data for near group iteration
|
||||
if (Group* group = GetGroup())
|
||||
@@ -12818,7 +12818,7 @@ void Player::SetClientControl(Unit* target, bool allowMove, bool packetOnly /*=
|
||||
SetMover(target);
|
||||
|
||||
// Xinef: disable moving if target has disable move flag
|
||||
if (target->GetTypeId() != TYPEID_UNIT)
|
||||
if (!target->IsCreature())
|
||||
return;
|
||||
|
||||
if (allowMove && target->HasUnitFlag(UNIT_FLAG_DISABLE_MOVE))
|
||||
@@ -12855,12 +12855,12 @@ void Player::SetMover(Unit* target)
|
||||
LOG_INFO("misc", "Player::SetMover (B2) - {}, {}, {}, {}, {}, {}, {}, {}", target->GetGUID().ToString(), target->GetMapId(), target->GetInstanceId(), target->FindMap()->GetId(), target->IsInWorld() ? 1 : 0, target->IsDuringRemoveFromWorld() ? 1 : 0, (target->ToPlayer() && target->ToPlayer()->IsBeingTeleported() ? 1 : 0), target->isBeingLoaded() ? 1 : 0);
|
||||
}
|
||||
m_mover->m_movedByPlayer = nullptr;
|
||||
if (m_mover->GetTypeId() == TYPEID_UNIT)
|
||||
if (m_mover->IsCreature())
|
||||
m_mover->GetMotionMaster()->Initialize();
|
||||
|
||||
m_mover = target;
|
||||
m_mover->m_movedByPlayer = this;
|
||||
if (m_mover->GetTypeId() == TYPEID_UNIT)
|
||||
if (m_mover->IsCreature())
|
||||
m_mover->GetMotionMaster()->Initialize();
|
||||
}
|
||||
|
||||
@@ -13105,7 +13105,7 @@ void Player::StopCastingBindSight(Aura* except /*= nullptr*/)
|
||||
{
|
||||
if (WorldObject* target = GetViewpoint())
|
||||
{
|
||||
if (target->isType(TYPEMASK_UNIT))
|
||||
if (target->IsUnit())
|
||||
{
|
||||
((Unit*)target)->RemoveAurasByType(SPELL_AURA_BIND_SIGHT, GetGUID(), except);
|
||||
((Unit*)target)->RemoveAurasByType(SPELL_AURA_MOD_POSSESS, GetGUID(), except);
|
||||
@@ -13129,7 +13129,7 @@ void Player::SetViewpoint(WorldObject* target, bool apply)
|
||||
// farsight dynobj or puppet may be very far away
|
||||
UpdateVisibilityOf(target);
|
||||
|
||||
if (target->isType(TYPEMASK_UNIT) && !GetVehicle())
|
||||
if (target->IsUnit() && !GetVehicle())
|
||||
((Unit*)target)->AddPlayerToVision(this);
|
||||
SetSeer(target);
|
||||
}
|
||||
@@ -13146,7 +13146,7 @@ void Player::SetViewpoint(WorldObject* target, bool apply)
|
||||
return;
|
||||
}
|
||||
|
||||
if (target->isType(TYPEMASK_UNIT) && !GetVehicle())
|
||||
if (target->IsUnit() && !GetVehicle())
|
||||
static_cast<Unit*>(target)->RemovePlayerFromVision(this);
|
||||
|
||||
// must immediately set seer back otherwise may crash
|
||||
|
||||
@@ -44,13 +44,13 @@ void Player::PrepareGossipMenu(WorldObject* source, uint32 menuId /*= 0*/, bool
|
||||
|
||||
uint32 npcflags = 0;
|
||||
|
||||
if (source->GetTypeId() == TYPEID_UNIT)
|
||||
if (source->IsCreature())
|
||||
{
|
||||
npcflags = source->ToUnit()->GetNpcFlags();
|
||||
if (showQuests && npcflags & UNIT_NPC_FLAG_QUESTGIVER)
|
||||
PrepareQuestMenu(source->GetGUID());
|
||||
}
|
||||
else if (source->GetTypeId() == TYPEID_GAMEOBJECT)
|
||||
else if (source->IsGameObject())
|
||||
if (showQuests && source->ToGameObject()->GetGoType() == GAMEOBJECT_TYPE_QUESTGIVER)
|
||||
PrepareQuestMenu(source->GetGUID());
|
||||
|
||||
@@ -211,7 +211,7 @@ void Player::SendPreparedGossip(WorldObject* source)
|
||||
if (!source)
|
||||
return;
|
||||
|
||||
if (source->GetTypeId() == TYPEID_UNIT)
|
||||
if (source->IsCreature())
|
||||
{
|
||||
// in case no gossip flag and quest menu not empty, open quest menu (client expect gossip menu with this flag)
|
||||
if (!source->ToCreature()->HasNpcFlag(UNIT_NPC_FLAG_GOSSIP) && !PlayerTalkClass->GetQuestMenu().Empty())
|
||||
@@ -220,7 +220,7 @@ void Player::SendPreparedGossip(WorldObject* source)
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (source->GetTypeId() == TYPEID_GAMEOBJECT)
|
||||
else if (source->IsGameObject())
|
||||
{
|
||||
// probably need to find a better way here
|
||||
if (!PlayerTalkClass->GetGossipMenu().GetMenuId() && !PlayerTalkClass->GetQuestMenu().Empty())
|
||||
@@ -256,7 +256,7 @@ void Player::OnGossipSelect(WorldObject* source, uint32 gossipListId, uint32 men
|
||||
uint32 gossipOptionId = item->OptionType;
|
||||
ObjectGuid guid = source->GetGUID();
|
||||
|
||||
if (sWorld->getIntConfig(CONFIG_INSTANT_TAXI) == 2 && source->GetTypeId() == TYPEID_UNIT)
|
||||
if (sWorld->getIntConfig(CONFIG_INSTANT_TAXI) == 2 && source->IsCreature())
|
||||
{
|
||||
if (gossipOptionId == GOSSIP_ACTION_TOGGLE_INSTANT_FLIGHT && source->ToUnit()->GetNpcFlags() & UNIT_NPC_FLAG_FLIGHTMASTER)
|
||||
{
|
||||
@@ -272,7 +272,7 @@ void Player::OnGossipSelect(WorldObject* source, uint32 gossipListId, uint32 men
|
||||
}
|
||||
}
|
||||
|
||||
if (source->GetTypeId() == TYPEID_GAMEOBJECT)
|
||||
if (source->IsGameObject())
|
||||
{
|
||||
if (gossipOptionId > GOSSIP_OPTION_QUESTGIVER)
|
||||
{
|
||||
|
||||
@@ -829,7 +829,7 @@ void Player::RewardQuest(Quest const* quest, uint32 reward, Object* questGiver,
|
||||
if (quest->GetRewSpellCast() > 0)
|
||||
{
|
||||
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(quest->GetRewSpellCast());
|
||||
if (questGiver->isType(TYPEMASK_UNIT) && !spellInfo->HasEffect(SPELL_EFFECT_LEARN_SPELL) && !spellInfo->HasEffect(SPELL_EFFECT_CREATE_ITEM) && !spellInfo->IsSelfCast())
|
||||
if (questGiver->IsUnit() && !spellInfo->HasEffect(SPELL_EFFECT_LEARN_SPELL) && !spellInfo->HasEffect(SPELL_EFFECT_CREATE_ITEM) && !spellInfo->IsSelfCast())
|
||||
{
|
||||
if (Creature* creature = GetMap()->GetCreature(questGiver->GetGUID()))
|
||||
creature->CastSpell(this, quest->GetRewSpellCast(), true);
|
||||
@@ -840,7 +840,7 @@ void Player::RewardQuest(Quest const* quest, uint32 reward, Object* questGiver,
|
||||
else if (quest->GetRewSpell() > 0)
|
||||
{
|
||||
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(quest->GetRewSpell());
|
||||
if (questGiver->isType(TYPEMASK_UNIT) && !spellInfo->HasEffect(SPELL_EFFECT_LEARN_SPELL) && !spellInfo->HasEffect(SPELL_EFFECT_CREATE_ITEM) && !spellInfo->IsSelfCast())
|
||||
if (questGiver->IsUnit() && !spellInfo->HasEffect(SPELL_EFFECT_LEARN_SPELL) && !spellInfo->HasEffect(SPELL_EFFECT_CREATE_ITEM) && !spellInfo->IsSelfCast())
|
||||
{
|
||||
if (Creature* creature = GetMap()->GetCreature(questGiver->GetGUID()))
|
||||
creature->CastSpell(this, quest->GetRewSpell(), true);
|
||||
|
||||
@@ -939,7 +939,7 @@ void Player::UpdateWeaponSkill(Unit* victim, WeaponAttackType attType, Item* ite
|
||||
if (GetShapeshiftForm() == FORM_TREE)
|
||||
return; // use weapon but not skill up
|
||||
|
||||
if (victim->GetTypeId() == TYPEID_UNIT &&
|
||||
if (victim->IsCreature() &&
|
||||
(victim->ToCreature()->GetCreatureTemplate()->flags_extra &
|
||||
CREATURE_FLAG_EXTRA_NO_SKILL_GAINS))
|
||||
return;
|
||||
@@ -1670,7 +1670,7 @@ void Player::UpdateVisibilityOf(WorldObject* target)
|
||||
{
|
||||
if (!CanSeeOrDetect(target, false, true))
|
||||
{
|
||||
if (target->GetTypeId() == TYPEID_UNIT)
|
||||
if (target->IsCreature())
|
||||
BeforeVisibilityDestroy<Creature>(target->ToCreature(), this);
|
||||
|
||||
target->DestroyForPlayer(this);
|
||||
@@ -1687,7 +1687,7 @@ void Player::UpdateVisibilityOf(WorldObject* target)
|
||||
// target aura duration for caster show only if target exist at
|
||||
// caster client send data at target visibility change (adding to
|
||||
// client)
|
||||
if (target->isType(TYPEMASK_UNIT))
|
||||
if (target->IsUnit())
|
||||
GetInitialVisiblePackets((Unit*) target);
|
||||
}
|
||||
}
|
||||
@@ -1913,7 +1913,7 @@ void Player::UpdateCharmedAI()
|
||||
|
||||
// Xinef: we should be killed if caster enters evade mode and charm is
|
||||
// infinite
|
||||
if (charmer->GetTypeId() == TYPEID_UNIT &&
|
||||
if (charmer->IsCreature() &&
|
||||
charmer->ToCreature()->IsInEvadeMode())
|
||||
{
|
||||
AuraEffectList const& auras =
|
||||
|
||||
Reference in New Issue
Block a user