diff --git a/src/game/engine/src/modules/empire/throne_room_profile.gd b/src/game/engine/src/modules/empire/throne_room_profile.gd index a6d4d962..d90b0d22 100644 --- a/src/game/engine/src/modules/empire/throne_room_profile.gd +++ b/src/game/engine/src/modules/empire/throne_room_profile.gd @@ -175,55 +175,50 @@ func record_game(record: Dictionary) -> void: game_records.append(record) +static var _STAT_KEY_MAP: Dictionary = { + "best_era_gte": "best_era", + "victories_gte": "victories", + "conquest_victories_gte": "conquest_victories", + "survival_victory_gte": "survival_victories", + "ironclad_victory": "ironclad_victories", + "games_played_gte": "games_played", + "best_tech_count_gte": "best_tech_count", + "best_city_count_gte": "best_city_count", + "best_happiness_gte": "best_happiness", + "golden_ages_lifetime_gte": "golden_ages_lifetime", + "best_score_gte": "best_score", + "turns_survived_best_gte": "turns_survived_best", + "lairs_cleared_lifetime_gte": "lairs_cleared_lifetime", + "units_lost_lifetime_gte": "units_lost_lifetime", + "legendary_unit_promoted": "legendary_unit_promoted", +} + + +func _check_leaf(ctype: String, unlock: Dictionary) -> bool: + if ctype == "always": + return true + if ctype == "wonder_ever_built": + var wonders: Array = lifetime_stats.get("wonders_ever_built", []) + return unlock.get("id", "") in wonders + if _STAT_KEY_MAP.has(ctype): + var default_v: int = 1 if ctype == "ironclad_victory" or ctype == "legendary_unit_promoted" else 0 + return lifetime_stats.get(_STAT_KEY_MAP[ctype], 0) >= unlock.get("value", default_v) + return false + + func _check_unlock(unlock: Dictionary) -> bool: var ctype: String = unlock.get("type", "always") - match ctype: - "always": - return true - "best_era_gte": - return lifetime_stats.get("best_era", 0) >= unlock.get("value", 0) - "victories_gte": - return lifetime_stats.get("victories", 0) >= unlock.get("value", 0) - "conquest_victories_gte": - return lifetime_stats.get("conquest_victories", 0) >= unlock.get("value", 0) - "survival_victory_gte": - return lifetime_stats.get("survival_victories", 0) >= unlock.get("value", 0) - "ironclad_victory": - return lifetime_stats.get("ironclad_victories", 0) >= unlock.get("value", 1) - "games_played_gte": - return lifetime_stats.get("games_played", 0) >= unlock.get("value", 0) - "best_tech_count_gte": - return lifetime_stats.get("best_tech_count", 0) >= unlock.get("value", 0) - "best_city_count_gte": - return lifetime_stats.get("best_city_count", 0) >= unlock.get("value", 0) - "best_happiness_gte": - return lifetime_stats.get("best_happiness", 0) >= unlock.get("value", 0) - "golden_ages_lifetime_gte": - return lifetime_stats.get("golden_ages_lifetime", 0) >= unlock.get("value", 0) - "best_score_gte": - return lifetime_stats.get("best_score", 0) >= unlock.get("value", 0) - "turns_survived_best_gte": - return lifetime_stats.get("turns_survived_best", 0) >= unlock.get("value", 0) - "lairs_cleared_lifetime_gte": - return lifetime_stats.get("lairs_cleared_lifetime", 0) >= unlock.get("value", 0) - "units_lost_lifetime_gte": - return lifetime_stats.get("units_lost_lifetime", 0) >= unlock.get("value", 0) - "legendary_unit_promoted": - return lifetime_stats.get("legendary_unit_promoted", 0) >= unlock.get("value", 1) - "wonder_ever_built": - var wonders: Variant = lifetime_stats.get("wonders_ever_built", []) - return wonders is Array and unlock.get("id", "") in wonders - "any_of": - for condition: Variant in unlock.get("conditions", []): - if condition is Dictionary and _check_unlock(condition): - return true - return false - "all_of": - for condition: Variant in unlock.get("conditions", []): - if condition is Dictionary and not _check_unlock(condition): - return false - return true - return false + if ctype == "any_of": + for condition: Dictionary in unlock.get("conditions", []): + if _check_unlock(condition): + return true + return false + if ctype == "all_of": + for condition: Dictionary in unlock.get("conditions", []): + if not _check_unlock(condition): + return false + return true + return _check_leaf(ctype, unlock) func _sort_by_tier_desc(a: Dictionary, b: Dictionary) -> bool: