mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
Dps target
This commit is contained in:
@@ -1372,6 +1372,11 @@ bool PlayerbotAI::IsRanged(Player* player)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PlayerbotAI::IsCaster(Player* player)
|
||||||
|
{
|
||||||
|
return IsRanged(player) && player->getClass() != CLASS_HUNTER;
|
||||||
|
}
|
||||||
|
|
||||||
bool PlayerbotAI::IsRangedDps(Player* player)
|
bool PlayerbotAI::IsRangedDps(Player* player)
|
||||||
{
|
{
|
||||||
return IsRanged(player) && IsDps(player);
|
return IsRanged(player) && IsDps(player);
|
||||||
|
|||||||
@@ -332,6 +332,7 @@ class PlayerbotAI : public PlayerbotAIBase
|
|||||||
bool IsHeal(Player* player);
|
bool IsHeal(Player* player);
|
||||||
bool IsDps(Player* player);
|
bool IsDps(Player* player);
|
||||||
bool IsRanged(Player* player);
|
bool IsRanged(Player* player);
|
||||||
|
bool IsCaster(Player* player);
|
||||||
bool IsRangedDps(Player* player);
|
bool IsRangedDps(Player* player);
|
||||||
bool IsMainTank(Player* player);
|
bool IsMainTank(Player* player);
|
||||||
bool IsAssistTank(Player* player);
|
bool IsAssistTank(Player* player);
|
||||||
|
|||||||
@@ -59,10 +59,11 @@ class FindMaxThreatGapTargetStrategy : public FindTargetStrategy
|
|||||||
float minThreat;
|
float minThreat;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FindTargetSmartStrategy : public FindTargetStrategy
|
// caster
|
||||||
|
class CasterFindTargetSmartStrategy : public FindTargetStrategy
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FindTargetSmartStrategy(PlayerbotAI* botAI, float dps) : FindTargetStrategy(botAI), dps_(dps), targetExpectedLifeTime(1000000) { }
|
CasterFindTargetSmartStrategy(PlayerbotAI* botAI, float dps) : FindTargetStrategy(botAI), dps_(dps), targetExpectedLifeTime(1000000) { }
|
||||||
|
|
||||||
void CheckAttacker(Unit* attacker, ThreatMgr* threatMgr) override
|
void CheckAttacker(Unit* attacker, ThreatMgr* threatMgr) override
|
||||||
{
|
{
|
||||||
@@ -123,6 +124,59 @@ class FindTargetSmartStrategy : public FindTargetStrategy
|
|||||||
float targetExpectedLifeTime;
|
float targetExpectedLifeTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// non caster
|
||||||
|
class NonCasterFindTargetSmartStrategy : public FindTargetStrategy
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NonCasterFindTargetSmartStrategy(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);
|
||||||
|
if (level == 0) {
|
||||||
|
return new_time < old_time;
|
||||||
|
}
|
||||||
|
// all targets are far away, choose the closest one
|
||||||
|
return botAI->GetBot()->GetDistance(new_unit) < botAI->GetBot()->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* DpsTargetValue::Calculate()
|
||||||
{
|
{
|
||||||
Unit* rti = RtiTargetValue::Calculate();
|
Unit* rti = RtiTargetValue::Calculate();
|
||||||
@@ -131,8 +185,11 @@ Unit* DpsTargetValue::Calculate()
|
|||||||
|
|
||||||
// FindLeastHpTargetStrategy strategy(botAI);
|
// FindLeastHpTargetStrategy strategy(botAI);
|
||||||
float dps = AI_VALUE(float, "expected group dps");
|
float dps = AI_VALUE(float, "expected group dps");
|
||||||
FindTargetSmartStrategy strategy(botAI, dps);
|
if (botAI->IsCaster(bot)) {
|
||||||
// FindMaxThreatGapTargetStrategy strategy(botAI);
|
CasterFindTargetSmartStrategy strategy(botAI, dps);
|
||||||
|
return TargetValue::FindTarget(&strategy);
|
||||||
|
}
|
||||||
|
NonCasterFindTargetSmartStrategy strategy(botAI, dps);
|
||||||
return TargetValue::FindTarget(&strategy);
|
return TargetValue::FindTarget(&strategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user