Skip to content

Commit

Permalink
Merge pull request #177 from suloku/master
Browse files Browse the repository at this point in the history
Daycare Stuff
  • Loading branch information
PiaCarrot authored Apr 17, 2024
2 parents 496039a + 6d0b4ba commit f549b44
Show file tree
Hide file tree
Showing 17 changed files with 397 additions and 26 deletions.
68 changes: 68 additions & 0 deletions battle/core.asm
Original file line number Diff line number Diff line change
Expand Up @@ -4124,6 +4124,24 @@ RecallPlayerMon: ; 3dce6
ret
; 3dcf9

HandleBugBiteEatBerry:
ld a, [hLinkPlayerNumber]
cp $1
jr z, .player_1
call SetEnemyTurn
call UseHPHealingEatenBerry
call UseHeldStatusHealingItem
call UseConfusionHealingItem
call SetPlayerTurn
ret
.player_1
call SetPlayerTurn
call UseHPHealingEatenBerry
call UseHeldStatusHealingItem
call UseConfusionHealingItem
call SetEnemyTurn
ret

HandleHealingItems: ; 3dcf9
ld a, [hLinkPlayerNumber]
cp $1
Expand All @@ -4148,6 +4166,56 @@ HandleHealingItems: ; 3dcf9
jp UseConfusionHealingItem
; 3dd2f

UseHPHealingEatenBerry:
farcall GetOpponentItem
ld a, b
cp $1
ret nz
ld de, EnemyMonHP + 1
ld hl, EnemyMonMaxHP
ld a, [hBattleTurn]
and a
jr z, .less
ld de, BattleMonHP + 1
ld hl, BattleMonMaxHP
.less
call ItemRecoveryAnim
; store max HP in Buffer1/2
ld a, [hli]
ld [Buffer2], a
ld a, [hl]
ld [Buffer1], a
ld a, [de]
add c
ld [Buffer5], a
ld c, a
dec de
ld a, [de]
adc $0
ld [Buffer6], a
ld b, a
ld a, [hld]
cp c
ld a, [hl]
sbc b
jr nc, .okay
ld a, [hli]
ld [Buffer6], a
ld a, [hl]
ld [Buffer5], a

.okay
ld a, [Buffer6]
ld [de], a
inc de
ld a, [Buffer5]
ld [de], a
ld a, [hBattleTurn]
ld [wWhichHPBar], a
and a
jp UseOpponentItem

HandleHPHealingItem: ; 3dd2f
farcall GetOpponentItem
ld a, b
Expand Down
1 change: 1 addition & 0 deletions battle/effect_command_pointers.asm
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,5 @@ BattleCommandPointers: ; 3fd28
dw BattleCommand_SuperEffectiveLoopText ; 351a5
dw BattleCommand_StartLoop ; 35197
dw BattleCommand_Curl ; 365a7
dw BattleCommand_Bugbite
; 3fe86
2 changes: 2 additions & 0 deletions battle/effect_commands.asm
Original file line number Diff line number Diff line change
Expand Up @@ -9348,3 +9348,5 @@ AppearUserRaiseSub: ; 37ece
ret

; 37ed5

INCLUDE "battle/effects/bugbite.asm"
144 changes: 144 additions & 0 deletions battle/effects/bugbite.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
BattleCommand_Bugbite:
; Bugbite

ld a, [hBattleTurn]
and a
jr nz, .enemy

; The enemy needs to have an item to eat.

call .enemyitem
ld a, [hl]
and a
ret z

; Enemy's item needs to be a berry.

ld [wd265], a
ld d, a
call ItemIsBerry
ret nc

ld a, [EffectFailed]
and a
ret nz

ld a, [wLinkMode]
and a
jr z, .stealenemyitem

ld a, [wBattleMode]
dec a
ret z

.stealenemyitem
call .playeritem
ld a, [hl]
push af ;store player's held item
ld a, [wd265] ;wd265 holds the berry ID
ld [hl], a ;overwrite BattleMon held item temporarily
ld [de], a ;overwrite PartyMon held item temporarily
call GetItemName
ld hl, EatBerryText
call StdBattleTextBox
;now we need to actually consume that berry
farcall HandleBugBiteEatBerry
;restore previous held item from party struct
call .playeritem
pop af
ld [hl], a
ld [de], a
;erase enemy berry
call .enemyitem ;get address for loaded enemy mon and that mon's enemy party
xor a
ld [hl], a ;erase EnemyMonItem
ld [de], a ;erase OTPartyMonXItem
ret

.enemy

; The player must have an item to steal.

call .playeritem
ld a, [hl]
and a
ret z

; Enemy's item needs to be a berry.

ld [wd265], a
ld d, a
call ItemIsBerry
ret nc

ld a, [EffectFailed]
and a
ret nz

; If the enemy eats your berry, it's gone for good
call .enemyitem
ld a, [hl]
push af ;store player's held item
ld a, [wd265] ;wd265 holds the berry ID
ld [hl], a ;overwrite BattleMon held item temporarily
ld [de], a ;overwrite PartyMon held item temporarily
call GetItemName
ld hl, EatBerryText
call StdBattleTextBox
;now we need to actually consume that berry
farcall HandleBugBiteEatBerry
;restore previous held item from party struct
call .enemyitem
pop af
ld [hl], a
ld [de], a
;erase player berry
call .playeritem ;get address for loaded enemy mon and that mon's enemy party
xor a
ld [hl], a ;erase EnemyMonItem
ld [de], a ;erase OTPartyMonXItem
ret

.playeritem
ld a, 1
call BattlePartyAttr
ld d, h
ld e, l
ld hl, BattleMonItem
ret

.enemyitem
ld a, 1
call OTPartyAttr
ld d, h
ld e, l
ld hl, EnemyMonItem
ret

ItemIsBerry:
ld a, d
ld hl, .items
ld de, 1
jp IsInArray

.items
db PINKAN_BERRY
db PSNCUREBERRY
db PRZCUREBERRY
db BURNT_BERRY
db ICE_BERRY
db BITTER_BERRY
db MINT_BERRY
db MIRACLEBERRY
db MYSTERYBERRY
db BERRY
db GOLD_BERRY
db -1
23 changes: 22 additions & 1 deletion battle/moves/move_effects.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
BugBite: ; TODO: implement EFFECT_BUG_BITE
BugBite:
checkobedience
usedmovetext
doturn
critical
damagestats
damagecalc
stab
damagevariation
checkhit
effectchance
hittarget
failuretext
checkfaint
criticaltext
supereffectivetext
bugbite
checkdestinybond
buildopponentrage
kingsrock
endmove

KarateChop:
Scratch:
Cut:
Expand Down
2 changes: 1 addition & 1 deletion battle/moves/moves.asm
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ endc
move SWAGGER, EFFECT_SWAGGER, 0, STATUS, NORMAL, 85, 15, 100
move WATER_PULSE, EFFECT_CONFUSE_HIT, 60, SPECIAL, WATER, 100, 20, 20
move SPARK, EFFECT_PARALYZE_HIT, 65, PHYSICAL, ELECTRIC, 100, 20, 30
move BUG_BITE, EFFECT_BUG_BITE, 60, PHYSICAL, BUG, 100, 20, 0
move BUG_BITE, EFFECT_BUG_BITE, 60, PHYSICAL, BUG, 100, 20, 100
move STEEL_WING, EFFECT_STEEL_WING, 70, PHYSICAL, STEEL, 90, 25, 10
move MEAN_LOOK, EFFECT_MEAN_LOOK, 0, STATUS, NORMAL, 100, 5, 0
move ATTRACT, EFFECT_ATTRACT, 0, STATUS, NORMAL, 100, 15, 0
Expand Down
6 changes: 3 additions & 3 deletions constants/event_flags.asm
Original file line number Diff line number Diff line change
Expand Up @@ -661,15 +661,15 @@
const EVENT_AIRSHIP_BIRDS
;Adding new events here to mantain savegame compatibility
const EVENT_MANDARIN_CAVE_KECLEON_FOUGHT ;01:d998 bit 3
const EVENT_MANDARIN_CAVE_KECLEON_FOUGHT
const EVENT_SUNRAY_CAVE_1F_MARSHADOW_FOUGHT
const EVENT_SUNRAY_CAVE_1F_CROSS_HS
const EVENT_SUNRAY_CAVE_1F_CROSS_HS ;cross sprite hide/show flag
const EVENT_CROSS_CORRUPTED_SUNRAY
const EVENT_CROSS_CORRUPTED_FOUGHT
const EVENT_ROUTE51_HO_OH_FOUGHT
const EVENT_TANGELO_JUNGLE_MEW_FOUGHT
const EVENT_VICTORY_ROAD_MEWTWO_FOUGHT
const EVENT_TARROCO_CELEBI_FOUGHT
const EVENT_SUNRAY_CAVE_1F_MARSHADOW_HS
const EVENT_SUNRAY_CAVE_1F_MARSHADOW_HS ;marshadow sprite hide/show flag

NUM_EVENTS EQU const_value
1 change: 1 addition & 0 deletions engine/map_triggers.asm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ ENDM
trigger_def ICE_ISLAND, wIceIslandTrigger
trigger_def SUNRAY_CAVE_MANDARIN_DESERT_1F, wSunrayCaveTrigger
trigger_def ROUTE_51, wRoute51Trigger
trigger_def DAYCARE, wDayCareTrigger

db -1
; 4d15b
2 changes: 2 additions & 0 deletions event/daycare.asm
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ Special_DayCareManOutside: ; 16936
jr .Load0

.Declined:
ld hl, wDaycareMan ;mantain breeding compatibility set to produce more eggs after declining
set 5, [hl] ;mantain breeding compatibility set to produce more eggs after declining
ld hl, .IllKeepItThanksText

.Load0:
Expand Down
10 changes: 8 additions & 2 deletions event/happiness_egg.asm
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,17 @@ DaycareStep:: ; 7282
ld hl, wStepsToEgg
dec [hl]
ret nz

call Random
ld [hl], a
farcall CheckBreedmonCompatibility
if DEF(DEBUG) ;skip compatibility checks
jp .okay
endc
ld a, [wd265]
cp 230
ld b, -1 + 32 percent
jr nc, .okay
;jr nc, .okay
jr .okay ;always check egg production with maximum compatibility
ld a, [wd265]
cp 170
ld b, 16 percent
Expand All @@ -231,7 +234,10 @@ DaycareStep:: ; 7282
.okay
call Random
cp b
if DEF(DEBUG) ;always produce an egg in debug version
else
ret nc
endc
ld hl, wDaycareMan
res 5, [hl]
set 6, [hl]
Expand Down
1 change: 1 addition & 0 deletions macros/move_effect.asm
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ endm
command supereffectivelooptext ; ac
command startloop ; ad
command curl ; ae
command bugbite ; af

enum_start -1, -1
command endmove
Expand Down
Loading

0 comments on commit f549b44

Please sign in to comment.