Пример #1
0
    def edit_skills_last(self, result, character):
        """
        Written by MH
        This function is the final method which checks whether a
        character's skills can be modified
        :param result: a list containing the user's input
        :param character: the instance of character
        :return:
        """
        input_v = InputView()

        try:
            input_v.check_valid_skill_dice(result[1])
            input_v.check_valid_skill_dice(result[2])
            input_v.check_valid_skill_dice(result[3])
            input_v.check_valid_skill_dice(result[4])
            input_v.check_valid_skill_dice(result[5])
            input_v.check_valid_skill_dice(result[6])

            # Start with the first skill input data, not the name:
            # remove the character name from the results list
            # The result list will now be length 6
            del result[0]

            # Get the skills data from each of the args
            num_dice_list = []
            type_dice_list = []

            for i in range(len(result)):
                dice_str_data = \
                    Character.obtain_dice_data(result[i])
                # print("number_dice_str: "+ number_dice_str)
                # print("type_dice_str: " + type_dice_str)
                num_dice_list.append(dice_str_data[0])
                type_dice_list.append(dice_str_data[1])

            try:
                character.check_number_dice(character, num_dice_list)

                try:
                    character.check_type_dice(character, type_dice_list)

                    # If the previous tests pass then the original skills
                    # can be removed and replaced with the updated skills:

                    skills_result = Character.obtain_dice_data(
                        result[0])
                    character.set_brawl(Skill(ESkill.brawl,
                                              character.find_edice
                                              (skills_result[1]),
                                              skills_result[0]))

                    skills_result = Character.obtain_dice_data(
                        result[1])
                    character.set_shoot(Skill(ESkill.shoot,
                                              character.find_edice
                                              (skills_result[1]),
                                              skills_result[0]))

                    skills_result = Character.obtain_dice_data(
                        result[2])
                    character.set_dodge(Skill(ESkill.dodge,
                                              character.find_edice
                                              (skills_result[1]),
                                              skills_result[0]))

                    skills_result = Character.obtain_dice_data(
                        result[3])
                    character.set_might(Skill(ESkill.might,
                                              character.find_edice
                                              (skills_result[1]),
                                              skills_result[0]))

                    skills_result = Character.obtain_dice_data(
                        result[4])
                    character.set_finesse(Skill(ESkill.finesse,
                                                character.find_edice
                                                (skills_result[1]),
                                                skills_result[0]))

                    skills_result = Character.obtain_dice_data(
                        result[5])
                    character.set_cunning(Skill(ESkill.cunning,
                                                character.find_edice
                                                (skills_result[1]),
                                                skills_result[0]))

                    print(character.get_name() + "'s skills have "
                                                 "successfuly been "
                                                 "replaced.")
                except CharacterException as e:
                    print(e.value)
            except CharacterException as e:
                print(e.value)
        except InputException as e:
            print(e.value)
Пример #2
0
    def do_addCharacter(self, args):
        '''
        addCharacter [CharacterName] [CharacterType] [Health] [Brawl] [Shoot]
        [Dodge] [Might] [Finesse] [Cunning]
        [Ability 1] [Ability 2] [Ability 3]

        Example
            addCharacter Testing Leader d10 3d8 3d10 3d10 2d8 3d10 2d10 Mighty
            Brash Crafty

        -----------------------------------------------------------------------
        This command adds a character to the current league.
        Your league starts with 10 roster slots.
        -----------------------------------------------------------------------
        [Character Name] = The character's name
        [CharacterType] = Can be either 'Leader' 'SideKick' 'Ally' or
        'Follower', You can only have ONE leader

        Skills. See below for examples on how to use this argument

        [Health] = A number used to represent your characters overall condition
        [Brawl] = Represents a character's overall hand-to-hand combat prowess
        [Shoot] = Indicates a character's combat effectiveness with all manner
                  of ranged weapons
        [Dodge] = Determines the character's ability to avoid enemy attacks,
                  perils, and other dangers.
        [Might] = Indicates a character's power, fitness and general
                  athleticism
        [Finesse] = measures the character's co ordination, awareness and
                  ability to manipulate
        [Cunning] = Represents a character's knowledge, resolve and ability to
                  solve complicated problems.

        Skill levels by type

        Leader
            MUST have a health value of d10
            Select four skills to start at 3 dice and two skills to start at
            2 dice
            Select four skills to start at d10 and two skills to start at d8
            Can choose 3 abilities at any level
        SideKick
            MUST have a health value of d8
            Select three skills to start at 3 dice and three skills to start at
            2 dice
            Select three skills to start at d8 and three skills to start at d6
            Can choose 2 abilities at level 1 to 3
            Uses three roster slots
        Ally
            MUST have a health value of d6
            Select two skills to start at 2 dice and four skills to start at
            1 dice
            All skills start at d6
            Can choose 1 ability at level 1 to 2
            Uses two roster slots
        Follower
            MUST have a health value of d6
            ALL skills must be 1d6
            Can choose 1 ability at level 1
            Uses one roster slot
        '''
        league = self._lm.get_current_league()
        if league == "":
            print("You need to create a league first before adding a "
                  "character.")
            return

        result = args.split(" ")
        inputV = InputView()

        if self._lm.get_current_league() is None:
            print("You need to create a league first!")
            return

        if len(result) >= 10:
            try:
                inputV.check_valid_name(result[0])
                inputV.check_valid_class(result[1])
                inputV.check_valid_skill_dice(result[3])
                inputV.check_valid_skill_dice(result[4])
                inputV.check_valid_skill_dice(result[5])
                inputV.check_valid_skill_dice(result[6])
                inputV.check_valid_skill_dice(result[7])
                inputV.check_valid_skill_dice(result[8])

                all_abilities = self._lm.get_all_abilities()

                if len(result) == 10:
                    try:
                        inputV.check_valid_ability(result[9], all_abilities)
                        league.add_character(name=result[0],
                                             char_type=result[1],
                                             health=result[2], brawl=result[3],
                                             shoot=result[4], dodge=result[5],
                                             might=result[
                                                 6], finesse=result[7],
                                             cunning=result[8], arg1=result[9])
                    except InputException as e:
                        print(e.value)

                elif len(result) == 11:
                    try:
                        inputV.check_valid_ability(result[9], all_abilities)
                        inputV.check_valid_ability(result[10], all_abilities)
                        inputV.check_duplicate_values([result[9], result[10]])

                        league.add_character(name=result[0],
                                             char_type=result[1],
                                             health=result[2], brawl=result[3],
                                             shoot=result[4], dodge=result[5],
                                             might=result[6],
                                             finesse=result[7],
                                             cunning=result[8], arg1=result[9],
                                             arg2=result[10])
                    except InputException as e:
                        print(e.value)

                elif len(result) == 12:
                    try:
                        inputV.check_valid_ability(result[9], all_abilities)
                        inputV.check_valid_ability(result[10], all_abilities)
                        inputV.check_valid_ability(result[11], all_abilities)
                        inputV.check_duplicate_values([result[9], result[10],
                                                       result[11]])
                        league.add_character(name=result[0],
                                             char_type=result[1],
                                             health=result[2], brawl=result[3],
                                             shoot=result[4], dodge=result[5],
                                             might=result[
                                                 6], finesse=result[7],
                                             cunning=result[8], arg1=result[9],
                                             arg2=result[10], arg3=result[11])
                    except InputException as e:
                        print(e.value)
                else:
                    print("You have entered too many arguments. Please try "
                          "again.")
            except InputException as e:
                print(e.value)
        else:
            print("You have not entered enough arguments to create a character"
                  ". Please try again.")