From 520a6f3aed7c54590da2e7e918dd8af3cd285b4c Mon Sep 17 00:00:00 2001 From: Gregory Heskett Date: Fri, 3 May 2024 01:54:43 -0400 Subject: [PATCH] Bugfix: Blue coin duplication (#787) Blue coins can be collected more than once if collected on the final frame of the switch timer when BLUE_COIN_SWITCH_RETRY is enabled. Fixing this on its own isn't enough though, as the blue coin switch also doesn't check for whether that coin was collected when it resets. --- src/game/behaviors/blue_coin.inc.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/game/behaviors/blue_coin.inc.c b/src/game/behaviors/blue_coin.inc.c index 189cd2d8..d9beb388 100644 --- a/src/game/behaviors/blue_coin.inc.c +++ b/src/game/behaviors/blue_coin.inc.c @@ -49,12 +49,6 @@ void bhv_hidden_blue_coin_loop(void) { cur_obj_enable_rendering(); cur_obj_become_tangible(); - // Delete the coin once collected - if (o->oInteractStatus & INT_STATUS_INTERACTED) { - spawn_object(o, MODEL_SPARKLES, bhvCoinSparklesSpawner); - obj_mark_for_deletion(o); - } - // After 200 frames of waiting and 20 2-frame blinks (for 240 frames total), // delete the object. if (cur_obj_wait_then_blink(200, 20)) { @@ -69,6 +63,12 @@ void bhv_hidden_blue_coin_loop(void) { break; } + // Delete the coin once collected + if (o->oInteractStatus & INT_STATUS_INTERACTED) { + spawn_object(o, MODEL_SPARKLES, bhvCoinSparklesSpawner); + obj_mark_for_deletion(o); + } + o->oInteractStatus = INT_STATUS_NONE; } @@ -158,7 +158,11 @@ void bhv_blue_coin_switch_loop(void) { load_object_collision_model(); break; case BLUE_COIN_SWITCH_ACT_EXTENDING: - if (o->oTimer > 3) { + if (cur_obj_nearest_object_with_behavior(bhvHiddenBlueCoin) == NULL) { + // This code can be executed if the last blue coin is collected at the very end of the timer. + spawn_mist_particles_variable(0, 0, 46.0f); + obj_mark_for_deletion(o); + } else if (o->oTimer > 3) { // Set to BLUE_COIN_SWITCH_ACT_IDLE o->oAction = BLUE_COIN_SWITCH_ACT_IDLE; } else {