We now have object creation support via MUX-style @create. Next up is room creation, exit creation and linking, and finally @pcreate.

This commit is contained in:
Greg Taylor 2006-12-11 00:48:31 +00:00
parent 977864c649
commit a34bdc2889
5 changed files with 103 additions and 29 deletions

View file

@ -1,5 +1,6 @@
from django.db import models
from django.contrib.auth.models import User
import global_defines
class ObjectClass(models.Model):
"""
@ -40,18 +41,11 @@ class Object(models.Model):
field. The different otypes denote an object's behaviors.
"""
# Do not mess with the default types (0-5).
OBJECT_TYPES = (
(0, 'NOTHING'),
(1, 'PLAYER'),
(2, 'ROOM'),
(3, 'THING'),
(4, 'EXIT'),
(5, 'GARBAGE'),
)
name = models.CharField(maxlength=255)
type = models.SmallIntegerField(choices=OBJECT_TYPES)
#owner = models.ForeignKey('self', related_name="owner")
#zone = models.ForeignKey('self', related_name="zone")
#home = models.ForeignKey('self', related_name="home")
type = models.SmallIntegerField(choices=global_defines.OBJECT_TYPES)
description = models.TextField(blank=True)
location = models.ForeignKey('self', related_name="olocation", blank=True, null=True)
@ -65,7 +59,7 @@ class Object(models.Model):
# A dictionary of attributes assocated with the object. The keys are the
# attribute's names.
attrib_list = {}
def __cmp__(self, other):
"""
Used to figure out if one object is the same as another.
@ -179,7 +173,16 @@ class Object(models.Model):
elif otype is 'g':
return self.is_garbage()
def flag_string(self):
"""
Returns the flag string for an object. This abbreviates all of the flags
set on the object into a list of single-character flag characters.
"""
# TODO: Once we add a flag system, add the other flag types here.
type_string = global_defines.OBJECT_TYPES[self.type][1][0]
return type_string
def __str__(self):
return "%s(%d)" % (self.name, self.id,)
return "%s(#%d%s)" % (self.name, self.id, self.flag_string())
import functions_db

View file

@ -20,22 +20,25 @@ def cmd_look(cdat):
if len(args) == 0:
target_obj = session.pobject.location
else:
results = functions_db.local_and_global_search(pobject, ''.join(args))
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(#%s)" % (result.name, result.id,))
session.msg(" %s" % (result,))
return
elif len(results) == 0:
session.msg("I don't see that here.")
return
else:
target_obj = results[0]
retval = "%s%s%s(#%i)%s\r\n%s" % (
retval = "%s%s%s(#%i%s)%s\r\n%s" % (
ansi["normal"],
ansi["hilite"],
target_obj.name,
target_obj.id,
target_obj.flag_string(),
ansi["normal"],
target_obj.description,
)
@ -57,15 +60,15 @@ def cmd_look(cdat):
if con_players:
session.msg("%sPlayers:%s" % (ansi["hilite"], ansi["normal"],))
for player in con_players:
session.msg('%s(#%s)' %(player.name, player.id,))
session.msg('%s' %(player,))
if con_things:
session.msg("%sThings:%s" % (ansi["hilite"], ansi["normal"],))
for thing in con_things:
session.msg('%s(#%s)' %(thing.name, thing.id,))
session.msg('%s' %(thing,))
if con_exits:
session.msg("%sExits:%s" % (ansi["hilite"], ansi["normal"],))
for exit in con_exits:
session.msg('%s(#%s)' %(exit.name, exit.id,))
session.msg('%s' %(exit,))
def cmd_quit(cdat):
"""

View file

@ -12,7 +12,7 @@ def cmd_dig(cdat):
Digs a new room out.
"""
session = cdat['session']
uinput= cdat['uinput']
uinput= cdat['uinput']['splitted']
roomname = ''.join(uinput[1:])
if roomname == '':
@ -22,6 +22,24 @@ def cmd_dig(cdat):
newroom.name = roomname
newroom.type = "Room"
def cmd_create(cdat):
"""
Creates a new object of type 'THING'.
"""
session = cdat['session']
server = session.server
uinput= cdat['uinput']['splitted']
thingname = ''.join(uinput[1:])
if thingname == '':
session.msg("You must supply a room name!")
else:
# Create and set the object up.
odat = {"name": thingname, "type": 3, "location": session.pobject.location, "owner": session.pobject}
new_object = functions_db.create_object(server, odat)
session.msg("You create a new object: %s" % (new_object,))
def cmd_nextfree(cdat):
"""
Returns the next free object number.
@ -55,8 +73,8 @@ def cmd_teleport(cdat):
# a direct teleport, @tel <destination>.
if len(eq_args) > 1:
# Equal sign teleport.
victim = functions_db.local_and_global_search(pobject, eq_args[0])
destination = functions_db.local_and_global_search(pobject, eq_args[1])
victim = functions_db.local_and_global_search(pobject, eq_args[0], searcher=pobject)
destination = functions_db.local_and_global_search(pobject, eq_args[1], searcher=pobject)
if len(victim) == 0:
session.msg("I can't find the victim to teleport.")
@ -89,12 +107,12 @@ def cmd_teleport(cdat):
else:
# Direct teleport (no equal sign)
results = functions_db.local_and_global_search(pobject, search_str)
results = functions_db.local_and_global_search(pobject, search_str, searcher=pobject)
if len(results) > 1:
session.msg("More than one match found (please narrow target):")
for result in results:
session.msg(" %s(#%s)" % (result.name, result.id,))
session.msg(" %s" % (result,))
elif len(results) == 0:
session.msg("I don't see that here.")
return
@ -128,7 +146,7 @@ def cmd_find(cdat):
if len(results) > 0:
session.msg("Name matches for: %s" % (searchstring,))
for result in results:
session.msg(" %s(#%s)" % (result.name, result.id,))
session.msg(" %s" % (result,))
session.msg("%d matches returned." % (len(results),))
else:
session.msg("No name matches found for: %s" % (searchstring,))

View file

@ -1,6 +1,7 @@
import sets
from django.contrib.auth.models import User
from apps.objects.models import Object
import functions_db
def get_nextfree_dbnum():
"""
@ -28,7 +29,7 @@ def list_search_object_namestr(searchlist, ostring, dbref_only=False):
else:
return [prospect for prospect in searchlist if prospect.name_match(ostring)]
def local_and_global_search(object, ostring, local_only=False):
def local_and_global_search(object, ostring, local_only=False, searcher=None):
"""
Searches an object's location then globally for a dbref or name match.
local_only: Only compare the objects in the player's location if True.
@ -46,6 +47,8 @@ def local_and_global_search(object, ostring, local_only=False):
# If the object the invoker is in matches, add it as well.
if object.location.dbref_match(ostring) or ostring == 'here':
local_matches.append(object.location)
elif ostring == 'me' and searcher:
local_matches.append(searcher)
return local_matches
@ -92,6 +95,45 @@ def get_object_from_dbref(server, dbref):
"""
return server.object_list.get(dbref, False)
def create_object(server, odat):
"""
Create a new object. odat is a dictionary that contains the following keys.
REQUIRED KEYS:
* type: Integer representing the object's type.
* name: The name of the new object.
* location: Reference to another object for the new object to reside in.
* owner: The creator of the object.
OPTIONAL KEYS:
* home: Reference to another object to home to. If not specified, use
location key for home.
"""
new_object = Object()
new_object.name = odat["name"]
new_object.type = odat["type"]
#if odat["home"]:
# new_object.home = odat["home"]
#else:
# new_object.home = odat["location"]
#if odat["owner"].zone:
# new_object.zone = odat["owner"].zone
#else:
# new_object.zone = None
#if odat["type"] is 1:
# new_object.owner = new_object
#else:
# new_object.owner = odat["owner"]
new_object.save()
# Add the object to our server's dictionary of objects.
server.add_object_to_cache(new_object)
new_object.move_to(server, odat['location'])
return new_object
def create_user(cdat, uname, email, password):
"""
Handles the creation of new users.
@ -112,9 +154,8 @@ def create_user(cdat, uname, email, password):
user.save
# Create a player object of the same ID in the Objects table.
user_object = Object(id=uid, type=1, name=uname, location=start_room_obj)
user_object.save()
server.add_object_to_cache(user_object)
odat = {"id": uid, "name": uname, "type": 1, "location": start_room_obj, "owner": None}
user_object = functions_db.create_object(server, odat)
# Activate the player's session and set them loose.
session.login(user)

View file

@ -0,0 +1,9 @@
# Do not mess with the default types (0-5).
OBJECT_TYPES = (
(0, 'NOTHING'),
(1, 'PLAYER'),
(2, 'ROOM'),
(3, 'THING'),
(4, 'EXIT'),
(5, 'GARBAGE'),
)