diff --git a/project.godot b/project.godot index d141a41..f33c346 100644 --- a/project.godot +++ b/project.godot @@ -10,6 +10,11 @@ config_version=4 _global_script_classes=[ { "base": "Reference", +"class": "abstract_achievement", +"language": "GDScript", +"path": "res://scripts/game/achievements/achievement.gd" +}, { +"base": "Reference", "class": "abstract_action", "language": "GDScript", "path": "res://characters/state/ai/action.gd" @@ -465,6 +470,7 @@ _global_script_classes=[ { "path": "res://characters/persons/vladimir.gd" } ] _global_script_class_icons={ +"abstract_achievement": "", "abstract_action": "", "abstract_behavior": "", "abstract_dialogue": "", diff --git a/scripts/game/achievements/achievement.gd b/scripts/game/achievements/achievement.gd new file mode 100644 index 0000000..c56c1d1 --- /dev/null +++ b/scripts/game/achievements/achievement.gd @@ -0,0 +1,17 @@ +class_name abstract_achievement + +static func id() -> String: + errors.debug_assert(false, "should not be called") + return "" + +static func name() -> String: + errors.debug_assert(false, "should not be called") + return "" + +static func description() -> String: + errors.debug_assert(false, "should not be called") + return "" + +static func icon() -> Resource: + errors.debug_assert(false, "should not be called") + return null diff --git a/scripts/game/achievements/achievements.gd b/scripts/game/achievements/achievements.gd new file mode 100644 index 0000000..c7f2be8 --- /dev/null +++ b/scripts/game/achievements/achievements.gd @@ -0,0 +1,41 @@ +extends Node + +var achievement_data: Dictionary = { + "all_dialogues": { + "name": "Way too much talk", + "description": "See every dialogue text at least once.", + "condition": funcref(self, "_all_dialogues_unlock") + }, + "high_speed": { + "name": "Light is my name", + "description": "Be fast.", + "condition": funcref(self, "_high_speed_unlock") + }, + "all_dead": { + "name": "I bring death", + "description": "Kill them. All of them. Then yourself.", + "condition": funcref(self, "_all_dead_unlock") + } +} + +var achievement_progress: Dictionary = {} + +func _process(_delta: float): + for achievement in achievement_data.keys(): + if(achievement_progress.get(achievement, false)): + continue + var unlock_func: FuncRef = achievement_data[achievement]["condition"] + if(unlock_func): + achievement_progress[achievement] = unlock_func.call_func() + +func _all_dialogues_unlock() -> bool: + return true + +func _all_dead_unlock() -> bool: + for x in game.mgmt.char_data.values(): + if(!x.get("stats", {}).get("dead", false)): + return false + return true + +func _high_speed_unlock() -> bool: + return game.mgmt.player.move.velocity.length_squared() > 1000.0