Minor cleanup and when more than one puzzle can be resolved, don't show their names but just how many
This commit is contained in:
parent
d46472d91b
commit
6254762b41
2 changed files with 11 additions and 18 deletions
|
|
@ -501,11 +501,6 @@ class CmdUsePuzzleParts(MuxCommand):
|
||||||
use <part1[,part2,...>]
|
use <part1[,part2,...>]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# TODO: consider allowing builder to provide
|
|
||||||
# messages and "hooks" that can be displayed
|
|
||||||
# and/or fired whenever the resolver of the puzzle
|
|
||||||
# enters the location where a result was spawned
|
|
||||||
|
|
||||||
key = 'use'
|
key = 'use'
|
||||||
aliases = 'combine'
|
aliases = 'combine'
|
||||||
locks = 'cmd:pperm(use) or pperm(Player)'
|
locks = 'cmd:pperm(use) or pperm(Player)'
|
||||||
|
|
@ -597,7 +592,7 @@ class CmdUsePuzzleParts(MuxCommand):
|
||||||
matched_puzzles[puzzle.dbref] = matched_dbrefparts
|
matched_puzzles[puzzle.dbref] = matched_dbrefparts
|
||||||
|
|
||||||
if len(matched_puzzles) == 0:
|
if len(matched_puzzles) == 0:
|
||||||
# TODO: we could use part.fail_message instead, if any
|
# TODO: we could use part.fail_message instead, if there was one
|
||||||
# random part falls and lands on your feet
|
# random part falls and lands on your feet
|
||||||
# random part hits you square on the face
|
# random part hits you square on the face
|
||||||
caller.msg(_PUZZLE_DEFAULT_FAIL_USE_MESSAGE % (many))
|
caller.msg(_PUZZLE_DEFAULT_FAIL_USE_MESSAGE % (many))
|
||||||
|
|
@ -613,13 +608,15 @@ class CmdUsePuzzleParts(MuxCommand):
|
||||||
puzzle = puzzles_dict[puzzledbref]
|
puzzle = puzzles_dict[puzzledbref]
|
||||||
largest_puzzles = list(itertools.takewhile(lambda t: len(t[1]) == nparts, puzzletuples))
|
largest_puzzles = list(itertools.takewhile(lambda t: len(t[1]) == nparts, puzzletuples))
|
||||||
|
|
||||||
# if there are more than one, ...
|
# if there are more than one, choose one at random.
|
||||||
|
# we could show the names of all those that can be resolved
|
||||||
|
# but that would give away that there are other puzzles that
|
||||||
|
# can be resolved with the same parts.
|
||||||
|
# just hint how many.
|
||||||
if len(largest_puzzles) > 1:
|
if len(largest_puzzles) > 1:
|
||||||
# TODO: pick a random one or let user choose?
|
|
||||||
# TODO: do we show the puzzle name or something else?
|
|
||||||
caller.msg(
|
caller.msg(
|
||||||
'Your gears start turning and a bunch of ideas come to your mind ...\n%s' % (
|
'Your gears start turning and %d different ideas come to your mind ...\n'
|
||||||
' ...\n'.join([puzzles_dict[lp[0]].db.puzzle_name for lp in largest_puzzles]))
|
% (len(largest_puzzles))
|
||||||
)
|
)
|
||||||
puzzletuple = choice(largest_puzzles)
|
puzzletuple = choice(largest_puzzles)
|
||||||
puzzle = puzzles_dict[puzzletuple[0]]
|
puzzle = puzzles_dict[puzzletuple[0]]
|
||||||
|
|
@ -632,10 +629,6 @@ class CmdUsePuzzleParts(MuxCommand):
|
||||||
result.tags.add(puzzle.db.puzzle_name, category=_PUZZLES_TAG_CATEGORY)
|
result.tags.add(puzzle.db.puzzle_name, category=_PUZZLES_TAG_CATEGORY)
|
||||||
result.db.puzzle_name = puzzle.db.puzzle_name
|
result.db.puzzle_name = puzzle.db.puzzle_name
|
||||||
result_names.append(result.name)
|
result_names.append(result.name)
|
||||||
# TODO: add 'ramdon' messages:
|
|
||||||
# Hmmm ... did I search result.location?
|
|
||||||
# What was that? ... I heard something in result.location?
|
|
||||||
# Eureka! you built a result
|
|
||||||
|
|
||||||
# Destroy all parts used
|
# Destroy all parts used
|
||||||
for dbref in matched_dbrefparts:
|
for dbref in matched_dbrefparts:
|
||||||
|
|
|
||||||
|
|
@ -1977,7 +1977,7 @@ class TestPuzzles(CommandTest):
|
||||||
# only one is.
|
# only one is.
|
||||||
self._use(
|
self._use(
|
||||||
'1-stone, 2-flint, 3-stone, 3-flint',
|
'1-stone, 2-flint, 3-stone, 3-flint',
|
||||||
'Your gears start turning and a bunch of ideas come to your mind ... ')
|
'Your gears start turning and 2 different ideas come to your mind ... ')
|
||||||
self._check_room_contents({'stone': 2, 'flint': 2, 'fire': 2}, check_test_tags=True)
|
self._check_room_contents({'stone': 2, 'flint': 2, 'fire': 2}, check_test_tags=True)
|
||||||
|
|
||||||
self.room1.msg_contents = Mock()
|
self.room1.msg_contents = Mock()
|
||||||
|
|
@ -2282,7 +2282,7 @@ class TestPuzzles(CommandTest):
|
||||||
parts = ['Balloon']
|
parts = ['Balloon']
|
||||||
results = ['Balloon'] # FIXME: we don't want results
|
results = ['Balloon'] # FIXME: we don't want results
|
||||||
recipe_dbref = self._good_recipe(
|
recipe_dbref = self._good_recipe(
|
||||||
'Boom!!!',
|
'boom!!!', # FIXME: uppercase name fails
|
||||||
parts, results,
|
parts, results,
|
||||||
and_destroy_it=False,
|
and_destroy_it=False,
|
||||||
expected_count=3
|
expected_count=3
|
||||||
|
|
@ -2293,7 +2293,7 @@ class TestPuzzles(CommandTest):
|
||||||
sps = sorted(parts)
|
sps = sorted(parts)
|
||||||
expected = {key: len(list(grp)) for key, grp in itertools.groupby(sps)}
|
expected = {key: len(list(grp)) for key, grp in itertools.groupby(sps)}
|
||||||
|
|
||||||
self._arm(recipe_dbref, 'Boom!!!', parts)
|
self._arm(recipe_dbref, 'boom!!!', parts)
|
||||||
self._check_room_contents(expected)
|
self._check_room_contents(expected)
|
||||||
|
|
||||||
self._use(','.join(parts), 'You are a Genius')
|
self._use(','.join(parts), 'You are a Genius')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue