Class: EtwMath
- Inherits:
-
Object
- Object
- EtwMath
- Defined in:
- lib/etw_math.rb
Overview
This class contains various methods that perform Eat the World calculations
Constant Summary collapse
- VERSION =
EtwMath version
"1.0.1"- SECONDS_PER_DAY =
Number of seconds in 1 day
86400- SECONDS_PER_HOUR =
Number of seconds in 1 hour
3600- SECONDS_PER_MINUTE =
Number of seconds in 1 minute
60
Class Method Summary collapse
-
.big_bite_amount(current_size, multi) ⇒ String, Boolean
Calculates big bite amount.
-
.big_bite_delta_multi(starting_size, ending_size) ⇒ String, Boolean
Calculates multiplier using a starting size and an ending size resulting from a big bite.
-
.big_first_bite_multi(bite_amount) ⇒ String, Boolean
Calculates multiplier using the first big bite amount.
-
.brown_crate_max(size) ⇒ String, Boolean
Calculates the maximum monetary reward from a brown crate.
-
.eat_level_cost(eat_level) ⇒ String, Boolean
Calculates cost of an eat speed level.
-
.eat_range_cost(starting_level, ending_level) ⇒ String, Boolean
Calculates eat speed cost using a range from a starting level to an ending level.
-
.format_number(number, use_decimal = false) ⇒ String
Makes numbers more readable to humans by adding commas.
-
.format_time(total_seconds) ⇒ String
Converts seconds to be displayed as hours, minutes, and seconds.
-
.input_valid?(*inputs) ⇒ Boolean
Validates numeric input.
-
.jackpot_amount(size) ⇒ String, Boolean
Calculates the jackpot reward from a daily spin.
-
.level_at_size(size) ⇒ String, Boolean
Calculates size level.
-
.medium_bite_amount(current_size, multi) ⇒ String, Boolean
Calculates medium bite amount.
-
.medium_bite_delta_multi(starting_size, ending_size) ⇒ String, Boolean
Calculates multiplier using a starting size and an ending size resulting from a medium bite.
-
.medium_first_bite_multi(bite_amount) ⇒ String, Boolean
Calculates multiplier using the first medium bite amount.
-
.multi_level_cost(multi_level) ⇒ String, Boolean
Calculates cost of a multiplier level.
-
.multi_range_cost(starting_level, ending_level) ⇒ String, Boolean
Calculates multiplier cost using a range from a starting level to an ending level.
-
.optimal_multi(size_level, ratio) ⇒ String, Boolean
Calculates optimal multiplier.
-
.optimal_size_level_threshold(multi, ratio) ⇒ String, Boolean
Calculates optimal size level threshold.
-
.print_decimal(value) ⇒ String
Displays float values with extraneous decimal positions omitted.
-
.purple_crate_max(size) ⇒ String, Boolean
Calculates the maximum monetary reward from a purple crate.
-
.size_at_level(level) ⇒ String, Boolean
Calculates maximum size.
-
.size_level_cost(size_level) ⇒ String, Boolean
Calculates cost of a size level.
-
.size_range_cost(starting_level, ending_level) ⇒ String, Boolean
Calculates size cost using a range from a starting level to an ending level.
-
.small_bite_amount(current_size, multi) ⇒ String, Boolean
Calculates small bite amount.
-
.small_bite_delta_multi(starting_size, ending_size) ⇒ String, Boolean
Calculates multiplier using a starting size and an ending size resulting from a small bite.
-
.small_first_bite_multi(bite_amount) ⇒ String, Boolean
Calculates multiplier using the first small bite amount.
-
.time_to_max(size_level, multi) ⇒ String, Boolean
Calculates time to reach maximum size in minutes for maximum size levels >141.
-
.time_to_max_small(size_level, multi) ⇒ String, Boolean
Calculates time to reach maximum size in minutes for maximum size levels <=141.
-
.total_eat_investment(eat_level) ⇒ String, Boolean
Calculates total cost of eat speed upgrades.
-
.total_multi_investment(multi_level) ⇒ String, Boolean
Calculates total cost of multiplier upgrades.
-
.total_size_investment(size_level) ⇒ String, Boolean
Calculates total cost of size upgrades.
-
.total_upgrade_investment(size_level, walk_speed_level, multi, eat_speed_level) ⇒ String, Boolean
Calculates total cost of all upgrades.
-
.total_walk_investment(walk_level) ⇒ String, Boolean
Calculates total cost of walk speed upgrades.
-
.walk_level_cost(walk_level) ⇒ String, Boolean
Calculates cost of a walk speed level.
-
.walk_range_cost(starting_level, ending_level) ⇒ String, Boolean
Calculates walk speed cost using a range from a starting level to an ending level.
-
.walk_speed_level(walk_speed_value) ⇒ String, Boolean
Calculates walk speed level.
-
.walk_speed_value(walk_speed_level) ⇒ String, Boolean
Calculates walk speed value.
-
.yellow_crate_max(size) ⇒ String, Boolean
Calculates the maximum monetary reward from a yellow crate.
Class Method Details
.big_bite_amount(current_size, multi) ⇒ String, Boolean
Calculates big bite amount
391 392 393 394 395 396 397 398 |
# File 'lib/etw_math.rb', line 391 def self.big_bite_amount(current_size, multi) return false if !input_valid?(current_size, multi) begin format_number(((50 * (((-50 + Math.sqrt(2500 + 200 * current_size)) / 100) + 0.04 * multi) ** 2 + 50 * (((-50 + Math.sqrt(2500 + 200 * current_size)) / 100) + 0.04 * multi)) - current_size).round) rescue # division by zero return false end end |
.big_bite_delta_multi(starting_size, ending_size) ⇒ String, Boolean
Calculates multiplier using a starting size and an ending size resulting from a big bite
436 437 438 439 440 441 442 443 |
# File 'lib/etw_math.rb', line 436 def self.big_bite_delta_multi(starting_size, ending_size) return false if !input_valid?(starting_size, ending_size) || starting_size > ending_size begin format_number(((((-50 + Math.sqrt(2500 + 200 * ending_size)) / 100) - ((-50 + Math.sqrt(2500 + 200 * starting_size)) / 100)) / 0.04).round) rescue # division by zero return false end end |
.big_first_bite_multi(bite_amount) ⇒ String, Boolean
Calculates multiplier using the first big bite amount
478 479 480 481 482 483 484 485 |
# File 'lib/etw_math.rb', line 478 def self.big_first_bite_multi(bite_amount) return false if !input_valid?(bite_amount) begin format_number((((-50 + Math.sqrt(2500 + 200 * bite_amount)) / 100) / 0.04).round) rescue # division by zero return false end end |
.brown_crate_max(size) ⇒ String, Boolean
Calculates the maximum monetary reward from a brown crate
108 109 110 111 |
# File 'lib/etw_math.rb', line 108 def self.brown_crate_max(size) return false if !input_valid?(size) format_number(size * 1) end |
.eat_level_cost(eat_level) ⇒ String, Boolean
Calculates cost of an eat speed level
252 253 254 255 |
# File 'lib/etw_math.rb', line 252 def self.eat_level_cost(eat_level) return false if !input_valid?(eat_level) format_number(10000 * eat_level ** 3) end |
.eat_range_cost(starting_level, ending_level) ⇒ String, Boolean
Calculates eat speed cost using a range from a starting level to an ending level
350 351 352 353 |
# File 'lib/etw_math.rb', line 350 def self.eat_range_cost(starting_level, ending_level) return false if !input_valid?(starting_level, ending_level) || starting_level > ending_level format_number(5000 * (0.5 * ending_level ** 4 + ending_level ** 3 + 0.5 * ending_level ** 2) - 5000 * (0.5 * starting_level ** 4 + starting_level ** 3 + 0.5 * starting_level ** 2)) end |
.format_number(number, use_decimal = false) ⇒ String
Makes numbers more readable to humans by adding commas
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/etw_math.rb', line 50 def self.format_number(number, use_decimal = false) whole, decimal = number.to_s.split(".") num_groups = whole.chars.to_a.reverse.each_slice(3) whole_with_commas = num_groups.map(&:join).join(',').reverse if use_decimal [whole_with_commas, decimal].compact.join(".") else return whole_with_commas end end |
.format_time(total_seconds) ⇒ String
Converts seconds to be displayed as hours, minutes, and seconds
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/etw_math.rb', line 67 def self.format_time(total_seconds) days = total_seconds / SECONDS_PER_DAY hours = (total_seconds % SECONDS_PER_DAY) / SECONDS_PER_HOUR minutes = (total_seconds % SECONDS_PER_HOUR) / SECONDS_PER_MINUTE seconds = total_seconds % SECONDS_PER_MINUTE if days > 999 format("%sd:%02dh:%02dm:%02ds", format_number(days), hours, minutes, seconds) else format("%02dd:%02dh:%02dm:%02ds", days, hours, minutes, seconds) end end |
.input_valid?(*inputs) ⇒ Boolean
Validates numeric input
94 95 96 97 98 99 100 101 |
# File 'lib/etw_math.rb', line 94 def self.input_valid?(*inputs) return false if inputs.empty? inputs.each do |input| return false if !input.is_a?(Numeric) return false if input <= 0 end return true end |
.jackpot_amount(size) ⇒ String, Boolean
Calculates the jackpot reward from a daily spin
138 139 140 141 |
# File 'lib/etw_math.rb', line 138 def self.jackpot_amount(size) return false if !input_valid?(size) format_number(size * 5) end |
.level_at_size(size) ⇒ String, Boolean
Calculates size level
182 183 184 185 186 187 188 189 |
# File 'lib/etw_math.rb', line 182 def self.level_at_size(size) return false if !input_valid?(size) begin format_number((-50 + Math.sqrt(2500 + 200 * size)) / 100) rescue # division by zero return false end end |
.medium_bite_amount(current_size, multi) ⇒ String, Boolean
Calculates medium bite amount
376 377 378 379 380 381 382 383 |
# File 'lib/etw_math.rb', line 376 def self.medium_bite_amount(current_size, multi) return false if !input_valid?(current_size, multi) begin format_number(((50 * (((-50 + Math.sqrt(2500 + 200 * current_size)) / 100) + 0.03 * multi) ** 2 + 50 * (((-50 + Math.sqrt(2500 + 200 * current_size)) / 100) + 0.03 * multi)) - current_size).round) rescue # division by zero return false end end |
.medium_bite_delta_multi(starting_size, ending_size) ⇒ String, Boolean
Calculates multiplier using a starting size and an ending size resulting from a medium bite
421 422 423 424 425 426 427 428 |
# File 'lib/etw_math.rb', line 421 def self.medium_bite_delta_multi(starting_size, ending_size) return false if !input_valid?(starting_size, ending_size) || starting_size > ending_size begin format_number(((((-50 + Math.sqrt(2500 + 200 * ending_size)) / 100) - ((-50 + Math.sqrt(2500 + 200 * starting_size)) / 100)) / 0.03).round) rescue # division by zero return false end end |
.medium_first_bite_multi(bite_amount) ⇒ String, Boolean
Calculates multiplier using the first medium bite amount
464 465 466 467 468 469 470 471 |
# File 'lib/etw_math.rb', line 464 def self.medium_first_bite_multi(bite_amount) return false if !input_valid?(bite_amount) begin format_number((((-50 + Math.sqrt(2500 + 200 * bite_amount)) / 100) / 0.03).round) rescue # division by zero return false end end |
.multi_level_cost(multi_level) ⇒ String, Boolean
Calculates cost of a multiplier level
242 243 244 245 |
# File 'lib/etw_math.rb', line 242 def self.multi_level_cost(multi_level) return false if !input_valid?(multi_level) format_number(5000 * multi_level ** 3) end |
.multi_range_cost(starting_level, ending_level) ⇒ String, Boolean
Calculates multiplier cost using a range from a starting level to an ending level
339 340 341 342 |
# File 'lib/etw_math.rb', line 339 def self.multi_range_cost(starting_level, ending_level) return false if !input_valid?(starting_level, ending_level) || starting_level > ending_level format_number(2500 * (0.5 * ending_level ** 4 + ending_level ** 3 + 0.5 * ending_level ** 2) - 2500 * (0.5 * starting_level ** 4 + starting_level ** 3 + 0.5 * starting_level ** 2)) end |
.optimal_multi(size_level, ratio) ⇒ String, Boolean
Calculates optimal multiplier
208 209 210 211 212 213 214 215 |
# File 'lib/etw_math.rb', line 208 def self.optimal_multi(size_level, ratio) return false if !input_valid?(size_level, ratio) begin format_number(size_level / ratio) rescue # division by zero return false end end |
.optimal_size_level_threshold(multi, ratio) ⇒ String, Boolean
Calculates optimal size level threshold
197 198 199 200 |
# File 'lib/etw_math.rb', line 197 def self.optimal_size_level_threshold(multi, ratio) return false if !input_valid?(multi, ratio) format_number(multi * ratio) end |
.print_decimal(value) ⇒ String
Displays float values with extraneous decimal positions omitted
84 85 86 |
# File 'lib/etw_math.rb', line 84 def self.print_decimal(value) printf('%0.2f', value) end |
.purple_crate_max(size) ⇒ String, Boolean
Calculates the maximum monetary reward from a purple crate
128 129 130 131 |
# File 'lib/etw_math.rb', line 128 def self.purple_crate_max(size) return false if !input_valid?(size) format_number(size * 3) end |
.size_at_level(level) ⇒ String, Boolean
Calculates maximum size
172 173 174 175 |
# File 'lib/etw_math.rb', line 172 def self.size_at_level(level) return false if !input_valid?(level) format_number(50 * level ** 2 + 50 * level) end |
.size_level_cost(size_level) ⇒ String, Boolean
Calculates cost of a size level
222 223 224 225 |
# File 'lib/etw_math.rb', line 222 def self.size_level_cost(size_level) return false if !input_valid?(size_level) format_number(10 * size_level ** 3) end |
.size_range_cost(starting_level, ending_level) ⇒ String, Boolean
Calculates size cost using a range from a starting level to an ending level
317 318 319 320 |
# File 'lib/etw_math.rb', line 317 def self.size_range_cost(starting_level, ending_level) return false if !input_valid?(starting_level, ending_level) || starting_level > ending_level format_number(5 * (0.5 * ending_level ** 4 + ending_level ** 3 + 0.5 * ending_level ** 2) - 5 * (0.5 * starting_level ** 4 + starting_level ** 3 + 0.5 * starting_level ** 2)) end |
.small_bite_amount(current_size, multi) ⇒ String, Boolean
Calculates small bite amount
361 362 363 364 365 366 367 368 |
# File 'lib/etw_math.rb', line 361 def self.small_bite_amount(current_size, multi) return false if !input_valid?(current_size, multi) begin format_number(((50 * (((-50 + Math.sqrt(2500 + 200 * current_size)) / 100) + 0.02 * multi) ** 2 + 50 * (((-50 + Math.sqrt(2500 + 200 * current_size)) / 100) + 0.02 * multi)) - current_size).round) rescue # division by zero return false end end |
.small_bite_delta_multi(starting_size, ending_size) ⇒ String, Boolean
Calculates multiplier using a starting size and an ending size resulting from a small bite
406 407 408 409 410 411 412 413 |
# File 'lib/etw_math.rb', line 406 def self.small_bite_delta_multi(starting_size, ending_size) return false if !input_valid?(starting_size, ending_size) || starting_size > ending_size begin format_number(((((-50 + Math.sqrt(2500 + 200 * ending_size)) / 100) - ((-50 + Math.sqrt(2500 + 200 * starting_size)) / 100)) / 0.02).round) rescue # division by zero return false end end |
.small_first_bite_multi(bite_amount) ⇒ String, Boolean
Calculates multiplier using the first small bite amount
450 451 452 453 454 455 456 457 |
# File 'lib/etw_math.rb', line 450 def self.small_first_bite_multi(bite_amount) return false if !input_valid?(bite_amount) begin format_number((((-50 + Math.sqrt(2500 + 200 * bite_amount)) / 100) / 0.02).round) rescue # division by zero return false end end |
.time_to_max(size_level, multi) ⇒ String, Boolean
Calculates time to reach maximum size in minutes for maximum size levels >141
493 494 495 496 497 498 499 500 |
# File 'lib/etw_math.rb', line 493 def self.time_to_max(size_level, multi) return false if !input_valid?(size_level, multi) begin format_time((((size_level.to_f / (multi.to_f * 0.03 * 3) * (141.0 / size_level.to_f)) * 3.3 + (size_level.to_f / (multi.to_f * 0.03 * 3.0) * (1 - 141.0 / size_level.to_f)) * 5.1)).round(2)) rescue # division by zero return false end end |
.time_to_max_small(size_level, multi) ⇒ String, Boolean
Calculates time to reach maximum size in minutes for maximum size levels <=141
508 509 510 511 512 513 514 515 |
# File 'lib/etw_math.rb', line 508 def self.time_to_max_small(size_level, multi) return false if !input_valid?(size_level, multi) begin format_time(((size_level.to_f / multi.to_f / (0.03 * 3) * 3.3 * (0.5 + size_level.to_f / (141 * 2)))).round(2)) rescue # division by zero return false end end |
.total_eat_investment(eat_level) ⇒ String, Boolean
Calculates total cost of eat speed upgrades
292 293 294 295 |
# File 'lib/etw_math.rb', line 292 def self.total_eat_investment(eat_level) return false if !input_valid?(eat_level) format_number(5000 * (0.5 * eat_level ** 4 + eat_level ** 3 + 0.5 * eat_level ** 2) - 10000) end |
.total_multi_investment(multi_level) ⇒ String, Boolean
Calculates total cost of multiplier upgrades
282 283 284 285 |
# File 'lib/etw_math.rb', line 282 def self.total_multi_investment(multi_level) return false if !input_valid?(multi_level) format_number(2500 * (0.5 * multi_level ** 4 + multi_level ** 3 + 0.5 * multi_level ** 2) - 5000) end |
.total_size_investment(size_level) ⇒ String, Boolean
Calculates total cost of size upgrades
262 263 264 265 |
# File 'lib/etw_math.rb', line 262 def self.total_size_investment(size_level) return false if !input_valid?(size_level) format_number(5 * (0.5 * size_level ** 4 + size_level ** 3 + 0.5 * size_level ** 2) - 10) end |
.total_upgrade_investment(size_level, walk_speed_level, multi, eat_speed_level) ⇒ String, Boolean
Calculates total cost of all upgrades
306 307 308 309 |
# File 'lib/etw_math.rb', line 306 def self.total_upgrade_investment(size_level, walk_speed_level, multi, eat_speed_level) return false if !input_valid?(size_level, walk_speed_level, multi, eat_speed_level) format_number(5 * (0.5 * size_level ** 4 + size_level ** 3 + 0.5 * size_level ** 2) - 10 + 67.5 * (0.5 * walk_speed_level ** 4 + walk_speed_level ** 3 + 0.5 * walk_speed_level ** 2) - 135 + 2500 * (0.5 * multi ** 4 + multi ** 3 + 0.5 * multi ** 2) - 5000 + 5000 * (0.5 * eat_speed_level ** 4 + eat_speed_level ** 3 + 0.5 * eat_speed_level ** 2) - 10000) end |
.total_walk_investment(walk_level) ⇒ String, Boolean
Calculates total cost of walk speed upgrades
272 273 274 275 |
# File 'lib/etw_math.rb', line 272 def self.total_walk_investment(walk_level) return false if !input_valid?(walk_level) format_number(67.5 * (0.5 * walk_level ** 4 + walk_level ** 3 + 0.5 * walk_level ** 2) - 135) end |
.walk_level_cost(walk_level) ⇒ String, Boolean
Calculates cost of a walk speed level
232 233 234 235 |
# File 'lib/etw_math.rb', line 232 def self.walk_level_cost(walk_level) return false if !input_valid?(walk_level) format_number(135 * walk_level ** 3) end |
.walk_range_cost(starting_level, ending_level) ⇒ String, Boolean
Calculates walk speed cost using a range from a starting level to an ending level
328 329 330 331 |
# File 'lib/etw_math.rb', line 328 def self.walk_range_cost(starting_level, ending_level) return false if !input_valid?(starting_level, ending_level) || starting_level > ending_level format_number(67.5 * (0.5 * ending_level ** 4 + ending_level ** 3 + 0.5 * ending_level ** 2) - 67.5 * (0.5 * starting_level ** 4 + starting_level ** 3 + 0.5 * starting_level ** 2)) end |
.walk_speed_level(walk_speed_value) ⇒ String, Boolean
Calculates walk speed level
158 159 160 161 162 163 164 165 |
# File 'lib/etw_math.rb', line 158 def self.walk_speed_level(walk_speed_value) return false if !input_valid?(walk_speed_value) begin format_number((walk_speed_value - 10) / 2) rescue # division by zero return false end end |
.walk_speed_value(walk_speed_level) ⇒ String, Boolean
Calculates walk speed value
148 149 150 151 |
# File 'lib/etw_math.rb', line 148 def self.walk_speed_value(walk_speed_level) return false if !input_valid?(walk_speed_level) format_number(walk_speed_level * 2 + 10) end |
.yellow_crate_max(size) ⇒ String, Boolean
Calculates the maximum monetary reward from a yellow crate
118 119 120 121 |
# File 'lib/etw_math.rb', line 118 def self.yellow_crate_max(size) return false if !input_valid?(size) format_number(size * 2) end |