Exemplo n.º 1
0
 def get_message(self):
     current_health = self.affected_target.entity.health.current_health
     changed = current_health - self.before_health  # negative means that the affected_target was damaged
     if changed == 0:
         return Message("{} was unaffected.",
                        named_variables=[self.affected_target.entity])
     elif changed > 0:
         return Message(
             "{} was healed by {} hp.",
             named_variables=[self.affected_target.entity, changed])
     extra = ""
     mult = self.multiplier
     if mult != 1:
         extra += "\n"
         if mult > 1.75:
             extra += "It's super effective!"
         elif mult > 1:
             extra += "It's pretty effective."
         elif mult >= .4:
             extra += "It's not very effective"
         elif mult < 0:
             extra += "The attack decided to do damage instead!"
         else:
             extra += "It didn't do very much at all."
     return Message("{} was damaged by {} hp." + extra,
                    named_variables=[self.affected_target.entity, -changed])
Exemplo n.º 2
0
    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 _handle_command(self, handler: Handler, sender: CommandSender, command_input: CommandInput):
        if isinstance(sender, Identifiable):
            sender.send_message(Message("Your UUID: ", end=""))
            sender.send_message(Message("{}", named_variables=[sender.uuid], message_type=MessageType.IMMEDIATE))
            return InputHandleType.HANDLED

        return InputHandleType.UNSUPPORTED_SENDER
    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)
Exemplo n.º 5
0
 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
Exemplo n.º 6
0
 def on_take(self, handler: Handler, item: Item, new_holder: Holder):
     if not isinstance(new_holder, Player):
         # If something else took the item we don't care. However, it's possible that this causes bugs so be careful
         return
     player = new_holder
     if isinstance(item, Wallet):
         if player[EventsObject].been_introduced_to_furry:
             handler.get_livings(OtherPerson, 1)[0].tell(player, "Hey that's not yours!")
             player.send_message("You set the wallet back on the ground.")
             player.items.remove(item)
             item.change_holder(player, player.location)
             return
         friend = player[PlayerFriend]
         player[EventsObject].been_introduced_to_furry = True  # has now been introduced
         player.send_message(Message("You throw all of {}'s cash at the furry monster.",
                                     named_variables=[friend]))
         player.send_wait(0.2)
         player.send_message("The furry monster fainted. You ga-")
         friend.tell(player, "THANK YOU, THANK YOU!!! You just saved my life from the furry monster!")
         friend.tell(player, "You can keep my wallet. It doesn't have much left anyway.")
         friend.tell(player, "Oh, and I met this really awesome person. If you go west past the double doors,"
                             " you'll find her.")
         player.send_wait(0.5)
         friend.tell(player,
                     "She's pretty shy so you can use the yell command to yell out to her.")
         friend.tell(player, "Well, 'shy' isn't really the word. Good luck.")
    def save(self, sender: Optional[CommandSender] = None) -> CanDo:
        """
        Saves data for the running game. If you want to change the save path, set save_path before you call this method
        as this method uses self.save_path to determine where to save the data
        :return: A CanDo representing whether or not the handler data saved successfully. The return value at [1]
                 should always be displayed to the user.
        """
        is_valid = self.save_path.is_valid()
        if not is_valid[0]:
            return is_valid
        handler_result = self._save_handler()
        if not handler_result[0]:
            return handler_result

        unsaved_string = ""
        unsaved_amount = 0
        for player in self.get_players():
            # sender.send_message(Message("Saving: {}", named_variables=[player]))
            player_result = self.player_handler.save_player(player)
            if not player_result[0]:
                sender.send_message(Message(str(player.uuid) + " - " + player_result[1],
                                            message_type=MessageType.IMMEDIATE))
                unsaved_amount += 1

        if unsaved_amount:
            unsaved_string = " {} players were unable to be saved.".format(unsaved_amount)

        return True, "You successfully saved data to {}.".format(self.save_path) + unsaved_string
    def _handle_command(self, handler: Handler, sender: CommandSender, command_input: CommandInput):
        if not isinstance(sender, Player):
            return InputHandleType.UNSUPPORTED_SENDER

        player = sender
        first_arg = command_input.get_arg(0)
        if not first_arg:
            self.send_help(player)
            return InputHandleType.HANDLED
        item = get_reference(player, " ".join(first_arg))

        if item is None:
            player.send_message(Item.CANNOT_SEE[1])
            return InputHandleType.HANDLED
        can_ref = item.can_reference(player)
        if can_ref[0] is False:
            player.send_message(can_ref[1])
            return InputHandleType.HANDLED
        can_put = item.can_put(player)
        if can_put[0] is False:
            player.send_message(can_put[1])
            return InputHandleType.HANDLED
        if item in player.items:
            if item.change_holder(player, player.location):
                player.location.on_place(handler, item, player)
                player.send_message(Message("You placed {}.", named_variables=[item]))
        else:
            player.send_message("Apparently, that item that you tried to place isn't in your inventory.\n"
                                "Please tell someone what you did so it can be fixed. (This message shouldn't appear)")
        return InputHandleType.HANDLED
        def handle_function(
                already_handled: List[InputHandleType]) -> InputHandleType:
            arg_index = 1
            arg = None
            if command.startswith(
                    ":"):  # the player is typing the argument as the command
                arg = command.replace(":", "")
                arg_index = 0
            elif len(command_input.get_arg(1)) != 0:
                arg = command_input.get_arg(0)[0].lower()

            # TODO, fix this code with : and setting and this is terrible
            if arg is not None:
                if arg == "speed":
                    speed = command_input.get_arg(
                        arg_index +
                        0)[0].lower()  # remember, arg 0 is the second word
                    if speed == "fast":
                        output.wait_multiplier = 0.4
                        player.send_message("Set speed to fast.")
                        return InputHandleType.HANDLED_AND_DONE
                    elif speed == "normal":
                        output.wait_multiplier = 1
                        player.send_message("Set speed to normal")
                        return InputHandleType.HANDLED_AND_DONE

            player.send_message(
                Message(
                    "Help for setting command: \n"
                    "\tspeed: setting speed <fast:normal>",
                    MessageType.IMMEDIATE))
            return InputHandleType.HANDLED_AND_DONE
