Core/Creatures: added helper to check if a class trainer can train a player and use it in various places to get rid of multiple checks

This commit is contained in:
Ovahlord committed 2019-12-13 17:49:16 +01:00
1 parent de371675e6
commit 108316ba28
4 files changed
+9 -5

No files matched your search

@@ -1119,9 +1119,12 @@ bool Creature::isCanInteractWithBattleMaster(Player* player, bool msg) const
bool Creature::isCanTrainingAndResetTalentsOf(Player* player) const
{
return player->getLevel() >= 10
&& GetCreatureTemplate()->trainer_type == TRAINER_TYPE_CLASS
&& player->getClass() == GetCreatureTemplate()->trainer_class;
return player->getLevel() >= 10 && IsClassTrainerOf(player);
}
bool Creature::IsClassTrainerOf(Player const* player) const
{
return GetCreatureTemplate()->trainer_type == TRAINER_TYPE_CLASS && player->getClass() == GetCreatureTemplate()->trainer_class;
}
Player* Creature::GetLootRecipient() const
@@ -109,6 +109,7 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
/// @todo Rename these properly
bool isCanInteractWithBattleMaster(Player* player, bool msg) const;
bool isCanTrainingAndResetTalentsOf(Player* player) const;
bool IsClassTrainerOf(Player const* player) const;
bool CanCreatureAttack(Unit const* victim, bool force = true) const;
void LoadTemplateImmunities();
bool IsImmunedToSpell(SpellInfo const* spellInfo, Unit* caster) const override;
+1 -1
View File
@@ -14381,7 +14381,7 @@ void Player::PrepareGossipMenu(WorldObject* source, uint32 menuId /*= 0*/, bool
canTalk = false;
break;
case GOSSIP_OPTION_TRAINER:
if (getClass() != creature->GetCreatureTemplate()->trainer_class && creature->GetCreatureTemplate()->trainer_type == TRAINER_TYPE_CLASS)
if (!creature->IsClassTrainerOf(this))
{
TC_LOG_ERROR("sql.sql", "GOSSIP_OPTION_TRAINER:: Player %s (GUID: %u) requested wrong gossip menu: %u with wrong class: %u at Creature: %s (Entry: %u, Trainer Class: %u)",
GetName().c_str(), GetGUID().GetCounter(), menu->GetGossipMenu().GetMenuId(), getClass(), creature->GetName().c_str(), creature->GetEntry(), creature->GetCreatureTemplate()->trainer_class);
+1 -1
View File
@@ -14504,7 +14504,7 @@ void Unit::BuildValuesUpdate(uint8 updateType, ByteBuffer* data, Player* target)
if (!target->CanSeeSpellClickOn(creature))
appendValue &= ~UNIT_NPC_FLAG_SPELLCLICK;
if (target->IsPlayer() && !creature->isCanTrainingAndResetTalentsOf(target->ToPlayer()))
if (target->IsPlayer() && !creature->IsClassTrainerOf(target->ToPlayer()))
appendValue &= ~UNIT_NPC_FLAG_TRAINER_CLASS;
}