Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#calcObject



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/CoC-Calc.rb', line 233

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_costObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/CoC-Calc.rb', line 45

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
    $cost_giants = 500
  elsif $lvls[3].to_i == 2
    $cost_giants = 1000
  elsif $lvls[3].to_i == 3
    $cost_giants = 1500
  elsif $lvls[3].to_i == 4
    $cost_giants = 2000
  elsif $lvls[3].to_i == 5
    $cost_giants = 2500
  elsif $lvls[3].to_i == 6
    $cost_giants = 3000
  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
    $cost_ballons = 2000
  elsif $lvls[5].to_i == 2
    $cost_ballons = 2500
  elsif $lvls[5].to_i == 3
    $cost_ballons = 3000
  elsif $lvls[5].to_i == 4
    $cost_ballons = 3500
  elsif $lvls[5].to_i == 5
    $cost_ballons = 4000
  elsif $lvls[5].to_i == 6
    $cost_ballons = 4500
  else
    puts "Your ballon lvl is invalid"
    $troopLvlErr = true
  end

  #wizards
  if $lvls[6].to_i == 1
    $cost_wizards = 1500
  elsif $lvls[6].to_i == 2
    $cost_wizards = 2000
  elsif $lvls[6].to_i == 3
    $cost_wizards = 2500
  elsif $lvls[6].to_i == 4
    $cost_wizards = 3000
  elsif $lvls[6].to_i == 5
    $cost_wizards = 3500
  elsif $lvls[6].to_i == 6
    $cost_wizards = 4000
  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

#initObject



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/CoC-Calc.rb', line 1

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

#initPutsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/CoC-Calc.rb', line 19

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_lvlObject



219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/CoC-Calc.rb', line 219

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