Skip to content

Commit

Permalink
add mushroom expires effect
Browse files Browse the repository at this point in the history
  • Loading branch information
JCog committed Sep 7, 2024
1 parent 1ffefc2 commit 1af34fd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/chaos.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ void chaosUpdate() {

// update active effects
for (u32 i = 0; i < totalEffectCount; i++) {
if (effectData[i].timer > 0 && (effectData[i].canTrigger == NULL || effectData[i].canTrigger())) {
b8 shouldTrigger = effectData[i].canTrigger == NULL || effectData[i].canTrigger();
if (effectData[i].timer > 0 && (shouldTrigger || effectData[i].maxSeconds == 0)) {
if (effectData[i].timer == 1 && effectData[i].off != NULL) {
effectData[i].off();
} else if (effectData[i].everyFrame){
Expand Down
41 changes: 40 additions & 1 deletion src/chaos_effects.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ static b8 isOverworld(void);
static b8 isBattle(void);
static b8 canUnequipBadge(void);
static b8 canPointSwap(void);
static b8 hasMushroom(void);

// overworld
static void posLoad(void);
Expand Down Expand Up @@ -52,6 +53,7 @@ static void addRemoveStarPoints(void);
static void randomTattle(void);
static void badMusic(void);
static void badMusicOff(void);
static void expireMushroom(void);

struct ChaosEffectData effectData[] = {
{"Rewind", TRUE, 0, 60, posLoad, NULL, isOverworld},
Expand All @@ -77,6 +79,7 @@ struct ChaosEffectData effectData[] = {
{"Add/Remove Star Points", FALSE, 0, 0, addRemoveStarPoints, NULL, NULL},
{"Random Tattle", FALSE, 0, 0, randomTattle, NULL, NULL},
{"Bad Music", TRUE, 0, 60, badMusic, badMusicOff, NULL},
{"Mushroom Expires", FALSE, 0, 0, expireMushroom, NULL, hasMushroom},
};

u8 totalEffectCount = ARRAY_COUNT(effectData);
Expand All @@ -89,6 +92,11 @@ static s16 perilTimer = 0;
static s16 badMusicTimer = 0;
static struct ActorScaleData actorScaleBuffer[] = {[0 ... ACTOR_DATA_COUNT] = {-1, 0, {0, 0, 0}} };

const enum ItemIDs mushroomIds[] = {
ITEM_MUSHROOM, ITEM_VOLT_SHROOM, ITEM_SUPER_SHROOM, ITEM_ULTRA_SHROOM, ITEM_LIFE_SHROOM, ITEM_HONEY_SHROOM,
ITEM_MAPLE_SHROOM, ITEM_JELLY_SHROOM
};

static void decTimer(s16 *timer) {
if (*timer >= 0) {
(*timer)--;
Expand Down Expand Up @@ -130,6 +138,19 @@ static b8 canPointSwap() {
return gPlayerData.curHP != gPlayerData.curFP;
}

static b8 hasMushroom() {
for (u32 i = 0; i < 10; i++) {
for (u32 j = 0; j < ARRAY_COUNT(mushroomIds); j++) {
if (gPlayerData.invItems[i] == mushroomIds[j]) {
return TRUE;
}
}
}
return FALSE;
}

////////////////////////////////////////////////////////////////////////////////

static void posLoad() {
static Vec3f savedPos;
if (frameCount % 30 == 20) {
Expand Down Expand Up @@ -551,4 +572,22 @@ static void badMusic() {

static void badMusicOff() {
chaosBadMusic = 0;
}
}

static void expireMushroom() {
s32 invIdx[10];
u8 count = 0;
for (u32 i = 0; i < 10; i++) {
for (u32 j = 0; j < ARRAY_COUNT(mushroomIds); j++) {
if (gPlayerData.invItems[i] == mushroomIds[j]) {
invIdx[count++] = i;
break;
}
}
}

if (count > 0) {
s32 idx = invIdx[rand_int(count - 1)];
gPlayerData.invItems[idx] = ITEM_DRIED_SHROOM;
}
}

0 comments on commit 1af34fd

Please sign in to comment.