Nyaruko69

Untitled

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