def pbThrowPokeBall(idxPokemon,ball,rareness=nil)
itemname=PBItems.getName(ball)
battler=nil
if pbIsOpposing?(idxPokemon)
battler=self.battlers[idxPokemon]
else
battler=self.battlers[idxPokemon].pbOppositeOpposing
end
if battler.hp<=0
battler=battler.pbPartner
end
pbDisplayBrief(_INTL("{1} threw one {2}!",self.pbPlayer.name,itemname))
if battler.hp<=0
pbDisplay(_INTL("But there was no target..."))
return
end
if @opponent && (!pbIsSnagBall?(ball) || !battler.isShadow?)
@scene.pbThrowAndDeflect(ball,1)
pbDisplay(_INTL("The Trainer blocked the Ball!\nDon't be a thief!"))
else
pokemon=battler.pokemon
species=pokemon.species
if $DEBUG && Input.press?(Input::CTRL)
shakes=4
else
if !rareness
dexdata=pbOpenDexData
pbDexDataOffset(dexdata,species,16)
rareness=dexdata.fgetb # Get rareness from dexdata file
dexdata.close
end
a=battler.totalhp
b=battler.hp
rareness=BallHandlers.modifyCatchRate(ball,rareness,self,battler)
x=(((a*3-b*2)*rareness)/(a*3)).floor
[COLOR="Red"]x*=2 if $game_switches[XX] #Where XX is the switch number[/COLOR]
if battler.status==PBStatuses::SLEEP || battler.status==PBStatuses::FROZEN
x*=2
elsif battler.status!=0
x=(x*3/2).floor
end
shakes=0
if x>255 || BallHandlers.isUnconditional?(ball,self,battler)
shakes=4
else
x=1 if x==0
y = 0x000FFFF0 / (Math.sqrt(Math.sqrt( 0x00FF0000/x ) ) )
shakes+=1 if pbRandom(65536)<y
shakes+=1 if pbRandom(65536)<y
shakes+=1 if pbRandom(65536)<y
shakes+=1 if pbRandom(65536)<y
end
end
@scene.pbThrow(ball,shakes,battler.index)
case shakes
when 0
pbDisplay(_INTL("Oh no! The Pokémon broke free!"))
when 1
pbDisplay(_INTL("Aww... It appeared to be caught!"))
when 2
pbDisplay(_INTL("Aargh! Almost had it!"))
when 3
pbDisplay(_INTL("Shoot! It was so close, too!"))
when 4
pbDisplayBrief(_INTL("Gotcha! {1} was caught!",pokemon.name))
@scene.pbThrowSuccess
if pbIsSnagBall?(ball) && @opponent
pbRemoveFromParty(battler.index,battler.pokemonIndex)
battler.pbReset
battler.participants=[]
else
@decision=4
end
if pbIsSnagBall?(ball)
pokemon.ot=self.pbPlayer.name
pokemon.trainerID=self.pbPlayer.id
end
BallHandlers.onCatch(ball,self,pokemon)
pokemon.ballused=pbGetBallType(ball)
if !self.pbPlayer.owned[species]
self.pbPlayer.owned[species]=true
if $Trainer.pokedex
pbDisplayPaused(_INTL("{1}'s data was added to the Pokédex.",pokemon.name))
@scene.pbShowPokedex(species)
end
end
@scene.pbHideCaptureBall
if pbIsSnagBall?(ball) && @opponent
pokemon.pbUpdateShadowMoves rescue nil
@snaggedpokemon.push(pokemon)
else
pbStorePokemon(pokemon)
end
end
end
end
end