def find_invalid_target(target_key, entity, action): bad_gen = make_gen('__invalid__') bad_targets = find_targets('primary', entity, target_key, bad_gen, action) try: return next(bad_targets) except StopIteration: bad_targets = find_targets('abbrev', entity, target_key, bad_gen, action) return next(bad_targets, None)
def make_action(action, verbs=None, msg_class=None, target_class=None, obj_class=None, **kw_args): if verbs: action.verbs = verbs if msg_class: action.msg_class = msg_class match_args = getattr(action, 'match_args', None) if not match_args: try: match_args = inspect.getargspec(action)[0] except TypeError: match_args = inspect.getargspec(action.__call__)[0] try: match_args.remove('self') except ValueError: pass action.match_args = match_args if target_class: action.target_class = target.make_gen(target_class) elif not hasattr(action, 'target_class'): if not match_args or len( match_args) == 1 and match_args[0] == 'source': action.target_class = target.make_gen('no_args') else: action.target_class = target.make_gen('default') if obj_class: action.obj_class = target.make_gen(obj_class) for arg_name, value in kw_args.items(): setattr(action, arg_name, value) if hasattr(action, 'prep') and not hasattr(action, 'obj_class'): action.obj_class = target.make_gen('default') if hasattr(action, 'obj_class') and not hasattr(action, 'prep'): action.prep = '_implicit_' return action
def _on_loaded(self): if self.direction: self._dir = Direction.ref_map[self.direction] self.verbs = self._dir.obj_id, self._dir.desc self.target_class = 'no_args' else: self._dir = None self.verbs = self.verb self.target_class = target.make_gen('action') if not self.title and self.verb: self.title = self.verb
return recursive_targets(key_type, (living for living in entity.env.denizens), target_key) @target_gen def player_env(key_type, target_key, entity, *_): return recursive_targets(key_type, (denizen for denizen in entity.env.denizens if getattr(denizen, 'is_player', False) and denizen != entity), target_key) @target_gen def env_items(key_type, target_key, entity, *_): return recursive_targets(key_type, [item for item in entity.env.inven], target_key) @target_gen def env_default(key_type, target_key, entity, *_): if not target_key: yield entity.env @target_gen def self_default(key_type, target_key, entity, *_): if not target_key: yield entity make_gen('self feature env_living env_items equip inven env_default', 'default') make_gen('self env_living self_default', 'living') make_gen('feature env_living env_items inven equip', '__invalid__')