Skip to content

Commit

Permalink
Merge pull request liyunfan1223#507 from liyunfan1223/equip_init
Browse files Browse the repository at this point in the history
Equip init
  • Loading branch information
liyunfan1223 authored Sep 5, 2024
2 parents ab40471 + 73f699f commit ef2c0cd
Show file tree
Hide file tree
Showing 23 changed files with 581 additions and 193 deletions.
31 changes: 23 additions & 8 deletions conf/playerbots.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ AiPlayerbot.AutoEquipUpgradeLoot = 1
# Default: 1.1 (Equip when the equipment score is 1.1 times higher than the current)
AiPlayerbot.EquipUpgradeThreshold = 1.1

# Two rounds of equipment initialization to create more suitable gear
AiPlayerbot.TwoRoundsGearInit = 0

#
#
#
Expand Down Expand Up @@ -821,13 +824,25 @@ AiPlayerbot.PremadeSpecGlyph.3.0 = 42912,43350,42902,43351,43338,45732
AiPlayerbot.PremadeSpecLink.3.0.60 = 51200201505112243100511351
AiPlayerbot.PremadeSpecLink.3.0.80 = 51200201505112253100531351-015305021
AiPlayerbot.PremadeSpecName.3.1 = mm pve
AiPlayerbot.PremadeSpecGlyph.3.1 = 42912,43350,42915,43351,43338,45732
AiPlayerbot.PremadeSpecLink.3.1.60 = -015305101230013233135030051
AiPlayerbot.PremadeSpecGlyph.3.1 = 42912,43350,42914,43351,43338,45732
AiPlayerbot.PremadeSpecLink.3.1.60 = -015305101230013233125031051
AiPlayerbot.PremadeSpecLink.3.1.80 = 502-035305101230013233135031351-5000002
AiPlayerbot.PremadeSpecName.3.2 = surv pve
AiPlayerbot.PremadeSpecGlyph.3.2 = 42912,43350,45731,43351,43338,45732
AiPlayerbot.PremadeSpecLink.3.2.60 = --5000032500033330502135001331
AiPlayerbot.PremadeSpecLink.3.2.80 = -005305101-5000032500033330522135301331
AiPlayerbot.PremadeSpecLink.3.2.60 = --5000032500033330502135201311
AiPlayerbot.PremadeSpecLink.3.2.80 = -005305101-5000032500033330532135301321

# HUNTER PET
#
# Ferocity
AiPlayerbot.PremadeHunterPetLink.0.16 = 2100003030103010101
AiPlayerbot.PremadeHunterPetLink.0.20 = 2100013030103010122
# Tenacity
AiPlayerbot.PremadeHunterPetLink.1.16 = 21103000300120101001
AiPlayerbot.PremadeHunterPetLink.1.20 = 21303010300120101002
# Cunning
AiPlayerbot.PremadeHunterPetLink.2.16 = 2100020330000211001
AiPlayerbot.PremadeHunterPetLink.2.20 = 21000203300002110221

#
#
Expand Down Expand Up @@ -965,7 +980,7 @@ AiPlayerbot.PremadeSpecLink.9.0.70 = 2350022001113510053500131151--55
AiPlayerbot.PremadeSpecLink.9.0.80 = 2350022001113510253500331151--5500000501
AiPlayerbot.PremadeSpecName.9.1 = emo pve
AiPlayerbot.PremadeSpecGlyph.9.1 = 45785,43390,50077,43394,43393,42459
AiPlayerbot.PremadeSpecLink.9.1.60 = -003203301135112530131201-55
AiPlayerbot.PremadeSpecLink.9.1.60 = -003203301135112530135201051
AiPlayerbot.PremadeSpecLink.9.1.70 = -003203301135112530135201051-55
AiPlayerbot.PremadeSpecLink.9.1.80 = -003203301135112530135221351-55000005
AiPlayerbot.PremadeSpecName.9.2 = destro pve
Expand Down Expand Up @@ -1165,11 +1180,11 @@ AiPlayerbot.RandomClassSpecIndex.8.2 = 2
#
#

