refactor(Core/ScriptedAI): few improvements with threat methods (#13146)

improve threat scripts

Co-authored-by: Maelthyrr <lynethris@protonmail.ch>
This commit is contained in:
Maelthyr
2022-11-12 13:29:28 +01:00
committed by GitHub
parent 758ed35db3
commit c1c9dc6105
50 changed files with 100 additions and 73 deletions

View File

@@ -384,11 +384,35 @@ SpellInfo const* ScriptedAI::SelectSpell(Unit* target, uint32 school, uint32 mec
return apSpell[urand(0, spellCount - 1)];
}
void ScriptedAI::DoResetThreat()
void ScriptedAI::DoAddThreat(Unit* unit, float amount)
{
if (!unit)
return;
me->GetThreatMgr().AddThreat(unit, amount);
}
void ScriptedAI::DoModifyThreatByPercent(Unit* unit, int32 pct)
{
if (!unit)
return;
me->GetThreatMgr().ModifyThreatByPercent(unit, pct);
}
void ScriptedAI::DoResetThreat(Unit* unit)
{
if (!unit)
return;
me->GetThreatMgr().ResetThreat(unit);
}
void ScriptedAI::DoResetThreatList()
{
if (!me->CanHaveThreatList() || me->GetThreatMgr().isThreatListEmpty())
{
LOG_ERROR("entities.unit.ai", "DoResetThreat called for creature that either cannot have threat list or has empty threat list (me entry = {})", me->GetEntry());
LOG_ERROR("entities.unit.ai", "DoResetThreatList called for creature that either cannot have threat list or has empty threat list (me entry = {})", me->GetEntry());
return;
}
@@ -399,14 +423,8 @@ float ScriptedAI::DoGetThreat(Unit* unit)
{
if (!unit)
return 0.0f;
return me->GetThreatMgr().GetThreat(unit);
}
void ScriptedAI::DoModifyThreatPercent(Unit* unit, int32 pct)
{
if (!unit)
return;
me->GetThreatMgr().ModifyThreatByPercent(unit, pct);
return me->GetThreatMgr().GetThreat(unit);
}
void ScriptedAI::DoTeleportPlayer(Unit* unit, float x, float y, float z, float o)

View File

@@ -304,11 +304,20 @@ struct ScriptedAI : public CreatureAI
//Plays music for all players in the zone (zone = true) or the area (zone = false)
void DoPlayMusic(uint32 soundId, bool zone);
//Drops all threat to 0%. Does not remove players from the threat list
void DoResetThreat();
// Add specified amount of threat directly to victim (ignores redirection effects) - also puts victim in combat and engages them if necessary
void DoAddThreat(Unit* unit, float amount);
// Adds/removes the specified percentage from the specified victim's threat (to who, or me if not specified)
void DoModifyThreatByPercent(Unit* unit, int32 pct);
//Drops all threat to 0%. Does not remove players from the threat list
void DoResetThreat(Unit* unit);
// Resets the specified unit's threat list (me if not specified) - does not delete entries, just sets their threat to zero
void DoResetThreatList();
// Returns the threat level of victim towards who (or me if not specified)
float DoGetThreat(Unit* unit);
void DoModifyThreatPercent(Unit* unit, int32 pct);
//Teleports a player without dropping threat (only teleports to same map)
void DoTeleportPlayer(Unit* unit, float x, float y, float z, float o);