[BattleGrounds] just a few little fixes before PR

This commit is contained in:
Fuzz
2024-07-22 15:50:05 +10:00
parent c69d828a51
commit be551a5618

View File

@@ -2413,33 +2413,33 @@ bool BGTactics::HandleConsoleCommand(ChatHandler* handler, char const* args)
handler->PSendSysMessage("|cffff0000Playerbot system is currently disabled!"); handler->PSendSysMessage("|cffff0000Playerbot system is currently disabled!");
return true; return true;
} }
WorldSession* m_session = handler->GetSession(); WorldSession* session = handler->GetSession();
if (!m_session) if (!session)
{ {
handler->PSendSysMessage("Command can only be used from an active session"); handler->PSendSysMessage("Command can only be used from an active session");
return true; return true;
} }
Player* player = m_session->GetPlayer(); std::string const commandOutput = HandleConsoleCommand(session, args);
if (!commandOutput.empty())
handler->PSendSysMessage(commandOutput.c_str());
return true;
}
std::string const BGTactics::HandleConsoleCommand(WorldSession* session, char const* args)
{
Player* player = session->GetPlayer();
if (!player) if (!player)
{ return "Error - session player not found";
handler->PSendSysMessage("Error - session player not found"); if (player->GetSession()->GetSecurity() < SEC_GAMEMASTER)
return true; return "Command can only be used by a GM";
}
if (player->GetSession()->GetSecurity() < SEC_GAMEMASTER) {
handler->PSendSysMessage("Command can only be used by a GM");
return true;
}
Battleground* bg = player->GetBattleground(); Battleground* bg = player->GetBattleground();
if (!bg) if (!bg)
{ return "Command can only be used within a battleground";
handler->PSendSysMessage("Command can only be used within a battleground");
return true;
}
BattlegroundTypeId bgType = bg->GetBgTypeID(); BattlegroundTypeId bgType = bg->GetBgTypeID();
if (bgType == BATTLEGROUND_RB) if (bgType == BATTLEGROUND_RB)
bgType = bg->GetBgTypeID(true); bgType = bg->GetBgTypeID(true);
char* cmd = strtok((char*)args, " "); char* cmd = strtok((char*)args, " ");
char* charname = strtok(nullptr, " "); //char* charname = strtok(nullptr, " ");
if (!strncmp(cmd, "showpath", 8)) if (!strncmp(cmd, "showpath", 8))
{ {
@@ -2447,10 +2447,7 @@ bool BGTactics::HandleConsoleCommand(ChatHandler* handler, char const* args)
if (!strncmp(cmd, "showpath=", 9)) if (!strncmp(cmd, "showpath=", 9))
{ {
if (sscanf(cmd, "showpath=%d", &num) == -1 || num < 0) if (sscanf(cmd, "showpath=%d", &num) == -1 || num < 0)
{ return "Bad showpath parameter";
handler->PSendSysMessage("Bad showpath parameter");
return true;
}
} }
std::vector<BattleBotPath*> const* vPaths; std::vector<BattleBotPath*> const* vPaths;
switch (bgType) switch (bgType)
@@ -2463,10 +2460,7 @@ bool BGTactics::HandleConsoleCommand(ChatHandler* handler, char const* args)
default: vPaths = nullptr; break; default: vPaths = nullptr; break;
} }
if (!vPaths) if (!vPaths)
{ return "This battleground has no paths and is unsupported";
handler->PSendSysMessage("This battleground has no paths and is unsupported");
return true;
}
if (num == -1) { if (num == -1) {
float closestPoint = FLT_MAX; float closestPoint = FLT_MAX;
for (uint32 j = 0; j < vPaths->size(); j++) for (uint32 j = 0; j < vPaths->size(); j++)
@@ -2484,10 +2478,7 @@ bool BGTactics::HandleConsoleCommand(ChatHandler* handler, char const* args)
} }
} }
if (num >= (*vPaths).size()) if (num >= (*vPaths).size())
{ return fmt::format("Path out of range of 0 - {}", vPaths->size() - 1);
handler->PSendSysMessage(fmt::format("Path out of range of 0 - {}", vPaths->size() - 1).c_str());
return true;
}
auto const& path = (*vPaths)[num]; auto const& path = (*vPaths)[num];
for (uint32 i = 0; i < path->size(); i++) for (uint32 i = 0; i < path->size(); i++)
{ {
@@ -2495,52 +2486,36 @@ bool BGTactics::HandleConsoleCommand(ChatHandler* handler, char const* args)
Creature* wpCreature = player->SummonCreature(15631, waypoint.x, waypoint.y, waypoint.z, 0, TEMPSUMMON_TIMED_DESPAWN, 15000u); Creature* wpCreature = player->SummonCreature(15631, waypoint.x, waypoint.y, waypoint.z, 0, TEMPSUMMON_TIMED_DESPAWN, 15000u);
wpCreature->SetOwnerGUID(player->GetGUID()); wpCreature->SetOwnerGUID(player->GetGUID());
} }
handler->PSendSysMessage(fmt::format("Showing path {}", num).c_str()); return fmt::format("Showing path {}", num);
return true;
} }
if (!strncmp(cmd, "showcreature=", 13)) if (!strncmp(cmd, "showcreature=", 13))
{ {
uint32 num; uint32 num;
if (sscanf(cmd, "showcreature=%u", &num) == -1) if (sscanf(cmd, "showcreature=%u", &num) == -1)
{ return "Bad showcreature parameter";
handler->PSendSysMessage("Bad showcreature parameter");
return true;
}
Creature* c = bg->GetBGCreature(num); Creature* c = bg->GetBGCreature(num);
if (!c) if (!c)
{ return "Creature not found";
handler->PSendSysMessage("Creature not found");
return true;
}
Creature* wpCreature = player->SummonCreature(15631, c->GetPositionX(), c->GetPositionY(), c->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN, 15000u); Creature* wpCreature = player->SummonCreature(15631, c->GetPositionX(), c->GetPositionY(), c->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN, 15000u);
wpCreature->SetOwnerGUID(player->GetGUID()); wpCreature->SetOwnerGUID(player->GetGUID());
handler->PSendSysMessage(fmt::format("Showing location of Creature {}", num).c_str()); return fmt::format("Showing location of Creature {}", num);
return true;
} }
if (!strncmp(cmd, "showobject=", 11)) if (!strncmp(cmd, "showobject=", 11))
{ {
uint32 num; uint32 num;
if (sscanf(cmd, "showobject=%u", &num) == -1) if (sscanf(cmd, "showobject=%u", &num) == -1)
{ return "Bad showobject parameter";
handler->PSendSysMessage("Bad showobject parameter");
return true;
}
GameObject* o = bg->GetBGObject(num); GameObject* o = bg->GetBGObject(num);
if (!o) if (!o)
{ return "GameObject not found";
handler->PSendSysMessage("GameObject not found");
return true;
}
Creature* wpCreature = player->SummonCreature(15631, o->GetPositionX(), o->GetPositionY(), o->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN, 15000u); Creature* wpCreature = player->SummonCreature(15631, o->GetPositionX(), o->GetPositionY(), o->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN, 15000u);
wpCreature->SetOwnerGUID(player->GetGUID()); wpCreature->SetOwnerGUID(player->GetGUID());
handler->PSendSysMessage(fmt::format("Showing location of GameObject {}", num).c_str()); return fmt::format("Showing location of GameObject {}", num);
return true;
} }
handler->PSendSysMessage("Unknown command"); return "usage: showpath(=[num]) / showcreature=[num] / showobject=[num]";
return true;
} }
// //
@@ -3139,8 +3114,7 @@ bool BGTactics::selectObjective(bool reset)
BattlegroundAV* alterValleyBG = (BattlegroundAV*)bg; BattlegroundAV* alterValleyBG = (BattlegroundAV*)bg;
uint32 role = context->GetValue<uint32>("bg role")->Get(); uint32 role = context->GetValue<uint32>("bg role")->Get();
bool supportDefense = role < 3;//defensive role and mine capture (mine capture disabled for now) bool supportDefense = role < 3;//defensive role and mine capture (mine capture disabled for now)
// TODO fix advancedAttack - its supposed to be mutually exclusive with above (ie: a > check). leaving as-is for now as it seems to effect horde vs ally balance bool advancedAttack = role > 5;//doesnt wait for point to be fully captured before moving on
bool advancedAttack = role < 7;//doesnt wait for point to be fully captured before moving on
// some of the code below is a bit inefficent (lots of rechecking same variables, could be made more efficient with a refactor) // some of the code below is a bit inefficent (lots of rechecking same variables, could be made more efficient with a refactor)
// but it's been left this way so it can be easily reordered. in future we could implement different strategies (eg: focus on // but it's been left this way so it can be easily reordered. in future we could implement different strategies (eg: focus on
@@ -3187,7 +3161,7 @@ bool BGTactics::selectObjective(bool reset)
// (supportDefense) defend objectives under attack // (supportDefense) defend objectives under attack
if (!BgObjective && supportDefense) if (!BgObjective && supportDefense)
{ {
// go to first defend objective under attack (the one closest to boss) // go to first defence objective under attack (the one closest to boss)
for (const auto& objective : AV_HordeDefendObjectives) for (const auto& objective : AV_HordeDefendObjectives)
{ {
if (alterValleyBG->GetAVNodeInfo(objective.first).State != POINT_DESTROYED && if (alterValleyBG->GetAVNodeInfo(objective.first).State != POINT_DESTROYED &&
@@ -4524,7 +4498,7 @@ bool BGTactics::resetObjective()
if (!bg) if (!bg)
return false; return false;
// sometimes change role // sometimes change role - should do so less often on larger BG's otherwise bots will spend too much time running around map instead of doing something useful
uint32 rollChangeOdds = BATTLEGROUND_AV == bg->GetBgTypeID() ? 63 : 5; uint32 rollChangeOdds = BATTLEGROUND_AV == bg->GetBgTypeID() ? 63 : 5;
if (!urand(0, rollChangeOdds) && !(bot->HasAura(BG_WS_SPELL_WARSONG_FLAG) || bot->HasAura(BG_WS_SPELL_SILVERWING_FLAG) || bot->HasAura(BG_EY_NETHERSTORM_FLAG_SPELL))) if (!urand(0, rollChangeOdds) && !(bot->HasAura(BG_WS_SPELL_WARSONG_FLAG) || bot->HasAura(BG_WS_SPELL_SILVERWING_FLAG) || bot->HasAura(BG_EY_NETHERSTORM_FLAG_SPELL)))
context->GetValue<uint32>("bg role")->Set(urand(0, 9)); context->GetValue<uint32>("bg role")->Set(urand(0, 9));