Fix unique equip init and bots login

This commit is contained in:
Yunfan Li
2024-09-05 15:04:46 +08:00
parent bbc95c953a
commit 369f3373ed
3 changed files with 42 additions and 24 deletions

View File

@@ -370,7 +370,7 @@ void RandomPlayerbotMgr::UpdateAIInternal(uint32 elapsed, bool /*minimal*/)
break; break;
} }
if (loginBots) if (loginBots && botLoading.empty())
{ {
loginBots += updateBots; loginBots += updateBots;
loginBots = std::min(loginBots, maxNewBots); loginBots = std::min(loginBots, maxNewBots);
@@ -1041,6 +1041,9 @@ bool RandomPlayerbotMgr::ProcessBot(uint32 bot)
SetEventValue(bot, "login", 0, 0); SetEventValue(bot, "login", 0, 0);
if (!player->IsInWorld())
return false;
if (player->GetGroup() || player->HasUnitState(UNIT_STATE_IN_FLIGHT)) if (player->GetGroup() || player->HasUnitState(UNIT_STATE_IN_FLIGHT))
return false; return false;

View File

@@ -235,6 +235,7 @@ void PlayerbotFactory::Randomize(bool incremental)
pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Spells1"); pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Spells1");
LOG_DEBUG("playerbots", "Initializing spells (step 1)..."); LOG_DEBUG("playerbots", "Initializing spells (step 1)...");
// bot->LearnDefaultSkills(); // bot->LearnDefaultSkills();
bot->LearnDefaultSkills();
InitClassSpells(); InitClassSpells();
InitAvailableSpells(); InitAvailableSpells();
if (pmo) if (pmo)
@@ -425,7 +426,10 @@ void PlayerbotFactory::Refresh()
InitFood(); InitFood();
InitReagents(); InitReagents();
// InitPotions(); // InitPotions();
InitTalentsTree(true, true, true); if (!sPlayerbotAIConfig->equipmentPersistence || bot->GetLevel() < sPlayerbotAIConfig->equipmentPersistenceLevel)
{
InitTalentsTree(true, true, true);
}
InitPet(); InitPet();
InitPetTalents(); InitPetTalents();
InitClassSpells(); InitClassSpells();
@@ -885,7 +889,7 @@ void PlayerbotFactory::ClearEverything()
ClearSpells(); ClearSpells();
ClearInventory(); ClearInventory();
ResetQuests(); ResetQuests();
bot->SaveToDB(false, false); // bot->SaveToDB(false, false);
} }
void PlayerbotFactory::ClearSpells() void PlayerbotFactory::ClearSpells()
@@ -1616,7 +1620,7 @@ void PlayerbotFactory::InitEquipment(bool incremental, bool second_chance)
if (proto->Quality != desiredQuality) if (proto->Quality != desiredQuality)
continue; continue;
// delay heavy check
// if (!CanEquipItem(proto)) // if (!CanEquipItem(proto))
// continue; // continue;
@@ -1634,7 +1638,7 @@ void PlayerbotFactory::InitEquipment(bool incremental, bool second_chance)
if (slot == EQUIPMENT_SLOT_OFFHAND && bot->getClass() == CLASS_ROGUE && if (slot == EQUIPMENT_SLOT_OFFHAND && bot->getClass() == CLASS_ROGUE &&
proto->Class != ITEM_CLASS_WEAPON) proto->Class != ITEM_CLASS_WEAPON)
continue; continue;
// delay heavy check
// uint16 dest = 0; // uint16 dest = 0;
// if (CanEquipUnseenItem(slot, dest, itemId)) // if (CanEquipUnseenItem(slot, dest, itemId))
items[slot].push_back(itemId); items[slot].push_back(itemId);
@@ -1690,6 +1694,7 @@ void PlayerbotFactory::InitEquipment(bool incremental, bool second_chance)
continue; continue;
} }
if (oldItem) if (oldItem)
{ {
uint8 bagIndex = oldItem->GetBagSlot(); uint8 bagIndex = oldItem->GetBagSlot();
@@ -1701,13 +1706,18 @@ void PlayerbotFactory::InitEquipment(bool incremental, bool second_chance)
bot->GetSession()->HandleAutoStoreBagItemOpcode(packet); 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); Item* newItem = bot->EquipNewItem(dest, bestItemForSlot, true);
bot->AutoUnequipOffhandIfNeed(); bot->AutoUnequipOffhandIfNeed();
if (newItem) // if (newItem)
{ // {
newItem->AddToWorld(); // newItem->AddToWorld();
newItem->AddToUpdateQueueOf(bot); // newItem->AddToUpdateQueueOf(bot);
} // }
} }
// Secondary init for better equips // Secondary init for better equips
/// @todo: clean up duplicate code /// @todo: clean up duplicate code
@@ -1770,11 +1780,11 @@ void PlayerbotFactory::InitEquipment(bool incremental, bool second_chance)
} }
Item* newItem = bot->EquipNewItem(dest, bestItemForSlot, true); Item* newItem = bot->EquipNewItem(dest, bestItemForSlot, true);
bot->AutoUnequipOffhandIfNeed(); bot->AutoUnequipOffhandIfNeed();
if (newItem) // if (newItem)
{ // {
newItem->AddToWorld(); // newItem->AddToWorld();
newItem->AddToUpdateQueueOf(bot); // newItem->AddToUpdateQueueOf(bot);
} // }
} }
} }
} }
@@ -2305,8 +2315,6 @@ void PlayerbotFactory::SetRandomSkill(uint16 id)
void PlayerbotFactory::InitAvailableSpells() void PlayerbotFactory::InitAvailableSpells()
{ {
bot->LearnDefaultSkills();
if (trainerIdCache.empty()) if (trainerIdCache.empty())
{ {
CreatureTemplateContainer const* creatureTemplateContainer = sObjectMgr->GetCreatureTemplates(); CreatureTemplateContainer const* creatureTemplateContainer = sObjectMgr->GetCreatureTemplates();
@@ -2324,7 +2332,8 @@ void PlayerbotFactory::InitAvailableSpells()
trainerIdCache.push_back(trainerId); trainerIdCache.push_back(trainerId);
} }
} }
uint32 learnedCounter = 0; // uint32 learnedCounter = 0;
// uint32 oktest = 0;
for (uint32 trainerId : trainerIdCache) for (uint32 trainerId : trainerIdCache)
{ {
TrainerSpellData const* trainer_spells = sObjectMgr->GetNpcTrainerSpells(trainerId); TrainerSpellData const* trainer_spells = sObjectMgr->GetNpcTrainerSpells(trainerId);
@@ -2368,6 +2377,7 @@ void PlayerbotFactory::InitAvailableSpells()
{ {
continue; continue;
} }
// oktest++;
if (tSpell->learnedSpell[0]) if (tSpell->learnedSpell[0])
{ {
bot->learnSpell(tSpell->learnedSpell[0], false); bot->learnSpell(tSpell->learnedSpell[0], false);
@@ -2377,8 +2387,9 @@ void PlayerbotFactory::InitAvailableSpells()
botAI->CastSpell(tSpell->spell, bot); botAI->CastSpell(tSpell->spell, bot);
} }
} }
if (++learnedCounter > 20) // LOG_INFO("playerbots", "C: {}, ok: {}", ++learnedCounter, oktest);
break; // if (++learnedCounter > 20)
// break;
} }
} }

View File

@@ -11,13 +11,13 @@
std::map<uint32, SkillLineAbilityEntry const*> ListSpellsAction::skillSpells; std::map<uint32, SkillLineAbilityEntry const*> ListSpellsAction::skillSpells;
std::set<uint32> ListSpellsAction::vendorItems; std::set<uint32> ListSpellsAction::vendorItems;
bool CompareSpells(std::pair<uint32, std::string>& s1, std::pair<uint32, std::string>& s2) bool CompareSpells(const std::pair<uint32, std::string>& s1, const std::pair<uint32, std::string>& s2)
{ {
SpellInfo const* si1 = sSpellMgr->GetSpellInfo(s1.first); SpellInfo const* si1 = sSpellMgr->GetSpellInfo(s1.first);
SpellInfo const* si2 = sSpellMgr->GetSpellInfo(s2.first); SpellInfo const* si2 = sSpellMgr->GetSpellInfo(s2.first);
if (!si1 || !si2) if (!si1 || !si2)
{ {
LOG_ERROR("playerbots", "SpellInfo missing."); LOG_ERROR("playerbots", "SpellInfo missing. {} {}", s1.first, s2.first);
return false; return false;
} }
uint32 p1 = si1->SchoolMask * 20000; uint32 p1 = si1->SchoolMask * 20000;
@@ -54,7 +54,7 @@ bool CompareSpells(std::pair<uint32, std::string>& s1, std::pair<uint32, std::st
if (p1 == p2) if (p1 == p2)
{ {
return strcmp(si1->SpellName[0], si1->SpellName[1]) > 0; return strcmp(si1->SpellName[0], si2->SpellName[0]) > 0;
} }
return p1 > p2; return p1 > p2;
@@ -273,7 +273,11 @@ std::vector<std::pair<uint32, std::string>> ListSpellsAction::GetSpellList(std::
if (out.str().empty()) if (out.str().empty())
continue; continue;
if (itr->first == 0)
{
LOG_ERROR("playerbots", "?! {}", itr->first);
}
spells.push_back(std::pair<uint32, std::string>(itr->first, out.str())); spells.push_back(std::pair<uint32, std::string>(itr->first, out.str()));
alreadySeenList += spellInfo->SpellName[0]; alreadySeenList += spellInfo->SpellName[0];
alreadySeenList += ","; alreadySeenList += ",";