mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-01-15 09:50:27 +00:00
[Stability] Various crash fixes based on Regrad fixes and crashlogs. (#1928)
These contains various fixes, fixes that have history worked one in past more then once as person as group, aswell @Wishmaster117. But due various reasons we had to drop them due priority or simply timewise. These fixes have recollected again by @Regrad based on his crash logs. Most crash logs we have, i am talking 30+ of them, to many to post here. @Regrad running a larger server 100+ real players with bots, which means he will walk into issues that most of us wont or are extremely difficult to reproduce. @Regrad used LLM to solve them based on crash log and mentioned his server crashes almost disappeared, instead of redoing every single PR and pull them apart. I tried to keep his bunch of changes together as whole, reviewed them, some redone, verified again etc etc. This is not how would normally do this. But since i want @Regrad being able to confirm, we need this in a package as a whole. Pulling them apart in the current situation is simply to much, to complicated in the verification process. So this PR is open and in my opinion has priority above others, but @Regrad is only person who can give the green light for the mod-playerbot changes for now. I, we spend huge amount of time into these issues over last couple of months. I will put other PR's on hold for abit. --------- Signed-off-by: Engardium <regradius@gmail.com> Co-authored-by: Engardium <regradius@gmail.com>
This commit is contained in:
@@ -3,8 +3,11 @@
|
||||
* and/or modify it under version 3 of the License, or (at your option), any later version.
|
||||
*/
|
||||
|
||||
#include "ReadyCheckAction.h"
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
#include "ReadyCheckAction.h"
|
||||
#include "Event.h"
|
||||
#include "Playerbots.h"
|
||||
|
||||
@@ -27,14 +30,17 @@ std::string const formatPercent(std::string const name, uint8 value, float perce
|
||||
class ReadyChecker
|
||||
{
|
||||
public:
|
||||
virtual ~ReadyChecker() = default;
|
||||
virtual bool Check(PlayerbotAI* botAI, AiObjectContext* context) = 0;
|
||||
virtual std::string const getName() = 0;
|
||||
virtual bool PrintAlways() { return true; }
|
||||
|
||||
static std::vector<ReadyChecker*> checkers;
|
||||
static std::vector<std::unique_ptr<ReadyChecker>> checkers;
|
||||
static std::once_flag initFlag;
|
||||
};
|
||||
|
||||
std::vector<ReadyChecker*> ReadyChecker::checkers;
|
||||
std::vector<std::unique_ptr<ReadyChecker>> ReadyChecker::checkers;
|
||||
std::once_flag ReadyChecker::initFlag;
|
||||
|
||||
class HealthChecker : public ReadyChecker
|
||||
{
|
||||
@@ -160,25 +166,30 @@ bool ReadyCheckAction::Execute(Event event)
|
||||
|
||||
bool ReadyCheckAction::ReadyCheck()
|
||||
{
|
||||
if (ReadyChecker::checkers.empty())
|
||||
{
|
||||
ReadyChecker::checkers.push_back(new HealthChecker());
|
||||
ReadyChecker::checkers.push_back(new ManaChecker());
|
||||
ReadyChecker::checkers.push_back(new DistanceChecker());
|
||||
ReadyChecker::checkers.push_back(new HunterChecker());
|
||||
std::call_once(
|
||||
ReadyChecker::initFlag,
|
||||
[]()
|
||||
{
|
||||
ReadyChecker::checkers.reserve(8);
|
||||
|
||||
ReadyChecker::checkers.push_back(new ItemCountChecker("food", "Food"));
|
||||
ReadyChecker::checkers.push_back(new ManaPotionChecker("drink", "Water"));
|
||||
ReadyChecker::checkers.push_back(new ItemCountChecker("healing potion", "Hpot"));
|
||||
ReadyChecker::checkers.push_back(new ManaPotionChecker("mana potion", "Mpot"));
|
||||
}
|
||||
ReadyChecker::checkers.emplace_back(std::make_unique<HealthChecker>());
|
||||
ReadyChecker::checkers.emplace_back(std::make_unique<ManaChecker>());
|
||||
ReadyChecker::checkers.emplace_back(std::make_unique<DistanceChecker>());
|
||||
ReadyChecker::checkers.emplace_back(std::make_unique<HunterChecker>());
|
||||
|
||||
ReadyChecker::checkers.emplace_back(std::make_unique<ItemCountChecker>("food", "Food"));
|
||||
ReadyChecker::checkers.emplace_back(std::make_unique<ManaPotionChecker>("drink", "Water"));
|
||||
ReadyChecker::checkers.emplace_back(std::make_unique<ItemCountChecker>("healing potion", "Hpot"));
|
||||
ReadyChecker::checkers.emplace_back(std::make_unique<ManaPotionChecker>("mana potion", "Mpot"));
|
||||
});
|
||||
|
||||
bool result = true;
|
||||
for (std::vector<ReadyChecker*>::iterator i = ReadyChecker::checkers.begin(); i != ReadyChecker::checkers.end();
|
||||
++i)
|
||||
for (auto const& checkerPtr : ReadyChecker::checkers)
|
||||
{
|
||||
ReadyChecker* checker = *i;
|
||||
bool ok = checker->Check(botAI, context);
|
||||
if (!checkerPtr)
|
||||
continue;
|
||||
|
||||
bool ok = checkerPtr->Check(botAI, context);
|
||||
result = result && ok;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user