Skip to content

Commit

Permalink
Merge pull request #476 from liyunfan1223/fix-lag
Browse files Browse the repository at this point in the history
Fix lag and hunter melee attack
  • Loading branch information
liyunfan1223 authored Aug 15, 2024
2 parents 0eba23d + f1c7071 commit e97c035
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/strategy/actions/AttackAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ bool AttackAction::Attack(Unit* target, bool with_pet /*true*/)
bot->SetSelection(target->GetGUID());

Unit* oldTarget = context->GetValue<Unit*>("current target")->Get();
bool melee = bot->IsWithinMeleeRange(target) || botAI->IsMelee(bot);

if (oldTarget == target && botAI->GetState() == BOT_STATE_COMBAT && bot->GetVictim() == target)
if (oldTarget == target && botAI->GetState() == BOT_STATE_COMBAT && bot->GetVictim() == target && (bot->HasUnitState(UNIT_STATE_MELEE_ATTACKING) == melee))
return false;

context->GetValue<Unit*>("old target")->Set(oldTarget);
Expand All @@ -129,7 +130,6 @@ bool AttackAction::Attack(Unit* target, bool with_pet /*true*/)
bot->StopMoving();
}

bool melee = bot->IsWithinMeleeRange(target) || botAI->IsMelee(bot);

if (IsMovingAllowed() && !bot->HasInArc(CAST_ANGLE_IN_FRONT, target))
{
Expand Down
74 changes: 31 additions & 43 deletions src/strategy/actions/ChooseRpgTargetAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,70 +54,58 @@ float ChooseRpgTargetAction::getMaxRelevance(GuidPosition guidP)
GuidPosition currentRpgTarget = AI_VALUE(GuidPosition, "rpg target");
SET_AI_VALUE(GuidPosition, "rpg target", guidP);

Strategy* rpgStrategy;
Strategy* rpgStrategy = botAI->GetAiObjectContext()->GetStrategy("rpg");
if (!rpgStrategy) return 0.0f;

std::vector<TriggerNode*> triggerNodes;
rpgStrategy->InitTriggers(triggerNodes);

float maxRelevance = 0.0f;

for (auto& strategy : botAI->GetAiObjectContext()->GetSupportedStrategies())
for (auto triggerNode : triggerNodes)
{
if (strategy.find("rpg") == std::string::npos)
continue;

if (!botAI->HasStrategy(strategy, BotState::BOT_STATE_NON_COMBAT))
continue;
Trigger* trigger = context->GetTrigger(triggerNode->getName());

rpgStrategy = botAI->GetAiObjectContext()->GetStrategy(strategy);

rpgStrategy->InitTriggers(triggerNodes);

for (auto triggerNode : triggerNodes)
if (trigger)
{
Trigger* trigger = context->GetTrigger(triggerNode->getName());

if (trigger)
{
triggerNode->setTrigger(trigger);
triggerNode->setTrigger(trigger);

if (triggerNode->getFirstRelevance() < maxRelevance || triggerNode->getFirstRelevance() > 2.0f)
continue;
if (triggerNode->getFirstRelevance() < maxRelevance || triggerNode->getFirstRelevance() > 2.0f)
continue;

Trigger* trigger = triggerNode->getTrigger();
Trigger* trigger = triggerNode->getTrigger();

if (!trigger->IsActive())
continue;
if (!trigger->IsActive())
continue;

NextAction** nextActions = triggerNode->getHandlers();
NextAction** nextActions = triggerNode->getHandlers();

bool isRpg = false;
bool isRpg = false;

for (int32 i = 0; i < NextAction::size(nextActions); i++)
{
NextAction* nextAction = nextActions[i];

Action* action = botAI->GetAiObjectContext()->GetAction(nextAction->getName());
for (int32 i = 0; i < NextAction::size(nextActions); i++)
{
NextAction* nextAction = nextActions[i];

if (dynamic_cast<RpgEnabled*>(action))
isRpg = true;
}
NextAction::destroy(nextActions);
Action* action = botAI->GetAiObjectContext()->GetAction(nextAction->getName());

if (isRpg)
{
maxRelevance = triggerNode->getFirstRelevance();
rgpActionReason[guidP] = triggerNode->getName();
}
if (dynamic_cast<RpgEnabled*>(action))
isRpg = true;
}
}
NextAction::destroy(nextActions);

for (auto trigger : triggerNodes)
{
delete trigger;
if (isRpg)
{
maxRelevance = triggerNode->getFirstRelevance();
rgpActionReason[guidP] = triggerNode->getName();
}
}
}

triggerNodes.clear();
for (auto trigger : triggerNodes)
{
delete trigger;
}
triggerNodes.clear();

SET_AI_VALUE(GuidPosition, "rpg target", currentRpgTarget);

Expand Down

0 comments on commit e97c035

Please sign in to comment.