From 51a88063f895481e672877be375bdf8b725f6110 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Sun, 23 Jun 2024 16:29:46 +0800 Subject: [PATCH] [Class spell] Hunter auto shot --- src/strategy/hunter/GenericHunterStrategy.cpp | 4 +- src/strategy/triggers/RangeTriggers.cpp | 44 +++++++++++-------- src/strategy/triggers/RangeTriggers.h | 8 ++++ src/strategy/triggers/TriggerContext.h | 2 + 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/strategy/hunter/GenericHunterStrategy.cpp b/src/strategy/hunter/GenericHunterStrategy.cpp index 914ef210..f59db30e 100644 --- a/src/strategy/hunter/GenericHunterStrategy.cpp +++ b/src/strategy/hunter/GenericHunterStrategy.cpp @@ -79,7 +79,7 @@ void GenericHunterStrategy::InitTriggers(std::vector& triggers) { CombatStrategy::InitTriggers(triggers); - triggers.push_back(new TriggerNode("enemy is close", + triggers.push_back(new TriggerNode("enemy within melee", NextAction::array(0, new NextAction("wing clip", ACTION_HIGH + 1), new NextAction("mongoose bite", ACTION_HIGH), @@ -88,7 +88,7 @@ void GenericHunterStrategy::InitTriggers(std::vector& triggers) triggers.push_back(new TriggerNode("hunters pet medium health", NextAction::array(0, new NextAction("mend pet", ACTION_HIGH + 2), nullptr))); // triggers.push_back(new TriggerNode("no ammo", NextAction::array(0, new NextAction("switch to melee", ACTION_HIGH + 1), new NextAction("say::no ammo", ACTION_HIGH), nullptr))); triggers.push_back(new TriggerNode("aspect of the viper", NextAction::array(0, new NextAction("aspect of the viper", ACTION_HIGH), NULL))); - triggers.push_back(new TriggerNode("enemy too close for shoot", NextAction::array(0, new NextAction("flee", ACTION_MOVE + 9), nullptr))); + triggers.push_back(new TriggerNode("enemy too close for auto shot", NextAction::array(0, new NextAction("flee", ACTION_MOVE + 9), nullptr))); triggers.push_back(new TriggerNode("misdirection on main tank", NextAction::array(0, new NextAction("misdirection on main tank", ACTION_HIGH + 7), NULL))); triggers.push_back(new TriggerNode("tranquilizing shot", NextAction::array(0, new NextAction("tranquilizing shot", 61.0f), NULL))); diff --git a/src/strategy/triggers/RangeTriggers.cpp b/src/strategy/triggers/RangeTriggers.cpp index 55b095dd..6431e779 100644 --- a/src/strategy/triggers/RangeTriggers.cpp +++ b/src/strategy/triggers/RangeTriggers.cpp @@ -52,29 +52,29 @@ bool EnemyTooCloseForSpellTrigger::IsActive() bool EnemyTooCloseForAutoShotTrigger::IsActive() { Unit* target = AI_VALUE(Unit*, "current target"); - if (!target) - return false; + + return target && (target->GetVictim() != bot || target->isFrozen() || !target->CanFreeMove()) && bot->IsWithinMeleeRange(target); - if (target->GetTarget() == bot->GetGUID() && !bot->GetGroup() && !target->HasUnitState(UNIT_STATE_ROOT) && GetSpeedInMotion(target) > GetSpeedInMotion(bot) * 0.65f) - return false; + // if (target->GetTarget() == bot->GetGUID() && !bot->GetGroup() && !target->HasUnitState(UNIT_STATE_ROOT) && GetSpeedInMotion(target) > GetSpeedInMotion(bot) * 0.65f) + // return false; - bool isBoss = false; - bool isRaid = false; - float combatReach = bot->GetCombatReach() + target->GetCombatReach(); - float targetDistance = sServerFacade->GetDistance2d(bot, target) + combatReach; - if (target->GetTypeId() == TYPEID_UNIT) - { - Creature* creature = botAI->GetCreature(target->GetGUID()); - if (creature) - { - isBoss = creature->isWorldBoss(); - } - } + // bool isBoss = false; + // bool isRaid = false; + // float combatReach = bot->GetCombatReach() + target->GetCombatReach(); + // float targetDistance = sServerFacade->GetDistance2d(bot, target) + combatReach; + // if (target->GetTypeId() == TYPEID_UNIT) + // { + // Creature* creature = botAI->GetCreature(target->GetGUID()); + // if (creature) + // { + // isBoss = creature->isWorldBoss(); + // } + // } - if (bot->GetMap() && bot->GetMap()->IsRaid()) - isRaid = true; + // if (bot->GetMap() && bot->GetMap()->IsRaid()) + // isRaid = true; - return sServerFacade->IsDistanceLessOrEqualThan(targetDistance, 5.0f); + // return sServerFacade->IsDistanceLessOrEqualThan(targetDistance, 5.0f); } bool EnemyTooCloseForShootTrigger::IsActive() @@ -128,6 +128,12 @@ bool EnemyIsCloseTrigger::IsActive() return target && sServerFacade->IsDistanceLessOrEqualThan(AI_VALUE2(float, "distance", "current target"), sPlayerbotAIConfig->tooCloseDistance); } +bool EnemyWithinMeleeTrigger::IsActive() +{ + Unit* target = AI_VALUE(Unit*, "current target"); + return target && bot->IsWithinMeleeRange(target); +} + bool OutOfRangeTrigger::IsActive() { Unit* target = AI_VALUE(Unit*, GetTargetName()); diff --git a/src/strategy/triggers/RangeTriggers.h b/src/strategy/triggers/RangeTriggers.h index ce33b3be..470b5a8f 100644 --- a/src/strategy/triggers/RangeTriggers.h +++ b/src/strategy/triggers/RangeTriggers.h @@ -50,6 +50,14 @@ class EnemyIsCloseTrigger : public Trigger bool IsActive() override; }; +class EnemyWithinMeleeTrigger : public Trigger +{ + public: + EnemyWithinMeleeTrigger(PlayerbotAI* botAI) : Trigger(botAI, "enemy within melee") { } + + bool IsActive() override; +}; + class OutOfRangeTrigger : public Trigger { public: diff --git a/src/strategy/triggers/TriggerContext.h b/src/strategy/triggers/TriggerContext.h index 92fb96a2..34ef3480 100644 --- a/src/strategy/triggers/TriggerContext.h +++ b/src/strategy/triggers/TriggerContext.h @@ -87,6 +87,7 @@ class TriggerContext : public NamedObjectContext creators["enemy too close for auto shot"] = &TriggerContext::enemy_too_close_for_auto_shot; creators["enemy too close for melee"] = &TriggerContext::enemy_too_close_for_melee; creators["enemy is close"] = &TriggerContext::enemy_is_close; + creators["enemy within melee"] = &TriggerContext::enemy_within_melee; creators["party member to heal out of spell range"] = &TriggerContext::party_member_to_heal_out_of_spell_range; creators["combo points available"] = &TriggerContext::ComboPointsAvailable; @@ -278,6 +279,7 @@ class TriggerContext : public NamedObjectContext static Trigger* enemy_too_close_for_shoot(PlayerbotAI* botAI) { return new EnemyTooCloseForShootTrigger(botAI); } static Trigger* enemy_too_close_for_melee(PlayerbotAI* botAI) { return new EnemyTooCloseForMeleeTrigger(botAI); } static Trigger* enemy_is_close(PlayerbotAI* botAI) { return new EnemyIsCloseTrigger(botAI); } + static Trigger* enemy_within_melee(PlayerbotAI* botAI) { return new EnemyWithinMeleeTrigger(botAI); } static Trigger* party_member_to_heal_out_of_spell_range(PlayerbotAI* botAI) { return new PartyMemberToHealOutOfSpellRangeTrigger(botAI); } static Trigger* ComboPointsAvailable(PlayerbotAI* botAI) { return new ComboPointsAvailableTrigger(botAI); } static Trigger* ComboPoints3Available(PlayerbotAI* botAI) { return new ComboPointsAvailableTrigger(botAI, 3); }