mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
Improve containsstrategy performance
This commit is contained in:
@@ -1379,7 +1379,7 @@ bool PlayerbotAI::ContainsStrategy(StrategyType type)
|
||||
{
|
||||
for (uint8 i = 0; i < BOT_STATE_MAX; i++)
|
||||
{
|
||||
if (engines[i]->ContainsStrategy(type))
|
||||
if (engines[i]->HasStrategyType(type))
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -86,6 +86,7 @@ Engine::~Engine(void)
|
||||
|
||||
void Engine::Reset()
|
||||
{
|
||||
strategyTypeMask = 0;
|
||||
ActionNode* action = nullptr;
|
||||
do
|
||||
{
|
||||
@@ -120,6 +121,7 @@ void Engine::Init()
|
||||
for (std::map<std::string, Strategy*>::iterator i = strategies.begin(); i != strategies.end(); i++)
|
||||
{
|
||||
Strategy* strategy = i->second;
|
||||
strategyTypeMask |= strategy->GetType();
|
||||
strategy->InitMultipliers(multipliers);
|
||||
strategy->InitTriggers(triggers);
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ public:
|
||||
void AddActionExecutionListener(ActionExecutionListener* listener) { actionExecutionListeners.Add(listener); }
|
||||
|
||||
void removeActionExecutionListener(ActionExecutionListener* listener) { actionExecutionListeners.Remove(listener); }
|
||||
|
||||
bool HasStrategyType(StrategyType type) { return strategyTypeMask & type; }
|
||||
virtual ~Engine(void);
|
||||
|
||||
bool testMode;
|
||||
@@ -112,6 +112,7 @@ protected:
|
||||
std::map<std::string, Strategy*> strategies;
|
||||
float lastRelevance;
|
||||
std::string lastAction;
|
||||
uint32 strategyTypeMask;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -98,7 +98,9 @@ void GenericHunterStrategy::InitTriggers(std::vector<TriggerNode*>& triggers)
|
||||
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)));
|
||||
new TriggerNode("tranquilizing shot enrage", NextAction::array(0, new NextAction("tranquilizing shot", 61.0f), NULL)));
|
||||
triggers.push_back(
|
||||
new TriggerNode("tranquilizing shot magic", NextAction::array(0, new NextAction("tranquilizing shot", 61.0f), NULL)));
|
||||
}
|
||||
|
||||
NextAction** HunterBoostStrategy::getDefaultActions()
|
||||
|
||||
@@ -85,7 +85,8 @@ public:
|
||||
creators["switch to melee"] = &HunterTriggerFactoryInternal::switch_to_melee;
|
||||
creators["switch to ranged"] = &HunterTriggerFactoryInternal::switch_to_ranged;
|
||||
creators["misdirection on main tank"] = &HunterTriggerFactoryInternal::misdirection_on_main_tank;
|
||||
creators["tranquilizing shot"] = &HunterTriggerFactoryInternal::remove_enrage;
|
||||
creators["tranquilizing shot enrage"] = &HunterTriggerFactoryInternal::remove_enrage;
|
||||
creators["tranquilizing shot magic"] = &HunterTriggerFactoryInternal::remove_magic;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -118,6 +119,7 @@ private:
|
||||
static Trigger* switch_to_ranged(PlayerbotAI* botAI) { return new SwitchToRangedTrigger(botAI); }
|
||||
static Trigger* misdirection_on_main_tank(PlayerbotAI* ai) { return new MisdirectionOnMainTankTrigger(ai); }
|
||||
static Trigger* remove_enrage(PlayerbotAI* ai) { return new TargetRemoveEnrageTrigger(ai); }
|
||||
static Trigger* remove_magic(PlayerbotAI* ai) { return new TargetRemoveMagicTrigger(ai); }
|
||||
};
|
||||
|
||||
class HunterAiObjectContextInternal : public NamedObjectContext<Action>
|
||||
|
||||
@@ -88,9 +88,3 @@ bool SwitchToMeleeTrigger::IsActive()
|
||||
(target->GetVictim() == bot &&
|
||||
sServerFacade->IsDistanceLessOrEqualThan(AI_VALUE2(float, "distance", "current target"), 8.0f));
|
||||
}
|
||||
|
||||
bool TargetRemoveEnrageTrigger::IsActive()
|
||||
{
|
||||
Unit* target = GetTarget();
|
||||
return target && (botAI->HasAuraToDispel(target, DISPEL_ENRAGE) || botAI->HasAuraToDispel(target, DISPEL_MAGIC));
|
||||
}
|
||||
@@ -170,6 +170,11 @@ class TargetRemoveEnrageTrigger : public TargetAuraDispelTrigger
|
||||
{
|
||||
public:
|
||||
TargetRemoveEnrageTrigger(PlayerbotAI* ai) : TargetAuraDispelTrigger(ai, "tranquilizing shot", DISPEL_ENRAGE) {}
|
||||
bool IsActive() override;
|
||||
};
|
||||
|
||||
class TargetRemoveMagicTrigger : public TargetAuraDispelTrigger
|
||||
{
|
||||
public:
|
||||
TargetRemoveMagicTrigger(PlayerbotAI* ai) : TargetAuraDispelTrigger(ai, "tranquilizing shot", DISPEL_MAGIC) {}
|
||||
};
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user