target && hunter auto shoot

This commit is contained in:
Yunfan Li
2023-10-22 15:19:12 +08:00
parent 45d0ae00ab
commit e727397963
2 changed files with 19 additions and 9 deletions

View File

@@ -41,7 +41,7 @@ bool CastAutoShotAction::isUseful()
if (botAI->IsInVehicle() && !botAI->IsInVehicle(false, false, true)) if (botAI->IsInVehicle() && !botAI->IsInVehicle(false, false, true))
return false; return false;
if (bot->GetCurrentSpell(CURRENT_AUTOREPEAT_SPELL)) { if (bot->GetCurrentSpell(CURRENT_AUTOREPEAT_SPELL) && bot->GetCurrentSpell(CURRENT_AUTOREPEAT_SPELL)->m_targets.GetUnitTargetGUID() == AI_VALUE(Unit*, "current target")->GetGUID()) {
return false; return false;
} }
return AI_VALUE(uint32, "active spell") != AI_VALUE2(uint32, "spell id", getName()); return AI_VALUE(uint32, "active spell") != AI_VALUE2(uint32, "spell id", getName());

View File

@@ -3,6 +3,7 @@
*/ */
#include "DpsTargetValue.h" #include "DpsTargetValue.h"
#include "PlayerbotAIConfig.h"
#include "Playerbots.h" #include "Playerbots.h"
class FindLeastHpTargetStrategy : public FindTargetStrategy class FindLeastHpTargetStrategy : public FindTargetStrategy
@@ -85,27 +86,36 @@ class FindTargetSmartStrategy : public FindTargetStrategy
float new_time = new_unit->GetHealth() / dps_; float new_time = new_unit->GetHealth() / dps_;
float old_time = old_unit->GetHealth() / dps_; float old_time = old_unit->GetHealth() / dps_;
// [5-20] > (5-0] > (20-inf) // [5-20] > (5-0] > (20-inf)
if (GetIntervalLevel(new_time) > GetIntervalLevel(old_time)) { if (GetIntervalLevel(new_unit) > GetIntervalLevel(old_unit)) {
return true; return true;
} }
int32_t interval = GetIntervalLevel(new_time); int32_t level = GetIntervalLevel(new_unit);
if (interval == 2 || interval == 0) { if (level % 10 == 2 || level % 10 == 0) {
return new_time < old_time; return new_time < old_time;
} }
// dont switch targets when all of them with low health // dont switch targets when all of them with low health
if (botAI->GetAiObjectContext()->GetValue<Unit*>("current target")->Get() == old_unit) { Unit* currentTarget = botAI->GetAiObjectContext()->GetValue<Unit*>("current target")->Get();
if (currentTarget == new_unit) {
return true;
}
if (currentTarget == old_unit) {
return false; return false;
} }
return new_time > old_time; return new_time > old_time;
} }
int32_t GetIntervalLevel(float time) { int32_t GetIntervalLevel(Unit* unit) {
float time = unit->GetHealth() / dps_;
float dis = unit->GetDistance(botAI->GetBot());
float attackRange = botAI->IsRanged(botAI->GetBot()) ? sPlayerbotAIConfig->spellDistance : sPlayerbotAIConfig->meleeDistance;
attackRange += 5.0f;
int level = dis < attackRange ? 10 : 0;
if (time >= 5 && time <= 20) { if (time >= 5 && time <= 20) {
return 2; return level + 2;
} }
if (time < 5) { if (time < 5) {
return 1; return level + 1;
} }
return 0; return level;
} }
protected: protected: