跳到主要内容

默认示例

Monoceros 当前自带了 4 份最关键的示例文件。你可以把它们理解为“最小可运行模板”。

分发器示例

文件:dispatcher/player-join.yml

resource-version: 1
id: player.join.welcome
listen-event: PlayerJoinEvent
listen-priority: NORMAL
weight: 20
execute:
route: script
value: dispatcher.player-join
variables:
triggerSource: join

这个示例演示了:

  • 监听 PlayerJoinEvent
  • 把事件路由到 dispatcher.player-join 脚本
  • 额外注入一个 triggerSource: join 变量

调度示例

文件:schedule/broadcast.yml

resource-version: 1
id: world.tick.broadcast
type: periodic
delay: 20t
period: 200t
auto-start: true
prototype: false
async: false
max-runs: -1
execute:
route: script
value: schedule.world.tick.broadcast
variables:
triggerSource: periodic

这个示例演示了:

  • 一个周期性调度
  • 首次延迟 20t
  • 200t 执行一次
  • 插件加载后自动启动
  • 路由到 schedule.world.tick.broadcast 脚本

数据包示例

文件:wireshark/example.yml

id: example.packet.trace

direction:
- send
- receive

matcher:
type: packet-name
value: PacketPlayOutChat

tracking: true
parse: true
intercept: false

rewrite:
type: field-set
field: b
value: monoceros

route:
type: script
value: debug.packet.trace

这个示例演示了:

  • 同时监听收包和发包
  • 匹配 PacketPlayOutChat
  • 开启追踪和解析
  • 定义一个覆写规则
  • 把命中的数据包交给脚本处理

注意:就算这里写了 rewrite,全局 config.yml 里的 wireshark.allow-rewrite 没开时,也不会真正生效。

动作工作流示例

文件:workflow/action/combat-hit.yml

resource-version: 1
id: combat.hit-feedback
failure-policy: continue
nodes:
- id: log-hit
type: log
message: "战斗命中反馈触发"
- id: set-damage
type: set
key: damage
value: 10
- id: run-script
type: script
script: action.combat.hit-feedback

这个示例演示了:

  • 先记录日志
  • 再把 damage 写进上下文变量
  • 最后调用脚本继续处理

推荐做法

  • 直接复制默认示例,再改 ID 和路由目标
  • 一次只改一个字段,方便排查
  • 改完后立刻用对应命令重载测试

如果你想继续深入某一类资源的字段说明,可以跳转到:

  • ../dispatcher/definition.md
  • ../schedule/definition.md
  • ../wireshark/definition.md
  • ../workflow/action.md