Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BattleCommand_DamageVariation: ; 34cfd
- ; damagevariation
- ; Modify the damage spread between 85% and 100%.
- ; Because of the method of division the probability distribution
- ; is not consistent. This makes the highest damage multipliers
- ; rarer than normal.
- ; No point in reducing 1 or 0 damage.
- ld hl, CurDamage
- ld a, [hli]
- and a
- jr nz, .go
- ld a, [hl]
- cp 2
- ret c
- .go
- ; Start with the maximum damage.
- xor a
- ld [hMultiplicand + 0], a
- dec hl
- ld a, [hli]
- ld [hMultiplicand + 1], a
- ld a, [hl]
- ld [hMultiplicand + 2], a
- ; Multiply by 85-100%...
- .loop
- call BattleRandom
- rrca
- cp $d9 ; 85%
- jr c, .loop
- ld [hMultiplier], a
- call Multiply
- ; ...divide by 100%...
- ld a, $ff ; 100%
- ld [hDivisor], a
- ld b, $4
- call Divide
- ; ...to get .85-1.00x damage.
- ld a, [hQuotient + 1]
- ld hl, CurDamage
- ld [hli], a
- ld a, [hQuotient + 2]
- ; it starts here
- push hl
- push af
- ld hl, BattleMonItem
- ld a, [hBattleTurn]
- and a
- jr z, .got_item_addr
- ld hl, EnemyMonItem
- .got_item_addr
- ld a, [hl]
- cp STICK
- ld [hl], a
- jr z, .reduceDamage
- pop af
- pop hl
- .returnToFray
- ld h, b
- ld l, c
- ret
- ; 34d32401
- .reduceDamage
- jr .popsYes
- .popsYesBack
- ld b, h
- ld c, l
- ld a, 17
- call ReduceNumberByAPercent
- jr .returnToFray
- .popsYes
- pop af
- pop hl
- jr .popsYesBack
- ReduceNumberByAPercent: ; thanks PikalaxALT!
- ; number in bc, percentage in a
- push af
- ld a, b
- ld [hMultiplicand + 1], a
- ld a, c
- ld [hMultiplicand + 2], a
- xor a
- ld [hMultiplicand], a
- pop bc
- ld a, 100
- sub b
- ld [hMultiplier], a
- call Multiply
- ld a, 100
- ld [hDivisor], a
- ld b, 4
- call Divide
- ld a, [hQuotient + 1]
- ld b, a
- ld a, [hQuotient + 2]
- ld c, a
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement