Skip to content

Commit

Permalink
fix: Enable repeatable items in Skulltulas.
Browse files Browse the repository at this point in the history
If an item is repeatable, it should respawn on cycle reset, and if the item is in inventory, it will only provide a blue rupee.
  • Loading branch information
PhlexPlexico committed Sep 30, 2024
1 parent 934b6d6 commit da6c9d6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 45 deletions.
1 change: 0 additions & 1 deletion code/include/rnd/actors/en_si.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "game/actor.h"
#include "rnd/models.h"
#include "rnd/item_override.h"
#if defined ENABLE_DEBUG || defined DEBUG_PRINT
#include "common/debug.h"
extern "C" {
Expand Down
32 changes: 16 additions & 16 deletions code/include/rnd/item_override.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,22 +442,22 @@ namespace rnd {
u8 ItemOverride_SetProgressiveItemDraw(ItemOverride);
bool ItemOverride_IsItemObtainedOrEmptyBottle(ItemOverride);
extern "C" {
bool ItemOverride_CheckAromaGivenItem();
bool ItemOverride_CheckMikauGivenItem();
bool ItemOverride_CheckDarmaniGivenItem();
void ItemOverride_GetItemTextAndItemID(game::act::Player*);
void ItemOverride_GetItem(game::GlobalContext*, game::act::Actor*, game::act::Player*, s16);
void ItemOverride_GetFairyRewardItem(game::GlobalContext*, game::act::GreatFairy*, s16);
void ItemOverride_GetSoHItem(game::GlobalContext*, game::act::Actor*, s16);
int ItemOverride_CheckInventoryItemOverride(game::ItemId);
void ItemOverride_SwapSoHGetItemText(game::GlobalContext*, u16, game::act::Actor*);
bool ItemOverride_CheckTingleMaps(u16, game::GlobalContext*);
u32 ItemOverride_GetGaboraExtData();
u32 ItemOverride_GetOshExtData();
void ItemOverride_SetSkullCollected(u16, game::SceneId);
u8 ItemOverride_IsSkullCollected(game::act::Actor*, game::SceneId);
u8 ItemOverride_OverrideSkullToken(game::act::Actor*);
u8 ItemOverride_CheckBossStatus();
bool ItemOverride_CheckAromaGivenItem();
bool ItemOverride_CheckMikauGivenItem();
bool ItemOverride_CheckDarmaniGivenItem();
void ItemOverride_GetItemTextAndItemID(game::act::Player*);
void ItemOverride_GetItem(game::GlobalContext*, game::act::Actor*, game::act::Player*, s16);
void ItemOverride_GetFairyRewardItem(game::GlobalContext*, game::act::GreatFairy*, s16);
void ItemOverride_GetSoHItem(game::GlobalContext*, game::act::Actor*, s16);
int ItemOverride_CheckInventoryItemOverride(game::ItemId);
void ItemOverride_SwapSoHGetItemText(game::GlobalContext*, u16, game::act::Actor*);
bool ItemOverride_CheckTingleMaps(u16, game::GlobalContext*);
u32 ItemOverride_GetGaboraExtData();
u32 ItemOverride_GetOshExtData();
void ItemOverride_SetSkullCollected(u16, game::SceneId);
u8 ItemOverride_IsSkullCollected(game::act::Actor*, game::SceneId);
u8 ItemOverride_OverrideSkullToken(game::act::Actor*);
u8 ItemOverride_CheckBossStatus();
}
extern "C" u32 rActiveItemGraphicId;
extern "C" ItemOverride rItemOverrides[640];
Expand Down
5 changes: 1 addition & 4 deletions code/source/rnd/actors/en_si.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
namespace rnd {
extern "C" {
void En_Si_Init(game::act::Actor* actor, game::GlobalContext* gctx) {
ItemOverride override = ItemOverride_Lookup(actor, (u16)gctx->scene, 0x20);
util::GetPointer<void(game::act::Actor*, game::GlobalContext*)>(0x2E7FCC)(actor, gctx);
if (ItemOverride_IsSkullCollected(actor, gctx->scene) && ItemOverride_IsItemObtainedOrEmptyBottle(override))
Model_SpawnByActor(actor, gctx, 0x01);
else Model_SpawnByActor(actor, gctx, 0x20);
Model_SpawnByActor(actor, gctx, 0x20);
}

void En_Si_Draw(game::act::Actor* actor, game::GlobalContext* gctx) {
Expand Down
36 changes: 15 additions & 21 deletions code/source/rnd/item_override.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,6 @@ namespace rnd {
}

void SetExtData() {
#if defined ENABLE_DEBUG || defined DEBUG_PRINT
rnd::util::Print("%s: STORED GET ITEM ID IS %#04x\n", __func__, storedGetItemId);
#endif
if (storedActorId == game::act::Id::NpcEnNb) {
gExtSaveData.givenItemChecks.enNbGivenItem = 1;
} else if (storedActorId == game::act::Id::NpcInvisibleGuard) {
Expand Down Expand Up @@ -727,6 +724,11 @@ namespace rnd {
override.value.getItemId = 0x02;
override.value.looksLikeItemId = 0x02;
}
} else if (override.key.type == ItemOverride_Type::OVR_SKULL &&
(gctx->scene == game::SceneId::SwampSpiderHouse || gctx->scene == game::SceneId::OceansideSpiderHouse) &&
ItemOverride_IsSkullCollected(fromActor, gctx->scene)) {
override.value.getItemId = 0x02;
override.value.looksLikeItemId = 0x02;
}

// This check is mainly to ensure we do not have repeatable progressive items within these base items.
Expand Down Expand Up @@ -1063,18 +1065,18 @@ namespace rnd {
return;
}
} else if (scene == game::SceneId::OceansideSpiderHouse) {
if (skulltulaMapOSH[i] == (params & 0xFF)) {
gExtSaveData.chestRewarded[(u8)game::SceneId::OceansideSpiderHouse][i] = 1;
// Special case - since OSH has one chest, let's remove
if ((i + 1) == 30)
break;
if (skulltulaMapOSH[i + 1] == (params & 0xFF)) {
gExtSaveData.chestRewarded[(u8)game::SceneId::OceansideSpiderHouse][i + 1] = 1;
return;
}
}
}
}

u8 ItemOverride_IsSkullCollected(game::act::Actor* actor, game::SceneId scene) {
#if defined ENABLE_DEBUG || defined DEBUG_PRINT
rnd::util::Print("%s: Our scene is %#06x\n", __func__, scene);
#endif
for (u8 i = 0; i < 30; i++) {
if (scene == game::SceneId::SwampSpiderHouse) {
if (skulltulaMapSSH[i] == (actor->params & 0xFF)) {
Expand All @@ -1095,21 +1097,13 @@ namespace rnd {
u8 ItemOverride_OverrideSkullToken(game::act::Actor* actor) {
game::GlobalContext* gctx = GetContext().gctx;
s16 getItemId = gctx->scene == game::SceneId::SwampSpiderHouse ? 0x44 : 0x6D;
if (ItemOverride_IsSkullCollected(actor, gctx->scene)) {
ItemOverride_GetItem(gctx, actor, gctx->GetPlayerActor(), 0x01);
if (rActiveItemRow != NULL) {
ItemOverride_GetItemTextAndItemID(gctx->GetPlayerActor());
return true;
}
} else {
ItemOverride_GetItem(gctx, actor, gctx->GetPlayerActor(), getItemId);
if (rActiveItemRow != NULL) {
ItemOverride_GetItemTextAndItemID(gctx->GetPlayerActor());
ItemOverride_SetSkullCollected(actor->params, gctx->scene);
ItemOverride_GetItem(gctx, actor, gctx->GetPlayerActor(), getItemId);
if (rActiveItemRow != NULL) {
ItemOverride_GetItemTextAndItemID(gctx->GetPlayerActor());
return true;
}
return true;
}

return false;
}

Expand Down
7 changes: 4 additions & 3 deletions code/source/rnd/models.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ namespace rnd {
objectBankIdx = ExtendedObject_Spawn(&globalCtx->object_context, model->itemRow->objectId);
}
storedObjId = model->itemRow->objectId;
#if defined ENABLE_DEBUG || defined DEBUG_PRINT
rnd::util::Print("%s: storedObjId is %#04x\n", __func__, storedObjId);
#endif
model->objectBankIdx = objectBankIdx;
}

Expand Down Expand Up @@ -205,6 +202,10 @@ namespace rnd {
ItemOverride override = ItemOverride_Lookup(actor, (u16)globalCtx->scene, baseItemId);

if (override.key.all != 0) {
if (override.key.type == ItemOverride_Type::OVR_SKULL && ItemOverride_IsSkullCollected(actor, globalCtx->scene)) {
override.value.getItemId = 0x02;
override.value.looksLikeItemId = 0x02;
}
Model_LookupByOverride(model, override);
Model_GetObjectBankIndex(model, actor, globalCtx);
}
Expand Down

0 comments on commit da6c9d6

Please sign in to comment.