Config option ApplyInstanceStrategies

This commit is contained in:
Yunfan Li
2024-08-19 23:55:37 +08:00
parent e983f9be00
commit 5a576cd9a5
11 changed files with 133 additions and 81 deletions

View File

@@ -369,8 +369,8 @@ AiPlayerbot.SyncQuestForPlayer = 0
#
#
# Bot can flee for enemy
AiPlayerbot.FleeingEnabled = 1
# Auto add dungeon/raid strategies when entering the instance if implemented
AiPlayerbot.ApplyInstanceStrategies = 1
# Enable auto avoid aoe (experimental)
# Default: 1 (enable)
@@ -388,6 +388,9 @@ AiPlayerbot.AutoSaveMana = 1
# Default: 60 (60%)
AiPlayerbot.SaveManaThreshold = 60
# Bot can flee for enemy
AiPlayerbot.FleeingEnabled = 1
#
#
#

View File

@@ -136,6 +136,8 @@ PlayerbotAI::PlayerbotAI(Player* bot)
engines[BOT_STATE_COMBAT] = AiFactory::createCombatEngine(bot, this, aiObjectContext);
engines[BOT_STATE_NON_COMBAT] = AiFactory::createNonCombatEngine(bot, this, aiObjectContext);
engines[BOT_STATE_DEAD] = AiFactory::createDeadEngine(bot, this, aiObjectContext);
if (sPlayerbotAIConfig->applyInstanceStrategies)
ApplyInstanceStrategies(bot->GetMapId());
currentEngine = engines[BOT_STATE_NON_COMBAT];
currentState = BOT_STATE_NON_COMBAT;
@@ -650,10 +652,11 @@ void PlayerbotAI::HandleTeleportAck()
bot->GetSession()->HandleMoveWorldportAck();
}
SetNextCheckDelay(urand(2000, 5000));
if (sPlayerbotAIConfig->applyInstanceStrategies)
ApplyInstanceStrategies(bot->GetMapId(), true);
}
SetNextCheckDelay(sPlayerbotAIConfig->globalCoolDown);
Reset();
}
@@ -1487,6 +1490,34 @@ std::vector<std::string> PlayerbotAI::GetStrategies(BotState type)
return e->GetStrategies();
}
void PlayerbotAI::ApplyInstanceStrategies(uint32 mapId, bool tellMaster)
{
std::string strategyName;
switch (mapId)
{
case 533:
strategyName = "naxx";
break;
case 603:
strategyName = "uld";
break;
case 469:
strategyName = "bwl";
break;
default:
break;
}
engines[BOT_STATE_COMBAT]->addStrategy(strategyName);
engines[BOT_STATE_NON_COMBAT]->addStrategy(strategyName);
if (tellMaster && !strategyName.empty())
{
std::ostringstream out;
out << "Add " << strategyName << " instance strategy";
TellMaster(out.str());
}
}
bool PlayerbotAI::DoSpecificAction(std::string const name, Event event, bool silent, std::string const qualifier)
{
std::ostringstream out;
@@ -1584,6 +1615,8 @@ void PlayerbotAI::ResetStrategies(bool load)
AiFactory::AddDefaultCombatStrategies(bot, this, engines[BOT_STATE_COMBAT]);
AiFactory::AddDefaultNonCombatStrategies(bot, this, engines[BOT_STATE_NON_COMBAT]);
AiFactory::AddDefaultDeadStrategies(bot, this, engines[BOT_STATE_DEAD]);
if (sPlayerbotAIConfig->applyInstanceStrategies)
ApplyInstanceStrategies(bot->GetMapId());
for (uint8 i = 0; i < BOT_STATE_MAX; i++)
engines[i]->Init();
@@ -5736,7 +5769,7 @@ uint32 PlayerbotAI::GetReactDelay()
bool isResting = bot->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING);
if (!isResting)
{
multiplier = urand(5, 20);
multiplier = urand(10, 30);
return base * multiplier;
}

View File

