Initial STEP 3 study game and questions API
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
extends Node
|
||||
|
||||
const XP_PER_LEVEL := 500
|
||||
|
||||
var badge_catalog := {
|
||||
"First Block": "Complete your first question block.",
|
||||
"Hot Streak": "Answer 5 questions correctly in a row.",
|
||||
"Tenacious": "Complete 10 total questions.",
|
||||
"Sharp Shooter": "Score at least 80% on a block.",
|
||||
"Clock Ready": "Complete a timed block."
|
||||
}
|
||||
|
||||
func level_for_xp(xp: int) -> int:
|
||||
return int(floor(float(xp) / float(XP_PER_LEVEL))) + 1
|
||||
|
||||
|
||||
func xp_into_level(xp: int) -> int:
|
||||
return xp % XP_PER_LEVEL
|
||||
|
||||
|
||||
func calculate_block_rewards(answers: Array, mode: String, system_name: String) -> Dictionary:
|
||||
var correct := 0
|
||||
var longest_streak := 0
|
||||
var running_streak := int(ProfileService.get_profile().get("current_streak", 0))
|
||||
var ending_streak := running_streak
|
||||
|
||||
for answer in answers:
|
||||
if bool(answer.get("is_correct", false)):
|
||||
correct += 1
|
||||
ending_streak += 1
|
||||
longest_streak = max(longest_streak, ending_streak)
|
||||
else:
|
||||
ending_streak = 0
|
||||
|
||||
var total: int = max(answers.size(), 1)
|
||||
var accuracy := float(correct) / float(total)
|
||||
var xp := answers.size() * 25 + correct * 35 + longest_streak * 10
|
||||
if accuracy >= 0.8:
|
||||
xp += 100
|
||||
if mode == "Timed":
|
||||
xp += 50
|
||||
|
||||
var profile: Dictionary = ProfileService.get_profile()
|
||||
var badges: Array[String] = []
|
||||
_add_badge_if_needed(badges, profile, "First Block", true)
|
||||
_add_badge_if_needed(badges, profile, "Hot Streak", longest_streak >= 5)
|
||||
_add_badge_if_needed(badges, profile, "Tenacious", profile.get("completed_question_ids", []).size() + answers.size() >= 10)
|
||||
_add_badge_if_needed(badges, profile, "Sharp Shooter", accuracy >= 0.8)
|
||||
_add_badge_if_needed(badges, profile, "Clock Ready", mode == "Timed")
|
||||
|
||||
return {
|
||||
"mode": mode,
|
||||
"system": system_name,
|
||||
"correct": correct,
|
||||
"total": answers.size(),
|
||||
"accuracy": accuracy,
|
||||
"xp_earned": xp,
|
||||
"ending_streak": ending_streak,
|
||||
"longest_streak": longest_streak,
|
||||
"badges_unlocked": badges,
|
||||
"answers": answers
|
||||
}
|
||||
|
||||
|
||||
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