跳转至内容

PyMUD讨论区

本版可以讨论所有与PyMUD使用有关的内容

此版块可通过社交网络公开平台使用用户名 pymud-discussion@bbs.pymud.cn 进行关注

6 主题 23 帖子
  • 新版功能测试中

    3
    2
    0 赞同
    3 帖子
    40 浏览
    T
    @newstart skills[literate]就是嵌套的字典变量呗?
  • 初步完成状态窗口

    1
    1
    1 赞同
    1 帖子
    9 浏览
    T
    后边慢慢优化 [image: 1767879258627-2555386c-a39e-456b-bf6e-695debf3c628-image-resized.png] # 清华西游记状态栏和状态窗口 import webbrowser, asyncio, ast from pymud import Session, IConfig, alias, trigger, timer, gmcp, exception, Trigger, SimpleTrigger, SimpleAlias, GMCPTrigger, Command from wcwidth import wcswidth from utils.utils import experience_in_M class MyConfig(IConfig): def __init__(self, session: Session, *args, **kwargs) -> None: super().__init__(session, *args, **kwargs) # 将自定义的状态窗口函数赋值给会话的status_maker属性,这样会话就会使用该函数来显示状态信息。 self.session.application.set_status('当前任务:未知') # 未来可以作为当前任务的状态栏 self.session.status_maker = self.status_window def __unload__(self): super().__unload__() # 创建自定义的健康条用作分隔符 def create_status_bar(self, current, maximum, actual_max, bar_length = 20, bar_char = "—"): """ 创建一个健康条,用于显示当前健康值、有效健康值和剩余健康值。 :param current: 当前健康值 :param maximum: 当前最大健康值 :param actual_max: 真实最大值 :param bar_length: 健康条的长度 :param bar_char: 健康条的填充字符 :return: 一个包含健康条的列表 """ # 气血: 1153/ 1702 ( 64%) 内力: 10943 / 5659 (100%) (+360) bar_line = list() char_width = wcswidth(bar_char) # 计算有效健康值 filled_length = int(round(bar_length * current / actual_max / char_width)) # 计算有效健康值部分的长度 current_max_length = int(round(bar_length * maximum / actual_max / char_width)) # 计算剩余部分长度 remaining_length = bar_length - current_max_length # 构造健康条 bar_line.append(("fg:lightcyan", bar_char * filled_length)) bar_line.append(("fg:yellow", bar_char * (current_max_length - filled_length))) bar_line.append(("fg:red", bar_char * remaining_length)) return bar_line # 自定义状态栏窗口。该函数会被渲染框架高频调用,请注意不要在该函数中 info 或者执行其他输出信息!!! def status_window(self): styles = { "title" : "bold", "value" : "lightgreen", "value.better" : "lightcyan", "value.worse" : "yellow", "value.worst" : "red" } try: formatted_list = list() # line 0. hp bar kee = int(self.session.getVariable("kee", 0)) max_kee = int(self.session.getVariable("max_kee", 1)) kee_percent = int(self.session.getVariable("kee_percent", 1)) actual_max_kee = int(round(max_kee / (kee_percent / 100))) sen = int(self.session.getVariable("sen", 0)) max_sen = int(self.session.getVariable("max_sen", 1)) sen_percent = int(self.session.getVariable("sen_percent", 1)) actual_max_sen = int(round(max_sen / (sen_percent / 100))) bar_char = "━" screenwidth = self.session.application.get_width() bar_length = screenwidth // 2 - 1 span = screenwidth - 2 * bar_length kee_bar = self.create_status_bar(kee, max_kee, actual_max_kee, bar_length, bar_char) sen_bar = self.create_status_bar(sen, max_sen, actual_max_sen, bar_length, bar_char) formatted_list.extend(kee_bar) formatted_list.append(("", " " * span)) formatted_list.extend(sen_bar) formatted_list.append(("", "\n")) # line 1. char, family, master, deposit, food, water, exp, pot formatted_list.append((styles["title"], "【角色】")) formatted_list.append((styles["value"], "{0}({1})".format(self.session.getVariable('name'), self.session.getVariable('id')))) formatted_list.append(("", " ")) formatted_list.append((styles["title"], "【门派】")) formatted_list.append((styles["value"], "{}".format(self.session.getVariable('family')))) formatted_list.append(("", " ")) formatted_list.append((styles["title"], "【师父】")) formatted_list.append((styles["value"], "{}".format(self.session.getVariable('master')))) formatted_list.append(("", " ")) formatted_list.append((styles["title"], "【武学】")) formatted_list.append((styles["value"], "{}".format(self.session.getVariable('combat_exp')))) formatted_list.append((styles["value"], "({})".format(experience_in_M(self.session.getVariable('combat_exp'))))) formatted_list.append(("", " ")) formatted_list.append((styles["title"], "【道行】")) formatted_list.append((styles["value"], "{}".format(self.session.getVariable('daoxing_exp')))) formatted_list.append((styles["value"], "({})".format(experience_in_M(self.session.getVariable('daoxing_exp'))))) formatted_list.append(("", " ")) formatted_list.append((styles["title"], "【潜能】")) formatted_list.append((styles["value"], "{}".format(self.session.getVariable('potential')))) # line 2. hp # a new-line formatted_list.append(("", "\n")) formatted_list.append((styles["title"], "【气血】")) if max_kee < actual_max_sen: style = styles["value.worst"] elif kee < 0.8 * max_kee: style = styles["value.worse"] else: style = styles["value"] if max_kee == 0: pct1 = pct2 = 0 else: pct1 = 100.0 * kee / actual_max_kee pct2 = 100.0 * max_kee / actual_max_kee formatted_list.append((style, "{0}[{1:3.0f}%] / {2}[{3:3.0f}%]".format(kee, pct1, max_kee, pct2))) formatted_list.append(("", " ")) formatted_list.append((styles["title"], "【精神】")) if max_sen < actual_max_sen: style = styles["value.worst"] elif sen < 0.8 * max_sen: style = styles["value.worse"] else: style = styles["value"] if max_sen == 0: pct1 = pct2 = 0 else: pct1 = 100.0 * sen / actual_max_sen pct2 = 100.0 * max_sen / actual_max_sen formatted_list.append((style, "{0}[{1:3.0f}%] / {2}[{3:3.0f}%]".format(sen, pct1, max_sen, pct2))) formatted_list.append(("", " ")) formatted_list.append((styles["title"], "【食物】")) food = int(self.session.getVariable('food', '0')) max_food = int(self.session.getVariable('max_food', 350)) if food < 100: style = styles["value.worst"] elif food < 200: style = styles["value.worse"] elif food < max_food: style = styles["value"] else: style = styles["value.better"] formatted_list.append((style, "{0}/{1}".format(food, max_food))) formatted_list.append(("", " ")) formatted_list.append((styles["title"], "【饮水】")) water = int(self.session.getVariable('water', '0')) max_water = int(self.session.getVariable('max_water', 350)) if water < 100: style = styles["value.worst"] elif water < 200: style = styles["value.worse"] elif water < max_water: style = styles["value"] else: style = styles["value.better"] formatted_list.append((style, "{0}/{1}".format(water, max_water))) formatted_list.append(("", " ")) formatted_list.append((styles["title"], "【存款】")) formatted_list.append((styles["value"], "{}金".format(self.session.getVariable('deposit')))) formatted_list.append(("", " ")) # line 3. hp # a new-line formatted_list.append(("", "\n")) force = int(self.session.getVariable("force", 0)) max_force = int(self.session.getVariable("max_force", 1)) mana = int(self.session.getVariable("mana", 0)) max_mana = int(self.session.getVariable("max_mana", 1)) # 内力 formatted_list.append((styles["title"], "【内力】")) if force < 0.6 * max_force: style = styles["value.worst"] elif force < 0.8 * max_force: style = styles["value.worse"] elif force < 1.2 * max_force: style = styles["value"] else: style = styles["value.better"] if max_force == 0: pct = 0 else: pct = 100.0 * force / max_force formatted_list.append((style, "{0} / {1}[{2:3.0f}%]".format(force, max_force, pct))) formatted_list.append(("", " ")) # 精力 formatted_list.append((styles["title"], "【法力】")) if mana < 0.6 * max_mana: style = styles["value.worst"] elif mana < 0.8 * max_mana: style = styles["value.worse"] elif mana < 1.2 * max_mana: style = styles["value"] else: style = styles["value.better"] if max_mana == 0: pct = 0 else: pct = 100.0 * mana / max_mana formatted_list.append((style, "{0} / {1}[{2:3.0f}%]".format(mana, max_mana, pct))) formatted_list.append(("", " ")) return formatted_list except Exception as e: return f"{e}"
  • 如何加载不同模块(.py)?

    12
    0 赞同
    12 帖子
    69 浏览
    T
    哦,我不上xkx的论坛的~~~ 不过这个帖子好像之前搜索pyMud的时候看过, 但现在又忘记了 这记性真不行了
  • 关于多行Trigger的讨论

    5
    0 赞同
    5 帖子
    37 浏览
    N
    很多时候都是这么实现的,比如抓房间描述不确定多少行时,用房间名做首行触发,用出口描述做结束触发,中间再判断是什么。
  • 最近发现一个奇怪的BUG

    bug报告
    1
    0 赞同
    1 帖子
    12 浏览
    N
    不知道为什么,在某些时候,PyMUD启动时偶尔会出现无法识别类型的情况,报错为类似 "Trigger对象不包含session属性" 这种,似乎是不同地方import的Session类型不一致,比如pymud.Session和pymud.session.Session不能被识别为一个类型,因此导致 isinstance(session, Session)判断失败,再进一步就是所有脚本加载均会被认为是从脚本。最终处理都是通过重新处理venv环境、重新指定python版本来解决的,更进一步的原因还没有查到。 不知道各位用户有没有碰到过类似的问题?
  • PyMUD 帮助文档

    1
    0 赞同
    1 帖子
    29 浏览
    T
    https://doc.pymud.cn/