pokecrystal-board/engine/battle/ai/items.asm

833 lines
12 KiB
NASM
Raw Normal View History

2018-06-24 07:09:41 -07:00
AI_SwitchOrTryItem:
and a
ld a, [wBattleMode]
dec a
ret z
ld a, [wLinkMode]
and a
ret nz
2017-12-24 09:47:30 -08:00
farcall CheckEnemyLockedIn
ret nz
2018-01-23 14:39:09 -08:00
ld a, [wPlayerSubStatus5]
bit SUBSTATUS_CANT_RUN, a
2014-09-30 11:20:38 -07:00
jr nz, DontSwitch
2015-11-08 10:27:26 -08:00
ld a, [wEnemyWrapCount]
and a
2014-09-30 11:20:38 -07:00
jr nz, DontSwitch
ld hl, TrainerClassAttributes + TRNATTR_AI_ITEM_SWITCH
ld a, [wInBattleTowerBattle] ; always load the first trainer class in wTrainerClass for BattleTower-Trainers
and a
jr nz, .ok
2015-09-09 16:27:07 -07:00
2018-01-23 14:39:09 -08:00
ld a, [wTrainerClass]
dec a
ld bc, NUM_TRAINER_ATTRIBUTES
call AddNTimes
.ok
bit SWITCH_OFTEN_F, [hl]
2014-09-30 11:20:38 -07:00
jp nz, SwitchOften
bit SWITCH_RARELY_F, [hl]
2014-09-30 11:20:38 -07:00
jp nz, SwitchRarely
bit SWITCH_SOMETIMES_F, [hl]
2014-09-30 11:20:38 -07:00
jp nz, SwitchSometimes
; fallthrough
2018-06-24 07:09:41 -07:00
DontSwitch:
2014-09-30 11:20:38 -07:00
call AI_TryItem
ret
2018-06-24 07:09:41 -07:00
SwitchOften:
2017-12-24 09:47:30 -08:00
callfar CheckAbleToSwitch
2015-11-08 16:09:36 -08:00
ld a, [wEnemySwitchMonParam]
and $f0
2014-09-30 11:20:38 -07:00
jp z, DontSwitch
cp $10
jr nz, .not_10
call Random
2018-02-04 18:21:34 -08:00
cp 50 percent + 1
jr c, .switch
2014-09-30 11:20:38 -07:00
jp DontSwitch
.not_10
cp $20
jr nz, .not_20
call Random
2018-02-04 18:21:34 -08:00
cp 79 percent - 1
jr c, .switch
2014-09-30 11:20:38 -07:00
jp DontSwitch
.not_20
; $30
call Random
2015-11-08 16:09:36 -08:00
cp 4 percent
2014-09-30 11:20:38 -07:00
jp c, DontSwitch
.switch
2015-11-08 16:09:36 -08:00
ld a, [wEnemySwitchMonParam]
and $f
inc a
; In register 'a' is the number (1-6) of the mon to switch to
2015-11-08 16:09:36 -08:00
ld [wEnemySwitchMonIndex], a
jp AI_TrySwitch
2018-06-24 07:09:41 -07:00
SwitchRarely:
2017-12-24 09:47:30 -08:00
callfar CheckAbleToSwitch
2015-11-08 16:09:36 -08:00
ld a, [wEnemySwitchMonParam]
and $f0
2014-09-30 11:20:38 -07:00
jp z, DontSwitch
cp $10
jr nz, .not_10
call Random
2015-11-08 16:09:36 -08:00
cp 8 percent
jr c, .switch
2014-09-30 11:20:38 -07:00
jp DontSwitch
.not_10
cp $20
jr nz, .not_20
call Random
2015-11-08 16:09:36 -08:00
cp 12 percent
jr c, .switch
2014-09-30 11:20:38 -07:00
jp DontSwitch
.not_20
; $30
call Random
2018-02-04 18:21:34 -08:00
cp 79 percent - 1
2014-09-30 11:20:38 -07:00
jp c, DontSwitch
.switch
2015-11-08 16:09:36 -08:00
ld a, [wEnemySwitchMonParam]
and $f
inc a
2015-11-08 16:09:36 -08:00
ld [wEnemySwitchMonIndex], a
jp AI_TrySwitch
2018-06-24 07:09:41 -07:00
SwitchSometimes:
2017-12-24 09:47:30 -08:00
callfar CheckAbleToSwitch
2015-11-08 16:09:36 -08:00
ld a, [wEnemySwitchMonParam]
and $f0
2014-09-30 11:20:38 -07:00
jp z, DontSwitch
cp $10
jr nz, .not_10
call Random
2018-02-04 18:21:34 -08:00
cp 20 percent - 1
jr c, .switch
2014-09-30 11:20:38 -07:00
jp DontSwitch
.not_10
cp $20
jr nz, .not_20
call Random
2018-02-04 18:21:34 -08:00
cp 50 percent + 1
jr c, .switch
2014-09-30 11:20:38 -07:00
jp DontSwitch
.not_20
; $30
call Random
2018-02-04 18:21:34 -08:00
cp 20 percent - 1
2014-09-30 11:20:38 -07:00
jp c, DontSwitch
.switch
2015-11-08 16:09:36 -08:00
ld a, [wEnemySwitchMonParam]
and $f
inc a
2015-11-08 16:09:36 -08:00
ld [wEnemySwitchMonIndex], a
jp AI_TrySwitch
2018-06-24 07:09:41 -07:00
CheckSubstatusCantRun:
2018-01-23 14:39:09 -08:00
ld a, [wEnemySubStatus5]
bit SUBSTATUS_CANT_RUN, a
ret
2018-06-24 07:09:41 -07:00
AI_TryItem:
2015-09-04 13:30:40 -07:00
; items are not allowed in the BattleTower
2018-01-23 14:39:09 -08:00
ld a, [wInBattleTowerBattle]
and a
ret nz
2014-09-30 11:20:38 -07:00
2015-11-05 16:13:09 -08:00
ld a, [wEnemyTrainerItem1]
ld b, a
2015-11-05 16:13:09 -08:00
ld a, [wEnemyTrainerItem2]
or b
ret z
2014-09-30 11:20:38 -07:00
call .IsHighestLevel
ret nc
2014-09-30 11:20:38 -07:00
2018-01-23 14:39:09 -08:00
ld a, [wTrainerClass]
dec a
ld hl, TrainerClassAttributes + TRNATTR_AI_ITEM_SWITCH
ld bc, NUM_TRAINER_ATTRIBUTES
call AddNTimes
ld b, h
ld c, l
2014-09-30 11:20:38 -07:00
ld hl, AI_Items
2015-11-05 16:13:09 -08:00
ld de, wEnemyTrainerItem1
2014-09-30 11:20:38 -07:00
.loop
ld a, [hl]
and a
inc a
ret z
2014-09-30 11:20:38 -07:00
ld a, [de]
cp [hl]
2014-09-30 11:20:38 -07:00
jr z, .has_item
inc de
ld a, [de]
cp [hl]
2014-09-30 11:20:38 -07:00
jr z, .has_item
dec de
inc hl
inc hl
inc hl
2014-09-30 11:20:38 -07:00
jr .loop
2014-09-30 11:20:38 -07:00
.has_item
inc hl
2014-09-30 11:20:38 -07:00
push hl
push de
2014-09-30 11:20:38 -07:00
ld de, .callback
push de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
2014-09-30 11:20:38 -07:00
.callback
pop de
pop hl
2014-09-30 11:20:38 -07:00
inc hl
inc hl
2014-09-30 11:20:38 -07:00
jr c, .loop
.used_item
xor a
ld [de], a
inc a
2015-11-08 16:09:36 -08:00
ld [wEnemyGoesFirst], a
2014-09-30 11:20:38 -07:00
2018-01-23 14:39:09 -08:00
ld hl, wEnemySubStatus3
res SUBSTATUS_BIDE, [hl]
2014-09-30 11:20:38 -07:00
xor a
2018-01-23 14:39:09 -08:00
ld [wEnemyFuryCutterCount], a
ld [wEnemyProtectCount], a
2015-11-05 16:13:09 -08:00
ld [wEnemyRageCounter], a
2014-09-30 11:20:38 -07:00
2018-01-23 14:39:09 -08:00
ld hl, wEnemySubStatus4
res SUBSTATUS_RAGE, [hl]
2014-09-30 11:20:38 -07:00
xor a
2018-01-23 14:39:09 -08:00
ld [wLastEnemyCounterMove], a
2014-09-30 11:20:38 -07:00
scf
ret
2018-06-24 07:09:41 -07:00
.IsHighestLevel:
2018-01-23 14:39:09 -08:00
ld a, [wOTPartyCount]
ld d, a
ld e, 0
2018-01-23 14:39:09 -08:00
ld hl, wOTPartyMon1Level
ld bc, PARTYMON_STRUCT_LENGTH
2014-09-30 11:20:38 -07:00
.next
ld a, [hl]
cp e
2014-09-30 11:20:38 -07:00
jr c, .ok
ld e, a
2014-09-30 11:20:38 -07:00
.ok
add hl, bc
dec d
2014-09-30 11:20:38 -07:00
jr nz, .next
2018-01-23 14:39:09 -08:00
ld a, [wCurOTMon]
ld hl, wOTPartyMon1Level
call AddNTimes
ld a, [hl]
cp e
2014-09-30 11:20:38 -07:00
jr nc, .yes
.no
and a
ret
2014-09-30 11:20:38 -07:00
.yes
scf
ret
2018-06-24 07:09:41 -07:00
AI_Items:
dbw FULL_RESTORE, .FullRestore
dbw MAX_POTION, .MaxPotion
dbw HYPER_POTION, .HyperPotion
dbw SUPER_POTION, .SuperPotion
dbw POTION, .Potion
dbw X_ACCURACY, .XAccuracy
dbw FULL_HEAL, .FullHeal
dbw GUARD_SPEC, .GuardSpec
dbw DIRE_HIT, .DireHit
dbw X_ATTACK, .XAttack
dbw X_DEFEND, .XDefend
dbw X_SPEED, .XSpeed
dbw X_SPECIAL, .XSpecial
2018-01-10 19:53:42 -08:00
db -1 ; end
2018-06-24 07:09:41 -07:00
.FullHeal:
call .Status
jp c, .DontUse
call EnemyUsedFullHeal
jp .Use
2018-06-24 07:09:41 -07:00
.Status:
2018-01-23 14:39:09 -08:00
ld a, [wEnemyMonStatus]
and a
jp z, .DontUse
ld a, [bc]
bit CONTEXT_USE_F, a
jr nz, .StatusCheckContext
ld a, [bc]
bit ALWAYS_USE_F, a
jp nz, .Use
call Random
2018-02-04 18:21:34 -08:00
cp 20 percent - 1
jp c, .Use
jp .DontUse
.StatusCheckContext:
2018-01-23 14:39:09 -08:00
ld a, [wEnemySubStatus5]
bit SUBSTATUS_TOXIC, a
jr z, .FailToxicCheck
2018-01-23 14:39:09 -08:00
ld a, [wEnemyToxicCount]
cp 4
jr c, .FailToxicCheck
call Random
2018-02-04 18:21:34 -08:00
cp 50 percent + 1
jp c, .Use
.FailToxicCheck:
2018-01-23 14:39:09 -08:00
ld a, [wEnemyMonStatus]
and 1 << FRZ | SLP
jp z, .DontUse
jp .Use
2018-06-24 07:09:41 -07:00
.FullRestore:
call .HealItem
jp nc, .UseFullRestore
ld a, [bc]
bit CONTEXT_USE_F, a
jp z, .DontUse
call .Status
jp c, .DontUse
.UseFullRestore:
call EnemyUsedFullRestore
jp .Use
2018-06-24 07:09:41 -07:00
.MaxPotion:
call .HealItem
jp c, .DontUse
call EnemyUsedMaxPotion
jp .Use
2018-06-24 07:09:41 -07:00
.HealItem:
ld a, [bc]
bit CONTEXT_USE_F, a
jr nz, .CheckHalfOrQuarterHP
2017-12-24 09:47:30 -08:00
callfar AICheckEnemyHalfHP
jp c, .DontUse
ld a, [bc]
bit UNKNOWN_USE_F, a
jp nz, .CheckQuarterHP
2017-12-24 09:47:30 -08:00
callfar AICheckEnemyQuarterHP
jp nc, .UseHealItem
call Random
2018-02-04 18:21:34 -08:00
cp 50 percent + 1
jp c, .UseHealItem
jp .DontUse
2018-06-24 07:09:41 -07:00
.CheckQuarterHP:
2017-12-24 09:47:30 -08:00
callfar AICheckEnemyQuarterHP
jp c, .DontUse
call Random
2018-02-04 18:21:34 -08:00
cp 20 percent - 1
jp c, .DontUse
jr .UseHealItem
2018-06-24 07:09:41 -07:00
.CheckHalfOrQuarterHP:
2017-12-24 09:47:30 -08:00
callfar AICheckEnemyHalfHP
jp c, .DontUse
2017-12-24 09:47:30 -08:00
callfar AICheckEnemyQuarterHP
jp nc, .UseHealItem
call Random
2018-02-04 18:21:34 -08:00
cp 20 percent - 1
jp nc, .DontUse
2018-06-24 07:09:41 -07:00
.UseHealItem:
jp .Use
2018-06-24 07:09:41 -07:00
.HyperPotion:
call .HealItem
jp c, .DontUse
ld b, 200
call EnemyUsedHyperPotion
jp .Use
2018-06-24 07:09:41 -07:00
.SuperPotion:
call .HealItem
jp c, .DontUse
ld b, 50
call EnemyUsedSuperPotion
jp .Use
2018-06-24 07:09:41 -07:00
.Potion:
call .HealItem
jp c, .DontUse
ld b, 20
call EnemyUsedPotion
jp .Use
.asm_382ae ; This appears to be unused
2017-12-24 09:47:30 -08:00
callfar AICheckEnemyMaxHP
2015-11-08 07:59:28 -08:00
jr c, .dont_use
push bc
2018-01-23 14:39:09 -08:00
ld de, wEnemyMonMaxHP + 1
ld hl, wEnemyMonHP + 1
ld a, [de]
sub [hl]
2015-11-08 07:59:28 -08:00
jr z, .check_40_percent
dec hl
dec de
ld c, a
sbc [hl]
and a
2015-11-08 07:59:28 -08:00
jr nz, .check_40_percent
ld a, c
cp b
2015-11-08 07:59:28 -08:00
jp c, .check_50_percent
2017-12-24 09:47:30 -08:00
callfar AICheckEnemyQuarterHP
2015-11-08 07:59:28 -08:00
jr c, .check_40_percent
2015-11-08 07:59:28 -08:00
.check_50_percent
pop bc
ld a, [bc]
bit UNKNOWN_USE_F, a
jp z, .Use
call Random
2018-02-04 18:21:34 -08:00
cp 50 percent + 1
jp c, .Use
2015-11-08 07:59:28 -08:00
.dont_use
jp .DontUse
2015-11-08 07:59:28 -08:00
.check_40_percent
pop bc
ld a, [bc]
bit UNKNOWN_USE_F, a
jp z, .DontUse
call Random
2018-02-04 18:21:34 -08:00
cp 39 percent + 1
jp c, .Use
jp .DontUse
2018-06-24 07:09:41 -07:00
.XAccuracy:
call .XItem
jp c, .DontUse
call EnemyUsedXAccuracy
jp .Use
2018-06-24 07:09:41 -07:00
.GuardSpec:
call .XItem
jp c, .DontUse
call EnemyUsedGuardSpec
jp .Use
2018-06-24 07:09:41 -07:00
.DireHit:
call .XItem
jp c, .DontUse
call EnemyUsedDireHit
jp .Use
2018-06-24 07:09:41 -07:00
.XAttack:
call .XItem
jp c, .DontUse
call EnemyUsedXAttack
jp .Use
2018-06-24 07:09:41 -07:00
.XDefend:
call .XItem
jp c, .DontUse
call EnemyUsedXDefend
jp .Use
2018-06-24 07:09:41 -07:00
.XSpeed:
call .XItem
jp c, .DontUse
call EnemyUsedXSpeed
jp .Use
2018-06-24 07:09:41 -07:00
.XSpecial:
call .XItem
jp c, .DontUse
call EnemyUsedXSpecial
jp .Use
2018-06-24 07:09:41 -07:00
.XItem:
2018-01-23 14:39:09 -08:00
ld a, [wEnemyTurnsTaken]
and a
jr nz, .notfirstturnout
ld a, [bc]
bit ALWAYS_USE_F, a
jp nz, .Use
call Random
2018-02-04 18:21:34 -08:00
cp 50 percent + 1
jp c, .DontUse
ld a, [bc]
bit CONTEXT_USE_F, a
jp nz, .Use
call Random
2018-02-04 18:21:34 -08:00
cp 50 percent + 1
jp c, .DontUse
jp .Use
.notfirstturnout
ld a, [bc]
bit ALWAYS_USE_F, a
jp z, .DontUse
call Random
2018-02-04 18:21:34 -08:00
cp 20 percent - 1
jp nc, .DontUse
jp .Use
.DontUse:
scf
ret
.Use:
and a
ret
2018-06-24 07:09:41 -07:00
AIUpdateHUD:
call UpdateEnemyMonInParty
farcall UpdateEnemyHUD
ld a, $1
ld [hBGMapMode], a
2016-01-12 09:46:18 -08:00
ld hl, wEnemyItemState
dec [hl]
scf
ret
2018-06-24 07:09:41 -07:00
AIUsedItemSound:
push de
ld de, SFX_FULL_HEAL
call PlaySFX
pop de
ret
2018-06-24 07:09:41 -07:00
EnemyUsedFullHeal:
call AIUsedItemSound
call AI_HealStatus
ld a, FULL_HEAL
2015-08-24 16:56:30 -07:00
jp PrintText_UsedItemOn_AND_AIUpdateHUD
2018-06-24 07:09:41 -07:00
EnemyUsedMaxPotion:
ld a, MAX_POTION
2018-01-23 14:39:09 -08:00
ld [wCurEnemyItem], a
jr FullRestoreContinue
2018-06-24 07:09:41 -07:00
EnemyUsedFullRestore:
call AI_HealStatus
ld a, FULL_RESTORE
2018-01-23 14:39:09 -08:00
ld [wCurEnemyItem], a
ld hl, wEnemySubStatus3
res SUBSTATUS_CONFUSED, [hl]
xor a
2018-01-23 14:39:09 -08:00
ld [wEnemyConfuseCount], a
2018-06-24 07:09:41 -07:00
FullRestoreContinue:
ld de, wCurHPAnimOldHP
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonHP + 1
ld a, [hld]
ld [de], a
inc de
ld a, [hl]
ld [de], a
inc de
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonMaxHP + 1
ld a, [hld]
ld [de], a
inc de
ld [wCurHPAnimMaxHP], a
2018-01-23 14:39:09 -08:00
ld [wEnemyMonHP + 1], a
ld a, [hl]
ld [de], a
ld [wCurHPAnimMaxHP + 1], a
2018-01-23 14:39:09 -08:00
ld [wEnemyMonHP], a
jr EnemyPotionFinish
2018-06-24 07:09:41 -07:00
EnemyUsedPotion:
ld a, POTION
ld b, 20
jr EnemyPotionContinue
2018-06-24 07:09:41 -07:00
EnemyUsedSuperPotion:
ld a, SUPER_POTION
ld b, 50
jr EnemyPotionContinue
2018-06-24 07:09:41 -07:00
EnemyUsedHyperPotion:
ld a, HYPER_POTION
ld b, 200
2018-06-24 07:09:41 -07:00
EnemyPotionContinue:
2018-01-23 14:39:09 -08:00
ld [wCurEnemyItem], a
ld hl, wEnemyMonHP + 1
ld a, [hl]
ld [wCurHPAnimOldHP], a
add b
ld [hld], a
ld [wCurHPAnimNewHP], a
ld a, [hl]
ld [wCurHPAnimOldHP + 1], a
ld [wCurHPAnimNewHP + 1], a
jr nc, .ok
inc a
ld [hl], a
ld [wCurHPAnimNewHP + 1], a
.ok
inc hl
ld a, [hld]
ld b, a
2018-01-23 14:39:09 -08:00
ld de, wEnemyMonMaxHP + 1
ld a, [de]
dec de
ld [wCurHPAnimMaxHP], a
sub b
ld a, [hli]
ld b, a
ld a, [de]
ld [wCurHPAnimMaxHP + 1], a
sbc b
jr nc, EnemyPotionFinish
inc de
ld a, [de]
dec de
ld [hld], a
ld [wCurHPAnimNewHP], a
ld a, [de]
ld [hl], a
ld [wCurHPAnimNewHP + 1], a
2018-06-24 07:09:41 -07:00
EnemyPotionFinish:
2015-08-24 16:56:30 -07:00
call PrintText_UsedItemOn
hlcoord 2, 2
xor a
ld [wWhichHPBar], a
call AIUsedItemSound
predef AnimateHPBar
jp AIUpdateHUD
2018-06-24 07:09:41 -07:00
AI_TrySwitch:
; Determine whether the AI can switch based on how many Pokemon are still alive.
; If it can switch, it will.
2018-01-23 14:39:09 -08:00
ld a, [wOTPartyCount]
ld c, a
2018-01-23 14:39:09 -08:00
ld hl, wOTPartyMon1HP
ld d, 0
.SwitchLoop:
ld a, [hli]
ld b, a
ld a, [hld]
or b
jr z, .fainted
inc d
.fainted
push bc
ld bc, PARTYMON_STRUCT_LENGTH
add hl, bc
pop bc
dec c
jr nz, .SwitchLoop
ld a, d
cp 2
jp nc, AI_Switch
and a
ret
2018-06-24 07:09:41 -07:00
AI_Switch:
ld a, $1
ld [wEnemyIsSwitching], a
2015-11-08 16:09:36 -08:00
ld [wEnemyGoesFirst], a
2018-01-23 14:39:09 -08:00
ld hl, wEnemySubStatus4
res SUBSTATUS_RAGE, [hl]
xor a
ld [hBattleTurn], a
2017-12-24 09:47:30 -08:00
callfar PursuitSwitch
2015-11-06 06:04:27 -08:00
push af
2018-01-23 14:39:09 -08:00
ld a, [wCurOTMon]
ld hl, wOTPartyMon1Status
ld bc, PARTYMON_STRUCT_LENGTH
call AddNTimes
ld d, h
ld e, l
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonStatus
2016-03-01 19:31:21 -08:00
ld bc, MON_MAXHP - MON_STATUS
call CopyBytes
pop af
2015-11-06 06:04:27 -08:00
jr c, .skiptext
2015-08-24 16:56:30 -07:00
ld hl, TextJump_EnemyWithdrew
call PrintText
2015-11-06 06:04:27 -08:00
.skiptext
2015-11-10 16:51:13 -08:00
ld a, 1
2016-08-07 15:14:20 -07:00
ld [wBattleHasJustStarted], a
2017-12-24 09:47:30 -08:00
callfar NewEnemyMonStatus
callfar ResetEnemyStatLevels
2018-01-23 14:39:09 -08:00
ld hl, wPlayerSubStatus1
res SUBSTATUS_IN_LOVE, [hl]
2017-12-24 09:47:30 -08:00
farcall EnemySwitch
farcall ResetBattleParticipants
xor a
2016-08-07 15:14:20 -07:00
ld [wBattleHasJustStarted], a
ld a, [wLinkMode]
and a
ret nz
scf
ret
2018-06-24 07:09:41 -07:00
TextJump_EnemyWithdrew:
2015-08-24 16:56:30 -07:00
text_jump Text_EnemyWithdrew
db "@"
Function384d5: ; This appears to be unused
call AIUsedItemSound
call AI_HealStatus
2017-12-12 19:58:20 -08:00
ld a, FULL_HEAL_RED ; X_SPEED
2015-08-24 16:56:30 -07:00
jp PrintText_UsedItemOn_AND_AIUpdateHUD
2018-06-24 07:09:41 -07:00
AI_HealStatus:
2018-01-23 14:39:09 -08:00
ld a, [wCurOTMon]
ld hl, wOTPartyMon1Status
ld bc, PARTYMON_STRUCT_LENGTH
call AddNTimes
xor a
ld [hl], a
2018-01-23 14:39:09 -08:00
ld [wEnemyMonStatus], a
2017-12-12 19:58:20 -08:00
; Bug: this should reset SUBSTATUS_NIGHTMARE too
; Uncomment the lines below to fix
2018-01-23 14:39:09 -08:00
; ld hl, wEnemySubStatus1
2017-12-12 19:58:20 -08:00
; res SUBSTATUS_NIGHTMARE, [hl]
2018-01-23 14:39:09 -08:00
ld hl, wEnemySubStatus5
res SUBSTATUS_TOXIC, [hl]
ret
2018-06-24 07:09:41 -07:00
EnemyUsedXAccuracy:
call AIUsedItemSound
2018-01-23 14:39:09 -08:00
ld hl, wEnemySubStatus4
set SUBSTATUS_X_ACCURACY, [hl]
ld a, X_ACCURACY
2015-08-24 16:56:30 -07:00
jp PrintText_UsedItemOn_AND_AIUpdateHUD
2018-06-24 07:09:41 -07:00
EnemyUsedGuardSpec:
call AIUsedItemSound
2018-01-23 14:39:09 -08:00
ld hl, wEnemySubStatus4
set SUBSTATUS_MIST, [hl]
ld a, GUARD_SPEC
2015-08-24 16:56:30 -07:00
jp PrintText_UsedItemOn_AND_AIUpdateHUD
2018-06-24 07:09:41 -07:00
EnemyUsedDireHit:
call AIUsedItemSound
2018-01-23 14:39:09 -08:00
ld hl, wEnemySubStatus4
set SUBSTATUS_FOCUS_ENERGY, [hl]
ld a, DIRE_HIT
2015-08-24 16:56:30 -07:00
jp PrintText_UsedItemOn_AND_AIUpdateHUD
Function3851e: ; This appears to be unused
2015-09-09 16:27:07 -07:00
ld [hDivisor], a
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonMaxHP
ld a, [hli]
ld [hDividend], a
ld a, [hl]
2015-09-09 16:27:07 -07:00
ld [hDividend + 1], a
ld b, 2
call Divide
2015-09-09 16:27:07 -07:00
ld a, [hQuotient + 2]
ld c, a
2015-09-09 16:27:07 -07:00
ld a, [hQuotient + 1]
ld b, a
2018-01-23 14:39:09 -08:00
ld hl, wEnemyMonHP + 1
ld a, [hld]
ld e, a
ld a, [hl]
ld d, a
ld a, d
sub b
ret nz
ld a, e
sub c
ret
2018-06-24 07:09:41 -07:00
EnemyUsedXAttack:
ld b, ATTACK
ld a, X_ATTACK
jr EnemyUsedXItem
2018-06-24 07:09:41 -07:00
EnemyUsedXDefend:
ld b, DEFENSE
ld a, X_DEFEND
jr EnemyUsedXItem
2018-06-24 07:09:41 -07:00
EnemyUsedXSpeed:
ld b, SPEED
ld a, X_SPEED
jr EnemyUsedXItem
2018-06-24 07:09:41 -07:00
EnemyUsedXSpecial:
ld b, SP_ATTACK
ld a, X_SPECIAL
2015-08-24 16:56:30 -07:00
; Parameter
; a = ITEM_CONSTANT
; b = BATTLE_CONSTANT (ATTACK, DEFENSE, SPEED, SP_ATTACK, SP_DEFENSE, ACCURACY, EVASION)
EnemyUsedXItem:
2018-01-23 14:39:09 -08:00
ld [wCurEnemyItem], a
push bc
2015-08-24 16:56:30 -07:00
call PrintText_UsedItemOn
pop bc
2017-12-24 09:47:30 -08:00
farcall CheckIfStatCanBeRaised
jp AIUpdateHUD
2015-08-24 16:56:30 -07:00
; Parameter
; a = ITEM_CONSTANT
2018-06-24 07:09:41 -07:00
PrintText_UsedItemOn_AND_AIUpdateHUD:
2018-01-23 14:39:09 -08:00
ld [wCurEnemyItem], a
2015-08-24 16:56:30 -07:00
call PrintText_UsedItemOn
jp AIUpdateHUD
2018-06-24 07:09:41 -07:00
PrintText_UsedItemOn:
2018-01-23 14:39:09 -08:00
ld a, [wCurEnemyItem]
ld [wNamedObjectIndexBuffer], a
call GetItemName
2018-01-23 14:39:09 -08:00
ld hl, wStringBuffer1
2015-12-18 17:07:09 -08:00
ld de, wMonOrItemNameBuffer
2014-09-30 11:20:38 -07:00
ld bc, ITEM_NAME_LENGTH
call CopyBytes
2015-08-24 16:56:30 -07:00
ld hl, TextJump_EnemyUsedOn
jp PrintText
2018-06-24 07:09:41 -07:00
TextJump_EnemyUsedOn:
2015-08-24 16:56:30 -07:00
text_jump Text_EnemyUsedOn
db "@"