Sort out ohko moves

This commit is contained in:
DizzyEggg 2020-02-08 10:39:22 +01:00
parent 90442ffbc2
commit 41f0c0acb5

View File

@ -8854,66 +8854,54 @@ static void Cmd_setlightscreen(void)
static void Cmd_tryKO(void) static void Cmd_tryKO(void)
{ {
u8 holdEffect, param; bool32 lands = FALSE;
u32 holdEffect = GetBattlerHoldEffect(gBattlerTarget, TRUE);
if (gBattleMons[gBattlerTarget].item == ITEM_ENIGMA_BERRY)
{
holdEffect = gEnigmaBerries[gBattlerTarget].holdEffect;
param = gEnigmaBerries[gBattlerTarget].holdEffectParam;
}
else
{
holdEffect = ItemId_GetHoldEffect(gBattleMons[gBattlerTarget].item);
param = ItemId_GetHoldEffectParam(gBattleMons[gBattlerTarget].item);
}
gPotentialItemEffectBattler = gBattlerTarget; gPotentialItemEffectBattler = gBattlerTarget;
if (holdEffect == HOLD_EFFECT_FOCUS_BAND
if (holdEffect == HOLD_EFFECT_FOCUS_BAND && (Random() % 100) < param) && (Random() % 100) < GetBattlerHoldEffectParam(gBattlerTarget))
{ {
RecordItemEffectBattle(gBattlerTarget, HOLD_EFFECT_FOCUS_BAND);
gSpecialStatuses[gBattlerTarget].focusBanded = 1; gSpecialStatuses[gBattlerTarget].focusBanded = 1;
RecordItemEffectBattle(gBattlerTarget, holdEffect);
}
else if (holdEffect == HOLD_EFFECT_FOCUS_SASH && BATTLER_MAX_HP(gBattlerTarget))
{
gSpecialStatuses[gBattlerTarget].focusSashed = 1;
RecordItemEffectBattle(gBattlerTarget, holdEffect);
} }
if (gBattleMons[gBattlerTarget].ability == ABILITY_STURDY) if (GetBattlerAbility(gBattlerTarget) == ABILITY_STURDY)
{ {
gMoveResultFlags |= MOVE_RESULT_MISSED; gMoveResultFlags |= MOVE_RESULT_MISSED;
gLastUsedAbility = ABILITY_STURDY; gLastUsedAbility = ABILITY_STURDY;
gBattlescriptCurrInstr = BattleScript_SturdyPreventsOHKO; gBattlescriptCurrInstr = BattleScript_SturdyPreventsOHKO;
RecordAbilityBattle(gBattlerTarget, ABILITY_STURDY); gBattlerAbility = gBattlerTarget;
} }
else else
{ {
u16 chance; if ((((gStatuses3[gBattlerTarget] & STATUS3_ALWAYS_HITS)
if (!(gStatuses3[gBattlerTarget] & STATUS3_ALWAYS_HITS)) && gDisableStructs[gBattlerTarget].battlerWithSureHit == gBattlerAttacker)
|| GetBattlerAbility(gBattlerAttacker) == ABILITY_NO_GUARD
|| GetBattlerAbility(gBattlerTarget) == ABILITY_NO_GUARD)
&& gBattleMons[gBattlerAttacker].level >= gBattleMons[gBattlerTarget].level)
{ {
chance = gBattleMoves[gCurrentMove].accuracy + (gBattleMons[gBattlerAttacker].level - gBattleMons[gBattlerTarget].level); lands = TRUE;
if (Random() % 100 + 1 < chance && gBattleMons[gBattlerAttacker].level >= gBattleMons[gBattlerTarget].level)
chance = TRUE;
else
chance = FALSE;
}
else if (gDisableStructs[gBattlerTarget].battlerWithSureHit == gBattlerAttacker
&& gBattleMons[gBattlerAttacker].level >= gBattleMons[gBattlerTarget].level)
{
chance = TRUE;
} }
else else
{ {
chance = gBattleMoves[gCurrentMove].accuracy + (gBattleMons[gBattlerAttacker].level - gBattleMons[gBattlerTarget].level); u16 odds = gBattleMoves[gCurrentMove].accuracy + (gBattleMons[gBattlerAttacker].level - gBattleMons[gBattlerTarget].level);
if (Random() % 100 + 1 < chance && gBattleMons[gBattlerAttacker].level >= gBattleMons[gBattlerTarget].level) if (Random() % 100 + 1 < odds && gBattleMons[gBattlerAttacker].level >= gBattleMons[gBattlerTarget].level)
chance = TRUE; lands = TRUE;
else
chance = FALSE;
} }
if (chance)
if (lands)
{ {
if (gProtectStructs[gBattlerTarget].endured) if (gProtectStructs[gBattlerTarget].endured)
{ {
gBattleMoveDamage = gBattleMons[gBattlerTarget].hp - 1; gBattleMoveDamage = gBattleMons[gBattlerTarget].hp - 1;
gMoveResultFlags |= MOVE_RESULT_FOE_ENDURED; gMoveResultFlags |= MOVE_RESULT_FOE_ENDURED;
} }
else if (gSpecialStatuses[gBattlerTarget].focusBanded) else if (gSpecialStatuses[gBattlerTarget].focusBanded || gSpecialStatuses[gBattlerTarget].focusSashed)
{ {
gBattleMoveDamage = gBattleMons[gBattlerTarget].hp - 1; gBattleMoveDamage = gBattleMons[gBattlerTarget].hp - 1;
gMoveResultFlags |= MOVE_RESULT_FOE_HUNG_ON; gMoveResultFlags |= MOVE_RESULT_FOE_HUNG_ON;