Revert expireActionTime (#991)

* Revert expireActionTime

* Revert expireActionTime

* Revert RemoveExpired

* Revert RemoveExpired

* Revert RemoveExpired

* Revert Action expiration
This commit is contained in:
SaW
2025-02-21 04:32:00 +01:00
committed by GitHub
parent 61333a02bf
commit 419e96e5aa
6 changed files with 60 additions and 8 deletions

View File

@@ -305,6 +305,9 @@ AiPlayerbot.DisableMoveSplinePath = 0
# default: 3 # default: 3
AiPlayerbot.MaxMovementSearchTime = 3 AiPlayerbot.MaxMovementSearchTime = 3
# Action expiration time
AiPlayerbot.ExpireActionTime = 5000
# Max dispel auras duration # Max dispel auras duration
AiPlayerbot.DispelAuraDuration = 700 AiPlayerbot.DispelAuraDuration = 700

View File

@@ -71,6 +71,7 @@ bool PlayerbotAIConfig::Initialize()
maxWaitForMove = sConfigMgr->GetOption<int32>("AiPlayerbot.MaxWaitForMove", 5000); maxWaitForMove = sConfigMgr->GetOption<int32>("AiPlayerbot.MaxWaitForMove", 5000);
disableMoveSplinePath = sConfigMgr->GetOption<int32>("AiPlayerbot.DisableMoveSplinePath", 0); disableMoveSplinePath = sConfigMgr->GetOption<int32>("AiPlayerbot.DisableMoveSplinePath", 0);
maxMovementSearchTime = sConfigMgr->GetOption<int32>("AiPlayerbot.MaxMovementSearchTime", 3); maxMovementSearchTime = sConfigMgr->GetOption<int32>("AiPlayerbot.MaxMovementSearchTime", 3);
expireActionTime = sConfigMgr->GetOption<int32>("AiPlayerbot.ExpireActionTime", 5000);
dispelAuraDuration = sConfigMgr->GetOption<int32>("AiPlayerbot.DispelAuraDuration", 7000); dispelAuraDuration = sConfigMgr->GetOption<int32>("AiPlayerbot.DispelAuraDuration", 7000);
reactDelay = sConfigMgr->GetOption<int32>("AiPlayerbot.ReactDelay", 100); reactDelay = sConfigMgr->GetOption<int32>("AiPlayerbot.ReactDelay", 100);
dynamicReactDelay = sConfigMgr->GetOption<bool>("AiPlayerbot.DynamicReactDelay", true); dynamicReactDelay = sConfigMgr->GetOption<bool>("AiPlayerbot.DynamicReactDelay", true);

View File

@@ -57,7 +57,7 @@ public:
bool enabled; bool enabled;
bool allowAccountBots, allowGuildBots; bool allowAccountBots, allowGuildBots;
bool randomBotGuildNearby, randomBotInvitePlayer, inviteChat; bool randomBotGuildNearby, randomBotInvitePlayer, inviteChat;
uint32 globalCoolDown, reactDelay, maxWaitForMove, disableMoveSplinePath, maxMovementSearchTime, uint32 globalCoolDown, reactDelay, maxWaitForMove, disableMoveSplinePath, maxMovementSearchTime, expireActionTime,
dispelAuraDuration, passiveDelay, repeatDelay, errorDelay, rpgDelay, sitDelay, returnDelay, lootDelay; dispelAuraDuration, passiveDelay, repeatDelay, errorDelay, rpgDelay, sitDelay, returnDelay, lootDelay;
bool dynamicReactDelay; bool dynamicReactDelay;
float sightDistance, spellDistance, reactDistance, grindDistance, lootDistance, shootDistance, fleeDistance, float sightDistance, spellDistance, reactDistance, grindDistance, lootDistance, shootDistance, fleeDistance,

View File

@@ -239,13 +239,9 @@ bool Engine::DoNextAction(Unit* unit, uint32 depth, bool minimal)
} }
if (!actionExecuted) if (!actionExecuted)
LogAction("No actions executed"); LogAction("no actions executed");
ActionNode* action = nullptr; queue.RemoveExpired();
while ((action = queue.Pop()) != nullptr)
{
delete action;
}
return actionExecuted; return actionExecuted;
} }

View File

@@ -48,6 +48,18 @@ uint32 Queue::Size()
return actions.size(); return actions.size();
} }
void Queue::RemoveExpired()
{
if (!sPlayerbotAIConfig->expireActionTime)
{
return;
}
std::list<ActionBasket*> expiredBaskets;
collectExpiredBaskets(expiredBaskets);
removeAndDeleteBaskets(expiredBaskets);
}
// Private helper methods // Private helper methods
void Queue::updateExistingBasket(ActionBasket* existing, ActionBasket* newBasket) void Queue::updateExistingBasket(ActionBasket* existing, ActionBasket* newBasket)
{ {
@@ -93,3 +105,30 @@ ActionNode* Queue::extractAndDeleteBasket(ActionBasket* basket)
delete basket; delete basket;
return action; return action;
} }
void Queue::collectExpiredBaskets(std::list<ActionBasket*>& expiredBaskets)
{
uint32 expiryTime = sPlayerbotAIConfig->expireActionTime;
for (ActionBasket* basket : actions)
{
if (basket->isExpired(expiryTime))
{
expiredBaskets.push_back(basket);
}
}
}
void Queue::removeAndDeleteBaskets(std::list<ActionBasket*>& basketsToRemove)
{
for (ActionBasket* basket : basketsToRemove)
{
actions.remove(basket);
if (ActionNode* action = basket->getAction())
{
delete action;
}
delete basket;
}
}

View File

@@ -53,6 +53,14 @@ public:
*/ */
uint32 Size(); uint32 Size();
/**
* @brief Removes and deletes expired actions from the queue
*
* Uses sPlayerbotAIConfig->expireActionTime to determine if actions have expired.
* Both the ActionNode and ActionBasket are deleted for expired actions.
*/
void RemoveExpired();
private: private:
/** /**
* @brief Updates existing basket with new relevance and cleans up new basket * @brief Updates existing basket with new relevance and cleans up new basket
@@ -70,6 +78,11 @@ private:
*/ */
ActionNode* extractAndDeleteBasket(ActionBasket* basket); ActionNode* extractAndDeleteBasket(ActionBasket* basket);
/**
* @brief Collects all expired baskets into the provided list
*/
void collectExpiredBaskets(std::list<ActionBasket*>& expiredBaskets);
/** /**
* @brief Removes and deletes all baskets in the provided list * @brief Removes and deletes all baskets in the provided list
*/ */