coredump fix & rpg actions

This commit is contained in:
Yunfan Li
2023-08-03 15:15:31 +08:00
parent 1d423e4820
commit 1c47108c23
14 changed files with 133 additions and 128 deletions

View File

@@ -4,6 +4,7 @@
#include "Action.h"
#include "Playerbots.h"
#include "Timer.h"
uint32 NextAction::size(NextAction** actions)
{
@@ -101,11 +102,11 @@ Unit* Action::GetTarget()
}
ActionBasket::ActionBasket(ActionNode* action, float relevance, bool skipPrerequisites, Event event) :
action(action), relevance(relevance), skipPrerequisites(skipPrerequisites), event(event), created(time(nullptr))
action(action), relevance(relevance), skipPrerequisites(skipPrerequisites), event(event), created(getMSTime())
{
}
bool ActionBasket::isExpired(time_t secs)
bool ActionBasket::isExpired(uint32 msecs)
{
return time(nullptr) - created >= secs;
return getMSTime() - created >= msecs;
}

View File

@@ -109,14 +109,14 @@ class ActionBasket
bool isSkipPrerequisites() { return skipPrerequisites; }
void AmendRelevance(float k) { relevance *= k; }
void setRelevance(float relevance) { this->relevance = relevance; }
bool isExpired(time_t secs);
bool isExpired(uint32 msecs);
private:
ActionNode* action;
float relevance;
bool skipPrerequisites;
Event event;
time_t created;
uint32 created;
};
#endif

View File

@@ -261,7 +261,7 @@ bool Engine::DoNextAction(Unit* unit, uint32 depth, bool minimal)
lastRelevance = 0.0f;
PushDefaultActions();
if (queue.Peek() && depth < 2)
if (queue.Peek() && depth < 1 && !minimal)
return DoNextAction(unit, depth + 1, minimal);
}
@@ -640,7 +640,7 @@ void Engine::LogAction(char const* format, ...)
else
{
Player* bot = botAI->GetBot();
if (sPlayerbotAIConfig->logInGroupOnly && !bot->GetGroup())
if (sPlayerbotAIConfig->logInGroupOnly && (!bot->GetGroup() || !botAI->HasRealPlayerMaster()))
return;
LOG_DEBUG("playerbots", "{} {}", bot->GetName().c_str(), buf);
@@ -677,7 +677,7 @@ void Engine::LogValues()
return;
Player* bot = botAI->GetBot();
if (sPlayerbotAIConfig->logInGroupOnly && !bot->GetGroup())
if (sPlayerbotAIConfig->logInGroupOnly && (!bot->GetGroup() || !botAI->HasRealPlayerMaster()))
return;
std::string const text = botAI->GetAiObjectContext()->FormatValues();

View File

@@ -86,7 +86,7 @@ void Queue::RemoveExpired()
for (std::list<ActionBasket*>::iterator iter = actions.begin(); iter != actions.end(); iter++)
{
ActionBasket* basket = *iter;
if (sPlayerbotAIConfig->expireActionTime && basket->isExpired(sPlayerbotAIConfig->expireActionTime / 1000))
if (sPlayerbotAIConfig->expireActionTime && basket->isExpired(sPlayerbotAIConfig->expireActionTime))
expired.push_back(basket);
}
@@ -97,7 +97,6 @@ void Queue::RemoveExpired()
if (ActionNode* action = basket->getAction())
{
// LOG_DEBUG("playerbots", "Action {} is expired", action->getName().c_str());
delete action;
}

View File

@@ -38,7 +38,7 @@ class FindBuffVisitor : public IterateItemsVisitor
return true;
Item* itemForSpell = *GET_PLAYERBOT_AI(bot)->GetAiObjectContext()->GetValue<Item*>("item for spell", spellId);
if (itemForSpell && itemForSpell->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT))
if (itemForSpell && itemForSpell->IsInWorld() && itemForSpell->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT))
return true;
if (items.find(proto->SubClass) == items.end())

View File

@@ -63,10 +63,10 @@ bool CastSpellAction::Execute(Event event)
bool CastSpellAction::isPossible()
{
if (botAI->IsInVehicle() && !botAI->IsInVehicle(false, false, true)) {
if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) {
LOG_DEBUG("playerbots", "Can cast spell failed. Vehicle. - bot name: {}",
bot->GetName());
}
// if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) {
// LOG_DEBUG("playerbots", "Can cast spell failed. Vehicle. - bot name: {}",
// bot->GetName());
// }
return false;
}
@@ -75,10 +75,10 @@ bool CastSpellAction::isPossible()
if (spell == "mount" && bot->IsInCombat())
{
if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) {
LOG_DEBUG("playerbots", "Can cast spell failed. Mount. - bot name: {}",
bot->GetName());
}
// if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) {
// LOG_DEBUG("playerbots", "Can cast spell failed. Mount. - bot name: {}",
// bot->GetName());
// }
bot->Dismount();
return false;
}

View File

@@ -4,6 +4,7 @@
#include "LeaveGroupAction.h"
#include "Event.h"
#include "PlayerbotAIConfig.h"
#include "Playerbots.h"
bool LeaveGroupAction::Execute(Event event)
@@ -153,5 +154,9 @@ bool LeaveFarAwayAction::isUseful()
if (abs(int32(master->getLevel() - bot->getLevel())) > 4)
return true;
if (bot->GetMapId() != master->GetMapId() || bot->GetDistance2d(master) >= 2 * sPlayerbotAIConfig->rpgDistance) {
return true;
}
return false;
}

View File

@@ -9,7 +9,7 @@ void GroupStrategy::InitTriggers(std::vector<TriggerNode*>& triggers)
{
triggers.push_back(new TriggerNode("often", NextAction::array(0, new NextAction("invite nearby", 4.0f), nullptr)));
triggers.push_back(new TriggerNode("random", NextAction::array(0, new NextAction("invite guild", 4.0f), nullptr)));
triggers.push_back(new TriggerNode("seldom", NextAction::array(0, new NextAction("leave far away", 4.0f), nullptr)));
triggers.push_back(new TriggerNode("often", NextAction::array(0, new NextAction("leave far away", 4.0f), nullptr)));
triggers.push_back(new TriggerNode("seldom", NextAction::array(0, new NextAction("reset instances", 1.0f), nullptr)));
}

View File

@@ -15,7 +15,7 @@ class SpellInfo;
class ItemForSpellValue : public CalculatedValue<Item*>, public Qualified
{
public:
ItemForSpellValue(PlayerbotAI* botAI, std::string const name = "item for spell") : CalculatedValue<Item*>(botAI, name, 20 * 1000) { }
ItemForSpellValue(PlayerbotAI* botAI, std::string const name = "item for spell") : CalculatedValue<Item*>(botAI, name, 1) { }
Item* Calculate() override;

View File

@@ -40,7 +40,7 @@ bool SpellCastUsefulValue::Calculate()
qualifier == "rockbiter weapon" || qualifier == "earthliving weapon" || qualifier == "spellstone")
{
if (Item* item = AI_VALUE2(Item*, "item for spell", spellid))
if (item->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT))
if (item->IsInWorld() && item->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT))
return false;
}