When multiple puzzles are matched, show their names to the caller and
then randomly pick one
This commit is contained in:
parent
7f9d8c1442
commit
a1c428a355
1 changed files with 24 additions and 9 deletions
|
|
@ -85,6 +85,7 @@ def proto_def(obj, with_tags=True):
|
||||||
and compare recipe with candidate part
|
and compare recipe with candidate part
|
||||||
"""
|
"""
|
||||||
protodef = {
|
protodef = {
|
||||||
|
# FIXME: Don't we need to honor ALL properties? locks, perms, etc.
|
||||||
'key': obj.key,
|
'key': obj.key,
|
||||||
'typeclass': 'evennia.contrib.puzzles.PuzzlePartObject', # FIXME: what if obj is another typeclass
|
'typeclass': 'evennia.contrib.puzzles.PuzzlePartObject', # FIXME: what if obj is another typeclass
|
||||||
'desc': obj.db.desc,
|
'desc': obj.db.desc,
|
||||||
|
|
@ -260,7 +261,6 @@ class CmdArmPuzzle(MuxCommand):
|
||||||
puzzle.name, puzzle.dbref, puzzle.db.puzzle_name, len(puzzle.db.parts)))
|
puzzle.name, puzzle.dbref, puzzle.db.puzzle_name, len(puzzle.db.parts)))
|
||||||
|
|
||||||
for proto_part in puzzle.db.parts:
|
for proto_part in puzzle.db.parts:
|
||||||
# caller.msg('Protopart %r %r' % (proto_part, type(proto_part)))
|
|
||||||
part = spawn(proto_part)[0]
|
part = spawn(proto_part)[0]
|
||||||
caller.msg("Part %s(%s) spawned and placed at %s(%s)" % (part.name, part.dbref, part.location, part.location.dbref))
|
caller.msg("Part %s(%s) spawned and placed at %s(%s)" % (part.name, part.dbref, part.location, part.location.dbref))
|
||||||
part.mark_as_puzzle_member(puzzle.db.puzzle_name)
|
part.mark_as_puzzle_member(puzzle.db.puzzle_name)
|
||||||
|
|
@ -351,6 +351,8 @@ class CmdUsePuzzleParts(MuxCommand):
|
||||||
else:
|
else:
|
||||||
puzzles.extend(_puzzles)
|
puzzles.extend(_puzzles)
|
||||||
|
|
||||||
|
logger.log_info("PUZZLES %r" % ([p.dbref for p in puzzles]))
|
||||||
|
|
||||||
# Create lookup dict
|
# Create lookup dict
|
||||||
puzzles_dict = dict((puzzle.dbref, puzzle) for puzzle in puzzles)
|
puzzles_dict = dict((puzzle.dbref, puzzle) for puzzle in puzzles)
|
||||||
|
|
||||||
|
|
@ -371,8 +373,6 @@ class CmdUsePuzzleParts(MuxCommand):
|
||||||
if part == puzzlepart:
|
if part == puzzlepart:
|
||||||
pz += 1
|
pz += 1
|
||||||
matched_dbrefparts.add(dbref)
|
matched_dbrefparts.add(dbref)
|
||||||
else:
|
|
||||||
pass
|
|
||||||
p += 1
|
p += 1
|
||||||
else:
|
else:
|
||||||
if len(puzzleparts) == len(matched_dbrefparts):
|
if len(puzzleparts) == len(matched_dbrefparts):
|
||||||
|
|
@ -387,27 +387,33 @@ class CmdUsePuzzleParts(MuxCommand):
|
||||||
|
|
||||||
puzzletuples = sorted(matched_puzzles.items(), key=lambda t: len(t[1]), reverse=True)
|
puzzletuples = sorted(matched_puzzles.items(), key=lambda t: len(t[1]), reverse=True)
|
||||||
|
|
||||||
|
logger.log_info("MATCHED PUZZLES %r" % (puzzletuples))
|
||||||
|
|
||||||
# sort all matched puzzles and pick largest one(s)
|
# sort all matched puzzles and pick largest one(s)
|
||||||
puzzledbref, matched_dbrefparts = puzzletuples[0]
|
puzzledbref, matched_dbrefparts = puzzletuples[0]
|
||||||
nparts = len(matched_dbrefparts)
|
nparts = len(matched_dbrefparts)
|
||||||
|
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, let user pick
|
# if there are more than one, ...
|
||||||
if len(largest_puzzles) > 1:
|
if len(largest_puzzles) > 1:
|
||||||
# FIXME: pick a random one or let user choose?
|
# FIXME: pick a random one or let user choose?
|
||||||
|
# FIXME: 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 a bunch of ideas come to your mind ...\n%s' % (
|
||||||
' ...\n'.join([lp.db.puzzle_name for lp in largest_puzzles]))
|
' ...\n'.join([puzzles_dict[lp[0]].db.puzzle_name for lp in largest_puzzles]))
|
||||||
)
|
)
|
||||||
puzzle = choice(largest_puzzles)
|
puzzletuple = choice(largest_puzzles)
|
||||||
|
puzzle = puzzles_dict[puzzletuple[0]]
|
||||||
caller.msg("You try %s ..." % (puzzle.db.puzzle_name))
|
caller.msg("You try %s ..." % (puzzle.db.puzzle_name))
|
||||||
|
|
||||||
# got one, spawn its results
|
# got one, spawn its results
|
||||||
puzzle = puzzles_dict[puzzledbref]
|
|
||||||
# FIXME: DRY with parts
|
# FIXME: DRY with parts
|
||||||
|
result_names = []
|
||||||
for proto_result in puzzle.db.results:
|
for proto_result in puzzle.db.results:
|
||||||
result = spawn(proto_result)[0]
|
result = spawn(proto_result)[0]
|
||||||
result.mark_as_puzzle_member(puzzle.db.puzzle_name)
|
result.mark_as_puzzle_member(puzzle.db.puzzle_name)
|
||||||
|
result_names.append(result.name)
|
||||||
# FIXME: add 'ramdon' messages:
|
# FIXME: add 'ramdon' messages:
|
||||||
# Hmmm ... did I search result.location?
|
# Hmmm ... did I search result.location?
|
||||||
# What was that? ... I heard something in result.location?
|
# What was that? ... I heard something in result.location?
|
||||||
|
|
@ -420,7 +426,16 @@ class CmdUsePuzzleParts(MuxCommand):
|
||||||
# FIXME: Add random messages
|
# FIXME: Add random messages
|
||||||
# You are a genius ... no matter what your 2nd grade teacher told you
|
# You are a genius ... no matter what your 2nd grade teacher told you
|
||||||
# You hear thunders and a cloud of dust raises leaving
|
# You hear thunders and a cloud of dust raises leaving
|
||||||
caller.msg("Puzzle solved |gsuccessfully|n.")
|
result_names = ', '.join(result_names)
|
||||||
|
caller.msg(
|
||||||
|
"You are a |wG|re|wn|ri|wu|rs|n!!!\nYou just created %s" % (
|
||||||
|
result_names
|
||||||
|
))
|
||||||
|
caller.location.msg_contents(
|
||||||
|
"|c%s|n performs some kind of tribal dance"
|
||||||
|
" and seems to create |y%s|n from thin air" % (
|
||||||
|
caller, result_names), exclude=(caller,)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class CmdListPuzzleRecipes(MuxCommand):
|
class CmdListPuzzleRecipes(MuxCommand):
|
||||||
|
|
@ -465,7 +480,7 @@ class PuzzleSystemCmdSet(CmdSet):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def at_cmdset_creation(self):
|
def at_cmdset_creation(self):
|
||||||
super(PuzzleSystemCmdSetCmdSet, self).at_cmdset_creation()
|
super(PuzzleSystemCmdSet, self).at_cmdset_creation()
|
||||||
|
|
||||||
self.add(CmdCreatePuzzleRecipe())
|
self.add(CmdCreatePuzzleRecipe())
|
||||||
self.add(CmdArmPuzzle())
|
self.add(CmdArmPuzzle())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue