gemwarrior 0.7.4 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/.gitignore +11 -11
 - data/bin/gemwarrior +58 -58
 - data/data/locations.yml +600 -0
 - data/gemwarrior.gemspec +1 -0
 - data/lib/gemwarrior/battle.rb +296 -296
 - data/lib/gemwarrior/entities/item.rb +2 -2
 - data/lib/gemwarrior/entities/items/bed.rb +3 -2
 - data/lib/gemwarrior/entities/items/couch.rb +2 -2
 - data/lib/gemwarrior/entities/items/floor_tile.rb +1 -1
 - data/lib/gemwarrior/entities/items/gun.rb +1 -1
 - data/lib/gemwarrior/entities/items/herb.rb +2 -2
 - data/lib/gemwarrior/entities/items/massive_door.rb +0 -2
 - data/lib/gemwarrior/entities/items/sparklything.rb +1 -1
 - data/lib/gemwarrior/entities/items/tent.rb +19 -0
 - data/lib/gemwarrior/entities/items/tower_switch.rb +1 -1
 - data/lib/gemwarrior/entities/items/waterfall.rb +1 -2
 - data/lib/gemwarrior/entities/player.rb +32 -11
 - data/lib/gemwarrior/evaluator.rb +14 -5
 - data/lib/gemwarrior/game.rb +1 -1
 - data/lib/gemwarrior/misc/version.rb +1 -1
 - data/lib/gemwarrior/world.rb +49 -388
 - metadata +6 -6
 
    
        data/gemwarrior.gemspec
    CHANGED
    
    | 
         @@ -24,6 +24,7 @@ Gem::Specification.new do |spec| 
     | 
|
| 
       24 
24 
     | 
    
         
             
              spec.add_runtime_dependency 'http', '~> 0.8.10'
         
     | 
| 
       25 
25 
     | 
    
         
             
              spec.add_runtime_dependency 'json', '~> 1.8.2'
         
     | 
| 
       26 
26 
     | 
    
         
             
              spec.add_runtime_dependency 'colorize', '~> 0.7.7'
         
     | 
| 
      
 27 
     | 
    
         
            +
              #spec.add_runtime_dependency 'hr', '~> 0.0.1'
         
     | 
| 
       27 
28 
     | 
    
         | 
| 
       28 
29 
     | 
    
         
             
              #spec.add_runtime_dependency 'feep', '~> 0.1.0'  
         
     | 
| 
       29 
30 
     | 
    
         
             
              #spec.add_runtime_dependency 'wordnik', '~> 4.12'
         
     | 
    
        data/lib/gemwarrior/battle.rb
    CHANGED
    
    | 
         @@ -1,296 +1,296 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # lib/gemwarrior/battle.rb
         
     | 
| 
       2 
     | 
    
         
            -
            # Monster battle
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            require_relative 'misc/player_levels'
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
            module Gemwarrior
         
     | 
| 
       7 
     | 
    
         
            -
              class Battle
         
     | 
| 
       8 
     | 
    
         
            -
                include PlayerLevels
         
     | 
| 
       9 
     | 
    
         
            -
              
         
     | 
| 
       10 
     | 
    
         
            -
                # CONSTANTS
         
     | 
| 
       11 
     | 
    
         
            -
                ## ERRORS
         
     | 
| 
       12 
     | 
    
         
            -
                ERROR_ATTACK_OPTION_INVALID = 'That will not do anything against the monster.'
         
     | 
| 
       13 
     | 
    
         
            -
                BEAST_MODE_ATTACK           = 100
         
     | 
| 
       14 
     | 
    
         
            -
                
         
     | 
| 
       15 
     | 
    
         
            -
                ## MESSAGES
         
     | 
| 
       16 
     | 
    
         
            -
                TEXT_ESCAPE                 = 'POOF'
         
     | 
| 
       17 
     | 
    
         
            -
                
         
     | 
| 
       18 
     | 
    
         
            -
                attr_accessor :world, :player, :monster
         
     | 
| 
       19 
     | 
    
         
            -
                
         
     | 
| 
       20 
     | 
    
         
            -
                def initialize(options)
         
     | 
| 
       21 
     | 
    
         
            -
                  self.world    = options.fetch(:world)
         
     | 
| 
       22 
     | 
    
         
            -
                  self.player   = options.fetch(:player)
         
     | 
| 
       23 
     | 
    
         
            -
                  self.monster  = options.fetch(:monster)
         
     | 
| 
       24 
     | 
    
         
            -
                end
         
     | 
| 
       25 
     | 
    
         
            -
                
         
     | 
| 
       26 
     | 
    
         
            -
                def start
         
     | 
| 
       27 
     | 
    
         
            -
                  print_battle_line
         
     | 
| 
       28 
     | 
    
         
            -
                  puts "You decide to attack the #{monster.name}!"
         
     | 
| 
       29 
     | 
    
         
            -
                  puts "#{monster.name} cries out: \"#{monster.battlecry}\"".colorize(:yellow)
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                  # first strike!
         
     | 
| 
       32 
     | 
    
         
            -
                  if monster_strikes_first?
         
     | 
| 
       33 
     | 
    
         
            -
                    puts "#{monster.name} strikes first!".colorize(:yellow)
         
     | 
| 
       34 
     | 
    
         
            -
                    monster_attacks_player
         
     | 
| 
       35 
     | 
    
         
            -
                  end
         
     | 
| 
       36 
     | 
    
         
            -
                  
         
     | 
| 
       37 
     | 
    
         
            -
                  # main battle loop
         
     | 
| 
       38 
     | 
    
         
            -
                  loop do
         
     | 
| 
       39 
     | 
    
         
            -
                    if monster_dead?
         
     | 
| 
       40 
     | 
    
         
            -
                      monster_death
         
     | 
| 
       41 
     | 
    
         
            -
                      return
         
     | 
| 
       42 
     | 
    
         
            -
                    elsif player_dead?
         
     | 
| 
       43 
     | 
    
         
            -
                      player_death
         
     | 
| 
       44 
     | 
    
         
            -
                    end
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
                    if player_near_death?
         
     | 
| 
       47 
     | 
    
         
            -
                      puts "You are almost dead!\n".colorize(:yellow)
         
     | 
| 
       48 
     | 
    
         
            -
                    end
         
     | 
| 
       49 
     | 
    
         
            -
                    if monster_near_death?
         
     | 
| 
       50 
     | 
    
         
            -
                      puts "#{monster.name} is almost dead!\n".colorize(:yellow)
         
     | 
| 
       51 
     | 
    
         
            -
                    end
         
     | 
| 
       52 
     | 
    
         
            -
                    
         
     | 
| 
       53 
     | 
    
         
            -
                    puts
         
     | 
| 
       54 
     | 
    
         
            -
                    print "PLAYER  :: #{player.hp_cur.to_s.rjust(3)} HP"
         
     | 
| 
       55 
     | 
    
         
            -
                    if world.debug_mode
         
     | 
| 
       56 
     | 
    
         
            -
                      print " (LVL: #{player.level})"
         
     | 
