From 72bb06c42fcab5c215ff034e8445c33057e0c23d Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sun, 4 Feb 2024 13:49:06 -0500 Subject: Persist traps between connections --- Archipelago/client.gd | 28 +++++++++++++++++++++++++++- Archipelago/effects.gd | 34 +++++++++++++++++++++++++++------- Archipelago/load.gd | 9 +++++++++ 3 files changed, 63 insertions(+), 8 deletions(-) diff --git a/Archipelago/client.gd b/Archipelago/client.gd index 788f6ca..3a2a783 100644 --- a/Archipelago/client.gd +++ b/Archipelago/client.gd @@ -112,6 +112,9 @@ var _progressive_progress = {} var _has_colors = ["white"] var _received_indexes = [] var _puzzle_skips = 0 +var _cached_slowness = 0 +var _cached_iceland = 0 +var _cached_atbash = 0 signal could_not_connect signal connect_status @@ -297,6 +300,21 @@ func _on_data(): if localdata.size() > 1: _puzzle_skips = localdata[1] + + if localdata.size() > 2: + _cached_slowness = localdata[2] + else: + _cached_slowness = 0 + + if localdata.size() > 3: + _cached_iceland = localdata[3] + else: + _cached_iceland = 0 + + if localdata.size() > 4: + _cached_atbash = localdata[4] + else: + _cached_atbash = 0 requestSync() @@ -450,7 +468,15 @@ func saveLocaldata(): var file = File.new() file.open(_localdata_file, File.WRITE) - var data = [_last_new_item, _puzzle_skips] + var effects_node = get_tree().get_root().get_node("Spatial/AP_Effects") + + var data = [ + _last_new_item, + _puzzle_skips, + effects_node.slowness_remaining, + effects_node.iceland_remaining, + effects_node.atbash_remaining + ] file.store_var(data, true) file.close() diff --git a/Archipelago/effects.gd b/Archipelago/effects.gd index e6d2dcd..1e2e311 100644 --- a/Archipelago/effects.gd +++ b/Archipelago/effects.gd @@ -58,13 +58,13 @@ func _ready(): func activate(): activated = true - for _i in range(0, queued_iceland): - trigger_iceland_trap() + if queued_iceland > 0: + trigger_iceland_trap(queued_iceland) queued_iceland = 0 -func trigger_slowness_trap(): +func trigger_slowness_trap(length = 30): if slowness_remaining == 0: var player = get_tree().get_root().get_node("Spatial/player") player.walk_speed = orig_walk / 2.0 @@ -72,13 +72,16 @@ func trigger_slowness_trap(): $SlownessTimer.start() - slowness_remaining += 30 + slowness_remaining += length text_dirty = true + var apclient = global.get_node("Archipelago") + apclient.saveLocaldata() -func trigger_iceland_trap(): + +func trigger_iceland_trap(length = 60): if not activated: - queued_iceland += 1 + queued_iceland += length return if iceland_remaining == 0: @@ -88,9 +91,12 @@ func trigger_iceland_trap(): $IcelandTimer.start() - iceland_remaining += 60 + iceland_remaining += length text_dirty = true + var apclient = global.get_node("Archipelago") + apclient.saveLocaldata() + func trigger_atbash_trap(): var newly_atbash = (atbash_remaining == 0) @@ -102,6 +108,9 @@ func trigger_atbash_trap(): text_dirty = true + var apclient = global.get_node("Archipelago") + apclient.saveLocaldata() + func deactivate_atbash_trap(): if atbash_remaining > 0: @@ -112,6 +121,9 @@ func deactivate_atbash_trap(): apclient.evaluateSolvability() text_dirty = true + + var apclient = global.get_node("Archipelago") + apclient.saveLocaldata() func show_puzzle_skip_message(node_path): @@ -180,6 +192,10 @@ func _tick_slowness(): player.run_speed = orig_run $SlownessTimer.stop() + + if slowness_remaining % 5 == 0: + var apclient = global.get_node("Archipelago") + apclient.saveLocaldata() func _tick_iceland(): @@ -192,6 +208,10 @@ func _tick_iceland(): ) $IcelandTimer.stop() + + if iceland_remaining % 5 == 0: + var apclient = global.get_node("Archipelago") + apclient.saveLocaldata() func _process(_delta): diff --git a/Archipelago/load.gd b/Archipelago/load.gd index 7f86c91..a277817 100644 --- a/Archipelago/load.gd +++ b/Archipelago/load.gd @@ -565,6 +565,15 @@ func _load(): global._print("Hooked Load End") ._load() + # Activate any cached traps. + if apclient._cached_slowness > 0: + effects.trigger_slowness_trap(apclient._cached_slowness) + if apclient._cached_iceland > 0: + effects.trigger_iceland_trap(apclient._cached_iceland) + if apclient._cached_atbash > 0: + for _i in range(0, apclient._cached_atbash): + effects.trigger_atbash_trap() + # Process any items received while the map was loading, and send the checks # from the save load. apclient.mapFinishedLoading() -- cgit 1.4.1