ThreatManager.h
ThreatManager --仇恨管理类
ThreatReference --仇恨列表
// Selection method used by SelectTarget
enum class SelectTargetMethod
{
Random, // just pick a random target
MaxThreat, // prefer targets higher in the threat list
MinThreat, // prefer targets lower in the threat list
MaxDistance, // prefer targets further from us
MinDistance // prefer targets closer to us
};
random 随机
MaxThreat 最大仇恨
MinThreat 最小仇恨
MaxDistance 最大距离
MinDistance 最小距离
void UnitAI::SelectTargetList(std::list<Unit*>& targetList, uint32 num,
SelectTargetMethod targetType, uint32 offset, float dist,
bool playerOnly, bool withTank, int32 aura)
①targetList:传出参数-获取的目标列表
②num: 需要获取的数量
③SelectTargetMethod : 选择目标的类型-例如最大仇恨往下递减找目标
④offset:点名往后偏移几位-例如点最大仇恨,往下偏移
⑤dist:距离
⑥playerOnly:只揍玩家
⑦withTank:是否包含第一仇恨
⑧aura:
这段代码用于检查生物身上是否存在特定的光环效果。如果 aura 变量为正值,则要求目标生物必须拥有具有相同 ID 的光环效果;如果为负值,则要求目标生物必须没有具有相同 ID 的光环效果。如果条件不满足,则返回 false。这样的设计可用于执行与特定光环效果相关的条件检查
1)找到最大仇恨的前两位,带主T,不限obj
std::list<Unit*> unitList;
SelectTargetList(unitList, 2, SelectTargetMethod::MaxThreat, 0, 0.0f, false);
if (unitList.size() > 1)
DoCast(SelectTarget(SelectTargetMethod::MaxThreat, 0, 100, true), SPELL_WILL_OF_HAKKAR);
2)找到倒数的5位仇恨的玩家,包括主T
std::list<Unit*> playerList;
SelectTargetList(playerList, 5, SelectTargetMethod::MaxThreat, 0, 0.0f, true);
3)取仇恨列表的玩家
①ranged:随机取25个战斗距离为5的玩家,默认有T
②melee:随机取25个战斗距离为5的玩家,默认有T
std::list<Unit*> ranged, melee;
uint32 minTargets = RAID_MODE<uint32>(3, 8, 3, 8);
SelectTargetList(ranged, 25, SelectTargetMethod::Random, 0, -5.0f, true);
SelectTargetList(melee, 25, SelectTargetMethod::Random, 0, 5.0f, true);
4)随机取3个玩家,不带主T
std::list<Unit*> targets;
SelectTargetList(targets, 3, SelectTargetMethod::Random, 0, 0.0f, true, false);
void UnitAI::SelectTargetList(std::list<Unit*>& targetList, uint32 num, SelectTargetMethod targetType, uint32 offset, float dist, bool playerOnly, bool withTank, int32 aura)
{
SelectTargetList(targetList, num, targetType, offset, DefaultTargetSelector(me, dist, playerOnly, withTank, aura));
}
--------------------------------------------------
template <class PREDICATE>
void SelectTargetList(std::list<Unit*>& targetList, uint32 num, SelectTargetMethod targetType, uint32 offset, PREDICATE const& predicate)
{
if (!PrepareTargetListSelection(targetList, targetType, offset))
return;
// then finally filter by predicate
targetList.remove_if([&predicate](Unit* target) { return !predicate(target); });
FinalizeTargetListSelection(targetList, num, targetType);
}