@@ -147,8 +147,7 @@ static std::map<ChatChannelSource, std::string> ChatChannelSourceStr = {
{SRC_PARTY, "SRC_PARTY"},
{SRC_RAID, "SRC_RAID"},
{ SRC_UNDEFINED, "SRC_UNDEFINED"}
};
{SRC_UNDEFINED, "SRC_UNDEFINED"}};
enum ChatChannelId
{
GENERAL = 1,
@@ -390,10 +389,12 @@ public:
void HandleTeleportAck();
void ChangeEngine(BotState type);
void DoNextAction(bool minimal = false);
virtual bool DoSpecificAction(std::string const name, Event event = Event(), bool silent = false, std::string const qualifier = "");
virtual bool DoSpecificAction(std::string const name, Event event = Event(), bool silent = false,
std::string const qualifier = "");
void ChangeStrategy(std::string const name, BotState type);
void ClearStrategies(BotState type);
std::vector<std::string> GetStrategies(BotState type);
void ApplyInstanceStrategies(uint32 mapId, bool tellMaster = false);
bool ContainsStrategy(StrategyType type);
bool HasStrategy(std::string const name, BotState type);
BotState GetState() { return currentState; };
@@ -434,8 +435,10 @@ public:
bool TellMaster(std::ostringstream& stream, PlayerbotSecurityLevel securityLevel = PLAYERBOT_SECURITY_ALLOW_ALL);
bool TellMaster(std::string const text, PlayerbotSecurityLevel securityLevel = PLAYERBOT_SECURITY_ALLOW_ALL);
bool TellMasterNoFacing(std::ostringstream& stream, PlayerbotSecurityLevel securityLevel = PLAYERBOT_SECURITY_ALLOW_ALL);
bool TellMasterNoFacing(std::string const text, PlayerbotSecurityLevel securityLevel = PLAYERBOT_SECURITY_ALLOW_ALL);
bool TellMasterNoFacing(std::ostringstream& stream,
PlayerbotSecurityLevel securityLevel = PLAYERBOT_SECURITY_ALLOW_ALL);
bool TellMasterNoFacing(std::string const text,
PlayerbotSecurityLevel securityLevel = PLAYERBOT_SECURITY_ALLOW_ALL);
bool TellError(std::string const text, PlayerbotSecurityLevel securityLevel = PLAYERBOT_SECURITY_ALLOW_ALL);
bool SayToGuild(const std::string& msg);
bool SayToWorld(const std::string& msg);
@@ -528,7 +531,11 @@ public:
bool IsSafe(WorldObject* obj);
ChatChannelSource GetChatChannelSource(Player* bot, uint32 type, std::string channelName);
bool HasCheat(BotCheatMask mask) { return ((uint32)mask & (uint32)cheatMask) != 0 || ((uint32)mask & (uint32)sPlayerbotAIConfig->botCheatMask) != 0; }
bool HasCheat(BotCheatMask mask)
{
return ((uint32)mask & (uint32)cheatMask) != 0 ||
((uint32)mask & (uint32)sPlayerbotAIConfig->botCheatMask) != 0;
}
BotCheatMask GetCheat() { return cheatMask; }
void SetCheat(BotCheatMask mask) { cheatMask = mask; }
@@ -563,7 +570,8 @@ public:
void PetFollow();
private:
static void _fillGearScoreData(Player* player, Item* item, std::vector<uint32>* gearScore, uint32& twoHandScore, bool mixed = false);
static void _fillGearScoreData(Player* player, Item* item, std::vector<uint32>* gearScore, uint32& twoHandScore,
bool mixed = false);
bool IsTellAllowed(PlayerbotSecurityLevel securityLevel = PLAYERBOT_SECURITY_ALLOW_ALL);
void HandleCommands();

View File

@@ -286,6 +286,7 @@ bool PlayerbotAIConfig::Initialize()
randomBotNonCombatStrategies = sConfigMgr->GetOption<std::string>("AiPlayerbot.RandomBotNonCombatStrategies", "");
combatStrategies = sConfigMgr->GetOption<std::string>("AiPlayerbot.CombatStrategies", "+custom::say");
nonCombatStrategies = sConfigMgr->GetOption<std::string>("AiPlayerbot.NonCombatStrategies", "+custom::say,+return");
applyInstanceStrategies = sConfigMgr->GetOption<bool>("AiPlayerbot.ApplyInstanceStrategies", true);
commandPrefix = sConfigMgr->GetOption<std::string>("AiPlayerbot.CommandPrefix", "");
commandSeparator = sConfigMgr->GetOption<std::string>("AiPlayerbot.CommandSeparator", "\\\\");
@@ -477,11 +478,11 @@ bool PlayerbotAIConfig::Initialize()
{
return true;
}
PlayerbotFactory::Init();
sRandomItemMgr->Init();
sRandomItemMgr->InitAfterAhBot();
sPlayerbotTextMgr->LoadBotTexts();
sPlayerbotTextMgr->LoadBotTextChance();
PlayerbotFactory::Init();
if (!sPlayerbotAIConfig->autoDoQuests)
{

View File

@@ -184,6 +184,7 @@ public:
bool summonAtInnkeepersEnabled;
std::string combatStrategies, nonCombatStrategies;
std::string randomBotCombatStrategies, randomBotNonCombatStrategies;
bool applyInstanceStrategies;
uint32 randomBotMinLevel, randomBotMaxLevel;
float randomChangeMultiplier;

View File

@@ -949,7 +949,6 @@ void RandomItemMgr::BuildItemInfoCache()
PlayerbotsDatabaseTransaction trans = PlayerbotsDatabase.BeginTransaction();
// generate stat weights for classes/specs
for (auto const& itr : *itemTemplate)
{
ItemTemplate const* proto = &itr.second;
@@ -958,11 +957,12 @@ void RandomItemMgr::BuildItemInfoCache()
// skip non armor/weapon
if (proto->Class != ITEM_CLASS_WEAPON && proto->Class != ITEM_CLASS_ARMOR &&
proto->Class != ITEM_CLASS_CONTAINER && proto->Class != ITEM_CLASS_PROJECTILE)
proto->Class != ITEM_CLASS_CONTAINER && proto->Class != ITEM_CLASS_PROJECTILE &&
proto->Class != ITEM_CLASS_GEM)
continue;
if (!CanEquipItemNew(proto))
continue;
// if (!CanEquipItemNew(proto))
// continue;
// skip test items
if (strstr(proto->Name1.c_str(), "(Test)") || strstr(proto->Name1.c_str(), "(TEST)") ||
@@ -990,29 +990,29 @@ void RandomItemMgr::BuildItemInfoCache()
proto->RequiredReputationRank > 0)
continue;*/
if (proto->RequiredHonorRank > 0 || proto->RequiredSkillRank > 0 || proto->RequiredCityRank > 0)
continue;
// if (proto->RequiredHonorRank > 0 || proto->RequiredSkillRank > 0 || proto->RequiredCityRank > 0)
// continue;
// skip random enchant items
if (proto->RandomProperty)
continue;
// // skip random enchant items
// if (proto->RandomProperty)
// continue;
// skip heirloom items
if (proto->Quality == ITEM_QUALITY_HEIRLOOM)
continue;
// // skip heirloom items
// if (proto->Quality == ITEM_QUALITY_HEIRLOOM)
// continue;
// check possible equip slots
EquipmentSlots slot = EQUIPMENT_SLOT_START;
for (std::map<EquipmentSlots, std::set<InventoryType> >::iterator i = viableSlots.begin();
i != viableSlots.end(); ++i)
{
std::set<InventoryType> slots = viableSlots[(EquipmentSlots)i->first];
if (slots.find((InventoryType)proto->InventoryType) != slots.end())
slot = i->first;
}
// // check possible equip slots
// EquipmentSlots slot = EQUIPMENT_SLOT_START;
// for (std::map<EquipmentSlots, std::set<InventoryType> >::iterator i = viableSlots.begin();
// i != viableSlots.end(); ++i)
// {
// std::set<InventoryType> slots = viableSlots[(EquipmentSlots)i->first];
// if (slots.find((InventoryType)proto->InventoryType) != slots.end())
// slot = i->first;
// }
if (slot == EQUIPMENT_SLOT_START)
continue;
// if (slot == EQUIPMENT_SLOT_START)
// continue;
// Init Item cache
// ItemInfoEntry cacheInfo;

View File

@@ -8,6 +8,7 @@
#include <map>
#include <set>
#include <unordered_set>
#include <vector>
#include "AiFactory.h"
@@ -203,7 +204,7 @@ private:
std::map<std::string, uint32> weightStatLink;
std::map<std::string, uint32> weightRatingLink;
std::map<uint32, ItemInfoEntry> itemInfoCache;
std::set<uint32> itemForTest;
std::unordered_set<uint32> itemForTest;
static std::set<uint32> itemCache;
// equipCacheNew[RequiredLevel][InventoryType]
std::map<uint32, std::map<uint32, std::vector<uint32>>> equipCacheNew;

View File

@@ -135,15 +135,17 @@ void PlayerbotFactory::Init()
{
continue;
}
if (gemId == 49110)
{ // unique gem
continue;
}
ItemTemplate const* proto = sObjectMgr->GetItemTemplate(gemId);
if (proto->ItemLevel < 60)
continue;
if (proto->Flags & ITEM_FLAG_UNIQUE_EQUIPPABLE)
{ // unique gem
{
continue;
}
if (sRandomItemMgr->IsTestItem(gemId))
continue;
if (!proto || !sGemPropertiesStore.LookupEntry(proto->GemProperties))
{
continue;
@@ -403,7 +405,7 @@ void PlayerbotFactory::Randomize(bool incremental)
bot->SetMoney(urand(level * 100000, level * 5 * 100000));
bot->SetHealth(bot->GetMaxHealth());
bot->SetPower(POWER_MANA, bot->GetMaxPower(POWER_MANA));
bot->SaveToDB(false, false);
// bot->SaveToDB(false, false);
LOG_INFO("playerbots", "Initialization Done.");
if (pmo)
pmo->finish();
@@ -438,7 +440,7 @@ void PlayerbotFactory::Refresh()
uint32 money = urand(level * 1000, level * 5 * 1000);
if (bot->GetMoney() < money)
bot->SetMoney(money);
bot->SaveToDB(false, false);
// bot->SaveToDB(false, false);
}
void PlayerbotFactory::AddConsumables()
@@ -805,17 +807,13 @@ void PlayerbotFactory::ClearSkills()
void PlayerbotFactory::ClearEverything()
{
bot->SaveToDB(false, false);
bot->GiveLevel(bot->getClass() == CLASS_DEATH_KNIGHT ? sWorld->getIntConfig(CONFIG_START_HEROIC_PLAYER_LEVEL)
: sWorld->getIntConfig(CONFIG_START_PLAYER_LEVEL));
bot->SetUInt32Value(PLAYER_XP, 0);
LOG_INFO("playerbots", "Resetting player...");
bot->resetTalents(true);
bot->SaveToDB(false, false);
ClearSkills();
// bot->SaveToDB(false, false);
ClearSpells();
bot->SaveToDB(false, false);
ClearInventory();
ResetQuests();
bot->SaveToDB(false, false);
@@ -2027,6 +2025,7 @@ void PlayerbotFactory::InitSkills()
SetRandomSkill(SKILL_THROWN);
bot->SetSkill(SKILL_DUAL_WIELD, 0, dualWieldLevel, dualWieldLevel);
bot->SetSkill(SKILL_PLATE_MAIL, 0, skillLevel, skillLevel);
bot->SetCanDualWield(dualWieldLevel);
break;
case CLASS_PALADIN:
SetRandomSkill(SKILL_SWORDS);
@@ -2079,8 +2078,9 @@ void PlayerbotFactory::InitSkills()
SetRandomSkill(SKILL_POLEARMS);
SetRandomSkill(SKILL_FIST_WEAPONS);
SetRandomSkill(SKILL_THROWN);
bot->SetSkill(SKILL_MAIL, 0, skillLevel, skillLevel);
bot->SetSkill(SKILL_DUAL_WIELD, 0, dualWieldLevel, dualWieldLevel);
bot->SetSkill(SKILL_MAIL, 0, skillLevel, skillLevel);
bot->SetCanDualWield(dualWieldLevel);
break;
case CLASS_ROGUE:
SetRandomSkill(SKILL_SWORDS);
@@ -2093,6 +2093,7 @@ void PlayerbotFactory::InitSkills()
SetRandomSkill(SKILL_FIST_WEAPONS);
SetRandomSkill(SKILL_THROWN);
bot->SetSkill(SKILL_DUAL_WIELD, 0, 1, 1);
bot->SetCanDualWield(true);
break;
case CLASS_DEATH_KNIGHT:
SetRandomSkill(SKILL_SWORDS);
@@ -2103,6 +2104,7 @@ void PlayerbotFactory::InitSkills()
SetRandomSkill(SKILL_2H_AXES);
SetRandomSkill(SKILL_POLEARMS);
bot->SetSkill(SKILL_DUAL_WIELD, 0, dualWieldLevel, dualWieldLevel);
bot->SetCanDualWield(dualWieldLevel);
break;
default:
break;
@@ -2572,7 +2574,6 @@ void PlayerbotFactory::InitInstanceQuests()
ClearInventory();
bot->SetUInt32Value(PLAYER_XP, currentXP);
bot->SaveToDB(false, false);
}
void PlayerbotFactory::ClearInventory()
@@ -3329,7 +3330,7 @@ void PlayerbotFactory::InitGuild()
if (bot->GetGuildId())
return;
bot->SaveToDB(false, false);
// bot->SaveToDB(false, false);
// add guild tabard
if (bot->GetGuildId() && !bot->HasItemCount(5976, 1))
@@ -3365,7 +3366,7 @@ void PlayerbotFactory::InitGuild()
if (bot->GetGuildId() && bot->GetLevel() > 9 && urand(0, 4) && !bot->HasItemCount(5976, 1))
StoreItem(5976, 1);
bot->SaveToDB(false, false);
// bot->SaveToDB(false, false);
}
void PlayerbotFactory::InitImmersive()
@@ -3554,7 +3555,7 @@ void PlayerbotFactory::InitArenaTeam()
arenateams.erase(arenateams.begin() + index);
}
bot->SaveToDB(false, false);
// bot->SaveToDB(false, false);
}
void PlayerbotFactory::ApplyEnchantTemplate()
@@ -3670,6 +3671,9 @@ void PlayerbotFactory::ApplyEnchantAndGemsNew(bool destoryOld)
if (!gemProperties)
continue;
if (sPlayerbotAIConfig->limitEnchantExpansion && bot->GetLevel() <= 70 && enchantGem >= 39900)
continue;
uint32 requiredLevel = gemTemplate->ItemLevel;
if (requiredLevel > bot->GetLevel())

