From 1c47108c2399fff5c240100726251297448c9656 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Thu, 3 Aug 2023 15:15:31 +0800 Subject: [PATCH] coredump fix & rpg actions --- conf/playerbots.conf.dist | 2 +- src/PlayerbotAI.cpp | 118 +++++++++---------- src/PlayerbotFactory.cpp | 28 ++--- src/RandomPlayerbotMgr.cpp | 64 +++++----- src/strategy/Action.cpp | 7 +- src/strategy/Action.h | 4 +- src/strategy/Engine.cpp | 6 +- src/strategy/Queue.cpp | 3 +- src/strategy/actions/BuffAction.cpp | 2 +- src/strategy/actions/GenericSpellActions.cpp | 16 +-- src/strategy/actions/LeaveGroupAction.cpp | 5 + src/strategy/generic/GroupStrategy.cpp | 2 +- src/strategy/values/ItemForSpellValue.h | 2 +- src/strategy/values/SpellCastUsefulValue.cpp | 2 +- 14 files changed, 133 insertions(+), 128 deletions(-) diff --git a/conf/playerbots.conf.dist b/conf/playerbots.conf.dist index 5f705e90..1ab426e0 100644 --- a/conf/playerbots.conf.dist +++ b/conf/playerbots.conf.dist @@ -608,7 +608,7 @@ AiPlayerbot.BotCheats = "taxi" AiPlayerbot.RandomBotRandomPassword = 0 # Set RandomBotMaxLevel bots to RandomBotMinLevel or not -AiPlayerbot.DowngradeMaxLevelBot = 1 +AiPlayerbot.DowngradeMaxLevelBot = 0 ################################################################################## # # diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index b42adbcb..0b0c410a 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -261,9 +261,7 @@ void PlayerbotAI::UpdateAI(uint32 elapsed, bool minimal) } bool min = minimal; - UpdateAIInternal(elapsed, min); - inCombat = bot->IsInCombat(); // test fix lags because of BG if (bot && !inCombat) @@ -272,6 +270,8 @@ void PlayerbotAI::UpdateAI(uint32 elapsed, bool minimal) if (HasRealPlayerMaster()) min = false; + + YieldThread(min); } @@ -1972,18 +1972,18 @@ bool PlayerbotAI::CanCastSpell(std::string const name, Unit* target, Item* itemT bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell, Item* itemTarget) { if (!spellid) { - if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { - LOG_DEBUG("playerbots", "Can cast spell failed. No spellid. - spellid: {}, bot name: {}", - spellid, bot->GetName()); - } + // if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster())) { + // LOG_DEBUG("playerbots", "Can cast spell failed. No spellid. - spellid: {}, bot name: {}", + // spellid, bot->GetName()); + // } return false; } if (bot->HasUnitState(UNIT_STATE_LOST_CONTROL)) { - if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { - LOG_DEBUG("playerbots", "Can cast spell failed. Unit state lost control. - spellid: {}, bot name: {}", - spellid, bot->GetName()); - } + // if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { + // LOG_DEBUG("playerbots", "Can cast spell failed. Unit state lost control. - spellid: {}, bot name: {}", + // spellid, bot->GetName()); + // } return false; } @@ -1991,19 +1991,19 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell, if (!target) target = bot; - if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) - LOG_DEBUG("playerbots", "Can cast spell? - target name: {}, spellid: {}, bot name: {}", - target->GetName(), spellid, bot->GetName()); + // if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) + // LOG_DEBUG("playerbots", "Can cast spell? - target name: {}, spellid: {}, bot name: {}", + // target->GetName(), spellid, bot->GetName()); if (Pet* pet = bot->GetPet()) if (pet->HasSpell(spellid)) return true; if (checkHasSpell && !bot->HasSpell(spellid)) { - if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { - LOG_DEBUG("playerbots", "Can cast spell failed. Bot not has spell. - target name: {}, spellid: {}, bot name: {}", - target->GetName(), spellid, bot->GetName()); - } + // if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { + // LOG_DEBUG("playerbots", "Can cast spell failed. Bot not has spell. - target name: {}, spellid: {}, bot name: {}", + // target->GetName(), spellid, bot->GetName()); + // } return false; } @@ -2014,28 +2014,28 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell, } if (bot->HasSpellCooldown(spellid)) { - if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { - LOG_DEBUG("playerbots", "Can cast spell failed. Spell not has cooldown. - target name: {}, spellid: {}, bot name: {}", - target->GetName(), spellid, bot->GetName()); - } + // if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { + // LOG_DEBUG("playerbots", "Can cast spell failed. Spell not has cooldown. - target name: {}, spellid: {}, bot name: {}", + // target->GetName(), spellid, bot->GetName()); + // } return false; } SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellid); if (!spellInfo) { - if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { - LOG_DEBUG("playerbots", "Can cast spell failed. No spellInfo. - target name: {}, spellid: {}, bot name: {}", - target->GetName(), spellid, bot->GetName()); - } + // if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { + // LOG_DEBUG("playerbots", "Can cast spell failed. No spellInfo. - target name: {}, spellid: {}, bot name: {}", + // target->GetName(), spellid, bot->GetName()); + // } return false; } uint32 CastingTime = !spellInfo->IsChanneled() ? spellInfo->CalcCastTime(bot) : spellInfo->GetDuration(); if (CastingTime && bot->isMoving()) { - if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { - LOG_DEBUG("playerbots", "Casting time and bot is moving - target name: {}, spellid: {}, bot name: {}", - target->GetName(), spellid, bot->GetName()); - } + // if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { + // LOG_DEBUG("playerbots", "Casting time and bot is moving - target name: {}, spellid: {}, bot name: {}", + // target->GetName(), spellid, bot->GetName()); + // } return false; } @@ -2059,10 +2059,10 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell, // } if (target->IsImmunedToSpell(spellInfo)) { - if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { - LOG_DEBUG("playerbots", "target is immuned to spell - target name: {}, spellid: {}, bot name: {}", - target->GetName(), spellid, bot->GetName()); - } + // if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { + // LOG_DEBUG("playerbots", "target is immuned to spell - target name: {}, spellid: {}, bot name: {}", + // target->GetName(), spellid, bot->GetName()); + // } return false; } @@ -2081,10 +2081,10 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell, // } if (bot != target && sServerFacade->GetDistance2d(bot, target) > sPlayerbotAIConfig->sightDistance) { - if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { - LOG_DEBUG("playerbots", "target is out of sight distance - target name: {}, spellid: {}, bot name: {}", - target->GetName(), spellid, bot->GetName()); - } + // if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { + // LOG_DEBUG("playerbots", "target is out of sight distance - target name: {}, spellid: {}, bot name: {}", + // target->GetName(), spellid, bot->GetName()); + // } return false; } } @@ -2100,12 +2100,12 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell, SpellCastResult result = spell->CheckCast(true); delete spell; - if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { - if (result != SPELL_FAILED_NOT_READY && result != SPELL_CAST_OK) { - LOG_DEBUG("playerbots", "CanCastSpell - target name: {}, spellid: {}, bot name: {}, result: {}", - target->GetName(), spellid, bot->GetName(), result); - } - } + // if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { + // if (result != SPELL_FAILED_NOT_READY && result != SPELL_CAST_OK) { + // LOG_DEBUG("playerbots", "CanCastSpell - target name: {}, spellid: {}, bot name: {}, result: {}", + // target->GetName(), spellid, bot->GetName(), result); + // } + // } if (oldSel) bot->SetSelection(oldSel->GetGUID()); @@ -2286,10 +2286,10 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget) aiObjectContext->GetValue("stay time")->Set(0); if (bot->IsFlying() || bot->HasUnitState(UNIT_STATE_IN_FLIGHT)) { - if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { - LOG_DEBUG("playerbots", "Spell cast is flying - target name: {}, spellid: {}, bot name: {}}", - target->GetName(), spellId, bot->GetName()); - } + // if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { + // LOG_DEBUG("playerbots", "Spell cast is flying - target name: {}, spellid: {}, bot name: {}}", + // target->GetName(), spellId, bot->GetName()); + // } return false; } @@ -2316,10 +2316,10 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget) if (failWithDelay) { SetNextCheckDelay(sPlayerbotAIConfig->globalCoolDown); - if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { - LOG_DEBUG("playerbots", "Spell cast fail with delay - target name: {}, spellid: {}, bot name: {}", - target->GetName(), spellId, bot->GetName()); - } + // if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { + // LOG_DEBUG("playerbots", "Spell cast fail with delay - target name: {}, spellid: {}, bot name: {}", + // target->GetName(), spellId, bot->GetName()); + // } return false; } @@ -2335,10 +2335,10 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget) { bot->GetTradeData()->SetSpell(spellId); delete spell; - if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { - LOG_DEBUG("playerbots", "Spell cast no item - target name: {}, spellid: {}, bot name: {}", - target->GetName(), spellId, bot->GetName()); - } + // if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { + // LOG_DEBUG("playerbots", "Spell cast no item - target name: {}, spellid: {}, bot name: {}", + // target->GetName(), spellId, bot->GetName()); + // } return true; } } @@ -2400,10 +2400,10 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget) SpellCastResult result = spell->prepare(&targets); if (result != SPELL_CAST_OK) { - if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { - LOG_DEBUG("playerbots", "Spell cast failed. - target name: {}, spellid: {}, bot name: {}, result: {}", - target->GetName(), spellId, bot->GetName(), result); - } + // if (!sPlayerbotAIConfig->logInGroupOnly || bot->GetGroup()) { + // LOG_DEBUG("playerbots", "Spell cast failed. - target name: {}, spellid: {}, bot name: {}, result: {}", + // target->GetName(), spellId, bot->GetName(), result); + // } return false; } // if (spellInfo->Effects[0].Effect == SPELL_EFFECT_OPEN_LOCK || spellInfo->Effects[0].Effect == SPELL_EFFECT_SKINNING) diff --git a/src/PlayerbotFactory.cpp b/src/PlayerbotFactory.cpp index dc5f819f..6835db53 100644 --- a/src/PlayerbotFactory.cpp +++ b/src/PlayerbotFactory.cpp @@ -267,14 +267,14 @@ void PlayerbotFactory::Randomize(bool incremental) if (pmo) pmo->finish(); - // if (bot->getLevel() >= sPlayerbotAIConfig->minEnchantingBotLevel) - // { - // pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_EnchantTemplate"); - // LOG_INFO("playerbots", "Initializing enchant templates..."); - // ApplyEnchantTemplate(); - // if (pmo) - // pmo->finish(); - // } + if (bot->getLevel() >= sPlayerbotAIConfig->minEnchantingBotLevel) + { + pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_EnchantTemplate"); + LOG_INFO("playerbots", "Initializing enchant templates..."); + ApplyEnchantTemplate(); + if (pmo) + pmo->finish(); + } pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Inventory"); LOG_INFO("playerbots", "Initializing inventory..."); @@ -306,6 +306,7 @@ void PlayerbotFactory::Randomize(bool incremental) } bot->RemovePet(nullptr, PET_SAVE_AS_CURRENT, true); + bot->RemovePet(nullptr, PET_SAVE_NOT_IN_SLOT, true); if (bot->getLevel() >= 10) { pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Pet"); @@ -339,17 +340,12 @@ void PlayerbotFactory::Refresh() InitClassSpells(); InitAvailableSpells(); bot->DurabilityRepairAll(false, 1.0f, false); + if (bot->isDead()) + bot->ResurrectPlayer(1.0f, false); uint32 money = urand(level * 1000, level * 5 * 1000); if (bot->GetMoney() < money) bot->SetMoney(money); bot->SaveToDB(false, false); - - // Prepare(); - // InitAmmo(); - // InitFood(); - // InitPotions(); - - //bot->SaveToDB(); } void PlayerbotFactory::AddConsumables() @@ -1203,7 +1199,7 @@ void PlayerbotFactory::InitEquipment(bool incremental) if (slot == EQUIPMENT_SLOT_OFFHAND && bot->getClass() == CLASS_ROGUE && proto->Class != ITEM_CLASS_WEAPON) continue; - + uint16 dest = 0; if (CanEquipUnseenItem(slot, dest, itemId)) items[slot].push_back(itemId); diff --git a/src/RandomPlayerbotMgr.cpp b/src/RandomPlayerbotMgr.cpp index 16bfa866..abbc114f 100644 --- a/src/RandomPlayerbotMgr.cpp +++ b/src/RandomPlayerbotMgr.cpp @@ -1166,36 +1166,38 @@ void RandomPlayerbotMgr::PrepareTeleportCache() } LOG_INFO("playerbots", "{} locations for level collected.", collected_locs); - LOG_INFO("playerbots", "Preparing RPG teleport caches for {} factions...", sFactionTemplateStore.GetNumRows()); - results = WorldDatabase.Query("SELECT map, position_x, position_y, position_z, r.race, r.minl, r.maxl FROM creature c INNER JOIN playerbots_rpg_races r ON c.id1 = r.entry " - "WHERE r.race < 15"); - if (results) - { - do - { - Field* fields = results->Fetch(); - uint16 mapId = fields[0].Get(); - float x = fields[1].Get(); - float y = fields[2].Get(); - float z = fields[3].Get(); - uint32 race = fields[4].Get(); - uint32 minl = fields[5].Get(); - uint32 maxl = fields[6].Get(); + // temporary only use locsPerLevelCache, so disable rpgLocsCacheLevel cache - for (uint32 level = 1; level < sPlayerbotAIConfig->randomBotMaxLevel + 1; level++) - { - if (level > maxl || level < minl) - continue; + // LOG_INFO("playerbots", "Preparing RPG teleport caches for {} factions...", sFactionTemplateStore.GetNumRows()); + // results = WorldDatabase.Query("SELECT map, position_x, position_y, position_z, r.race, r.minl, r.maxl FROM creature c INNER JOIN playerbots_rpg_races r ON c.id1 = r.entry " + // "WHERE r.race < 15"); + // if (results) + // { + // do + // { + // Field* fields = results->Fetch(); + // uint16 mapId = fields[0].Get(); + // float x = fields[1].Get(); + // float y = fields[2].Get(); + // float z = fields[3].Get(); + // uint32 race = fields[4].Get(); + // uint32 minl = fields[5].Get(); + // uint32 maxl = fields[6].Get(); - WorldLocation loc(mapId, x, y, z, 0); - for (uint32 r = 1; r < MAX_RACES; r++) - { - if (race == r || race == 0) - rpgLocsCacheLevel[r][level].push_back(loc); - } - } - } while (results->NextRow()); - } + // for (uint32 level = 1; level < sPlayerbotAIConfig->randomBotMaxLevel + 1; level++) + // { + // if (level > maxl || level < minl) + // continue; + + // WorldLocation loc(mapId, x, y, z, 0); + // for (uint32 r = 1; r < MAX_RACES; r++) + // { + // if (race == r || race == 0) + // rpgLocsCacheLevel[r][level].push_back(loc); + // } + // } + // } while (results->NextRow()); + // } } void RandomPlayerbotMgr::RandomTeleportForLevel(Player* bot) @@ -1341,7 +1343,6 @@ void RandomPlayerbotMgr::RandomizeFirst(Player* bot) // teleport to a random inn for bot level GET_PLAYERBOT_AI(bot)->Reset(true); -// RandomTeleportForRpg(bot); if (bot->GetGroup()) bot->RemoveFromGroup(); @@ -1458,6 +1459,9 @@ void RandomPlayerbotMgr::Refresh(Player* bot) uint32 money = bot->GetMoney(); bot->SetMoney(money + 500 * sqrt(urand(1, bot->getLevel() * 5))); + if (bot->GetGroup()) + bot->RemoveFromGroup(); + if (pmo) pmo->finish(); } @@ -1706,7 +1710,7 @@ bool RandomPlayerbotMgr::HandlePlayerbotConsoleCommand(ChatHandler* handler, cha handlers["levelup"] = handlers["level"] = &RandomPlayerbotMgr::IncreaseLevel; handlers["refresh"] = &RandomPlayerbotMgr::Refresh; handlers["teleport"] = &RandomPlayerbotMgr::RandomTeleportForLevel; - handlers["rpg"] = &RandomPlayerbotMgr::RandomTeleportForRpg; + // handlers["rpg"] = &RandomPlayerbotMgr::RandomTeleportForRpg; handlers["revive"] = &RandomPlayerbotMgr::Revive; handlers["grind"] = &RandomPlayerbotMgr::RandomTeleport; handlers["change_strategy"] = &RandomPlayerbotMgr::ChangeStrategy; diff --git a/src/strategy/Action.cpp b/src/strategy/Action.cpp index 62525ff6..3fd4a723 100644 --- a/src/strategy/Action.cpp +++ b/src/strategy/Action.cpp @@ -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; } diff --git a/src/strategy/Action.h b/src/strategy/Action.h index f67f9ed6..7069a5b3 100644 --- a/src/strategy/Action.h +++ b/src/strategy/Action.h @@ -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 diff --git a/src/strategy/Engine.cpp b/src/strategy/Engine.cpp index 5ab29cac..9cac56d7 100644 --- a/src/strategy/Engine.cpp +++ b/src/strategy/Engine.cpp @@ -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(); diff --git a/src/strategy/Queue.cpp b/src/strategy/Queue.cpp index 91c46895..c70fccc7 100644 --- a/src/strategy/Queue.cpp +++ b/src/strategy/Queue.cpp @@ -86,7 +86,7 @@ void Queue::RemoveExpired() for (std::list::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; } diff --git a/src/strategy/actions/BuffAction.cpp b/src/strategy/actions/BuffAction.cpp index 6c7c4d2a..3def115c 100644 --- a/src/strategy/actions/BuffAction.cpp +++ b/src/strategy/actions/BuffAction.cpp @@ -38,7 +38,7 @@ class FindBuffVisitor : public IterateItemsVisitor return true; Item* itemForSpell = *GET_PLAYERBOT_AI(bot)->GetAiObjectContext()->GetValue("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()) diff --git a/src/strategy/actions/GenericSpellActions.cpp b/src/strategy/actions/GenericSpellActions.cpp index 817a5eeb..6f108ad1 100644 --- a/src/strategy/actions/GenericSpellActions.cpp +++ b/src/strategy/actions/GenericSpellActions.cpp @@ -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; } diff --git a/src/strategy/actions/LeaveGroupAction.cpp b/src/strategy/actions/LeaveGroupAction.cpp index 381019ea..4414e152 100644 --- a/src/strategy/actions/LeaveGroupAction.cpp +++ b/src/strategy/actions/LeaveGroupAction.cpp @@ -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; } diff --git a/src/strategy/generic/GroupStrategy.cpp b/src/strategy/generic/GroupStrategy.cpp index 05c16877..7f87e2e6 100644 --- a/src/strategy/generic/GroupStrategy.cpp +++ b/src/strategy/generic/GroupStrategy.cpp @@ -9,7 +9,7 @@ void GroupStrategy::InitTriggers(std::vector& 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))); } diff --git a/src/strategy/values/ItemForSpellValue.h b/src/strategy/values/ItemForSpellValue.h index b43aad49..525a9109 100644 --- a/src/strategy/values/ItemForSpellValue.h +++ b/src/strategy/values/ItemForSpellValue.h @@ -15,7 +15,7 @@ class SpellInfo; class ItemForSpellValue : public CalculatedValue, public Qualified { public: - ItemForSpellValue(PlayerbotAI* botAI, std::string const name = "item for spell") : CalculatedValue(botAI, name, 20 * 1000) { } + ItemForSpellValue(PlayerbotAI* botAI, std::string const name = "item for spell") : CalculatedValue(botAI, name, 1) { } Item* Calculate() override; diff --git a/src/strategy/values/SpellCastUsefulValue.cpp b/src/strategy/values/SpellCastUsefulValue.cpp index ee7b5299..277eff43 100644 --- a/src/strategy/values/SpellCastUsefulValue.cpp +++ b/src/strategy/values/SpellCastUsefulValue.cpp @@ -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; }