feat(Core/Unit): New helper IsClass and script hook OnPlayerIsClass (#18243)

* Class Comparison Logic Encapsulation - Parity

* Add Context to IsClass

* Add Unit IsClass script hook

* Replace additional getClass with IsClass

* Update CanUseItem to replace getClass with IsClass

* Add separate context for pet vs ability

* Change Create to Init since not all referenced contexts are creation

* Align spacing in ClassContext

* Drop context on LFGManager max power

* Update IsClass context that wraps around Missle Barrage

* Rename context for swapping weapons

* Be more specific than CLASS_CONTEXT_TALENT

* Remove duplicate context

* Moved IsClass Hook to Player

* Removed unused parameter in virtual base function

* Added maybe_unused to IsClass virtual in order to compile

To match the override signature, the virtual base needs to include the parameter in question, so using [maybe_unused] to signal to the compiler to allow it

* Remove extra blank line

* Add ABILITY_REACTIVE context

* Add context for PET_CHARM

* Remove explicit nullopt check per review

* Code Readability - Change if to if else in pet

Due to the return pattern, this doesn't change functionality in any way

* Add OnPlayer to disambiguate

---------

Co-authored-by: NathanHandley <nathanhandley@protonmail.com>
This commit is contained in:
Nathan Handley
2024-02-10 09:25:00 -06:00
committed by GitHub
parent c47c945aa4
commit df33a57b78
33 changed files with 344 additions and 280 deletions

View File

@@ -446,7 +446,7 @@ class spell_pet_hit_expertise_scalling : public AuraScript
{
if (Player* modOwner = GetUnitOwner()->GetSpellModOwner())
{
if (modOwner->getClass() == CLASS_HUNTER)
if (modOwner->IsClass(CLASS_HUNTER, CLASS_CONTEXT_STATS))
amount = CalculatePercent(modOwner->m_modRangedHitChance, 8.0f, 8.0f);
else if (modOwner->getPowerType() == POWER_MANA)
amount = CalculatePercent(modOwner->m_modSpellHitChance, 17.0f, 8.0f);
@@ -459,7 +459,7 @@ class spell_pet_hit_expertise_scalling : public AuraScript
{
if (Player* modOwner = GetUnitOwner()->GetSpellModOwner())
{
if (modOwner->getClass() == CLASS_HUNTER)
if (modOwner->IsClass(CLASS_HUNTER, CLASS_CONTEXT_STATS))
amount = CalculatePercent(modOwner->m_modRangedHitChance, 8.0f, 17.0f);
else if (modOwner->getPowerType() == POWER_MANA)
amount = CalculatePercent(modOwner->m_modSpellHitChance, 17.0f, 17.0f);
@@ -472,7 +472,7 @@ class spell_pet_hit_expertise_scalling : public AuraScript
{
if (Player* modOwner = GetUnitOwner()->GetSpellModOwner())
{
if (modOwner->getClass() == CLASS_HUNTER)
if (modOwner->IsClass(CLASS_HUNTER, CLASS_CONTEXT_STATS))
amount = CalculatePercent(modOwner->m_modRangedHitChance, 8.0f, 26.0f);
else if (modOwner->getPowerType() == POWER_MANA)
amount = CalculatePercent(modOwner->m_modSpellHitChance, 17.0f, 26.0f);
@@ -1673,7 +1673,7 @@ class spell_gen_pet_summoned : public SpellScript
Player* player = GetCaster()->ToPlayer();
if (player->GetLastPetNumber() && player->CanResummonPet(player->GetLastPetSpell()))
{
PetType newPetType = (player->getClass() == CLASS_HUNTER) ? HUNTER_PET : SUMMON_PET;
PetType newPetType = (player->IsClass(CLASS_HUNTER, CLASS_CONTEXT_PET)) ? HUNTER_PET : SUMMON_PET;
Pet* newPet = new Pet(player, newPetType);
if (newPet->LoadPetFromDB(player, 0, player->GetLastPetNumber(), true, 100))
{
@@ -3545,11 +3545,11 @@ class spell_gen_on_tournament_mount : public AuraScript
case NPC_ARGENT_WARHORSE:
{
if (player->HasAchieved(ACHIEVEMENT_CHAMPION_ALLIANCE) || player->HasAchieved(ACHIEVEMENT_CHAMPION_HORDE))
return player->getClass() == CLASS_DEATH_KNIGHT ? SPELL_PENNANT_EBON_BLADE_CHAMPION : SPELL_PENNANT_ARGENT_CRUSADE_CHAMPION;
return player->IsClass(CLASS_DEATH_KNIGHT) ? SPELL_PENNANT_EBON_BLADE_CHAMPION : SPELL_PENNANT_ARGENT_CRUSADE_CHAMPION;
else if (player->HasAchieved(ACHIEVEMENT_ARGENT_VALOR))
return player->getClass() == CLASS_DEATH_KNIGHT ? SPELL_PENNANT_EBON_BLADE_VALIANT : SPELL_PENNANT_ARGENT_CRUSADE_VALIANT;
return player->IsClass(CLASS_DEATH_KNIGHT) ? SPELL_PENNANT_EBON_BLADE_VALIANT : SPELL_PENNANT_ARGENT_CRUSADE_VALIANT;
else
return player->getClass() == CLASS_DEATH_KNIGHT ? SPELL_PENNANT_EBON_BLADE_ASPIRANT : SPELL_PENNANT_ARGENT_CRUSADE_ASPIRANT;
return player->IsClass(CLASS_DEATH_KNIGHT) ? SPELL_PENNANT_EBON_BLADE_ASPIRANT : SPELL_PENNANT_ARGENT_CRUSADE_ASPIRANT;
}
default:
return 0;