AiPlayerbot.RandomClassSpecProb.9.0 = 40
AiPlayerbot.RandomClassSpecProb.9.0 = 45
AiPlayerbot.RandomClassSpecIndex.9.0 = 0
AiPlayerbot.RandomClassSpecProb.9.1 = 40
AiPlayerbot.RandomClassSpecProb.9.1 = 45
AiPlayerbot.RandomClassSpecIndex.9.1 = 1
AiPlayerbot.RandomClassSpecProb.9.2 = 20
AiPlayerbot.RandomClassSpecProb.9.2 = 10
AiPlayerbot.RandomClassSpecIndex.9.2 = 2

#
Expand Down
11 changes: 5 additions & 6 deletions src/PlayerbotAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5257,6 +5257,7 @@ bool PlayerbotAI::EqualLowercaseName(std::string s1, std::string s2)
return true;
}

// A custom CanEquipItem (remove AutoUnequipOffhand in FindEquipSlot to prevent unequip on `item usage` calculation)
InventoryResult PlayerbotAI::CanEquipItem(uint8 slot, uint16& dest, Item* pItem, bool swap, bool not_loading) const
{
dest = 0;
Expand All @@ -5277,11 +5278,9 @@ InventoryResult PlayerbotAI::CanEquipItem(uint8 slot, uint16& dest, Item* pItem,
if (pItem->IsBindedNotWith(bot))
return EQUIP_ERR_DONT_OWN_THAT_ITEM;

// Yunfan: skip it
// // check count of items (skip for auto move for same player from bank)
// InventoryResult res = bot->CanTakeMoreSimilarItems(pItem);
// if (res != EQUIP_ERR_OK)
// return res;
InventoryResult res = bot->CanTakeMoreSimilarItems(pItem);
if (res != EQUIP_ERR_OK)
return res;

ScalingStatDistributionEntry const* ssd =
pProto->ScalingStatDistribution
Expand All @@ -5300,7 +5299,7 @@ InventoryResult PlayerbotAI::CanEquipItem(uint8 slot, uint16& dest, Item* pItem,
if (!bot->CanUseAttackType(bot->GetAttackBySlot(eslot)))
return EQUIP_ERR_NOT_WHILE_DISARMED;

InventoryResult res = bot->CanUseItem(pItem, not_loading);
res = bot->CanUseItem(pItem, not_loading);
if (res != EQUIP_ERR_OK)
return res;

Expand Down
62 changes: 59 additions & 3 deletions src/PlayerbotAIConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,17 @@ bool PlayerbotAIConfig::Initialize()
parsedSpecLinkOrder[cls][spec][level] = ParseTempTalentsOrder(cls, premadeSpecLink[cls][spec][level]);
}
}
for (uint32 spec = 0; spec < 3; ++spec)
{
for (uint32 points = 0; points < 21; ++points)
{
std::ostringstream os;
os << "AiPlayerbot.PremadeHunterPetLink." << spec << "." << points;
premadeHunterPetLink[spec][points] = sConfigMgr->GetOption<std::string>(os.str().c_str(), "", false);
parsedHunterPetLinkOrder[spec][points] =
ParseTempPetTalentsOrder(spec, premadeHunterPetLink[spec][points]);
}
}
for (uint32 spec = 0; spec < MAX_SPECNO; ++spec)
{
std::ostringstream os;
Expand Down Expand Up @@ -460,6 +471,7 @@ bool PlayerbotAIConfig::Initialize()
autoPickReward = sConfigMgr->GetOption<std::string>("AiPlayerbot.AutoPickReward", "yes");
autoEquipUpgradeLoot = sConfigMgr->GetOption<bool>("AiPlayerbot.AutoEquipUpgradeLoot", true);
equipUpgradeThreshold = sConfigMgr->GetOption<float>("AiPlayerbot.EquipUpgradeThreshold", 1.1f);
twoRoundsGearInit = sConfigMgr->GetOption<bool>("AiPlayerbot.TwoRoundsGearInit", false);
syncQuestWithPlayer = sConfigMgr->GetOption<bool>("AiPlayerbot.SyncQuestWithPlayer", true);
syncQuestForPlayer = sConfigMgr->GetOption<bool>("AiPlayerbot.SyncQuestForPlayer", false);
autoTrainSpells = sConfigMgr->GetOption<std::string>("AiPlayerbot.AutoTrainSpells", "yes");
Expand All @@ -484,13 +496,13 @@ bool PlayerbotAIConfig::Initialize()
selfBotLevel = sConfigMgr->GetOption<int32>("AiPlayerbot.SelfBotLevel", 1);

RandomPlayerbotFactory::CreateRandomBots();
if (sPlayerbotAIConfig->addClassCommand)
sRandomPlayerbotMgr->PrepareAddclassCache();

if (World::IsStopped())
{
return true;
}
if (sPlayerbotAIConfig->addClassCommand)
sRandomPlayerbotMgr->PrepareAddclassCache();

sRandomItemMgr->Init();
sRandomItemMgr->InitAfterAhBot();
sPlayerbotTextMgr->LoadBotTexts();
Expand Down Expand Up @@ -760,3 +772,47 @@ std::vector<std::vector<uint32>> PlayerbotAIConfig::ParseTempTalentsOrder(uint32
}
return res;
}

std::vector<std::vector<uint32>> PlayerbotAIConfig::ParseTempPetTalentsOrder(uint32 spec, std::string tab_link)
{
// check bad link
// uint32 classMask = 1 << (cls - 1);
std::vector<TalentEntry const*> spells;
std::vector<std::vector<uint32>> orders;
for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
{
TalentEntry const* talentInfo = sTalentStore.LookupEntry(i);
if (!talentInfo)
continue;

TalentTabEntry const* talentTabInfo = sTalentTabStore.LookupEntry(talentInfo->TalentTab);
if (!talentTabInfo)
continue;

if (!((1 << spec) & talentTabInfo->petTalentMask))
continue;
// skip some duplicate spells like dash/dive
if (talentInfo->TalentID == 2201 || talentInfo->TalentID == 2208 || talentInfo->TalentID == 2219 || talentInfo->TalentID == 2203)
continue;

spells.push_back(talentInfo);
}
std::sort(spells.begin(), spells.end(),
[&](TalentEntry const* lhs, TalentEntry const* rhs)
{ return lhs->Row != rhs->Row ? lhs->Row < rhs->Row : lhs->Col < rhs->Col; });
for (int i = 0; i < tab_link.size(); i++)
{
if (i >= spells.size())
{
break;
}
int lvl = tab_link[i] - '0';
if (lvl == 0)
continue;
orders.push_back({spells[i]->Row, spells[i]->Col, (uint32)lvl});
}
// sort by talent tab size
std::sort(orders.begin(), orders.end(), [&](auto& lhs, auto& rhs) { return lhs.size() > rhs.size(); });

return orders;
}
4 changes: 4 additions & 0 deletions src/PlayerbotAIConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ class PlayerbotAIConfig
std::string premadeSpecGlyph[MAX_CLASSES][MAX_SPECNO];
std::vector<uint32> parsedSpecGlyph[MAX_CLASSES][MAX_SPECNO];
std::string premadeSpecLink[MAX_CLASSES][MAX_SPECNO][MAX_LEVEL];
std::string premadeHunterPetLink[3][21];
std::vector<std::vector<uint32>> parsedSpecLinkOrder[MAX_CLASSES][MAX_SPECNO][MAX_LEVEL];
std::vector<std::vector<uint32>> parsedHunterPetLinkOrder[3][21];
uint32 randomClassSpecProb[MAX_CLASSES][MAX_SPECNO];
uint32 randomClassSpecIndex[MAX_CLASSES][MAX_SPECNO];

Expand Down Expand Up @@ -269,6 +271,7 @@ class PlayerbotAIConfig
std::string autoPickReward;
bool autoEquipUpgradeLoot;
float equipUpgradeThreshold;
bool twoRoundsGearInit;
bool syncQuestWithPlayer;
bool syncQuestForPlayer;
std::string autoTrainSpells;
Expand Down Expand Up @@ -325,6 +328,7 @@ class PlayerbotAIConfig

void loadWorldBuf(uint32 factionId, uint32 classId, uint32 minLevel, uint32 maxLevel);
static std::vector<std::vector<uint32>> ParseTempTalentsOrder(uint32 cls, std::string temp_talents_order);
static std::vector<std::vector<uint32>> ParseTempPetTalentsOrder(uint32 spec, std::string temp_talents_order);
};

