semi-idle-arpg/scripts/Analytics.gd
2024-11-05 09:29:20 -07:00

71 lines
2.2 KiB
GDScript

extends SceneTree
class GameplaySim:
const EXP_COEFFICIENT := 10
const EXP_EXPONENT := 2.4
func level_eqn(experience):
# return log(0.2 * experience + 5) + 1
return pow(experience / EXP_COEFFICIENT, 1 / EXP_EXPONENT) + 1
func experience_eqn(level):
# return 5 * exp(level - 1) - 5
return EXP_COEFFICIENT * pow((level - 1), EXP_EXPONENT)
func avg_difficulty():
return (1 + (2.0 / 100) + (3.0 / 500) + (4.0 / 2500) + (5.0 / 25000)) / 5.0
func exp_kill_eqn(level):
var difficulty = avg_difficulty()
# var experience_per_kill = ((level / 10) + 1) ** avg_difficulty ** 3
var tier = (level - 1) / 10
return (tier + 1) * difficulty
func kill_eqn(level):
var experience_per_kill = exp_kill_eqn(level)
return (experience_eqn(level) - experience_eqn(level - 1)) / experience_per_kill
func time_per_level(level):
var seconds_per_kill = 2
var kills = kill_eqn(level)
return kills * seconds_per_kill
func elapsed_time(seconds: float) -> Array:
# returns array of time in format [seconds_remainder, minutes, hours, days]
var seconds_remainder = fmod(seconds, 60)
var seconds_int = floori(seconds)
var minutes = seconds_int / 60 % 60
var hours = seconds_int / 60 / 60 % 24
var days = seconds_int / 60 / 60 / 24
return [seconds_remainder, minutes, hours, days]
func elapsed_time_format(elapsed_time: Array, round_seconds: bool = true) -> String:
var seconds_format = "%02.3f"
var days_format = "%d days "
if elapsed_time[3] == 0:
days_format = ""
elapsed_time = elapsed_time.slice(0, 3)
if round_seconds:
seconds_format = "%02d"
elapsed_time.reverse()
return (days_format + "%02d:%02d:" + seconds_format) % elapsed_time
func _init() -> void:
var total_time = 0
for level in range(2, 92):
total_time += time_per_level(level)
print("%s: %.1f @ %s per kill taking %s" % [level, kill_eqn(level), exp_kill_eqn(level), elapsed_time_format(elapsed_time(time_per_level(level)))])
print(elapsed_time_format(elapsed_time(total_time)))
# print(elapsed_time_format(elapsed_time(999*24*60*60)))
# quit()