Esempio n. 1
0
def roll_damage(attack, target, critical=False):
    if critical:
        log.info("Rolling critical damage.")
        damage = (2 *
                  roll_dice(attack["damage_dice"])) + attack["damage_bonus"]
    else:
        log.info("Rolling normal damage.")
        damage = roll_dice(attack["damage_dice"]) + attack["damage_bonus"]

    log.info(
        "Dealing {} damage to {}, reducing their hit points from {} to {}.".
        format(damage, target.name, target.hit_points,
               target.hit_points - damage))

    target.hit_points -= damage
Esempio n. 2
0
 def initialize_hit_points(self):
     
     if self.stats["max_hit_points"]["method"] == "exact":
         self.state["current_hit_points"] = int(self.stats["max_hit_points"]["value"])
         
     elif self.stats["max_hit_points"]["method"] == "average":
         dice_vals = utils.evaluate_dice_string(self.stats["max_hit_points"]["value"])
         self.state["current_hit_points"] = math.floor(dice_vals[0] * (dice_vals[1] + 1)/2) + dice_vals[2]
         
     elif self.stats["max_hit_points"]["method"] == "roll":
         dice_vals = utils.evaluate_dice_string(self.stats["max_hit_points"]["value"])
         self.state["current_hit_points"] = utils.roll_dice(dice_vals[0],dice_vals[1])[0] + dice_vals[2]
Esempio n. 3
0
def roll_attack(attacker, attack, target):
    log.info("Making attack: " + attack['name'])

    # Make attack roll
    natural_attack_roll = roll_dice("1d20")

    # Check for natural 1
    if natural_attack_roll == 1:
        log.info("{} rolled a natural 1!".format(attacker.name))

    # Check for natural 20
    elif natural_attack_roll == 20:
        log.info("{} rolled a critical hit!".format(attacker.name))
        roll_damage(attack, target, critical=True)
    else:
        attack_roll = natural_attack_roll + attack['attack_bonus']
        log.info("{} rolled {} against {}'s AC {}".format(
            attacker.name, attack_roll, target.name, target.armour_class))
        if attack_roll >= target.armour_class:
            log.info("Attack hit!")
            roll_damage(attack, target)
        else:
            log.info("Attack missed!")
Esempio n. 4
0
def add_skills(hero, monster):

    hero.skills = {

        # Basic attack
        1:
        Skill(hero,
              name='Atack',
              energy=0,
              min_level=1,
              action=(lambda: hero.attack(hero.atk, monster))),

        # Heals 1d8 life points per level
        2:
        Skill(hero,
              name='Heal (1)',
              energy=1,
              min_level=1,
              action=(lambda: hero.heal())),

        # A stronger attack +5
        3:
        Skill(hero,
              name='Charged Attack (1)',
              energy=1,
              min_level=2,
              action=(lambda: hero.attack(hero.atk + 5, monster))),

        # Adds another dice roll to the charged attack
        4:
        Skill(
            hero,
            name='Double tap (2)',
            energy=2,
            min_level=3,
            action=(lambda: hero.attack(hero.atk + 5 + roll_dice(8), monster)))
    }
Esempio n. 5
0
def main():

    # Create object with players
    players = utils.get_players(config.N_PLAYERS)

    # Create board with properties
    board = utils.get_board(config.BOARD_FILENAME)

    # Continue playing as long as more than one player remains in game
    while len(players) > 1:

        # Take turns
        for turn in range(config.N_PLAYERS):

            # Define current player
            curr_player = players[turn]

            # Double roll counter
            n_double_roll = 0

            # Continue turn until player rolls no doubles or goes to jail
            while True:

                # Roll dice
                roll, rolled_double = utils.roll_dice()

                # Update double roll counter
                n_double_roll += int(rolled_double)

                # If player is in jail
                if players[turn].jail_turns > 0:

                    # Select jail strategy
                    curr_player.choose_jail_strategy(rolled_double)

                    # If player is still in jail
                    if curr_player.jail_turns > 0:
                        break

                # If player rolled less than 3 doubles
                if n_double_roll < 3:

                    # Move player
                    curr_player.move(roll)

                    # Define current board space
                    curr_space = board[curr_player.position]

                    for case in classes.Switch(type(curr_space).__name__):
                        if case('Street'):
                            curr_player.evaluate_buy(curr_space, players)

                    # If no double rolled, end turn
                    if not rolled_double:
                        break

                # Otherwise, send player to jail and end turn
                elif n_double_roll == 3:

                    curr_player.go_to_jail()
                    break
Esempio n. 6
0
 def _calculate_hit_points(self):
     result = roll_dice(self.hit_dice) + (get_bonus(self.constitution) *
                                          self.number_of_hit_dice)
     # Make sure the HP is at least 1
     return result if result > 1 else 1
import utils

print(utils.roll_dice(6))

numbers = [10, 2, 5, 7]
maximum_number = utils.find_max_number(numbers)
print(maximum_number)

# how to install external module
#    pip install python-docx
# it will be in Externnal Libraries/site-packages
# import docx and you can use it

# uninstall by pip uninstall python-docx