#define sPlayerbotAIConfig PlayerbotAIConfig::instance()
Expand Down
36 changes: 34 additions & 2 deletions src/PlayerbotMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,14 +724,14 @@ std::string const PlayerbotHolder::ProcessBotCommand(std::string const cmd, Obje
sPlayerbotAIConfig->autoInitEquipLevelLimitRatio;
PlayerbotFactory factory(bot, master->GetLevel(), ITEM_QUALITY_LEGENDARY, mixedGearScore);
factory.Randomize(false);
return "ok, gear score limit: " + std::to_string(mixedGearScore / (ITEM_QUALITY_EPIC + 1)) +
return "ok, gear score limit: " + std::to_string(mixedGearScore / PlayerbotAI::GetItemScoreMultiplier(ItemQualities(ITEM_QUALITY_EPIC))) +
"(for epic)";
}
else if (cmd.starts_with("init=") && sscanf(cmd.c_str(), "init=%d", &gs) != -1)
{
PlayerbotFactory factory(bot, master->GetLevel(), ITEM_QUALITY_LEGENDARY, gs);
factory.Randomize(false);
return "ok, gear score limit: " + std::to_string(gs / (ITEM_QUALITY_EPIC + 1)) + "(for epic)";
return "ok, gear score limit: " + std::to_string(gs / PlayerbotAI::GetItemScoreMultiplier(ItemQualities(ITEM_QUALITY_EPIC))) + "(for epic)";
}
}