| 
       57 
     | 
    
         
            -
                    end
         
     | 
| 
       58 
     | 
    
         
            -
                    print "\n"
         
     | 
| 
       59 
     | 
    
         
            -
                    
         
     | 
| 
       60 
     | 
    
         
            -
                    print "MONSTER :: "
         
     | 
| 
       61 
     | 
    
         
            -
                    if world.debug_mode || PlayerLevels::get_level_stats(player.level)[:special_abilities].include?(:rocking_vision)
         
     | 
| 
       62 
     | 
    
         
            -
                      print "#{monster.hp_cur.to_s.rjust(3)}"
         
     | 
| 
       63 
     | 
    
         
            -
                    else
         
     | 
| 
       64 
     | 
    
         
            -
                      print "???"
         
     | 
| 
       65 
     | 
    
         
            -
                    end
         
     | 
| 
       66 
     | 
    
         
            -
                    print " HP"
         
     | 
| 
       67 
     | 
    
         
            -
                    if world.debug_mode
         
     | 
| 
       68 
     | 
    
         
            -
                      print " (LVL: #{monster.level})"
         
     | 
| 
       69 
     | 
    
         
            -
                    end
         
     | 
| 
       70 
     | 
    
         
            -
                    print "\n"
         
     | 
| 
       71 
     | 
    
         
            -
                    puts
         
     | 
| 
       72 
     | 
    
         
            -
                    
         
     | 
| 
       73 
     | 
    
         
            -
                    puts 'What do you do?'
         
     | 
| 
       74 
     | 
    
         
            -
                    puts "[Fight/Attack][Look][Run]".colorize(:color => :yellow)
         
     | 
| 
       75 
     | 
    
         
            -
                    
         
     | 
| 
       76 
     | 
    
         
            -
                    cmd = gets.chomp.downcase
         
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
                    # player action
         
     | 
| 
       79 
     | 
    
         
            -
                    case cmd
         
     | 
| 
       80 
     | 
    
         
            -
                    when 'fight', 'f', 'attack', 'a'
         
     | 
| 
       81 
     | 
    
         
            -
                      puts "You attack #{monster.name}#{player.cur_weapon_name}!"
         
     | 
| 
       82 
     | 
    
         
            -
                      dmg = calculate_damage_to(monster)
         
     | 
| 
       83 
     | 
    
         
            -
                      if dmg > 0
         
     | 
| 
       84 
     | 
    
         
            -
                        take_damage(monster, dmg)
         
     | 
| 
       85 
     | 
    
         
            -
                        if monster_dead?
         
     | 
| 
       86 
     | 
    
         
            -
                          monster_death
         
     | 
| 
       87 
     | 
    
         
            -
                          return
         
     | 
| 
       88 
     | 
    
         
            -
                        end
         
     | 
| 
       89 
     | 
    
         
            -
                      else
         
     | 
| 
       90 
     | 
    
         
            -
                        puts "You miss entirely!".colorize(:yellow)
         
     | 
| 
       91 
     | 
    
         
            -
                      end
         
     | 
| 
       92 
     | 
    
         
            -
                    when 'look', 'l'
         
     | 
| 
       93 
     | 
    
         
            -
                      print "#{monster.name}".colorize(:white)
         
     | 
| 
       94 
     | 
    
         
            -
                      print " (#{monster.hp_cur}/#{monster.hp_max} HP): #{monster.description}\n"
         
     | 
| 
       95 
     | 
    
         
            -
                      puts "It has some distinguishing features, too: face is #{monster.face}, hands are #{monster.hands}, and general mood is #{monster.mood}."
         
     | 
| 
       96 
     | 
    
         
            -
                      if world.debug_mode
         
     | 
| 
       97 
     | 
    
         
            -
                        puts "If defeated, will receive:"
         
     | 
| 
       98 
     | 
    
         
            -
                        puts " >> XP   : #{monster.xp}"
         
     | 
| 
       99 
     | 
    
         
            -
                        puts " >> ROX  : #{monster.rox}"
         
     | 
| 
       100 
     | 
    
         
            -
                        puts " >> ITEMS: #{monster.inventory.list_contents}"
         
     | 
| 
       101 
     | 
    
         
            -
                        next
         
     | 
| 
       102 
     | 
    
         
            -
                      end
         
     | 
| 
       103 
     | 
    
         
            -
                    when 'run', 'r'
         
     | 
| 
       104 
     | 
    
         
            -
                      if player_escape?
         
     | 
| 
       105 
     | 
    
         
            -
                        monster.hp_cur = monster.hp_max
         
     | 
| 
       106 
     | 
    
         
            -
                        puts "You successfully elude #{monster.name}!".colorize(:green)
         
     | 
| 
       107 
     | 
    
         
            -
                        print_escape_text
         
     | 
| 
       108 
     | 
    
         
            -
                        return
         
     | 
| 
       109 
     | 
    
         
            -
                      else
         
     | 
| 
       110 
     | 
    
         
            -
                        puts "You were not able to run away! :-(".colorize(:yellow)
         
     | 
| 
       111 
     | 
    
         
            -
                      end
         
     | 
| 
       112 
     | 
    
         
            -
                    else
         
     | 
| 
       113 
     | 
    
         
            -
                      puts ERROR_ATTACK_OPTION_INVALID
         
     | 
| 
       114 
     | 
    
         
            -
                      next
         
     | 
| 
       115 
     | 
    
         
            -
                    end
         
     | 
| 
       116 
     | 
    
         
            -
                    
         
     | 
| 
       117 
     | 
    
         
            -
                    # monster action
         
     | 
| 
       118 
     | 
    
         
            -
                    monster_attacks_player
         
     | 
| 
       119 
     | 
    
         
            -
                  end
         
     | 
| 
       120 
     | 
    
         
            -
                end
         
     | 
| 
       121 
     | 
    
         
            -
                
         
     | 
| 
       122 
     | 
    
         
            -
                private
         
     | 
| 
       123 
     | 
    
         
            -
                
         
     | 
| 
       124 
     | 
    
         
            -
                # NEUTRAL   
         
     | 
| 
       125 
     | 
    
         
            -
                def calculate_damage_to(entity)
         
     | 
| 
       126 
     | 
    
         
            -
                  miss = rand(0..(100 + entity.defense))
         
     | 
| 
       127 
     | 
    
         
            -
                  if (miss < 15)
         
     | 
| 
       128 
     | 
    
         
            -
                    0
         
     | 
| 
       129 
     | 
    
         
            -
                  else
         
     | 
| 
       130 
     | 
    
         
            -
                    if entity.eql?(monster)
         
     | 
| 
       131 
     | 
    
         
            -
                      if player.beast_mode
         
     | 
| 
       132 
     | 
    
         
            -
                        atk_range = BEAST_MODE_ATTACK..BEAST_MODE_ATTACK
         
     | 
| 
       133 
     | 
    
         
            -
                      else
         
     | 
