mirror of
https://github.com/evennia/evennia.git
synced 2026-03-27 18:26:32 +01:00
Fixed character swap mechanisms. Created an example command @puppet for switching control between characters (note that it does not currently check permissions, nor make sure the target has the appropriate cmdsets).
This commit is contained in:
parent
922a7d5064
commit
9459178c43
8 changed files with 107 additions and 56 deletions
|
|
@ -343,58 +343,3 @@ class ObjectManager(TypedObjectManager):
|
|||
new_object.attr(attr.attr_name, attr.value)
|
||||
|
||||
return new_object
|
||||
|
||||
|
||||
#
|
||||
# ObjectManager User control
|
||||
#
|
||||
|
||||
def user_swap_object(self, uid, new_obj_id, delete_old_obj=False):
|
||||
"""
|
||||
This moves the user from one database object to another.
|
||||
The new object must already exist.
|
||||
delete_old_obj (bool) - Delete the user's old dbobject.
|
||||
|
||||
This is different from ObjectDB.swap_type() since it actually
|
||||
swaps the database object the user is connected to, rather
|
||||
than change any typeclass on the same dbobject. This means
|
||||
that the old object (typeclass and all) can remain unchanged
|
||||
in-game except it is now not tied to any user.
|
||||
|
||||
Note that the new object will be unchanged, the only
|
||||
difference is that its 'user' property is set to the
|
||||
user. No other initializations are done here, such as
|
||||
setting the default cmdset - this has to be done
|
||||
separately when calling this method.
|
||||
|
||||
This method raises Exceptions instead of logging feedback
|
||||
since this is a method which might be very useful to embed in
|
||||
your own game implementation.
|
||||
|
||||
Also note that this method don't check any permissions beyond
|
||||
making sure no other user is connected to the object before
|
||||
swapping.
|
||||
"""
|
||||
# get the objects.
|
||||
try:
|
||||
user = User.get(uid)
|
||||
new_obj = self.get(new_obj_id)
|
||||
except:
|
||||
raise Exception("OBJ_FIND_ERROR")
|
||||
|
||||
# check so the new object is not already controlled.
|
||||
if new_obj.user:
|
||||
if new_obj.user == user:
|
||||
raise Exception("SELF_CONTROL_ERROR")
|
||||
else:
|
||||
raise Exception("CONTROL_ERROR")
|
||||
# set user to new object.
|
||||
new_obj.user = user
|
||||
new_obj.save()
|
||||
# get old object, sets its user to None and/or delete it
|
||||
for old_obj in self.get_object_with_user(uid):
|
||||
if delete_old_obj:
|
||||
old_obj.delete()
|
||||
else:
|
||||
old_obj.user = None
|
||||
old_obj.save()
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ class ObjectDB(TypedObject):
|
|||
typeclass - auto-linked typeclass
|
||||
date_created - time stamp of object creation
|
||||
permissions - perm strings
|
||||
dbref - #id of object
|
||||
Dbref - #id of object
|
||||
db - persistent attribute storage
|
||||
ndb - non-persistent attribute storage
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue