diff options
author | Daniel Harding <33dannye@gmail.com> | 2020-05-16 21:42:24 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-16 21:42:24 -0500 |
commit | 8a924f1f783572ff395f617f99546b4c949c8b04 (patch) | |
tree | 1b6c7de331cb983256651b11b8adf413a3a434f1 /engine/battle/move_effects/protect.asm | |
parent | 88d7e9a34a8b610b358cec1ccc6660634ca9ce80 (diff) | |
parent | ed94962edf1668aba3f60938e8a5ba8040e2a59c (diff) |
Merge pull request #30 from entrpntr/spring-cleaning
Spring Cleaning
Diffstat (limited to 'engine/battle/move_effects/protect.asm')
-rw-r--r-- | engine/battle/move_effects/protect.asm | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/engine/battle/move_effects/protect.asm b/engine/battle/move_effects/protect.asm new file mode 100644 index 00000000..9f3899a9 --- /dev/null +++ b/engine/battle/move_effects/protect.asm @@ -0,0 +1,75 @@ +BattleCommand_Protect: +; protect + call ProtectChance + ret c + + ld a, BATTLE_VARS_SUBSTATUS1 + call GetBattleVarAddr + set SUBSTATUS_PROTECT, [hl] + + call AnimateCurrentMove + + ld hl, ProtectedItselfText + jp StdBattleTextbox + +ProtectChance: + ld de, wPlayerProtectCount + ldh a, [hBattleTurn] + and a + jr z, .asm_37736 + ld de, wEnemyProtectCount +.asm_37736 + + call CheckOpponentWentFirst + jr nz, .failed + +; Can't have a substitute. + + ld a, BATTLE_VARS_SUBSTATUS4 + call GetBattleVar + bit SUBSTATUS_SUBSTITUTE, a + jr nz, .failed + +; Halve the chance of a successful Protect for each consecutive use. + + ld b, $ff + ld a, [de] + ld c, a +.loop + ld a, c + and a + jr z, .done + dec c + + srl b + ld a, b + and a + jr nz, .loop + jr .failed +.done + +.rand + call BattleRandom + and a + jr z, .rand + + dec a + cp b + jr nc, .failed + +; Another consecutive Protect use. + + ld a, [de] + inc a + ld [de], a + + and a + ret + +.failed + xor a + ld [de], a + call AnimateFailedMove + call PrintButItFailed + scf + ret |