Exemplo n.º 10
0
 def get_message(self):
     return Message("{} used {} on {}.",
                    named_variables=[
                        self.move.user.entity, self.move,
                        list(
                            map(lambda x: x.entity,
                                self.get_targets_object()))
                    ])
Exemplo n.º 11
0
    def _handle_command(self, handler: Handler, sender: CommandSender, command_input: CommandInput):
        if not isinstance(sender, Holder):
            return InputHandleType.UNSUPPORTED_SENDER

        holder = sender
        amount = len(holder.items)
        if amount == 0:
            holder.send_message("You don't have anything in your inventory")
        elif amount == 1:
            holder.send_message(Message("You have {}.", named_variables=holder.items))
        else:
            names = []
            for i in range(0, amount):
                names.append("{}")

            holder.send_message(Message("You have these items: {}".format(", ".join(names)),
                                        named_variables=holder.items))

        return InputHandleType.HANDLED
Exemplo n.º 12
0
    def _handle_command(self, handler: Handler, sender: CommandSender, command_input: CommandInput) -> InputHandleType:
        if not isinstance(sender, Player):
            sender.send_message("This must be an error. A {} shouldn't be trying to attack.".format(type(sender)))
        player = sender

        manager = handler.get_managers(BattleManager, 1)[0]  # get the BattleManager, there should be 1
        battles = manager.get_battles(player)
        assert len(battles) <= 1, "The player can only by in one battle"
        battle = None
        if len(battles) > 0:
            battle = battles[0]
        # now we have the battle that the player is currently in which could be None

        if battle is None:  # the player isn't in a battle
            first_arg = command_input.get_arg(0, False)  # remember this is a list containing the first arg at [0]
            # ignore_unimportant_before is False (^)because we want to get everything the player typed after the command

            if not first_arg:  # there isn't a first argument
                player.send_message("Who would you like to battle?")
                return InputHandleType.HANDLED
            reference = " ".join(first_arg)
            challenged = player.location.get_referenced_entity(handler, reference)
            if challenged is None:
                player.send_message(Message("Cannot find entity named: '{}' in your current location.",
                                            named_variables=[reference]))
                return InputHandleType.HANDLED
            challenge_action = EntityChallengeAction(player, challenged)
            handler.do_action(challenge_action)
            challenge_action.try_action(handler)
            return InputHandleType.HANDLED

        # now we know the player is in a battle since Battle isn't None
        assert not battle.has_ended, "For whatever reason, we received at battle that was ended."
        if not battle.has_started:
            player.send_message("Sorry, for whatever reason the battle hasn't started yet. This could be an error.")
            return InputHandleType.HANDLED
        turn = battle.current_turn
        assert turn is not None, "The battle is started and there's no current_turn ??? That would be an error."
        user = turn.get_target(player)
        assert isinstance(user.move_chooser, SetMoveChooser), "We need the player's MoveChooser to be a SetMoveChooser."

        first_arg = command_input.get_arg(0)
        if not first_arg:
            return self.__class__.send_options(player, user)
        try:
            number = int(first_arg[0])
            # now that we know the first argument is a number, the player wants to choose a move
            return self.__class__.choose_option_from_number(battle, number, player, user)
        except ValueError:
            pass  # the first argument was not a number so lets test for something else now
        if first_arg[0].lower() == "members":
            return self.__class__.send_members(battle, player)

        self.send_help(player)
        return InputHandleType.HANDLED
Exemplo n.º 13
0
    def get_message(message: Union[MessageConstant, Any]) -> Message:
        """
        Converts a MessageConstant to a Message
        Makes sure that the passed message value is returned as a Message object

        :param message: The message or string to make sure or change to a Message
        :return: A message object
        """

        if isinstance(message, Message):
            return message
        return Message(str(message))
Exemplo n.º 14
0
    def on_input(self, sender: 'CommandSender', command_input: 'CommandInput'):
        if command_input.is_empty():
            now = time.time()
            # if self._last_blank + 1 > now:
            self.__print_parts(immediate=True)  # only thing in if statement
            self._last_blank = now
            return True

        self.send_message(
            Message(Color.YELLOW >> str(command_input),
                    message_type=MessageType.IMMEDIATE))
        self.print_immediately()
        return False
Exemplo n.º 15
0
        def handle_function(already_handled: List[InputHandleType]):
            if not self._should_handle_input(already_handled):
                return InputHandleType.NOT_HANDLED
            # if ["hi", "ho", "he"] any/all/only 1 in "hello there how are you"
            if "n" in str(command_input):
                player.send_message("What? Are you sure?")
            else:
                player.send_message("OK, that's great")
                player.send_message("The door opens with a loud creek...")
                player.send_wait(0.5)
                player.send_message(Message("ERrreeeek", MessageType.TYPE_SLOW))
                player.send_wait(0.5)
                player.send_message("You walk in...")
                player.send_wait(1)
                player.send_message(Message("BOOOOOOM", MessageType.TYPE_SLOW))
                player.send_message("The door has closed behind you")

                player.location = handler.get_location(InsideEntrance)
                player.location.on_enter(player, self, handler)

                player.send_wait(1.3)
                handler.input_handlers.append(NameTaker(player))
            return InputHandleType.HANDLED
Exemplo n.º 16
0
    def choose_option_from_number(battle, number, player, user, chosen_targets: Optional[List[Target]] = None):
        options = user.get_move_options()
        length = len(options)
        if number < 0 or number >= length:
            player.send_message(Message("The number {} is not valid", named_variables=[number]))
            return InputHandleType.HANDLED
        option = options[number]  # a MoveOption
        chooser = user.move_chooser  # A SetMoveChooser

        if chosen_targets is None:  # lets automatically create the list for the player.
            chosen_targets = option.get_targeting_option(user).get_recommended_targets(battle.current_turn, user,
                                                                                       battle.teams)

        was_successful = chooser.set_option(user, option, chosen_targets)
        if not was_successful[0]:
            player.send_message(was_successful[1])
        return InputHandleType.HANDLED
Exemplo n.º 17
0
        def handle_function(already_handled: List[InputHandleType]):
            if not self._should_handle_input(already_handled):
                raise Exception("NameTaker is the number one priority! What happened?")
            split = command_input.split()
            if len(split) > 1:
                player[PlayerFriend].tell(player, "Hey, I can't remember that many words!")
                return InputHandleType.INCORRECT_RESPONSE

            friend = player[PlayerFriend]
            if player.name is not None:  # all for the friend's name
                if self.current_friend_name is None:
                    self.current_friend_name = split[0]
                    friend.tell(player, Message("I'm {}, right? (y/n)", named_variables=[self.current_friend_name]))
                    return InputHandleType.HANDLED
                if is_string_true(split[0]):
                    friend.name = self.current_friend_name
                    friend.tell(player, "Ok, right.")
                    player.send_wait(0.5)
                    friend.tell(player, Message("I'm {}.", named_variables=[friend]))
                    friend.tell(player, "Welp... I guess I'll smell you later. I'm off on my journey!")
                    friend.tell(player, "If you get stuck, use the help command and try to use all of your senses.")
                    return InputHandleType.REMOVE_HANDLER
                friend.tell(player, "It's not? Gosh, just tell me my name.")
                self.current_friend_name = None
                return InputHandleType.HANDLED
            # stuff below is for the player's name (think like an else statement from cuz it returns above)
            if self.current_name is None:
                name = split[0]
                if not handler.player_handler.is_name_valid(name):
                    player.send_message(Message("'{}' is not valid", named_variables=[name]))
                    return InputHandleType.HANDLED
                elif handler.player_handler.is_name_taken(name):
                    player.send_message(Message("'{}' is already taken!", named_variables=[name]))
                    return InputHandleType.HANDLED
                self.current_name = split[0]
                player[PlayerFriend].tell(player, Message("Are you sure your name is {}? (y/n)",
                                                          named_variables=[self.current_name]))
                return InputHandleType.HANDLED
            if is_string_true(split[0]):
                player.name = self.current_name
                friend.tell(player, Message("Right! {}... I remember now", named_variables=[player]))
                friend.tell(player, "Wait... I can't remember my name. What's my name?")

                return InputHandleType.HANDLED
            friend.tell(player, "Oops. I guess I didn't hear it right. What is it?")
            self.current_name = None  # reset
            return InputHandleType.HANDLED
