evennia.objects.objects¶
This module defines the basic DefaultObject and its children DefaultCharacter, DefaultAccount, DefaultRoom and DefaultExit. These are the (default) starting points for all in-game visible entities.
-
class
evennia.objects.objects.
ObjectSessionHandler
(obj)[source]¶ Bases:
object
Handles the get/setting of the sessid comma-separated integer field
-
__init__
(obj)[source]¶ Initializes the handler.
- Parameters
obj (DefaultObject) – The object on which the handler is defined.
-
get
(sessid=None)[source]¶ Get the sessions linked to this Object.
- Parameters
sessid (int, optional) – A specific session id.
- Returns
list –
- The sessions connected to this object. If sessid is given,
this is a list of one (or zero) elements.
Notes
Aliased to self.all().
-
add
(session)[source]¶ Add session to handler.
- Parameters
session (Session or int) – Session or session id to add.
Notes
We will only add a session/sessid if this actually also exists in the the core sessionhandler.
-
-
class
evennia.objects.objects.
DefaultObject
(*args, **kwargs)[source]¶ Bases:
evennia.objects.models.ObjectDB
This is the root Object typeclass, representing all entities that have an actual presence in-game. DefaultObjects generally have a location. They can also be manipulated and looked at. Game entities you define should inherit from DefaultObject at some distance.
It is recommended to create children of this class using the evennia.create_object() function rather than to initialize the class directly - this will both set things up and efficiently save the object without obj.save() having to be called explicitly.
Note: Check the autodocs for complete class members, this may not always be up-to date.
Base properties defined/available on all Objects
key (string) - name of object name (string)- same as key dbref (int, read-only) - unique #id-number. Also “id” can be used. date_created (string) - time stamp of object creation
- account (Account) - controlling account (if any, only set together with
sessid below)
- sessid (int, read-only) - session id (if any, only set together with
account above). Use sessions handler to get the Sessions directly.
location (Object) - current location. Is None if this is a room home (Object) - safety start-location has_account (bool, read-only)- will only return connected accounts contents (list, read only) - returns all objects inside this object exits (list of Objects, read-only) - returns all exits from this
object, if any
destination (Object) - only set if this object is an exit. is_superuser (bool, read-only) - True/False if this user is a superuser is_connected (bool, read-only) - True if this object is associated with
an Account with any connected sessions.
has_account (bool, read-only) - True is this object has an associated account. is_superuser (bool, read-only): True if this object has an account and that
account is a superuser.
plural_category (string) - Alias category for the plural strings of this object
Handlers available
aliases - alias-handler: use aliases.add/remove/get() to use. permissions - permission-handler: use permissions.add/remove() to
add/remove new perms.
locks - lock-handler: use locks.add() to add new lock strings scripts - script-handler. Add new scripts to object with scripts.add() cmdset - cmdset-handler. Use cmdset.add() to add new cmdsets to object nicks - nick-handler. New nicks with nicks.add(). sessions - sessions-handler. Get Sessions connected to this
object with sessions.get()
attributes - attribute-handler. Use attributes.add/remove/get. db - attribute-handler: Shortcut for attribute-handler. Store/retrieve
database attributes using self.db.myattr=val, val=self.db.myattr
- ndb - non-persistent attribute handler: same as db but does not create
a database entry when storing data
Helper methods (see src.objects.objects.py for full headers)
get_search_query_replacement(searchdata, **kwargs) get_search_direct_match(searchdata, **kwargs) get_search_candidates(searchdata, **kwargs) get_search_result(searchdata, attribute_name=None, typeclass=None,
candidates=None, exact=False, use_dbref=None, tags=None, **kwargs)
get_stacked_result(results, **kwargs) handle_search_results(searchdata, results, **kwargs) search(searchdata, global_search=False, use_nicks=True, typeclass=None,
location=None, attribute_name=None, quiet=False, exact=False, candidates=None, use_locks=True, nofound_string=None, multimatch_string=None, use_dbref=None, tags=None, stacked=0)
search_account(searchdata, quiet=False) execute_cmd(raw_string, session=None, **kwargs)) msg(text=None, from_obj=None, session=None, options=None, **kwargs) for_contents(func, exclude=None, **kwargs) msg_contents(message, exclude=None, from_obj=None, mapping=None,
raise_funcparse_errors=False, **kwargs)
move_to(destination, quiet=False, emit_to_obj=None, use_destination=True) clear_contents() create(key, account, caller, method, **kwargs) copy(new_key=None) at_object_post_copy(new_obj, **kwargs) delete() is_typeclass(typeclass, exact=False) swap_typeclass(new_typeclass, clean_attributes=False, no_default=True) access(accessing_obj, access_type=’read’, default=False,
no_superuser_bypass=False, **kwargs)
filter_visible(obj_list, looker, **kwargs) get_default_lockstring() get_cmdsets(caller, current, **kwargs) check_permstring(permstring) get_cmdset_providers() get_display_name(looker=None, **kwargs) get_extra_display_name_info(looker=None, **kwargs) get_numbered_name(count, looker, **kwargs) get_display_header(looker, **kwargs) get_display_desc(looker, **kwargs) get_display_exits(looker, **kwargs) get_display_characters(looker, **kwargs) get_display_things(looker, **kwargs) get_display_footer(looker, **kwargs) format_appearance(appearance, looker, **kwargs) return_apperance(looker, **kwargs)
Hooks (these are class methods, so args should start with self):
- basetype_setup() - only called once, used for behind-the-scenes
setup. Normally not modified.
- basetype_posthook_setup() - customization in basetype, after the object
has been created; Normally not modified.
- at_object_creation() - only called once, when object is first created.
Object customizations go here.
- at_object_post_creation() - only called once, when object is first created.
Additional setup involving e.g. prototype-set attributes can go here.
- at_object_delete() - called just before deleting an object. If returning
False, deletion is aborted. Note that all objects inside a deleted object are automatically moved to their <home>, they don’t need to be removed here.
- at_object_post_spawn() - called when object is spawned from a prototype or updated
by the spawner to apply prototype changes.
- at_init() - called whenever typeclass is cached from memory,
at least once every server restart/reload
at_first_save() at_cmdset_get(**kwargs) - this is called just before the command handler
requests a cmdset from this object. The kwargs are not normally used unless the cmdset is created dynamically (see e.g. Exits).
- at_pre_puppet(account)- (account-controlled objects only) called just
before puppeting
- at_post_puppet() - (account-controlled objects only) called just
after completing connection account<->object
- at_pre_unpuppet() - (account-controlled objects only) called just
before un-puppeting
- at_post_unpuppet(account) - (account-controlled objects only) called just
after disconnecting account<->object link
at_server_reload() - called before server is reloaded at_server_shutdown() - called just before server is fully shut down
- at_access(result, accessing_obj, access_type) - called with the result
of a lock access check on this object. Return value does not affect check result.
- at_pre_move(destination) - called just before moving object
to the destination. If returns False, move is cancelled.
- announce_move_from(destination) - called in old location, just
before move, if obj.move_to() has quiet=False
- announce_move_to(source_location) - called in new location, just
after move, if obj.move_to() has quiet=False
- at_post_move(source_location) - always called after a move has
been successfully performed.
at_pre_object_leave(leaving_object, destination, **kwargs) at_object_leave(obj, target_location, move_type=”move”, **kwargs) at_object_leave(obj, target_location) - called when an object leaves
this object in any fashion
at_pre_object_receive(obj, source_location) at_object_receive(obj, source_location, move_type=”move”, **kwargs) - called when this object
receives another object
at_post_move(source_location, move_type=”move”, **kwargs)
- at_traverse(traversing_object, target_location, **kwargs) - (exit-objects only)
handles all moving across the exit, including calling the other exit hooks. Use super() to retain the default functionality.
- at_post_traverse(traversing_object, source_location) - (exit-objects only)
called just after a traversal has happened.
- at_failed_traverse(traversing_object) - (exit-objects only) called if
traversal fails and property err_traverse is not defined.
- at_msg_receive(self, msg, from_obj=None, **kwargs) - called when a message
(via self.msg()) is sent to this obj. If returns false, aborts send.
- at_msg_send(self, msg, to_obj=None, **kwargs) - called when this objects
sends a message to someone via self.msg().
- return_appearance(looker) - describes this object. Used by “look”
command by default
- at_desc(looker=None) - called by ‘look’ whenever the
appearance is requested.
at_pre_get(getter, **kwargs) at_get(getter) - called after object has been picked up.
Does not stop pickup.
at_pre_give(giver, getter, **kwargs) at_give(giver, getter, **kwargs) at_pre_drop(dropper, **kwargs) at_drop(dropper, **kwargs) - called when this object has been dropped. at_pre_say(speaker, message, **kwargs) at_say(message, msg_self=None, msg_location=None, receivers=None, msg_receivers=None, **kwargs)
at_look(target, **kwargs) at_desc(looker=None) at_rename(oldname, newname)
-
cmdset_provider_order
= 100¶
-
cmdset_provider_error_order
= 100¶
-
cmdset_provider_type
= 'object'¶
-
objects
= <evennia.objects.manager.ObjectManager object>¶
-
appearance_template
= '\n{header}\n|c{name}{extra_name_info}|n\n{desc}\n{exits}\n{characters}\n{things}\n{footer}\n '¶
-
plural_category
= 'plural_key'¶
-
property
is_connected
¶ True if this object is associated with an Account with any connected sessions.
-
property
has_account
¶ True is this object has an associated account.
-
get_cmdset_providers
() → dict[source]¶ Overrideable method which returns a dictionary of every kind of object which has a cmdsethandler linked to this Object, and should participate in cmdset merging.
Objects might be aware of an Account. Otherwise, just themselves, by default.
- Returns
dict[str, CmdSetProvider] – The CmdSetProviders linked to this Object.
-
property
is_superuser
¶ True if this object has an account and that account is a superuser.
-
contents_get
(exclude=None, content_type=None)[source]¶ Returns the contents of this object, i.e. all objects that has this object set as its location. This should be publically available.
- Parameters
exclude (DefaultObject) – Object to exclude from returned contents list
content_type (str) – A content_type to filter by. None for no filtering.
- Returns
list – List of contents of this Object.
Notes
Also available as the .contents property, but that doesn’t allow for exclusion and filtering on content-types.
-
contents_set
(*args)[source]¶ Makes sure .contents is read-only. Raises AttributeError if trying to set it.
-
property
contents
¶ Returns the contents of this object, i.e. all objects that has this object set as its location. This should be publically available.
- Parameters
exclude (DefaultObject) – Object to exclude from returned contents list
content_type (str) – A content_type to filter by. None for no filtering.
- Returns
list – List of contents of this Object.
Notes
Also available as the .contents property, but that doesn’t allow for exclusion and filtering on content-types.
-
property
exits
¶ Returns all exits from this object, i.e. all objects at this location having the property .destination != None.
-
get_search_query_replacement
(searchdata, **kwargs)[source]¶ This method is called by the search method to allow for direct replacements of the search string before it is used in the search.
- Parameters
searchdata (str) – The search string to replace.
**kwargs (any) – These are the same as passed to the search method.
- Returns
str – The (potentially modified) search string.
-
get_search_direct_match
(searchdata, **kwargs)[source]¶ This method is called by the search method to allow for direct replacements, such as ‘me’ always being an alias for this object.
- Parameters
searchdata (str) – The search string to replace.
**kwargs (any) – These are the same as passed to the search method.
- Returns
tuple – A tuple (should_return, str or Obj), where should_return is a boolean indicating the .search method should return the result immediately without further processing. If should_return is True, the second element of the tuple is the result that is returned.
-
get_search_candidates
(searchdata, **kwargs)[source]¶ Helper for the .search method. Get the candidates for a search. Also the candidates provided to the search function is included, and could be modified in-place here.
- Parameters
searchdata (str) – The search criterion (could be modified by get_search_query_replacement).
**kwargs (any) – These are the same as passed to the search method.
- Returns
list – A list of objects possibly relevant for the search.
Notes
If searchdata is a #dbref, this method should always return None. This is because the search should always be global in this case. If candidates were already given, they should be used as is. If location was given, the candidates should be based on that.
-
get_search_result
(searchdata, attribute_name=None, typeclass=None, candidates=None, exact=False, use_dbref=None, tags=None, **kwargs)[source]¶ Helper for the .search method. This is a wrapper for actually searching for objects, used by the search method. This is broken out into a separate method to allow for easier overriding in child classes.
- Parameters
searchdata (str) – The search criterion.
attribute_name (str) – The attribute to search on (default is **.
typeclass (Typeclass or list) – The typeclass to search for.
candidates (list) – A list of objects to search between.
exact (bool) – Require exact match.
use_dbref (bool) – Allow dbref search.
tags (list) – Tags to search for.
- Returns
queryset or iterable – The result of the search.
-
get_stacked_results
(results, **kwargs)[source]¶ This method is called by the search method to allow for handling of multi-match results that should be stacked.
- Parameters
results (list) – The list of results from the search.
- Returns
tuple – A tuple (stacked, results), where stacked is a boolean indicating if the result is stacked and results is the list of results to return. If stacked is True, the “.search” method will return results immediately without further processing (it will not result in a multimatch-error).
Notes
The stacked keyword argument is an integer that controls the max size of each stack (if >0). It’s important to make sure to only stack _identical_ objects, otherwise we risk losing track of objects.
-
handle_search_results
(searchdata, results, **kwargs)[source]¶ This method is called by the search method to allow for handling of the final search result.
- Parameters
searchdata (str) – The original search criterion (potentially modified by get_search_query_replacement).
results (list) – The list of results from the search.
**kwargs (any) – These are the same as passed to the search method.
- Returns
Object, None or list – Normally this is a single object, but if quiet=True it should be a list. If quiet=False and we have to handle a no/multi-match error (directly messaging the user), this should return None.
-
search
(searchdata, global_search=False, use_nicks=True, typeclass=None, location=None, attribute_name=None, quiet=False, exact=False, candidates=None, use_locks=True, nofound_string=None, multimatch_string=None, use_dbref=None, tags=None, stacked=0)[source]¶ Returns an Object matching a search string/condition
Perform a standard object search in the database, handling multiple results and lack thereof gracefully. By default, only objects in the current location of self or its inventory are searched for.
- Parameters
searchdata (str or obj) –
Primary search criterion. Will be matched against object.key (with object.aliases second) unless the keyword attribute_name specifies otherwise.
Special keywords:
#<num>: search by unique dbref. This is always a global search.
me,self: self-reference to this object
- <num>-<string> - can be used to differentiate
between multiple same-named matches. The exact form of this input is given by settings.SEARCH_MULTIMATCH_REGEX.
global_search (bool) – Search all objects globally. This overrules ‘location’ data.
use_nicks (bool) – Use nickname-replace (nicktype “object”) on searchdata.
typeclass (str or Typeclass, or list of either) – Limit search only to Objects with this typeclass. May be a list of typeclasses for a broader search.
location (Object or list) – Specify a location or multiple locations to search. Note that this is used to query the contents of a location and will not match for the location itself - if you want that, don’t set this or use candidates to specify exactly which objects should be searched. If this nor candidates are given, candidates will include caller’s inventory, current location and all objects in the current location.
attribute_name (str) – Define which property to search. If set, no key+alias search will be performed. This can be used to search database fields (db_ will be automatically prepended), and if that fails, it will try to return objects having Attributes with this name and value equal to searchdata. A special use is to search for “key” here if you want to do a key-search without including aliases.
quiet (bool) – don’t display default error messages - this tells the search method that the user wants to handle all errors themselves. It also changes the return value type, see below.
exact (bool) – if unset (default) - prefers to match to beginning of string rather than not matching at all. If set, requires exact matching of entire string.
candidates (list of objects) – this is an optional custom list of objects to search (filter) between. It is ignored if global_search is given. If not set, this list will automatically be defined to include the location, the contents of location and the caller’s contents (inventory).
use_locks (bool) – If True (default) - removes search results which fail the “search” lock.
nofound_string (str) – optional custom string for not-found error message.
multimatch_string (str) – optional custom string for multimatch error header.
use_dbref (bool or None, optional) – If True, allow to enter e.g. a query “#123” to find an object (globally) by its database-id 123. If False, the string “#123” will be treated like a normal string. If None (default), the ability to query by #dbref is turned on if self has the permission ‘Builder’ and is turned off otherwise.
tags (list or tuple) – Find objects matching one or more Tags. This should be one or more tag definitions on the form tagname or (tagname, tagcategory).
stacked (int, optional) – If > 0, multimatches will be analyzed to determine if they only contains identical objects; these are then assumed ‘stacked’ and no multi-match error will be generated, instead stacked number of matches will be returned as a list. If stacked is larger than number of matches, returns that number of matches. If the found stack is a mix of objects, return None and handle the multi-match error depending on the value of quiet.
- Returns
Object, None or list – Will return an Object or None if quiet=False. Will return a list with 0, 1 or more matches if quiet=True. If stacked is a positive integer, this list may contain all stacked identical matches.
Notes
To find Accounts, use eg. evennia.account_search. If quiet=False, error messages will be handled by settings.SEARCH_AT_RESULT and echoed automatically (on error, return will be None). If quiet=True, the error messaging is assumed to be handled by the caller.
-
search_account
(searchdata, quiet=False)[source]¶ Simple shortcut wrapper to search for accounts, not characters.
- Parameters
searchdata (str) – Search criterion - the key or dbref of the account to search for. If this is “here” or “me”, search for the account connected to this object.
quiet (bool) – Returns the results as a list rather than echo eventual standard error messages. Default False.
- Returns
DefaultAccount, None or list – What is returned depends on the quiet setting:
quiet=False: No match or multumatch auto-echoes errors to self.msg, then returns None. The esults are passed through settings.SEARCH_AT_RESULT and settings.SEARCH_AT_MULTIMATCH_INPUT. If there is a unique match, this will be returned.
quiet=True: No automatic error messaging is done, and what is returned is always a list with 0, 1 or more matching Accounts.
-
execute_cmd
(raw_string, session=None, **kwargs)[source]¶ Do something as this object. This is never called normally, it’s only used when wanting specifically to let an object be the caller of a command. It makes use of nicks of eventual connected accounts as well.
- Parameters
raw_string (string) – Raw command input
session (Session, optional) – Session to return results to
- Keyword Arguments
keyword arguments will be added to the found command (Other) –
instace as variables before it executes. This is (object) –
by default Evennia but may be used to set flags and (unused) –
operating paramaters for commands at run-time. (change) –
- Returns
Deferred – This is an asynchronous Twisted object that will not fire until the command has actually finished executing. To overload this one needs to attach callback functions to it, with addCallback(function). This function will be called with an eventual return value from the command execution. 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.
-
msg
(text=None, from_obj=None, session=None, options=None, **kwargs)[source]¶ Emits something to a session attached to the object.
- Keyword Arguments
text (str or tuple) – The message to send. This is treated internally like any send-command, so its value can be a tuple if sending multiple arguments to the text oob command.
from_obj (DefaultObject, DefaultAccount, Session, or list) – object that is sending. If given, at_msg_send will be called. This value will be passed on to the protocol. If iterable, will execute hook on all entities in it.
session (Session or list) – Session or list of Sessions to relay data to, if any. If set, will force send to these sessions. If unset, who receives the message depends on the MULTISESSION_MODE.
options (dict) – Message-specific option-value pairs. These will be applied at the protocol level.
**kwargs (string or tuples) – All kwarg keys not listed above will be treated as send-command names and their arguments (which can be a string or a tuple).
Notes
The at_msg_receive method will be called on this Object. All extra kwargs will be passed on to the protocol.
-
for_contents
(func, exclude=None, **kwargs)[source]¶ Runs a function on every object contained within this one.
- Parameters
func (callable) – Function to call. This must have the formal call sign func(obj, kwargs), where obj is the object currently being processed and ****kwargs are passed on from the call to for_contents.
exclude (list, optional) – A list of object not to call the function on.
- Keyword Arguments
arguments will be passed to the function for all objects. (Keyword) –
-
msg_contents
(text=None, exclude=None, from_obj=None, mapping=None, raise_funcparse_errors=False, **kwargs)[source]¶ Emits a message to all objects inside this object.
- Parameters
text (str or tuple) – Message to send. If a tuple, this should be on the valid OOB outmessage form (message, {kwargs}), where kwargs are optional data passed to the text outputfunc. The message will be parsed for {key} formatting and $You/$you()/$You(), $obj(name), $conj(verb) and $pron(pronoun, option) inline function callables. The name is taken from the mapping kwarg {“name”: object, …}**. The mapping[key].get_display_name(looker=recipient) will be called for that key for every recipient of the string.
exclude (list, optional) – A list of objects not to send to.
from_obj (Object, optional) – An object designated as the “sender” of the message. See DefaultObject.msg() for more info. This will be used for $You/you if using funcparser inlines.
mapping (dict, optional) – A mapping of formatting keys {“key”:<object>, “key2”:<object2>,…}. The keys must either match **{key} or $You(key)/$you(key) markers in the text string. If <object> doesn’t have a get_display_name method, it will be returned as a string. Pass “you” to represent the caller, this can be skipped if from_obj is provided (that will then act as ‘you’).
raise_funcparse_errors (bool, optional) – If set, a failing $func() will lead to an outright error. If unset (default), the failing $func() will instead appear in output unparsed.
**kwargs – Keyword arguments will be passed on to obj.msg() for all messaged objects.
Notes
For ‘actor-stance’ reporting (You say/Name says), use the $You()/$you()/$You(key) and $conj(verb) (verb-conjugation) inline callables. This will use the respective get_display_name() for all onlookers except for from_obj or self, which will become ‘You/you’. If you use $You/you(key), the key must be in mapping.
For ‘director-stance’ reporting (Name says/Name says), use {key} syntax directly. For both {key} and You/you(key), mapping[key].get_display_name(looker=recipient) may be called depending on who the recipient is.
Examples
Let’s assume:
player1.key -> “Player1”,
player1.get_display_name(looker=player2) -> “The First girl”
player2.key -> “Player2”,
player2.get_display_name(looker=player1) -> “The Second girl”
Actor-stance:
char.location.msg_contents( "$You() $conj(attack) $you(defender).", from_obj=player1, mapping={"defender": player2})
player1 will see You attack The Second girl.
player2 will see ‘The First girl attacks you.’
Director-stance:
char.location.msg_contents( "{attacker} attacks {defender}.", mapping={"attacker":player1, "defender":player2})
player1 will see: ‘Player1 attacks The Second girl.’
player2 will see: ‘The First girl attacks Player2’
-
move_to
(destination, quiet=False, emit_to_obj=None, use_destination=True, to_none=False, move_hooks=True, move_type='move', **kwargs)[source]¶ Moves this object to a new location.
- Parameters
destination (DefaultObject) – Reference to the object to move to. This can also be an exit object, in which case the destination property is used as destination.
quiet (bool) – If true, turn off the calling of the emit hooks (announce_move_to/from etc)
emit_to_obj (DefaultObject) – object to receive error messages
use_destination (bool) – Default is for objects to use the “destination” property of destinations as the target to move to. Turning off this keyword allows objects to move “inside” exit objects.
to_none (bool) – Allow destination to be None. Note that no hooks are run when moving to a None location. If you want to run hooks, run them manually (and make sure they can manage None locations).
move_hooks (bool) – If False, turn off the calling of move-related hooks (at_pre/post_move etc) with quiet=True, this is as quiet a move as can be done.
move_type (str) – The “kind of move” being performed, such as “teleport”, “traverse”, “get”, “give”, or “drop”. The value can be arbitrary. By default, it only affects the text message generated by announce_move_to and announce_move_from by defining their {“type”: move_type} for outgoing text. This can be used for altering messages and/or overloaded hook behaviors.
**kwargs – Passed on to all movement- and announcement hooks. Use in your game to let hooks know about any special condition of the move (such as running or sneaking). Exits will pass an “exit_obj” kwarg.
- Returns
bool – True/False depending on if there were problems with the move. This method may also return various error messages to the emit_to_obj.
Notes
No access checks are done in this method, these should be handled before calling move_to.
The DefaultObject hooks called (if move_hooks=True) are, in order:
self.at_pre_move(destination) (abort if return False)
source_location.at_pre_object_leave(self, destination) (abort if return False)
destination.at_pre_object_receive(self, source_location) (abort if return False)
source_location.at_object_leave(self, destination)
self.announce_move_from(destination)
(move happens here)
self.announce_move_to(source_location)
destination.at_object_receive(self, source_location)
self.at_post_move(source_location)
-
clear_exits
()[source]¶ Destroys all of the exits and any exits pointing to this object as a destination.
-
clear_contents
()[source]¶ Moves all objects (accounts/things) to their home location or to default home.
-
classmethod
get_default_lockstring
(account: DefaultAccount = None, caller: DefaultObject = None, **kwargs)[source]¶ Classmethod called during .create() to determine default locks for the object.
- Parameters
account (DefaultAccount) – Account to attribute this object to.
caller (DefaultObject) – The object which is creating this one.
**kwargs – Arbitrary input.
- Returns
str – A lockstring to use for this object.
-
classmethod
create
(key: str, account: DefaultAccount = None, caller: DefaultObject = None, method: str = 'create', **kwargs)[source]¶ Creates a basic object with default parameters, unless otherwise specified or extended.
Provides a friendlier interface to the utils.create_object() function.
- Parameters
key (str) – Name of the new object.
- Keyword Arguments
account (DefaultAccount) – Account to attribute this object to.
caller (DefaultObject) – The object which is creating this one.
description (str) – Brief description for this object.
ip (str) – IP address of creator (for object auditing).
method (str) – The method of creation. Defaults to “create”.
- Returns
tuple – A tuple (Object, errors): A newly created object of the given typeclass. This will be None if there are errors. The second element is then a list of errors that occurred during creation. If this is empty, it’s safe to assume the object was created successfully.
-
copy
(new_key=None, **kwargs)[source]¶ Makes an identical copy of this object, identical except for a new dbref in the database. If you want to customize the copy by changing some settings, use ObjectDB.object.copy_object() directly.
- Parameters
new_key (string) – New key/name of copied object. If new_key is not specified, the copy will be named <old_key>_copy by default.
- Returns
Object – A copy of this object.
-
at_object_post_copy
(new_obj, **kwargs)[source]¶ Called by DefaultObject.copy(). Meant to be overloaded. In case there’s extra data not covered by .copy(), this can be used to deal with it.
- Parameters
new_obj (DefaultObject) – The new Copy of this object.
-
delete
()[source]¶ Deletes this object. Before deletion, this method makes sure to move all contained objects to their respective home locations, as well as clean up all exits to/from the object.
- Returns
bool – Whether or not the delete completed successfully or not.
-
access
(accessing_obj, access_type='read', default=False, no_superuser_bypass=False, **kwargs)[source]¶ Determines if another object has permission to access this object in whatever way.
- Parameters
accessing_obj (DefaultObject) – Object trying to access this one.
access_type (str, optional) – Type of access sought.
default (bool, optional) – What to return if no lock of access_type was found.
no_superuser_bypass (bool, optional) – If True, don’t skip lock check for superuser (be careful with this one).
**kwargs – Passed on to the at_access hook along with the result of the access check.
-
filter_visible
(obj_list, looker, **kwargs)[source]¶ Filter a list of objects to only include those that are visible to the looker.
- Parameters
obj_list (list) – List of objects to filter.
looker (DefaultObject) – Object doing the looking.
**kwargs – Arbitrary data for use when overriding.
- Returns
list – The filtered list of visible objects.
Notes
By default this simply checks the ‘view’ and ‘search’ locks on each object in the list. Override this method to implement custom visibility mechanics.
-
get_display_name
(looker=None, **kwargs)[source]¶ Displays the name of the object in a viewer-aware manner.
- Parameters
looker (DefaultObject) – The object or account that is looking at or getting information for this object.
- Returns
str – A name to display for this object. By default this returns the .name of the object.
Notes
This function can be extended to change how object names appear to users in character, but it does not change an object’s keys or aliases when searching.
-
get_extra_display_name_info
(looker=None, **kwargs)[source]¶ Adds any extra display information to the object’s name. By default this is is the object’s dbref in parentheses, if the looker has permission to see it.
- Parameters
looker (DefaultObject) – The object looking at this object.
- Returns
str – The dbref of this object, if the looker has permission to see it. Otherwise, an empty string is returned.
Notes
By default, this becomes a string (#dbref) attached to the object’s name.
-
get_numbered_name
(count, looker, **kwargs)[source]¶ Return the numbered (singular, plural) forms of this object’s key. This is by default called by return_appearance and is used for grouping multiple same-named of this object. Note that this will be called on every member of a group even though the plural name will be only shown once. Also the singular display version, such as ‘an apple’, ‘a tree’ is determined from this method.
- Parameters
count (int) – Number of objects of this type
looker (DefaultObject) – Onlooker. Not used by default.
- Keyword Arguments
key (str) – Optional key to pluralize. If not given, the object’s .get_display_name() method is used.
return_string (bool) – If True, return only the singular form if count is 0,1 or the plural form otherwise. If False (default), return both forms as a tuple.
no_article (bool) – If True, do not return an article if count is 1.
- Returns
tuple – This is a tuple (str, str) with the singular and plural forms of the key including the count.
Examples:
obj.get_numbered_name(3, looker, key="foo") -> ("a foo", "three foos") obj.get_numbered_name(1, looker, key="Foobert", return_string=True) -> "a Foobert" obj.get_numbered_name(1, looker, key="Foobert", return_string=True, no_article=True) -> "Foobert"
-
get_display_header
(looker, **kwargs)[source]¶ Get the ‘header’ component of the object description. Called by return_appearance.
- Parameters
looker (DefaultObject) – Object doing the looking.
**kwargs – Arbitrary data for use when overriding.
- Returns
str – The header display string.
-
get_display_desc
(looker, **kwargs)[source]¶ Get the ‘desc’ component of the object description. Called by return_appearance.
- Parameters
looker (DefaultObject) – Object doing the looking.
**kwargs – Arbitrary data for use when overriding.
- Returns
str – The desc display string.
-
get_display_exits
(looker, **kwargs)[source]¶ Get the ‘exits’ component of the object description. Called by return_appearance.
- Parameters
looker (DefaultObject) – Object doing the looking.
**kwargs – Arbitrary data for use when overriding.
- Keyword Arguments
exit_order (iterable of str) – The order in which exits should be listed, with unspecified exits appearing at the end, alphabetically.
- Returns
str – The exits display data.
Examples:
For a room with exits in the order 'portal', 'south', 'north', and 'out': obj.get_display_name(looker, exit_order=('north', 'south')) -> "Exits: north, south, out, and portal." (markup not shown here)
-
get_display_characters
(looker, **kwargs)[source]¶ Get the ‘characters’ component of the object description. Called by return_appearance.
- Parameters
looker (DefaultObject) – Object doing the looking.
**kwargs – Arbitrary data for use when overriding.
- Returns
str – The character display data.
-
get_display_things
(looker, **kwargs)[source]¶ Get the ‘things’ component of the object description. Called by return_appearance.
- Parameters
looker (DefaultObject) – Object doing the looking.
**kwargs – Arbitrary data for use when overriding.
- Returns
str – The things display data.
Get the ‘footer’ component of the object description. Called by return_appearance.
- Parameters
looker (DefaultObject) – Object doing the looking.
**kwargs – Arbitrary data for use when overriding.
- Returns
str – The footer display string.
-
format_appearance
(appearance, looker, **kwargs)[source]¶ Final processing of the entire appearance string. Called by return_appearance.
- Parameters
appearance (str) – The compiled appearance string.
looker (DefaultObject) – Object doing the looking.
**kwargs – Arbitrary data for use when overriding.
- Returns
str – The final formatted output.
-
return_appearance
(looker, **kwargs)[source]¶ Main callback used by ‘look’ for the object to describe itself. This formats a description. By default, this looks for the appearance_template string set on this class and populates it with formatting keys ‘name’, ‘desc’, ‘exits’, ‘characters’, ‘things’ as well as (currently empty) ‘header’/’footer’. Each of these values are retrieved by a matching method .get_display_*, such as get_display_name, get_display_footer etc.
- Parameters
looker (DefaultObject) – Object doing the looking. Passed into all helper methods.
**kwargs (dict) – Arbitrary, optional arguments for users overriding the call. This is passed into all helper methods.
- Returns
str – The description of this entity. By default this includes the entity’s name, description and any contents inside it.
Notes
To simply change the layout of how the object displays itself (like adding some line decorations or change colors of different sections), you can simply edit .appearance_template. You only need to override this method (and/or its helpers) if you want to change what is passed into the template or want the most control over output.
-
at_first_save
()[source]¶ This is called by the typeclass system whenever an instance of this class is saved for the first time. It is a generic hook for calling the startup hooks for the various game entities. When overloading you generally don’t overload this but overload the hooks called by this method.
-
basetype_setup
()[source]¶ This sets up the default properties of an Object, just before the more general at_object_creation.
You normally don’t need to change this unless you change some fundamental things like names of permission groups.
-
basetype_posthook_setup
()[source]¶ Called once, after basetype_setup and at_object_creation. This should generally not be overloaded unless you are redefining how a room/exit/object works. It allows for basetype-like setup after the object is created. An example of this is EXITs, who need to know keys, aliases, locks etc to set up their exit-cmdsets.
-
at_object_creation
()[source]¶ Called once, when this object is first created. This is the normal hook to overload for most object types.
-
at_object_post_creation
()[source]¶ Called once, when this object is first created and after any attributes, tags, etc. that were passed to the create_object function or defined in a prototype have been applied.
-
at_object_delete
()[source]¶ Called just before the database object is persistently delete()d from the database. If this method returns False, deletion is aborted.
-
at_object_post_spawn
(prototype=None)[source]¶ Called when this object is spawned or updated from a prototype, after all other hooks have been run.
- Keyword Arguments
prototype (dict) – The prototype that was used to spawn or update this object.
-
at_init
()[source]¶ This is always called whenever this object is initiated – that is, whenever it its typeclass is cached from memory. This happens on-demand first time the object is used or activated in some way after being created but also after each server restart or reload.
-
at_cmdset_get
(**kwargs)[source]¶ Called just before cmdsets on this object are requested by the command handler. If changes need to be done on the fly to the cmdset before passing them on to the cmdhandler, this is the place to do it. This is called also if the object currently have no cmdsets.
- Keyword Arguments
caller (DefaultObject, DefaultAccount or Session) – The object requesting the cmdsets.
current (CmdSet) – The current merged cmdset.
force_init (bool) – If True, force a re-build of the cmdset. (seems unused)
**kwargs – Arbitrary input for overloads.
-
get_cmdsets
(caller, current, **kwargs)[source]¶ Called by the CommandHandler to get a list of cmdsets to merge.
- Parameters
caller (DefaultObject) – The object requesting the cmdsets.
current (cmdset) – The current merged cmdset.
**kwargs – Arbitrary input for overloads.
- Returns
tuple – A tuple of (current, cmdsets), which is probably self.cmdset.current and self.cmdset.cmdset_stack
-
at_pre_puppet
(account, session=None, **kwargs)[source]¶ Called just before an Account connects to this object to puppet it.
- Parameters
account (DefaultAccount) – This is the connecting account.
session (Session) – Session controlling the connection.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
-
at_post_puppet
(**kwargs)[source]¶ Called just after puppeting has been completed and all Account<->Object links have been established.
- Parameters
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
Notes
You can use self.account and self.sessions.get() to get account and sessions at this point; the last entry in the list from self.sessions.get() is the latest Session puppeting this Object.
-
at_pre_unpuppet
(**kwargs)[source]¶ Called just before beginning to un-connect a puppeting from this Account.
- Parameters
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
Notes
You can use self.account and self.sessions.get() to get account and sessions at this point; the last entry in the list from self.sessions.get() is the latest Session puppeting this Object.
-
at_post_unpuppet
(account=None, session=None, **kwargs)[source]¶ Called just after the Account successfully disconnected from this object, severing all connections.
- Parameters
account (DefaultAccount) – The account object that just disconnected from this object. This can be None if this is called automatically (such as after a cleanup operation).
session (Session) – Session id controlling the connection that just disconnected.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
-
at_server_reload
()[source]¶ This hook is called whenever the server is shutting down for restart/reboot. If you want to, for example, save non-persistent properties across a restart, this is the place to do it.
-
at_server_shutdown
()[source]¶ This hook is called whenever the server is shutting down fully (i.e. not for a restart).
-
at_access
(result, accessing_obj, access_type, **kwargs)[source]¶ This is called with the result of an access call, along with any kwargs used for that call. The return of this method does not affect the result of the lock check. It can be used e.g. to customize error messages in a central location or other effects based on the access result.
- Parameters
result (bool) – The outcome of the access call.
accessing_obj (Object or Account) – The entity trying to gain access.
access_type (str) – The type of access that was requested.
**kwargs – Arbitrary, optional arguments. Unused by default.
-
at_pre_move
(destination, move_type='move', **kwargs)[source]¶ Called just before starting to move this object to destination. Return False to abort move.
- Parameters
destination (DefaultObject) – The object we are moving to
move_type (str) – The type of move. “give”, “traverse”, etc. This is an arbitrary string provided to obj.move_to(). Useful for altering messages or altering logic depending on the kind of movement.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
- Returns
bool – If we should move or not.
Notes
If this method returns False or None, the move is cancelled before it is even started.
-
at_pre_object_leave
(leaving_object, destination, **kwargs)[source]¶ Called just before this object is about lose an object that was previously ‘inside’ it. Return False to abort move.
- Parameters
leaving_object (DefaultObject) – The object that is about to leave.
destination (DefaultObject) – Where object is going to.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
- Returns
bool – If leaving_object should be allowed to leave or not.
Notes
If this method returns False or None, the move is canceled before it even started.
-
at_pre_object_receive
(arriving_object, source_location, **kwargs)[source]¶ Called just before this object received another object. If this method returns False, the move is aborted and the moved entity remains where it was.
- Parameters
arriving_object (DefaultObject) – The object moved into this one
source_location (DefaultObject) – Where moved_object came from. Note that this could be None.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
- Returns
bool – If False, abort move and moved_obj remains where it was.
Notes
If this method returns False or None, the move is canceled before it even started.
-
at_before_move
(destination, move_type='move', **kwargs)¶ Called just before starting to move this object to destination. Return False to abort move.
- Parameters
destination (DefaultObject) – The object we are moving to
move_type (str) – The type of move. “give”, “traverse”, etc. This is an arbitrary string provided to obj.move_to(). Useful for altering messages or altering logic depending on the kind of movement.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
- Returns
bool – If we should move or not.
Notes
If this method returns False or None, the move is cancelled before it is even started.
-
announce_move_from
(destination, msg=None, mapping=None, move_type='move', **kwargs)[source]¶ Called if the move is to be announced. This is called while we are still standing in the old location.
- Parameters
destination (DefaultObject) – The place we are going to.
msg (str, optional) – a replacement message.
mapping (dict, optional) – additional mapping objects.
move_type (str) – The type of move. “give”, “traverse”, etc. This is an arbitrary string provided to obj.move_to(). Useful for altering messages or altering logic depending on the kind of movement.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
Notes
You can override this method and call its parent with a message to simply change the default message. In the string, you can use the following as mappings:
{object}: the object which is moving.
{exit}: the exit from which the object is moving (if found).
{origin}: the location of the object before the move.
{destination}: the location of the object after moving.
-
announce_move_to
(source_location, msg=None, mapping=None, move_type='move', **kwargs)[source]¶ Called after the move if the move was not quiet. At this point we are standing in the new location.
- Parameters
source_location (DefaultObject) – The place we came from
msg (str, optional) – the replacement message if location.
mapping (dict, optional) – additional mapping objects.
move_type (str) – The type of move. “give”, “traverse”, etc. This is an arbitrary string provided to obj.move_to(). Useful for altering messages or altering logic depending on the kind of movement.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
Notes
You can override this method and call its parent with a message to simply change the default message. In the string, you can use the following as mappings (between braces):
{object}: the object which is moving.
{exit}: the exit from which the object is moving (if found).
{origin}: the location of the object before the move.
{destination}: the location of the object after moving.
-
at_post_move
(source_location, move_type='move', **kwargs)[source]¶ Called after move has completed, regardless of quiet mode or not. Allows changes to the object due to the location it is now in.
- Parameters
source_location (DefaultObject) – Where we came from. This may be None.
move_type (str) – The type of move. “give”, “traverse”, etc. This is an arbitrary string provided to obj.move_to(). Useful for altering messages or altering logic depending on the kind of movement.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
-
at_after_move
(source_location, move_type='move', **kwargs)¶ Called after move has completed, regardless of quiet mode or not. Allows changes to the object due to the location it is now in.
- Parameters
source_location (DefaultObject) – Where we came from. This may be None.
move_type (str) – The type of move. “give”, “traverse”, etc. This is an arbitrary string provided to obj.move_to(). Useful for altering messages or altering logic depending on the kind of movement.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
-
at_object_leave
(moved_obj, target_location, move_type='move', **kwargs)[source]¶ Called just before an object leaves from inside this object
- Parameters
moved_obj (DefaultObject) – The object leaving
target_location (DefaultObject) – Where moved_obj is going.
move_type (str) – The type of move. “give”, “traverse”, etc. This is an arbitrary string provided to obj.move_to(). Useful for altering messages or altering logic depending on the kind of movement.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
-
at_object_receive
(moved_obj, source_location, move_type='move', **kwargs)[source]¶ Called after an object has been moved into this object.
- Parameters
moved_obj (DefaultObject) – The object moved into this one
source_location (DefaultObject) – Where moved_object came from. Note that this could be None.
move_type (str) – The type of move. “give”, “traverse”, etc. This is an arbitrary string provided to obj.move_to(). Useful for altering messages or altering logic depending on the kind of movement.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
-
at_traverse
(traversing_object, target_location, **kwargs)[source]¶ This hook is responsible for handling the actual traversal, normally by calling traversing_object.move_to(target_location). It is normally only implemented by Exit objects. If it returns False (usually because move_to returned False), at_post_traverse below should not be called and instead at_failed_traverse should be called.
- Parameters
traversing_object (DefaultObject) – Object traversing us.
target_location (DefaultObject) – Where target is going.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
-
at_post_traverse
(traversing_object, source_location, **kwargs)[source]¶ Called just after an object successfully used this object to traverse to another object (i.e. this object is a type of Exit)
- Parameters
traversing_object (DefaultObject) – The object traversing us.
source_location (DefaultObject) – Where traversing_object came from.
**kwargs (dict) – Arbitrary, optional arguments for users overriding the call (unused by default).
Notes
The target location should normally be available as self.destination.
-
at_after_traverse
(traversing_object, source_location, **kwargs)¶ Called just after an object successfully used this object to traverse to another object (i.e. this object is a type of Exit)
- Parameters
traversing_object (DefaultObject) – The object traversing us.
source_location (DefaultObject) – Where traversing_object came from.
**kwargs (dict) – Arbitrary, optional arguments for users overriding the call (unused by default).
Notes
The target location should normally be available as self.destination.
-
at_failed_traverse
(traversing_object, **kwargs)[source]¶ This is called if an object fails to traverse this object for some reason.
- Parameters
traversing_object (DefaultObject) – The object that failed traversing us.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
Notes
Using the default exits, this hook will not be called if an Attribute err_traverse is defined - this will in that case be read for an error string instead.
-
at_msg_receive
(text=None, from_obj=None, **kwargs)[source]¶ This hook is called whenever someone sends a message to this object using the msg method.
Note that from_obj may be None if the sender did not include itself as an argument to the obj.msg() call - so you have to check for this. .
Consider this a pre-processing method before msg is passed on to the user session. If this method returns False, the msg will not be passed on.
- Parameters
text (str, optional) – The message received.
from_obj (any, optional) – The object sending the message.
**kwargs – This includes any keywords sent to the msg method.
- Returns
receive (bool) – If this message should be received.
Notes
If this method returns False, the msg operation will abort without sending the message.
-
at_msg_send
(text=None, to_obj=None, **kwargs)[source]¶ This is a hook that is called when this object sends a message to another object with obj.msg(text, to_obj=obj).
- Parameters
text (str, optional) – Text to send.
to_obj (any, optional) – The object to send to.
**kwargs – Keywords passed from msg().
Notes
Since this method is executed by from_obj, if no from_obj was passed to DefaultCharacter.msg this hook will never get called.
-
get_visible_contents
(looker, **kwargs)[source]¶ DEPRECATED Get all contents of this object that a looker can see (whatever that means, by default it checks the ‘view’ and ‘search’ locks and excludes the looker themselves), grouped by type. Helper method to return_appearance.
- Parameters
looker (DefaultObject) – The entity looking.
**kwargs – Passed from return_appearance. Unused by default.
- Returns
dict – A dict of lists categorized by type. Byt default this contains ‘exits’, ‘characters’ and ‘things’. The elements of these lists are the actual objects.
-
get_content_names
(looker, **kwargs)[source]¶ DEPRECATED Get the proper names for all contents of this object. Helper method for return_appearance.
- Parameters
looker (DefaultObject) – The entity looking.
**kwargs – Passed from return_appearance. Passed into get_display_name for each found entity.
- Returns
dict – A dict of lists categorized by type. Byt default this contains ‘exits’, ‘characters’ and ‘things’. The elements of these lists are strings - names of the objects that can depend on the looker and also be grouped in the case of multiple same-named things etc.
Notes
This method shouldn’t add extra coloring to the names beyond what is already given by the .get_display_name() (and the .name field) already. Per-type coloring can be applied in return_appearance.
-
at_look
(target, **kwargs)[source]¶ Called when this object performs a look. It allows to customize just what this means. It will not itself send any data.
- Parameters
target (DefaultObject) – The target being looked at. This is commonly an object or the current location. It will be checked for the “view” type access.
**kwargs – Arbitrary, optional arguments for users overriding the call. This will be passed into return_appearance, get_display_name and at_desc but is not used by default.
- Returns
str – A ready-processed look string potentially ready to return to the looker.
-
at_desc
(looker=None, **kwargs)[source]¶ This is called whenever someone looks at this object.
- Parameters
looker (Object, optional) – The object requesting the description.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
-
at_pre_get
(getter, **kwargs)[source]¶ Called by the default get command before this object has been picked up.
- Parameters
getter (DefaultObject) – The object about to get this object.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
- Returns
bool – If the object should be gotten or not.
Notes
If this method returns False/None, the getting is cancelled before it is even started.
-
at_before_get
(getter, **kwargs)¶ Called by the default get command before this object has been picked up.
- Parameters
getter (DefaultObject) – The object about to get this object.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
- Returns
bool – If the object should be gotten or not.
Notes
If this method returns False/None, the getting is cancelled before it is even started.
-
at_get
(getter, **kwargs)[source]¶ Called by the default get command when this object has been picked up.
- Parameters
getter (DefaultObject) – The object getting this object.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
Notes
This hook cannot stop the pickup from happening. Use permissions or the at_pre_get() hook for that.
-
at_pre_give
(giver, getter, **kwargs)[source]¶ Called by the default give command before this object has been given.
- Parameters
giver (DefaultObject) – The object about to give this object.
getter (DefaultObject) – The object about to get this object.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
- Returns
shouldgive (bool) – If the object should be given or not.
Notes
If this method returns False or None, the giving is cancelled before it is even started.
-
at_before_give
(giver, getter, **kwargs)¶ Called by the default give command before this object has been given.
- Parameters
giver (DefaultObject) – The object about to give this object.
getter (DefaultObject) – The object about to get this object.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
- Returns
shouldgive (bool) – If the object should be given or not.
Notes
If this method returns False or None, the giving is cancelled before it is even started.
-
at_give
(giver, getter, **kwargs)[source]¶ Called by the default give command when this object has been given.
- Parameters
giver (DefaultObject) – The object giving this object.
getter (DefaultObject) – The object getting this object.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
Notes
This hook cannot stop the give from happening. Use permissions or the at_pre_give() hook for that.
-
at_pre_drop
(dropper, **kwargs)[source]¶ Called by the default drop command before this object has been dropped.
- Parameters
dropper (DefaultObject) – The object which will drop this object.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
- Returns
bool – If the object should be dropped or not.
Notes
If this method returns False or None, the dropping is cancelled before it is even started.
-
at_before_drop
(dropper, **kwargs)¶ Called by the default drop command before this object has been dropped.
- Parameters
dropper (DefaultObject) – The object which will drop this object.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
- Returns
bool – If the object should be dropped or not.
Notes
If this method returns False or None, the dropping is cancelled before it is even started.
-
at_drop
(dropper, **kwargs)[source]¶ Called by the default drop command when this object has been dropped.
- Parameters
dropper (DefaultObject) – The object which just dropped this object.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
Notes
This hook cannot stop the drop from happening. Use permissions or the at_pre_drop() hook for that.
-
at_pre_say
(message, **kwargs)[source]¶ Before the object says something.
This hook is by default used by the ‘say’ and ‘whisper’ commands as used by this command it is called before the text is said/whispered and can be used to customize the outgoing text from the object. Returning None aborts the command.
- Parameters
message (str) – The suggested say/whisper text spoken by self.
- Keyword Arguments
whisper (bool) – If True, this is a whisper rather than a say. This is sent by the whisper command by default. Other verbal commands could use this hook in similar ways.
receivers (DefaultObject or iterable) – If set, this is the target or targets for the say/whisper.
- Returns
str – The (possibly modified) text to be spoken.
-
at_before_say
(message, **kwargs)¶ Before the object says something.
This hook is by default used by the ‘say’ and ‘whisper’ commands as used by this command it is called before the text is said/whispered and can be used to customize the outgoing text from the object. Returning None aborts the command.
- Parameters
message (str) – The suggested say/whisper text spoken by self.
- Keyword Arguments
whisper (bool) – If True, this is a whisper rather than a say. This is sent by the whisper command by default. Other verbal commands could use this hook in similar ways.
receivers (DefaultObject or iterable) – If set, this is the target or targets for the say/whisper.
- Returns
str – The (possibly modified) text to be spoken.
-
at_say
(message, msg_self=None, msg_location=None, receivers=None, msg_receivers=None, **kwargs)[source]¶ Display the actual say (or whisper) of self.
This hook should display the actual say/whisper of the object in its location. It should both alert the object (self) and its location that some text is spoken. The overriding of messages or mapping allows for simple customization of the hook without re-writing it completely.
- Parameters
message (str) – The message to convey.
msg_self (bool or str, optional) – If boolean True, echo message to self. If a string, return that message. If False or unset, don’t echo to self.
msg_location (str, optional) – The message to echo to self’s location.
receivers (DefaultObject or iterable, optional) – An eventual receiver or receivers of the message (by default only used by whispers).
msg_receivers (str) – Specific message to pass to the receiver(s). This will parsed with the {receiver} placeholder replaced with the given receiver.
- Keyword Arguments
whisper (bool) – If this is a whisper rather than a say. Kwargs can be used by other verbal commands in a similar way.
mapping (dict) – Pass an additional mapping to the message.
Notes
Messages can contain {} markers. These are substituted against the values passed in the mapping argument.
msg_self = 'You say: "{speech}"' msg_location = '{object} says: "{speech}"' msg_receivers = '{object} whispers: "{speech}"'
Supported markers by default:
{self}: text to self-reference with (default ‘You’)
{speech}: the text spoken/whispered by self.
{object}: the object speaking.
{receiver}: replaced with a single receiver only for strings meant for a specific receiver (otherwise ‘None’).
{all_receivers}: comma-separated list of all receivers, if more than one, otherwise same as receiver
{location}: the location where object is.
-
at_rename
(oldname, newname)[source]¶ This Hook is called by @name on a successful rename.
- Parameters
oldname (str) – The instance’s original name.
newname (str) – The new name for the instance.
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶ Bases:
evennia.objects.models.ObjectDB.MultipleObjectsReturned
-
path
= 'evennia.objects.objects.DefaultObject'¶
-
typename
= 'DefaultObject'¶
-
class
evennia.objects.objects.
DefaultCharacter
(*args, **kwargs)[source]¶ Bases:
evennia.objects.objects.DefaultObject
This implements an Object puppeted by a Session - that is, a character avatar controlled by an account.
-
lockstring
= 'puppet:id({character_id}) or pid({account_id}) or perm(Developer) or pperm(Developer);delete:id({account_id}) or perm(Admin);edit:pid({account_id}) or perm(Admin)'¶
-
classmethod
get_default_lockstring
(account: DefaultAccount = None, caller: DefaultObject = None, **kwargs)[source]¶ Classmethod called during .create() to determine default locks for the object.
- Parameters
account (DefaultAccount) – Account to attribute this object to.
caller (DefaultObject) – The object which is creating this one.
**kwargs – Arbitrary input.
- Returns
str – A lockstring to use for this object.
-
classmethod
create
(key, account: DefaultAccount = None, caller: DefaultObject = None, method: str = 'create', **kwargs)[source]¶ Creates a basic Character with default parameters, unless otherwise specified or extended.
Provides a friendlier interface to the utils.create_character() function.
- Parameters
key (str) – Name of the new Character.
account (obj, optional) – Account to associate this Character with. If unset supplying None– it will change the default lockset and skip creator attribution.
- Keyword Arguments
description (str) – Brief description for this object.
ip (str) – IP address of creator (for object auditing).
other kwargs will be passed into the create_object call. (All) –
- Returns
tuple – (new_character, errors). On error, the new_character is None and errors is a list of error strings (an empty list otherwise).
-
classmethod
normalize_name
(name)[source]¶ Normalize the character name prior to creating.
- Parameters
name (str) – The name of the character
- Returns
str – A valid, latinized name.
Notes
The main purpose of this is to make sure that character names are not created with special unicode characters that look visually identical to latin charaters. This could be used to impersonate other characters.
This method should be refactored to support i18n for non-latin names, but as we (currently) have no bug reports requesting better support of non-latin character sets, requiring character names to be latinified is an acceptable default option.
-
classmethod
validate_name
(name, account=None) → Optional[str, None][source]¶ Validate the character name prior to creating. Overload this function to add custom validators
- Parameters
name (str) – The name of the character
- Keyword Arguments
account (DefaultAccount, optional) – The account creating the character.
- Returns
str or None – A non-empty error message if there is a problem, otherwise None.
-
basetype_setup
()[source]¶ Setup character-specific security.
You should normally not need to overload this, but if you do, make sure to reproduce at least the two last commands in this method (unless you want to fundamentally change how a Character object works).
-
at_post_move
(source_location, move_type='move', **kwargs)[source]¶ We make sure to look around after a move.
-
at_after_move
(source_location, move_type='move', **kwargs)¶ We make sure to look around after a move.
-
at_pre_puppet
(account, session=None, **kwargs)[source]¶ Return the character from storage in None location in at_post_unpuppet. :param account: This is the connecting account. :type account: DefaultAccount :param session: Session controlling the connection. :type session: Session
-
at_post_puppet
(**kwargs)[source]¶ Called just after puppeting has been completed and all Account<->Object links have been established.
- Parameters
**kwargs (dict) – Arbitrary, optional arguments for users overriding the call (unused by default).
Notes
You can use self.account and self.sessions.get() to get account and sessions at this point; the last entry in the list from self.sessions.get() is the latest Session puppeting this Object.
-
at_post_unpuppet
(account=None, session=None, **kwargs)[source]¶ We stove away the character when the account goes ooc/logs off, otherwise the character object will remain in the room also after the account logged off (“headless”, so to say).
- Parameters
account (DefaultAccount) – The account object that just disconnected from this object.
session (Session) – Session controlling the connection that just disconnected.
- Keyword Arguments
reason (str) – If given, adds a reason for the unpuppet. This is set when the user is auto-unpuppeted due to being link-dead.
**kwargs – Arbitrary, optional arguments for users overriding the call (unused by default).
-
property
idle_time
¶ Returns the idle time of the least idle session in seconds. If no sessions are connected it returns nothing.
-
property
connection_time
¶ Returns the maximum connection time of all connected sessions in seconds. Returns nothing if there are no sessions.
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶ Bases:
evennia.objects.objects.DefaultObject.MultipleObjectsReturned
-
path
= 'evennia.objects.objects.DefaultCharacter'¶
-
typename
= 'DefaultCharacter'¶
-
-
class
evennia.objects.objects.
DefaultRoom
(*args, **kwargs)[source]¶ Bases:
evennia.objects.objects.DefaultObject
This is the base room object. It’s just like any Object except its location is always None.
-
classmethod
create
(key: str, account: DefaultAccount = None, caller: evennia.objects.objects.DefaultObject = None, method: str = 'create', **kwargs)[source]¶ Creates a basic Room with default parameters, unless otherwise specified or extended.
Provides a friendlier interface to the utils.create_object() function.
- Parameters
key (str) – Name of the new Room.
- Keyword Arguments
account (DefaultAccount, optional) – Account to associate this Room with. If given, it will be given specific control/edit permissions to this object (along with normal Admin perms). If not given, default
caller (DefaultObject) – The object which is creating this one.
description (str) – Brief description for this object.
ip (str) – IP address of creator (for object auditing).
method (str) – The method used to create the room. Defaults to “create”.
- Returns
tuple – A tuple (Object, error) with the newly created Room of the given typeclass, or None if there was an error. If there was an error, error will be a list of error strings.
-
basetype_setup
()[source]¶ Simple room setup setting locks to make sure the room cannot be picked up.
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶ Bases:
evennia.objects.objects.DefaultObject.MultipleObjectsReturned
-
path
= 'evennia.objects.objects.DefaultRoom'¶
-
typename
= 'DefaultRoom'¶
-
classmethod
-
class
evennia.objects.objects.
ExitCommand
(**kwargs)[source]¶ Bases:
evennia.commands.default.muxcommand.MuxCommand
This is a command that simply cause the caller to traverse the object it is attached to.
-
obj
= None¶
-
get_extra_info
(caller, **kwargs)[source]¶ Shows a bit of information on where the exit leads.
- Parameters
caller (DefaultObject) – The object (usually a character) that entered an ambiguous command.
**kwargs (dict) – Arbitrary, optional arguments for users overriding the call (unused by default).
- Returns
str – A string with identifying information to disambiguate the command, conventionally with a preceding space.
-
aliases
= []¶
-
help_category
= 'general'¶
-
key
= 'command'¶
-
lock_storage
= 'cmd:all();'¶
-
search_index_entry
= {'aliases': '', 'category': 'general', 'key': 'command', 'no_prefix': ' ', 'tags': '', 'text': '\n This is a command that simply cause the caller to traverse\n the object it is attached to.\n\n '}¶
-
-
class
evennia.objects.objects.
DefaultExit
(*args, **kwargs)[source]¶ Bases:
evennia.objects.objects.DefaultObject
This is the base exit object - it connects a location to another. This is done by the exit assigning a “command” on itself with the same name as the exit object (to do this we need to remember to re-create the command when the object is cached since it must be created dynamically depending on what the exit is called). This command (which has a high priority) will thus allow us to traverse exits simply by giving the exit-object’s name on its own.
-
exit_command
¶ alias of
ExitCommand
-
priority
= 101¶
-
create_exit_cmdset
(exidbobj)[source]¶ Helper function for creating an exit command set + command.
The command of this cmdset has the same name as the Exit object and allows the exit to react when the account enter the exit’s name, triggering the movement between rooms.
- Parameters
exidbobj (DefaultObject) – The DefaultExit object to base the command on.
-
classmethod
create
(key: str, location: evennia.objects.objects.DefaultRoom = None, destination: evennia.objects.objects.DefaultRoom = None, account: DefaultAccount = None, caller: evennia.objects.objects.DefaultObject = None, method: str = 'create', **kwargs) → tuple[source]¶ Creates a basic Exit with default parameters, unless otherwise specified or extended.
Provides a friendlier interface to the utils.create_object() function.
- Parameters
key (str) – Name of the new Exit, as it should appear from the source room.
location (Room) – The room to create this exit in.
- Keyword Arguments
account (DefaultAccountDB) – Account to associate this Exit with.
caller (DefaultObject) – The Object creating this Object.
description (str) – Brief description for this object.
ip (str) – IP address of creator (for object auditing).
destination (Room) – The room to which this exit should go.
- Returns
tuple – A tuple (Object, errors), where the object is the newly created exit of the given typeclass, or None if there was an error. If there was an error, errors will be a list of error strings.
-
basetype_setup
()[source]¶ Setup exit-security.
You should normally not need to overload this - if you do make sure you include all the functionality in this method.
-
at_cmdset_get
(**kwargs)[source]¶ Called just before cmdsets on this object are requested by the command handler. If changes need to be done on the fly to the cmdset before passing them on to the cmdhandler, this is the place to do it. This is called also if the object currently has no cmdsets.
- Keyword Arguments
caller (DefaultObject, DefaultAccount or Session) – The object requesting the cmdsets.
current (CmdSet) – The current merged cmdset.
force_init (bool) – If True, force a re-build of the cmdset (for example to update aliases).
-
at_init
()[source]¶ This is called when this objects is re-loaded from cache. When that happens, we make sure to remove any old ExitCmdSet cmdset (this most commonly occurs when renaming an existing exit)
-
at_traverse
(traversing_object, target_location, **kwargs)[source]¶ This implements the actual traversal. The traverse lock has already been checked (in the Exit command) at this point.
- Parameters
traversing_object (DefaultObject) – Object traversing us.
target_location (DefaultObject) – Where target is going.
**kwargs (dict) – Arbitrary, optional arguments for users overriding the call (unused by default).
-
at_failed_traverse
(traversing_object, **kwargs)[source]¶ Overloads the default hook to implement a simple default error message.
- Parameters
traversing_object (DefaultObject) – The object that failed traversing us.
**kwargs (dict) – Arbitrary, optional arguments for users overriding the call (unused by default).
Notes
Using the default exits, this hook will not be called if an Attribute err_traverse is defined - this will in that case be read for an error string instead.
-
get_return_exit
(return_all=False)[source]¶ Get the exits that pair with this one in its destination room (i.e. returns to its location)
- Parameters
return_all (bool) – Whether to return available results as a queryset or single matching exit.
- Returns
Exit or queryset – The matching exit(s). If return_all is True, this will be a queryset of all matching exits. Otherwise, it will be the first Exit matched.
-
exception
DoesNotExist
¶
-
exception
MultipleObjectsReturned
¶ Bases:
evennia.objects.objects.DefaultObject.MultipleObjectsReturned
-
path
= 'evennia.objects.objects.DefaultExit'¶
-
typename
= 'DefaultExit'¶
-