Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PokeBattle_FakeTrainer
- attr_accessor(:id)
- attr_accessor(:pokemon)
- def initialize(pokemon)
- @id=$Trainer.id
- @pokemon=pokemon
- end
- def name
- return @pokemon.name
- end
- def fullname
- return self.name
- end
- def language
- return $Trainer.language
- end
- def numbadges # Number of badges
- return 16
- end
- def gender
- return @pokemon.gender
- end
- def isMale?; return self.gender==0; end
- def isFemale?; return self.gender==1; end
- def party
- return [@pokemon]
- end
- def pokemonParty
- return self.party.find_all {|item| item && !item.isEgg? }
- end
- def ablePokemonParty
- return self.party.find_all {|item| item && !item.isEgg? && item.hp>0 }
- end
- def partyCount
- return self.party.length
- end
- def pokemonCount
- ret=0
- for i in 0...self.party.length
- ret+=1 if self.party[i] && !self.party[i].isEgg?
- end
- return ret
- end
- def ablePokemonCount
- ret=0
- for i in 0...self.party.length
- ret+=1 if self.party[i] && !self.party[i].isEgg? && self.party[i].hp>0
- end
- return ret
- end
- def firstParty
- return nil if self.party.length==0
- return self.party[0]
- end
- def firstPokemon
- p=self.pokemonParty
- return nil if p.length==0
- return p[0]
- end
- def firstAblePokemon
- p=self.ablePokemonParty
- return nil if p.length==0
- return p[0]
- end
- def lastParty
- return nil if self.party.length==0
- return self.party[@party.length-1]
- end
- def lastPokemon
- p=self.pokemonParty
- return nil if p.length==0
- return p[p.length-1]
- end
- def lastAblePokemon
- p=self.ablePokemonParty
- return nil if p.length==0
- return p[p.length-1]
- end
- def pokedexSeen(region=-1) # Number of Pokémon seen
- return $Trainer.pokedexSeen(region)
- end
- def pokedexOwned(region=-1) # Number of Pokémon owned
- return $Trainer.pokedexOwned(region)
- end
- def numFormsSeen(species)
- return $Trainer.numFormsSeen(species)
- end
- def hasSeen?(species)
- return $Trainer.hasSeen?(species)
- end
- def hasOwned?(species)
- return $Trainer.hasOwned?(species)
- end
- def setSeen(species)
- $Trainer.setSeen(species)
- end
- def setOwned(species)
- $Trainer.setOwned(species)
- end
- end
- class PokeBattle_DreamWorld < PokeBattle_Battle
- MAXPARTYSIZE = 6
- def ballcount
- return (@ballcount<0) ? 0 : @ballcount
- end
- def ballcount=(value)
- @ballcount=(value<0) ? 0 : value
- end
- alias __dw_initialize initialize
- def initialize(*args)
- __dw_initialize(*args)
- @ballcount=30
- @faketrainer=PokeBattle_FakeTrainer.new(@party1[0])
- end
- def pbSetSeen(pokemon)
- if pokemon && @internalbattle
- $Trainer.seen[pokemon.species]=true
- pbSeenForm(pokemon)
- end
- end
- def pbPlayer(realplayer=false)
- if realplayer
- return $Trainer
- end
- return @faketrainer
- end
- def pbEscapeRate(rareness)
- ret=25
- ret=50 if rareness<200
- ret=75 if rareness<150
- ret=100 if rareness<100
- ret=125 if rareness<25
- return ret
- end
- def pbCanMegaEvolve?(index)
- return false
- end
- def pbCanZMove?(index)
- return false
- end
- def pbDreamCommandMenu(i)
- return @scene.pbDreamCommandMenu(i)
- end
- def pbDreamItemMenu(i)
- return @scene.pbDreamItemMenu(i)
- end
- def pbRegisterItem(idxPokemon,idxItem,idxTarget=nil)
- if idxTarget!=nil && idxTarget>=0
- for i in 0...4
- if !@battlers[i].pbIsOpposing?(idxPokemon) &&
- @battlers[i].pokemonIndex==idxTarget &&
- @battlers[i].effects[PBEffects::Embargo]>0
- pbDisplay(_INTL("Embargo's effect prevents the item's use on {1}!",@battlers[i].pbThis(true)))
- if pbBelongsToPlayer?(@battlers[i].index)
- if $Trainer.dreambag.pbCanStore?(idxItem)
- $Trainer.dreambag.pbStoreItem(idxItem)
- else
- raise _INTL("Couldn't return unused item to Bag somehow.")
- end
- end
- return false
- end
- end
- end
- if ItemHandlers.hasUseInBattle(idxItem)
- # if idxPokemon==0 # Player's first Pokémon
- if ItemHandlers.triggerBattleUseOnBattler(idxItem,@battlers[idxPokemon],self)
- # Using Poké Balls or Poké Doll only
- ItemHandlers.triggerUseInBattle(idxItem,@battlers[idxPokemon],self)
- if @doublebattle
- @battlers[(idxPokemon+2)%4].effects[PBEffects::SkipTurn]=true
- end
- else
- if $Trainer.dreambag.pbCanStore?(idxItem)
- $Trainer.dreambag.pbStoreItem(idxItem)
- else
- raise _INTL("Couldn't return unusable item to Bag somehow.")
- end
- 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
- if @zMove[side][owner]==idxPokemon
- @zMove[side][owner]=-1
- end
- return true
- 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
- #=====================================
- # 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
- @battlers[0].pbInitialize(@party1[sendout1],sendout1,false)
- @battlers[2].pbInitialize(@party1[sendout2],sendout2,false)
- pbSetSeen(@party1[sendout1])
- pbSetSeen(@party1[sendout2])
- else
- sendout1=pbFindNextUnfainted(@party1,0)
- sendout2=pbFindNextUnfainted(@party1,sendout1+1)
- if sendout1<0 #|| sendout2<0
- raise _INTL("Player doesn't have any unfainted Pokémon")
- end
- @battlers[0].pbInitialize(@party1[sendout1],sendout1,false)
- @battlers[2].pbInitialize(@party1[sendout2],sendout2,false) if sendout2>=0
- @scene.pbStartDreamBattle(self)
- end
- #====================================
- # Initialize player in single battles
- #====================================
- else
- sendout=pbFindNextUnfainted(@party1,0)
- if sendout<0
- raise _INTL("Player has no unfainted Pokémon")
- end
- @battlers[0].pbInitialize(@party1[sendout],sendout,false)
- end
- #========================
- # 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]
- if pbIsUB? && !$Trainer.seen[wildpoke.species]
- wildpoke.name=_INTL("???")
- end
- if $game_switches[70]
- wildpoke.name=_INTL("Ghost")
- end
- @battlers[1].pbInitialize(wildpoke,0,false)
- @peer.pbOnEnteringBattle(self,wildpoke)
- pbSetSeen(wildpoke) if !pbIsUB?
- @scene.pbStartDreamBattle(self)
- if $game_switches[70]
- pbDisplayPaused(_INTL("Ghost appeared!"))
- pbDisplayPaused(_INTL("Darn. The Ghost can't be ID'd!"))
- else
- pbDisplayPaused(_INTL("Wild {1} appeared!",wildpoke.name)) if (!pbIsUB? || (pbIsUB? && $Trainer.seen[wildpoke.species])) && !wildpoke.isTotem?
- pbDisplayPaused(_INTL("The Totem {1} appeared!",wildpoke.name)) if wildpoke.isTotem?
- pbDisplayPaused(_INTL("??? appeared!")) if pbIsUB? && !$Trainer.seen[wildpoke.species]
- if wildpoke.isTotem? || pbIsUB?
- pbAuraStatRaise(@battlers[1])
- end
- if wildpoke.isDelta?
- pbDisplayPaused(_INTL("Oh! It's a delta species!"))
- end
- end
- 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.pbStartDreamBattle(self)
- if $game_switches[70]
- pbDisplayPaused(_INTL("Ghost and Ghost appeared!"))
- pbDisplayPaused(_INTL("Darn. Those Ghosts can't be ID'd!"))
- else
- pbDisplayPaused(_INTL("Wild {1} and\r\n{2} appeared!",
- @party2[0].name,@party2[1].name))
- if (@party2[0].isDelta? || @party2[1].isDelta?)
- pbDisplayPaused(_INTL("Oh! One of them is a delta species!"))
- elsif @party2[0].isDelta? && @party2[1].isDelta?
- pbDisplayPaused(_INTL("Oh! They're both delta species!"))
- end
- end
- else
- raise _INTL("Only one or two wild Pokémon are allowed")
- end
- @scene.pbDreamStart
- for i in 0...4
- @battlers[i].effects[PBEffects::Nativeness]=true if @battlers[i]
- 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::HEAVYRAIN
- pbCommonAnimation("HeavyRain",nil,nil)
- pbDisplay(_INTL("It is raining heavily."))
- elsif @weather==PBWeather::HARSHSUN
- pbCommonAnimation("HarshSun",nil,nil)
- pbDisplay(_INTL("The sunlight is extremely harsh."))
- elsif @weather==PBWeather::STRONGWINDS
- pbCommonAnimation("StrongWinds",nil,nil)
- pbDisplay(_INTL("The wind is strong."))
- elsif @weather==PBWeather::ACIDRAIN
- pbCommonAnimation("AcidRain",nil,nil)
- pbDisplay(_INTL("Acid rain falls from the sky."))
- end
- pbOnActiveAll # Abilities
- @turncount=0
- loop do # Now begin the battle loop
- PBDebug.log("")
- PBDebug.log("***Round #{@turncount+1}***")
- if @debug && @turncount>=100
- @decision=pbDecisionOnTime()
- PBDebug.log("")
- PBDebug.log("***Undecided after 100 rounds, aborting***")
- 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
- def pbCommandPhase
- @scene.pbBeginCommandPhase
- @scene.pbResetCommandIndices
- for i in 0...4 # Reset choices if commands can be shown
- @battlers[i].effects[PBEffects::SkipTurn]=false
- if pbCanShowCommands?(i) || @battlers[i].isFainted?
- @choices[i][0]=0
- @choices[i][1]=0
- @choices[i][2]=nil
- @choices[i][3]=-1
- else
- unless !@doublebattle && pbIsDoubleBattler?(i)
- PBDebug.log("[Reusing commands] #{@battlers[i].pbThis(true)}")
- end
- end
- end
- # Reset choices to perform Mega Evolution if it wasn't done somehow
- for i in 0...2
- for j in 0...@megaEvolution[i].length
- @megaEvolution[i][j]=-1 if @megaEvolution[i][j]>=0
- end
- end
- for i in 0...@zMove[0].length
- @zMove[0][i]=-1 if @zMove[0][i]>=0
- end
- for i in 0...@zMove[1].length
- @zMove[1][i]=-1 if @zMove[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=pbDreamCommandMenu(i)
- if cmd==0 # Fight
- if $game_switches[70]# If you're in the graveyard
- wildbattle = !@opponent# && pbIsOpposing?(opponent.index)
- if wildbattle # this is dumb
- pbDisplay(_INTL("{1} is too scared to move!",@battlers[i].pbThis))
- return
- end
- end
- 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
- if @zMove[side][owner]==i
- @zMove[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,target)
- next if target<0
- pbRegisterTarget(i,target)
- elsif target==PBTargets::UserOrPartner # Acupressure
- target=@scene.pbChooseTarget(i,target)
- next if target<0 || (target&1)==1
- pbRegisterTarget(i,target)
- end
- end
- commandDone=true
- end
- else
- pbAutoChooseMove(i)
- commandDone=true
- end
- elsif cmd!=0 && @battlers[i].effects[PBEffects::SkyDrop]
- pbDisplay(_INTL("Sky Drop won't let {1} go!",@battlers[i].pbThis(true)))
- elsif cmd==1 # Bag
- if !@internalbattle
- if pbOwnedByPlayer?(i)
- pbDisplay(_INTL("Items can't be used here."))
- end
- else
- item=pbDreamItemMenu(i)
- if item[0]>0
- if pbRegisterItem(i,item[0],item[1])
- commandDone=true
- end
- end
- end
- elsif cmd==2 # Ball
- if pbBoxesFull?
- pbDisplay(_INTL("The boxes are full! You can't catch any more Pokémon!"))
- elsif @ballcount<=0
- pbDisplay(_INTL("You're out of Dream Balls!"))
- else
- @ballcount-=1
- dreamBall=getConst(PBItems,:SAFARIBALL)
- if pbRegisterItem(i,dreamBall)
- commandDone=true
- end
- 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
- if @zMove[side][owner]==i
- @zMove[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
- if @zMove[side][owner]==i
- @zMove[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
- @zMove[0][0]=-1 if @zMove[0][0]>=0
- @zMove[1][0]=-1 if @zMove[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
- def pbEndOfBattle(canlose=false)
- case @decision
- ##### WIN #####
- when 1
- PBDebug.log("")
- PBDebug.log("***Player won***")
- ##### LOSE, DRAW #####
- when 2, 5
- PBDebug.log("")
- PBDebug.log("***Player lost***") if @decision==2
- PBDebug.log("***Player drew with opponent***") if @decision==5
- if @internalbattle
- pbDisplayPaused(_INTL("{1} is out of usable Pokémon!",self.pbPlayer.name))
- pbDisplayPaused(_INTL("{1} blacked out!",self.pbPlayer.name)) if !canlose
- end
- end
- #### PICK UP POKEBALLS ####
- if @decision == 1 || 4
- pbrs = [] #pokeball retrieval service
- # This array has a pattern. POKEBALLTYPE, Number, POKEBALLTYPE, NUMBER
- if $PokemonGlobal.ballsused[0] != nil #don't use unless there are pokeballs to regain
- pokeballs=$PokemonGlobal.ballsused
- pokeballs.each do |ball| # This part repeats for each pokeball
- chance=25
- rnd=rand(100)
- if rnd<chance
- unless pbrs.include?(ball) #unless the array already has the ball
- pbrs.push(ball)
- pbrs.push(1)
- else
- temp = pbrs.index(ball) #finds where in the array the pokeball type is
- pbrs[temp+1] +=1 #adds another ball to the number
- end
- end
- end
- while pbrs[0] != nil #While there are still pokeballs left to retreive
- balltype = pbrs.shift#destructively removes the first element (in this case, the pokeball name)
- #pbDisplayPaused(_INTL("{1}!",balltype))
- ballnumber = pbrs.shift #remember each even numbered item in the array is the pokeball number
- #pbDisplayPaused(_INTL("{1}!",ballnumber))
- $Trainer.dreambag.pbStoreItem(balltype,ballnumber)
- if ballnumber>1
- pbDisplayPaused(_INTL("{1} picked up {2} {3} thrown during the battle.", @battler[0].name, ballnumber, PBItems.getNamePlural(balltype)))
- else
- pbDisplayPaused(_INTL("{1} picked up one {2} thrown during the battle.", @battler[0].name, PBItems.getName(balltype)))
- end
- end
- end
- end
- $PokemonGlobal.ballsused=[] #to reset the array after the battle
- @scene.pbEndBattle(@decision)
- for i in @battlers
- i.pbResetForm
- if i.hasWorkingAbility(:NATURALCURE)
- i.status=0
- end
- end
- return @decision
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement