Ejemplo n.º 1
0
def test_roll_of_die():
    """
       Test die roll to ensure that it is generating values that
       we want (i.e., corresponds with a real dice throw)
    """
    die_type = 20
    num_die = 3
    modifier = 5

    result = die_roll(num_die, die_type, modifier)

    if 1 <= result <= (num_die * die_type) + modifier:
        return 1, result
    else:
        return 0, result
Ejemplo n.º 2
0
    def roll_initiative(self):

        all_characters_list =

        for npc in npc_creatures:

           dexterity = npc.attributes['DEX']
           dex_modifier = bHF.get_ability_modifer(dexterity)
           npc.initiative = bHF.die_roll(1, 20, dex_modifier)
           all_characters_list.append(npc)

        for player in player_characters:

            print("What is {}'s initiative roll?".format(player.name))
            roll_value = raw_input('roll_value: ')
            player.initiative = roll_value
            all_characters_list.append(player)

        self.ordered_creature_list = bHF.order_by_initiative(all_characters_list)
Ejemplo n.º 3
0
    def npc_action(self, npc):

        action_dict = dict()
        i = 0
        print('----Attacks----')
        for key, _ in npc.data['attacks'].items():
            print("{0}) {1}".format(i, key))
            action_dict[i] = (0, key)
            i += 1

        print('----Spells----')
        if npc.data['spells'] == None:
            print('npc {} has no spells'.format(npc.npc_id))

        else:
            for key, _ in npc.data['spells'].items()
                print("{0}) {1}".format(i, key))
                action_dict[i] = (1, key)
                i += 1

        action_idx = raw_input("Chosen action idx: ")
        action_bool, action = action_dict[action_idx]
        if action_bool == 1:
            action_data = npc.data['attacks'][action]
        else:
            action_data = npc.data['spells'][action]
            print("Spell description:\n{}".format(
                action_data['description']))

        # roll for action
        dtype = action_data['dType']
        number = action_data['dNumber']
        modifier = action_data['modifier']

        roll_value = bHF.die_roll(number, dtype, modifier)

        return roll_value
Ejemplo n.º 4
0
    def roll_initiative(self):
        '''Automatically rolls initiatives for all creatures involved in
           scenario
        '''

        # Creature container to be passed to ordering function
        creature_list = list()

        # Roll initiative for all npcs
        #pdb.set_trace()
        for creatureID in self.creatureDict.keys():
            creature = self.creatureDict[creatureID]
            # initiative: d20 + dex modifier
            #pdb.set_trace()
            try:
                dexterity = creature.abilities["DEXTERITY"]
                dex_modifier = bHF.get_ability_modifer(dexterity)

            except (KeyError, TypeError) as e:
                dex_modifier = 0

            creature.initiative = bHF.die_roll(1, 20, dex_modifier)
            creature_list.append(creature)

        # Have the players roll for initiative
        for player_name in self.playerDict.keys():
            print(player_name)
            player = self.playerDict[player_name]
            print(self.bMessager.ask_player_to_roll_initiative(player_name))
            player.initiative = int(input("rolled initiative: "))
            # place in list of creatures
            creature_list.append(player)

        # return list of all creatures and players based on initiative
        self.ordered_creature_list = bHF.order_by_initiative(creature_list)
        return
