forked from vantablack/vantaMOO
Compare commits
1 Commits
Author | SHA1 | Date |
---|---|---|
Alexander Yakovlev | 776485b4db |
|
@ -23,7 +23,7 @@ from evennia.contrib.grid.ingame_map_display import MapDisplayCmdSet
|
|||
from evennia.contrib.grid import simpledoor
|
||||
from evennia.contrib.rpg.rpsystem import RPSystemCmdSet
|
||||
from evennia.contrib.game_systems.clothing import ClothedCharacterCmdSet
|
||||
|
||||
from typeclasses import container
|
||||
|
||||
class CharacterCmdSet(default_cmds.CharacterCmdSet):
|
||||
"""
|
||||
|
|
|
@ -4,13 +4,13 @@ Container objects. Bags, chests, etc.
|
|||
|
||||
"""
|
||||
from typeclasses.objects import Object as DefaultObject
|
||||
from commands.base import ArxCommand
|
||||
from commands.command import Command
|
||||
from evennia.commands import cmdset
|
||||
from typeclasses.mixins import LockMixins
|
||||
|
||||
|
||||
# noinspection PyUnresolvedReferences
|
||||
class CmdChestKey(ArxCommand):
|
||||
class CmdChestKey(Command):
|
||||
"""
|
||||
Grants a key to this chest to a player
|
||||
|
||||
|
@ -63,7 +63,7 @@ class CmdChestKey(ArxCommand):
|
|||
return
|
||||
|
||||
|
||||
class CmdRoot(ArxCommand):
|
||||
class CmdRoot(Command):
|
||||
"""
|
||||
Makes a container object immovable or removes the immovable
|
||||
quality of the container object.
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
class LockMixins(object):
|
||||
def has_lock_permission(self, caller):
|
||||
"""
|
||||
Checks if a caller has permission to open this object - assume we're a locked door or chest.
|
||||
|
||||
:type self: ObjectDB
|
||||
:type caller: ObjectDB or AccountDB
|
||||
Args:
|
||||
caller: Caller object to check access.
|
||||
|
||||
Returns:
|
||||
True if they have access, False otherwise.
|
||||
"""
|
||||
if (
|
||||
caller
|
||||
and not caller.check_permstring("builders")
|
||||
and not self.access(caller, "usekey")
|
||||
):
|
||||
caller.msg("You do not have a key to %s." % self)
|
||||
return False
|
||||
return True
|
||||
|
||||
def lock(self, caller=None):
|
||||
"""
|
||||
:type self: ObjectDB
|
||||
:param caller: ObjectDB
|
||||
"""
|
||||
if not self.has_lock_permission(caller):
|
||||
return
|
||||
self.locks.add("traverse: perm(builders)")
|
||||
if self.item_data.is_locked:
|
||||
if caller:
|
||||
caller.msg("%s is already locked." % self)
|
||||
return
|
||||
self.item_data.is_locked = True
|
||||
msg = "%s is now locked." % self.key
|
||||
if caller:
|
||||
caller.msg(msg)
|
||||
self.location.msg_contents(msg, exclude=caller)
|
||||
# set the locked attribute of the destination of this exit, if we have one
|
||||
if (
|
||||
self.destination
|
||||
and hasattr(self.destination, "entrances")
|
||||
and self.destination.item_data.is_locked is False
|
||||
):
|
||||
entrances = [
|
||||
ob
|
||||
for ob in self.destination.entrances
|
||||
if ob.item_data.is_locked is False
|
||||
]
|
||||
if not entrances:
|
||||
self.destination.item_data.is_locked = True
|
||||
|
||||
def unlock(self, caller=None):
|
||||
"""
|
||||
:type self: ObjectDB:
|
||||
:param caller: ObjectDB
|
||||
:return:
|
||||
"""
|
||||
if not self.has_lock_permission(caller):
|
||||
return
|
||||
self.locks.add("traverse: all()")
|
||||
if not self.item_data.is_locked:
|
||||
if caller:
|
||||
caller.msg("%s is already unlocked." % self)
|
||||
return
|
||||
self.item_data.is_locked = False
|
||||
msg = "%s is now unlocked." % self.key
|
||||
if caller:
|
||||
caller.msg(msg)
|
||||
self.location.msg_contents(msg, exclude=caller)
|
||||
if self.destination:
|
||||
self.destination.item_data.is_locked = False
|
||||
|
||||
@property
|
||||
def currently_open(self):
|
||||
return not self.item_data.is_locked
|
||||
|
||||
@property
|
||||
def displayable(self):
|
||||
return self.tags.get("displayable")
|
||||
|
||||
@property
|
||||
def should_show_contents(self):
|
||||
return self.currently_open or self.displayable
|
||||
|
||||
def return_appearance(
|
||||
self, pobject, detailed=False, format_desc=False, show_contents=True
|
||||
):
|
||||
"""
|
||||
:type self: AppearanceMixins, Container
|
||||
:param pobject: ObjectDB
|
||||
:param detailed: bool
|
||||
:param format_desc: bool
|
||||
:param show_contents: bool
|
||||
:return: str
|
||||
"""
|
||||
show_contents = self.should_show_contents and show_contents
|
||||
base = super(LockMixins, self).return_appearance(
|
||||
pobject,
|
||||
detailed=detailed,
|
||||
format_desc=format_desc,
|
||||
show_contents=show_contents,
|
||||
)
|
||||
return base + "\nIt is currently %s." % (
|
||||
"locked" if self.item_data.is_locked else "unlocked"
|
||||
)
|
Loading…
Reference in New Issue