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.2.0"- 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
-
.actual_level_at_size(size) ⇒ String, Boolean
Calculates actual size level (float).
-
.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.
-
.eat_speed_level(eat_speed_value) ⇒ String, Boolean
Calculates eat speed level.
-
.eat_speed_value(eat_speed_level) ⇒ String, Boolean
Calculates eat speed value.
-
.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 (floor).
-
.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.
-
.nearest_level_at_size(size) ⇒ String, Boolean
Calculates nearest size level (rounded).
-
.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
.actual_level_at_size(size) ⇒ String, Boolean
Calculates actual size level (float)
196 197 198 199 200 201 202 203 |
# File 'lib/etw_math.rb', line 196 def self.actual_level_at_size(size) return false if !input_valid?(size) begin format_number(((-50 + Math.sqrt(2500 + 200 * size)) / 100).round(3), true) rescue # division by zero return false end end |
.big_bite_amount(current_size, multi) ⇒ String, Boolean
Calculates big bite amount
439 440 441 442 443 444 445 446 |
# File 'lib/etw_math.rb', line 439 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
484 485 486 487 488 489 490 491 |
# File 'lib/etw_math.rb', line 484 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
526 527 528 529 530 531 532 533 |
# File 'lib/etw_math.rb', line 526 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
300 301 302 303 |
# File 'lib/etw_math.rb', line 300 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
398 399 400 401 |
# File 'lib/etw_math.rb', line 398 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 |
.eat_speed_level(eat_speed_value) ⇒ String, Boolean
Calculates eat speed level
234 235 236 237 |
# File 'lib/etw_math.rb', line 234 def self.eat_speed_level(eat_speed_value) return false if !input_valid?(eat_speed_value) format_number(5 * eat_speed_value - 4) end |
.eat_speed_value(eat_speed_level) ⇒ String, Boolean
Calculates eat speed value
224 225 226 227 |
# File 'lib/etw_math.rb', line 224 def self.eat_speed_value(eat_speed_level) return false if !input_valid?(eat_speed_level) format_number(0.2 * eat_speed_level + 0.8, true) 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 (floor)
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
424 425 426 427 428 429 430 431 |
# File 'lib/etw_math.rb', line 424 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
469 470 471 472 473 474 475 476 |
# File 'lib/etw_math.rb', line 469 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
512 513 514 515 516 517 518 519 |
# File 'lib/etw_math.rb', line 512 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
290 291 292 293 |
# File 'lib/etw_math.rb', line 290 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
387 388 389 390 |
# File 'lib/etw_math.rb', line 387 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 |
.nearest_level_at_size(size) ⇒ String, Boolean
Calculates nearest size level (rounded)
210 211 212 213 214 215 216 217 |
# File 'lib/etw_math.rb', line 210 def self.nearest_level_at_size(size) return false if !input_valid?(size) begin format_number(((-50 + Math.sqrt(2500 + 200 * size)) / 100).round) rescue # division by zero return false end end |
.optimal_multi(size_level, ratio) ⇒ String, Boolean
Calculates optimal multiplier
256 257 258 259 260 261 262 263 |
# File 'lib/etw_math.rb', line 256 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
245 246 247 248 |
# File 'lib/etw_math.rb', line 245 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
270 271 272 273 |
# File 'lib/etw_math.rb', line 270 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
365 366 367 368 |
# File 'lib/etw_math.rb', line 365 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
409 410 411 412 413 414 415 416 |
# File 'lib/etw_math.rb', line 409 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
454 455 456 457 458 459 460 461 |
# File 'lib/etw_math.rb', line 454 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
498 499 500 501 502 503 504 505 |
# File 'lib/etw_math.rb', line 498 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
541 542 543 544 545 546 547 548 |
# File 'lib/etw_math.rb', line 541 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
556 557 558 559 560 561 562 563 |
# File 'lib/etw_math.rb', line 556 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
340 341 342 343 |
# File 'lib/etw_math.rb', line 340 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
330 331 332 333 |
# File 'lib/etw_math.rb', line 330 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
310 311 312 313 |
# File 'lib/etw_math.rb', line 310 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
354 355 356 357 |
# File 'lib/etw_math.rb', line 354 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
320 321 322 323 |
# File 'lib/etw_math.rb', line 320 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
280 281 282 283 |
# File 'lib/etw_math.rb', line 280 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
376 377 378 379 |
# File 'lib/etw_math.rb', line 376 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 |