class Scene_Battle
 def start_phase5
  @phase = 5
  $game_system.me_play($game_system.battle_end_me)
  $game_system.bgm_play($game_temp.map_bgm)
  exp = 0
  gold = 0
  treasures = []
  for enemy in $game_troop.enemies
   unless enemy.hidden
    exp += enemy.exp
    gold += enemy.gold
    if rand(100) < enemy.treasure_prob
     if enemy.item_id > 0
      treasures.push($data_items[enemy.item_id])
     end
     if enemy.weapon_id > 0
      treasures.push($data_weapons[enemy.weapon_id])
     end
     if enemy.armor_id > 0
      treasures.push($data_armors[enemy.armor_id])
     end
    end
   end
  end
  treasures = treasures[0..5]
  actor_size = 0
  for actor in $game_party.actors
   actor_size += 1 unless actor.dead?
  end
  exp /= [actor_size, 1].max
  for i in 0...$game_party.actors.size
   actor = $game_party.actors[i]
   if actor.cant_get_exp? == false
    last_level = actor.level
    actor.exp += exp
    if actor.level > last_level
     @status_window.level_up(i)
    end
   end
  end
  $game_party.gain_gold(gold)
  for item in treasures
   case item
   when RPG::Item
    $game_party.gain_item(item.id, 1)
   when RPG::Weapon
    $game_party.gain_weapon(item.id, 1)
   when RPG::Armor
    $game_party.gain_armor(item.id, 1)
   end
  end
  @result_window = Window_BattleResult.new(exp, gold, treasures)
  @phase5_wait_count = 100
 end
end