From 162c83fcff2ee8d3b07331c62bafe60334d3a4a5 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 30 Sep 2018 12:27:51 +0200 Subject: [PATCH] Bestow --- asm/macros/battle_script.inc | 5 ++++ data/battle_scripts_1.s | 14 +++++++++ include/battle_util.h | 1 + include/constants/battle_move_effects.h | 1 + include/constants/battle_script_commands.h | 1 + include/constants/battle_string_ids.h | 1 + src/battle_message.c | 2 ++ src/battle_script_commands.c | 33 +++++++++++++++++++--- src/battle_util.c | 19 +++++++++++++ src/data/battle_moves.h | 2 +- 10 files changed, 74 insertions(+), 5 deletions(-) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index ca7f453d5..d24a0e293 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -1445,6 +1445,11 @@ .4byte \ptr .endm + .macro trybestow ptr + various BS_ATTACKER, VARIOUS_BESTOW + .4byte \ptr + .endm + .macro invertstatstages battler various \battler, VARIOUS_INVERT_STAT_STAGES .endm diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 3aa4f2149..38e6f853f 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -325,6 +325,20 @@ gBattleScriptsForMoveEffects:: @ 82D86A8 .4byte BattleScript_EffectPowerTrick .4byte BattleScript_EffectFlameBurst .4byte BattleScript_EffectAfterYou + .4byte BattleScript_EffectBestow + +BattleScript_EffectBestow: + attackcanceler + accuracycheck BattleScript_PrintMoveMissed, NO_ACC_CALC_CHECK_LOCK_ON + attackstring + ppreduce + jumpifsubstituteblocks BattleScript_ButItFailed + trybestow BattleScript_ButItFailed + attackanimation + waitanimation + printstring STRINGID_BESTOWITEMGIVING + waitmessage 0x40 + goto BattleScript_MoveEnd BattleScript_EffectAfterYou: attackcanceler diff --git a/include/battle_util.h b/include/battle_util.h index 3f14bd59f..ede49e10d 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -92,5 +92,6 @@ u16 GetMegaEvolutionSpecies(u16 preEvoSpecies, u16 heldItemId); bool32 CanMegaEvolve(u8 battlerId); void UndoMegaEvolution(u8 monId); bool32 DoBattlersShareType(u32 battler1, u32 battler2); +bool32 CanBattlerGetOrLoseItem(u8 battlerId, u16 itemId); #endif // GUARD_BATTLE_UTIL_H diff --git a/include/constants/battle_move_effects.h b/include/constants/battle_move_effects.h index 9963a59b7..1816d3a50 100644 --- a/include/constants/battle_move_effects.h +++ b/include/constants/battle_move_effects.h @@ -314,5 +314,6 @@ #define EFFECT_POWER_TRICK 308 #define EFFECT_FLAME_BURST 309 #define EFFECT_AFTER_YOU 310 +#define EFFECT_BESTOW 311 #endif // GUARD_CONSTANTS_BATTLE_MOVE_EFFECTS_H diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index e6a6b8d66..bd70f718b 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -116,6 +116,7 @@ #define VARIOUS_CURE_STATUS 62 #define VARIOUS_POWER_TRICK 63 #define VARIOUS_AFTER_YOU 64 +#define VARIOUS_BESTOW 65 // atk80, dmg manipulation #define ATK80_DMG_CHANGE_SIGN 0 diff --git a/include/constants/battle_string_ids.h b/include/constants/battle_string_ids.h index 667dc13d7..8f2e52908 100644 --- a/include/constants/battle_string_ids.h +++ b/include/constants/battle_string_ids.h @@ -509,6 +509,7 @@ #define STRINGID_INFESTATION 506 #define STRINGID_NOEFFECTONTARGET 507 #define STRINGID_BURSTINGFLAMESHIT 508 +#define STRINGID_BESTOWITEMGIVING 509 #define BATTLESTRINGS_COUNT 521 diff --git a/src/battle_message.c b/src/battle_message.c index 2f43cc84b..0ff8d1806 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -650,6 +650,7 @@ static const u8 sText_severely[] = _("severely "); static const u8 sText_Infestation[] = _("{B_DEF_NAME_WITH_PREFIX} has been afflicted\nwith an infestation by {B_ATK_NAME_WITH_PREFIX}!"); static const u8 sText_NoEffectOnTarget[] = _("It had no effect\non {B_DEF_NAME_WITH_PREFIX}!"); static const u8 sText_BurstingFlames[] = _("The bursting flames\nhit {B_SCR_ACTIVE_NAME_WITH_PREFIX}!"); +static const u8 sText_BestowItemGiving[] = _("{B_DEF_NAME_WITH_PREFIX} received {B_LAST_ITEM}\nfrom {B_ATK_NAME_WITH_PREFIX}!"); const u8 *const gBattleStringsTable[BATTLESTRINGS_COUNT] = { @@ -1151,6 +1152,7 @@ const u8 *const gBattleStringsTable[BATTLESTRINGS_COUNT] = sText_Infestation, sText_NoEffectOnTarget, sText_BurstingFlames, + sText_BestowItemGiving, }; const u16 gTerrainStringIds[] = diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index db5f39a66..7bd15de9a 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -7010,6 +7010,31 @@ static void atk76_various(void) gBattlescriptCurrInstr += 7; } return; + case VARIOUS_BESTOW: + if (gBattleMons[gBattlerAttacker].item == ITEM_NONE + || gBattleMons[gBattlerTarget].item != ITEM_NONE + || !CanBattlerGetOrLoseItem(gBattlerAttacker, gBattleMons[gBattlerAttacker].item) + || !CanBattlerGetOrLoseItem(gBattlerTarget, gBattleMons[gBattlerAttacker].item)) + { + gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 3); + } + else + { + gLastUsedItem = gBattleMons[gBattlerAttacker].item; + + gActiveBattler = gBattlerAttacker; + gBattleMons[gActiveBattler].item = ITEM_NONE; + BtlController_EmitSetMonData(0, REQUEST_HELDITEM_BATTLE, 0, 2, &gBattleMons[gActiveBattler].item); + MarkBattlerForControllerExec(gActiveBattler); + + gActiveBattler = gBattlerTarget; + gBattleMons[gActiveBattler].item = gLastUsedItem; + BtlController_EmitSetMonData(0, REQUEST_HELDITEM_BATTLE, 0, 2, &gBattleMons[gActiveBattler].item); + MarkBattlerForControllerExec(gActiveBattler); + + gBattlescriptCurrInstr += 7; + } + return; } gBattlescriptCurrInstr += 3; @@ -9687,10 +9712,10 @@ static void atkD2_tryswapitems(void) // trick // can't swap if two pokemon don't have an item // or if either of them is an enigma berry or a mail else if ((gBattleMons[gBattlerAttacker].item == 0 && gBattleMons[gBattlerTarget].item == 0) - || gBattleMons[gBattlerAttacker].item == ITEM_ENIGMA_BERRY - || gBattleMons[gBattlerTarget].item == ITEM_ENIGMA_BERRY - || IS_ITEM_MAIL(gBattleMons[gBattlerAttacker].item) - || IS_ITEM_MAIL(gBattleMons[gBattlerTarget].item)) + || !CanBattlerGetOrLoseItem(gBattlerAttacker, gBattleMons[gBattlerAttacker].item) + || !CanBattlerGetOrLoseItem(gBattlerAttacker, gBattleMons[gBattlerTarget].item) + || !CanBattlerGetOrLoseItem(gBattlerTarget, gBattleMons[gBattlerTarget].item) + || !CanBattlerGetOrLoseItem(gBattlerTarget, gBattleMons[gBattlerAttacker].item)) { gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 1); } diff --git a/src/battle_util.c b/src/battle_util.c index 17ce185af..2e2924101 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -24,6 +24,7 @@ #include "link.h" #include "berry.h" #include "pokedex.h" +#include "mail.h" #include "constants/battle_config.h" extern u8 weather_get_current(void); @@ -5680,3 +5681,21 @@ bool32 DoBattlersShareType(u32 battler1, u32 battler2) else return FALSE; } + +bool32 CanBattlerGetOrLoseItem(u8 battlerId, u16 itemId) +{ + u16 species = gBattleMons[battlerId].species; + + if (IS_ITEM_MAIL(itemId)) + return FALSE; + else if (itemId == ITEM_ENIGMA_BERRY) + return FALSE; + else if (species == SPECIES_KYOGRE && itemId == ITEM_BLUE_ORB) + return FALSE; + else if (species == SPECIES_GROUDON && itemId == ITEM_RED_ORB) + return FALSE; + else if (ItemId_GetHoldEffect(itemId) == HOLD_EFFECT_MEGA_STONE && GetMegaEvolutionSpecies(species, itemId) != SPECIES_NONE) + return FALSE; + else + return TRUE; +} diff --git a/src/data/battle_moves.h b/src/data/battle_moves.h index 5e7637a0e..0a4248540 100644 --- a/src/data/battle_moves.h +++ b/src/data/battle_moves.h @@ -6201,7 +6201,7 @@ const struct BattleMove gBattleMoves[MOVES_COUNT] = .split = SPLIT_SPECIAL, }, { // MOVE_BESTOW - .effect = EFFECT_PLACEHOLDER, // Needs a custom move effect + .effect = EFFECT_BESTOW, .power = 0, .type = TYPE_NORMAL, .accuracy = 0,