def func(self, invoker, parsed_cmd): if not parsed_cmd.arguments: raise CommandError('Alias what?') # End up with a list of one or two members. Splits around the # first equal sign found. equal_sign_split = parsed_cmd.argument_string.split('=', 1) if len(equal_sign_split) == 1: raise CommandError('No alias(es) provided.') obj_to_alias_str = equal_sign_split[0] aliases = equal_sign_split[1].split() obj_to_alias = invoker.contextual_object_search(obj_to_alias_str) if not obj_to_alias: raise CommandError('Unable to find your target object to alias.') if not aliases: invoker.emit_to('You clear all aliases on %s.' % (obj_to_alias.get_appearance_name(invoker))) else: invoker.emit_to('You alias %s to: %s' % (obj_to_alias.get_appearance_name(invoker), ', '.join(aliases))) obj_to_alias.aliases = aliases obj_to_alias.save()
def func(self, invoker, parsed_cmd): if not parsed_cmd.arguments: raise CommandError('Set the zone on what?') # End up with a list of one or two members. Splits around the # first equal sign found. equal_sign_split = parsed_cmd.argument_string.split('=', 1) if len(equal_sign_split) == 1: raise CommandError('No zone provided.') obj_to_zone_str = equal_sign_split[0] obj_to_zone = invoker.contextual_object_search(obj_to_zone_str) if not obj_to_zone: raise CommandError('Unable to find your target object to zone.') zone_obj_str = equal_sign_split[1] if not zone_obj_str: zone_obj = None else: zone_obj = invoker.contextual_object_search(zone_obj_str) if not zone_obj: raise CommandError('Unable to find your zone master object.') obj_to_zone.zone = zone_obj yield obj_to_zone.save() if zone_obj: invoker.emit_to('You zone %s to %s' % ( obj_to_zone.get_appearance_name(invoker), zone_obj.get_appearance_name(invoker), )) else: invoker.emit_to('You clear the zone (if any) on %s' % (obj_to_zone.get_appearance_name(invoker), ))
def func(self, invoker, parsed_cmd): if not parsed_cmd.arguments: raise CommandError('Re-parent what?') # End up with a list of one or two members. Splits around the # first equal sign found. equal_sign_split = parsed_cmd.argument_string.split('=', 1) if len(equal_sign_split) == 1: raise CommandError('No parent provided.') obj_to_parent_str = equal_sign_split[0] parent_str = equal_sign_split[1] parent_str = self._substitute_aliased_parent(parent_str) if not parent_str: raise CommandError('No parent provided.') obj_to_parent = invoker.contextual_object_search(obj_to_parent_str) if not obj_to_parent: raise CommandError( 'Unable to find your target object to re-parent.') mud_service = invoker.mud_service try: mud_service.object_store.parent_loader.load_parent(parent_str) except InvalidParent, exc: raise CommandError(exc.message)
def func(self, invoker, parsed_cmd): if not parsed_cmd.arguments: raise CommandError('Describe what?') # End up with a list of one or two members. Splits around the # first equal sign found. equal_sign_split = parsed_cmd.argument_string.split('=', 1) if len(equal_sign_split) == 1: raise CommandError('No description provided.') obj_to_desc_str = equal_sign_split[0] description = equal_sign_split[1] obj_to_desc = invoker.contextual_object_search(obj_to_desc_str) if not obj_to_desc: raise CommandError( 'Unable to find your target object to describe.') is_idesc = {'internal', 'i', 'in'} & parsed_cmd.switches desc_verb = 'internally describe' if is_idesc else 'describe' invoker.emit_to('You %s %s' % (desc_verb, obj_to_desc.get_appearance_name(invoker))) if is_idesc: obj_to_desc.internal_description = description else: obj_to_desc.description = description yield obj_to_desc.save()
def do_dock(self, invoker, parsed_cmd): """ An argument was provided with dock, meaning that the user wishes to dock. """ object_store = invoker.mud_service.object_store try: dock_id = int(parsed_cmd.argument_string) except (TypeError, ValueError): raise CommandError('Invalid docking location ID.') _, flat_hangar_id_list = self.ship.location.get_dockable_obj_list( self.ship) if dock_id not in flat_hangar_id_list: raise CommandError('No dock with that ID found.') dock_obj = object_store.get_object(dock_id) invoker.emit_to('Docking in %s' % dock_obj.get_appearance_name(invoker)) # TODO: Emit to others in system that ship is beginning to land/dock. self.ship.emit_to_interior( 'A docking tone sounds as the ship begins its approach.') # TODO: A CallLater based on ship maneuverability. # TODO: Emit to others in system that ship has landed. self.ship.move_to(dock_obj) self.ship.emit_to_interior( 'A loud CLANG resonates through the hull as a docking collar ' 'is slapped on from outside.') invoker.emit_to('You have docked in %s' % (dock_obj.get_appearance_name(invoker), ))
def func(self, invoker, parsed_cmd): if not parsed_cmd.arguments: raise CommandError('Go through which exit?') obj_to_traverse = invoker.contextual_object_search( parsed_cmd.argument_string) if not obj_to_traverse: raise CommandError("Destination unknown.") if not obj_to_traverse.base_type == 'exit': invoker.emit_to("That doesn't look like an exit.") obj_to_traverse.pass_object_through(invoker)
def func(self, invoker, parsed_cmd): bridge = invoker.location ship = bridge.get_ship_obj() hangar = ship.location if not ship.is_ship_landed(): raise CommandError("You're already flying around!") launch_to = hangar.get_launchto_location() if not launch_to: raise CommandError( "The hangar your ship is in appears to be shut.") bridge.emit_to_contents("Starting launch sequence...") ship.start_launch_sequence()
def func(self, invoker, parsed_cmd): if not parsed_cmd.arguments: raise CommandError('Open an exit named what, and to where?') if len(parsed_cmd.arguments) < 2: raise CommandError( 'You must at least provide an alias and an exit name.') alias_str = parsed_cmd.arguments[0] name_and_dest_str = ' '.join(parsed_cmd.arguments[1:]) name_dest_split = name_and_dest_str.split('=', 1) exit_name = name_dest_split[0] if len(name_dest_split) > 1: dest_str = name_dest_split[1] else: dest_str = None if dest_str: destination = invoker.contextual_object_search(dest_str) if not destination: raise CommandError('Unable to find specified destination.') destination_id = destination.id else: destination = None destination_id = None mud_service = invoker.mud_service exit_parent = 'src.game.parents.base_objects.exit.ExitObject' new_exit = yield mud_service.object_store.create_object( exit_parent, name=exit_name, location_id=invoker.location.id, destination_id=destination_id, aliases=[alias_str], ) if destination: invoker.emit_to('You have opened a new exit to %s named "%s"' % ( destination.get_appearance_name(invoker), new_exit.get_appearance_name(invoker), )) else: invoker.emit_to( 'You have opened a new exit (with no destination) named "%s"' % (new_exit.get_appearance_name(invoker)))
def do_warp_to(self, invoker, parsed_cmd): """ An argument was provided with warp, meaning that the user wishes to warp to a place. """ service = invoker.mud_service try: warp_id = int(parsed_cmd.argument_string) except (TypeError, ValueError): raise CommandError('Invalid warp destination ID.') try: place_obj = service.object_store.get_object(warp_id) except NoSuchObject: raise CommandError('No warp destination with that ID found.') if place_obj.id == self.current_place.id: raise CommandError('You are already there!') if not isinstance(place_obj, SolarSystemPlaceObject): # Attempting to warp to a non-place. raise CommandError('No warp destination with that ID found.') if not self.solar_system == place_obj.get_solar_system_obj(): # Attempting to warp to a place in another solar system. raise CommandError('No warp destination with that ID found.') invoker.emit_to('Warping to %s in the %s system.' % ( place_obj.get_appearance_name(invoker), self.solar_system.get_appearance_name(invoker), )) self.ship.emit_to_interior( 'The hull begins to vibrate, and the whine of the charging warp ' 'drives becomes deafening.') # TODO: A CallLater based on ship maneuverability. self.ship.emit_to_interior( 'The ship groans audibly as it flings itself into warp.') # TODO: Move the ship somewhere unreachable. # TODO: CallLater to come out of warp. self.ship.move_to(place_obj) self.ship.emit_to_interior( 'You feel a strong lurch as your vessel slows after its warp.') invoker.emit_to('You arrive at %s in the %s system.' % ( place_obj.get_appearance_name(invoker), self.solar_system.get_appearance_name(invoker), ))
def func(self, invoker, parsed_cmd): if not parsed_cmd.arguments: raise CommandError('Destroy what?') obj_to_destroy = invoker.contextual_object_search( parsed_cmd.argument_string) if not obj_to_destroy: raise CommandError('Unable to find your target object to destroy.') invoker.emit_to('You destroy %s' % obj_to_destroy.get_appearance_name(invoker)) try: obj_to_destroy.destroy() except ObjectHasZoneMembers, exc: raise CommandError(exc.message)
def func(self, invoker, parsed_cmd): if not parsed_cmd.arguments: raise CommandError('Unlink which exit?') obj_to_unlink = invoker.contextual_object_search( parsed_cmd.argument_string) if not obj_to_unlink: raise CommandError('Unable to find your target exit to unlink.') if not isinstance(obj_to_unlink, ExitObject): raise CommandError('You may only unlink exits.') invoker.emit_to('You unlink %s' % obj_to_unlink.get_appearance_name(invoker)) obj_to_unlink.destination = None obj_to_unlink.save()
def func(self, invoker, parsed_cmd): if not parsed_cmd.arguments: raise CommandError('You must specify a Zone Master Object (ZMO).') zmo = invoker.contextual_object_search(parsed_cmd.argument_string) if not zmo: raise CommandError( 'Unable to find the given Zone Master Object (ZMO).') if not parsed_cmd.switches: self.handle_zmo_summary(invoker, parsed_cmd, zmo) elif 'empty' in parsed_cmd.switches: self.handle_zmo_empty(invoker, parsed_cmd, zmo) elif 'raze' in parsed_cmd.switches: self.handle_zmo_raze(invoker, parsed_cmd, zmo) else: raise CommandError( "Invalid @zmo switch. Must be one of: empty, raze")
def func(self, invoker, parsed_cmd): if not parsed_cmd.arguments: raise CommandError('Enter what?') obj_to_enter = invoker.contextual_object_search( parsed_cmd.argument_string) if not obj_to_enter: raise CommandError("You look around, but can't find it.") can_enter, cant_enter_msg = obj_to_enter.can_object_enter(invoker) if not can_enter: raise CommandError(cant_enter_msg) # Determine where entering the object puts us. enter_to = obj_to_enter.determine_enter_destination(invoker) # Use the original object's name for the user message. enter_to_name = obj_to_enter.get_appearance_name(invoker) invoker.emit_to("You enter %s" % enter_to_name) invoker.move_to(enter_to)
def func(self, invoker, parsed_cmd): location = invoker.location can_leave, cant_leave_msg = location.can_object_leave(invoker) if not can_leave: raise CommandError(cant_leave_msg) # Determine where leaving the object puts us. leave_to = location.determine_leave_destination(invoker) # Use the original object's name for the user message. leave_from_name = location.get_appearance_name(invoker) invoker.emit_to("You leave %s" % leave_from_name) invoker.move_to(leave_to)
def func(self, invoker, parsed_cmd): if not parsed_cmd.arguments: raise CommandError('Link which exit?') # End up with a list of one or two members. Splits around the # first equal sign found. equal_sign_split = parsed_cmd.argument_string.split('=', 1) if len(equal_sign_split) == 1: raise CommandError('No destination provided.') obj_to_link_str = equal_sign_split[0] obj_to_link = invoker.contextual_object_search(obj_to_link_str) if not obj_to_link: raise CommandError('Unable to find your target exit to link.') if not isinstance(obj_to_link, ExitObject): raise CommandError('You may only link exits.') destination_obj_str = equal_sign_split[1] destination_obj = invoker.contextual_object_search(destination_obj_str) if not destination_obj: raise CommandError('Unable to find the specified destination.') if isinstance(destination_obj, ExitObject): raise CommandError("You can't link to other exits.") invoker.emit_to('You link %s to %s.' % ( obj_to_link.get_appearance_name(invoker), destination_obj.get_appearance_name(invoker), )) obj_to_link.destination = destination_obj obj_to_link.save()
def func(self, invoker, parsed_cmd): if not parsed_cmd.arguments: # No arguments means defaulting to 'here'. if not invoker.location: # This shouldn't ever happen, but... raise CommandError('You appear to be nowhere. Bummer.') user_query = 'here' else: user_query = ' '.join(parsed_cmd.arguments) if not user_query: raise CommandError('You must specify an object to examine.') obj_match = invoker.contextual_object_search(user_query) if not obj_match: raise CommandError('No matching object found.') appearance = self.get_appearance(obj_match, invoker) invoker.emit_to(appearance)
def func(self, invoker, parsed_cmd): if not parsed_cmd.arguments: raise CommandError('Name what?') # End up with a list of one or two members. Splits around the # first equal sign found. equal_sign_split = parsed_cmd.argument_string.split('=', 1) if len(equal_sign_split) == 1: raise CommandError('No name provided.') obj_to_desc_str = equal_sign_split[0] name = equal_sign_split[1] obj_to_desc = invoker.contextual_object_search(obj_to_desc_str) if not obj_to_desc: raise CommandError('Unable to find your target object to name.') invoker.emit_to('You re-name %s' % obj_to_desc.get_appearance_name(invoker)) obj_to_desc.name = name obj_to_desc.save()
def func(self, invoker, parsed_cmd): if not parsed_cmd.arguments: raise CommandError('Which object do you wish to set?') # End up with a list of one or two members. Splits around the # first equal sign found. equal_sign_split = parsed_cmd.argument_string.split('=', 1) if len(equal_sign_split) <= 1: raise CommandError('You must specify a target and a value.') target_obj_str = equal_sign_split[0] target_obj = invoker.contextual_object_search(target_obj_str) if not target_obj: raise CommandError('Unable to find target object: %s' % target_obj_str) set_value = equal_sign_split[1] if ':' not in set_value: raise CommandError('Attribute values must be in the form of ' 'ATTRIBNAME:VALUE') attr_name, attr_value = set_value.split(':', 1) try: json_value = json.loads(attr_value) except ValueError: raise CommandError('Invalid JSON value.') target_obj.attributes[attr_name] = json_value yield target_obj.save() invoker.emit_to('Set %s on %s: %s' % ( attr_name, target_obj.get_appearance_name(invoker), attr_value, ))
def func(self, invoker, parsed_cmd): if not parsed_cmd.arguments: raise CommandError('Teleport what to where?') # End up with a list of one or two members. Splits around the # first equal sign found. equal_sign_split = parsed_cmd.argument_string.split('=', 1) # Start off assuming the first member is the object that is to # be teleported. obj_to_tel_str = equal_sign_split[0] if len(equal_sign_split) == 1: # No destination provided. Defaults target object to 'me', and # moves the single arg to the destination. obj_to_tel_str = 'me' # First (and only) arg becomes destination. destination_str = equal_sign_split[0] else: # A destination was provided, so use it. destination_str = equal_sign_split[1] obj_to_tel = invoker.contextual_object_search(obj_to_tel_str) if not obj_to_tel: raise CommandError( 'Unable to find your target object to teleport.') destination = invoker.contextual_object_search(destination_str) if not destination: raise CommandError('Unable to find your destination.') if isinstance(obj_to_tel, RoomObject): raise CommandError('Rooms cannot be teleported') if obj_to_tel.id == destination.id: raise CommandError('Objects can not teleport inside themselves.') # Move the object, forces a 'look' afterwards. obj_to_tel.move_to(destination)
def func(self, invoker, parsed_cmd): self.bridge = invoker.location self.ship = self.bridge.get_ship_obj() is_landed = self.ship.is_ship_landed() if is_landed: raise CommandError("You'll have to launch first!") self.solar_system = self.ship.get_solar_system_obj() if not parsed_cmd.arguments: # No arguments passed, show the places list. self.do_list_docks(invoker, parsed_cmd) else: # User provided input. Warping somewhere. self.do_dock(invoker, parsed_cmd)
def func(self, invoker, parsed_cmd): mud_service = invoker.mud_service name_str = ' '.join(parsed_cmd.arguments) if name_str.strip() == '': raise CommandError('You must provide a name for the new Thing.') thing_parent = 'src.game.parents.base_objects.thing.ThingObject' new_thing = yield mud_service.object_store.create_object( thing_parent, name=name_str, location_id=invoker.location.id, ) invoker.emit_to('You have created a new thing named "%s"' % (new_thing.get_appearance_name(invoker), ))
def func(self, invoker, parsed_cmd): mud_service = invoker.mud_service name_str = ' '.join(parsed_cmd.arguments) if name_str.strip() == '': raise CommandError('@dig requires a name for the new room.') room_parent = 'src.game.parents.base_objects.room.RoomObject' new_room = yield mud_service.object_store.create_object( room_parent, name=name_str, ) invoker.emit_to('You have dug a new room named "%s"' % (new_room.get_appearance_name(invoker), )) if 'teleport' in parsed_cmd.switches: invoker.move_to(new_room)
def func(self, invoker, parsed_cmd): mud_service = invoker.mud_service search_str = ' '.join(parsed_cmd.arguments) if search_str.strip() == '': raise CommandError('@find requires a name to search for.') # Performs a global fuzzy name match. Returns a generator. matches = mud_service.object_store.global_name_search(search_str) # Buffer for returning everything at once. match_counter = 0 buf = self._get_header_str('Searching for "%s"' % search_str) for match in matches: buf += '\n %s' % match.get_appearance_name(invoker) match_counter += 1 buf += self._get_footer_str(pad_char='-') buf += '\n Matches found: %d' % match_counter buf += self._get_footer_str() invoker.emit_to(buf)
def func(self, invoker, parsed_cmd): bridge = invoker.location ship = bridge.get_ship_obj() solar_system = ship.get_solar_system_obj() if ship.is_ship_landed(): raise CommandError("What contacts? You aren't in space.") buf = self._get_header_str("Contacts near %s" % ship.location.get_appearance_name(invoker)) for contact in ship.get_visible_contacts(): shield_bar, shield_perc, shield_color = progress_bar_str( 12, contact.get_max_shield_hp(), contact.get_current_shield_hp()) hull_bar, hull_perc, hull_color = progress_bar_str( 12, contact.get_max_hull_hp(), contact.get_current_hull_hp()) standing_val = contact.check_ship_standing(ship) standing_str, standing_color = get_standing_value_cosmetics( standing_val) status_flags = self._get_short_status_flags(contact) buf += ( "\n {standing_color}{id:>5}]{ship_class_code:<1} {ship_reference:<10} " "{display_name:<20} S:{shield_bar} H:{hull_bar} " "S:{status_flags}{escape_color}".format( standing_color=standing_color, id=contact.id, ship_class_code=contact.ship_class_code, ship_reference=contact.ship_reference, display_name=contact.display_name, shield_bar=shield_bar, hull_bar=hull_bar, status_flags=status_flags, escape_color=ANSI_NORMAL)) buf += self._get_footer_str() invoker.emit_to(buf)