Skip to content

Commit

Permalink
-Debug feature: Added 'debug log' and 'debug logname' which logs a bo…
Browse files Browse the repository at this point in the history
…t's chat to the files chat_log.csv and chat_log_<botname>.csv respectively.
  • Loading branch information
mostlikely4r committed Oct 9, 2024
1 parent cac788f commit 2fc91ad
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
31 changes: 31 additions & 0 deletions playerbot/PlayerbotAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3178,6 +3178,37 @@ bool PlayerbotAI::TellPlayerNoFacing(Player* player, std::string text, Playerbot
if (type == CHAT_MSG_SYSTEM && (sPlayerbotAIConfig.randomBotSayWithoutMaster || HasStrategy("debug", BotState::BOT_STATE_NON_COMBAT)))
type = CHAT_MSG_SAY;

if ((sPlayerbotAIConfig.hasLog("chat_log.csv") && HasStrategy("debug log", BotState::BOT_STATE_NON_COMBAT)) || HasStrategy("debug logname", BotState::BOT_STATE_NON_COMBAT))
{
std::ostringstream out;
out << sPlayerbotAIConfig.GetTimestampStr() << "+00,";
out << bot->GetName() << ",";
out << std::fixed << std::setprecision(2);

out << std::to_string(bot->getRace()) << ",";
out << std::to_string(bot->getClass()) << ",";
float subLevel = GetLevelFloat();

out << subLevel << ",";
out << std::fixed << std::setprecision(2);
WorldPosition(bot).printWKT(out);

out << type << ",";
out << text;

if (HasStrategy("debug logname", BotState::BOT_STATE_NON_COMBAT))
{
std::string fileName = "chat_log_";
fileName += bot->GetName();
fileName += ".csv";
if (!sPlayerbotAIConfig.isLogOpen(fileName))
sPlayerbotAIConfig.openLog(fileName, "a", true);
sPlayerbotAIConfig.log(fileName, out.str().c_str());
}
else
sPlayerbotAIConfig.log("chat_log.csv", out.str().c_str());
}

WorldPacket data;

switch (type)
Expand Down
4 changes: 4 additions & 0 deletions playerbot/strategy/StrategyContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ namespace ai
creators["debug mount"] = &StrategyContext::debug_mount;
creators["debug grind"] = &StrategyContext::debug_grind;
creators["debug loot"] = &StrategyContext::debug_loot;
creators["debug log"] = &StrategyContext::debug_log;
creators["debug logname"] = &StrategyContext::debug_logname;
creators["rtsc"] = &StrategyContext::rtsc;
creators["rtsc jump"] = &StrategyContext::rtsc_jump;
creators["maintenance"] = &StrategyContext::maintenance;
Expand Down Expand Up @@ -231,6 +233,8 @@ namespace ai
static Strategy* debug_mount(PlayerbotAI* ai) { return new DebugMountStrategy(ai); }
static Strategy* debug_grind(PlayerbotAI* ai) { return new DebugGrindStrategy(ai); }
static Strategy* debug_loot(PlayerbotAI* ai) { return new DebugLootStrategy(ai); }
static Strategy* debug_log(PlayerbotAI* ai) { return new DebugLogStrategy(ai); }
static Strategy* debug_logname(PlayerbotAI* ai) { return new DebugLogNameStrategy(ai); }
static Strategy* rtsc(PlayerbotAI* ai) { return new RTSCStrategy(ai); }
static Strategy* rtsc_jump(PlayerbotAI* ai) { return new RTSCSJumptrategy(ai); }
static Strategy* maintenance(PlayerbotAI* ai) { return new MaintenanceStrategy(ai); }
Expand Down
30 changes: 30 additions & 0 deletions playerbot/strategy/generic/DebugStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,36 @@ namespace ai
return "This strategy will make the bot give chat feedback about looting.";
}
virtual std::vector<std::string> GetRelatedStrategies() { return { "debug" }; }
#endif
};

class DebugLogStrategy : public Strategy
{
public:
DebugLogStrategy(PlayerbotAI* ai) : Strategy(ai) {}
virtual int GetType() { return STRATEGY_TYPE_NONCOMBAT; }
virtual std::string getName() { return "debug log"; }
#ifdef GenerateBotHelp
virtual std::string GetHelpName() { return "debug log"; } //Must equal iternal name
virtual std::string GetHelpDescription() {
return "This strategy will bots log anything they say to master to a logfile";
}
virtual std::vector<std::string> GetRelatedStrategies() { return { "debug" }; }
#endif
};

class DebugLogNameStrategy : public Strategy
{
public:
DebugLogNameStrategy(PlayerbotAI* ai) : Strategy(ai) {}
virtual int GetType() { return STRATEGY_TYPE_NONCOMBAT; }
virtual std::string getName() { return "debug logname"; }
#ifdef GenerateBotHelp
virtual std::string GetHelpName() { return "debug logname"; } //Must equal iternal name
virtual std::string GetHelpDescription() {
return "This strategy will bots log anything they say to master to a logfile with the bot's name";
}
virtual std::vector<std::string> GetRelatedStrategies() { return { "debug" }; }
#endif
};
}

0 comments on commit 2fc91ad

Please sign in to comment.