SHARE
TWEET

Untitled

Crystal_ Jun 17th, 2014 297 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Made over HalveMoney routine at 0x12513
  2. ; Instead of halving current money upon losing
  3. ; substract 4*(l^2) from current money
  4. ; where l is the level of the highest leveled Pokemon in the party
  5.         ld hl,DCFE ; pokemon 1 level
  6.         ld de,0030 ; pokemon n level - pokemon n-1 level
  7.         ld a,(DCD7) ; party count
  8.         ld b,a
  9. ; get highest level from party
  10. loop:
  11.         cp (hl)
  12.         jr nc, .keepold
  13.         ld a,(hl)
  14. .keepold
  15.         add hl,de
  16.         dec b
  17.         jr nz,loop
  18. ; get level^2 * 4
  19.         ld (FF00+B6),a ; highest level into hMultiplicand
  20.         ld (FF00+B7),a ; highest level into hMultiplier
  21.         xor a
  22.         ld (FF00+B4),a ; hMultiplicand
  23.         ld (FF00+B5),a ; hMultiplicand
  24.         call Multiply_3119 ; level^2 at FFB5-FFB6
  25.         ld a,4
  26.         ld (FF00+B7),a
  27.         call Multiply_3119 ; level^2 * 4 at FFB5-FFB6
  28. ; substract it from money
  29.         ld hl, Money+2 ; lowest byte
  30.         ld a,(FF00+B6)
  31.         ld b,a
  32.         ld a,(hl)
  33.         sub b
  34.         ld (hld),a
  35.         ld a,(FF00+B5)
  36.         ld b,a
  37.         ld a,(hl) ; middle byte
  38.         sbc b
  39.         ld (hld),a
  40.         ld b,0
  41.         ld a,(hl) ; highest byte
  42.         sbc b
  43.         ld (hl),a
  44.         ret nc
  45. ; prevent underflow
  46.         xor a
  47.         ld (hli),a
  48.         ld (hli),a
  49.         ld (hl),a
  50.         ret
  51.  
  52.  
  53. ; *************************************************************************************************************************************
  54.  
  55.  
  56. ; asm_3ffaa
  57. ; multiply exp about to gain by enemy's level and divide by player's level (maximum factor is 2/1)
  58. ; only as long as enemy's level is the highest of the two (never disfavors the player)
  59. ; output result at ff00 + b5 and ff00 + b6
  60. ; (D213) = EnemyMonLevel
  61. ; (D109) = CurPartyMon
  62.         call z, DoubleExp ; this is what we overwrote with jp 7FAA (2nd part of Lucky Egg check)
  63.  
  64. ; (ff00+B5) = hMultiplicandMiddleByte = (at this point) ExpHighByte
  65. ; (ff00+B6) = hMultiplicandLowByte = (at this point) ExpLowByte
  66.         push af
  67.         push bc
  68.         push de
  69.         push hl
  70.         ld a,(D109)
  71.         ld hl,DCCE ; PartyMon1Level - 30
  72.         ld bc,0030
  73.         inc a
  74. .loop
  75. ; make hl point to level of CurPartyMon
  76.         add hl,bc
  77.         dec a
  78.         jr nz, .loop
  79.  
  80.         ld b,(hl) ; level of CurPartyMon into b
  81.         ld a,(D213) ; EnemyMonLevel into a
  82.         cp b
  83.         jr c, .finish ; do nothing if player's level is higher than enemy's level
  84.         sla b ; level of CurPartyMon * 2 into b
  85.         cp b
  86.         jr nc, .double ; if enemy's level is at least twice as high as player's level, exp is only doubled     
  87.  
  88.         ld (ff00+B7),a ; EnemyMonLevel into hMultiplier
  89.         xor a
  90.         ld (ff00+B4),a ; just in case...
  91.         call Multiply ; returns Experience * EnemyMonLevel at hProduct = hDividend
  92.         ld a,(hl) ;
  93.         ld (ff00+B7),a ; level of CurPartyMon into hDivisor
  94.         ld b,4
  95.         call Divide ; returns Experience * EnemyMonLevel / level of CurPartyMon  at hQuotient
  96. ; ff00 + B4 should always contain 00, so there's nothing else to do
  97. .finish
  98.         pop hl
  99.         pop de
  100.         pop bc
  101.         pop af 
  102.         jp 6EF8 ; go back to where we jumped from
  103.  
  104. .double
  105.         ld a,2
  106.         ld (ff00+B7),a
  107.         call Multiply ; double experience
  108.         jr .finish
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top