init=auto

This commit is contained in:
Yunfan Li
2023-10-05 00:59:08 +08:00
parent 4672b3edcf
commit ac6f7a1e98
7 changed files with 122 additions and 21 deletions

View File

@@ -581,13 +581,13 @@ void AiFactory::AddDefaultNonCombatStrategies(Player* player, PlayerbotAI* const
// nonCombatEngine->addStrategy("group"); // nonCombatEngine->addStrategy("group");
// nonCombatEngine->addStrategy("guild"); // nonCombatEngine->addStrategy("guild");
if (sPlayerbotAIConfig->autoDoQuests) // if (sPlayerbotAIConfig->autoDoQuests)
{ // {
// nonCombatEngine->addStrategy("travel"); // // nonCombatEngine->addStrategy("travel");
nonCombatEngine->addStrategy("rpg"); // nonCombatEngine->addStrategy("rpg");
} else { // } else {
nonCombatEngine->addStrategy("move random"); // nonCombatEngine->addStrategy("move random");
} // }
// if (masterBotAI) // if (masterBotAI)
// nonCombatEngine->addStrategy("maintenance"); // nonCombatEngine->addStrategy("maintenance");

View File

@@ -3514,7 +3514,91 @@ uint32 PlayerbotAI::GetEquipGearScore(Player* player, bool withBags, bool withBa
return 0; return 0;
} }
void PlayerbotAI::_fillGearScoreData(Player* player, Item* item, std::vector<uint32>* gearScore, uint32& twoHandScore) uint32 PlayerbotAI::GetMixedGearScore(Player* player, bool withBags, bool withBank)
{
std::vector<uint32> gearScore(EQUIPMENT_SLOT_END);
uint32 twoHandScore = 0;
for (uint8 i = EQUIPMENT_SLOT_START; i < EQUIPMENT_SLOT_END; ++i)
{
if (Item* item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
_fillGearScoreData(player, item, &gearScore, twoHandScore, true);
}
if (withBags)
{
// check inventory
for (uint8 i = INVENTORY_SLOT_ITEM_START; i < INVENTORY_SLOT_ITEM_END; ++i)
{
if (Item* item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
_fillGearScoreData(player, item, &gearScore, twoHandScore, true);
}
// check bags
for (uint8 i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; ++i)
{
if (Bag* pBag = (Bag*)player->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
{
for (uint32 j = 0; j < pBag->GetBagSize(); ++j)
{
if (Item* item2 = pBag->GetItemByPos(j))
_fillGearScoreData(player, item2, &gearScore, twoHandScore, true);
}
}
}
}
if (withBank)
{
for (uint8 i = BANK_SLOT_ITEM_START; i < BANK_SLOT_ITEM_END; ++i)
{
if (Item* item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
_fillGearScoreData(player, item, &gearScore, twoHandScore, true);
}
for (uint8 i = BANK_SLOT_BAG_START; i < BANK_SLOT_BAG_END; ++i)
{
if (Item* item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
{
if (item->IsBag())
{
Bag* bag = (Bag*)item;
for (uint8 j = 0; j < bag->GetBagSize(); ++j)
{
if (Item* item2 = bag->GetItemByPos(j))
_fillGearScoreData(player, item2, &gearScore, twoHandScore, true);
}
}
}
}
}
uint8 count = EQUIPMENT_SLOT_END - 2; // ignore body and tabard slots
uint32 sum = 0;
// check if 2h hand is higher level than main hand + off hand
if (gearScore[EQUIPMENT_SLOT_MAINHAND] + gearScore[EQUIPMENT_SLOT_OFFHAND] < twoHandScore * 2)
{
gearScore[EQUIPMENT_SLOT_OFFHAND] = 0; // off hand is ignored in calculations if 2h weapon has higher score
--count;
gearScore[EQUIPMENT_SLOT_MAINHAND] = twoHandScore;
}
for (uint8 i = EQUIPMENT_SLOT_START; i < EQUIPMENT_SLOT_END; ++i)
{
sum += gearScore[i];
}
if (count)
{
uint32 res = uint32(sum / count);
return res;
}
return 0;
}
void PlayerbotAI::_fillGearScoreData(Player* player, Item* item, std::vector<uint32>* gearScore, uint32& twoHandScore, bool mixed)
{ {
if (!item) if (!item)
return; return;
@@ -3524,7 +3608,7 @@ void PlayerbotAI::_fillGearScoreData(Player* player, Item* item, std::vector<uin
return; return;
uint8 type = proto->InventoryType; uint8 type = proto->InventoryType;
uint32 level = proto->ItemLevel; uint32 level = mixed ? proto->ItemLevel * (1 + proto->Quality) : proto->ItemLevel;
switch (type) switch (type)
{ {

View File

@@ -400,6 +400,7 @@ class PlayerbotAI : public PlayerbotAIBase
bool IsInVehicle(bool canControl = false, bool canCast = false, bool canAttack = false, bool canTurn = false, bool fixed = false); bool IsInVehicle(bool canControl = false, bool canCast = false, bool canAttack = false, bool canTurn = false, bool fixed = false);
uint32 GetEquipGearScore(Player* player, bool withBags, bool withBank); uint32 GetEquipGearScore(Player* player, bool withBags, bool withBank);
static uint32 GetMixedGearScore(Player* player, bool withBags, bool withBank);
bool HasSkill(SkillType skill); bool HasSkill(SkillType skill);
bool IsAllowedCommand(std::string const text); bool IsAllowedCommand(std::string const text);
float GetRange(std::string const type); float GetRange(std::string const type);
@@ -447,7 +448,7 @@ class PlayerbotAI : public PlayerbotAIBase
static std::vector<std::string> dispel_whitelist; static std::vector<std::string> dispel_whitelist;
bool EqualLowercaseName(std::string s1, std::string s2); bool EqualLowercaseName(std::string s1, std::string s2);
private: private:
void _fillGearScoreData(Player* player, Item* item, std::vector<uint32>* gearScore, uint32& twoHandScore); static void _fillGearScoreData(Player* player, Item* item, std::vector<uint32>* gearScore, uint32& twoHandScore, bool mixed = false);
bool IsTellAllowed(PlayerbotSecurityLevel securityLevel = PLAYERBOT_SECURITY_ALLOW_ALL); bool IsTellAllowed(PlayerbotSecurityLevel securityLevel = PLAYERBOT_SECURITY_ALLOW_ALL);
protected: protected:
Player* bot; Player* bot;

View File

@@ -52,7 +52,7 @@ uint32 PlayerbotFactory::tradeSkills[] =
std::list<uint32> PlayerbotFactory::classQuestIds; std::list<uint32> PlayerbotFactory::classQuestIds;
std::list<uint32> PlayerbotFactory::specialQuestIds; std::list<uint32> PlayerbotFactory::specialQuestIds;
PlayerbotFactory::PlayerbotFactory(Player* bot, uint32 level, uint32 itemQuality) : level(level), itemQuality(itemQuality), InventoryAction(GET_PLAYERBOT_AI(bot), "factory") PlayerbotFactory::PlayerbotFactory(Player* bot, uint32 level, uint32 itemQuality, uint32 gearScoreLimit) : level(level), itemQuality(itemQuality), gearScoreLimit(gearScoreLimit), InventoryAction(GET_PLAYERBOT_AI(bot), "factory")
{ {
} }
@@ -984,7 +984,7 @@ bool PlayerbotFactory::CanEquipItem(ItemTemplate const* proto, uint32 desiredQua
if (proto->Quality != desiredQuality) if (proto->Quality != desiredQuality)
return false; return false;
if (proto->Bonding == BIND_QUEST_ITEM || proto->Bonding == BIND_WHEN_USE) if (proto->Bonding == BIND_QUEST_ITEM /*|| proto->Bonding == BIND_WHEN_USE*/)
return false; return false;
if (proto->Class == ITEM_CLASS_CONTAINER) if (proto->Class == ITEM_CLASS_CONTAINER)
@@ -1200,7 +1200,10 @@ void PlayerbotFactory::InitEquipment(bool incremental)
ItemTemplate const* proto = sObjectMgr->GetItemTemplate(itemId); ItemTemplate const* proto = sObjectMgr->GetItemTemplate(itemId);
if (!proto) if (!proto)
continue; continue;
if (gearScoreLimit != 0 && CalcMixedGearScore(proto->ItemLevel, proto->Quality) > gearScoreLimit) {
continue;
}
if (proto->Class != ITEM_CLASS_WEAPON && if (proto->Class != ITEM_CLASS_WEAPON &&
proto->Class != ITEM_CLASS_ARMOR) proto->Class != ITEM_CLASS_ARMOR)
continue; continue;
@@ -2253,6 +2256,11 @@ void PlayerbotFactory::InitAmmo()
bot->SetAmmo(entry); bot->SetAmmo(entry);
} }
uint32 PlayerbotFactory::CalcMixedGearScore(uint32 gs, uint32 quality)
{
return gs * (quality + 1);
}
void PlayerbotFactory::InitMounts() void PlayerbotFactory::InitMounts()
{ {
uint32 firstmount = 20; uint32 firstmount = 20;

View File

@@ -103,7 +103,7 @@ enum PriorizedConsumables
class PlayerbotFactory : public InventoryAction class PlayerbotFactory : public InventoryAction
{ {
public: public:
PlayerbotFactory(Player* bot, uint32 level, uint32 itemQuality = 0); PlayerbotFactory(Player* bot, uint32 level, uint32 itemQuality = 0, uint32 gearScoreLimit = 0);
static ObjectGuid GetRandomBot(); static ObjectGuid GetRandomBot();
static void Init(); static void Init();
@@ -121,7 +121,7 @@ class PlayerbotFactory : public InventoryAction
void InitEquipment(bool incremental); void InitEquipment(bool incremental);
void InitPet(); void InitPet();
void InitAmmo(); void InitAmmo();
static uint32 CalcMixedGearScore(uint32 gs, uint32 quality);
private: private:
void Prepare(); void Prepare();
// void InitSecondEquipmentSet(); // void InitSecondEquipmentSet();
@@ -175,6 +175,7 @@ class PlayerbotFactory : public InventoryAction
EnchantContainer::const_iterator GetEnchantContainerEnd() { return m_EnchantContainer.end(); } EnchantContainer::const_iterator GetEnchantContainerEnd() { return m_EnchantContainer.end(); }
uint32 level; uint32 level;
uint32 itemQuality; uint32 itemQuality;
uint32 gearScoreLimit;
static std::list<uint32> specialQuestIds; static std::list<uint32> specialQuestIds;
std::vector<uint32> trainerIdCache; std::vector<uint32> trainerIdCache;
protected: protected:

View File

@@ -571,6 +571,13 @@ std::string const PlayerbotHolder::ProcessBotCommand(std::string const cmd, Obje
factory.Randomize(false); factory.Randomize(false);
return "ok"; return "ok";
} }
else if (cmd == "init=auto")
{
uint32 mixedGearScore = PlayerbotAI::GetMixedGearScore(master, true, true) * 1.1f;
PlayerbotFactory factory(bot, master->getLevel(), ITEM_QUALITY_LEGENDARY, mixedGearScore);
factory.Randomize(false);
return "ok, gear score limit: " + std::to_string(mixedGearScore);
}
} }
if (cmd == "levelup" || cmd == "level") if (cmd == "levelup" || cmd == "level")

View File

@@ -160,12 +160,12 @@ bool CheckMountStateAction::Mount()
{ {
uint32 secondmount = 40; uint32 secondmount = 40;
// if (bot->isMoving()) if (bot->isMoving())
// { {
// bot->StopMoving(); bot->StopMoving();
// bot->GetMotionMaster()->Clear(); // bot->GetMotionMaster()->Clear();
// // bot->GetMotionMaster()->MoveIdle(); // bot->GetMotionMaster()->MoveIdle();
// } }
Player* master = GetMaster(); Player* master = GetMaster();
botAI->RemoveShapeshift(); botAI->RemoveShapeshift();