Expand Down Expand Up @@ -845,6 +845,22 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg

if (!strncmp(cmd, "initself=", 9))
{
if (!strcmp(cmd, "initself=uncommon"))
{
if (master->GetSession()->GetSecurity() >= SEC_GAMEMASTER)
{
// OnBotLogin(master);
PlayerbotFactory factory(master, master->GetLevel(), ITEM_QUALITY_UNCOMMON);
factory.Randomize(false);
messages.push_back("initself ok");
return messages;
}
else
{
messages.push_back("ERROR: Only GM can use this command.");
return messages;
}
}
if (!strcmp(cmd, "initself=rare"))
{
if (master->GetSession()->GetSecurity() >= SEC_GAMEMASTER)
Expand Down Expand Up @@ -877,6 +893,22 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
return messages;
}
}
if (!strcmp(cmd, "initself=legendary"))
{
if (master->GetSession()->GetSecurity() >= SEC_GAMEMASTER)
{
// OnBotLogin(master);
PlayerbotFactory factory(master, master->GetLevel(), ITEM_QUALITY_LEGENDARY);
factory.Randomize(false);
messages.push_back("initself ok");
return messages;
}
else
{
messages.push_back("ERROR: Only GM can use this command.");
return messages;
}
}
int32 gs;
if (sscanf(cmd, "initself=%d", &gs) != -1)
{
Expand Down
5 changes: 4 additions & 1 deletion src/RandomPlayerbotMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ void RandomPlayerbotMgr::UpdateAIInternal(uint32 elapsed, bool /*minimal*/)
break;
}

if (loginBots)
if (loginBots && botLoading.empty())
{
loginBots += updateBots;
loginBots = std::min(loginBots, maxNewBots);
Expand Down Expand Up @@ -1041,6 +1041,9 @@ bool RandomPlayerbotMgr::ProcessBot(uint32 bot)

SetEventValue(bot, "login", 0, 0);

if (!player->IsInWorld())
return false;

if (player->GetGroup() || player->HasUnitState(UNIT_STATE_IN_FLIGHT))
return false;

Expand Down
Loading

0 comments on commit ef2c0cd

Please sign in to comment.