From c21b534e473cf472911c4970a08317ff52cb8c0b Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Fri, 14 Jul 2023 14:46:02 +0800 Subject: [PATCH] fix equip replace bug --- src/PlayerbotFactory.cpp | 12 ++++++------ src/PlayerbotFactory.h | 8 ++++---- src/strategy/actions/UseMeetingStoneAction.cpp | 1 + src/strategy/values/ItemUsageValue.cpp | 14 +++++++++----- src/strategy/values/LootStrategyValue.h | 2 +- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/PlayerbotFactory.cpp b/src/PlayerbotFactory.cpp index e823e8e4..f8bc4c21 100644 --- a/src/PlayerbotFactory.cpp +++ b/src/PlayerbotFactory.cpp @@ -1271,7 +1271,7 @@ void PlayerbotFactory::InitEquipment(bool incremental) if (!CanEquipUnseenItem(slot, dest, newItemId)) continue; - float cur_score = CalculateItemScore(newItemId); + float cur_score = CalculateItemScore(newItemId, bot); if (cur_score > bestScoreForSlot) { bestScoreForSlot = cur_score; bestItemForSlot = newItemId; @@ -2866,7 +2866,7 @@ void PlayerbotFactory::LoadEnchantContainer() } } -float PlayerbotFactory::CalculateItemScore(uint32 item_id) +float PlayerbotFactory::CalculateItemScore(uint32 item_id, Player* bot) { float score = 0; int tab = AiFactory::GetPlayerSpecTab(bot); @@ -2989,7 +2989,7 @@ float PlayerbotFactory::CalculateItemScore(uint32 item_id) + defense * 0.25 + dodge * 0.25 + armor * 0.5 + stamina * 1.5 + hit * 1 + crit * 1 + haste * 0.5 + expertise * 3; } - if (proto->Class == ITEM_CLASS_ARMOR && NotSameArmorType(proto->SubClass)) + if (proto->Class == ITEM_CLASS_ARMOR && NotSameArmorType(proto->SubClass, bot)) { score *= 0.8; } @@ -3008,7 +3008,7 @@ float PlayerbotFactory::CalculateItemScore(uint32 item_id) (cls == CLASS_ROGUE) || (cls == CLASS_DEATH_KNIGHT && tab == 1) || (cls == CLASS_WARRIOR && tab == 1 && !bot->HasSpell(46917)) || - IsShieldTank())) { + IsShieldTank(bot))) { score *= 0.1; } // spec with double hand @@ -3026,13 +3026,13 @@ float PlayerbotFactory::CalculateItemScore(uint32 item_id) // return score; } -bool PlayerbotFactory::IsShieldTank() +bool PlayerbotFactory::IsShieldTank(Player* bot) { int tab = AiFactory::GetPlayerSpecTab(bot); return (bot->getClass() == CLASS_WARRIOR && tab == 2) || (bot->getClass() == CLASS_PALADIN && tab == 1); } -bool PlayerbotFactory::NotSameArmorType(uint32 item_subclass_armor) +bool PlayerbotFactory::NotSameArmorType(uint32 item_subclass_armor, Player* bot) { if (bot->HasSkill(SKILL_PLATE_MAIL)) { return item_subclass_armor != ITEM_SUBCLASS_ARMOR_PLATE; diff --git a/src/PlayerbotFactory.h b/src/PlayerbotFactory.h index 804e91c8..9418b85a 100644 --- a/src/PlayerbotFactory.h +++ b/src/PlayerbotFactory.h @@ -114,6 +114,7 @@ class PlayerbotFactory : public InventoryAction void InitSkills(); static uint32 tradeSkills[]; + static float CalculateItemScore(uint32 item_id, Player* bot); private: void Prepare(); @@ -164,10 +165,9 @@ class PlayerbotFactory : public InventoryAction static void AddPrevQuests(uint32 questId, std::list& questIds); void LoadEnchantContainer(); void ApplyEnchantTemplate(); - void ApplyEnchantTemplate(uint8 spec); - float CalculateItemScore(uint32 item_id); - bool IsShieldTank(); - bool NotSameArmorType(uint32 item_subclass_armor); + void ApplyEnchantTemplate(uint8 spec); + static bool IsShieldTank(Player* bot); + static bool NotSameArmorType(uint32 item_subclass_armor, Player* bot); EnchantContainer::const_iterator GetEnchantContainerBegin() { return m_EnchantContainer.begin(); } EnchantContainer::const_iterator GetEnchantContainerEnd() { return m_EnchantContainer.end(); } diff --git a/src/strategy/actions/UseMeetingStoneAction.cpp b/src/strategy/actions/UseMeetingStoneAction.cpp index ef9b82d7..5406e93e 100644 --- a/src/strategy/actions/UseMeetingStoneAction.cpp +++ b/src/strategy/actions/UseMeetingStoneAction.cpp @@ -169,6 +169,7 @@ bool SummonAction::Teleport(Player* summoner, Player* player) if (bot->isDead() && botAI->GetMaster()->IsAlive()) { bot->ResurrectPlayer(1.0f, false); + bot->DurabilityRepairAll(false, 1.0f, false); botAI->TellMasterNoFacing("I live, again!"); } diff --git a/src/strategy/values/ItemUsageValue.cpp b/src/strategy/values/ItemUsageValue.cpp index 92cac572..c569c82f 100644 --- a/src/strategy/values/ItemUsageValue.cpp +++ b/src/strategy/values/ItemUsageValue.cpp @@ -3,8 +3,10 @@ */ #include "ItemUsageValue.h" +#include "AiFactory.h" #include "ChatHelper.h" #include "GuildTaskMgr.h" +#include "PlayerbotFactory.h" #include "Playerbots.h" #include "RandomItemMgr.h" #include "ServerFacade.h" @@ -180,8 +182,9 @@ ItemUsage ItemUsageValue::QueryItemUsageForEquip(ItemTemplate const* itemProto) } bool shouldEquip = false; - uint32 statWeight = sRandomItemMgr->GetLiveStatWeight(bot, itemProto->ItemId); - if (statWeight) + // uint32 statWeight = sRandomItemMgr->GetLiveStatWeight(bot, itemProto->ItemId); + float itemScore = PlayerbotFactory::CalculateItemScore(itemProto->ItemId, bot); + if (itemScore) shouldEquip = true; if (itemProto->Class == ITEM_CLASS_WEAPON && !sRandomItemMgr->CanEquipWeapon(bot->getClass(), itemProto)) @@ -201,10 +204,11 @@ ItemUsage ItemUsageValue::QueryItemUsageForEquip(ItemTemplate const* itemProto) ItemTemplate const* oldItemProto = oldItem->GetTemplate(); if (oldItem) { - uint32 oldStatWeight = sRandomItemMgr->GetLiveStatWeight(bot, oldItemProto->ItemId); - if (statWeight || oldStatWeight) + // uint32 oldStatWeight = sRandomItemMgr->GetLiveStatWeight(bot, oldItemProto->ItemId); + float oldScore = PlayerbotFactory::CalculateItemScore(oldItemProto->ItemId, bot); + if (itemScore || oldScore) { - shouldEquip = statWeight >= oldStatWeight; + shouldEquip = itemScore >= oldScore * 1.2; } } diff --git a/src/strategy/values/LootStrategyValue.h b/src/strategy/values/LootStrategyValue.h index 93ae94b1..0788eab5 100644 --- a/src/strategy/values/LootStrategyValue.h +++ b/src/strategy/values/LootStrategyValue.h @@ -13,7 +13,7 @@ class PlayerbotAI; class LootStrategyValue : public ManualSetValue { public: - LootStrategyValue(PlayerbotAI* botAI, std::string const name = "loot strategy") : ManualSetValue(botAI, normal, name) { } + LootStrategyValue(PlayerbotAI* botAI, std::string const name = "loot strategy") : ManualSetValue(botAI, all, name) { } virtual ~LootStrategyValue(); std::string const Save() override;