Skip to content

Commit

Permalink
Factionaction: Various fixes to make the faction command not crash an…
Browse files Browse the repository at this point in the history
…d display the correct factions.
  • Loading branch information
mostlikely4r committed Nov 14, 2024
1 parent ccba436 commit 8d42830
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
8 changes: 7 additions & 1 deletion playerbot/ChatHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ std::set<uint32> ChatHelper::ExtractAllFactionIds(const std::string& text)
for (std::sregex_iterator i = begin; i != end; ++i)
{
std::smatch match = *i;
ids.insert(std::stoi(match.str().erase(0, 7)));
ids.insert(std::stoi(match.str().erase(0, 9)));
}

return ids;
Expand Down Expand Up @@ -606,6 +606,9 @@ std::string ChatHelper::formatSkill(uint32 skillId, Player* player)
if (skillInfo)
{
int loc_idx = sPlayerbotTextMgr.GetLocalePriority();

if (loc_idx = -1)
loc_idx = 0;
name = skillInfo->name[loc_idx];
}
std::ostringstream out;
Expand Down Expand Up @@ -641,6 +644,7 @@ std::string ChatHelper::formatFaction(uint32 factionId, Player* player)
ReputationRankStrIndex[REP_HATED] = LANG_REP_HATED;
ReputationRankStrIndex[REP_HOSTILE] = LANG_REP_HOSTILE;
ReputationRankStrIndex[REP_UNFRIENDLY] = LANG_REP_UNFRIENDLY;
ReputationRankStrIndex[REP_NEUTRAL] = LANG_REP_NEUTRAL;
ReputationRankStrIndex[REP_FRIENDLY] = LANG_REP_FRIENDLY;
ReputationRankStrIndex[REP_HONORED] = LANG_REP_HONORED;
ReputationRankStrIndex[REP_REVERED] = LANG_REP_REVERED;
Expand All @@ -655,6 +659,8 @@ std::string ChatHelper::formatFaction(uint32 factionId, Player* player)
if (factionEntry)
{
int loc_idx = sPlayerbotTextMgr.GetLocalePriority();
if (loc_idx = -1)
loc_idx = 0;
name = factionEntry->name[loc_idx];
}
std::ostringstream out;
Expand Down
52 changes: 31 additions & 21 deletions playerbot/strategy/actions/FactionAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ bool FactionAction::Execute(Event& event)
Player* requester = event.getOwner() ? event.getOwner() : GetMaster();
std::string cmd = event.getParam();

bool setwar = (cmd.find("+atwar") == 0);
bool setWar = (cmd.find("+atwar") == 0);
bool removeWar = (cmd.find("-atwar") == 0);

std::string factionName = cmd;
std::string factionName;

if ((setWar || removeWar) && cmd.size() > 6)
factionName = cmd.substr(7);

if (setwar || removeWar)
factionName = factionName.substr(7);

std::wstring wnamepart;

Expand All @@ -31,7 +32,7 @@ bool FactionAction::Execute(Event& event)
bool factionFound = false;
std::map<std::string, std::string> args;

for (uint32 id = 0; id < sSkillLineStore.GetNumRows(); ++id)
for (uint32 id = 0; id < sFactionStore.GetNumRows(); ++id)
{
#ifndef MANGOSBOT_ONE
const FactionEntry* factionEntry = sFactionStore.LookupEntry(id);
Expand All @@ -44,10 +45,16 @@ bool FactionAction::Execute(Event& event)

FactionState const* repState = bot->GetReputationMgr().GetState(factionEntry);

if (!repState || repState->Flags & FACTION_FLAG_VISIBLE)
if (!repState)
continue;

if(!(repState->Flags & FACTION_FLAG_VISIBLE))
continue;

if (!bot->HasSkill(id))
if(repState->Flags & FACTION_FLAG_HIDDEN)
continue;

if (repState->Flags & FACTION_FLAG_INVISIBLE_FORCED)
continue;

int loc = requester->GetSession()->GetSessionDbcLocale();
Expand Down Expand Up @@ -81,21 +88,21 @@ bool FactionAction::Execute(Event& event)
{
ReputationMgr& mgr = bot->GetReputationMgr();

if (setwar || removeWar)
if (setWar || removeWar)
{
args["%factionname"] = ChatHelper::formatSkill(id);

if (removeWar && mgr.IsAtWar(id) && bot->GetReputationMgr().GetRank(factionEntry) == REP_HATED)
{
ai->TellPlayerNoFacing(requester, BOT_TEXT2("Unable uncheck at war for %factionname because they hate me too much.", args));
return false;
}
args["%factionname"] = ChatHelper::formatFaction(id);

if (!factionName.empty())
{
if (repState->Flags & FACTION_FLAG_INVISIBLE_FORCED)
if (removeWar && mgr.IsAtWar(id) && bot->GetReputationMgr().GetRank(factionEntry) < REP_HOSTILE)
{
ai->TellPlayerNoFacing(requester, BOT_TEXT2("Unable uncheck at war for %factionname because they hate me too much.", args));
return false;
}

if (repState->Flags & FACTION_FLAG_PEACE_FORCED)
{
ai->TellPlayerNoFacing(requester, BOT_TEXT2("Unable change at war for %factionname because the warstate is forced.", args));
ai->TellPlayerNoFacing(requester, BOT_TEXT2("Unable change at war for %factionname because peace is forced for this faction.", args));
return false;
}

Expand All @@ -105,16 +112,16 @@ bool FactionAction::Execute(Event& event)
return false;
}

if (setwar && mgr.IsAtWar(id))
if (setWar && mgr.IsAtWar(id))
{
ai->TellPlayerNoFacing(requester, BOT_TEXT2("I already have at war checked for %factionname.", args));
return false;
}
}

bot->GetReputationMgr().SetAtWar(id, setwar);
bot->GetReputationMgr().SetAtWar(repState->ReputationListID, setWar);

if(setwar)
if(setWar)
ai->TellPlayerNoFacing(requester, BOT_TEXT2("Checked at war for %factionname", args));
else
ai->TellPlayerNoFacing(requester, BOT_TEXT2("Unchecked at war for %factionname", args));
Expand All @@ -132,7 +139,10 @@ bool FactionAction::Execute(Event& event)
{
if (factionName.empty())
{
ai->TellPlayerNoFacing(requester, BOT_TEXT2("I do not have any visible factions.", args));
if (setWar || removeWar)
ai->TellPlayerNoFacing(requester, BOT_TEXT2("I do not have any factions where I can toggle at war.", args));
else
ai->TellPlayerNoFacing(requester, BOT_TEXT2("I do not have any visible factions.", args));
}
else
{
Expand Down

0 comments on commit 8d42830

Please sign in to comment.