mirror of
https://github.com/liyunfan1223/mod-playerbots.git
synced 2026-06-20 15:39:25 +02:00
# Pull Request Feature - Enable multi node flying for bots - Bots currently only do node to node flying. This PR makes it so they can connect multiple noted. -- This is enabled by sending a vector containing the node sequence instead of a single destination node -- To minimize the run-time cost of searching for available nodes and connection, a cache of all possible connections is prepared at start up using a BFS search algorithm. Refactor - Move all world destination logic (cities, banks, inns) to existing Travel manager - Eliminate flightmastercache and integrate to new manager - replace SQLs calls with in-memory data search by core - Add in new map that stores creature areas by template. Clean up - Move other rpg files to related folder. (Next steps) The selection for where bots fly to should be smarter than it is. Instead of trying to determine where a bot can go, it should first decide where it should go, and then identify the correct way to get there. --- ## Feature Evaluation Please answer the following: - Describe the **minimum logic** required to achieve the intended behavior? - Describe the **cheapest implementation** that produces an acceptable result? - Describe the **runtime cost** when this logic executes across many bots? --- ## 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**) The call itself is fairly infrequent, and although now there are a greater number of paths available for the bots, I dont think it would be significant. ## Defaults & Configuration Does this change modify default bot behavior? - - [ ] No - - [x] Yes (**explain why**) If this introduces more advanced or AI-heavy logic: - - [x] 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? - - [ ] No - - [x] Yes (**explain below**) Gemini first suggested the use of a BFS algorithm. This was rewritten by me to actually work as intended. Verification by additional logging not present in final code. Claude code converted the SQL filtering to the atrocious if statements found in PrepareDestinationCache, but after verifying them it works. If there are better ways to do this Im open to it. --- ## 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.
199 lines
5.4 KiB
C++
199 lines
5.4 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 "RpgAction.h"
|
|
|
|
#include <random>
|
|
|
|
#include "ChatHelper.h"
|
|
#include "EmoteAction.h"
|
|
#include "Event.h"
|
|
#include "Formations.h"
|
|
#include "Playerbots.h"
|
|
#include "ServerFacade.h"
|
|
#include "RpgSubActions.h"
|
|
|
|
bool RpgAction::Execute(Event /*event*/)
|
|
{
|
|
GuidPosition guidP = AI_VALUE(GuidPosition, "rpg target");
|
|
if (!guidP && botAI->GetMaster())
|
|
{
|
|
if (WorldObject* target = ObjectAccessor::GetWorldObject(*bot, botAI->GetMaster()->GetTarget()))
|
|
{
|
|
guidP = GuidPosition(target);
|
|
if (guidP)
|
|
{
|
|
RemIgnore(guidP);
|
|
SET_AI_VALUE(GuidPosition, "rpg target", guidP);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (bot->GetShapeshiftForm() > 0)
|
|
bot->SetShapeshiftForm(FORM_NONE);
|
|
|
|
if (!SetNextRpgAction())
|
|
RESET_AI_VALUE(GuidPosition, "rpg target");
|
|
|
|
return true;
|
|
}
|
|
|
|
bool RpgAction::isUseful() { return AI_VALUE(GuidPosition, "rpg target"); }
|
|
|
|
bool RpgAction::SetNextRpgAction()
|
|
{
|
|
Strategy* rpgStrategy;
|
|
std::vector<Action*> actions;
|
|
std::vector<uint32> relevances;
|
|
std::vector<TriggerNode*> triggerNodes;
|
|
|
|
for (auto& strategy : botAI->GetAiObjectContext()->GetSupportedStrategies())
|
|
{
|
|
if (strategy.find("rpg") == std::string::npos)
|
|
continue;
|
|
|
|
rpgStrategy = botAI->GetAiObjectContext()->GetStrategy(strategy);
|
|
|
|
rpgStrategy->InitTriggers(triggerNodes);
|
|
|
|
for (auto& triggerNode : triggerNodes)
|
|
{
|
|
Trigger* trigger = context->GetTrigger(triggerNode->getName());
|
|
|
|
if (trigger)
|
|
{
|
|
|
|
triggerNode->setTrigger(trigger);
|
|
|
|
std::vector<NextAction> nextActions = triggerNode->getHandlers();
|
|
|
|
Trigger* trigger = triggerNode->getTrigger();
|
|
|
|
bool isChecked = false;
|
|
|
|
for (NextAction nextAction : nextActions)
|
|
{
|
|
if (nextAction.getRelevance() > 5.0f)
|
|
continue;
|
|
|
|
if (!isChecked && !trigger->IsActive())
|
|
break;
|
|
|
|
isChecked = true;
|
|
|
|
Action* action = botAI->GetAiObjectContext()->GetAction(nextAction.getName());
|
|
if (!dynamic_cast<RpgEnabled*>(action) || !action->isUseful() || !action->isPossible())
|
|
continue;
|
|
|
|
actions.push_back(action);
|
|
relevances.push_back((nextAction.getRelevance() - 1) * 500);
|
|
}
|
|
}
|
|
}
|
|
|
|
for (const auto i : triggerNodes)
|
|
{
|
|
delete i;
|
|
}
|
|
triggerNodes.clear();
|
|
}
|
|
|
|
if (actions.empty())
|
|
return false;
|
|
|
|
if (botAI->HasStrategy("debug rpg", BotState::BOT_STATE_NON_COMBAT))
|
|
{
|
|
std::vector<std::pair<Action*, uint32>> sortedActions;
|
|
|
|
for (int i = 0; i < actions.size(); i++)
|
|
sortedActions.push_back(std::make_pair(actions[i], relevances[i]));
|
|
|
|
std::sort(sortedActions.begin(), sortedActions.end(), [](std::pair<Action*, uint32>i, std::pair<Action*, uint32> j) {return i.second > j.second; });
|
|
|
|
std::stringstream ss;
|
|
ss << "------" << chat->FormatWorldobject(AI_VALUE(GuidPosition, "rpg target").GetWorldObject()) << "------";
|
|
bot->Say(ss.str(), LANG_UNIVERSAL);
|
|
botAI->TellMasterNoFacing(ss.str());
|
|
|
|
for (auto action : sortedActions)
|
|
{
|
|
std::ostringstream out;
|
|
|
|
out << " " << action.first->getName() << " " << action.second;
|
|
|
|
botAI->TellMasterNoFacing(out);
|
|
}
|
|
}
|
|
|
|
std::mt19937 gen(time(0));
|
|
|
|
TravelMgr::instance().weighted_shuffle(actions.begin(), actions.end(), relevances.begin(), relevances.end(), gen);
|
|
|
|
Action* action = actions.front();
|
|
|
|
if ((botAI->HasStrategy("debug", BotState::BOT_STATE_NON_COMBAT) || botAI->HasStrategy("debug rpg", BotState::BOT_STATE_NON_COMBAT)))
|
|
{
|
|
std::ostringstream out;
|
|
out << "do: ";
|
|
out << chat->FormatWorldobject(AI_VALUE(GuidPosition, "rpg target").GetWorldObject());
|
|
|
|
out << " " << action->getName();
|
|
|
|
botAI->TellMasterNoFacing(out);
|
|
}
|
|
|
|
SET_AI_VALUE(std::string, "next rpg action", action->getName());
|
|
|
|
return true;
|
|
}
|
|
|
|
bool RpgAction::AddIgnore(ObjectGuid guid)
|
|
{
|
|
if (HasIgnore(guid))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
GuidSet& ignoreList = context->GetValue<GuidSet&>("ignore rpg target")->Get();
|
|
ignoreList.insert(guid);
|
|
|
|
if (ignoreList.size() > 50)
|
|
ignoreList.erase(ignoreList.begin());
|
|
|
|
context->GetValue<GuidSet&>("ignore rpg target")->Set(ignoreList);
|
|
|
|
return true;
|
|
}
|
|
bool RpgAction::RemIgnore(ObjectGuid guid)
|
|
{
|
|
if (!HasIgnore(guid))
|
|
return false;
|
|
|
|
GuidSet& ignoreList = context->GetValue<GuidSet&>("ignore rpg target")->Get();
|
|
ignoreList.erase(ignoreList.find(guid));
|
|
|
|
context->GetValue<GuidSet&>("ignore rpg target")->Set(ignoreList);
|
|
|
|
return true;
|
|
}
|
|
|
|
bool RpgAction::HasIgnore(ObjectGuid guid)
|
|
{
|
|
GuidSet& ignoreList = context->GetValue<GuidSet&>("ignore rpg target")->Get();
|
|
if (ignoreList.empty())
|
|
return false;
|
|
|
|
if (ignoreList.find(guid) == ignoreList.end())
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool CRpgAction::isUseful()
|
|
{
|
|
RESET_AI_VALUE(GuidPosition, "rpg target");
|
|
return true;
|
|
};
|