Added a give command to the default command set. As part of this also fixed some bugs in how object typeclasses were compared.
This commit is contained in:
parent
949da47917
commit
c615693a2a
8 changed files with 53 additions and 21 deletions
|
|
@ -673,15 +673,16 @@ hole
|
||||||
# light source.
|
# light source.
|
||||||
#
|
#
|
||||||
@desc
|
@desc
|
||||||
{YThe {yflickering light{Y of the torch reveals a small square
|
{YThe {yflickering light{Y of your makeshift light reveals a small square
|
||||||
cell. It does not seem like you are still in the castle, for the
|
cell. It does not seem like you are still in the castle, for the
|
||||||
stone of the walls are chiseled crudely and drip with water and mold.
|
stone of the walls are chiseled crudely and drip with water and mold.
|
||||||
|
|
||||||
One wall holds a solid iron-cast door. While rusted and covered with
|
One wall holds a solid iron-cast door. While rusted and covered with
|
||||||
lichen it seems very sturdy. In a corner lies what might have once
|
lichen it seems very sturdy. In a corner lies what might have once
|
||||||
been a bed or a bench but is now nothing more than a pile or rotting
|
been a bed or a bench but is now nothing more than a pile of splinters,
|
||||||
splinters. One of the walls are covered with a thick cover of black
|
one of which you are using for light. One of the walls is covered with a
|
||||||
roots where they have broken through the cracks.{n
|
thick cover of black roots having broken through the cracks from the
|
||||||
|
outside.{n
|
||||||
#
|
#
|
||||||
@create/drop iron-cast door;iron;door;iron-cast
|
@create/drop iron-cast door;iron;door;iron-cast
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -180,9 +180,9 @@ class CmdLookDark(Command):
|
||||||
lightsource = lightsources[0]
|
lightsource = lightsources[0]
|
||||||
else:
|
else:
|
||||||
# create the light source from scratch.
|
# create the light source from scratch.
|
||||||
lightsource = create_object(LightSource, key="torch")
|
lightsource = create_object(LightSource, key="splinter")
|
||||||
lightsource.location = caller
|
lightsource.location = caller
|
||||||
string = "Your fingers bump against a piece of wood in a corner. Smelling it you sense the faint smell of tar. A {c%s{n!"
|
string = "Your fingers bump against a splinter of wood in a corner. It smells of resin and seems dry enough to burn!"
|
||||||
string += "\nYou pick it up, holding it firmly. Now you just need to {wlight{n it using the flint and steel you carry with you."
|
string += "\nYou pick it up, holding it firmly. Now you just need to {wlight{n it using the flint and steel you carry with you."
|
||||||
caller.msg(string % lightsource.key)
|
caller.msg(string % lightsource.key)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1678,7 +1678,7 @@ class CmdExamine(ObjManipCommand):
|
||||||
string += headers["cmdset"] % ("\n ".join("%s (prio %s)" % (cmdset.path, cmdset.priority) for cmdset in all_cmdsets))
|
string += headers["cmdset"] % ("\n ".join("%s (prio %s)" % (cmdset.path, cmdset.priority) for cmdset in all_cmdsets))
|
||||||
#cmdsetstr = "\n".join([utils.fill(cmdset, indent=2) for cmdset in str(obj.cmdset).split("\n")])
|
#cmdsetstr = "\n".join([utils.fill(cmdset, indent=2) for cmdset in str(obj.cmdset).split("\n")])
|
||||||
|
|
||||||
# list the actually available commands
|
# list the commands available to this object
|
||||||
avail_cmdset = sorted([cmd.key for cmd in avail_cmdset if cmd.access(obj, "cmd")])
|
avail_cmdset = sorted([cmd.key for cmd in avail_cmdset if cmd.access(obj, "cmd")])
|
||||||
|
|
||||||
cmdsetstr = utils.fill(", ".join(avail_cmdset), indent=2)
|
cmdsetstr = utils.fill(", ".join(avail_cmdset), indent=2)
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ class DefaultCmdSet(CmdSet):
|
||||||
self.add(general.CmdNick())
|
self.add(general.CmdNick())
|
||||||
self.add(general.CmdGet())
|
self.add(general.CmdGet())
|
||||||
self.add(general.CmdDrop())
|
self.add(general.CmdDrop())
|
||||||
|
self.add(general.CmdGive())
|
||||||
self.add(general.CmdSay())
|
self.add(general.CmdSay())
|
||||||
self.add(general.CmdAccess())
|
self.add(general.CmdAccess())
|
||||||
self.add(general.CmdColorTest())
|
self.add(general.CmdColorTest())
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ from src.commands.default.muxcommand import MuxCommand, MuxCommandOOC
|
||||||
|
|
||||||
# limit symbol import for API
|
# limit symbol import for API
|
||||||
__all__ = ("CmdHome", "CmdLook", "CmdPassword", "CmdNick",
|
__all__ = ("CmdHome", "CmdLook", "CmdPassword", "CmdNick",
|
||||||
"CmdInventory", "CmdGet", "CmdDrop", "CmdQuit", "CmdWho",
|
"CmdInventory", "CmdGet", "CmdDrop", "CmdGive", "CmdQuit", "CmdWho",
|
||||||
"CmdSay", "CmdPose", "CmdEncoding", "CmdAccess",
|
"CmdSay", "CmdPose", "CmdEncoding", "CmdAccess",
|
||||||
"CmdOOCLook", "CmdIC", "CmdOOC", "CmdColorTest")
|
"CmdOOCLook", "CmdIC", "CmdOOC", "CmdColorTest")
|
||||||
|
|
||||||
|
|
@ -345,6 +345,42 @@ class CmdDrop(MuxCommand):
|
||||||
obj.at_drop(caller)
|
obj.at_drop(caller)
|
||||||
|
|
||||||
|
|
||||||
|
class CmdGive(MuxCommand):
|
||||||
|
"""
|
||||||
|
give away things
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
give <inventory obj> = <target>
|
||||||
|
|
||||||
|
Gives an items from your inventory to another character,
|
||||||
|
placing it in their inventory.
|
||||||
|
"""
|
||||||
|
key = "give"
|
||||||
|
locks = "cmd:all()"
|
||||||
|
|
||||||
|
def func(self):
|
||||||
|
"Implement give"
|
||||||
|
|
||||||
|
caller = self.caller
|
||||||
|
if not self.args or not self.rhs:
|
||||||
|
caller.msg("Usage: give <inventory object> = <target>")
|
||||||
|
return
|
||||||
|
to_give = caller.search(self.lhs)
|
||||||
|
target = caller.search(self.rhs)
|
||||||
|
if not (to_give and target):
|
||||||
|
return
|
||||||
|
if target == caller:
|
||||||
|
caller.msg("You keep %s to yourself." % to_give.key)
|
||||||
|
return
|
||||||
|
if not to_give.location == caller:
|
||||||
|
caller.msg("You are not holding %s." % to_give.key)
|
||||||
|
return
|
||||||
|
# give object
|
||||||
|
to_give.location = target
|
||||||
|
caller.msg("You give %s to %s." % (to_give.key, target.key))
|
||||||
|
target.msg("%s gives you %s." % (caller.key, to_give.key))
|
||||||
|
|
||||||
|
|
||||||
class CmdQuit(MuxCommand):
|
class CmdQuit(MuxCommand):
|
||||||
"""
|
"""
|
||||||
quit
|
quit
|
||||||
|
|
|
||||||
|
|
@ -387,13 +387,11 @@ class Object(TypeClass):
|
||||||
parent doesn't work.
|
parent doesn't work.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return _GA(_GA(self, "dbobj"),"dbid") == other \
|
return _GA(_GA(self, "dbobj"),"dbid") == _GA(_GA(other,"dbobj"),"dbid")
|
||||||
or _GA(_GA(self, "dbobj"),"dbid") == _GA(_GA(other,"dbobj"),"dbid")
|
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# compare players instead
|
# compare players instead
|
||||||
try:
|
try:
|
||||||
return _GA(_GA(_GA(self, "dbobj"),"player"),"uid") == other \
|
return _GA(_GA(_GA(self, "dbobj"),"player"),"uid") == _GA(_GA(other, "player"),"uid")
|
||||||
or _GA(_GA(_GA(self, "dbobj"),"player"),"uid") == _GA(_GA(other, "player"),"uid")
|
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -157,10 +157,9 @@ class TypeClass(object):
|
||||||
dbobj-recognized comparison
|
dbobj-recognized comparison
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return other == self or other == _GA(self, dbobj) or other == _GA(self, dbobj).user
|
return _GA(_GA(self, "dbobj"), "dbid") == _GA(_GA(other, "dbobj"), "dbid")
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# if self.dbobj.user fails it means the two previous comparisons failed already
|
return id(self) == id(other)
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def __delattr__(self, propname):
|
def __delattr__(self, propname):
|
||||||
|
|
|
||||||
|
|
@ -350,13 +350,10 @@ def to_str(obj, encoding='utf-8', force_string=False):
|
||||||
if force_string and not isinstance(obj, basestring):
|
if force_string and not isinstance(obj, basestring):
|
||||||
# some sort of other object. Try to
|
# some sort of other object. Try to
|
||||||
# convert it to a string representation.
|
# convert it to a string representation.
|
||||||
if hasattr(obj, '__str__'):
|
try:
|
||||||
obj = obj.__str__()
|
|
||||||
elif hasattr(obj, '__unicode__'):
|
|
||||||
obj = obj.__unicode__()
|
|
||||||
else:
|
|
||||||
# last resort
|
|
||||||
obj = str(obj)
|
obj = str(obj)
|
||||||
|
except Exception:
|
||||||
|
obj = unicode(obj)
|
||||||
|
|
||||||
if isinstance(obj, basestring) and isinstance(obj, unicode):
|
if isinstance(obj, basestring) and isinstance(obj, unicode):
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue