Add prestige graph

This commit is contained in:
2026-05-06 23:37:52 +02:00
parent af62e379ee
commit 1ccb498947
32 changed files with 1537 additions and 279 deletions

View File

@@ -24,7 +24,7 @@ const FORMULA_TRIANGULAR_INVERSE: int = 1
const MULTIPLIER_MODE_ADDITIVE: int = 0
const MULTIPLIER_MODE_MULTIPLICATIVE_POWER: int = 1
@export var config: Resource
@export var config: PrestigeConfig
@export var game_state: LevelGameState
var total_prestige_earned: BigNumber = BigNumber.from_float(0.0)
@@ -36,7 +36,7 @@ var last_reset_time: int = 0
func _ready() -> void:
if config == null:
config = load("res://docs/gyms/tiny_sword/prestige/primary_prestige.tres") as Resource
config = load("res://docs/gyms/tiny_sword/prestige/primary_prestige.tres") as PrestigeConfig
if not _is_config_valid():
push_warning("PrestigeManager has invalid or missing config; prestige is disabled.")
@@ -58,7 +58,7 @@ func _ready() -> void:
prestige_state_changed.emit(get_total_prestige(), calculate_pending_gain())
prestige_threshold_changed.emit(get_next_prestige_threshold())
func get_config() -> Resource:
func get_config() -> PrestigeConfig:
return config
func get_source_currency_id() -> StringName:
@@ -110,7 +110,7 @@ func get_total_multiplier() -> float:
return 1.0
var base: float = maxf(_get_config_float("base_multiplier", 1.0), 0.0)
var prestige_value: float = _big_number_to_float(total_prestige_earned)
var prestige_value: float = total_prestige_earned.to_float()
if prestige_value <= 0.0:
return base
@@ -209,7 +209,7 @@ func get_next_prestige_threshold() -> BigNumber:
BASIS_RUN_TOTAL, BASIS_ALL_CURRENCIES:
return _get_config_threshold()
_:
var current_total: float = _big_number_to_float(total_prestige_earned)
var current_total: float = total_prestige_earned.to_float()
var next_target: float = _calculate_target_for_prestige(current_total + 1.0)
return BigNumber.from_float(next_target)
@@ -260,7 +260,7 @@ func _calculate_target_for_prestige(prestige_level: float) -> float:
if config == null:
return 0.0
var threshold_value: float = _big_number_to_float(_get_config_threshold())
var threshold_value: float = _get_config_threshold().to_float()
if threshold_value <= 0.0:
return 0.0
@@ -289,11 +289,11 @@ func _calculate_raw_gain_float(basis_value: BigNumber) -> float:
match _get_config_int("formula", FORMULA_POWER):
FORMULA_TRIANGULAR_INVERSE:
var threshold_value: float = _big_number_to_float(_get_config_threshold())
var threshold_value: float = _get_config_threshold().to_float()
if threshold_value <= 0.0:
return 0.0
var basis_float: float = _big_number_to_float(basis_value)
var basis_float: float = basis_value.to_float()
if basis_float <= 0.0:
return 0.0
@@ -303,7 +303,7 @@ func _calculate_raw_gain_float(basis_value: BigNumber) -> float:
var target_total: float = (sqrt(1.0 + 8.0 * k) - 1.0) * 0.5
if _is_cumulative_basis():
return target_total - _big_number_to_float(total_prestige_earned)
return target_total - total_prestige_earned.to_float()
return target_total
_:
var ratio: float = _big_number_ratio_to_float(basis_value, _get_config_threshold())
@@ -312,7 +312,7 @@ func _calculate_raw_gain_float(basis_value: BigNumber) -> float:
var value: float = maxf(_get_config_float("scale", 0.0), 0.0) * pow(ratio, maxf(_get_config_float("exponent", 0.0001), 0.0001)) + _get_config_float("flat_bonus", 0.0)
if _is_cumulative_basis():
return value - _big_number_to_float(total_prestige_earned)
return value - total_prestige_earned.to_float()
return value
func _get_basis_value() -> BigNumber:
@@ -449,9 +449,11 @@ func _reset_all_buff_levels() -> void:
if game_state == null:
return
for buff_id in game_state._buff_levels.keys():
game_state.set_buff_level(buff_id, 0)
game_state.set_buff_unlocked(buff_id, false)
for buff in game_state.get_all_buffs():
if buff == null:
continue
game_state.set_buff_level(buff.id, 0)
game_state.set_buff_unlocked(buff.id, false)
func _reinitialize_generators_after_prestige_reset() -> void:
var scene_root: Node = get_tree().current_scene
@@ -489,14 +491,7 @@ func _big_number_ratio_to_float(a: BigNumber, b: BigNumber) -> float:
return (a.mantissa / b.mantissa) * pow(10.0, float(exponent_delta))
func _big_number_to_float(value: BigNumber) -> float:
if value.mantissa <= 0.0:
return 0.0
if value.exponent > 308:
return INF
if value.exponent < -308:
return 0.0
return value.mantissa * pow(10.0, float(value.exponent))
func _normalize_currency_id(currency_id: StringName) -> StringName:
var normalized: String = String(currency_id).to_lower().strip_edges()
@@ -514,35 +509,18 @@ func _to_non_negative_int(value: Variant, fallback: int = 0) -> int:
func _is_config_valid() -> bool:
if config == null:
return false
if not config.has_method("is_valid"):
return false
return bool(config.call("is_valid"))
return config.is_valid()
func _is_cumulative_basis() -> bool:
if config != null and config.has_method("is_cumulative_basis"):
return bool(config.call("is_cumulative_basis"))
var basis_type: int = _get_config_int("basis", BASIS_LIFETIME_TOTAL)
return basis_type != BASIS_RUN_TOTAL and basis_type != BASIS_ALL_CURRENCIES
func _round_gain(value: float) -> float:
if config != null and config.has_method("round_value"):
var rounded: Variant = config.call("round_value", value)
if rounded is float:
return rounded
if rounded is int:
return float(rounded)
return floorf(value)
return config.round_value(value)
func _get_config_threshold() -> BigNumber:
if config != null and config.has_method("get_threshold"):
var threshold: Variant = config.call("get_threshold")
if threshold is BigNumber:
return threshold
if config != null:
return config.get_threshold()
return BigNumber.from_float(1.0)
func _get_config_string_name(property_name: String, fallback: StringName = &"") -> StringName: