Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GiveExperiencePoints:
- ; Give experience.
- ; Don't give experience if linked or in the Battle Tower.
- ld a, [wLinkMode]
- and a
- ret nz
- ld a, [wInBattleTowerBattle]
- bit 0, a
- ret nz
- call .EvenlyDivideExpAmongParticipants
- xor a
- ld [wCurPartyMon], a
- ld bc, wPartyMon1Species
- .loop
- ld hl, MON_HP
- add hl, bc
- ld a, [hli]
- or [hl]
- jp z, .next_mon ; fainted
- push bc
- ld hl, wBattleParticipantsNotFainted
- ld a, [wCurPartyMon]
- ld c, a
- ld b, CHECK_FLAG
- ld d, 0
- predef SmallFarFlagAction
- ld a, c
- and a
- pop bc
- jp z, .next_mon
- ; Give EVs
- ; e = 0 for no Pokerus, 1 for Pokerus
- ld e, 0
- ld hl, MON_PKRUS
- add hl, bc
- ld a, [hl]
- and a
- jr z, .no_pokerus
- inc e
- .no_pokerus
- ld hl, MON_EVS
- add hl, bc
- push bc
- ld a, [wEnemyMonSpecies]
- ld [wCurSpecies], a
- call GetBaseData
- ; EV yield format: %hhaaddss %ttff0000
- ; h = hp, a = atk, d = def, s = spd
- ; t = sat, f = sdf, 0 = unused bits
- ld a, [wBaseHPAtkDefSpdEVs]
- ld b, a
- ld c, 6 ; six EVs
- .ev_loop
- rlc b
- rlc b
- ld a, b
- and %11
- bit 0, e
- jr z, .no_pokerus_boost
- add a
- .no_pokerus_boost
- ; Make sure total EVs never surpass 512
- ld d, a
- push af
- push bc
- push hl
- ld e, 6
- ld bc, 0
- .count_evs
- ld a, [hli]
- add c
- ld c, a
- jr nc, .cont
- inc b
- .cont
- dec e
- jr nz, .count_evs
- ld a, d
- add c
- ld c, a
- adc b
- sub c
- ld b, a
- ld e, a
- .decrease_evs_gained
- call IsEvsGreaterThan512
- jr z, .check_ev_overflow
- jr c, .check_ev_overflow
- dec e
- dec bc
- jr .decrease_evs_gained
- .check_ev_overflow
- pop hl
- pop bc
- pop af
- ld a, e
- add [hl]
- cp MAX_EV
- jr nc, .ev_overflow
- cp MAX_EV + 1
- jr c, .got_ev
- .ev_overflow
- ld a, MAX_EV
- .got_ev
- ld [hli], a
- dec c
- jr z, .evs_done
- ; Use the second byte for Sp.Atk and Sp.Def
- ld a, c
- cp 2 ; two stats left, Sp.Atk and Sp.Def
- jr nz, .ev_loop
- ld a, [wBaseSpAtkSpDefEVs]
- ld b, a
- jr .ev_loop
- .evs_done
- xor a
- ldh [hMultiplicand + 0], a
- ldh [hMultiplicand + 1], a
- ld a, [wEnemyMonBaseExp]
- ldh [hMultiplicand + 2], a
- ld a, [wEnemyMonLevel]
- ldh [hMultiplier], a
- call Multiply
- ld a, 7
- ldh [hDivisor], a
- ld b, 4
- call Divide
- ; Boost Experience for traded Pokemon
- pop bc
- ld hl, MON_ID
- add hl, bc
- ld a, [wPlayerID]
- cp [hl]
- jr nz, .boosted
- inc hl
- ld a, [wPlayerID + 1]
- cp [hl]
- ld a, 0
- jr z, .no_boost
- .boosted
- call BoostExp
- ld a, 1
- .no_boost
- ; Boost experience for a Trainer Battle
- ld [wStringBuffer2 + 2], a
- ld a, [wBattleMode]
- dec a
- call nz, BoostExp
- ; Boost experience for Lucky Egg
- push bc
- ld a, MON_ITEM
- call GetPartyParamLocation
- ld a, [hl]
- cp LUCKY_EGG
- call z, BoostExp
- ldh a, [hQuotient + 3]
- ld [wStringBuffer2 + 1], a
- ldh a, [hQuotient + 2]
- ld [wStringBuffer2], a
- ld a, [wCurPartyMon]
- ld hl, wPartyMonNicknames
- call GetNick
- ld hl, Text_MonGainedExpPoint
- call BattleTextbox
- ld a, [wStringBuffer2 + 1]
- ldh [hQuotient + 3], a
- ld a, [wStringBuffer2]
- ldh [hQuotient + 2], a
- pop bc
- call AnimateExpBar
- push bc
- call LoadTilemapToTempTilemap
- pop bc
- ld hl, MON_EXP + 2
- add hl, bc
- ld d, [hl]
- ldh a, [hQuotient + 3]
- add d
- ld [hld], a
- ld d, [hl]
- ldh a, [hQuotient + 2]
- adc d
- ld [hl], a
- jr nc, .no_exp_overflow
- dec hl
- inc [hl]
- jr nz, .no_exp_overflow
- ld a, $ff
- ld [hli], a
- ld [hli], a
- ld [hl], a
- .no_exp_overflow
- ld a, [wCurPartyMon]
- ld e, a
- ld d, 0
- ld hl, wPartySpecies
- add hl, de
- ld a, [hl]
- ld [wCurSpecies], a
- call GetBaseData
- push bc
- ld d, MAX_LEVEL
- callfar CalcExpAtLevel
- pop bc
- ld hl, MON_EXP + 2
- add hl, bc
- push bc
- ldh a, [hQuotient + 1]
- ld b, a
- ldh a, [hQuotient + 2]
- ld c, a
- ldh a, [hQuotient + 3]
- ld d, a
- ld a, [hld]
- sub d
- ld a, [hld]
- sbc c
- ld a, [hl]
- sbc b
- jr c, .not_max_exp
- ld a, b
- ld [hli], a
- ld a, c
- ld [hli], a
- ld a, d
- ld [hld], a
- .not_max_exp
- ; Check if the mon leveled up
- xor a ; PARTYMON
- ld [wMonType], a
- predef CopyMonToTempMon
- callfar CalcLevel
- pop bc
- ld hl, MON_LEVEL
- add hl, bc
- ld a, [hl]
- cp MAX_LEVEL
- jp nc, .next_mon
- cp d
- jp z, .next_mon
- ; <NICKNAME> grew to level ##!
- ld [wTempLevel], a
- ld a, [wCurPartyLevel]
- push af
- ld a, d
- ld [wCurPartyLevel], a
- ld [hl], a
- ld hl, MON_SPECIES
- add hl, bc
- ld a, [hl]
- ld [wCurSpecies], a
- ld [wTempSpecies], a ; unused?
- call GetBaseData
- ld hl, MON_MAXHP + 1
- add hl, bc
- ld a, [hld]
- ld e, a
- ld d, [hl]
- push de
- ld hl, MON_MAXHP
- add hl, bc
- ld d, h
- ld e, l
- ld hl, MON_EVS - 1
- add hl, bc
- push bc
- ld b, TRUE
- predef CalcMonStats
- pop bc
- pop de
- ld hl, MON_MAXHP + 1
- add hl, bc
- ld a, [hld]
- sub e
- ld e, a
- ld a, [hl]
- sbc d
- ld d, a
- dec hl
- ld a, [hl]
- add e
- ld [hld], a
- ld a, [hl]
- adc d
- ld [hl], a
- ld a, [wCurBattleMon]
- ld d, a
- ld a, [wCurPartyMon]
- cp d
- jr nz, .skip_active_mon_update
- ld de, wBattleMonHP
- ld a, [hli]
- ld [de], a
- inc de
- ld a, [hli]
- ld [de], a
- ld de, wBattleMonMaxHP
- push bc
- ld bc, PARTYMON_STRUCT_LENGTH - MON_MAXHP
- call CopyBytes
- pop bc
- ld hl, MON_LEVEL
- add hl, bc
- ld a, [hl]
- ld [wBattleMonLevel], a
- ld a, [wPlayerSubStatus5]
- bit SUBSTATUS_TRANSFORMED, a
- jr nz, .transformed
- ld hl, MON_ATK
- add hl, bc
- ld de, wPlayerStats
- ld bc, PARTYMON_STRUCT_LENGTH - MON_ATK
- call CopyBytes
- .transformed
- xor a ; FALSE
- ld [wApplyStatLevelMultipliersToEnemy], a
- call ApplyStatLevelMultiplierOnAllStats
- callfar ApplyStatusEffectOnPlayerStats
- callfar BadgeStatBoosts
- callfar UpdatePlayerHUD
- call EmptyBattleTextbox
- call LoadTilemapToTempTilemap
- ld a, $1
- ldh [hBGMapMode], a
- .skip_active_mon_update
- farcall LevelUpHappinessMod
- ld a, [wCurBattleMon]
- ld b, a
- ld a, [wCurPartyMon]
- cp b
- jr z, .skip_exp_bar_animation
- ld de, SFX_HIT_END_OF_EXP_BAR
- call PlaySFX
- call WaitSFX
- ld hl, BattleText_StringBuffer1GrewToLevel
- call StdBattleTextbox
- call LoadTilemapToTempTilemap
- .skip_exp_bar_animation
- xor a ; PARTYMON
- ld [wMonType], a
- predef CopyMonToTempMon
- hlcoord 9, 0
- ld b, 10
- ld c, 9
- call Textbox
- hlcoord 11, 1
- ld bc, 4
- predef PrintTempMonStats
- ld c, 30
- call DelayFrames
- call WaitPressAorB_BlinkCursor
- call SafeLoadTempTilemapToTilemap
- xor a ; PARTYMON
- ld [wMonType], a
- ld a, [wCurSpecies]
- ld [wTempSpecies], a ; unused?
- ld a, [wCurPartyLevel]
- push af
- ld c, a
- ld a, [wTempLevel]
- ld b, a
- .level_loop
- inc b
- ld a, b
- ld [wCurPartyLevel], a
- push bc
- predef LearnLevelMoves
- pop bc
- ld a, b
- cp c
- jr nz, .level_loop
- pop af
- ld [wCurPartyLevel], a
- ld hl, wEvolvableFlags
- ld a, [wCurPartyMon]
- ld c, a
- ld b, SET_FLAG
- predef SmallFarFlagAction
- pop af
- ld [wCurPartyLevel], a
- .next_mon
- ld a, [wPartyCount]
- ld b, a
- ld a, [wCurPartyMon]
- inc a
- cp b
- jr z, .done
- ld [wCurPartyMon], a
- ld a, MON_SPECIES
- call GetPartyParamLocation
- ld b, h
- ld c, l
- jp .loop
- .done
- jp ResetBattleParticipants
- .EvenlyDivideExpAmongParticipants:
- ; count number of battle participants
- ld a, [wBattleParticipantsNotFainted]
- ld b, a
- ld c, PARTY_LENGTH
- ld d, 0
- .count_loop
- xor a
- srl b
- adc d
- ld d, a
- dec c
- jr nz, .count_loop
- cp 2
- ret c
- ld [wTempByteValue], a
- ld hl, wEnemyMonBaseStats
- ld c, wEnemyMonEnd - wEnemyMonBaseStats
- .base_stat_division_loop
- xor a
- ldh [hDividend + 0], a
- ld a, [hl]
- ldh [hDividend + 1], a
- ld a, [wTempByteValue]
- ldh [hDivisor], a
- ld b, 2
- call Divide
- ldh a, [hQuotient + 3]
- ld [hli], a
- dec c
- jr nz, .base_stat_division_loop
- ret
- IsEvsGreaterThan512:
- ; EV total in bc
- ; Returns c if lower
- ld a, b
- cp HIGH(MAX_TOTAL_EV)
- ret nz
- ld a, c
- cp LOW(MAX_TOTAL_EV)
- ret
Add Comment
Please, Sign In to add comment