mirror of
https://github.com/evennia/evennia.git
synced 2026-03-19 14:26:30 +01:00
266 lines
No EOL
17 KiB
HTML
266 lines
No EOL
17 KiB
HTML
|
||
<!DOCTYPE html>
|
||
|
||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<title>Command Prompt — Evennia 0.9.1 documentation</title>
|
||
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
|
||
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
||
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
|
||
<script src="_static/jquery.js"></script>
|
||
<script src="_static/underscore.js"></script>
|
||
<script src="_static/doctools.js"></script>
|
||
<script src="_static/language_data.js"></script>
|
||
<link rel="index" title="Index" href="genindex.html" />
|
||
<link rel="search" title="Search" href="search.html" />
|
||
|
||
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
|
||
|
||
|
||
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
|
||
|
||
</head><body>
|
||
|
||
|
||
<div class="document">
|
||
<div class="documentwrapper">
|
||
<div class="bodywrapper">
|
||
|
||
|
||
<div class="body" role="main">
|
||
|
||
<div class="section" id="command-prompt">
|
||
<h1>Command Prompt<a class="headerlink" href="#command-prompt" title="Permalink to this headline">¶</a></h1>
|
||
<p>A <em>prompt</em> is quite common in MUDs. The prompt display useful details about your character that you are likely to want to keep tabs on at all times, such as health, magical power etc. It might also show things like in-game time, weather and so on. Many modern MUD clients (including Evennia’s own webclient) allows for identifying the prompt and have it appear in a correct location (usually just above the input line). Usually it will remain like that until it is explicitly updated.</p>
|
||
<div class="section" id="sending-a-prompt">
|
||
<h2>Sending a prompt<a class="headerlink" href="#sending-a-prompt" title="Permalink to this headline">¶</a></h2>
|
||
<p>A prompt is sent using the <code class="docutils literal notranslate"><span class="pre">prompt</span></code> keyword to the <code class="docutils literal notranslate"><span class="pre">msg()</span></code> method on objects. The prompt will be sent without any line breaks.</p>
|
||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="bp">self</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="n">prompt</span><span class="o">=</span><span class="s2">"HP: 5, MP: 2, SP: 8"</span><span class="p">)</span>
|
||
</pre></div>
|
||
</td></tr></table></div>
|
||
<p>You can combine the sending of normal text with the sending (updating of the prompt):</p>
|
||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="bp">self</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="s2">"This is a text"</span><span class="p">,</span> <span class="n">prompt</span><span class="o">=</span><span class="s2">"This is a prompt"</span><span class="p">)</span>
|
||
</pre></div>
|
||
</td></tr></table></div>
|
||
<p>You can update the prompt on demand, this is normally done using <a class="reference internal" href="OOB.html"><span class="doc">OOB</span></a>-tracking of the relevant Attributes (like the character’s health). You could also make sure that attacking commands update the prompt when they cause a change in health, for example.</p>
|
||
<p>Here is a simple example of the prompt sent/updated from a command class:</p>
|
||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||
2
|
||
3
|
||
4
|
||
5
|
||
6
|
||
7
|
||
8
|
||
9
|
||
10
|
||
11
|
||
12
|
||
13
|
||
14
|
||
15
|
||
16
|
||
17
|
||
18
|
||
19
|
||
20
|
||
21
|
||
22
|
||
23
|
||
24
|
||
25
|
||
26
|
||
27
|
||
28
|
||
29
|
||
30
|
||
31
|
||
32
|
||
33
|
||
34
|
||
35
|
||
36</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">Command</span>
|
||
|
||
<span class="k">class</span> <span class="nc">CmdDiagnose</span><span class="p">(</span><span class="n">Command</span><span class="p">):</span>
|
||
<span class="sd">"""</span>
|
||
<span class="sd"> see how hurt your are</span>
|
||
|
||
<span class="sd"> Usage: </span>
|
||
<span class="sd"> diagnose [target]</span>
|
||
|
||
<span class="sd"> This will give an estimate of the target's health. Also</span>
|
||
<span class="sd"> the target's prompt will be updated. </span>
|
||
<span class="sd"> """</span>
|
||
<span class="n">key</span> <span class="o">=</span> <span class="s2">"diagnose"</span>
|
||
|
||
<span class="k">def</span> <span class="nf">func</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="p">:</span>
|
||
<span class="n">target</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">caller</span>
|
||
<span class="k">else</span><span class="p">:</span>
|
||
<span class="n">target</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="p">)</span>
|
||
<span class="k">if</span> <span class="ow">not</span> <span class="n">target</span><span class="p">:</span>
|
||
<span class="k">return</span>
|
||
<span class="c1"># try to get health, mana and stamina</span>
|
||
<span class="n">hp</span> <span class="o">=</span> <span class="n">target</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">hp</span>
|
||
<span class="n">mp</span> <span class="o">=</span> <span class="n">target</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">mp</span>
|
||
<span class="n">sp</span> <span class="o">=</span> <span class="n">target</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">sp</span>
|
||
|
||
<span class="k">if</span> <span class="bp">None</span> <span class="ow">in</span> <span class="p">(</span><span class="n">hp</span><span class="p">,</span> <span class="n">mp</span><span class="p">,</span> <span class="n">sp</span><span class="p">):</span>
|
||
<span class="c1"># Attributes not defined </span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="s2">"Not a valid target!"</span><span class="p">)</span>
|
||
<span class="k">return</span>
|
||
|
||
<span class="n">text</span> <span class="o">=</span> <span class="s2">"You diagnose </span><span class="si">%s</span><span class="s2"> as having "</span> \
|
||
<span class="s2">"</span><span class="si">%i</span><span class="s2"> health, </span><span class="si">%i</span><span class="s2"> mana and </span><span class="si">%i</span><span class="s2"> stamina."</span> \
|
||
<span class="o">%</span> <span class="p">(</span><span class="n">hp</span><span class="p">,</span> <span class="n">mp</span><span class="p">,</span> <span class="n">sp</span><span class="p">)</span>
|
||
<span class="n">prompt</span> <span class="o">=</span> <span class="s2">"</span><span class="si">%i</span><span class="s2"> HP, </span><span class="si">%i</span><span class="s2"> MP, </span><span class="si">%i</span><span class="s2"> SP"</span> <span class="o">%</span> <span class="p">(</span><span class="n">hp</span><span class="p">,</span> <span class="n">mp</span><span class="p">,</span> <span class="n">sp</span><span class="p">)</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">caller</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="n">text</span><span class="p">,</span> <span class="n">prompt</span><span class="o">=</span><span class="n">prompt</span><span class="p">)</span>
|
||
</pre></div>
|
||
</td></tr></table></div>
|
||
</div>
|
||
<div class="section" id="a-prompt-sent-with-every-command">
|
||
<h2>A prompt sent with every command<a class="headerlink" href="#a-prompt-sent-with-every-command" title="Permalink to this headline">¶</a></h2>
|
||
<p>The prompt sent as described above uses a standard telnet instruction (the Evennia web client gets a special flag). Most MUD telnet clients will understand and allow users to catch this and keep the prompt in place until it updates. So <em>in principle</em> you’d not need to update the prompt every command.</p>
|
||
<p>However, with a varying user base it can be unclear which clients are used and which skill level the users have. So sending a prompt with every command is a safe catch-all. You don’t need to manually go in and edit every command you have though. Instead you edit the base command class for your custom commands (like <code class="docutils literal notranslate"><span class="pre">MuxCommand</span></code> in your <code class="docutils literal notranslate"><span class="pre">mygame/commands/command.py</span></code> folder) and overload the <code class="docutils literal notranslate"><span class="pre">at_post_cmd()</span></code> hook. This hook is always called <em>after</em> the main <code class="docutils literal notranslate"><span class="pre">func()</span></code> method of the Command.</p>
|
||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||
2
|
||
3
|
||
4
|
||
5
|
||
6
|
||
7
|
||
8
|
||
9
|
||
10
|
||
11</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">default_cmds</span>
|
||
|
||
<span class="k">class</span> <span class="nc">MuxCommand</span><span class="p">(</span><span class="n">default_cmds</span><span class="o">.</span><span class="n">MuxCommand</span><span class="p">):</span>
|
||
<span class="c1"># ...</span>
|
||
<span class="k">def</span> <span class="nf">at_post_cmd</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||
<span class="s2">"called after self.func()."</span>
|
||
<span class="n">caller</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">caller</span>
|
||
<span class="n">prompt</span> <span class="o">=</span> <span class="s2">"</span><span class="si">%i</span><span class="s2"> HP, </span><span class="si">%i</span><span class="s2"> MP, </span><span class="si">%i</span><span class="s2"> SP"</span> <span class="o">%</span> <span class="p">(</span><span class="n">caller</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">hp</span><span class="p">,</span>
|
||
<span class="n">caller</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">mp</span><span class="p">,</span>
|
||
<span class="n">caller</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">sp</span><span class="p">)</span>
|
||
<span class="n">caller</span><span class="o">.</span><span class="n">msg</span><span class="p">(</span><span class="n">prompt</span><span class="o">=</span><span class="n">prompt</span><span class="p">)</span>
|
||
</pre></div>
|
||
</td></tr></table></div>
|
||
<div class="section" id="modifying-default-commands">
|
||
<h3>Modifying default commands<a class="headerlink" href="#modifying-default-commands" title="Permalink to this headline">¶</a></h3>
|
||
<p>If you want to add something small like this to Evennia’s default commands without modifying them directly the easiest way is to just wrap those with a multiple inheritance to your own base class:</p>
|
||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
|
||
2
|
||
3
|
||
4
|
||
5
|
||
6
|
||
7
|
||
8
|
||
9</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in (for example) mygame/commands/mycommands.py</span>
|
||
|
||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">default_cmds</span>
|
||
<span class="c1"># our custom MuxCommand with at_post_cmd hook</span>
|
||
<span class="kn">from</span> <span class="nn">commands.command</span> <span class="kn">import</span> <span class="n">MuxCommand</span>
|
||
|
||
<span class="c1"># overloading the look command</span>
|
||
<span class="k">class</span> <span class="nc">CmdLook</span><span class="p">(</span><span class="n">default_cmds</span><span class="o">.</span><span class="n">CmdLook</span><span class="p">,</span> <span class="n">MuxCommand</span><span class="p">):</span>
|
||
<span class="k">pass</span>
|
||
</pre></div>
|
||
</td></tr></table></div>
|
||
<p>The result of this is that the hooks from your custom <code class="docutils literal notranslate"><span class="pre">MuxCommand</span></code> will be mixed into the default <code class="docutils literal notranslate"><span class="pre">CmdLook</span></code> through multiple inheritance. Next you just add this to your default command set:</p>
|
||
<div class="highlight-python notranslate"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
|
||
2
|
||
3
|
||
4
|
||
5
|
||
6
|
||
7
|
||
8
|
||
9
|
||
10</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="c1"># in mygame/commands/default_cmdsets.py</span>
|
||
|
||
<span class="kn">from</span> <span class="nn">evennia</span> <span class="kn">import</span> <span class="n">default_cmds</span>
|
||
<span class="kn">from</span> <span class="nn">commands</span> <span class="kn">import</span> <span class="n">mycommands</span>
|
||
|
||
<span class="k">class</span> <span class="nc">CharacterCmdSet</span><span class="p">(</span><span class="n">default_cmds</span><span class="o">.</span><span class="n">CharacterCmdSet</span><span class="p">):</span>
|
||
<span class="c1"># ...</span>
|
||
<span class="k">def</span> <span class="nf">at_cmdset_creation</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||
<span class="c1"># ...</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">mycommands</span><span class="o">.</span><span class="n">CmdLook</span><span class="p">())</span>
|
||
</pre></div>
|
||
</td></tr></table></div>
|
||
<p>This will automatically replace the default <code class="docutils literal notranslate"><span class="pre">look</span></code> command in your game with your own version.</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||
<div class="sphinxsidebarwrapper">
|
||
<div id="searchbox" style="display: none" role="search">
|
||
<h3 id="searchlabel">Quick search</h3>
|
||
<div class="searchformwrapper">
|
||
<form class="search" action="search.html" method="get">
|
||
<input type="text" name="q" aria-labelledby="searchlabel" />
|
||
<input type="submit" value="Go" />
|
||
</form>
|
||
</div>
|
||
</div>
|
||
<script>$('#searchbox').show(0);</script>
|
||
<p><h3><a href="index.html">Table of Contents</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#">Command Prompt</a><ul>
|
||
<li><a class="reference internal" href="#sending-a-prompt">Sending a prompt</a></li>
|
||
<li><a class="reference internal" href="#a-prompt-sent-with-every-command">A prompt sent with every command</a><ul>
|
||
<li><a class="reference internal" href="#modifying-default-commands">Modifying default commands</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<div class="relations">
|
||
<h3>Related Topics</h3>
|
||
<ul>
|
||
<li><a href="index.html">Documentation overview</a><ul>
|
||
</ul></li>
|
||
</ul>
|
||
</div>
|
||
<div role="note" aria-label="source link">
|
||
<!--h3>This Page</h3-->
|
||
<ul class="this-page-menu">
|
||
<li><a href="_sources/Command-Prompt.md.txt"
|
||
rel="nofollow">Show Page Source</a></li>
|
||
</ul>
|
||
</div>
|
||
<h3>Versions</h3>
|
||
<ul>
|
||
<li><a href="../../versions/1.0-dev/index.html">1.0-dev (develop branch)</a></li>
|
||
<li><a href="Command-Prompt.html">0.9.1 (master branch)</a></li>
|
||
</ul>
|
||
|
||
</div>
|
||
</div>
|
||
<div class="clearer"></div>
|
||
</div>
|
||
<div class="footer">
|
||
©2020, The Evennia developer community.
|
||
|
||
|
|
||
Powered by <a href="http://sphinx-doc.org/">Sphinx 2.4.4</a>
|
||
& <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
|
||
|
||
|
|
||
<a href="_sources/Command-Prompt.md.txt"
|
||
rel="nofollow">Page source</a>
|
||
</div>
|
||
|
||
|
||
|
||
|
||
</body>
|
||
</html> |