Advertisement
Guest User

Untitled

a guest
Feb 4th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 116.94 KB | None | 0 0
  1. =begin
  2. - def pbChooseNewEnemy(index,party)
  3. Use this method to choose a new Pokémon for the enemy
  4. The enemy's party is guaranteed to have at least one
  5. choosable member.
  6. index - Index to the battler to be replaced (use e.g. @battle.battlers[index] to
  7. access the battler)
  8. party - Enemy's party
  9.  
  10. - def pbWildBattleSuccess
  11. This method is called when the player wins a wild Pokémon battle.
  12. This method can change the battle's music for example.
  13.  
  14. - def pbTrainerBattleSuccess
  15. This method is called when the player wins a Trainer battle.
  16. This method can change the battle's music for example.
  17.  
  18. - def pbFainted(pkmn)
  19. This method is called whenever a Pokémon faints.
  20. pkmn - PokeBattle_Battler object indicating the Pokémon that fainted
  21.  
  22. - def pbChooseEnemyCommand(index)
  23. Use this method to choose a command for the enemy.
  24. index - Index of enemy battler (use e.g. @battle.battlers[index] to
  25. access the battler)
  26.  
  27. - def pbCommandMenu(index)
  28. Use this method to display the list of commands and choose
  29. a command for the player.
  30. index - Index of battler (use e.g. @battle.battlers[index] to
  31. access the battler)
  32. Return values:
  33. 0 - Fight
  34. 1 - Pokémon
  35. 2 - Bag
  36. 3 - Run
  37. =end
  38.  
  39. #===============================================================================
  40. # Command menu (Fight/Pokémon/Bag/Run)
  41. #===============================================================================
  42. class CommandMenuDisplay
  43. attr_accessor :mode
  44.  
  45. def initialize(viewport=nil)
  46. @display=nil
  47. if PokeBattle_SceneConstants::USECOMMANDBOX
  48. #@display=IconSprite.new(0,Graphics.height-96,viewport)
  49. @display=IconSprite.new(0,Graphics.height-58,viewport)#0,82
  50.  
  51. #@display.setBitmap("Graphics/Pictures/battleCommand")
  52. @display.setBitmap("Graphics/Pictures/luchaComando")
  53. end
  54. @window=Window_CommandPokemon.newWithSize([],
  55. Graphics.width-240,Graphics.height-96,240,96,viewport)
  56. @window.columns=2
  57. @window.columnSpacing=4
  58. @window.ignore_input=true
  59. @msgbox=Window_UnformattedTextPokemon.newWithSize(
  60. #"",16,Graphics.height-96+2,220,96,viewport)
  61. "",-12,Graphics.height-62+2,280,96,viewport)#280
  62.  
  63. #@msgbox.baseColor=PokeBattle_SceneConstants::MESSAGEBASECOLOR
  64. #@msgbox.shadowColor=PokeBattle_SceneConstants::MESSAGESHADOWCOLOR
  65. @msgbox.baseColor=PokeBattle_SceneConstants::MESSAGEBASECOLOR2
  66. @msgbox.shadowColor=PokeBattle_SceneConstants::MESSAGESHADOWCOLOR2
  67. @msgbox.windowskin=nil
  68. @title=""
  69. @buttons=nil
  70. if PokeBattle_SceneConstants::USECOMMANDBOX
  71. @window.opacity=0
  72. @window.x=Graphics.width
  73. @buttons=CommandMenuButtons.new(self.index,self.mode,viewport)
  74. end
  75. end
  76.  
  77. def x; @window.x; end
  78. def x=(value)
  79. @window.x=value
  80. @msgbox.x=value
  81. @display.x=value if @display
  82. @buttons.x=value if @buttons
  83. end
  84.  
  85. def y; @window.y; end
  86. def y=(value)
  87. @window.y=value
  88. @msgbox.y=value
  89. @display.y=value if @display
  90. @buttons.y=value if @buttons
  91. end
  92.  
  93. def z; @window.z; end
  94. def z=(value)
  95. @window.z=value
  96. @msgbox.z=value
  97. @display.z=value if @display
  98. @buttons.z=value+1 if @buttons
  99. end
  100.  
  101. def ox; @window.ox; end
  102. def ox=(value)
  103. @window.ox=value
  104. @msgbox.ox=value
  105. @display.ox=value if @display
  106. @buttons.ox=value if @buttons
  107. end
  108.  
  109. def oy; @window.oy; end
  110. def oy=(value)
  111. @window.oy=value
  112. @msgbox.oy=value
  113. @display.oy=value if @display
  114. @buttons.oy=value if @buttons
  115. end
  116.  
  117. def visible; @window.visible; end
  118. def visible=(value)
  119. @window.visible=value
  120. @msgbox.visible=value
  121. @display.visible=value if @display
  122. @buttons.visible=value if @buttons
  123. end
  124.  
  125. def color; @window.color; end
  126. def color=(value)
  127. @window.color=value
  128. @msgbox.color=value
  129. @display.color=value if @display
  130. @buttons.color=value if @buttons
  131. end
  132.  
  133. def disposed?
  134. return @msgbox.disposed? || @window.disposed?
  135. end
  136.  
  137. def dispose
  138. return if disposed?
  139. @msgbox.dispose
  140. @window.dispose
  141. @display.dispose if @display
  142. @buttons.dispose if @buttons
  143. end
  144.  
  145. def index; @window.index; end
  146. def index=(value); @window.index=value; end
  147.  
  148. def setTexts(value)
  149. @msgbox.text=value[0]
  150. commands=[]
  151. for i in 1..4
  152. commands.push(value[i]) if value[i] && value[i]!=nil
  153. end
  154. @window.commands=commands
  155. end
  156.  
  157. def refresh
  158. @msgbox.refresh
  159. @window.refresh
  160. @buttons.refresh(self.index,self.mode) if @buttons
  161. end
  162.  
  163. def update
  164. @msgbox.update
  165. @window.update
  166. @display.update if @display
  167. @buttons.update(self.index,self.mode) if @buttons
  168. end
  169. end
  170.  
  171.  
  172.  
  173. class CommandMenuButtons < BitmapSprite
  174. def initialize(index=0,mode=0,viewport=nil)
  175. super(260,96,viewport)
  176. self.x=Graphics.width-260
  177. self.y=Graphics.height-96
  178. @mode=mode
  179. #@buttonbitmap=AnimatedBitmap.new(_INTL("Graphics/Pictures/battleCommandButtons"))
  180. @buttonbitmap=AnimatedBitmap.new(_INTL("Graphics/Pictures/luchaComandoBoton"))
  181. refresh(index,mode)
  182. end
  183.  
  184. def dispose
  185. @buttonbitmap.dispose
  186. super
  187. end
  188.  
  189. def update(index=0,mode=0)
  190. refresh(index,mode)
  191. end
  192.  
  193. def refresh(index,mode=0)
  194. self.bitmap.clear
  195. @mode=mode
  196. cmdarray=[0,2,1,3]
  197. case @mode
  198. when 1
  199. cmdarray=[0,2,1,4] # Use "Call"
  200. when 2
  201. cmdarray=[5,7,6,3] # Safari Zone battle
  202. when 3
  203. cmdarray=[0,8,1,3] # Bug Catching Contest
  204. end
  205. for i in 0...4
  206. next if i==index
  207. #x=((i%2)==0) ? 0 : 126
  208. #y=((i/2)==0) ? 6 : 48
  209. #self.bitmap.blt(x,y,@buttonbitmap.bitmap,Rect.new(0,cmdarray[i]*46,130,46))
  210. #x=[3,67,128,195][i]
  211. x=[4,68,132,196][i]
  212. y=14
  213. self.bitmap.blt(x,y,@buttonbitmap.bitmap,Rect.new(0,cmdarray[i]*82,64,82))
  214. end
  215. for i in 0...4
  216. next if i!=index
  217. #x=((i%2)==0) ? 0 : 126
  218. #y=((i/2)==0) ? 6 : 48
  219. #self.bitmap.blt(x,y,@buttonbitmap.bitmap,Rect.new(130,cmdarray[i]*46,130,46))
  220. x=[4,68,132,196][i]
  221. y=14
  222. self.bitmap.blt(x,y,@buttonbitmap.bitmap,Rect.new(64,cmdarray[i]*82,64,82))
  223. end
  224. end
  225. end
  226.  
  227.  
  228.  
  229. #===============================================================================
  230. # Fight menu (choose a move)
  231. #===============================================================================
  232. class FightMenuDisplay
  233. attr_reader :battler
  234. attr_reader :index
  235. attr_accessor :megaButton
  236.  
  237.  
  238. def initialize(battler,viewport=nil)
  239. @display=nil
  240. if PokeBattle_SceneConstants::USEFIGHTBOX
  241. @display=IconSprite.new(0,Graphics.height-96,viewport)
  242. #@display.setBitmap("Graphics/Pictures/battleFight")
  243. @display.setBitmap("Graphics/Pictures/BatallaMessage")
  244. end
  245. @window=Window_CommandPokemon.newWithSize([],0,Graphics.height-96,320,96,viewport)
  246. @window.columns=2
  247. @window.columnSpacing=4
  248. @window.ignore_input=true
  249. pbSetNarrowFont(@window.contents)
  250. @info=Window_AdvancedTextPokemon.newWithSize(
  251. "",320,Graphics.height-96,Graphics.width-320,96,viewport)
  252. pbSetNarrowFont(@info.contents)
  253. @ctag=shadowctag(PokeBattle_SceneConstants::MENUBASECOLOR,
  254. PokeBattle_SceneConstants::MENUSHADOWCOLOR)
  255. @buttons=nil
  256. @battler=battler
  257. @index=0
  258. @megaButton=0 # 0=don't show, 1=show, 2=pressed
  259.  
  260. if PokeBattle_SceneConstants::USEFIGHTBOX
  261. @window.opacity=0
  262. @window.x=Graphics.width
  263. @info.opacity=0
  264. @info.x=Graphics.width+Graphics.width-96
  265. @buttons=FightMenuButtons.new(self.index,nil,viewport)
  266. end
  267. refresh
  268. end
  269.  
  270. def x; @window.x; end
  271. def x=(value)
  272. @window.x=value
  273. @info.x=value
  274. @display.x=value if @display
  275. @buttons.x=value if @buttons
  276. end
  277.  
  278. def y; @window.y; end
  279. def y=(value)
  280. @window.y=value
  281. @info.y=value
  282. @display.y=value if @display
  283. @buttons.y=value if @buttons
  284. end
  285.  
  286. def z; @window.z; end
  287. def z=(value)
  288. @window.z=value
  289. @info.z=value
  290. @display.z=value if @display
  291. @buttons.z=value+1 if @buttons
  292. end
  293.  
  294. def ox; @window.ox; end
  295. def ox=(value)
  296. @window.ox=value
  297. @info.ox=value
  298. @display.ox=value if @display
  299. @buttons.ox=value if @buttons
  300. end
  301.  
  302. def oy; @window.oy; end
  303. def oy=(value)
  304. @window.oy=value
  305. @info.oy=value
  306. @display.oy=value if @display
  307. @buttons.oy=value if @buttons
  308. end
  309.  
  310. def visible; @window.visible; end
  311. def visible=(value)
  312. @window.visible=value
  313. @info.visible=value
  314. @display.visible=value if @display
  315. @buttons.visible=value if @buttons
  316. end
  317.  
  318. def color; @window.color; end
  319. def color=(value)
  320. @window.color=value
  321. @info.color=value
  322. @display.color=value if @display
  323. @buttons.color=value if @buttons
  324. end
  325.  
  326. def disposed?
  327. return @info.disposed? || @window.disposed?
  328. end
  329.  
  330. def dispose
  331. return if disposed?
  332. @info.dispose
  333. @display.dispose if @display
  334. @buttons.dispose if @buttons
  335. @window.dispose
  336. end
  337.  
  338. def battler=(value)
  339. @battler=value
  340. refresh
  341. end
  342.  
  343. def setIndex(value)
  344. if @battler && @battler.moves[value].id!=0
  345. @index=value
  346. @window.index=value
  347. refresh
  348. return true
  349. end
  350. return false
  351. end
  352.  
  353. def refresh
  354. return if !@battler
  355. commands=[]
  356. for i in 0...4
  357. break if @battler.moves[i].id==0
  358. commands.push(@battler.moves[i].name)
  359. end
  360. @window.commands=commands
  361. selmove=@battler.moves[@index]
  362. movetype=PBTypes.getName(selmove.type)
  363. if selmove.totalpp==0
  364. @info.text=_ISPRINTF("{1:s}PP: ---<br>TIPO/{2:s}",@ctag,movetype)
  365. else
  366. @info.text=_ISPRINTF("{1:s}PP: {2: 2d}/{3: 2d}<br>TIPO/{4:s}",
  367. @ctag,selmove.pp,selmove.totalpp,movetype)
  368. end
  369. @buttons.refresh(self.index,@battler ? @battler.moves : nil,@megaButton) if @buttons
  370. end
  371.  
  372. def update
  373. @info.update
  374. @window.update
  375. @display.update if @display
  376. if @buttons
  377. moves=@battler ? @battler.moves : nil
  378. @buttons.update(self.index,moves,@megaButton)
  379. end
  380. end
  381. end
  382.  
  383.  
  384.  
  385. class FightMenuButtons < BitmapSprite
  386. UPPERGAP=46
  387.  
  388. def initialize(index=0,moves=nil,viewport=nil)
  389. super(Graphics.width,146+UPPERGAP,viewport)#96
  390. self.x=0
  391. self.y=Graphics.height-146-UPPERGAP#96
  392. pbSetNarrowFont(self.bitmap)
  393. @buttonbitmap=AnimatedBitmap.new("Graphics/Pictures/battleBatallaBotones")
  394. @typebitmap=AnimatedBitmap.new(_INTL("Graphics/Pictures/types"))
  395. @categorybitmap=AnimatedBitmap.new(_INTL("Graphics/Pictures/category"))
  396. @megaevobitmap=AnimatedBitmap.new(_INTL("Graphics/Pictures/battleMegaEvo"))
  397. refresh(index,moves,0)
  398. end
  399.  
  400. def dispose
  401. @buttonbitmap.dispose
  402. @typebitmap.dispose
  403. @categorybitmap.dispose
  404. @megaevobitmap.dispose
  405. super
  406. end
  407.  
  408. def update(index=0,moves=nil,megaButton=0)
  409. refresh(index,moves,megaButton)
  410. end
  411.  
  412. def refresh(index,moves,megaButton)
  413. return if !moves
  414. self.bitmap.clear
  415. moveboxes=_INTL("Graphics/Pictures/battleFightButtons")
  416. textpos=[]
  417. for i in 0...4
  418. next if i==index
  419. next if moves[i].id==0
  420. x=[0,0,0,0][i]
  421. y=[104,64,24,-16][i]
  422. y+=UPPERGAP
  423. self.bitmap.blt(x,y,@buttonbitmap.bitmap,Rect.new(0,moves[i].type*42,196,42))
  424. textpos.push([_INTL("{1}",moves[i].name),x+96,y+8,2,
  425. #PokeBattle_SceneConstants::MENUBASECOLOR,PokeBattle_SceneConstants::MENUSHADOWCOLOR])
  426. PokeBattle_SceneConstants::MESSAGEBASECOLOR3,PokeBattle_SceneConstants::MESSAGESHADOWCOLOR3])
  427. end
  428. ppcolors=[
  429. PokeBattle_SceneConstants::PPTEXTBASECOLOR2,PokeBattle_SceneConstants::PPTEXTSHADOWCOLOR2,
  430. PokeBattle_SceneConstants::PPTEXTBASECOLOR2,PokeBattle_SceneConstants::PPTEXTSHADOWCOLOR2,
  431. PokeBattle_SceneConstants::PPTEXTBASECOLORYELLOW,PokeBattle_SceneConstants::PPTEXTSHADOWCOLORYELLOW,
  432. PokeBattle_SceneConstants::PPTEXTBASECOLORORANGE,PokeBattle_SceneConstants::PPTEXTSHADOWCOLORORANGE,
  433. PokeBattle_SceneConstants::PPTEXTBASECOLORRED,PokeBattle_SceneConstants::PPTEXTSHADOWCOLORRED
  434. ]
  435. for i in 0...4
  436. next if i!=index
  437. next if moves[i].id==0
  438. x=[0,0,0,0][i]
  439. y=[104,64,24,-16][i]
  440. y+=UPPERGAP
  441. self.bitmap.blt(x,y,@buttonbitmap.bitmap,Rect.new(196,moves[i].type*42,196,42))
  442. self.bitmap.blt(416-200,50+15+UPPERGAP,@typebitmap.bitmap,Rect.new(0,moves[i].type*28,64,28))
  443. textpos.push([_INTL("{1}",moves[i].name),x+96,y+8,2,
  444. #PokeBattle_SceneConstants::MENUBASECOLOR,PokeBattle_SceneConstants::MENUSHADOWCOLOR])
  445. PokeBattle_SceneConstants::MESSAGEBASECOLOR3,PokeBattle_SceneConstants::MESSAGESHADOWCOLOR3])
  446. #
  447. self.bitmap.blt(416-115,50+25+46,@categorybitmap.bitmap,Rect.new(0,moves[i].category*28,64,28))
  448. if moves[i].accuracy==0
  449. textpos.push([_INTL("---"),488,136,2,
  450. PokeBattle_SceneConstants::MESSAGEBASECOLOR3,PokeBattle_SceneConstants::MESSAGESHADOWCOLOR3])
  451. textpos.push([_INTL("precision"),423,136,2,
  452. PokeBattle_SceneConstants::MESSAGEBASECOLOR3,PokeBattle_SceneConstants::MESSAGESHADOWCOLOR3])
  453. else
  454. textpos.push([_INTL("{1}%",moves[i].accuracy),488,136,2,
  455. PokeBattle_SceneConstants::MESSAGEBASECOLOR3,PokeBattle_SceneConstants::MESSAGESHADOWCOLOR3])
  456. textpos.push([_INTL("precision"),423,136,2,
  457. PokeBattle_SceneConstants::MESSAGEBASECOLOR3,PokeBattle_SceneConstants::MESSAGESHADOWCOLOR3])
  458. end
  459. if moves[i].basedamage==0
  460. textpos.push([_INTL("---"),488,106,2,
  461. PokeBattle_SceneConstants::MESSAGEBASECOLOR3,PokeBattle_SceneConstants::MESSAGESHADOWCOLOR3])
  462. textpos.push([_INTL("potencia"),420,106,2,
  463. PokeBattle_SceneConstants::MESSAGEBASECOLOR3,PokeBattle_SceneConstants::MESSAGESHADOWCOLOR3])
  464. elsif moves[i].basedamage==1
  465. textpos.push([_INTL("???"),488,106,2,
  466. PokeBattle_SceneConstants::MESSAGEBASECOLOR3,PokeBattle_SceneConstants::MESSAGESHADOWCOLOR3])
  467. textpos.push([_INTL("potencia"),420,106,2,
  468. PokeBattle_SceneConstants::MESSAGEBASECOLOR3,PokeBattle_SceneConstants::MESSAGESHADOWCOLOR3])
  469. else
  470. textpos.push([_INTL("{1}",moves[i].basedamage),488,106,2,
  471. PokeBattle_SceneConstants::MESSAGEBASECOLOR3,PokeBattle_SceneConstants::MESSAGESHADOWCOLOR3])
  472. textpos.push([_INTL("potencia"),420,106,2,
  473. PokeBattle_SceneConstants::MESSAGEBASECOLOR3,PokeBattle_SceneConstants::MESSAGESHADOWCOLOR3])
  474. end
  475. #
  476. if moves[i].totalpp>0
  477. ppfraction=(4.0*moves[i].pp/moves[i].totalpp).ceil
  478. textpos.push([_INTL("PP: {1}/{2}",moves[i].pp,moves[i].totalpp),
  479. 448-200,50+15+30+UPPERGAP,2,ppcolors[(4-ppfraction)*2],ppcolors[(4-ppfraction)*2+1]])
  480. end
  481. end
  482. pbDrawTextPositions(self.bitmap,textpos)
  483. if megaButton>0
  484. self.bitmap.blt(146,0+50,@megaevobitmap.bitmap,Rect.new(0,(megaButton-1)*46,96,46))
  485. end
  486. end
  487. end
  488.  
  489.  
  490.  
  491. #===============================================================================
  492. # Data box for safari battles
  493. #===============================================================================
  494. class SafariDataBox < SpriteWrapper
  495. attr_accessor :selected
  496. attr_reader :appearing
  497.  
  498. def initialize(battle,viewport=nil)
  499. super(viewport)
  500. @selected=0
  501. @battle=battle
  502. @databox=AnimatedBitmap.new("Graphics/Pictures/battlePlayerSafari")
  503. @spriteX=PokeBattle_SceneConstants::SAFARIBOX_X
  504. @spriteY=PokeBattle_SceneConstants::SAFARIBOX_Y
  505. @appearing=false
  506. @contents=BitmapWrapper.new(@databox.width,@databox.height)
  507. self.bitmap=@contents
  508. self.visible=false
  509. self.z=50
  510.  
  511. refresh
  512. end
  513.  
  514. def appear
  515. refresh
  516. self.visible=true
  517. self.opacity=255
  518. self.x=@spriteX+240
  519. self.y=@spriteY
  520. @appearing=true
  521. end
  522.  
  523. def refresh
  524. self.bitmap.clear
  525. self.bitmap.blt(0,0,@databox.bitmap,Rect.new(0,0,@databox.width,@databox.height))
  526. pbSetSystemFont(self.bitmap)
  527.  
  528. textpos=[]
  529. base=PokeBattle_SceneConstants::BOXTEXTBASECOLOR
  530. shadow=PokeBattle_SceneConstants::BOXTEXTSHADOWCOLOR
  531. textpos.push([_INTL("Safari Balls"),30,8,false,base,shadow])
  532. textpos.push([_INTL("Quedan: {1}",@battle.ballcount),30,38,false,base,shadow])
  533. pbDrawTextPositions(self.bitmap,textpos)
  534. end
  535.  
  536. def update
  537. super
  538. if @appearing
  539. self.x-=12
  540. self.x=@spriteX if self.x<@spriteX
  541. @appearing=false if self.x<=@spriteX
  542. self.y=@spriteY
  543. return
  544. end
  545. self.x=@spriteX
  546. self.y=@spriteY
  547. end
  548. end
  549.  
  550.  
  551.  
  552. #===============================================================================
  553. # Data box for regular battles (both single and double)
  554. #===============================================================================
  555. class PokemonDataBox < SpriteWrapper
  556. attr_reader :battler
  557. attr_accessor :selected
  558. attr_accessor :appearing
  559. attr_reader :animatingHP
  560. attr_reader :animatingEXP
  561.  
  562. def initialize(battler,doublebattle,viewport=nil)
  563. super(viewport)
  564. @explevel=0
  565. @battler=battler
  566. @selected=0
  567. @frame=0
  568. @showhp=false
  569. @showexp=false
  570. @appearing=false
  571. @animatingHP=false
  572. @starthp=0
  573. @currenthp=0
  574. @endhp=0
  575. @expflash=0
  576. if (@battler.index&1)==0 # if player's Pokémon
  577. @spritebaseX=34
  578. else
  579. @spritebaseX=16
  580. end
  581. if doublebattle
  582. case @battler.index
  583. when 0
  584.  
  585. @databox=AnimatedBitmap.new("Graphics/Pictures/battlePlayerBoxD")
  586. @spriteX=PokeBattle_SceneConstants::PLAYERBOXD1_X
  587. @spriteY=PokeBattle_SceneConstants::PLAYERBOXD1_Y
  588. when 1
  589.  
  590. @databox=AnimatedBitmap.new("Graphics/Pictures/battleFoeBoxD")
  591. @spriteX=PokeBattle_SceneConstants::FOEBOXD1_X
  592. @spriteY=PokeBattle_SceneConstants::FOEBOXD1_Y
  593. when 2
  594.  
  595. @databox=AnimatedBitmap.new("Graphics/Pictures/battlePlayerBoxD")
  596. @spriteX=PokeBattle_SceneConstants::PLAYERBOXD2_X
  597. @spriteY=PokeBattle_SceneConstants::PLAYERBOXD2_Y
  598. when 3
  599.  
  600. @databox=AnimatedBitmap.new("Graphics/Pictures/battleFoeBoxD")
  601. @spriteX=PokeBattle_SceneConstants::FOEBOXD2_X
  602. @spriteY=PokeBattle_SceneConstants::FOEBOXD2_Y
  603. end
  604. else
  605. case @battler.index
  606. when 0
  607.  
  608. @databox=AnimatedBitmap.new("Graphics/Pictures/battlePlayerBoxS")
  609. @spriteX=PokeBattle_SceneConstants::PLAYERBOX_X
  610. @spriteY=PokeBattle_SceneConstants::PLAYERBOX_Y
  611. @showhp=true
  612. @showexp=true
  613. when 1
  614.  
  615. @databox=AnimatedBitmap.new("Graphics/Pictures/battleFoeBoxS")
  616. @spriteX=PokeBattle_SceneConstants::FOEBOX_X
  617. @spriteY=PokeBattle_SceneConstants::FOEBOX_Y
  618. end
  619. end
  620. @statuses=AnimatedBitmap.new(_INTL("Graphics/Pictures/battleStatuses"))
  621.  
  622.  
  623.  
  624.  
  625. @contents=BitmapWrapper.new(@databox.width,@databox.height)
  626. self.bitmap=@contents
  627. self.visible=false
  628. self.z=50
  629. refreshExpLevel
  630. refresh
  631. end
  632.  
  633. def dispose
  634. @statuses.dispose
  635.  
  636.  
  637. @databox.dispose
  638. @contents.dispose
  639. super
  640. end
  641.  
  642. def refreshExpLevel
  643. if !@battler.pokemon
  644. @explevel=0
  645. else
  646. growthrate=@battler.pokemon.growthrate
  647. startexp=PBExperience.pbGetStartExperience(@battler.pokemon.level,growthrate)
  648. endexp=PBExperience.pbGetStartExperience(@battler.pokemon.level+1,growthrate)
  649. if startexp==endexp
  650. @explevel=0
  651. else
  652. @explevel=(@battler.pokemon.exp-startexp)*PokeBattle_SceneConstants::EXPGAUGESIZE/(endexp-startexp)
  653. end
  654. end
  655. end
  656.  
  657. def exp
  658. return @animatingEXP ? @currentexp : @explevel
  659. end
  660.  
  661. def hp
  662. return @animatingHP ? @currenthp : @battler.hp
  663. end
  664.  
  665. def animateHP(oldhp,newhp)
  666. @starthp=oldhp
  667. @currenthp=oldhp
  668. @endhp=newhp
  669. @animatingHP=true
  670. end
  671.  
  672. def animateEXP(oldexp,newexp)
  673. @currentexp=oldexp
  674. @endexp=newexp
  675. @animatingEXP=true
  676. end
  677.  
  678. def appear
  679. refreshExpLevel
  680. refresh
  681. self.visible=true
  682. self.opacity=255
  683. if (@battler.index&1)==0 # if player's Pokémon
  684. self.x=@spriteX+320
  685. else
  686. self.x=@spriteX-320
  687. end
  688. self.y=@spriteY
  689. @appearing=true
  690. end
  691.  
  692. def refresh
  693. self.bitmap.clear
  694. return if !@battler.pokemon
  695. self.bitmap.blt(0,0,@databox.bitmap,Rect.new(0,0,@databox.width,@databox.height))
  696. base=PokeBattle_SceneConstants::BOXTEXTBASECOLOR
  697. shadow=PokeBattle_SceneConstants::BOXTEXTSHADOWCOLOR
  698. pokename=@battler.name
  699.  
  700. pbSetSystemFont(self.bitmap)
  701. textpos=[
  702. [pokename,@spritebaseX+8,6,false,base,shadow]
  703. ]
  704. genderX=self.bitmap.text_size(pokename).width
  705. genderX+=@spritebaseX+14
  706.  
  707. case @battler.displayGender
  708. when 0 # Male
  709. textpos.push([_INTL("♂"),genderX,6,false,Color.new(48,96,216),shadow])
  710. when 1 # Female
  711. textpos.push([_INTL("♀"),genderX,6,false,Color.new(248,88,40),shadow])
  712. end
  713. pbDrawTextPositions(self.bitmap,textpos)
  714.  
  715. pbSetSmallFont(self.bitmap)
  716. textpos=[
  717. [_INTL("Nv{1}",@battler.level),@spritebaseX+202,8,true,base,shadow]
  718. ]
  719. if @showhp
  720. hpstring=_ISPRINTF("{1: 2d}/{2: 2d}",self.hp,@battler.totalhp)
  721. textpos.push([hpstring,@spritebaseX+188,48,true,base,shadow])
  722. end
  723. pbDrawTextPositions(self.bitmap,textpos)
  724. imagepos=[]
  725. if @battler.isShiny?
  726. shinyX=206
  727. shinyX=-6 if (@battler.index&1)==0 # If player's Pokémon
  728. imagepos.push(["Graphics/Pictures/shiny.png",@spritebaseX+shinyX,36,0,0,-1,-1])
  729. end
  730. if @battler.isMega?
  731. imagepos.push(["Graphics/Pictures/battleMegaEvoBox.png",@spritebaseX+8,34,0,0,-1,-1])
  732. elsif @battler.isPrimal?
  733. if isConst?(@battler.pokemon.species,PBSpecies,:KYOGRE)
  734. imagepos.push(["Graphics/Pictures/battlePrimalKyogreBox.png",@spritebaseX+140,4,0,0,-1,-1])
  735. elsif isConst?(@battler.pokemon.species,PBSpecies,:GROUDON)
  736. imagepos.push(["Graphics/Pictures/battlePrimalGroudonBox.png",@spritebaseX+140,4,0,0,-1,-1])
  737. end
  738. end
  739. if @battler.owned && (@battler.index&1)==1
  740. imagepos.push(["Graphics/Pictures/battleBoxOwned.png",@spritebaseX+8,36,0,0,-1,-1])
  741. end
  742. pbDrawImagePositions(self.bitmap,imagepos)
  743. if @battler.status>0
  744.  
  745. self.bitmap.blt(@spritebaseX+24,36,@statuses.bitmap,
  746. Rect.new(0,(@battler.status-1)*16,44,16))
  747. end
  748. hpGaugeSize=PokeBattle_SceneConstants::HPGAUGESIZE
  749. hpgauge=@battler.totalhp==0 ? 0 : (self.hp*hpGaugeSize/@battler.totalhp)
  750. hpgauge=2 if hpgauge==0 && self.hp>0
  751. hpzone=0
  752. hpzone=1 if self.hp<=(@battler.totalhp/2).floor
  753. hpzone=2 if self.hp<=(@battler.totalhp/4).floor
  754. hpcolors=[
  755. PokeBattle_SceneConstants::HPCOLORGREENDARK,
  756. PokeBattle_SceneConstants::HPCOLORGREEN,
  757. PokeBattle_SceneConstants::HPCOLORYELLOWDARK,
  758. PokeBattle_SceneConstants::HPCOLORYELLOW,
  759. PokeBattle_SceneConstants::HPCOLORREDDARK,
  760. PokeBattle_SceneConstants::HPCOLORRED
  761. ]
  762. # fill with black (shows what the HP used to be)
  763. hpGaugeX=PokeBattle_SceneConstants::HPGAUGE_X
  764. hpGaugeY=PokeBattle_SceneConstants::HPGAUGE_Y
  765. if @animatingHP && self.hp>0
  766. self.bitmap.fill_rect(@spritebaseX+hpGaugeX,hpGaugeY,
  767. @starthp*hpGaugeSize/@battler.totalhp,6,Color.new(0,0,0))
  768. end
  769. # fill with HP color
  770. self.bitmap.fill_rect(@spritebaseX+hpGaugeX,hpGaugeY,hpgauge,2,hpcolors[hpzone*2])
  771. self.bitmap.fill_rect(@spritebaseX+hpGaugeX,hpGaugeY+2,hpgauge,4,hpcolors[hpzone*2+1])
  772.  
  773. if @showexp
  774. # fill with EXP color
  775. expGaugeX=PokeBattle_SceneConstants::EXPGAUGE_X
  776. expGaugeY=PokeBattle_SceneConstants::EXPGAUGE_Y
  777. self.bitmap.fill_rect(@spritebaseX+expGaugeX,expGaugeY,self.exp,2,
  778. PokeBattle_SceneConstants::EXPCOLORSHADOW)
  779. self.bitmap.fill_rect(@spritebaseX+expGaugeX,expGaugeY+2,self.exp,2,
  780. PokeBattle_SceneConstants::EXPCOLORBASE)
  781. end
  782. end
  783.  
  784. def update
  785. super
  786. @frame+=1
  787. if @animatingHP
  788. if @currenthp<@endhp
  789. @currenthp+=[1,(@battler.totalhp/PokeBattle_SceneConstants::HPGAUGESIZE).floor].max
  790. @currenthp=@endhp if @currenthp>@endhp
  791. elsif @currenthp>@endhp
  792. @currenthp-=[1,(@battler.totalhp/PokeBattle_SceneConstants::HPGAUGESIZE).floor].max
  793. @currenthp=@endhp if @currenthp<@endhp
  794. end
  795. @animatingHP=false if @currenthp==@endhp
  796. refresh
  797. end
  798. if @animatingEXP
  799. if !@showexp
  800. @currentexp=@endexp
  801. elsif @currentexp<@endexp # Gaining Exp
  802. if @endexp>=PokeBattle_SceneConstants::EXPGAUGESIZE ||
  803. @endexp-@currentexp>=PokeBattle_SceneConstants::EXPGAUGESIZE/4
  804. @currentexp+=4
  805. else
  806. @currentexp+=2
  807. end
  808. @currentexp=@endexp if @currentexp>@endexp
  809. elsif @currentexp>@endexp # Losing Exp
  810. if @endexp==0 ||
  811. @currentexp-@endexp>=PokeBattle_SceneConstants::EXPGAUGESIZE/4
  812. @currentexp-=4
  813. elsif @currentexp>@endexp
  814. @currentexp-=2
  815. end
  816. @currentexp=@endexp if @currentexp<@endexp
  817. end
  818. refresh
  819. if @currentexp==@endexp
  820. if @currentexp==PokeBattle_SceneConstants::EXPGAUGESIZE
  821. if @expflash==0
  822. pbSEPlay("expfull")
  823. self.flash(Color.new(64,200,248),8)
  824. @expflash=8
  825. else
  826. @expflash-=1
  827. if @expflash==0
  828. @animatingEXP=false
  829. refreshExpLevel
  830. end
  831. end
  832. else
  833. @animatingEXP=false
  834. end
  835. end
  836. end
  837. if @appearing
  838. if (@battler.index&1)==0 # if player's Pokémon
  839. self.x-=12
  840. self.x=@spriteX if self.x<@spriteX
  841. @appearing=false if self.x<=@spriteX
  842. else
  843. self.x+=12
  844. self.x=@spriteX if self.x>@spriteX
  845. @appearing=false if self.x>=@spriteX
  846. end
  847. self.y=@spriteY
  848. return
  849. end
  850. self.x=@spriteX
  851. self.y=@spriteY
  852. # Data box bobbing while Pokémon is selected
  853. if ((@frame/10).floor&1)==1 && @selected==1 # Choosing commands for this Pokémon
  854. self.y=@spriteY+2
  855. elsif ((@frame/10).floor&1)==1 && @selected==2 # When targeted or damaged
  856. self.y=@spriteY+2
  857. end
  858. end
  859. end
  860.  
  861.  
  862.  
  863. #===============================================================================
  864. # Shows the enemy trainer(s)'s Pokémon being thrown out. It appears at coords
  865. # (@spritex,@spritey), and moves in y to @endspritey where it stays for the rest
  866. # of the battle, i.e. the latter is the more important value.
  867. # Doesn't show the ball itself being thrown.
  868. #===============================================================================
  869. class PokeballSendOutAnimation
  870. SPRITESTEPS=10
  871. STARTZOOM=0.125
  872.  
  873. def initialize(sprite,spritehash,pkmn,illusionpoke,doublebattle)
  874. @illusionpoke=illusionpoke
  875. @disposed=false
  876. @ballused=pkmn.pokemon ? pkmn.pokemon.ballused : 0
  877. if @illusionpoke
  878. @ballused=@illusionpoke.ballused || 0
  879. end
  880. @PokemonBattlerSprite=sprite
  881. @PokemonBattlerSprite.visible=false
  882. @PokemonBattlerSprite.tone=Tone.new(248,248,248,248)
  883. @pokeballsprite=IconSprite.new(0,0,sprite.viewport)
  884. @pokeballsprite.setBitmap(sprintf("Graphics/Pictures/ball%02d",@ballused))
  885. if doublebattle
  886. @spritex=PokeBattle_SceneConstants::FOEBATTLERD1_X if pkmn.index==1
  887. @spritex=PokeBattle_SceneConstants::FOEBATTLERD2_X if pkmn.index==3
  888. else
  889. @spritex=PokeBattle_SceneConstants::FOEBATTLER_X
  890. end
  891. @spritey=0
  892. if @illusionpoke
  893. @endspritey=adjustBattleSpriteY(sprite,@illusionpoke.species,pkmn.index)
  894. else
  895. @endspritey=adjustBattleSpriteY(sprite,pkmn.species,pkmn.index)
  896. end
  897. if doublebattle
  898. @spritey=PokeBattle_SceneConstants::FOEBATTLERD1_Y if pkmn.index==1
  899. @spritey=PokeBattle_SceneConstants::FOEBATTLERD2_Y if pkmn.index==3
  900. @endspritey+=PokeBattle_SceneConstants::FOEBATTLERD1_Y if pkmn.index==1
  901. @endspritey+=PokeBattle_SceneConstants::FOEBATTLERD2_Y if pkmn.index==3
  902. else
  903. @spritey=PokeBattle_SceneConstants::FOEBATTLER_Y
  904. @endspritey+=PokeBattle_SceneConstants::FOEBATTLER_Y
  905. end
  906. @spritehash=spritehash
  907. @pokeballsprite.x=@spritex-@pokeballsprite.bitmap.width/2
  908. @pokeballsprite.y=@spritey-@pokeballsprite.bitmap.height/2-4
  909. @pokeballsprite.z=@PokemonBattlerSprite.z+1
  910. @pkmn=pkmn
  911. @shadowX=@spritex
  912. @shadowY=@spritey
  913. if @spritehash["shadow#{@pkmn.index}"] && @spritehash["shadow#{@pkmn.index}"].bitmap!=nil
  914. @shadowX-=@spritehash["shadow#{@pkmn.index}"].bitmap.width/2
  915. @shadowY-=@spritehash["shadow#{@pkmn.index}"].bitmap.height/2
  916. end
  917. @shadowVisible=showShadow?(pkmn.species)
  918. if @illusionpoke
  919. @shadowVisible=showShadow?(@illusionpoke.species)
  920. end
  921. @stepspritey=(@spritey-@endspritey)
  922. @zoomstep=(1.0-STARTZOOM)/SPRITESTEPS
  923. @animdone=false
  924. @frame=0
  925. end
  926.  
  927. def disposed?
  928. return @disposed
  929. end
  930.  
  931. def animdone?
  932. return @animdone
  933. end
  934.  
  935. def dispose
  936. return if disposed?
  937. @pokeballsprite.dispose
  938. @disposed=true
  939. end
  940.  
  941. def update
  942. return if disposed?
  943. @pokeballsprite.update
  944. @frame+=1
  945. if @frame==2
  946. pbSEPlay("recall")
  947. end
  948. if @frame==4
  949. @PokemonBattlerSprite.visible=true
  950. @PokemonBattlerSprite.zoom_x=STARTZOOM
  951. @PokemonBattlerSprite.zoom_y=STARTZOOM
  952. pbSpriteSetCenter(@PokemonBattlerSprite,@spritex,@spritey)
  953. if @illusionpoke
  954. pbPlayCry(@illusionpoke)
  955. else
  956. pbPlayCry(@pkmn.pokemon ? @pkmn.pokemon : @pkmn.species)
  957.  
  958.  
  959.  
  960.  
  961. end
  962. @pokeballsprite.setBitmap(sprintf("Graphics/Pictures/ball%02d_open",@ballused))
  963. end
  964. if @frame==8
  965. @pokeballsprite.visible=false
  966. end
  967. if @frame>8 && @frame<=16
  968. color=Color.new(248,248,248,256-(16-@frame)*32)
  969. @spritehash["enemybase"].color=color
  970. @spritehash["playerbase"].color=color
  971. @spritehash["battlebg"].color=color
  972. for i in 0...4
  973. @spritehash["shadow#{i}"].color=color if @spritehash["shadow#{i}"]
  974. end
  975. end
  976. if @frame>16 && @frame<=24
  977. color=Color.new(248,248,248,(24-@frame)*32)
  978. tone=(24-@frame)*32
  979. @PokemonBattlerSprite.tone=Tone.new(tone,tone,tone,tone)
  980. @spritehash["enemybase"].color=color
  981. @spritehash["playerbase"].color=color
  982. @spritehash["battlebg"].color=color
  983. for i in 0...4
  984. @spritehash["shadow#{i}"].color=color if @spritehash["shadow#{i}"]
  985. end
  986. end
  987. if @frame>5 && @PokemonBattlerSprite.zoom_x<1.0
  988. @PokemonBattlerSprite.zoom_x+=@zoomstep
  989. @PokemonBattlerSprite.zoom_y+=@zoomstep
  990. @PokemonBattlerSprite.zoom_x=1.0 if @PokemonBattlerSprite.zoom_x > 1.0
  991. @PokemonBattlerSprite.zoom_y=1.0 if @PokemonBattlerSprite.zoom_y > 1.0
  992. currentY=@spritey-(@stepspritey*@PokemonBattlerSprite.zoom_y)
  993. pbSpriteSetCenter(@PokemonBattlerSprite,@spritex,currentY)
  994. @PokemonBattlerSprite.y=currentY
  995. end
  996. if @PokemonBattlerSprite.tone.gray<=0 && @PokemonBattlerSprite.zoom_x>=1.0
  997. @animdone=true
  998. if @spritehash["shadow#{@pkmn.index}"]
  999. @spritehash["shadow#{@pkmn.index}"].x=@shadowX
  1000. @spritehash["shadow#{@pkmn.index}"].y=@shadowY
  1001. @spritehash["shadow#{@pkmn.index}"].visible=@shadowVisible
  1002. end
  1003. end
  1004. end
  1005. end
  1006.  
  1007.  
  1008.  
  1009. #===============================================================================
  1010. # Shows the player's (or partner's) Pokémon being thrown out. It appears at
  1011. # (@spritex,@spritey), and moves in y to @endspritey where it stays for the rest
  1012. # of the battle, i.e. the latter is the more important value.
  1013. # Doesn't show the ball itself being thrown.
  1014. #===============================================================================
  1015. class PokeballPlayerSendOutAnimation
  1016. # Ball curve: 8,52; 22,44; 52, 96
  1017. # Player: Color.new(16*8,23*8,30*8)
  1018. SPRITESTEPS=10
  1019. STARTZOOM=0.125
  1020.  
  1021. def initialize(sprite,spritehash,pkmn,illusionpoke,doublebattle)
  1022. @illusionpoke=illusionpoke
  1023. @disposed=false
  1024. @PokemonBattlerSprite=sprite
  1025. @pkmn=pkmn
  1026. @PokemonBattlerSprite.visible=false
  1027. @PokemonBattlerSprite.tone=Tone.new(248,248,248,248)
  1028. @spritehash=spritehash
  1029. if doublebattle
  1030. @spritex=PokeBattle_SceneConstants::PLAYERBATTLERD1_X if pkmn.index==0
  1031. @spritex=PokeBattle_SceneConstants::PLAYERBATTLERD2_X if pkmn.index==2
  1032. else
  1033. @spritex=PokeBattle_SceneConstants::PLAYERBATTLER_X
  1034. end
  1035. @spritey=0
  1036. if @illusionpoke
  1037. @endspritey=adjustBattleSpriteY(sprite,@illusionpoke.species,pkmn.index)
  1038. else
  1039. @endspritey=adjustBattleSpriteY(sprite,pkmn.species,pkmn.index)
  1040. end
  1041. if doublebattle
  1042. @spritey+=PokeBattle_SceneConstants::PLAYERBATTLERD1_Y if pkmn.index==0
  1043. @spritey+=PokeBattle_SceneConstants::PLAYERBATTLERD2_Y if pkmn.index==2
  1044. @endspritey+=PokeBattle_SceneConstants::PLAYERBATTLERD1_Y if pkmn.index==0
  1045. @endspritey+=PokeBattle_SceneConstants::PLAYERBATTLERD2_Y if pkmn.index==2
  1046. else
  1047. @spritey+=PokeBattle_SceneConstants::PLAYERBATTLER_Y
  1048. @endspritey+=PokeBattle_SceneConstants::PLAYERBATTLER_Y
  1049. end
  1050. @animdone=false
  1051. @frame=0
  1052. end
  1053.  
  1054. def disposed?
  1055. return @disposed
  1056. end
  1057.  
  1058. def animdone?
  1059. return @animdone
  1060. end
  1061.  
  1062. def dispose
  1063. return if disposed?
  1064. @disposed=true
  1065. end
  1066.  
  1067. def update
  1068. return if disposed?
  1069. @frame+=1
  1070. if @frame==4
  1071. @PokemonBattlerSprite.visible=true
  1072. @PokemonBattlerSprite.zoom_x=STARTZOOM
  1073. @PokemonBattlerSprite.zoom_y=STARTZOOM
  1074. pbSEPlay("recall")
  1075. pbSpriteSetCenter(@PokemonBattlerSprite,@spritex,@spritey)
  1076. if @illusionpoke
  1077. pbPlayCry(@illusionpoke)
  1078. else
  1079. pbPlayCry(@pkmn.pokemon ? @pkmn.pokemon : @pkmn.species)
  1080. end
  1081. end
  1082. if @frame>8 && @frame<=16
  1083. color=Color.new(248,248,248,256-(16-@frame)*32)
  1084. @spritehash["enemybase"].color=color
  1085. @spritehash["playerbase"].color=color
  1086. @spritehash["battlebg"].color=color
  1087. for i in 0...4
  1088. @spritehash["shadow#{i}"].color=color if @spritehash["shadow#{i}"]
  1089. end
  1090. end
  1091. if @frame>16 && @frame<=24
  1092. color=Color.new(248,248,248,(24-@frame)*32)
  1093. tone=(24-@frame)*32
  1094. @PokemonBattlerSprite.tone=Tone.new(tone,tone,tone,tone)
  1095. @spritehash["enemybase"].color=color
  1096. @spritehash["playerbase"].color=color
  1097. @spritehash["battlebg"].color=color
  1098. for i in 0...4
  1099. @spritehash["shadow#{i}"].color=color if @spritehash["shadow#{i}"]
  1100. end
  1101. end
  1102. if @frame>5 && @PokemonBattlerSprite.zoom_x<1.0
  1103. @PokemonBattlerSprite.zoom_x+=0.1
  1104. @PokemonBattlerSprite.zoom_y+=0.1
  1105. @PokemonBattlerSprite.zoom_x=1.0 if @PokemonBattlerSprite.zoom_x > 1.0
  1106. @PokemonBattlerSprite.zoom_y=1.0 if @PokemonBattlerSprite.zoom_y > 1.0
  1107. pbSpriteSetCenter(@PokemonBattlerSprite,@spritex,0)
  1108. @PokemonBattlerSprite.y=@spritey+(@endspritey-@spritey)*@PokemonBattlerSprite.zoom_y
  1109. end
  1110. if @PokemonBattlerSprite.tone.gray<=0 && @PokemonBattlerSprite.zoom_x>=1.0
  1111. @animdone=true
  1112. end
  1113. end
  1114. end
  1115.  
  1116.  
  1117.  
  1118. #===============================================================================
  1119. # Shows the enemy trainer(s) and the enemy party lineup sliding off screen.
  1120. # Doesn't show the ball thrown or the Pokémon.
  1121. #===============================================================================
  1122. class TrainerFadeAnimation
  1123. def initialize(sprites)
  1124. @frame=0
  1125. @sprites=sprites
  1126. @animdone=false
  1127. end
  1128.  
  1129. def animdone?
  1130. return @animdone
  1131. end
  1132.  
  1133. def update
  1134. return if @animdone
  1135. @frame+=1
  1136. @sprites["trainer"].x+=8
  1137. @sprites["trainer2"].x+=8 if @sprites["trainer2"]
  1138. @sprites["partybarfoe"].x+=8
  1139. @sprites["partybarfoe"].opacity-=12
  1140. for i in 0...6
  1141. @sprites["enemy#{i}"].opacity-=12
  1142. @sprites["enemy#{i}"].x+=8 if @frame>=i*4
  1143. end
  1144. @animdone=true if @sprites["trainer"].x>=Graphics.width &&
  1145. (!@sprites["trainer2"] || @sprites["trainer2"].x>=Graphics.width)
  1146. end
  1147. end
  1148.  
  1149.  
  1150.  
  1151. #===============================================================================
  1152. # Shows the player (and partner) and the player party lineup sliding off screen.
  1153. # Shows the player's/partner's throwing animation (if they have one).
  1154. # Doesn't show the ball thrown or the Pokémon.
  1155. #===============================================================================
  1156. class PlayerFadeAnimation
  1157. def initialize(sprites)
  1158. @frame=0
  1159. @sprites=sprites
  1160. @animdone=false
  1161. end
  1162.  
  1163. def animdone?
  1164. return @animdone
  1165. end
  1166.  
  1167. def update
  1168. return if @animdone
  1169. @frame+=1
  1170. @sprites["player"].x-=8
  1171. @sprites["playerB"].x-=8 if @sprites["playerB"]
  1172. @sprites["partybarplayer"].x-=8
  1173. @sprites["partybarplayer"].opacity-=12
  1174. for i in 0...6
  1175. if @sprites["player#{i}"]
  1176. @sprites["player#{i}"].opacity-=12
  1177. @sprites["player#{i}"].x-=8 if @frame>=i*4
  1178. end
  1179. end
  1180. pa=@sprites["player"]
  1181. pb=@sprites["playerB"]
  1182. pawidth=128
  1183. pbwidth=128
  1184. if (pa && pa.bitmap && !pa.bitmap.disposed?)
  1185. if pa.bitmap.height<pa.bitmap.width
  1186. numframes=pa.bitmap.width/pa.bitmap.height # Number of frames
  1187. pawidth=pa.bitmap.width/numframes # Width per frame
  1188. @sprites["player"].src_rect.x=pawidth*1 if @frame>0
  1189. @sprites["player"].src_rect.x=pawidth*2 if @frame>8
  1190. @sprites["player"].src_rect.x=pawidth*3 if @frame>12
  1191. @sprites["player"].src_rect.x=pawidth*4 if @frame>16
  1192. @sprites["player"].src_rect.width=pawidth
  1193. else
  1194. pawidth=pa.bitmap.width
  1195. @sprites["player"].src_rect.x=0
  1196. @sprites["player"].src_rect.width=pawidth
  1197. end
  1198. end
  1199. if (pb && pb.bitmap && !pb.bitmap.disposed?)
  1200. if pb.bitmap.height<pb.bitmap.width
  1201. numframes=pb.bitmap.width/pb.bitmap.height # Number of frames
  1202. pbwidth=pb.bitmap.width/numframes # Width per frame
  1203. @sprites["playerB"].src_rect.x=pbwidth*1 if @frame>0
  1204. @sprites["playerB"].src_rect.x=pbwidth*2 if @frame>8
  1205. @sprites["playerB"].src_rect.x=pbwidth*3 if @frame>12
  1206. @sprites["playerB"].src_rect.x=pbwidth*4 if @frame>16
  1207. @sprites["playerB"].src_rect.width=pbwidth
  1208. else
  1209. pbwidth=pb.bitmap.width
  1210. @sprites["playerB"].src_rect.x=0
  1211. @sprites["playerB"].src_rect.width=pbwidth
  1212. end
  1213. end
  1214. if pb
  1215. @animdone=true if pb.x<=-pbwidth
  1216. else
  1217. @animdone=true if pa.x<=-pawidth
  1218. end
  1219. end
  1220. end
  1221.  
  1222.  
  1223.  
  1224. #===============================================================================
  1225. # Shows the player's Poké Ball being thrown to capture a Pokémon.
  1226. #===============================================================================
  1227. def pokeballThrow(ball,shakes,critical,targetBattler,scene,battler,burst=-1,showplayer=false)
  1228. balltype=pbGetBallType(ball)
  1229. animtrainer=false
  1230. if showplayer && @sprites["player"].bitmap.width>@sprites["player"].bitmap.height
  1231. animtrainer=true
  1232. end
  1233. oldvisible=@sprites["shadow#{targetBattler}"].visible
  1234. @sprites["shadow#{targetBattler}"].visible=false
  1235. ball=sprintf("Graphics/Pictures/ball%02d",balltype)
  1236. ballopen=sprintf("Graphics/Pictures/ball%02d_open",balltype)
  1237. # sprites
  1238. spritePoke=@sprites["pokemon#{targetBattler}"]
  1239. spriteBall=IconSprite.new(0,0,@viewport)
  1240. spriteBall.visible=false
  1241. spritePlayer=@sprites["player"] if animtrainer
  1242. # pictures
  1243. pictureBall=PictureEx.new(spritePoke.z+1)
  1244. picturePoke=PictureEx.new(spritePoke.z)
  1245. dims=[spritePoke.x,spritePoke.y]
  1246. center=getSpriteCenter(@sprites["pokemon#{targetBattler}"])
  1247. if @battle.doublebattle
  1248. ballendy=PokeBattle_SceneConstants::FOEBATTLERD1_Y-4 if targetBattler==1
  1249. ballendy=PokeBattle_SceneConstants::FOEBATTLERD2_Y-4 if targetBattler==3
  1250. else
  1251. ballendy=PokeBattle_SceneConstants::FOEBATTLER_Y-4
  1252. end
  1253. if animtrainer
  1254. picturePlayer=PictureEx.new(spritePoke.z+2)
  1255. playerpos=[@sprites["player"].x,@sprites["player"].y]
  1256. end
  1257. # starting positions
  1258. pictureBall.moveVisible(1,true)
  1259. pictureBall.moveName(1,ball)
  1260. pictureBall.moveOrigin(1,PictureOrigin::Center)
  1261. if animtrainer
  1262. pictureBall.moveXY(0,1,64,256)
  1263. else
  1264. pictureBall.moveXY(0,1,10,180)
  1265. end
  1266. picturePoke.moveVisible(1,true)
  1267. picturePoke.moveOrigin(1,PictureOrigin::Center)
  1268. picturePoke.moveXY(0,1,center[0],center[1])
  1269. if animtrainer
  1270. picturePlayer.moveVisible(1,true)
  1271. picturePlayer.moveName(1,spritePlayer.name)
  1272. picturePlayer.moveOrigin(1,PictureOrigin::TopLeft)
  1273. picturePlayer.moveXY(0,1,playerpos[0],playerpos[1])
  1274. end
  1275. # directives
  1276. picturePoke.moveSE(1,"Audio/SE/throw")
  1277. if animtrainer
  1278. pictureBall.moveCurve(30,1,64,256,30+Graphics.width/2,10,center[0],center[1])
  1279. pictureBall.moveAngle(30,1,-720)
  1280. else
  1281. pictureBall.moveCurve(30,1,150,70,30+Graphics.width/2,10,center[0],center[1])
  1282. pictureBall.moveAngle(30,1,-1080)
  1283. end
  1284. pictureBall.moveAngle(0,pictureBall.totalDuration,0)
  1285. delay=pictureBall.totalDuration+4
  1286. picturePoke.moveTone(10,delay,Tone.new(0,-224,-224,0))
  1287. delay=picturePoke.totalDuration
  1288. picturePoke.moveSE(delay,"Audio/SE/recall")
  1289. pictureBall.moveName(delay+4,ballopen)
  1290. if animtrainer
  1291. picturePlayer.moveSrc(1,@sprites["player"].bitmap.height,0)
  1292. picturePlayer.moveXY(0,1,playerpos[0]-14,playerpos[1])
  1293. picturePlayer.moveSrc(4,@sprites["player"].bitmap.height*2,0)
  1294. picturePlayer.moveXY(0,4,playerpos[0]-12,playerpos[1])
  1295. picturePlayer.moveSrc(8,@sprites["player"].bitmap.height*3,0)
  1296. picturePlayer.moveXY(0,8,playerpos[0]+20,playerpos[1])
  1297. picturePlayer.moveSrc(16,@sprites["player"].bitmap.height*4,0)
  1298. picturePlayer.moveXY(0,16,playerpos[0]+16,playerpos[1])
  1299. picturePlayer.moveSrc(40,0,0)
  1300. picturePlayer.moveXY(0,40,playerpos[0],playerpos[1])
  1301. end
  1302. loop do
  1303. pictureBall.update
  1304. picturePoke.update
  1305. picturePlayer.update if animtrainer
  1306. setPictureIconSprite(spriteBall,pictureBall)
  1307. setPictureSprite(spritePoke,picturePoke)
  1308. setPictureIconSprite(spritePlayer,picturePlayer) if animtrainer
  1309. pbGraphicsUpdate
  1310. pbInputUpdate
  1311. pbFrameUpdate
  1312. break if !pictureBall.running? && !picturePoke.running?
  1313. end
  1314. # Burst animation here
  1315. if burst>=0 && scene.battle.battlescene
  1316. scene.pbCommonAnimation("BallBurst#{burst}",battler,nil)
  1317. end
  1318. pictureBall.clearProcesses
  1319. picturePoke.clearProcesses
  1320. delay=0
  1321. picturePoke.moveZoom(15,delay,0)
  1322. picturePoke.moveXY(15,delay,center[0],center[1])
  1323. picturePoke.moveSE(delay+10,"Audio/SE/jumptoball")
  1324. picturePoke.moveVisible(delay+15,false)
  1325. pictureBall.moveName(picturePoke.totalDuration+2,ball)
  1326. delay=pictureBall.totalDuration+6
  1327. if critical
  1328. pictureBall.moveSE(delay,"Audio/SE/ballshake")
  1329. pictureBall.moveXY(2,delay,center[0]+4,center[1])
  1330. pictureBall.moveXY(4,pictureBall.totalDuration,center[0]-4,center[1])
  1331. pictureBall.moveSE(pictureBall.totalDuration,"Audio/SE/ballshake")
  1332. pictureBall.moveXY(4,pictureBall.totalDuration,center[0]+4,center[1])
  1333. pictureBall.moveXY(4,pictureBall.totalDuration,center[0]-4,center[1])
  1334. pictureBall.moveXY(2,pictureBall.totalDuration,center[0],center[1])
  1335. delay=pictureBall.totalDuration+4
  1336. end
  1337. pictureBall.moveXY(10,delay,center[0],ballendy)
  1338. pictureBall.moveSE(pictureBall.totalDuration,"Audio/SE/balldrop")
  1339. pictureBall.moveXY(5,pictureBall.totalDuration+2,center[0],ballendy-((ballendy-center[1])/2))
  1340. pictureBall.moveXY(5,pictureBall.totalDuration+2,center[0],ballendy)
  1341. pictureBall.moveSE(pictureBall.totalDuration,"Audio/SE/balldrop")
  1342. pictureBall.moveXY(3,pictureBall.totalDuration+2,center[0],ballendy-((ballendy-center[1])/4))
  1343. pictureBall.moveXY(3,pictureBall.totalDuration+2,center[0],ballendy)
  1344. pictureBall.moveSE(pictureBall.totalDuration,"Audio/SE/balldrop")
  1345. pictureBall.moveXY(1,pictureBall.totalDuration+2,center[0],ballendy-((ballendy-center[1])/8))
  1346. pictureBall.moveXY(1,pictureBall.totalDuration+2,center[0],ballendy)
  1347. pictureBall.moveSE(pictureBall.totalDuration,"Audio/SE/balldrop")
  1348. picturePoke.moveXY(0,pictureBall.totalDuration,center[0],ballendy)
  1349. delay=pictureBall.totalDuration+18# if shakes==0
  1350. [shakes,3].min.times do
  1351.  
  1352. pictureBall.moveSE(delay,"Audio/SE/ballshake")
  1353. pictureBall.moveXY(3,delay,center[0]-8,ballendy)
  1354. pictureBall.moveAngle(3,delay,20) # positive means counterclockwise
  1355. delay=pictureBall.totalDuration
  1356. pictureBall.moveXY(6,delay,center[0]+8,ballendy)
  1357. pictureBall.moveAngle(6,delay,-20) # negative means clockwise
  1358. delay=pictureBall.totalDuration
  1359. pictureBall.moveXY(3,delay,center[0],ballendy)
  1360. pictureBall.moveAngle(3,delay,0)
  1361. delay=pictureBall.totalDuration+18
  1362. end
  1363. if shakes<4
  1364. picturePoke.moveSE(delay,"Audio/SE/recall")
  1365. pictureBall.moveName(delay,ballopen)
  1366. pictureBall.moveVisible(delay+10,false)
  1367. picturePoke.moveVisible(delay,true)
  1368. picturePoke.moveZoom(15,delay,100)
  1369. picturePoke.moveXY(15,delay,center[0],center[1])
  1370. picturePoke.moveTone(0,delay,Tone.new(248,248,248,248))
  1371. picturePoke.moveTone(24,delay,Tone.new(0,0,0,0))
  1372. delay=picturePoke.totalDuration
  1373. end
  1374. pictureBall.moveXY(0,delay,center[0],ballendy)
  1375. picturePoke.moveOrigin(picturePoke.totalDuration,PictureOrigin::TopLeft)
  1376. picturePoke.moveXY(0,picturePoke.totalDuration,dims[0],dims[1])
  1377. loop do
  1378. pictureBall.update
  1379. picturePoke.update
  1380. setPictureIconSprite(spriteBall,pictureBall)
  1381. setPictureSprite(spritePoke,picturePoke)
  1382. pbGraphicsUpdate
  1383. pbInputUpdate
  1384. pbFrameUpdate
  1385. break if !pictureBall.running? && !picturePoke.running?
  1386. end
  1387. if shakes<4
  1388. @sprites["shadow#{targetBattler}"].visible=oldvisible
  1389. spriteBall.dispose
  1390. else
  1391. spriteBall.tone=Tone.new(-64,-64,-64,128)
  1392. pbSEPlay("balldrop",100,150)
  1393. @sprites["capture"]=spriteBall
  1394. spritePoke.visible=false
  1395. end
  1396. end
  1397.  
  1398.  
  1399.  
  1400. #===============================================================================
  1401. # Battle scene (the visuals of the battle)
  1402. #===============================================================================
  1403. class PokeBattle_Scene
  1404. attr_accessor :abortable
  1405. attr_reader :viewport
  1406. attr_reader :sprites
  1407.  
  1408. BLANK = 0
  1409. MESSAGEBOX = 1
  1410. COMMANDBOX = 2
  1411. FIGHTBOX = 3
  1412.  
  1413. def initialize
  1414. @battle=nil
  1415. @lastcmd=[0,0,0,0]
  1416. @lastmove=[0,0,0,0]
  1417. @pkmnwindows=[nil,nil,nil,nil]
  1418. @sprites={}
  1419. @battlestart=true
  1420. @messagemode=false
  1421. @abortable=false
  1422. @aborted=false
  1423. end
  1424.  
  1425. def pbUpdate
  1426. partyAnimationUpdate
  1427. @sprites["battlebg"].update if @sprites["battlebg"].respond_to?("update")
  1428. end
  1429.  
  1430. def pbGraphicsUpdate
  1431. partyAnimationUpdate
  1432. @sprites["battlebg"].update if @sprites["battlebg"].respond_to?("update")
  1433. Graphics.update
  1434. end
  1435.  
  1436. def pbInputUpdate
  1437. Input.update
  1438. if Input.trigger?(Input::B) && @abortable && !@aborted
  1439. @aborted=true
  1440. @battle.pbAbort
  1441. end
  1442. end
  1443.  
  1444. def pbShowWindow(windowtype)
  1445. @sprites["messagebox"].visible = (windowtype==MESSAGEBOX)# ||
  1446. #windowtype==COMMANDBOX ||
  1447. #windowtype==FIGHTBOX ||
  1448. #windowtype==FIGHTBOX )
  1449. #windowtype==BLANK )
  1450. @sprites["messagewindow"].visible = (windowtype==MESSAGEBOX)
  1451. @sprites["commandwindow"].visible = (windowtype==COMMANDBOX)
  1452. @sprites["fightwindow"].visible = (windowtype==FIGHTBOX)
  1453. end
  1454.  
  1455. def pbSetMessageMode(mode)
  1456. @messagemode=mode
  1457. msgwindow=@sprites["messagewindow"]
  1458. if mode # Within Pokémon command
  1459. msgwindow.baseColor=PokeBattle_SceneConstants::MENUBASECOLOR
  1460. msgwindow.shadowColor=PokeBattle_SceneConstants::MENUSHADOWCOLOR
  1461. #msgwindow.baseColor=PokeBattle_SceneConstants::MENUBASECOLOR2
  1462. #msgwindow.shadowColor=PokeBattle_SceneConstants::MENUSHADOWCOLOR2
  1463. msgwindow.opacity=255
  1464. msgwindow.x=16
  1465. msgwindow.width=Graphics.width
  1466. msgwindow.height=96
  1467. msgwindow.y=Graphics.height-msgwindow.height+2
  1468. else
  1469. #msgwindow.baseColor=PokeBattle_SceneConstants::MESSAGEBASECOLOR
  1470. #msgwindow.shadowColor=PokeBattle_SceneConstants::MESSAGESHADOWCOLOR
  1471. msgwindow.baseColor=PokeBattle_SceneConstants::MESSAGEBASECOLOR2
  1472. msgwindow.shadowColor=PokeBattle_SceneConstants::MESSAGESHADOWCOLOR2
  1473. msgwindow.opacity=0
  1474. msgwindow.x=16
  1475. msgwindow.width=Graphics.width-32
  1476. #msgwindow.height=96
  1477. #msgwindow.y=Graphics.height-msgwindow.height+2
  1478. msgwindow.height=60
  1479. msgwindow.y=Graphics.height-msgwindow.height#+2
  1480. end
  1481. end
  1482.  
  1483. def pbWaitMessage
  1484. if @briefmessage
  1485. pbShowWindow(MESSAGEBOX)
  1486. cw=@sprites["messagewindow"]
  1487. 60.times do
  1488. pbGraphicsUpdate
  1489. pbInputUpdate
  1490. pbFrameUpdate(cw)
  1491. end
  1492. cw.text=""
  1493. cw.visible=false
  1494. @briefmessage=false
  1495. end
  1496. end
  1497.  
  1498. def pbDisplay(msg,brief=false)
  1499. pbDisplayMessage(msg,brief)
  1500. end
  1501.  
  1502. def pbDisplayMessage(msg,brief=false)
  1503. pbWaitMessage
  1504. pbRefresh
  1505. pbShowWindow(MESSAGEBOX)
  1506. cw=@sprites["messagewindow"]
  1507. cw.text=msg
  1508. i=0
  1509. loop do
  1510. pbGraphicsUpdate
  1511. pbInputUpdate
  1512. pbFrameUpdate(cw)
  1513. if i==40
  1514. cw.text=""
  1515. cw.visible=false
  1516. return
  1517. end
  1518. if Input.trigger?(Input::C) || @abortable
  1519. if cw.pausing?
  1520. pbPlayDecisionSE() if !@abortable
  1521. cw.resume
  1522. end
  1523. end
  1524. if !cw.busy?
  1525. if brief
  1526. @briefmessage=true
  1527. return
  1528. end
  1529. i+=1
  1530. end
  1531. end
  1532. end
  1533.  
  1534. def pbDisplayPausedMessage(msg)
  1535. pbWaitMessage
  1536. pbRefresh
  1537. pbShowWindow(MESSAGEBOX)
  1538. if @messagemode
  1539. @switchscreen.pbDisplay(msg)
  1540. return
  1541. end
  1542. cw=@sprites["messagewindow"]
  1543. cw.text=_ISPRINTF("{1:s}\1",msg)
  1544. loop do
  1545. pbGraphicsUpdate
  1546. pbInputUpdate
  1547. pbFrameUpdate(cw)
  1548. if Input.trigger?(Input::C) || @abortable
  1549. if cw.busy?
  1550. pbPlayDecisionSE() if cw.pausing? && !@abortable
  1551. cw.resume
  1552. elsif !inPartyAnimation?
  1553. cw.text=""
  1554. pbPlayDecisionSE()
  1555. cw.visible=false if @messagemode
  1556. return
  1557. end
  1558. end
  1559. cw.update
  1560. end
  1561. end
  1562.  
  1563. def pbDisplayConfirmMessage(msg)
  1564. return pbShowCommands(msg,[_INTL("Si"),_INTL("No")],1)==0
  1565. end
  1566.  
  1567. def pbShowCommands(msg,commands,defaultValue)
  1568. pbWaitMessage
  1569. pbRefresh
  1570. pbShowWindow(MESSAGEBOX)
  1571. dw=@sprites["messagewindow"]
  1572. dw.text=msg
  1573. cw = Window_CommandPokemon.new(commands)
  1574. cw.x=Graphics.width-cw.width
  1575. cw.y=Graphics.height-cw.height-dw.height
  1576. cw.index=0
  1577. cw.viewport=@viewport
  1578. pbRefresh
  1579. loop do
  1580. cw.visible=!dw.busy?
  1581. pbGraphicsUpdate
  1582. pbInputUpdate
  1583. pbFrameUpdate(cw)
  1584. dw.update
  1585. if Input.trigger?(Input::B) && defaultValue>=0
  1586. if dw.busy?
  1587. pbPlayDecisionSE() if dw.pausing?
  1588. dw.resume
  1589. else
  1590. cw.dispose
  1591. dw.text=""
  1592. return defaultValue
  1593. end
  1594. end
  1595. if Input.trigger?(Input::C)
  1596. if dw.busy?
  1597. pbPlayDecisionSE() if dw.pausing?
  1598. dw.resume
  1599. else
  1600. cw.dispose
  1601. dw.text=""
  1602. return cw.index
  1603. end
  1604. end
  1605. end
  1606. end
  1607.  
  1608. def pbFrameUpdate(cw=nil)
  1609. cw.update if cw
  1610. for i in 0...4
  1611. if @sprites["battlebox#{i}"]
  1612. @sprites["battlebox#{i}"].update
  1613. end
  1614. if @sprites["pokemon#{i}"]
  1615. @sprites["pokemon#{i}"].update
  1616. end
  1617. end
  1618. end
  1619.  
  1620. def pbRefresh
  1621. for i in 0...4
  1622. if @sprites["battlebox#{i}"]
  1623. @sprites["battlebox#{i}"].refresh
  1624. end
  1625. end
  1626. end
  1627.  
  1628. def pbAddSprite(id,x,y,filename,viewport)
  1629. sprite=IconSprite.new(x,y,viewport)
  1630. if filename
  1631. sprite.setBitmap(filename) rescue nil
  1632. end
  1633. @sprites[id]=sprite
  1634. return sprite
  1635. end
  1636.  
  1637. def pbAddPlane(id,filename,viewport)
  1638. sprite=AnimatedPlane.new(viewport)
  1639. if filename
  1640. sprite.setBitmap(filename)
  1641. end
  1642. @sprites[id]=sprite
  1643. return sprite
  1644. end
  1645.  
  1646. def pbDisposeSprites
  1647. pbDisposeSpriteHash(@sprites)
  1648. end
  1649.  
  1650. def pbBeginCommandPhase
  1651. # Called whenever a new round begins.
  1652. @battlestart=false
  1653. end
  1654.  
  1655. def pbShowOpponent(index)
  1656. if @battle.opponent
  1657. if @battle.opponent.is_a?(Array)
  1658. trainerfile=pbTrainerSpriteFile(@battle.opponent[index].trainertype)
  1659. else
  1660. trainerfile=pbTrainerSpriteFile(@battle.opponent.trainertype)
  1661. end
  1662. else
  1663. trainerfile="Graphics/Characters/trfront"
  1664. end
  1665. pbAddSprite("trainer",Graphics.width,PokeBattle_SceneConstants::FOETRAINER_Y,
  1666. trainerfile,@viewport)
  1667. if @sprites["trainer"].bitmap
  1668. @sprites["trainer"].y-=@sprites["trainer"].bitmap.height
  1669. @sprites["trainer"].z=8
  1670. end
  1671. 20.times do
  1672. pbGraphicsUpdate
  1673. pbInputUpdate
  1674. pbFrameUpdate
  1675. @sprites["trainer"].x-=6
  1676. end
  1677. end
  1678.  
  1679. def pbHideOpponent
  1680. 20.times do
  1681. pbGraphicsUpdate
  1682. pbInputUpdate
  1683. pbFrameUpdate
  1684. @sprites["trainer"].x+=6
  1685. end
  1686. end
  1687.  
  1688. def pbShowHelp(text)
  1689. @sprites["helpwindow"].resizeToFit(text,Graphics.width)
  1690. @sprites["helpwindow"].y=0
  1691. @sprites["helpwindow"].x=0
  1692. @sprites["helpwindow"].text=text
  1693. @sprites["helpwindow"].visible=true
  1694. end
  1695.  
  1696. def pbHideHelp
  1697. @sprites["helpwindow"].visible=false
  1698. end
  1699.  
  1700. def pbBackdrop
  1701. environ=@battle.environment
  1702. # Choose backdrop
  1703. backdrop="Field"
  1704. if environ==PBEnvironment::Cave
  1705. backdrop="Cave"
  1706. elsif environ==PBEnvironment::MovingWater || environ==PBEnvironment::StillWater
  1707. backdrop="Water"
  1708. elsif environ==PBEnvironment::Underwater
  1709. backdrop="Underwater"
  1710. elsif environ==PBEnvironment::Rock
  1711. backdrop="Mountain"
  1712. else
  1713. if !$game_map || !pbGetMetadata($game_map.map_id,MetadataOutdoor)
  1714. backdrop="IndoorA"
  1715. end
  1716. end
  1717. if $game_map
  1718. back=pbGetMetadata($game_map.map_id,MetadataBattleBack)
  1719. if back && back!=""
  1720. backdrop=back
  1721. end
  1722. end
  1723. if $PokemonGlobal && $PokemonGlobal.nextBattleBack
  1724. backdrop=$PokemonGlobal.nextBattleBack
  1725. end
  1726. # Choose bases
  1727. base=""
  1728. trialname=""
  1729. if environ==PBEnvironment::Grass || environ==PBEnvironment::TallGrass
  1730. trialname="Grass"
  1731. elsif environ==PBEnvironment::Sand
  1732. trialname="Sand"
  1733. elsif $PokemonGlobal.surfing
  1734. trialname="Water"
  1735. end
  1736. if pbResolveBitmap(sprintf("Graphics/Battlebacks/playerbase"+backdrop+trialname))
  1737. base=trialname
  1738. end
  1739. # Choose time of day
  1740. time=""
  1741. if ENABLESHADING
  1742. trialname=""
  1743. timenow=pbGetTimeNow
  1744. if PBDayNight.isNight?(timenow)
  1745. trialname="Night"
  1746. elsif PBDayNight.isEvening?(timenow)
  1747. trialname="Eve"
  1748. end
  1749. if pbResolveBitmap(sprintf("Graphics/Battlebacks/battlebg"+backdrop+trialname))
  1750. time=trialname
  1751. end
  1752. end
  1753. # Apply graphics
  1754. battlebg="Graphics/Battlebacks/battlebg"+backdrop+time
  1755. enemybase="Graphics/Battlebacks/enemybase"+backdrop+base+time
  1756. playerbase="Graphics/Battlebacks/playerbase"+backdrop+base+time
  1757. pbAddPlane("battlebg",battlebg,@viewport)
  1758. pbAddSprite("playerbase",
  1759. PokeBattle_SceneConstants::PLAYERBASEX,
  1760. PokeBattle_SceneConstants::PLAYERBASEY,playerbase,@viewport)
  1761. @sprites["playerbase"].x-=@sprites["playerbase"].bitmap.width/2 if @sprites["playerbase"].bitmap!=nil
  1762. @sprites["playerbase"].y-=@sprites["playerbase"].bitmap.height if @sprites["playerbase"].bitmap!=nil
  1763. pbAddSprite("enemybase",
  1764. PokeBattle_SceneConstants::FOEBASEX,
  1765. PokeBattle_SceneConstants::FOEBASEY,enemybase,@viewport)
  1766. @sprites["enemybase"].x-=@sprites["enemybase"].bitmap.width/2 if @sprites["enemybase"].bitmap!=nil
  1767. @sprites["enemybase"].y-=@sprites["enemybase"].bitmap.height/2 if @sprites["enemybase"].bitmap!=nil
  1768. @sprites["battlebg"].z=0
  1769. @sprites["playerbase"].z=1
  1770. @sprites["enemybase"].z=1
  1771. end
  1772.  
  1773. # Returns whether the party line-ups are currently appearing on-screen
  1774. def inPartyAnimation?
  1775. return @enablePartyAnim && @partyAnimPhase<3
  1776. end
  1777.  
  1778. # Shows the party line-ups appearing on-screen
  1779. def partyAnimationUpdate
  1780. return if !inPartyAnimation?
  1781. ballmovedist=16 # How far a ball moves each frame
  1782. # Bar slides on
  1783. if @partyAnimPhase==0
  1784. @sprites["partybarfoe"].x+=16
  1785. @sprites["partybarplayer"].x-=16
  1786. if @sprites["partybarfoe"].x+@sprites["partybarfoe"].bitmap.width>=PokeBattle_SceneConstants::FOEPARTYBAR_X
  1787. @sprites["partybarfoe"].x=PokeBattle_SceneConstants::FOEPARTYBAR_X-@sprites["partybarfoe"].bitmap.width
  1788. @sprites["partybarplayer"].x=PokeBattle_SceneConstants::PLAYERPARTYBAR_X
  1789. @partyAnimPhase=1
  1790. end
  1791. return
  1792. end
  1793. # Set up all balls ready to slide on
  1794. if @partyAnimPhase==1
  1795. @xposplayer=PokeBattle_SceneConstants::PLAYERPARTYBALL1_X
  1796. counter=0
  1797. # Make sure the ball starts off-screen
  1798. while @xposplayer<Graphics.width
  1799. counter+=1; @xposplayer+=ballmovedist
  1800. end
  1801. @xposenemy=PokeBattle_SceneConstants::FOEPARTYBALL1_X-counter*ballmovedist
  1802. for i in 0...6
  1803. # Choose the ball's graphic (player's side)
  1804. ballgraphic="Graphics/Pictures/ballempty"
  1805. if i<@battle.party1.length && @battle.party1[i]
  1806. if @battle.party1[i].hp<=0 || @battle.party1[i].isEgg?
  1807. ballgraphic="Graphics/Pictures/ballfainted"
  1808. elsif @battle.party1[i].status>0
  1809. ballgraphic="Graphics/Pictures/ballstatus"
  1810. else
  1811. ballgraphic="Graphics/Pictures/ballnormal"
  1812. end
  1813. end
  1814. pbAddSprite("player#{i}",
  1815. @xposplayer+i*ballmovedist*6,PokeBattle_SceneConstants::PLAYERPARTYBALL1_Y,
  1816. ballgraphic,@viewport)
  1817. @sprites["player#{i}"].z=41
  1818. # Choose the ball's graphic (opponent's side)
  1819. ballgraphic="Graphics/Pictures/ballempty"
  1820. enemyindex=i
  1821. if @battle.doublebattle && i>=3
  1822. enemyindex=(i%3)+@battle.pbSecondPartyBegin(1)
  1823. end
  1824. if enemyindex<@battle.party2.length && @battle.party2[enemyindex]
  1825. if @battle.party2[enemyindex].hp<=0 || @battle.party2[enemyindex].isEgg?
  1826. ballgraphic="Graphics/Pictures/ballfainted"
  1827. elsif @battle.party2[enemyindex].status>0
  1828. ballgraphic="Graphics/Pictures/ballstatus"
  1829. else
  1830. ballgraphic="Graphics/Pictures/ballnormal"
  1831. end
  1832. end
  1833. pbAddSprite("enemy#{i}",
  1834. @xposenemy-i*ballmovedist*6,PokeBattle_SceneConstants::FOEPARTYBALL1_Y,
  1835. ballgraphic,@viewport)
  1836. @sprites["enemy#{i}"].z=41
  1837. end
  1838. @partyAnimPhase=2
  1839. end
  1840. # Balls slide on
  1841. if @partyAnimPhase==2
  1842. for i in 0...6
  1843. if @sprites["enemy#{i}"].x<PokeBattle_SceneConstants::FOEPARTYBALL1_X-i*PokeBattle_SceneConstants::FOEPARTYBALL_GAP
  1844. @sprites["enemy#{i}"].x+=ballmovedist
  1845. @sprites["player#{i}"].x-=ballmovedist
  1846. if @sprites["enemy#{i}"].x>=PokeBattle_SceneConstants::FOEPARTYBALL1_X-i*PokeBattle_SceneConstants::FOEPARTYBALL_GAP
  1847. @sprites["enemy#{i}"].x=PokeBattle_SceneConstants::FOEPARTYBALL1_X-i*PokeBattle_SceneConstants::FOEPARTYBALL_GAP
  1848. @sprites["player#{i}"].x=PokeBattle_SceneConstants::PLAYERPARTYBALL1_X+i*PokeBattle_SceneConstants::PLAYERPARTYBALL_GAP
  1849. if i==5
  1850. @partyAnimPhase=3
  1851. end
  1852. end
  1853. end
  1854. end
  1855. end
  1856. end
  1857.  
  1858. def pbStartBattle(battle)
  1859. # Called whenever the battle begins
  1860. @battle=battle
  1861. @lastcmd=[0,0,0,0]
  1862. @lastmove=[0,0,0,0]
  1863. @showingplayer=true
  1864. @showingenemy=true
  1865. @sprites.clear
  1866. @viewport=Viewport.new(0,Graphics.height/2,Graphics.width,0)
  1867. @viewport.z=99999
  1868. @traineryoffset=(Graphics.height-320) # Adjust player's side for screen size
  1869. @foeyoffset=(@traineryoffset*3/4).floor # Adjust foe's side for screen size
  1870. pbBackdrop
  1871. pbAddSprite("partybarfoe",
  1872. PokeBattle_SceneConstants::FOEPARTYBAR_X,
  1873. PokeBattle_SceneConstants::FOEPARTYBAR_Y,
  1874. "Graphics/Pictures/battleLineup",@viewport)
  1875. pbAddSprite("partybarplayer",
  1876. PokeBattle_SceneConstants::PLAYERPARTYBAR_X,
  1877. PokeBattle_SceneConstants::PLAYERPARTYBAR_Y,
  1878. "Graphics/Pictures/battleLineup",@viewport)
  1879. @sprites["partybarfoe"].x-=@sprites["partybarfoe"].bitmap.width
  1880. @sprites["partybarplayer"].mirror=true
  1881. @sprites["partybarfoe"].z=40
  1882. @sprites["partybarplayer"].z=40
  1883. @sprites["partybarfoe"].visible=false
  1884. @sprites["partybarplayer"].visible=false
  1885. if @battle.player.is_a?(Array)
  1886. trainerfile=pbPlayerSpriteBackFile(@battle.player[0].trainertype)
  1887. pbAddSprite("player",
  1888. PokeBattle_SceneConstants::PLAYERTRAINERD1_X,
  1889. PokeBattle_SceneConstants::PLAYERTRAINERD1_Y,trainerfile,@viewport)
  1890. trainerfile=pbTrainerSpriteBackFile(@battle.player[1].trainertype)
  1891. pbAddSprite("playerB",
  1892. PokeBattle_SceneConstants::PLAYERTRAINERD2_X,
  1893. PokeBattle_SceneConstants::PLAYERTRAINERD2_Y,trainerfile,@viewport)
  1894. if @sprites["player"].bitmap
  1895. if @sprites["player"].bitmap.width>@sprites["player"].bitmap.height
  1896. @sprites["player"].src_rect.x=0
  1897. @sprites["player"].src_rect.width=@sprites["player"].bitmap.width/5
  1898. end
  1899. @sprites["player"].x-=(@sprites["player"].src_rect.width/2)
  1900. @sprites["player"].y-=@sprites["player"].bitmap.height
  1901. @sprites["player"].z=30
  1902. end
  1903. if @sprites["playerB"].bitmap
  1904. if @sprites["playerB"].bitmap.width>@sprites["playerB"].bitmap.height
  1905. @sprites["playerB"].src_rect.x=0
  1906. @sprites["playerB"].src_rect.width=@sprites["playerB"].bitmap.width/5
  1907. end
  1908. @sprites["playerB"].x-=(@sprites["playerB"].src_rect.width/2)
  1909. @sprites["playerB"].y-=@sprites["playerB"].bitmap.height
  1910. @sprites["playerB"].z=31
  1911. end
  1912. else
  1913. trainerfile=pbPlayerSpriteBackFile(@battle.player.trainertype)
  1914. pbAddSprite("player",
  1915. PokeBattle_SceneConstants::PLAYERTRAINER_X,
  1916. PokeBattle_SceneConstants::PLAYERTRAINER_Y,trainerfile,@viewport)
  1917. if @sprites["player"].bitmap
  1918. if @sprites["player"].bitmap.width>@sprites["player"].bitmap.height
  1919. @sprites["player"].src_rect.x=0
  1920. @sprites["player"].src_rect.width=@sprites["player"].bitmap.width/5
  1921. end
  1922. @sprites["player"].x-=(@sprites["player"].src_rect.width/2)
  1923. @sprites["player"].y-=@sprites["player"].bitmap.height
  1924. @sprites["player"].z=30
  1925. end
  1926. end
  1927. if @battle.opponent
  1928. if @battle.opponent.is_a?(Array)
  1929. trainerfile=pbTrainerSpriteFile(@battle.opponent[1].trainertype)
  1930. pbAddSprite("trainer2",
  1931. PokeBattle_SceneConstants::FOETRAINERD2_X,
  1932. PokeBattle_SceneConstants::FOETRAINERD2_Y,trainerfile,@viewport)
  1933. trainerfile=pbTrainerSpriteFile(@battle.opponent[0].trainertype)
  1934. pbAddSprite("trainer",
  1935. PokeBattle_SceneConstants::FOETRAINERD1_X,
  1936. PokeBattle_SceneConstants::FOETRAINERD1_Y,trainerfile,@viewport)
  1937. else
  1938. trainerfile=pbTrainerSpriteFile(@battle.opponent.trainertype)
  1939. pbAddSprite("trainer",
  1940. PokeBattle_SceneConstants::FOETRAINER_X,
  1941. PokeBattle_SceneConstants::FOETRAINER_Y,trainerfile,@viewport)
  1942. end
  1943. else
  1944. trainerfile="Graphics/Characters/trfront"
  1945. pbAddSprite("trainer",
  1946. PokeBattle_SceneConstants::FOETRAINER_X,
  1947. PokeBattle_SceneConstants::FOETRAINER_Y,trainerfile,@viewport)
  1948. end
  1949. if @sprites["trainer"].bitmap
  1950. @sprites["trainer"].x-=(@sprites["trainer"].bitmap.width/2)
  1951. @sprites["trainer"].y-=@sprites["trainer"].bitmap.height
  1952. @sprites["trainer"].z=8
  1953. end
  1954. if @sprites["trainer2"] && @sprites["trainer2"].bitmap
  1955. @sprites["trainer2"].x-=(@sprites["trainer2"].bitmap.width/2)
  1956. @sprites["trainer2"].y-=@sprites["trainer2"].bitmap.height
  1957. @sprites["trainer2"].z=7
  1958. end
  1959. @sprites["shadow0"]=IconSprite.new(0,0,@viewport)
  1960. @sprites["shadow0"].z=3
  1961. pbAddSprite("shadow1",0,0,"Graphics/Pictures/battleShadow",@viewport)
  1962. @sprites["shadow1"].z=3
  1963. @sprites["shadow1"].visible=false
  1964. @sprites["pokemon0"]=PokemonBattlerSprite.new(battle.doublebattle,0,@viewport)
  1965. @sprites["pokemon0"].z=21
  1966. @sprites["pokemon1"]=PokemonBattlerSprite.new(battle.doublebattle,1,@viewport)
  1967. @sprites["pokemon1"].z=16
  1968. if battle.doublebattle
  1969. @sprites["shadow2"]=IconSprite.new(0,0,@viewport)
  1970. @sprites["shadow2"].z=3
  1971. pbAddSprite("shadow3",0,0,"Graphics/Pictures/battleShadow",@viewport)
  1972. @sprites["shadow3"].z=3
  1973. @sprites["shadow3"].visible=false
  1974. @sprites["pokemon2"]=PokemonBattlerSprite.new(battle.doublebattle,2,@viewport)
  1975. @sprites["pokemon2"].z=26
  1976. @sprites["pokemon3"]=PokemonBattlerSprite.new(battle.doublebattle,3,@viewport)
  1977. @sprites["pokemon3"].z=11
  1978. end
  1979. @sprites["battlebox0"]=PokemonDataBox.new(battle.battlers[0],battle.doublebattle,@viewport)
  1980. @sprites["battlebox1"]=PokemonDataBox.new(battle.battlers[1],battle.doublebattle,@viewport)
  1981. if battle.doublebattle
  1982. @sprites["battlebox2"]=PokemonDataBox.new(battle.battlers[2],battle.doublebattle,@viewport)
  1983. @sprites["battlebox3"]=PokemonDataBox.new(battle.battlers[3],battle.doublebattle,@viewport)
  1984. end
  1985. #pbAddSprite("messagebox",0,Graphics.height-96,"Graphics/Pictures/battleMessage",@viewport)
  1986. pbAddSprite("messagebox",0,Graphics.height-60,"Graphics/Pictures/BatallaMessage",@viewport)#82
  1987.  
  1988. @sprites["messagebox"].z=90
  1989. @sprites["helpwindow"]=Window_UnformattedTextPokemon.newWithSize("",0,0,32,32,@viewport)
  1990. @sprites["helpwindow"].visible=false
  1991. @sprites["helpwindow"].z=90
  1992.  
  1993. @sprites["messagewindow"]=Window_AdvancedTextPokemon.new("")
  1994. @sprites["messagewindow"].letterbyletter=true
  1995. @sprites["messagewindow"].viewport=@viewport
  1996. @sprites["messagewindow"].z=100
  1997. @sprites["commandwindow"]=CommandMenuDisplay.new(@viewport)
  1998. @sprites["commandwindow"].z=100
  1999. @sprites["fightwindow"]=FightMenuDisplay.new(nil,@viewport)
  2000. @sprites["fightwindow"].z=100
  2001. pbShowWindow(MESSAGEBOX)
  2002. pbSetMessageMode(false)
  2003. trainersprite1=@sprites["trainer"]
  2004. trainersprite2=@sprites["trainer2"]
  2005. if !@battle.opponent
  2006. @sprites["trainer"].visible=false
  2007. if @battle.party2.length>=1
  2008. if @battle.party2.length==1
  2009. species=@battle.party2[0].species
  2010. @sprites["pokemon1"].setPokemonBitmap(@battle.party2[0],false)
  2011. @sprites["pokemon1"].tone=Tone.new(-128,-128,-128,-128)
  2012. @sprites["pokemon1"].x=PokeBattle_SceneConstants::FOEBATTLER_X
  2013. @sprites["pokemon1"].x-=@sprites["pokemon1"].width/2
  2014. @sprites["pokemon1"].y=PokeBattle_SceneConstants::FOEBATTLER_Y
  2015. @sprites["pokemon1"].y+=adjustBattleSpriteY(@sprites["pokemon1"],species,1)
  2016. @sprites["pokemon1"].visible=true
  2017. @sprites["shadow1"].x=PokeBattle_SceneConstants::FOEBATTLER_X
  2018. @sprites["shadow1"].y=PokeBattle_SceneConstants::FOEBATTLER_Y
  2019. @sprites["shadow1"].x-=@sprites["shadow1"].bitmap.width/2 if @sprites["shadow1"].bitmap!=nil
  2020. @sprites["shadow1"].y-=@sprites["shadow1"].bitmap.height/2 if @sprites["shadow1"].bitmap!=nil
  2021. @sprites["shadow1"].visible=showShadow?(species)
  2022. trainersprite1=@sprites["pokemon1"]
  2023. elsif @battle.party2.length==2
  2024. species=@battle.party2[0].species
  2025. @sprites["pokemon1"].setPokemonBitmap(@battle.party2[0],false)
  2026. @sprites["pokemon1"].tone=Tone.new(-128,-128,-128,-128)
  2027. @sprites["pokemon1"].x=PokeBattle_SceneConstants::FOEBATTLERD1_X
  2028. @sprites["pokemon1"].x-=@sprites["pokemon1"].width/2
  2029. @sprites["pokemon1"].y=PokeBattle_SceneConstants::FOEBATTLERD1_Y
  2030. @sprites["pokemon1"].y+=adjustBattleSpriteY(@sprites["pokemon1"],species,1)
  2031. @sprites["pokemon1"].visible=true
  2032. @sprites["shadow1"].x=PokeBattle_SceneConstants::FOEBATTLERD1_X
  2033. @sprites["shadow1"].y=PokeBattle_SceneConstants::FOEBATTLERD1_Y
  2034. @sprites["shadow1"].x-=@sprites["shadow1"].bitmap.width/2 if @sprites["shadow1"].bitmap!=nil
  2035. @sprites["shadow1"].y-=@sprites["shadow1"].bitmap.height/2 if @sprites["shadow1"].bitmap!=nil
  2036. @sprites["shadow1"].visible=showShadow?(species)
  2037. trainersprite1=@sprites["pokemon1"]
  2038. species=@battle.party2[1].species
  2039. @sprites["pokemon3"].setPokemonBitmap(@battle.party2[1],false)
  2040. @sprites["pokemon3"].tone=Tone.new(-128,-128,-128,-128)
  2041. @sprites["pokemon3"].x=PokeBattle_SceneConstants::FOEBATTLERD2_X
  2042. @sprites["pokemon3"].x-=@sprites["pokemon3"].width/2
  2043. @sprites["pokemon3"].y=PokeBattle_SceneConstants::FOEBATTLERD2_Y
  2044. @sprites["pokemon3"].y+=adjustBattleSpriteY(@sprites["pokemon3"],species,3)
  2045. @sprites["pokemon3"].visible=true
  2046. @sprites["shadow3"].x=PokeBattle_SceneConstants::FOEBATTLERD2_X
  2047. @sprites["shadow3"].y=PokeBattle_SceneConstants::FOEBATTLERD2_Y
  2048. @sprites["shadow3"].x-=@sprites["shadow3"].bitmap.width/2 if @sprites["shadow3"].bitmap!=nil
  2049. @sprites["shadow3"].y-=@sprites["shadow3"].bitmap.height/2 if @sprites["shadow3"].bitmap!=nil
  2050. @sprites["shadow3"].visible=showShadow?(species)
  2051. trainersprite2=@sprites["pokemon3"]
  2052. end
  2053. end
  2054. end
  2055. #################
  2056. # Move trainers/bases/etc. off-screen
  2057. oldx=[]
  2058. oldx[0]=@sprites["playerbase"].x; @sprites["playerbase"].x+=Graphics.width
  2059. oldx[1]=@sprites["player"].x; @sprites["player"].x+=Graphics.width
  2060. if @sprites["playerB"]
  2061. oldx[2]=@sprites["playerB"].x; @sprites["playerB"].x+=Graphics.width
  2062. end
  2063. oldx[3]=@sprites["enemybase"].x; @sprites["enemybase"].x-=Graphics.width
  2064. oldx[4]=trainersprite1.x; trainersprite1.x-=Graphics.width
  2065. if trainersprite2
  2066. oldx[5]=trainersprite2.x; trainersprite2.x-=Graphics.width
  2067. end
  2068. oldx[6]=@sprites["shadow1"].x; @sprites["shadow1"].x-=Graphics.width
  2069. if @sprites["shadow3"]
  2070. oldx[7]=@sprites["shadow3"].x; @sprites["shadow3"].x-=Graphics.width
  2071. end
  2072. @sprites["partybarfoe"].x-=PokeBattle_SceneConstants::FOEPARTYBAR_X
  2073. @sprites["partybarplayer"].x+=Graphics.width-PokeBattle_SceneConstants::PLAYERPARTYBAR_X
  2074. #################
  2075. appearspeed=12
  2076. (1+Graphics.width/appearspeed).times do
  2077. tobreak=true
  2078. if @viewport.rect.y>0
  2079. @viewport.rect.y-=appearspeed/2
  2080. @viewport.rect.y=0 if @viewport.rect.y<0
  2081. @viewport.rect.height+=appearspeed
  2082. @viewport.rect.height=Graphics.height if @viewport.rect.height>Graphics.height
  2083. tobreak=false
  2084. end
  2085. if !tobreak
  2086. for i in @sprites
  2087. i[1].ox=@viewport.rect.x
  2088. i[1].oy=@viewport.rect.y
  2089. end
  2090. end
  2091. if @sprites["playerbase"].x>oldx[0]
  2092. @sprites["playerbase"].x-=appearspeed; tobreak=false
  2093. @sprites["playerbase"].x=oldx[0] if @sprites["playerbase"].x<oldx[0]
  2094. end
  2095. if @sprites["player"].x>oldx[1]
  2096. @sprites["player"].x-=appearspeed; tobreak=false
  2097. @sprites["player"].x=oldx[1] if @sprites["player"].x<oldx[1]
  2098. end
  2099. if @sprites["playerB"] && @sprites["playerB"].x>oldx[2]
  2100. @sprites["playerB"].x-=appearspeed; tobreak=false
  2101. @sprites["playerB"].x=oldx[2] if @sprites["playerB"].x<oldx[2]
  2102. end
  2103. if @sprites["enemybase"].x<oldx[3]
  2104. @sprites["enemybase"].x+=appearspeed; tobreak=false
  2105. @sprites["enemybase"].x=oldx[3] if @sprites["enemybase"].x>oldx[3]
  2106. end
  2107. if trainersprite1.x<oldx[4]
  2108. trainersprite1.x+=appearspeed; tobreak=false
  2109. trainersprite1.x=oldx[4] if trainersprite1.x>oldx[4]
  2110. end
  2111. if trainersprite2 && trainersprite2.x<oldx[5]
  2112. trainersprite2.x+=appearspeed; tobreak=false
  2113. trainersprite2.x=oldx[5] if trainersprite2.x>oldx[5]
  2114. end
  2115. if @sprites["shadow1"].x<oldx[6]
  2116. @sprites["shadow1"].x+=appearspeed; tobreak=false
  2117. @sprites["shadow1"].x=oldx[6] if @sprites["shadow1"].x>oldx[6]
  2118. end
  2119. if @sprites["shadow3"] && @sprites["shadow3"].x<oldx[7]
  2120. @sprites["shadow3"].x+=appearspeed; tobreak=false
  2121. @sprites["shadow3"].x=oldx[7] if @sprites["shadow3"].x>oldx[7]
  2122. end
  2123. pbGraphicsUpdate
  2124. pbInputUpdate
  2125. pbFrameUpdate
  2126. break if tobreak
  2127. end
  2128. #################
  2129. if @battle.opponent
  2130. @enablePartyAnim=true
  2131. @partyAnimPhase=0
  2132. @sprites["partybarfoe"].visible=true
  2133. @sprites["partybarplayer"].visible=true
  2134. else
  2135. pbPlayCry(@battle.party2[0]) # Play cry for wild Pokémon
  2136. @sprites["battlebox1"].appear
  2137. @sprites["battlebox3"].appear if @battle.party2.length==2
  2138. appearing=true
  2139. begin
  2140. pbGraphicsUpdate
  2141. pbInputUpdate
  2142. pbFrameUpdate
  2143. @sprites["pokemon1"].tone.red+=8 if @sprites["pokemon1"].tone.red<0
  2144. @sprites["pokemon1"].tone.blue+=8 if @sprites["pokemon1"].tone.blue<0
  2145. @sprites["pokemon1"].tone.green+=8 if @sprites["pokemon1"].tone.green<0
  2146. @sprites["pokemon1"].tone.gray+=8 if @sprites["pokemon1"].tone.gray<0
  2147. appearing=@sprites["battlebox1"].appearing
  2148. if @battle.party2.length==2
  2149. @sprites["pokemon3"].tone.red+=8 if @sprites["pokemon3"].tone.red<0
  2150. @sprites["pokemon3"].tone.blue+=8 if @sprites["pokemon3"].tone.blue<0
  2151. @sprites["pokemon3"].tone.green+=8 if @sprites["pokemon3"].tone.green<0
  2152. @sprites["pokemon3"].tone.gray+=8 if @sprites["pokemon3"].tone.gray<0
  2153. appearing=(appearing || @sprites["battlebox3"].appearing)
  2154. end
  2155. end while appearing
  2156. # Show shiny animation for wild Pokémon
  2157. if @battle.battlers[1].isShiny? && @battle.battlescene
  2158. pbCommonAnimation("Shiny",@battle.battlers[1],nil)
  2159. end
  2160. if @battle.party2.length==2
  2161. if @battle.battlers[3].isShiny? && @battle.battlescene
  2162. pbCommonAnimation("Shiny",@battle.battlers[3],nil)
  2163. end
  2164. end
  2165. end
  2166. end
  2167.  
  2168. def pbEndBattle(result)
  2169. @abortable=false
  2170. pbShowWindow(BLANK)
  2171. # Fade out all sprites
  2172. pbBGMFade(1.0)
  2173. pbFadeOutAndHide(@sprites)
  2174. pbDisposeSprites
  2175. end
  2176.  
  2177. def pbRecall(battlerindex)
  2178. @briefmessage=false
  2179. if @battle.pbIsOpposing?(battlerindex)
  2180. origin=PokeBattle_SceneConstants::FOEBATTLER_Y
  2181. if @battle.doublebattle
  2182. origin=PokeBattle_SceneConstants::FOEBATTLERD1_Y if battlerindex==1
  2183. origin=PokeBattle_SceneConstants::FOEBATTLERD2_Y if battlerindex==3
  2184. end
  2185. @sprites["shadow#{battlerindex}"].visible=false
  2186. else
  2187. origin=PokeBattle_SceneConstants::PLAYERBATTLER_Y
  2188. if @battle.doublebattle
  2189. origin=PokeBattle_SceneConstants::PLAYERBATTLERD1_Y if battlerindex==0
  2190. origin=PokeBattle_SceneConstants::PLAYERBATTLERD2_Y if battlerindex==2
  2191. end
  2192. end
  2193. spritePoke=@sprites["pokemon#{battlerindex}"]
  2194. picturePoke=PictureEx.new(spritePoke.z)
  2195. dims=[spritePoke.x,spritePoke.y]
  2196. center=getSpriteCenter(spritePoke)
  2197. # starting positions
  2198. picturePoke.moveVisible(1,true)
  2199. picturePoke.moveOrigin(1,PictureOrigin::Center)
  2200. picturePoke.moveXY(0,1,center[0],center[1])
  2201. # directives
  2202. picturePoke.moveTone(10,1,Tone.new(248,248,248,248))
  2203. delay=picturePoke.totalDuration
  2204. picturePoke.moveSE(delay,"Audio/SE/recall")
  2205. picturePoke.moveZoom(15,delay,0)
  2206. picturePoke.moveXY(15,delay,center[0],origin)
  2207. picturePoke.moveVisible(picturePoke.totalDuration,false)
  2208. picturePoke.moveTone(0,picturePoke.totalDuration,Tone.new(0,0,0,0))
  2209. picturePoke.moveOrigin(picturePoke.totalDuration,PictureOrigin::TopLeft)
  2210. loop do
  2211. picturePoke.update
  2212. setPictureSprite(spritePoke,picturePoke)
  2213. pbGraphicsUpdate
  2214. pbInputUpdate
  2215. pbFrameUpdate
  2216. break if !picturePoke.running?
  2217. end
  2218. end
  2219.  
  2220. def pbTrainerSendOut(battlerindex,pkmn)
  2221. illusionpoke=@battle.battlers[battlerindex].effects[PBEffects::Illusion]
  2222. @briefmessage=false
  2223. fadeanim=nil
  2224. while inPartyAnimation?; end
  2225. if @showingenemy
  2226. fadeanim=TrainerFadeAnimation.new(@sprites)
  2227. end
  2228. frame=0
  2229. @sprites["pokemon#{battlerindex}"].setPokemonBitmap(pkmn,false)
  2230. if illusionpoke
  2231. @sprites["pokemon#{battlerindex}"].setPokemonBitmap(illusionpoke,false)
  2232. end
  2233. sendout=PokeballSendOutAnimation.new(@sprites["pokemon#{battlerindex}"],
  2234. @sprites,@battle.battlers[battlerindex],illusionpoke,@battle.doublebattle)
  2235. loop do
  2236. fadeanim.update if fadeanim
  2237. frame+=1
  2238. if frame==1
  2239. @sprites["battlebox#{battlerindex}"].appear
  2240. end
  2241. if frame>=10
  2242. sendout.update
  2243. end
  2244. pbGraphicsUpdate
  2245. pbInputUpdate
  2246. pbFrameUpdate
  2247. break if (!fadeanim || fadeanim.animdone?) && sendout.animdone? &&
  2248. !@sprites["battlebox#{battlerindex}"].appearing
  2249. end
  2250. if @battle.battlers[battlerindex].isShiny? && @battle.battlescene
  2251. pbCommonAnimation("Shiny",@battle.battlers[battlerindex],nil)
  2252. end
  2253. sendout.dispose
  2254. if @showingenemy
  2255. @showingenemy=false
  2256. pbDisposeSprite(@sprites,"trainer")
  2257. pbDisposeSprite(@sprites,"partybarfoe")
  2258. for i in 0...6
  2259. pbDisposeSprite(@sprites,"enemy#{i}")
  2260. end
  2261. end
  2262. pbRefresh
  2263. end
  2264.  
  2265. def pbSendOut(battlerindex,pkmn) # Player sending out Pokémon
  2266. while inPartyAnimation?; end
  2267. illusionpoke=@battle.battlers[battlerindex].effects[PBEffects::Illusion]
  2268. balltype=pkmn.ballused
  2269. balltype=illusionpoke.ballused if illusionpoke
  2270. ballbitmap=sprintf("Graphics/Pictures/ball%02d",balltype)
  2271. pictureBall=PictureEx.new(32)
  2272. delay=1
  2273. pictureBall.moveVisible(delay,true)
  2274. pictureBall.moveName(delay,ballbitmap)
  2275. pictureBall.moveOrigin(delay,PictureOrigin::Center)
  2276. # Setting the ball's movement path
  2277. path=[[0, 146], [10, 134], [21, 122], [30, 112],
  2278. [39, 104], [46, 99], [53, 95], [61, 93],
  2279. [68, 93], [75, 96], [82, 102], [89, 111],
  2280. [94, 121], [100, 134], [106, 150], [111, 166],
  2281. [116, 183], [120, 199], [124, 216], [127, 238]]
  2282. spriteBall=IconSprite.new(0,0,@viewport)
  2283. spriteBall.visible=false
  2284. angle=0
  2285. multiplier=1.0
  2286. if @battle.doublebattle
  2287. multiplier=(battlerindex==0) ? 0.7 : 1.3
  2288. end
  2289. for coord in path
  2290. delay=pictureBall.totalDuration
  2291. pictureBall.moveAngle(0,delay,angle)
  2292. pictureBall.moveXY(1,delay,coord[0]*multiplier,coord[1])
  2293. angle+=40
  2294. angle%=360
  2295. end
  2296. #pictureBall.adjustPosition(0,@traineryoffset)
  2297. pictureBall.adjustPosition(0,(Graphics.height-220))
  2298.  
  2299. @sprites["battlebox#{battlerindex}"].visible=false
  2300. @briefmessage=false
  2301. fadeanim=nil
  2302. if @showingplayer
  2303. fadeanim=PlayerFadeAnimation.new(@sprites)
  2304. end
  2305. frame=0
  2306. @sprites["pokemon#{battlerindex}"].setPokemonBitmap(pkmn,true)
  2307. if illusionpoke
  2308. @sprites["pokemon#{battlerindex}"].setPokemonBitmap(illusionpoke,true)
  2309. end
  2310. sendout=PokeballPlayerSendOutAnimation.new(@sprites["pokemon#{battlerindex}"],
  2311. @sprites,@battle.battlers[battlerindex],illusionpoke,@battle.doublebattle)
  2312. loop do
  2313. fadeanim.update if fadeanim
  2314. frame+=1
  2315. if frame>1 && !pictureBall.running? && !@sprites["battlebox#{battlerindex}"].appearing
  2316. @sprites["battlebox#{battlerindex}"].appear
  2317. end
  2318. if frame>=3 && !pictureBall.running?
  2319. sendout.update
  2320. end
  2321. if (frame>=10 || !fadeanim) && pictureBall.running?
  2322. pictureBall.update
  2323. setPictureIconSprite(spriteBall,pictureBall)
  2324. end
  2325. pbGraphicsUpdate
  2326. pbInputUpdate
  2327. pbFrameUpdate
  2328. break if (!fadeanim || fadeanim.animdone?) && sendout.animdone? &&
  2329. !@sprites["battlebox#{battlerindex}"].appearing
  2330. end
  2331. spriteBall.dispose
  2332. sendout.dispose
  2333. if @battle.battlers[battlerindex].isShiny? && @battle.battlescene
  2334. pbCommonAnimation("Shiny",@battle.battlers[battlerindex],nil)
  2335. end
  2336. if @showingplayer
  2337. @showingplayer=false
  2338. pbDisposeSprite(@sprites,"player")
  2339. pbDisposeSprite(@sprites,"partybarplayer")
  2340. for i in 0...6
  2341. pbDisposeSprite(@sprites,"player#{i}")
  2342. end
  2343. end
  2344. pbRefresh
  2345. end
  2346.  
  2347. def pbTrainerWithdraw(battle,pkmn)
  2348. pbRefresh
  2349. end
  2350.  
  2351. def pbWithdraw(battle,pkmn)
  2352. pbRefresh
  2353. end
  2354.  
  2355. def pbMoveString(move)
  2356. ret=_INTL("{1}",move.name)
  2357. typename=PBTypes.getName(move.type)
  2358. if move.id>0
  2359. ret+=_INTL(" ({1}) PP: {2}/{3}",typename,move.pp,move.totalpp)
  2360. end
  2361. return ret
  2362. end
  2363.  
  2364. def pbBeginAttackPhase
  2365. pbSelectBattler(-1)
  2366. pbGraphicsUpdate
  2367. end
  2368.  
  2369. def pbSafariStart
  2370. @briefmessage=false
  2371. @sprites["battlebox0"]=SafariDataBox.new(@battle,@viewport)
  2372. @sprites["battlebox0"].appear
  2373. loop do
  2374. @sprites["battlebox0"].update
  2375. pbGraphicsUpdate
  2376. pbInputUpdate
  2377. pbFrameUpdate
  2378. break if !@sprites["battlebox0"].appearing
  2379. end
  2380. pbRefresh
  2381. end
  2382.  
  2383. def pbResetCommandIndices
  2384. @lastcmd=[0,0,0,0]
  2385. end
  2386.  
  2387. def pbResetMoveIndex(index)
  2388. @lastmove[index]=0
  2389. end
  2390.  
  2391. def pbSafariCommandMenu(index)
  2392. pbCommandMenuEx(index,[
  2393.  
  2394. _INTL("¿Qué hará {1}?",@battle.pbPlayer.name),
  2395. _INTL("Ball"),
  2396. _INTL("Cebo"),
  2397. _INTL("Piedra"),
  2398. _INTL("Huir")
  2399. ],2)
  2400. end
  2401.  
  2402. # Use this method to display the list of commands.
  2403. # Return values: 0=Fight, 1=Bag, 2=Pokémon, 3=Run, 4=Call
  2404. def pbCommandMenu(index)
  2405. shadowTrainer=(hasConst?(PBTypes,:SHADOW) && @battle.opponent)
  2406. ret=pbCommandMenuEx(index,[
  2407.  
  2408. _INTL("¿Qué hará {1}?",@battle.battlers[index].name),
  2409. _INTL("Luchar"),
  2410. _INTL("Mochila"),
  2411. _INTL("Pokémon"),
  2412. shadowTrainer ? _INTL("Llamar") : _INTL("Huir")
  2413. ],(shadowTrainer ? 1 : 0))
  2414. ret=4 if ret==3 && shadowTrainer # Convert "Run" to "Call"
  2415. return ret
  2416. end
  2417.  
  2418. def pbCommandMenuEx(index,texts,mode=0) # Mode: 0 - regular battle
  2419. pbShowWindow(COMMANDBOX) # 1 - Shadow Pokémon battle
  2420. cw=@sprites["commandwindow"] # 2 - Safari Zone
  2421. cw.setTexts(texts) # 3 - Bug Catching Contest
  2422. cw.index=@lastcmd[index]
  2423. cw.mode=mode
  2424. pbSelectBattler(index)
  2425. pbRefresh
  2426. loop do
  2427. pbGraphicsUpdate
  2428. pbInputUpdate
  2429. pbFrameUpdate(cw)
  2430. # Update selected command
  2431. if Input.trigger?(Input::LEFT)
  2432. if cw.index>=1
  2433. pbSEPlay("SE_Select1")
  2434. cw.index-=1
  2435. end
  2436. elsif Input.trigger?(Input::RIGHT)
  2437. if cw.index<=2
  2438. pbSEPlay("SE_Select1")
  2439. cw.index+=1
  2440. end
  2441. end
  2442. =begin
  2443. if Input.trigger?(Input::LEFT) && (cw.index&1)==1
  2444. pbPlayCursorSE()
  2445.  
  2446. cw.index-=1
  2447.  
  2448. elsif Input.trigger?(Input::RIGHT) && (cw.index&1)==0
  2449. pbPlayCursorSE()
  2450.  
  2451. cw.index+=1
  2452. elsif Input.trigger?(Input::UP) && (cw.index&2)==2
  2453. pbPlayCursorSE()
  2454. cw.index-=2
  2455. elsif Input.trigger?(Input::DOWN) && (cw.index&2)==0
  2456. pbPlayCursorSE()
  2457. cw.index+=2
  2458. end
  2459. =end
  2460. if Input.trigger?(Input::C) # Confirm choice
  2461. pbPlayDecisionSE()
  2462. ret=cw.index
  2463. @lastcmd[index]=ret
  2464. return ret
  2465. elsif Input.trigger?(Input::B) && index==2 && @lastcmd[0]!=2 # Cancel
  2466. pbPlayDecisionSE()
  2467. return -1
  2468. end
  2469. end
  2470. end
  2471.  
  2472. # Use this method to display the list of moves for a Pokémon
  2473. def pbFightMenu(index)
  2474. pbShowWindow(FIGHTBOX)
  2475. cw = @sprites["fightwindow"]
  2476. battler=@battle.battlers[index]
  2477. cw.battler=battler
  2478. lastIndex=@lastmove[index]
  2479. if battler.moves[lastIndex].id!=0
  2480. cw.setIndex(lastIndex)
  2481. else
  2482. cw.setIndex(0)
  2483. end
  2484. cw.megaButton=0
  2485. cw.megaButton=1 if @battle.pbCanMegaEvolve?(index)
  2486. pbSelectBattler(index)
  2487. pbRefresh
  2488. loop do
  2489. pbGraphicsUpdate
  2490. pbInputUpdate
  2491. pbFrameUpdate(cw)
  2492. # Update selected command
  2493. if Input.trigger?(Input::DOWN)#LEFT
  2494. pbPlayCursorSE() if (cw.index-1)>=0 && cw.setIndex(cw.index-1)
  2495. elsif Input.trigger?(Input::UP)#RIGHT
  2496. pbPlayCursorSE() if (cw.index+1)<=3 && cw.setIndex(cw.index+1)
  2497. end
  2498. =begin
  2499. if Input.trigger?(Input::LEFT) && (cw.index&1)==1
  2500. pbPlayCursorSE() if cw.setIndex(cw.index-1)
  2501. elsif Input.trigger?(Input::RIGHT) && (cw.index&1)==0
  2502. pbPlayCursorSE() if cw.setIndex(cw.index+1)
  2503. elsif Input.trigger?(Input::UP) && (cw.index&2)==2
  2504. pbPlayCursorSE() if cw.setIndex(cw.index-2)
  2505. elsif Input.trigger?(Input::DOWN) && (cw.index&2)==0
  2506. pbPlayCursorSE() if cw.setIndex(cw.index+2)
  2507. end
  2508. =end
  2509. if Input.trigger?(Input::C) # Confirm choice
  2510. ret=cw.index
  2511. pbPlayDecisionSE()
  2512. @lastmove[index]=ret
  2513. return ret
  2514. elsif Input.trigger?(Input::A) # Use Mega Evolution
  2515. if @battle.pbCanMegaEvolve?(index)
  2516. @battle.pbRegisterMegaEvolution(index)
  2517. cw.megaButton=2
  2518. pbPlayDecisionSE()
  2519. end
  2520. elsif Input.trigger?(Input::B) # Cancel fight menu
  2521. @lastmove[index]=cw.index
  2522. pbPlayCancelSE()
  2523. return -1
  2524. end
  2525. end
  2526. end
  2527.  
  2528. # Use this method to display the inventory
  2529. # The return value is the item chosen, or 0 if the choice was canceled.
  2530. def pbItemMenu(index)
  2531. ret=0
  2532. retindex=-1
  2533. pkmnid=-1
  2534. endscene=true
  2535. oldsprites=pbFadeOutAndHide(@sprites)
  2536. itemscene=PokemonBag_Scene.new
  2537. itemscene.pbStartScene($PokemonBag)
  2538. loop do
  2539. item=itemscene.pbChooseItem
  2540. break if item==0
  2541. usetype=$ItemData[item][ITEMBATTLEUSE]
  2542. cmdUse=-1
  2543. commands=[]
  2544. if usetype==0
  2545. commands[commands.length]=_INTL("Salir")
  2546. else
  2547. commands[cmdUse=commands.length]=_INTL("Usar")
  2548. commands[commands.length]=_INTL("Salir")
  2549. end
  2550. itemname=PBItems.getName(item)
  2551. command=itemscene.pbShowCommands(_INTL("{1} está seleccionado.",itemname),commands)
  2552. if cmdUse>=0 && command==cmdUse
  2553. if usetype==1 || usetype==3
  2554. modparty=[]
  2555. for i in 0...6
  2556. modparty.push(@battle.party1[@battle.party1order[i]])
  2557. end
  2558. pkmnlist=PokemonScreen_Scene.new
  2559. pkmnscreen=PokemonScreen.new(pkmnlist,modparty)
  2560. itemscene.pbEndScene
  2561. pkmnscreen.pbStartScene(_INTL("¿En qué Pokémon usarlo?"),@battle.doublebattle)
  2562. activecmd=pkmnscreen.pbChoosePokemon
  2563. pkmnid=@battle.party1order[activecmd]
  2564. if activecmd>=0 && pkmnid>=0 && ItemHandlers.hasBattleUseOnPokemon(item)
  2565. pkmnlist.pbEndScene
  2566. ret=item
  2567. retindex=pkmnid
  2568. endscene=false
  2569. break
  2570. end
  2571. pkmnlist.pbEndScene
  2572. itemscene.pbStartScene($PokemonBag)
  2573. elsif usetype==2 || usetype==4
  2574. if ItemHandlers.hasBattleUseOnBattler(item)
  2575. ret=item
  2576. retindex=index
  2577. break
  2578. end
  2579. end
  2580. end
  2581. end
  2582. pbConsumeItemInBattle($PokemonBag,ret) if ret>0
  2583. itemscene.pbEndScene if endscene
  2584. pbFadeInAndShow(@sprites,oldsprites)
  2585. return [ret,retindex]
  2586. end
  2587.  
  2588. # Called whenever a Pokémon should forget a move. It should return -1 if the
  2589. # selection is canceled, or 0 to 3 to indicate the move to forget. The function
  2590. # should not allow HM moves to be forgotten.
  2591. def pbForgetMove(pokemon,moveToLearn)
  2592. ret=-1
  2593. pbFadeOutIn(99999){
  2594. scene=PokemonSummaryScene.new
  2595. screen=PokemonSummary.new(scene)
  2596. ret=screen.pbStartForgetScreen([pokemon],0,moveToLearn)
  2597. }
  2598. return ret
  2599. end
  2600.  
  2601. # Called whenever a Pokémon needs one of its moves chosen. Used for Ether.
  2602. def pbChooseMove(pokemon,message)
  2603. ret=-1
  2604. pbFadeOutIn(99999){
  2605. scene=PokemonSummaryScene.new
  2606. screen=PokemonSummary.new(scene)
  2607. ret=screen.pbStartChooseMoveScreen([pokemon],0,message)
  2608. }
  2609. return ret
  2610. end
  2611.  
  2612. def pbNameEntry(helptext,pokemon)
  2613. return pbEnterPokemonName(helptext,0,10,"",pokemon)
  2614. end
  2615.  
  2616. def pbSelectBattler(index,selectmode=1)
  2617. numwindows=@battle.doublebattle ? 4 : 2
  2618. for i in 0...numwindows
  2619. sprite=@sprites["battlebox#{i}"]
  2620. sprite.selected=(i==index) ? selectmode : 0
  2621. sprite=@sprites["pokemon#{i}"]
  2622. sprite.selected=(i==index) ? selectmode : 0
  2623. end
  2624. end
  2625.  
  2626. def pbFirstTarget(index,targettype)
  2627. case targettype
  2628. when PBTargets::SingleNonUser
  2629. for i in 0...4
  2630. if i!=index && !@battle.battlers[i].isFainted? &&
  2631. @battle.battlers[index].pbIsOpposing?(i)
  2632. return i
  2633. end
  2634. end
  2635. when PBTargets::UserOrPartner
  2636. return index
  2637. end
  2638. return -1
  2639. end
  2640.  
  2641. def pbUpdateSelected(index)
  2642. numwindows=@battle.doublebattle ? 4 : 2
  2643. for i in 0...numwindows
  2644. if i==index
  2645. @sprites["battlebox#{i}"].selected=2
  2646. @sprites["pokemon#{i}"].selected=2
  2647. else
  2648. @sprites["battlebox#{i}"].selected=0
  2649. @sprites["pokemon#{i}"].selected=0
  2650. end
  2651. @sprites["battlebox#{i}"].update
  2652. @sprites["pokemon#{i}"].update
  2653. end
  2654.  
  2655. end
  2656.  
  2657. # Use this method to make the player choose a target
  2658. # for certain moves in double battles.
  2659. def pbChooseTarget(index,targettype)
  2660. pbShowWindow(FIGHTBOX)
  2661. cw = @sprites["fightwindow"]
  2662. battler=@battle.battlers[index]
  2663. cw.battler=battler
  2664. lastIndex=@lastmove[index]
  2665. if battler.moves[lastIndex].id!=0
  2666. cw.setIndex(lastIndex)
  2667. else
  2668. cw.setIndex(0)
  2669. end
  2670.  
  2671. curwindow=pbFirstTarget(index,targettype)
  2672. if curwindow==-1
  2673. raise RuntimeError.new(_INTL("Sin objetivo por alguna razón..."))
  2674. end
  2675. loop do
  2676. pbGraphicsUpdate
  2677. pbInputUpdate
  2678. pbFrameUpdate
  2679. pbUpdateSelected(curwindow)
  2680. if Input.trigger?(Input::C)
  2681. pbUpdateSelected(-1)
  2682. return curwindow
  2683. end
  2684. if Input.trigger?(Input::B)
  2685. pbUpdateSelected(-1)
  2686. return -1
  2687.  
  2688.  
  2689.  
  2690. end
  2691. if curwindow>=0
  2692. if Input.trigger?(Input::RIGHT) || Input.trigger?(Input::DOWN)
  2693. loop do
  2694. case targettype
  2695. when PBTargets::SingleNonUser
  2696. case curwindow
  2697. when 0; newcurwindow=2
  2698. when 1; newcurwindow=0
  2699. when 2; newcurwindow=3
  2700. when 3; newcurwindow=1
  2701. end
  2702. when PBTargets::UserOrPartner
  2703. newcurwindow=(curwindow+2)%4
  2704. end
  2705. curwindow=newcurwindow
  2706. next if targettype==PBTargets::SingleNonUser && curwindow==index
  2707. break if !@battle.battlers[curwindow].isFainted?
  2708. end
  2709. elsif Input.trigger?(Input::LEFT) || Input.trigger?(Input::UP)
  2710. loop do
  2711. case targettype
  2712. when PBTargets::SingleNonUser
  2713. case curwindow
  2714. when 0; newcurwindow=1
  2715. when 1; newcurwindow=3
  2716. when 2; newcurwindow=0
  2717. when 3; newcurwindow=2
  2718. end
  2719. when PBTargets::UserOrPartner
  2720. newcurwindow=(curwindow+2)%4
  2721. end
  2722. curwindow=newcurwindow
  2723. next if targettype==PBTargets::SingleNonUser && curwindow==index
  2724. break if !@battle.battlers[curwindow].isFainted?
  2725. end
  2726. end
  2727. end
  2728. end
  2729. end
  2730.  
  2731. def pbSwitch(index,lax,cancancel)
  2732. party=@battle.pbParty(index)
  2733. partypos=@battle.party1order
  2734. ret=-1
  2735. # Fade out and hide all sprites
  2736. visiblesprites=pbFadeOutAndHide(@sprites)
  2737. pbShowWindow(BLANK)
  2738. pbSetMessageMode(true)
  2739. modparty=[]
  2740. for i in 0...6
  2741. modparty.push(party[partypos[i]])
  2742. end
  2743. scene=PokemonScreen_Scene.new
  2744. @switchscreen=PokemonScreen.new(scene,modparty)
  2745. @switchscreen.pbStartScene(_INTL("Elige un Pokémon."),
  2746. @battle.doublebattle && !@battle.fullparty1)
  2747. loop do
  2748. scene.pbSetHelpText(_INTL("Elige un Pokémon."))
  2749. activecmd=@switchscreen.pbChoosePokemon
  2750. if cancancel && activecmd==-1
  2751. ret=-1
  2752. break
  2753. end
  2754. if activecmd>=0
  2755. commands=[]
  2756. cmdShift=-1
  2757. cmdSummary=-1
  2758. pkmnindex=partypos[activecmd]
  2759. commands[cmdShift=commands.length]=_INTL("Cambio") if !party[pkmnindex].isEgg?
  2760. commands[cmdSummary=commands.length]=_INTL("Datos")
  2761. commands[commands.length]=_INTL("Salir")
  2762. command=scene.pbShowCommands(_INTL("¿Qué hacer con {1}?",party[pkmnindex].name),commands)
  2763. if cmdShift>=0 && command==cmdShift
  2764. canswitch=lax ? @battle.pbCanSwitchLax?(index,pkmnindex,true) :
  2765. @battle.pbCanSwitch?(index,pkmnindex,true)
  2766. if canswitch
  2767. ret=pkmnindex
  2768. break
  2769. end
  2770. elsif cmdSummary>=0 && command==cmdSummary
  2771. scene.pbSummary(activecmd)
  2772. end
  2773. end
  2774. end
  2775. @switchscreen.pbEndScene
  2776. @switchscreen=nil
  2777. pbShowWindow(BLANK)
  2778. pbSetMessageMode(false)
  2779. # back to main battle screen
  2780. pbFadeInAndShow(@sprites,visiblesprites)
  2781. return ret
  2782. end
  2783.  
  2784. def pbDamageAnimation(pkmn,effectiveness)
  2785. pkmnsprite=@sprites["pokemon#{pkmn.index}"]
  2786. shadowsprite=@sprites["shadow#{pkmn.index}"]
  2787. sprite=@sprites["battlebox#{pkmn.index}"]
  2788. oldshadowvisible=shadowsprite.visible
  2789. oldvisible=sprite.visible
  2790. sprite.selected=3
  2791. @briefmessage=false
  2792. 6.times do
  2793. pbGraphicsUpdate
  2794. pbInputUpdate
  2795. pbFrameUpdate
  2796. end
  2797. case effectiveness
  2798. when 0
  2799. pbSEPlay("normaldamage")
  2800. when 1
  2801. pbSEPlay("notverydamage")
  2802. when 2
  2803. pbSEPlay("superdamage")
  2804. end
  2805. 8.times do
  2806. pkmnsprite.visible=!pkmnsprite.visible
  2807. if oldshadowvisible
  2808. shadowsprite.visible=!shadowsprite.visible
  2809. end
  2810. 4.times do
  2811. pbGraphicsUpdate
  2812. pbInputUpdate
  2813. pbFrameUpdate
  2814. sprite.update
  2815. end
  2816. end
  2817. sprite.selected=0
  2818. sprite.visible=oldvisible
  2819. end
  2820.  
  2821. # This method is called whenever a Pokémon's HP changes.
  2822. # Used to animate the HP bar.
  2823. def pbHPChanged(pkmn,oldhp,anim=false)
  2824. @briefmessage=false
  2825. hpchange=pkmn.hp-oldhp
  2826. if hpchange<0
  2827. hpchange=-hpchange
  2828. PBDebug.log("[Modificación PS] #{pkmn.pbThis} perdió #{hpchange} PS (#{oldhp}=>#{pkmn.hp})")
  2829. else
  2830. PBDebug.log("[Modificación PS] #{pkmn.pbThis} ganó #{hpchange} PS (#{oldhp}=>#{pkmn.hp})")
  2831. end
  2832. if anim && @battle.battlescene
  2833. if pkmn.hp>oldhp
  2834. pbCommonAnimation("HealthUp",pkmn,nil)
  2835. elsif pkmn.hp<oldhp
  2836. pbCommonAnimation("HealthDown",pkmn,nil)
  2837. end
  2838. end
  2839. sprite=@sprites["battlebox#{pkmn.index}"]
  2840. sprite.animateHP(oldhp,pkmn.hp)
  2841. while sprite.animatingHP
  2842. pbGraphicsUpdate
  2843. pbInputUpdate
  2844. pbFrameUpdate
  2845. sprite.update
  2846. end
  2847. end
  2848.  
  2849. # This method is called whenever a Pokémon faints.
  2850. def pbFainted(pkmn)
  2851. frames=pbCryFrameLength(pkmn.pokemon)
  2852. pbPlayCry(pkmn.pokemon)
  2853. frames.times do
  2854. pbGraphicsUpdate
  2855. pbInputUpdate
  2856. pbFrameUpdate
  2857. end
  2858. @sprites["shadow#{pkmn.index}"].visible=false
  2859. pkmnsprite=@sprites["pokemon#{pkmn.index}"]
  2860. ycoord=0
  2861. if @battle.doublebattle
  2862. ycoord=PokeBattle_SceneConstants::PLAYERBATTLERD1_Y if pkmn.index==0
  2863. ycoord=PokeBattle_SceneConstants::FOEBATTLERD1_Y if pkmn.index==1
  2864. ycoord=PokeBattle_SceneConstants::PLAYERBATTLERD2_Y if pkmn.index==2
  2865. ycoord=PokeBattle_SceneConstants::FOEBATTLERD2_Y if pkmn.index==3
  2866. else
  2867. if @battle.pbIsOpposing?(pkmn.index)
  2868. ycoord=PokeBattle_SceneConstants::FOEBATTLER_Y
  2869. else
  2870. ycoord=PokeBattle_SceneConstants::PLAYERBATTLER_Y
  2871. end
  2872. end
  2873. pbSEPlay("faint")
  2874. loop do
  2875. pkmnsprite.y+=8
  2876. if pkmnsprite.y-pkmnsprite.oy+pkmnsprite.src_rect.height>=ycoord
  2877. pkmnsprite.src_rect.height=ycoord-pkmnsprite.y+pkmnsprite.oy
  2878. end
  2879. pbGraphicsUpdate
  2880. pbInputUpdate
  2881. pbFrameUpdate
  2882. break if pkmnsprite.y>=ycoord
  2883. end
  2884. pkmnsprite.visible=false
  2885. 8.times do
  2886. @sprites["battlebox#{pkmn.index}"].opacity-=32
  2887. pbGraphicsUpdate
  2888. pbInputUpdate
  2889. pbFrameUpdate
  2890. end
  2891. @sprites["battlebox#{pkmn.index}"].visible=false
  2892. pkmn.pbResetForm
  2893. end
  2894.  
  2895. # Use this method to choose a command for the enemy.
  2896. def pbChooseEnemyCommand(index)
  2897. @battle.pbDefaultChooseEnemyCommand(index)
  2898. end
  2899.  
  2900. # Use this method to choose a new Pokémon for the enemy
  2901. # The enemy's party is guaranteed to have at least one choosable member.
  2902. def pbChooseNewEnemy(index,party)
  2903. @battle.pbDefaultChooseNewEnemy(index,party)
  2904. end
  2905.  
  2906. # This method is called when the player wins a wild Pokémon battle.
  2907. # This method can change the battle's music for example.
  2908. def pbWildBattleSuccess
  2909. pbBGMPlay(pbGetWildVictoryME())
  2910. end
  2911.  
  2912. # This method is called when the player wins a Trainer battle.
  2913. # This method can change the battle's music for example.
  2914. def pbTrainerBattleSuccess
  2915. pbBGMPlay(pbGetTrainerVictoryME(@battle.opponent))
  2916. end
  2917.  
  2918. def pbEXPBar(pokemon,battler,startexp,endexp,tempexp1,tempexp2)
  2919. if battler
  2920. @sprites["battlebox#{battler.index}"].refreshExpLevel
  2921. exprange=(endexp-startexp)
  2922. startexplevel=0
  2923. endexplevel=0
  2924. if exprange!=0
  2925. startexplevel=(tempexp1-startexp)*PokeBattle_SceneConstants::EXPGAUGESIZE/exprange
  2926. endexplevel=(tempexp2-startexp)*PokeBattle_SceneConstants::EXPGAUGESIZE/exprange
  2927. end
  2928. @sprites["battlebox#{battler.index}"].animateEXP(startexplevel,endexplevel)
  2929. while @sprites["battlebox#{battler.index}"].animatingEXP
  2930. pbGraphicsUpdate
  2931. pbInputUpdate
  2932. pbFrameUpdate
  2933. @sprites["battlebox#{battler.index}"].update
  2934. end
  2935. end
  2936. end
  2937.  
  2938. def pbShowPokedex(species)
  2939. pbFadeOutIn(99999){
  2940. scene=PokemonPokedexScene.new
  2941. screen=PokemonPokedex.new(scene)
  2942. screen.pbDexEntry(species)
  2943. }
  2944. end
  2945.  
  2946. def pbChangeSpecies(attacker,species)
  2947. pkmn=@sprites["pokemon#{attacker.index}"]
  2948. shadow=@sprites["shadow#{attacker.index}"]
  2949. back=!@battle.pbIsOpposing?(attacker.index)
  2950. pkmn.setPokemonBitmapSpecies(attacker.pokemon,species,back)
  2951. pkmn.x=-pkmn.bitmap.width/2
  2952. pkmn.y=adjustBattleSpriteY(pkmn,species,attacker.index)
  2953. if @battle.doublebattle
  2954. case attacker.index
  2955. when 0
  2956. pkmn.x+=PokeBattle_SceneConstants::PLAYERBATTLERD1_X
  2957. pkmn.y+=PokeBattle_SceneConstants::PLAYERBATTLERD1_Y
  2958. when 1
  2959. pkmn.x+=PokeBattle_SceneConstants::FOEBATTLERD1_X
  2960. pkmn.y+=PokeBattle_SceneConstants::FOEBATTLERD1_Y
  2961. when 2
  2962. pkmn.x+=PokeBattle_SceneConstants::PLAYERBATTLERD2_X
  2963. pkmn.y+=PokeBattle_SceneConstants::PLAYERBATTLERD2_Y
  2964. when 3
  2965. pkmn.x+=PokeBattle_SceneConstants::FOEBATTLERD2_X
  2966. pkmn.y+=PokeBattle_SceneConstants::FOEBATTLERD2_Y
  2967. end
  2968. else
  2969. pkmn.x+=PokeBattle_SceneConstants::PLAYERBATTLER_X if attacker.index==0
  2970. pkmn.y+=PokeBattle_SceneConstants::PLAYERBATTLER_Y if attacker.index==0
  2971. pkmn.x+=PokeBattle_SceneConstants::FOEBATTLER_X if attacker.index==1
  2972. pkmn.y+=PokeBattle_SceneConstants::FOEBATTLER_Y if attacker.index==1
  2973. end
  2974. if shadow && !back
  2975. shadow.visible=showShadow?(species)
  2976. end
  2977. end
  2978.  
  2979. def pbChangePokemon(attacker,pokemon)
  2980. pkmn=@sprites["pokemon#{attacker.index}"]
  2981. shadow=@sprites["shadow#{attacker.index}"]
  2982. back=!@battle.pbIsOpposing?(attacker.index)
  2983. pkmn.setPokemonBitmap(pokemon,back)
  2984. pkmn.x=-pkmn.bitmap.width/2
  2985. pkmn.y=adjustBattleSpriteY(pkmn,pokemon.species,attacker.index)
  2986. if @battle.doublebattle
  2987. case attacker.index
  2988. when 0
  2989. pkmn.x+=PokeBattle_SceneConstants::PLAYERBATTLERD1_X
  2990. pkmn.y+=PokeBattle_SceneConstants::PLAYERBATTLERD1_Y
  2991. when 1
  2992. pkmn.x+=PokeBattle_SceneConstants::FOEBATTLERD1_X
  2993. pkmn.y+=PokeBattle_SceneConstants::FOEBATTLERD1_Y
  2994. when 2
  2995. pkmn.x+=PokeBattle_SceneConstants::PLAYERBATTLERD2_X
  2996. pkmn.y+=PokeBattle_SceneConstants::PLAYERBATTLERD2_Y
  2997. when 3
  2998. pkmn.x+=PokeBattle_SceneConstants::FOEBATTLERD2_X
  2999. pkmn.y+=PokeBattle_SceneConstants::FOEBATTLERD2_Y
  3000. end
  3001. else
  3002. pkmn.x+=PokeBattle_SceneConstants::PLAYERBATTLER_X if attacker.index==0
  3003. pkmn.y+=PokeBattle_SceneConstants::PLAYERBATTLER_Y if attacker.index==0
  3004. pkmn.x+=PokeBattle_SceneConstants::FOEBATTLER_X if attacker.index==1
  3005. pkmn.y+=PokeBattle_SceneConstants::FOEBATTLER_Y if attacker.index==1
  3006. end
  3007. if shadow && !back
  3008. shadow.visible=showShadow?(pokemon.species)
  3009. end
  3010. end
  3011.  
  3012. def pbSaveShadows
  3013. shadows=[]
  3014. for i in 0...4
  3015. s=@sprites["shadow#{i}"]
  3016. shadows[i]=s ? s.visible : false
  3017. s.visible=false if s
  3018. end
  3019. yield
  3020. for i in 0...4
  3021. s=@sprites["shadow#{i}"]
  3022. s.visible=shadows[i] if s
  3023. end
  3024. end
  3025.  
  3026. def pbFindAnimation(moveid,userIndex,hitnum)
  3027. begin
  3028. move2anim=load_data("Data/move2anim.dat")
  3029. noflip=false
  3030. if (userIndex&1)==0 # On player's side
  3031. anim=move2anim[0][moveid]
  3032. else # On opposing side
  3033. anim=move2anim[1][moveid]
  3034. noflip=true if anim
  3035. anim=move2anim[0][moveid] if !anim
  3036. end
  3037. return [anim+hitnum,noflip] if anim
  3038. # Actual animation not found, get the default animation for the move's type
  3039. # Animación actual no encontrada, se usa animación por defecto según el tipo del movimiento
  3040. move=PBMoveData.new(moveid)
  3041. type=move.type
  3042. typedefaultanim=[[:NORMAL,:TACKLE],
  3043. [:FIGHTING,:COMETPUNCH],
  3044. [:FLYING,:GUST],
  3045. [:POISON,:SLUDGE],
  3046. [:GROUND,:MUDSLAP],
  3047. [:ROCK,:ROCKTHROW],
  3048. [:BUG,:TWINEEDLE],
  3049. [:GHOST,:NIGHTSHADE],
  3050. [:STEEL,:GYROBALL],
  3051. [:FIRE,:EMBER],
  3052. [:WATER,:WATERGUN],
  3053. [:GRASS,:RAZORLEAF],
  3054. [:ELECTRIC,:THUNDERSHOCK],
  3055. [:PSYCHIC,:CONFUSION],
  3056. [:ICE,:ICEBALL],
  3057. [:DRAGON,:DRAGONRAGE],
  3058. [:DARK,:PURSUIT],
  3059. [:FAIRY,:FAIRYWIND]]
  3060. for i in typedefaultanim
  3061. if isConst?(type,PBTypes,i[0]) && hasConst?(PBMoves,i[1])
  3062. noflip=false
  3063. if (userIndex&1)==0 # On player's side
  3064. anim=move2anim[0][getConst(PBMoves,i[1])]
  3065. else # On opposing side
  3066. anim=move2anim[1][getConst(PBMoves,i[1])]
  3067. noflip=true if anim
  3068. anim=move2anim[0][getConst(PBMoves,i[1])] if !anim
  3069. end
  3070. return [anim,noflip] if anim
  3071. break
  3072. end
  3073. end
  3074. # Default animation for the move's type not found, use Tackle's animation
  3075. # Animación por defecto para tipos de movimientos no encontrados, se usa la animación de Placaje
  3076. if hasConst?(PBMoves,:TACKLE)
  3077. anim=move2anim[0][getConst(PBMoves,:TACKLE)]
  3078. return [anim,false] if anim
  3079. end
  3080. rescue
  3081. return nil
  3082. end
  3083. return nil
  3084. end
  3085.  
  3086. def pbCommonAnimation(animname,user,target,hitnum=0)
  3087. animations=load_data("Data/PkmnAnimations.rxdata")
  3088. for i in 0...animations.length
  3089. if animations[i] && animations[i].name=="Common:"+animname
  3090. pbAnimationCore(animations[i],user,(target!=nil) ? target : user)
  3091. return
  3092. end
  3093. end
  3094. end
  3095.  
  3096. def pbAnimation(moveid,user,target,hitnum=0)
  3097. animid=pbFindAnimation(moveid,user.index,hitnum)
  3098. return if !animid
  3099. anim=animid[0]
  3100. animations=load_data("Data/PkmnAnimations.rxdata")
  3101. pbSaveShadows {
  3102. if animid[1] # On opposing side and using OppMove animation
  3103. pbAnimationCore(animations[anim],target,user,true)
  3104. else # On player's side, and/or using Move animation
  3105. pbAnimationCore(animations[anim],user,target)
  3106. end
  3107. }
  3108. if PBMoveData.new(moveid).function==0x69 && user && target # Transform
  3109. # Change form to transformed version
  3110. pbChangePokemon(user,target.pokemon)
  3111. end
  3112. end
  3113.  
  3114. def pbAnimationCore(animation,user,target,oppmove=false)
  3115. return if !animation
  3116. @briefmessage=false
  3117. usersprite=(user) ? @sprites["pokemon#{user.index}"] : nil
  3118. targetsprite=(target) ? @sprites["pokemon#{target.index}"] : nil
  3119. olduserx=usersprite ? usersprite.x : 0
  3120. oldusery=usersprite ? usersprite.y : 0
  3121. oldtargetx=targetsprite ? targetsprite.x : 0
  3122. oldtargety=targetsprite ? targetsprite.y : 0
  3123. if !targetsprite
  3124. target=user if !target
  3125. animplayer=PBAnimationPlayerX.new(animation,user,target,self,oppmove)
  3126. userwidth=(!usersprite || !usersprite.bitmap || usersprite.bitmap.disposed?) ? 128 : usersprite.bitmap.width
  3127. userheight=(!usersprite || !usersprite.bitmap || usersprite.bitmap.disposed?) ? 128 : usersprite.bitmap.height
  3128. animplayer.setLineTransform(
  3129. PokeBattle_SceneConstants::FOCUSUSER_X,PokeBattle_SceneConstants::FOCUSUSER_Y,
  3130. PokeBattle_SceneConstants::FOCUSTARGET_X,PokeBattle_SceneConstants::FOCUSTARGET_Y,
  3131. olduserx+(userwidth/2),oldusery+(userheight/2),
  3132. olduserx+(userwidth/2),oldusery+(userheight/2))
  3133. else
  3134. animplayer=PBAnimationPlayerX.new(animation,user,target,self,oppmove)
  3135. userwidth=(!usersprite || !usersprite.bitmap || usersprite.bitmap.disposed?) ? 128 : usersprite.bitmap.width
  3136. userheight=(!usersprite || !usersprite.bitmap || usersprite.bitmap.disposed?) ? 128 : usersprite.bitmap.height
  3137. targetwidth=(!targetsprite.bitmap || targetsprite.bitmap.disposed?) ? 128 : targetsprite.bitmap.width
  3138. targetheight=(!targetsprite.bitmap || targetsprite.bitmap.disposed?) ? 128 : targetsprite.bitmap.height
  3139. animplayer.setLineTransform(
  3140. PokeBattle_SceneConstants::FOCUSUSER_X,PokeBattle_SceneConstants::FOCUSUSER_Y,
  3141. PokeBattle_SceneConstants::FOCUSTARGET_X,PokeBattle_SceneConstants::FOCUSTARGET_Y,
  3142. olduserx+(userwidth/2),oldusery+(userheight/2),
  3143. oldtargetx+(targetwidth/2),oldtargety+(targetheight/2))
  3144. end
  3145. animplayer.start
  3146. while animplayer.playing?
  3147. animplayer.update
  3148. pbGraphicsUpdate
  3149. pbInputUpdate
  3150. pbFrameUpdate
  3151. end
  3152. usersprite.ox=0 if usersprite
  3153. usersprite.oy=0 if usersprite
  3154. usersprite.x=olduserx if usersprite
  3155. usersprite.y=oldusery if usersprite
  3156. targetsprite.ox=0 if targetsprite
  3157. targetsprite.oy=0 if targetsprite
  3158. targetsprite.x=oldtargetx if targetsprite
  3159. targetsprite.y=oldtargety if targetsprite
  3160. animplayer.dispose
  3161. end
  3162.  
  3163. def pbLevelUp(pokemon,battler,oldtotalhp,oldattack,olddefense,oldspeed,
  3164. oldspatk,oldspdef)
  3165. pbTopRightWindow(_INTL("PS Máx.<r>+{1}\r\nAtaque<r>+{2}\r\nDefensa<r>+{3}\r\nAt. Esp<r>+{4}\r\nDef. Esp<r>+{5}\r\nVelocidad<r>+{6}",
  3166. pokemon.totalhp-oldtotalhp,
  3167. pokemon.attack-oldattack,
  3168. pokemon.defense-olddefense,
  3169. pokemon.spatk-oldspatk,
  3170. pokemon.spdef-oldspdef,
  3171. pokemon.speed-oldspeed))
  3172. pbTopRightWindow(_INTL("PS Máx.<r>{1}\r\nAtaque<r>{2}\r\nDefensa<r>{3}\r\nAt. Esp<r>{4}\r\nDef. Esp<r>{5}\r\nVelocidad<r>{6}",
  3173. pokemon.totalhp,pokemon.attack,pokemon.defense,pokemon.spatk,pokemon.spdef,pokemon.speed))
  3174. end
  3175.  
  3176. def pbThrowAndDeflect(ball,targetBattler)
  3177. @briefmessage=false
  3178. balltype=pbGetBallType(ball)
  3179. ball=sprintf("Graphics/Pictures/ball%02d",balltype)
  3180. # sprite
  3181. spriteBall=IconSprite.new(0,0,@viewport)
  3182. spriteBall.visible=false
  3183. # picture
  3184. pictureBall=PictureEx.new(@sprites["pokemon#{targetBattler}"].z+1)
  3185. center=getSpriteCenter(@sprites["pokemon#{targetBattler}"])
  3186. # starting positions
  3187. pictureBall.moveVisible(1,true)
  3188. pictureBall.moveName(1,ball)
  3189. pictureBall.moveOrigin(1,PictureOrigin::Center)
  3190. pictureBall.moveXY(0,1,10,180)
  3191. # directives
  3192. pictureBall.moveSE(1,"Audio/SE/throw")
  3193. pictureBall.moveCurve(30,1,150,70,30+Graphics.width/2,10,center[0],center[1])
  3194. pictureBall.moveAngle(30,1,-1080)
  3195. pictureBall.moveAngle(0,pictureBall.totalDuration,0)
  3196. delay=pictureBall.totalDuration
  3197. pictureBall.moveSE(delay,"Audio/SE/balldrop")
  3198. pictureBall.moveXY(20,delay,0,Graphics.height)
  3199. loop do
  3200. pictureBall.update
  3201. setPictureIconSprite(spriteBall,pictureBall)
  3202. pbGraphicsUpdate
  3203. pbInputUpdate
  3204. pbFrameUpdate
  3205. break if !pictureBall.running?
  3206. end
  3207. spriteBall.dispose
  3208. end
  3209.  
  3210. def pbThrow(ball,shakes,critical,targetBattler,showplayer=false)
  3211. @briefmessage=false
  3212. burst=-1
  3213. animations=load_data("Data/PkmnAnimations.rxdata")
  3214. for i in 0...2
  3215. t=(i==0) ? ball : 0
  3216. for j in 0...animations.length
  3217. if animations[j]
  3218. if animations[j].name=="Common:BallBurst#{t}"
  3219. burst=t if burst<0
  3220. break
  3221. end
  3222. end
  3223. end
  3224. break if burst>=0
  3225. end
  3226. pokeballThrow(ball,shakes,critical,targetBattler,self,@battle.battlers[targetBattler],burst,showplayer)
  3227. end
  3228.  
  3229. def pbThrowSuccess
  3230. if !@battle.opponent
  3231. @briefmessage=false
  3232. pbMEPlay("Jingle - HMTM")
  3233. frames=(3.5*Graphics.frame_rate).to_i
  3234. frames.times do
  3235. pbGraphicsUpdate
  3236. pbInputUpdate
  3237. pbFrameUpdate
  3238. end
  3239. end
  3240. end
  3241.  
  3242. def pbHideCaptureBall
  3243. if @sprites["capture"]
  3244. loop do
  3245. break if @sprites["capture"].opacity<=0
  3246. @sprites["capture"].opacity-=12
  3247. pbGraphicsUpdate
  3248. pbInputUpdate
  3249. pbFrameUpdate
  3250. end
  3251. end
  3252. end
  3253.  
  3254. def pbThrowBait
  3255. @briefmessage=false
  3256. ball=sprintf("Graphics/Pictures/battleBait")
  3257. armanim=false
  3258. if @sprites["player"].bitmap.width>@sprites["player"].bitmap.height
  3259. armanim=true
  3260. end
  3261. # sprites
  3262. spritePoke=@sprites["pokemon1"]
  3263. spritePlayer=@sprites["player"]
  3264. spriteBall=IconSprite.new(0,0,@viewport)
  3265. spriteBall.visible=false
  3266. # pictures
  3267. pictureBall=PictureEx.new(spritePoke.z+1)
  3268. picturePoke=PictureEx.new(spritePoke.z)
  3269. picturePlayer=PictureEx.new(spritePoke.z+2)
  3270. dims=[spritePoke.x,spritePoke.y]
  3271. pokecenter=getSpriteCenter(@sprites["pokemon1"])
  3272. playerpos=[@sprites["player"].x,@sprites["player"].y]
  3273. ballendy=PokeBattle_SceneConstants::FOEBATTLER_Y-4
  3274. # starting positions
  3275. pictureBall.moveVisible(1,true)
  3276. pictureBall.moveName(1,ball)
  3277. pictureBall.moveOrigin(1,PictureOrigin::Center)
  3278. pictureBall.moveXY(0,1,64,256)
  3279. picturePoke.moveVisible(1,true)
  3280. picturePoke.moveOrigin(1,PictureOrigin::Center)
  3281. picturePoke.moveXY(0,1,pokecenter[0],pokecenter[1])
  3282. picturePlayer.moveVisible(1,true)
  3283. picturePlayer.moveName(1,@sprites["player"].name)
  3284. picturePlayer.moveOrigin(1,PictureOrigin::TopLeft)
  3285. picturePlayer.moveXY(0,1,playerpos[0],playerpos[1])
  3286. # directives
  3287. picturePoke.moveSE(1,"Audio/SE/throw")
  3288. pictureBall.moveCurve(30,1,64,256,Graphics.width/2,48,
  3289. PokeBattle_SceneConstants::FOEBATTLER_X-48,
  3290. PokeBattle_SceneConstants::FOEBATTLER_Y)
  3291. pictureBall.moveAngle(30,1,-720)
  3292. pictureBall.moveAngle(0,pictureBall.totalDuration,0)
  3293. if armanim
  3294. picturePlayer.moveSrc(1,@sprites["player"].bitmap.height,0)
  3295. picturePlayer.moveXY(0,1,playerpos[0]-14,playerpos[1])
  3296. picturePlayer.moveSrc(4,@sprites["player"].bitmap.height*2,0)
  3297. picturePlayer.moveXY(0,4,playerpos[0]-12,playerpos[1])
  3298. picturePlayer.moveSrc(8,@sprites["player"].bitmap.height*3,0)
  3299. picturePlayer.moveXY(0,8,playerpos[0]+20,playerpos[1])
  3300. picturePlayer.moveSrc(16,@sprites["player"].bitmap.height*4,0)
  3301. picturePlayer.moveXY(0,16,playerpos[0]+16,playerpos[1])
  3302. picturePlayer.moveSrc(40,0,0)
  3303. picturePlayer.moveXY(0,40,playerpos[0],playerpos[1])
  3304. end
  3305. # Show Pokémon jumping before eating the bait
  3306. picturePoke.moveSE(50,"Audio/SE/jump")
  3307. picturePoke.moveXY(8,50,pokecenter[0],pokecenter[1]-8)
  3308. picturePoke.moveXY(8,58,pokecenter[0],pokecenter[1])
  3309. pictureBall.moveVisible(66,false)
  3310. picturePoke.moveSE(66,"Audio/SE/jump")
  3311. picturePoke.moveXY(8,66,pokecenter[0],pokecenter[1]-8)
  3312. picturePoke.moveXY(8,74,pokecenter[0],pokecenter[1])
  3313. # TODO: Show Pokémon eating the bait (pivots at the bottom right corner)
  3314. picturePoke.moveOrigin(picturePoke.totalDuration,PictureOrigin::TopLeft)
  3315. picturePoke.moveXY(0,picturePoke.totalDuration,dims[0],dims[1])
  3316. loop do
  3317. pictureBall.update
  3318. picturePoke.update
  3319. picturePlayer.update
  3320. setPictureIconSprite(spriteBall,pictureBall)
  3321. setPictureSprite(spritePoke,picturePoke)
  3322. setPictureIconSprite(spritePlayer,picturePlayer)
  3323. pbGraphicsUpdate
  3324. pbInputUpdate
  3325. pbFrameUpdate
  3326. break if !pictureBall.running? && !picturePoke.running? && !picturePlayer.running?
  3327. end
  3328. spriteBall.dispose
  3329. end
  3330.  
  3331. def pbThrowRock
  3332. @briefmessage=false
  3333. ball=sprintf("Graphics/Pictures/battleRock")
  3334. anger=sprintf("Graphics/Pictures/battleAnger")
  3335. armanim=false
  3336. if @sprites["player"].bitmap.width>@sprites["player"].bitmap.height
  3337. armanim=true
  3338. end
  3339. # sprites
  3340. spritePoke=@sprites["pokemon1"]
  3341. spritePlayer=@sprites["player"]
  3342. spriteBall=IconSprite.new(0,0,@viewport)
  3343. spriteBall.visible=false
  3344. spriteAnger=IconSprite.new(0,0,@viewport)
  3345. spriteAnger.visible=false
  3346. # pictures
  3347. pictureBall=PictureEx.new(spritePoke.z+1)
  3348. picturePoke=PictureEx.new(spritePoke.z)
  3349. picturePlayer=PictureEx.new(spritePoke.z+2)
  3350. pictureAnger=PictureEx.new(spritePoke.z+1)
  3351. dims=[spritePoke.x,spritePoke.y]
  3352. pokecenter=getSpriteCenter(@sprites["pokemon1"])
  3353. playerpos=[@sprites["player"].x,@sprites["player"].y]
  3354. ballendy=PokeBattle_SceneConstants::FOEBATTLER_Y-4
  3355. # starting positions
  3356. pictureBall.moveVisible(1,true)
  3357. pictureBall.moveName(1,ball)
  3358. pictureBall.moveOrigin(1,PictureOrigin::Center)
  3359. pictureBall.moveXY(0,1,64,256)
  3360. picturePoke.moveVisible(1,true)
  3361. picturePoke.moveOrigin(1,PictureOrigin::Center)
  3362. picturePoke.moveXY(0,1,pokecenter[0],pokecenter[1])
  3363. picturePlayer.moveVisible(1,true)
  3364. picturePlayer.moveName(1,@sprites["player"].name)
  3365. picturePlayer.moveOrigin(1,PictureOrigin::TopLeft)
  3366. picturePlayer.moveXY(0,1,playerpos[0],playerpos[1])
  3367. pictureAnger.moveVisible(1,false)
  3368. pictureAnger.moveName(1,anger)
  3369. pictureAnger.moveXY(0,1,pokecenter[0]-56,pokecenter[1]-48)
  3370. pictureAnger.moveOrigin(1,PictureOrigin::Center)
  3371. pictureAnger.moveZoom(0,1,100)
  3372. # directives
  3373. picturePoke.moveSE(1,"Audio/SE/throw")
  3374. pictureBall.moveCurve(30,1,64,256,Graphics.width/2,48,pokecenter[0],pokecenter[1])
  3375. pictureBall.moveAngle(30,1,-720)
  3376. pictureBall.moveAngle(0,pictureBall.totalDuration,0)
  3377. pictureBall.moveSE(30,"Audio/SE/notverydamage")
  3378. if armanim
  3379. picturePlayer.moveSrc(1,@sprites["player"].bitmap.height,0)
  3380. picturePlayer.moveXY(0,1,playerpos[0]-14,playerpos[1])
  3381. picturePlayer.moveSrc(4,@sprites["player"].bitmap.height*2,0)
  3382. picturePlayer.moveXY(0,4,playerpos[0]-12,playerpos[1])
  3383. picturePlayer.moveSrc(8,@sprites["player"].bitmap.height*3,0)
  3384. picturePlayer.moveXY(0,8,playerpos[0]+20,playerpos[1])
  3385. picturePlayer.moveSrc(16,@sprites["player"].bitmap.height*4,0)
  3386. picturePlayer.moveXY(0,16,playerpos[0]+16,playerpos[1])
  3387. picturePlayer.moveSrc(40,0,0)
  3388. picturePlayer.moveXY(0,40,playerpos[0],playerpos[1])
  3389. end
  3390. pictureBall.moveVisible(40,false)
  3391. # Show Pokémon being angry
  3392. pictureAnger.moveSE(48,"Audio/SE/jump")
  3393. pictureAnger.moveVisible(48,true)
  3394. pictureAnger.moveZoom(8,48,130)
  3395. pictureAnger.moveZoom(8,56,100)
  3396. pictureAnger.moveXY(0,64,pokecenter[0]+56,pokecenter[1]-64)
  3397. pictureAnger.moveSE(64,"Audio/SE/jump")
  3398. pictureAnger.moveZoom(8,64,130)
  3399. pictureAnger.moveZoom(8,72,100)
  3400. pictureAnger.moveVisible(80,false)
  3401. picturePoke.moveOrigin(picturePoke.totalDuration,PictureOrigin::TopLeft)
  3402. picturePoke.moveXY(0,picturePoke.totalDuration,dims[0],dims[1])
  3403. loop do
  3404. pictureBall.update
  3405. picturePoke.update
  3406. picturePlayer.update
  3407. pictureAnger.update
  3408. setPictureIconSprite(spriteBall,pictureBall)
  3409. setPictureSprite(spritePoke,picturePoke)
  3410. setPictureIconSprite(spritePlayer,picturePlayer)
  3411. setPictureIconSprite(spriteAnger,pictureAnger)
  3412. pbGraphicsUpdate
  3413. pbInputUpdate
  3414. pbFrameUpdate
  3415. break if !pictureBall.running? && !picturePoke.running? &&
  3416. !picturePlayer.running? && !pictureAnger.running?
  3417. end
  3418. spriteBall.dispose
  3419. end
  3420. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement