Changed the input format of the create_object() function as suggested in the code. A more normal function now, no more strange dictionary input.
This commit is contained in:
parent
9bf3e48def
commit
c339c1f6f6
3 changed files with 93 additions and 66 deletions
|
|
@ -291,11 +291,14 @@ def cmd_create(command):
|
||||||
|
|
||||||
# Create and set the object up.
|
# Create and set the object up.
|
||||||
# TODO: This dictionary stuff is silly. Feex.
|
# TODO: This dictionary stuff is silly. Feex.
|
||||||
odat = {"name": target_name,
|
#odat = {"name": target_name,
|
||||||
"type": defines_global.OTYPE_THING,
|
# "type": defines_global.OTYPE_THING,
|
||||||
"location": source_object,
|
# "location": source_object,
|
||||||
"owner": source_object}
|
# "owner": source_object}
|
||||||
new_object = Object.objects.create_object(odat)
|
new_object = Object.objects.create_object(target_name,
|
||||||
|
defines_global.OTYPE_THING,
|
||||||
|
source_object,
|
||||||
|
source_object)
|
||||||
new_object.set_attribute('desc', 'Nothing special.')
|
new_object.set_attribute('desc', 'Nothing special.')
|
||||||
if len(eq_args)>1:
|
if len(eq_args)>1:
|
||||||
parent_str = eq_args[1]
|
parent_str = eq_args[1]
|
||||||
|
|
@ -431,37 +434,48 @@ def cmd_open(command):
|
||||||
source_object.emit_to("You can't open an exit to an exit!")
|
source_object.emit_to("You can't open an exit to an exit!")
|
||||||
return
|
return
|
||||||
|
|
||||||
odat = {"name": exit_name,
|
#odat = {"name": exit_name,
|
||||||
"type": defines_global.OTYPE_EXIT,
|
# "type": defines_global.OTYPE_EXIT,
|
||||||
"location": source_object.get_location(),
|
# "location": source_object.get_location(),
|
||||||
"owner": source_object,
|
# "owner": source_object,
|
||||||
"home": destination}
|
# "home": destination}
|
||||||
new_object = Object.objects.create_object(odat)
|
new_object = Object.objects.create_object(exit_name,
|
||||||
|
defines_global.OTYPE_EXIT,
|
||||||
|
source_object.get_location(),
|
||||||
|
source_object,
|
||||||
|
destination)
|
||||||
|
|
||||||
source_object.emit_to("You open the an exit - %s to %s" % (
|
source_object.emit_to("You open the an exit - %s to %s" % (
|
||||||
new_object.get_name(),
|
new_object.get_name(),
|
||||||
destination.get_name()))
|
destination.get_name()))
|
||||||
if len(comma_split) > 1:
|
if len(comma_split) > 1:
|
||||||
second_exit_name = ','.join(comma_split[1:])
|
second_exit_name = ','.join(comma_split[1:])
|
||||||
odat = {"name": second_exit_name,
|
#odat = {"name": second_exit_name,
|
||||||
"type": defines_global.OTYPE_EXIT,
|
# "type": defines_global.OTYPE_EXIT,
|
||||||
"location": destination,
|
# "location": destination,
|
||||||
"owner": source_object,
|
# "owner": source_object,
|
||||||
"home": source_object.get_location()}
|
# "home": source_object.get_location()}
|
||||||
new_object = Object.objects.create_object(odat)
|
new_object = Object.objects.create_object(second_exit_name,
|
||||||
|
defines_global.OTYPE_EXIT,
|
||||||
|
destination,
|
||||||
|
source_object,
|
||||||
|
source_object.get_location())
|
||||||
source_object.emit_to("You open the an exit - %s to %s" % (
|
source_object.emit_to("You open the an exit - %s to %s" % (
|
||||||
new_object.get_name(),
|
new_object.get_name(),
|
||||||
source_object.get_location().get_name()))
|
source_object.get_location().get_name()))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Create an un-linked exit.
|
# Create an un-linked exit.
|
||||||
odat = {"name": exit_name,
|
#odat = {"name": exit_name,
|
||||||
"type": defines_global.OTYPE_EXIT,
|
# "type": defines_global.OTYPE_EXIT,
|
||||||
"location": source_object.get_location(),
|
# "location": source_object.get_location(),
|
||||||
"owner": source_object,
|
# "owner": source_object,
|
||||||
"home": None}
|
# "home": None}
|
||||||
new_object = Object.objects.create_object(odat)
|
new_object = Object.objects.create_object(exit_name,
|
||||||
|
defines_global.OTYPE_EXIT,
|
||||||
|
source_object.get_location(),
|
||||||
|
source_object,
|
||||||
|
None)
|
||||||
source_object.emit_to("You open an unlinked exit - %s" % new_object)
|
source_object.emit_to("You open an unlinked exit - %s" % new_object)
|
||||||
GLOBAL_CMD_TABLE.add_command("@open", cmd_open,
|
GLOBAL_CMD_TABLE.add_command("@open", cmd_open,
|
||||||
priv_tuple=("genperms.builder"))
|
priv_tuple=("genperms.builder"))
|
||||||
|
|
@ -695,11 +709,14 @@ def cmd_dig(command):
|
||||||
source_object.emit_to("You must supply a new room name.")
|
source_object.emit_to("You must supply a new room name.")
|
||||||
else:
|
else:
|
||||||
# Create and set the object up.
|
# Create and set the object up.
|
||||||
odat = {"name": roomname,
|
#odat = {"name": roomname,
|
||||||
"type": defines_global.OTYPE_ROOM,
|
# "type": defines_global.OTYPE_ROOM,
|
||||||
"location": None,
|
# "location": None,
|
||||||
"owner": source_object}
|
# "owner": source_object}
|
||||||
new_room = Object.objects.create_object(odat)
|
new_room = Object.objects.create_object(roomname,
|
||||||
|
defines_global.OTYPE_ROOM,
|
||||||
|
None,
|
||||||
|
source_object)
|
||||||
source_object.emit_to("Created a new room '%s'." % (new_room,))
|
source_object.emit_to("Created a new room '%s'." % (new_room,))
|
||||||
|
|
||||||
if parent:
|
if parent:
|
||||||
|
|
@ -714,22 +731,30 @@ def cmd_dig(command):
|
||||||
location = source_object.get_location()
|
location = source_object.get_location()
|
||||||
|
|
||||||
#create an exit from here to the new room.
|
#create an exit from here to the new room.
|
||||||
odat = {"name": exits[0].strip(),
|
#odat = {"name": exits[0].strip(),
|
||||||
"type": defines_global.OTYPE_EXIT,
|
# "type": defines_global.OTYPE_EXIT,
|
||||||
"location": location,
|
# "location": location,
|
||||||
"owner": source_object,
|
# "owner": source_object,
|
||||||
"home": destination}
|
# "home": destination}
|
||||||
new_object = Object.objects.create_object(odat)
|
new_object = Object.objects.create_object(exits[0].strip(),
|
||||||
|
defines_global.OTYPE_EXIT,
|
||||||
|
location,
|
||||||
|
source_object,
|
||||||
|
destination)
|
||||||
source_object.emit_to("Created exit from %s to %s named '%s'." % (location,destination,new_object))
|
source_object.emit_to("Created exit from %s to %s named '%s'." % (location,destination,new_object))
|
||||||
|
|
||||||
if len(exits)>1:
|
if len(exits)>1:
|
||||||
#create exit back to this room
|
#create exit back to this room
|
||||||
odat = {"name": exits[1].strip(),
|
#odat = {"name": exits[1].strip(),
|
||||||
"type": defines_global.OTYPE_EXIT,
|
# "type": defines_global.OTYPE_EXIT,
|
||||||
"location": destination,
|
# "location": destination,
|
||||||
"owner": source_object,
|
# "owner": source_object,
|
||||||
"home": location}
|
# "home": location}
|
||||||
new_object = Object.objects.create_object(odat)
|
new_object = Object.objects.create_object(exits[1].strip(),
|
||||||
|
defines_global.OTYPE_EXIT,
|
||||||
|
destination,
|
||||||
|
source_object,
|
||||||
|
location)
|
||||||
source_object.emit_to("Created exit back from %s to %s named '%s'" % (destination, location, new_object))
|
source_object.emit_to("Created exit back from %s to %s named '%s'" % (destination, location, new_object))
|
||||||
if 'teleport' in switches:
|
if 'teleport' in switches:
|
||||||
source_object.move_to(new_room)
|
source_object.move_to(new_room)
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ def create_objects():
|
||||||
limbo_obj = Object(id=2, type=defines_global.OTYPE_ROOM)
|
limbo_obj = Object(id=2, type=defines_global.OTYPE_ROOM)
|
||||||
limbo_obj.set_owner(god_user_obj)
|
limbo_obj.set_owner(god_user_obj)
|
||||||
limbo_obj.set_name('%ch%ccLimbo%cn')
|
limbo_obj.set_name('%ch%ccLimbo%cn')
|
||||||
limbo_obj.set_attribute('desc',"Welcome to your new Evennia-based game. From here you are ready to begin development. If you should need help or would like to participate in community discussions, visit http://evennia.com.")
|
limbo_obj.set_attribute('desc',"Welcome to your new %chEvennia%cn-based game. From here you are ready to begin development. If you should need help or would like to participate in community discussions, visit http://evennia.com.")
|
||||||
limbo_obj.scriptlink.at_object_creation()
|
limbo_obj.scriptlink.at_object_creation()
|
||||||
limbo_obj.save()
|
limbo_obj.save()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -255,17 +255,16 @@ class ObjectManager(models.Manager):
|
||||||
except self.model.DoesNotExist:
|
except self.model.DoesNotExist:
|
||||||
raise ObjectNotExist(dbref)
|
raise ObjectNotExist(dbref)
|
||||||
|
|
||||||
def create_object(self, odat):
|
def create_object(self, name, otype, location, owner, home=None):
|
||||||
"""
|
"""
|
||||||
Create a new object. odat is a dictionary that contains the following keys.
|
Create a new object
|
||||||
REQUIRED KEYS:
|
|
||||||
* type: Integer representing the object's type.
|
type: Integer representing the object's type.
|
||||||
* name: The name of the new object.
|
name: The name of the new object.
|
||||||
* location: Reference to another object for the new object to reside in.
|
location: Reference to another object for the new object to reside in.
|
||||||
* owner: The creator of the object.
|
owner: The creator of the object.
|
||||||
OPTIONAL KEYS:
|
home: Reference to another object to home to. If not specified,
|
||||||
* home: Reference to another object to home to. If not specified, use
|
set to location.
|
||||||
location key for home.
|
|
||||||
"""
|
"""
|
||||||
#get_nextfree_dbnum() returns either an integer or an object to recycle.
|
#get_nextfree_dbnum() returns either an integer or an object to recycle.
|
||||||
next_dbref = self.get_nextfree_dbnum()
|
next_dbref = self.get_nextfree_dbnum()
|
||||||
|
|
@ -280,36 +279,36 @@ class ObjectManager(models.Manager):
|
||||||
#recycle an old object's dbref
|
#recycle an old object's dbref
|
||||||
new_object = next_dbref
|
new_object = next_dbref
|
||||||
|
|
||||||
new_object.type = odat["type"]
|
new_object.type = otype
|
||||||
new_object.set_name(odat["name"])
|
new_object.set_name(name)
|
||||||
|
|
||||||
# If this is a player, we don't want him owned by anyone.
|
# If this is a player, we don't want him owned by anyone.
|
||||||
# The get_owner() function will return that the player owns
|
# The get_owner() function will return that the player owns
|
||||||
# himself.
|
# himself.
|
||||||
if odat["type"] == defines_global.OTYPE_PLAYER:
|
if otype == defines_global.OTYPE_PLAYER:
|
||||||
new_object.owner = None
|
new_object.owner = None
|
||||||
new_object.zone = None
|
new_object.zone = None
|
||||||
else:
|
else:
|
||||||
new_object.owner = odat["owner"]
|
new_object.owner = owner
|
||||||
|
|
||||||
if new_object.get_owner().get_zone():
|
if new_object.get_owner().get_zone():
|
||||||
new_object.zone = new_object.get_owner().get_zone()
|
new_object.zone = new_object.get_owner().get_zone()
|
||||||
|
|
||||||
# If we have a 'home' key, use that for our home value. Otherwise use
|
# If we have a 'home' key, use that for our home value. Otherwise use
|
||||||
# the location key.
|
# the location key.
|
||||||
if odat.has_key("home"):
|
if home:
|
||||||
new_object.home = odat["home"]
|
new_object.home = home
|
||||||
else:
|
else:
|
||||||
if new_object.is_exit():
|
if new_object.is_exit():
|
||||||
new_object.home = None
|
new_object.home = None
|
||||||
else:
|
else:
|
||||||
new_object.home = odat["location"]
|
new_object.home = location
|
||||||
|
|
||||||
new_object.save()
|
new_object.save()
|
||||||
|
|
||||||
# Rooms have a NULL location.
|
# Rooms have a NULL location.
|
||||||
if not new_object.is_room():
|
if not new_object.is_room():
|
||||||
new_object.move_to(odat['location'], force_look=False)
|
new_object.move_to(location, force_look=False)
|
||||||
|
|
||||||
return new_object
|
return new_object
|
||||||
|
|
||||||
|
|
@ -351,12 +350,15 @@ class ObjectManager(models.Manager):
|
||||||
user = User.objects.get(id=uid)
|
user = User.objects.get(id=uid)
|
||||||
|
|
||||||
# Create a player object of the same ID in the Objects table.
|
# Create a player object of the same ID in the Objects table.
|
||||||
odat = {"id": uid,
|
#odat = {"id": uid,
|
||||||
"name": uname,
|
# "name": uname,
|
||||||
"type": defines_global.OTYPE_PLAYER,
|
# "type": defines_global.OTYPE_PLAYER,
|
||||||
"location": start_room_obj,
|
# "location": start_room_obj,
|
||||||
"owner": None}
|
# "owner": None}
|
||||||
user_object = self.create_object(odat)
|
user_object = self.create_object(uname,
|
||||||
|
defines_global.OTYPE_PLAYER,
|
||||||
|
start_room_obj,
|
||||||
|
None)
|
||||||
|
|
||||||
# The User and player Object are ready, do anything needed by the
|
# The User and player Object are ready, do anything needed by the
|
||||||
# game to further prepare things.
|
# game to further prepare things.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue