Exemple #1
0
    def choose_random_computer_move(self):
        """ returns one or three possible moves """
        choices = [BattleMessage.ATTACK, BattleMessage.DEFEND, BattleMessage.ATTACK]
        monster_weapon = ArmoryWeapon.by_id(self.monster.weapon_id)
        # If the monster can do advanced attacks
        if monster_weapon.advanced:
            choices.append(BattleMessage.ADVANCED)

        return choice(choices)
Exemple #2
0
 def advanced_attack_user(self, user):
     """ calculates damage agianst a provided user """
     true_monster = Monster.by_id(self.id)
     true_user = User.by_id(user.id)
     user_armor = true_user.equiped_armor
     weapon = ArmoryWeapon.by_id(true_monster.weapon_id)
     if user_armor != None and weapon != None:
         hit = self.roll_advanced_hit()
         if hit:
             reduction = user_armor.rating
             damage = get_random_damage(weapon.damage)
             damage -= int(reduction / REDUCTION_CONSTANT)
             # Make sure we never return zero
             return max(damage, 0) * 2
     return 0
Exemple #3
0
 def do_computer_round(self):
     """ perform the computers turn """
     # Randomly choose a move
     move = self.choose_random_computer_move()
     # perform that move
     if move == BattleMessage.ATTACK:
         damage = self.monster.attack_user(self.user)
         self.user.health -= damage
         if damage > 0:
             self.text = self.monster.name + " hits " + self.user.name + " for " + str(damage) + " damage!"
         else:
             self.text = self.monster.name + " misses !"
     elif move == BattleMessage.DEFEND:
         initial_health = self.monster.health
         initial_mana = self.monster.mana
         self.monster.recover_health()
         self.monster.recover_mana()
         self.text = (
             self.monster.name
             + " defends and recovers "
             + str(self.monster.health - initial_health)
             + " health and "
             + str(self.monster.mana - initial_mana)
             + " mana!"
         )
     elif move == BattleMessage.ADVANCED:
         monster = Monster.by_id(self.monster.id)
         monster_weapon = ArmoryWeapon.by_id(monster.weapon_id)
         required_mana = monster_weapon.rating
         if self.monster.mana > required_mana:
             # Remove the mana we just used
             self.monster.mana -= required_mana
             damage = self.monster.advanced_attack_user(self.user)
             self.user.health -= damage
             if damage > 0:
                 self.text = (
                     self.monster.name
                     + "'s Advanced attack hits "
                     + self.user.name
                     + " for "
                     + str(damage)
                     + " damage!"
                 )
             else:
                 self.text = self.monster.name + "'s Advanced attack misses !"