<h1>Achievements<aclass="headerlink"href="#achievements"title="Permalink to this headline">¶</a></h1>
<p>A simple, but reasonably comprehensive, system for tracking achievements. Achievements are defined using ordinary Python dicts, reminiscent of the core prototypes system, and while it’s expected you’ll use it only on Characters or Accounts, they can be tracked for any typeclassed object.</p>
<p>The contrib provides several functions for tracking and accessing achievements, as well as a basic in-game command for viewing achievement status.</p>
<sectionid="installation">
<h2>Installation<aclass="headerlink"href="#installation"title="Permalink to this headline">¶</a></h2>
<p>This contrib requires creation one or more module files containing your achievement data, which you then add to your settings file to make them available.</p>
<blockquote>
<div><p>See the section below on “Creating Achievements” for what to put in this module.</p>
</div></blockquote>
<divclass="highlight-python notranslate"><divclass="highlight"><pre><span></span><spanclass="c1"># in server/conf/settings.py</span>
<p>To allow players to check their achievements, you’ll also want to add the <codeclass="docutils literal notranslate"><spanclass="pre">achievements</span></code> command to your default Character and/or Account command sets.</p>
<divclass="highlight-python notranslate"><divclass="highlight"><pre><span></span><spanclass="c1"># in commands/default_cmdsets.py</span>
<p><strong>Optional</strong> - The achievements contrib stores individual progress data on the <codeclass="docutils literal notranslate"><spanclass="pre">achievements</span></code> attribute by default, visible via <codeclass="docutils literal notranslate"><spanclass="pre">obj.db.achievements</span></code>. You can change this by assigning an attribute (key, category) tuple to the setting <codeclass="docutils literal notranslate"><spanclass="pre">ACHIEVEMENT_CONTRIB_ATTRIBUTE</span></code></p>
<h2>Creating achievements<aclass="headerlink"href="#creating-achievements"title="Permalink to this headline">¶</a></h2>
<p>An achievement is represented by a simple python dictionary defined at the module level in your achievements module(s).</p>
<p>Each achievement requires certain specific keys to be defined to work properly, along with several optional keys that you can use to override defaults.</p>
<blockquote>
<div><p>Note: Any additional keys not described here are included in the achievement data when you access those acheivements through the contrib, so you can easily add your own extended features.</p>
</div></blockquote>
<sectionid="required-keys">
<h3>Required keys<aclass="headerlink"href="#required-keys"title="Permalink to this headline">¶</a></h3>
<ulclass="simple">
<li><p><strong>name</strong> (str): The searchable name for the achievement. Doesn’t need to be unique.</p></li>
<li><p><strong>category</strong> (str): The category, or general type, of condition which can progress this achievement. Usually this will be a player action or result. e.g. you would use a category of “defeat” on an achievement for killing 10 rats.</p></li>
<li><p><strong>tracking</strong> (str or list): The specific subset of condition which can progress this achievement. e.g. you would use a tracking value of “rat” on an achievement for killing 10 rats. An achievement can also track multiple things, for example killing 10 rats or snakes. For that situation, assign a list of all the values to check against, e.g. <codeclass="docutils literal notranslate"><spanclass="pre">["rat",</span><spanclass="pre">"snake"]</span></code></p></li>
</ul>
</section>
<sectionid="optional-keys">
<h3>Optional keys<aclass="headerlink"href="#optional-keys"title="Permalink to this headline">¶</a></h3>
<ulclass="simple">
<li><p><strong>key</strong> (str): <em>Default value if unset: the variable name.</em> The unique, case-insensitive key identifying this achievement.</p></li>
</ul>
<blockquote>
<div><p>Note: If any achievements have the same unique key, only <em>one</em> will be loaded. It is case-insensitive, but punctuation is respected - “ten_rats”, “Ten_Rats” and “TEN_RATS” will conflict, but “ten_rats” and “ten rats” will not.</p>
</div></blockquote>
<ulclass="simple">
<li><p><strong>desc</strong> (str): A longer description of the achievement. Common uses for this would be flavor text or hints on how to complete it.</p></li>
<li><p><strong>count</strong> (int): <em>Default value if unset: 1</em> The number of tallies this achievement’s requirements need to build up in order to complete the achievement. e.g. killing 10 rats would have a <codeclass="docutils literal notranslate"><spanclass="pre">"count"</span></code> value of <codeclass="docutils literal notranslate"><spanclass="pre">10</span></code>. For achievements using the “separate” tracking type, <em>each</em> item being tracked must tally up to this number to be completed.</p></li>
<li><p><strong>tracking_type</strong> (str): <em>Default value if unset: <codeclass="docutils literal notranslate"><spanclass="pre">"sum"</span></code></em> There are two valid tracking types: “sum” (which is the default) and “separate”. <codeclass="docutils literal notranslate"><spanclass="pre">"sum"</span></code> will increment a single counter every time any of the tracked items match. <codeclass="docutils literal notranslate"><spanclass="pre">"separate"</span></code> will have a counter for each individual item in the tracked items. (“See the Example Achievements” section for a demonstration of the difference.)</p></li>
<li><p><strong>prereqs</strong> (str or list): The <em>keys</em> of any achievements which must be completed before this achievement can start tracking progress.</p></li>
</ul>
</section>
<sectionid="example-achievements">
<h3>Example achievements<aclass="headerlink"href="#example-achievements"title="Permalink to this headline">¶</a></h3>
<p>A simple achievement which you can get just for logging in the first time. This achievement has no prerequisites and it only needs to be fulfilled once to complete.</p>
<divclass="highlight-python notranslate"><divclass="highlight"><pre><span></span><spanclass="c1"># This achievement has the unique key of "first_login_achieve"</span>
<spanclass="s2">"name"</span><spanclass="p">:</span><spanclass="s2">"Welcome!"</span><spanclass="p">,</span><spanclass="c1"># the searchable, player-friendly display name</span>
<spanclass="s2">"desc"</span><spanclass="p">:</span><spanclass="s2">"We're glad to have you here."</span><spanclass="p">,</span><spanclass="c1"># the longer description</span>
<spanclass="s2">"category"</span><spanclass="p">:</span><spanclass="s2">"login"</span><spanclass="p">,</span><spanclass="c1"># the type of action this tracks</span>
<spanclass="s2">"tracking"</span><spanclass="p">:</span><spanclass="s2">"first"</span><spanclass="p">,</span><spanclass="c1"># the specific login action</span>
<spanclass="p">}</span>
</pre></div>
</div>
<p>An achievement for killing a total of 10 rats, and another for killing 10 <em>dire</em> rats which requires the “kill 10 rats” achievement to be completed first. The dire rats achievement won’t begin tracking <em>any</em> progress until the first achievement is completed.</p>
<divclass="highlight-python notranslate"><divclass="highlight"><pre><span></span><spanclass="c1"># This achievement has the unique key of "ten_rats" instead of "achieve_ten_rats"</span>
<spanclass="s2">"desc"</span><spanclass="p">:</span><spanclass="s2">"Why do all these inns have rat problems?"</span><spanclass="p">,</span>
<spanclass="s2">"name"</span><spanclass="p">:</span><spanclass="s2">"Once More, But Bigger"</span><spanclass="p">,</span>
<spanclass="s2">"desc"</span><spanclass="p">:</span><spanclass="s2">"Somehow, normal rats just aren't enough any more."</span><spanclass="p">,</span>
<p>An achievement for buying a total of 5 of apples, oranges, <em>or</em> pears. The “sum” tracking types means that all items are tallied together - so it can be completed by buying 5 apples, or 5 pears, or 3 apples, 1 orange and 1 pear, or any other combination of those three fruits that totals to 5.</p>
<spanclass="s2">"name"</span><spanclass="p">:</span><spanclass="s2">"A Fan of Fruit"</span><spanclass="p">,</span><spanclass="c1"># note, there is no desc here - that's allowed!</span>
<spanclass="s2">"tracking_type"</span><spanclass="p">:</span><spanclass="s2">"sum"</span><spanclass="p">,</span><spanclass="c1"># this is the default, but it's included here for clarity</span>
<spanclass="p">}</span>
</pre></div>
</div>
<p>An achievement for buying 5 <em>each</em> of apples, oranges, and pears. The “separate” tracking type means that each of the tracked items is tallied independently of the other items - so you will need 5 apples, 5 oranges, and 5 pears.</p>
<spanclass="s2">"desc"</span><spanclass="p">:</span><spanclass="s2">"One kind of fruit just isn't enough."</span><spanclass="p">,</span>
<h2>Usage<aclass="headerlink"href="#usage"title="Permalink to this headline">¶</a></h2>
<p>The two main things you’ll need to do in order to use the achievements contrib in your game are <strong>tracking achievements</strong> and <strong>getting achievement information</strong>. The first is done with the function <codeclass="docutils literal notranslate"><spanclass="pre">track_achievements</span></code>; the second can be done with <codeclass="docutils literal notranslate"><spanclass="pre">search_achievement</span></code> or <codeclass="docutils literal notranslate"><spanclass="pre">get_achievement</span></code>.</p>
<sectionid="tracking-achievements">
<h3>Tracking achievements<aclass="headerlink"href="#tracking-achievements"title="Permalink to this headline">¶</a></h3>
<sectionid="track-achievements">
<h4><codeclass="docutils literal notranslate"><spanclass="pre">track_achievements</span></code><aclass="headerlink"href="#track-achievements"title="Permalink to this headline">¶</a></h4>
<p>In any actions or functions in your game’s mechanics which you might want to track in an achievement, add a call to <codeclass="docutils literal notranslate"><spanclass="pre">track_achievements</span></code> to update that player’s achievement progress.</p>
<p>Using the “kill 10 rats” example achievement from earlier, you might have some code that triggers when a character is defeated: for the sake of example, we’ll pretend we have an <codeclass="docutils literal notranslate"><spanclass="pre">at_defeated</span></code> method on the base Object class that gets called when the Object is defeated.</p>
<p>Adding achievement tracking to it could then look something like this:</p>
<divclass="highlight-python notranslate"><divclass="highlight"><pre><span></span><spanclass="c1"># in typeclasses/objects.py</span>
<p>If a player defeats something tagged <codeclass="docutils literal notranslate"><spanclass="pre">rat</span></code> with a tag category of <codeclass="docutils literal notranslate"><spanclass="pre">mob_type</span></code>, it’d now count towards the rat-killing achievement.</p>
<p>You can also have the tracking information hard-coded into your game, for special or unique situations. The achievement described earlier, <codeclass="docutils literal notranslate"><spanclass="pre">FIRST_LOGIN_ACHIEVE</span></code>, for example, would be tracked like this:</p>
<divclass="highlight-py notranslate"><divclass="highlight"><pre><span></span><spanclass="c1"># in typeclasses/accounts.py</span>
<p>The <codeclass="docutils literal notranslate"><spanclass="pre">track_achievements</span></code> function does also return a value: an iterable of keys for any achievements which were newly completed by that update. You can ignore this value, or you can use it to e.g. send a message to the player with their latest achievements.</p>
</section>
</section>
<sectionid="getting-achievements">
<h3>Getting achievements<aclass="headerlink"href="#getting-achievements"title="Permalink to this headline">¶</a></h3>
<p>The main method for getting a specific achievement’s information is <codeclass="docutils literal notranslate"><spanclass="pre">get_achievement</span></code>, which takes an already-known achievement key and returns the data for that one achievement.</p>
<p>For handling more variable and player-friendly input, however, there is also <codeclass="docutils literal notranslate"><spanclass="pre">search_achievement</span></code>, which does partial matching on not just the keys, but also the display names and descriptions for the achievements.</p>
<sectionid="get-achievement">
<h4><codeclass="docutils literal notranslate"><spanclass="pre">get_achievement</span></code><aclass="headerlink"href="#get-achievement"title="Permalink to this headline">¶</a></h4>
<p>A utility function for retrieving a specific achievement’s data from the achievement’s unique key. It cannot be used for searching, but if you already have an achievement’s key - for example, from the results of <codeclass="docutils literal notranslate"><spanclass="pre">track_achievements</span></code> - you can retrieve its data this way.</p>
</section>
<sectionid="example">
<h4>Example:<aclass="headerlink"href="#example"title="Permalink to this headline">¶</a></h4>
<h4><codeclass="docutils literal notranslate"><spanclass="pre">search_achievement</span></code><aclass="headerlink"href="#search-achievement"title="Permalink to this headline">¶</a></h4>
<p>A utility function for searching achievements by name or description. It handles partial matching and returns a dictionary of matching achievements. The provided <codeclass="docutils literal notranslate"><spanclass="pre">achievement</span></code> command for in-game uses this function to find matching achievements from user inputs.</p>
</section>
<sectionid="id1">
<h4>Example:<aclass="headerlink"href="#id1"title="Permalink to this headline">¶</a></h4>
<p>The first example does a search for “fruit”, which returns the fruit medley achievement as it contains “fruit” in the key and name.</p>
<p>The second example searches for “usual”, which returns the ten rats achievement due to its display name.</p>
<spanclass="go">{'ten_rats': {'key': 'ten_rats', 'name': 'The Usual', 'desc': 'Why do all these inns have rat problems?', 'category': 'defeat', 'tracking': 'rat', 'count': 10}}</span>
</pre></div>
</div>
</section>
</section>
<sectionid="the-achievements-command">
<h3>The <codeclass="docutils literal notranslate"><spanclass="pre">achievements</span></code> command<aclass="headerlink"href="#the-achievements-command"title="Permalink to this headline">¶</a></h3>
<p>The contrib’s provided command, <codeclass="docutils literal notranslate"><spanclass="pre">CmdAchieve</span></code>, aims to be usable as-is, with multiple switches to filter achievements by various progress statuses and the ability to search by achievement names.</p>
<p>To make it easier to customize for your own game (e.g. displaying some of that extra achievement data you might have added), the format and style code is split out from the command logic into the <codeclass="docutils literal notranslate"><spanclass="pre">format_achievement</span></code> method and the <codeclass="docutils literal notranslate"><spanclass="pre">template</span></code> attribute, both on <codeclass="docutils literal notranslate"><spanclass="pre">CmdAchieve</span></code></p>
<sectionid="example-output">
<h4>Example output<aclass="headerlink"href="#example-output"title="Permalink to this headline">¶</a></h4>
<p><small>This document page is generated from <codeclass="docutils literal notranslate"><spanclass="pre">evennia/contrib/game_systems/achievements/README.md</span></code>. Changes to this
file will be overwritten, so edit that file rather than this one.</small></p>