Files
mod-playerbots/src/Ai/Base/Actions/ChatShortcutActions.cpp
Keleborn 441f9f7552 Warnings PR 1: Event warnings and headers (#2106)
# Pull Request

This is the first in a series of PRs intended to eliminate warnings in
the module. The design intent is to eliminate the calling event when not
needed in the body of the function. Based off of SmashingQuasars work.

---

## How to Test the Changes

- Step-by-step instructions to test the change
- Any required setup (e.g. multiple players, bots, specific
configuration)
- Expected behavior and how to verify it

## Complexity & Impact

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

- Does this change increase per-bot or per-tick processing?
    - [x] No
    - [ ] Yes (**describe and justify impact**)

- Could this logic scale poorly under load?
    - [x] No
    - [ ] Yes (**explain why**)

---

## Defaults & Configuration

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

If this introduces more advanced or AI-heavy logic:

- [ ] Lightweight mode remains the default
- [ ] More complex behavior is optional and thereby configurable

---

## AI Assistance

- Was AI assistance (e.g. ChatGPT or similar tools) used while working
on this change?
    - [x] No
    - [ ] Yes (**explain below**)

---

## Final Checklist

- [x] Stability is not compromised
- [x] Performance impact is understood, tested, and acceptable
- [x] Added logic complexity is justified and explained
- [x] Documentation updated if needed

---

## Notes for Reviewers

Anything that significantly improves realism at the cost of stability or
performance should be carefully discussed
before merging.

---------

Co-authored-by: bashermens <31279994+hermensbas@users.noreply.github.com>
2026-02-14 20:55:10 +01:00

256 lines
7.1 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 "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 (Pet* pet = bot->GetPet())
{
botAI->PetFollow();
}
if (moved)
{
botAI->TellMaster("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("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("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("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("I will not flee with you - too far away");
return true;
}
botAI->TellMaster("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("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("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("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 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;
}