| 
       134 
     | 
    
         
            -
                        atk_range = player.atk_lo..player.atk_hi
         
     | 
| 
       135 
     | 
    
         
            -
                      end
         
     | 
| 
       136 
     | 
    
         
            -
                      rand(atk_range)
         
     | 
| 
       137 
     | 
    
         
            -
                    else
         
     | 
| 
       138 
     | 
    
         
            -
                      rand(monster.atk_lo..monster.atk_hi)
         
     | 
| 
       139 
     | 
    
         
            -
                    end
         
     | 
| 
       140 
     | 
    
         
            -
                  end
         
     | 
| 
       141 
     | 
    
         
            -
                end
         
     | 
| 
       142 
     | 
    
         
            -
                
         
     | 
| 
       143 
     | 
    
         
            -
                def take_damage(entity, dmg)
         
     | 
| 
       144 
     | 
    
         
            -
                  entity.hp_cur = entity.hp_cur.to_i - dmg.to_i
         
     | 
| 
       145 
     | 
    
         
            -
                  who_gets_wounded = ''
         
     | 
| 
       146 
     | 
    
         
            -
                  
         
     | 
| 
       147 
     | 
    
         
            -
                  if entity.eql?(monster)
         
     | 
| 
       148 
     | 
    
         
            -
                    who_gets_wounded = "> You wound #{monster.name} for "
         
     | 
| 
       149 
     | 
    
         
            -
                  else
         
     | 
| 
       150 
     | 
    
         
            -
                    who_gets_wounded = "> You are wounded for "
         
     | 
| 
       151 
     | 
    
         
            -
                  end
         
     | 
| 
       152 
     | 
    
         
            -
                  
         
     | 
| 
       153 
     | 
    
         
            -
                  print who_gets_wounded
         
     | 
| 
       154 
     | 
    
         
            -
                  Animation::run({ :phrase => dmg.to_s, :speed => :slow, :oneline => true, :alpha => false, :random => false })
         
     | 
| 
       155 
     | 
    
         
            -
                  print " point(s)!\n"
         
     | 
| 
       156 
     | 
    
         
            -
                end
         
     | 
| 
       157 
     | 
    
         
            -
                
         
     | 
| 
       158 
     | 
    
         
            -
                # MONSTER
         
     | 
| 
       159 
     | 
    
         
            -
                def monster_strikes_first?
         
     | 
| 
       160 
     | 
    
         
            -
                  if (monster.dexterity > player.dexterity)
         
     | 
| 
       161 
     | 
    
         
            -
                    return true
         
     | 
| 
       162 
     | 
    
         
            -
                  else
         
     | 
| 
       163 
     | 
    
         
            -
                    dex_diff = player.dexterity - monster.dexterity
         
     | 
| 
       164 
     | 
    
         
            -
                    rand_dex = rand(0..dex_diff)
         
     | 
| 
       165 
     | 
    
         
            -
                    if rand_dex % 2 > 0
         
     | 
| 
       166 
     | 
    
         
            -
                      return true
         
     | 
| 
       167 
     | 
    
         
            -
                    else
         
     | 
| 
       168 
     | 
    
         
            -
                      return false
         
     | 
| 
       169 
     | 
    
         
            -
                    end
         
     | 
| 
       170 
     | 
    
         
            -
                  end
         
     | 
| 
       171 
     | 
    
         
            -
                end
         
     | 
| 
       172 
     | 
    
         
            -
                
         
     | 
| 
       173 
     | 
    
         
            -
                def monster_attacks_player
         
     | 
| 
       174 
     | 
    
         
            -
                  puts "#{monster.name} attacks you!"
         
     | 
| 
       175 
     | 
    
         
            -
                  dmg = calculate_damage_to(player)
         
     | 
| 
       176 
     | 
    
         
            -
                  if dmg > 0
         
     | 
| 
       177 
     | 
    
         
            -
                    take_damage(player, dmg)
         
     | 
| 
       178 
     | 
    
         
            -
                    if player_dead?
         
     | 
| 
       179 
     | 
    
         
            -
                      player_death
         
     | 
| 
       180 
     | 
    
         
            -
                    end
         
     | 
| 
       181 
     | 
    
         
            -
                  else
         
     | 
| 
       182 
     | 
    
         
            -
                    puts "#{monster.name} misses entirely!".colorize(:yellow)
         
     | 
| 
       183 
     | 
    
         
            -
                  end
         
     | 
| 
       184 
     | 
    
         
            -
                end
         
     | 
| 
       185 
     | 
    
         
            -
             
     | 
| 
       186 
     | 
    
         
            -
                def monster_near_death?
         
     | 
| 
       187 
     | 
    
         
            -
                  ((monster.hp_cur.to_f / monster.hp_max.to_f) < 0.10)
         
     | 
| 
       188 
     | 
    
         
            -
                end
         
     | 
| 
       189 
     | 
    
         
            -
                
         
     | 
| 
       190 
     | 
    
         
            -
                def monster_dead?
         
     | 
| 
       191 
     | 
    
         
            -
                  monster.hp_cur <= 0
         
     | 
| 
       192 
     | 
    
         
            -
                end
         
     | 
| 
       193 
     | 
    
         
            -
                
         
     | 
| 
       194 
     | 
    
         
            -
                def monster_death
         
     | 
| 
       195 
     | 
    
         
            -
                  puts "You have defeated #{monster.name}!\n".colorize(:green)
         
     | 
| 
       196 
     | 
    
         
            -
                  if monster.is_boss
         
     | 
| 
       197 
     | 
    
         
            -
                    if monster.name.eql?("Emerald")
         
     | 
| 
       198 
     | 
    
         
            -
                      puts monster.defeated_text
         
     | 
| 
       199 
     | 
    
         
            -
                      exit(0)
         
     | 
| 
       200 
     | 
    
         
            -
                    else
         
     | 
| 
       201 
     | 
    
         
            -
                      puts 'You just beat a boss monster. Way to go!'
         
     | 
| 
       202 
     | 
    
         
            -
                      puts " XP : #{monster.xp}".colorize(:green)
         
     | 
| 
       203 
     | 
    
         
            -
                      puts " ROX: #{monster.rox}".colorize(:green)
         
     | 
| 
       204 
     | 
    
         
            -
                      print_battle_line
         
     | 
| 
       205 
     | 
    
         
            -
                      update_player_stats
         
     | 
| 
       206 
     | 
    
         
            -
                      world.location_by_coords(player.cur_coords).remove_monster(monster.name)
         
     | 
| 
       207 
     | 
    
         
            -
                    end
         
     | 
| 
       208 
     | 
    
         
            -
                  else
         
     | 
| 
       209 
     | 
    
         
            -
                    puts 'You get the following spoils of war:'
         
     | 
| 
       210 
     | 
    
         
            -
                    puts " XP   : #{monster.xp}".colorize(:green)
         
     | 
| 
       211 
     | 
    
         
            -
                    puts " ROX  : #{monster.rox}".colorize(:green)
         
     | 
| 
       212 
     | 
    
         
            -
                    unless monster.inventory.nil?
         
     | 
