From 481c2494bbc6b5b7be2c7df9f6c8c62b7a0c90b8 Mon Sep 17 00:00:00 2001 From: Atidot3 Date: Tue, 6 Aug 2024 10:50:01 +0200 Subject: [PATCH 1/3] Fix oil issue --- src/PlayerbotAI.cpp | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index 0b4db3ef..3e7afb5e 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -4388,14 +4388,14 @@ Item* PlayerbotAI::FindStoneFor(Item* weapon) const return stone; } -static const uint32 uPriorizedWizardOilIds[5] = {MINOR_WIZARD_OIL, LESSER_WIZARD_OIL, BRILLIANT_WIZARD_OIL, WIZARD_OIL, - SUPERIOR_WIZARD_OIL}; +static const std::vector uPriorizedWizardOilIds = +{ + MINOR_WIZARD_OIL, LESSER_WIZARD_OIL, BRILLIANT_WIZARD_OIL, WIZARD_OIL, SUPERIOR_WIZARD_OIL +}; -static const uint32 uPriorizedManaOilIds[4] = { - MINOR_MANA_OIL, - LESSER_MANA_OIL, - BRILLIANT_MANA_OIL, - SUPERIOR_MANA_OIL, +static const std::vector uPriorizedManaOilIds = +{ + MINOR_MANA_OIL, LESSER_MANA_OIL, BRILLIANT_MANA_OIL, SUPERIOR_MANA_OIL, }; Item* PlayerbotAI::FindOilFor(Item* weapon) const @@ -4405,25 +4405,22 @@ Item* PlayerbotAI::FindOilFor(Item* weapon) const if (pProto && (pProto->SubClass == ITEM_SUBCLASS_WEAPON_SWORD || pProto->SubClass == ITEM_SUBCLASS_WEAPON_STAFF || pProto->SubClass == ITEM_SUBCLASS_WEAPON_DAGGER)) { - for (uint8 i = 0; i < std::size(uPriorizedWizardOilIds); ++i) + for (const auto& id : uPriorizedWizardOilIds) { - oil = FindConsumable(uPriorizedWizardOilIds[i]); + oil = FindConsumable(uPriorizedWizardOilIds[id]); if (!oil) - oil = FindConsumable(uPriorizedManaOilIds[i]); - + oil = FindConsumable(uPriorizedManaOilIds[id]); if (oil) return oil; } } - else if (pProto && - (pProto->SubClass == ITEM_SUBCLASS_WEAPON_MACE || pProto->SubClass == ITEM_SUBCLASS_WEAPON_MACE2)) + else if (pProto && (pProto->SubClass == ITEM_SUBCLASS_WEAPON_MACE || pProto->SubClass == ITEM_SUBCLASS_WEAPON_MACE2)) { - for (uint8 i = 0; i < std::size(uPriorizedManaOilIds); ++i) + for (const auto& id : uPriorizedManaOilIds) { - oil = FindConsumable(uPriorizedManaOilIds[i]); + oil = FindConsumable(uPriorizedManaOilIds[id]); if (!oil) - oil = FindConsumable(uPriorizedWizardOilIds[i]); - + oil = FindConsumable(uPriorizedWizardOilIds[id]); if (oil) return oil; } @@ -4924,4 +4921,4 @@ uint8 PlayerbotAI::FindEquipSlot(ItemTemplate const* proto, uint32 slot, bool sw // no free position return NULL_SLOT; -} \ No newline at end of file +} From bfa3172ea44649d8970e3d34ffbc79fbc6b18f9f Mon Sep 17 00:00:00 2001 From: antony Date: Wed, 7 Aug 2024 09:18:31 +0200 Subject: [PATCH 2/3] fix the fix --- src/PlayerbotAI.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index 3e7afb5e..117f6263 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -4407,9 +4407,9 @@ Item* PlayerbotAI::FindOilFor(Item* weapon) const { for (const auto& id : uPriorizedWizardOilIds) { - oil = FindConsumable(uPriorizedWizardOilIds[id]); + oil = FindConsumable(id); if (!oil) - oil = FindConsumable(uPriorizedManaOilIds[id]); + oil = FindConsumable(id); if (oil) return oil; } @@ -4418,9 +4418,9 @@ Item* PlayerbotAI::FindOilFor(Item* weapon) const { for (const auto& id : uPriorizedManaOilIds) { - oil = FindConsumable(uPriorizedManaOilIds[id]); + oil = FindConsumable(id); if (!oil) - oil = FindConsumable(uPriorizedWizardOilIds[id]); + oil = FindConsumable(id); if (oil) return oil; } From 1f70acb06efeecb26163c6745e8c284fe12933c4 Mon Sep 17 00:00:00 2001 From: antony Date: Thu, 8 Aug 2024 16:12:57 +0200 Subject: [PATCH 3/3] Fix oil priority based on weapon type and code reduncy --- src/PlayerbotAI.cpp | 54 +++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index 117f6263..20c1c09d 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -4388,40 +4388,50 @@ Item* PlayerbotAI::FindStoneFor(Item* weapon) const return stone; } -static const std::vector uPriorizedWizardOilIds = -{ - MINOR_WIZARD_OIL, LESSER_WIZARD_OIL, BRILLIANT_WIZARD_OIL, WIZARD_OIL, SUPERIOR_WIZARD_OIL -}; - -static const std::vector uPriorizedManaOilIds = -{ - MINOR_MANA_OIL, LESSER_MANA_OIL, BRILLIANT_MANA_OIL, SUPERIOR_MANA_OIL, -}; - Item* PlayerbotAI::FindOilFor(Item* weapon) const { + if (!weapon) + return nullptr; + + const ItemTemplate* item_template = weapon->GetTemplate(); + if (!item_template) + return nullptr; + + // static const will only get created once whatever the call amout + static const std::vector uPriorizedWizardOilIds = + { + MINOR_WIZARD_OIL, MINOR_MANA_OIL, + LESSER_WIZARD_OIL, LESSER_MANA_OIL, + BRILLIANT_WIZARD_OIL, BRILLIANT_MANA_OIL, + WIZARD_OIL, SUPERIOR_MANA_OIL, SUPERIOR_WIZARD_OIL + }; + + // static const will only get created once whatever the call amout + static const std::vector uPriorizedManaOilIds = + { + MINOR_MANA_OIL, MINOR_WIZARD_OIL, + LESSER_MANA_OIL, LESSER_WIZARD_OIL, + BRILLIANT_MANA_OIL, BRILLIANT_WIZARD_OIL, + SUPERIOR_MANA_OIL, WIZARD_OIL, SUPERIOR_WIZARD_OIL + }; + Item* oil = nullptr; - ItemTemplate const* pProto = weapon->GetTemplate(); - if (pProto && (pProto->SubClass == ITEM_SUBCLASS_WEAPON_SWORD || pProto->SubClass == ITEM_SUBCLASS_WEAPON_STAFF || - pProto->SubClass == ITEM_SUBCLASS_WEAPON_DAGGER)) + if (item_template->SubClass == ITEM_SUBCLASS_WEAPON_SWORD || + item_template->SubClass == ITEM_SUBCLASS_WEAPON_STAFF || + item_template->SubClass == ITEM_SUBCLASS_WEAPON_DAGGER) { for (const auto& id : uPriorizedWizardOilIds) { - oil = FindConsumable(id); - if (!oil) - oil = FindConsumable(id); - if (oil) + if (oil = FindConsumable(id)) return oil; } } - else if (pProto && (pProto->SubClass == ITEM_SUBCLASS_WEAPON_MACE || pProto->SubClass == ITEM_SUBCLASS_WEAPON_MACE2)) + else if (item_template->SubClass == ITEM_SUBCLASS_WEAPON_MACE || + item_template->SubClass == ITEM_SUBCLASS_WEAPON_MACE2) { for (const auto& id : uPriorizedManaOilIds) { - oil = FindConsumable(id); - if (!oil) - oil = FindConsumable(id); - if (oil) + if (oil = FindConsumable(id)) return oil; } }