From a2b6080accf998bff715d79381bf8b1c372efbe8 Mon Sep 17 00:00:00 2001 From: Foereaper Date: Mon, 29 Jan 2024 22:38:57 +0100 Subject: [PATCH] Some threat related cleanup Considering only creatures can have threat, it is more appropriate for threat related methods to be in the Creature class. They should still function the same, but are somewhat more unified now. --- CMangos/CreatureMethods.h | 54 +++++++++++++++++++++++++++++++++-- CMangos/UnitMethods.h | 51 --------------------------------- TrinityCore/CreatureMethods.h | 37 +++++++++++++++++------- TrinityCore/UnitMethods.h | 42 --------------------------- 4 files changed, 79 insertions(+), 105 deletions(-) diff --git a/CMangos/CreatureMethods.h b/CMangos/CreatureMethods.h index d631b2039b..7a38c3bc4d 100644 --- a/CMangos/CreatureMethods.h +++ b/CMangos/CreatureMethods.h @@ -1116,6 +1116,55 @@ namespace LuaCreature return 1; } + /** + * Adds threat to the [Creature] from the victim. + * + *
+     * enum SpellSchoolMask
+     * {
+     *     SPELL_SCHOOL_MASK_NONE    = 0,
+     *     SPELL_SCHOOL_MASK_NORMAL  = 1,
+     *     SPELL_SCHOOL_MASK_HOLY    = 2,
+     *     SPELL_SCHOOL_MASK_FIRE    = 4,
+     *     SPELL_SCHOOL_MASK_NATURE  = 8,
+     *     SPELL_SCHOOL_MASK_FROST   = 16,
+     *     SPELL_SCHOOL_MASK_SHADOW  = 32,
+     *     SPELL_SCHOOL_MASK_ARCANE  = 64,
+     * }
+     * 
+ * + * @param [Unit] victim : [Unit] that caused the threat + * @param float threat : threat amount + * @param [SpellSchoolMask] schoolMask = 0 : [SpellSchoolMask] of the threat causer + * @param uint32 spell = 0 : spell entry used for threat + */ + int AddThreat(Eluna* E, Creature* creature) + { + Unit* victim = Eluna::CHECKOBJ(E->L, 2); + float threat = Eluna::CHECKVAL(E->L, 3, true); + uint32 spell = Eluna::CHECKVAL(E->L, 4, 0); + + uint32 schoolMask = Eluna::CHECKVAL(E->L, 5, 0); + SpellEntry const* spellEntry = GetSpellStore()->LookupEntry(spell); + creature->AddThreat(victim, threat, false, (SpellSchoolMask)schoolMask, spellEntry); + +#ifdef CLASSIC + creature->AddThreat(victim, threat, false, spellEntry ? GetSchoolMask(spellEntry->School) : SPELL_SCHOOL_MASK_NONE, spellEntry); +#else + creature->AddThreat(victim, threat, false, spellEntry ? static_cast(spellEntry->SchoolMask) : SPELL_SCHOOL_MASK_NONE, spellEntry); +#endif + return 0; + } + + /** + * Clears the [Creature]'s threat list. + */ + int ClearThreatList(Eluna* /*E*/, Creature* creature) + { + creature->getThreatManager().clearReferences(); + return 0; + } + ElunaRegister CreatureMethods[] = { // Getters @@ -1207,7 +1256,10 @@ namespace LuaCreature { "SelectVictim", &LuaCreature::SelectVictim }, { "MoveWaypoint", &LuaCreature::MoveWaypoint }, { "UpdateEntry", &LuaCreature::UpdateEntry }, + { "AddThreat", &LuaCreature::AddThreat }, + { "ClearThreatList", &LuaCreature::ClearThreatList }, + // Not implemented methods { "GetWaypointPath", nullptr, METHOD_REG_NONE }, // TC/Acore { "GetLootMode", nullptr, METHOD_REG_NONE }, // TC/Acore @@ -1223,9 +1275,7 @@ namespace LuaCreature { "ResetLootMode", nullptr, METHOD_REG_NONE }, // TC/Acore { "RemoveLootMode", nullptr, METHOD_REG_NONE }, // TC/Acore { "GetThreat", nullptr, METHOD_REG_NONE }, // TC/Acore - { "AddThreat", nullptr, METHOD_REG_NONE }, // TC/Acore { "ClearThreat", nullptr, METHOD_REG_NONE }, // TC/Acore - { "ClearAllThreat", nullptr, METHOD_REG_NONE }, // TC/Acore { "ResetAllThreat", nullptr, METHOD_REG_NONE }, // TC/Acore { "FixateTarget", nullptr, METHOD_REG_NONE }, // TC/Acore { "ClearFixate", nullptr, METHOD_REG_NONE }, // TC/Acore diff --git a/CMangos/UnitMethods.h b/CMangos/UnitMethods.h index eba63350e8..0b206995ca 100644 --- a/CMangos/UnitMethods.h +++ b/CMangos/UnitMethods.h @@ -1631,15 +1631,6 @@ namespace LuaUnit return 0; } - /** - * Clears the [Unit]'s threat list. - */ - int ClearThreatList(Eluna* /*E*/, Unit* unit) - { - unit->getThreatManager().clearReferences(); - return 0; - } - /** * Mounts the [Unit] on the given displayID/modelID. * @@ -2456,46 +2447,6 @@ namespace LuaUnit #endif return 0; } - - /** - * Adds threat to the [Unit] from the victim. - * - *
-     * enum SpellSchoolMask
-     * {
-     *     SPELL_SCHOOL_MASK_NONE    = 0,
-     *     SPELL_SCHOOL_MASK_NORMAL  = 1,
-     *     SPELL_SCHOOL_MASK_HOLY    = 2,
-     *     SPELL_SCHOOL_MASK_FIRE    = 4,
-     *     SPELL_SCHOOL_MASK_NATURE  = 8,
-     *     SPELL_SCHOOL_MASK_FROST   = 16,
-     *     SPELL_SCHOOL_MASK_SHADOW  = 32,
-     *     SPELL_SCHOOL_MASK_ARCANE  = 64,
-     * }
-     * 
- * - * @param [Unit] victim : [Unit] that caused the threat - * @param float threat : threat amount - * @param [SpellSchoolMask] schoolMask = 0 : [SpellSchoolMask] of the threat causer - * @param uint32 spell = 0 : spell entry used for threat - */ - int AddThreat(Eluna* E, Unit* unit) - { - Unit* victim = Eluna::CHECKOBJ(E->L, 2); - float threat = Eluna::CHECKVAL(E->L, 3, true); - uint32 spell = Eluna::CHECKVAL(E->L, 4, 0); - - uint32 schoolMask = Eluna::CHECKVAL(E->L, 5, 0); - SpellEntry const* spellEntry = GetSpellStore()->LookupEntry(spell); - unit->AddThreat(victim, threat, false, (SpellSchoolMask)schoolMask, spellEntry); - -#ifdef CLASSIC - unit->AddThreat(victim, threat, false, spellEntry ? GetSchoolMask(spellEntry->School) : SPELL_SCHOOL_MASK_NONE, spellEntry); -#else - unit->AddThreat(victim, threat, false, spellEntry ? static_cast(spellEntry->SchoolMask) : SPELL_SCHOOL_MASK_NONE, spellEntry); -#endif - return 0; - } ElunaRegister UnitMethods[] = { @@ -2652,7 +2603,6 @@ namespace LuaUnit { "CountPctFromMaxHealth", &LuaUnit::CountPctFromMaxHealth }, { "Dismount", &LuaUnit::Dismount }, { "Mount", &LuaUnit::Mount }, - { "ClearThreatList", &LuaUnit::ClearThreatList }, { "ClearUnitState", &LuaUnit::ClearUnitState }, { "AddUnitState", &LuaUnit::AddUnitState }, { "NearTeleport", &LuaUnit::NearTeleport }, @@ -2669,7 +2619,6 @@ namespace LuaUnit { "MoveClear", &LuaUnit::MoveClear }, { "DealDamage", &LuaUnit::DealDamage }, { "DealHeal", &LuaUnit::DealHeal }, - { "AddThreat", &LuaUnit::AddThreat }, #if defined(TBC) || defined(WOTLK) { "RemoveArenaAuras", &LuaUnit::RemoveArenaAuras }, #else diff --git a/TrinityCore/CreatureMethods.h b/TrinityCore/CreatureMethods.h index 4d606cc8c1..9f08081f9d 100644 --- a/TrinityCore/CreatureMethods.h +++ b/TrinityCore/CreatureMethods.h @@ -767,17 +767,34 @@ namespace LuaCreature } /** - * Adds threat to a [Unit] for this [Creature]. + * Adds threat to the [Creature] from the victim. * - * @param [Unit] target - * @param float amount + *
+     * enum SpellSchoolMask
+     * {
+     *     SPELL_SCHOOL_MASK_NONE    = 0,
+     *     SPELL_SCHOOL_MASK_NORMAL  = 1,
+     *     SPELL_SCHOOL_MASK_HOLY    = 2,
+     *     SPELL_SCHOOL_MASK_FIRE    = 4,
+     *     SPELL_SCHOOL_MASK_NATURE  = 8,
+     *     SPELL_SCHOOL_MASK_FROST   = 16,
+     *     SPELL_SCHOOL_MASK_SHADOW  = 32,
+     *     SPELL_SCHOOL_MASK_ARCANE  = 64,
+     * }
+     * 
+ * + * @param [Unit] victim : [Unit] that caused the threat + * @param float threat : threat amount + * @param [SpellSchoolMask] schoolMask = 0 : [SpellSchoolMask] of the threat causer + * @param uint32 spell = 0 : spell entry used for threat */ int AddThreat(Eluna* E, Creature* creature) { - Unit* target = Eluna::CHECKOBJ(E->L, 2); - float amt = Eluna::CHECKVAL(E->L, 3); + Unit* victim = Eluna::CHECKOBJ(E->L, 2); + float threat = Eluna::CHECKVAL(E->L, 3, true); + uint32 spell = Eluna::CHECKVAL(E->L, 4, 0); - creature->GetThreatManager().AddThreat(target, amt); + creature->GetThreatManager().AddThreat(victim, threat, spell ? sSpellMgr->GetSpellInfo(spell) : NULL, true, true); return 0; } @@ -811,7 +828,7 @@ namespace LuaCreature /** * Clear the [Creature]'s threat list. This will cause evading. */ - int ClearAllThreat(Eluna* E, Creature* creature) + int ClearThreatList(Eluna* /*E*/, Creature* creature) { creature->GetThreatManager().ClearAllThreat(); return 0; @@ -820,7 +837,7 @@ namespace LuaCreature /** * Resets the [Creature]'s threat list, setting all threat targets' threat to 0. */ - int ResetAllThreat(Eluna* E, Creature* creature) + int ResetAllThreat(Eluna* /*E*/, Creature* creature) { creature->GetThreatManager().ResetAllThreat(); return 0; @@ -842,7 +859,7 @@ namespace LuaCreature /** * Clears the [Creature]'s fixated target. */ - int ClearFixate(Eluna* E, Creature* creature) + int ClearFixate(Eluna* /*E*/, Creature* creature) { creature->GetThreatManager().ClearFixate(); return 0; @@ -1464,7 +1481,7 @@ namespace LuaCreature { "UpdateEntry", &LuaCreature::UpdateEntry }, { "AddThreat", &LuaCreature::AddThreat }, { "ClearThreat", &LuaCreature::ClearThreat }, - { "ClearAllThreat", &LuaCreature::ClearAllThreat }, + { "ClearThreatList", &LuaCreature::ClearThreatList }, { "ResetAllThreat", &LuaCreature::ResetAllThreat }, { "FixateTarget", &LuaCreature::FixateTarget }, { "ClearFixate", &LuaCreature::ClearFixate }, diff --git a/TrinityCore/UnitMethods.h b/TrinityCore/UnitMethods.h index 1faf72c652..3376ba0670 100644 --- a/TrinityCore/UnitMethods.h +++ b/TrinityCore/UnitMethods.h @@ -1713,15 +1713,6 @@ namespace LuaUnit return 0; } - /** - * Clears the [Unit]'s threat list. - */ - int ClearThreatList(Eluna* /*E*/, Unit* unit) - { - unit->GetThreatManager().ClearAllThreat(); - return 0; - } - /** * Mounts the [Unit] on the given displayID/modelID. * @@ -2434,38 +2425,6 @@ namespace LuaUnit return 0; } - /** - * Adds threat to the [Unit] from the victim. - * - *
-     * enum SpellSchoolMask
-     * {
-     *     SPELL_SCHOOL_MASK_NONE    = 0,
-     *     SPELL_SCHOOL_MASK_NORMAL  = 1,
-     *     SPELL_SCHOOL_MASK_HOLY    = 2,
-     *     SPELL_SCHOOL_MASK_FIRE    = 4,
-     *     SPELL_SCHOOL_MASK_NATURE  = 8,
-     *     SPELL_SCHOOL_MASK_FROST   = 16,
-     *     SPELL_SCHOOL_MASK_SHADOW  = 32,
-     *     SPELL_SCHOOL_MASK_ARCANE  = 64,
-     * }
-     * 
- * - * @param [Unit] victim : [Unit] that caused the threat - * @param float threat : threat amount - * @param [SpellSchoolMask] schoolMask = 0 : [SpellSchoolMask] of the threat causer - * @param uint32 spell = 0 : spell entry used for threat - */ - int AddThreat(Eluna* E, Unit* unit) - { - Unit* victim = Eluna::CHECKOBJ(E->L, 2); - float threat = Eluna::CHECKVAL(E->L, 3, true); - uint32 spell = Eluna::CHECKVAL(E->L, 4, 0); - - unit->GetThreatManager().AddThreat(victim, threat, spell ? sSpellMgr->GetSpellInfo(spell) : NULL, true, true); - return 0; - } - int RestoreDisplayId(Eluna* /*E*/, Unit* unit) { unit->RestoreDisplayId(); @@ -2694,7 +2653,6 @@ namespace LuaUnit { "RestoreFaction", &LuaUnit::RestoreFaction }, { "RemoveBindSightAuras", &LuaUnit::RemoveBindSightAuras }, { "RemoveCharmAuras", &LuaUnit::RemoveCharmAuras }, - { "ClearThreatList", &LuaUnit::ClearThreatList }, { "ClearUnitState", &LuaUnit::ClearUnitState }, { "AddUnitState", &LuaUnit::AddUnitState }, { "DisableMelee", &LuaUnit::DisableMelee },