mirror of
https://github.com/evennia/evennia.git
synced 2026-03-26 17:56:32 +01:00
* Updated and expanded the State system; the API changed a bit. You now have to first *create* the state using
GLOBAL_STATE_TABLE.add_state() before adding commands to it. The state can now be much more configured by including as much or as little of the normal default commands into it as wanted (so you can now have states which are almost as normal, except some commands are missing or change their behaviour ... illness or darkness comes to mind). The possibilities here are limitless. * States now also optionally allow traversing exits as well as using command tables defined on objects. * States now better handle error messages (so if you try 'look' in a state which does not contain a look command you will no longer get the 'Huh?' but will be told that the command is not available at the moment). * All examples in commands/examples/ have been updated to use the new State system. Also added a @test_state function for trying out the functionality. * Added hooks at_before_move() and at_after_move(), useful for character based move-restrictions and checks (e.g. movement speed) * Minor tweaks to the event system; avoiding the counters to go negative should they hit an uncaught traceback. * Small fixes of typos and minor extra safety checks. /Griatch
This commit is contained in:
parent
f5b40648a6
commit
1d4f075ca7
16 changed files with 555 additions and 196 deletions
|
|
@ -8,6 +8,7 @@ from django.db import connection
|
|||
from django.contrib.auth.models import User
|
||||
from django.db.models import Q
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.conf import settings
|
||||
|
||||
from src.config.models import ConfigValue
|
||||
from src.objects.exceptions import ObjectNotExist
|
||||
|
|
@ -83,7 +84,6 @@ class ObjectManager(models.Manager):
|
|||
Searches through all objects returning those which has a certain script parent.
|
||||
"""
|
||||
o_query = self.filter(script_parent__exact=script_parent)
|
||||
|
||||
return o_query.exclude(type__in=[defines_global.OTYPE_GARBAGE,
|
||||
defines_global.OTYPE_GOING])
|
||||
|
||||
|
|
@ -124,7 +124,6 @@ class ObjectManager(models.Manager):
|
|||
return dbtotals
|
||||
|
||||
|
||||
|
||||
def player_alias_search(self, searcher, ostring):
|
||||
"""
|
||||
Search players by alias. Returns a list of objects whose "ALIAS"
|
||||
|
|
@ -288,8 +287,10 @@ class ObjectManager(models.Manager):
|
|||
if otype == defines_global.OTYPE_PLAYER:
|
||||
new_object.owner = None
|
||||
new_object.zone = None
|
||||
new_object.script_parent = settings.SCRIPT_DEFAULT_PLAYER
|
||||
else:
|
||||
new_object.owner = owner
|
||||
new_object.script_parent = settings.SCRIPT_DEFAULT_OBJECT
|
||||
|
||||
if new_object.get_owner().get_zone():
|
||||
new_object.zone = new_object.get_owner().get_zone()
|
||||
|
|
@ -308,7 +309,7 @@ class ObjectManager(models.Manager):
|
|||
|
||||
# Rooms have a NULL location.
|
||||
if not new_object.is_room():
|
||||
new_object.move_to(location, force_look=False)
|
||||
new_object.move_to(location, quiet=True, force_look=False)
|
||||
|
||||
return new_object
|
||||
|
||||
|
|
@ -350,11 +351,6 @@ 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(uname,
|
||||
defines_global.OTYPE_PLAYER,
|
||||
start_room_obj,
|
||||
|
|
@ -368,9 +364,12 @@ class ObjectManager(models.Manager):
|
|||
command.session.login(user)
|
||||
|
||||
logger.log_infomsg('Registration: %s' % user_object.get_name())
|
||||
user_object.emit_to("Welcome to %s, %s.\n\r" % (
|
||||
ConfigValue.objects.get_configvalue('site_name'),
|
||||
user_object.get_name(show_dbref=False)))
|
||||
|
||||
#Don't show the greeting; it messes with using the login hooks for
|
||||
#making character creation wizards. /Griatch
|
||||
#user_object.emit_to("Welcome to %s, %s.\n\r" % (
|
||||
# ConfigValue.objects.get_configvalue('site_name'),
|
||||
# user_object.get_name(show_dbref=False)))
|
||||
|
||||
# Add the user to all of the CommChannel objects that are flagged
|
||||
# is_joined_by_default.
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ class Object(models.Model):
|
|||
|
||||
objects = ObjectManager()
|
||||
|
||||
#state system can set a particular command table to be used.
|
||||
#state system can set a particular command table to be used (not persistent).
|
||||
state = None
|
||||
|
||||
def __cmp__(self, other):
|
||||
|
|
@ -141,6 +141,12 @@ class Object(models.Model):
|
|||
|
||||
class Meta:
|
||||
ordering = ['-date_created', 'id']
|
||||
|
||||
def dbref(self):
|
||||
"""Returns the object's dbref id on the form #NN, directly
|
||||
usable by Object.objects.dbref_search()
|
||||
"""
|
||||
return "#%s" % str(self.id)
|
||||
|
||||
"""
|
||||
BEGIN COMMON METHODS
|
||||
|
|
@ -245,8 +251,7 @@ class Object(models.Model):
|
|||
Returns True if the object is a staff player.
|
||||
"""
|
||||
if not self.is_player():
|
||||
return False
|
||||
|
||||
return False
|
||||
try:
|
||||
profile = self.get_user_account()
|
||||
return profile.is_staff
|
||||
|
|
@ -303,7 +308,7 @@ class Object(models.Model):
|
|||
user. This form accepts an iterable of strings representing permissions,
|
||||
if the user has any of them return true.
|
||||
|
||||
perm: (iterable) An iterable of strings of permissions.
|
||||
perm_list: (iterable) An iterable of strings of permissions.
|
||||
"""
|
||||
if not self.is_player():
|
||||
return False
|
||||
|
|
@ -705,9 +710,9 @@ class Object(models.Model):
|
|||
# in SQLite.
|
||||
flags = str(self.flags).split()
|
||||
nosave_flags = str(self.nosave_flags).split()
|
||||
return flag in flags or flag in nosave_flags
|
||||
return flag.upper() in flags or flag in nosave_flags
|
||||
|
||||
def set_flag(self, flag, value):
|
||||
def set_flag(self, flag, value=True):
|
||||
"""
|
||||
Add a flag to our object's flag list.
|
||||
|
||||
|
|
@ -735,7 +740,7 @@ class Object(models.Model):
|
|||
# Object doesn't have the flag to begin with.
|
||||
pass
|
||||
elif value == True and has_flag:
|
||||
# We've already go it.
|
||||
# We've already got it.
|
||||
pass
|
||||
else:
|
||||
# Setting a flag.
|
||||
|
|
@ -755,6 +760,9 @@ class Object(models.Model):
|
|||
flags.append(flag)
|
||||
self.flags = ' '.join(flags)
|
||||
self.save()
|
||||
|
||||
def unset_flag(self, flag):
|
||||
self.set_flag(flag,value=False)
|
||||
|
||||
def is_connected_plr(self):
|
||||
"""
|
||||
|
|
@ -885,8 +893,13 @@ class Object(models.Model):
|
|||
|
||||
target: (Object) Reference to the object to move to.
|
||||
quiet: (bool) If true, don't emit left/arrived messages.
|
||||
force_look: (bool) If true and target is a player, make them 'look'.
|
||||
force_look: (bool) If true and self is a player, make them 'look'.
|
||||
"""
|
||||
|
||||
#before the move, call the appropriate hook
|
||||
if self.scriptlink.at_before_move(target) != None:
|
||||
return
|
||||
|
||||
if not quiet:
|
||||
location = self.get_location()
|
||||
if location:
|
||||
|
|
@ -897,17 +910,21 @@ class Object(models.Model):
|
|||
(self.get_name()))
|
||||
|
||||
self.location = target
|
||||
self.save()
|
||||
self.save()
|
||||
|
||||
if not quiet:
|
||||
arrival_message = "%s has arrived." % (self.get_name())
|
||||
self.get_location().emit_to_contents(arrival_message, exclude=self)
|
||||
if self.location.is_player():
|
||||
self.location.emit_to("%s is now in your inventory." % (self.get_name()))
|
||||
|
||||
|
||||
#execute eventual extra commands on this object after moving it
|
||||
self.scriptlink.at_after_move()
|
||||
|
||||
if force_look:
|
||||
self.execute_cmd('look')
|
||||
|
||||
|
||||
|
||||
def dbref_match(self, oname):
|
||||
"""
|
||||
Check if the input (oname) can be used to identify this particular object
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue