From 48aee0c7be7a149e442c277a597d0077d853a726 Mon Sep 17 00:00:00 2001 From: MysterD Date: Wed, 14 Oct 2020 23:52:07 -0700 Subject: [PATCH] Enemies drop player when picked up --- src/game/behaviors/chuckya.inc.c | 1 + src/game/mario_actions_automatic.c | 13 ++++++++++++- src/pc/network/packets/packet_player.c | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/game/behaviors/chuckya.inc.c b/src/game/behaviors/chuckya.inc.c index 839ad638..61290126 100644 --- a/src/game/behaviors/chuckya.inc.c +++ b/src/game/behaviors/chuckya.inc.c @@ -6,6 +6,7 @@ void common_anchor_mario_behavior(f32 sp28, f32 sp2C, s32 sp30) { struct MarioState* marioState = &gMarioStates[i]; struct Object* player = gMarioStates[i].marioObj; if (marioState->heldByObj != o->parentObj && marioState->heldByObj != o) { continue; } + if (marioState->action != ACT_GRABBED) { continue; } switch (o->parentObj->oChuckyaUnk88) { case 0: break; diff --git a/src/game/mario_actions_automatic.c b/src/game/mario_actions_automatic.c index be3a824f..9db20959 100644 --- a/src/game/mario_actions_automatic.c +++ b/src/game/mario_actions_automatic.c @@ -682,7 +682,18 @@ s32 act_grabbed(struct MarioState *m) { // check if they should still be grabbed if (m->playerIndex == 0) { - if (m->heldByObj == NULL || !(m->heldByObj->oInteractStatus | INT_STATUS_GRABBED_MARIO)) { + // check if the object holding me is being held + u8 heldObjIsHeld = FALSE; + if (m->heldByObj != NULL) { + for (int i = 0; i < MAX_PLAYERS; i++) { + if (!is_player_active(&gMarioStates[i])) { continue; } + if (gMarioStates[i].heldObj == m->heldByObj) { heldObjIsHeld = TRUE; } + } + } + + // error state, get out of grab + if (heldObjIsHeld || m->heldByObj == NULL || !(m->heldByObj->oInteractStatus | INT_STATUS_GRABBED_MARIO)) { + m->heldByObj = NULL; return set_mario_action(m, (m->forwardVel >= 0.0f) ? ACT_THROWN_FORWARD : ACT_THROWN_BACKWARD, FALSE); } } diff --git a/src/pc/network/packets/packet_player.c b/src/pc/network/packets/packet_player.c index 24e76493..dd1cd304 100644 --- a/src/pc/network/packets/packet_player.c +++ b/src/pc/network/packets/packet_player.c @@ -259,7 +259,7 @@ void network_receive_player(struct Packet* p) { // find and set their held object m->heldObj = (heldSyncID != 0) ? gSyncObjects[heldSyncID].o : NULL; if (m->heldObj != NULL) { - if (np->globalIndex < gNetworkPlayerLocal->globalIndex) { + if (gMarioStates[0].heldObj == m->heldObj && np->globalIndex < gNetworkPlayerLocal->globalIndex) { // drop the object if a higher priority player is holding our object mario_drop_held_object(&gMarioStates[0]); force_idle_state(&gMarioStates[0]);