def get_cmdset(self, source_object): """ Retrieve cmdset for channels this source_object has access to send to. Args: source_object (Object): An object subscribing to one or more channels. Returns: cmdsets (list): The Channel-Cmdsets `source_object` has access to. """ if source_object in self.cached_cmdsets: return self.cached_cmdsets[source_object] else: # create a new cmdset holding all channels chan_cmdset = cmdset.CmdSet() chan_cmdset.key = '_channelset' chan_cmdset.priority = 120 chan_cmdset.duplicates = True for cmd in [ cmd for cmd in self.cached_channel_cmds if cmd.access(source_object, 'send') ]: chan_cmdset.add(cmd) self.cached_cmdsets[source_object] = chan_cmdset return chan_cmdset
def get_cmdset(self, source_object): """ Retrieve cmdset for channels this source_object has access to send to. Args: source_object (Object): An object subscribing to one or more channels. Returns: cmdsets (list): The Channel-Cmdsets `source_object` has access to. """ if source_object in self._cached_cmdsets: return self._cached_cmdsets[source_object] else: # create a new cmdset holding all viable channels chan_cmdset = None chan_cmds = [ channelcmd for channel, channelcmd in self._cached_channel_cmds.items() if channel.subscriptions.has(source_object) and channelcmd.access(source_object, "send") ] if chan_cmds: chan_cmdset = cmdset.CmdSet() chan_cmdset.key = "ChannelCmdSet" chan_cmdset.priority = 101 chan_cmdset.duplicates = True for cmd in chan_cmds: chan_cmdset.add(cmd) self._cached_cmdsets[source_object] = chan_cmdset return chan_cmdset
def create_exit_cmdset(self, exidbobj): class ShardhavenExitCommand(command.Command): def func(self): if self.obj.can_traverse(self.caller): self.obj.at_traverse(self.caller, self.obj.destination, arguments=self.args) exitkey = exidbobj.db_key.strip().lower() exitaliases = list(exidbobj.aliases.all()) exitcmd = ShardhavenExitCommand( key=exitkey, aliases=exitaliases, locks=str(exidbobj.locks), auto_help=False, destination=exidbobj.db_destination, is_exit=True, obj=exidbobj, ) exit_cmdset = cmdset.CmdSet(None) exit_cmdset.key = "_exitset" exit_cmdset.priority = 101 # equal to channel priority exit_cmdset.duplicates = True exit_cmdset.add(exitcmd) return exit_cmdset
def create_exit_cmdset(self, exidbobj): cmd = self.exit_command(key=exidbobj.db_key.strip().lower(), aliases=exidbobj.aliases, locks=str(exidbobj.locks), auto_help=False, destination=exidbobj.db_destination, arg_regex=r"^$", is_exit=True, obj=exidbobj, gateway=exidbobj.gateway) exit_cmdset = cmdset.CmdSet(None) exit_cmdset.key = "ExitCmdSet" exit_cmdset.priority = self.priority exit_cmdset.duplicates = True exit_cmdset.add(cmd) return exit_cmdset
def get_cmdset(self, source_object): """ Retrieve cmdset for channels this source_object has access to send to. """ if source_object in self.cached_cmdsets: return self.cached_cmdsets[source_object] else: # create a new cmdset holding all channels chan_cmdset = cmdset.CmdSet() chan_cmdset.key = '_channelset' chan_cmdset.priority = 120 chan_cmdset.duplicates = True for cmd in [ cmd for cmd in self.cached_channel_cmds if cmd.access(source_object, 'send') ]: chan_cmdset.add(cmd) self.cached_cmdsets[source_object] = chan_cmdset return chan_cmdset
def create_container_cmdset(self, contdbobj): """ Helper function for creating an container command set + command. The command of this cmdset has the same name as the container object and allows the container to react when the player enter the container's name, triggering the movement between rooms. Note that containerdbobj is an ObjectDB instance. This is necessary for handling reloads and avoid tracebacks if this is called while the typeclass system is rebooting. """ # create a cmdset container_cmdset = cmdset.CmdSet(None) container_cmdset.key = '_containerset' container_cmdset.priority = 9 container_cmdset.duplicates = True # add command to cmdset container_cmdset.add(CmdChestKey(obj=contdbobj)) return container_cmdset
def create_exit_cmdset(self, exidbobj): """ 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 player enter the exit's name, triggering the movement between rooms. Note that exitdbobj is an ObjectDB instance. This is necessary for handling reloads and avoid tracebacks if this is called while the typeclass system is rebooting. """ exitkey = exidbobj.db_key.strip().lower() exitaliases = list(exidbobj.aliases.all()) # noinspection PyUnresolvedReferences class ExitCommand(command.Command): """ This is a command that simply cause the caller to traverse the object it is attached to. """ obj = None def func(self): """Default exit traverse if no syscommand is defined.""" if self.obj.password: # get our number of password_failures for this caller yikes = 10 failures = self.obj.password_failures.get(self.caller, 0) # return if we had too many failures if failures > yikes: msg = "Attempting this password AGAIN would result in Privacy Disturbance " msg += "Citation 47c, as per Decree 332 Appendix M of Queen Alaricetta the " msg += "Prudent. Best not to try it." self.msg(msg) return attempt = yield self.obj.password_question if attempt != self.obj.password: self.obj.at_password_fail(self.caller) return if self.obj.can_traverse(self.caller): self.obj.at_traverse(self.caller, self.obj.destination) # noinspection PyUnresolvedReferences class PassExit(command.Command): def func(self): # TODO: Figure out way to make this DRY if self.obj.password: # get our number of password_failures for this caller yikes = 10 failures = self.obj.password_failures.get(self.caller, 0) # return if we had too many failures if failures > yikes: msg = "Attempting this password AGAIN would result in Privacy Disturbance " msg += "Citation 47c, as per Decree 332 Appendix M of Queen Alaricetta the " msg += "Prudent. Best not to try it." self.caller.msg(msg) return attempt = yield self.obj.password_question if attempt != self.obj.password: self.obj.at_password_fail(self.caller) return # iff locked, then we can pass through it if we have a key if self.obj.db.locked: if not self.obj.access(self.caller, "usekey"): self.caller.msg("You don't have a key to this exit.") return else: self.obj.at_traverse(self.caller, self.obj.destination) return # normal checks for non-locked doors if self.obj.can_traverse(self.caller): self.obj.at_traverse(self.caller, self.obj.destination) # noinspection PyUnresolvedReferences class KnockExit(RewardRPToolUseMixin, command.Command): simplified_key = "knock" def func(self): self.caller.msg("You knocked on the door.") self.obj.destination.msg_contents( "{wThere is a knock coming from %s." % self.obj.reverse_exit) self.mark_command_used() # create an exit command. We give the properties here, # to always trigger metaclass preparations exitcmd = ExitCommand( key=exitkey, aliases=exitaliases, locks=str(exidbobj.locks), auto_help=False, destination=exidbobj.db_destination, arg_regex=r"$", is_exit=True, obj=exidbobj, ) passaliases = ["pass %s" % alias for alias in exitaliases] passcmd = PassExit( key="pass %s" % exitkey, aliases=passaliases, is_exit=True, auto_help=False, obj=exidbobj, ) knockaliases = ["knock %s" % alias for alias in exitaliases] knockcmd = KnockExit( key="knock %s" % exitkey, aliases=knockaliases, is_exit=True, auto_help=False, obj=exidbobj, ) # create a cmdset exit_cmdset = cmdset.CmdSet(None) exit_cmdset.key = "_exitset" exit_cmdset.priority = 101 # equal to channel priority exit_cmdset.duplicates = True # add command to cmdset exit_cmdset.add(exitcmd) exit_cmdset.add(passcmd) exit_cmdset.add(knockcmd) return exit_cmdset
def create_exit_cmdset(self, exidbobj): """ 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 player enter the exit's name, triggering the movement between rooms. Note that exitdbobj is an ObjectDB instance. This is necessary for handling reloads and avoid tracebacks if this is called while the typeclass system is rebooting. """ exitkey = exidbobj.db_key.strip().lower() exitaliases = list(exidbobj.aliases.all()) # noinspection PyUnresolvedReferences class ExitCommand(command.Command): """ This is a command that simply cause the caller to traverse the object it is attached to. """ obj = None def func(self): """Default exit traverse if no syscommand is defined.""" if self.obj.can_traverse(self.caller): self.obj.at_traverse(self.caller, self.obj.destination) # noinspection PyUnresolvedReferences class PassExit(command.Command): def func(self): if self.obj.db.locked and not self.obj.access( self.caller, 'usekey'): self.caller.msg("You don't have a key to this exit.") return self.obj.at_traverse(self.caller, self.obj.destination) # noinspection PyUnresolvedReferences class KnockExit(command.Command): def func(self): self.caller.msg("You knocked on the door.") self.obj.destination.msg_contents( "{wThere is a knock coming from %s." % self.obj.reverse_exit) # create an exit command. We give the properties here, # to always trigger metaclass preparations exitcmd = ExitCommand(key=exitkey, aliases=exitaliases, locks=str(exidbobj.locks), auto_help=False, destination=exidbobj.db_destination, arg_regex=r"$", is_exit=True, obj=exidbobj) # create a cmdset exit_cmdset = cmdset.CmdSet(None) exit_cmdset.key = '_exitset' exit_cmdset.priority = 101 # equal to channel priority exit_cmdset.duplicates = True # add command to cmdset exit_cmdset.add(exitcmd) # exit_cmdset.add(passcmd) # exit_cmdset.add(knockcmd) return exit_cmdset