def send_options(player: Player, user: Target): options = user.get_move_options() rep = join_list([str(option) for option in options], use_brackets=True, use_indexes=True) player.send_message(Message("Options: {}".format(rep), named_variables=options)) chooser = user.move_chooser # should be a SetMoveChooser if chooser.chosen_move is not None: player.send_message(Message("You have already chosen: {}", named_variables=[chooser.chosen_move])) return InputHandleType.HANDLED
def on_enter(self, player: Player, previous_location: Optional[Location], handler: Handler): self._send_welcome(player) if not player[EventsObject].been_introduced_to_furry: player.send_message("You hear screaming.") player.send_wait(0.3) player[PlayerFriend].tell(player, "H-Help me! This furry monster is chasing me!") player[PlayerFriend].tell(player, "Take my wallet! It's on the ground! Maybe you can distract it!") wallet = Wallet() penny = Coin.PENNY.create() wallet.change_holder(None, player.location) penny.change_holder(None, wallet)
def on_item_use(self, handler: Handler, player: Player, item: Item): if isinstance(item, Sword): can_use = item.can_use(player) if not can_use[0]: player.send_message(can_use[1]) return result = item.use_item(handler, player, does_custom_action=True) if result[0]: self.do_player_clear(player) else: player.send_message(result[1]) else: super().on_item_use(handler, player, item)
def on_yell(self, handler: Handler, player: Player, command_input: CommandInput, is_there_response=False) -> None: """ There is a default player implementation for this is_there_response is only meant to be changed by inheriting classes (It shouldn't be changed by YellCommandHa..) :param handler: The handler object :param player: The player :param command_input: The player input object :param is_there_response: By default, False. If set to True, the default implementation won't send a message saying no one responded. :return: None """ first_arg = command_input.get_arg(0, False) player.send_message( Message("You (Yelling): {}".format(" ".join(first_arg)), MessageType.IMMEDIATE)) player.send_message(Message("....", message_type=MessageType.TYPE_SLOW)) if not is_there_response: player.send_message(self.__class__.NO_YELL_RESPONSE)
def create_simple_player(savable): colorama_init() print() player_input = KeyboardInputGetter() player_input.start() output = ImmediateStreamOutput() player = Player(player_input, output, savable) return player, [output], lambda: None
def on_item_use(self, handler: Handler, player: Player, item: Item) -> None: """ Should be called by the UseCommandHandler. If overridden, it's recommended that you call the super method (this method) Note that this method should automatically check can_use, however, you should check item.can_reference\ before you call this method :param handler: The handler object :param player: The player object :param item: The weapon that is being 'used' :return: None because the this Location should choose how it wants to handle the using of this weapon """ can_use = item.can_use(player) if not can_use[0]: player.send_message(can_use[1]) return result = item.use_item(handler, player, does_custom_action=False) if not result[0]: player.send_message( result[1] ) # send the player a message if they failed in some way
def player_go(handler: Handler, player: Player, first_argument: str) -> InputHandleType: # note that first_argument doesn't have to be a single word point = get_point(handler, player, first_argument) if point is None: player.send_message("Cannot find location: \"" + first_argument + "\"") return InputHandleType.HANDLED new_location = handler.get_point_location(point) if new_location == player.location: player.send_message("You're already in that location!") return InputHandleType.HANDLED result = player.location.go_to_other_location(handler, new_location, point - player.location.point, player) if not result[0]: player.send_message(result[1]) return InputHandleType.HANDLED
def create_fancy_player(stdscr, savable): from textprint.input import InputLineUpdater from textprint.section import Section from textprint.textprinter import TextPrinter curses_init() std_init(stdscr) colorama_init() input_section = Section(None, fill_up_left_over=False) # we want to allow it to go for as many lines it needs temp_section = Section(None, fill_up_left_over=False) print_section = Section(None, fake_line=(Color.BLUE >> "~")) title_section = Section(1) printer = TextPrinter([input_section, temp_section, print_section, title_section], print_from_top=False, stdscr=stdscr) printer.update_dimensions() # print_section.fake_line = Color.RED + Color.BOLD + "|" + (" " * (printer.dimensions[1] - 3)) + "|" updater = InputLineUpdater(printer, input_section.println(printer, "", flush=True), stdscr) player_input = TextPrinterInputGetter(updater) # input_manager = InputLineUpdaterManager(updater) # calls updater's update output = OutputNotifierSender(TextPrinterOutput(printer, print_section), lambda: temp_output.section.clear_lines(printer, flush=True)) temp_output = TextPrinterOutput(printer, temp_section) player = Player(player_input, output, savable) def interrupt_handler(): if updater.current_line().is_clear(): temp_output.send_message(Message(Color.YELLOW >> "Press CTRL+D to exit", message_type=MessageType.IMMEDIATE)) print_section.update_lines(printer, flush=True, force_reprint=True) else: updater.current_line().clear() add_interrupt_handler(interrupt_handler) # clear line when CTRL+C is pressed title_manager = LocationTitleBarManager(player, printer, title_section.println(printer, "")) return player, [player_input, output, temp_output, title_manager], lambda: curses_end()
def taste(self, handler: Handler, player: Player): player.send_message(DONT_TASTE)
def feel(self, handler: Handler, player: Player): player.send_message("You feel glad you've made it this far.")
def listen(self, handler: Handler, player: Player): player.send_message(DONT_HEAR)
def feel(self, handler: Handler, player: Player): player.send_message("You feel a little bit spooked.")
def smell(self, handler: Handler, player: Player): player.send_message("You smell BO. It's yours!")
def see(self, handler: Handler, player: Player): if player not in self.ninja.entities_lost_to: player.send_message("You see {} waiting to fight you. There's no escaping now.".format(self.ninja)) else: player.send_message("You see the path to the fountain to the west.")
def listen(self, handler: Handler, player: Player): if player[EventsObject].been_introduced_to_furry: player.send_message(DONT_HEAR) else: player.send_message("You hear your friend screaming.")
def feel(self, handler: Handler, player: Player): if player[EventsObject].been_introduced_to_furry: player.send_message("You remember the moment you met the furry monster.") else: player.send_message("You feel scared. You should probably do something about the furry monster")
def feel(self, handler: Handler, player: Player): player.send_message("You feel that it's cooler here than at the entrance.")
def do_player_clear(player: Player): if player[EventsObject].has_cleared_spider_webs_at_entrance: player.send_message("You've already cleared the spider webs.") else: player.send_message("You cleared the spider webs.") player[EventsObject].has_cleared_spider_webs_at_entrance = True
def see(self, handler: Handler, player: Player): if player[EventsObject].has_cleared_spider_webs_at_entrance: player.send_message("You see a lot of spider webs and an entrance north and south.") else: player.send_message("You see a lot of spider webs. It doesn't look passable.")
def see(self, handler: Handler, player: Player): player.send_message("You see lots of trees and an exit back to the double doors")
def on_enter(self, player: Player, previous_location: Optional[Location], handler: Handler): self._send_welcome(player) if not player[EventsObject].been_introduced_to_furry: player.send_message("You hear your friend off in the distance screaming. " "It's coming from the east of the double doors")
def on_yell(self, handler: Handler, player: Player, command_input: CommandInput, is_there_response=False): if player[EventsObject].knows_laura: super().on_yell(handler, player, command_input, False) else: super().on_yell(handler, player, command_input, True) player.send_message("You feel a hand go over your mouth.") player.send_message("You see a rock coming at your fa-") player.clear_screen() player.send_wait(1) laura = handler.get_livings(LauraPerson, 1)[0] laura.tell(player, "Who are you?") player.send_wait(0.5) laura.tell(player, Message("You have {}'s wallet! What did you do to them?", named_variables=[player[PlayerFriend]])) player.send_wait(0.3) player.tell(player, "He's my fri-") laura.tell(player, "Lies!") player.send_wait(1.2) player.clear_screen() player.send_wait(1) laura.tell(player, Message("Hi I'm {}. Sorry about that. Everything is cleared up now.", named_variables=[laura])) player[EventsObject].knows_laura = True # make sure this code isn't run for the player again sword = Sword(SwordType.WOODEN) # we just need this variable to reference in named_variables sword.change_holder(None, player.location) laura.tell(player, Message("How about for all your troubles I'll give you this {}. Take it.", named_variables=[sword])) Sword(SwordType.CHINESE_STEEL).change_holder(None, player.location)
def feel(self, handler: Handler, player: Player): if player not in self.ninja.entities_lost_to: player.send_message(Message("You feel scared that you have to face {}.", named_variables=[self.ninja])) else: player.send_message(Message("You feel glad that you beat {}.", named_variables=[self.ninja]))
def _send_welcome(self, player: Player): player.send_line() player.send_message(Message("The {}.", named_variables=[self])) player.send_message(self.description) player.send_line()
def smell(self, handler: Handler, player: Player): player.send_message(DONT_SMELL)
def listen(self, handler: Handler, player: Player): player.send_message("You hear nothing except for the occasional drop of water out of the fountain.")
def on_enter(self, player: Player, previous_location: Optional[Location], handler: Handler): self._send_welcome(player) if player.uuid not in self.ninja.entities_lost_to: player.send_message(Message("It looks like you are going to have to fight {}.", named_variables=[self.ninja]))
def see(self, handler: Handler, player: Player): player.send_message("You see an old fountain and a ninja dude ")
def listen(self, handler: Handler, player: Player): player.send_message("Silence. Kinda spooky.")
def listen(self, handler: Handler, player: Player): # test if player[EventsObject].knows_laura or not player[EventsObject].been_introduced_to_furry: player.send_message(DONT_HEAR) else: player.send_message("You hear someone in the bushes. Maybe you can yell out to them.")