Skip to content

Commit

Permalink
Add silent strategy to make bots not talk
Browse files Browse the repository at this point in the history
  • Loading branch information
davidonete committed May 12, 2024
1 parent 298eb77 commit 2b6d51f
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 34 deletions.
73 changes: 46 additions & 27 deletions playerbot/PlayerbotAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2447,11 +2447,14 @@ std::vector<Player*> PlayerbotAI::GetPlayersInGroup()
return members;
}

bool PlayerbotAI::TellPlayerNoFacing(Player* player, std::string text, PlayerbotSecurityLevel securityLevel, bool isPrivate, bool noRepeat)
bool PlayerbotAI::TellPlayerNoFacing(Player* player, std::string text, PlayerbotSecurityLevel securityLevel, bool isPrivate, bool noRepeat, bool ignoreSilent)
{
if(!player)
return false;

if (!ignoreSilent && HasStrategy("silent", BotState::BOT_STATE_NON_COMBAT))
return false;

time_t lastSaid = whispers[text];
if (!noRepeat || !lastSaid || (time(0) - lastSaid) >= sPlayerbotAIConfig.repeatDelay / 1000)
{
Expand All @@ -2464,9 +2467,10 @@ bool PlayerbotAI::TellPlayerNoFacing(Player* player, std::string text, Playerbot
if (!isPrivate && bot->GetGroup())
{
recievers = GetPlayersInGroup();

if(!recievers.empty())
{
type = bot->GetGroup()->IsRaidGroup() ? CHAT_MSG_RAID : CHAT_MSG_PARTY;
}
}

if (type == CHAT_MSG_SYSTEM && HasRealPlayerMaster())
Expand All @@ -2477,46 +2481,61 @@ bool PlayerbotAI::TellPlayerNoFacing(Player* player, std::string text, Playerbot

WorldPacket data;

switch (type) {
case CHAT_MSG_SAY:
bot->Say(text, (bot->GetTeam() == ALLIANCE ? LANG_COMMON : LANG_ORCISH));
return true;
case CHAT_MSG_RAID:
case CHAT_MSG_PARTY:
ChatHandler::BuildChatPacket(data, type, text.c_str(), LANG_UNIVERSAL, CHAT_TAG_NONE, bot->GetObjectGuid(), bot->GetName());
switch (type)
{
case CHAT_MSG_SAY:
{
bot->Say(text, (bot->GetTeam() == ALLIANCE ? LANG_COMMON : LANG_ORCISH));
return true;
}

for (auto reciever : recievers)
sServerFacade.SendPacket(reciever, data);
case CHAT_MSG_RAID:
case CHAT_MSG_PARTY:
{
ChatHandler::BuildChatPacket(data, type, text.c_str(), LANG_UNIVERSAL, CHAT_TAG_NONE, bot->GetObjectGuid(), bot->GetName());

return true;
case CHAT_MSG_WHISPER:
if (!IsTellAllowed(player, securityLevel))
return false;
for (auto reciever : recievers)
{
sServerFacade.SendPacket(reciever, data);
}

if (!HasRealPlayerMaster())
return false;
return true;
}

whispers[text] = time(0);
case CHAT_MSG_WHISPER:
{
if (!IsTellAllowed(player, securityLevel))
return false;

if (currentChat.second >= time(0))
type = currentChat.first;
if (!HasRealPlayerMaster())
return false;

whispers[text] = time(0);

if (type == CHAT_MSG_ADDON)
text = "BOT\t" + text;
if (currentChat.second >= time(0))
type = currentChat.first;

ChatHandler::BuildChatPacket(data, type == CHAT_MSG_ADDON ? CHAT_MSG_PARTY : type, text.c_str(), type == CHAT_MSG_ADDON ? LANG_ADDON : LANG_UNIVERSAL, CHAT_TAG_NONE, bot->GetObjectGuid(), bot->GetName());
sServerFacade.SendPacket(player, data);
if (type == CHAT_MSG_ADDON)
text = "BOT\t" + text;

ChatHandler::BuildChatPacket(data, type == CHAT_MSG_ADDON ? CHAT_MSG_PARTY : type, text.c_str(), type == CHAT_MSG_ADDON ? LANG_ADDON : LANG_UNIVERSAL, CHAT_TAG_NONE, bot->GetObjectGuid(), bot->GetName());
sServerFacade.SendPacket(player, data);
return true;
}
}
}

return true;
}

bool PlayerbotAI::TellError(Player* player, std::string text, PlayerbotSecurityLevel securityLevel)
bool PlayerbotAI::TellError(Player* player, std::string text, PlayerbotSecurityLevel securityLevel, bool ignoreSilent)
{
if (!IsTellAllowed(player, securityLevel) || !IsSafe(player) || player->GetPlayerbotAI())
return false;

if (!ignoreSilent && HasStrategy("silent", BotState::BOT_STATE_NON_COMBAT))
return false;

PlayerbotMgr* mgr = player->GetPlayerbotMgr();
if (mgr) mgr->TellError(bot->GetName(), text);

Expand All @@ -2539,9 +2558,9 @@ bool PlayerbotAI::IsTellAllowed(Player* player, PlayerbotSecurityLevel securityL
return true;
}

bool PlayerbotAI::TellPlayer(Player* player, std::string text, PlayerbotSecurityLevel securityLevel, bool isPrivate)
bool PlayerbotAI::TellPlayer(Player* player, std::string text, PlayerbotSecurityLevel securityLevel, bool isPrivate, bool ignoreSilent)
{
if (!TellPlayerNoFacing(player, text, securityLevel, isPrivate))
if (!TellPlayerNoFacing(player, text, securityLevel, isPrivate, ignoreSilent))
return false;

if (player && !player->IsBeingTeleported() && !sServerFacade.isMoving(bot) && !sServerFacade.IsInCombat(bot) && bot->GetMapId() == player->GetMapId() && !bot->IsTaxiFlying() && !bot->IsFlying())
Expand Down
10 changes: 5 additions & 5 deletions playerbot/PlayerbotAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,11 @@ class PlayerbotAI : public PlayerbotAIBase
static GameObject* GetGameObject(GameObjectDataPair const* gameObjectDataPair);
WorldObject* GetWorldObject(ObjectGuid guid);
std::vector<Player*> GetPlayersInGroup();
bool TellPlayer(Player* player, std::ostringstream &stream, PlayerbotSecurityLevel securityLevel = PlayerbotSecurityLevel::PLAYERBOT_SECURITY_ALLOW_ALL, bool isPrivate = true) { return TellPlayer(player, stream.str(), securityLevel, isPrivate); }
bool TellPlayer(Player* player, std::string text, PlayerbotSecurityLevel securityLevel = PlayerbotSecurityLevel::PLAYERBOT_SECURITY_ALLOW_ALL, bool isPrivate = true);
bool TellPlayerNoFacing(Player* player, std::ostringstream& stream, PlayerbotSecurityLevel securityLevel = PlayerbotSecurityLevel::PLAYERBOT_SECURITY_ALLOW_ALL, bool isPrivate = true, bool noRepeat = true) { return TellPlayerNoFacing(player, stream.str(), securityLevel, isPrivate, noRepeat); }
bool TellPlayerNoFacing(Player* player, std::string text, PlayerbotSecurityLevel securityLevel = PlayerbotSecurityLevel::PLAYERBOT_SECURITY_ALLOW_ALL, bool isPrivate = true, bool noRepeat = true);
bool TellError(Player* player, std::string text, PlayerbotSecurityLevel securityLevel = PlayerbotSecurityLevel::PLAYERBOT_SECURITY_ALLOW_ALL);
bool TellPlayer(Player* player, std::ostringstream &stream, PlayerbotSecurityLevel securityLevel = PlayerbotSecurityLevel::PLAYERBOT_SECURITY_ALLOW_ALL, bool isPrivate = true, bool ignoreSilent = false) { return TellPlayer(player, stream.str(), securityLevel, isPrivate, ignoreSilent); }
bool TellPlayer(Player* player, std::string text, PlayerbotSecurityLevel securityLevel = PlayerbotSecurityLevel::PLAYERBOT_SECURITY_ALLOW_ALL, bool isPrivate = true, bool ignoreSilent = false);
bool TellPlayerNoFacing(Player* player, std::ostringstream& stream, PlayerbotSecurityLevel securityLevel = PlayerbotSecurityLevel::PLAYERBOT_SECURITY_ALLOW_ALL, bool isPrivate = true, bool noRepeat = true, bool ignoreSilent = false) { return TellPlayerNoFacing(player, stream.str(), securityLevel, isPrivate, noRepeat, ignoreSilent); }
bool TellPlayerNoFacing(Player* player, std::string text, PlayerbotSecurityLevel securityLevel = PlayerbotSecurityLevel::PLAYERBOT_SECURITY_ALLOW_ALL, bool isPrivate = true, bool noRepeat = true, bool ignoreSilent = false);
bool TellError(Player* player, std::string text, PlayerbotSecurityLevel securityLevel = PlayerbotSecurityLevel::PLAYERBOT_SECURITY_ALLOW_ALL, bool ignoreSilent = false);
void SpellInterrupted(uint32 spellid);
int32 CalculateGlobalCooldown(uint32 spellid);
void InterruptSpell(bool withMeleeAndAuto = true);
Expand Down
2 changes: 1 addition & 1 deletion playerbot/strategy/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ void Engine::PrintStrategies(Player* requester, const std::string& engineType)
std::string engineStrategies = engineType;
engineStrategies.append(" Strategies: ");
engineStrategies.append(ListStrategies());
ai->TellPlayer(requester, engineStrategies);
ai->TellPlayer(requester, engineStrategies, PlayerbotSecurityLevel::PLAYERBOT_SECURITY_ALLOW_ALL, true, true);
}

void Engine::LogValues()
Expand Down
2 changes: 2 additions & 0 deletions playerbot/strategy/StrategyContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ namespace ai
creators["heal interrupt"] = &StrategyContext::heal_interrupt;
creators["preheal"] = &StrategyContext::preheal;
creators["wbuff"] = &StrategyContext::world_buff;
creators["silent"] = &StrategyContext::silent;

// Dungeon Strategies
creators["dungeon"] = &StrategyContext::dungeon;
Expand Down Expand Up @@ -237,6 +238,7 @@ namespace ai
static Strategy* heal_interrupt(PlayerbotAI* ai) { return new HealInterruptStrategy(ai); }
static Strategy* preheal(PlayerbotAI* ai) { return new PreHealStrategy(ai); }
static Strategy* world_buff(PlayerbotAI* ai) { return new WorldBuffStrategy(ai); }
static Strategy* silent(PlayerbotAI* ai) { return new SilentStrategy(ai); }

// Dungeon Strategies
static Strategy* dungeon(PlayerbotAI* ai) { return new DungeonStrategy(ai); }
Expand Down
8 changes: 8 additions & 0 deletions playerbot/strategy/actions/SayAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ bool SayAction::isUseful()
if (!ai->AllowActivity())
return false;

if (ai->HasStrategy("silent", BotState::BOT_STATE_NON_COMBAT))
return false;

time_t lastSaid = AI_VALUE2(time_t, "last said", qualifier);
return (time(0) - lastSaid) > 30;
}
Expand Down Expand Up @@ -690,3 +693,8 @@ void ChatReplyAction::ChatReplyDo(Player* bot, uint32 type, uint32 guid1, uint32
bot->GetPlayerbotAI()->GetAiObjectContext()->GetValue<time_t>("last said", "chat")->Set(time(0) + urand(5, 25));
}
}

bool ChatReplyAction::isUseful()
{
return !ai->HasStrategy("silent", BotState::BOT_STATE_NON_COMBAT);
}
2 changes: 1 addition & 1 deletion playerbot/strategy/actions/SayAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace ai
public:
ChatReplyAction(PlayerbotAI* ai) : Action(ai, "chat message") {}
virtual bool Execute(Event& event) { return true; }
bool isUseful() { return true; }
bool isUseful();
static void ChatReplyDo(Player* bot, uint32 type, uint32 guid1, uint32 guid2, std::string msg, std::string chanName, std::string name);
};
}
8 changes: 8 additions & 0 deletions playerbot/strategy/generic/NonCombatStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,12 @@ namespace ai
virtual void InitNonCombatTriggers(std::list<TriggerNode*>& triggers) override;
void OnStrategyRemoved(BotState state) override;
};

class SilentStrategy : public Strategy
{
public:
SilentStrategy(PlayerbotAI* ai) : Strategy(ai) {}
virtual int GetType() { return STRATEGY_TYPE_NONCOMBAT; }
virtual std::string getName() { return "silent"; }
};
}

0 comments on commit 2b6d51f

Please sign in to comment.