Skip to content

怪物批次

将一组怪物作为一个批次管理,支持追加生成、追击玩家、数量查询和清理。波次、补怪频率、胜负条件由普通脚本控制,参见玩法示例

兼容性: 本页均为 GOW-Next 新增接口,不属于原版兼容接口。

使用约定

  • 当前仅支持动态房间中的 NPC 脚本上下文,包括房间控制 NPC 及其延迟回调。
  • 批次属于当前房间,句柄使用 Int64。房间回收或脚本重载后不可继续使用旧句柄。
  • 存活上限不是累计生成上限。怪物死亡或被清理后,可以再次追加;引擎不会自动补怪。
  • 正常击杀按怪物配置掉落。裁剪、清空、释放属于移除,不触发击杀掉落。
  • 以下示例中的 BatchValueInt64AddedStatusCountInteger

MonsterBatchCreate

用途: 在当前动态房间创建空批次。

pascal
function MonsterBatchCreate(Context: TCreature; MaxAlive: Integer): Int64;
参数说明
Context当前房间中的玩家或 NPC,用于确定所属房间
MaxAlive批次存活上限,范围 1..2000

返回批次句柄,失败返回 0。怪物还受房间和全局容量限制。

pascal
Batch := MonsterBatchCreate(This_Player, 100);

MonsterBatchAdd

用途: 向已有批次追加怪物,返回本次实际生成数量。

pascal
function MonsterBatchAdd(Batch: Int64; const MonName: string;
  Count, X, Y, InnerRadius, OuterRadius: Integer;
  var Status: Integer): Integer;
参数说明
Batch批次句柄
MonName怪物数据库中的名称
Count本次请求数量,范围 0..128
XY生成区域中心坐标
InnerRadiusOuterRadius内外半径,满足 0 <= InnerRadius <= OuterRadius
Status输出状态,见下表

区域按方形格距计算,包含边界;两个半径均为 0 时只尝试中心点。只在可用落点生成。

返回非负数表示实际生成数量;负数表示失败,具体原因查看 Status。容量、落点或共享生成预算不足时,可能只生成一部分,甚至为 0;剩余数量不会自动排队。

Status 常量含义
MONSTER_BATCH_STATUS_COMPLETE请求完成
MONSTER_BATCH_STATUS_BUDGET本轮生成预算不足
MONSTER_BATCH_STATUS_CAP达到容量上限
MONSTER_BATCH_STATUS_POSITIONS可用落点不足
MONSTER_BATCH_STATUS_INVALID_ARGUMENTS参数错误
MONSTER_BATCH_STATUS_INVALID_BATCH批次无效或不属于当前上下文
MONSTER_BATCH_STATUS_UNSUPPORTED_MONSTER怪物不存在或不支持
pascal
Added := MonsterBatchAdd(Batch, '半兽人', 8, 100, 100, 10, 16, Status);

MonsterAttributes

用途: 构造怪物出生属性,全部字段默认 -1,表示继承怪物模板。

pascal
function MonsterAttributes: TMonsterAttributes;
字段含义
MaxHP最大生命,设置时必须为正数,怪物满血出生
ACMAC防御、魔防
DCMaxDC攻击下限、上限,合并模板后下限不能超过上限
MCSC魔法、道术
AgilityAccuracy敏捷、命中,设置范围 0..65535
AttackIntervalMsMoveIntervalMs攻击、移动间隔,毫秒,设置范围 1..2147483647

所有字段为 Int64。除生命和间隔外,0 是有效覆盖值;小于 -1 为非法参数。先调用构造函数,再设置需要覆盖的字段,不要直接使用未初始化的记录。

pascal
var Attr: TMonsterAttributes;
begin
  Attr := MonsterAttributes;
  Attr.MaxHP := 5000;
  Attr.AC := 0;
end;

MonsterBatchAddEx

用途: 按指定属性追加怪物;数量、生成区域、返回值及状态与 MonsterBatchAdd 相同。

pascal
function MonsterBatchAddEx(Batch: Int64; const MonName: string;
  Count, X, Y, InnerRadius, OuterRadius: Integer;
  const Attr: TMonsterAttributes; var Status: Integer): Integer;

Attr 仅影响本次生成,不修改数据库或已有怪物。属性非法时返回负数,StatusMONSTER_BATCH_STATUS_INVALID_ARGUMENTS,本次不生成怪物。

pascal
Added := MonsterBatchAddEx(Batch, '半兽人', 8,
  100, 100, 10, 16, Attr, Status);

MonsterBatchSetTarget

用途: 设置批次怪物追击的玩家,对已有和后续追加的怪物均生效。

pascal
function MonsterBatchSetTarget(Batch: Int64; Target: TPlayer): Boolean;

Target 应为同地图中有效、存活的玩家;传入 nil 解除强制目标,恢复普通 AI。返回是否设置成功。当前不支持指定怪物或建筑作为目标,也不提供跨地图追击。

pascal
MonsterBatchSetTarget(Batch, This_Player);

MonsterBatchGetStat

用途: 查询批次统计。

pascal
function MonsterBatchGetStat(Batch: Int64; Stat: Integer;
  var Value: Int64): Boolean;

Batch 为句柄,Stat 为下表常量,Value 接收结果。返回 False 表示查询失败,此时 Value0,不能当作清怪完成。

Stat 常量Value 含义
MONSTER_BATCH_STAT_ALIVE当前存活数量
MONSTER_BATCH_STAT_SPAWNED累计实际生成数量
MONSTER_BATCH_STAT_DEATHS累计死亡数量,不等同于某个玩家的击杀数
MONSTER_BATCH_STAT_REMOVED累计非死亡移除数量
MONSTER_BATCH_STAT_TARGET_VALID追击目标是否有效,1 有效、0 无效
pascal
if MonsterBatchGetStat(Batch, MONSTER_BATCH_STAT_ALIVE, Value) then
begin
  // 使用 Value 判断当前存活数量
end;

MonsterBatchCountNear

用途: 统计中心附近的批次存活怪物。

pascal
function MonsterBatchCountNear(Batch: Int64;
  X, Y, Radius: Integer): Integer;

XY 为中心,Radius 为非负方形格距半径,包含边界。返回数量,失败返回负数;不统计其他批次或普通刷出的怪物。

pascal
Count := MonsterBatchCountNear(Batch, 100, 100, 16);

MonsterBatchTrimOutside

用途: 移除指定范围外的批次存活怪物。

pascal
function MonsterBatchTrimOutside(Batch: Int64;
  X, Y, Radius: Integer): Integer;

参数含义与 MonsterBatchCountNear 相同。返回移除数量,失败返回负数。边界内怪物保留,累计统计不清零。

pascal
Count := MonsterBatchTrimOutside(Batch, 100, 100, 24);

MonsterBatchClear

用途: 清理批次怪物和尸体,但保留批次,方便下一波继续使用。

pascal
function MonsterBatchClear(Batch: Int64): Integer;

Batch 为句柄。返回移除的存活怪物数量,失败返回负数。追击目标和累计统计保留。

pascal
Count := MonsterBatchClear(Batch);

MonsterBatchRelease

用途: 清理并释放批次。

pascal
function MonsterBatchRelease(Batch: Int64): Boolean;

Batch 为句柄。返回是否成功;释放后原句柄不可再用。

pascal
MonsterBatchRelease(Batch);
Batch := 0;

GOW-Next 引擎开发手册 · 原版 API 兼容列表持续核验中