diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 6574e26ab..13a96c89a 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -9560,3 +9560,9 @@ BattleScript_MagicianActivates:: call BattleScript_AbilityPopUp call BattleScript_ItemSteal return + +BattleScript_SymbiosisActivates:: + call BattleScript_AbilityPopUp + printstring STRINGID_SYMBIOSISITEMPASS + waitmessage B_WAIT_TIME_LONG + return diff --git a/include/battle_scripts.h b/include/battle_scripts.h index 740d27148..f77431e99 100644 --- a/include/battle_scripts.h +++ b/include/battle_scripts.h @@ -419,5 +419,6 @@ extern const u8 BattleScript_MagicianActivates[]; extern const u8 BattleScript_BeakBlastSetUp[]; extern const u8 BattleScript_BeakBlastBurn[]; extern const u8 BattleScript_DefDownSpeedUp[]; +extern const u8 BattleScript_SymbiosisActivates[]; #endif // GUARD_BATTLE_SCRIPTS_H diff --git a/src/battle_message.c b/src/battle_message.c index 3e2d9abd9..d2b02e341 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -601,7 +601,7 @@ static const u8 sText_HarvestBerry[] = _("{B_ATK_NAME_WITH_PREFIX} harvested\nit static const u8 sText_LastAbilityRaisedBuff1[] = _("{B_ATK_NAME_WITH_PREFIX}'s {B_LAST_ABILITY}\nraised its {B_BUFF1}!"); static const u8 sText_MagicBounceActivates[] = _("The {B_DEF_NAME_WITH_PREFIX} bounced the\n{B_ATK_NAME_WITH_PREFIX} back!"); static const u8 sText_ProteanTypeChange[] = _("{B_ATK_NAME_WITH_PREFIX}'s {B_ATK_ABILITY} transformed\nit into the {B_BUFF1} type!"); -static const u8 sText_SymbiosisItemPass[] = _("{B_ATK_NAME_WITH_PREFIX} passed its {B_LAST_ITEM}\nto {B_SCR_ACTIVE_NAME_WITH_PREFIX} through {B_ATK_ABILITY}!"); +static const u8 sText_SymbiosisItemPass[] = _("{B_SCR_ACTIVE_NAME_WITH_PREFIX} passed its {B_LAST_ITEM}\nto {B_DEF_NAME_WITH_PREFIX} through {B_LAST_ABILITY}!"); static const u8 sText_StealthRockDmg[] = _("Pointed stones dug into\n{B_SCR_ACTIVE_NAME_WITH_PREFIX}!"); static const u8 sText_ToxicSpikesAbsorbed[] = _("The poison spikes disappeared\nfrom around the opposing team's feet!"); static const u8 sText_ToxicSpikesPoisoned[] = _("{B_SCR_ACTIVE_NAME_WITH_PREFIX} was poisoned!"); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index d6edb0ab2..6657aa9c0 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -7030,6 +7030,53 @@ static bool32 TryCheekPouch(u32 battlerId, u32 itemId) return FALSE; } +// Notes: +// Symbiosis applies before a move and after a gem is used in Gen 6. +// Symbiosis applies if an ally consumes a berry through Bug Bite / Pluck and doesn't have an item. +// Symbiosis does not apply if an ally has an item stolen, knocked off, or destroyed by Incinerate. +// Symbiosis does not apply after Eject Button (except in Gen 6, where it is bugged). +// Symbiosis does not apply if an ally tricks away their item and does not receive one in return. + +//itemId is used to check Eject Button or Eject Pack +static bool32 TrySymbiosis(u32 battler, u32 itemId) +{ + u32 ally = battler ^ BIT_FLANK; + + if (!gBattleStruct->itemStolen[gBattlerPartyIndexes[battler]].stolen + && gBattleStruct->changedItems[battler] == ITEM_NONE + && ItemId_GetHoldEffect(itemId) != HOLD_EFFECT_EJECT_BUTTON + && ItemId_GetHoldEffect(itemId) != HOLD_EFFECT_EJECT_PACK + && GetBattlerAbility(ally) == ABILITY_SYMBIOSIS + && gBattleMons[battler].item == ITEM_NONE + && gBattleMons[ally].item != ITEM_NONE + && CanBattlerGetOrLoseItem(battler, gBattleMons[ally].item) + && CanBattlerGetOrLoseItem(ally, gBattleMons[ally].item) + && gBattleMons[battler].hp != 0 + && gBattleMons[ally].hp != 0) + { + gLastUsedItem = gBattleMons[ally].item; + + gActiveBattler = ally; + gBattleMons[ally].item = ITEM_NONE; + BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[battler].item), &gBattleMons[battler].item); + MarkBattlerForControllerExec(ally); + + gActiveBattler = battler; + gBattleMons[battler].item = gLastUsedItem; + BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[battler].item), &gBattleMons[battler].item); + MarkBattlerForControllerExec(battler); + gBattleResources->flags->flags[battler] &= ~RESOURCE_FLAG_UNBURDEN; + + gLastUsedAbility = gBattleMons[ally].ability; + gBattleScripting.battler = gBattlerAbility = ally; + gBattlerTarget = battler; + BattleScriptPush(gBattlescriptCurrInstr + 2); + gBattlescriptCurrInstr = BattleScript_SymbiosisActivates; + return TRUE; + } + return FALSE; +} + static void Cmd_removeitem(void) { u16 itemId = 0; @@ -7048,7 +7095,7 @@ static void Cmd_removeitem(void) MarkBattlerForControllerExec(gActiveBattler); ClearBattlerItemEffectHistory(gActiveBattler); - if (!TryCheekPouch(gActiveBattler, itemId)) + if (!TryCheekPouch(gActiveBattler, itemId) && !TrySymbiosis(gActiveBattler, itemId)) gBattlescriptCurrInstr += 2; } @@ -8830,7 +8877,8 @@ static void Cmd_various(void) MarkBattlerForControllerExec(gActiveBattler); gBattleResources->flags->flags[gBattlerTarget] &= ~RESOURCE_FLAG_UNBURDEN; - gBattlescriptCurrInstr += 7; + if (!TrySymbiosis(gBattlerAttacker, gLastUsedItem)) + gBattlescriptCurrInstr += 7; } return; case VARIOUS_ARGUMENT_TO_MOVE_EFFECT: @@ -12623,6 +12671,7 @@ static void Cmd_tryswapitems(void) // trick else { CheckSetUnburden(gBattlerAttacker); + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_ITEM_SWAP_GIVEN; // attacker's item -> <- nothing } }