From 09566cb664aaad6c0f05180e66466e68a5555172 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Thu, 3 Aug 2023 21:27:59 +0800 Subject: [PATCH] miscs: engine --- conf/playerbots.conf.dist | 2 +- src/PlayerbotFactory.cpp | 11 ++--- src/RandomPlayerbotMgr.cpp | 5 +- src/strategy/Engine.cpp | 4 +- src/strategy/actions/LootRollAction.cpp | 62 ++++++++++++++++++------ src/strategy/actions/MovementActions.cpp | 5 +- src/strategy/values/Arrow.cpp | 2 +- 7 files changed, 62 insertions(+), 29 deletions(-) diff --git a/conf/playerbots.conf.dist b/conf/playerbots.conf.dist index 1ab426e0..b9ff26be 100644 --- a/conf/playerbots.conf.dist +++ b/conf/playerbots.conf.dist @@ -87,7 +87,7 @@ AiPlayerbot.RandomBotShowCloak = 1 AiPlayerbot.DisableRandomLevels = 0 # Set randombots starting level here if "AiPlayerbot.DisableRandomLevels" enabled -AiPlayerbot.RandombotStartingLevel = 1 +AiPlayerbot.RandombotStartingLevel = 5 # Set kill XP rate for bots (default: 1) # Server XP Rate * AiPlayerbot.KillXPRate diff --git a/src/PlayerbotFactory.cpp b/src/PlayerbotFactory.cpp index 6835db53..d31990ca 100644 --- a/src/PlayerbotFactory.cpp +++ b/src/PlayerbotFactory.cpp @@ -305,8 +305,10 @@ void PlayerbotFactory::Randomize(bool incremental) pmo->finish(); } - bot->RemovePet(nullptr, PET_SAVE_AS_CURRENT, true); - bot->RemovePet(nullptr, PET_SAVE_NOT_IN_SLOT, true); + if (!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"); @@ -1147,6 +1149,7 @@ void PlayerbotFactory::InitEquipmentNew(bool incremental) void PlayerbotFactory::InitEquipment(bool incremental) { + // todo(yunfan): to be refactored, too much time overhead DestroyItemsVisitor visitor(bot); IterateItems(&visitor, ITERATE_ALL_ITEMS); @@ -1215,13 +1218,11 @@ void PlayerbotFactory::InitEquipment(bool incremental) std::vector& ids = items[slot]; if (ids.empty()) { - sLog->outMessage("playerbot", LOG_LEVEL_DEBUG, "%s: no items to equip for slot %d", bot->GetName().c_str(), slot); continue; } Item* oldItem = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, slot); if (incremental && !IsDesiredReplacement(oldItem)) { - sLog->outMessage("playerbot", LOG_LEVEL_DEBUG, "%s: doesn't desire to replace current slot %d", bot->GetName().c_str(), slot); continue; } @@ -1243,7 +1244,6 @@ void PlayerbotFactory::InitEquipment(bool incremental) } } if (bestItemForSlot == 0) { - // sLog->outMessage("playerbot", LOG_LEVEL_INFO, "%s: equip failed for slot %d(bestItemForSlot == 0))", bot->GetName().c_str(), slot); continue; } if (oldItem) @@ -1253,7 +1253,6 @@ void PlayerbotFactory::InitEquipment(bool incremental) } uint16 dest; if (!CanEquipUnseenItem(slot, dest, bestItemForSlot)) { - sLog->outMessage("playerbot", LOG_LEVEL_DEBUG, "%s: equip failed for slot %d", bot->GetName().c_str(), slot); continue; } Item* newItem = bot->EquipNewItem(dest, bestItemForSlot, true); diff --git a/src/RandomPlayerbotMgr.cpp b/src/RandomPlayerbotMgr.cpp index abbc114f..31c195ba 100644 --- a/src/RandomPlayerbotMgr.cpp +++ b/src/RandomPlayerbotMgr.cpp @@ -1275,7 +1275,10 @@ void RandomPlayerbotMgr::IncreaseLevel(Player* bot) PerformanceMonitorOperation* pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "IncreaseLevel"); uint32 lastLevel = GetValue(bot, "level"); - uint32 level = bot->getLevel(); + uint8 level = bot->getLevel() + 1; + if (level > maxLevel) { + level = maxLevel; + } if (lastLevel != level) { PlayerbotFactory factory(bot, level); diff --git a/src/strategy/Engine.cpp b/src/strategy/Engine.cpp index 9cac56d7..e3602843 100644 --- a/src/strategy/Engine.cpp +++ b/src/strategy/Engine.cpp @@ -261,8 +261,8 @@ bool Engine::DoNextAction(Unit* unit, uint32 depth, bool minimal) lastRelevance = 0.0f; PushDefaultActions(); - if (queue.Peek() && depth < 1 && !minimal) - return DoNextAction(unit, depth + 1, minimal); + // if (queue.Peek() && depth < 1 && !minimal) + // return DoNextAction(unit, depth + 1, minimal); } // MEMORY FIX TEST diff --git a/src/strategy/actions/LootRollAction.cpp b/src/strategy/actions/LootRollAction.cpp index f97f3c24..7ccd7aef 100644 --- a/src/strategy/actions/LootRollAction.cpp +++ b/src/strategy/actions/LootRollAction.cpp @@ -26,21 +26,53 @@ bool LootRollAction::Execute(Event event) p >> rollType; //need,greed or pass on roll RollVote vote = PASS; - if (ItemTemplate const* proto = sObjectMgr->GetItemTemplate(guid.GetEntry())) - { - switch (proto->Class) - { - case ITEM_CLASS_WEAPON: - case ITEM_CLASS_ARMOR: - if (!QueryItemUsage(proto).empty()) - vote = NEED; - break; - default: - if (StoreLootAction::IsLootAllowed(guid.GetEntry(), botAI)) - vote = NEED; - break; - } - } + + // std::vector rolls = group->GetRolls(); + // bot->Say("guid:" + std::to_string(guid.GetCounter()) + + // "item entry:" + std::to_string(guid.GetEntry()), LANG_UNIVERSAL); + // for (std::vector::iterator i = rolls.begin(); i != rolls.end(); ++i) + // { + // if ((*i)->isValid() && (*i)->itemGUID == guid && (*i)->itemSlot == slot) + // { + // uint32 itemId = (*i)->itemid; + // bot->Say("item entry2:" + std::to_string(itemId), LANG_UNIVERSAL); + // ItemTemplate const *proto = sObjectMgr->GetItemTemplate(itemId); + // if (!proto) + // continue; + + // switch (proto->Class) + // { + // case ITEM_CLASS_WEAPON: + // case ITEM_CLASS_ARMOR: + // if (!QueryItemUsage(proto).empty()) + // vote = NEED; + // else if (bot->HasSkill(SKILL_ENCHANTING)) + // vote = DISENCHANT; + // break; + // default: + // if (StoreLootAction::IsLootAllowed(itemId, botAI)) + // vote = NEED; + // break; + // } + // break; + // } + // } + + // if (ItemTemplate const* proto = sObjectMgr->GetItemTemplate(guid.GetEntry())) + // { + // switch (proto->Class) + // { + // case ITEM_CLASS_WEAPON: + // case ITEM_CLASS_ARMOR: + // if (!QueryItemUsage(proto).empty()) + // vote = NEED; + // break; + // default: + // if (StoreLootAction::IsLootAllowed(guid.GetEntry(), botAI)) + // vote = NEED; + // break; + // } + // } switch (group->GetLootMethod()) { diff --git a/src/strategy/actions/MovementActions.cpp b/src/strategy/actions/MovementActions.cpp index fb8a5786..1a6eabaa 100644 --- a/src/strategy/actions/MovementActions.cpp +++ b/src/strategy/actions/MovementActions.cpp @@ -135,11 +135,10 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle, if (!IsMovingAllowed(mapId, x, y, z)) { return false; } - // if (bot->HasUnitMovementFlag(MOVEMENTFLAG_FALLING | MOVEMENTFLAG_FALLING_FAR)) { - // bot->Yell("I'm falling!", LANG_UNIVERSAL); + // if (bot->m_movementInfo.HasMovementFlag(MOVEMENTFLAG_FALLING | MOVEMENTFLAG_FALLING_SLOW | MOVEMENTFLAG_FALLING_FAR)) { + // bot->Say("I'm falling!, flag:" + std::to_string(bot->m_movementInfo.GetMovementFlags()), LANG_UNIVERSAL); // return false; // } - // bot->UpdateGroundPositionZ(x, y, z); z += 2.0f; bot->UpdateAllowedPositionZ(x, y, z); // z += 0.5f; diff --git a/src/strategy/values/Arrow.cpp b/src/strategy/values/Arrow.cpp index e51752f9..22cbf619 100644 --- a/src/strategy/values/Arrow.cpp +++ b/src/strategy/values/Arrow.cpp @@ -43,7 +43,7 @@ WorldLocation ArrowFormation::GetLocationInternal() float x = master->GetPositionX() - masterUnit->GetX() + botUnit->GetX(); float y = master->GetPositionY() - masterUnit->GetY() + botUnit->GetY(); - float z = master->GetPositionZ(); + float z = master->GetPositionZ() + 5.0f; float ground = master->GetMap()->GetHeight(x, y, z + 0.5f); if (ground <= INVALID_HEIGHT)