diff --git a/evennia/trunk/apps/objects/models.py b/evennia/trunk/apps/objects/models.py index bdd9ba715f..ebfabc8af0 100755 --- a/evennia/trunk/apps/objects/models.py +++ b/evennia/trunk/apps/objects/models.py @@ -2,18 +2,18 @@ from django.db import models from django.contrib.auth.models import User import global_defines -class ObjectClass(models.Model): - """ - Each object class can have different behaviors to apply to it. - """ - name = models.CharField(maxlength=255) - description = models.TextField() +#class ObjectClass(models.Model): +# """ +# Each object class can have different behaviors to apply to it. +# """ +# name = models.CharField(maxlength=255) +# description = models.TextField() - def __str__(self): - return "%s(%d)" % (self.name, self.id,) +# def __str__(self): +# return "%s(%d)" % (self.name, self.id,) - class Admin: - list_display = ('name', 'description',) +# class Admin: +# list_display = ('name', 'description',) class Attribute(models.Model): """ @@ -26,6 +26,7 @@ class Attribute(models.Model): """ name = models.CharField(maxlength=255) value = models.CharField(maxlength=255) + is_hidden = models.BooleanField() object = models.ForeignKey("Object") def __str__(self): @@ -42,12 +43,13 @@ class Object(models.Model): """ name = models.CharField(maxlength=255) - #owner = models.ForeignKey('self', related_name="owner") - #zone = models.ForeignKey('self', related_name="zone") - #home = models.ForeignKey('self', related_name="home") + owner = models.ForeignKey('self', related_name="obj_owner") + zone = models.ForeignKey('self', related_name="obj_zone", blank=True, null=True) + home = models.ForeignKey('self', related_name="obj_home", blank=True, null=True) type = models.SmallIntegerField(choices=global_defines.OBJECT_TYPES) description = models.TextField(blank=True) - location = models.ForeignKey('self', related_name="olocation", blank=True, null=True) + location = models.ForeignKey('self', related_name="obj_location", blank=True, null=True) + date_created = models.DateField(editable=False, auto_now_add=True) # Rather than keeping another relation for this, we're just going to use # foreign keys and populate each object's contents and attribute lists at @@ -77,6 +79,12 @@ class Object(models.Model): """ BEGIN COMMON METHODS """ + def get_attribute(self, attrib): + """ + Returns the value of an attribute on an object. + """ + return self.attrib_list.get(attrib, False) + def load_to_location(self): """ Adds an object to its location. @@ -119,7 +127,7 @@ class Object(models.Model): try: is_match = int(oname[1:]) == self.id except ValueError: - return false + return False return is_match @@ -146,31 +154,40 @@ class Object(models.Model): # Type comparison methods. def is_player(self): - return self.type is 1 + return self.type == 1 def is_room(self): - return self.type is 2 + return self.type == 2 def is_thing(self): - return self.type is 3 + return self.type == 3 def is_exit(self): - return self.type is 4 + return self.type == 4 def is_garbage(self): - return self.type is 5 - + return self.type == 5 + + def get_type(self, return_number=False): + """ + Returns the numerical or string representation of an object's type. + """ + if return_number: + return self.type + else: + return global_defines.OBJECT_TYPES[self.type][1] + def is_type(self, otype): """ See if an object is a certain type. """ otype = otype[0] - if otype is 'p': + if otype == 'p': return self.is_player() - elif otype is 'r': + elif otype == 'r': return self.is_room() - elif otype is 't': + elif otype == 't': return self.is_thing() - elif otype is 'e': + elif otype == 'e': return self.is_exit() - elif otype is 'g': + elif otype == 'g': return self.is_garbage() def flag_string(self): diff --git a/evennia/trunk/commands_general.py b/evennia/trunk/commands_general.py index 43e816bcab..b4dcea936a 100644 --- a/evennia/trunk/commands_general.py +++ b/evennia/trunk/commands_general.py @@ -20,7 +20,7 @@ def cmd_look(cdat): if len(args) == 0: target_obj = session.pobject.location else: - results = functions_db.local_and_global_search(pobject, ''.join(args), searcher=pobject) + results = functions_db.local_and_global_search(pobject, ' '.join(args), searcher=pobject) if len(results) > 1: session.msg("More than one match found (please narrow target):") @@ -69,6 +69,72 @@ def cmd_look(cdat): session.msg("%sExits:%s" % (ansi["hilite"], ansi["normal"],)) for exit in con_exits: session.msg('%s' %(exit,)) + +def cmd_examine(cdat): + """ + Detailed object examine command + """ + session = cdat['session'] + pobject = session.pobject + args = cdat['uinput']['splitted'][1:] + + if len(args) == 0: + target_obj = session.pobject.location + else: + results = functions_db.local_and_global_search(pobject, ' '.join(args), searcher=pobject) + + if len(results) > 1: + session.msg("More than one match found (please narrow target):") + for result in results: + session.msg(" %s" % (result,)) + return + elif len(results) == 0: + session.msg("I don't see that here.") + return + else: + target_obj = results[0] + + session.msg("%s%s%s(#%i%s)%s" % ( + ansi["normal"], + ansi["hilite"], + target_obj.name, + target_obj.id, + target_obj.flag_string(), + ansi["normal"], + )) + session.msg("Type: %s Flags: " % (target_obj.get_type(),)) + session.msg("Zone: ") + + for attribute in target_obj.attrib_list: + session.msg("%s%s%s: %s" % (ansi["hilite"], attribute, ansi["normal"], target_obj.get_attribute(attribute))) + + con_players = [] + con_things = [] + con_exits = [] + + for obj in target_obj.get_contents(): + if obj.is_player: + con_players.append(obj) + elif obj.is_exit: + con_exits.append(obj) + else: + con_things.append(obj) + + if con_players or con_things: + session.msg("Contents:") + for player in con_players: + session.msg('%s' %(player,)) + for thing in con_things: + session.msg('%s' %(thing,)) + + if con_exits: + session.msg("%sExits:%s" % (ansi["hilite"], ansi["normal"],)) + for exit in con_exits: + session.msg('%s' %(exit,)) + + if not target_obj.is_room(): + session.msg("Home: ") + session.msg("Location: %s" % (target_obj.location,)) def cmd_quit(cdat): """ @@ -114,7 +180,7 @@ def cmd_say(cdat): """ session_list = cdat['server'].get_session_list() session = cdat['session'] - speech = ''.join(cdat['uinput']['splitted'][1:]) + speech = ' '.join(cdat['uinput']['splitted'][1:]) players_present = [player for player in session_list if player.pobject.location == session.pobject.location and player != session] retval = "You say, '%s'" % (speech,) diff --git a/evennia/trunk/commands_staff.py b/evennia/trunk/commands_staff.py index 8579c47e54..75a6b217de 100644 --- a/evennia/trunk/commands_staff.py +++ b/evennia/trunk/commands_staff.py @@ -9,18 +9,21 @@ Restricted staff commands. def cmd_dig(cdat): """ - Digs a new room out. + Creates a new object of type 'ROOM'. """ session = cdat['session'] + server = session.server uinput= cdat['uinput']['splitted'] - roomname = ''.join(uinput[1:]) + roomname = ' '.join(uinput[1:]) if roomname == '': - session.msg("You must supply a room name!") + session.msg("You must supply a name!") else: - newroom = Object() - newroom.name = roomname - newroom.type = "Room" + # Create and set the object up. + odat = {"name": roomname, "type": 2, "location": None, "owner": session.pobject} + new_object = functions_db.create_object(server, odat) + + session.msg("You create a new room: %s" % (new_object,)) def cmd_create(cdat): """ @@ -29,16 +32,16 @@ def cmd_create(cdat): session = cdat['session'] server = session.server uinput= cdat['uinput']['splitted'] - thingname = ''.join(uinput[1:]) + thingname = ' '.join(uinput[1:]) if thingname == '': - session.msg("You must supply a room name!") + session.msg("You must supply a name!") else: # Create and set the object up. - odat = {"name": thingname, "type": 3, "location": session.pobject.location, "owner": session.pobject} + odat = {"name": thingname, "type": 3, "location": session.pobject, "owner": session.pobject} new_object = functions_db.create_object(server, odat) - session.msg("You create a new object: %s" % (new_object,)) + session.msg("You create a new thing: %s" % (new_object,)) def cmd_nextfree(cdat): """ @@ -132,7 +135,7 @@ def cmd_find(cdat): """ session = cdat['session'] server = cdat['server'] - searchstring = ''.join(cdat['uinput']['splitted'][1:]) + searchstring = ' '.join(cdat['uinput']['splitted'][1:]) if searchstring == '': session.msg("No search pattern given.")