View File

@@ -431,7 +431,8 @@ void StatsWeightCalculator::CalculateItemTypePenalty(ItemTemplate const* proto)
// spec with double hand
// fury without duel wield, arms, bear, retribution, blood dk
if (isDoubleHand &&
((cls == CLASS_WARRIOR && tab == WARRIOR_TAB_FURY && !player_->CanDualWield()) ||
((cls == CLASS_HUNTER && !player_->CanDualWield()) ||
(cls == CLASS_WARRIOR && tab == WARRIOR_TAB_FURY && !player_->CanDualWield()) ||
(cls == CLASS_WARRIOR && tab == WARRIOR_TAB_ARMS) || (cls == CLASS_DRUID && tab == DRUID_TAB_FERAL) ||
(cls == CLASS_PALADIN && tab == PALADIN_TAB_RETRIBUTION) ||
(cls == CLASS_DEATH_KNIGHT && tab == DEATHKNIGHT_TAB_BLOOD) ||

View File

@@ -197,6 +197,7 @@ bool MovementAction::MoveTo(uint32 mapId, float x, float y, float z, bool idle,
{
VehicleSeatEntry const* seat = vehicle->GetSeatForPassenger(bot);
Unit* vehicleBase = vehicle->GetBase();
generatePath = vehicleBase->CanFly();
if (!vehicleBase || !seat || !seat->CanControl()) // is passenger and cant move anyway
return false;
@@ -815,7 +816,6 @@ bool MovementAction::ReachCombatTo(Unit* target, float distance)
if (target->HasUnitMovementFlag(MOVEMENTFLAG_FORWARD)) // target is moving forward, predict the position
{
float needToGo = bot->GetExactDist(target) - distance;
float timeToGo = MoveDelay(abs(needToGo)) + sPlayerbotAIConfig->reactDelay / 1000.0f;
float targetMoveDist = timeToGo * target->GetSpeed(MOVE_RUN);
@@ -848,7 +848,8 @@ bool MovementAction::ReachCombatTo(Unit* target, float distance)
return false;
path.ShortenPathUntilDist(G3D::Vector3(tx, ty, tz), distance);
G3D::Vector3 endPos = path.GetPath().back();
return MoveTo(target->GetMapId(), endPos.x, endPos.y, endPos.z, false, false, false, false, MovementPriority::MOVEMENT_COMBAT);
return MoveTo(target->GetMapId(), endPos.x, endPos.y, endPos.z, false, false, false, false,
MovementPriority::MOVEMENT_COMBAT);
}
float MovementAction::GetFollowAngle()
@@ -924,7 +925,6 @@ bool MovementAction::IsWaitingForLastMove(MovementPriority priority)
if (lastMove.lastdelayTime + lastMove.msTime > getMSTime())
return true;
return false;
}
@@ -2403,7 +2403,8 @@ bool MoveInsideAction::Execute(Event event) { return MoveInside(bot->GetMapId(),
bool RotateAroundTheCenterPointAction::Execute(Event event)
{
uint32 next_point = GetCurrWaypoint();
if (MoveTo(bot->GetMapId(), waypoints[next_point].first, waypoints[next_point].second, bot->GetPositionZ(), false, false, false, false, MovementPriority::MOVEMENT_COMBAT))
if (MoveTo(bot->GetMapId(), waypoints[next_point].first, waypoints[next_point].second, bot->GetPositionZ(), false,
false, false, false, MovementPriority::MOVEMENT_COMBAT))
{
call_counters += 1;
return true;

View File

@@ -319,7 +319,6 @@ bool SpiritHealerAction::Execute(Event event)
PlayerbotChatHandler ch(bot);
bot->ResurrectPlayer(0.5f);
bot->SpawnCorpseBones();
bot->SaveToDB(false, false);
context->GetValue<Unit*>("current target")->Set(nullptr);
bot->SetTarget();
botAI->TellMaster("Hello");