Пример #1
0
 def get_suggestions(self, words):
     if len(words) == 2:
         return ["encounter", "monster", "party"]
     if len(words) == 3 and words[1] == "monster":
         image_loader = ImageLoader(self.game)
         monster_loader = MonsterLoader(image_loader)
         return monster_loader.get_available_monster_keys()
Пример #2
0
    def load_monster(self, monster_name):
        def prompt_initiative(monster):
            # prompt to add the monsters to initiative order
            roll_advice = f"1d20{monster.initiative_mod:+}" \
                    if monster.initiative_mod else "1d20"
            roll = self.safe_input(f"Initiative for {monster.name}",
                                   default=roll_advice,
                                   converter=convert_to_int_or_dice_expr)
            print(f"Adding to turn order at: {roll}")
            return roll

        image_loader = ImageLoader(self.game)
        monster_loader = MonsterLoader(image_loader)
        count = self.safe_input("Number of monsters",
                                converter=convert_to_int_or_dice_expr)
        monsters = monster_loader.load(monster_name, count=count)

        if not monsters:
            print("No monsters loaded. Might be a data problem?")
            return

        #TODO: this is a cheat and really bad and we should clean it up
        encounter_loader = EncounterLoader(
            self.game.encounters_dir,
            monster_loader,
            self.game.combat,
            initiative_resolver=prompt_initiative)
        encounter_loader._set_hp([], monsters)
        encounter_loader._set_names([], monsters)
        encounter_loader._add_to_combat(self.game.combat, monsters)
        for monster in monsters:
            monster.origin = "unplanned"

        print(f"Loaded {len(monsters)} monsters.")
Пример #3
0
    def load_encounter(self, args):
        def prompt_count(count, monster_name="monsters"):
            count = self.safe_input(
                f"Number of {monster_name}",
                default=count,
                converter=convert_to_int_or_dice_expr,
            )
            return count

        def prompt_initiative(monster):
            # prompt to add the monsters to initiative order
            roll_advice = (f"1d20{monster.initiative_mod:+}"
                           if monster.initiative_mod else "1d20")
            roll = self.safe_input(
                f"Initiative for {monster.name}",
                default=roll_advice,
                converter=convert_to_int_or_dice_expr,
            )
            print(f"Adding to turn order at: {roll}")
            return roll

        image_loader = ImageLoader(self.game)
        monster_loader = MonsterLoader(image_loader)
        encounter_loader = EncounterLoader(
            self.game.encounters_dir,
            monster_loader,
            self.game.combat,
            count_resolver=prompt_count,
            initiative_resolver=prompt_initiative,
        )

        filter_string = f"*{args[0].lower()}*" if args else "*"
        encounters = [
            e for e in encounter_loader.get_available_encounters()
            if fnmatch(e.name.lower(), filter_string)
            or fnmatch(e.location.lower(), filter_string)
        ]

        if not encounters:
            print("No available encounters found.")
            return

        # prompt to pick an encounter
        print("Available encounters:\n")
        for i, encounter in enumerate(encounters, 1):
            print(f"{i}: {encounter.name} ({encounter.location})")

        pick = self.safe_input("Load encounter", converter=convert_to_int)
        pick = pick - 1
        if pick < 0 or pick > len(encounters):
            print("Invalid encounter.")
            return

        encounter = encounters[pick]
        monsters = encounter_loader.load(encounter)
        print(f"Loaded encounter: {encounter.name}"
              f" with {len(monsters)} monsters")
Пример #4
0
class Image(Command):

    keywords = ["image"]
    help_text = """{keyword}
{divider}
Summary: Send an image to be displayed in the player view or, with no image
specified, clear the image in the player view.

Usage:

    {keyword} [<image>]
    {keyword}

Examples:

    {keyword} cult_symbol.jpg
    {keyword} monster orc
    {keyword} http://example.com/image.gif
    {keyword}
"""

    def __init__(self, game, session, player_view):
        super().__init__(game, session, player_view)
        self.image_loader = ImageLoader(game)
        self.monster_loader = MonsterLoader(self.image_loader)

    def get_suggestions(self, words):
        if len(words) == 2:
            return [
                "monster",
                "player",
            ] + self.image_loader.get_available_content_images()
        if len(words) == 3:
            if words[1] == "monster":
                return self.monster_loader.get_available_monster_keys()
            elif words[1] == "player":
                return list(sorted(self.game.combat.characters.keys()))

    def do_command(self, *args):
        orig_image = self.game.player_view_image
        if args:
            new_image = self.get_image_url(*args)
            self.game.player_view_image = new_image
            print("Okay, image sent.")
        else:
            self.game.player_view_image = ""
            print("Okay, image cleared.")
        if self.game.player_view_image != orig_image:
            self.game.changed = True

    def get_image_url(self, *args):
        image_url = ""

        if len(args) >= 2:
            if args[0] == "monster":
                monster = self.monster_loader.load(args[1])[0]
                image_url = monster.image_url
            elif args[0] == "player":
                character = self.game.combat.get_target(args[1])
                image_url = character.image_url
            else:
                image_url = " ".join(args)

        elif len(args) == 1:
            image_url = args[0]

        if image_url and not image_url.startswith("http"):
            if args[0] == "monster":
                # already resolved when loading the monster
                pass
            elif args[0] == "player":
                image_url = self.image_loader.get_player_image_path(image_url)
            else:
                image_url = self.image_loader.get_content_image_path(image_url)

        print("Resolved image_url:", image_url)
        return image_url
Пример #5
0
 def __init__(self, game, session, player_view):
     super().__init__(game, session, player_view)
     self.image_loader = ImageLoader(game)
     self.monster_loader = MonsterLoader(self.image_loader)