mod-playerbots/src/Ai/Base/Actions/ChatShortcutActions.cpp
kadeshar 55c5d29e2d
Replace hardcoded bot texts (#2408)
<!--
Thank you for contributing to mod-playerbots, please make sure that
you...
1. Submit your PR to the test-staging branch, not master.
2. Read the guidelines below before submitting.
3. Don't delete parts of this template.

DESIGN PHILOSOPHY: We prioritize STABILITY, PERFORMANCE, AND
PREDICTABILITY over behavioral realism.

Every action and decision executes PER BOT AND PER TRIGGER. Small
increases in logic complexity scale
poorly across thousands of bots and negatively affect all. We prioritize
a stable system over a smarter
one. Bots don't need to behave perfectly; believable behavior is the
goal, not human simulation.
Default behavior must be cheap in processing; expensive behavior must be
opt-in.

Before submitting, make sure your changes aligns with these principles.
-->

## Pull Request Description
<!-- Describe what this change does and why it is needed -->

Replaced hardcoded bot text with translationable.

Related with: #1295 


## How to Test the Changes
<!--
- Step-by-step instructions to test the change.
- Any required setup (e.g. multiple players, number of bots, specific
configuration).
- Expected behavior and how to verify it.
-->

1. Invite bots
2. Check that text after "follow" and "stay" return texts "Following"
and "Staying"

## Impact Assessment
<!-- As a generic test, before and after measure of pmon (playerbot pmon
tick) can help you here. -->
- Does this change increase per-bot/per-tick processing or risk scaling
poorly with thousands of bots?
    - - [x] No, not at all
    - - [ ] Minimal impact (**explain below**)
    - - [ ] Moderate impact (**explain below**)



- Does this change modify default bot behavior?
    - - [x] No
    - - [ ] Yes (**explain why**)



- Does this change add new decision branches or increase maintenance
complexity?
    - - [x] No
    - - [ ] Yes (**explain below**)



## AI Assistance
<!--
AI assistance is allowed, but all submitted code must be fully
understood, reviewed, and owned by the contributor.
We expect contributors to be honest about what they do and do not
understand.
-->
Was AI assistance used while working on this change?
- - [ ] No
- - [x] Yes (**explain below**)
<!--
If yes, please specify:
- Purpose of usage (e.g. brainstorming, refactoring, documentation, code
generation).
- Which parts of the change were influenced or generated, and whether it
was thoroughly reviewed.
-->

Summary hardcoded text and checking that they already exists to reuse.

<!--
TRANSLATIONS:
Anything new that the bots say in chat must be in a translatable format.
This is done using GetBotTextOrDefault,
which you can search for in the codebase to find examples. Your code
needs to have English as the default fallback,
while the full translations need to be in an SQL update file. The
languages in the file are the nine language
options supported by AzerothCore: English, Korean, French, German,
Chinese, Taiwanese, Spanish, Spanish Mexico, and
Russian. See
data/sql/playerbots/updates/2025_12_27_ai_playerbot_fishing_text.sql as
an example of a translation SQL
update, whose content are called within the codebase at
src/strategy/actions/FishingAction.cpp
-->

## Final Checklist

- - [x] Stability is not compromised.
- - [x] Performance impact is understood, tested, and acceptable.
- - [x] Added logic complexity is justified and explained.
- - [x] Any new bot dialogue lines are translated.
- - [x] Documentation updated if needed (Conf comments, WiKi commands).

## Notes for Reviewers
<!-- Anything else that's helpful to review or test your pull request.
-->
2026-05-22 21:41:24 -07:00

276 lines
8.2 KiB
C++

/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license, you may redistribute it
* and/or modify it under version 3 of the License, or (at your option), any later version.
*/
#include "ChatShortcutActions.h"
#include "Event.h"
#include "Formations.h"
#include "PlayerbotTextMgr.h"
#include "Playerbots.h"
#include "PositionValue.h"
void PositionsResetAction::ResetReturnPosition()
{
PositionMap& posMap = context->GetValue<PositionMap&>("position")->Get();
PositionInfo pos = posMap["return"];
pos.Reset();
posMap["return"] = pos;
}
void PositionsResetAction::SetReturnPosition(float x, float y, float z)
{
PositionMap& posMap = context->GetValue<PositionMap&>("position")->Get();
PositionInfo pos = posMap["return"];
pos.Set(x, y, z, botAI->GetBot()->GetMapId());
posMap["return"] = pos;
}
void PositionsResetAction::ResetStayPosition()
{
PositionMap& posMap = context->GetValue<PositionMap&>("position")->Get();
PositionInfo pos = posMap["stay"];
pos.Reset();
posMap["stay"] = pos;
}
void PositionsResetAction::SetStayPosition(float x, float y, float z)
{
PositionMap& posMap = context->GetValue<PositionMap&>("position")->Get();
PositionInfo pos = posMap["stay"];
pos.Set(x, y, z, botAI->GetBot()->GetMapId());
posMap["stay"] = pos;
}
bool FollowChatShortcutAction::Execute(Event /*event*/)
{
Player* master = GetMaster();
if (!master)
return false;
// botAI->Reset();
botAI->ChangeStrategy("+follow,-passive,-grind,-move from group", BOT_STATE_NON_COMBAT);
botAI->ChangeStrategy("-stay,-follow,-passive,-grind,-move from group", BOT_STATE_COMBAT);
botAI->GetAiObjectContext()->GetValue<GuidVector>("prioritized targets")->Reset();
PositionMap& posMap = context->GetValue<PositionMap&>("position")->Get();
PositionInfo pos = posMap["return"];
pos.Reset();
posMap["return"] = pos;
pos = posMap["stay"];
pos.Reset();
posMap["stay"] = pos;
if (bot->IsInCombat())
{
Formation* formation = AI_VALUE(Formation*, "formation");
std::string const target = formation->GetTargetName();
bool moved = false;
if (!target.empty())
moved = Follow(AI_VALUE(Unit*, target));
else
{
WorldLocation loc = formation->GetLocation();
if (Formation::IsNullLocation(loc) || loc.GetMapId() == -1)
return false;
MovementPriority priority = botAI->GetState() == BOT_STATE_COMBAT ? MovementPriority::MOVEMENT_COMBAT : MovementPriority::MOVEMENT_NORMAL;
moved = MoveTo(loc.GetMapId(), loc.GetPositionX(), loc.GetPositionY(), loc.GetPositionZ(), false, false, false,
true, priority);
}
if (bot->GetPet())
botAI->PetFollow();
if (moved)
{
botAI->TellMaster(PlayerbotTextMgr::instance().GetBotTextOrDefault(
"following", "Following", {}));
return true;
}
}
/* Default mechanics takes care of this now.
if (bot->GetMapId() != master->GetMapId() || (master && bot->GetDistance(master) >
sPlayerbotAIConfig.sightDistance))
{
if (bot->isDead())
{
bot->ResurrectPlayer(1.0f, false);
botAI->TellMasterNoFacing("Back from the grave!");
}
else
botAI->TellMaster("You are too far away from me! I will there soon.");
bot->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_TELEPORTED | AURA_INTERRUPT_FLAG_CHANGE_MAP);
bot->TeleportTo(master->GetMapId(), master->GetPositionX(), master->GetPositionY(), master->GetPositionZ(),
master->GetOrientation()); return true;
}
*/
botAI->TellMaster(PlayerbotTextMgr::instance().GetBotTextOrDefault(
"following", "Following", {}));
return true;
}
bool StayChatShortcutAction::Execute(Event /*event*/)
{
Player* master = GetMaster();
if (!master)
return false;
botAI->Reset();
botAI->ChangeStrategy("+stay,-passive,-move from group", BOT_STATE_NON_COMBAT);
botAI->ChangeStrategy("+stay,-follow,-passive,-move from group", BOT_STATE_COMBAT);
SetReturnPosition(bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ());
SetStayPosition(bot->GetPositionX(), bot->GetPositionY(), bot->GetPositionZ());
botAI->TellMaster(PlayerbotTextMgr::instance().GetBotTextOrDefault(
"staying", "Staying", {}));
return true;
}
bool MoveFromGroupChatShortcutAction::Execute(Event /*event*/)
{
Player* master = GetMaster();
if (!master)
return false;
// dont need to remove stay or follow, move from group takes priority over both
// (see their isUseful() methods)
botAI->ChangeStrategy("+move from group", BOT_STATE_NON_COMBAT);
botAI->ChangeStrategy("+move from group", BOT_STATE_COMBAT);
botAI->TellMaster(PlayerbotTextMgr::instance().GetBotTextOrDefault(
"move_from_group", "Moving away from group", {}));
return true;
}
bool FleeChatShortcutAction::Execute(Event /*event*/)
{
Player* master = GetMaster();
if (!master)
return false;
botAI->Reset();
botAI->ChangeStrategy("+follow,-stay,+passive", BOT_STATE_NON_COMBAT);
botAI->ChangeStrategy("+follow,-stay,+passive", BOT_STATE_COMBAT);
ResetReturnPosition();
ResetStayPosition();
if (bot->GetMapId() != master->GetMapId() || bot->GetDistance(master) > sPlayerbotAIConfig.sightDistance)
{
botAI->TellError(PlayerbotTextMgr::instance().GetBotTextOrDefault(
"fleeing_far", "I will not flee with you - too far away", {}));
return true;
}
botAI->TellMaster(PlayerbotTextMgr::instance().GetBotTextOrDefault(
"fleeing", "Fleeing", {}));
return true;
}
bool GoawayChatShortcutAction::Execute(Event /*event*/)
{
Player* master = GetMaster();
if (!master)
return false;
botAI->Reset();
botAI->ChangeStrategy("+runaway,-stay", BOT_STATE_NON_COMBAT);
botAI->ChangeStrategy("+runaway,-stay", BOT_STATE_COMBAT);
ResetReturnPosition();
ResetStayPosition();
botAI->TellMaster(PlayerbotTextMgr::instance().GetBotTextOrDefault(
"running_away", "Running away", {}));
return true;
}
bool GrindChatShortcutAction::Execute(Event /*event*/)
{
Player* master = GetMaster();
if (!master)
return false;
botAI->Reset();
botAI->ChangeStrategy("+grind,-passive,-stay", BOT_STATE_NON_COMBAT);
ResetReturnPosition();
ResetStayPosition();
botAI->TellMaster(PlayerbotTextMgr::instance().GetBotTextOrDefault(
"grinding", "Grinding", {}));
return true;
}
bool TankAttackChatShortcutAction::Execute(Event /*event*/)
{
Player* master = GetMaster();
if (!master)
return false;
if (!botAI->IsTank(bot))
return false;
botAI->Reset();
botAI->ChangeStrategy("-passive", BOT_STATE_NON_COMBAT);
botAI->ChangeStrategy("-passive", BOT_STATE_COMBAT);
ResetReturnPosition();
ResetStayPosition();
botAI->TellMaster(PlayerbotTextMgr::instance().GetBotTextOrDefault(
"attacking", "Attacking", {}));
return true;
}
bool MaxDpsChatShortcutAction::Execute(Event /*event*/)
{
Player* master = GetMaster();
if (!master)
return false;
if (!botAI->ContainsStrategy(STRATEGY_TYPE_DPS))
return false;
botAI->Reset();
botAI->ChangeStrategy("-threat,-conserve mana,-cast time,+dps debuff,+boost", BOT_STATE_COMBAT);
botAI->TellMaster("Max DPS!");
return true;
}
bool NaxxChatShortcutAction::Execute(Event /*event*/)
{
Player* master = GetMaster();
if (!master)
return false;
botAI->Reset();
botAI->ChangeStrategy("+naxx", BOT_STATE_NON_COMBAT);
botAI->ChangeStrategy("+naxx", BOT_STATE_COMBAT);
botAI->TellMasterNoFacing("Add Naxx Strategies!");
// bot->Say("Add Naxx Strategies!", LANG_UNIVERSAL);
return true;
}
bool BwlChatShortcutAction::Execute(Event /*event*/)
{
Player* master = GetMaster();
if (!master)
return false;
botAI->Reset();
botAI->ChangeStrategy("+bwl", BOT_STATE_NON_COMBAT);
botAI->ChangeStrategy("+bwl", BOT_STATE_COMBAT);
botAI->TellMasterNoFacing("Add Bwl Strategies!");
return true;
}