mirror of
https://github.com/evennia/evennia.git
synced 2026-04-05 07:27:17 +02:00
Implemented locks.
The main command to use is @lock, which accept three types of locks at the moment, and three types of keys: Locks: DefaultLock, UseLock, EnterLock Keys: ObjectIDs, Groups, Permissions This offers the most useful functionality - stopping people from picking up things, blocking exits and stopping anyone from using an object. If the attributes lock_msg, use_lock_msg and enter_lock_msg are defined on the locked object, these will be used as error messages instead of a standard one (so "the door is locked" instead of "you cannot traverse that exit"). Behind the scenes, there is a new module, src/locks.py that defines Keys and Locks. A Locks object is a collection of Lock types. This is stored in the LOCKS attribute on objects. Each Lock contains a set of Keys that might be of mixed type and which the player must match in order to pass the lock. /Griatch
This commit is contained in:
parent
7f7306a6e4
commit
66095a0b16
7 changed files with 491 additions and 26 deletions
|
|
@ -338,6 +338,22 @@ class Object(models.Model):
|
|||
# Fall through to failure
|
||||
return False
|
||||
|
||||
def has_group(self, group):
|
||||
"""
|
||||
Checks if a user is member of a particular user group.
|
||||
"""
|
||||
if not self.is_player():
|
||||
return False
|
||||
|
||||
if self.is_superuser():
|
||||
return True
|
||||
|
||||
if group in [g.name for g in self.get_user_account().groups.all()]:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def owns_other(self, other_obj):
|
||||
"""
|
||||
See if the envoked object owns another object.
|
||||
|
|
@ -367,7 +383,7 @@ class Object(models.Model):
|
|||
|
||||
# When builder_override is enabled, a builder permission means
|
||||
# the object controls the other.
|
||||
if builder_override and not other_obj.is_player() and self.has_perm('genperms.builder'):
|
||||
if builder_override and not other_obj.is_player() and self.has_group('Builders'):
|
||||
return True
|
||||
|
||||
# They've failed to meet any of the above conditions.
|
||||
|
|
@ -883,9 +899,18 @@ class Object(models.Model):
|
|||
quiet: (bool) If true, don't emit left/arrived messages.
|
||||
force_look: (bool) If true and self is a player, make them 'look'.
|
||||
"""
|
||||
|
||||
|
||||
#first, check if we can enter that location at all.
|
||||
if not target.scriptlink.enter_lock(self):
|
||||
lock_desc = self.get_attribute_value("enter_lock_msg")
|
||||
if lock_desc:
|
||||
self.emit_to(lock_desc)
|
||||
else:
|
||||
self.emit_to("That destination is blocked from you.")
|
||||
return
|
||||
|
||||
#before the move, call eventual pre-commands.
|
||||
if self.scriptlink.at_before_move(target) != None:
|
||||
if self.scriptlink.at_before_move(target) != None:
|
||||
return
|
||||
|
||||
if not quiet:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue