ref: e1da37e03303b1a6dd6531d8a044339f337731a1
parent: 0c446367ce79dfe2a26f4bd7668036477811a279
author: mid-kid <esteve.varela@gmail.com>
date: Wed Apr 4 18:35:47 EDT 2018
Comment SapHealth Also fixed some Beat Up inconsistencies to make it more readable.
--- a/engine/battle/effect_commands.asm
+++ b/engine/battle/effect_commands.asm
@@ -4136,6 +4136,7 @@
SapHealth: ; 36011
+ ; Divide damage by 2, store it in hDividend
ld hl, wCurDamage
ld a, [hli]
srl a
@@ -4145,10 +4146,11 @@
rr a
ld [hDividend + 1], a
or b
- jr nz, .ok1
- ld a, $1
+ jr nz, .at_least_one
+ ld a, 1
ld [hDividend + 1], a
-.ok1
+.at_least_one
+
ld hl, wBattleMonHP
ld de, wBattleMonMaxHP
ld a, [hBattleTurn]
@@ -4157,6 +4159,8 @@
ld hl, wEnemyMonHP
ld de, wEnemyMonMaxHP
.battlemonhp
+
+ ; Store current HP in little endian wBuffer3/4
ld bc, wBuffer4
ld a, [hli]
ld [bc], a
@@ -4163,6 +4167,8 @@
ld a, [hl]
dec bc
ld [bc], a
+
+ ; Store max HP in little endian wBuffer1/2
ld a, [de]
dec bc
ld [bc], a
@@ -4170,6 +4176,8 @@
ld a, [de]
dec bc
ld [bc], a
+
+ ; Add hDividend to current HP and copy it to little endian wBuffer5/6
ld a, [hDividend + 1]
ld b, [hl]
add b
@@ -4180,7 +4188,9 @@
adc b
ld [hli], a
ld [wBuffer6], a
- jr c, .okay2
+ jr c, .max_hp
+
+ ; Substract current HP from max HP (to see if we have more than max HP)
ld a, [hld]
ld b, a
ld a, [de]
@@ -4191,8 +4201,10 @@
ld a, [de]
inc de
sbc b
- jr nc, .okay3
-.okay2
+ jr nc, .finish
+
+.max_hp
+ ; Load max HP into current HP and copy it to little endian wBuffer5/6
ld a, [de]
ld [hld], a
ld [wBuffer5], a
@@ -4201,7 +4213,8 @@
ld [hli], a
ld [wBuffer6], a
inc de
-.okay3
+
+.finish
ld a, [hBattleTurn]
and a
hlcoord 10, 9
--- a/engine/battle/move_effects/beat_up.asm
+++ b/engine/battle/move_effects/beat_up.asm
@@ -5,9 +5,11 @@
ld a, [hBattleTurn]
and a
jp nz, .enemy_beats_up
+
ld a, [wPlayerSubStatus3]
bit SUBSTATUS_IN_LOOP, a
jr nz, .next_mon
+
ld c, 20
call DelayFrames
xor a
@@ -51,11 +53,13 @@
ld [wBeatUpHitAtLeastOnce], a
ld hl, BeatUpAttackText
call StdBattleTextBox
+
ld a, [wEnemyMonSpecies]
ld [wCurSpecies], a
call GetBaseData
ld a, [wBaseDefense]
ld c, a
+
push bc
ld a, MON_SPECIES
call GetBeatupMonLocation
@@ -65,6 +69,7 @@
ld a, [wBaseAttack]
pop bc
ld b, a
+
push bc
ld a, MON_LEVEL
call GetBeatupMonLocation
@@ -71,6 +76,7 @@
ld a, [hl]
ld e, a
pop bc
+
ld a, [wPlayerMoveStructPower]
ld d, a
ret
@@ -78,21 +84,22 @@
.enemy_beats_up
ld a, [wEnemySubStatus3]
bit SUBSTATUS_IN_LOOP, a
- jr nz, .not_first_enemy_beatup
+ jr nz, .enemy_next_mon
xor a
ld [wEnemyRolloutCount], a
ld [wd002], a
ld [wBeatUpHitAtLeastOnce], a
- jr .enemy_continue
+ jr .enemy_got_mon
-.not_first_enemy_beatup
+.enemy_next_mon
ld a, [wEnemyRolloutCount]
ld b, a
ld a, [wOTPartyCount]
sub b
ld [wd002], a
-.enemy_continue
+
+.enemy_got_mon
ld a, [wBattleMode]
dec a
jr z, .wild
@@ -122,6 +129,7 @@
call AddNTimes
ld de, wStringBuffer1
call CopyBytes
+
.got_enemy_nick
ld a, MON_HP
call GetBeatupMonLocation
@@ -128,6 +136,7 @@
ld a, [hli]
or [hl]
jp z, .beatup_fail
+
ld a, [wd002]
ld b, a
ld a, [wCurOTMon]
@@ -134,7 +143,6 @@
cp b
ld hl, wEnemyMonStatus
jr z, .active_enemy
-
ld a, MON_STATUS
call GetBeatupMonLocation
.active_enemy
@@ -157,11 +165,13 @@
.finish_beatup
ld hl, BeatUpAttackText
call StdBattleTextBox
+
ld a, [wBattleMonSpecies]
ld [wCurSpecies], a
call GetBaseData
ld a, [wBaseDefense]
ld c, a
+
push bc
ld a, MON_SPECIES
call GetBeatupMonLocation
@@ -171,6 +181,7 @@
ld a, [wBaseAttack]
pop bc
ld b, a
+
push bc
ld a, MON_LEVEL
call GetBeatupMonLocation
@@ -177,6 +188,7 @@
ld a, [hl]
ld e, a
pop bc
+
ld a, [wEnemyMoveStructPower]
ld d, a
ret