diff --git a/src/RandomPlayerbotMgr.cpp b/src/RandomPlayerbotMgr.cpp index 21bd012a..0f06e0a5 100644 --- a/src/RandomPlayerbotMgr.cpp +++ b/src/RandomPlayerbotMgr.cpp @@ -370,7 +370,7 @@ void RandomPlayerbotMgr::UpdateAIInternal(uint32 elapsed, bool /*minimal*/) break; } - if (loginBots) + if (loginBots && botLoading.empty()) { loginBots += updateBots; loginBots = std::min(loginBots, maxNewBots); @@ -1041,6 +1041,9 @@ bool RandomPlayerbotMgr::ProcessBot(uint32 bot) SetEventValue(bot, "login", 0, 0); + if (!player->IsInWorld()) + return false; + if (player->GetGroup() || player->HasUnitState(UNIT_STATE_IN_FLIGHT)) return false; diff --git a/src/factory/PlayerbotFactory.cpp b/src/factory/PlayerbotFactory.cpp index a5ada525..47db56b6 100644 --- a/src/factory/PlayerbotFactory.cpp +++ b/src/factory/PlayerbotFactory.cpp @@ -235,6 +235,7 @@ void PlayerbotFactory::Randomize(bool incremental) pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Spells1"); LOG_DEBUG("playerbots", "Initializing spells (step 1)..."); // bot->LearnDefaultSkills(); + bot->LearnDefaultSkills(); InitClassSpells(); InitAvailableSpells(); if (pmo) @@ -425,7 +426,10 @@ void PlayerbotFactory::Refresh() InitFood(); InitReagents(); // InitPotions(); - InitTalentsTree(true, true, true); + if (!sPlayerbotAIConfig->equipmentPersistence || bot->GetLevel() < sPlayerbotAIConfig->equipmentPersistenceLevel) + { + InitTalentsTree(true, true, true); + } InitPet(); InitPetTalents(); InitClassSpells(); @@ -885,7 +889,7 @@ void PlayerbotFactory::ClearEverything() ClearSpells(); ClearInventory(); ResetQuests(); - bot->SaveToDB(false, false); + // bot->SaveToDB(false, false); } void PlayerbotFactory::ClearSpells() @@ -1616,7 +1620,7 @@ void PlayerbotFactory::InitEquipment(bool incremental, bool second_chance) if (proto->Quality != desiredQuality) continue; - + // delay heavy check // if (!CanEquipItem(proto)) // continue; @@ -1634,7 +1638,7 @@ void PlayerbotFactory::InitEquipment(bool incremental, bool second_chance) if (slot == EQUIPMENT_SLOT_OFFHAND && bot->getClass() == CLASS_ROGUE && proto->Class != ITEM_CLASS_WEAPON) continue; - + // delay heavy check // uint16 dest = 0; // if (CanEquipUnseenItem(slot, dest, itemId)) items[slot].push_back(itemId); @@ -1690,6 +1694,7 @@ void PlayerbotFactory::InitEquipment(bool incremental, bool second_chance) continue; } + if (oldItem) { uint8 bagIndex = oldItem->GetBagSlot(); @@ -1701,13 +1706,18 @@ void PlayerbotFactory::InitEquipment(bool incremental, bool second_chance) bot->GetSession()->HandleAutoStoreBagItemOpcode(packet); } + oldItem = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, slot); + // fail to store in bag + if (oldItem) + continue; + Item* newItem = bot->EquipNewItem(dest, bestItemForSlot, true); bot->AutoUnequipOffhandIfNeed(); - if (newItem) - { - newItem->AddToWorld(); - newItem->AddToUpdateQueueOf(bot); - } + // if (newItem) + // { + // newItem->AddToWorld(); + // newItem->AddToUpdateQueueOf(bot); + // } } // Secondary init for better equips /// @todo: clean up duplicate code @@ -1770,11 +1780,11 @@ void PlayerbotFactory::InitEquipment(bool incremental, bool second_chance) } Item* newItem = bot->EquipNewItem(dest, bestItemForSlot, true); bot->AutoUnequipOffhandIfNeed(); - if (newItem) - { - newItem->AddToWorld(); - newItem->AddToUpdateQueueOf(bot); - } + // if (newItem) + // { + // newItem->AddToWorld(); + // newItem->AddToUpdateQueueOf(bot); + // } } } } @@ -2305,8 +2315,6 @@ void PlayerbotFactory::SetRandomSkill(uint16 id) void PlayerbotFactory::InitAvailableSpells() { - bot->LearnDefaultSkills(); - if (trainerIdCache.empty()) { CreatureTemplateContainer const* creatureTemplateContainer = sObjectMgr->GetCreatureTemplates(); @@ -2324,7 +2332,8 @@ void PlayerbotFactory::InitAvailableSpells() trainerIdCache.push_back(trainerId); } } - uint32 learnedCounter = 0; + // uint32 learnedCounter = 0; + // uint32 oktest = 0; for (uint32 trainerId : trainerIdCache) { TrainerSpellData const* trainer_spells = sObjectMgr->GetNpcTrainerSpells(trainerId); @@ -2368,6 +2377,7 @@ void PlayerbotFactory::InitAvailableSpells() { continue; } + // oktest++; if (tSpell->learnedSpell[0]) { bot->learnSpell(tSpell->learnedSpell[0], false); @@ -2377,8 +2387,9 @@ void PlayerbotFactory::InitAvailableSpells() botAI->CastSpell(tSpell->spell, bot); } } - if (++learnedCounter > 20) - break; + // LOG_INFO("playerbots", "C: {}, ok: {}", ++learnedCounter, oktest); + // if (++learnedCounter > 20) + // break; } } diff --git a/src/strategy/actions/ListSpellsAction.cpp b/src/strategy/actions/ListSpellsAction.cpp index 75d25ac9..80277ea8 100644 --- a/src/strategy/actions/ListSpellsAction.cpp +++ b/src/strategy/actions/ListSpellsAction.cpp @@ -11,13 +11,13 @@ std::map ListSpellsAction::skillSpells; std::set ListSpellsAction::vendorItems; -bool CompareSpells(std::pair& s1, std::pair& s2) +bool CompareSpells(const std::pair& s1, const std::pair& s2) { SpellInfo const* si1 = sSpellMgr->GetSpellInfo(s1.first); SpellInfo const* si2 = sSpellMgr->GetSpellInfo(s2.first); if (!si1 || !si2) { - LOG_ERROR("playerbots", "SpellInfo missing."); + LOG_ERROR("playerbots", "SpellInfo missing. {} {}", s1.first, s2.first); return false; } uint32 p1 = si1->SchoolMask * 20000; @@ -54,7 +54,7 @@ bool CompareSpells(std::pair& s1, std::pairSpellName[0], si1->SpellName[1]) > 0; + return strcmp(si1->SpellName[0], si2->SpellName[0]) > 0; } return p1 > p2; @@ -273,7 +273,11 @@ std::vector> ListSpellsAction::GetSpellList(std:: if (out.str().empty()) continue; - + + if (itr->first == 0) + { + LOG_ERROR("playerbots", "?! {}", itr->first); + } spells.push_back(std::pair(itr->first, out.str())); alreadySeenList += spellInfo->SpellName[0]; alreadySeenList += ",";