class Object
Public Instance Methods
calc()
click to toggle source
# File lib/CoC-Calc.rb, line 209 def calc if ARGV[1].is_a? String if ARGV[1].downcase == 'help' puts 'Calc the training time and cost of your troops run "CoC-Calc.rb calc [amount of barbarians] [amount of archers] [amount of goblins] [amount of giants] [amount of wallbreakers] [amount of ballons] [amount of wizards] [amount of healers] [amount of dragons] [amount of pekkas]"' elsif File.file? "/CoC-Calc-Saves/lvl.txt" totalCost = 0 totalTime = 0 get_troop_cost if $troopLvlErr else totalCost += ARGV[1].to_i * $cost_barbarians totalCost += ARGV[2].to_i * $cost_archers totalCost += ARGV[3].to_i * $cost_goblins totalCost += ARGV[4].to_i * $cost_giants totalCost += ARGV[5].to_i * $cost_wallbreakers totalCost += ARGV[6].to_i * $cost_ballons totalCost += ARGV[7].to_i * $cost_wizards totalCost += ARGV[8].to_i * $cost_healers totalCost += ARGV[9].to_i * $cost_dragons totalCost += ARGV[10].to_i * $cost_pekkas totalTime += ARGV[1].to_i * 20 totalTime += ARGV[2].to_i * 25 totalTime += ARGV[3].to_i * 30 totalTime += ARGV[4].to_i * 120 totalTime += ARGV[5].to_i * 120 totalTime += ARGV[6].to_i * 380 totalTime += ARGV[7].to_i * 380 totalTime += ARGV[8].to_i * 900 totalTime += ARGV[9].to_i * 1800 totalTime += ARGV[10].to_i * 2700 puts "Your Troops will cost #{totalCost} elixir." puts "Your total training time is #{totalTime}s." end else puts "You need to enter the levels of your troops by running 'CoC-Calc set_troop_lvl' if you need futher help run 'CoC-Calc set_troop_lvl help'!" end else puts "You need to supply an argument (run 'CoC-Calc calc help' for help)" end end
get_troop_cost()
click to toggle source
# File lib/CoC-Calc.rb, line 49 def get_troop_cost #Barbs if $lvls[0].to_i == 1 $cost_barbarians = 25 elsif $lvls[0].to_i == 2 $cost_barbarians = 40 elsif $lvls[0].to_i == 3 $cost_barbarians = 60 elsif $lvls[0].to_i == 4 $cost_barbarians = 80 elsif $lvls[0].to_i == 5 $cost_barbarians = 100 elsif $lvls[0].to_i == 6 $cost_barbarians = 150 else puts "Your barbarian lvl is invalid" $troopLvlErr = true end #Archers if $lvls[1].to_i == 1 $cost_archers = 50 elsif $lvls[1].to_i == 2 $cost_archers = 80 elsif $lvls[1].to_i == 3 $cost_archers = 120 elsif $lvls[1].to_i == 4 $cost_archers = 160 elsif $lvls[1].to_i == 5 $cost_archers = 200 elsif $lvls[1].to_i == 6 $cost_archers = 300 else puts "Your archer lvl (#{$lvls[1]}) is invalid" $troopLvlErr = true end #gobs if $lvls[2].to_i == 1 $cost_goblins = 25 elsif $lvls[2].to_i == 2 $cost_goblins = 40 elsif $lvls[2].to_i == 3 $cost_goblins = 60 elsif $lvls[2].to_i == 4 $cost_goblins = 80 elsif $lvls[2].to_i == 5 $cost_goblins = 100 elsif $lvls[2].to_i == 6 $cost_goblins = 150 else puts "Your goblin lvl is invalid" $troopLvlErr = true end #giants if $lvls[3].to_i == 1 or $lvls[3].to_i == 2 or $lvls[3].to_i == 3 or $lvls[3].to_i == 4 or $lvls[3].to_i == 5 or $lvls[3].to_i == 6 $cost_wizards = $lvls[3].to_i * 500 else puts "Your giant lvl is invalid" $troopLvlErr = true end #wallies if $lvls[4].to_i == 1 $cost_wallbreakers = 1000 elsif $lvls[4].to_i == 2 $cost_wallbreakers = 1500 elsif $lvls[4].to_i == 3 $cost_wallbreakers = 2000 elsif $lvls[4].to_i == 4 $cost_wallbreakers = 2500 elsif $lvls[4].to_i == 5 $cost_wallbreakers = 3000 elsif $lvls[4].to_i == 6 $cost_wallbreakers = 3500 else puts "Your wallbreaker lvl is invalid" $troopLvlErr = true end #ballons if $lvls[5].to_i == 1 or $lvls[5].to_i == 2 or $lvls[5].to_i == 3 or $lvls[5].to_i == 4 or $lvls[5].to_i == 5 or $lvls[5].to_i == 6 $cost_wizards = 1500 + $lvls[5].to_i * 500 else puts "Your ballon lvl is invalid" $troopLvlErr = true end #wizards if $lvls[6].to_i == 1 or $lvls[6].to_i == 2 or $lvls[6].to_i == 3 or $lvls[6].to_i == 4 or $lvls[6].to_i == 5 or $lvls[6].to_i == 6 $cost_wizards = 1000 + $lvls[6].to_i * 500 else puts "Your wizard lvl is invalid" $troopLvlErr = true end #healers if $lvls[7].to_i == 1 $cost_healers = 5000 elsif $lvls[7].to_i == 2 $cost_healers = 6000 elsif $lvls[7].to_i == 3 $cost_healers = 8000 elsif $lvls[7].to_i == 4 $cost_healers = 10000 else puts "Your healer lvl is invalid" $troopLvlErr = true end #dragons if $lvls[8].to_i == 1 $cost_dragons = 25000 elsif $lvls[8].to_i == 2 $cost_dragons = 30000 elsif $lvls[8].to_i == 3 $cost_dragons = 36000 elsif $lvls[8].to_i == 4 $cost_dragons = 42000 else puts "Your dragon lvl is invalid" $troopLvlErr = true end #pekkas if $lvls[9].to_i == 1 $cost_pekkas = 30000 elsif $lvls[9].to_i == 2 $cost_pekkas = 35000 elsif $lvls[9].to_i == 3 $cost_pekkas = 42000 elsif $lvls[9].to_i == 4 $cost_pekkas = 45000 elsif $lvls[9].to_i == 5 $cost_pekkas = 50000 else puts "Your pekka lvl is invalid" $troopLvlErr = true end end
init()
click to toggle source
# File lib/CoC-Calc.rb, line 5 def init if Dir.exists? "/CoC-Calc-Saves" else Dir.mkdir "/CoC-Calc-Saves" end if File.file? "/CoC-Calc-Saves/lvl.txt" $lvlSaveContent = File.read("/CoC-Calc-Saves/lvl.txt") else $lvlSaveFile = File.new("/CoC-Calc-Saves/lvl.txt", "w") $lvlSaveContent = "" end $lvls = $lvlSaveContent.split('||') $lvls.each do |i| i = i.to_i end end
initPuts()
click to toggle source
# File lib/CoC-Calc.rb, line 23 def initPuts if Dir.exists? "/CoC-Calc-Saves" else Dir.mkdir "/CoC-Calc-Saves" end if File.file? "/CoC-Calc-Saves/lvl.txt" $lvlSaveContent = File.read("/CoC-Calc-Saves/lvl.txt") else $lvlSaveFile = File.new("/CoC-Calc-Saves/lvl.txt", "w") puts "You need to enter the levels of your troops by running 'CoC-Calc set_troop_lvl' if you need futher help run 'CoC-Calc set_troop_lvl help'!" $lvlSaveContent = "" end if $lvlSaveContent == "" puts "You need to enter the levels of your troops by running 'CoC-Calc set_troop_lvl' if you need futher help run 'CoC-Calc set_troop_lvl help'!" else puts "Tests were successful!" end $lvls = $lvlSaveContent.split('||') $lvls.each do |i| i = i.to_i end end
set_troop_lvl()
click to toggle source
# File lib/CoC-Calc.rb, line 195 def set_troop_lvl if ARGV[1].is_a? String if ARGV[1].downcase == 'help' puts "To save the lvl of your troop enter 'CoC-Calc set_troop_lvl [lvl of barbarians] [lvl of archers] [lvl of goblins] [lvl of giants] [lvl of wallbreakers] [lvl of ballons] [lvl of wizards] [lvl of healers] [lvl of dragons] [lvl of pekkas]'" else $lvls = [ARGV[1], ARGV[2], ARGV[3], ARGV[4], ARGV[5],ARGV[6], ARGV[7], ARGV[8], ARGV[9], ARGV[10]] $lvlSaveFile = File.new("/CoC-Calc-Saves/lvl.txt", "w") $lvlSaveFile.puts $lvls.join('||') end else puts "Run 'CoC-Calc set_troop_lvl help' for help on this command." end end
stand()
click to toggle source
# File lib/CoC-Calc.rb, line 1 def stand puts "CoC-Calc up and running, Sir! Version: 1.2.5" end