Ejemplo n.º 5
0
    def importFeatures(self, yaml_file_path):

        with open(yaml_file_path, 'r') as stream:
            creature_data = yaml.safe_load(stream)

            # List to contain errors encountered during import
            errors = []

            # Import different creature features from yaml file
            print("creature_data type: ", type(creature_data))
            for key, value in creature_data.items():
                print("key: ", key)
                print("value: ", value)

            #pdb.set_trace()

            #pdb.set_trace()
            # Creature Name
            #pdb.set_trace()
            try:
                #pdb.set_trace()
                self.attributes = creature_data["ATTRIBUTES"]
            except KeyError:
                print("Unable to load attributes")
                print("Input some now?")
                confirmation = input("(y/N): ")
                if confirmation.lower() == 'y':
                    attribute_input = input("Attributes: ")
                else:
                    errors.append("attributes")
                    pass

            # Creature Abilities
            try:
                self.abilities = creature_data["ABILITIES"]
            except KeyError:
                print("Unable to load abilities")
                print("Input some now?")
                confirmation = input("(y/N): ")
                if confirmation.lower() == 'y':
                    abilities_input = input("Abilities: ")
                    # Put in some post processing here
                    self.abilities = abilities_input
                else:
                    errors.append("abilities")
                    pass

            try:
                self.feats = creature_data["FEATS"]
            except KeyError:
                print("Unable to load feats")
                print("Input some now?")
                confirmation = input("(y/N): ")
                if confirmation.lower() == 'y':
                    feats_input = input("feats: ")
                    # Put in some post processing here
                    self.feats = feats_input
                else:
                    errors.append("feats")
                    pass

            # Creature Actions
            try:
                self.actions = creature_data["ACTIONS"]
            except KeyError:
                print("Unable to load actions")
                print("Input some now?")
                confirmation = input("(y/N): ")
                if confirmation.lower() == 'y':
                    actions_input = input("actions: ")
                    # Put in some post processing here
                    self.actions["misc actions"] = actions_input
                else:
                    errors.append("actions")
                    pass

            # Creature Attacks
            try:
                self.actions['attacks'] = creature_data["ATTACKS"]
            except KeyError:
                print("Unable to load attacks")
                print("Input some now?")
                confirmation = input("(y/N): ")
                if confirmation.lower() == 'y':
                    attacks_input = input("attacks: ")
                    # Put in some post processing here
                    self.actions["attacks"] = attacks_input
                else:
                    errors.append("attacks")
                    self.actions["attacks"] = None
                    pass

            # Creature spells
            try:
                self.actions['spells'] = creature_data["SPELLS"]
            except KeyError:
                print("Unable to load spells")
                print("Input some now?")
                confirmation = input("(y/N): ")
                if confirmation.lower() == 'y':
                    spells_input = input("spells: ")
                    # Put in some post processing here
                    self.actions["spells"] = spells_input
                else:
                    errors.append("spells")
                    self.actions["spells"] = None
                    pass

            # Creature challenge rating
            try:
                self.challenge_rating = creature_data["CHALLENGE"]
            except KeyError:
                print("Unable to load challenge_rating")
                print("Input some now?")
                confirmation = input("(y/N): ")
                if confirmation.lower() == 'y':
                    challenge_rating_input = input("challenge_rating: ")
                    # Put in some post processing here
                    self.challenge_rating = challenge_rating_input
                else:
                    errors.append("challenge_rating")
                    pass

            # Creature challenge rating
            try:
                self.armor_class = creature_data["ARMORCLASS"]
            except KeyError:
                print("Unable to load armor_class")
                print("Input some now?")
                confirmation = input("(y/N): ")
                if confirmation.lower() == 'y':
                    armor_class_input = input("armor_class: ")
                    # Put in some post processing here
                    self.armor_class = armor_class_input
                else:
                    errors.append("armor_class")
                    pass

            # Creaturetype
            try:
                self.creature_class = creature_data["CREATURETYPE"]
            except KeyError:
                print("Unable to load creature type")
                print("Input some now?")
                confirmation = input("(y/N): ")
                if confirmation.lower() == 'y':
                    creature_class_input = input("creature_class: ")
                    # Put in some post processing here
                    self.creature_class = creature_class_input
                else:
                    errors.append("creature_class")
                    pass

            # Creature experience points
            try:
                self.experience_points = creature_data["EXPERIENCEPOINTS"]
            except KeyError:
                print("Unable to load experience_points")
                print("Input some now?")
                confirmation = input("(y/N): ")
                if confirmation.lower() == 'y':
                    experience_points_input = input("experience_points: ")
                    # Put in some post processing here
                    self.experience_points = experience_points_input
                else:
                    errors.append("experience_points")
                    pass

            # Creature experience points
            try:
                self.hit_dice = creature_data["HITPOINTS"]
                self.max_hitpoints = self.current_hitpoints = die_roll(self.hit_dice[2],
                                                                       self.hit_dice[0],
                                                                       self.hit_dice[1])
            except KeyError:
                print("Unable to import HP stat for {0} of type {1}".format(self.name, self.creature_type))
                print("Unable to load hit dice")
                print("Input some now?")
                confirmation = input("(y/N): ")
                if confirmation.lower() == 'y':
                    num_hit_die = int(input("number of hit die: "))
                    die_type = int(input("dietype: "))
                    modifier = int(input("modifier: "))
                    self.hit_dice = [die_type, modifier, num_hit_die]
                    self.max_hitpoints = self.current_hitpoints = die_roll(self.hit_dice[2],
                                                                           self.hit_dice[0],
                                                                           self.hit_dice[1])
                    # Put in some post processing here
                else:
                    errors.append("hit_points")
                    pass
                errors.append("hitpoints")
                pass

            # Creature speed stats
            try:
                self.speed = creature_data["SPEED"]
            except KeyError:
                errors.append("speed")
                pass

            # Creature saving throws
            try:
                self.save_throws = creature_data["SAVETHROWS"]
            except KeyError:
                errors.append("save_throws")
                pass

            # Creature args
            try:
                self.args = creature_data["ARGS"]
            except KeyError:
                errors.append("args")
                pass

            self.errors = errors
            return