ref: aaf77957bf6e2a149827461a3126fea0a85102c9
parent: d07cd794431090033b62b8438530a99e1f52bfad
author: yenatch <[email protected]>
date: Mon Sep 9 17:50:34 EDT 2013
comment protect and endure move effects
--- a/battle/effect_commands.asm
+++ b/battle/effect_commands.asm
@@ -9547,66 +9547,77 @@
BattleCommand55: ; 37618
; protect
-
- call Function0x3762c
+ call ProtectChance
ret c
+
ld a, BATTLE_VARS_SUBSTATUS1
call GetBattleVarPair
- set 2, [hl]
+ set SUBSTATUS_PROTECT, [hl]
+
call Function0x37e01
+
ld hl, ProtectedItselfText
jp StdBattleTextBox
; 3762c
-Function0x3762c: ; 3762c
- ld de, $c679
+ProtectChance: ; 3762c
+
+ ld de, PlayerProtectCount
ld a, [hBattleTurn]
and a
jr z, .asm_37637
- ld de, $c681
-
+ ld de, EnemyProtectCount
.asm_37637
+
call Function0x36abf
- jr nz, .asm_37665
+ jr nz, .failed
- ld a, $3
+; Can't have a substitute.
+
+ ld a, BATTLE_VARS_SUBSTATUS4
call CleanGetBattleVarPair
- bit 4, a
- jr nz, .asm_37665
+ 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
-.asm_37649
+.loop
ld a, c
and a
- jr z, .asm_37656
-
+ jr z, .done
dec c
+
srl b
ld a, b
and a
- jr nz, .asm_37649
+ jr nz, .loop
+ jr .failed
+.done
- jr .asm_37665
-
-.asm_37656
+.rand
call BattleRandom
and a
- jr z, .asm_37656
+ jr z, .rand
dec a
cp b
- jr nc, .asm_37665
+ jr nc, .failed
+; Another consecutive Protect use.
+
ld a, [de]
inc a
ld [de], a
+
and a
ret
-.asm_37665
+
+.failed
xor a
ld [de], a
call Function0x37e77
@@ -9619,13 +9630,15 @@
BattleCommand5a: ; 3766f
; endure
- call Function0x3762c
+ call ProtectChance
ret c
ld a, BATTLE_VARS_SUBSTATUS1
call GetBattleVarPair
set SUBSTATUS_ENDURE, [hl]
+
call Function0x37e01
+
ld hl, BracedItselfText
jp StdBattleTextBox
; 37683