fix: typo in test example
This commit is contained in:
parent
98ce816e39
commit
15b1a287d4
1 changed files with 261 additions and 263 deletions
|
|
@ -39,7 +39,6 @@ new character max HP to start.
|
|||
- _Knave_ also have random tables, such as for starting equipment and to see if dying when
|
||||
hitting 0. Death, if it happens, is permanent.
|
||||
|
||||
|
||||
## Making a rule module
|
||||
|
||||
> Create a new module mygame/evadventure/rules.py
|
||||
|
|
@ -48,6 +47,7 @@ hitting 0. Death, if it happens, is permanent.
|
|||
A complete version of the rule module is found in
|
||||
[evennia/contrib/tutorials/evadventure/rules.py](../../../api/evennia.contrib.tutorials.evadventure.rules.md).
|
||||
```
|
||||
|
||||
There are three broad sets of rules for most RPGS:
|
||||
|
||||
- Character generation rules, often only used during character creation
|
||||
|
|
@ -57,7 +57,6 @@ There are three broad sets of rules for most RPGS:
|
|||
We want our `rules` module to cover as many aspeects of what we'd otherwise would have to look up
|
||||
in a rulebook.
|
||||
|
||||
|
||||
## Rolling dice
|
||||
|
||||
We will start by making a dice roller. Let's group all of our dice rolling into a structure like this
|
||||
|
|
@ -94,6 +93,7 @@ class EvAdventureRollEngine:
|
|||
dice = EvAdventureRollEngine()
|
||||
|
||||
```
|
||||
|
||||
```{sidebar}
|
||||
This groups all dice-related code into one 'container' that is easy to import. But it's mostly a matter
|
||||
of taste. You _could_ also break up the class' methods into normal functions at the top-level of the
|
||||
|
|
@ -156,6 +156,7 @@ in a specific range. The line
|
|||
```python
|
||||
sum(randint(1, diesize) for _ in range(number))
|
||||
```
|
||||
|
||||
works like this:
|
||||
|
||||
- For a certain `number` of times ...
|
||||
|
|
@ -223,6 +224,7 @@ have it figure things out:
|
|||
```python
|
||||
result, quality = dice.saving_throw(character, Ability.STR)
|
||||
```
|
||||
|
||||
The return will be a boolean `True/False` if they pass, as well as a `quality` that tells us if
|
||||
a perfect fail/success was rolled or not.
|
||||
|
||||
|
|
@ -379,7 +381,6 @@ number of HPs
|
|||
> Knowing what is available on the character and what rule rolls we need is a bit of a chicken-and-egg
|
||||
> problem. We will make sure to implement the matching _Character_ class next lesson.
|
||||
|
||||
|
||||
### Rolling on a table
|
||||
|
||||
We occasionally need to roll on a 'table' - a selection of choices. There are two main table-types
|
||||
|
|
@ -388,7 +389,7 @@ we need to support:
|
|||
Simply one element per row of the table (same odds to get each result).
|
||||
|
||||
| Result |
|
||||
|:------:|
|
||||
| :----: |
|
||||
| item1 |
|
||||
| item2 |
|
||||
| item3 |
|
||||
|
|
@ -403,7 +404,7 @@ This we will simply represent as a plain list
|
|||
Ranges per item (varying odds per result):
|
||||
|
||||
| Range | Result |
|
||||
|:-----:|:------:|
|
||||
| :---: | :----: |
|
||||
| 1-5 | item1 |
|
||||
| 6-15 | item2 |
|
||||
| 16-19 | item3 |
|
||||
|
|
@ -461,9 +462,11 @@ class EvAdventureRollEngine:
|
|||
roll_result = max(1, min(len(table_choices), roll_result))
|
||||
return table_choices[roll_result - 1]
|
||||
```
|
||||
|
||||
Check that you understand what this does.
|
||||
|
||||
This may be confusing:
|
||||
|
||||
```python
|
||||
minval, *maxval = valrange.split("-", 1)
|
||||
minval = abs(int(minval))
|
||||
|
|
@ -484,7 +487,6 @@ maxval = abs(int(maxval[0]) if maxval else minval)
|
|||
we check if `maxval` actually has a value `("5",)` or if its empty `()`. The result is either
|
||||
`"5"` or the value of `minval`.
|
||||
|
||||
|
||||
### Roll for death
|
||||
|
||||
While original Knave suggests hitting 0 HP means insta-death, we will grab the optional "death table"
|
||||
|
|
@ -492,8 +494,8 @@ from the "prettified" Knave's optional rules to make it a little less punishing.
|
|||
result of `2` to 'dead' since we don't simulate 'dismemberment' in this tutorial:
|
||||
|
||||
| Roll | Result | -1d4 Loss of Ability |
|
||||
|:---: |:--------:|:--------------------:|
|
||||
| 1-2 | dead | -
|
||||
| :--: | :--------: | :------------------: |
|
||||
| 1-2 | dead | - |
|
||||
| 3 | weakened | STR |
|
||||
| 4 | unsteady | DEX |
|
||||
| 5 | sickly | CON |
|
||||
|
|
@ -584,7 +586,7 @@ class TestEvAdventureRuleEngine(BaseEvenniaTest):
|
|||
@patch("evadventure.rules.randint")
|
||||
def test_roll(self, mock_randint):
|
||||
mock_randint.return_value = 4
|
||||
self.assertEqual(self.roll_engine.roll("1d6", 4))
|
||||
self.assertEqual(self.roll_engine.roll("1d6"), 4)
|
||||
self.assertEqual(self.roll_engine.roll("2d6"), 2 * 4)
|
||||
|
||||
# test of the other rule methods below ...
|
||||
|
|
@ -600,6 +602,7 @@ As before, run the specific test with
|
|||
In [evennia/contrib/tutorials/evadventure/tests/test_rules.py](../../../api/evennia.contrib.tutorials.evadventure.tests.test_rules.md)
|
||||
has a complete example of rule testing.
|
||||
```
|
||||
|
||||
The `setUp` method is a special method of the testing class. It will be run before every
|
||||
test method. We use `super().setUp()` to make sure the parent class' version of this method
|
||||
always fire. Then we create a fresh `EvAdventureRollEngine` we can test with.
|
||||
|
|
@ -626,8 +629,3 @@ them for further help.
|
|||
This concludes all the core rule mechanics of _Knave_ - the rules used during play. We noticed here
|
||||
that we are going to soon need to establish how our _Character_ actually stores data. So we will
|
||||
address that next.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue