Advertisement
wolfboyft

Is this working?

Mar 8th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. BattleCommand_DamageVariation: ; 34cfd
  2. ; damagevariation
  3.  
  4. ; Modify the damage spread between 85% and 100%.
  5.  
  6. ; Because of the method of division the probability distribution
  7. ; is not consistent. This makes the highest damage multipliers
  8. ; rarer than normal.
  9.  
  10.  
  11. ; No point in reducing 1 or 0 damage.
  12. ld hl, CurDamage
  13. ld a, [hli]
  14. and a
  15. jr nz, .go
  16. ld a, [hl]
  17. cp 2
  18. ret c
  19.  
  20. .go
  21. ; Start with the maximum damage.
  22. xor a
  23. ld [hMultiplicand + 0], a
  24. dec hl
  25. ld a, [hli]
  26. ld [hMultiplicand + 1], a
  27. ld a, [hl]
  28. ld [hMultiplicand + 2], a
  29.  
  30. ; Multiply by 85-100%...
  31. .loop
  32. call BattleRandom
  33. rrca
  34. cp $d9 ; 85%
  35. jr c, .loop
  36.  
  37. ld [hMultiplier], a
  38. call Multiply
  39.  
  40. ; ...divide by 100%...
  41. ld a, $ff ; 100%
  42. ld [hDivisor], a
  43. ld b, $4
  44. call Divide
  45.  
  46. ; ...to get .85-1.00x damage.
  47. ld a, [hQuotient + 1]
  48. ld hl, CurDamage
  49. ld [hli], a
  50. ld a, [hQuotient + 2]
  51.  
  52. ; it starts here
  53.  
  54. push hl
  55. push af
  56. ld hl, BattleMonItem
  57. ld a, [hBattleTurn]
  58. and a
  59. jr z, .got_item_addr
  60. ld hl, EnemyMonItem
  61. .got_item_addr
  62. ld a, [hl]
  63. cp STICK
  64. ld [hl], a
  65. jr z, .reduceDamage
  66. pop af
  67. pop hl
  68. .returnToFray
  69. ld h, b
  70. ld l, c
  71. ret
  72. ; 34d32401
  73.  
  74. .reduceDamage
  75. jr .popsYes
  76. .popsYesBack
  77. ld b, h
  78. ld c, l
  79. ld a, 17
  80. call ReduceNumberByAPercent
  81. jr .returnToFray
  82.  
  83. .popsYes
  84. pop af
  85. pop hl
  86. jr .popsYesBack
  87.  
  88. ReduceNumberByAPercent: ; thanks PikalaxALT!
  89. ; number in bc, percentage in a
  90. push af
  91. ld a, b
  92. ld [hMultiplicand + 1], a
  93. ld a, c
  94. ld [hMultiplicand + 2], a
  95. xor a
  96. ld [hMultiplicand], a
  97. pop bc
  98. ld a, 100
  99. sub b
  100. ld [hMultiplier], a
  101. call Multiply
  102. ld a, 100
  103. ld [hDivisor], a
  104. ld b, 4
  105. call Divide
  106. ld a, [hQuotient + 1]
  107. ld b, a
  108. ld a, [hQuotient + 2]
  109. ld c, a
  110. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement