We now have a working flags system. Yay.
This commit is contained in:
parent
82039e8053
commit
833d7b3b45
5 changed files with 109 additions and 13 deletions
|
|
@ -57,6 +57,10 @@ class Object(models.Model):
|
||||||
# easily.
|
# easily.
|
||||||
attrib_list = {}
|
attrib_list = {}
|
||||||
|
|
||||||
|
# We keep a separate list of active flags in memory so we can store some of
|
||||||
|
# the non-saved flags such as CONNECTED.
|
||||||
|
flags_active = []
|
||||||
|
|
||||||
def __cmp__(self, other):
|
def __cmp__(self, other):
|
||||||
"""
|
"""
|
||||||
Used to figure out if one object is the same as another.
|
Used to figure out if one object is the same as another.
|
||||||
|
|
@ -74,11 +78,24 @@ class Object(models.Model):
|
||||||
"""
|
"""
|
||||||
BEGIN COMMON METHODS
|
BEGIN COMMON METHODS
|
||||||
"""
|
"""
|
||||||
|
def load_flags(self):
|
||||||
|
"""
|
||||||
|
Toss the flags from self.flags into our flags_active list, where we
|
||||||
|
pull from.
|
||||||
|
"""
|
||||||
|
self.flags_active = self.flags.split()
|
||||||
|
|
||||||
|
def get_name(self):
|
||||||
|
"""
|
||||||
|
Returns an object's name.
|
||||||
|
"""
|
||||||
|
return self.name
|
||||||
|
|
||||||
def get_flags(self):
|
def get_flags(self):
|
||||||
"""
|
"""
|
||||||
Returns an object's flag list.
|
Returns an object's flag list.
|
||||||
"""
|
"""
|
||||||
return self.flags
|
return ' '.join(self.flags_active)
|
||||||
|
|
||||||
def has_flag(self, flag):
|
def has_flag(self, flag):
|
||||||
"""
|
"""
|
||||||
|
|
@ -86,7 +103,7 @@ class Object(models.Model):
|
||||||
|
|
||||||
flag: (str) Flag name
|
flag: (str) Flag name
|
||||||
"""
|
"""
|
||||||
return flag in self.flags.split()
|
return flag in self.flags_active
|
||||||
|
|
||||||
def set_flag(self, flag, value):
|
def set_flag(self, flag, value):
|
||||||
"""
|
"""
|
||||||
|
|
@ -95,17 +112,20 @@ class Object(models.Model):
|
||||||
flag: (str) Flag name
|
flag: (str) Flag name
|
||||||
value: (bool) Set (True) or un-set (False)
|
value: (bool) Set (True) or un-set (False)
|
||||||
"""
|
"""
|
||||||
|
flag = flag.upper()
|
||||||
has_flag = self.has_flag(flag)
|
has_flag = self.has_flag(flag)
|
||||||
|
|
||||||
if value == False and has_flag:
|
if value == False and has_flag:
|
||||||
# The flag is there and we want to un-set it.
|
# The flag is there and we want to un-set it.
|
||||||
flags_list = self.flags.split()
|
self.flags_active.remove(flag)
|
||||||
flags_list.remove(flag)
|
|
||||||
self.flags = ' '.join(flags_list)
|
|
||||||
|
|
||||||
# Not all flags are saved, such as CONNECTED.
|
# Not all flags are saved, such as CONNECTED.
|
||||||
# Don't waste queries on these things.
|
# Don't waste queries on these things.
|
||||||
if flag not in global_defines.NOSAVE_FLAGS:
|
if flag not in global_defines.NOSAVE_FLAGS:
|
||||||
|
flag_templist = self.flags.split()
|
||||||
|
flag_templist.remove(flag)
|
||||||
|
|
||||||
|
self.flags = ' '.join(flag_templist)
|
||||||
self.save()
|
self.save()
|
||||||
elif value == False and not has_flag:
|
elif value == False and not has_flag:
|
||||||
# Object doesn't have the flag to begin with.
|
# Object doesn't have the flag to begin with.
|
||||||
|
|
@ -114,11 +134,13 @@ class Object(models.Model):
|
||||||
# We've already go it.
|
# We've already go it.
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
# Add the flag.
|
# Add the flag to our active, memory-resident list no matter what.
|
||||||
flags_list = self.flags.split()
|
self.flags_active.append(flag)
|
||||||
flags_list.append(flag.upper())
|
|
||||||
self.flags = ' '.join(flags_list)
|
|
||||||
if flag not in global_defines.NOSAVE_FLAGS:
|
if flag not in global_defines.NOSAVE_FLAGS:
|
||||||
|
flag_templist = self.flags.split()
|
||||||
|
flag_templist.append(flag)
|
||||||
|
|
||||||
|
self.flags = ' '.join(flag_templist)
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
def get_owner(self):
|
def get_owner(self):
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,10 @@ import commands_general
|
||||||
import cmdhandler
|
import cmdhandler
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Restricted staff commands.
|
Staff commands may be a bad description for this file, but it'll do for now.
|
||||||
|
Any command here is prefixed by an '@' sign, usually denoting a builder, staff
|
||||||
|
or otherwise manipulative command that doesn't fall within the scope of
|
||||||
|
normal gameplay.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def cmd_dig(cdat):
|
def cmd_dig(cdat):
|
||||||
|
|
@ -128,7 +131,66 @@ def cmd_teleport(cdat):
|
||||||
pobject.move_to(server, results[0])
|
pobject.move_to(server, results[0])
|
||||||
commands_general.cmd_look(cdat)
|
commands_general.cmd_look(cdat)
|
||||||
|
|
||||||
#session.msg("Args: %s\n\rEqargs: %s" % (args, eq_args,))
|
def cmd_set(cdat):
|
||||||
|
"""
|
||||||
|
Sets flags or attributes on objects.
|
||||||
|
"""
|
||||||
|
session = cdat['session']
|
||||||
|
pobject = session.pobject
|
||||||
|
server = cdat['server']
|
||||||
|
args = cdat['uinput']['splitted'][1:]
|
||||||
|
|
||||||
|
if len(args) == 0:
|
||||||
|
session.msg("Set what?")
|
||||||
|
return
|
||||||
|
|
||||||
|
# There's probably a better way to do this. Break the arguments (minus
|
||||||
|
# the root command) up so we have two items in the list, 0 being the victim,
|
||||||
|
# 1 being the list of flags or the attribute/value pair.
|
||||||
|
eq_args = ' '.join(args).split('=')
|
||||||
|
|
||||||
|
if len(eq_args) < 2:
|
||||||
|
session.msg("Set what?")
|
||||||
|
return
|
||||||
|
|
||||||
|
victim = functions_db.local_and_global_search(pobject, eq_args[0], searcher=pobject)
|
||||||
|
|
||||||
|
if len(victim) == 0:
|
||||||
|
session.msg("I don't see that here.")
|
||||||
|
return
|
||||||
|
elif len(victim) > 1:
|
||||||
|
session.msg("I don't know which one you mean!")
|
||||||
|
return
|
||||||
|
|
||||||
|
victim = victim[0]
|
||||||
|
attrib_args = eq_args[1].split(':')
|
||||||
|
|
||||||
|
if len(attrib_args) > 1:
|
||||||
|
# We're dealing with an attribute/value pair.
|
||||||
|
attrib_name = attrib_args[0].upper()
|
||||||
|
attrib_value = ' '.join(attrib_args[1:])
|
||||||
|
session.msg("%s - %s set." % (victim.get_name(), attrib_name))
|
||||||
|
else:
|
||||||
|
# Flag manipulation form.
|
||||||
|
flag_list = eq_args[1].split()
|
||||||
|
|
||||||
|
for flag in flag_list:
|
||||||
|
flag = flag.upper()
|
||||||
|
if flag[0] == '!':
|
||||||
|
# We're un-setting the flag.
|
||||||
|
flag = flag[1:]
|
||||||
|
if not functions_db.modifiable_flag(flag):
|
||||||
|
session.msg("You can't set/unset the flag - %s." % (flag,))
|
||||||
|
else:
|
||||||
|
session.msg('%s - %s cleared.' % (victim.get_name(), flag.upper(),))
|
||||||
|
victim.set_flag(flag, False)
|
||||||
|
else:
|
||||||
|
# We're setting the flag.
|
||||||
|
if not functions_db.modifiable_flag(flag):
|
||||||
|
session.msg("You can't set/unset the flag - %s." % (flag,))
|
||||||
|
else:
|
||||||
|
session.msg('%s - %s set.' % (victim.get_name(), flag.upper(),))
|
||||||
|
victim.set_flag(flag, True)
|
||||||
|
|
||||||
def cmd_find(cdat):
|
def cmd_find(cdat):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,16 @@
|
||||||
import sets
|
import sets
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from apps.objects.models import Object
|
from apps.objects.models import Object
|
||||||
import functions_db
|
import global_defines
|
||||||
|
|
||||||
|
def modifiable_flag(flagname):
|
||||||
|
"""
|
||||||
|
Check to see if a particular flag is modifiable.
|
||||||
|
"""
|
||||||
|
if flagname not in global_defines.NOSET_FLAGS:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def get_nextfree_dbnum():
|
def get_nextfree_dbnum():
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -13,3 +13,5 @@ OBJECT_TYPES = (
|
||||||
SERVER_FLAGS = ["CONNECTED"]
|
SERVER_FLAGS = ["CONNECTED"]
|
||||||
# These flags are not saved.
|
# These flags are not saved.
|
||||||
NOSAVE_FLAGS = ["CONNECTED"]
|
NOSAVE_FLAGS = ["CONNECTED"]
|
||||||
|
# These flags can't be modified by players.
|
||||||
|
NOSET_FLAGS = ["CONNECTED"]
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ class Server(dispatcher):
|
||||||
"""
|
"""
|
||||||
object_list = Object.objects.all()
|
object_list = Object.objects.all()
|
||||||
for object in object_list:
|
for object in object_list:
|
||||||
|
object.load_flags()
|
||||||
dbnum = object.id
|
dbnum = object.id
|
||||||
self.object_list[dbnum] = object
|
self.object_list[dbnum] = object
|
||||||
print ' Objects Loaded: %d' % (len(self.object_list),)
|
print ' Objects Loaded: %d' % (len(self.object_list),)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue