fix: bot stuck after drink or food && initialization customized

This commit is contained in:
Yunfan Li
2023-05-23 23:39:20 +08:00
parent 32da0c07c9
commit c16e587854
18 changed files with 247 additions and 119 deletions

View File

@@ -152,7 +152,7 @@ RandomItemMgr::RandomItemMgr()
void RandomItemMgr::Init()
{
BuildItemInfoCache();
BuildEquipCache();
// BuildEquipCache();
BuildAmmoCache();
BuildPotionCache();
BuildFoodCache();
@@ -285,7 +285,7 @@ void RandomItemMgr::BuildRandomItemCache()
if (!proto)
continue;
LOG_INFO("playerbots", " [{}] {}", itemId, proto->Name1.c_str());
LOG_DEBUG("playerbots", " [{}] {}", itemId, proto->Name1.c_str());
}
}
}
@@ -332,30 +332,29 @@ bool RandomItemMgr::CanEquipItem(BotEquipKey key, ItemTemplate const* proto)
requiredLevel = key.level;
uint32 level = key.level;
uint32 delta = 2;
if (level < 15)
delta = urand(7, 15);
else if (proto->Class == ITEM_CLASS_WEAPON || proto->SubClass == ITEM_SUBCLASS_ARMOR_SHIELD)
delta = urand(2, 3);
else if (!(level % 10) || (level % 10) == 9)
delta = 2;
delta = 15;
else if (level < 40)
delta = urand(5, 10);
delta = 10; //urand(5, 10);
else if (level < 60)
delta = urand(3, 7);
delta = 6; // urand(3, 7);
else if (level < 70)
delta = urand(2, 5);
delta = 9; // urand(2, 5);
else if (level < 80)
delta = urand(2, 4);
delta = 9; // urand(2, 4);
else if (level == 80)
delta = 2; // urand(2, 4);
if (key.quality > ITEM_QUALITY_NORMAL && (requiredLevel > level || requiredLevel < level - delta))
return false;
for (uint32 gap = 60; gap <= 80; gap += 10)
{
if (level > gap && requiredLevel <= gap)
return false;
}
// for (uint32 gap = 60; gap <= 80; gap += 10)
// {
// if (level > gap && requiredLevel <= gap)
// return false;
// }
return true;
}
@@ -1026,7 +1025,7 @@ void RandomItemMgr::BuildItemInfoCache()
//statWeight.weight = statW;
// save item statWeight into ItemCache
cacheInfo.weights[statWeight.id] = statWeight.weight;
LOG_INFO("playerbots", "Item: {}, weight: {}, class: {}, spec: {}", proto->ItemId, statWeight.weight, clazz, m_weightScales[clazz][spec].info.name);
LOG_DEBUG("playerbots", "Item: {}, weight: {}, class: {}, spec: {}", proto->ItemId, statWeight.weight, clazz, m_weightScales[clazz][spec].info.name);
}
}
@@ -1051,7 +1050,7 @@ void RandomItemMgr::BuildItemInfoCache()
}
if (cacheInfo.team < TEAM_NEUTRAL)
LOG_INFO("playerbots", "Item: {}, team (item): {}", proto->ItemId, cacheInfo.team == TEAM_ALLIANCE ? "Alliance" : "Horde");
LOG_DEBUG("playerbots", "Item: {}, team (item): {}", proto->ItemId, cacheInfo.team == TEAM_ALLIANCE ? "Alliance" : "Horde");
// check min level
if (proto->RequiredLevel)
@@ -1062,7 +1061,7 @@ void RandomItemMgr::BuildItemInfoCache()
if (proto->Flags & ITEM_FLAG_NO_DISENCHANT)
{
cacheInfo.source = ITEM_SOURCE_PVP;
LOG_INFO("playerbots", "Item: {}, source: PvP Reward", proto->ItemId);
LOG_DEBUG("playerbots", "Item: {}, source: PvP Reward", proto->ItemId);
}
// check quests
@@ -1105,13 +1104,13 @@ void RandomItemMgr::BuildItemInfoCache()
else if (isHorde)
cacheInfo.team = TEAM_HORDE;
LOG_INFO("playerbots", "Item: {}, team (quest): {}", proto->ItemId, cacheInfo.team == TEAM_ALLIANCE ? "Alliance" : cacheInfo.team == TEAM_HORDE ? "Horde" : "Both");
LOG_INFO("playerbots", "Item: {}, source: quest {}, minlevel: {}", proto->ItemId, cacheInfo.sourceId, cacheInfo.minLevel);
LOG_DEBUG("playerbots", "Item: {}, team (quest): {}", proto->ItemId, cacheInfo.team == TEAM_ALLIANCE ? "Alliance" : cacheInfo.team == TEAM_HORDE ? "Horde" : "Both");
LOG_DEBUG("playerbots", "Item: {}, source: quest {}, minlevel: {}", proto->ItemId, cacheInfo.sourceId, cacheInfo.minLevel);
}
}
if (cacheInfo.minLevel)
LOG_INFO("playerbots", "Item: {}, minlevel: {}", proto->ItemId, cacheInfo.minLevel);
LOG_DEBUG("playerbots", "Item: {}, minlevel: {}", proto->ItemId, cacheInfo.minLevel);
// check vendors
if (cacheInfo.source == ITEM_SOURCE_NONE)
@@ -1121,7 +1120,7 @@ void RandomItemMgr::BuildItemInfoCache()
if (proto->ItemId == *i)
{
cacheInfo.source = ITEM_SOURCE_VENDOR;
LOG_INFO("playerbots", "Item: {} source: vendor", proto->ItemId);
LOG_DEBUG("playerbots", "Item: {} source: vendor", proto->ItemId);
break;
}
}
@@ -1149,12 +1148,12 @@ void RandomItemMgr::BuildItemInfoCache()
{
cacheInfo.source = ITEM_SOURCE_DROP;
cacheInfo.sourceId = creatures.front();
LOG_INFO("playerbots", "Item: {}, source: creature drop, ID: {}", proto->ItemId, creatures.front());
LOG_DEBUG("playerbots", "Item: {}, source: creature drop, ID: {}", proto->ItemId, creatures.front());
}
else
{
cacheInfo.source = ITEM_SOURCE_DROP;
LOG_INFO("playerbots", "Item: {}, source: creatures drop, number: {}", proto->ItemId, creatures.size());
LOG_DEBUG("playerbots", "Item: {}, source: creatures drop, number: {}", proto->ItemId, creatures.size());
}
}
}
@@ -1548,9 +1547,9 @@ uint32 RandomItemMgr::CalculateSingleStatWeight(uint8 playerclass, uint8 spec, s
if (stat == i->stat)
{
statWeight = i->weight * value;
if (statWeight)
LOG_INFO("playerbots", "stat: {}, val: {}, weight: {}, total: {}, class: {}, spec: {}",
stat, value, i->weight, statWeight, playerclass, m_weightScales[playerclass][spec].info.name);
// if (statWeight)
// LOG_INFO("playerbots", "stat: {}, val: {}, weight: {}, total: {}, class: {}, spec: {}",
// stat, value, i->weight, statWeight, playerclass, m_weightScales[playerclass][spec].info.name);
return statWeight;
}
}
@@ -2121,7 +2120,7 @@ void RandomItemMgr::BuildEquipCache()
equipCache[key] = items;
LOG_INFO("playerbots", "Equipment cache for class: {}, level {}, slot {}, quality {}: {} items",
LOG_DEBUG("playerbots", "Equipment cache for class: {}, level {}, slot {}, quality {}: {} items",
class_, level, slot, quality, items.size());
}
}
@@ -2134,8 +2133,36 @@ void RandomItemMgr::BuildEquipCache()
RandomItemList RandomItemMgr::Query(uint32 level, uint8 clazz, uint8 slot, uint32 quality)
{
// return equipCache[key];
BotEquipKey key(level, clazz, slot, quality);
return equipCache[key];
RandomItemList items;
ItemTemplateContainer const* itemTemplates = sObjectMgr->GetItemTemplateStore();
for (auto const& itr : *itemTemplates)
{
ItemTemplate const* proto = &itr.second;
if (!proto)
continue;
if (proto->Class != ITEM_CLASS_WEAPON && proto->Class != ITEM_CLASS_ARMOR && proto->Class != ITEM_CLASS_CONTAINER && proto->Class != ITEM_CLASS_PROJECTILE)
continue;
if (!CanEquipItem(key, proto))
continue;
if (proto->Class == ITEM_CLASS_ARMOR && (slot == EQUIPMENT_SLOT_HEAD || slot == EQUIPMENT_SLOT_SHOULDERS || slot == EQUIPMENT_SLOT_CHEST ||
slot == EQUIPMENT_SLOT_WAIST || slot == EQUIPMENT_SLOT_LEGS || slot == EQUIPMENT_SLOT_FEET || slot == EQUIPMENT_SLOT_WRISTS ||
slot == EQUIPMENT_SLOT_HANDS) && !CanEquipArmor(key.clazz, key.level, proto))
continue;
if (proto->Class == ITEM_CLASS_WEAPON && !CanEquipWeapon(key.clazz, proto))
continue;
if (slot == EQUIPMENT_SLOT_OFFHAND && key.clazz == CLASS_ROGUE && proto->Class != ITEM_CLASS_WEAPON)
continue;
items.push_back(itr.first);
}
return items;
}
void RandomItemMgr::BuildAmmoCache()
@@ -2238,7 +2265,7 @@ void RandomItemMgr::BuildPotionCache()
uint32 size = potionCache[level / 10][effect].size();
++counter;
LOG_INFO("server.loading", "Potion cache for level={}, effect={}: {} items", level, effect, size);
LOG_DEBUG("server.loading", "Potion cache for level={}, effect={}: {} items", level, effect, size);
}
}
@@ -2298,7 +2325,7 @@ void RandomItemMgr::BuildFoodCache()
uint32 category = categories[i];
uint32 size = foodCache[level / 10][category].size();
++counter;
LOG_INFO("server.loading", "Food cache for level={}, category={}: {} items", level, category, size);
LOG_DEBUG("server.loading", "Food cache for level={}, category={}: {} items", level, category, size);
}
}
@@ -2414,7 +2441,7 @@ void RandomItemMgr::BuildTradeCache()
for (uint32 level = 1; level <= maxLevel + 1; level += 10)
{
uint32 size = tradeCache[level / 10].size();
LOG_INFO("server.loading", "Trade cache for level={}: {} items", level, size);
LOG_DEBUG("server.loading", "Trade cache for level={}: {} items", level, size);
++counter;
}