mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-01-13 09:07:19 +00:00
Merge pull request #476 from liyunfan1223/fix-lag
Fix lag and hunter melee attack
This commit is contained in:
@@ -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);
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -54,71 +54,59 @@ 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;
|
||||
Trigger* trigger = context->GetTrigger(triggerNode->getName());
|
||||
|
||||
if (!botAI->HasStrategy(strategy, BotState::BOT_STATE_NON_COMBAT))
|
||||
continue;
|
||||
|
||||
rpgStrategy = botAI->GetAiObjectContext()->GetStrategy(strategy);
|
||||
|
||||
rpgStrategy->InitTriggers(triggerNodes);
|
||||
|
||||
for (auto triggerNode : triggerNodes)
|
||||
if (trigger)
|
||||
{
|
||||
Trigger* trigger = context->GetTrigger(triggerNode->getName());
|
||||
triggerNode->setTrigger(trigger);
|
||||
|
||||
if (trigger)
|
||||
if (triggerNode->getFirstRelevance() < maxRelevance || triggerNode->getFirstRelevance() > 2.0f)
|
||||
continue;
|
||||
|
||||
Trigger* trigger = triggerNode->getTrigger();
|
||||
|
||||
if (!trigger->IsActive())
|
||||
continue;
|
||||
|
||||
NextAction** nextActions = triggerNode->getHandlers();
|
||||
|
||||
bool isRpg = false;
|
||||
|
||||
for (int32 i = 0; i < NextAction::size(nextActions); i++)
|
||||
{
|
||||
triggerNode->setTrigger(trigger);
|
||||
NextAction* nextAction = nextActions[i];
|
||||
|
||||
if (triggerNode->getFirstRelevance() < maxRelevance || triggerNode->getFirstRelevance() > 2.0f)
|
||||
continue;
|
||||
Action* action = botAI->GetAiObjectContext()->GetAction(nextAction->getName());
|
||||
|
||||
Trigger* trigger = triggerNode->getTrigger();
|
||||
if (dynamic_cast<RpgEnabled*>(action))
|
||||
isRpg = true;
|
||||
}
|
||||
NextAction::destroy(nextActions);
|
||||
|
||||
if (!trigger->IsActive())
|
||||
continue;
|
||||
|
||||
NextAction** nextActions = triggerNode->getHandlers();
|
||||
|
||||
bool isRpg = false;
|
||||
|
||||
for (int32 i = 0; i < NextAction::size(nextActions); i++)
|
||||
{
|
||||
NextAction* nextAction = nextActions[i];
|
||||
|
||||
Action* action = botAI->GetAiObjectContext()->GetAction(nextAction->getName());
|
||||
|
||||
if (dynamic_cast<RpgEnabled*>(action))
|
||||
isRpg = true;
|
||||
}
|
||||
NextAction::destroy(nextActions);
|
||||
|
||||
if (isRpg)
|
||||
{
|
||||
maxRelevance = triggerNode->getFirstRelevance();
|
||||
rgpActionReason[guidP] = triggerNode->getName();
|
||||
}
|
||||
if (isRpg)
|
||||
{
|
||||
maxRelevance = triggerNode->getFirstRelevance();
|
||||
rgpActionReason[guidP] = triggerNode->getName();
|
||||
}
|
||||
}
|
||||
|
||||
for (auto trigger : triggerNodes)
|
||||
{
|
||||
delete trigger;
|
||||
}
|
||||
|
||||
triggerNodes.clear();
|
||||
}
|
||||
|
||||
for (auto trigger : triggerNodes)
|
||||
{
|
||||
delete trigger;
|
||||
}
|
||||
triggerNodes.clear();
|
||||
|
||||
SET_AI_VALUE(GuidPosition, "rpg target", currentRpgTarget);
|
||||
|
||||
if (!maxRelevance)
|
||||
|
||||
Reference in New Issue
Block a user