Exemplo n.º 18
0
    def __init__(self,
                 name,
                 health,
                 location,
                 hostile_to_types: List[Type[Entity]],
                 savable: Optional[Savable],
                 hostile_type=HostileEntityType.KILL_ONCE):
        super().__init__(name, health, location, savable)
        self.hostile_to_types = hostile_to_types
        """The types of entities this hostile entity wants to attack"""

        self.hostile_now = True
        """Will be used by the instance. When False, can_entity_pass() will return True."""
        self._can_not_pass = False, Message(self.__class__.CANNOT_PASS_STRING,
                                            named_variables=[self])
        """Usually constant, but it can change if a subclass changes it. It is used as a message in can_entity_pass"""
        self.hostile_type = hostile_type

        self.entities_lost_to = []
        """A list of UUIDs from entities that beat this enemy in battle"""
        self.entities_won_against = []
        """A list of UUIDs from entities that have been beaten by this enemy"""
Exemplo n.º 19
0
    def _handle_command(self, handler: Handler, sender: CommandSender, command_input: CommandInput):
        if not isinstance(sender, Player):
            return InputHandleType.UNSUPPORTED_SENDER
        player = sender
        first_arg = command_input.get_arg(0)
        if not first_arg:
            self.send_help(player)
            return InputHandleType.HANDLED
        item = get_reference(player, " ".join(first_arg))

        if item is None:
            player.send_message(Item.CANNOT_SEE[1])
            return InputHandleType.HANDLED
        can_ref = item.can_reference(player)
        if can_ref[0] is False:
            player.send_message(can_ref[1])
            return InputHandleType.HANDLED
        can_take = item.can_take(player)
        if can_take[0] is False:
            player.send_message(can_take[1])
            return InputHandleType.HANDLED

        # if we are here, the player is allowed to take this item

        if item in player.location.items:
            if item.change_holder(player.location, player):
                player.location.on_take(handler, item, player)
                player.send_message(Message("You took {}.", named_variables=[item]))
        else:
            player.send_message("You were unable to take the item because we couldn't find who had the item.\n"
                                "Obviously, this is kind of embarrassing so please tell someone what you did "
                                "so it can be fixed.")

        # previous_holder = item.holder
        # if item.change_holder(previous_holder, player) and isinstance(previous_holder, Location):
        #     previous_holder.on_take(handler, item)
        return InputHandleType.HANDLED
Exemplo n.º 20
0
 def send_locate_message(self, sender: CommandSender):
     sender.send_message(
         Message("You are at {}, which is '{}'",
                 named_variables=[self.point, self]))
Exemplo n.º 21
0
 def _handle_command(self, handler: Handler, sender: CommandSender, command_input: CommandInput):
     sender.send_message(Message("Your name is {}.", named_variables=[sender]))
     return InputHandleType.HANDLED
Exemplo n.º 22
0
 def _handle_command(self, handler: Handler, sender: CommandSender, command_input: CommandInput):
     result = handler.save(sender)
     sender.send_message(Message(result[1], message_type=MessageType.IMMEDIATE))
     return InputHandleType.HANDLED
Exemplo n.º 23
0
 def _handle_command(self, handler: Handler, sender: CommandSender, command_input: CommandInput) -> InputHandleType:
     sender.send_message(Message("Get help for commands: '<command> help'", message_type=MessageType.IMMEDIATE))
     sender.send_message(
         Message("Useful commands: 'go', 'look', 'listen', 'feel', 'taste', 'smell', 'locate', 'items'"))
     return InputHandleType.HANDLED
Exemplo n.º 24
0
 def get_message(self):
     return Message(
         "{} was removed from {}.",
         named_variables=[self.removed_effect, self.affected_target.entity])
Exemplo n.º 25
0
 def get_message(self):
     return Message(
         "{} was added to {}.",
         named_variables=[self.added_effect, self.affected_target.entity])
Exemplo n.º 26
0
 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]))
Exemplo n.º 27
0
 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]))
Exemplo n.º 28
0
 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()
Exemplo n.º 29
0
def create_leave_message(location: Location) -> Message:
    return Message(LEAVING_LOCATION, named_variables=[location])
Exemplo n.º 30
0
    def send_members(battle, player):
        for index, team in enumerate(battle.teams):
            player.send_message(Message("{}: {}".format(index, "{}"), named_variables=team))

        return InputHandleType.HANDLED