Skip to content

More Damage Based on Retreat Cost

RealCataclyptic edited this page Apr 27, 2025 · 6 revisions

This tutorial will focus on the simple, yet fun, effect of dealing damage based on the Defending Pokémon's Retreat Cost. There will be three different effects presented. In this first section, we will define effect commands for an attack that does 10 times the Defending Pokémon's Retreat Cost and another attack that will add 10 more damage for each Colorless Energy symbol in the Defending Pokémon's Retreat Cost. The second section will feature a more advanced effect, wherein one can do damage based upon the total retreat cost of all one player's Pokémon in play.


  1. First, we need to add the following code to src/engine/duel/effect_commands.asm:
; sets attack's damage to 10 times the Defending Pokémon's adjusted Retreat Cost
Do10PerOppRCEffectCommands:
	dbw EFFECTCMDTYPE_BEFORE_DAMAGE, LowKickEffect
	dbw EFFECTCMDTYPE_AI, LowKickEffect
	db  $00

; increases attack's damage by 10 times the Defending Pokémon's adjusted Retreat Cost 
Do10MorePerOppRCEffectCommands:
	dbw EFFECTCMDTYPE_BEFORE_DAMAGE, GrassKnotEffect
	dbw EFFECTCMDTYPE_AI, GrassKnot_AIEffect
	db  $00

Since this effect is very simple, we only have two commands for each attack: one for the player, and another for the AI to understand it. As always, name these effects however you like.

  1. Next, we need to create the actual attack effects in src/engine/duel/effect_functions.asm
; output:
;	a = 10 * Defending Pokémon's adjusted Retreat Cost (accounting for things like Retreat Aid)
RCPlusDamageCalc:
        call SwapTurn
	ld e, PLAY_AREA_ARENA
	call GetPlayAreaCardRetreatCost
	call SwapTurn
	jp ATimes10 ; multiplies result by 10

LowKickEffect: 
	call RCPlusDamageCalc ; calls the calculation by the above function
	jp SetDefiniteDamage  ; and sets the attack's damage to the result

GrassKnotEffect:
        call RCPlusDamageCalc ; calls the calculation by the above function
	jp AddToDamage        ; and adds the result to the attack's base damage

GrassKnot_AIEffect:
        call GrassKnotEffect
	jp SetDefiniteAIDamage

And that's all it takes to program this simple, yet potent effect. However, we can go even further beyond...


In this section, we will create an attack effect that does 10 damage times the number of [C] in the retreat cost of all Pokémon in the player's field. To do this, we'll have to borrow some code from the Energy Burst function, then modify it to suit our needs.

  1. Once again, add a new effect command to src/engine/duel/effect_commands.asm:
; sets attack's damage to 10 times the retreat cost of all the turn player's Pokémon 
Damage10xAllRCinYourPKMN: ; Does 10x times the total retreat costs of all your pokemon in play
	dbw EFFECTCMDTYPE_BEFORE_DAMAGE, CalcAllRCInPlayAreaEffect
	dbw EFFECTCMDTYPE_AI, AI_CalcAllRCInPlayAreaEffect
	db  $00

Simple effect commands again, but the function will be more in depth this time.

  1. Next, we create the attack effect in src/engine/duel/effect_functions.asm
CalcAllRCInPlayAreaEffect:
; sets attack damage to 10x the number of {C} symbols
; in the Retreat Costs of all of the turn holder's Pokémon.
; preserves de
    	ld a, DUELVARS_NUMBER_OF_POKEMON_IN_PLAY_AREA         ; count the number of play area pokemon, store to a.
   	call GetTurnDuelistVariable                           ; - of the current player's turn only.
    	ld b, a                                               ; store a to b
    	ld l, DUELVARS_ARENA_CARD     
   	; hl is now set to the first duel variable that holds the deck indices of the turn holder's play area Pokémon
   	ld c, 0                                               ; initial Retreat Cost counter, set to 0 before counting to prevent errors
   	ld e, c                                               ; PLAY_AREA_ARENA

; loop through each play area Pokémon, adding its Retreat Cost to c
.loop_play_area
   	ld a, [hli]
   	call LoadCardDataToBuffer1_FromDeckIndex      ; Load card data of current card
   	ld a, [wLoadedCard1RetreatCost]               ; Get the retreat cost value
    	add c                                         ; Add the previous retreat cost value, c
   	ld c, a                                       ; Add the retreat cost value found in a to c
    	dec b                                         ; Decrease number of pokemon to count by 1
    	jr nz, .loop_play_area                        ; If it hits 0, go to .done. Otherwise, repeat the loop. 
.done
    	ld a, c                                       ; Load final retreat cost value to a
    	call ATimes10                                 ; Multiply A by 10
    	jp SetDefiniteDamage                          ; Damage!

AI_CalcAllRCInPlayAreaEffect:
	call CalcAllRCInPlayAreaEffect
	jp SetDefiniteAIDamage

And that's all for this function.

Clone this wiki locally