From ac6f7a1e98cef258b3ebb25ca1a7da7b323cd70f Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Thu, 5 Oct 2023 00:59:08 +0800 Subject: [PATCH] init=auto --- src/AiFactory.cpp | 14 +-- src/PlayerbotAI.cpp | 88 ++++++++++++++++++- src/PlayerbotAI.h | 3 +- src/PlayerbotFactory.cpp | 14 ++- src/PlayerbotFactory.h | 5 +- src/PlayerbotMgr.cpp | 7 ++ .../actions/CheckMountStateAction.cpp | 12 +-- 7 files changed, 122 insertions(+), 21 deletions(-) diff --git a/src/AiFactory.cpp b/src/AiFactory.cpp index a6674b70..53d8f564 100644 --- a/src/AiFactory.cpp +++ b/src/AiFactory.cpp @@ -581,13 +581,13 @@ void AiFactory::AddDefaultNonCombatStrategies(Player* player, PlayerbotAI* const // nonCombatEngine->addStrategy("group"); // nonCombatEngine->addStrategy("guild"); - if (sPlayerbotAIConfig->autoDoQuests) - { - // nonCombatEngine->addStrategy("travel"); - nonCombatEngine->addStrategy("rpg"); - } else { - nonCombatEngine->addStrategy("move random"); - } + // if (sPlayerbotAIConfig->autoDoQuests) + // { + // // nonCombatEngine->addStrategy("travel"); + // nonCombatEngine->addStrategy("rpg"); + // } else { + // nonCombatEngine->addStrategy("move random"); + // } // if (masterBotAI) // nonCombatEngine->addStrategy("maintenance"); diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index 347c4d52..aa2d4d50 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -3514,7 +3514,91 @@ uint32 PlayerbotAI::GetEquipGearScore(Player* player, bool withBags, bool withBa return 0; } -void PlayerbotAI::_fillGearScoreData(Player* player, Item* item, std::vector* gearScore, uint32& twoHandScore) +uint32 PlayerbotAI::GetMixedGearScore(Player* player, bool withBags, bool withBank) +{ + std::vector 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* gearScore, uint32& twoHandScore, bool mixed) { if (!item) return; @@ -3524,7 +3608,7 @@ void PlayerbotAI::_fillGearScoreData(Player* player, Item* item, std::vectorInventoryType; - uint32 level = proto->ItemLevel; + uint32 level = mixed ? proto->ItemLevel * (1 + proto->Quality) : proto->ItemLevel; switch (type) { diff --git a/src/PlayerbotAI.h b/src/PlayerbotAI.h index 67455fdb..7bdaadaa 100644 --- a/src/PlayerbotAI.h +++ b/src/PlayerbotAI.h @@ -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); uint32 GetEquipGearScore(Player* player, bool withBags, bool withBank); + static uint32 GetMixedGearScore(Player* player, bool withBags, bool withBank); bool HasSkill(SkillType skill); bool IsAllowedCommand(std::string const text); float GetRange(std::string const type); @@ -447,7 +448,7 @@ class PlayerbotAI : public PlayerbotAIBase static std::vector dispel_whitelist; bool EqualLowercaseName(std::string s1, std::string s2); private: - void _fillGearScoreData(Player* player, Item* item, std::vector* gearScore, uint32& twoHandScore); + static void _fillGearScoreData(Player* player, Item* item, std::vector* gearScore, uint32& twoHandScore, bool mixed = false); bool IsTellAllowed(PlayerbotSecurityLevel securityLevel = PLAYERBOT_SECURITY_ALLOW_ALL); protected: Player* bot; diff --git a/src/PlayerbotFactory.cpp b/src/PlayerbotFactory.cpp index 8a8becd4..cba06a8f 100644 --- a/src/PlayerbotFactory.cpp +++ b/src/PlayerbotFactory.cpp @@ -52,7 +52,7 @@ uint32 PlayerbotFactory::tradeSkills[] = std::list PlayerbotFactory::classQuestIds; std::list 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) 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; if (proto->Class == ITEM_CLASS_CONTAINER) @@ -1200,7 +1200,10 @@ void PlayerbotFactory::InitEquipment(bool incremental) ItemTemplate const* proto = sObjectMgr->GetItemTemplate(itemId); if (!proto) continue; - + + if (gearScoreLimit != 0 && CalcMixedGearScore(proto->ItemLevel, proto->Quality) > gearScoreLimit) { + continue; + } if (proto->Class != ITEM_CLASS_WEAPON && proto->Class != ITEM_CLASS_ARMOR) continue; @@ -2253,6 +2256,11 @@ void PlayerbotFactory::InitAmmo() bot->SetAmmo(entry); } +uint32 PlayerbotFactory::CalcMixedGearScore(uint32 gs, uint32 quality) +{ + return gs * (quality + 1); +} + void PlayerbotFactory::InitMounts() { uint32 firstmount = 20; diff --git a/src/PlayerbotFactory.h b/src/PlayerbotFactory.h index 3c8f010f..e699c3ab 100644 --- a/src/PlayerbotFactory.h +++ b/src/PlayerbotFactory.h @@ -103,7 +103,7 @@ enum PriorizedConsumables class PlayerbotFactory : public InventoryAction { public: - PlayerbotFactory(Player* bot, uint32 level, uint32 itemQuality = 0); + PlayerbotFactory(Player* bot, uint32 level, uint32 itemQuality = 0, uint32 gearScoreLimit = 0); static ObjectGuid GetRandomBot(); static void Init(); @@ -121,7 +121,7 @@ class PlayerbotFactory : public InventoryAction void InitEquipment(bool incremental); void InitPet(); void InitAmmo(); - + static uint32 CalcMixedGearScore(uint32 gs, uint32 quality); private: void Prepare(); // void InitSecondEquipmentSet(); @@ -175,6 +175,7 @@ class PlayerbotFactory : public InventoryAction EnchantContainer::const_iterator GetEnchantContainerEnd() { return m_EnchantContainer.end(); } uint32 level; uint32 itemQuality; + uint32 gearScoreLimit; static std::list specialQuestIds; std::vector trainerIdCache; protected: diff --git a/src/PlayerbotMgr.cpp b/src/PlayerbotMgr.cpp index 2902927a..b88e9ddf 100644 --- a/src/PlayerbotMgr.cpp +++ b/src/PlayerbotMgr.cpp @@ -571,6 +571,13 @@ std::string const PlayerbotHolder::ProcessBotCommand(std::string const cmd, Obje factory.Randomize(false); 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") diff --git a/src/strategy/actions/CheckMountStateAction.cpp b/src/strategy/actions/CheckMountStateAction.cpp index fdc22d26..a4f7ef9c 100644 --- a/src/strategy/actions/CheckMountStateAction.cpp +++ b/src/strategy/actions/CheckMountStateAction.cpp @@ -160,12 +160,12 @@ bool CheckMountStateAction::Mount() { uint32 secondmount = 40; - // if (bot->isMoving()) - // { - // bot->StopMoving(); - // bot->GetMotionMaster()->Clear(); - // // bot->GetMotionMaster()->MoveIdle(); - // } + if (bot->isMoving()) + { + bot->StopMoving(); + // bot->GetMotionMaster()->Clear(); + // bot->GetMotionMaster()->MoveIdle(); + } Player* master = GetMaster(); botAI->RemoveShapeshift();