mirror of
https://github.com/evennia/evennia.git
synced 2026-03-23 00:06:30 +01:00
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.
|
||||
#
|
||||
@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
|
||||
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
|
||||
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
|
||||
splinters. One of the walls are covered with a thick cover of black
|
||||
roots where they have broken through the cracks.{n
|
||||
been a bed or a bench but is now nothing more than a pile of splinters,
|
||||
one of which you are using for light. One of the walls is covered with a
|
||||
thick cover of black roots having broken through the cracks from the
|
||||
outside.{n
|
||||
#
|
||||
@create/drop iron-cast door;iron;door;iron-cast
|
||||
#
|
||||
|
|
|
|||
|
|
@ -180,9 +180,9 @@ class CmdLookDark(Command):
|
|||
lightsource = lightsources[0]
|
||||
else:
|
||||
# create the light source from scratch.
|
||||
lightsource = create_object(LightSource, key="torch")
|
||||
lightsource = create_object(LightSource, key="splinter")
|
||||
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."
|
||||
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))
|
||||
#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")])
|
||||
|
||||
cmdsetstr = utils.fill(", ".join(avail_cmdset), indent=2)
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ class DefaultCmdSet(CmdSet):
|
|||
self.add(general.CmdNick())
|
||||
self.add(general.CmdGet())
|
||||
self.add(general.CmdDrop())
|
||||
self.add(general.CmdGive())
|
||||
self.add(general.CmdSay())
|
||||
self.add(general.CmdAccess())
|
||||
self.add(general.CmdColorTest())
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ from src.commands.default.muxcommand import MuxCommand, MuxCommandOOC
|
|||
|
||||
# limit symbol import for API
|
||||
__all__ = ("CmdHome", "CmdLook", "CmdPassword", "CmdNick",
|
||||
"CmdInventory", "CmdGet", "CmdDrop", "CmdQuit", "CmdWho",
|
||||
"CmdInventory", "CmdGet", "CmdDrop", "CmdGive", "CmdQuit", "CmdWho",
|
||||
"CmdSay", "CmdPose", "CmdEncoding", "CmdAccess",
|
||||
"CmdOOCLook", "CmdIC", "CmdOOC", "CmdColorTest")
|
||||
|
||||
|
|
@ -345,6 +345,42 @@ class CmdDrop(MuxCommand):
|
|||
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):
|
||||
"""
|
||||
quit
|
||||
|
|
|
|||
|
|
@ -387,13 +387,11 @@ class Object(TypeClass):
|
|||
parent doesn't work.
|
||||
"""
|
||||
try:
|
||||
return _GA(_GA(self, "dbobj"),"dbid") == other \
|
||||
or _GA(_GA(self, "dbobj"),"dbid") == _GA(_GA(other,"dbobj"),"dbid")
|
||||
return _GA(_GA(self, "dbobj"),"dbid") == _GA(_GA(other,"dbobj"),"dbid")
|
||||
except AttributeError:
|
||||
# compare players instead
|
||||
try:
|
||||
return _GA(_GA(_GA(self, "dbobj"),"player"),"uid") == other \
|
||||
or _GA(_GA(_GA(self, "dbobj"),"player"),"uid") == _GA(_GA(other, "player"),"uid")
|
||||
return _GA(_GA(_GA(self, "dbobj"),"player"),"uid") == _GA(_GA(other, "player"),"uid")
|
||||
except AttributeError:
|
||||
return False
|
||||
|
||||
|
|
|
|||
|
|
@ -157,10 +157,9 @@ class TypeClass(object):
|
|||
dbobj-recognized comparison
|
||||
"""
|
||||
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:
|
||||
# if self.dbobj.user fails it means the two previous comparisons failed already
|
||||
return False
|
||||
return id(self) == id(other)
|
||||
|
||||
|
||||
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):
|
||||
# some sort of other object. Try to
|
||||
# convert it to a string representation.
|
||||
if hasattr(obj, '__str__'):
|
||||
obj = obj.__str__()
|
||||
elif hasattr(obj, '__unicode__'):
|
||||
obj = obj.__unicode__()
|
||||
else:
|
||||
# last resort
|
||||
try:
|
||||
obj = str(obj)
|
||||
except Exception:
|
||||
obj = unicode(obj)
|
||||
|
||||
if isinstance(obj, basestring) and isinstance(obj, unicode):
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue