diff --git a/soh/soh/Enhancements/randomizer/hook_handlers.cpp b/soh/soh/Enhancements/randomizer/hook_handlers.cpp index dcc36873a..f1715c8eb 100644 --- a/soh/soh/Enhancements/randomizer/hook_handlers.cpp +++ b/soh/soh/Enhancements/randomizer/hook_handlers.cpp @@ -29,6 +29,7 @@ extern "C" { #include "src/overlays/actors/ovl_En_Box/z_en_box.h" #include "src/overlays/actors/ovl_En_Skj/z_en_skj.h" #include "src/overlays/actors/ovl_En_Hy/z_en_hy.h" +#include "src/overlays/actors/ovl_Obj_Comb/z_obj_comb.h" #include "adult_trade_shuffle.h" extern SaveContext gSaveContext; extern PlayState* gPlayState; @@ -599,7 +600,11 @@ void RandomizerOnVanillaBehaviorHandler(GIVanillaBehavior id, bool* should, void case GI_VB_GIVE_ITEM_FROM_ITEM_00: { EnItem00* item00 = static_cast(optionalArg); if (item00->actor.params == ITEM00_SOH_DUMMY) { - Flags_SetCollectible(gPlayState, item00->collectibleFlag); + if (item00->randoInf != RAND_INF_MAX) { + Flags_SetRandomizerInf(item00->randoInf); + } else { + Flags_SetCollectible(gPlayState, item00->collectibleFlag); + } Actor_Kill(&item00->actor); *should = false; } else if (item00->actor.params == ITEM00_SOH_GIVE_ITEM_ENTRY) { @@ -1043,6 +1048,70 @@ void EnDns_RandomizerPurchase(EnDns* enDns) { Flags_SetRandomizerInf(enDns->sohScrubIdentity.randomizerInf); } +void ObjComb_RandomizerChooseItemDrop(ObjComb* objComb, PlayState* play) { + s16 params = objComb->actor.params & 0x1F; + + if ( + RAND_GET_OPTION(RSK_SHUFFLE_BEEHIVES) && + !Flags_GetRandomizerInf(objComb->beehiveIdentity.randomizerInf) + ) { + EnItem00* item00 = (EnItem00*)Item_DropCollectible2(play, &objComb->actor.world.pos, ITEM00_SOH_DUMMY); + item00->randoInf = objComb->beehiveIdentity.randomizerInf; + item00->itemEntry = OTRGlobals::Instance->gRandomizer->GetItemFromKnownCheck(objComb->beehiveIdentity.randomizerCheck, GI_NONE); + item00->actor.draw = (ActorFunc)EnItem00_DrawRandomizedItem; + return; + } + + if ((params > 0) || (params < 0x1A)) { + if (params == 6) { + if (Flags_GetCollectible(play, (objComb->actor.params >> 8) & 0x3F)) { + params = -1; + } else { + params = (params | (((objComb->actor.params >> 8) & 0x3F) << 8)); + } + } else if (Rand_ZeroOne() < 0.5f) { + params = -1; + } + if (params >= 0 && !CVarGetInteger("gNoRandomDrops", 0)) { + Item_DropCollectible(play, &objComb->actor.world.pos, params); + } + } +} + +void ObjComb_RandomizerWait(ObjComb* objComb, PlayState* play) { + s32 dmgFlags; + + objComb->unk_1B0 -= 50; + if ( + RAND_GET_OPTION(RSK_SHUFFLE_BEEHIVES) && + !Flags_GetRandomizerInf(objComb->beehiveIdentity.randomizerInf) + ) { + if (objComb->unk_1B0 <= -5000) { + objComb->unk_1B0 = 1500; + } + } else if (objComb->unk_1B0 < 0) { + objComb->unk_1B0 = 0; + } + + if ((objComb->collider.base.acFlags & AC_HIT) != 0) { + objComb->collider.base.acFlags &= ~AC_HIT; + dmgFlags = objComb->collider.elements[0].info.acHitInfo->toucher.dmgFlags; + if (dmgFlags & 0x4001F866) { + objComb->unk_1B0 = 1500; + } else { + ObjComb_Break(objComb, play); + ObjComb_RandomizerChooseItemDrop(objComb, play); + Actor_Kill(&objComb->actor); + } + } else { + CollisionCheck_SetAC(play, &play->colChkCtx, &objComb->collider.base); + } + + if (objComb->actor.update != NULL) { + CollisionCheck_SetOC(play, &play->colChkCtx, &objComb->collider.base); + } +} + void RandomizerOnActorInitHandler(void* actorRef) { Actor* actor = static_cast(actorRef); @@ -1140,6 +1209,13 @@ void RandomizerOnActorInitHandler(void* actorRef) { } } } + + if (actor->id == ACTOR_OBJ_COMB) { + ObjComb* objComb = static_cast(actorRef); + s16 respawnData = gSaveContext.respawn[RESPAWN_MODE_RETURN].data & ((1 << 8) - 1); + objComb->beehiveIdentity = OTRGlobals::Instance->gRandomizer->IdentifyBeehive(gPlayState->sceneNum, (s16)actor->world.pos.x, respawnData); + objComb->actionFunc = (ObjCombActionFunc)ObjComb_RandomizerWait; + } } void RandomizerRegisterHooks() { diff --git a/soh/src/overlays/actors/ovl_Obj_Comb/z_obj_comb.c b/soh/src/overlays/actors/ovl_Obj_Comb/z_obj_comb.c index 0dde415e0..e17de7597 100644 --- a/soh/src/overlays/actors/ovl_Obj_Comb/z_obj_comb.c +++ b/soh/src/overlays/actors/ovl_Obj_Comb/z_obj_comb.c @@ -132,21 +132,6 @@ void ObjComb_Break(ObjComb* this, PlayState* play) { void ObjComb_ChooseItemDrop(ObjComb* this, PlayState* play) { s16 params = this->actor.params & 0x1F; - if ( - IS_RANDO && - Randomizer_GetSettingValue(RSK_SHUFFLE_BEEHIVES) && - !Flags_GetRandomizerInf(this->beehiveIdentity.randomizerInf) - ) { - GetItemEntry getItemEntry = Randomizer_GetItemFromKnownCheck(this->beehiveIdentity.randomizerCheck, GI_NONE); - - EnItem00* actor = (EnItem00*)Item_DropCollectible2(play, &this->actor.world.pos, ITEM00_SMALL_KEY); - actor->randoCheck = this->beehiveIdentity.randomizerCheck; - actor->randoGiEntry = getItemEntry; - actor->randoGiEntry.getItemFrom = ITEM_FROM_FREESTANDING; - actor->randoInf = this->beehiveIdentity.randomizerInf; - return; - } - if ((params > 0) || (params < 0x1A)) { if (params == 6) { if (Flags_GetCollectible(play, (this->actor.params >> 8) & 0x3F)) { @@ -170,10 +155,6 @@ void ObjComb_Init(Actor* thisx, PlayState* play) { Collider_InitJntSph(play, &this->collider); Collider_SetJntSph(play, &this->collider, &this->actor, &sJntSphInit, this->colliderItems); ObjComb_SetupWait(this); - if (IS_RANDO) { - s16 respawnData = gSaveContext.respawn[RESPAWN_MODE_RETURN].data & ((1 << 8) - 1); - this->beehiveIdentity = Randomizer_IdentifyBeehive(play->sceneNum, (s16)this->actor.world.pos.x, respawnData); - } } void ObjComb_Destroy(Actor* thisx, PlayState* play2) { @@ -191,15 +172,7 @@ void ObjComb_Wait(ObjComb* this, PlayState* play) { s32 dmgFlags; this->unk_1B0 -= 50; - if ( - IS_RANDO && - Randomizer_GetSettingValue(RSK_SHUFFLE_BEEHIVES) && - !Flags_GetRandomizerInf(this->beehiveIdentity.randomizerInf) - ) { - if (this->unk_1B0 <= -5000) { - this->unk_1B0 = 1500; - } - } else if (this->unk_1B0 < 0) { + if (this->unk_1B0 < 0) { this->unk_1B0 = 0; } diff --git a/soh/src/overlays/actors/ovl_Obj_Comb/z_obj_comb.h b/soh/src/overlays/actors/ovl_Obj_Comb/z_obj_comb.h index f7713a961..ded72dfc4 100644 --- a/soh/src/overlays/actors/ovl_Obj_Comb/z_obj_comb.h +++ b/soh/src/overlays/actors/ovl_Obj_Comb/z_obj_comb.h @@ -18,4 +18,6 @@ typedef struct ObjComb { /* */ BeehiveIdentity beehiveIdentity; } ObjComb; // size = 0x01B4 +void ObjComb_Break(ObjComb* objComb, PlayState* play); + #endif