自定义对话主题 (Chemdah 开发者文档)
来自Purtmars Wikipedia —— 普特莫斯维基
目录
- Chemdah
- 开始
- 基本
- 事件
- ink.ptms.chemdah.api.event.collect.ConversationEvents
- ink.ptms.chemdah.api.event.collect.ObjectiveEvents
- ink.ptms.chemdah.api.event.collect.PlayerEvents
- ink.ptms.chemdah.api.event.collect.QuestEvents
- ink.ptms.chemdah.api.event.collect.TemplateEvents
- ink.ptms.chemdah.api.event.InferEntityHookEvent
- ink.ptms.chemdah.api.event.InferItemHookEvent
- ink.ptms.chemdah.api.event.PartyHookEvent
- 对话相关
- 数据相关
- 任务相关
对话主题
注册自定义对话主题需要分别实现 Theme 与 ThemeSettings 类,在本章文档中我们会从零开始注册一个简单的聊天框对话主题。
ink.ptms.chemdah.core.conversation.theme.Theme
/**
* 注册到 ChemdahAPI 中
*/
fun register(name)
/**
* 当配置文件被重载
* 使用时必须调用 super.reloadConfig()
*/
open fun reloadConfig()
/**
* 是否支持告别
* 即结束对话时使用 talk 语句创建没有回复的对话信息
* 在原版 chat 对话模式中支持告别,而 chest 不支持(会被转换为 Holographic 信息)
*/
open fun allowFarewell()
/**
* 重置会话时(即 begin 之前)
* 在原版 chat 对话模式中用于归位玩家所选择的回复序号,而 chest 中没有使用
*/
open fun reset(session: Session): CompletableFuture
/**
* 会话开始之前,在原版 chat 对话模式中用于播放音效特效等
* 使用时必须返回 super.begin(session)
*/
open fun begin(session: Session): CompletableFuture
/**
* 会话结束时,目前未被使用
*/
open fun end(session: Session): CompletableFuture
/**
* 初始化对话配置文件
*/
abstract fun getConfig(): T
/**
* 会话渲染时
* @param canReply 是否可以回复
*/
abstract fun npcTalk(session: Session, message: List, canReply: Boolean = true): CompletableFuture
实现
继承 Theme 与 ThemeSettings 类,并实现部分简单的逻辑。
class ThemeDemoSettings(root: ConfigurationSection) : ThemeSettings(root)
class ThemeDemo : Theme() {
/**
* 初始化配置文件,并将其指向 plugins/Chemdah/core/conversation.yml 文件
*/
override fun getConfig(): ThemeDemoSettings {
return ThemeDemoSettings(ConversationManager.conf.getConfigurationSection("theme-demo")!!)
}
/**
* 对话开始之前,在 NPC 头顶播放一团粒子,示意 NPC 正在发言
*/
override fun begin(session: Session): CompletableFuture {
// 粒子播放行为
Effects.create(Particle.CLOUD, session.origin.clone().add(0.0, 0.5, 0.0)).count(5).player(session.player).play()
// 必须返回这段代码,否则需要自行实现父类逻辑
return super.begin(session)
}
override fun display(session: Session, message: List, canReply: Boolean): CompletableFuture {
TODO("Not yet implemented")
}
}
接下来的渲染 NPC 发言是至关重要的部分,在 npcTalk 方法中提供了一个 message 参数代表 NPC 说的话。我们不需要再做任何处理。需要注意的是玩家的任何回复都可能存在条件判断,所以无论是渲染还是在执行回复时都需要进行条件判断,以免发生越权行为。