普特莫斯维基 (Purtmars Wikipedia 📖)

自定义对话主题 (Chemdah 开发者文档)

来自Purtmars Wikipedia —— 普特莫斯维基
Bkm016讨论 | 贡献2021年5月5日 (三) 23:43的版本 →‎对话主题

目录

对话主题

注册自定义对话主题需要分别实现 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

实现

首先继承 ThemeSettings 类,若没有特殊需求则不需要额外读取数据。数据来源由 Theme 类决定,可自行定义。

class ThemeDemoSettings(root: ConfigurationSection) : ThemeSettings(root)

其次继承 Theme 类,并进行注册与配置定义。

class ThemeDemo : Theme() {

    init {
        // 注册 demo 对话风格到插件
        register("demo")
    }
    
    /**
     * 初始化配置文件,并将其指向 plugins/Chemdah/core/conversation.yml 文
     */
    override fun getConfig(): ThemeDemoSettings {
        return ThemeDemoSettings(ConversationManager.conf.getConfigurationSection("theme-demo")!!)
    }

    override fun npcTalk(session: Session, message: List, canReply: Boolean): CompletableFuture {
        TODO("Not yet implemented")
    }
}