普特莫斯维基 (Purtmars Wikipedia 📖)

“Chemdah 开发者文档:自定义限制器”的版本间的差异

来自Purtmars Wikipedia —— 普特莫斯维基
第25行: 第25行:
  
 
     /**
 
     /**
     * 创建签名
+
     * 创建签名(标记)
 +
    * 例如什么时间接受或完成了任务
 
     */
 
     */
 
     abstract fun signature(profile: PlayerProfile, template: Template)
 
     abstract fun signature(profile: PlayerProfile, template: Template)
第31行: 第32行:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
别忘记注册哦。
+
我相信不需要过多描述这些方法的作用你也能明白,最后别忘记通过 '''TemplateEvents.ControlHook''' 事件注册。
  
 
<syntaxhighlight lang="kotlin" line="line">
 
<syntaxhighlight lang="kotlin" line="line">
override fun onEnable() {
+
 
     ChemdahAPI.addQuestAddon("foo", AddonFoo::class.java)
+
@EventHandler
 +
fun e(e: TemplateEvents.ControlHook) {
 +
     if (e.type == "foo") {
 +
        e.template = ControlFoo(e.map)
 +
    }
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

2021年5月7日 (五) 08:39的版本

目录

自定义限制器

任务限制器是一种特殊的元数据类型,任务管理器会在玩家接受任务之前调用来判断玩家是否能够接受该任务。
目前为止 Chemdah 提供了四种限制器类型分别是:

  • 脚本代理(agent)
  • 冷却(cooldown)
  • 共存(coexist)
  • 重复(repeat)

通过继承 ink.ptms.chemdah.core.quest.meta.MetaControl$Control 类来实现自定义限制器。

abstract class Control {

    /**
     * 是否支持该触发器判断依据(返回空则不支持)
     * 如 cooldown 可以判断是以任务的接受还是完成为依据,而 coexist 则不需要
     */
    abstract val trigger: Trigger?

    /**
     * 玩家是否可以接受该任务
     */
    abstract fun check(profile: PlayerProfile, template: Template): CompletableFuture

    /**
     * 创建签名(标记)
     * 例如什么时间接受或完成了任务
     */
    abstract fun signature(profile: PlayerProfile, template: Template)
}

我相信不需要过多描述这些方法的作用你也能明白,最后别忘记通过 TemplateEvents.ControlHook 事件注册。

@EventHandler
fun e(e: TemplateEvents.ControlHook) {
    if (e.type == "foo") {
        e.template = ControlFoo(e.map)
    }
}