Changed player.search to only search for players explicitly.
Added a MuxCommandOOC class to handle the OOC commands in a more uniform way. Fixed the @ic/@ooc and page commands. Resolves issue 233. Resolves issue 234.
This commit is contained in:
parent
96e95ca525
commit
8ad4f4a9fc
12 changed files with 253 additions and 168 deletions
|
|
@ -4,7 +4,6 @@ The managers for the custom Player object and permissions.
|
|||
|
||||
import datetime
|
||||
from functools import update_wrapper
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from src.typeclasses.managers import returns_typeclass_list, returns_typeclass, TypedObjectManager
|
||||
from src.utils import logger
|
||||
|
|
@ -181,6 +180,7 @@ class PlayerManager(TypedObjectManager):
|
|||
return matches
|
||||
return self.filter(user__username__iexact=ostring)
|
||||
|
||||
|
||||
def swap_character(self, player, new_character, delete_old_character=False):
|
||||
"""
|
||||
This disconnects a player from the current character (if any) and connects
|
||||
|
|
@ -201,9 +201,10 @@ class PlayerManager(TypedObjectManager):
|
|||
new_character.player = player
|
||||
except Exception:
|
||||
# recover old setup
|
||||
old_character.player = player
|
||||
player.character = old_character
|
||||
if old_character:
|
||||
old_character.player = player
|
||||
player.character = old_character
|
||||
return False
|
||||
if delete_old_character:
|
||||
if old_character and delete_old_character:
|
||||
old_character.delete()
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -50,9 +50,11 @@ from src.typeclasses.models import _get_cache, _set_cache, _del_cache
|
|||
from src.server.sessionhandler import SESSIONS
|
||||
from src.players import manager
|
||||
from src.typeclasses.models import Attribute, TypedObject, TypeNick, TypeNickHandler
|
||||
from src.utils import logger, utils
|
||||
from src.typeclasses.typeclass import TypeClass
|
||||
from src.commands.cmdsethandler import CmdSetHandler
|
||||
from src.commands import cmdhandler
|
||||
from src.utils import logger, utils
|
||||
from src.utils.utils import inherits_from
|
||||
|
||||
__all__ = ("PlayerAttribute", "PlayerNick", "PlayerDB")
|
||||
|
||||
|
|
@ -217,9 +219,11 @@ class PlayerDB(TypedObject):
|
|||
"Getter. Allows for value = self.character"
|
||||
return _get_cache(self, "obj")
|
||||
#@character.setter
|
||||
def character_set(self, value):
|
||||
def character_set(self, character):
|
||||
"Setter. Allows for self.character = value"
|
||||
_set_cache(self, "obj", value)
|
||||
if inherits_from(character, TypeClass):
|
||||
character = character.dbobj
|
||||
_set_cache(self, "obj", character)
|
||||
#@character.deleter
|
||||
def character_del(self):
|
||||
"Deleter. Allows for del self.character"
|
||||
|
|
@ -382,25 +386,17 @@ class PlayerDB(TypedObject):
|
|||
break
|
||||
return cmdhandler.cmdhandler(self.typeclass, raw_string)
|
||||
|
||||
def search(self, ostring, global_search=False, attribute_name=None, use_nicks=False,
|
||||
location=None, ignore_errors=False, player=False):
|
||||
"""
|
||||
A shell method mimicking the ObjectDB equivalent, for easy inclusion from
|
||||
commands regardless of if the command is run by a Player or an Object.
|
||||
def search(self, ostring, return_character=False):
|
||||
"""
|
||||
This is similar to the ObjectDB search method but will search for Players only. Errors
|
||||
will be echoed, and None returned if no Player is found.
|
||||
|
||||
if self.character:
|
||||
# run the normal search
|
||||
return self.character.search(ostring, global_search=global_search, attribute_name=attribute_name,
|
||||
use_nicks=use_nicks, location=location,
|
||||
ignore_errors=ignore_errors, player=player)
|
||||
if player:
|
||||
# seach for players
|
||||
matches = self.__class__.objects.player_search(ostring)
|
||||
else:
|
||||
# more limited player-only search. Still returns an Object.
|
||||
ObjectDB = ContentType.objects.get(app_label="objects", model="objectdb").model_class()
|
||||
matches = ObjectDB.objects.object_search(ostring, caller=self, global_search=global_search)
|
||||
# deal with results
|
||||
matches = _AT_SEARCH_RESULT(self, ostring, matches, global_search=global_search)
|
||||
return_character - will try to return the character the player controls instead of
|
||||
the Player object itself. If no Character exists (since Player is
|
||||
OOC), None will be returned.
|
||||
"""
|
||||
matches = self.__class__.objects.player_search(ostring)
|
||||
matches = _AT_SEARCH_RESULT(self, ostring, matches, global_search=True)
|
||||
if matches and return_character and hasattr(matches, "character"):
|
||||
return matches.character
|
||||
return matches
|
||||
|
|
|
|||
|
|
@ -129,16 +129,14 @@ class Player(TypeClass):
|
|||
This return is not used at all by Evennia by default, but might be useful
|
||||
for coders intending to implement some sort of nested command structure.
|
||||
"""
|
||||
self.dbobj.execute_cmd(raw_string)
|
||||
return self.dbobj.execute_cmd(raw_string)
|
||||
|
||||
def search(self, ostring, global_search=False, attribute_name=None, use_nicks=False,
|
||||
location=None, ignore_errors=False, player=False):
|
||||
def search(self, ostring, return_character=False):
|
||||
"""
|
||||
This method mimicks object.search if self.character is set. Otherwise only
|
||||
other Players can be searched with this method.
|
||||
"""
|
||||
self.dbobj.search(ostring, global_search=global_search, attribute_name=attribute_name, use_nicks=use_nicks,
|
||||
location=location, ignore_errors=ignore_errors, player=player)
|
||||
return self.dbobj.search(ostring, return_character=return_character)
|
||||
|
||||
def is_typeclass(self, typeclass, exact=False):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue