[Attack target] Crash fix

This commit is contained in:
Yunfan Li
2024-06-02 23:22:20 +08:00
parent d5d1bb3904
commit 05236fddec
2 changed files with 26 additions and 24 deletions

View File

@@ -179,9 +179,9 @@ void PlayerbotFactory::Randomize(bool incremental)
// return;
// }
LOG_INFO("playerbots", "Preparing to {} randomize...", (incremental ? "incremental" : "full"));
LOG_DEBUG("playerbots", "Preparing to {} randomize...", (incremental ? "incremental" : "full"));
Prepare();
LOG_INFO("playerbots", "Resetting player...");
LOG_DEBUG("playerbots", "Resetting player...");
PerformanceMonitorOperation* pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Reset");
bot->resetTalents(true);
// bot->SaveToDB(false, false);
@@ -221,14 +221,14 @@ void PlayerbotFactory::Randomize(bool incremental)
}
pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Spells1");
LOG_INFO("playerbots", "Initializing spells (step 1)...");
LOG_DEBUG("playerbots", "Initializing spells (step 1)...");
// bot->LearnDefaultSkills();
InitClassSpells();
InitAvailableSpells();
if (pmo)
pmo->finish();
LOG_INFO("playerbots", "Initializing skills (step 1)...");
LOG_DEBUG("playerbots", "Initializing skills (step 1)...");
pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Skills1");
InitSkills();
InitSpecialSpells();
@@ -238,7 +238,7 @@ void PlayerbotFactory::Randomize(bool incremental)
pmo->finish();
pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Talents");
LOG_INFO("playerbots", "Initializing talents...");
LOG_DEBUG("playerbots", "Initializing talents...");
if (!sPlayerbotAIConfig->equipmentPersistence || bot->GetLevel() < sPlayerbotAIConfig->equipmentPersistenceLevel) {
InitTalentsTree();
}
@@ -252,13 +252,13 @@ void PlayerbotFactory::Randomize(bool incremental)
pmo->finish();
pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Spells2");
LOG_INFO("playerbots", "Initializing spells (step 2)...");
LOG_DEBUG("playerbots", "Initializing spells (step 2)...");
InitAvailableSpells();
if (pmo)
pmo->finish();
pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Mounts");
LOG_INFO("playerbots", "Initializing mounts...");
LOG_DEBUG("playerbots", "Initializing mounts...");
InitMounts();
bot->SaveToDB(false, false);
if (pmo)
@@ -271,7 +271,7 @@ void PlayerbotFactory::Randomize(bool incremental)
pmo->finish();
pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Equip");
LOG_INFO("playerbots", "Initializing equipmemt...");
LOG_DEBUG("playerbots", "Initializing equipmemt...");
if (!sPlayerbotAIConfig->equipmentPersistence || bot->GetLevel() < sPlayerbotAIConfig->equipmentPersistenceLevel) {
InitEquipment(incremental);
}
@@ -289,38 +289,38 @@ void PlayerbotFactory::Randomize(bool incremental)
// }
pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Bags");
LOG_INFO("playerbots", "Initializing bags...");
LOG_DEBUG("playerbots", "Initializing bags...");
InitBags();
// bot->SaveToDB(false, false);
if (pmo)
pmo->finish();
pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Ammo");
LOG_INFO("playerbots", "Initializing ammo...");
LOG_DEBUG("playerbots", "Initializing ammo...");
InitAmmo();
if (pmo)
pmo->finish();
pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Food");
LOG_INFO("playerbots", "Initializing food...");
LOG_DEBUG("playerbots", "Initializing food...");
InitFood();
if (pmo)
pmo->finish();
pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Potions");
LOG_INFO("playerbots", "Initializing potions...");
LOG_DEBUG("playerbots", "Initializing potions...");
InitPotions();
if (pmo)
pmo->finish();
pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Reagents");
LOG_INFO("playerbots", "Initializing reagents...");
LOG_DEBUG("playerbots", "Initializing reagents...");
InitReagents();
if (pmo)
pmo->finish();
pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_EqSets");
LOG_INFO("playerbots", "Initializing second equipment set...");
LOG_DEBUG("playerbots", "Initializing second equipment set...");
// InitSecondEquipmentSet();
if (pmo)
pmo->finish();
@@ -337,18 +337,18 @@ void PlayerbotFactory::Randomize(bool incremental)
// }
pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Inventory");
LOG_INFO("playerbots", "Initializing inventory...");
LOG_DEBUG("playerbots", "Initializing inventory...");
// InitInventory();
if (pmo)
pmo->finish();
pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Consumable");
LOG_INFO("playerbots", "Initializing consumables...");
LOG_DEBUG("playerbots", "Initializing consumables...");
AddConsumables();
if (pmo)
pmo->finish();
LOG_INFO("playerbots", "Initializing glyphs...");
LOG_DEBUG("playerbots", "Initializing glyphs...");
bot->SaveToDB(false, false);
InitGlyphs();
@@ -385,12 +385,12 @@ void PlayerbotFactory::Randomize(bool incremental)
}
pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Save");
LOG_INFO("playerbots", "Saving to DB...");
LOG_DEBUG("playerbots", "Saving to DB...");
bot->SetMoney(urand(level * 100000, level * 5 * 100000));
bot->SetHealth(bot->GetMaxHealth());
bot->SetPower(POWER_MANA, bot->GetMaxPower(POWER_MANA));
bot->SaveToDB(false, false);
LOG_INFO("playerbots", "Done.");
LOG_INFO("playerbots", "Initialization Done.");
if (pmo)
pmo->finish();
}

View File

@@ -23,7 +23,7 @@ GuidVector AttackersValue::Calculate()
if (Group* group = bot->GetGroup())
AddAttackersOf(group, targets);
// prioritize target
// prioritized target
GuidVector prioritizedTargets = AI_VALUE(GuidVector, "prioritized targets");
for (ObjectGuid target : prioritizedTargets) {
Unit* unit = botAI->GetUnit(target);
@@ -31,11 +31,13 @@ GuidVector AttackersValue::Calculate()
targets.insert(unit);
}
}
ObjectGuid skullGuid = bot->GetGroup()->GetTargetIcon(4);
if (Group* group = bot->GetGroup()) {
ObjectGuid skullGuid = group->GetTargetIcon(4);
Unit* skullTarget = botAI->GetUnit(skullGuid);
if (skullTarget) {
targets.insert(skullTarget);
}
}
RemoveNonThreating(targets);