Skip to content

Commit 6970092

Browse files
committed
Finished Test, Dark and Ghost switched
1 parent 0c3603d commit 6970092

File tree

2 files changed

+813
-449
lines changed

2 files changed

+813
-449
lines changed

engine/battle/core.asm

+185-18
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ HandleBetweenTurnEffects:
264264
call HandlePerishSong
265265
call CheckFaint_PlayerThenEnemy
266266
ret c
267+
call HandleTrickRoom
268+
call CheckFaint_PlayerThenEnemy
269+
ret c
267270
jr .NoMoreFaintingConditions
268271

269272
.CheckEnemyFirst:
@@ -281,6 +284,9 @@ HandleBetweenTurnEffects:
281284
call HandlePerishSong
282285
call CheckFaint_EnemyThenPlayer
283286
ret c
287+
call HandleTrickRoom
288+
call CheckFaint_PlayerThenEnemy
289+
ret c
284290

285291
.NoMoreFaintingConditions:
286292
call HandleLeftovers
@@ -535,6 +541,10 @@ DetermineMoveOrder:
535541
ld c, 2
536542
call CompareBytes
537543
jr z, .speed_tie
544+
ld a, [wTrickRoom]
545+
ld d, a
546+
and d ; Is Trick Room active?
547+
jp nz, .trick_room
538548
jp nc, .player_first
539549
jp .enemy_first
540550

@@ -551,6 +561,7 @@ DetermineMoveOrder:
551561
call BattleRandom
552562
cp 50 percent + 1
553563
jp c, .enemy_first
564+
554565
.player_first
555566
scf
556567
ret
@@ -559,6 +570,27 @@ DetermineMoveOrder:
559570
and a
560571
ret
561572

573+
.trick_room
574+
ld hl, wTrickRoom
575+
jp nc, .enemy_first
576+
jp .player_first
577+
578+
579+
HandleTrickRoom:
580+
ld hl, wTrickRoom
581+
ld a, [hl]
582+
and a
583+
ret z
584+
dec [hl]
585+
ret nz
586+
ld hl, TrickRoomEndedText
587+
jp StdBattleTextbox
588+
589+
.end_trick_room
590+
ld hl, TrickRoomEndedText
591+
jp StdBattleTextbox
592+
593+
562594
CheckContestBattleOver:
563595
ld a, [wBattleType]
564596
cp BATTLETYPE_CONTEST
@@ -609,13 +641,15 @@ ParsePlayerAction:
609641
bit SUBSTATUS_ENCORED, [hl]
610642
jr z, .not_encored
611643
ld a, [wLastPlayerMove]
644+
and a
645+
jr z, .not_encored
612646
ld [wCurPlayerMove], a
613647
jr .encored
614648

615649
.not_encored
616650
ld a, [wBattlePlayerAction]
617651
cp BATTLEPLAYERACTION_SWITCH
618-
jr z, .reset_rage
652+
jp z, .reset_rage
619653
and a
620654
jr nz, .reset_bide
621655
ld a, [wPlayerSubStatus3]
@@ -639,6 +673,7 @@ ParsePlayerAction:
639673
ldh [hBGMapMode], a
640674
pop af
641675
ret nz
676+
call SetChoiceLock
642677

643678
.encored
644679
call SetPlayerTurn
@@ -829,8 +864,8 @@ GetMovePriority:
829864

830865
ld b, a
831866

832-
; Vital Throw goes last.
833-
cp VITAL_THROW
867+
; Trick Room goes last.
868+
cp TRICK_ROOM
834869
ld a, 0
835870
ret z
836871

@@ -1294,9 +1329,33 @@ HandleLeftovers:
12941329
ld [wNamedObjectIndex], a
12951330
call GetItemName
12961331
ld a, b
1332+
cp HELD_BLACK_SLUDGE
1333+
jr nz, .check_leftovers
1334+
1335+
; check if user is poison type
1336+
ld hl, wBattleMonType1
1337+
ldh a, [hBattleTurn]
1338+
and a
1339+
jr z, .gottype
1340+
ld hl, wEnemyMonType1
1341+
.gottype
1342+
ld a, [hli]
1343+
cp POISON
1344+
jp z, .get_hp
1345+
ld a, [hl]
1346+
cp POISON
1347+
jp z, .get_hp
1348+
1349+
; User is not poison, deal damage
1350+
call GetEighthMaxHP
1351+
call SubtractHPFromTarget
1352+
ld hl, BattleText_UsersHurtByStringBuffer1
1353+
jp StdBattleTextbox
1354+
1355+
.check_leftovers
12971356
cp HELD_LEFTOVERS
12981357
ret nz
1299-
1358+
.get_hp
13001359
ld hl, wBattleMonHP
13011360
ldh a, [hBattleTurn]
13021361
and a
@@ -1323,6 +1382,7 @@ HandleLeftovers:
13231382
ld hl, BattleText_TargetRecoveredWithItem
13241383
jp StdBattleTextbox
13251384

1385+
13261386
HandleMysteryberry:
13271387
ldh a, [hSerialConnectionStatus]
13281388
cp USING_EXTERNAL_CLOCK
@@ -1687,14 +1747,22 @@ HandleWeather:
16871747

16881748
ld hl, wWeatherCount
16891749
dec [hl]
1690-
jr z, .ended
1750+
jr nz, .continues
1751+
1752+
; ended
1753+
ld hl, .WeatherEndedMessages
1754+
call .PrintWeatherMessage
1755+
xor a
1756+
ld [wBattleWeather], a
1757+
ret
16911758

1759+
.continues
16921760
ld hl, .WeatherMessages
16931761
call .PrintWeatherMessage
16941762

16951763
ld a, [wBattleWeather]
16961764
cp WEATHER_SANDSTORM
1697-
ret nz
1765+
jr nz, .check_hail
16981766

16991767
ldh a, [hSerialConnectionStatus]
17001768
cp USING_EXTERNAL_CLOCK
@@ -1751,12 +1819,51 @@ HandleWeather:
17511819
ld hl, SandstormHitsText
17521820
jp StdBattleTextbox
17531821

1754-
.ended
1755-
ld hl, .WeatherEndedMessages
1756-
call .PrintWeatherMessage
1757-
xor a
1758-
ld [wBattleWeather], a
1759-
ret
1822+
.check_hail
1823+
ld a, [wBattleWeather]
1824+
cp WEATHER_HAIL
1825+
ret nz
1826+
1827+
ldh a, [hSerialConnectionStatus]
1828+
cp USING_EXTERNAL_CLOCK
1829+
jr z, .enemy_first_hail
1830+
1831+
; player first
1832+
call SetPlayerTurn
1833+
call .HailDamage
1834+
call SetEnemyTurn
1835+
jr .HailDamage
1836+
1837+
.enemy_first_hail
1838+
call SetEnemyTurn
1839+
call .HailDamage
1840+
call SetPlayerTurn
1841+
1842+
.HailDamage:
1843+
ld a, BATTLE_VARS_SUBSTATUS3
1844+
call GetBattleVar
1845+
bit SUBSTATUS_UNDERGROUND, a
1846+
ret nz
1847+
1848+
ld hl, wBattleMonType1
1849+
ldh a, [hBattleTurn]
1850+
and a
1851+
jr z, .ok1
1852+
ld hl, wEnemyMonType1
1853+
.ok1
1854+
ld a, [hli]
1855+
cp ICE
1856+
ret z
1857+
1858+
ld a, [hl]
1859+
cp ICE
1860+
ret z
1861+
1862+
call GetSixteenthMaxHP
1863+
call SubtractHPFromUser
1864+
1865+
ld hl, PeltedByHailText
1866+
jp StdBattleTextbox
17601867

17611868
.PrintWeatherMessage:
17621869
ld a, [wBattleWeather]
@@ -1775,12 +1882,14 @@ HandleWeather:
17751882
dw BattleText_RainContinuesToFall
17761883
dw BattleText_TheSunlightIsStrong
17771884
dw BattleText_TheSandstormRages
1885+
dw BattleText_HailContinuesToFall
17781886

17791887
.WeatherEndedMessages:
17801888
; entries correspond to WEATHER_* constants
17811889
dw BattleText_TheRainStopped
17821890
dw BattleText_TheSunlightFaded
17831891
dw BattleText_TheSandstormSubsided
1892+
dw BattleText_TheHailStopped
17841893

17851894
SubtractHPFromTarget:
17861895
call SubtractHP
@@ -4172,7 +4281,7 @@ PursuitSwitch:
41724281

41734282
ld a, BATTLE_VARS_MOVE
41744283
call GetBattleVarAddr
4175-
ld a, $ff
4284+
xor a ; NO_MOVE
41764285
ld [hl], a
41774286

41784287
pop af
@@ -5808,6 +5917,7 @@ ParseEnemyAction:
58085917
bit SUBSTATUS_ENCORED, [hl]
58095918
ld a, [wLastEnemyMove]
58105919
jp nz, .finish
5920+
call SetChoiceLock
58115921
ld hl, wEnemyMonMoves
58125922
ld b, 0
58135923
add hl, bc
@@ -5888,6 +5998,7 @@ ParseEnemyAction:
58885998

58895999
.skip_load
58906000
call SetEnemyTurn
6001+
call SetChoiceLock
58916002
callfar UpdateMoveData
58926003
call CheckEnemyLockedIn
58936004
jr nz, .raging
@@ -5924,6 +6035,30 @@ ParseEnemyAction:
59246035
ld a, STRUGGLE
59256036
jr .finish
59266037

6038+
SetChoiceLock:
6039+
push hl
6040+
push bc
6041+
callfar GetUserItem
6042+
ld a, b
6043+
cp HELD_CHOICE_BOOST
6044+
jr nz, .done
6045+
ld hl, wPlayerEncoreCount
6046+
ldh a, [hBattleTurn]
6047+
and a
6048+
jr z, .GotEncoreCount
6049+
ld hl, wEnemyEncoreCount
6050+
.GotEncoreCount
6051+
ld a, -1 ; Set encore count to 255
6052+
ld [hl], a
6053+
ld a, BATTLE_VARS_SUBSTATUS5
6054+
call GetBattleVarAddr
6055+
set SUBSTATUS_ENCORED, [hl]
6056+
6057+
.done
6058+
pop bc
6059+
pop hl
6060+
ret
6061+
59276062
ResetVarsForSubstatusRage:
59286063
xor a
59296064
ld [wEnemyFuryCutterCount], a
@@ -6192,12 +6327,13 @@ LoadEnemyMon:
61926327
jr nc, .GenerateDVs
61936328

61946329
.CheckMagikarpArea:
6330+
; TODO: Replace GROUP_NONE and MAP_NONE with the map you want for large Magikarp.
61956331
; BUG: Magikarp in Lake of Rage are shorter, not longer (see docs/bugs_and_glitches.md)
61966332
ld a, [wMapGroup]
6197-
cp GROUP_LAKE_OF_RAGE
6333+
cp GROUP_NONE
61986334
jr z, .Happiness
61996335
ld a, [wMapNumber]
6200-
cp MAP_LAKE_OF_RAGE
6336+
cp MAP_NONE
62016337
jr z, .Happiness
62026338
; 40% chance of not flooring
62036339
call Random
@@ -6791,7 +6927,7 @@ BadgeStatBoosts:
67916927
rrca
67926928
ld c, a
67936929
ld a, d
6794-
and ((1 << ZEPHYRBADGE) | (1 << HIVEBADGE) | (1 << FOGBADGE) | (1 << STORMBADGE) | (1 << GLACIERBADGE) | (1 << RISINGBADGE))
6930+
and ((1 << ANCHORBADGE) | (1 << HIVEBADGE) | (1 << FOGBADGE) | (1 << STORMBADGE) | (1 << GLACIERBADGE) | (1 << RISINGBADGE))
67956931
or b
67966932
or c
67976933
ld b, a
@@ -7404,6 +7540,37 @@ BoostExp:
74047540
pop bc
74057541
ret
74067542

7543+
CheckOpponentFullHP:
7544+
; check if the opponent has full HP
7545+
; z: yes, nz: no
7546+
ld hl, wEnemyMonHP
7547+
ld a, [hBattleTurn]
7548+
and a
7549+
jr z, DoCheckFullHP
7550+
ld hl, wBattleMonHP
7551+
jr DoCheckFullHP
7552+
7553+
CheckFullHP:
7554+
; check if the user has full HP
7555+
; z: yes, nz: no
7556+
ld hl, wBattleMonHP
7557+
ld a, [hBattleTurn]
7558+
and a
7559+
jr z, DoCheckFullHP
7560+
ld hl, wEnemyMonHP
7561+
; fallthrough
7562+
DoCheckFullHP:
7563+
ld a, [hli]
7564+
ld b, a
7565+
ld a, [hli]
7566+
ld c, a
7567+
ld a, [hli]
7568+
cp b
7569+
ret nz
7570+
ld a, [hl]
7571+
cp c
7572+
ret
7573+
74077574
Text_MonGainedExpPoint:
74087575
text_far Text_Gained
74097576
text_asm
@@ -8123,9 +8290,9 @@ InitEnemyTrainer:
81238290
callfar GetTrainerAttributes
81248291
callfar ReadTrainerParty
81258292

8126-
; RIVAL1's first mon has no held item
8293+
; RIVALP's first mon has no held item
81278294
ld a, [wTrainerClass]
8128-
cp RIVAL1
8295+
cp POKEMON_PROF
81298296
jr nz, .ok
81308297
xor a
81318298
ld [wOTPartyMon1Item], a

0 commit comments

Comments
 (0)