Move the presentation part of the 'look' command out to the new scripting system. You can now make different scripted objects appear vastly different by overriding basicobject's return_appearance (or any of its submethods). Also fixed word wrapping, and we are now wrapping descriptions to 78 characters by default. We'll see how gracefully it handles this, and we might eventually apply it to all output.

This commit is contained in:
Greg Taylor 2007-07-17 14:39:10 +00:00
parent fa4cc4cab3
commit fadf3933af
4 changed files with 57 additions and 49 deletions

View file

@ -3,6 +3,8 @@ This will be the base object type/interface that all scripts are derived from by
default. It will have the necessary outline for developers to sub-class and override.
"""
import ansi
class BasicObject:
def __init__(self, source_obj):
"""
@ -22,6 +24,42 @@ class BasicObject:
#print "SCRIPT TEST: %s looked at %s." % (actor, self.source_obj)
pass
def return_appearance(self, values):
target_obj = values["target_obj"]
pobject = values["pobject"]
retval = "\r\n%s\r\n%s" % (
target_obj.get_name(),
target_obj.get_description(),
)
con_players = []
con_things = []
con_exits = []
for obj in target_obj.get_contents():
if obj.is_player():
if obj != pobject and obj.is_connected_plr():
con_players.append(obj)
elif obj.is_exit():
con_exits.append(obj)
else:
con_things.append(obj)
if con_players:
retval += "\n\r%sPlayers:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],)
for player in con_players:
retval +='\n\r%s' %(player.get_name(),)
if con_things:
retval += "\n\r%sContents:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],)
for thing in con_things:
retval += '\n\r%s' %(thing.get_name(),)
if con_exits:
retval += "\n\r%sExits:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],)
for exit in con_exits:
retval += '\n\r%s' %(exit.get_name(),)
return retval
def a_get(self, actor):
"""
Perform this action when someone uses the GET command on the object.