IdainTV

Soothe Bell Implementation - ChangeHappiness

Sep 30th, 2021 (edited)
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ChangeHappiness:
  2. ; Perform happiness action c on wCurPartyMon
  3.  
  4.     ld a, [wCurPartyMon]
  5.     inc a
  6.     ld e, a
  7.     ld d, 0
  8.     ld hl, wPartySpecies - 1
  9.     add hl, de
  10.     ld a, [hl]
  11.     cp EGG
  12.     ret z
  13.  
  14.     ld a, MON_HAPPINESS
  15.     call GetPartyParamLocation
  16.  
  17.     ld d, h
  18.     ld e, l
  19.  
  20.     push de
  21.     ld a, [de]
  22.     cp HAPPINESS_THRESHOLD_1
  23.     ld e, 0
  24.     jr c, .ok
  25.     inc e
  26.     cp HAPPINESS_THRESHOLD_2
  27.     jr c, .ok
  28.     inc e
  29.  
  30. .ok
  31.     dec c
  32.     ld b, 0
  33.     ld hl, HappinessChanges
  34.     add hl, bc
  35.     add hl, bc
  36.     add hl, bc
  37.     ld d, 0
  38.     add hl, de
  39.     pop de
  40.     ; If happiness change is 0, don't modify anything.
  41.     ld a, [hl]
  42.     and a
  43.     jr z, .done2
  44.     ld b, a
  45.     add a
  46.     jr c, .negative
  47.  
  48.     ld a, MON_ITEM
  49.     call GetPartyParamLocation
  50.     ld a, [hl]
  51.     cp SOOTHE_BELL
  52.     jr nz, .continue
  53.  
  54.     ld a, b
  55.     inc a
  56.     srl a
  57.     add b
  58.     ld b, a
  59.     ; fallthrough
  60. .continue
  61.     ld a, [de]
  62.     add b
  63.     jr nc, .done
  64.     ld a, $ff
  65.     jr .done
  66.  
  67. .negative
  68.     ld a, [de]
  69.     add b
  70.     jr c, .done
  71.     xor a
  72.     ; fallthrough
  73. .done
  74.     ld [de], a
  75. .done2
  76.     ld a, [wBattleMode]
  77.     and a
  78.     ret z
  79.     ld a, [wCurPartyMon]
  80.     ld b, a
  81.     ld a, [wPartyMenuCursor]
  82.     cp b
  83.     ret nz
  84.     ld a, [de]
  85.     ld [wBattleMonHappiness], a
  86.     ret
  87.  
  88. INCLUDE "data/events/happiness_changes.asm"
Add Comment
Please, Sign In to add comment