Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Results of battle:
- # 0 - Undecided or aborted
- # 1 - Player won
- # 2 - Player lost
- # 3 - Player or wild Pokémon ran from battle, or player forfeited the match
- # 4 - Wild Pokémon was caught
- # 5 - Draw
- ################################################################################
- # Battle Peer.
- ################################################################################
- class PokeBattle_NullBattlePeer
- def pbStorePokemon(player,pokemon)
- if player.party.length<6
- player.party[player.party.length]=pokemon
- return -1
- else
- return -1
- end
- end
- def pbOnEnteringBattle(battle,pokemon)
- end
- def pbGetStorageCreator()
- return nil
- end
- def pbCurrentBox()
- return -1
- end
- def pbBoxName(box)
- return ""
- end
- end
- class PokeBattle_BattlePeer
- def self.create
- return PokeBattle_NullBattlePeer.new()
- end
- end
- ################################################################################
- # Success State.
- ################################################################################
- class PokeBattle_SuccessState
- attr_accessor :typemod
- attr_accessor :useState # 0 - not used, 1 - failed, 2 - succeeded
- attr_accessor :protected
- attr_accessor :skill # Used in Battle Arena
- def initialize
- clear
- end
- def clear
- @typemod=4
- @useState=0
- @protected=false
- @skill=0
- end
- def updateSkill
- if @useState==1 && !@protected
- @skill-=2
- elsif @useState==2
- if @typemod>4
- @skill+=2 # "Super effective"
- elsif @typemod>=1 && @typemod<4
- @skill-=1 # "Not very effective"
- elsif @typemod==0
- @skill-=2 # Ineffective
- else
- @skill+=1
- end
- end
- @typemod=4
- @useState=0
- @protected=false
- end
- end
- ################################################################################
- # Catching and storing Pokémon.
- ################################################################################
- module PokeBattle_BattleCommon
- def pbStorePokemon(pokemon)
- if !(pokemon.isShadow? rescue false)
- if pbDisplayConfirm(_INTL("Would you like to give a nickname to {1}?",pokemon.name))
- species=PBSpecies.getName(pokemon.species)
- nickname=@scene.pbNameEntry(_INTL("{1}'s nickname?",species),pokemon)
- pokemon.name=nickname if nickname!=""
- end
- end
- oldcurbox=@peer.pbCurrentBox()
- storedbox=@peer.pbStorePokemon(self.pbPlayer,pokemon)
- creator=@peer.pbGetStorageCreator()
- return if storedbox<0
- curboxname=@peer.pbBoxName(oldcurbox)
- boxname=@peer.pbBoxName(storedbox)
- if storedbox!=oldcurbox
- if creator
- pbDisplayPaused(_INTL("Box \"{1}\" on {2}'s PC was full.",curboxname,creator))
- else
- pbDisplayPaused(_INTL("Box \"{1}\" on someone's PC was full.",curboxname))
- end
- pbDisplayPaused(_INTL("{1} was transferred to box \"{2}\".",pokemon.name,boxname))
- else
- if creator
- pbDisplayPaused(_INTL("{1} was transferred to {2}'s PC.",pokemon.name,creator))
- else
- pbDisplayPaused(_INTL("{1} was transferred to someone's PC.",pokemon.name))
- end
- pbDisplayPaused(_INTL("It was stored in box \"{1}\".",boxname))
- end
- end
- def pbThrowPokeBall(idxPokemon,ball,rareness=nil,showplayer=false)
- itemname=PBItems.getName(ball)
- battler=nil
- if pbIsOpposing?(idxPokemon)
- battler=self.battlers[idxPokemon]
- else
- battler=self.battlers[idxPokemon].pbOppositeOpposing
- end
- if battler.isFainted?
- battler=battler.pbPartner
- end
- pbDisplayBrief(_INTL("{1} threw one {2}!",self.pbPlayer.name,itemname))
- if battler.isFainted?
- pbDisplay(_INTL("But there was no target..."))
- return
- end
- if @opponent && (!pbIsSnagBall?(ball) || !battler.isShadow?)
- @scene.pbThrowAndDeflect(ball,1)
- if $game_switches[290]==false
- pbDisplay(_INTL("The Trainer blocked the Ball!\nDon't be a thief!"))
- else
- pbDisplay(_INTL("The Pokémon knocked the ball away!"))
- end
- else
- if $game_switches[290]==true || $game_variables[975]!=0
- pbDisplay(_INTL("The Pokémon knocked the ball away!"))
- return
- end
- 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
- if battler.status==PBStatuses::SLEEP || battler.status==PBStatuses::FROZEN
- x=(x*2.5).floor
- elsif battler.status!=0
- x=(x*3/2).floor
- end
- #Critical Capture chances based on caught species'
- c=0
- if $Trainer
- if $Trainer.pokedexOwned>600
- c=(x*2.5/6).floor
- elsif $Trainer.pokedexOwned>450
- c=(x*2/6).floor
- elsif $Trainer.pokedexOwned>300
- c=(x*1.5/6).floor
- elsif $Trainer.pokedexOwned>150
- c=(x*1/6).floor
- elsif $Trainer.pokedexOwned>30
- c=(x*0.5/6).floor
- end
- end
- shakes=0; critical=false; critsuccess=false
- if x>255 || BallHandlers.isUnconditional?(ball,self,battler)
- shakes=4
- else
- x=1 if x==0
- y = ( 65536 / ((255.0/x)**0.1875) ).floor
- if pbRandom(256)<c
- critical=true
- if pbRandom(65536)<y
- critsuccess=true
- shakes=4
- end
- else
- 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
- end
- @scene.pbThrow(ball,(critical) ? 1 : shakes,critical,critsuccess,battler.index,showplayer)
- case shakes
- when 0
- pbDisplay(_INTL("Oh no! The Pokémon broke free!"))
- BallHandlers.onFailCatch(ball,self,pokemon)
- when 1
- pbDisplay(_INTL("Aww... It appeared to be caught!"))
- BallHandlers.onFailCatch(ball,self,pokemon)
- when 2
- pbDisplay(_INTL("Aargh! Almost had it!"))
- BallHandlers.onFailCatch(ball,self,pokemon)
- when 3
- pbDisplay(_INTL("Shoot! It was so close, too!"))
- BallHandlers.onFailCatch(ball,self,pokemon)
- 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)
- pokemon.pbRecordFirstMoves
- 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
- ################################################################################
- # Main battle class.
- ################################################################################
- class PokeBattle_Battle
- attr_reader(:scene) # Scene object for this battle
- attr_accessor(:decision) # Decision: 0=undecided; 1=win; 2=loss; 3=escaped; 4=caught
- attr_accessor(:internalbattle) # Internal battle flag
- attr_accessor(:doublebattle) # Double battle flag
- attr_accessor(:cantescape) # True if player can't escape
- attr_accessor(:shiftStyle) # Shift/Set "battle style" option
- attr_accessor(:battlescene) # "Battle scene" option
- attr_accessor(:debug) # Debug flag
- attr_reader(:player) # Player trainer
- attr_reader(:opponent) # Opponent trainer
- attr_reader(:party1) # Player's Pokémon party
- attr_reader(:party2) # Foe's Pokémon party
- attr_reader(:partyorder) # Order of Pokémon in the player's party
- attr_accessor(:fullparty1) # True if player's party's max size is 6 instead of 3
- attr_accessor(:fullparty2) # True if opponent's party's max size is 6 instead of 3
- attr_reader(:battlers) # Currently active Pokémon
- attr_accessor(:items) # Items held by opponents
- attr_reader(:sides) # Effects common to each side of a battle
- attr_reader(:field) # Effects common to the whole of a battle
- attr_accessor(:environment) # Battle surroundings
- attr_accessor(:weather) # Current weather, custom methods should use pbWeather instead
- attr_accessor(:weatherduration) # Duration of current weather, or -1 if indefinite
- attr_reader(:switching) # True if during the switching phase of the round
- attr_reader(:faintswitch) # True if switching after a faint during endphase
- attr_reader(:struggle) # The Struggle move
- attr_accessor(:choices) # Choices made by each Pokémon this round
- attr_reader(:successStates) # Success states
- attr_accessor(:lastMoveUsed) # Last move used
- attr_accessor(:lastMoveUser) # Last move user
- attr_accessor(:synchronize) # Synchronize state
- attr_accessor(:megaEvolution) # Battle index of each trainer's Pokémon to Mega Evolve
- attr_accessor(:amuletcoin) # Whether Amulet Coin's effect applies
- attr_accessor(:extramoney) # Money gained in battle by using Pay Day
- attr_accessor(:endspeech) # Speech by opponent when player wins
- attr_accessor(:endspeech2) # Speech by opponent when player wins
- attr_accessor(:endspeechwin) # Speech by opponent when opponent wins
- attr_accessor(:endspeechwin2) # Speech by opponent when opponent wins
- attr_accessor(:trickroom)
- #### KUROTSUNE - 015 - START
- attr_accessor(:switchedOut)
- #### KUROTSUNE - 015 - END
- attr_accessor(:previousMove) # Move used directly previously
- attr_accessor(:rules)
- attr_reader(:turncount)
- attr_accessor :controlPlayer
- include PokeBattle_BattleCommon
- MAXPARTYSIZE = 6
- class BattleAbortedException < Exception; end
- def pbAbort
- raise BattleAbortedException.new("Battle aborted")
- end
- def pbDebugUpdate
- end
- def pbRandom(x)
- return rand(x)
- end
- def pbAIRandom(x)
- return rand(x)
- end
- def isOnline?
- return false
- end
- ################################################################################
- # Initialise battle class.
- ################################################################################
- def initialize(scene,p1,p2,player,opponent)
- if p1.length==0
- raise ArgumentError.new(_INTL("Party 1 has no Pokémon."))
- return
- end
- if p2.length==0
- raise ArgumentError.new(_INTL("Party 2 has no Pokémon."))
- return
- end
- if p2.length>2 && !opponent
- raise ArgumentError.new(_INTL("Wild battles with more than two Pokémon are not allowed."))
- return
- end
- @scene = scene
- @decision = 0
- @internalbattle = true
- @doublebattle = false
- @cantescape = false
- @shiftStyle = true
- @battlescene = true
- @debug = false
- @debugupdate = 0
- if opponent && player.is_a?(Array) && player.length==0
- player = player[0]
- end
- if opponent && opponent.is_a?(Array) && opponent.length==0
- opponent = opponent[0]
- end
- @player = player # PokeBattle_Trainer object
- @opponent = opponent # PokeBattle_Trainer object
- @party1 = p1
- @party2 = p2
- @partyorder = []
- for i in 0...6; @partyorder.push(i); end
- @fullparty1 = false
- @fullparty2 = false
- @battlers = []
- @items = nil
- @sides = [PokeBattle_ActiveSide.new, # Player's side
- PokeBattle_ActiveSide.new] # Foe's side
- @field = PokeBattle_ActiveField.new # Whole field (gravity/rooms)
- @environment = PBEnvironment::None # e.g. Tall grass, cave, still water
- @weather = 0
- @weatherduration = 0
- @switching = false
- @faintswitch = false
- @choices = [ [0,0,nil,-1],[0,0,nil,-1],[0,0,nil,-1],[0,0,nil,-1] ]
- @successStates = []
- for i in 0...4
- @successStates.push(PokeBattle_SuccessState.new)
- end
- @lastMoveUsed = -1
- @lastMoveUser = -1
- @synchronize = [-1,-1,0]
- @megaEvolution = []
- if @player.is_a?(Array)
- @megaEvolution[0]=[-1]*@player.length
- else
- @megaEvolution[0]=[-1]
- end
- if @opponent.is_a?(Array)
- @megaEvolution[1]=[-1]*@opponent.length
- else
- @megaEvolution[1]=[-1]
- end
- @amuletcoin = false
- #### KUROTSUNE - 015 - START
- @switchedOut = []
- #### KUROTSUNE - 015 - END
- @extramoney = 0
- @endspeech = ""
- @endspeech2 = ""
- @endspeechwin = ""
- @endspeechwin2 = ""
- @rules = {}
- @turncount = 0
- @peer = PokeBattle_BattlePeer.create()
- @trickroom = 0
- @priority = []
- @usepriority = false
- @snaggedpokemon = []
- @runCommand = 0
- if hasConst?(PBMoves,:STRUGGLE)
- @struggle = PokeBattle_Move.pbFromPBMove(self,PBMove.new(getConst(PBMoves,:STRUGGLE)))
- else
- @struggle = PokeBattle_Struggle.new(self,nil)
- end
- @struggle.pp = -1
- for i in 0...4
- battlers[i] = PokeBattle_Battler.new(self,i)
- end
- for i in @party1
- next if !i
- i.itemRecycle = 0
- i.itemInitial = i.item
- end
- for i in @party2
- next if !i
- i.itemRecycle = 0
- i.itemInitial = i.item
- end
- end
- ################################################################################
- # Info about battle.
- ################################################################################
- def pbIsWild?
- return !@opponent? true : false
- end
- def pbDoubleBattleAllowed?
- return true
- end
- def pbCheckSideAbility(a,pkmn) #checks to see if your side has a pokemon with a certain ability.
- for i in 0...4 # in order from own first, opposing first, own second, opposing second
- if @battlers[i].hasWorkingAbility(a)
- if @battlers[i]==pkmn || @battlers[i]==pkmn.pbPartner
- return @battlers[i]
- end
- end
- end
- return nil
- end
- def pbWeather
- for i in 0...4
- if @battlers[i].hasWorkingAbility(:CLOUDNINE) ||
- @battlers[i].hasWorkingAbility(:AIRLOCK) ||
- $fefieldeffect == 22
- return 0
- end
- end
- return @weather
- end
- ################################################################################
- # Get battler info.
- ################################################################################
- def pbIsOpposing?(index)
- return (index%2)==1
- end
- def pbOwnedByPlayer?(index)
- return false if pbIsOpposing?(index)
- return false if @player.is_a?(Array) && index==2
- return true
- end
- def pbIsDoubleBattler?(index)
- return (index>=2)
- end
- def pbThisEx(battlerindex,pokemonindex)
- party=pbParty(battlerindex)
- if pbIsOpposing?(battlerindex)
- if @opponent
- return _INTL("The foe {1}",party[pokemonindex].name)
- else
- return _INTL("The wild {1}",party[pokemonindex].name)
- end
- else
- return _INTL("{1}",party[pokemonindex].name)
- end
- end
- # Checks whether an item can be removed from a Pokémon.
- def pbIsUnlosableItem(pkmn,item)
- return true if pbIsMail?(item)
- return false if pkmn.effects[PBEffects::Transform]
- if isConst?(pkmn.ability,PBAbilities,:MULTITYPE) &&
- (isConst?(item,PBItems,:FISTPLATE) ||
- isConst?(item,PBItems,:SKYPLATE) ||
- isConst?(item,PBItems,:TOXICPLATE) ||
- isConst?(item,PBItems,:EARTHPLATE) ||
- isConst?(item,PBItems,:STONEPLATE) ||
- isConst?(item,PBItems,:INSECTPLATE) ||
- isConst?(item,PBItems,:SPOOKYPLATE) ||
- isConst?(item,PBItems,:IRONPLATE) ||
- isConst?(item,PBItems,:FLAMEPLATE) ||
- isConst?(item,PBItems,:SPLASHPLATE) ||
- isConst?(item,PBItems,:MEADOWPLATE) ||
- isConst?(item,PBItems,:ZAPPLATE) ||
- isConst?(item,PBItems,:MINDPLATE) ||
- isConst?(item,PBItems,:ICICLEPLATE) ||
- isConst?(item,PBItems,:DRACOPLATE) ||
- isConst?(item,PBItems,:PIXIEPLATE) ||
- isConst?(item,PBItems,:DREADPLATE))
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:GIRATINA) &&
- isConst?(item,PBItems,:GRISEOUSORB)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:GENESECT) &&
- (isConst?(item,PBItems,:SHOCKDRIVE) ||
- isConst?(item,PBItems,:BURNDRIVE) ||
- isConst?(item,PBItems,:CHILLDRIVE) ||
- isConst?(item,PBItems,:DOUSEDRIVE))
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:VENUSAUR) &&
- isConst?(item,PBItems,:VENUSAURITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:CHARIZARD) &&
- (isConst?(item,PBItems,:CHARIZARDITEX) ||
- isConst?(item,PBItems,:CHARIZARDITEY))
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:BLASTOISE) &&
- isConst?(item,PBItems,:BLASTOISINITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:ABOMBASNOW) &&
- isConst?(item,PBItems,:ABOMASITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:ABSOL) &&
- isConst?(item,PBItems,:ABSOLITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:AERODACTYL) &&
- isConst?(item,PBItems,:AERODACTYLITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:AGGRON) &&
- isConst?(item,PBItems,:AGGRONITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:ALAKAZAM) &&
- isConst?(item,PBItems,:ALAKAZITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:AMPHAROS) &&
- isConst?(item,PBItems,:AMPHAROSITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:BANETTE) &&
- isConst?(item,PBItems,:BANETTITITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:BLAZIKEN) &&
- isConst?(item,PBItems,:BLAZIKENITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:GARCHOMP) &&
- isConst?(item,PBItems,:GARCHOMPITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:GARDEVOIR) &&
- isConst?(item,PBItems,:GARDEVOIRITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:GENGAR) &&
- isConst?(item,PBItems,:GENGARITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:GYARADOS) &&
- isConst?(item,PBItems,:GYARADOSITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:HERACROSS) &&
- isConst?(item,PBItems,:HERACROSSITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:HOUNDOOM) &&
- isConst?(item,PBItems,:HOUNDOOMITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:KANGASKHAN) &&
- isConst?(item,PBItems,:KANGASKHANITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:LUCARIO) &&
- isConst?(item,PBItems,:LUCARIONITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:MANECTRIC) &&
- isConst?(item,PBItems,:MANECTITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:MAWILE) &&
- isConst?(item,PBItems,:MAWILITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:MEDICHAM) &&
- isConst?(item,PBItems,:MEDICHAMITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:MEWTWO) &&
- (isConst?(item,PBItems,:MEWTWONITEX) ||
- isConst?(item,PBItems,:MEWTWONITEY))
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:PINSIR) &&
- isConst?(item,PBItems,:PINSIRITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:SCIZOR) &&
- isConst?(item,PBItems,:SCIZORITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:TYRANITAR) &&
- isConst?(item,PBItems,:TYRANITARITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:BEEDRILL) &&
- isConst?(item,PBItems,:BEEDRILLITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:PIDGEOT) &&
- isConst?(item,PBItems,:PIDGEOTITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:SLOWBRO) &&
- isConst?(item,PBItems,:SLOWBRONITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:STEELIX) &&
- isConst?(item,PBItems,:STEELIXITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:SCEPTILE) &&
- isConst?(item,PBItems,:SCEPTILITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:SWAMPERT) &&
- isConst?(item,PBItems,:SWAMPERTITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:SHARPEDO) &&
- isConst?(item,PBItems,:SHARPEDONITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:SABLEYE) &&
- isConst?(item,PBItems,:SABLENITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:CAMERUPT) &&
- isConst?(item,PBItems,:CAMERUPTITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:ALTARIA) &&
- isConst?(item,PBItems,:ALTARIANITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:GLALIE) &&
- isConst?(item,PBItems,:GLALITITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:SALAMENCE) &&
- isConst?(item,PBItems,:SALAMENCITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:METAGROSS) &&
- isConst?(item,PBItems,:METAGROSSITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:LOPUNNY) &&
- isConst?(item,PBItems,:LOPUNNITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:GALLADE) &&
- isConst?(item,PBItems,:GALLADITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:AUDINO) &&
- isConst?(item,PBItems,:AUDINITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:DIANCIE) &&
- isConst?(item,PBItems,:DIANCITE)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:GROUDON) &&
- isConst?(item,PBItems,:REDORB)
- return true
- end
- if isConst?(pkmn.species,PBSpecies,:KYOGRE) &&
- isConst?(item,PBItems,:BLUEORB)
- return true
- end
- if isConst?(item,PBItems,:PULSEHOLD)
- return true
- end
- return false
- end
- def pbCheckGlobalAbility(a)
- for i in 0...4 # in order from own first, opposing first, own second, opposing second
- if @battlers[i].hasWorkingAbility(a)
- return @battlers[i]
- end
- end
- return nil
- end
- ################################################################################
- # Player-related info.
- ################################################################################
- def pbPlayer
- if @player.is_a?(Array)
- return @player[0]
- else
- return @player
- end
- end
- def pbGetOwnerItems(battlerIndex)
- return [] if !@items
- if pbIsOpposing?(battlerIndex)
- if @opponent.is_a?(Array)
- return (battlerIndex==1) ? @items[0] : @items[1]
- else
- return @items
- end
- else
- return []
- end
- end
- def pbSetSeen(pokemon)
- if pokemon && @internalbattle
- self.pbPlayer.seen[pokemon.species]=true
- pbSeenForm(pokemon)
- end
- end
- def pbGetMegaRingName(battlerIndex)
- if pbBelongsToPlayer?(battlerIndex)
- ringsA=[:MEGARING,:MEGABRACELET,:MEGACUFF,:MEGACHARM]
- ringsB=[566] # 566 = Mega Ring.
- for i in ringsA
- next if !hasConst?(PBItems,i)
- for k in ringsB
- return PBItems.getName(k) if $PokemonBag.pbQuantity(k)>0
- end
- end
- end
- # Add your own Mega objects for particular trainer types here
- # if isConst?(pbGetOwner(battlerIndex).trainertype,PBTrainers,:BUGCATCHER)
- # return _INTL("Mega Net")
- # end
- return _INTL("Mega Ring")
- end
- def pbHasMegaRing(battlerIndex)
- return true if !pbBelongsToPlayer?(battlerIndex)
- rings=[:MEGARING,:MEGABRACELET,:MEGACUFF,:MEGACHARM]
- for i in rings
- next if !hasConst?(PBItems,i)
- return true if $PokemonBag.pbQuantity(i)>0
- end
- return false
- end
- ################################################################################
- # Get party info, manipulate parties.
- ################################################################################
- def pbPokemonCount(party)
- count=0
- for i in party
- next if !i
- count+=1 if i.hp>0 && !i.isEgg?
- end
- return count
- end
- def pbAllFainted?(party)
- pbPokemonCount(party)==0
- end
- def pbMaxLevelFromIndex(index)
- party=pbParty(index)
- owner=(pbIsOpposing?(index)) ? @opponent : @player
- maxlevel=0
- if owner.is_a?(Array)
- start=0
- limit=pbSecondPartyBegin(index)
- start=limit if pbIsDoubleBattler?(index)
- for i in start...start+limit
- next if !party[i]
- maxlevel=party[i].level if maxlevel<party[i].level
- end
- else
- for i in party
- next if !i
- maxlevel=i.level if maxlevel<i.level
- end
- end
- return maxlevel
- end
- def pbMaxLevel(party)
- lv=0
- for i in party
- next if !i
- lv=i.level if lv<i.level
- end
- return lv
- end
- def pbParty(index)
- return pbIsOpposing?(index) ? party2 : party1
- end
- def pbSecondPartyBegin(battlerIndex)
- if pbIsOpposing?(battlerIndex)
- return @fullparty2 ? 6 : 3
- else
- return @fullparty1 ? 6 : 3
- end
- end
- def pbFindNextUnfainted(party,start,finish=-1)
- finish=party.length if finish<0
- for i in start...finish
- next if !party[i]
- return i if party[i].hp>0 && !party[i].isEgg?
- end
- return -1
- end
- def pbFindPlayerBattler(pkmnIndex)
- battler=nil
- for k in 0...4
- if !pbIsOpposing?(k) && @battlers[k].pokemonIndex==pkmnIndex
- battler=@battlers[k]
- break
- end
- end
- return battler
- end
- def pbIsOwner?(battlerIndex,partyIndex)
- secondParty=pbSecondPartyBegin(battlerIndex)
- if !pbIsOpposing?(battlerIndex)
- return true if !@player || !@player.is_a?(Array)
- return (battlerIndex==0) ? partyIndex<secondParty : partyIndex>=secondParty
- else
- return true if !@opponent || !@opponent.is_a?(Array)
- return (battlerIndex==1) ? partyIndex<secondParty : partyIndex>=secondParty
- end
- end
- def pbGetOwner(battlerIndex)
- if pbIsOpposing?(battlerIndex)
- if @opponent.is_a?(Array)
- return (battlerIndex==1) ? @opponent[0] : @opponent[1]
- else
- return @opponent
- end
- else
- if @player.is_a?(Array)
- return (battlerIndex==0) ? @player[0] : @player[1]
- else
- return @player
- end
- end
- end
- def pbGetOwnerPartner(battlerIndex)
- if pbIsOpposing?(battlerIndex)
- if @opponent.is_a?(Array)
- return (battlerIndex==1) ? @opponent[1] : @opponent[0]
- else
- return @opponent
- end
- else
- if @player.is_a?(Array)
- return (battlerIndex==0) ? @player[1] : @player[0]
- else
- return @player
- end
- end
- end
- def pbGetOwnerIndex(battlerIndex)
- if pbIsOpposing?(battlerIndex)
- return (@opponent.is_a?(Array)) ? ((battlerIndex==1) ? 0 : 1) : 0
- else
- return (@player.is_a?(Array)) ? ((battlerIndex==0) ? 0 : 1) : 0
- end
- end
- def pbBelongsToPlayer?(battlerIndex)
- if @player.is_a?(Array) && @player.length>1
- return battlerIndex==0
- else
- return (battlerIndex%2)==0
- end
- return false
- end
- def pbPartyGetOwner(battlerIndex,partyIndex)
- secondParty=pbSecondPartyBegin(battlerIndex)
- if !pbIsOpposing?(battlerIndex)
- return @player if !@player || !@player.is_a?(Array)
- return (partyIndex<secondParty) ? @player[0] : @player[1]
- else
- return @opponent if !@opponent || !@opponent.is_a?(Array)
- return (partyIndex<secondParty) ? @opponent[0] : @opponent[1]
- end
- end
- def pbAddToPlayerParty(pokemon)
- party=pbParty(0)
- for i in 0...party.length
- party[i]=pokemon if pbIsOwner?(0,i) && !party[i]
- end
- end
- def pbRemoveFromParty(battlerIndex,partyIndex)
- party=pbParty(battlerIndex)
- side=(pbIsOpposing?(battlerIndex)) ? @opponent : @player
- party[partyIndex]=nil
- if !side || !side.is_a?(Array) # Wild or single opponent
- party.compact!
- for i in battlerIndex...party.length
- for j in 0..3
- next if !@battlers[j]
- if pbGetOwner(j)==side && @battlers[j].pokemonIndex==i
- @battlers[j].pokemonIndex-=1
- break
- end
- end
- end
- else
- if battlerIndex<pbSecondPartyBegin(battlerIndex)-1
- for i in battlerIndex...pbSecondPartyBegin(battlerIndex)
- if i>=pbSecondPartyBegin(battlerIndex)-1
- party[i]=nil
- else
- party[i]=party[i+1]
- end
- end
- else
- for i in battlerIndex...party.length
- if i>=party.length-1
- party[i]=nil
- else
- party[i]=party[i+1]
- end
- end
- end
- end
- end
- ################################################################################
- # Check whether actions can be taken.
- ################################################################################
- def pbCanShowCommands?(idxPokemon)
- thispkmn=@battlers[idxPokemon]
- return false if thispkmn.isFainted?
- return false if thispkmn.effects[PBEffects::TwoTurnAttack]>0
- return false if thispkmn.effects[PBEffects::HyperBeam]>0
- return false if thispkmn.effects[PBEffects::Rollout]>0
- return false if thispkmn.effects[PBEffects::Outrage]>0
- return false if thispkmn.effects[PBEffects::Rage]==true && $fefieldeffect == 24
- return false if thispkmn.effects[PBEffects::Uproar]>0
- return false if thispkmn.effects[PBEffects::Bide]>0
- #### KUROTSUNE - 022 - START
- return false if thispkmn.effects[PBEffects::SkyDrop]
- #### KUROTSUNE - 022 - END
- return true
- end
- ################################################################################
- # Attacking.
- ################################################################################
- def pbCanShowFightMenu?(idxPokemon)
- thispkmn=@battlers[idxPokemon]
- if !pbCanShowCommands?(idxPokemon)
- return false
- end
- # No moves that can be chosen
- if !pbCanChooseMove?(idxPokemon,0,false) &&
- !pbCanChooseMove?(idxPokemon,1,false) &&
- !pbCanChooseMove?(idxPokemon,2,false) &&
- !pbCanChooseMove?(idxPokemon,3,false)
- return false
- end
- # Encore
- return false if thispkmn.effects[PBEffects::Encore]>0
- return true
- end
- def pbCanChooseMove?(idxPokemon,idxMove,showMessages,sleeptalk=false)
- thispkmn=@battlers[idxPokemon]
- thismove=thispkmn.moves[idxMove]
- opp1=thispkmn.pbOpposing1
- opp2=thispkmn.pbOpposing2
- if !thismove||thismove.id==0
- return false
- end
- if thismove.pp<=0 && thismove.totalpp>0 && !sleeptalk
- if showMessages
- pbDisplayPaused(_INTL("There's no PP left for this move!"))
- end
- return false
- end
- if thispkmn.effects[PBEffects::ChoiceBand]>=0 &&
- (thispkmn.hasWorkingItem(:CHOICEBAND) ||
- thispkmn.hasWorkingItem(:CHOICESPECS) ||
- thispkmn.hasWorkingItem(:CHOICESCARF))
- hasmove=false
- for i in 0...4
- if thispkmn.moves[i].id==thispkmn.effects[PBEffects::ChoiceBand]
- hasmove=true
- break
- end
- end
- if hasmove && thismove.id!=thispkmn.effects[PBEffects::ChoiceBand]
- if showMessages
- pbDisplayPaused(_INTL("{1} allows the use of only {2}!",
- PBItems.getName(thispkmn.item),
- PBMoves.getName(thispkmn.effects[PBEffects::ChoiceBand])))
- end
- return false
- end
- end
- #### KUROTSUNE - 018 - START
- if isConst?(thispkmn.item,PBItems,:ASSAULTVEST) && !(thismove.pbIsPhysical?(thismove.type) || thismove.pbIsSpecial?(thismove.type))
- if showMessages
- pbDisplayPaused(_INTL("{1} doesn't allow use of non-attacking moves!",
- PBItems.getName(thispkmn.item)))
- end
- return false
- end
- #### KUROTSUNE - 018 - END
- if opp1.effects[PBEffects::Imprison]
- if thismove.id==opp1.moves[0].id ||
- thismove.id==opp1.moves[1].id ||
- thismove.id==opp1.moves[2].id ||
- thismove.id==opp1.moves[3].id
- if showMessages
- pbDisplayPaused(_INTL("{1} can't use the sealed {2}!",thispkmn.pbThis,thismove.name))
- end
- #PBDebug.log("[CanChoose][#{opp1.pbThis} has: #{opp1.moves[0].name}, #{opp1.moves[1].name},#{opp1.moves[2].name},#{opp1.moves[3].name}]") if $INTERNAL
- return false
- end
- end
- if opp2.effects[PBEffects::Imprison]
- if thismove.id==opp2.moves[0].id ||
- thismove.id==opp2.moves[1].id ||
- thismove.id==opp2.moves[2].id ||
- thismove.id==opp2.moves[3].id
- if showMessages
- pbDisplayPaused(_INTL("{1} can't use the sealed {2}!",thispkmn.pbThis,thismove.name))
- end
- #PBDebug.log("[CanChoose][#{opp2.pbThis} has: #{opp2.moves[0].name}, #{opp2.moves[1].name},#{opp2.moves[2].name},#{opp2.moves[3].name}]") if $INTERNAL
- return false
- end
- end
- if thispkmn.effects[PBEffects::Taunt]>0 && thismove.basedamage==0
- if showMessages
- pbDisplayPaused(_INTL("{1} can't use {2} after the Taunt!",thispkmn.pbThis,thismove.name))
- end
- return false
- end
- if thispkmn.effects[PBEffects::Torment]
- if thismove.id==thispkmn.lastMoveUsed
- if showMessages
- pbDisplayPaused(_INTL("{1} can't use the same move in a row due to the torment!",thispkmn.pbThis))
- end
- return false
- end
- end
- if thismove.id==thispkmn.effects[PBEffects::DisableMove] && !sleeptalk
- if showMessages
- pbDisplayPaused(_INTL("{1}'s {2} is disabled!",thispkmn.pbThis,thismove.name))
- end
- return false
- end
- if thispkmn.effects[PBEffects::Encore]>0 && idxMove!=thispkmn.effects[PBEffects::EncoreIndex]
- return false
- end
- return true
- end
- def pbAutoChooseMove(idxPokemon,showMessages=true)
- thispkmn=@battlers[idxPokemon]
- if thispkmn.isFainted?
- @choices[idxPokemon][0]=0
- @choices[idxPokemon][1]=0
- @choices[idxPokemon][2]=nil
- return
- end
- if thispkmn.effects[PBEffects::Encore]>0 &&
- pbCanChooseMove?(idxPokemon,thispkmn.effects[PBEffects::EncoreIndex],false)
- PBDebug.log("[Auto choosing Encore move...]") if $INTERNAL
- @choices[idxPokemon][0]=1 # "Use move"
- @choices[idxPokemon][1]=thispkmn.effects[PBEffects::EncoreIndex] # Index of move
- @choices[idxPokemon][2]=thispkmn.moves[thispkmn.effects[PBEffects::EncoreIndex]]
- @choices[idxPokemon][3]=-1 # No target chosen yet
- if @doublebattle
- thismove=thispkmn.moves[thispkmn.effects[PBEffects::EncoreIndex]]
- target=thispkmn.pbTarget(thismove)
- if target==PBTargets::SingleNonUser #&& ($fefieldeffect != 33 ||
- #$fecounter != 4 || (thismove.id != 192 || thismove.id != 214 ||
- # thismove.id != 218 || thismove.id != 219 || thismove.id != 220 ||
- # thismove.id != 445 || thismove.id != 596 || thismove.id != 600))
- # print("this message is bad")
- target=@scene.pbChooseTarget(idxPokemon)
- pbRegisterTarget(idxPokemon,target) if target>=0
- elsif target==PBTargets::UserOrPartner
- target=@scene.pbChooseTarget(idxPokemon)
- pbRegisterTarget(idxPokemon,target) if target>=0 && (target&1)==(idxPokemon&1)
- end
- end
- else
- if !pbIsOpposing?(idxPokemon)
- pbDisplayPaused(_INTL("{1} has no moves left!",thispkmn.name)) if showMessages
- end
- @choices[idxPokemon][0]=1 # "Use move"
- @choices[idxPokemon][1]=-1 # Index of move to be used
- @choices[idxPokemon][2]=@struggle # Use Struggle
- @choices[idxPokemon][3]=-1 # No target chosen yet
- end
- end
- def pbRegisterMove(idxPokemon,idxMove,showMessages=true)
- thispkmn=@battlers[idxPokemon]
- thismove=thispkmn.moves[idxMove]
- #### KUROTSUNE - 010 - START
- thispkmn.selectedMove = thismove.id
- #### KUROTSUNE - 010 - END
- return false if !pbCanChooseMove?(idxPokemon,idxMove,showMessages)
- @choices[idxPokemon][0]=1 # "Use move"
- @choices[idxPokemon][1]=idxMove # Index of move to be used
- @choices[idxPokemon][2]=thismove # PokeBattle_Move object of the move
- @choices[idxPokemon][3]=-1 # No target chosen yet
- return true
- end
- def pbChoseMove?(i,move)
- return false if @battlers[i].isFainted?
- if @choices[i][0]==1 && @choices[i][1]>=0
- choice=@choices[i][1]
- return isConst?(@battlers[i].moves[choice].id,PBMoves,move)
- end
- return false
- end
- def pbChoseMoveFunctionCode?(i,code)
- return false if @battlers[i].isFainted?
- if @choices[i][0]==1 && @choices[i][1]>=0
- choice=@choices[i][1]
- return @battlers[i].moves[choice].function==code
- end
- return false
- end
- def pbRegisterTarget(idxPokemon,idxTarget)
- @choices[idxPokemon][3]=idxTarget # Set target of move
- return true
- end
- # UPDATE 11/23/2013
- # implementing STALL
- def pbPriority(ignorequickclaw = false)
- if @usepriority
- # use stored priority if round isn't over yet
- return @priority
- end
- speeds=[]
- quickclaw=[]
- custapberry=[]
- stall=[] # <--- Add this here
- lagtail=[] # <--- This too
- incense=[] # <--- ... and this
- priorities=[]
- temp=[]
- @priority.clear
- maxpri=0
- minpri=0
- # Calculate each Pokémon's speed
- ### Simplified below
- #speeds[0]=@battlers[0].pbSpeed
- #speeds[1]=@battlers[1].pbSpeed
- #speeds[2]=@battlers[2].pbSpeed
- #speeds[3]=@battlers[3].pbSpeed
- #quickclaw[0]=isConst?(@battlers[0].item,PBItems,:QUICKCLAW)
- #quickclaw[1]=isConst?(@battlers[1].item,PBItems,:QUICKCLAW)
- #quickclaw[2]=isConst?(@battlers[2].item,PBItems,:QUICKCLAW)
- #quickclaw[3]=isConst?(@battlers[3].item,PBItems,:QUICKCLAW)
- ###
- # Find the maximum and minimum priority
- for i in 0..3
- ### add these here
- speeds[i] = @battlers[i].pbSpeed
- quickclaw[i] = isConst?(@battlers[i].item, PBItems, :QUICKCLAW)
- custapberry[i] = @battlers[i].custap
- # && !ignorequickclaw && @choices[i][0] == 1
- stall[i] = isConst?(@battlers[i].ability, PBAbilities, :STALL)
- lagtail[i] = isConst?(@battlers[i].item, PBItems, :LAGGINGTAIL)
- incense[i] = isConst?(@battlers[i].item, PBItems, :FULLINCENSE)
- ###
- # For this function, switching and using items
- # is the same as using a move with a priority of 0
- pri=0
- if @choices[i][0]==1 # Is a move
- pri=@choices[i][2].priority
- pri+=1 if isConst?(@battlers[i].ability,PBAbilities,:PRANKSTER) &&
- @choices[i][2].basedamage==0 # Is status move
- pri+=1 if isConst?(@battlers[i].ability,PBAbilities,:GALEWINGS) && @choices[i][2].type==2
- # pri-=1 if $fefieldeffect == 6 &&
- # @battlers[i].effects[PBEffects::TwoTurnAttack] !=0 &&
- # (@choices[i][2].id==156 || @choices[i][2].id==157)
- end
- priorities[i]=pri
- if i==0
- maxpri=pri
- minpri=pri
- else
- maxpri=pri if maxpri<pri
- minpri=pri if minpri>pri
- end
- end
- # Find and order all moves with the same priority
- curpri=maxpri
- loop do
- temp.clear
- for j in 0...4
- if priorities[j]==curpri
- temp[temp.length]=j
- end
- end
- # Sort by speed
- if temp.length==1
- @priority[@priority.length]=@battlers[temp[0]]
- else
- n=temp.length
- usequickclaw=(pbRandom(100)<20)
- for m in 0..n-2
- for i in 1..n-1
- if quickclaw[temp[i]] && usequickclaw
- cmp=(quickclaw[temp[i-1]]) ? 0 : -1 #Rank higher if without Quick Claw, or equal if with it
- elsif quickclaw[temp[i-1]] && usequickclaw
- cmp=1 # Rank lower
- elsif custapberry[temp[i]]
- cmp=(custapberry[temp[i-1]]) ? 0 : -1 #Rank higher if without Custap Berry, or equal if with it
- elsif custapberry[temp[i-1]]
- cmp=1 # Rank lower
- # UPDATE 11/23/2013
- # stall ability
- # add the following two elsif blocks
- ####
- # ignored if we have full incense or lagging tail
- elsif stall[temp[i]] && !(incense[temp[i]] || lagtail[temp[i]])
- # if they also have stall
- if stall[temp[i-1]] && !(incense[temp[i-1]] || lagtail[temp[i-1]])
- # higher speed -> lower priority
- cmp=speeds[temp[i]] > speeds[temp[i-1]] ? 1 : -1
- else
- cmp=1
- end
- elsif lagtail[temp[i-1]] || incense[temp[i-1]]
- cmp=-1
- elsif lagtail[temp[i]] || incense[temp[i]]
- cmp=1
- elsif stall[temp[i-1]] && !(incense[temp[i-1]] || lagtail[temp[i-1]])
- cmp= lagtail[temp[i]] || incense[temp[i]] ? 1 : -1
- # end of update
- elsif speeds[temp[i]]!=speeds[temp[i-1]]
- cmp=(speeds[temp[i]]>speeds[temp[i-1]]) ? -1 : 1 #Rank higher to higher-speed battler
- else
- cmp=0
- end
- # UPDATE implementing Trick Room
- if cmp<0 && @trickroom==0
- # put higher-speed Pokémon first
- swaptmp=temp[i]
- temp[i]=temp[i-1]
- temp[i-1]=swaptmp
- elsif cmp>0 && @trickroom>0
- swaptmp=temp[i]
- temp[i]=temp[i-1]
- temp[i-1]=swaptmp
- elsif cmp==0
- # END OF UPDATE
- # swap at random if speeds are equal
- if pbRandom(2)==0
- swaptmp=temp[i]
- temp[i]=temp[i-1]
- temp[i-1]=swaptmp
- end
- end
- end
- end
- #Now add the temp array to priority
- for i in temp
- @priority[@priority.length]=@battlers[i]
- end
- end
- curpri-=1
- break unless curpri>=minpri
- end
- =begin
- prioind=[
- @priority[0].index,
- @priority[1].index,
- @priority[2] ? @priority[2].index : -1,
- @priority[3] ? @priority[3].index : -1
- ]
- print("#{speeds.inspect} #{prioind.inspect}")
- =end
- @usepriority=true
- return @priority
- end
- ##### KUROTSUNE - 011 - START
- # Makes target pokemon move last
- def pbMoveLast(target)
- priorityTarget = pbGetPriority(target)
- priority = @priority
- case priorityTarget
- when 0
- # Opponent has likely already moved
- return false
- when 1
- aux = priority[3]
- priority[3] = target
- priority[1] = aux
- aux = priority[2]
- priority[2] = priority[1]
- priority[1] = aux
- @priority = priority
- return true
- when 2
- aux = priority[2]
- priority[2] = priority[3]
- priority[3] = aux
- @priority = priority
- return true
- when 3
- return false
- end
- end
- # Makes the second pokemon move after the first.
- def pbMoveAfter(first, second)
- priorityFirst = pbGetPriority(first)
- priority = @priority
- case priorityFirst
- when 0
- if second == priority[1]
- # Nothing to do here
- return false
- elsif second == priority[2]
- aux = priority[1]
- priority[1] = second
- priority[2] = aux
- @priority = priority
- return true
- elsif second == priority[3]
- aux = priority[1]
- priority[1] = second
- priority[3] = aux
- aux = priority[2]
- priority[2] = priority[3]
- priority[3] = aux
- @priority = priority
- return true
- end
- when 1
- if second == priority[0] || second == priority[2]
- # Nothing to do here
- return false
- elsif second == priority[3]
- aux = priority[2]
- priority[2] = priority[3]
- priority[3] = aux
- @priority = priority
- return true
- end
- when 2
- return false
- when 3
- return false
- end
- end
- ##### KUROTSUNE - 011 - END
- def pbGetPriority(mon)
- for i in 0..3
- if @priority[i] == mon
- return i
- end
- end
- return -1
- end
- def pbClearChoices(index)
- choices[index][0] = -1
- choices[index][1] = -1
- choices[index][2] = -1
- choices[index][3] = -1
- end
- ################################################################################
- # Switching Pokémon.
- ################################################################################
- def pbCanSwitchLax?(idxPokemon,pkmnidxTo,showMessages)
- if pkmnidxTo>=0
- party=pbParty(idxPokemon)
- if pkmnidxTo>=party.length
- return false
- end
- if !party[pkmnidxTo]
- return false
- end
- if party[pkmnidxTo].isEgg?
- pbDisplayPaused(_INTL("An Egg can't battle!")) if showMessages
- return false
- end
- if !pbIsOwner?(idxPokemon,pkmnidxTo)
- owner=pbPartyGetOwner(idxPokemon,pkmnidxTo)
- pbDisplayPaused(_INTL("You can't switch {1}'s Pokémon with one of yours!",owner.name)) if showMessages
- return false
- end
- if party[pkmnidxTo].hp<=0
- pbDisplayPaused(_INTL("{1} has no energy left to battle!",party[pkmnidxTo].name)) if showMessages
- return false
- end
- if @battlers[idxPokemon].pokemonIndex==pkmnidxTo
- pbDisplayPaused(_INTL("{1} is already in battle!",party[pkmnidxTo].name)) if showMessages
- return false
- end
- if @battlers[idxPokemon].pbPartner.pokemonIndex==pkmnidxTo
- pbDisplayPaused(_INTL("{1} is already in battle!",party[pkmnidxTo].name)) if showMessages
- return false
- end
- end
- return true
- end
- def pbCanSwitch?(idxPokemon,pkmnidxTo,showMessages)
- thispkmn=@battlers[idxPokemon]
- # Multi-Turn Attacks/Mean Look
- if !pbCanSwitchLax?(idxPokemon,pkmnidxTo,showMessages)
- return false
- end
- # UPDATE 11/16/2013
- # Ghost type can now escape from anything
- if thispkmn.pbHasType?(:GHOST)
- return true
- end
- isOpposing=pbIsOpposing?(idxPokemon)
- party=pbParty(idxPokemon)
- for i in 0...4
- next if isOpposing!=pbIsOpposing?(i)
- if choices[i][0]==2 && choices[i][1]==pkmnidxTo
- pbDisplayPaused(_INTL("{1} has already been selected.",party[pkmnidxTo].name)) if showMessages
- return false
- end
- end
- if thispkmn.hasWorkingItem(:SHEDSHELL)
- return true
- end
- if thispkmn.effects[PBEffects::MultiTurn]>0 ||
- thispkmn.effects[PBEffects::MeanLook]>=0 ||
- field.effects[PBEffects::FairyLock]==1
- pbDisplayPaused(_INTL("{1} can't be switched out!",thispkmn.pbThis)) if showMessages
- return false
- end
- # Ingrain
- if thispkmn.effects[PBEffects::Ingrain]
- pbDisplayPaused(_INTL("{1} can't be switched out!",thispkmn.pbThis)) if showMessages
- return false
- end
- opp1=thispkmn.pbOpposing1
- opp2=thispkmn.pbOpposing2
- opp=nil
- if thispkmn.pbHasType?(:STEEL)
- opp=opp1 if opp1.hasWorkingAbility(:MAGNETPULL)
- opp=opp2 if opp2.hasWorkingAbility(:MAGNETPULL)
- end
- if !thispkmn.isAirborne?
- opp=opp1 if opp1.hasWorkingAbility(:ARENATRAP)
- opp=opp2 if opp2.hasWorkingAbility(:ARENATRAP)
- end
- if !thispkmn.hasWorkingAbility(:SHADOWTAG)
- opp=opp1 if opp1.hasWorkingAbility(:SHADOWTAG)
- opp=opp2 if opp2.hasWorkingAbility(:SHADOWTAG)
- end
- if opp
- abilityname=PBAbilities.getName(opp.ability)
- pbDisplayPaused(_INTL("{1}'s {2} prevents switching!",opp.pbThis,abilityname)) if showMessages
- # UPDATE 11/16
- # now displays the proper fleeing message iff you are attempting to flee
- # Note: not very elegant, but it should work.
- pbDisplayPaused(_INTL("{1} prevents escaping with {2}!", opp.pbThis, abilityname)) if !showMessages && pkmnidxTo == -1
- return false
- end
- return true
- end
- def pbRegisterSwitch(idxPokemon,idxOther)
- return false if !pbCanSwitch?(idxPokemon,idxOther,false)
- @choices[idxPokemon][0]=2 # "Switch Pokémon"
- @choices[idxPokemon][1]=idxOther # Index of other Pokémon to switch with
- @choices[idxPokemon][2]=nil
- side=(pbIsOpposing?(idxPokemon)) ? 1 : 0
- owner=pbGetOwnerIndex(idxPokemon)
- if @megaEvolution[side][owner]==idxPokemon
- @megaEvolution[side][owner]=-1
- end
- return true
- end
- def pbCanChooseNonActive?(index)
- party=pbParty(index)
- for i in 0..party.length-1
- return true if pbCanSwitchLax?(index,i,false)
- end
- return false
- end
- def pbJudgeSwitch(favorDraws=false)
- if !favorDraws
- return if @decision>0
- pbJudge()
- return if @decision>0
- else
- return if @decision==5
- pbJudge()
- return if @decision>0
- end
- end
- def pbSwitch(favorDraws=false)
- if !favorDraws
- return if @decision>0
- pbJudge()
- return if @decision>0
- else
- return if @decision==5
- pbJudge()
- return if @decision>0
- end
- firstbattlerhp=@battlers[0].hp
- switched=[]
- for index in 0...4
- next if !@doublebattle && pbIsDoubleBattler?(index)
- next if @battlers[index] && !@battlers[index].isFainted?
- next if !pbCanChooseNonActive?(index)
- if !pbOwnedByPlayer?(index)
- if !pbIsOpposing?(index) || (@opponent && pbIsOpposing?(index))
- newenemy=pbSwitchInBetween(index,false,false)
- #### JERICHO - 001 - START
- if !pbIsOpposing?(index)
- if isConst?(@party1[newenemy].ability,PBAbilities,:ILLUSION) #ILLUSION
- party3=@party1.find_all {|item| item && !item.egg? && item.hp>0 }
- if party3[@party1.length-1] != @party1[newenemy]
- illusionpoke = party3[party3.length-1]
- end
- end #ILLUSION
- newname = illusionpoke != nil ? illusionpoke.name : @party1[newenemy].name #ILLUSION
- else
- if isConst?(@party2[newenemy].ability,PBAbilities,:ILLUSION) #ILLUSION
- party3=@party1.find_all {|item| item && !item.egg? && item.hp>0 }
- if party3[@party1.length-1] != @party1[newenemy]
- illusionpoke = party3[party3.length-1]
- end
- end #ILLUSION
- newname = illusionpoke != nil ? illusionpoke.name : PBSpecies.getName(@party2[newenemy].species) #ILLUSION
- end
- #### JERICHO - 001 - END
- opponent=pbGetOwner(index)
- if !@doublebattle && firstbattlerhp>0 && @shiftStyle && @opponent &&
- @internalbattle && pbCanChooseNonActive?(0) && pbIsOpposing?(index) &&
- @battlers[0].effects[PBEffects::Outrage]==0
- #### JERICHO - 001 - START
- pbDisplayPaused(_INTL("{1} is about to send in {2}.",opponent.fullname,newname)) #ILLUSION
- #### JERICHO - 001 - END
- if pbDisplayConfirm(_INTL("Will {1} change Pokémon?",self.pbPlayer.name))
- newpoke=pbSwitchPlayer(0,true,true)
- if newpoke>=0
- pbDisplayBrief(_INTL("{1}, that's enough! Come back!",@battlers[0].name))
- pbRecallAndReplace(0,newpoke)
- switched.push(0)
- end
- end
- end
- pbRecallAndReplace(index,newenemy)
- switched.push(index)
- end
- elsif @opponent
- newpoke=pbSwitchInBetween(index,true,false)
- pbRecallAndReplace(index,newpoke)
- switched.push(index)
- else
- switch=false
- if !pbDisplayConfirm(_INTL("Use next Pokémon?"))
- switch=(pbRun(index,true)<=0)
- else
- switch=true
- end
- if switch
- newpoke=pbSwitchInBetween(index,true,false)
- pbRecallAndReplace(index,newpoke)
- switched.push(index)
- end
- end
- end
- if switched.length>0
- priority=pbPriority
- for i in priority
- i.pbAbilitiesOnSwitchIn(true) if switched.include?(i.index)
- end
- end
- end
- def pbSendOut(index,pokemon)
- pbSetSeen(pokemon)
- @peer.pbOnEnteringBattle(self,pokemon)
- if pbIsOpposing?(index)
- # in-battle text
- @scene.pbTrainerSendOut(index,pokemon)
- # Last Pokemon script; credits to venom12 and HelioAU
- if !@opponent.is_a?(Array)
- trainertext = @opponent
- if pbPokemonCount(@party2)==1
- # Define any trainers that you want to activate this script below
- # For each defined trainer, add the BELOW section for them
- if isConst?(trainertext.trainertype,PBTrainers,:Hotshot)
- if $game_variables[192] == 0
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("You think you can get away with that?"))
- @scene.pbHideOpponent
- elsif $game_variables[192] == 1
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("You don't actually think you're special, do you?"))
- @scene.pbHideOpponent
- elsif $game_variables[192] == 2
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("You're really starting to grate on my nerves, and you don't wanna do that."))
- @scene.pbHideOpponent
- elsif $game_variables[192] == 4
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("Pfft, picking on you is way too easy."))
- @scene.pbHideOpponent
- elsif $game_variables[192] == 5
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("You're a real thorn in my side, you know?"))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:Leader)
- if $game_variables[192] == 0
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("Don'tgoboom,don'tgoboom,don'tgoboom..."))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:Victoria)
- if $game_variables[192] == 1
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("If you can't handle this, there's no way you can get through there safely!"))
- @scene.pbHideOpponent
- elsif $game_variables[192] == 3
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("Is there really nothing I can do?"))
- @scene.pbHideOpponent
- elsif $game_variables[192] == 4
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("Please, for Kiki's sake..."))
- @scene.pbHideOpponent
- elsif $game_variables[192] == 7
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("To minimize the chaos within... Sensei, I'm so sorry."))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:Cain)
- if $game_variables[192] == 1
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("Aha, well this is a rough first battle for the little guy. But the first time is always rough, huh?"))
- @scene.pbHideOpponent
- elsif $game_variables[192] == 2
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("I am sooo getting bent-over here."))
- @scene.pbHideOpponent
- elsif $game_variables[192] == 3
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("Welllll, I thought I could get away with not opening it from a rematch, but-- oops."))
- @scene.pbHideOpponent
- elsif $game_variables[192] == 5
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("You always seem to overwhelm me...~"))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:Leader_096)
- if $game_variables[192] == 0
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("Conclusion forthcoming..."))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:Taka)
- if $game_variables[192] == 0
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("It's a shame it has to come to this, but..."))
- @scene.pbHideOpponent
- elsif $game_variables[192] == 1
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("I guess that means it's time for this, right?"))
- @scene.pbHideOpponent
- elsif $game_variables[192] == 2
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("Defeat was never such a relief."))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:Corey)
- if $game_variables[192] == 0
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("Disappointment is a two-way street."))
- @scene.pbHideOpponent
- elsif $game_variables[192] == 1
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("All things must end. Even you. Even I."))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:Leader_101)
- if $game_variables[192] == 0
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("Hehe... Failing again..."))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:Leader_103)
- if $game_variables[192] == 0
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("..."))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:ZEL)
- if $game_variables[192] == 2
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("Zel: Tch, no choice then!"))
- @scene.pbHideOpponent
- end
- if $game_variables[192] == 4
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("zeL: I'm sorry, Magnezone... If we're gonna get through this, we need your help!"))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:Sensei)
- if $game_variables[192] == 0
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("To minimize the chaos within... Perhaps it's too late."))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:WPunk)
- if $game_variables[192] == 0
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("Just finish it already, why don't you."))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:Sirius)
- if $game_variables[192] == 0 || $game_variables[192] == 1
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("Perhaps we've left this threat unchecked for too long."))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:DOCTOR)
- if $game_variables[192] == 0 || $game_variables[192] == 1
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("Your silence does not eclipse your arrogance."))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:BENNETT)
- if $game_variables[192] == 0
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("I see, I see... You are at a highly advanced stage of metamorphosis already!"))
- @scene.pbHideOpponent
- elsif $game_variables[192] == 1
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("Tch, she would never... No! I won't give up! I'll make her see!"))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:SERRA)
- if $game_variables[192] == 0
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("Ice, like a mirror, will never be perfect again once it cracks."))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:Radomus)
- if $game_variables[192] == 0
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("Well, well, I am impressed."))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:Noel)
- if $game_variables[192] == 0
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("It's too bad. They can't always get what they want."))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:LUNA)
- if $game_variables[192] == 0
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("Oh? Perhaps I've lost my way after all. How wonderful!"))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:SAMSON)
- if $game_variables[192] == 0
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("No sweat. I've been in worse positions."))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:EclipseDame)
- if $game_variables[192] == 0
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("ECLIPSE: Seriously, can we stop this already?"))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:CHARLOTTE)
- if $game_variables[192] == 0
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("Ever seen a wildfire start from just a spark? ...D'you wanna?"))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:AsterAce)
- if $game_variables[192] == 0
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("Eclipse-- I'm sorry."))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:TERRA)
- if $game_variables[192] == 0
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("FUCK!!! THE WHAT!!!!!!!"))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:CIEL)
- if $game_variables[192] == 0
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("Hold your applause! You've yet to see the final act!"))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:ARCLIGHT)
- if $game_variables[192] == 0
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("You've got a good showing. But don't think I'm going off the air just yet!"))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:ADRIENN)
- if $game_variables[192] == 0
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("I haven't had a battle this exhilarating in ages-- even by my twisted timeline!"))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:Exleader)
- if $game_variables[192] == 0
- @scene.pbShowOpponent(0)
- pbDisplayPaused(_INTL("This feels empty."))
- @scene.pbHideOpponent
- end
- elsif isConst?(trainertext.trainertype,PBTrainers,:Techlord)
- if $game_variables[192] == 2
- @scene.pbShowOpponent(0)
- pbBGMPlay("Rayquayza_Theme",100,150)
- pbDisplayPaused(_INTL("That was merely a warm-up. The real fight begins now."))
- @scene.pbHideOpponent
- end
- end
- end
- # For each defined trainer, add the ABOVE section for them
- end
- else
- @scene.pbSendOut(index,pokemon)
- end
- @scene.pbResetMoveIndex(index)
- end
- def pbReplace(index,newpoke,batonpass=false)
- party=pbParty(index)
- if pbOwnedByPlayer?(index)
- # Reorder the party for this battle
- bpo=-1; bpn=-1
- for i in 0...6
- bpo=i if @partyorder[i]==@battlers[index].pokemonIndex
- bpn=i if @partyorder[i]==newpoke
- end
- poke1=@partyorder[bpo]
- @partyorder[bpo]=@partyorder[bpn]
- @partyorder[bpn]=poke1
- @battlers[index].pbInitialize(party[newpoke],newpoke,batonpass)
- pbSendOut(index,party[newpoke])
- else
- @battlers[index].pbInitialize(party[newpoke],newpoke,batonpass)
- pbSetSeen(party[newpoke])
- if pbIsOpposing?(index)
- pbSendOut(index,party[newpoke])
- else
- pbSendOut(index,party[newpoke])
- end
- end
- end
- def pbRecallAndReplace(index,newpoke,batonpass=false)
- if @battlers[index].effects[PBEffects::Illusion]
- @battlers[index].effects[PBEffects::Illusion] = nil
- end
- @switchedOut[index] = true
- pbClearChoices(index)
- @battlers[index].pbResetForm
- if !@battlers[index].isFainted?
- @scene.pbRecall(index)
- end
- pbMessagesOnReplace(index,newpoke)
- pbReplace(index,newpoke,batonpass)
- @scene.partyBetweenKO2(!pbOwnedByPlayer?(index)) unless @doublebattle
- return pbOnActiveOne(@battlers[index])
- end
- def pbMessagesOnReplace(index,newpoke)
- party=pbParty(index)
- if pbOwnedByPlayer?(index)
- # if !party[newpoke]
- # p [index,newpoke,party[newpoke],pbAllFainted?(party)]
- # PBDebug.log([index,newpoke,party[newpoke],"pbMOR"].inspect)
- # for i in 0...party.length
- # PBDebug.log([i,party[i].hp].inspect)
- # end
- # raise BattleAbortedException.new
- # end
- #### JERICHO - 001 - start
- if isConst?(party[newpoke].ability,PBAbilities,:ILLUSION) #ILLUSION
- party2=party.find_all {|item| item && !item.egg? && item.hp>0 }
- if party2[party.length-1] != party[newpoke]
- illusionpoke = party[party.length-1]
- end
- end #ILLUSION
- newname = illusionpoke != nil ? illusionpoke.name : party[newpoke].name
- opposing=@battlers[index].pbOppositeOpposing
- if opposing.hp<=0 || opposing.hp==opposing.totalhp
- pbDisplayBrief(_INTL("Go! {1}!",newname))
- elsif opposing.hp>=(opposing.totalhp/2)
- pbDisplayBrief(_INTL("Do it! {1}!",newname))
- elsif opposing.hp>=(opposing.totalhp/4)
- pbDisplayBrief(_INTL("Go for it, {1}!",newname))
- else
- pbDisplayBrief(_INTL("Your foe's weak!\nGet 'em, {1}!",newname))
- end
- #### JERICHO - 001 - END
- else
- # if !party[newpoke]
- # p [index,newpoke,party[newpoke],pbAllFainted?(party)]
- # PBDebug.log([index,newpoke,party[newpoke],"pbMOR"].inspect)
- # for i in 0...party.length
- # PBDebug.log([i,party[i].hp].inspect)
- # end
- # raise BattleAbortedException.new
- # end
- #### JERICHO - 001 - START
- if isConst?(party[newpoke].ability,PBAbilities,:ILLUSION) #ILLUSION
- party2=party.find_all {|item| item && !item.egg? && item.hp>0 }
- if party2[party.length-1] != party[newpoke]
- illusionpoke = party[party.length-1]
- end
- end #ILLUSION
- if pbIsOpposing?(index)
- newname = illusionpoke != nil ? illusionpoke.name : PBSpecies.getName(party[newpoke].species) #ILLUSION
- else
- newname = illusionpoke != nil ? illusionpoke.name : party[newpoke].name #ILLUSION
- end
- owner=pbGetOwner(index)
- pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",owner.fullname,newname)) #ILLUSION
- #### JERICHO - 001 - END
- end
- end
- def pbSwitchInBetween(index,lax,cancancel)
- if !pbOwnedByPlayer?(index)
- return @scene.pbChooseNewEnemy(index,pbParty(index))
- else
- return pbSwitchPlayer(index,lax,cancancel)
- end
- end
- def pbSwitchPlayer(index,lax,cancancel)
- if @debug
- return @scene.pbChooseNewEnemy(index,pbParty(index))
- else
- return @scene.pbSwitch(index,lax,cancancel)
- end
- end
- ################################################################################
- # Using an item.
- ################################################################################
- # Uses an item on a Pokémon in the player's party.
- def pbUseItemOnPokemon(item,pkmnIndex,userPkmn,scene)
- pokemon=@party1[pkmnIndex]
- battler=nil
- name=pbGetOwner(userPkmn.index).fullname
- name=pbGetOwner(userPkmn.index).name if pbBelongsToPlayer?(userPkmn.index)
- pbDisplayBrief(_INTL("{1} used the\r\n{2}.",name,PBItems.getName(item)))
- PBDebug.log("[Player used #{PBItems.getName(item)}]")
- ret=false
- if pokemon.isEgg?
- pbDisplay(_INTL("But it had no effect!"))
- else
- for i in 0...4
- if !pbIsOpposing?(i) && @battlers[i].pokemonIndex==pkmnIndex
- battler=@battlers[i]
- end
- end
- ret=ItemHandlers.triggerBattleUseOnPokemon(item,pokemon,battler,scene)
- end
- if !ret && pbBelongsToPlayer?(userPkmn.index)
- if $PokemonBag.pbCanStore?(item)
- $PokemonBag.pbStoreItem(item)
- else
- raise _INTL("Couldn't return unused item to Bag somehow.")
- end
- end
- return ret
- end
- # Uses an item on an active Pokémon.
- def pbUseItemOnBattler(item,index,userPkmn,scene)
- PBDebug.log("[Player used #{PBItems.getName(item)}]")
- ret=ItemHandlers.triggerBattleUseOnBattler(item,@battlers[index],scene)
- if !ret && pbBelongsToPlayer?(userPkmn.index)
- if $PokemonBag.pbCanStore?(item)
- $PokemonBag.pbStoreItem(item)
- else
- raise _INTL("Couldn't return unused item to Bag somehow.")
- end
- end
- return ret
- end
- def pbRegisterItem(idxPokemon,idxItem,idxTarget=nil)
- if ItemHandlers.hasUseInBattle(idxItem)
- if idxPokemon==0
- if ItemHandlers.triggerBattleUseOnBattler(idxItem,@battlers[idxPokemon],self)
- ItemHandlers.triggerUseInBattle(idxItem,@battlers[idxPokemon],self)
- if @doublebattle
- @choices[idxPokemon+2][0]=3 # "Use an item"
- @choices[idxPokemon+2][1]=idxItem # ID of item to be used
- @choices[idxPokemon+2][2]=idxTarget # Index of Pokémon to use item on
- end
- else
- return false
- end
- else
- if ItemHandlers.triggerBattleUseOnBattler(idxItem,@battlers[idxPokemon],self)
- pbDisplay(_INTL("It's impossible to aim without being focused!"))
- end
- return false
- end
- end
- @choices[idxPokemon][0]=3 # "Use an item"
- @choices[idxPokemon][1]=idxItem # ID of item to be used
- @choices[idxPokemon][2]=idxTarget # Index of Pokémon to use item on
- side=(pbIsOpposing?(idxPokemon)) ? 1 : 0
- owner=pbGetOwnerIndex(idxPokemon)
- if @megaEvolution[side][owner]==idxPokemon
- @megaEvolution[side][owner]=-1
- end
- return true
- end
- def pbEnemyUseItem(item,battler)
- return 0 if !@internalbattle
- items=pbGetOwnerItems(battler.index)
- return if !items
- opponent=pbGetOwner(battler.index)
- for i in 0...items.length
- if items[i]==item
- items.delete_at(i)
- break
- end
- end
- itemname=PBItems.getName(item)
- pbDisplayBrief(_INTL("{1} used the\r\n{2}!",opponent.fullname,itemname))
- if isConst?(item,PBItems,:POTION)
- battler.pbRecoverHP(20,true)
- pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
- elsif isConst?(item,PBItems,:SUPERPOTION)
- battler.pbRecoverHP(50,true)
- pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
- elsif isConst?(item,PBItems,:HYPERPOTION)
- battler.pbRecoverHP(200,true)
- pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
- elsif isConst?(item,PBItems,:ULTRAPOTION)
- battler.pbRecoverHP(120,true)
- pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
- elsif isConst?(item,PBItems,:MOOMOOMILK)
- battler.pbRecoverHP(110,true)
- pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
- elsif isConst?(item,PBItems,:STRAWBIC)
- battler.pbRecoverHP(90,true)
- pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
- elsif isConst?(item,PBItems,:CHOCOLATEIC)
- battler.pbRecoverHP(70,true)
- pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
- elsif isConst?(item,PBItems,:MAXPOTION)
- battler.pbRecoverHP(battler.totalhp-battler.hp,true)
- pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
- elsif isConst?(item,PBItems,:FULLRESTORE)
- fullhp=(battler.hp==battler.totalhp)
- battler.pbRecoverHP(battler.totalhp-battler.hp,true)
- battler.status=0; battler.statusCount=0
- battler.effects[PBEffects::Confusion]=0
- if fullhp
- pbDisplay(_INTL("{1} became healthy!",battler.pbThis))
- else
- pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
- end
- elsif isConst?(item,PBItems,:FULLHEAL)
- battler.status=0; battler.statusCount=0
- battler.effects[PBEffects::Confusion]=0
- pbDisplay(_INTL("{1} became healthy!",battler.pbThis))
- elsif isConst?(item,PBItems,:XATTACK)
- if battler.pbCanIncreaseStatStage?(PBStats::ATTACK)
- battler.pbIncreaseStat(PBStats::ATTACK,1,true)
- end
- elsif isConst?(item,PBItems,:XDEFEND)
- if battler.pbCanIncreaseStatStage?(PBStats::DEFENSE)
- battler.pbIncreaseStat(PBStats::DEFENSE,1,true)
- end
- elsif isConst?(item,PBItems,:XSPEED)
- if battler.pbCanIncreaseStatStage?(PBStats::SPEED)
- battler.pbIncreaseStat(PBStats::SPEED,1,true)
- end
- elsif isConst?(item,PBItems,:XSPECIAL)
- if battler.pbCanIncreaseStatStage?(PBStats::SPATK)
- battler.pbIncreaseStat(PBStats::SPATK,1,true)
- end
- elsif isConst?(item,PBItems,:XSPDEF)
- if battler.pbCanIncreaseStatStage?(PBStats::SPDEF)
- battler.pbIncreaseStat(PBStats::SPDEF,1,true)
- end
- elsif isConst?(item,PBItems,:XACCURACY)
- if battler.pbCanIncreaseStatStage?(PBStats::ACCURACY)
- battler.pbIncreaseStat(PBStats::ACCURACY,1,true)
- end
- end
- end
- ################################################################################
- # Fleeing from battle.
- ################################################################################
- def pbCanRun?(idxPokemon)
- return false if @opponent
- thispkmn=@battlers[idxPokemon]
- return true if thispkmn.hasWorkingItem(:SMOKEBALL)
- return true if thispkmn.hasWorkingAbility(:RUNAWAY)
- return pbCanSwitch?(idxPokemon,-1,false)
- end
- def pbRun(idxPokemon,duringBattle=false)
- thispkmn=@battlers[idxPokemon]
- if pbIsOpposing?(idxPokemon)
- return 0 if @opponent
- @choices[i][0]=5 # run
- @choices[i][1]=0
- @choices[i][2]=nil
- return -1
- end
- if @opponent
- if $DEBUG && Input.press?(Input::CTRL)
- if pbDisplayConfirm(_INTL("Treat this battle as a win?"))
- @decision=1
- return 1
- elsif pbDisplayConfirm(_INTL("Treat this battle as a loss?"))
- @decision=2
- return 1
- end
- elsif @internalbattle
- pbDisplayPaused(_INTL("No! There's no running from a Trainer battle!"))
- elsif pbDisplayConfirm(_INTL("Would you like to forfeit the match and quit now?"))
- pbDisplay(_INTL("{1} forfeited the match!",self.pbPlayer.name))
- @decision=3
- return 1
- end
- return 0
- end
- if $DEBUG && Input.press?(Input::CTRL)
- pbDisplayPaused(_INTL("Got away safely!"))
- @decision=3
- return 1
- end
- if @cantescape
- pbDisplayPaused(_INTL("Can't escape!"))
- return 0
- end
- if thispkmn.pbHasType?(:GHOST)
- pbDisplayPaused(_INTL("Got away safely!"))
- @decision=3
- return 1
- end
- if thispkmn.hasWorkingItem(:SMOKEBALL)
- if duringBattle
- pbDisplayPaused(_INTL("Got away safely!"))
- else
- pbDisplayPaused(_INTL("{1} fled using its {2}!",thispkmn.pbThis,PBItems.getName(thispkmn.item)))
- end
- @decision=3
- return 1
- end
- if thispkmn.hasWorkingAbility(:RUNAWAY)
- if duringBattle
- pbDisplayPaused(_INTL("Got away safely!"))
- else
- pbDisplayPaused(_INTL("{1} fled using Run Away!",thispkmn.pbThis))
- end
- @decision=3
- return 1
- end
- if !duringBattle && !pbCanSwitch?(idxPokemon,-1,false) # TODO: Use real messages
- pbDisplayPaused(_INTL("Can't escape!"))
- return 0
- end
- # Note: not pbSpeed, because using unmodified Speed
- speedPlayer=@battlers[idxPokemon].speed
- opposing=@battlers[idxPokemon].pbOppositeOpposing
- if opposing.isFainted?
- opposing=opposing.pbPartner
- end
- if !opposing.isFainted?
- speedEnemy=opposing.speed
- if speedPlayer>speedEnemy
- rate=256
- else
- speedEnemy=1 if speedEnemy<=0
- rate=speedPlayer*128/speedEnemy
- rate+=@runCommand*30
- rate&=0xFF
- end
- else
- rate=256
- end
- ret=1
- if pbAIRandom(256)<rate
- pbDisplayPaused(_INTL("Got away safely!"))
- @decision=3
- else
- pbDisplayPaused(_INTL("Can't escape!"))
- ret=-1
- end
- if !duringBattle
- @runCommand+=1
- end
- return ret
- end
- ################################################################################
- # Mega Evolve battler.
- ################################################################################
- def pbCanMegaEvolve?(index)
- return false if $game_switches[NO_MEGA_EVOLUTION]
- return false if !@battlers[index].hasMega?
- return false if !pbHasMegaRing(index)
- side=(pbIsOpposing?(index)) ? 1 : 0
- owner=pbGetOwnerIndex(index)
- return false if @megaEvolution[side][owner]!=-1
- return true
- end
- def pbRegisterMegaEvolution(index)
- side=(pbIsOpposing?(index)) ? 1 : 0
- owner=pbGetOwnerIndex(index)
- @megaEvolution[side][owner]=index
- end
- def pbMegaEvolve(index)
- return if !@battlers[index] || !@battlers[index].pokemon
- return if !(@battlers[index].hasMega? rescue false)
- return if (@battlers[index].isMega? rescue true)
- ownername=pbGetOwner(index).fullname
- ownername=pbGetOwner(index).name if pbBelongsToPlayer?(index)
- if $game_switches[457] && @battlers[index].item==606
- pbDisplay(_INTL("{1}'s {2} is reacting to the PULSE machine!",
- @battlers[index].pbThis,
- PBItems.getName(@battlers[index].item),
- ownername))
- #### KUROTSUNE - 005 - START
- elsif isConst?(@battlers[index].species, PBSpecies, :RAYQUAZA)
- pbDisplay(_INTL("{1}'s fervent wish has reached {2}!",
- ownername,
- @battlers[index].pbThis))
- #### KUROTSUNE - 005 - END
- else
- pbDisplay(_INTL("{1}'s {2} is reacting to {3}'s {4}!",
- @battlers[index].pbThis,PBItems.getName(@battlers[index].item),
- ownername,pbGetMegaRingName(index)))
- end
- if $game_switches[457] && @battlers[index].item==606
- pbCommonAnimation("PulseEvolution",@battlers[index],nil)
- else
- pbCommonAnimation("MegaEvolution",@battlers[index],nil)
- end
- @battlers[index].pokemon.makeMega
- @battlers[index].form=@battlers[index].pokemon.form
- @battlers[index].pbUpdate(true)
- @scene.pbChangePokemon(@battlers[index],@battlers[index].pokemon)
- meganame=@battlers[index].pokemon.megaName
- if !meganame || meganame==""
- meganame=_INTL("Mega {1}",PBSpecies.getName(@battlers[index].pokemon.species))
- end
- if $game_switches[457] && @battlers[index].item==606
- pbDisplay(_INTL("{1} mutated into {2}!",@battlers[index].pbThis,meganame))
- else
- pbDisplay(_INTL("{1} Mega Evolved into {2}!",@battlers[index].pbThis,meganame))
- end
- side=(pbIsOpposing?(index)) ? 1 : 0
- owner=pbGetOwnerIndex(index)
- @megaEvolution[side][owner]=-2
- #### KUROTSUNE - 006 - START
- @battlers[index].pbAbilitiesOnSwitchIn(true)
- #### KUROTSUNE - 006 - END
- end
- ################################################################################
- # Call battler.
- ################################################################################
- def pbCall(index)
- owner=pbGetOwner(index)
- pbDisplay(_INTL("{1} called {2}!",owner.name,@battlers[index].name))
- pbDisplay(_INTL("{1}!",@battlers[index].name))
- if @battlers[index].isShadow?
- if @battlers[index].inHyperMode?
- @battlers[index].pokemon.hypermode=false
- @battlers[index].pokemon.adjustHeart(-300)
- pbDisplay(_INTL("{1} came to its senses from the Trainer's call!",@battlers[index].pbThis))
- else
- pbDisplay(_INTL("But nothing happened!"))
- end
- elsif @battlers[index].status!=PBStatuses::SLEEP &&
- @battlers[index].pbCanIncreaseStatStage?(PBStats::ACCURACY)
- @battlers[index].pbIncreaseStat(PBStats::ACCURACY,1,true)
- else
- pbDisplay(_INTL("But nothing happened!"))
- end
- end
- ################################################################################
- # Gaining Experience.
- ################################################################################
- def pbGainEXP
- return if !@internalbattle
- successbegin=true
- for i in 0...4 # Not ordered by priority
- if !@doublebattle && pbIsDoubleBattler?(i)
- @battlers[i].participants=[]
- next
- end
- if pbIsOpposing?(i) && @battlers[i].participants.length>0 && @battlers[i].isFainted?
- battlerSpecies=@battlers[i].pokemon.species
- # Original species, not current species
- baseexp=@battlers[i].pokemon.baseExp
- level=@battlers[i].level
- # First count the number of participants
- partic=0
- expshare=0
- for j in @battlers[i].participants
- next if !@party1[j] || !pbIsOwner?(0,j)
- partic+=1 if @party1[j].hp>0 && !@party1[j].isEgg?
- end
- for j in 0...@party1.length
- next if !@party1[j] || !pbIsOwner?(0,j)
- expshare+=1 if @party1[j].hp>0 && !@party1[j].isEgg? &&
- (isConst?(@party1[j].item,PBItems,:EXPSHARE) ||
- isConst?(@party1[j].itemInitial,PBItems,:EXPSHARE))
- end
- # Now calculate EXP for the participants
- if partic>0 || expshare>0
- if !@opponent && successbegin && pbAllFainted?(@party2)
- @scene.pbWildBattleSuccess
- successbegin=false
- end
- for j in 0...@party1.length
- thispoke=@party1[j]
- next if !@party1[j] || !pbIsOwner?(0,j)
- ispartic=0
- haveexpshare=(isConst?(thispoke.item,PBItems,:EXPSHARE) ||
- isConst?(thispoke.itemInitial,PBItems,:EXPSHARE)) ? 1 : 0
- for k in @battlers[i].participants
- ispartic=1 if k==j
- end
- if thispoke.hp>0 && !thispoke.isEgg?
- exp=0
- if expshare>0
- if partic==0
- exp=(level*baseexp).floor
- exp=(exp/expshare).floor*haveexpshare
- else
- exp=(level*baseexp/2).floor
- exp=(exp/partic).floor*ispartic + (exp/expshare).floor*haveexpshare
- end
- elsif ispartic==1
- exp=(level*baseexp/partic).floor
- end
- exp=(exp*3/2).floor if @opponent
- if USENEWEXPFORMULA # Use new (Gen 5) Exp. formula
- #### COMMANDER - 003 - START
- #### COMMANDER - 003 - END
- exp=(exp/5).floor
- leveladjust=(2*level+10.0)/(level+thispoke.level+10.0)
- leveladjust=leveladjust**5
- leveladjust=Math.sqrt(leveladjust)
- exp=(exp*leveladjust).floor
- exp+=1 if ispartic>0 || haveexpshare>0
- else # Use old (Gen 1-4) Exp. formula
- exp=(exp/7).floor
- end
- #### COMMANDER - XX1 - START
- $game_switches[1218] = false
- almostLimit = false
- levelLimits = [20, 25, 32, 35, 40, 42, 45, 50, 55, 60, 62, 65, 70, 72, 75, 80, 85, 88, 90, 95, 100]
- leadersDefeated = pbPlayer.numbadges
- if $game_variables[107]>=1
- leadersDefeated += 2
- elsif $game_variables[77]>=1
- leadersDefeated += 1
- end
- if thispoke.level>=levelLimits[leadersDefeated]
- exp = 0
- $game_switches[1218] = true
- elsif thispoke.level == levelLimits[leadersDefeated] - 1
- almostLimit = true
- end
- #### COMMANDER - XX1 - END
- # print("#{thispoke.trainerID}")
- isOutsider=((thispoke.trainerID != self.pbPlayer.id &&
- thispoke.trainerID != 0) ||
- (thispoke.language!=0 && thispoke.language!=self.pbPlayer.language))||$game_variables[975] != 0
- # print("#{isOutsider}")
- if isOutsider
- if thispoke.language!=0 && thispoke.language!=self.pbPlayer.language
- exp=(exp*17/10).floor
- else
- exp=(exp*3/2).floor
- end
- end
- exp=(exp*3/2).floor if isConst?(thispoke.item,PBItems,:LUCKYEGG) ||
- isConst?(thispoke.itemInitial,PBItems,:LUCKYEGG)
- growthrate=thispoke.growthrate
- #### COMMANDER - XX2 - START
- if almostLimit
- totalExpNeeded = PBExperience.pbGetStartExperience(levelLimits[leadersDefeated],growthrate)
- currExpNeeded = totalExpNeeded - thispoke.exp
- if exp > currExpNeeded
- exp = currExpNeeded
- end
- end
- #### COMMANDER - XX2 - END
- newexp=PBExperience.pbAddExperience(thispoke.exp,exp,growthrate)
- exp=newexp-thispoke.exp
- if exp > 0 || $game_switches[1218]
- #### KUROTSUNE - 020 - START
- if isOutsider || isConst?(thispoke.item,PBItems,:LUCKYEGG)
- #### KUROTSUNE - 020 - END
- pbDisplayPaused(_INTL("{1} gained a boosted {2} Exp. Points!",thispoke.name,exp))if exp > 0
- elsif exp > 0
- pbDisplayPaused(_INTL("{1} gained {2} Exp. Points!",thispoke.name,exp))
- end
- #Gain effort value points, using RS effort values
- totalev=0
- for k in 0..5
- totalev+=thispoke.ev[k]
- end
- # Original species, not current species
- evyield=@battlers[i].pokemon.evYield
- for k in 0..5
- evgain=evyield[k]
- evgain*=2 if isConst?(thispoke.item,PBItems,:MACHOBRACE) ||
- isConst?(thispoke.itemInitial,PBItems,:MACHOBRACE)
- case k
- when 0
- if isConst?(thispoke.item,PBItems,:POWERWEIGHT)
- evgain+=4
- end
- when 1
- if isConst?(thispoke.item,PBItems,:POWERBRACER)
- evgain+=4
- end
- when 2
- if isConst?(thispoke.item,PBItems,:POWERBELT)
- evgain+=4
- end
- when 3
- if isConst?(thispoke.item,PBItems,:POWERANKLET)
- evgain+=4
- end
- when 4
- if isConst?(thispoke.item,PBItems,:POWERLENS)
- evgain+=4
- end
- when 5
- if isConst?(thispoke.item,PBItems,:POWERBAND)
- evgain+=4
- end
- end
- evgain*=2 if thispoke.pokerusStage>=1 # Infected or cured
- if evgain>0
- # Can't exceed overall limit
- if totalev+evgain>510
- evgain-=totalev+evgain-510
- end
- # Can't exceed stat limit
- if thispoke.ev[k]+evgain>252
- evgain-=thispoke.ev[k]+evgain-252
- end
- # Add EV gain
- thispoke.ev[k]+=evgain
- if thispoke.ev[k]>252
- print "Single-stat EV limit 252 exceeded.\r\nStat: #{k} EV gain: #{evgain} EVs: #{thispoke.ev.inspect}"
- thispoke.ev[k]=252
- end
- totalev+=evgain
- if totalev>510
- print "EV limit 510 exceeded.\r\nTotal EVs: #{totalev} EV gain: #{evgain} EVs: #{thispoke.ev.inspect}"
- end
- end
- end
- newlevel=PBExperience.pbGetLevelFromExperience(newexp,growthrate)
- tempexp=0
- curlevel=thispoke.level
- thisPokeSpecies=thispoke.species
- if newlevel<curlevel
- debuginfo="#{thispoke.name}: #{thispoke.level}/#{newlevel} | #{thispoke.exp}/#{newexp} | gain: #{exp}"
- raise RuntimeError.new(
- _INTL("The new level ({1}) is less than the Pokémon's\r\ncurrent level ({2}), which shouldn't happen.\r\n[Debug: {3}]",
- newlevel,curlevel,debuginfo))
- return
- end
- if thispoke.respond_to?("isShadow?") && thispoke.isShadow?
- thispoke.exp+=exp
- else
- tempexp1=thispoke.exp
- tempexp2=0
- # Find battler
- battler=pbFindPlayerBattler(j)
- loop do
- #EXP Bar animation
- startexp=PBExperience.pbGetStartExperience(curlevel,growthrate)
- endexp=PBExperience.pbGetStartExperience(curlevel+1,growthrate)
- tempexp2=(endexp<newexp) ? endexp : newexp
- thispoke.exp=tempexp2
- @scene.pbEXPBar(thispoke,battler,startexp,endexp,tempexp1,tempexp2)
- tempexp1=tempexp2
- curlevel+=1
- if curlevel>newlevel
- thispoke.calcStats
- battler.pbUpdate(false) if battler
- @scene.pbRefresh
- break
- end
- oldtotalhp=thispoke.totalhp
- oldattack=thispoke.attack
- olddefense=thispoke.defense
- oldspeed=thispoke.speed
- oldspatk=thispoke.spatk
- oldspdef=thispoke.spdef
- if battler
- if battler.pokemon && @internalbattle
- battler.pokemon.changeHappiness("level up")
- end
- end
- thispoke.calcStats
- battler.pbUpdate(false) if battler
- @scene.pbRefresh
- pbDisplayPaused(_INTL("{1} grew to Level {2}!",thispoke.name,curlevel))
- @scene.pbLevelUp(thispoke,battler,oldtotalhp,oldattack,
- olddefense,oldspeed,oldspatk,oldspdef)
- # Finding all moves learned at this level
- movelist=thispoke.getMoveList
- for k in movelist
- if k[0]==thispoke.level # Learned a new move
- pbLearnMove(j,k[1])
- end
- end
- end
- end
- end
- end
- end
- end
- # Now clear the participants array
- @battlers[i].participants=[]
- end
- end
- end
- ################################################################################
- # Learning a move.
- ################################################################################
- def pbLearnMove(pkmnIndex,move)
- pokemon=@party1[pkmnIndex]
- return if !pokemon
- pkmnname=pokemon.name
- battler=pbFindPlayerBattler(pkmnIndex)
- movename=PBMoves.getName(move)
- for i in 0...4
- if pokemon.moves[i].id==move
- return
- end
- if pokemon.moves[i].id==0
- pokemon.moves[i]=PBMove.new(move)
- battler.moves[i]=PokeBattle_Move.pbFromPBMove(self,pokemon.moves[i]) if battler
- pbDisplayPaused(_INTL("{1} learned {2}!",pkmnname,movename))
- return
- end
- end
- loop do
- pbDisplayPaused(_INTL("{1} is trying to learn {2}.",pkmnname,movename))
- pbDisplayPaused(_INTL("But {1} can't learn more than four moves.",pkmnname))
- if pbDisplayConfirm(_INTL("Delete a move to make room for {1}?",movename))
- pbDisplayPaused(_INTL("Which move should be forgotten?"))
- forgetmove=@scene.pbForgetMove(pokemon,move)
- if forgetmove >=0
- oldmovename=PBMoves.getName(pokemon.moves[forgetmove].id)
- pokemon.moves[forgetmove]=PBMove.new(move) # Replaces current/total PP
- battler.moves[forgetmove]=PokeBattle_Move.pbFromPBMove(self,pokemon.moves[forgetmove]) if battler
- pbDisplayPaused(_INTL("1, 2, and... ... ..."))
- pbDisplayPaused(_INTL("Poof!"))
- pbDisplayPaused(_INTL("{1} forgot {2}.",pkmnname,oldmovename))
- pbDisplayPaused(_INTL("And..."))
- pbDisplayPaused(_INTL("{1} learned {2}!",pkmnname,movename))
- return
- elsif pbDisplayConfirm(_INTL("Should {1} stop learning {2}?",pkmnname,movename))
- pbDisplayPaused(_INTL("{1} did not learn {2}.",pkmnname,movename))
- return
- end
- elsif pbDisplayConfirm(_INTL("Should {1} stop learning {2}?",pkmnname,movename))
- pbDisplayPaused(_INTL("{1} did not learn {2}.",pkmnname,movename))
- return
- end
- end
- end
- ################################################################################
- # Abilities.
- ################################################################################
- def pbOnActiveAll
- for i in 0...4 # Currently unfainted participants will earn EXP even if they faint afterwards
- @battlers[i].pbUpdateParticipants if pbIsOpposing?(i)
- @amuletcoin=true if !pbIsOpposing?(i) &&
- (isConst?(@battlers[i].item,PBItems,:AMULETCOIN) ||
- isConst?(@battlers[i].item,PBItems,:LUCKINCENSE))
- end
- for i in 0...4
- if !@battlers[i].isFainted?
- if @battlers[i].isShadow? && pbIsOpposing?(i)
- pbCommonAnimation("Shadow",@battlers[i],nil)
- pbDisplay(_INTL("Oh!\nA Shadow Pokemon!"))
- end
- end
- end
- # Weather-inducing abilities, Trace, Imposter, etc.
- @usepriority=false
- priority=pbPriority
- for i in priority
- i.pbAbilitiesOnSwitchIn(true)
- end
- # Check forms are correct
- for i in 0...4
- next if @battlers[i].isFainted?
- @battlers[i].pbCheckForm
- end
- end
- def pbOnActiveOne(pkmn,onlyabilities=false)
- return false if pkmn.isFainted?
- if !onlyabilities
- for i in 0...4 # Currently unfainted participants will earn EXP even if they faint afterwards
- @battlers[i].pbUpdateParticipants if pbIsOpposing?(i)
- @amuletcoin=true if !pbIsOpposing?(i) &&
- (isConst?(@battlers[i].item,PBItems,:AMULETCOIN) ||
- isConst?(@battlers[i].item,PBItems,:LUCKINCENSE))
- end
- if pkmn.isShadow? && pbIsOpposing?(pkmn.index)
- pbCommonAnimation("Shadow",pkmn,nil)
- pbDisplay(_INTL("Oh!\nA Shadow Pokemon!"))
- end
- # Healing Wish
- if pkmn.effects[PBEffects::HealingWish]
- pkmn.pbRecoverHP(pkmn.totalhp,true)
- pkmn.status=0
- pkmn.statusCount=0
- pkmn.pbIncreaseStat(PBStats::ATTACK, 1, true) if $fefieldeffect == 31 || $fefieldeffect == 34
- pkmn.pbIncreaseStat(PBStats::SPATK, 1, true) if $fefieldeffect == 31 || $fefieldeffect == 34
- pbDisplayPaused(_INTL("The healing wish came true for {1}!",pkmn.pbThis(true)))
- pkmn.effects[PBEffects::HealingWish]=false
- end
- # Lunar Dance
- if pkmn.effects[PBEffects::LunarDance]
- pkmn.pbRecoverHP(pkmn.totalhp,true)
- pkmn.status=0
- pkmn.statusCount=0
- pkmn.pbIncreaseStat(PBStats::ATTACK, 1, true) if $fefieldeffect == 35 || $fefieldeffect == 34
- pkmn.pbIncreaseStat(PBStats::DEFENSE, 1, true) if $fefieldeffect == 35
- pkmn.pbIncreaseStat(PBStats::SPATK, 1, true) if $fefieldeffect == 35 || $fefieldeffect == 34
- pkmn.pbIncreaseStat(PBStats::SPDEF, 1, true) if $fefieldeffect == 35
- pkmn.pbIncreaseStat(PBStats::SPEED, 1, true) if $fefieldeffect == 35
- pkmn.pbIncreaseStat(PBStats::ACCURACY, 1, true) if $fefieldeffect == 35
- pkmn.pbIncreaseStat(PBStats::EVASION, 1, true) if $fefieldeffect == 35
- for i in 0...4
- pkmn.moves[i].pp=pkmn.moves[i].totalpp
- end
- pbDisplayPaused(_INTL("{1} became cloaked in mystical moonlight!",pkmn.pbThis))
- pkmn.effects[PBEffects::LunarDance]=false
- end
- # Spikes
- pkmn.pbOwnSide.effects[PBEffects::Spikes]=0 if $fefieldeffect == 21 ||
- $fefieldeffect == 26
- if pkmn.pbOwnSide.effects[PBEffects::Spikes]>0
- if !pkmn.isAirborne?
- if !pkmn.hasWorkingAbility(:MAGICGUARD)
- spikesdiv=[8,8,6,4][pkmn.pbOwnSide.effects[PBEffects::Spikes]]
- @scene.pbDamageAnimation(pkmn,0)
- pkmn.pbReduceHP([(pkmn.totalhp/spikesdiv).floor,1].max)
- pbDisplay(_INTL("{1} was hurt by spikes!",pkmn.pbThis))
- end
- end
- end
- pkmn.pbFaint if pkmn.isFainted?
- # Stealth Rock
- if pkmn.pbOwnSide.effects[PBEffects::StealthRock]
- if !pkmn.hasWorkingAbility(:MAGICGUARD)
- atype=getConst(PBTypes,:ROCK) || 0
- if $fefieldeffect == 25
- randtype = pbRandom(4)
- case randtype
- when 0
- atype=getConst(PBTypes,:WATER) || 0
- when 1
- atype=getConst(PBTypes,:GRASS) || 0
- when 2
- atype=getConst(PBTypes,:FIRE) || 0
- when 3
- atype=getConst(PBTypes,:PSYCHIC) || 0
- end
- end
- eff=PBTypes.getCombinedEffectiveness(atype,pkmn.type1,pkmn.type2)
- if eff>0
- if $fefieldeffect == 14 || $fefieldeffect == 23
- eff = eff*2
- end
- @scene.pbDamageAnimation(pkmn,0)
- pkmn.pbReduceHP([(pkmn.totalhp*eff/32).floor,1].max)
- if $fefieldeffect == 25
- pbDisplay(_INTL("{1} was hurt by the crystalized stealth rocks!",pkmn.pbThis))
- else
- pbDisplay(_INTL("{1} was hurt by stealth rocks!",pkmn.pbThis))
- end
- end
- end
- end
- pkmn.pbFaint if pkmn.isFainted?
- # Corrosive Field Entry
- if $fefieldeffect == 10
- if !pkmn.hasWorkingAbility(:MAGICGUARD) &&
- !pkmn.hasWorkingAbility(:POISONHEAL) &&
- !pkmn.hasWorkingAbility(:IMMUNITY) &&
- !pkmn.hasWorkingAbility(:WONDERGUARD) &&
- !pkmn.hasWorkingAbility(:TOXICBOOST)
- if !pkmn.isAirborne?
- if !pkmn.pbHasType?(:POISON) && !pkmn.pbHasType?(:STEEL)
- atype=getConst(PBTypes,:POISON) || 0
- eff=PBTypes.getCombinedEffectiveness(atype,pkmn.type1,pkmn.type2)
- if eff>0
- eff=eff*2
- @scene.pbDamageAnimation(pkmn,0)
- pkmn.pbReduceHP([(pkmn.totalhp*eff/32).floor,1].max)
- pbDisplay(_INTL("{1} was seared by the corrosion!",pkmn.pbThis))
- end
- end
- end
- end
- end
- pkmn.pbFaint if pkmn.hp<=0
- # Sticky Web
- if pkmn.pbOwnSide.effects[PBEffects::StickyWeb]
- if !pkmn.isAirborne?
- if $fefieldeffect == 15
- #StickyWebMessage
- pbDisplay(_INTL("{1} was caught in a sticky web!",pkmn.pbThis))
- pkmn.pbReduceStat(PBStats::SPEED, 2, true)
- else
- pbDisplay(_INTL("{1} was caught in a sticky web!",pkmn.pbThis))
- pkmn.pbReduceStat(PBStats::SPEED, 1, true)
- end
- end
- end
- # Toxic Spikes
- pkmn.pbOwnSide.effects[PBEffects::ToxicSpikes]=0 if $fefieldeffect == 21 ||
- $fefieldeffect == 26
- if pkmn.pbOwnSide.effects[PBEffects::ToxicSpikes]>0
- if !pkmn.isAirborne?
- if pkmn.pbHasType?(:POISON) && $fefieldeffect != 10
- pkmn.pbOwnSide.effects[PBEffects::ToxicSpikes]=0
- pbDisplay(_INTL("{1} absorbed the poison spikes!",pkmn.pbThis)) elsif pkmn.pbCanPoisonSpikes?
- if pkmn.pbOwnSide.effects[PBEffects::ToxicSpikes]==2
- pkmn.pbPoison(pkmn,true)
- pbDisplay(_INTL("{1} was badly poisoned!",pkmn.pbThis))
- else
- pkmn.pbPoison(pkmn)
- pbDisplay(_INTL("{1} was poisoned!",pkmn.pbThis))
- end
- end
- end
- end
- end
- pkmn.pbAbilityCureCheck
- if pkmn.isFainted?
- pbGainEXP
- pbSwitch if @faintswitch
- return false
- end
- #pkmn.pbAbilitiesOnSwitchIn(true)
- if !onlyabilities
- pkmn.pbCheckForm
- pkmn.pbBerryCureCheck
- end
- return true
- end
- ################################################################################
- # Judging.
- ################################################################################
- def pbJudgeCheckpoint(attacker,move=0)
- end
- def pbDecisionOnTime
- count1=0
- count2=0
- hptotal1=0
- hptotal2=0
- for i in @party1
- next if !i
- if i.hp>0 && !i.isEgg?
- count1+=1
- hptotal1+=i.hp
- end
- end
- for i in @party2
- next if !i
- if i.hp>0 && !i.isEgg?
- count2+=1
- hptotal2+=i.hp
- end
- end
- return 1 if count1>count2 # win
- return 2 if count1<count2 # loss
- return 1 if hptotal1>hptotal2 # win
- return 2 if hptotal1<hptotal2 # loss
- return 5 # draw
- end
- def pbDecisionOnTime2
- count1=0
- count2=0
- hptotal1=0
- hptotal2=0
- for i in @party1
- next if !i
- if i.hp>0 && !i.isEgg?
- count1+=1
- hptotal1+=(i.hp*100/i.totalhp)
- end
- end
- hptotal1/=count1 if count1>0
- for i in @party2
- next if !i
- if i.hp>0 && !i.isEgg?
- count2+=1
- hptotal2+=(i.hp*100/i.totalhp)
- end
- end
- hptotal2/=count2 if count2>0
- return 1 if count1>count2 # win
- return 2 if count1<count2 # loss
- return 1 if hptotal1>hptotal2 # win
- return 2 if hptotal1<hptotal2 # loss
- return 5 # draw
- end
- def pbDecisionOnDraw
- return 5 # draw
- end
- def pbJudge
- # PBDebug.log("[Counts: #{pbPokemonCount(@party1)}/#{pbPokemonCount(@party2)}]")
- if pbAllFainted?(@party1) && pbAllFainted?(@party2)
- @decision=pbDecisionOnDraw() # Draw
- return
- end
- if pbAllFainted?(@party1)
- @decision=2 # Loss
- return
- end
- if pbAllFainted?(@party2)
- @decision=1 # Win
- return
- end
- end
- ################################################################################
- # Messages and animations.
- ################################################################################
- def pbApplySceneBG(sprite,filename)
- @scene.pbApplyBGSprite(sprite,filename)
- end
- def pbDisplay(msg)
- @scene.pbDisplayMessage(msg)
- end
- def pbDisplayPaused(msg)
- @scene.pbDisplayPausedMessage(msg)
- end
- def pbDisplayBrief(msg)
- @scene.pbDisplayMessage(msg,true)
- end
- def pbDisplayConfirm(msg)
- @scene.pbDisplayConfirmMessage(msg)
- end
- def pbShowCommands(msg,commands,cancancel=true)
- @scene.pbShowCommands(msg,commands,cancancel)
- end
- def pbAnimation(move,attacker,opponent,hitnum=0)
- if @battlescene
- @scene.pbAnimation(move,attacker,opponent,hitnum)
- end
- end
- def pbCommonAnimation(name,attacker,opponent,hitnum=0)
- if @battlescene
- @scene.pbCommonAnimation(name,attacker,opponent,hitnum)
- end
- end
- def pbChangeBGSprite
- case $fefieldeffect
- when 0 # indoor
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgIndoorA.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseIndoorA.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseIndoorA.png")
- when 1 # electric
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgElectric.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseElectric.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseElectric.png")
- when 2 # grassy
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgGrassy.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseGrassy.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseGrassy.png")
- when 3 # misty
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgMisty.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseMisty.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseMisty.png")
- when 4 # dark crystal cavern
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgDarkCrystalCavern.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseDarkCrystalCavern.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseDarkCrystalCavern.png")
- when 5 # chess
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgChess.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseChess.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseChess.png")
- when 6 # bigtop
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgBigtop.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseBigtop.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseBigtop.png")
- when 7 # burning
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgBurning.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseBurning.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseBurning.png")
- when 8 # swamp
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgSwamp.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseSwamp.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseSwamp.png")
- when 9 # rainbow
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgRainbow.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseRainbow.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseRainbow.png")
- when 10 # corrosive
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgCorrosive.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseCorrosive.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseCorrosive.png")
- when 11 # corrosive mist
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgCorrosiveMist.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseCorrosiveMist.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseCorrosiveMist.png")
- when 12 # desert
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgDesert.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseDesert.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseDesert.png")
- when 13 # icy
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgIcy.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseIcy.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseIcy.png")
- when 14 # rocky
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgRocky.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseRocky.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseRocky.png")
- when 15 # forest
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgForest.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseForest.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseForest.png")
- when 16 # superheated
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgSuperheated.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseSuperheated.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseSuperheated.png")
- when 17 # factory
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgFactory.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseFactory.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseFactory.png")
- when 18 # short-circuit
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgShortcircuit.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseShortcircuit.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseShortcircuit.png")
- when 19 # wasteland
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgWasteland.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseWasteland.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseWasteland.png")
- when 20 # ashen beach
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgAshenBeach.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseAshenBeach.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseAshenBeach.png")
- when 21 # water surface
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgWaterSurface.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseWaterSurface.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseWaterSurface.png")
- when 22 # underwater
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgUnderwater.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseUnderwater.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseUnderwater.png")
- when 23 # cave
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgCave.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseCave.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseCave.png")
- when 24 # glitch
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgGlitch.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseGlitch.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseGlitch.png")
- when 25 # crystal cavern
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgCrystalCavern.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseCrystalCavern.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseCrystalCavern.png")
- when 26 # murkwater surface
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgMurkwaterSurface.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseMurkwaterSurface.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseMurkwaterSurface.png")
- when 27 # mountain
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgMountain.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseMountain.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseMountain.png")
- when 28 # snowymountain
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgSnowyMountain.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseSnowyMountain.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseSnowyMountain.png")
- when 29 # holy
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgHoly.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseHoly.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseHoly.png")
- when 30 # mirror
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgMirror.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseMirror.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseMirror.png")
- when 31 # fairy tale
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgFairyTale.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseFairyTale.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseFairyTale.png")
- when 32 # dragons den
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgDragonsDen.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseDragonsDen.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseDragonsDen.png")
- when 33 # flower garden
- case $fecounter
- when 0
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgFlowerGarden0.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseFlowerGarden0.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseFlowerGarden0.png")
- when 1
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgFlowerGarden1.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseFlowerGarden1.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseFlowerGarden1.png")
- when 2
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgFlowerGarden2.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseFlowerGarden2.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseFlowerGarden2.png")
- when 3
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgFlowerGarden3.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseFlowerGarden3.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseFlowerGarden3.png")
- when 4
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgFlowerGarden4.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseFlowerGarden4.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseFlowerGarden4.png")
- end
- when 34 # starlight field
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgStarlight.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseStarlight.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseStarlight.png")
- when 35 # new world
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgNewWorld.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseNewWorld.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseNewWorld.png")
- when 36 # inverse
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgInverse.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseInverse.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseInverse.png")
- when 37 # indoorA
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgIndoorA.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseIndoorA.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseIndoorA.png")
- when 38 # indoorB
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgIndoorB.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseIndoorB.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseIndoorB.png")
- when 39 # indoorC
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgIndoorC.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseIndoorC.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseIndoorC.png")
- when 40 # city
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgCity.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseCity.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseCity.png")
- when 41 # citynew
- pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgCityNew.png")
- pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseCityNew.png")
- pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseCityNew.png")
- end
- end
- ################################################################################
- # Battle core.
- ################################################################################
- def pbStartBattle(canlose=false)
- begin
- pbStartBattleCore(canlose)
- rescue BattleAbortedException
- @decision=0
- @scene.pbEndBattle(@decision)
- end
- return @decision
- end
- def pbStartBattleCore(canlose)
- if !@fullparty1 && @party1.length>MAXPARTYSIZE
- raise ArgumentError.new(_INTL("Party 1 has more than {1} Pokémon.",MAXPARTYSIZE))
- end
- if !@fullparty2 && @party2.length>MAXPARTYSIZE
- raise ArgumentError.new(_INTL("Party 2 has more than {1} Pokémon.",MAXPARTYSIZE))
- end
- if !@opponent
- #========================
- # Initialize wild Pokémon
- #========================
- if @party2.length==1
- if @doublebattle
- raise _INTL("Only two wild Pokémon are allowed in double battles")
- end
- wildpoke=@party2[0]
- @battlers[1].pbInitialize(wildpoke,0,false)
- @peer.pbOnEnteringBattle(self,wildpoke)
- pbSetSeen(wildpoke)
- @scene.pbStartBattle(self)
- pbDisplayPaused(_INTL("Wild {1} appeared!",wildpoke.name))
- elsif @party2.length==2
- if !@doublebattle
- raise _INTL("Only one wild Pokémon is allowed in single battles")
- end
- @battlers[1].pbInitialize(@party2[0],0,false)
- @battlers[3].pbInitialize(@party2[1],0,false)
- @peer.pbOnEnteringBattle(self,@party2[0])
- @peer.pbOnEnteringBattle(self,@party2[1])
- pbSetSeen(@party2[0])
- pbSetSeen(@party2[1])
- @scene.pbStartBattle(self)
- pbDisplayPaused(_INTL("Wild {1} and\r\n{2} appeared!",
- @party2[0].name,@party2[1].name))
- else
- raise _INTL("Only one or two wild Pokémon are allowed")
- end
- elsif @doublebattle
- #=======================================
- # Initialize opponents in double battles
- #=======================================
- if @opponent.is_a?(Array)
- if @opponent.length==1
- @opponent=@opponent[0]
- elsif @opponent.length!=2
- raise _INTL("Opponents with zero or more than two people are not allowed")
- end
- end
- if @player.is_a?(Array)
- if @player.length==1
- @player=@player[0]
- elsif @player.length!=2
- raise _INTL("Player trainers with zero or more than two people are not allowed")
- end
- end
- @scene.pbStartBattle(self)
- if @opponent.is_a?(Array)
- pbDisplayBrief(_INTL("{1} and {2} want to battle!",@opponent[0].fullname,@opponent[1].fullname))
- sendout1=pbFindNextUnfainted(@party2,0,pbSecondPartyBegin(1))
- raise _INTL("Opponent 1 has no unfainted Pokémon") if sendout1<0
- sendout2=pbFindNextUnfainted(@party2,pbSecondPartyBegin(1))
- raise _INTL("Opponent 2 has no unfainted Pokémon") if sendout2<0
- # pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",@opponent[0].fullname,@party2[sendout1].name))
- #### JERICHO - 001 - START
- @battlers[1].pbInitialize(@party2[sendout1],sendout1,false)
- @battlers[3].pbInitialize(@party2[sendout2],sendout2,false)
- pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",@opponent[0].fullname,PBSpecies.getName(@battlers[1].species))) #ILLUSION
- pbSendOut(1,@party2[sendout1])
- pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",@opponent[1].fullname,PBSpecies.getName(@battlers[3].species))) #ILLUSION
- #### JERICHO - 001 - END
- pbSendOut(3,@party2[sendout2])
- else
- pbDisplayBrief(_INTL("{1}\r\nwould like to battle!",@opponent.fullname))
- sendout1=pbFindNextUnfainted(@party2,0)
- sendout2=pbFindNextUnfainted(@party2,sendout1+1)
- if sendout1<0 || sendout2<0
- raise _INTL("Opponent doesn't have two unfainted Pokémon")
- end
- #### JERICHO - 001 - START
- @battlers[1].pbInitialize(@party2[sendout1],sendout1,false) #ILLUSION
- @battlers[3].pbInitialize(@party2[sendout2],sendout2,false)
- pbDisplayBrief(_INTL("{1} sent\r\nout {2} and {3}!",
- @opponent.fullname,PBSpecies.getName(@battlers[1].species),PBSpecies.getName(@battlers[3].species))) #ILLUSION
- #### JERICHO - 001 - END
- pbSendOut(1,@party2[sendout1])
- pbSendOut(3,@party2[sendout2])
- end
- else
- #======================================
- # Initialize opponent in single battles
- #======================================
- sendout=pbFindNextUnfainted(@party2,0)
- raise _INTL("Trainer has no unfainted Pokémon") if sendout<0
- if @opponent.is_a?(Array)
- raise _INTL("Opponent trainer must be only one person in single battles") if @opponent.length!=1
- @opponent=@opponent[0]
- end
- if @player.is_a?(Array)
- raise _INTL("Player trainer must be only one person in single battles") if @player.length!=1
- @player=@player[0]
- end
- trainerpoke=@party2[sendout]
- @scene.pbStartBattle(self)
- pbDisplayBrief(_INTL("{1}\r\nwould like to battle!",@opponent.fullname))
- #### JERICHO - 001 - START
- @battlers[1].pbInitialize(trainerpoke,sendout,false) #ILLUSION
- pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",@opponent.fullname,PBSpecies.getName(@battlers[1].species)))
- #### JERICHO - 001 - END
- pbSendOut(1,trainerpoke)
- end
- #=====================================
- # Initialize players in double battles
- #=====================================
- if @doublebattle
- if @player.is_a?(Array)
- sendout1=pbFindNextUnfainted(@party1,0,pbSecondPartyBegin(0))
- raise _INTL("Player 1 has no unfainted Pokémon") if sendout1<0
- sendout2=pbFindNextUnfainted(@party1,pbSecondPartyBegin(0))
- raise _INTL("Player 2 has no unfainted Pokémon") if sendout2<0
- #### JERICHO - 001 - START
- @battlers[0].pbInitialize(@party1[sendout1],sendout1,false) #ILLUSION
- @battlers[2].pbInitialize(@party1[sendout2],sendout2,false)
- pbDisplayBrief(_INTL("{1} sent\r\nout {2}! Go! {3}!",
- @player[1].fullname,@battlers[2].name,@battlers[0].name))#ILLUSION
- #### JERICHO - 001 - END
- pbSetSeen(@party1[sendout1])
- pbSetSeen(@party1[sendout2])
- else
- sendout1=pbFindNextUnfainted(@party1,0)
- sendout2=pbFindNextUnfainted(@party1,sendout1+1)
- #### JERICHO - 001 - START
- @battlers[0].pbInitialize(@party1[sendout1],sendout1,false) #ILLUSION
- @battlers[2].pbInitialize(@party1[sendout2],sendout2,false) unless sendout2==-1
- if sendout2>-1
- pbDisplayBrief(_INTL("Go! {1} and {2}!",@battlers[0].name,@battlers[2].name)) #ILLUSION
- else
- pbDisplayBrief(_INTL("Go! {1}!",@battlers[0].name)) #ILLUSION
- end
- end
- #### JERICHO - 001 - END
- pbSendOut(0,@party1[sendout1])
- pbSendOut(2,@party1[sendout2]) unless sendout2==-1
- else
- #====================================
- # Initialize player in single battles
- #====================================
- sendout=pbFindNextUnfainted(@party1,0)
- if sendout<0
- raise _INTL("Player has no unfainted Pokémon")
- end
- playerpoke=@party1[sendout]
- #### JERICHO - 001 - START
- @battlers[0].pbInitialize(playerpoke,sendout,false) #Illusion
- pbDisplayBrief(_INTL("Go! {1}!",@battlers[0].name))
- #### JERICHO - 001 - END
- pbSendOut(0,playerpoke)
- end
- #==================
- # Initialize battle
- #==================
- if @weather==PBWeather::SUNNYDAY
- pbCommonAnimation("Sunny",nil,nil)
- pbDisplay(_INTL("The sunlight is strong."))
- elsif @weather==PBWeather::RAINDANCE
- pbCommonAnimation("Rain",nil,nil)
- pbDisplay(_INTL("It is raining."))
- elsif @weather==PBWeather::SANDSTORM
- pbCommonAnimation("Sandstorm",nil,nil)
- pbDisplay(_INTL("A sandstorm is raging."))
- elsif @weather==PBWeather::HAIL
- pbCommonAnimation("Hail",nil,nil)
- pbDisplay(_INTL("Hail is falling."))
- elsif @weather==PBWeather::STRONGWINDS
- pbDisplay(_INTL("The wind is strong."))
- end
- # Field Effects BEGIN UPDATE
- case $fefieldeffect
- when 1
- pbDisplay(_INTL("The field is hyper-charged!"))
- when 2
- pbDisplay(_INTL("The field is in full bloom."))
- when 3
- pbDisplay(_INTL("Mist settles on the field."))
- when 4
- pbDisplay(_INTL("Darkness is gathering..."))
- when 5
- pbDisplay(_INTL("Opening variation set."))
- when 6
- pbDisplay(_INTL("Now presenting...!"))
- when 7
- pbDisplay(_INTL("The field is ablaze!"))
- when 8
- pbDisplay(_INTL("The field is swamped."))
- when 9
- pbDisplay(_INTL("What does it mean?"))
- when 10
- pbDisplay(_INTL("The field is corrupted!"))
- when 11
- pbDisplay(_INTL("Corrosive mist settles on the field!"))
- when 12
- pbDisplay(_INTL("The field is rife with sand."))
- when 13
- pbDisplay(_INTL("The field is covered in ice."))
- when 14
- pbDisplay(_INTL("The field is littered with rocks."))
- when 15
- pbDisplay(_INTL("The field is abound with trees."))
- when 16
- pbDisplay(_INTL("The field is super-heated!"))
- when 17
- pbDisplay(_INTL("Machines whir in the background."))
- when 18
- pbDisplay(_INTL("Bzzt!"))
- when 19
- pbDisplay(_INTL("The waste is watching..."))
- when 20
- pbDisplay(_INTL("Ash and sand line the field."))
- when 21
- pbDisplay(_INTL("The water's surface is calm."))
- when 22
- pbDisplay(_INTL("Blub blub..."))
- when 23
- pbDisplay(_INTL("The cave echoes dully..."))
- when 24
- pbDisplay(_INTL("1n!taliz3 .b//////attl3"))
- when 25
- pbDisplay(_INTL("The cave is littered with crystals."))
- when 26
- pbDisplay(_INTL("The water is tainted..."))
- when 27
- pbDisplay(_INTL("Adieu to disappointment and spleen."))
- when 28
- pbDisplay(_INTL("The snow glows white on the mountain..."))
- when 29
- pbDisplay(_INTL("Benedictus Sanctus Spiritus..."))
- when 30
- pbDisplay(_INTL("Mirror, mirror, on the field,"))
- pbDisplay(_INTL("Who shalt this fractured power wield?"))
- when 31
- pbDisplay(_INTL("Once upon a time..."))
- when 32
- pbDisplay(_INTL("If you wish to slay a dragon..."))
- when 33
- pbDisplay(_INTL("Seeds line the field."))
- when 34
- pbDisplay(_INTL("Starlight fills the battlefield."))
- when 35
- pbDisplay(_INTL("From darkness, from stardust,"))
- pbDisplay(_INTL("From memories of eons past and visions yet to come..."))
- when 36
- pbDisplay(_INTL("!trats elttaB"))
- end
- # END OF UPDATE
- pbOnActiveAll # Abilities
- @turncount=0
- loop do # Now begin the battle loop
- PBDebug.log("***Round #{@turncount+1}***") if $INTERNAL
- if @debug && @turncount>=100
- @decision=pbDecisionOnTime()
- PBDebug.log("***[Undecided after 100 rounds]")
- pbAbort
- break
- end
- PBDebug.logonerr{
- pbCommandPhase
- }
- break if @decision>0
- PBDebug.logonerr{
- pbAttackPhase
- }
- break if @decision>0
- PBDebug.logonerr{
- pbEndOfRoundPhase
- }
- break if @decision>0
- @turncount+=1
- end
- return pbEndOfBattle(canlose)
- end
- ################################################################################
- # Command phase.
- ################################################################################
- def pbCommandMenu(i)
- return @scene.pbCommandMenu(i)
- end
- def pbItemMenu(i)
- return @scene.pbItemMenu(i)
- end
- def pbAutoFightMenu(i)
- return false
- end
- def pbCommandPhase
- @scene.pbBeginCommandPhase
- @scene.pbResetCommandIndices
- for i in 0...4 # Reset choices if commands can be shown
- if pbCanShowCommands?(i) || @battlers[i].isFainted?
- @choices[i][0]=0
- @choices[i][1]=0
- @choices[i][2]=nil
- @choices[i][3]=-1
- else
- battler=@battlers[i]
- unless !@doublebattle && pbIsDoubleBattler?(i)
- PBDebug.log("[reusing commands for #{battler.pbThis(true)}]") if $INTERNAL
- end
- end
- end
- #### KUROTSUNE - 015 - START
- for i in 0..3
- @switchedOut[i] = false
- end
- #### KUROTSUNE - 015 - END
- # Reset choices to perform Mega Evolution if it wasn't done somehow
- for i in 0...@megaEvolution[0].length
- @megaEvolution[0][i]=-1 if @megaEvolution[0][i]>=0
- end
- for i in 0...@megaEvolution[1].length
- @megaEvolution[1][i]=-1 if @megaEvolution[1][i]>=0
- end
- for i in 0...4
- break if @decision!=0
- next if @choices[i][0]!=0
- if !pbOwnedByPlayer?(i) || @controlPlayer
- if !@battlers[i].isFainted? && pbCanShowCommands?(i)
- @scene.pbChooseEnemyCommand(i)
- end
- else
- commandDone=false
- commandEnd=false
- if pbCanShowCommands?(i)
- loop do
- cmd=pbCommandMenu(i)
- if cmd==0 # Fight
- if pbCanShowFightMenu?(i)
- commandDone=true if pbAutoFightMenu(i)
- until commandDone
- index=@scene.pbFightMenu(i)
- if index<0
- side=(pbIsOpposing?(i)) ? 1 : 0
- owner=pbGetOwnerIndex(i)
- if @megaEvolution[side][owner]==i
- @megaEvolution[side][owner]=-1
- end
- break
- end
- next if !pbRegisterMove(i,index)
- if @doublebattle
- thismove=@battlers[i].moves[index]
- target=@battlers[i].pbTarget(thismove)
- if target==PBTargets::SingleNonUser # single non-user
- target=@scene.pbChooseTarget(i)
- next if target<0
- pbRegisterTarget(i,target)
- elsif target==PBTargets::UserOrPartner # Acupressure
- target=@scene.pbChooseTargetAcupressure(i)
- next if target<0 || (target&1)!=(i&1)
- pbRegisterTarget(i,target)
- end
- end
- commandDone=true
- end
- else
- pbAutoChooseMove(i)
- commandDone=true
- end
- elsif cmd==1 # Bag
- if !@internalbattle
- if pbOwnedByPlayer?(i)
- pbDisplay(_INTL("Items can't be used here."))
- end
- else
- item=pbItemMenu(i)
- if item[0]>0
- if pbRegisterItem(i,item[0],item[1])
- commandDone=true
- end
- end
- end
- elsif cmd==2 # Pokémon
- pkmn=pbSwitchPlayer(i,false,true)
- if pkmn>=0
- commandDone=true if pbRegisterSwitch(i,pkmn)
- end
- elsif cmd==3 # Run
- run=pbRun(i)
- if run>0
- commandDone=true
- return
- elsif run<0
- commandDone=true
- side=(pbIsOpposing?(i)) ? 1 : 0
- owner=pbGetOwnerIndex(i)
- if @megaEvolution[side][owner]==i
- @megaEvolution[side][owner]=-1
- end
- end
- elsif cmd==4 # Call
- thispkmn=@battlers[i]
- @choices[i][0]=4 # "Call Pokémon"
- @choices[i][1]=0
- @choices[i][2]=nil
- side=(pbIsOpposing?(i)) ? 1 : 0
- owner=pbGetOwnerIndex(i)
- if @megaEvolution[side][owner]==i
- @megaEvolution[side][owner]=-1
- end
- commandDone=true
- elsif cmd==-1 # Go back to first battler's choice
- @megaEvolution[0][0]=-1 if @megaEvolution[0][0]>=0
- @megaEvolution[1][0]=-1 if @megaEvolution[1][0]>=0
- # Restore the item the player's first Pokémon was due to use
- if @choices[0][0]==3 && $PokemonBag && $PokemonBag.pbCanStore?(@choices[0][1])
- $PokemonBag.pbStoreItem(@choices[0][1])
- end
- pbCommandPhase
- return
- end
- break if commandDone
- end
- end
- end
- end
- end
- ################################################################################
- # Attack phase.
- ################################################################################
- def pbAttackPhase
- @scene.pbBeginAttackPhase
- for i in 0...4
- @successStates[i].clear
- if @choices[i][0]!=1 && @choices[i][0]!=2
- @battlers[i].effects[PBEffects::DestinyBond]=false
- @battlers[i].effects[PBEffects::Grudge]=false
- end
- @battlers[i].turncount+=1 if !@battlers[i].isFainted?
- @battlers[i].effects[PBEffects::Rage]=false if !pbChoseMove?(i,:RAGE)
- @battlers[i].pbCustapBerry
- end
- # Calculate priority at this time
- @usepriority=false
- priority=pbPriority
- # Mega Evolution
- for i in priority
- next if @choices[i.index][0]!=1
- side=(pbIsOpposing?(i.index)) ? 1 : 0
- owner=pbGetOwnerIndex(i.index)
- if @megaEvolution[side][owner]==i.index
- pbMegaEvolve(i.index)
- end
- end
- # Call at Pokémon
- for i in priority
- if @choices[i.index][0]==4
- pbCall(i.index)
- end
- end
- # Switch out Pokémon
- @switching=true
- switched=[]
- for i in priority
- if @choices[i.index][0]==2
- index=@choices[i.index][1] # party position of Pokémon to switch to
- self.lastMoveUser=i.index
- if !pbOwnedByPlayer?(i.index)
- owner=pbGetOwner(i.index)
- pbDisplayBrief(_INTL("{1} withdrew {2}!",owner.fullname,PBSpecies.getName(i.species)))
- else
- pbDisplayBrief(_INTL("{1}, that's enough!\r\nCome back!",i.name))
- end
- for j in priority
- next if !i.pbIsOpposing?(j.index)
- # if Pursuit and this target ("i") was chosen
- if pbChoseMoveFunctionCode?(j.index,0x88) &&
- !j.effects[PBEffects::Pursuit] &&
- (@choices[j.index][3]==-1 || @choices[j.index][3]==i.index)
- if j.status!=PBStatuses::SLEEP &&
- j.status!=PBStatuses::FROZEN &&
- (!j.hasWorkingAbility(:TRUANT) || !j.effects[PBEffects::Truant])
- j.pbUseMove(@choices[j.index])
- j.effects[PBEffects::Pursuit]=true
- # UseMove calls pbGainEXP as appropriate
- @switching=false
- return if @decision>0
- end
- end
- break if i.isFainted?
- end
- if !pbRecallAndReplace(i.index,index)
- # If a forced switch somehow occurs here in single battles
- # the attack phase now ends
- if !@doublebattle
- @switching=false
- return
- end
- else
- switched.push(i.index)
- end
- end
- end
- if switched.length>0
- for i in priority
- i.pbAbilitiesOnSwitchIn(true) if switched.include?(i.index)
- end
- end
- @switching=false
- # Use items
- for i in priority
- if pbIsOpposing?(i.index) && @choices[i.index][0]==3
- pbEnemyUseItem(@choices[i.index][1],i)
- i.itemUsed = true
- elsif @choices[i.index][0]==3
- # Player use item
- item=@choices[i.index][1]
- if item>0
- usetype=$ItemData[item][ITEMBATTLEUSE]
- if usetype==1 || usetype==3
- if @choices[i.index][2]>=0
- pbUseItemOnPokemon(item,@choices[i.index][2],i,@scene)
- i.itemUsed = true
- end
- elsif usetype==2 || usetype==4
- if !ItemHandlers.hasUseInBattle(item) # Poké Ball/Poké Doll used already
- pbUseItemOnBattler(item,@choices[i.index][2],i,@scene)
- i.itemUsed = true
- end
- end
- end
- end
- end
- #### KUROTSUNE - 014 - START
- if @field.effects[PBEffects::WonderRoom] > 0
- for i in @battlers
- if !i.wonderroom
- i.pbSwapDefenses
- end
- end
- end
- #### KUROTSUNE - 014 - END
- symbiosis = pbSymbiosisCheck(priority)
- # Use Attacks
- for i in priority
- if pbChoseMoveFunctionCode?(i.index,0x115) # Focus Punch
- pbCommonAnimation("FocusPunch",i,nil)
- pbDisplay(_INTL("{1} is tightening its focus!",i.pbThis))
- end
- end
- for i in priority
- i.pbProcessTurn(@choices[i.index])
- if i.effects[PBEffects::Round]
- i.pbPartner.selectedMove = 297
- end
- if symbiosis
- for s in symbiosis
- if s.item == 0 && s.pbPartner.item
- pbDisplay(_INTL("{1} received {2}'s {3} from symbiosis! ",s.pbThis, s.pbPartner.pbThis, PBItems.getName(s.pbPartner.item)))
- s.item = s.pbPartner.item
- s.pokemon.itemInitial = s.pbPartner.item
- s.pbPartner.pokemon.itemInitial = 0
- s.pbPartner.item=0
- end
- end
- end
- return if @decision>0
- end
- pbWait(20)
- end
- # Checks if anyone is eligible to receive an item through symbiosis
- def pbSymbiosisCheck(battlers)
- result = Array.new
- count = 0
- for i in battlers
- if i.item != 0 && i.pokemon.itemInitial != 0 &&
- i.pbPartner.item != 0 && i.pbPartner.pokemon.itemInitial != 0 &&
- i.pbPartner.hasWorkingAbility(:SYMBIOSIS)
- result[count] = i
- count += 1
- end
- end
- if result.any?
- return result
- else
- return false
- end
- end
- ################################################################################
- # End of round.
- ################################################################################
- def pbEndOfRoundPhase
- for i in 0...4
- @battlers[i].forcedSwitchEarlier = false
- @battlers[i].effects[PBEffects::Roost]=false
- @battlers[i].effects[PBEffects::Protect]=false
- @battlers[i].effects[PBEffects::KingsShield]=false # add this line
- @battlers[i].effects[PBEffects::ProtectNegation]=false
- @battlers[i].effects[PBEffects::Endure]=false
- @battlers[i].effects[PBEffects::HyperBeam]-=1 if @battlers[i].effects[PBEffects::HyperBeam]>0
- @battlers[i].effects[PBEffects::SpikyShield]=false
- #### KUROTSUNE - 023 - START
- @battlers[i].effects[PBEffects::Powder] = false
- #### KUROTSUNE - 023 - END
- #### KUROTSUNE - 032 - START
- @battlers[i].effects[PBEffects::MeFirst] = false
- #### KUROTSUNE - 032 - END
- @battlers[i].itemUsed = false
- end
- #### KUROTSUNE - 013 - START
- @field.effects[PBEffects::IonDeluge] = false
- #### KUROTSUNE - 013 - END
- for i in 0...2
- sides[i].effects[PBEffects::QuickGuard]=false
- sides[i].effects[PBEffects::WideGuard]=false
- sides[i].effects[PBEffects::MatBlock]=false
- end
- @usepriority=false # recalculate priority
- priority=pbPriority(true) # Ignoring Quick Claw here
- if @trickroom > 0
- @trickroom=@trickroom-1
- if @trickroom == 0
- Kernel.pbMessage("The twisted dimensions returned to normal!")
- end
- end
- #### KUROTSUNE - 014 - START
- if @field.effects[PBEffects::WonderRoom] > 0
- @field.effects[PBEffects::WonderRoom] -= 1
- if @field.effects[PBEffects::WonderRoom] == 0
- for i in @battlers
- if i.wonderroom
- i.pbSwapDefenses
- end
- end
- Kernel.pbMessage("Wonder Room wore off, and the Defense and Sp. Def stats returned to normal!")
- end
- end
- #### KUROTSUNE - 014 - END
- priority=pbPriority(true) # Ignoring Quick Claw here
- #### AME - 003 - START
- # Field Effects
- endmessage=false
- for i in priority
- next if i.isFainted?
- case $fefieldeffect
- when 2 # Grassy Field
- next if i.hp<=0
- if !i.isAirborne?
- if i.effects[PBEffects::HealBlock]==0 && i.totalhp != i.hp
- pbDisplay(_INTL("The grassy terrain healed the Pokemon on the field.",i.pbThis)) if endmessage == false
- endmessage=true
- hpgain=(i.totalhp/16).floor
- hpgain=(hpgain*1.3).floor if isConst?(i.item,PBItems,:BIGROOT)
- hpgain=i.pbRecoverHP(hpgain,true)
- end
- end
- when 7 # Burning Field
- next if i.hp<=0
- if !i.isAirborne?
- if isConst?(i.ability,PBAbilities,:FLASHFIRE)
- if !i.effects[PBEffects::FlashFire]
- i.effects[PBEffects::FlashFire]=true
- pbDisplay(_INTL("{1}'s {2} raised its Fire power!",
- i.pbThis,PBAbilities.getName(i.ability)))
- end
- end
- if !i.pbHasType?(:FIRE) && !i.effects[PBEffects::AquaRing] &&
- !isConst?(i.ability,PBAbilities,:FLAREBOOST) &&
- !isConst?(i.ability,PBAbilities,:WATERVEIL) &&
- !isConst?(i.ability,PBAbilities,:FLASHFIRE) &&
- !isConst?(i.ability,PBAbilities,:HEATPROOF) &&
- !isConst?(i.ability,PBAbilities,:MAGMAARMOR) &&
- !isConst?(i.ability,PBAbilities,:FLAMEBODY) &&
- !isConst?(i.ability,PBAbilities,:MAGICGUARD) &&
- ![0xCA,0xCB].include?(PBMoveData.new(i.effects[PBEffects::TwoTurnAttack]).function) # Dig, Dive
- atype=getConst(PBTypes,:FIRE) || 0
- eff=PBTypes.getCombinedEffectiveness(atype,i.type1,i.type2)
- if eff>0
- @scene.pbDamageAnimation(i,0)
- if isConst?(i.ability,PBAbilities,:LEAFGUARD) ||
- isConst?(i.ability,PBAbilities,:ICEBODY) ||
- isConst?(i.ability,PBAbilities,:GRASSPELT)
- eff = eff*2
- end
- pbDisplay(_INTL("The Pokemon were burned by the field!",i.pbThis)) if endmessage == false
- endmessage=true
- i.pbReduceHP([(i.totalhp*eff/32).floor,1].max)
- if i.hp<=0
- return if !i.pbFaint
- end
- end
- end
- end
- when 10 # Corrosive Field
- next if i.hp<=0
- if i.hasWorkingAbility(:GRASSPELT)
- @scene.pbDamageAnimation(i,0)
- i.pbReduceHP((i.totalhp/8).floor)
- pbDisplay(_INTL("{1}'s Pelt was corroded!",i.pbThis)) if hpgain>0
- if i.hp<=0
- return if !i.pbFaint
- end
- end
- if i.hasWorkingAbility(:POISONHEAL)
- if !i.isAirborne?
- if i.effects[PBEffects::HealBlock]==0
- if i.hp<i.totalhp
- pbCommonAnimation("Poison",i,nil)
- i.pbRecoverHP((i.totalhp/8).floor,true)
- pbDisplay(_INTL("{1} was healed by poison!",i.pbThis))
- end
- end
- end
- end
- when 11 # Corrosive Mist Field
- if i.pbCanPoison?(false)
- pbDisplay(_INTL("The Pokemon were poisoned by the corroded mist!",i.pbThis)) if endmessage == false
- endmessage=true
- i.pbPoison(i)
- end
- if isConst?(i.ability,PBAbilities,:POISONHEAL)
- if i.effects[PBEffects::HealBlock]==0
- if i.hp<i.totalhp
- pbCommonAnimation("Poison",i,nil)
- i.pbRecoverHP((i.totalhp/8).floor,true)
- pbDisplay(_INTL("{1} was healed by poison!",i.pbThis))
- end
- end
- end
- when 15 # Forest Field
- next if i.hp<=0
- if i.hasWorkingAbility(:SAPSIPPER) && i.effects[PBEffects::HealBlock]==0
- hpgain=(i.totalhp/16).floor
- hpgain=i.pbRecoverHP(hpgain,true)
- pbDisplay(_INTL("{1} drank tree sap to recover!",i.pbThis)) if hpgain>0
- end
- when 18 # Shortcircuit Field
- next if i.hp<=0
- if i.hasWorkingAbility(:VOLTABSORB) && i.effects[PBEffects::HealBlock]==0
- hpgain=(i.totalhp/16).floor
- hpgain=i.pbRecoverHP(hpgain,true)
- pbDisplay(_INTL("{1} absorbed stray electricity!",i.pbThis)) if hpgain>0
- end
- when 19 # Wasteland
- if i.hasWorkingAbility(:POISONHEAL)
- if !i.isAirborne?
- if i.effects[PBEffects::HealBlock]==0
- if i.hp<i.totalhp
- pbCommonAnimation("Poison",i,nil)
- i.pbRecoverHP((i.totalhp/8).floor,true)
- pbDisplay(_INTL("{1} was healed by poison!",i.pbThis))
- end
- end
- end
- end
- when 21 # Water Surface
- next if i.hp<=0
- if i.hasWorkingAbility(:WATERABSORB) && i.effects[PBEffects::HealBlock]==0
- hpgain=(i.totalhp/16).floor
- hpgain=i.pbRecoverHP(hpgain,true)
- pbDisplay(_INTL("{1} absorbed some of the water!",i.pbThis)) if hpgain>0
- end
- when 22# Underwater
- next if i.hp<=0
- if !i.pbHasType?(:WATER) &&
- !i.hasWorkingAbility(:SWIFTSWIM) &&
- !i.hasWorkingAbility(:MAGICGUARD)
- atype=getConst(PBTypes,:WATER) || 0
- eff=PBTypes.getCombinedEffectiveness(atype,i.type1,i.type2)
- if eff>4
- @scene.pbDamageAnimation(i,0)
- if i.hasWorkingAbility(:FLAMEBODY) ||
- i.hasWorkingAbility(:MAGMAARMOR)
- eff = eff*2
- end
- i.pbReduceHP([(i.totalhp*eff/32).floor,1].max)
- pbDisplay(_INTL("{1} struggled in the water!",i.pbThis))
- if i.hp<=0
- return if !i.pbFaint
- end
- end
- end
- when 26 # Murkwater Surface
- if !i.pbHasType?(:STEEL) && !i.pbHasType?(:POISON) &&
- !i.hasWorkingAbility(:POISONHEAL) &&
- !i.hasWorkingAbility(:MAGICGUARD) &&
- !i.hasWorkingAbility(:WONDERGUARD) &&
- !i.hasWorkingAbility(:TOXICBOOST) &&
- !i.hasWorkingAbility(:IMMUNITY)
- atype=getConst(PBTypes,:POISON) || 0
- eff=PBTypes.getCombinedEffectiveness(atype,i.type1,i.type2)
- if i.hasWorkingAbility(:FLAMEBODY) ||
- i.hasWorkingAbility(:MAGMAARMOR) ||
- i.hasWorkingAbility(:DRYSKIN) ||
- i.hasWorkingAbility(:WATERABSORB)
- eff = eff*2
- end
- if PBMoveData.new(i.effects[PBEffects::TwoTurnAttack]).function==0xCB # Dive
- @scene.pbDamageAnimation(i,0)
- i.pbReduceHP([(i.totalhp*eff/8).floor,1].max)
- pbDisplay(_INTL("{1} suffocated underneath the toxic water!",i.pbThis))
- else
- if !i.isAirborne?
- @scene.pbDamageAnimation(i,0)
- i.pbReduceHP([(i.totalhp*eff/32).floor,1].max)
- pbDisplay(_INTL("{1} was hurt by the toxic water!",i.pbThis))
- end
- end
- end
- if i.isFainted?
- return if !i.pbFaint
- end
- if i.hasWorkingAbility(:POISONHEAL)
- if !i.isAirborne?
- if i.effects[PBEffects::HealBlock]==0
- if i.hp<i.totalhp
- pbCommonAnimation("Poison",i,nil)
- i.pbRecoverHP((i.totalhp/8).floor,true)
- pbDisplay(_INTL("{1} was healed by poisoned water!",i.pbThis))
- end
- end
- end
- end
- if i.pbHasType?(:POISON) && (i.hasWorkingAbility(:DRYSKIN) ||
- i.hasWorkingAbility(:WATERABSORB))
- if !i.isAirborne?
- if i.effects[PBEffects::HealBlock]==0
- if i.hp<i.totalhp
- pbCommonAnimation("Poison",i,nil)
- i.pbRecoverHP((i.totalhp/8).floor,true)
- pbDisplay(_INTL("{1} was healed by the poisoned water!",i.pbThis))
- end
- end
- end
- end
- when 35 # New World
- $fecounter = 1
- end
- end
- # End Field stuff
- #### AME - 003 - END # Weather
- if $fefieldeffect != 22
- if @weather != PBWeather::HAIL && $fefieldeffect == 27
- $fecounter = 0
- end
- case @weather
- when PBWeather::SUNNYDAY
- @weatherduration=@weatherduration-1 if @weatherduration>0
- if @weatherduration==0
- pbDisplay(_INTL("The sunlight faded."))
- @weather=0
- if $febackup == 34
- $fefieldeffect = 34
- pbChangeBGSprite
- pbDisplay(_INTL("The starry sky shone through!"));
- end
- else
- pbCommonAnimation("Sunny",nil,nil)
- if $fefieldeffect == 34 # Starlight Arena
- $fefieldeffect = 0
- pbChangeBGSprite
- pbDisplay(_INTL("The sunlight eclipsed the starry sky!"));
- end
- # pbDisplay(_INTL("The sunlight is strong."));
- for i in priority
- if i.hasWorkingAbility(:SOLARPOWER)
- pbDisplay(_INTL("{1} was hurt by the sunlight!",i.pbThis))
- @scene.pbDamageAnimation(i,0)
- i.pbReduceHP((i.totalhp/8).floor)
- if i.isFainted?
- return if !i.pbFaint
- end
- end
- end
- end
- when PBWeather::RAINDANCE
- @weatherduration=@weatherduration-1 if @weatherduration>0
- if @weatherduration==0
- pbDisplay(_INTL("The rain stopped."))
- @weather=0
- if $febackup == 34
- $fefieldeffect = 34
- pbChangeBGSprite
- pbDisplay(_INTL("The starry sky shone through!"));
- end
- else
- pbCommonAnimation("Rain",nil,nil)
- # pbDisplay(_INTL("Rain continues to fall."));
- if $fefieldeffect == 7 # Burning Field
- if $fefieldeffect == $febackup
- $fefieldeffect = 0
- else
- $fefieldeffect = $febackup
- end
- pbChangeBGSprite
- pbDisplay(_INTL("The rain snuffed out the flame!"));
- end
- if $fefieldeffect == 34 # Starlight Arena
- $fefieldeffect = 0
- pbChangeBGSprite
- pbDisplay(_INTL("The weather blocked out the starry sky!"));
- end
- end
- when PBWeather::SANDSTORM
- @weatherduration=@weatherduration-1 if @weatherduration>0
- if @weatherduration==0
- pbDisplay(_INTL("The sandstorm subsided."))
- @weather=0
- if $febackup == 34
- $fefieldeffect = 34
- pbChangeBGSprite
- pbDisplay(_INTL("The starry sky shone through!"));
- end
- else
- pbCommonAnimation("Sandstorm",nil,nil)
- # pbDisplay(_INTL("The sandstorm rages."))
- if $fefieldeffect == 7 # Burning Field
- if $fefieldeffect == $febackup
- $fefieldeffect = 0
- else
- $fefieldeffect = $febackup
- end
- pbChangeBGSprite
- pbDisplay(_INTL("The sand snuffed out the flame!"));
- end
- if $fefieldeffect == 9 # Rainbow Field
- if $fefieldeffect == $febackup
- $fefieldeffect = 0
- else
- $fefieldeffect = $febackup
- end
- pbChangeBGSprite
- pbDisplay(_INTL("The weather blocked out the rainbow!"));
- end
- if $fefieldeffect == 34 # Starlight Arena
- $fefieldeffect = 0
- pbChangeBGSprite
- pbDisplay(_INTL("The weather blocked out the starry sky!"));
- end
- if pbWeather==PBWeather::SANDSTORM
- endmessage=false
- for i in priority
- next if i.isFainted?
- if !i.pbHasType?(:GROUND) && !i.pbHasType?(:ROCK) && !i.pbHasType?(:STEEL) &&
- !i.hasWorkingAbility(:SANDVEIL) &&
- !i.hasWorkingAbility(:SANDRUSH) &&
- !i.hasWorkingAbility(:SANDFORCE) &&
- !i.hasWorkingAbility(:MAGICGUARD) &&
- !isConst?(i.item,PBItems,:SAFETYGOGGLES) &&
- !i.hasWorkingAbility(:OVERCOAT) &&
- ![0xCA,0xCB].include?(PBMoveData.new(i.effects[PBEffects::TwoTurnAttack]).function) # Dig, Dive
- pbDisplay(_INTL("The Pokemon were buffeted by the sandstorm!",i.pbThis)) if endmessage==false
- endmessage=true
- @scene.pbDamageAnimation(i,0)
- i.pbReduceHP((i.totalhp/16).floor)
- if i.isFainted?
- return if !i.pbFaint
- end
- end
- end
- end
- end
- when PBWeather::HAIL
- @weatherduration=@weatherduration-1 if @weatherduration>0
- if @weatherduration==0
- pbDisplay(_INTL("The hail stopped."))
- @weather=0
- if $febackup == 34
- $fefieldeffect = 34
- pbChangeBGSprite
- pbDisplay(_INTL("The starry sky shone through!"));
- end
- elsif $fefieldeffect == 16
- pbDisplay(_INTL("The hail melted away."))
- @weather=0
- else
- pbCommonAnimation("Hail",nil,nil)
- # pbDisplay(_INTL("Hail continues to fall."))
- if $fefieldeffect == 9 # Rainbow ield
- if $fefieldeffect == $febackup
- $fefieldeffect = 0
- else
- $fefieldeffect = $febackup
- end
- pbChangeBGSprite
- pbDisplay(_INTL("The weather blocked out the rainbow!"));
- end
- if $fefieldeffect == 34 # Starlight Arena
- $fefieldeffect = 0
- pbChangeBGSprite
- pbDisplay(_INTL("The weather blocked out the starry sky!"));
- end
- if pbWeather==PBWeather::HAIL
- endmessage=false
- for i in priority
- next if i.isFainted?
- if !i.pbHasType?(:ICE) &&
- !i.hasWorkingAbility(:ICEBODY) &&
- !i.hasWorkingAbility(:SNOWCLOAK) &&
- !i.hasWorkingAbility(:MAGICGUARD) &&
- !isConst?(i.item,PBItems,:SAFETYGOGGLES) &&
- !i.hasWorkingAbility(:OVERCOAT) &&
- ![0xCA,0xCB].include?(PBMoveData.new(i.effects[PBEffects::TwoTurnAttack]).function) # Dig, Dive
- pbDisplay(_INTL("The Pokemon were buffeted by the hail!",i.pbThis)) if endmessage==false
- endmessage=true
- @scene.pbDamageAnimation(i,0)
- i.pbReduceHP((i.totalhp/16).floor)
- if i.isFainted?
- return if !i.pbFaint
- end
- end
- end
- if $fefieldeffect == 27
- $fecounter+=1
- if $fecounter == 3
- $fecounter = 0
- $fefieldeffect = 28
- pbChangeBGSprite
- pbDisplay(_INTL("The mountain was covered in snow!"))
- end
- end
- end
- end
- when PBWeather::STRONGWINDS
- pbCommonAnimation("Wind",nil,nil)
- # pbDisplay(_INTL("The wind is strong."));
- end
- end
- # Shadow Sky weather
- if isConst?(@weather,PBWeather,:SHADOWSKY)
- @weatherduration=@weatherduration-1 if @weatherduration>0
- if @weatherduration==0
- pbDisplay(_INTL("The shadow sky faded."))
- @weather=0
- else
- pbCommonAnimation("ShadowSky",nil,nil)
- # pbDisplay(_INTL("The shadow sky continues."));
- if isConst?(pbWeather,PBWeather,:SHADOWSKY)
- for i in priority
- next if i.isFainted?
- if !i.isShadow?
- pbDisplay(_INTL("{1} was hurt by the shadow sky!",i.pbThis))
- @scene.pbDamageAnimation(i,0)
- i.pbReduceHP((i.totalhp/16).floor)
- if i.isFainted?
- return if !i.pbFaint
- end
- end
- end
- end
- end
- end
- # Future Sight/Doom Desire
- for i in battlers # not priority
- next if i.isFainted?
- if i.effects[PBEffects::FutureSight]>0
- i.effects[PBEffects::FutureSight]-=1
- if i.effects[PBEffects::FutureSight]==0
- if i.effects[PBEffects::FutureSightMove] == 516
- move=PokeBattle_Move.pbFromPBMove(self,PBMove.new(637))
- elsif i.effects[PBEffects::FutureSightMove] == 450
- move=PokeBattle_Move.pbFromPBMove(self,PBMove.new(636))
- end
- pbDisplay(_INTL("{1} took the {2} attack!",i.pbThis,move.name))
- moveuser=@battlers[i.effects[PBEffects::FutureSightUser]]
- if i.isFainted? || move.pbAccuracyCheck(moveuser,i)
- i.damagestate.reset
- damage = nil
- if i.effects[PBEffects::FutureSightMove] == 450 && !(i.pbHasType?(:DARK))
- pbCommonAnimation("FutureSight",i,nil)
- elsif i.effects[PBEffects::FutureSightMove] == 516
- pbCommonAnimation("DoomDesire",i,nil)
- end
- move.pbReduceHPDamage(damage,moveuser,i)
- move.pbEffectMessages(moveuser,i)
- else
- pbDisplay(_INTL("But it failed!"))
- end
- i.effects[PBEffects::FutureSight]=0
- i.effects[PBEffects::FutureSightMove]=0
- i.effects[PBEffects::FutureSightDamage]=0
- i.effects[PBEffects::FutureSightUser]=-1
- if i.isFainted?
- return if !i.pbFaint
- next
- end
- end
- end
- end
- for i in priority
- next if i.isFainted?
- # Rain Dish
- if pbWeather==PBWeather::RAINDANCE && i.hasWorkingAbility(:RAINDISH)
- hpgain=i.pbRecoverHP((i.totalhp/16).floor,true)
- pbDisplay(_INTL("{1}'s Rain Dish restored its HP a little!",i.pbThis)) if hpgain>0
- end
- # Dry Skin
- if isConst?(i.ability,PBAbilities,:DRYSKIN)
- if pbWeather==PBWeather::RAINDANCE && i.effects[PBEffects::HealBlock]==0
- hpgain=i.pbRecoverHP((i.totalhp/8).floor,true)
- pbDisplay(_INTL("{1}'s Dry Skin was healed by the rain!",i.pbThis)) if hpgain>0
- elsif pbWeather==PBWeather::SUNNYDAY
- @scene.pbDamageAnimation(i,0)
- hploss=i.pbReduceHP((i.totalhp/8).floor)
- pbDisplay(_INTL("{1}'s Dry Skin was hurt by the sunlight!",i.pbThis)) if hploss>0
- elsif $fefieldeffect == 11 && !i.pbHasType?(:STEEL)
- if !i.pbHasType?(:POISON)
- @scene.pbDamageAnimation(i,0)
- hploss=i.pbReduceHP((i.totalhp/8).floor)
- pbDisplay(_INTL("{1}'s Dry Skin absorbed the poison!",i.pbThis)) if hploss>0
- elsif i.effects[PBEffects::HealBlock]==0
- hpgain=i.pbRecoverHP((i.totalhp/8).floor,true)
- pbDisplay(_INTL("{1}'s Dry Skin was healed by the poison!",i.pbThis)) if hpgain>0
- end
- elsif $fefieldeffect == 12
- @scene.pbDamageAnimation(i,0)
- hploss=i.pbReduceHP((i.totalhp/8).floor)
- pbDisplay(_INTL("{1}'s Dry Skin was hurt by the desert air!",i.pbThis)) if hploss>0
- elsif $fefieldeffect == 3 || $fefieldeffect == 8 && # Misty/Swamp Field
- i.effects[PBEffects::HealBlock]==0
- hpgain=(i.totalhp/16).floor
- hpgain=i.pbRecoverHP(hpgain,true)
- pbDisplay(_INTL("{1}'s Dry Skin was healed by the mist!",i.pbThis)) if hpgain>0
- elsif $fefieldeffect == 21 || $fefieldeffect == 22 && #Water fields
- i.effects[PBEffects::HealBlock]==0
- hpgain=(i.totalhp/16).floor
- hpgain=i.pbRecoverHP(hpgain,true)
- pbDisplay(_INTL("{1}'s Dry Skin was healed by the water!",i.pbThis)) if hpgain>0
- end
- end
- # Ice Body
- if (pbWeather==PBWeather::HAIL || $fefieldeffect == 13 ||
- $fefieldeffefct == 28) &&
- i.hasWorkingAbility(:ICEBODY) && i.effects[PBEffects::HealBlock]==0
- hpgain=i.pbRecoverHP((i.totalhp/16).floor,true)
- pbDisplay(_INTL("{1}'s Ice Body restored its HP a little!",i.pbThis)) if hpgain>0
- end
- if i.isFainted?
- return if !i.pbFaint
- next
- end
- end
- # Wish
- for i in priority
- next if i.isFainted?
- if i.effects[PBEffects::Wish]>0
- i.effects[PBEffects::Wish]-=1
- if i.effects[PBEffects::Wish]==0
- hpgain=i.pbRecoverHP(i.effects[PBEffects::WishAmount],true)
- if hpgain>0
- wishmaker=pbThisEx(i.index,i.effects[PBEffects::WishMaker])
- pbDisplay(_INTL("{1}'s wish came true!",wishmaker))
- end
- end
- end
- end
- # Fire Pledge + Grass Pledge combination damage - should go here
- for i in priority
- next if i.isFainted?
- # Shed Skin
- if i.hasWorkingAbility(:SHEDSKIN)
- if pbRandom(10)<3 && i.status>0
- case i.status
- when PBStatuses::SLEEP
- pbDisplay(_INTL("{1}'s Shed Skin cured its sleep problem!",i.pbThis))
- when PBStatuses::FROZEN
- pbDisplay(_INTL("{1}'s Shed Skin cured its ice problem!",i.pbThis))
- when PBStatuses::BURN
- pbDisplay(_INTL("{1}'s Shed Skin cured its burn problem!",i.pbThis))
- when PBStatuses::POISON
- pbDisplay(_INTL("{1}'s Shed Skin cured its poison problem!",i.pbThis))
- when PBStatuses::PARALYSIS
- pbDisplay(_INTL("{1}'s Shed Skin cured its paralysis problem!",i.pbThis))
- end
- i.status=0
- i.statusCount=0
- end
- end
- # Hydration
- if i.hasWorkingAbility(:HYDRATION) && (pbWeather==PBWeather::RAINDANCE ||
- $fefieldeffect == 21 || $fefieldeffect == 22)
- if i.status>0
- case i.status
- when PBStatuses::SLEEP
- pbDisplay(_INTL("{1}'s Hydration cured its sleep problem!",i.pbThis))
- when PBStatuses::FROZEN
- pbDisplay(_INTL("{1}'s Hydration cured its ice problem!",i.pbThis))
- when PBStatuses::BURN
- pbDisplay(_INTL("{1}'s Hydration cured its burn problem!",i.pbThis))
- when PBStatuses::POISON
- pbDisplay(_INTL("{1}'s Hydration cured its poison problem!",i.pbThis))
- when PBStatuses::PARALYSIS
- pbDisplay(_INTL("{1}'s Hydration cured its paralysis problem!",i.pbThis))
- end
- i.status=0
- i.statusCount=0
- end
- end
- if i.hasWorkingAbility(:WATERVEIL) && ($fefieldeffect == 21 ||
- $fefieldeffect == 22)
- if i.status>0
- pbDisplay(_INTL("{1}'s Water Veil cured its status problem!",i.pbThis))
- i.status=0
- i.statusCount=0
- end
- end
- # Healer
- if i.hasWorkingAbility(:HEALER)
- partner=i.pbPartner
- if partner
- if pbRandom(10)<3 && partner.status>0
- case partner.status
- when PBStatuses::SLEEP
- pbDisplay(_INTL("{1}'s Healer cured its partner's sleep problem!",i.pbThis))
- when PBStatuses::FROZEN
- pbDisplay(_INTL("{1}'s Healer cured its partner's ice problem!",i.pbThis))
- when PBStatuses::BURN
- pbDisplay(_INTL("{1}'s Healer cured its partner's burn problem!",i.pbThis))
- when PBStatuses::POISON
- pbDisplay(_INTL("{1}'s Healer cured its partner's poison problem!",i.pbThis))
- when PBStatuses::PARALYSIS
- pbDisplay(_INTL("{1}'s Healer cured its partner's paralysis problem!",i.pbThis))
- end
- partner.status=0
- partner.statusCount=0
- end
- end
- end
- end
- # Held berries/Leftovers/Black Sludge
- for i in priority
- next if i.isFainted?
- i.pbBerryCureCheck(true)
- if i.isFainted?
- return if !i.pbFaint
- next
- end
- end
- # Aqua Ring
- for i in priority
- next if i.hp<=0
- if i.effects[PBEffects::AquaRing]
- if $fefieldeffect == 11 &&
- !i.pbHasType?(:STEEL) && !i.pbHasType?(:POISON)
- @scene.pbDamageAnimation(i,0)
- i.pbReduceHP((i.totalhp/16).floor)
- pbDisplay(_INTL("{1}'s Aqua Ring absorbed poison!",i.pbThis)) if hpgain>0
- if i.hp<=0
- return if !i.pbFaint
- end
- elsif i.effects[PBEffects::HealBlock]==0
- hpgain=(i.totalhp/16).floor
- hpgain=(hpgain*1.3).floor if isConst?(i.item,PBItems,:BIGROOT)
- hpgain=(hpgain*2).floor if $fefieldeffect == 3 ||
- $fefieldeffect == 8 || $fefieldeffect == 21 || $fefieldeffect == 22
- hpgain=i.pbRecoverHP(hpgain,true)
- pbDisplay(_INTL("{1}'s Aqua Ring restored its HP a little!",i.pbThis)) if hpgain>0
- end
- end
- end
- # Ingrain
- for i in priority
- next if i.hp<=0
- if i.effects[PBEffects::Ingrain]
- if ($fefieldeffect == 8 || $fefieldeffect == 10) &&
- (!i.pbHasType?(:STEEL) && !i.pbHasType?(:POISON))
- @scene.pbDamageAnimation(i,0)
- i.pbReduceHP((i.totalhp/16).floor)
- pbDisplay(_INTL("{1} absorbed foul nutrients with its roots!",i.pbThis))
- if i.hp<=0
- return if !i.pbFaint
- end
- else
- if ($fefieldeffect == 33 && $fecounter >2)
- hpgain=(i.totalhp/4).floor
- elsif ($fefieldeffect == 15 || ($fefieldeffect == 33 && $fecounter >0))
- hpgain=(i.totalhp/8).floor
- elsif i.effects[PBEffects::HealBlock]==0
- hpgain=(i.totalhp/16).floor
- end
- if i.effects[PBEffects::HealBlock]==0
- hpgain=(hpgain*1.3).floor if isConst?(i.item,PBItems,:BIGROOT)
- hpgain=i.pbRecoverHP(hpgain,true)
- pbDisplay(_INTL("{1} absorbed nutrients with its roots!",i.pbThis)) if hpgain>0
- end
- end
- end
- end
- # Leech Seed
- for i in priority
- if i.hasWorkingAbility(:LIQUIDOOZE,true) && i.effects[PBEffects::LeechSeed]>=0
- recipient=@battlers[i.effects[PBEffects::LeechSeed]]
- if recipient && !recipient.isFainted?
- hploss=(i.totalhp/8).floor
- hploss= hploss * 2 if $fefieldeffect == 19
- pbCommonAnimation("LeechSeed",recipient,i)
- i.pbReduceHP(hploss,true)
- hploss= hploss / 2 if $fefieldeffect == 19 || $fefieldeffect == 26
- recipient.pbReduceHP(hploss,true)
- pbDisplay(_INTL("{1} sucked up the liquid ooze!",recipient.pbThis))
- if i.isFainted?
- return if !i.pbFaint
- end
- if recipient.isFainted?
- return if !recipient.pbFaint
- end
- next
- end
- end
- next if i.isFainted?
- if i.effects[PBEffects::LeechSeed]>=0
- recipient=@battlers[i.effects[PBEffects::LeechSeed]]
- if recipient && !recipient.isFainted? &&
- !i.hasWorkingAbility(:MAGICGUARD) # if recipient exists
- pbCommonAnimation("LeechSeed",recipient,i)
- hploss=i.pbReduceHP((i.totalhp/8).floor,true)
- hploss= hploss * 2 if $fefieldeffect == 19
- # if i.hasWorkingAbility(:LIQUIDOOZE)
- # recipient.pbReduceHP(hploss,true)
- # pbDisplay(_INTL("{1} sucked up the liquid ooze!",recipient.pbThis))
- # hploss= hploss / 2 if $fefieldeffect == 19 || $fefieldeffect == 26
- if recipient.effects[PBEffects::HealBlock]==0
- hploss=(hploss*1.3).floor if recipient.hasWorkingItem(:BIGROOT)
- recipient.pbRecoverHP(hploss,true)
- pbDisplay(_INTL("{1}'s health was sapped by Leech Seed!",i.pbThis))
- end
- if i.isFainted?
- return if !i.pbFaint
- end
- if recipient.isFainted?
- return if !recipient.pbFaint
- end
- end
- end
- end
- for i in priority
- next if i.isFainted?
- # Poison/Bad poison
- if i.status==PBStatuses::POISON &&
- !i.hasWorkingAbility(:MAGICGUARD)
- if i.hasWorkingAbility(:POISONHEAL)
- if i.effects[PBEffects::HealBlock]==0
- if i.hp<i.totalhp
- pbCommonAnimation("Poison",i,nil)
- i.pbRecoverHP((i.totalhp/8).floor,true)
- pbDisplay(_INTL("{1} is healed by poison!",i.pbThis))
- end
- if i.statusCount>0
- i.effects[PBEffects::Toxic]+=1
- i.effects[PBEffects::Toxic]=[15,i.effects[PBEffects::Toxic]].min
- end
- end
- else
- i.pbContinueStatus
- if i.statusCount==0
- i.pbReduceHP((i.totalhp/8).floor)
- else
- i.effects[PBEffects::Toxic]+=1
- i.effects[PBEffects::Toxic]=[15,i.effects[PBEffects::Toxic]].min
- i.pbReduceHP((i.totalhp/16).floor*i.effects[PBEffects::Toxic])
- end
- end
- end
- # Burn
- if i.status==PBStatuses::BURN &&
- !i.hasWorkingAbility(:MAGICGUARD)
- i.pbContinueStatus
- if i.hasWorkingAbility(:HEATPROOF) || $fefieldeffect == 13
- i.pbReduceHP((i.totalhp/16).floor)
- else
- i.pbReduceHP((i.totalhp/8).floor)
- end
- end
- # Nightmare
- if i.effects[PBEffects::Nightmare] &&
- !i.hasWorkingAbility(:MAGICGUARD) &&
- $fefieldeffect != 9
- if i.status==PBStatuses::SLEEP
- pbCommonAnimation("Nightmare",i,nil)
- pbDisplay(_INTL("{1} is locked in a nightmare!",i.pbThis))
- i.pbReduceHP((i.totalhp/4).floor,true)
- else
- i.effects[PBEffects::Nightmare]=false
- end
- end
- if i.isFainted?
- return if !i.pbFaint
- next
- end
- end
- # Curse
- for i in priority
- next if i.isFainted?
- if $fefieldeffect == 29 && i.effects[PBEffects::Curse]
- i.effects[PBEffects::Curse] = false
- pbDisplay(_INTL("{1}'s curse was lifted!",i.pbThis))
- end
- if i.effects[PBEffects::Curse] &&
- !i.hasWorkingAbility(:MAGICGUARD)
- pbCommonAnimation("Curse",i,nil)
- pbDisplay(_INTL("{1} is afflicted by the curse!",i.pbThis))
- i.pbReduceHP((i.totalhp/4).floor,true)
- end
- if i.isFainted?
- return if !i.pbFaint
- next
- end
- end
- # Multi-turn attacks (Bind/Clamp/Fire Spin/Magma Storm/Sand Tomb/Whirlpool/Wrap)
- for i in priority
- next if i.isFainted?
- if i.effects[PBEffects::MultiTurn]>0
- i.effects[PBEffects::MultiTurn]-=1
- movename=PBMoves.getName(i.effects[PBEffects::MultiTurnAttack])
- if i.effects[PBEffects::MultiTurn]==0
- pbDisplay(_INTL("{1} was freed from {2}!",i.pbThis,movename))
- $bindingband=0
- else
- pbDisplay(_INTL("{1} is hurt by {2}!",i.pbThis,movename))
- if isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:BIND)
- pbCommonAnimation("Bind",i,nil)
- elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:CLAMP)
- pbCommonAnimation("Clamp",i,nil)
- elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:FIRESPIN)
- pbCommonAnimation("FireSpin",i,nil)
- elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:MAGMASTORM)
- pbCommonAnimation("MagmaStorm",i,nil)
- elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:SANDTOMB)
- pbCommonAnimation("SandTomb",i,nil)
- elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:WRAP)
- pbCommonAnimation("Wrap",i,nil)
- elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:INFESTATION)
- pbCommonAnimation("Infestation",i,nil)
- elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:WHIRLPOOL)
- pbCommonAnimation("Whirlpool",i,nil)
- else
- pbCommonAnimation("Wrap",i,nil)
- end
- @scene.pbDamageAnimation(i,0)
- if $bindingband==1
- i.pbReduceHP((i.totalhp/6).floor)
- elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:MAGMASTORM) &&
- $fefieldeffect == 32
- i.pbReduceHP((i.totalhp/6).floor)
- elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:SANDTOMB) &&
- $fefieldeffect == 12
- i.pbReduceHP((i.totalhp/6).floor)
- elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:WHIRLPOOL) &&
- ($fefieldeffect == 21 || $fefieldeffect == 22)
- i.pbReduceHP((i.totalhp/6).floor)
- elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:INFESTATION) &&
- $fefieldeffect == 15
- i.pbReduceHP((i.totalhp/6).floor)
- elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:INFESTATION) &&
- $fefieldeffect == 33 && $fecounter > 1
- case $fecounter
- when 2
- i.pbReduceHP((i.totalhp/6).floor)
- when 3
- i.pbReduceHP((i.totalhp/4).floor)
- when 4
- i.pbReduceHP((i.totalhp/3).floor)
- end
- else
- i.pbReduceHP((i.totalhp/8).floor)
- end
- if isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:SANDTOMB) &&
- $fefieldeffect == 20
- i.pbCanReduceStatStage?(PBStats::ACCURACY)
- i.pbReduceStat(PBStats::ACCURACY,1,true)
- end
- end
- end
- if i.hp<=0
- return if !i.pbFaint
- next
- end
- end
- # Taunt
- for i in priority
- next if i.isFainted?
- if i.effects[PBEffects::Taunt]>0
- i.effects[PBEffects::Taunt]-=1
- if i.effects[PBEffects::Taunt]==0
- pbDisplay(_INTL("{1} recovered from the taunting!",i.pbThis))
- end
- end
- end
- # Encore
- for i in priority
- next if i.isFainted?
- if i.effects[PBEffects::Encore]>0
- if i.moves[i.effects[PBEffects::EncoreIndex]].id!=i.effects[PBEffects::EncoreMove]
- i.effects[PBEffects::Encore]=0
- i.effects[PBEffects::EncoreIndex]=0
- i.effects[PBEffects::EncoreMove]=0
- else
- i.effects[PBEffects::Encore]-=1
- if i.effects[PBEffects::Encore]==0 || i.moves[i.effects[PBEffects::EncoreIndex]].pp==0
- i.effects[PBEffects::Encore]=0
- pbDisplay(_INTL("{1}'s encore ended!",i.pbThis))
- end
- end
- end
- end
- # Disable/Cursed Body
- for i in priority
- next if i.isFainted?
- if i.effects[PBEffects::Disable]>0
- i.effects[PBEffects::Disable]-=1
- if i.effects[PBEffects::Disable]==0
- i.effects[PBEffects::DisableMove]=0
- pbDisplay(_INTL("{1} is disabled no more!",i.pbThis))
- end
- end
- end
- # Magnet Rise
- for i in priority
- next if i.isFainted?
- if i.effects[PBEffects::MagnetRise]>0
- i.effects[PBEffects::MagnetRise]-=1
- if i.effects[PBEffects::MagnetRise]==0
- pbDisplay(_INTL("{1} stopped levitating.",i.pbThis))
- end
- end
- end
- # Telekinesis
- for i in priority
- next if i.isFainted?
- if i.effects[PBEffects::Telekinesis]>0
- i.effects[PBEffects::Telekinesis]-=1
- if i.effects[PBEffects::Telekinesis]==0
- pbDisplay(_INTL("{1} stopped levitating.",i.pbThis))
- end
- end
- end
- # Heal Block
- for i in priority
- next if i.isFainted?
- if i.effects[PBEffects::HealBlock]>0
- i.effects[PBEffects::HealBlock]-=1
- if i.effects[PBEffects::HealBlock]==0
- pbDisplay(_INTL("The heal block on {1} ended.",i.pbThis))
- end
- end
- end
- # Embargo
- for i in priority
- next if i.isFainted?
- if i.effects[PBEffects::Embargo]>0
- i.effects[PBEffects::Embargo]-=1
- if i.effects[PBEffects::Embargo]==0
- pbDisplay(_INTL("The embargo on {1} was lifted.",i.pbThis(true)))
- end
- end
- end
- # Yawn
- for i in priority
- next if i.isFainted?
- if i.effects[PBEffects::Yawn]>0
- i.effects[PBEffects::Yawn]-=1
- if i.effects[PBEffects::Yawn]==0 && i.pbCanSleepYawn?
- i.pbSleep
- pbDisplay(_INTL("{1} fell asleep!",i.pbThis))
- end
- end
- end
- # Perish Song
- perishSongUsers=[]
- for i in priority
- next if i.isFainted?
- if i.effects[PBEffects::PerishSong]>0
- i.effects[PBEffects::PerishSong]-=1
- pbDisplay(_INTL("{1}'s Perish count fell to {2}!",i.pbThis,i.effects[PBEffects::PerishSong]))
- if i.effects[PBEffects::PerishSong]==0
- perishSongUsers.push(i.effects[PBEffects::PerishSongUser])
- i.pbReduceHP(i.hp,true)
- end
- end
- if i.isFainted?
- return if !i.pbFaint
- end
- end
- if perishSongUsers.length>0
- # If all remaining Pokemon fainted by a Perish Song triggered by a single side
- if (perishSongUsers.find_all{|item| pbIsOpposing?(item) }.length==perishSongUsers.length) ||
- (perishSongUsers.find_all{|item| !pbIsOpposing?(item) }.length==perishSongUsers.length)
- pbJudgeCheckpoint(@battlers[perishSongUsers[0]])
- end
- end
- if @decision>0
- pbGainEXP
- return
- end
- # Reflect
- for i in 0...2
- if sides[i].effects[PBEffects::Reflect]>0
- sides[i].effects[PBEffects::Reflect]-=1
- if sides[i].effects[PBEffects::Reflect]==0
- pbDisplay(_INTL("Your team's Reflect faded!")) if i==0
- pbDisplay(_INTL("The opposing team's Reflect faded!")) if i==1
- end
- end
- end
- # Light Screen
- for i in 0...2
- if sides[i].effects[PBEffects::LightScreen]>0
- sides[i].effects[PBEffects::LightScreen]-=1
- if sides[i].effects[PBEffects::LightScreen]==0
- pbDisplay(_INTL("Your team's Light Screen faded!")) if i==0
- pbDisplay(_INTL("The opposing team's Light Screen faded!")) if i==1
- end
- end
- end
- # Safeguard
- for i in 0...2
- if sides[i].effects[PBEffects::Safeguard]>0
- sides[i].effects[PBEffects::Safeguard]-=1
- if sides[i].effects[PBEffects::Safeguard]==0
- pbDisplay(_INTL("Your team is no longer protected by Safeguard!")) if i==0
- pbDisplay(_INTL("The opposing team is no longer protected by Safeguard!")) if i==1
- end
- end
- end
- # Mist
- for i in 0...2
- if sides[i].effects[PBEffects::Mist]>0
- sides[i].effects[PBEffects::Mist]-=1
- if sides[i].effects[PBEffects::Mist]==0
- pbDisplay(_INTL("Your team's Mist faded!")) if i==0
- pbDisplay(_INTL("The opposing team's Mist faded!")) if i==1
- end
- end
- end
- # Tailwind
- for i in 0...2
- if sides[i].effects[PBEffects::Tailwind]>0
- sides[i].effects[PBEffects::Tailwind]-=1
- if sides[i].effects[PBEffects::Tailwind]==0
- pbDisplay(_INTL("Your team's tailwind stopped blowing!")) if i==0
- pbDisplay(_INTL("The opposing team's tailwind stopped blowing!")) if i==1
- end
- end
- end
- # Lucky Chant
- for i in 0...2
- if sides[i].effects[PBEffects::LuckyChant]>0
- sides[i].effects[PBEffects::LuckyChant]-=1
- if sides[i].effects[PBEffects::LuckyChant]==0
- pbDisplay(_INTL("Your team's Lucky Chant faded!")) if i==0
- pbDisplay(_INTL("The opposing team's Lucky Chant faded!")) if i==1
- end
- end
- end
- # Mud Sport
- if @field.effects[PBEffects::MudSport]>0
- @field.effects[PBEffects::MudSport]-=1
- if @field.effects[PBEffects::MudSport]==0
- pbDisplay(_INTL("The effects of Mud Sport faded."))
- end
- end
- # Water Sport
- if @field.effects[PBEffects::WaterSport]>0
- @field.effects[PBEffects::WaterSport]-=1
- if @field.effects[PBEffects::WaterSport]==0
- pbDisplay(_INTL("The effects of Water Sport faded."))
- end
- end
- # Gravity
- if @field.effects[PBEffects::Gravity]>0
- @field.effects[PBEffects::Gravity]-=1
- if @field.effects[PBEffects::Gravity]==0
- pbDisplay(_INTL("Gravity returned to normal."))
- if $febackup == 35 && $fefieldeffect != 35
- $fefieldeffect = $febackup
- pbDisplay(_INTL("The world broke apart again!"))
- pbChangeBGSprite
- end
- end
- end
- # Terrain
- if @field.effects[PBEffects::Terrain]>0
- terrain=[@field.effects[PBEffects::Terrain]].max
- terrain-=1
- @field.effects[PBEffects::Terrain] = terrain
- if terrain==0
- $fefieldeffect = $febackup
- pbDisplay(_INTL("The terrain returned to normal."))
- pbChangeBGSprite
- end
- end
- # Trick Room - should go here
- # Wonder Room - should go here
- # Magic Room
- if @field.effects[PBEffects::MagicRoom]>0
- @field.effects[PBEffects::MagicRoom]-=1
- if @field.effects[PBEffects::MagicRoom]==0
- pbDisplay(_INTL("The area returned to normal."))
- end
- end
- # Fairy Lock
- if @field.effects[PBEffects::FairyLock]>0
- @field.effects[PBEffects::FairyLock]-=1
- if @field.effects[PBEffects::FairyLock]==0
- # Fairy Lock seems to have no end-of-effect text so I've added some.
- pbDisplay(_INTL("The Fairy Lock was released."))
- end
- end
- # Uproar
- for i in priority
- next if i.isFainted?
- if i.effects[PBEffects::Uproar]>0
- for j in priority
- if !j.isFainted? && j.status==PBStatuses::SLEEP && !j.hasWorkingAbility(:SOUNDPROOF)
- j.effects[PBEffects::Nightmare]=false
- j.status=0
- j.statusCount=0
- pbDisplay(_INTL("{1} woke up in the uproar!",j.pbThis))
- end
- end
- i.effects[PBEffects::Uproar]-=1
- if i.effects[PBEffects::Uproar]==0
- pbDisplay(_INTL("{1} calmed down.",i.pbThis))
- else
- pbDisplay(_INTL("{1} is making an uproar!",i.pbThis))
- end
- end
- end
- #Wasteland hazard interaction
- if $fefieldeffect == 19
- for i in priority
- next if i.isFainted?
- # SR
- if i.pbOwnSide.effects[PBEffects::StealthRock]==true
- pbDisplay(_INTL("The waste swallowed up the pointed stones!"))
- i.pbOwnSide.effects[PBEffects::StealthRock]=false
- pbDisplay(_INTL("...Rocks spewed out from the ground below!"))
- atype=getConst(PBTypes,:ROCK) || 0
- if !i.isFainted?
- eff=PBTypes.getCombinedEffectiveness(atype,i.type1,i.type2)
- if eff>0
- @scene.pbDamageAnimation(i,0)
- i.pbReduceHP([(i.totalhp*eff/16).floor,1].max)
- end
- end
- partner=i.pbPartner
- if partner && !partner.isFainted?
- eff=PBTypes.getCombinedEffectiveness(atype,partner.type1,partner.type2)
- if eff>0
- @scene.pbDamageAnimation(partner,0)
- partner.pbReduceHP([(partner.totalhp*eff/16).floor,1].max)
- end
- end
- end
- # Spikes
- if i.pbOwnSide.effects[PBEffects::Spikes]>0
- pbDisplay(_INTL("The waste swallowed up the spikes!"))
- i.pbOwnSide.effects[PBEffects::Spikes]=0
- pbDisplay(_INTL("...Stalagmites burst up from the ground!"))
- if !i.isFainted? && !i.isAirborne?
- @scene.pbDamageAnimation(i,0)
- i.pbReduceHP([(i.totalhp/3).floor,1].max)
- end
- partner=i.pbPartner
- if partner && !partner.isFainted?
- if !partner.isAirborne?
- @scene.pbDamageAnimation(partner,0)
- partner.pbReduceHP([(partner.totalhp/3).floor,1].max)
- end
- end
- end
- # TSpikes
- if i.pbOwnSide.effects[PBEffects::ToxicSpikes]>0
- pbDisplay(_INTL("The waste swallowed up the toxic spikes!"))
- i.pbOwnSide.effects[PBEffects::ToxicSpikes]=0
- pbDisplay(_INTL("...Poison needles shot up from the ground!"))
- if !i.isFainted? && !i.isAirborne? &&
- !i.pbHasType?(:STEEL) && !i.pbHasType?(:POISON)
- @scene.pbDamageAnimation(i,0)
- i.pbReduceHP([(i.totalhp/8).floor,1].max)
- if i.status==0 && i.pbCanPoison?(false)
- i.status=PBStatuses::POISON
- i.statusCount=1
- i.effects[PBEffects::Toxic]=0
- pbCommonAnimation("Poison",i,nil)
- end
- end
- partner=i.pbPartner
- if partner && !partner.isFainted?
- if !partner.isAirborne? &&
- !partner.pbHasType?(:STEEL) && !partner.pbHasType?(:POISON)
- @scene.pbDamageAnimation(partner,0)
- partner.pbReduceHP([(partner.totalhp/8).floor,1].max)
- if partner.status==0 && partner.pbCanPoison?(false)
- partner.status=PBStatuses::POISON
- partner.statusCount=1
- partner.effects[PBEffects::Toxic]=0
- pbCommonAnimation("Poison",i,nil)
- end
- end
- end
- end
- # StickyWeb
- if i.pbOwnSide.effects[PBEffects::StickyWeb]
- pbDisplay(_INTL("The waste swallowed up the sticky web!"))
- i.pbOwnSide.effects[PBEffects::StickyWeb]=false
- pbDisplay(_INTL("...Sticky string shot out of the ground!"))
- if !i.isFainted?
- if !i.pbTooLow?(PBStats::SPEED)
- i.pbReduceStatBasic(PBStats::SPEED,4)
- pbCommonAnimation("StatDown",i,nil)
- pbDisplay(_INTL("{1}'s Speed was severely lowered!",i.pbThis))
- end
- end
- partner=i.pbPartner
- if partner && !partner.isFainted?
- if !partner.pbTooLow?(PBStats::SPEED)
- partner.pbReduceStatBasic(PBStats::SPEED,4)
- pbCommonAnimation("StatDown",partner,nil)
- pbDisplay(_INTL("{1}'s Speed was severely lowered!",partner.pbThis))
- end
- end
- end
- if i.hp<=0
- return if !i.pbFaint
- next
- end
- end
- end
- # End Wasteland hazards
- for i in priority
- next if i.isFainted?
- # Speed Boost
- # A Pokémon's turncount is 0 if it became active after the beginning of a round
- if i.turncount>0 && i.hasWorkingAbility(:SPEEDBOOST)
- if !i.pbTooHigh?(PBStats::SPEED)
- i.pbIncreaseStatBasic(PBStats::SPEED,1)
- pbCommonAnimation("StatUp",i,nil)
- pbDisplay(_INTL("{1}'s Speed Boost raised its Speed!",i.pbThis))
- end
- end
- if i.turncount>0 && $fefieldeffect == 8 && # Swamp Field
- !isConst?(i.ability,PBAbilities,:WHITESMOKE) &&
- !isConst?(i.ability,PBAbilities,:CLEARBODY) &&
- !isConst?(i.ability,PBAbilities,:QUICKFEET) &&
- !isConst?(i.ability,PBAbilities,:SWIFTSWIM)
- if !i.isAirborne?
- if !i.pbTooLow?(PBStats::SPEED)
- i.pbReduceStatBasic(PBStats::SPEED,1)
- pbCommonAnimation("StatDown",i,nil)
- pbDisplay(_INTL("{1}'s Speed sank...",i.pbThis))
- end
- end
- end
- #sleepyswamp
- if i.status==PBStatuses::SLEEP && !isConst?(i.ability,PBAbilities,:MAGICGUARD)
- if $fefieldeffect == 8 # Swamp Field
- hploss=i.pbReduceHP((i.totalhp/16).floor,true)
- pbDisplay(_INTL("{1}'s strength is sapped by the swamp!",i.pbThis)) if hploss>0
- end
- end
- if i.hp<=0
- return if !i.pbFaint
- next
- end
- #sleepyrainbow
- if i.status==PBStatuses::SLEEP
- if $fefieldeffect == 9 && i.effects[PBEffects::HealBlock]==0#Rainbow Field
- hpgain=(i.totalhp/16).floor
- hpgain=(hpgain*1.3).floor if isConst?(i.item,PBItems,:BIGROOT)
- hpgain=i.pbRecoverHP(hpgain,true)
- pbDisplay(_INTL("{1} recovered health in its peaceful sleep!",i.pbThis))
- end
- end
- #sleepycorro
- if i.status==PBStatuses::SLEEP && i.hasWorkingAbility(:MAGICGUARD) &&
- !i.hasWorkingAbility(:POISONHEAL) && !i.hasWorkingAbility(:TOXICBOOST) &&
- !i.hasWorkingAbility(:WONDERGUARD) &&
- !i.pbHasType?(:STEEL) && !i.pbHasType?(:POISON) &&
- $fefieldeffect == 10 # Corrosive Field
- hploss=i.pbReduceHP((i.totalhp/16).floor,true)
- pbDisplay(_INTL("{1}'s is seared by the corrosion!",i.pbThis)) if hploss>0
- end
- if i.hp<=0
- return if !i.pbFaint
- next
- end
- # Bad Dreams
- if i.status==PBStatuses::SLEEP && !isConst?(i.ability,PBAbilities,:MAGICGUARD) &&
- $fefieldeffect != 9
- if i.pbOpposing1.hasWorkingAbility(:BADDREAMS) ||
- i.pbOpposing2.hasWorkingAbility(:BADDREAMS)
- hploss=i.pbReduceHP((i.totalhp/8).floor,true)
- pbDisplay(_INTL("{1} is having a bad dream!",i.pbThis)) if hploss>0
- end
- end
- if i.isFainted?
- return if !i.pbFaint
- next
- end
- # Harvest
- if i.hasWorkingAbility(:HARVEST) && i.item<=0 && i.pokemon.itemRecycle>0 #if an item was recycled, check
- if pbIsBerry?(i.pokemon.itemRecycle) && (rand(100)>50 ||
- pbWeather==PBWeather::SUNNYDAY || ($fefieldeffect == 33 && $fecounter>0))
- i.item=i.pokemon.itemRecycle
- i.pokemon.itemInitial=i.pokemon.itemRecycle
- i.pokemon.itemRecycle=0
- firstberryletter=PBItems.getName(i.item).split(//).first
- if firstberryletter=="A" || firstberryletter=="E" || firstberryletter=="I" ||
- firstberryletter=="O" || firstberryletter=="U"
- pbDisplay(_INTL("{1} harvested an {2}!",i.pbThis,PBItems.getName(i.item)))
- else
- pbDisplay(_INTL("{1} harvested a {2}!",i.pbThis,PBItems.getName(i.item)))
- end
- i.pbBerryCureCheck(true)
- end
- end
- # Moody
- if i.hasWorkingAbility(:CLOUDNINE) && $fefieldeffect == 9
- failsafe=0
- randoms=[]
- loop do
- failsafe+=1
- break if failsafe==1000
- rand=1+self.pbRandom(7)
- if !i.pbTooHigh?(rand)
- randoms.push(rand)
- break
- end
- end
- statnames=[_INTL("Attack"),_INTL("Defense"),_INTL("Speed"),_INTL("Special Attack"),
- _INTL("Special Defense"),_INTL("accuracy"),_INTL("evasiveness")]
- if failsafe!=1000
- i.stages[randoms[0]]+=1
- i.stages[randoms[0]]=6 if i.stages[randoms[0]]>6
- pbCommonAnimation("StatUp",i,nil)
- pbDisplay(_INTL("{1}'s Cloud Nine raised its {2}!",i.pbThis,statnames[randoms[0]-1]))
- end
- end
- if i.hasWorkingAbility(:MOODY)
- randomup=[]
- randomdown=[]
- failsafe1=0
- failsafe2=0
- loop do
- failsafe1+=1
- break if failsafe1==1000
- rand=1+self.pbRandom(7)
- if !i.pbTooHigh?(rand)
- randomup.push(rand)
- break
- end
- end
- loop do
- failsafe2+=1
- break if failsafe2==1000
- rand=1+self.pbRandom(7)
- if !i.pbTooLow?(rand) && rand!=randomup[0]
- randomdown.push(rand)
- break
- end
- end
- statnames=[_INTL("Attack"),_INTL("Defense"),_INTL("Speed"),_INTL("Special Attack"),
- _INTL("Special Defense"),_INTL("accuracy"),_INTL("evasiveness")]
- if failsafe1!=1000
- i.stages[randomup[0]]+=2
- i.stages[randomup[0]]=6 if i.stages[randomup[0]]>6
- pbCommonAnimation("StatUp",i,nil)
- pbDisplay(_INTL("{1}'s Moody sharply raised its {2}!",i.pbThis,statnames[randomup[0]-1]))
- end
- if failsafe2!=1000
- i.stages[randomdown[0]]-=1
- pbCommonAnimation("StatDown",i,nil)
- pbDisplay(_INTL("{1}'s Moody lowered its {2}!",i.pbThis,statnames[randomdown[0]-1]))
- end
- end
- end
- for i in priority
- next if i.isFainted?
- # Toxic Orb
- if i.hasWorkingItem(:TOXICORB) && i.status==0 && i.pbCanPoison?(false)
- i.status=PBStatuses::POISON
- i.statusCount=1
- i.effects[PBEffects::Toxic]=0
- pbCommonAnimation("Poison",i,nil)
- pbDisplay(_INTL("{1} was poisoned by its {2}!",i.pbThis,PBItems.getName(i.item)))
- end
- # Flame Orb
- if i.hasWorkingItem(:FLAMEORB) && i.status==0 && i.pbCanBurn?(false)
- i.status=PBStatuses::BURN
- i.statusCount=0
- pbCommonAnimation("Burn",i,nil)
- pbDisplay(_INTL("{1} was burned by its {2}!",i.pbThis,PBItems.getName(i.item)))
- end
- # Sticky Barb
- if i.hasWorkingItem(:STICKYBARB) && !i.hasWorkingAbility(:MAGICGUARD)
- pbDisplay(_INTL("{1} is hurt by its {2}!",i.pbThis,PBItems.getName(i.item)))
- @scene.pbDamageAnimation(i,0)
- i.pbReduceHP((i.totalhp/8).floor)
- end
- if i.isFainted?
- return if !i.pbFaint
- next
- end
- end
- # Form checks
- for i in 0...4
- next if @battlers[i].isFainted?
- @battlers[i].pbCheckForm
- end
- pbGainEXP
- ##### KUROTSUNE - 009 - START
- # Checks if a pokemon on either side has fainted on this turn
- # for retaliate
- player = priority[0]
- opponent = priority[1]
- if player.isFainted? ||
- (@doublebattle && player.pbPartner.isFainted?)
- player.pbOwnSide.effects[PBEffects::Retaliate] = true
- else
- # No pokemon has fainted in this side this turn
- player.pbOwnSide.effects[PBEffects::Retaliate] = false
- end
- if opponent.isFainted? ||
- (@doublebattle && player.pbPartner.isFainted?)
- opponent.pbOwnSide.effects[PBEffects::Retaliate] = true
- else
- opponent.pbOwnSide.effects[PBEffects::Retaliate] = false
- end
- ##### KUROTSUNE - 009 - END
- @faintswitch = true
- pbSwitch
- @faintswitch = false
- return if @decision>0
- for i in priority
- next if i.isFainted?
- i.pbAbilitiesOnSwitchIn(false)
- end
- # Healing Wish/Lunar Dance - should go here
- # Spikes/Toxic Spikes/Stealth Rock - should go here (in order of their 1st use)
- for i in 0...4
- if @battlers[i].turncount>0 && @battlers[i].hasWorkingAbility(:TRUANT)
- @battlers[i].effects[PBEffects::Truant]=!@battlers[i].effects[PBEffects::Truant]
- end
- if @battlers[i].effects[PBEffects::LockOn]>0 # Also Mind Reader
- @battlers[i].effects[PBEffects::LockOn]-=1
- @battlers[i].effects[PBEffects::LockOnPos]=-1 if @battlers[i].effects[PBEffects::LockOn]==0
- end
- @battlers[i].effects[PBEffects::Flinch]=false
- @battlers[i].effects[PBEffects::FollowMe]=false
- @battlers[i].effects[PBEffects::HelpingHand]=false
- @battlers[i].effects[PBEffects::MagicCoat]=false
- @battlers[i].effects[PBEffects::Snatch]=false
- #### KUROTSUNE - 024 - START
- @battlers[i].effects[PBEffects::Electrify]=false
- #### KUROTSUNE - 024 - END
- @battlers[i].effects[PBEffects::Charge]-=1 if @battlers[i].effects[PBEffects::Charge]>0
- @battlers[i].lastHPLost=0
- @battlers[i].lastAttacker=-1
- @battlers[i].effects[PBEffects::Counter]=-1
- @battlers[i].effects[PBEffects::CounterTarget]=-1
- @battlers[i].effects[PBEffects::MirrorCoat]=-1
- @battlers[i].effects[PBEffects::MirrorCoatTarget]=-1
- end
- # invalidate stored priority
- @usepriority=false
- end
- ################################################################################
- # End of battle.
- ################################################################################
- def pbEndOfBattle(canlose=false)
- case @decision
- ##### WIN #####
- when 1
- if @opponent
- @scene.pbTrainerBattleSuccess
- if @opponent.is_a?(Array)
- pbDisplayPaused(_INTL("{1} defeated {2} and {3}!",self.pbPlayer.name,@opponent[0].fullname,@opponent[1].fullname))
- else
- pbDisplayPaused(_INTL("{1} defeated\r\n{2}!",self.pbPlayer.name,@opponent.fullname))
- end
- @scene.pbShowOpponent(0)
- pbDisplayPaused(@endspeech.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
- if @opponent.is_a?(Array)
- @scene.pbHideOpponent
- @scene.pbShowOpponent(1)
- pbDisplayPaused(@endspeech2.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
- end
- # Calculate money gained for winning
- if @internalbattle
- tmoney=0
- if @opponent.is_a?(Array) # Double battles
- maxlevel1=0; maxlevel2=0; limit=pbSecondPartyBegin(1)
- for i in 0...limit
- if @party2[i]
- maxlevel1=@party2[i].level if maxlevel1<@party2[i].level
- end
- if @party2[i+limit]
- maxlevel2=@party2[i+limit].level if maxlevel1<@party2[i+limit].level
- end
- end
- tmoney+=maxlevel1*@opponent[0].moneyEarned
- tmoney+=maxlevel2*@opponent[1].moneyEarned
- else
- maxlevel=0
- for i in @party2
- next if !i
- maxlevel=i.level if maxlevel<i.level
- end
- tmoney+=maxlevel*@opponent.moneyEarned
- end
- # If Amulet Coin/Luck Incense's effect applies, double money earned
- badgemultiplier = [1,self.pbPlayer.numbadges].max
- tmoney*=badgemultiplier
- tmoney*=2 if @amuletcoin
- oldmoney=self.pbPlayer.money
- self.pbPlayer.money+=tmoney
- moneygained=self.pbPlayer.money-oldmoney
- if moneygained>0
- pbDisplayPaused(_INTL("{1} got ${2}\r\nfor winning!",self.pbPlayer.name,tmoney))
- end
- end
- end
- if @internalbattle && @extramoney>0
- @extramoney*=2 if @amuletcoin
- oldmoney=self.pbPlayer.money
- self.pbPlayer.money+=@extramoney
- moneygained=self.pbPlayer.money-oldmoney
- if moneygained>0
- pbDisplayPaused(_INTL("{1} picked up ${2}!",self.pbPlayer.name,@extramoney))
- end
- end
- for pkmn in @snaggedpokemon
- pbStorePokemon(pkmn)
- self.pbPlayer.shadowcaught=[] if !self.pbPlayer.shadowcaught
- self.pbPlayer.shadowcaught[pkmn.species]=true
- end
- @snaggedpokemon.clear
- ##### LOSE, DRAW #####
- when 2, 5
- if @internalbattle
- pbDisplayPaused(_INTL("{1} is out of usable Pokémon!",self.pbPlayer.name))
- moneylost=pbMaxLevelFromIndex(0)
- multiplier=[8,16,24,36,48,64,80,100,120,144,178,206,234,266,298,334,370,410,450,500] #Badge no. multiplier for money lost
- moneylost*=multiplier[[multiplier.length-1,self.pbPlayer.numbadges].min]
- moneylost=self.pbPlayer.money if moneylost>self.pbPlayer.money
- moneylost=0 if $game_switches[NO_MONEY_LOSS]
- self.pbPlayer.money-=moneylost
- if @opponent
- if @opponent.is_a?(Array)
- pbDisplayPaused(_INTL("{1} lost against {2} and {3}!",self.pbPlayer.name,@opponent[0].fullname,@opponent[1].fullname))
- else
- pbDisplayPaused(_INTL("{1} lost against\r\n{2}!",self.pbPlayer.name,@opponent.fullname))
- end
- if moneylost>0
- pbDisplayPaused(_INTL("{1} paid ${2}\r\nas the prize money...",self.pbPlayer.name,moneylost))
- pbDisplayPaused(_INTL("...")) if !canlose
- end
- else
- if moneylost>0
- pbDisplayPaused(_INTL("{1} panicked and lost\r\n${2}...",self.pbPlayer.name,moneylost))
- pbDisplayPaused(_INTL("...")) if !canlose
- end
- end
- pbDisplayPaused(_INTL("{1} blacked out!",self.pbPlayer.name)) if !canlose
- elsif @decision==2
- @scene.pbShowOpponent(0)
- pbDisplayPaused(@endspeechwin.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
- if @opponent.is_a?(Array)
- @scene.pbHideOpponent
- @scene.pbShowOpponent(1)
- pbDisplayPaused(@endspeechwin2.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
- end
- elsif @decision==5
- PBDebug.log("***[Draw game]") if $INTERNAL
- end
- end
- # Pass on Pokérus within the party
- infected=[]
- for i in 0...$Trainer.party.length
- if $Trainer.party[i].pokerusStage==1
- infected.push(i)
- end
- end
- if infected.length>=1
- for i in infected
- strain=$Trainer.party[i].pokerus/16
- if i>0 && $Trainer.party[i-1].pokerusStage==0
- $Trainer.party[i-1].givePokerus(strain) if rand(3)==0
- end
- if i<$Trainer.party.length-1 && $Trainer.party[i+1].pokerusStage==0
- $Trainer.party[i+1].givePokerus(strain) if rand(3)==0
- end
- end
- end
- @scene.pbEndBattle(@decision)
- for i in @battlers
- i.pbResetForm
- end
- for i in $Trainer.party
- i.setItem(i.itemInitial)
- i.itemInitial=i.itemRecycle=0
- end
- return @decision
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement