mirror of
https://github.com/liyunfan1223/mod-playerbots.git
synced 2026-06-20 23:49:25 +02:00
<!--
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 -->
I was getting annoyed by the constant "No event owner detected" message
after I enabled bot debugging messaging.
And then I figured that there is no reason that maintenance should
trigger this action every 5 seconds. So I swapped it to seldom, so it
runs every 5 mins. More Performance!
## Feature Evaluation
<!--
If your PR is very minimal (comment typo, wrong ID reference, etc), and
it is very obvious it will not have
any impact on performance, you may skip these question. If necessary, a
maintainer may ask you for them later.
-->
<!-- Please answer the following: -->
- Describe the **minimum logic** required to achieve the intended
behavior.
- Describe the **processing 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, number of bots, specific
configuration).
- Expected behavior and how to verify it.
-->
## 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?
- - [x] No
- - [ ] 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.
-->
<!--
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.
-->
247 lines
8.1 KiB
C++
247 lines
8.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 "DropQuestAction.h"
|
|
|
|
#include "ChatHelper.h"
|
|
#include "Event.h"
|
|
#include "Playerbots.h"
|
|
|
|
bool DropQuestAction::Execute(Event event)
|
|
{
|
|
std::string const link = event.getParam();
|
|
|
|
Player* master = GetMaster();
|
|
if (!master)
|
|
return false;
|
|
|
|
PlayerbotChatHandler handler(master);
|
|
uint32 entry = handler.extractQuestId(link);
|
|
|
|
// remove all quest entries for 'entry' from quest log
|
|
for (uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot)
|
|
{
|
|
uint32 logQuest = bot->GetQuestSlotQuestId(slot);
|
|
|
|
Quest const* quest = sObjectMgr->GetQuestTemplate(logQuest);
|
|
if (!quest)
|
|
continue;
|
|
|
|
if (logQuest == entry || link.find(quest->GetTitle()) != std::string::npos)
|
|
{
|
|
bot->SetQuestSlot(slot, 0);
|
|
|
|
// we ignore unequippable quest items in this case, its' still be equipped
|
|
bot->TakeQuestSourceItem(logQuest, false);
|
|
entry = logQuest;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!entry)
|
|
return false;
|
|
|
|
bot->RemoveRewardedQuest(entry);
|
|
bot->RemoveActiveQuest(entry, false);
|
|
|
|
if (botAI->HasStrategy("debug quest", BotState::BOT_STATE_NON_COMBAT) || botAI->HasStrategy("debug rpg", BotState::BOT_STATE_COMBAT))
|
|
{
|
|
const Quest* pQuest = sObjectMgr->GetQuestTemplate(entry);
|
|
const std::string text_quest = ChatHelper::FormatQuest(pQuest);
|
|
LOG_INFO("playerbots", "{} => Quest [ {} ] removed", bot->GetName(), pQuest->GetTitle());
|
|
bot->Say("Quest [ " + text_quest + " ] removed", LANG_UNIVERSAL);
|
|
}
|
|
|
|
botAI->TellMaster("Quest removed");
|
|
return true;
|
|
}
|
|
|
|
bool CleanQuestLogAction::Execute(Event event)
|
|
{
|
|
Player* requester = event.getOwner() ? event.getOwner() : GetMaster();
|
|
if (!requester)
|
|
return false;
|
|
|
|
if (!sPlayerbotAIConfig.dropObsoleteQuests)
|
|
return false;
|
|
|
|
// Only output this message if "debug rpg" strategy is enabled
|
|
if (botAI->HasStrategy("debug rpg", BotState::BOT_STATE_COMBAT))
|
|
botAI->TellMaster("Clean Quest Log command received, removing grey/trivial quests...");
|
|
|
|
uint8 botLevel = bot->GetLevel(); // Get bot's level
|
|
|
|
for (uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot)
|
|
{
|
|
uint32 questId = bot->GetQuestSlotQuestId(slot);
|
|
if (!questId)
|
|
continue;
|
|
|
|
const Quest* quest = sObjectMgr->GetQuestTemplate(questId);
|
|
if (!quest)
|
|
continue;
|
|
|
|
// Determine if quest is trivial by comparing levels
|
|
int32 questLevel = quest->GetQuestLevel();
|
|
if (questLevel == -1) // For scaling quests, default to bot level
|
|
questLevel = botLevel;
|
|
|
|
// Set the level difference for when a quest becomes trivial
|
|
// This was determined by using the Lua code the client uses
|
|
int32 trivialLevel = 5;
|
|
if (botLevel >= 40)
|
|
trivialLevel = 8;
|
|
else if (botLevel >= 30)
|
|
trivialLevel = 7;
|
|
else if (botLevel >= 20)
|
|
trivialLevel = 6;
|
|
|
|
// Check if the quest is trivial (grey) for the bot
|
|
if ((botLevel - questLevel) > trivialLevel)
|
|
{
|
|
// Output only if "debug rpg" strategy is enabled
|
|
if (botAI->HasStrategy("debug rpg", BotState::BOT_STATE_COMBAT))
|
|
botAI->TellMaster("Quest [ " + quest->GetTitle() + " ] will be removed because it is trivial (grey).");
|
|
|
|
// Remove quest
|
|
botAI->rpgStatistic.questDropped++;
|
|
bot->SetQuestSlot(slot, 0);
|
|
bot->TakeQuestSourceItem(questId, false);
|
|
bot->SetQuestStatus(questId, QUEST_STATUS_NONE);
|
|
bot->RemoveRewardedQuest(questId);
|
|
|
|
if (botAI->HasStrategy("debug rpg", BotState::BOT_STATE_COMBAT))
|
|
{
|
|
const std::string text_quest = ChatHelper::FormatQuest(quest);
|
|
LOG_INFO("playerbots", "{} => Quest [ {} ] removed", bot->GetName(), quest->GetTitle());
|
|
bot->Say("Quest [ " + text_quest + " ] removed", LANG_UNIVERSAL);
|
|
}
|
|
|
|
if (botAI->HasStrategy("debug rpg", BotState::BOT_STATE_COMBAT))
|
|
botAI->TellMaster("Quest [ " + quest->GetTitle() + " ] has been removed.");
|
|
}
|
|
else
|
|
{
|
|
// Only output if "debug rpg" strategy is enabled
|
|
if (botAI->HasStrategy("debug rpg", BotState::BOT_STATE_COMBAT))
|
|
botAI->TellMaster("Quest [ " + quest->GetTitle() + " ] is not trivial and will be kept.");
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void CleanQuestLogAction::DropQuestType(uint8& numQuest, uint8 wantNum, bool isGreen, bool hasProgress, bool isComplete)
|
|
{
|
|
std::vector<uint8> slots;
|
|
for (uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot)
|
|
slots.push_back(slot);
|
|
|
|
if (wantNum < 100)
|
|
{
|
|
std::random_device rd;
|
|
std::mt19937 g(rd());
|
|
std::shuffle(slots.begin(), slots.end(), g);
|
|
}
|
|
|
|
for (uint8 slot : slots)
|
|
{
|
|
uint32 questId = bot->GetQuestSlotQuestId(slot);
|
|
if (!questId)
|
|
continue;
|
|
|
|
Quest const* quest = sObjectMgr->GetQuestTemplate(questId);
|
|
if (!quest)
|
|
continue;
|
|
|
|
// Do not drop class quest, may be not rewarding gold but important spells
|
|
if (quest->GetRequiredClasses())
|
|
continue;
|
|
|
|
if (wantNum == 100)
|
|
numQuest++;
|
|
|
|
int32 lowLevelDiff = sWorld->getIntConfig(CONFIG_QUEST_LOW_LEVEL_HIDE_DIFF);
|
|
if (lowLevelDiff < 0 ||
|
|
bot->GetLevel() <= bot->GetQuestLevel(quest) + uint32(lowLevelDiff)) // Quest is not gray
|
|
{
|
|
if (bot->GetLevel() + 5 > bot->GetQuestLevel(quest)) // Quest is not red
|
|
{
|
|
if (!isGreen)
|
|
continue;
|
|
}
|
|
}
|
|
else // Quest is gray
|
|
{
|
|
if (isGreen)
|
|
continue;
|
|
}
|
|
|
|
if (HasProgress(bot, quest) && !hasProgress && bot->GetQuestStatus(questId) != QUEST_STATUS_FAILED)
|
|
continue;
|
|
|
|
if (bot->GetQuestStatus(questId) == QUEST_STATUS_COMPLETE && !isComplete)
|
|
continue;
|
|
|
|
// Always drop failed quests
|
|
if (numQuest <= wantNum && bot->GetQuestStatus(questId) != QUEST_STATUS_FAILED)
|
|
continue;
|
|
|
|
// Drop quest.
|
|
bot->SetQuestSlot(slot, 0);
|
|
|
|
// We ignore unequippable quest items in this case, its' still be equipped
|
|
bot->TakeQuestSourceItem(questId, false);
|
|
|
|
bot->SetQuestStatus(questId, QUEST_STATUS_NONE);
|
|
bot->RemoveRewardedQuest(questId);
|
|
|
|
numQuest--;
|
|
|
|
if (botAI->HasStrategy("debug quest", BotState::BOT_STATE_NON_COMBAT) || botAI->HasStrategy("debug rpg", BotState::BOT_STATE_COMBAT))
|
|
{
|
|
const std::string text_quest = ChatHelper::FormatQuest(quest);
|
|
LOG_INFO("playerbots", "{} => Quest [ {} ] removed", bot->GetName(), quest->GetTitle());
|
|
bot->Say("Quest [ " + text_quest + " ] removed", LANG_UNIVERSAL);
|
|
}
|
|
botAI->TellMaster("Quest removed" + chat->FormatQuest(quest));
|
|
}
|
|
}
|
|
|
|
bool CleanQuestLogAction::HasProgress(Player* bot, Quest const* quest)
|
|
{
|
|
uint32 questId = quest->GetQuestId();
|
|
|
|
if (bot->GetQuestStatus(questId) == QUEST_STATUS_COMPLETE)
|
|
return true;
|
|
|
|
QuestStatusData questStatus = bot->getQuestStatusMap()[questId];
|
|
|
|
for (uint32 i = 0; i < QUEST_OBJECTIVES_COUNT; i++)
|
|
{
|
|
if (!quest->ObjectiveText[i].empty())
|
|
return true;
|
|
|
|
if (quest->RequiredItemId[i])
|
|
{
|
|
int required = quest->RequiredItemCount[i];
|
|
int available = questStatus.ItemCount[i];
|
|
if (available > 0 && required > 0)
|
|
return true;
|
|
}
|
|
|
|
if (quest->RequiredNpcOrGo[i])
|
|
{
|
|
int required = quest->RequiredNpcOrGoCount[i];
|
|
int available = questStatus.CreatureOrGOCount[i];
|
|
|
|
if (available > 0 && required > 0)
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|