refactor: naxxramas and kel'thuzad strategy

This commit is contained in:
Yunfan Li
2023-07-18 17:58:51 +08:00
parent 7f328b6e32
commit 7c70f42f34
26 changed files with 647 additions and 425 deletions

View File

@@ -4,6 +4,7 @@
#include "AttackerCountValues.h"
#include "Playerbots.h"
#include "SharedDefines.h"
uint8 MyAttackerCountValue::Calculate()
{
@@ -13,80 +14,17 @@ uint8 MyAttackerCountValue::Calculate()
bool HasAggroValue::Calculate()
{
Unit* target = GetTarget();
if (!target)
if (!target) {
return true;
}
Unit* victim = target->GetVictim();
if (!victim) {
return true;
}
if (victim->GetGUID() == bot->GetGUID() || (victim->ToPlayer() && botAI->IsMainTank(victim->ToPlayer()))) {
if (victim && (victim->GetGUID() == bot->GetGUID() || (victim->ToPlayer() && botAI->IsMainTank(victim->ToPlayer())))) {
return true;
}
// botAI->TellMaster("target: " + target->GetName() + " victim: " + victim->GetName());
// if (victim->ToPlayer() ) {
// botAI->TellMaster("victim is mt: " + std::to_string(botAI->IsMainTank(victim->ToPlayer())));
// }
return false;
// HostileReference *ref = bot->getHostileRefMgr().getFirst();
// if (!ref)
// return true; // simulate as target is not atacking anybody yet
// while( ref )
// {
// ThreatMgr *threatManager = ref->GetSource();
// Unit *attacker = threatManager->GetOwner();
// if (attacker->GetGUID() != target->GetGUID()) {
// ref = ref->next();
// continue;
// }
// Unit *victim = attacker->GetVictim();
// if (!victim) {
// return true;
// }
// if ((victim->GetGUID() == bot->GetGUID() || (victim && victim->ToPlayer() && botAI->IsMainTank(victim->ToPlayer()))) &&
// target->GetGUID() == attacker->GetGUID())
// return true;
// ref = ref->next();
// }
// Unit* target = GetTarget();
// if (!target)
// return true;
// HostileReference *ref = bot->getHostileRefMgr().getFirst();
// if (!ref)
// return true; // simulate as target is not atacking anybody yet
// while( ref )
// {
// ThreatMgr* threatMgr = ref->GetSource();
// Unit* attacker = threatMgr->GetOwner();
// Unit* victim = attacker->GetVictim();
// if (victim == bot && target == attacker)
// return true;
// ref = ref->next();
// }
// ref = target->GetThreatMgr().getCurrentVictim();
// if (ref)
// {
// if (Unit* victim = ref->getTarget())
// {
// if (Player* pl = victim->ToPlayer())
// {
// if (botAI->IsMainTank(pl))
// {
// return true;
// }
// }
// }
// }
// return false;
}
uint8 AttackerCountValue::Calculate()

View File

@@ -208,7 +208,7 @@ ItemUsage ItemUsageValue::QueryItemUsageForEquip(ItemTemplate const* itemProto)
float oldScore = PlayerbotFactory::CalculateItemScore(oldItemProto->ItemId, bot);
if (itemScore || oldScore)
{
shouldEquip = itemScore >= oldScore * 1.2;
shouldEquip = itemScore >= oldScore * 1.5;
}
}

View File

@@ -39,3 +39,15 @@ bool NearestVehiclesValue::AcceptUnit(Unit* unit)
return true;
}
void NearestTriggersValue::FindUnits(std::list<Unit*>& targets)
{
Acore::AnyUnfriendlyUnitInObjectRangeCheck u_check(bot, bot, range);
Acore::UnitListSearcher<Acore::AnyUnfriendlyUnitInObjectRangeCheck> searcher(bot, targets, u_check);
Cell::VisitAllObjects(bot, searcher, range);
}
bool NearestTriggersValue::AcceptUnit(Unit* unit)
{
return !unit->IsPlayer();
}

View File

@@ -30,4 +30,13 @@ class NearestVehiclesValue : public NearestUnitsValue
bool AcceptUnit(Unit* unit) override;
};
class NearestTriggersValue : public NearestUnitsValue
{
public:
NearestTriggersValue(PlayerbotAI* botAI, float range = sPlayerbotAIConfig->sightDistance) : NearestUnitsValue(botAI, "nearest triggers", range) { }
protected:
void FindUnits(std::list<Unit*>& targets) override;
bool AcceptUnit(Unit* unit) override;
};
#endif

View File

@@ -19,7 +19,7 @@ class FindTargetStrategy
FindTargetStrategy(PlayerbotAI* botAI) : result(nullptr), botAI(botAI) { }
Unit* GetResult();
virtual void CheckAttacker(Unit* attacker, ThreatMgr* threatMgr) = 0;
virtual void CheckAttacker(Unit* attacker, ThreatMgr* threatMgr) = 0;
void GetPlayerCount(Unit* creature, uint32* tankCount, uint32* dpsCount);
protected:

View File

@@ -85,6 +85,7 @@
#include "TankTargetValue.h"
#include "ThreatValues.h"
#include "TradeValues.h"
#include "Value.h"
class PlayerbotAI;
@@ -289,6 +290,7 @@ class ValueContext : public NamedObjectContext<UntypedValue>
creators["main tank"] = &ValueContext::main_tank;
creators["find target"] = &ValueContext::find_target;
creators["boss target"] = &ValueContext::boss_target;
creators["nearest triggers"] = &ValueContext::nearest_triggers;
}
private:
@@ -483,6 +485,7 @@ class ValueContext : public NamedObjectContext<UntypedValue>
static UntypedValue* main_tank(PlayerbotAI* ai) { return new PartyMemberMainTankValue(ai); }
static UntypedValue* find_target(PlayerbotAI* ai) { return new FindTargetValue(ai); }
static UntypedValue* boss_target(PlayerbotAI* ai) { return new BossTargetValue(ai); }
static UntypedValue* nearest_triggers(PlayerbotAI* ai) { return new NearestTriggersValue(ai); }
};
#endif