Improve prestige and add ascension as currency
This commit is contained in:
@@ -16,6 +16,7 @@ const LAST_RESET_TIME_KEY: String = "last_reset_time"
|
||||
const BASIS_LIFETIME_TOTAL: int = 0
|
||||
const BASIS_RUN_TOTAL: int = 1
|
||||
const BASIS_RUN_MAX: int = 2
|
||||
const BASIS_ALL_CURRENCIES: int = 3
|
||||
|
||||
const FORMULA_POWER: int = 0
|
||||
const FORMULA_TRIANGULAR_INVERSE: int = 1
|
||||
@@ -66,6 +67,38 @@ func get_source_currency_id() -> StringName:
|
||||
|
||||
return _normalize_currency_id(_get_config_string_name("source_currency_id", &""))
|
||||
|
||||
func get_prestige_currency_id() -> StringName:
|
||||
if not _is_config_valid():
|
||||
return &""
|
||||
|
||||
return _normalize_currency_id(_get_config_string_name("prestige_currency_id", &""))
|
||||
|
||||
func get_tracked_currency_ids() -> Array[StringName]:
|
||||
if not _is_config_valid():
|
||||
return []
|
||||
|
||||
var basis_type: int = _get_config_int("basis", BASIS_LIFETIME_TOTAL)
|
||||
|
||||
if basis_type == BASIS_ALL_CURRENCIES:
|
||||
var include_ids: Array[StringName] = _get_config_array("include_currency_ids", [])
|
||||
if not include_ids.is_empty():
|
||||
return include_ids
|
||||
if game_state and game_state.currency_catalogue:
|
||||
return game_state.currency_catalogue.get_all_ids()
|
||||
return []
|
||||
|
||||
return [get_source_currency_id()]
|
||||
|
||||
func _get_config_array(property_name: String, fallback: Array = []) -> Array:
|
||||
if config == null:
|
||||
return fallback
|
||||
|
||||
var value: Variant = config.get(property_name)
|
||||
if value is Array:
|
||||
return value
|
||||
|
||||
return fallback
|
||||
|
||||
func get_total_prestige() -> BigNumber:
|
||||
return _copy_big_number(total_prestige_earned)
|
||||
|
||||
@@ -136,12 +169,20 @@ func perform_prestige() -> bool:
|
||||
if gain.mantissa > 0.0:
|
||||
total_prestige_earned.add_in_place(gain)
|
||||
current_prestige_unspent.add_in_place(gain)
|
||||
|
||||
var prestige_currency_id: StringName = get_prestige_currency_id()
|
||||
if prestige_currency_id != &"" and game_state:
|
||||
game_state.add_currency_by_id(prestige_currency_id, gain)
|
||||
|
||||
prestige_resets_count += 1
|
||||
last_reset_time = Time.get_unix_time_from_system()
|
||||
|
||||
if game_state:
|
||||
game_state.reset_for_prestige(true, false)
|
||||
var preserve_currencies: Array[StringName] = []
|
||||
var prestige_currency_id: StringName = get_prestige_currency_id()
|
||||
if prestige_currency_id != &"":
|
||||
preserve_currencies.append(prestige_currency_id)
|
||||
game_state.reset_for_prestige(false, false, preserve_currencies)
|
||||
_reset_all_buff_levels()
|
||||
_reinitialize_generators_after_prestige_reset()
|
||||
if game_state:
|
||||
@@ -162,8 +203,10 @@ 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:
|
||||
var basis_type: int = _get_config_int("basis", BASIS_LIFETIME_TOTAL)
|
||||
|
||||
match basis_type:
|
||||
BASIS_RUN_TOTAL, BASIS_ALL_CURRENCIES:
|
||||
return _get_config_threshold()
|
||||
_:
|
||||
var current_total: float = _big_number_to_float(total_prestige_earned)
|
||||
@@ -176,28 +219,38 @@ func get_basis_value_for_display() -> BigNumber:
|
||||
func get_basis_label() -> String:
|
||||
if not _is_config_valid():
|
||||
return "-"
|
||||
|
||||
match _get_config_int("basis", BASIS_LIFETIME_TOTAL):
|
||||
|
||||
var basis_type: int = _get_config_int("basis", BASIS_LIFETIME_TOTAL)
|
||||
|
||||
match basis_type:
|
||||
BASIS_RUN_TOTAL:
|
||||
return "Run Total"
|
||||
BASIS_RUN_MAX:
|
||||
return "Run Max"
|
||||
BASIS_ALL_CURRENCIES:
|
||||
return "Total Currency"
|
||||
_:
|
||||
return "Lifetime Total"
|
||||
|
||||
func _on_currency_changed(changed_currency_id: StringName, new_amount: BigNumber) -> void:
|
||||
if config == null:
|
||||
return
|
||||
|
||||
var source_currency_id: StringName = get_source_currency_id()
|
||||
if source_currency_id == &"":
|
||||
return
|
||||
if changed_currency_id != source_currency_id:
|
||||
return
|
||||
|
||||
if new_amount.is_greater_than(run_peak_source_currency):
|
||||
run_peak_source_currency = _copy_big_number(new_amount)
|
||||
|
||||
|
||||
var basis_type: int = _get_config_int("basis", BASIS_LIFETIME_TOTAL)
|
||||
|
||||
if basis_type == BASIS_ALL_CURRENCIES:
|
||||
if new_amount.is_greater_than(run_peak_source_currency):
|
||||
run_peak_source_currency = _copy_big_number(new_amount)
|
||||
else:
|
||||
var source_currency_id: StringName = get_source_currency_id()
|
||||
if source_currency_id == &"":
|
||||
return
|
||||
if changed_currency_id != source_currency_id:
|
||||
return
|
||||
|
||||
if new_amount.is_greater_than(run_peak_source_currency):
|
||||
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())
|
||||
@@ -266,15 +319,18 @@ func _get_basis_value() -> BigNumber:
|
||||
if config == null:
|
||||
return BigNumber.from_float(0.0)
|
||||
|
||||
var source_currency_id: StringName = get_source_currency_id()
|
||||
if source_currency_id == &"":
|
||||
return BigNumber.from_float(0.0)
|
||||
|
||||
if game_state == null:
|
||||
return BigNumber.from_float(0.0)
|
||||
|
||||
var basis_type: int = _get_config_int("basis", BASIS_LIFETIME_TOTAL)
|
||||
|
||||
match _get_config_int("basis", BASIS_LIFETIME_TOTAL):
|
||||
match basis_type:
|
||||
BASIS_ALL_CURRENCIES:
|
||||
return _get_total_all_currencies()
|
||||
BASIS_RUN_TOTAL:
|
||||
var source_currency_id: StringName = get_source_currency_id()
|
||||
if source_currency_id == &"":
|
||||
return BigNumber.from_float(0.0)
|
||||
var lifetime_now: BigNumber = game_state.get_total_currency_acquired_by_id(source_currency_id)
|
||||
var run_total: BigNumber = lifetime_now.subtract(run_start_total_source_currency)
|
||||
if run_total.mantissa < 0.0:
|
||||
@@ -283,11 +339,37 @@ func _get_basis_value() -> BigNumber:
|
||||
BASIS_RUN_MAX:
|
||||
return _copy_big_number(run_peak_source_currency)
|
||||
_:
|
||||
var source_currency_id: StringName = get_source_currency_id()
|
||||
if source_currency_id == &"":
|
||||
return BigNumber.from_float(0.0)
|
||||
return _copy_big_number(game_state.get_total_currency_acquired_by_id(source_currency_id))
|
||||
|
||||
func _get_total_all_currencies() -> BigNumber:
|
||||
var total: BigNumber = BigNumber.from_float(0.0)
|
||||
var currency_ids: Array[StringName] = get_tracked_currency_ids()
|
||||
|
||||
for currency_id in currency_ids:
|
||||
var currency_total: BigNumber = game_state.get_total_currency_acquired_by_id(currency_id)
|
||||
total.add_in_place(currency_total)
|
||||
|
||||
return total
|
||||
|
||||
func _initialize_run_tracking_from_current_state() -> void:
|
||||
if config == null:
|
||||
return
|
||||
|
||||
var basis_type: int = _get_config_int("basis", BASIS_LIFETIME_TOTAL)
|
||||
|
||||
if basis_type == BASIS_ALL_CURRENCIES:
|
||||
run_start_total_source_currency = _get_total_all_currencies()
|
||||
run_peak_source_currency = BigNumber.from_float(0.0)
|
||||
var currency_ids: Array[StringName] = get_tracked_currency_ids()
|
||||
for currency_id in currency_ids:
|
||||
var current: BigNumber = game_state.get_currency_amount_by_id(currency_id)
|
||||
if current.is_greater_than(run_peak_source_currency):
|
||||
run_peak_source_currency = _copy_big_number(current)
|
||||
_save_state_to_game_state()
|
||||
return
|
||||
|
||||
var source_currency_id: StringName = get_source_currency_id()
|
||||
if source_currency_id == &"":
|
||||
@@ -307,6 +389,19 @@ func _initialize_run_tracking_from_current_state() -> void:
|
||||
func _validate_loaded_run_tracking() -> void:
|
||||
if config == null:
|
||||
return
|
||||
|
||||
var basis_type: int = _get_config_int("basis", BASIS_LIFETIME_TOTAL)
|
||||
|
||||
if basis_type == BASIS_ALL_CURRENCIES:
|
||||
var currency_ids: Array[StringName] = get_tracked_currency_ids()
|
||||
var peak: BigNumber = BigNumber.from_float(0.0)
|
||||
for currency_id in currency_ids:
|
||||
var current: BigNumber = game_state.get_currency_amount_by_id(currency_id)
|
||||
if current.is_greater_than(peak):
|
||||
peak = _copy_big_number(current)
|
||||
if peak.is_greater_than(run_peak_source_currency):
|
||||
run_peak_source_currency = _copy_big_number(peak)
|
||||
return
|
||||
|
||||
var source_currency_id: StringName = get_source_currency_id()
|
||||
if source_currency_id == &"":
|
||||
@@ -427,8 +522,10 @@ func _is_config_valid() -> bool:
|
||||
func _is_cumulative_basis() -> bool:
|
||||
if config != null and config.has_method("is_cumulative_basis"):
|
||||
return bool(config.call("is_cumulative_basis"))
|
||||
|
||||
return _get_config_int("basis", BASIS_LIFETIME_TOTAL) != BASIS_RUN_TOTAL
|
||||
|
||||
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"):
|
||||
|
||||
Reference in New Issue
Block a user