| 
       213 
     | 
    
         
            -
                      puts " ITEMS: #{monster.inventory.list_contents}".colorize(:green) unless monster.inventory.items.empty?
         
     | 
| 
       214 
     | 
    
         
            -
                    end
         
     | 
| 
       215 
     | 
    
         
            -
                    print_battle_line
         
     | 
| 
       216 
     | 
    
         
            -
                    update_player_stats
         
     | 
| 
       217 
     | 
    
         
            -
                    world.location_by_coords(player.cur_coords).remove_monster(monster.name)
         
     | 
| 
       218 
     | 
    
         
            -
                  end
         
     | 
| 
       219 
     | 
    
         
            -
                end
         
     | 
| 
       220 
     | 
    
         
            -
                
         
     | 
| 
       221 
     | 
    
         
            -
                # PLAYER
         
     | 
| 
       222 
     | 
    
         
            -
                def update_player_stats
         
     | 
| 
       223 
     | 
    
         
            -
                  old_player_level = PlayerLevels::check_level(player.xp)
         
     | 
| 
       224 
     | 
    
         
            -
                  
         
     | 
| 
       225 
     | 
    
         
            -
                  player.xp = player.xp + monster.xp
         
     | 
| 
       226 
     | 
    
         
            -
                  player.rox = player.rox + monster.rox
         
     | 
| 
       227 
     | 
    
         
            -
                  
         
     | 
| 
       228 
     | 
    
         
            -
                  monster_items = monster.inventory.items
         
     | 
| 
       229 
     | 
    
         
            -
                  unless monster_items.nil?
         
     | 
| 
       230 
     | 
    
         
            -
                    player.inventory.items.concat monster_items unless monster_items.empty?
         
     | 
| 
       231 
     | 
    
         
            -
                  end
         
     | 
| 
       232 
     | 
    
         
            -
                  
         
     | 
| 
       233 
     | 
    
         
            -
                  new_player_level = PlayerLevels::check_level(player.xp)
         
     | 
| 
       234 
     | 
    
         
            -
                  
         
     | 
| 
       235 
     | 
    
         
            -
                  if new_player_level > old_player_level
         
     | 
| 
       236 
     | 
    
         
            -
                     
     | 
| 
       237 
     | 
    
         
            -
                    new_stats = PlayerLevels::get_level_stats(new_player_level)
         
     | 
| 
       238 
     | 
    
         
            -
                    
         
     | 
| 
       239 
     | 
    
         
            -
                    player.level = new_stats[:level]
         
     | 
| 
       240 
     | 
    
         
            -
                    puts "You are now level #{player.level}!"
         
     | 
| 
       241 
     | 
    
         
            -
                    player.hp_cur = new_stats[:hp_max]
         
     | 
| 
       242 
     | 
    
         
            -
                    player.hp_max = new_stats[:hp_max]
         
     | 
| 
       243 
     | 
    
         
            -
                    puts "You now have #{player.hp_max} hit points!"
         
     | 
| 
       244 
     | 
    
         
            -
                    player.stam_cur = new_stats[:stam_max]
         
     | 
| 
       245 
     | 
    
         
            -
                    player.stam_max = new_stats[:stam_max]
         
     | 
| 
       246 
     | 
    
         
            -
                    puts "You now have #{player.stam_max} stamina points!"
         
     | 
| 
       247 
     | 
    
         
            -
                    player.atk_lo = new_stats[:atk_lo]
         
     | 
| 
       248 
     | 
    
         
            -
                    player.atk_hi = new_stats[:atk_hi]
         
     | 
| 
       249 
     | 
    
         
            -
                    puts "You now have an attack of #{player.atk_lo}-#{player.atk_hi}!"
         
     | 
| 
       250 
     | 
    
         
            -
                    player.defense = new_stats[:defense]
         
     | 
| 
       251 
     | 
    
         
            -
                    puts "You now have #{player.defense} defensive points!"
         
     | 
| 
       252 
     | 
    
         
            -
                    player.dexterity = new_stats[:dexterity]
         
     | 
| 
       253 
     | 
    
         
            -
                    puts "You now have #{player.dexterity} dexterity points!"
         
     | 
| 
       254 
     | 
    
         
            -
                  end
         
     | 
| 
       255 
     | 
    
         
            -
                end
         
     | 
| 
       256 
     | 
    
         
            -
                
         
     | 
| 
       257 
     | 
    
         
            -
                def player_near_death?
         
     | 
| 
       258 
     | 
    
         
            -
                  ((player.hp_cur.to_f / player.hp_max.to_f) < 0.10 && !player.god_mode)
         
     | 
| 
       259 
     | 
    
         
            -
                end
         
     | 
| 
       260 
     | 
    
         
            -
                
         
     | 
| 
       261 
     | 
    
         
            -
                def player_dead?
         
     | 
| 
       262 
     | 
    
         
            -
                  (player.hp_cur <= 0 && !player.god_mode)
         
     | 
| 
       263 
     | 
    
         
            -
                end
         
     | 
| 
       264 
     | 
    
         
            -
                
         
     | 
| 
       265 
     | 
    
         
            -
                def player_death
         
     | 
| 
       266 
     | 
    
         
            -
                  puts "You are dead, slain by the #{monster.name}!".colorize(:red)
         
     | 
| 
       267 
     | 
    
         
            -
                  puts 'Your adventure ends here. Try again next time!'.colorize(:red)
         
     | 
| 
       268 
     | 
    
         
            -
                  print_battle_line
         
     | 
| 
       269 
     | 
    
         
            -
                  exit(0)
         
     | 
| 
       270 
     | 
    
         
            -
                end
         
     | 
| 
       271 
     | 
    
         
            -
                
         
     | 
| 
       272 
     | 
    
         
            -
                def player_escape?
         
     | 
| 
       273 
     | 
    
         
            -
                  if (player.dexterity > monster.dexterity)
         
     | 
| 
       274 
     | 
    
         
            -
                    return true
         
     | 
| 
       275 
     | 
    
         
            -
                  else
         
     | 
| 
       276 
     | 
    
         
            -
                    dex_diff = monster.dexterity - player.dexterity
         
     | 
| 
       277 
     | 
    
         
            -
                    rand_dex = rand(0..dex_diff)
         
     | 
| 
       278 
     | 
    
         
            -
                    if rand_dex % 2 > 0
         
     | 
| 
       279 
     | 
    
         
            -
                      return true
         
     | 
| 
       280 
     | 
    
         
            -
                    else
         
     | 
| 
       281 
     | 
    
         
            -
                      return false
         
     | 
| 
       282 
     | 
    
         
            -
                    end
         
     | 
| 
       283 
     | 
    
         
            -
                  end
         
     | 
| 
       284 
     | 
    
         
            -
                end
         
     | 
| 
       285 
     | 
    
         
            -
                
         
     | 
| 
       286 
     | 
    
         
            -
                # STATUS TEXT
         
     | 
| 
       287 
     | 
    
         
            -
                
         
     | 
