Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ################################################################################
- # 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 ||
- @battlers[idxPokemon].pbPartner.pokemonIndex==pkmnidxTo
- pbDisplayPaused(_INTL("{1} is already in battle!",party[pkmnidxTo].name)) if showMessages
- return false
- end
- if @skybattle && !pbCanSkyBattle?(party[pkmnidxTo])
- pbDisplayPaused(_INTL("{1} can't fight in a sky 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
- 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
- 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) && !(thispkmn.pbHasType?(:GHOST)))
- opp=opp2 if (opp2.hasWorkingAbility(:ARENATRAP) && !(thispkmn.pbHasType?(:GHOST)))
- end
- if !thispkmn.hasWorkingAbility(:SHADOWTAG)
- opp=opp1 if (opp1.hasWorkingAbility(:SHADOWTAG) && !(thispkmn.pbHasType?(:GHOST)))
- opp=opp2 if (opp2.hasWorkingAbility(:SHADOWTAG) && !(thispkmn.pbHasType?(:GHOST)))
- end
- if opp
- #pbDisplayEffect(opp)
- abilityname=PBAbilities.getName(opp.ability)
- if EFFECTMESSAGES
- pbDisplayPaused(_INTL("{1} can't be switched out!",thispkmn.pbThis))
- else
- pbDisplayPaused(_INTL("{1}'s {2} prevents switching!",opp.pbThis,abilityname)) if showMessages
- end
- 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 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)
- if pbIsOpposing?(index) #Temp Edit
- if isConst?(@party2[newenemy].f,PBAbilities,:ILLUSION) #ILLUSION
- party3=@party2.find_all {|item| item && !item.egg? && item.hp>0 }
- if party3[@party2.length-1] != @party2[newenemy]
- illusionpoke = party3[party3.length-1]
- end
- end #ILLUSION
- newname = illusionpoke != nil ? illusionpoke.name : @party2[newenemy].name #ILLUSION
- end #Temp Edit
- opponent=pbGetOwner(index)
- if !@doublebattle && firstbattlerhp>0 && @shiftStyle && @opponent &&
- @internalbattle && pbCanChooseNonActive?(0) && pbIsOpposing?(index) &&
- @battlers[0].effects[PBEffects::Outrage]==0
- pbDisplayPaused(_INTL("{1} is about to send in {2}.",opponent.fullname,newname)) #ILLUSION
- if pbDisplayConfirm(_INTL("Will you switch your Pokémon?"))
- newpoke=pbSwitchPlayer(0,true,true)
- if newpoke>=0
- pbDisplayBrief(_INTL("{1}, switch out! 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)
- @scene.pbTrainerSendOut(index,pokemon)
- else
- @scene.pbSendOut(index,pokemon)
- end
- @scene.pbResetMoveIndex(index)
- # Primal Reversion
- pbPrimalReversion(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
- if @weather==PBWeather::DELTASTREAM && !pbCheckGlobalAbility(:DELTASTREAM)
- @weather=0
- pbDisplayBrief("The air current faded.")
- elsif @weather==PBWeather::PRIMORDIALSEA && !pbCheckGlobalAbility(:PRIMORDIALSEA)
- @weather=0
- pbDisplayBrief("The heavy rain relented.")
- elsif @weather==PBWeather::DESOLATELAND && !pbCheckGlobalAbility(:DESOLATELAND)
- @weather=0
- pbDisplayBrief("The harsh sunlight faded.")
- end
- end
- def pbRecallAndReplace(index,newpoke,batonpass=false)
- @battlers[index].pbResetForm
- if !@battlers[index].isFainted?
- @scene.pbRecall(index)
- end
- pbMessagesOnReplace(index,newpoke)
- pbReplace(index,newpoke,batonpass)
- 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
- 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
- PBDebug.log("[Player sent out #{party[newpoke].name}]")
- 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
- 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 #ILLUSION
- owner=pbGetOwner(index)
- pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",owner.fullname,newname)) #ILLUSION
- PBDebug.log("[Opponent sent out #{party[newpoke].name}]")
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement