fix(Core/Creatures): Fixed displaying trainer npcflags that are not valid to player. (#4848)

This commit is contained in:
UltraNix
2021-03-21 15:18:41 +01:00
committed by GitHub
parent 485f7e7639
commit 6c7cc1690f
4 changed files with 52 additions and 0 deletions

View File

@@ -1033,6 +1033,47 @@ bool Creature::isCanTrainingAndResetTalentsOf(Player* player) const
&& player->getClass() == GetCreatureTemplate()->trainer_class;
}
bool Creature::IsValidTrainerForPlayer(Player* player, uint32* npcFlags /*= nullptr*/) const
{
if (!IsTrainer())
{
return false;
}
switch (m_creatureInfo->trainer_type)
{
case TRAINER_TYPE_CLASS:
case TRAINER_TYPE_PETS:
if (m_creatureInfo->trainer_class && m_creatureInfo->trainer_class != player->getClass())
{
if (npcFlags)
*npcFlags &= ~UNIT_NPC_FLAG_TRAINER_CLASS;
return false;
}
break;
case TRAINER_TYPE_MOUNTS:
if (m_creatureInfo->trainer_race && m_creatureInfo->trainer_race != player->getRace())
{
return false;
}
break;
case TRAINER_TYPE_TRADESKILLS:
if (m_creatureInfo->trainer_spell && !player->HasSpell(m_creatureInfo->trainer_spell))
{
if (npcFlags)
*npcFlags &= ~UNIT_NPC_FLAG_TRAINER_PROFESSION;
return false;
}
break;
default:
break;
}
return true;
}
Player* Creature::GetLootRecipient() const
{
if (!m_lootRecipient)

View File

@@ -474,6 +474,7 @@ public:
///// TODO RENAME THIS!!!!!
bool isCanInteractWithBattleMaster(Player* player, bool msg) const;
bool isCanTrainingAndResetTalentsOf(Player* player) const;
[[nodiscard]] bool IsValidTrainerForPlayer(Player* player, uint32* npcFlags = nullptr) const;
bool CanCreatureAttack(Unit const* victim, bool skipDistCheck = false) const;
void LoadSpellTemplateImmunity();
bool IsImmunedToSpell(SpellInfo const* spellInfo) override;

View File

@@ -15074,6 +15074,11 @@ void Player::PrepareGossipMenu(WorldObject* source, uint32 menuId /*= 0*/, bool
canTalk = false;
break;
case GOSSIP_OPTION_TRAINER:
if (!creature->IsValidTrainerForPlayer(this))
{
canTalk = false;
}
break;
case GOSSIP_OPTION_GOSSIP:
case GOSSIP_OPTION_SPIRITGUIDE:
case GOSSIP_OPTION_INNKEEPER:

View File

@@ -19844,6 +19844,11 @@ void Unit::BuildValuesUpdate(uint8 updateType, ByteBuffer* data, Player* target)
if (!target->CanSeeSpellClickOn(creature))
appendValue &= ~UNIT_NPC_FLAG_SPELLCLICK;
if (!creature->IsValidTrainerForPlayer(target, &appendValue))
{
appendValue &= ~UNIT_NPC_FLAG_TRAINER;
}
}
fieldBuffer << uint32(appendValue);