<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[深入浅出制作全自动Mud机器人-对象列表]]></title><description><![CDATA[<p dir="auto">对象(Object)是Mud底层 的Mudos/Fluffos的核心概念。</p>
<p dir="auto">每个房间/npc/道具都是一个Object,每个Object 内能包含一系列其他Object的列表。</p>
<p dir="auto">所以，作为一个针对运行在Mudos/Fluffos上的机器人，必然需要面对大量的Object的处理。</p>
<p dir="auto">我在newhelljs中创建了一个Object类来专门处理这个问题</p>
<p dir="auto"><a href="https://github.com/hellclient-scripts/newhelljs/blob/main/script/helllibjs/object/object.js" target="_blank" rel="noopener noreferrer nofollow ugc">代码地址</a></p>
<p dir="auto">代码中对应了两种概念</p>
<p dir="auto"><strong>Object对象</strong></p>
<p dir="auto">Object对象中包括了 Label(显示的名字),ID(物品ID),IDLower(小写化的ID),惰性加载的 数量，单位，名字，依据可选的Param</p>
<p dir="auto">对应的就是Mud中最基本的Object概念。</p>
<p dir="auto">不论房间中的对象，还是身上的道具，都抽象成这样的一个标准类。</p>
<p dir="auto"><strong>List对象类表</strong></p>
<p dir="auto">对象列表是一个非常实用的类。</p>
<p dir="auto">它除了用来放置所有的Object对象外，还提供了一些快速的查找过滤的方法</p>
<ul>
<li>FindByID 通过ID(大小写敏感)查找</li>
<li>FindByIDLower 通过ID(大小写不敏感)查找</li>
<li>FindByKey 通过特意制定的Key查找</li>
<li>FindByLabel 通过显示的标签(带数量)查找</li>
<li>FindByName 通过解析后的不带数量的名字查找</li>
<li>SearchByName 部分匹配不带数量名字查找</li>
<li>SearchByLabel 部分匹配带数量名字查找</li>
<li>SearchByID 部分匹配id查找</li>
<li>ExcludeID 排除ID查找</li>
<li>FindByFilter 自定义过滤函数查找</li>
</ul>
<p dir="auto">以及一些快速方法</p>
<ul>
<li>First 返回列表中的一个元素</li>
<li>Last 返回列表中的最后一个元素</li>
<li>Sum 统计列表中的数量总和</li>
</ul>
<p dir="auto">来覆盖了绝大部分Mud任务的需求。</p>
<p dir="auto">毕竟本质上，由于Mud底层的实现，除了解密类任务，大部分任务主要就是针对道具，以及房间中的 NPC进行交互。</p>
<p dir="auto">只要能及时把身上的道具和房间里的NPC抽象为Object和List,做对应的任务可以说易如反掌。</p>
<p dir="auto"><a href="https://github.com/hellclient-scripts/newhelljs/blob/main/script/core/item.js" target="_blank" rel="noopener noreferrer nofollow ugc">道具处理代码参考</a></p>
<pre><code class="language-javascript">    let matcheritem = /^(  |□|○)(.+)\(([^\(\)]+)\)$/
    let matcherend = /^目前携带了(.+)件物品。$/
    //道具统计的计划
    let PlanOnItem = new App.Plan(
        App.Positions.Connect,
        function (task) {
            let data = {}
            task.AddTrigger(matcheritem, function (task, result, event) {
                let item = new objectModule.Object(result[2], result[3], App.History.CurrentOutput)
                let index = data[item.IDLower]
                if (index == null) {
                    index = 1
                }
                switch (result[1]) {
                    case "□":
                        item.Mode = 1
                        break
                    case "○":
                        item.Mode = 2
                        break
                    default:
                        item.Mode = 0
                }
                item.WithKey(item.IDLower + " " + index)
                App.Data.Item.List.Append(item)
                data[item.IDLower] = index + 1
                return true
            })
            task.AddTrigger(matcherend, function (task, result, event) {
                App.Data.Item.Count = objectModule.CNumber.ParseNumber(result[1])
            })
        },
        function (result) {
            checkerI.Reset()
        },
    )
...
</code></pre>
<p dir="auto"><a href="https://github.com/hellclient-scripts/newhelljs/blob/main/script/core/room.js" target="_blank" rel="noopener noreferrer nofollow ugc">房间NPC处理代码参考</a></p>
<pre><code class="language-javascript">    let matcherOnHeal = /^    (\S{2,8})正坐在地下(.+)。$/
    let matcherOnYanlian = /^    (\S{2,8})正在演练招式。$/
    let matcherOnObj = /^    ((\S+) )?(\S*[「\(].+[\)」])?(\S+)\(([^\(\)]+)\)( \[.+\])?(( &lt;.+&gt;)*)$/
    //处理得到出口之后的信息(npc和道具列表)的计划
    var PlanOnExit = new App.Plan(App.Positions.Connect,
        function (task) {
            task.AddTrigger(matcherOnObj, function (trigger, result, event) {
                let item = new objectModule.Object(result[4], result[5], App.History.CurrentOutput).
                    WithParam("身份", result[2]).
                    WithParam("外号", result[3]).
                    WithParam("描述", result[6] || "").
                    WithParam("状态", result[7] || "").
                    WithParam("动作", "")
                App.Map.Room.Data.Objects.Append(item)
                event.Context.Set("core.room.onobject", true)
                return true
            })
            task.AddTrigger(matcherOnHeal, function (trigger, result, event) {
                let item = new objectModule.Object(result[1], "", App.History.CurrentOutput).
                    WithParam("动作", result[2])
                App.Map.Room.Data.Objects.Append(item)
                event.Context.Set("core.room.onobject", true)
                return true
            })
            task.AddTrigger(matcherOnYanlian, function (trigger, result, event) {
                let item = new objectModule.Object(result[1], "", App.History.CurrentOutput).
                    WithParam("动作", "演练招式")
                App.Map.Room.Data.Objects.Append(item)
                event.Context.Set("core.room.onobject", true)
                return true
            })

            task.AddCatcher("line", function (catcher, event) {
                let output = event.Data.Output
                if (output.length &gt; 4 &amp;&amp; output.startsWith("    ") &amp;&amp; output[4] != " ") {
                    return true
                }
                //未匹配过的行代表npc和道具结束
                return event.Context.Get("core.room.onobject")
            })
...
</code></pre>
]]></description><link>https://forum.hellclient.com/topic/34/深入浅出制作全自动mud机器人-对象列表</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Jul 2026 20:24:57 GMT</lastBuildDate><atom:link href="https://forum.hellclient.com/topic/34.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 03 Feb 2026 10:42:03 GMT</pubDate><ttl>60</ttl></channel></rss>