Ejemplo n.º 1
0
 def __init__(self, user):
     """ Randomly generates a monster for the player to fight """
     self.user = BattleUser(user)
     self.monster = BattleMonster(Monster.get_monster(user))
     self.text = "A random " + self.monster.name + " appears!"
     # True means its the users turn, False means its the cpu's turn
     self.turn = True
Ejemplo n.º 2
0
 def recover_mana(self):
     """ Recover between 10-20% mana """
     true_user = Monster.by_id(self.id)
     max_mana = true_user.mana
     # If there is health to gain
     if self.mana < max_mana:
         self.mana += min(int(max_mana * (random() % 0.2)), max_mana)
Ejemplo n.º 3
0
 def recover_health(self):
     """ Recover between 10-20% health """
     true_user = Monster.by_id(self.id)
     max_health = true_user.health
     # If there is health to gain
     if self.health < max_health:
         # Random number between .0 <-> .2 take that percentage of max hp and add it back in capping at your max hp
         self.health += min(int(max_health * (random() % 0.1)), max_health)
Ejemplo n.º 4
0
 def append_model(self, models_set, fields_list, texture, object_type):
     if object_type == 'monster':
         for field in fields_list:
             # 4 to jest maksymalna liczba potworów do losowego renderowania
             border_object = Monster(texture, 4, self, *field)
             models_set.add(border_object)
     elif object_type == 'obstacle':
         for field in fields_list:
             border_object = Obstacle(texture, *field)
             models_set.add(border_object)
     elif object_type == 'border':
         for field in fields_list:
             border_object = Border(texture, *field)
             models_set.add(border_object)
Ejemplo n.º 5
0
 def attack_monster(self, monster):
     """ Calculates the damage toward a given monster """
     true_monster = Monster.by_id(monster.id)
     true_user = User.by_id(self.id)
     monster_armor = ArmoryArmor.by_id(true_monster.armor_id)
     weapon = true_user.equiped_weapon
     if monster_armor != None and weapon != None:
         hit = self.roll_hit()
         if hit:
             reduction = monster_armor.rating
             damage = get_random_damage(weapon.damage)
             damage -= int(reduction / REDUCTION_CONSTANT)
             # Make sure we never return zero
             return max(damage, 0)
     return 0
Ejemplo n.º 6
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
Ejemplo n.º 7
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 !"