def pbPokemonString(pkmn) status="" if pkmn.hp<=0 status=" [FNT]" else case pkmn.status when PBStatuses::SLEEP status=" [SLP]" when PBStatuses::FROZEN status=" [FRZ]" when PBStatuses::BURN status=" [BRN]" when PBStatuses::PARALYSIS status=" [PAR]" when PBStatuses::POISON status=" [PSN]" end end return "#{pkmn.name} (Lv. #{pkmn.level})#{status} HP: #{pkmn.hp}/#{pkmn.totalhp}" end class Window_Pokemon < Window_Base attr_reader :highlighted def highlighted=(value) @highlighted=value refresh end def initialize(battler) @battler=battler @highlighted=false @highlightOpacity=255 @highlightIncr=-2 super(0,0,480,64) self.contents=Bitmap.new(self.width-32,self.height-32) refresh end def update if @highlighted @highlightIncr=-5 if @highlightOpacity>=255 @highlightIncr=5 if @highlightOpacity<=160 self.opacity=@highlightOpacity self.contents_opacity=@highlightOpacity @highlightOpacity+=@highlightIncr elsif self.opacity!=255 || self.contents_opacity!=255 self.opacity=255 self.contents_opacity=255 end super end def refresh self.contents.clear self.contents.font.color = normal_color str=pbPokemonString(@battler) self.contents.draw_text(0, 0, self.width-32, 32, str, 0) end end class Window_SimpleText < Window_Base attr_reader :text attr_reader :lines def text=(value) @text=value refresh end def initialize(text,lines) @text=text @lines=lines @lines=1 if @lines<1 super(0,0,480,32+(@lines*32)) self.contents=Bitmap.new(self.width-32,self.height-32) refresh end def refresh self.contents.clear textmsg=@text.clone x=y=0 while ((c = textmsg.slice!(/\S*\s?/m)) != nil) break if c=="" textwidth=self.contents.text_size(c).width if c=="\n" # Add 1 to y y += 1 x = 0 next end if x>0 && x+textwidth>=self.contents.width # Add 1 to y y += 1 x = 0 end # Draw text self.contents.draw_text(4 + x, 32 * y, textwidth, 32, c) # Add x to drawn text width x += textwidth end end end class PokeBattle_Scene def initialize @battle=nil @lastcmd=[0,0,0,0] @lastmove=[0,0,0,0] @pkmnwindows=[nil,nil,nil,nil] end def pbDisplayMessage(msg) pbRefresh cw = Window_SimpleText.new(msg,4) cw.y=256 i=0 loop do Graphics.update Input.update cw.update if i==80 cw.dispose return end if Input.trigger?(Input::C) cw.dispose return end i+=1 end end def pbDisplayPausedMessage(msg) cw = Window_SimpleText.new(msg,4) cw.y=256 loop do Graphics.update Input.update cw.update if Input.trigger?(Input::C) cw.dispose return end end end def pbDisplayConfirmMessage(msg) dw = Window_SimpleText.new(msg,4) dw.y=256 commands=["YES","NO"] cw = Window_Command.new(96, commands) cw.x=384 cw.y=160 cw.index=0 pbRefresh loop do Graphics.update Input.update pbFrameUpdate(cw) if Input.trigger?(Input::B) cw.dispose dw.dispose return false end if Input.trigger?(Input::C) cw.dispose dw.dispose return (cw.index==0)?true:false end end end def pbFrameUpdate(cw) cw.update if cw for i in 0..3 @pkmnwindows[i].update end # @exceptwindow.text="Exceptions: #{$PBDebugExceptions}" # @exceptwindow.update end def pbRefresh for i in 0..3 @pkmnwindows[i].refresh end @exceptwindow.refresh end def pbBeginCommandPhase # Called whenever a new round begins. end def pbStartBattle(battle) # Called whenever the battle begins @battle=battle @lastcmd=[0,0,0,0] @lastmove=[0,0,0,0] for i in 0..3 @pkmnwindows[i]=Window_Pokemon.new(@battle.battlers[i]) @pkmnwindows[i].y=i*64 end @exceptwindow=Window_SimpleText.new("Exceptions: 0",1) @exceptwindow.x=0 @exceptwindow.y=416 end def pbEndBattle(result) for i in 0..3 if @pkmnwindows[i] @pkmnwindows[i].dispose end end @exceptwindow.dispose end def pbTrainerSendOut(battle,pkmn) pbRefresh end def pbSendOut(battle,pkmn) pbRefresh end def pbTrainerWithdraw(battle,pkmn) pbRefresh end def pbWithdraw(battle,pkmn) pbRefresh end def pbForgetMove(pkmn) # Called whenever a Pokemon should forget a move. It # should return -1 if the selection is canceled, or 0 to 3 # to indicate the move to forget. The function should not # allow HM moves to be forgotten. return 0 end def pbBeginAttackPhase end def pbCommandMenu(index) # Use this method to display the list of commands. # Return values: # 0 - Fight # 1 - Pokemon # 2 - Bag # 3 - Run commands=["FIGHT","POKeMON","BAG","RUN"] cw = Window_Command.new(192, commands) cw.x=0 cw.y=256 cw.index=@lastcmd[index] pbRefresh loop do Graphics.update Input.update pbFrameUpdate(cw) if Input.trigger?(Input::C) ret=cw.index cw.dispose @lastcmd[index]=ret return ret end end end def pbPokemonString(pkmn) status="" if pkmn.hp<=0 status=" [FNT]" else case pkmn.status when PBStatuses::SLEEP status=" [SLP]" when PBStatuses::FROZEN status=" [FRZ]" when PBStatuses::BURN status=" [BRN]" when PBStatuses::PARALYSIS status=" [PAR]" when PBStatuses::POISON status=" [PSN]" end end return "#{pkmn.name} (Lv. #{pkmn.level})#{status} HP: #{pkmn.hp}/#{pkmn.totalhp}" end def pbMoveString(move) ret="#{move.name}" typename=PBTypes.getName(move.type) if move.id>0 ret+=" (#{typename}) PP: #{move.pp}/#{move.totalpp}" end return ret end def pbFightMenu(index) # Use this method to display the list of moves for a Pokemon moves=@battle.battlers[index].moves commands=[ pbMoveString(moves[0]), pbMoveString(moves[1]), pbMoveString(moves[2]), pbMoveString(moves[3]) ] cw = Window_Command.new(480, commands) cw.x=0 cw.y=256 cw.index=@lastmove[index] pbRefresh loop do Graphics.update Input.update pbFrameUpdate(cw) if Input.trigger?(Input::B) @lastmove[index]=cw.index cw.dispose return -1 end if Input.trigger?(Input::C) ret=cw.index @lastmove[index]=ret cw.dispose return ret end end end def pbItemMenu(index) # Use this method to display the inventory # The return value is the item chosen, or 0 if the choice was canceled. pbDisplayMessage("Items can't be used here.") return -1 end def pbFirstTarget(index) for i in 0..3 if i!=index && @battle.battlers[i].hp>0 return i end end return -1 end def pbNextTarget(cur,index) return -1 if cur>=3 for i in cur+1..3 if i!=index && @battle.battlers[i].hp>0 return i end end return -1 end def pbPrevTarget(cur,index) return -1 if cur<=0 ret=-1 for i in 0..cur-1 if i!=index && @battle.battlers[i].hp>0 ret=i end end return ret end def pbChooseTarget(index) # Use this method to make the player choose a target # for certain moves in double battles. curwindow=pbFirstTarget(index) if curwindow==-1 pbDisplay("No targets somehow...") return -1 end for i in 0..3 @pkmnwindows[i].highlighted=(i==curwindow) end pbRefresh loop do Graphics.update Input.update pbFrameUpdate(nil) if Input.trigger?(Input::DOWN) newwindow=pbNextTarget(curwindow,index) if newwindow>=0 curwindow=newwindow for i in 0..3 @pkmnwindows[i].highlighted=(i==curwindow) end end end if Input.trigger?(Input::UP) newwindow=pbPrevTarget(curwindow,index) if newwindow>=0 curwindow=newwindow for i in 0..3 @pkmnwindows[i].highlighted=(i==curwindow) end end end if Input.trigger?(Input::B) for i in 0..3 @pkmnwindows[i].highlighted=false @pkmnwindows[i].update end return -1 end if Input.trigger?(Input::C) for i in 0..3 @pkmnwindows[i].highlighted=false @pkmnwindows[i].update end return curwindow end end end def pbSwitch(index,lax,cancancel) party=@battle.pbParty(index) commands=[] inactives=[1,1,1,1,1,1] partypos=[] activecmd=0 numactive=(@doublebattle)?2:1 battler=@battle.battlers[0] commands[commands.length]=pbPokemonString(party[battler.pokemonIndex]) activecmd=0 if battler.index==index inactives[battler.pokemonIndex]=0 partypos[partypos.length]=battler.pokemonIndex if @battle.doublebattle battler=@battle.battlers[2] commands[commands.length]=pbPokemonString(party[battler.pokemonIndex]) activecmd=1 if battler.index==index inactives[battler.pokemonIndex]=0 partypos[partypos.length]=battler.pokemonIndex end for i in 0..party.length-1 if inactives[i]==1 commands[commands.length]=pbPokemonString(party[i]) partypos[partypos.length]=i end end for i in 0..3 @pkmnwindows[i].visible=false end cw = Window_Command.new(480, commands) cw.x=0 cw.y=0 cw.index=activecmd pbRefresh ret=0 loop do Graphics.update Input.update pbFrameUpdate(cw) if cancancel && Input.trigger?(Input::B) ret=-1 cw.dispose break end if Input.trigger?(Input::C) pkmnindex=partypos[cw.index] canswitch=lax ? @battle.pbCanSwitchLax?(index,pkmnindex,true) : @battle.pbCanSwitch?(index,pkmnindex,true) if canswitch ret=pkmnindex cw.dispose break end end end for i in 0..3 @pkmnwindows[i].visible=true end return ret end def pbHPChanged(pkmn,oldhp) # This method is called whenever a Pokemon's HP changes. # Used to animate the HP bar. hpchange=pkmn.hp-oldhp if hpchange<0 hpchange=-hpchange PBDebug.log("[#{pkmn.pbThis} lost #{hpchange} HP, now has #{pkmn.hp} HP]") else PBDebug.log("[#{pkmn.pbThis} gained #{hpchange} HP, now has #{pkmn.hp} HP]") end pbRefresh end def pbFainted(pkmn) # This method is called whenever a Pokemon faints end def pbChooseEnemyCommand(index) # Use this method to choose a command for the enemy. if !@battle.pbCanShowFightMenu?(index) @battle.pbAutoChooseMove(index) return end choices=[] for i in 0..3 if @battle.pbCanChooseMove?(index,i,false) choices[choices.length]=i end end if choices.length>0 @battle.pbRegisterMove(index,choices[@battle.pbRandom(choices.length)]) else @battle.pbAutoChooseMove(index) end end def pbChooseNewEnemy(index,party) # Use this method to choose a new Pokemon for the enemy # The enemy's party is guaranteed to have at least one choosable member. for i in 0..party.length-1 return i if @battle.pbCanSwitchLax?(index,i,false) end return -1 end def pbWildBattleSuccess # This method is called when the player wins a wild Pokemon battle. # This method can change the battle's music for example. end def pbTrainerBattleSuccess # This method is called when the player wins a Trainer battle. # This method can change the battle's music for example. end def pbEXPBar(thispoke,startexp,endexp,tempexp1,tempexp2) end def pbLevelUp(thispoke,oldtotalhp,oldattack, olddefense,oldspeed,oldspatk,oldspdef) end end