Skip to content

Commit

Permalink
Some threat related cleanup
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Foereaper committed Jan 29, 2024
1 parent 2ebe9b7 commit a2b6080
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 105 deletions.
54 changes: 52 additions & 2 deletions CMangos/CreatureMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,55 @@ namespace LuaCreature
return 1;
}

/**
* Adds threat to the [Creature] from the victim.
*
* <pre>
* 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,
* }
* </pre>
*
* @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<Unit>(E->L, 2);
float threat = Eluna::CHECKVAL<float>(E->L, 3, true);
uint32 spell = Eluna::CHECKVAL<uint32>(E->L, 4, 0);

uint32 schoolMask = Eluna::CHECKVAL<uint32>(E->L, 5, 0);
SpellEntry const* spellEntry = GetSpellStore()->LookupEntry<SpellEntry>(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<SpellSchoolMask>(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<Creature> CreatureMethods[] =
{
// Getters
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
51 changes: 0 additions & 51 deletions CMangos/UnitMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -2456,46 +2447,6 @@ namespace LuaUnit
#endif
return 0;
}

/**
* Adds threat to the [Unit] from the victim.
*
* <pre>
* 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,
* }
* </pre>
*
* @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<Unit>(E->L, 2);
float threat = Eluna::CHECKVAL<float>(E->L, 3, true);
uint32 spell = Eluna::CHECKVAL<uint32>(E->L, 4, 0);

uint32 schoolMask = Eluna::CHECKVAL<uint32>(E->L, 5, 0);
SpellEntry const* spellEntry = GetSpellStore()->LookupEntry<SpellEntry>(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<SpellSchoolMask>(spellEntry->SchoolMask) : SPELL_SCHOOL_MASK_NONE, spellEntry);
#endif
return 0;
}

ElunaRegister<Unit> UnitMethods[] =
{
Expand Down Expand Up @@ -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 },
Expand All @@ -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
Expand Down
37 changes: 27 additions & 10 deletions TrinityCore/CreatureMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <pre>
* 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,
* }
* </pre>
*
* @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<Unit>(E->L, 2);
float amt = Eluna::CHECKVAL<float>(E->L, 3);
Unit* victim = Eluna::CHECKOBJ<Unit>(E->L, 2);
float threat = Eluna::CHECKVAL<float>(E->L, 3, true);
uint32 spell = Eluna::CHECKVAL<uint32>(E->L, 4, 0);

creature->GetThreatManager().AddThreat(target, amt);
creature->GetThreatManager().AddThreat(victim, threat, spell ? sSpellMgr->GetSpellInfo(spell) : NULL, true, true);
return 0;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 },
Expand Down
42 changes: 0 additions & 42 deletions TrinityCore/UnitMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -2434,38 +2425,6 @@ namespace LuaUnit
return 0;
}

/**
* Adds threat to the [Unit] from the victim.
*
* <pre>
* 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,
* }
* </pre>
*
* @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<Unit>(E->L, 2);
float threat = Eluna::CHECKVAL<float>(E->L, 3, true);
uint32 spell = Eluna::CHECKVAL<uint32>(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();
Expand Down Expand Up @@ -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 },
Expand Down

0 comments on commit a2b6080

Please sign in to comment.