From 68fdf57c3c21a863923d7b1d71b400c898f3f106 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Tue, 19 Mar 2024 17:06:14 +0800 Subject: [PATCH] Enhance equip upgrade --- src/PlayerbotFactory.cpp | 34 ++++++++++++++++--- src/strategy/actions/ChatActionContext.h | 2 ++ src/strategy/actions/EquipAction.cpp | 17 ++++++++++ src/strategy/actions/EquipAction.h | 9 +++++ .../generic/ChatCommandHandlerStrategy.cpp | 1 + src/strategy/generic/RacialsStrategy.cpp | 2 +- src/strategy/triggers/ChatTriggerContext.h | 2 ++ 7 files changed, 62 insertions(+), 5 deletions(-) diff --git a/src/PlayerbotFactory.cpp b/src/PlayerbotFactory.cpp index 6ad45526..ba04119d 100644 --- a/src/PlayerbotFactory.cpp +++ b/src/PlayerbotFactory.cpp @@ -3370,8 +3370,11 @@ void PlayerbotFactory::ApplyEnchantAndGemsNew(bool destoryOld) if (!spellInfo) continue; - uint32 requiredLevel = spellInfo->BaseLevel; + if (!item->IsFitToSpellRequirements(spellInfo)) { + continue; + } + uint32 requiredLevel = spellInfo->BaseLevel; if (requiredLevel > bot->GetLevel()) { continue; } @@ -3385,9 +3388,6 @@ void PlayerbotFactory::ApplyEnchantAndGemsNew(bool destoryOld) continue; } - if (!item->IsFitToSpellRequirements(spellInfo)) { - continue; - } for (uint8 j = 0; j < MAX_SPELL_EFFECTS; ++j) { @@ -3604,6 +3604,32 @@ float PlayerbotFactory::CalculateItemScore(uint32 item_id, Player* bot) break; } } + for (uint8 j = 0; j < MAX_ITEM_PROTO_SPELLS; j++) + { + SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(proto->Spells[j].SpellId); + if (!spellInfo) + continue; + + for (uint8 i = 0 ; i < 3; i++) + { + if (spellInfo->Effects[i].Effect == SPELL_EFFECT_APPLY_AURA) + { + switch (spellInfo->Effects[i].ApplyAuraName) + { + case SPELL_AURA_MOD_DAMAGE_DONE: + // case SPELL_AURA_MOD_HEALING_DONE: duplicated + spell_power += spellInfo->Effects[i].BasePoints + 1; + break; + case SPELL_AURA_MOD_ATTACK_POWER: + attack_power += spellInfo->Effects[i].BasePoints + 1; + case SPELL_AURA_MOD_SHIELD_BLOCKVALUE: + block += spellInfo->Effects[i].BasePoints + 1; + default: + break; + } + } + } + } // Basic score float score = (agility + strength + intellect + spirit + stamina + defense + dodge + parry + block + resilience + hit + crit + haste + expertise + attack_power + mana_regeneration + spell_power + armor_penetration + diff --git a/src/strategy/actions/ChatActionContext.h b/src/strategy/actions/ChatActionContext.h index cec70a7e..ba1438ca 100644 --- a/src/strategy/actions/ChatActionContext.h +++ b/src/strategy/actions/ChatActionContext.h @@ -115,6 +115,7 @@ class ChatActionContext : public NamedObjectContext creators["de"] = &ChatActionContext::dead; creators["trainer"] = &ChatActionContext::trainer; creators["maintenance"] = &ChatActionContext::maintenance; + creators["equip upgrade"] = &ChatActionContext::equip_upgrade; creators["attack my target"] = &ChatActionContext::attack_my_target; creators["chat"] = &ChatActionContext::chat; creators["home"] = &ChatActionContext::home; @@ -213,6 +214,7 @@ class ChatActionContext : public NamedObjectContext static Action* attack_my_target(PlayerbotAI* botAI) { return new AttackMyTargetAction(botAI); } static Action* trainer(PlayerbotAI* botAI) { return new TrainerAction(botAI); } static Action* maintenance(PlayerbotAI* botAI) { return new MaintenanceAction(botAI); } + static Action* equip_upgrade(PlayerbotAI* botAI) { return new EquipUpgradeAction(botAI); } static Action* co(PlayerbotAI* botAI) { return new ChangeCombatStrategyAction(botAI); } static Action* nc(PlayerbotAI* botAI) { return new ChangeNonCombatStrategyAction(botAI); } static Action* dead(PlayerbotAI* botAI) { return new ChangeDeadStrategyAction(botAI); } diff --git a/src/strategy/actions/EquipAction.cpp b/src/strategy/actions/EquipAction.cpp index bda823e6..c542ac89 100644 --- a/src/strategy/actions/EquipAction.cpp +++ b/src/strategy/actions/EquipAction.cpp @@ -129,3 +129,20 @@ bool EquipUpgradesAction::Execute(Event event) return true; } +bool EquipUpgradeAction::Execute(Event event) +{ + ListItemsVisitor visitor; + IterateItems(&visitor, ITERATE_ITEMS_IN_BAGS); + + ItemIds items; + for (std::map::iterator i = visitor.items.begin(); i != visitor.items.end(); ++i) + { + ItemUsage usage = AI_VALUE2(ItemUsage, "item usage", i->first); + if (usage == ITEM_USAGE_EQUIP || usage == ITEM_USAGE_REPLACE || usage == ITEM_USAGE_BAD_EQUIP) + { + items.insert(i->first); + } + } + EquipItems(items); + return true; +} diff --git a/src/strategy/actions/EquipAction.h b/src/strategy/actions/EquipAction.h index 2d53abe1..816cd0af 100644 --- a/src/strategy/actions/EquipAction.h +++ b/src/strategy/actions/EquipAction.h @@ -34,4 +34,13 @@ class EquipUpgradesAction : public EquipAction bool Execute(Event event) override; }; +class EquipUpgradeAction : public EquipAction +{ + public: + EquipUpgradeAction(PlayerbotAI* botAI, std::string const name = "equip upgrade") : EquipAction(botAI, name) { } + + bool Execute(Event event) override; +}; + + #endif diff --git a/src/strategy/generic/ChatCommandHandlerStrategy.cpp b/src/strategy/generic/ChatCommandHandlerStrategy.cpp index 0a838231..5ce52136 100644 --- a/src/strategy/generic/ChatCommandHandlerStrategy.cpp +++ b/src/strategy/generic/ChatCommandHandlerStrategy.cpp @@ -89,6 +89,7 @@ ChatCommandHandlerStrategy::ChatCommandHandlerStrategy(PlayerbotAI* botAI) : Pas supported.push_back("de"); supported.push_back("trainer"); supported.push_back("maintenance"); + supported.push_back("equip upgrade"); supported.push_back("chat"); supported.push_back("home"); supported.push_back("destroy"); diff --git a/src/strategy/generic/RacialsStrategy.cpp b/src/strategy/generic/RacialsStrategy.cpp index 3282ca5f..cb3b8938 100644 --- a/src/strategy/generic/RacialsStrategy.cpp +++ b/src/strategy/generic/RacialsStrategy.cpp @@ -26,7 +26,7 @@ class RacialsStrategyActionNodeFactory : public NamedObjectFactory void RacialsStrategy::InitTriggers(std::vector& triggers) { triggers.push_back(new TriggerNode("low health", NextAction::array(0, new NextAction("lifeblood", 71.0f), nullptr))); - triggers.push_back(new TriggerNode("medium aoe", NextAction::array(0, new NextAction("war stomp", 71.0f), nullptr))); + // triggers.push_back(new TriggerNode("medium aoe", NextAction::array(0, new NextAction("war stomp", 71.0f), nullptr))); /*triggers.push_back(new TriggerNode("low health", NextAction::array(0, new NextAction("war stomp", 71.0f), nullptr)));*/ /*triggers.push_back(new TriggerNode("low mana", NextAction::array(0, new NextAction("arcane torrent", ACTION_EMERGENCY + 6), nullptr))); triggers.push_back(new TriggerNode("medium mana", NextAction::array(0, new NextAction("mana tap", ACTION_EMERGENCY + 6), nullptr)));*/ diff --git a/src/strategy/triggers/ChatTriggerContext.h b/src/strategy/triggers/ChatTriggerContext.h index 61cc9793..482840c8 100644 --- a/src/strategy/triggers/ChatTriggerContext.h +++ b/src/strategy/triggers/ChatTriggerContext.h @@ -55,6 +55,7 @@ class ChatTriggerContext : public NamedObjectContext creators["de"] = &ChatTriggerContext::dead; creators["trainer"] = &ChatTriggerContext::trainer; creators["maintenance"] = &ChatTriggerContext::maintenance; + creators["equip upgrade"] = &ChatTriggerContext::equip_upgrade; creators["attack"] = &ChatTriggerContext::attack; creators["chat"] = &ChatTriggerContext::chat; creators["accept"] = &ChatTriggerContext::accept; @@ -166,6 +167,7 @@ class ChatTriggerContext : public NamedObjectContext static Trigger* attack(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "attack"); } static Trigger* trainer(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "trainer"); } static Trigger* maintenance(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "maintenance"); } + static Trigger* equip_upgrade(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "equip upgrade"); } static Trigger* co(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "co"); } static Trigger* nc(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "nc"); } static Trigger* dead(PlayerbotAI* botAI) { return new ChatCommandTrigger(botAI, "de"); }