mirror of
https://github.com/evennia/evennia.git
synced 2026-03-30 04:27:16 +02:00
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.
|
||||
# TODO: This dictionary stuff is silly. Feex.
|
||||
odat = {"name": target_name,
|
||||
"type": defines_global.OTYPE_THING,
|
||||
"location": source_object,
|
||||
"owner": source_object}
|
||||
new_object = Object.objects.create_object(odat)
|
||||
#odat = {"name": target_name,
|
||||
# "type": defines_global.OTYPE_THING,
|
||||
# "location": source_object,
|
||||
# "owner": source_object}
|
||||
new_object = Object.objects.create_object(target_name,
|
||||
defines_global.OTYPE_THING,
|
||||
source_object,
|
||||
source_object)
|
||||
new_object.set_attribute('desc', 'Nothing special.')
|
||||
if len(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!")
|
||||
return
|
||||
|
||||
odat = {"name": exit_name,
|
||||
"type": defines_global.OTYPE_EXIT,
|
||||
"location": source_object.get_location(),
|
||||
"owner": source_object,
|
||||
"home": destination}
|
||||
new_object = Object.objects.create_object(odat)
|
||||
#odat = {"name": exit_name,
|
||||
# "type": defines_global.OTYPE_EXIT,
|
||||
# "location": source_object.get_location(),
|
||||
# "owner": source_object,
|
||||
# "home": destination}
|
||||
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" % (
|
||||
new_object.get_name(),
|
||||
destination.get_name()))
|
||||
if len(comma_split) > 1:
|
||||
second_exit_name = ','.join(comma_split[1:])
|
||||
odat = {"name": second_exit_name,
|
||||
"type": defines_global.OTYPE_EXIT,
|
||||
"location": destination,
|
||||
"owner": source_object,
|
||||
"home": source_object.get_location()}
|
||||
new_object = Object.objects.create_object(odat)
|
||||
#odat = {"name": second_exit_name,
|
||||
# "type": defines_global.OTYPE_EXIT,
|
||||
# "location": destination,
|
||||
# "owner": source_object,
|
||||
# "home": source_object.get_location()}
|
||||
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" % (
|
||||
new_object.get_name(),
|
||||
source_object.get_location().get_name()))
|
||||
|
||||
else:
|
||||
# Create an un-linked exit.
|
||||
odat = {"name": exit_name,
|
||||
"type": defines_global.OTYPE_EXIT,
|
||||
"location": source_object.get_location(),
|
||||
"owner": source_object,
|
||||
"home": None}
|
||||
new_object = Object.objects.create_object(odat)
|
||||
|
||||
#odat = {"name": exit_name,
|
||||
# "type": defines_global.OTYPE_EXIT,
|
||||
# "location": source_object.get_location(),
|
||||
# "owner": source_object,
|
||||
# "home": None}
|
||||
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)
|
||||
GLOBAL_CMD_TABLE.add_command("@open", cmd_open,
|
||||
priv_tuple=("genperms.builder"))
|
||||
|
|
@ -695,11 +709,14 @@ def cmd_dig(command):
|
|||
source_object.emit_to("You must supply a new room name.")
|
||||
else:
|
||||
# Create and set the object up.
|
||||
odat = {"name": roomname,
|
||||
"type": defines_global.OTYPE_ROOM,
|
||||
"location": None,
|
||||
"owner": source_object}
|
||||
new_room = Object.objects.create_object(odat)
|
||||
#odat = {"name": roomname,
|
||||
# "type": defines_global.OTYPE_ROOM,
|
||||
# "location": None,
|
||||
# "owner": source_object}
|
||||
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,))
|
||||
|
||||
if parent:
|
||||
|
|
@ -714,22 +731,30 @@ def cmd_dig(command):
|
|||
location = source_object.get_location()
|
||||
|
||||
#create an exit from here to the new room.
|
||||
odat = {"name": exits[0].strip(),
|
||||
"type": defines_global.OTYPE_EXIT,
|
||||
"location": location,
|
||||
"owner": source_object,
|
||||
"home": destination}
|
||||
new_object = Object.objects.create_object(odat)
|
||||
#odat = {"name": exits[0].strip(),
|
||||
# "type": defines_global.OTYPE_EXIT,
|
||||
# "location": location,
|
||||
# "owner": source_object,
|
||||
# "home": destination}
|
||||
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))
|
||||
|
||||
if len(exits)>1:
|
||||
#create exit back to this room
|
||||
odat = {"name": exits[1].strip(),
|
||||
"type": defines_global.OTYPE_EXIT,
|
||||
"location": destination,
|
||||
"owner": source_object,
|
||||
"home": location}
|
||||
new_object = Object.objects.create_object(odat)
|
||||
#odat = {"name": exits[1].strip(),
|
||||
# "type": defines_global.OTYPE_EXIT,
|
||||
# "location": destination,
|
||||
# "owner": source_object,
|
||||
# "home": location}
|
||||
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))
|
||||
if 'teleport' in switches:
|
||||
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.set_owner(god_user_obj)
|
||||
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.save()
|
||||
|
||||
|
|
|
|||
|
|
@ -255,17 +255,16 @@ class ObjectManager(models.Manager):
|
|||
except self.model.DoesNotExist:
|
||||
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.
|
||||
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.
|
||||
Create a new object
|
||||
|
||||
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.
|
||||
home: Reference to another object to home to. If not specified,
|
||||
set to location.
|
||||
"""
|
||||
#get_nextfree_dbnum() returns either an integer or an object to recycle.
|
||||
next_dbref = self.get_nextfree_dbnum()
|
||||
|
|
@ -280,36 +279,36 @@ class ObjectManager(models.Manager):
|
|||
#recycle an old object's dbref
|
||||
new_object = next_dbref
|
||||
|
||||
new_object.type = odat["type"]
|
||||
new_object.set_name(odat["name"])
|
||||
new_object.type = otype
|
||||
new_object.set_name(name)
|
||||
|
||||
# If this is a player, we don't want him owned by anyone.
|
||||
# The get_owner() function will return that the player owns
|
||||
# himself.
|
||||
if odat["type"] == defines_global.OTYPE_PLAYER:
|
||||
if otype == defines_global.OTYPE_PLAYER:
|
||||
new_object.owner = None
|
||||
new_object.zone = None
|
||||
else:
|
||||
new_object.owner = odat["owner"]
|
||||
new_object.owner = owner
|
||||
|
||||
if 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
|
||||
# the location key.
|
||||
if odat.has_key("home"):
|
||||
new_object.home = odat["home"]
|
||||
if home:
|
||||
new_object.home = home
|
||||
else:
|
||||
if new_object.is_exit():
|
||||
new_object.home = None
|
||||
else:
|
||||
new_object.home = odat["location"]
|
||||
new_object.home = location
|
||||
|
||||
new_object.save()
|
||||
|
||||
# Rooms have a NULL location.
|
||||
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
|
||||
|
||||
|
|
@ -351,12 +350,15 @@ class ObjectManager(models.Manager):
|
|||
user = User.objects.get(id=uid)
|
||||
|
||||
# Create a player object of the same ID in the Objects table.
|
||||
odat = {"id": uid,
|
||||
"name": uname,
|
||||
"type": defines_global.OTYPE_PLAYER,
|
||||
"location": start_room_obj,
|
||||
"owner": None}
|
||||
user_object = self.create_object(odat)
|
||||
#odat = {"id": uid,
|
||||
# "name": uname,
|
||||
# "type": defines_global.OTYPE_PLAYER,
|
||||
# "location": start_room_obj,
|
||||
# "owner": None}
|
||||
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
|
||||
# game to further prepare things.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue