mirror of
https://github.com/evennia/evennia.git
synced 2026-04-02 14:07:16 +02:00
Enforce parts and results to be DefaultObject not DefaultCharacter, DefaultRoom nor DefaultExit with tests. Tests for @lspuzzlerecipes and @lsarmedpuzzles
This commit is contained in:
parent
e51ff36801
commit
2e376a32cb
2 changed files with 99 additions and 3 deletions
|
|
@ -75,6 +75,7 @@ from evennia import DefaultObject
|
|||
from evennia import DefaultScript
|
||||
from evennia import DefaultCharacter
|
||||
from evennia import DefaultRoom
|
||||
from evennia import DefaultExit
|
||||
from evennia.commands.default.muxcommand import MuxCommand
|
||||
from evennia.utils.utils import inherits_from
|
||||
from evennia.utils import search, utils, logger
|
||||
|
|
@ -193,12 +194,28 @@ class CmdCreatePuzzleRecipe(MuxCommand):
|
|||
def is_valid_result_location(part):
|
||||
return is_valid_obj_location(part)
|
||||
|
||||
def is_valid_inheritance(obj):
|
||||
valid = not inherits_from(obj, DefaultCharacter) \
|
||||
and not inherits_from(obj, DefaultRoom) \
|
||||
and not inherits_from(obj, DefaultExit)
|
||||
if not valid:
|
||||
caller.msg('Invalid typeclass for %s' % (obj))
|
||||
return valid
|
||||
|
||||
def is_valid_part(part):
|
||||
return is_valid_inheritance(part) \
|
||||
and is_valid_part_location(part)
|
||||
|
||||
def is_valid_result(result):
|
||||
return is_valid_inheritance(result) \
|
||||
and is_valid_result_location(result)
|
||||
|
||||
parts = []
|
||||
for objname in self.lhslist[1:]:
|
||||
obj = caller.search(objname)
|
||||
if not obj:
|
||||
return
|
||||
if not is_valid_part_location(obj):
|
||||
if not is_valid_part(obj):
|
||||
return
|
||||
parts.append(obj)
|
||||
|
||||
|
|
@ -207,7 +224,7 @@ class CmdCreatePuzzleRecipe(MuxCommand):
|
|||
obj = caller.search(objname)
|
||||
if not obj:
|
||||
return
|
||||
if not is_valid_result_location(obj):
|
||||
if not is_valid_result(obj):
|
||||
return
|
||||
results.append(obj)
|
||||
|
||||
|
|
|
|||
|
|
@ -1215,7 +1215,7 @@ class TestPuzzles(CommandTest):
|
|||
def _assert_no_recipes(self):
|
||||
self.assertEqual(
|
||||
0,
|
||||
len(search.search_tag('', category=puzzles._PUZZLES_TAG_CATEGORY))
|
||||
len(search.search_script_tag('', category=puzzles._PUZZLES_TAG_CATEGORY))
|
||||
)
|
||||
|
||||
# good recipes
|
||||
|
|
@ -1294,6 +1294,11 @@ class TestPuzzles(CommandTest):
|
|||
_bad_recipe('name', ['nothing'], ['neither'], r"Could not find 'nothing'.")
|
||||
_bad_recipe('name', ['stone'], ['nothing'], r"Could not find 'nothing'.")
|
||||
_bad_recipe('', ['stone', 'fire'], ['stone', 'fire'], r"^Invalid puzzle name ''.")
|
||||
self.stone.location = self.char1
|
||||
_bad_recipe('name', ['stone'], ['fire'], r"^Invalid location for stone$")
|
||||
_bad_recipe('name', ['flint'], ['stone'], r"^Invalid location for stone$")
|
||||
_bad_recipe('name', ['self'], ['fire'], r"^Invalid typeclass for Char$")
|
||||
_bad_recipe('name', ['here'], ['fire'], r"^Invalid typeclass for Room$")
|
||||
|
||||
self._assert_no_recipes()
|
||||
|
||||
|
|
@ -1352,3 +1357,77 @@ class TestPuzzles(CommandTest):
|
|||
# and the parts were destroyed
|
||||
_use('stone, flint', 'There is no stone around')
|
||||
_use('flint, stone', 'There is no flint around')
|
||||
|
||||
def test_lspuzzlerecipes_lsarmedpuzzles(self):
|
||||
msg = self.call(
|
||||
puzzles.CmdListPuzzleRecipes(),
|
||||
'',
|
||||
caller=self.char1
|
||||
)
|
||||
self._assert_msg_matched(
|
||||
msg,
|
||||
[
|
||||
r"^-+$",
|
||||
r"^-+$",
|
||||
],
|
||||
re.MULTILINE | re.DOTALL
|
||||
)
|
||||
|
||||
recipe_dbref = self._good_recipe(
|
||||
'makefire', ['stone', 'flint'], ['fire'],
|
||||
and_destroy_it=False)
|
||||
|
||||
msg = self.call(
|
||||
puzzles.CmdListPuzzleRecipes(),
|
||||
'',
|
||||
caller=self.char1
|
||||
)
|
||||
self._assert_msg_matched(
|
||||
msg,
|
||||
[
|
||||
r"^-+$",
|
||||
r"^Puzzle 'makefire'.*$",
|
||||
r"^Parts$",
|
||||
r"^.*key: stone$",
|
||||
r"^.*key: flint$",
|
||||
r"^Results$",
|
||||
r"^.*key: fire$",
|
||||
r"^.*key: stone$",
|
||||
r"^.*key: flint$",
|
||||
r"^-+$",
|
||||
],
|
||||
re.MULTILINE | re.DOTALL
|
||||
)
|
||||
|
||||
msg = self.call(
|
||||
puzzles.CmdListArmedPuzzles(),
|
||||
'',
|
||||
caller=self.char1
|
||||
)
|
||||
self._assert_msg_matched(
|
||||
msg,
|
||||
[
|
||||
r"^-+$",
|
||||
r"^-+$"
|
||||
],
|
||||
re.MULTILINE | re.DOTALL
|
||||
)
|
||||
|
||||
self._arm(recipe_dbref, 'makefire', ['stone', 'flint'])
|
||||
|
||||
msg = self.call(
|
||||
puzzles.CmdListArmedPuzzles(),
|
||||
'',
|
||||
caller=self.char1
|
||||
)
|
||||
self._assert_msg_matched(
|
||||
msg,
|
||||
[
|
||||
r"^-+$",
|
||||
r"^Puzzle name: makefire$",
|
||||
r"^.*stone.* at \s+ Room.*$",
|
||||
r"^.*flint.* at \s+ Room.*$",
|
||||
r"^-+$",
|
||||
],
|
||||
re.MULTILINE | re.DOTALL
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue