summaryrefslogtreecommitdiff
path: root/engine/battle/move_effects/protect.asm
diff options
context:
space:
mode:
authorRangi <remy.oukaour+rangi42@gmail.com>2018-01-26 11:36:00 -0500
committerRangi <remy.oukaour+rangi42@gmail.com>2018-01-26 11:36:00 -0500
commit0cf4eb68955952659b0e94fbeae0a75fe36255ae (patch)
treef38113626f149a5f71b01212a6440c0f8926b662 /engine/battle/move_effects/protect.asm
parenta0cc4a33929f6aeb08a733c4a985c3bbb24ef55f (diff)
Move-unique effect commands consistently go in engine/battle/move_effects/
Diffstat (limited to 'engine/battle/move_effects/protect.asm')
-rw-r--r--engine/battle/move_effects/protect.asm80
1 files changed, 80 insertions, 0 deletions
diff --git a/engine/battle/move_effects/protect.asm b/engine/battle/move_effects/protect.asm
new file mode 100644
index 000000000..568ac00f8
--- /dev/null
+++ b/engine/battle/move_effects/protect.asm
@@ -0,0 +1,80 @@
+BattleCommand_Protect: ; 37618
+; protect
+ call ProtectChance
+ ret c
+
+ ld a, BATTLE_VARS_SUBSTATUS1
+ call GetBattleVarAddr
+ set SUBSTATUS_PROTECT, [hl]
+
+ call AnimateCurrentMove
+
+ ld hl, ProtectedItselfText
+ jp StdBattleTextBox
+; 3762c
+
+
+ProtectChance: ; 3762c
+
+ ld de, PlayerProtectCount
+ ld a, [hBattleTurn]
+ and a
+ jr z, .asm_37637
+ ld de, EnemyProtectCount
+.asm_37637
+
+ 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
+; 3766f