魔兽3.3.5仇恨列表模块解析

发布时间:2024年01月08日

一、涉及文件

  • 涉及文件
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 最小距离

二、仇恨列表模块调用API

1)总体集成到UnitAI类的SelectTargetList接口

  • 参数解释
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);
}
文章来源:https://blog.csdn.net/weixin_43679037/article/details/135452604
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。