#!/usr/bin/env ruby # Program named: wfcalc # Create by Kim "Hagbarddenstore" Johansson # 2008-02-09 # Licensed under BSD license. # Do whatever you want with this program. # Check if we have valid amount of arguments. if ARGV.size < 3 puts "wfcalc {type} {grade} {amount}" exit 1 end # The five types we can calculate and their grades. TYPES = { "Iron"=>["Raw","Depleted","Normal","Pure","Refined",], "Silicon"=>["Raw","Depleted","Pure","Good","Refined"], "Iridium"=>["Raw","Depleted","Pure","Good","Refined"], "Titanium"=>["Raw","Depleted","Pure","Good","Refined"], "Stethan"=>["Pure"] } # The objects with the data we want. type = ARGV[0].capitalize grade = ARGV[1].capitalize amount = ARGV[2].to_i # Check if we have greater amount than 0. if false == ( amount > 0 ) puts "Amount must be greater than 0." exit 1 end # Check if we have a valid type. if TYPES.include?(type) == false puts "Valid types are: #{TYPES.keys.join(' ')}" exit 1 end # Check if we have a valid grade. if TYPES[type].include?(grade) == false puts "Valid grades for #{type} are: #{TYPES[type].join(' ')}" exit 1 end # If Stethan, we only have one option. if type == "Stethan" puts "To create #{amount}x Stethan you need:" puts "#{amount}x Iron (Depleted)" puts "#{amount}x Silicon (Depleted)" puts "#{amount}x Iridium (Depleted)" puts "#{amount}x Titanium (Depleted)" end # Loop through each grade and print out # how many you need of each type # to get to the top type that you want. i = 0 TYPES[type].each do |g| if g == grade i.times { amount *= 10 } i.times do |j| str = "You need #{amount}x #{type} (#{TYPES[type][j]})" str += " to create #{amount/=10}x #{type} (#{TYPES[type][j+1]})" puts str end break else i += 1 end end