mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-02-01 18:03:47 +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());
|
bot->SetSelection(target->GetGUID());
|
||||||
|
|
||||||
Unit* oldTarget = context->GetValue<Unit*>("current target")->Get();
|
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;
|
return false;
|
||||||
|
|
||||||
context->GetValue<Unit*>("old target")->Set(oldTarget);
|
context->GetValue<Unit*>("old target")->Set(oldTarget);
|
||||||
@@ -129,7 +130,6 @@ bool AttackAction::Attack(Unit* target, bool with_pet /*true*/)
|
|||||||
bot->StopMoving();
|
bot->StopMoving();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool melee = bot->IsWithinMeleeRange(target) || botAI->IsMelee(bot);
|
|
||||||
|
|
||||||
if (IsMovingAllowed() && !bot->HasInArc(CAST_ANGLE_IN_FRONT, target))
|
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");
|
GuidPosition currentRpgTarget = AI_VALUE(GuidPosition, "rpg target");
|
||||||
SET_AI_VALUE(GuidPosition, "rpg target", guidP);
|
SET_AI_VALUE(GuidPosition, "rpg target", guidP);
|
||||||
|
|
||||||
Strategy* rpgStrategy;
|
Strategy* rpgStrategy = botAI->GetAiObjectContext()->GetStrategy("rpg");
|
||||||
|
if (!rpgStrategy) return 0.0f;
|
||||||
|
|
||||||
std::vector<TriggerNode*> triggerNodes;
|
std::vector<TriggerNode*> triggerNodes;
|
||||||
|
rpgStrategy->InitTriggers(triggerNodes);
|
||||||
|
|
||||||
float maxRelevance = 0.0f;
|
float maxRelevance = 0.0f;
|
||||||
|
|
||||||
for (auto& strategy : botAI->GetAiObjectContext()->GetSupportedStrategies())
|
for (auto triggerNode : triggerNodes)
|
||||||
{
|
{
|
||||||
if (strategy.find("rpg") == std::string::npos)
|
Trigger* trigger = context->GetTrigger(triggerNode->getName());
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!botAI->HasStrategy(strategy, BotState::BOT_STATE_NON_COMBAT))
|
if (trigger)
|
||||||
continue;
|
|
||||||
|
|
||||||
rpgStrategy = botAI->GetAiObjectContext()->GetStrategy(strategy);
|
|
||||||
|
|
||||||
rpgStrategy->InitTriggers(triggerNodes);
|
|
||||||
|
|
||||||
for (auto triggerNode : triggerNodes)
|
|
||||||
{
|
{
|
||||||
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)
|
Action* action = botAI->GetAiObjectContext()->GetAction(nextAction->getName());
|
||||||
continue;
|
|
||||||
|
|
||||||
Trigger* trigger = triggerNode->getTrigger();
|
if (dynamic_cast<RpgEnabled*>(action))
|
||||||
|
isRpg = true;
|
||||||
|
}
|
||||||
|
NextAction::destroy(nextActions);
|
||||||
|
|
||||||
if (!trigger->IsActive())
|
if (isRpg)
|
||||||
continue;
|
{
|
||||||
|
maxRelevance = triggerNode->getFirstRelevance();
|
||||||
NextAction** nextActions = triggerNode->getHandlers();
|
rgpActionReason[guidP] = triggerNode->getName();
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto trigger : triggerNodes)
|
|
||||||
{
|
|
||||||
delete trigger;
|
|
||||||
}
|
|
||||||
|
|
||||||
triggerNodes.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto trigger : triggerNodes)
|
||||||
|
{
|
||||||
|
delete trigger;
|
||||||
|
}
|
||||||
|
triggerNodes.clear();
|
||||||
|
|
||||||
SET_AI_VALUE(GuidPosition, "rpg target", currentRpgTarget);
|
SET_AI_VALUE(GuidPosition, "rpg target", currentRpgTarget);
|
||||||
|
|
||||||
if (!maxRelevance)
|
if (!maxRelevance)
|
||||||
|
|||||||
Reference in New Issue
Block a user