Fix research xp generation

This commit is contained in:
2026-04-18 00:56:44 +02:00
parent 2bc81a73fd
commit dfb1161854
29 changed files with 485 additions and 47 deletions

View File

@@ -149,12 +149,17 @@ func _grant_cycle_income(cycle_count: int) -> void:
production_tick.emit(produced, cycle_count, owned)
if data != null and data.research_data != null:
if not _is_research_active(data.research_data.id):
return
var amount_float: float = produced.mantissa * pow(10.0, float(produced.exponent))
var research_xp_amount: BigNumber = BigNumber.from_float(data.research_data.xp_per_currency_produced * amount_float)
if game_state != null and research_xp_amount.mantissa > 0.0:
var tracker: ResearchXPTracker = game_state.research_tracker as ResearchXPTracker
if tracker:
tracker.add_xp_with_buffs(data.research_data.id, research_xp_amount)
else:
game_state.add_research_xp(data.research_data.id, research_xp_amount)
## Convenience helper for the next single-unit purchase cost.
func get_next_cost() -> BigNumber:
@@ -359,6 +364,29 @@ func get_research_multiplier() -> float:
return 1.0
return game_state.get_research_multiplier(data.research_data.id)
func _is_research_active(research_id: StringName) -> bool:
if game_state == null:
return true
var research_panel: Node = null
var parent: Node = get_parent()
while parent != null and parent != game_state.get_tree().root:
if parent.has_method("is_research_active"):
research_panel = parent
break
parent = parent.get_parent()
if research_panel == null:
research_panel = game_state.find_child("ResearchPanel", true, false)
if research_panel == null:
return true
if research_panel.has_method("is_research_active"):
return research_panel.is_research_active(research_id)
return true
func reset_runtime_state_for_prestige() -> void:
_is_registered = false
_is_registering = false
@@ -405,17 +433,23 @@ func _try_grant_click_currency() -> void:
var click_value: BigNumber = _get_click_value()
_add_currency(click_value)
_remaining_click_cooldown_seconds = _get_click_cooldown_seconds()
# Grant research XP for manual clicks
if data.research_data != null and click_value.mantissa > 0.0:
if not _is_research_active(data.research_data.id):
return
var amount_float: float = click_value.mantissa * pow(10.0, float(click_value.exponent))
var research_xp_amount: BigNumber = BigNumber.from_float(data.research_data.xp_per_currency_produced * amount_float)
if game_state != null and research_xp_amount.mantissa > 0.0:
var tracker: ResearchXPTracker = game_state.research_tracker as ResearchXPTracker
if tracker:
tracker.add_xp_with_buffs(data.research_data.id, research_xp_amount)
else:
game_state.add_research_xp(data.research_data.id, research_xp_amount)
_remaining_click_cooldown_seconds = _get_click_cooldown_seconds()
## Resolves click reward from data.
func _get_click_value() -> BigNumber: