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:
Griatch 2010-10-18 21:07:26 +00:00
parent 922a7d5064
commit 9459178c43
8 changed files with 107 additions and 56 deletions

View file

@ -156,3 +156,32 @@ class PlayerManager(models.Manager):
if not players:
players = self.filter(user__username=ostring)
return players
def swap_character(self, player, new_character, delete_old_character=False):
"""
This disconnects a player from the current character (if any) and connects
to a new character object.
"""
if new_character.player:
# the new character is already linked to a player!
return False
# do the swap
old_character = player.character
if old_character:
old_character.player = None
try:
player.character = new_character
new_character.player = player
except Exception:
# recover old setup
old_character.player = player
player.character = old_character
return False
if delete_old_character:
old_character.delete()
return True