Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CheckAbleToSwitch:
- ; added stat drop checks for Ultimate
- xor a
- ld [wEnemySwitchMonParam], a
- call FindAliveEnemyMons
- ret c
- ld hl, TrainerClassAttributes + TRNATTR_AI_ITEM_SWITCH
- ld a, [wTrainerClass]
- dec a
- ld bc, NUM_TRAINER_ATTRIBUTES
- call AddNTimes
- ld a, BANK(TrainerClassAttributes)
- call GetFarByte
- bit SWITCH_OFTEN_F, a
- jr nz, .checkstat
- bit SWITCH_SOMETIMES_F, a
- jr nz, .checkstat
- jr .checkperish
- .checkstat
- ; Checks if non-spd stat (because of Curse) is below -2
- ; Checks if Accuracy is below -1
- ; Checks if Evasion is greater than 0
- ld a, [wEnemyEvaLevel]
- cp BASE_STAT_LEVEL
- ret c
- ld a, [wEnemyAccLevel]
- cp BASE_STAT_LEVEL - 1
- jr c, .rollswitch
- ld hl, wEnemyStatLevels
- ld c, NUM_LEVEL_STATS - 1
- ld b, 0
- .checkstatbuff
- ld a, [hli]
- inc d
- ld e, a
- sub BASE_STAT_LEVEL
- ; b holds the stat buffs
- ld a, [hl]
- cp BASE_STAT_LEVEL
- jr nc, .checkstatbuff
- ld a, b
- add e
- ld b, a
- dec c
- jr z, .cont_check
- jr .checkstatbuff
- .cont_check
- ; Checks if the player has at least 2 stat buffs
- ; If yes, the AI will not switch. Otherwise, continue checking for stat drops.
- ; +1 = 1 stat buff, +2 = 2 stat buffs
- ; 0 and lower = no stat buffs
- ld a, b
- cp 1
- jr c, .checkperish
- ; Checks for stat drops
- ld a, [wEnemyAtkLevel]
- cp BASE_STAT_LEVEL - 2
- jr c, .rollswitch
- ld a, [wEnemyDefLevel]
- cp BASE_STAT_LEVEL - 2
- jr c, .rollswitch
- ld a, [wEnemySAtkLevel]
- cp BASE_STAT_LEVEL - 2
- jr c, .rollswitch
- ld a, [wEnemySDefLevel]
- cp BASE_STAT_LEVEL - 2
- jr c, .rollswitch
- jr .checkperish
- .rollswitch
- call Random
- cp 65 percent
- jr c, .switch
- jr .checkperish
- .checkperish
- ld a, [wEnemySubStatus1]
- bit SUBSTATUS_PERISH, a
- jr z, .no_perish
- ld a, [wEnemyPerishCount]
- cp 1
- jr nz, .no_perish
- ; Try to switch
- .switch
- call FindAliveEnemyMons
- call FindEnemyMonsWithAtLeastQuarterMaxHP
- call FindEnemyMonsThatResistPlayer
- call FindAliveEnemyMonsWithASuperEffectiveMove
- ld a, e
- cp 2
- jr nz, .not_2
- ld a, [wEnemyAISwitchScore]
- add $30 ; maximum chance
- ld [wEnemySwitchMonParam], a
- ret
- .not_2
- call FindAliveEnemyMons
- sla c
- sla c
- ld b, $ff
- .loop1
- inc b
- sla c
- jr nc, .loop1
- ld a, b
- add $30 ; maximum chance
- ld [wEnemySwitchMonParam], a
- ret
- .no_perish
- call CheckPlayerMoveTypeMatchups
- ld a, [wEnemyAISwitchScore]
- cp 11
- ret nc
- ld a, [wLastPlayerCounterMove]
- and a
- jr z, .no_last_counter_move
- call FindEnemyMonsImmuneToLastCounterMove
- ld a, [wEnemyAISwitchScore]
- and a
- jr z, .no_last_counter_move
- ld c, a
- call FindEnemyMonsWithASuperEffectiveMove
- ld a, [wEnemyAISwitchScore]
- cp $ff
- ret z
- ld b, a
- ld a, e
- cp 2
- jr z, .not_2_again
- call CheckPlayerMoveTypeMatchups
- ld a, [wEnemyAISwitchScore]
- cp 11
- ret nc
- ld a, b
- add $20
- ld [wEnemySwitchMonParam], a
- ret
- .not_2_again
- ld c, $10
- call CheckPlayerMoveTypeMatchups
- ld a, [wEnemyAISwitchScore]
- cp 10
- jr nc, .okay
- ld c, $20
- .okay
- ld a, b
- add c
- ld [wEnemySwitchMonParam], a
- ret
- ; Smart switching
- .smartswitch
- call Random
- cp 80 percent
- jr c, .no_switch
- ld a, e
- cp 2
- jr nz, .not_2
- ld a, [wEnemyAISwitchScore]
- add $20
- ld [wEnemySwitchMonParam], a
- ret
- .no_switch
- ld a, e
- cp $2
- ret nz
- .no_last_counter_move
- call CheckPlayerMoveTypeMatchups
- ld a, [wEnemyAISwitchScore]
- cp 11
- ret nc
- ld hl, TrainerClassAttributes + TRNATTR_AI_ITEM_SWITCH
- ld a, [wTrainerClass]
- dec a
- ld bc, NUM_TRAINER_ATTRIBUTES
- call AddNTimes
- ld a, BANK(TrainerClassAttributes)
- call GetFarByte
- bit SWITCH_OFTEN_F, a
- jr nz, .smartcheck
- jr .defaultcheck
- ; Randomize switch check only for SWITCH_OFTEN AI
- .smartcheck:
- call Random
- cp 35 percent
- jr c, .algorithm2
- ; Algorithm 1
- call FindAliveEnemyMons
- call FindEnemyMonsWithAtLeastQuarterMaxHP
- call FindEnemyMonsThatResistPlayer
- call FindAliveEnemyMonsWithASuperEffectiveMove
- jp .smartswitch
- .algorithm2
- call FindAliveEnemyMons
- call FindEnemyMonsWithAtLeastQuarterMaxHP
- call FindEnemyMonsThatResistPlayer
- jp .smartswitch
- ; Default switch check for SWITCH_SOMETIMES and SWITCH_RARELY
- .defaultcheck
- call FindAliveEnemyMons
- call FindEnemyMonsWithAtLeastQuarterMaxHP
- call FindEnemyMonsThatResistPlayer
- call FindAliveEnemyMonsWithASuperEffectiveMove
- ld a, e
- cp $2
- ret nz
- ld a, [wEnemyAISwitchScore]
- add $10
- ld [wEnemySwitchMonParam], a
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement