Rogue stealth spell & Target selection for combo class

This commit is contained in:
Yunfan Li
2024-02-10 22:03:33 +08:00
parent 4091ba3e5a
commit f09d8d72f4
5 changed files with 119 additions and 42 deletions

View File

@@ -177,6 +177,64 @@ class NonCasterFindTargetSmartStrategy : public FindTargetStrategy
float targetExpectedLifeTime;
};
// combo
class ComboFindTargetSmartStrategy : public FindTargetStrategy
{
public:
ComboFindTargetSmartStrategy(PlayerbotAI* botAI, float dps) : FindTargetStrategy(botAI), dps_(dps), targetExpectedLifeTime(1000000) { }
void CheckAttacker(Unit* attacker, ThreatMgr* threatMgr) override
{
if (Group* group = botAI->GetBot()->GetGroup())
{
ObjectGuid guid = group->GetTargetIcon(4);
if (guid && attacker->GetGUID() == guid)
return;
}
if (!attacker->IsAlive()) {
return;
}
float expectedLifeTime = attacker->GetHealth() / dps_;
// Unit* victim = attacker->GetVictim();
if (!result || IsBetter(attacker, result)) {
targetExpectedLifeTime = expectedLifeTime;
result = attacker;
}
}
bool IsBetter(Unit* new_unit, Unit* old_unit) {
float new_time = new_unit->GetHealth() / dps_;
float old_time = old_unit->GetHealth() / dps_;
// [5-20] > (5-0] > (20-inf)
if (GetIntervalLevel(new_unit) > GetIntervalLevel(old_unit)) {
return true;
}
// attack enemy in range and with lowest health
int level = GetIntervalLevel(new_unit);
Player* bot = botAI->GetBot();
if (level == 10) {
Unit* combo_unit = bot->GetComboTarget();
if (new_unit == combo_unit) {
return true;
}
return new_time < old_time;
}
// all targets are far away, choose the closest one
return bot->GetDistance(new_unit) < bot->GetDistance(old_unit);
}
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;
return level;
}
protected:
float dps_;
float targetExpectedLifeTime;
};
Unit* DpsTargetValue::Calculate()
{
Unit* rti = RtiTargetValue::Calculate();
@@ -188,6 +246,9 @@ Unit* DpsTargetValue::Calculate()
if (botAI->IsCaster(bot)) {
CasterFindTargetSmartStrategy strategy(botAI, dps);
return TargetValue::FindTarget(&strategy);
} else if (botAI->IsCombo(bot)) {
ComboFindTargetSmartStrategy strategy(botAI, dps);
return TargetValue::FindTarget(&strategy);
}
NonCasterFindTargetSmartStrategy strategy(botAI, dps);
return TargetValue::FindTarget(&strategy);