| 
       288 
     | 
    
         
            -
                def print_escape_text
         
     | 
| 
       289 
     | 
    
         
            -
                  Animation::run({ :phrase => " 
     | 
| 
       290 
     | 
    
         
            -
                end
         
     | 
| 
       291 
     | 
    
         
            -
                
         
     | 
| 
       292 
     | 
    
         
            -
                def print_battle_line
         
     | 
| 
       293 
     | 
    
         
            -
                  puts ' 
     | 
| 
       294 
     | 
    
         
            -
                end
         
     | 
| 
       295 
     | 
    
         
            -
              end
         
     | 
| 
       296 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            # lib/gemwarrior/battle.rb
         
     | 
| 
      
 2 
     | 
    
         
            +
            # Monster battle
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            require_relative 'misc/player_levels'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            module Gemwarrior
         
     | 
| 
      
 7 
     | 
    
         
            +
              class Battle
         
     | 
| 
      
 8 
     | 
    
         
            +
                include PlayerLevels
         
     | 
| 
      
 9 
     | 
    
         
            +
              
         
     | 
| 
      
 10 
     | 
    
         
            +
                # CONSTANTS
         
     | 
| 
      
 11 
     | 
    
         
            +
                ## ERRORS
         
     | 
| 
      
 12 
     | 
    
         
            +
                ERROR_ATTACK_OPTION_INVALID = 'That will not do anything against the monster.'
         
     | 
| 
      
 13 
     | 
    
         
            +
                BEAST_MODE_ATTACK           = 100
         
     | 
| 
      
 14 
     | 
    
         
            +
                
         
     | 
| 
      
 15 
     | 
    
         
            +
                ## MESSAGES
         
     | 
| 
      
 16 
     | 
    
         
            +
                TEXT_ESCAPE                 = 'POOF'
         
     | 
| 
      
 17 
     | 
    
         
            +
                
         
     | 
| 
      
 18 
     | 
    
         
            +
                attr_accessor :world, :player, :monster
         
     | 
| 
      
 19 
     | 
    
         
            +
                
         
     | 
| 
      
 20 
     | 
    
         
            +
                def initialize(options)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  self.world    = options.fetch(:world)
         
     | 
| 
      
 22 
     | 
    
         
            +
                  self.player   = options.fetch(:player)
         
     | 
| 
      
 23 
     | 
    
         
            +
                  self.monster  = options.fetch(:monster)
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
                
         
     | 
| 
      
 26 
     | 
    
         
            +
                def start
         
     | 
| 
      
 27 
     | 
    
         
            +
                  print_battle_line
         
     | 
| 
      
 28 
     | 
    
         
            +
                  puts "You decide to attack the #{monster.name}!"
         
     | 
| 
      
 29 
     | 
    
         
            +
                  puts "#{monster.name} cries out: \"#{monster.battlecry}\"".colorize(:yellow)
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                  # first strike!
         
     | 
| 
      
 32 
     | 
    
         
            +
                  if monster_strikes_first?
         
     | 
| 
      
 33 
     | 
    
         
            +
                    puts "#{monster.name} strikes first!".colorize(:yellow)
         
     | 
| 
      
 34 
     | 
    
         
            +
                    monster_attacks_player
         
     | 
| 
      
 35 
     | 
    
         
            +
                  end
         
     | 
| 
      
 36 
     | 
    
         
            +
                  
         
     | 
| 
      
 37 
     | 
    
         
            +
                  # main battle loop
         
     | 
| 
      
 38 
     | 
    
         
            +
                  loop do
         
     | 
| 
      
 39 
     | 
    
         
            +
                    if monster_dead?
         
     | 
| 
      
 40 
     | 
    
         
            +
                      monster_death
         
     | 
| 
      
 41 
     | 
    
         
            +
                      return
         
     | 
| 
      
 42 
     | 
    
         
            +
                    elsif player_dead?
         
     | 
| 
      
 43 
     | 
    
         
            +
                      player_death
         
     | 
| 
      
 44 
     | 
    
         
            +
                    end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                    if player_near_death?
         
     | 
| 
      
 47 
     | 
    
         
            +
                      puts "You are almost dead!\n".colorize(:yellow)
         
     | 
| 
      
 48 
     | 
    
         
            +
                    end
         
     | 
| 
      
 49 
     | 
    
         
            +
                    if monster_near_death?
         
     | 
| 
      
 50 
     | 
    
         
            +
                      puts "#{monster.name} is almost dead!\n".colorize(:yellow)
         
     | 
| 
      
 51 
     | 
    
         
            +
                    end
         
     | 
| 
      
 52 
     | 
    
         
            +
                    
         
     | 
| 
      
 53 
     | 
    
         
            +
                    puts
         
     | 
| 
      
 54 
     | 
    
         
            +
                    print "PLAYER  :: #{player.hp_cur.to_s.rjust(3)} HP"
         
     | 
| 
      
 55 
     | 
    
         
            +
                    if world.debug_mode
         
     | 
| 
      
 56 
     | 
    
         
            +
                      print " (LVL: #{player.level})"
         
     | 
| 
      
 57 
     | 
    
         
            +
                    end
         
     | 
| 
      
 58 
     | 
    
         
            +
                    print "\n"
         
     | 
| 
      
 59 
     | 
    
         
            +
                    
         
     | 
| 
      
 60 
     | 
    
         
            +
                    print "MONSTER :: "
         
     | 
| 
      
 61 
     | 
    
         
            +
                    if world.debug_mode || PlayerLevels::get_level_stats(player.level)[:special_abilities].include?(:rocking_vision)
         
     | 
| 
      
 62 
     | 
    
         
            +
                      print "#{monster.hp_cur.to_s.rjust(3)}"
         
     | 
| 
      
 63 
     | 
    
         
            +
                    else
         
     | 
| 
      
 64 
     | 
    
         
            +
                      print "???"
         
     | 
| 
      
 65 
     | 
    
         
            +
                    end
         
     | 
| 
      
 66 
     | 
    
         
            +
                    print " HP"
         
     | 
| 
      
 67 
     | 
    
         
            +
                    if world.debug_mode
         
     | 
| 
      
 68 
     | 
    
         
            +
                      print " (LVL: #{monster.level})"
         
     | 
| 
      
 69 
     | 
    
         
            +
                    end
         
     | 
| 
      
 70 
     | 
    
         
            +
                    print "\n"
         
     | 
| 
      
 71 
     | 
    
         
            +
                    puts
         
     | 
| 
      
 72 
     | 
    
         
            +
                    
         
     | 
| 
      
 73 
     | 
    
         
            +
                    puts 'What do you do?'
         
     | 
| 
      
 74 
     | 
    
         
            +
                    puts "[Fight/Attack][Look][Run]".colorize(:color => :yellow)
         
     | 
| 
      
 75 
     | 
    
         
            +
                    
         
     | 
| 
      
 76 
     | 
    
         
            +
                    cmd = gets.chomp.downcase
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
                    # player action
         
     | 
| 
      
 79 
     | 
    
         
            +
                    case cmd
         
     | 
| 
      
 80 
     | 
    
         
            +
                    when 'fight', 'f', 'attack', 'a'
         
     | 
| 
      
 81 
     | 
    
         
            +
                      puts "You attack #{monster.name}#{player.cur_weapon_name}!"
         
     | 
| 
      
 82 
     | 
    
         
            +
                      dmg = calculate_damage_to(monster)
         
     | 
| 
      
 83 
     | 
    
         
            +
                      if dmg > 0
         
     | 
| 
      
 84 
     | 
    
         
            +
                        take_damage(monster, dmg)
         
     | 
| 
      
 85 
     | 
    
         
            +
                        if monster_dead?
         
     | 
| 
      
 86 
     | 
    
         
            +
                          monster_death
         
     | 
| 
      
 87 
     | 
    
         
            +
                          return
         
     | 
| 
      
 88 
     | 
    
         
            +
                        end
         
     | 
| 
      
 89 
     | 
    
         
            +
                      else
         
     | 
| 
      
 90 
     | 
    
         
            +
                        puts "You miss entirely!".colorize(:yellow)
         
     | 
| 
      
 91 
     | 
    
         
            +
                      end
         
     | 
| 
      
 92 
     | 
    
         
            +
                    when 'look', 'l'
         
     | 
| 
      
 93 
     | 
    
         
            +
                      print "#{monster.name}".colorize(:white)
         
     | 
| 
      
 94 
     | 
    
         
            +
                      print " (#{monster.hp_cur}/#{monster.hp_max} HP): #{monster.description}\n"
         
     | 
| 
      
 95 
     | 
    
         
            +
                      puts "It has some distinguishing features, too: face is #{monster.face}, hands are #{monster.hands}, and general mood is #{monster.mood}."
         
     | 
| 
      
 96 
     | 
    
         
            +
                      if world.debug_mode
         
     | 
| 
      
 97 
     | 
    
         
            +
                        puts "If defeated, will receive:"
         
     | 
| 
      
 98 
     | 
    
         
            +
                        puts " >> XP   : #{monster.xp}"
         
     | 
| 
      
 99 
     | 
    
         
            +
                        puts " >> ROX  : #{monster.rox}"
         
     | 
| 
      
 100 
     | 
    
         
            +
                        puts " >> ITEMS: #{monster.inventory.list_contents}"
         
     | 
| 
      
 101 
     | 
    
         
            +
                        next
         
     | 
| 
      
 102 
     | 
    
         
            +
                      end
         
     | 
| 
      
 103 
     | 
    
         
            +
                    when 'run', 'r'
         
     | 
| 
      
 104 
     | 
    
         
            +
                      if player_escape?
         
     | 
| 
      
 105 
     | 
    
         
            +
                        monster.hp_cur = monster.hp_max
         
     | 
| 
      
 106 
     | 
    
         
            +
                        puts "You successfully elude #{monster.name}!".colorize(:green)
         
     | 
| 
      
 107 
     | 
    
         
            +
                        print_escape_text
         
     | 
| 
      
 108 
     | 
    
         
            +
                        return
         
     | 
| 
      
 109 
     | 
    
         
            +
                      else
         
     | 
| 
      
 110 
     | 
    
         
            +
                        puts "You were not able to run away! :-(".colorize(:yellow)
         
     | 
| 
      
 111 
     | 
    
         
            +
                      end
         
     | 
| 
      
 112 
     | 
    
         
            +
                    else
         
     | 
| 
      
 113 
     | 
    
         
            +
                      puts ERROR_ATTACK_OPTION_INVALID
         
     | 
| 
      
 114 
     | 
    
         
            +
                      next
         
     | 
| 
      
 115 
     | 
    
         
            +
                    end
         
     | 
| 
      
 116 
     | 
    
         
            +
                    
         
     | 
| 
      
 117 
     | 
    
         
            +
                    # monster action
         
     | 
| 
      
 118 
     | 
    
         
            +
                    monster_attacks_player
         
     | 
| 
      
 119 
     | 
    
         
            +
                  end
         
     | 
| 
      
 120 
     | 
    
         
            +
                end
         
     | 
| 
      
 121 
     | 
    
         
            +
                
         
     | 
| 
      
 122 
     | 
    
         
            +
                private
         
     | 
| 
      
 123 
     | 
    
         
            +
                
         
     | 
| 
      
 124 
     | 
    
         
            +
                # NEUTRAL   
         
     | 
| 
      
 125 
     | 
    
         
            +
                def calculate_damage_to(entity)
         
     | 
| 
      
 126 
     | 
    
         
            +
                  miss = rand(0..(100 + entity.defense))
         
     | 
| 
      
 127 
     | 
    
         
            +
                  if (miss < 15)
         
     | 
| 
      
 128 
     | 
    
         
            +
                    0
         
     | 
| 
      
 129 
     | 
    
         
            +
                  else
         
     | 
| 
      
 130 
     | 
    
         
            +
                    if entity.eql?(monster)
         
     | 
| 
      
 131 
     | 
    
         
            +
                      if player.beast_mode
         
     | 
| 
      
 132 
     | 
    
         
            +
                        atk_range = BEAST_MODE_ATTACK..BEAST_MODE_ATTACK
         
     | 
| 
      
 133 
     | 
    
         
            +
                      else
         
     | 
| 
      
 134 
     | 
    
         
            +
                        atk_range = player.atk_lo..player.atk_hi
         
     | 
| 
      
 135 
     | 
    
         
            +
                      end
         
     | 
| 
      
 136 
     | 
    
         
            +
                      rand(atk_range)
         
     | 
| 
      
 137 
     | 
    
         
            +
                    else
         
     | 
| 
      
 138 
     | 
    
         
            +
                      rand(monster.atk_lo..monster.atk_hi)
         
     | 
| 
      
 139 
     | 
    
         
            +
                    end
         
     | 
| 
      
 140 
     | 
    
         
            +
                  end
         
     | 
| 
      
 141 
     | 
    
         
            +
                end
         
     | 
| 
      
 142 
     | 
    
         
            +
                
         
     | 
| 
      
 143 
     | 
    
         
            +
                def take_damage(entity, dmg)
         
     | 
| 
      
 144 
     | 
    
         
            +
                  entity.hp_cur = entity.hp_cur.to_i - dmg.to_i
         
     | 
| 
      
 145 
     | 
    
         
            +
                  who_gets_wounded = ''
         
     | 
| 
      
 146 
     | 
    
         
            +
                  
         
     | 
| 
      
 147 
     | 
    
         
            +
                  if entity.eql?(monster)
         
     | 
| 
      
 148 
     | 
    
         
            +
                    who_gets_wounded = "> You wound #{monster.name} for "
         
     | 
| 
      
 149 
     | 
    
         
            +
                  else
         
     | 
| 
      
 150 
     | 
    
         
            +
                    who_gets_wounded = "> You are wounded for "
         
     | 
| 
      
 151 
     | 
    
         
            +
                  end
         
     | 
| 
      
 152 
     | 
    
         
            +
                  
         
     | 
| 
      
 153 
     | 
    
         
            +
                  print who_gets_wounded
         
     | 
| 
      
 154 
     | 
    
         
            +
                  Animation::run({ :phrase => dmg.to_s, :speed => :slow, :oneline => true, :alpha => false, :random => false })
         
     | 
| 
      
 155 
     | 
    
         
            +
                  print " point(s)!\n"
         
     | 
| 
      
 156 
     | 
    
         
            +
                end
         
     | 
| 
      
 157 
     | 
    
         
            +
                
         
     | 
| 
      
 158 
     | 
    
         
            +
                # MONSTER
         
     | 
| 
      
 159 
     | 
    
         
            +
                def monster_strikes_first?
         
     | 
| 
      
 160 
     | 
    
         
            +
                  if (monster.dexterity > player.dexterity)
         
     | 
| 
      
 161 
     | 
    
         
            +
                    return true
         
     | 
| 
      
 162 
     | 
    
         
            +
                  else
         
     | 
| 
      
 163 
     | 
    
         
            +
                    dex_diff = player.dexterity - monster.dexterity
         
     | 
| 
      
 164 
     | 
    
         
            +
                    rand_dex = rand(0..dex_diff)
         
     | 
| 
      
 165 
     | 
    
         
            +
                    if rand_dex % 2 > 0
         
     | 
| 
      
 166 
     | 
    
         
            +
                      return true
         
     | 
| 
      
 167 
     | 
    
         
            +
                    else
         
     | 
| 
      
 168 
     | 
    
         
            +
                      return false
         
     | 
| 
      
 169 
     | 
    
         
            +
                    end
         
     | 
| 
      
 170 
     | 
    
         
            +
                  end
         
     | 
| 
      
 171 
     | 
    
         
            +
                end
         
     | 
| 
      
 172 
     | 
    
         
            +
                
         
     | 
| 
      
 173 
     | 
    
         
            +
                def monster_attacks_player
         
     | 
| 
      
 174 
     | 
    
         
            +
                  puts "#{monster.name} attacks you!"
         
     | 
| 
      
 175 
     | 
    
         
            +
                  dmg = calculate_damage_to(player)
         
     | 
| 
      
 176 
     | 
    
         
            +
                  if dmg > 0
         
     | 
| 
      
 177 
     | 
    
         
            +
                    take_damage(player, dmg)
         
     | 
| 
      
 178 
     | 
    
         
            +
                    if player_dead?
         
     | 
| 
      
 179 
     | 
    
         
            +
                      player_death
         
     | 
| 
      
 180 
     | 
    
         
            +
                    end
         
     | 
| 
      
 181 
     | 
    
         
            +
                  else
         
     | 
| 
      
 182 
     | 
    
         
            +
                    puts "#{monster.name} misses entirely!".colorize(:yellow)
         
     | 
| 
      
 183 
     | 
    
         
            +
                  end
         
     | 
| 
      
 184 
     | 
    
         
            +
                end
         
     | 
| 
      
 185 
     | 
    
         
            +
             
     | 
| 
      
 186 
     | 
    
         
            +
                def monster_near_death?
         
     | 
| 
      
 187 
     | 
    
         
            +
                  ((monster.hp_cur.to_f / monster.hp_max.to_f) < 0.10)
         
     | 
| 
      
 188 
     | 
    
         
            +
                end
         
     | 
| 
      
 189 
     | 
    
         
            +
                
         
     | 
| 
      
 190 
     | 
    
         
            +
                def monster_dead?
         
     | 
| 
      
 191 
     | 
    
         
            +
                  monster.hp_cur <= 0
         
     | 
| 
      
 192 
     | 
    
         
            +
                end
         
     | 
| 
      
 193 
     | 
    
         
            +
                
         
     | 
| 
      
 194 
     | 
    
         
            +
                def monster_death
         
     | 
| 
      
 195 
     | 
    
         
            +
                  puts "You have defeated #{monster.name}!\n".colorize(:green)
         
     | 
| 
      
 196 
     | 
    
         
            +
                  if monster.is_boss
         
     | 
| 
      
 197 
     | 
    
         
            +
                    if monster.name.eql?("Emerald")
         
     | 
| 
      
 198 
     | 
    
         
            +
                      puts monster.defeated_text
         
     | 
| 
      
 199 
     | 
    
         
            +
                      exit(0)
         
     | 
| 
      
 200 
     | 
    
         
            +
                    else
         
     | 
| 
      
 201 
     | 
    
         
            +
                      puts 'You just beat a boss monster. Way to go!'
         
     | 
| 
      
 202 
     | 
    
         
            +
                      puts " XP : #{monster.xp}".colorize(:green)
         
     | 
| 
      
 203 
     | 
    
         
            +
                      puts " ROX: #{monster.rox}".colorize(:green)
         
     | 
| 
      
 204 
     | 
    
         
            +
                      print_battle_line
         
     | 
| 
      
 205 
     | 
    
         
            +
                      update_player_stats
         
     | 
| 
      
 206 
     | 
    
         
            +
                      world.location_by_coords(player.cur_coords).remove_monster(monster.name)
         
     | 
| 
      
 207 
     | 
    
         
            +
                    end
         
     | 
| 
      
 208 
     | 
    
         
            +
                  else
         
     | 
| 
      
 209 
     | 
    
         
            +
                    puts 'You get the following spoils of war:'
         
     | 
| 
      
 210 
     | 
    
         
            +
                    puts " XP   : #{monster.xp}".colorize(:green)
         
     | 
| 
      
 211 
     | 
    
         
            +
                    puts " ROX  : #{monster.rox}".colorize(:green)
         
     | 
| 
      
 212 
     | 
    
         
            +
                    unless monster.inventory.nil?
         
     | 
| 
      
 213 
     | 
    
         
            +
                      puts " ITEMS: #{monster.inventory.list_contents}".colorize(:green) unless monster.inventory.items.empty?
         
     | 
| 
      
 214 
     | 
    
         
            +
                    end
         
     | 
| 
      
 215 
     | 
    
         
            +
                    print_battle_line
         
     | 
| 
      
 216 
     | 
    
         
            +
                    update_player_stats
         
     | 
| 
      
 217 
     | 
    
         
            +
                    world.location_by_coords(player.cur_coords).remove_monster(monster.name)
         
     | 
| 
      
 218 
     | 
    
         
            +
                  end
         
     | 
| 
      
 219 
     | 
    
         
            +
                end
         
     | 
| 
      
 220 
     | 
    
         
            +
                
         
     | 
| 
      
 221 
     | 
    
         
            +
                # PLAYER
         
     | 
| 
      
 222 
     | 
    
         
            +
                def update_player_stats
         
     | 
| 
      
 223 
     | 
    
         
            +
                  old_player_level = PlayerLevels::check_level(player.xp)
         
     | 
| 
      
 224 
     | 
    
         
            +
                  
         
     | 
| 
      
 225 
     | 
    
         
            +
                  player.xp = player.xp + monster.xp
         
     | 
| 
      
 226 
     | 
    
         
            +
                  player.rox = player.rox + monster.rox
         
     | 
| 
      
 227 
     | 
    
         
            +
                  
         
     | 
| 
      
 228 
     | 
    
         
            +
                  monster_items = monster.inventory.items
         
     | 
| 
      
 229 
     | 
    
         
            +
                  unless monster_items.nil?
         
     | 
| 
      
 230 
     | 
    
         
            +
                    player.inventory.items.concat monster_items unless monster_items.empty?
         
     | 
| 
      
 231 
     | 
    
         
            +
                  end
         
     | 
| 
      
 232 
     | 
    
         
            +
                  
         
     | 
| 
      
 233 
     | 
    
         
            +
                  new_player_level = PlayerLevels::check_level(player.xp)
         
     | 
| 
      
 234 
     | 
    
         
            +
                  
         
     | 
| 
      
 235 
     | 
    
         
            +
                  if new_player_level > old_player_level
         
     | 
| 
      
 236 
     | 
    
         
            +
                    Animation::run({:phrase => '** LEVEL UP! **'})
         
     | 
| 
      
 237 
     | 
    
         
            +
                    new_stats = PlayerLevels::get_level_stats(new_player_level)
         
     | 
| 
      
 238 
     | 
    
         
            +
                    
         
     | 
| 
      
 239 
     | 
    
         
            +
                    player.level = new_stats[:level]
         
     | 
| 
      
 240 
     | 
    
         
            +
                    puts "You are now level #{player.level}!"
         
     | 
| 
      
 241 
     | 
    
         
            +
                    player.hp_cur = new_stats[:hp_max]
         
     | 
| 
      
 242 
     | 
    
         
            +
                    player.hp_max = new_stats[:hp_max]
         
     | 
| 
      
 243 
     | 
    
         
            +
                    puts "You now have #{player.hp_max} hit points!"
         
     | 
| 
      
 244 
     | 
    
         
            +
                    player.stam_cur = new_stats[:stam_max]
         
     | 
| 
      
 245 
     | 
    
         
            +
                    player.stam_max = new_stats[:stam_max]
         
     | 
| 
      
 246 
     | 
    
         
            +
                    puts "You now have #{player.stam_max} stamina points!"
         
     | 
| 
      
 247 
     | 
    
         
            +
                    player.atk_lo = new_stats[:atk_lo]
         
     | 
| 
      
 248 
     | 
    
         
            +
                    player.atk_hi = new_stats[:atk_hi]
         
     | 
| 
      
 249 
     | 
    
         
            +
                    puts "You now have an attack of #{player.atk_lo}-#{player.atk_hi}!"
         
     | 
| 
      
 250 
     | 
    
         
            +
                    player.defense = new_stats[:defense]
         
     | 
| 
      
 251 
     | 
    
         
            +
                    puts "You now have #{player.defense} defensive points!"
         
     | 
| 
      
 252 
     | 
    
         
            +
                    player.dexterity = new_stats[:dexterity]
         
     | 
| 
      
 253 
     | 
    
         
            +
                    puts "You now have #{player.dexterity} dexterity points!"
         
     | 
| 
      
 254 
     | 
    
         
            +
                  end
         
     | 
| 
      
 255 
     | 
    
         
            +
                end
         
     | 
| 
      
 256 
     | 
    
         
            +
                
         
     | 
| 
      
 257 
     | 
    
         
            +
                def player_near_death?
         
     | 
| 
      
 258 
     | 
    
         
            +
                  ((player.hp_cur.to_f / player.hp_max.to_f) < 0.10 && !player.god_mode)
         
     | 
| 
      
 259 
     | 
    
         
            +
                end
         
     | 
| 
      
 260 
     | 
    
         
            +
                
         
     | 
| 
      
 261 
     | 
    
         
            +
                def player_dead?
         
     | 
| 
      
 262 
     | 
    
         
            +
                  (player.hp_cur <= 0 && !player.god_mode)
         
     | 
| 
      
 263 
     | 
    
         
            +
                end
         
     | 
| 
      
 264 
     | 
    
         
            +
                
         
     | 
| 
      
 265 
     | 
    
         
            +
                def player_death
         
     | 
| 
      
 266 
     | 
    
         
            +
                  puts "You are dead, slain by the #{monster.name}!".colorize(:red)
         
     | 
| 
      
 267 
     | 
    
         
            +
                  puts 'Your adventure ends here. Try again next time!'.colorize(:red)
         
     | 
| 
      
 268 
     | 
    
         
            +
                  print_battle_line
         
     | 
| 
      
 269 
     | 
    
         
            +
                  exit(0)
         
     | 
| 
      
 270 
     | 
    
         
            +
                end
         
     | 
| 
      
 271 
     | 
    
         
            +
                
         
     | 
| 
      
 272 
     | 
    
         
            +
                def player_escape?
         
     | 
| 
      
 273 
     | 
    
         
            +
                  if (player.dexterity > monster.dexterity)
         
     | 
| 
      
 274 
     | 
    
         
            +
                    return true
         
     | 
| 
      
 275 
     | 
    
         
            +
                  else
         
     | 
| 
      
 276 
     | 
    
         
            +
                    dex_diff = monster.dexterity - player.dexterity
         
     | 
| 
      
 277 
     | 
    
         
            +
                    rand_dex = rand(0..dex_diff)
         
     | 
| 
      
 278 
     | 
    
         
            +
                    if rand_dex % 2 > 0
         
     | 
| 
      
 279 
     | 
    
         
            +
                      return true
         
     | 
| 
      
 280 
     | 
    
         
            +
                    else
         
     | 
| 
      
 281 
     | 
    
         
            +
                      return false
         
     | 
| 
      
 282 
     | 
    
         
            +
                    end
         
     | 
| 
      
 283 
     | 
    
         
            +
                  end
         
     | 
| 
      
 284 
     | 
    
         
            +
                end
         
     | 
| 
      
 285 
     | 
    
         
            +
                
         
     | 
| 
      
 286 
     | 
    
         
            +
                # STATUS TEXT
         
     | 
| 
      
 287 
     | 
    
         
            +
                
         
     | 
| 
      
 288 
     | 
    
         
            +
                def print_escape_text
         
     | 
| 
      
 289 
     | 
    
         
            +
                  Animation::run({ :phrase => "** POOF **", :oneline => true })
         
     | 
| 
      
 290 
     | 
    
         
            +
                end
         
     | 
| 
      
 291 
     | 
    
         
            +
                
         
     | 
| 
      
 292 
     | 
    
         
            +
                def print_battle_line
         
     | 
| 
      
 293 
     | 
    
         
            +
                  puts '******************************'
         
     | 
| 
      
 294 
     | 
    
         
            +
                end
         
     | 
| 
      
 295 
     | 
    
         
            +
              end
         
     | 
| 
      
 296 
     | 
    
         
            +
            end
         
     |