Dungeon code cleanup

Consistent code, easier to read logic flow and some missing nullptr checks
This commit is contained in:
Bobblybook
2024-10-20 15:49:10 +11:00
parent a430786133
commit d0a9e98801
16 changed files with 106 additions and 151 deletions

View File

@@ -14,7 +14,7 @@ bool AttackFrostTombAction::Execute(Event event)
for (auto i = targets.begin(); i != targets.end(); ++i)
{
Unit* unit = botAI->GetUnit(*i);
if (unit && unit->GetName() == "Frost Tomb")
if (unit && unit->GetEntry() == NPC_FROST_TOMB)
{
frostTomb = unit;
break;
@@ -31,7 +31,9 @@ bool AttackFrostTombAction::Execute(Event event)
bool AttackDalronnAction::Execute(Event event)
{
Unit* boss = AI_VALUE2(Unit*, "find target", "dalronn the controller");
if (!boss || AI_VALUE(Unit*, "current target") == boss)
if (!boss) { return false; }
if (AI_VALUE(Unit*, "current target") == boss)
{
return false;
}
@@ -42,10 +44,7 @@ bool IngvarStopCastingAction::Execute(Event event)
{
// Doesn't work, this action gets queued behind the current spell instead of interrupting it
Unit* boss = AI_VALUE2(Unit*, "find target", "ingvar the plunderer");
if (!boss)
{
return false;
}
if (!boss) { return false; }
int32 my_spell_id = AI_VALUE(uint32, "active spell");
if (!my_spell_id || my_spell_id == 0)
@@ -54,10 +53,7 @@ bool IngvarStopCastingAction::Execute(Event event)
}
Spell* spell = bot->FindCurrentSpellBySpellId(my_spell_id);
if (!spell)
{
return false;
}
if (!spell) { return false; }
// bot->Yell("cancelling spell="+std::to_string(my_spell_id), LANG_UNIVERSAL);
bot->InterruptSpell(spell->GetCurrentContainer(), false, true, true);
@@ -71,10 +67,7 @@ bool IngvarDodgeSmashAction::isUseful() { return !AI_VALUE2(bool, "behind", "cur
bool IngvarDodgeSmashAction::Execute(Event event)
{
Unit* boss = AI_VALUE2(Unit*, "find target", "ingvar the plunderer");
if (!boss)
{
return false;
}
if (!boss) { return false; }
float distance = bot->GetExactDist2d(boss->GetPosition());
// Extra units to move into the boss, instead of being just 1 pixel past his midpoint.
@@ -88,10 +81,7 @@ bool IngvarSmashReturnAction::isUseful() { return AI_VALUE2(bool, "behind", "cur
bool IngvarSmashReturnAction::Execute(Event event)
{
Unit* boss = AI_VALUE2(Unit*, "find target", "ingvar the plunderer");
if (!boss)
{
return false;
}
if (!boss) { return false; }
float distance = bot->GetExactDist2d(boss->GetPosition());
return Move(bot->GetAngle(boss), distance + bot->GetMeleeReach());

View File

@@ -7,10 +7,8 @@
float PrinceKelesethMultiplier::GetValue(Action* action)
{
Unit* boss = AI_VALUE2(Unit*, "find target", "prince keleseth");
if (!boss)
{
return 1.0f;
}
if (!boss) { return 1.0f; }
if (dynamic_cast<DpsAssistAction*>(action))
{
return 0.0f;
@@ -20,13 +18,9 @@ float PrinceKelesethMultiplier::GetValue(Action* action)
float SkarvaldAndDalronnMultiplier::GetValue(Action* action)
{
// Unit* skarvald = AI_VALUE2(Unit*, "find target", "skarvald the constructor");
Unit* dalronn = AI_VALUE2(Unit*, "find target", "dalronn the controller");
if (!dalronn)
{
return 1.0f;
}
// Only need to deal with Dalronn here. If he's dead, just fall back to normal dps strat
Unit* boss = AI_VALUE2(Unit*, "find target", "dalronn the controller");
if (!boss) { return 1.0f; }
if (dynamic_cast<DpsAssistAction*>(action))
{
@@ -39,10 +33,7 @@ float IngvarThePlundererMultiplier::GetValue(Action* action)
{
Unit* boss = AI_VALUE2(Unit*, "find target", "ingvar the plunderer");
bool isTank = botAI->IsTank(bot);
if (!boss)
{
return 1.0f;
}
if (!boss) { return 1.0f; }
// Prevent movement actions overriding current movement, we're probably dodging a slam
if (isTank && bot->isMoving() && dynamic_cast<MovementAction*>(action))
@@ -60,10 +51,7 @@ float IngvarThePlundererMultiplier::GetValue(Action* action)
{
uint32 spellId = AI_VALUE2(uint32, "spell id", action->getName());
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
if (!spellInfo)
{
return 1.0f;
}
if (!spellInfo) { return 1.0f; }
uint32 castTime = spellInfo->CalcCastTime(bot);
if (castTime != 0)
@@ -73,10 +61,8 @@ float IngvarThePlundererMultiplier::GetValue(Action* action)
}
}
// Done with non-tank logic
if (!isTank)
{
return 1.0f;
}
if (!isTank) { return 1.0f; }
// TANK ONLY
if (boss->FindCurrentSpellBySpellId(SPELL_SMASH) ||
boss->FindCurrentSpellBySpellId(SPELL_DARK_SMASH))

View File

@@ -9,7 +9,7 @@ bool KelesethFrostTombTrigger::IsActive()
for (auto& member : members)
{
Unit* unit = botAI->GetUnit(member);
if (unit && unit->HasAura(DEBUFF_FROST_TOMB))
if (unit && unit->HasAura(SPELL_FROST_TOMB))
{
return true;
}
@@ -19,21 +19,17 @@ bool KelesethFrostTombTrigger::IsActive()
bool DalronnNontankTrigger::IsActive()
{
Unit* dalronn = AI_VALUE2(Unit*, "find target", "dalronn the controller");
if (!dalronn)
{
return false;
}
Unit* boss = AI_VALUE2(Unit*, "find target", "dalronn the controller");
if (!boss) { return false; }
return !botAI->IsTank(bot);
}
bool IngvarStaggeringRoarTrigger::IsActive()
{
Unit* boss = AI_VALUE2(Unit*, "find target", "ingvar the plunderer");
if (!boss)
{
return false;
}
if (!boss) { return false; }
if (boss->HasUnitState(UNIT_STATE_CASTING))
{
if (boss->FindCurrentSpellBySpellId(SPELL_STAGGERING_ROAR))
@@ -47,16 +43,12 @@ bool IngvarStaggeringRoarTrigger::IsActive()
bool IngvarDreadfulRoarTrigger::IsActive()
{
Unit* boss = AI_VALUE2(Unit*, "find target", "ingvar the plunderer");
if (!boss)
if (!boss) { return false; }
if (boss->HasUnitState(UNIT_STATE_CASTING) &&
boss->FindCurrentSpellBySpellId(SPELL_DREADFUL_ROAR))
{
return false;
}
if (boss->HasUnitState(UNIT_STATE_CASTING))
{
if (boss->FindCurrentSpellBySpellId(SPELL_DREADFUL_ROAR))
{
return true;
}
return true;
}
return false;
}
@@ -64,10 +56,7 @@ bool IngvarDreadfulRoarTrigger::IsActive()
bool IngvarSmashTankTrigger::IsActive()
{
Unit* boss = AI_VALUE2(Unit*, "find target", "ingvar the plunderer");
if (!boss || !botAI->IsTank(bot))
{
return false;
}
if (!boss || !botAI->IsTank(bot)) { return false; }
if (boss->HasUnitState(UNIT_STATE_CASTING))
{
@@ -86,20 +75,15 @@ bool IngvarSmashTankReturnTrigger::IsActive()
// if (!boss || !botAI->IsTank(bot) || boss->HasUnitState(UNIT_STATE_CASTING))
// Ignore casting state as Ingvar will sometimes chain-cast a roar after a smash..
// We don't want this to prevent our tank from repositioning properly.
if (!boss || !botAI->IsTank(bot))
{
return false;
}
if (!boss || !botAI->IsTank(bot)) { return false; }
return true;
}
bool NotBehindIngvarTrigger::IsActive()
{
Unit* boss = AI_VALUE2(Unit*, "find target", "ingvar the plunderer");
if (!boss || botAI->IsTank(bot))
{
return false;
}
if (!boss || botAI->IsTank(bot)) { return false; }
return AI_VALUE2(bool, "behind", "current target");
}