Improve prestige
This commit is contained in:
@@ -2,6 +2,7 @@ extends Node
|
||||
|
||||
signal prestige_state_changed(total_prestige: BigNumber, pending_gain: BigNumber)
|
||||
signal prestige_performed(gain: BigNumber, total_prestige: BigNumber)
|
||||
signal prestige_threshold_changed(next_threshold: BigNumber)
|
||||
|
||||
const SAVE_KEY: String = "prestige_state"
|
||||
const TOTAL_PRESTIGE_KEY: String = "total_prestige_earned"
|
||||
@@ -48,6 +49,10 @@ func _ready() -> void:
|
||||
|
||||
GameState.currency_changed.connect(_on_currency_changed)
|
||||
prestige_state_changed.emit(get_total_prestige(), calculate_pending_gain())
|
||||
prestige_threshold_changed.emit(get_next_prestige_threshold())
|
||||
|
||||
func get_config() -> Resource:
|
||||
return config
|
||||
|
||||
func get_source_currency_id() -> StringName:
|
||||
if not _is_config_valid():
|
||||
@@ -138,10 +143,24 @@ func perform_prestige() -> bool:
|
||||
GameState.save_game()
|
||||
|
||||
var total: BigNumber = get_total_prestige()
|
||||
var next_threshold: BigNumber = get_next_prestige_threshold()
|
||||
prestige_performed.emit(gain, total)
|
||||
prestige_state_changed.emit(total, calculate_pending_gain())
|
||||
prestige_threshold_changed.emit(next_threshold)
|
||||
return true
|
||||
|
||||
func get_next_prestige_threshold() -> BigNumber:
|
||||
if not _is_config_valid():
|
||||
return BigNumber.from_float(0.0)
|
||||
|
||||
match _get_config_int("basis", BASIS_LIFETIME_TOTAL):
|
||||
BASIS_RUN_TOTAL:
|
||||
return _get_config_threshold()
|
||||
_:
|
||||
var current_total: float = _big_number_to_float(total_prestige_earned)
|
||||
var next_target: float = _calculate_target_for_prestige(current_total + 1.0)
|
||||
return BigNumber.from_float(next_target)
|
||||
|
||||
func get_basis_value_for_display() -> BigNumber:
|
||||
return _get_basis_value()
|
||||
|
||||
@@ -171,7 +190,36 @@ func _on_currency_changed(changed_currency_id: StringName, new_amount: BigNumber
|
||||
run_peak_source_currency = _copy_big_number(new_amount)
|
||||
|
||||
_save_state_to_game_state()
|
||||
var next_threshold: BigNumber = get_next_prestige_threshold()
|
||||
prestige_state_changed.emit(get_total_prestige(), calculate_pending_gain())
|
||||
prestige_threshold_changed.emit(next_threshold)
|
||||
|
||||
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())
|
||||
if threshold_value <= 0.0:
|
||||
return 0.0
|
||||
|
||||
match _get_config_int("formula", FORMULA_POWER):
|
||||
FORMULA_TRIANGULAR_INVERSE:
|
||||
var target_total: float = prestige_level
|
||||
var k: float = target_total * (target_total + 1.0) * 0.5
|
||||
return k * threshold_value
|
||||
_:
|
||||
var scale: float = maxf(_get_config_float("scale", 1.0), 0.0001)
|
||||
var exponent: float = maxf(_get_config_float("exponent", 1.0), 0.0001)
|
||||
var flat_bonus: float = _get_config_float("flat_bonus", 0.0)
|
||||
if scale <= 0.0:
|
||||
scale = 0.0001
|
||||
if exponent <= 0.0:
|
||||
exponent = 0.0001
|
||||
|
||||
var ratio: float = pow((prestige_level - flat_bonus) / scale, 1.0 / exponent)
|
||||
if ratio <= 0.0:
|
||||
return threshold_value
|
||||
return ratio * threshold_value
|
||||
|
||||
func _calculate_raw_gain_float(basis_value: BigNumber) -> float:
|
||||
if config == null:
|
||||
|
||||
Reference in New Issue
Block a user