Add core game retry flow and question stats
This commit is contained in:
@@ -4,6 +4,7 @@ const XP_PER_LEVEL := 500
|
||||
|
||||
var badge_catalog := {
|
||||
"First Block": "Complete your first question block.",
|
||||
"First Run": "Answer your first core mode question.",
|
||||
"Hot Streak": "Answer 5 questions correctly in a row.",
|
||||
"Tenacious": "Complete 10 total questions.",
|
||||
"Sharp Shooter": "Score at least 80% on a block.",
|
||||
@@ -62,6 +63,38 @@ func calculate_block_rewards(answers: Array, mode: String, system_name: String)
|
||||
}
|
||||
|
||||
|
||||
func calculate_question_rewards(answer: Dictionary, elapsed_seconds: float, target_seconds: float, score_delta: int) -> Dictionary:
|
||||
var is_correct := bool(answer.get("is_correct", false))
|
||||
var profile: Dictionary = ProfileService.get_profile()
|
||||
var ending_streak := int(profile.get("current_streak", 0)) + 1 if is_correct else 0
|
||||
var xp := 20
|
||||
if is_correct:
|
||||
xp += 35
|
||||
if elapsed_seconds <= target_seconds:
|
||||
xp += 10
|
||||
elif elapsed_seconds > target_seconds * 1.5:
|
||||
xp = max(10, xp - 10)
|
||||
|
||||
var badges: Array[String] = []
|
||||
_add_badge_if_needed(badges, profile, "First Run", true)
|
||||
_add_badge_if_needed(badges, profile, "Hot Streak", ending_streak >= 5)
|
||||
_add_badge_if_needed(badges, profile, "Tenacious", profile.get("completed_question_ids", []).size() + 1 >= 10)
|
||||
|
||||
return {
|
||||
"mode": "Core",
|
||||
"system": str(answer.get("question", {}).get("system", "All Systems")),
|
||||
"correct": 1 if is_correct else 0,
|
||||
"total": 1,
|
||||
"accuracy": 1.0 if is_correct else 0.0,
|
||||
"xp_earned": xp,
|
||||
"score_delta": score_delta,
|
||||
"ending_streak": ending_streak,
|
||||
"longest_streak": ending_streak,
|
||||
"badges_unlocked": badges,
|
||||
"answers": [answer]
|
||||
}
|
||||
|
||||
|
||||
func _add_badge_if_needed(badges: Array[String], profile: Dictionary, badge_name: String, condition: bool) -> void:
|
||||
if condition and not profile.get("badges", []).has(badge_name):
|
||||
badges.append(badge_name)
|
||||
|
||||
Reference in New Issue
Block a user