예제 #1
0
파일: load.py 프로젝트: mpirnat/dndme
    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")
예제 #2
0
파일: load.py 프로젝트: marilson/dndme
    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):
        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

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

        encounters = encounter_loader.get_available_encounters()

        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 = input("\nLoad encounter: ")
        if not pick.isdigit():
            print("Invalid encounter.")
            return

        pick = int(pick) - 1
        if pick < 0 or pick > len(encounters):
            print("Invalid encounter.")
            return

        encounter = encounters[pick]
        monsters = encounter_loader.load(encounter, self.game.combat)
        print(f"Loaded encounter: {encounter.name}"
              f" with {len(monsters)} monsters")
예제 #4
0
def encounter_loader():
    """Create a testing encounter loader"""
    return EncounterLoader(base_dir='content/example/encounters',
                           monster_loader=None)
예제 #5
0
def encounter_loader():
    """Create a testing encounter loader"""
    return EncounterLoader(base_dir="content/example/encounters",
                           monster_loader=None,
                           combat=Combat())