Guest User

Untitled

a guest
Mar 6th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 151.38 KB | None | 0 0
  1. # Results of battle:
  2. # 0 - Undecided or aborted
  3. # 1 - Player won
  4. # 2 - Player lost
  5. # 3 - Player or wild Pokémon ran from battle, or player forfeited the match
  6. # 4 - Wild Pokémon was caught
  7. # 5 - Draw
  8.  
  9. ################################################################################
  10. # Catching and storing Pokémon.
  11. ################################################################################
  12. module PokeBattle_BattleCommon
  13. def pbStorePokemon(pokemon)
  14. if !(pokemon.isShadow? rescue false)
  15. if pbDisplayConfirm(_INTL("Would you like to give a nickname to {1}?",pokemon.name))
  16. species=PBSpecies.getName(pokemon.species)
  17. nickname=@scene.pbNameEntry(_INTL("{1}'s nickname?",species),pokemon)
  18. pokemon.name=nickname if nickname!=""
  19. end
  20. end
  21. oldcurbox=@peer.pbCurrentBox()
  22. storedbox=@peer.pbStorePokemon(self.pbPlayer,pokemon)
  23. creator=@peer.pbGetStorageCreator()
  24. return if storedbox<0
  25. curboxname=@peer.pbBoxName(oldcurbox)
  26. boxname=@peer.pbBoxName(storedbox)
  27. if storedbox!=oldcurbox
  28. if creator
  29. pbDisplayPaused(_INTL("Box \"{1}\" on {2}'s PC was full.",curboxname,creator))
  30. else
  31. pbDisplayPaused(_INTL("Box \"{1}\" on someone's PC was full.",curboxname))
  32. end
  33. pbDisplayPaused(_INTL("{1} was transferred to box \"{2}\".",pokemon.name,boxname))
  34. else
  35. if creator
  36. pbDisplayPaused(_INTL("{1} was transferred to {2}'s PC.",pokemon.name,creator))
  37. else
  38. pbDisplayPaused(_INTL("{1} was transferred to someone's PC.",pokemon.name))
  39. end
  40. pbDisplayPaused(_INTL("It was stored in box \"{1}\".",boxname))
  41. end
  42. end
  43.  
  44. def pbThrowPokeBall(idxPokemon,ball,rareness=nil,showplayer=false)
  45. itemname=PBItems.getName(ball)
  46. battler=nil
  47. if pbIsOpposing?(idxPokemon)
  48. battler=self.battlers[idxPokemon]
  49. else
  50. battler=self.battlers[idxPokemon].pbOppositeOpposing
  51. end
  52. if battler.fainted?
  53. battler=battler.pbPartner
  54. end
  55. pbDisplayBrief(_INTL("{1} threw one {2}!",self.pbPlayer.name,itemname))
  56. if battler.fainted?
  57. pbDisplay(_INTL("But there was no target..."))
  58. return
  59. end
  60. if @opponent && (!pbIsSnagBall?(ball) || !battler.isShadow?)
  61. @scene.pbThrowAndDeflect(ball,1)
  62. pbDisplay(_INTL("The Trainer blocked the Ball!\nDon't be a thief!"))
  63. else
  64. pokemon=battler.pokemon
  65. species=pokemon.species
  66. if $DEBUG && Input.press?(Input::CTRL)
  67. shakes=4
  68. else
  69. if !rareness
  70. dexdata=pbOpenDexData
  71. pbDexDataOffset(dexdata,pokemon.fSpecies,16)
  72. rareness=dexdata.fgetb # Get rareness from dexdata file
  73. dexdata.close
  74. end
  75. a=battler.totalhp
  76. b=battler.hp
  77. rareness=BallHandlers.modifyCatchRate(ball,rareness,self,battler)
  78. x=(((a*3-b*2)*rareness)/(a*3)).floor
  79. if battler.status==PBStatuses::SLEEP || battler.status==PBStatuses::FROZEN
  80. x=(x*2.5).floor
  81. elsif battler.status!=0
  82. x=(x*1.5).floor
  83. end
  84. c=0
  85. if $Trainer
  86. if $Trainer.pokedexOwned>600
  87. c=(x*2.5/6).floor
  88. elsif $Trainer.pokedexOwned>450
  89. c=(x*2/6).floor
  90. elsif $Trainer.pokedexOwned>300
  91. c=(x*1.5/6).floor
  92. elsif $Trainer.pokedexOwned>150
  93. c=(x*1/6).floor
  94. elsif $Trainer.pokedexOwned>30
  95. c=(x*0.5/6).floor
  96. end
  97. end
  98. shakes=0; critical=false
  99. if x>255 || BallHandlers.isUnconditional?(ball,self,battler)
  100. shakes=4
  101. else
  102. x=1 if x<1
  103. y = ( 65536 / ((255.0/x)**0.1875) ).floor
  104. if USECRITICALCAPTURE && pbRandom(256)<c
  105. critical=true
  106. shakes=4 if pbRandom(65536)<y
  107. else
  108. shakes+=1 if pbRandom(65536)<y
  109. shakes+=1 if pbRandom(65536)<y && shakes==1
  110. shakes+=1 if pbRandom(65536)<y && shakes==2
  111. shakes+=1 if pbRandom(65536)<y && shakes==3
  112. end
  113. end
  114. end
  115. PBDebug.log("[Threw Poké Ball] #{itemname}, #{shakes} shakes (4=capture)")
  116. @scene.pbThrow(ball,shakes,critical,battler.index,showplayer)
  117. case shakes
  118. when 0
  119. pbDisplay(_INTL("Oh no! The Pokémon broke free!"))
  120. BallHandlers.onFailCatch(ball,self,battler)
  121. when 1
  122. pbDisplay(_INTL("Aww... It appeared to be caught!"))
  123. BallHandlers.onFailCatch(ball,self,battler)
  124. when 2
  125. pbDisplay(_INTL("Aargh! Almost had it!"))
  126. BallHandlers.onFailCatch(ball,self,battler)
  127. when 3
  128. pbDisplay(_INTL("Gah! It was so close, too!"))
  129. BallHandlers.onFailCatch(ball,self,battler)
  130. when 4
  131. pbDisplayBrief(_INTL("Gotcha! {1} was caught!",pokemon.name))
  132. @scene.pbThrowSuccess
  133. if pbIsSnagBall?(ball) && @opponent
  134. pbRemoveFromParty(battler.index,battler.pokemonIndex)
  135. battler.pbReset
  136. battler.participants=[]
  137. else
  138. @decision=4
  139. end
  140. if pbIsSnagBall?(ball)
  141. pokemon.ot=self.pbPlayer.name
  142. pokemon.trainerID=self.pbPlayer.id
  143. end
  144. BallHandlers.onCatch(ball,self,pokemon)
  145. pokemon.ballused=pbGetBallType(ball)
  146. ((pokemon.makeUnmega if pokemon.isMega?) rescue nil)
  147. pokemon.makeUnprimal rescue nil
  148. pokemon.pbRecordFirstMoves
  149. if GAINEXPFORCAPTURE
  150. battler.captured=true
  151. pbGainEXP
  152. battler.captured=false
  153. end
  154. if !self.pbPlayer.hasOwned?(species)
  155. self.pbPlayer.setOwned(species)
  156. if $Trainer.pokedex
  157. pbDisplayPaused(_INTL("{1}'s data was added to the Pokédex.",pokemon.name))
  158. @scene.pbShowPokedex(species)
  159. end
  160. end
  161. pokemon.forcedForm = false if MultipleForms.hasFunction?(pokemon.species,"getForm")
  162. @scene.pbHideCaptureBall
  163. if pbIsSnagBall?(ball) && @opponent
  164. pokemon.pbUpdateShadowMoves rescue nil
  165. @snaggedpokemon.push(pokemon)
  166. else
  167. pbStorePokemon(pokemon)
  168. end
  169. end
  170. end
  171. end
  172. end
  173.  
  174.  
  175.  
  176. ################################################################################
  177. # Main battle class.
  178. ################################################################################
  179. class PokeBattle_Battle
  180. attr_reader(:scene) # Scene object for this battle
  181. attr_accessor(:decision) # Decision: 0=undecided; 1=win; 2=loss; 3=escaped; 4=caught
  182. attr_accessor(:internalbattle) # Internal battle flag
  183. attr_accessor(:doublebattle) # Double battle flag
  184. attr_accessor(:cantescape) # True if player can't escape
  185. attr_accessor(:shiftStyle) # Shift/Set "battle style" option
  186. attr_accessor(:battlescene) # "Battle scene" option
  187. attr_accessor(:debug) # Debug flag
  188. attr_reader(:player) # Player trainer
  189. attr_reader(:opponent) # Opponent trainer
  190. attr_reader(:party1) # Player's Pokémon party
  191. attr_reader(:party2) # Foe's Pokémon party
  192. attr_reader(:party1order) # Order of Pokémon in the player's party
  193. attr_reader(:party2order) # Order of Pokémon in the opponent's party
  194. attr_accessor(:fullparty1) # True if player's party's max size is 6 instead of 3
  195. attr_accessor(:fullparty2) # True if opponent's party's max size is 6 instead of 3
  196. attr_reader(:battlers) # Currently active Pokémon
  197. attr_accessor(:items) # Items held by opponents
  198. attr_reader(:sides) # Effects common to each side of a battle
  199. attr_reader(:field) # Effects common to the whole of a battle
  200. attr_accessor(:environment) # Battle surroundings
  201. attr_accessor(:weather) # Current weather, custom methods should use pbWeather instead
  202. attr_accessor(:weatherduration) # Duration of current weather, or -1 if indefinite
  203. attr_reader(:switching) # True if during the switching phase of the round
  204. attr_reader(:futuresight) # True if Future Sight is hitting
  205. attr_reader(:struggle) # The Struggle move
  206. attr_accessor(:choices) # Choices made by each Pokémon this round
  207. attr_reader(:successStates) # Success states
  208. attr_accessor(:lastMoveUsed) # Last move used
  209. attr_accessor(:lastMoveUser) # Last move user
  210. attr_accessor(:megaEvolution) # Battle index of each trainer's Pokémon to Mega Evolve
  211. attr_accessor(:amuletcoin) # Whether Amulet Coin's effect applies
  212. attr_accessor(:extramoney) # Money gained in battle by using Pay Day
  213. attr_accessor(:doublemoney) # Whether Happy Hour's effect applies
  214. attr_accessor(:endspeech) # Speech by opponent when player wins
  215. attr_accessor(:endspeech2) # Speech by opponent when player wins
  216. attr_accessor(:endspeechwin) # Speech by opponent when opponent wins
  217. attr_accessor(:endspeechwin2) # Speech by opponent when opponent wins
  218. attr_accessor(:rules)
  219. attr_reader(:turncount)
  220. attr_accessor :controlPlayer
  221. include PokeBattle_BattleCommon
  222.  
  223. MAXPARTYSIZE = 6
  224.  
  225. class BattleAbortedException < Exception; end
  226.  
  227. def pbAbort
  228. raise BattleAbortedException.new("Battle aborted")
  229. end
  230.  
  231. def pbDebugUpdate
  232. end
  233.  
  234. def pbRandom(x)
  235. return rand(x)
  236. end
  237.  
  238. def pbAIRandom(x)
  239. return rand(x)
  240. end
  241.  
  242. ################################################################################
  243. # Initialise battle class.
  244. ################################################################################
  245. def initialize(scene,p1,p2,player,opponent)
  246. if p1.length==0
  247. raise ArgumentError.new(_INTL("Party 1 has no Pokémon."))
  248. return
  249. end
  250. if p2.length==0
  251. raise ArgumentError.new(_INTL("Party 2 has no Pokémon."))
  252. return
  253. end
  254. if p2.length>2 && !opponent
  255. raise ArgumentError.new(_INTL("Wild battles with more than two Pokémon are not allowed."))
  256. return
  257. end
  258. @scene = scene
  259. @decision = 0
  260. @internalbattle = true
  261. @doublebattle = false
  262. @cantescape = false
  263. @shiftStyle = true
  264. @battlescene = true
  265. @debug = false
  266. @debugupdate = 0
  267. if opponent && player.is_a?(Array) && player.length==0
  268. player = player[0]
  269. end
  270. if opponent && opponent.is_a?(Array) && opponent.length==0
  271. opponent = opponent[0]
  272. end
  273. @player = player # PokeBattle_Trainer object
  274. @opponent = opponent # PokeBattle_Trainer object
  275. @party1 = p1
  276. @party2 = p2
  277. @party1order = []
  278. for i in 0...12; @party1order.push(i); end
  279. @party2order = []
  280. for i in 0...12; @party2order.push(i); end
  281. @fullparty1 = false
  282. @fullparty2 = false
  283. @battlers = []
  284. @items = nil
  285. @sides = [PokeBattle_ActiveSide.new, # Player's side
  286. PokeBattle_ActiveSide.new] # Foe's side
  287. @field = PokeBattle_ActiveField.new # Whole field (gravity/rooms)
  288. @environment = PBEnvironment::None # e.g. Tall grass, cave, still water
  289. @weather = 0
  290. @weatherduration = 0
  291. @switching = false
  292. @futuresight = false
  293. @choices = [ [0,0,nil,-1],[0,0,nil,-1],[0,0,nil,-1],[0,0,nil,-1] ]
  294. @successStates = []
  295. for i in 0...4
  296. @successStates.push(PokeBattle_SuccessState.new)
  297. end
  298. @lastMoveUsed = -1
  299. @lastMoveUser = -1
  300. @nextPickupUse = 0
  301. @megaEvolution = []
  302. if @player.is_a?(Array)
  303. @megaEvolution[0]=[-1]*@player.length
  304. else
  305. @megaEvolution[0]=[-1]
  306. end
  307. if @opponent.is_a?(Array)
  308. @megaEvolution[1]=[-1]*@opponent.length
  309. else
  310. @megaEvolution[1]=[-1]
  311. end
  312. @amuletcoin = false
  313. @extramoney = 0
  314. @doublemoney = false
  315. @endspeech = ""
  316. @endspeech2 = ""
  317. @endspeechwin = ""
  318. @endspeechwin2 = ""
  319. @rules = {}
  320. @turncount = 0
  321. @peer = PokeBattle_BattlePeer.create()
  322. @priority = []
  323. @usepriority = false
  324. @snaggedpokemon = []
  325. @runCommand = 0
  326. if hasConst?(PBMoves,:STRUGGLE)
  327. @struggle = PokeBattle_Move.pbFromPBMove(self,PBMove.new(getConst(PBMoves,:STRUGGLE)))
  328. else
  329. @struggle = PokeBattle_Struggle.new(self,nil)
  330. end
  331. @struggle.pp = -1
  332. for i in 0...4
  333. battlers[i] = PokeBattle_Battler.new(self,i)
  334. end
  335. for i in @party1
  336. next if !i
  337. i.itemRecycle = 0
  338. i.itemInitial = i.item
  339. i.belch = false
  340. end
  341. for i in @party2
  342. next if !i
  343. i.itemRecycle = 0
  344. i.itemInitial = i.item
  345. i.belch = false
  346. end
  347. end
  348.  
  349. ################################################################################
  350. # Info about battle.
  351. ################################################################################
  352. def pbDoubleBattleAllowed?
  353. return false if !@fullparty1 && @party1.length>MAXPARTYSIZE
  354. return false if !@fullparty2 && @party2.length>MAXPARTYSIZE
  355. _opponent=@opponent
  356. _player=@player
  357. # Wild battle
  358. if !_opponent
  359. if @party2.length==1
  360. return false
  361. elsif @party2.length==2
  362. return true
  363. else
  364. return false
  365. end
  366. # Trainer battle
  367. else
  368. if _opponent.is_a?(Array)
  369. if _opponent.length==1
  370. _opponent=_opponent[0]
  371. elsif _opponent.length!=2
  372. return false
  373. end
  374. end
  375. _player=_player
  376. if _player.is_a?(Array)
  377. if _player.length==1
  378. _player=_player[0]
  379. elsif _player.length!=2
  380. return false
  381. end
  382. end
  383. if _opponent.is_a?(Array)
  384. sendout1=pbFindNextUnfainted(@party2,0,pbSecondPartyBegin(1))
  385. sendout2=pbFindNextUnfainted(@party2,pbSecondPartyBegin(1))
  386. return false if sendout1<0 || sendout2<0
  387. else
  388. sendout1=pbFindNextUnfainted(@party2,0)
  389. sendout2=pbFindNextUnfainted(@party2,sendout1+1)
  390. return false if sendout1<0 || sendout2<0
  391. end
  392. end
  393. if _player.is_a?(Array)
  394. sendout1=pbFindNextUnfainted(@party1,0,pbSecondPartyBegin(0))
  395. sendout2=pbFindNextUnfainted(@party1,pbSecondPartyBegin(0))
  396. return false if sendout1<0 || sendout2<0
  397. else
  398. sendout1=pbFindNextUnfainted(@party1,0)
  399. sendout2=pbFindNextUnfainted(@party1,sendout1+1)
  400. return false if sendout1<0 || sendout2<0
  401. end
  402. return true
  403. end
  404.  
  405. def pbWeather
  406. for i in 0...4
  407. if @battlers[i].hasWorkingAbility(:CLOUDNINE) ||
  408. @battlers[i].hasWorkingAbility(:AIRLOCK)
  409. return 0
  410. end
  411. end
  412. return @weather
  413. end
  414.  
  415. ################################################################################
  416. # Get battler info.
  417. ################################################################################
  418. def pbIsOpposing?(index)
  419. return (index%2)==1
  420. end
  421.  
  422. def pbOwnedByPlayer?(index)
  423. return false if pbIsOpposing?(index)
  424. return false if @player.is_a?(Array) && index==2
  425. return true
  426. end
  427.  
  428. def pbIsDoubleBattler?(index)
  429. return (index>=2)
  430. end
  431.  
  432. # Only used for Wish
  433. def pbThisEx(battlerindex,pokemonindex)
  434. party=pbParty(battlerindex)
  435. if pbIsOpposing?(battlerindex)
  436. if @opponent
  437. return _INTL("The foe {1}",party[pokemonindex].name)
  438. else
  439. return _INTL("The wild {1}",party[pokemonindex].name)
  440. end
  441. else
  442. return party[pokemonindex].name
  443. end
  444. end
  445.  
  446. # Checks whether an item can be removed from a Pokémon.
  447. def pbIsUnlosableItem(pkmn,item)
  448. return true if pbIsMail?(item)
  449. return false if pkmn.effects[PBEffects::Transform]
  450. return true if pkmn.pokemon && pkmn.pokemon.getMegaForm(true)!=0 # Mega Stone
  451. if isConst?(pkmn.ability,PBAbilities,:MULTITYPE)
  452. plates=[:FISTPLATE,:SKYPLATE,:TOXICPLATE,:EARTHPLATE,:STONEPLATE,
  453. :INSECTPLATE,:SPOOKYPLATE,:IRONPLATE,:FLAMEPLATE,:SPLASHPLATE,
  454. :MEADOWPLATE,:ZAPPLATE,:MINDPLATE,:ICICLEPLATE,:DRACOPLATE,
  455. :DREADPLATE,:PIXIEPLATE]
  456. for i in plates
  457. return true if isConst?(item,PBItems,i)
  458. end
  459. end
  460. combos=[[:GIRATINA,:GRISEOUSORB],
  461. [:GENESECT,:BURNDRIVE],
  462. [:GENESECT,:CHILLDRIVE],
  463. [:GENESECT,:DOUSEDRIVE],
  464. [:GENESECT,:SHOCKDRIVE],
  465. # Primal Reversion stones
  466. [:KYOGRE,:BLUEORB],
  467. [:GROUDON,:REDORB]
  468. ]
  469. for i in combos
  470. if isConst?(pkmn.species,PBSpecies,i[0]) && isConst?(item,PBItems,i[1])
  471. return true
  472. end
  473. end
  474. return false
  475. end
  476.  
  477. def pbCheckGlobalAbility(a)
  478. for i in 0...4 # in order from own first, opposing first, own second, opposing second
  479. if @battlers[i].hasWorkingAbility(a)
  480. return @battlers[i]
  481. end
  482. end
  483. return nil
  484. end
  485.  
  486. def nextPickupUse
  487. @nextPickupUse+=1
  488. return @nextPickupUse
  489. end
  490.  
  491. ################################################################################
  492. # Player-related info.
  493. ################################################################################
  494. def pbPlayer
  495. if @player.is_a?(Array)
  496. return @player[0]
  497. else
  498. return @player
  499. end
  500. end
  501.  
  502. def pbGetOwnerItems(battlerIndex)
  503. return [] if !@items
  504. if pbIsOpposing?(battlerIndex)
  505. if @opponent.is_a?(Array)
  506. return (battlerIndex==1) ? @items[0] : @items[1]
  507. else
  508. return @items
  509. end
  510. else
  511. return []
  512. end
  513. end
  514.  
  515. def pbSetSeen(pokemon)
  516. if pokemon && @internalbattle
  517. self.pbPlayer.seen[pokemon.species]=true
  518. pbSeenForm(pokemon)
  519. end
  520. end
  521.  
  522. def pbGetMegaRingName(battlerIndex)
  523. if pbBelongsToPlayer?(battlerIndex)
  524. for i in MEGARINGS
  525. next if !hasConst?(PBItems,i)
  526. return PBItems.getName(getConst(PBItems,i)) if $PokemonBag.pbHasItem?(i)
  527. end
  528. end
  529. # Add your own Mega objects for particular NPC trainers here
  530. # if isConst?(pbGetOwner(battlerIndex).trainertype,PBTrainers,:BUGCATCHER)
  531. # return _INTL("Mega Net")
  532. # end
  533. return _INTL("Mega Ring")
  534. end
  535.  
  536. def pbHasMegaRing?(battlerIndex)
  537. return true if !pbBelongsToPlayer?(battlerIndex)
  538. for i in MEGARINGS
  539. next if !hasConst?(PBItems,i)
  540. return true if $PokemonBag.pbHasItem?(i)
  541. end
  542. return false
  543. end
  544.  
  545. ################################################################################
  546. # Get party info, manipulate parties.
  547. ################################################################################
  548. def pbPokemonCount(party)
  549. count=0
  550. for i in party
  551. next if !i
  552. count+=1 if i.hp>0 && !i.egg?
  553. end
  554. return count
  555. end
  556.  
  557. def pbAllFainted?(party)
  558. pbPokemonCount(party)==0
  559. end
  560.  
  561. def pbMaxLevel(party)
  562. lv=0
  563. for i in party
  564. next if !i
  565. lv=i.level if lv<i.level
  566. end
  567. return lv
  568. end
  569.  
  570. def pbMaxLevelFromIndex(index)
  571. party=pbParty(index)
  572. owner=(pbIsOpposing?(index)) ? @opponent : @player
  573. maxlevel=0
  574. if owner.is_a?(Array)
  575. start=0
  576. limit=pbSecondPartyBegin(index)
  577. start=limit if pbIsDoubleBattler?(index)
  578. for i in start...start+limit
  579. next if !party[i]
  580. maxlevel=party[i].level if maxlevel<party[i].level
  581. end
  582. else
  583. for i in party
  584. next if !i
  585. maxlevel=i.level if maxlevel<i.level
  586. end
  587. end
  588. return maxlevel
  589. end
  590.  
  591. def pbParty(index)
  592. return pbIsOpposing?(index) ? party2 : party1
  593. end
  594.  
  595. def pbOpposingParty(index)
  596. return pbIsOpposing?(index) ? party1 : party2
  597. end
  598.  
  599. def pbSecondPartyBegin(battlerIndex)
  600. if pbIsOpposing?(battlerIndex)
  601. return @fullparty2 ? 6 : 3
  602. else
  603. return @fullparty1 ? 6 : 3
  604. end
  605. end
  606.  
  607. def pbPartyLength(battlerIndex)
  608. if pbIsOpposing?(battlerIndex)
  609. return (@opponent.is_a?(Array)) ? pbSecondPartyBegin(battlerIndex) : MAXPARTYSIZE
  610. else
  611. return @player.is_a?(Array) ? pbSecondPartyBegin(battlerIndex) : MAXPARTYSIZE
  612. end
  613. end
  614.  
  615. def pbFindNextUnfainted(party,start,finish=-1)
  616. finish=party.length if finish<0
  617. for i in start...finish
  618. next if !party[i]
  619. return i if party[i].hp>0 && !party[i].egg?
  620. end
  621. return -1
  622. end
  623.  
  624. def pbGetLastPokeInTeam(index)
  625. party=pbParty(index)
  626. partyorder=(!pbIsOpposing?(index)) ? @party1order : @party2order
  627. plength=pbPartyLength(index)
  628. pstart=pbGetOwnerIndex(index)*plength
  629. lastpoke=-1
  630. for i in pstart...pstart+plength
  631. p=party[partyorder[i]]
  632. next if !p || p.egg? || p.hp<=0
  633. lastpoke=partyorder[i]
  634. end
  635. return lastpoke
  636. end
  637.  
  638. def pbFindPlayerBattler(pkmnIndex)
  639. battler=nil
  640. for k in 0...4
  641. if !pbIsOpposing?(k) && @battlers[k].pokemonIndex==pkmnIndex
  642. battler=@battlers[k]
  643. break
  644. end
  645. end
  646. return battler
  647. end
  648.  
  649. def pbIsOwner?(battlerIndex,partyIndex)
  650. secondParty=pbSecondPartyBegin(battlerIndex)
  651. if !pbIsOpposing?(battlerIndex)
  652. return true if !@player || !@player.is_a?(Array)
  653. return (battlerIndex==0) ? partyIndex<secondParty : partyIndex>=secondParty
  654. else
  655. return true if !@opponent || !@opponent.is_a?(Array)
  656. return (battlerIndex==1) ? partyIndex<secondParty : partyIndex>=secondParty
  657. end
  658. end
  659.  
  660. def pbGetOwner(battlerIndex)
  661. if pbIsOpposing?(battlerIndex)
  662. if @opponent.is_a?(Array)
  663. return (battlerIndex==1) ? @opponent[0] : @opponent[1]
  664. else
  665. return @opponent
  666. end
  667. else
  668. if @player.is_a?(Array)
  669. return (battlerIndex==0) ? @player[0] : @player[1]
  670. else
  671. return @player
  672. end
  673. end
  674. end
  675.  
  676. def pbGetOwnerPartner(battlerIndex)
  677. if pbIsOpposing?(battlerIndex)
  678. if @opponent.is_a?(Array)
  679. return (battlerIndex==1) ? @opponent[1] : @opponent[0]
  680. else
  681. return @opponent
  682. end
  683. else
  684. if @player.is_a?(Array)
  685. return (battlerIndex==0) ? @player[1] : @player[0]
  686. else
  687. return @player
  688. end
  689. end
  690. end
  691.  
  692. def pbGetOwnerIndex(battlerIndex)
  693. if pbIsOpposing?(battlerIndex)
  694. return (@opponent.is_a?(Array)) ? ((battlerIndex==1) ? 0 : 1) : 0
  695. else
  696. return (@player.is_a?(Array)) ? ((battlerIndex==0) ? 0 : 1) : 0
  697. end
  698. end
  699.  
  700. def pbBelongsToPlayer?(battlerIndex)
  701. if @player.is_a?(Array) && @player.length>1
  702. return battlerIndex==0
  703. else
  704. return (battlerIndex%2)==0
  705. end
  706. return false
  707. end
  708.  
  709. def pbPartyGetOwner(battlerIndex,partyIndex)
  710. secondParty=pbSecondPartyBegin(battlerIndex)
  711. if !pbIsOpposing?(battlerIndex)
  712. return @player if !@player || !@player.is_a?(Array)
  713. return (partyIndex<secondParty) ? @player[0] : @player[1]
  714. else
  715. return @opponent if !@opponent || !@opponent.is_a?(Array)
  716. return (partyIndex<secondParty) ? @opponent[0] : @opponent[1]
  717. end
  718. end
  719.  
  720. def pbAddToPlayerParty(pokemon)
  721. party=pbParty(0)
  722. for i in 0...party.length
  723. party[i]=pokemon if pbIsOwner?(0,i) && !party[i]
  724. end
  725. end
  726.  
  727. def pbRemoveFromParty(battlerIndex,partyIndex)
  728. party=pbParty(battlerIndex)
  729. side=(pbIsOpposing?(battlerIndex)) ? @opponent : @player
  730. order=(pbIsOpposing?(battlerIndex)) ? @party2order : @party1order
  731. secondpartybegin=pbSecondPartyBegin(battlerIndex)
  732. party[partyIndex]=nil
  733. if !side || !side.is_a?(Array) # Wild or single opponent
  734. party.compact!
  735. for i in partyIndex...party.length+1
  736. for j in 0...4
  737. next if !@battlers[j]
  738. if pbGetOwner(j)==side && @battlers[j].pokemonIndex==i
  739. @battlers[j].pokemonIndex-=1
  740. break
  741. end
  742. end
  743. end
  744. for i in 0...order.length
  745. order[i]=(i==partyIndex) ? order.length-1 : order[i]-1
  746. end
  747. else
  748. if partyIndex<secondpartybegin-1
  749. for i in partyIndex...secondpartybegin
  750. if i>=secondpartybegin-1
  751. party[i]=nil
  752. else
  753. party[i]=party[i+1]
  754. end
  755. end
  756. for i in 0...order.length
  757. next if order[i]>=secondpartybegin
  758. order[i]=(i==partyIndex) ? secondpartybegin-1 : order[i]-1
  759. end
  760. else
  761. for i in partyIndex...secondpartybegin+pbPartyLength(battlerIndex)
  762. if i>=party.length-1
  763. party[i]=nil
  764. else
  765. party[i]=party[i+1]
  766. end
  767. end
  768. for i in 0...order.length
  769. next if order[i]<secondpartybegin
  770. order[i]=(i==partyIndex) ? secondpartybegin+pbPartyLength(battlerIndex)-1 : order[i]-1
  771. end
  772. end
  773. end
  774. end
  775.  
  776. ################################################################################
  777. # Check whether actions can be taken.
  778. ################################################################################
  779. def pbCanShowCommands?(idxPokemon)
  780. thispkmn=@battlers[idxPokemon]
  781. return false if thispkmn.fainted?
  782. return false if thispkmn.effects[PBEffects::TwoTurnAttack]>0
  783. return false if thispkmn.effects[PBEffects::HyperBeam]>0
  784. return false if thispkmn.effects[PBEffects::Rollout]>0
  785. return false if thispkmn.effects[PBEffects::Outrage]>0
  786. return false if thispkmn.effects[PBEffects::Uproar]>0
  787. return false if thispkmn.effects[PBEffects::Bide]>0
  788. return true
  789. end
  790.  
  791. ################################################################################
  792. # Attacking.
  793. ################################################################################
  794. def pbCanShowFightMenu?(idxPokemon)
  795. thispkmn=@battlers[idxPokemon]
  796. if !pbCanShowCommands?(idxPokemon)
  797. return false
  798. end
  799. # No moves that can be chosen
  800. if !pbCanChooseMove?(idxPokemon,0,false) &&
  801. !pbCanChooseMove?(idxPokemon,1,false) &&
  802. !pbCanChooseMove?(idxPokemon,2,false) &&
  803. !pbCanChooseMove?(idxPokemon,3,false)
  804. return false
  805. end
  806. # Encore
  807. return false if thispkmn.effects[PBEffects::Encore]>0
  808. return true
  809. end
  810.  
  811. def pbCanChooseMove?(idxPokemon,idxMove,showMessages,sleeptalk=false)
  812. thispkmn=@battlers[idxPokemon]
  813. thismove=thispkmn.moves[idxMove]
  814. opp1=thispkmn.pbOpposing1
  815. opp2=thispkmn.pbOpposing2
  816. if !thismove || thismove.id==0
  817. return false
  818. end
  819. if thismove.pp<=0 && thismove.totalpp>0 && !sleeptalk
  820. if showMessages
  821. pbDisplayPaused(_INTL("There's no PP left for this move!"))
  822. end
  823. return false
  824. end
  825. if thispkmn.hasWorkingItem(:ASSAULTVEST) && thismove.pbIsStatus?
  826. if showMessages
  827. pbDisplayPaused(_INTL("The effects of the {1} prevent status moves from being used!",
  828. PBItems.getName(thispkmn.item)))
  829. end
  830. return false
  831. end
  832. if thispkmn.effects[PBEffects::ChoiceBand]>=0 &&
  833. (thispkmn.hasWorkingItem(:CHOICEBAND) ||
  834. thispkmn.hasWorkingItem(:CHOICESPECS) ||
  835. thispkmn.hasWorkingItem(:CHOICESCARF))
  836. hasmove=false
  837. for i in 0...4
  838. if thispkmn.moves[i].id==thispkmn.effects[PBEffects::ChoiceBand]
  839. hasmove=true; break
  840. end
  841. end
  842. if hasmove && thismove.id!=thispkmn.effects[PBEffects::ChoiceBand]
  843. if showMessages
  844. pbDisplayPaused(_INTL("{1} allows the use of only {2}!",
  845. PBItems.getName(thispkmn.item),
  846. PBMoves.getName(thispkmn.effects[PBEffects::ChoiceBand])))
  847. end
  848. return false
  849. end
  850. end
  851. if opp1.effects[PBEffects::Imprison]
  852. if thismove.id==opp1.moves[0].id ||
  853. thismove.id==opp1.moves[1].id ||
  854. thismove.id==opp1.moves[2].id ||
  855. thismove.id==opp1.moves[3].id
  856. if showMessages
  857. pbDisplayPaused(_INTL("{1} can't use the sealed {2}!",thispkmn.pbThis,thismove.name))
  858. end
  859. #PBDebug.log("[CanChoose][#{opp1.pbThis} has: #{opp1.moves[0].name}, #{opp1.moves[1].name},#{opp1.moves[2].name},#{opp1.moves[3].name}]")
  860. return false
  861. end
  862. end
  863. if opp2.effects[PBEffects::Imprison]
  864. if thismove.id==opp2.moves[0].id ||
  865. thismove.id==opp2.moves[1].id ||
  866. thismove.id==opp2.moves[2].id ||
  867. thismove.id==opp2.moves[3].id
  868. if showMessages
  869. pbDisplayPaused(_INTL("{1} can't use the sealed {2}!",thispkmn.pbThis,thismove.name))
  870. end
  871. #PBDebug.log("[CanChoose][#{opp2.pbThis} has: #{opp2.moves[0].name}, #{opp2.moves[1].name},#{opp2.moves[2].name},#{opp2.moves[3].name}]")
  872. return false
  873. end
  874. end
  875. if thispkmn.effects[PBEffects::Taunt]>0 && thismove.basedamage==0
  876. if showMessages
  877. pbDisplayPaused(_INTL("{1} can't use {2} after the taunt!",thispkmn.pbThis,thismove.name))
  878. end
  879. return false
  880. end
  881. if thispkmn.effects[PBEffects::Torment]
  882. if thismove.id==thispkmn.lastMoveUsed
  883. if showMessages
  884. pbDisplayPaused(_INTL("{1} can't use the same move twice in a row due to the torment!",thispkmn.pbThis))
  885. end
  886. return false
  887. end
  888. end
  889. if thismove.id==thispkmn.effects[PBEffects::DisableMove] && !sleeptalk
  890. if showMessages
  891. pbDisplayPaused(_INTL("{1}'s {2} is disabled!",thispkmn.pbThis,thismove.name))
  892. end
  893. return false
  894. end
  895. if thismove.function==0x158 && # Belch
  896. (!thispkmn.pokemon || !thispkmn.pokemon.belch)
  897. if showMessages
  898. pbDisplayPaused(_INTL("{1} hasn't eaten any held berry, so it can't possibly belch!",thispkmn.pbThis))
  899. end
  900. return false
  901. end
  902. if thispkmn.effects[PBEffects::Encore]>0 && idxMove!=thispkmn.effects[PBEffects::EncoreIndex]
  903. return false
  904. end
  905. return true
  906. end
  907.  
  908. def pbAutoChooseMove(idxPokemon,showMessages=true)
  909. thispkmn=@battlers[idxPokemon]
  910. if thispkmn.fainted?
  911. @choices[idxPokemon][0]=0
  912. @choices[idxPokemon][1]=0
  913. @choices[idxPokemon][2]=nil
  914. return
  915. end
  916. if thispkmn.effects[PBEffects::Encore]>0 &&
  917. pbCanChooseMove?(idxPokemon,thispkmn.effects[PBEffects::EncoreIndex],false)
  918. PBDebug.log("[Auto choosing Encore move] #{thispkmn.moves[thispkmn.effects[PBEffects::EncoreIndex]].name}")
  919. @choices[idxPokemon][0]=1 # "Use move"
  920. @choices[idxPokemon][1]=thispkmn.effects[PBEffects::EncoreIndex] # Index of move
  921. @choices[idxPokemon][2]=thispkmn.moves[thispkmn.effects[PBEffects::EncoreIndex]]
  922. @choices[idxPokemon][3]=-1 # No target chosen yet
  923. if @doublebattle
  924. thismove=thispkmn.moves[thispkmn.effects[PBEffects::EncoreIndex]]
  925. target=thispkmn.pbTarget(thismove)
  926. if target==PBTargets::SingleNonUser
  927. target=@scene.pbChooseTarget(idxPokemon,target)
  928. pbRegisterTarget(idxPokemon,target) if target>=0
  929. elsif target==PBTargets::UserOrPartner
  930. target=@scene.pbChooseTarget(idxPokemon,target)
  931. pbRegisterTarget(idxPokemon,target) if target>=0 && (target&1)==(idxPokemon&1)
  932. end
  933. end
  934. else
  935. if !pbIsOpposing?(idxPokemon)
  936. pbDisplayPaused(_INTL("{1} has no moves left!",thispkmn.name)) if showMessages
  937. end
  938. @choices[idxPokemon][0]=1 # "Use move"
  939. @choices[idxPokemon][1]=-1 # Index of move to be used
  940. @choices[idxPokemon][2]=@struggle # Use Struggle
  941. @choices[idxPokemon][3]=-1 # No target chosen yet
  942. end
  943. end
  944.  
  945. def pbRegisterMove(idxPokemon,idxMove,showMessages=true)
  946. thispkmn=@battlers[idxPokemon]
  947. thismove=thispkmn.moves[idxMove]
  948. return false if !pbCanChooseMove?(idxPokemon,idxMove,showMessages)
  949. @choices[idxPokemon][0]=1 # "Use move"
  950. @choices[idxPokemon][1]=idxMove # Index of move to be used
  951. @choices[idxPokemon][2]=thismove # PokeBattle_Move object of the move
  952. @choices[idxPokemon][3]=-1 # No target chosen yet
  953. return true
  954. end
  955.  
  956. def pbChoseMove?(i,move)
  957. return false if @battlers[i].fainted?
  958. if @choices[i][0]==1 && @choices[i][1]>=0
  959. choice=@choices[i][1]
  960. return isConst?(@battlers[i].moves[choice].id,PBMoves,move)
  961. end
  962. return false
  963. end
  964.  
  965. def pbChoseMoveFunctionCode?(i,code)
  966. return false if @battlers[i].fainted?
  967. if @choices[i][0]==1 && @choices[i][1]>=0
  968. choice=@choices[i][1]
  969. return @battlers[i].moves[choice].function==code
  970. end
  971. return false
  972. end
  973.  
  974. def pbRegisterTarget(idxPokemon,idxTarget)
  975. @choices[idxPokemon][3]=idxTarget # Set target of move
  976. return true
  977. end
  978.  
  979. def pbPriority(ignorequickclaw=false,log=false)
  980. return @priority if @usepriority # use stored priority if round isn't over yet
  981. @priority.clear
  982. speeds=[]
  983. priorities=[]
  984. quickclaw=[]; lagging=[]
  985. minpri=0; maxpri=0
  986. temp=[]
  987. # Calculate each Pokémon's speed
  988. for i in 0...4
  989. speeds[i]=@battlers[i].pbSpeed
  990. quickclaw[i]=false
  991. lagging[i]=false
  992. if !ignorequickclaw && @choices[i][0]==1 # Chose to use a move
  993. if !quickclaw[i] && @battlers[i].hasWorkingItem(:CUSTAPBERRY) &&
  994. !@battlers[i].pbOpposing1.hasWorkingAbility(:UNNERVE) &&
  995. !@battlers[i].pbOpposing2.hasWorkingAbility(:UNNERVE)
  996. if (@battlers[i].hasWorkingAbility(:GLUTTONY) && @battlers[i].hp<=(@battlers[i].totalhp/2).floor) ||
  997. @battlers[i].hp<=(@battlers[i].totalhp/4).floor
  998. pbCommonAnimation("UseItem",@battlers[i],nil)
  999. quickclaw[i]=true
  1000. pbDisplayBrief(_INTL("{1}'s {2} let it move first!",
  1001. @battlers[i].pbThis,PBItems.getName(@battlers[i].item)))
  1002. @battlers[i].pbConsumeItem
  1003. end
  1004. end
  1005. if !quickclaw[i] && @battlers[i].hasWorkingItem(:QUICKCLAW)
  1006. if pbRandom(10)<2
  1007. pbCommonAnimation("UseItem",@battlers[i],nil)
  1008. quickclaw[i]=true
  1009. pbDisplayBrief(_INTL("{1}'s {2} let it move first!",
  1010. @battlers[i].pbThis,PBItems.getName(@battlers[i].item)))
  1011. end
  1012. end
  1013. if !quickclaw[i] &&
  1014. (@battlers[i].hasWorkingAbility(:STALL) ||
  1015. @battlers[i].hasWorkingItem(:LAGGINGTAIL) ||
  1016. @battlers[i].hasWorkingItem(:FULLINCENSE))
  1017. lagging[i]=true
  1018. end
  1019. end
  1020. end
  1021. # Calculate each Pokémon's priority bracket, and get the min/max priorities
  1022. for i in 0...4
  1023. # Assume that doing something other than using a move is priority 0
  1024. pri=0
  1025. if @choices[i][0]==1 # Chose to use a move
  1026. pri=@choices[i][2].priority
  1027. pri+=1 if @battlers[i].hasWorkingAbility(:PRANKSTER) &&
  1028. @choices[i][2].pbIsStatus?
  1029. pri+=1 if @battlers[i].hasWorkingAbility(:GALEWINGS) &&
  1030. isConst?(@choices[i][2].type,PBTypes,:FLYING)
  1031. end
  1032. priorities[i]=pri
  1033. if i==0
  1034. minpri=pri
  1035. maxpri=pri
  1036. else
  1037. minpri=pri if minpri>pri
  1038. maxpri=pri if maxpri<pri
  1039. end
  1040. end
  1041. # Find and order all moves with the same priority
  1042. curpri=maxpri
  1043. loop do
  1044. temp.clear
  1045. for j in 0...4
  1046. temp.push(j) if priorities[j]==curpri
  1047. end
  1048. # Sort by speed
  1049. if temp.length==1
  1050. @priority[@priority.length]=@battlers[temp[0]]
  1051. elsif temp.length>1
  1052. n=temp.length
  1053. for m in 0...temp.length-1
  1054. for i in 1...temp.length
  1055. # For each pair of battlers, rank the second compared to the first
  1056. # -1 means rank higher, 0 means rank equal, 1 means rank lower
  1057. cmp=0
  1058. if quickclaw[temp[i]]
  1059. cmp=-1
  1060. if quickclaw[temp[i-1]]
  1061. if speeds[temp[i]]==speeds[temp[i-1]]
  1062. cmp=0
  1063. else
  1064. cmp=(speeds[temp[i]]>speeds[temp[i-1]]) ? -1 : 1
  1065. end
  1066. end
  1067. elsif quickclaw[temp[i-1]]
  1068. cmp=1
  1069. elsif lagging[temp[i]]
  1070. cmp=1
  1071. if lagging[temp[i-1]]
  1072. if speeds[temp[i]]==speeds[temp[i-1]]
  1073. cmp=0
  1074. else
  1075. cmp=(speeds[temp[i]]>speeds[temp[i-1]]) ? 1 : -1
  1076. end
  1077. end
  1078. elsif lagging[temp[i-1]]
  1079. cmp=-1
  1080. elsif speeds[temp[i]]!=speeds[temp[i-1]]
  1081. if @field.effects[PBEffects::TrickRoom]>0
  1082. cmp=(speeds[temp[i]]>speeds[temp[i-1]]) ? 1 : -1
  1083. else
  1084. cmp=(speeds[temp[i]]>speeds[temp[i-1]]) ? -1 : 1
  1085. end
  1086. end
  1087. if cmp<0 || # Swap the pair according to the second battler's rank
  1088. (cmp==0 && pbRandom(2)==0)
  1089. swaptmp=temp[i]
  1090. temp[i]=temp[i-1]
  1091. temp[i-1]=swaptmp
  1092. end
  1093. end
  1094. end
  1095. # Battlers in this bracket are properly sorted, so add them to @priority
  1096. for i in temp
  1097. @priority[@priority.length]=@battlers[i]
  1098. end
  1099. end
  1100. curpri-=1
  1101. break if curpri<minpri
  1102. end
  1103. # Write the priority order to the debug log
  1104. if log
  1105. d="[Priority] "; comma=false
  1106. for i in 0...4
  1107. if @priority[i] && !@priority[i].fainted?
  1108. d+=", " if comma
  1109. d+="#{@priority[i].pbThis(comma)} (#{@priority[i].index})"; comma=true
  1110. end
  1111. end
  1112. PBDebug.log(d)
  1113. end
  1114. @usepriority=true
  1115. return @priority
  1116. end
  1117.  
  1118. ################################################################################
  1119. # Switching Pokémon.
  1120. ################################################################################
  1121. def pbCanSwitchLax?(idxPokemon,pkmnidxTo,showMessages)
  1122. if pkmnidxTo>=0
  1123. party=pbParty(idxPokemon)
  1124. return false if pkmnidxTo>=party.length
  1125. return false if !party[pkmnidxTo]
  1126. if party[pkmnidxTo].egg?
  1127. pbDisplayPaused(_INTL("An Egg can't battle!")) if showMessages
  1128. return false
  1129. end
  1130. if !pbIsOwner?(idxPokemon,pkmnidxTo)
  1131. owner=pbPartyGetOwner(idxPokemon,pkmnidxTo)
  1132. pbDisplayPaused(_INTL("You can't switch {1}'s Pokémon with one of yours!",owner.name)) if showMessages
  1133. return false
  1134. end
  1135. if party[pkmnidxTo].hp<=0
  1136. pbDisplayPaused(_INTL("{1} has no energy left to battle!",party[pkmnidxTo].name)) if showMessages
  1137. return false
  1138. end
  1139. if @battlers[idxPokemon].pokemonIndex==pkmnidxTo ||
  1140. @battlers[idxPokemon].pbPartner.pokemonIndex==pkmnidxTo
  1141. pbDisplayPaused(_INTL("{1} is already in battle!",party[pkmnidxTo].name)) if showMessages
  1142. return false
  1143. end
  1144. end
  1145. return true
  1146. end
  1147.  
  1148. def pbCanSwitch?(idxPokemon,pkmnidxTo,showMessages,ignoremeanlook=false)
  1149. thispkmn=@battlers[idxPokemon]
  1150. # Multi-Turn Attacks/Mean Look
  1151. return false if !pbCanSwitchLax?(idxPokemon,pkmnidxTo,showMessages)
  1152. isOpposing=pbIsOpposing?(idxPokemon)
  1153. party=pbParty(idxPokemon)
  1154. for i in 0...4
  1155. next if isOpposing!=pbIsOpposing?(i)
  1156. if choices[i][0]==2 && choices[i][1]==pkmnidxTo
  1157. pbDisplayPaused(_INTL("{1} has already been selected.",party[pkmnidxTo].name)) if showMessages
  1158. return false
  1159. end
  1160. end
  1161. return true if thispkmn.hasWorkingItem(:SHEDSHELL)
  1162. return true if USENEWBATTLEMECHANICS && thispkmn.pbHasType?(:GHOST)
  1163. if thispkmn.effects[PBEffects::MultiTurn]>0 ||
  1164. (!ignoremeanlook && thispkmn.effects[PBEffects::MeanLook]>=0)
  1165. pbDisplayPaused(_INTL("{1} can't be switched out!",thispkmn.pbThis)) if showMessages
  1166. return false
  1167. end
  1168. if @field.effects[PBEffects::FairyLock]>0
  1169. pbDisplayPaused(_INTL("{1} can't be switched out!",thispkmn.pbThis)) if showMessages
  1170. return false
  1171. end
  1172. if thispkmn.effects[PBEffects::Ingrain]
  1173. pbDisplayPaused(_INTL("{1} can't be switched out!",thispkmn.pbThis)) if showMessages
  1174. return false
  1175. end
  1176. opp1=thispkmn.pbOpposing1
  1177. opp2=thispkmn.pbOpposing2
  1178. opp=nil
  1179. if thispkmn.pbHasType?(:STEEL)
  1180. opp=opp1 if opp1.hasWorkingAbility(:MAGNETPULL)
  1181. opp=opp2 if opp2.hasWorkingAbility(:MAGNETPULL)
  1182. end
  1183. if !thispkmn.isAirborne?
  1184. opp=opp1 if opp1.hasWorkingAbility(:ARENATRAP)
  1185. opp=opp2 if opp2.hasWorkingAbility(:ARENATRAP)
  1186. end
  1187. if !thispkmn.hasWorkingAbility(:SHADOWTAG)
  1188. opp=opp1 if opp1.hasWorkingAbility(:SHADOWTAG)
  1189. opp=opp2 if opp2.hasWorkingAbility(:SHADOWTAG)
  1190. end
  1191. if opp
  1192. abilityname=PBAbilities.getName(opp.ability)
  1193. pbDisplayPaused(_INTL("{1}'s {2} prevents switching!",opp.pbThis,abilityname)) if showMessages
  1194. return false
  1195. end
  1196. return true
  1197. end
  1198.  
  1199. def pbRegisterSwitch(idxPokemon,idxOther)
  1200. return false if !pbCanSwitch?(idxPokemon,idxOther,false)
  1201. @choices[idxPokemon][0]=2 # "Switch Pokémon"
  1202. @choices[idxPokemon][1]=idxOther # Index of other Pokémon to switch with
  1203. @choices[idxPokemon][2]=nil
  1204. side=(pbIsOpposing?(idxPokemon)) ? 1 : 0
  1205. owner=pbGetOwnerIndex(idxPokemon)
  1206. if @megaEvolution[side][owner]==idxPokemon
  1207. @megaEvolution[side][owner]=-1
  1208. end
  1209. return true
  1210. end
  1211.  
  1212. def pbCanChooseNonActive?(index)
  1213. party=pbParty(index)
  1214. for i in 0...party.length
  1215. return true if pbCanSwitchLax?(index,i,false)
  1216. end
  1217. return false
  1218. end
  1219.  
  1220. def pbSwitch(favorDraws=false)
  1221. if !favorDraws
  1222. return if @decision>0
  1223. else
  1224. return if @decision==5
  1225. end
  1226. pbJudge()
  1227. return if @decision>0
  1228. firstbattlerhp=@battlers[0].hp
  1229. switched=[]
  1230. for index in 0...4
  1231. next if !@doublebattle && pbIsDoubleBattler?(index)
  1232. next if @battlers[index] && !@battlers[index].fainted?
  1233. next if !pbCanChooseNonActive?(index)
  1234. if !pbOwnedByPlayer?(index)
  1235. if !pbIsOpposing?(index) || (@opponent && pbIsOpposing?(index))
  1236. newenemy=pbSwitchInBetween(index,false,false)
  1237. newenemyname=newenemy
  1238. if newenemy>=0 && isConst?(pbParty(index)[newenemy].ability,PBAbilities,:ILLUSION)
  1239. newenemyname=pbGetLastPokeInTeam(index)
  1240. end
  1241. opponent=pbGetOwner(index)
  1242. if !@doublebattle && firstbattlerhp>0 && @shiftStyle && @opponent &&
  1243. @internalbattle && pbCanChooseNonActive?(0) && pbIsOpposing?(index) &&
  1244. @battlers[0].effects[PBEffects::Outrage]==0
  1245. pbDisplayPaused(_INTL("{1} is about to send in {2}.",opponent.fullname,pbParty(index)[newenemyname].name))
  1246. if pbDisplayConfirm(_INTL("Will {1} change Pokémon?",self.pbPlayer.name))
  1247. newpoke=pbSwitchPlayer(0,true,true)
  1248. if newpoke>=0
  1249. newpokename=newpoke
  1250. if isConst?(@party1[newpoke].ability,PBAbilities,:ILLUSION)
  1251. newpokename=pbGetLastPokeInTeam(0)
  1252. end
  1253. pbDisplayBrief(_INTL("{1}, that's enough! Come back!",@battlers[0].name))
  1254. pbRecallAndReplace(0,newpoke,newpokename)
  1255. switched.push(0)
  1256. end
  1257. end
  1258. end
  1259. pbRecallAndReplace(index,newenemy,newenemyname,false,false)
  1260. switched.push(index)
  1261. end
  1262. elsif @opponent
  1263. newpoke=pbSwitchInBetween(index,true,false)
  1264. newpokename=newpoke
  1265. if isConst?(@party1[newpoke].ability,PBAbilities,:ILLUSION)
  1266. newpokename=pbGetLastPokeInTeam(index)
  1267. end
  1268. pbRecallAndReplace(index,newpoke,newpokename)
  1269. switched.push(index)
  1270. else
  1271. switch=false
  1272. if !pbDisplayConfirm(_INTL("Use next Pokémon?"))
  1273. switch=(pbRun(index,true)<=0)
  1274. else
  1275. switch=true
  1276. end
  1277. if switch
  1278. newpoke=pbSwitchInBetween(index,true,false)
  1279. newpokename=newpoke
  1280. if isConst?(@party1[newpoke].ability,PBAbilities,:ILLUSION)
  1281. newpokename=pbGetLastPokeInTeam(index)
  1282. end
  1283. pbRecallAndReplace(index,newpoke,newpokename)
  1284. switched.push(index)
  1285. end
  1286. end
  1287. end
  1288. if switched.length>0
  1289. priority=pbPriority
  1290. for i in priority
  1291. i.pbAbilitiesOnSwitchIn(true) if switched.include?(i.index)
  1292. end
  1293. end
  1294. end
  1295.  
  1296. def pbSendOut(index,pokemon)
  1297. pbSetSeen(pokemon)
  1298. @peer.pbOnEnteringBattle(self,pokemon)
  1299. if pbIsOpposing?(index)
  1300. @scene.pbTrainerSendOut(index,pokemon)
  1301. else
  1302. @scene.pbSendOut(index,pokemon)
  1303. #bugtrainer/rival
  1304. if $game_switches[130] and pbPokemonCount(@party2)==1
  1305. @scene.pbShowOpponent(0)
  1306. pbDisplayPaused(_INTL("????: Uhhh, that's a Kakuna..."))
  1307. @peer.pbOnEnteringBattle(self,pokemon) #mistake?
  1308. pbDisplayPaused(_INTL("Rusty: Uhuh. I know: I named it Pikachu after my hero's favorite Pokémon!"))
  1309. pbDisplayPaused(_INTL("????: Uhh, ok... Go Rattata!"))
  1310. pbDisplayPaused(_INTL("Rusty: PIKACHU, USE HEADBUTT!!!"))
  1311. @scene.pbHideOpponent
  1312. end
  1313. end
  1314. @scene.pbResetMoveIndex(index)
  1315. end
  1316.  
  1317. def pbReplace(index,newpoke,batonpass=false)
  1318. party=pbParty(index)
  1319. oldpoke=@battlers[index].pokemonIndex
  1320. # Initialise the new Pokémon
  1321. @battlers[index].pbInitialize(party[newpoke],newpoke,batonpass)
  1322. # Reorder the party for this battle
  1323. partyorder=(!pbIsOpposing?(index)) ? @party1order : @party2order
  1324. bpo=-1; bpn=-1
  1325. for i in 0...partyorder.length
  1326. bpo=i if partyorder[i]==oldpoke
  1327. bpn=i if partyorder[i]==newpoke
  1328. end
  1329. p=partyorder[bpo]; partyorder[bpo]=partyorder[bpn]; partyorder[bpn]=p
  1330. # Send out the new Pokémon
  1331. pbSendOut(index,party[newpoke])
  1332. pbSetSeen(party[newpoke])
  1333. end
  1334.  
  1335. def pbRecallAndReplace(index,newpoke,newpokename=-1,batonpass=false,moldbreaker=false)
  1336. @battlers[index].pbResetForm
  1337. if !@battlers[index].fainted?
  1338. @scene.pbRecall(index)
  1339. end
  1340. pbMessagesOnReplace(index,newpoke,newpokename)
  1341. pbReplace(index,newpoke,batonpass)
  1342. return pbOnActiveOne(@battlers[index],false,moldbreaker)
  1343. end
  1344.  
  1345. def pbMessagesOnReplace(index,newpoke,newpokename=-1)
  1346. newpokename=newpoke if newpokename<0
  1347. party=pbParty(index)
  1348. if pbOwnedByPlayer?(index)
  1349. # if !party[newpoke]
  1350. # p [index,newpoke,party[newpoke],pbAllFainted?(party)]
  1351. # PBDebug.log([index,newpoke,party[newpoke],"pbMOR"].inspect)
  1352. # for i in 0...party.length
  1353. # PBDebug.log([i,party[i].hp].inspect)
  1354. # end
  1355. # raise BattleAbortedException.new
  1356. # end
  1357. opposing=@battlers[index].pbOppositeOpposing
  1358. if opposing.fainted? || opposing.hp==opposing.totalhp
  1359. pbDisplayBrief(_INTL("Go! {1}!",party[newpokename].name))
  1360. elsif opposing.hp>=(opposing.totalhp/2)
  1361. pbDisplayBrief(_INTL("Do it! {1}!",party[newpokename].name))
  1362. elsif opposing.hp>=(opposing.totalhp/4)
  1363. pbDisplayBrief(_INTL("Go for it, {1}!",party[newpokename].name))
  1364. else
  1365. pbDisplayBrief(_INTL("Your opponent's weak!\nGet 'em, {1}!",party[newpokename].name))
  1366. end
  1367. PBDebug.log("[Send out Pokémon] Player sent out #{party[newpokename].name} in position #{index}")
  1368. else
  1369. # if !party[newpoke]
  1370. # p [index,newpoke,party[newpoke],pbAllFainted?(party)]
  1371. # PBDebug.log([index,newpoke,party[newpoke],"pbMOR"].inspect)
  1372. # for i in 0...party.length
  1373. # PBDebug.log([i,party[i].hp].inspect)
  1374. # end
  1375. # raise BattleAbortedException.new
  1376. # end
  1377. owner=pbGetOwner(index)
  1378. pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",owner.fullname,party[newpokename].name))
  1379. PBDebug.log("[Send out Pokémon] Opponent sent out #{party[newpokename].name} in position #{index}")
  1380. end
  1381. end
  1382.  
  1383. def pbSwitchInBetween(index,lax,cancancel)
  1384. if !pbOwnedByPlayer?(index)
  1385. return @scene.pbChooseNewEnemy(index,pbParty(index))
  1386. else
  1387. return pbSwitchPlayer(index,lax,cancancel)
  1388. end
  1389. end
  1390.  
  1391. def pbSwitchPlayer(index,lax,cancancel)
  1392. if @debug
  1393. return @scene.pbChooseNewEnemy(index,pbParty(index))
  1394. else
  1395. return @scene.pbSwitch(index,lax,cancancel)
  1396. end
  1397. end
  1398.  
  1399. ################################################################################
  1400. # Using an item.
  1401. ################################################################################
  1402. # Uses an item on a Pokémon in the player's party.
  1403. def pbUseItemOnPokemon(item,pkmnIndex,userPkmn,scene)
  1404. pokemon=@party1[pkmnIndex]
  1405. battler=nil
  1406. name=pbGetOwner(userPkmn.index).fullname
  1407. name=pbGetOwner(userPkmn.index).name if pbBelongsToPlayer?(userPkmn.index)
  1408. pbDisplayBrief(_INTL("{1} used the\r\n{2}.",name,PBItems.getName(item)))
  1409. PBDebug.log("[Use item] Player used #{PBItems.getName(item)} on #{pokemon.name}")
  1410. ret=false
  1411. if pokemon.egg?
  1412. pbDisplay(_INTL("But it had no effect!"))
  1413. else
  1414. for i in 0...4
  1415. if !pbIsOpposing?(i) && @battlers[i].pokemonIndex==pkmnIndex
  1416. battler=@battlers[i]
  1417. end
  1418. end
  1419. ret=ItemHandlers.triggerBattleUseOnPokemon(item,pokemon,battler,scene)
  1420. end
  1421. if !ret && pbBelongsToPlayer?(userPkmn.index)
  1422. if $PokemonBag.pbCanStore?(item)
  1423. $PokemonBag.pbStoreItem(item)
  1424. else
  1425. raise _INTL("Couldn't return unused item to Bag somehow.")
  1426. end
  1427. end
  1428. return ret
  1429. end
  1430.  
  1431. # Uses an item on an active Pokémon.
  1432. def pbUseItemOnBattler(item,index,userPkmn,scene)
  1433. PBDebug.log("[Use item] Player used #{PBItems.getName(item)} on #{@battlers[index].pbThis(true)}")
  1434. ret=ItemHandlers.triggerBattleUseOnBattler(item,@battlers[index],scene)
  1435. if !ret && pbBelongsToPlayer?(userPkmn.index)
  1436. if $PokemonBag.pbCanStore?(item)
  1437. $PokemonBag.pbStoreItem(item)
  1438. else
  1439. raise _INTL("Couldn't return unused item to Bag somehow.")
  1440. end
  1441. end
  1442. return ret
  1443. end
  1444.  
  1445. def pbRegisterItem(idxPokemon,idxItem,idxTarget=nil)
  1446. if idxTarget!=nil && idxTarget>=0
  1447. for i in 0...4
  1448. if !@battlers[i].pbIsOpposing?(idxPokemon) &&
  1449. @battlers[i].pokemonIndex==idxTarget &&
  1450. @battlers[i].effects[PBEffects::Embargo]>0
  1451. pbDisplay(_INTL("Embargo's effect prevents the item's use on {1}!",@battlers[i].pbThis(true)))
  1452. if pbBelongsToPlayer?(@battlers[i].index)
  1453. if $PokemonBag.pbCanStore?(idxItem)
  1454. $PokemonBag.pbStoreItem(idxItem)
  1455. else
  1456. raise _INTL("Couldn't return unused item to Bag somehow.")
  1457. end
  1458. end
  1459. return false
  1460. end
  1461. end
  1462. end
  1463. if ItemHandlers.hasUseInBattle(idxItem)
  1464. if idxPokemon==0 # Player's first Pokémon
  1465. if ItemHandlers.triggerBattleUseOnBattler(idxItem,@battlers[idxPokemon],self)
  1466. # Using Poké Balls or Poké Doll only
  1467. ItemHandlers.triggerUseInBattle(idxItem,@battlers[idxPokemon],self)
  1468. if @doublebattle
  1469. @battlers[idxPokemon].pbPartner.effects[PBEffects::SkipTurn]=true
  1470. end
  1471. else
  1472. if $PokemonBag.pbCanStore?(idxItem)
  1473. $PokemonBag.pbStoreItem(idxItem)
  1474. else
  1475. raise _INTL("Couldn't return unusable item to Bag somehow.")
  1476. end
  1477. return false
  1478. end
  1479. else
  1480. if ItemHandlers.triggerBattleUseOnBattler(idxItem,@battlers[idxPokemon],self)
  1481. pbDisplay(_INTL("It's impossible to aim without being focused!"))
  1482. end
  1483. return false
  1484. end
  1485. end
  1486. @choices[idxPokemon][0]=3 # "Use an item"
  1487. @choices[idxPokemon][1]=idxItem # ID of item to be used
  1488. @choices[idxPokemon][2]=idxTarget # Index of Pokémon to use item on
  1489. side=(pbIsOpposing?(idxPokemon)) ? 1 : 0
  1490. owner=pbGetOwnerIndex(idxPokemon)
  1491. if @megaEvolution[side][owner]==idxPokemon
  1492. @megaEvolution[side][owner]=-1
  1493. end
  1494. return true
  1495. end
  1496.  
  1497. def pbEnemyUseItem(item,battler)
  1498. return 0 if !@internalbattle
  1499. items=pbGetOwnerItems(battler.index)
  1500. return if !items
  1501. opponent=pbGetOwner(battler.index)
  1502. for i in 0...items.length
  1503. if items[i]==item
  1504. items.delete_at(i)
  1505. break
  1506. end
  1507. end
  1508. itemname=PBItems.getName(item)
  1509. pbDisplayBrief(_INTL("{1} used the\r\n{2}!",opponent.fullname,itemname))
  1510. PBDebug.log("[Use item] Opponent used #{itemname} on #{battler.pbThis(true)}")
  1511. if isConst?(item,PBItems,:POTION)
  1512. battler.pbRecoverHP(20,true)
  1513. pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
  1514. elsif isConst?(item,PBItems,:SUPERPOTION)
  1515. battler.pbRecoverHP(50,true)
  1516. pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
  1517. elsif isConst?(item,PBItems,:HYPERPOTION)
  1518. battler.pbRecoverHP(200,true)
  1519. pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
  1520. elsif isConst?(item,PBItems,:MAXPOTION)
  1521. battler.pbRecoverHP(battler.totalhp-battler.hp,true)
  1522. pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
  1523. elsif isConst?(item,PBItems,:FULLRESTORE)
  1524. fullhp=(battler.hp==battler.totalhp)
  1525. battler.pbRecoverHP(battler.totalhp-battler.hp,true)
  1526. battler.status=0; battler.statusCount=0
  1527. battler.effects[PBEffects::Confusion]=0
  1528. if fullhp
  1529. pbDisplay(_INTL("{1} became healthy!",battler.pbThis))
  1530. else
  1531. pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
  1532. end
  1533. elsif isConst?(item,PBItems,:FULLHEAL)
  1534. battler.status=0; battler.statusCount=0
  1535. battler.effects[PBEffects::Confusion]=0
  1536. pbDisplay(_INTL("{1} became healthy!",battler.pbThis))
  1537. elsif isConst?(item,PBItems,:XATTACK)
  1538. if battler.pbCanIncreaseStatStage?(PBStats::ATTACK,battler)
  1539. battler.pbIncreaseStat(PBStats::ATTACK,1,battler,true)
  1540. end
  1541. elsif isConst?(item,PBItems,:XDEFEND)
  1542. if battler.pbCanIncreaseStatStage?(PBStats::DEFENSE,battler)
  1543. battler.pbIncreaseStat(PBStats::DEFENSE,1,battler,true)
  1544. end
  1545. elsif isConst?(item,PBItems,:XSPEED)
  1546. if battler.pbCanIncreaseStatStage?(PBStats::SPEED,battler)
  1547. battler.pbIncreaseStat(PBStats::SPEED,1,battler,true)
  1548. end
  1549. elsif isConst?(item,PBItems,:XSPECIAL)
  1550. if battler.pbCanIncreaseStatStage?(PBStats::SPATK,battler)
  1551. battler.pbIncreaseStat(PBStats::SPATK,1,battler,true)
  1552. end
  1553. elsif isConst?(item,PBItems,:XSPDEF)
  1554. if battler.pbCanIncreaseStatStage?(PBStats::SPDEF,battler)
  1555. battler.pbIncreaseStat(PBStats::SPDEF,1,battler,true)
  1556. end
  1557. elsif isConst?(item,PBItems,:XACCURACY)
  1558. if battler.pbCanIncreaseStatStage?(PBStats::ACCURACY,battler)
  1559. battler.pbIncreaseStat(PBStats::ACCURACY,1,battler,true)
  1560. end
  1561. end
  1562. end
  1563.  
  1564. ################################################################################
  1565. # Fleeing from battle.
  1566. ################################################################################
  1567. def pbCanRun?(idxPokemon)
  1568. return false if @opponent
  1569. return false if @cantescape && !pbIsOpposing?(idxPokemon)
  1570. thispkmn=@battlers[idxPokemon]
  1571. return true if thispkmn.pbHasType?(:GHOST) && USENEWBATTLEMECHANICS
  1572. return true if thispkmn.hasWorkingItem(:SMOKEBALL)
  1573. return true if thispkmn.hasWorkingAbility(:RUNAWAY)
  1574. return pbCanSwitch?(idxPokemon,-1,false)
  1575. end
  1576.  
  1577. def pbRun(idxPokemon,duringBattle=false)
  1578. thispkmn=@battlers[idxPokemon]
  1579. if pbIsOpposing?(idxPokemon)
  1580. return 0 if @opponent
  1581. @choices[i][0]=5 # run
  1582. @choices[i][1]=0
  1583. @choices[i][2]=nil
  1584. return -1
  1585. end
  1586. if @opponent
  1587. if $DEBUG && Input.press?(Input::CTRL)
  1588. if pbDisplayConfirm(_INTL("Treat this battle as a win?"))
  1589. @decision=1
  1590. return 1
  1591. elsif pbDisplayConfirm(_INTL("Treat this battle as a loss?"))
  1592. @decision=2
  1593. return 1
  1594. end
  1595. elsif @internalbattle
  1596. pbDisplayPaused(_INTL("No! There's no running from a Trainer battle!"))
  1597. elsif pbDisplayConfirm(_INTL("Would you like to forfeit the match and quit now?"))
  1598. pbSEPlay("Battle flee")
  1599. pbDisplay(_INTL("{1} forfeited the match!",self.pbPlayer.name))
  1600. @decision=3
  1601. return 1
  1602. end
  1603. return 0
  1604. end
  1605. if $DEBUG && Input.press?(Input::CTRL)
  1606. pbSEPlay("Battle flee")
  1607. pbDisplayPaused(_INTL("Got away safely!"))
  1608. @decision=3
  1609. return 1
  1610. end
  1611. if @cantescape
  1612. pbDisplayPaused(_INTL("Can't escape!"))
  1613. return 0
  1614. end
  1615. if thispkmn.pbHasType?(:GHOST) && USENEWBATTLEMECHANICS
  1616. pbSEPlay("Battle flee")
  1617. pbDisplayPaused(_INTL("Got away safely!"))
  1618. @decision=3
  1619. return 1
  1620. end
  1621. if thispkmn.hasWorkingAbility(:RUNAWAY)
  1622. pbSEPlay("Battle flee")
  1623. if duringBattle
  1624. pbDisplayPaused(_INTL("Got away safely!"))
  1625. else
  1626. pbDisplayPaused(_INTL("{1} escaped using Run Away!",thispkmn.pbThis))
  1627. end
  1628. @decision=3
  1629. return 1
  1630. end
  1631. if thispkmn.hasWorkingItem(:SMOKEBALL)
  1632. pbSEPlay("Battle flee")
  1633. if duringBattle
  1634. pbDisplayPaused(_INTL("Got away safely!"))
  1635. else
  1636. pbDisplayPaused(_INTL("{1} escaped using its {2}!",thispkmn.pbThis,PBItems.getName(thispkmn.item)))
  1637. end
  1638. @decision=3
  1639. return 1
  1640. end
  1641. if !duringBattle && !pbCanSwitch?(idxPokemon,-1,false)
  1642. pbDisplayPaused(_INTL("Can't escape!"))
  1643. return 0
  1644. end
  1645. # Note: not pbSpeed, because using unmodified Speed
  1646. speedPlayer=@battlers[idxPokemon].speed
  1647. opposing=@battlers[idxPokemon].pbOppositeOpposing
  1648. opposing=opposing.pbPartner if opposing.fainted?
  1649. if !opposing.fainted?
  1650. speedEnemy=opposing.speed
  1651. if speedPlayer>speedEnemy
  1652. rate=256
  1653. else
  1654. speedEnemy=1 if speedEnemy<=0
  1655. rate=speedPlayer*128/speedEnemy
  1656. rate+=@runCommand*30
  1657. rate&=0xFF
  1658. end
  1659. else
  1660. rate=256
  1661. end
  1662. ret=1
  1663. if pbAIRandom(256)<rate
  1664. pbSEPlay("Battle flee")
  1665. pbDisplayPaused(_INTL("Got away safely!"))
  1666. @decision=3
  1667. else
  1668. pbDisplayPaused(_INTL("Can't escape!"))
  1669. ret=-1
  1670. end
  1671. @runCommand+=1 if !duringBattle
  1672. return ret
  1673. end
  1674.  
  1675. ################################################################################
  1676. # Mega Evolve battler.
  1677. ################################################################################
  1678. def pbCanMegaEvolve?(index)
  1679. return false if $game_switches[NO_MEGA_EVOLUTION]
  1680. return false if !@battlers[index].hasMega?
  1681. return false if pbIsOpposing?(index) && !@opponent
  1682. return true if $DEBUG && Input.press?(Input::CTRL)
  1683. return false if !pbHasMegaRing?(index)
  1684. side=(pbIsOpposing?(index)) ? 1 : 0
  1685. owner=pbGetOwnerIndex(index)
  1686. return false if @megaEvolution[side][owner]!=-1
  1687. return false if @battlers[index].effects[PBEffects::SkyDrop]
  1688. return true
  1689. end
  1690.  
  1691. def pbRegisterMegaEvolution(index)
  1692. side=(pbIsOpposing?(index)) ? 1 : 0
  1693. owner=pbGetOwnerIndex(index)
  1694. @megaEvolution[side][owner]=index
  1695. end
  1696.  
  1697. def pbMegaEvolve(index)
  1698. return if !@battlers[index] || !@battlers[index].pokemon
  1699. return if !(@battlers[index].hasMega? rescue false)
  1700. return if (@battlers[index].isMega? rescue true)
  1701. ownername=pbGetOwner(index).fullname
  1702. ownername=pbGetOwner(index).name if pbBelongsToPlayer?(index)
  1703. case (@battlers[index].pokemon.megaMessage rescue 0)
  1704. when 1 # Rayquaza
  1705. pbDisplay(_INTL("{1}'s fervent wish has reached {2}!",ownername,@battlers[index].pbThis))
  1706. else
  1707. pbDisplay(_INTL("{1}'s {2} is reacting to {3}'s {4}!",
  1708. @battlers[index].pbThis,PBItems.getName(@battlers[index].item),
  1709. ownername,pbGetMegaRingName(index)))
  1710. end
  1711. pbCommonAnimation("MegaEvolution",@battlers[index],nil)
  1712. @battlers[index].pokemon.makeMega
  1713. @battlers[index].form=@battlers[index].pokemon.form
  1714. @battlers[index].pbUpdate(true)
  1715. @scene.pbChangePokemon(@battlers[index],@battlers[index].pokemon)
  1716. pbCommonAnimation("MegaEvolution2",@battlers[index],nil)
  1717. meganame=(@battlers[index].pokemon.megaName rescue nil)
  1718. if !meganame || meganame==""
  1719. meganame=_INTL("Mega {1}",PBSpecies.getName(@battlers[index].pokemon.species))
  1720. end
  1721. pbDisplay(_INTL("{1} has Mega Evolved into {2}!",@battlers[index].pbThis,meganame))
  1722. PBDebug.log("[Mega Evolution] #{@battlers[index].pbThis} became #{meganame}")
  1723. side=(pbIsOpposing?(index)) ? 1 : 0
  1724. owner=pbGetOwnerIndex(index)
  1725. @megaEvolution[side][owner]=-2
  1726. end
  1727.  
  1728. ################################################################################
  1729. # Primal Revert battler.
  1730. ################################################################################
  1731. def pbPrimalReversion(index)
  1732. return if !@battlers[index] || !@battlers[index].pokemon
  1733. return if !(@battlers[index].hasPrimal? rescue false)
  1734. return if (@battlers[index].isPrimal? rescue true)
  1735. if isConst?(@battlers[index].pokemon.species,PBSpecies,:KYOGRE)
  1736. pbCommonAnimation("PrimalKyogre",@battlers[index],nil)
  1737. elsif isConst?(@battlers[index].pokemon.species,PBSpecies,:GROUDON)
  1738. pbCommonAnimation("PrimalGroudon",@battlers[index],nil)
  1739. end
  1740. @battlers[index].pokemon.makePrimal
  1741. @battlers[index].form=@battlers[index].pokemon.form
  1742. @battlers[index].pbUpdate(true)
  1743. @scene.pbChangePokemon(@battlers[index],@battlers[index].pokemon)
  1744. if isConst?(@battlers[index].pokemon.species,PBSpecies,:KYOGRE)
  1745. pbCommonAnimation("PrimalKyogre2",@battlers[index],nil)
  1746. elsif isConst?(@battlers[index].pokemon.species,PBSpecies,:GROUDON)
  1747. pbCommonAnimation("PrimalGroudon2",@battlers[index],nil)
  1748. end
  1749. pbDisplay(_INTL("{1}'s Primal Reversion!\nIt reverted to its primal form!",@battlers[index].pbThis))
  1750. PBDebug.log("[Primal Reversion] #{@battlers[index].pbThis} Primal Reverted")
  1751. end
  1752.  
  1753. ################################################################################
  1754. # Call battler.
  1755. ################################################################################
  1756. def pbCall(index)
  1757. owner=pbGetOwner(index)
  1758. pbDisplay(_INTL("{1} called {2}!",owner.name,@battlers[index].name))
  1759. pbDisplay(_INTL("{1}!",@battlers[index].name))
  1760. PBDebug.log("[Call to Pokémon] #{owner.name} called to #{@battlers[index].pbThis(true)}")
  1761. if @battlers[index].isShadow?
  1762. if @battlers[index].inHyperMode?
  1763. @battlers[index].pokemon.hypermode=false
  1764. @battlers[index].pokemon.adjustHeart(-300)
  1765. pbDisplay(_INTL("{1} came to its senses from the Trainer's call!",@battlers[index].pbThis))
  1766. else
  1767. pbDisplay(_INTL("But nothing happened!"))
  1768. end
  1769. elsif @battlers[index].status!=PBStatuses::SLEEP &&
  1770. @battlers[index].pbCanIncreaseStatStage?(PBStats::ACCURACY,@battlers[index])
  1771. @battlers[index].pbIncreaseStat(PBStats::ACCURACY,1,@battlers[index],true)
  1772. else
  1773. pbDisplay(_INTL("But nothing happened!"))
  1774. end
  1775. end
  1776.  
  1777. ################################################################################
  1778. # Gaining Experience.
  1779. ################################################################################
  1780. def pbGainEXP
  1781. return if !@internalbattle
  1782. successbegin=true
  1783. for i in 0...4 # Not ordered by priority
  1784. if !@doublebattle && pbIsDoubleBattler?(i)
  1785. @battlers[i].participants=[]
  1786. next
  1787. end
  1788. if pbIsOpposing?(i) && @battlers[i].participants.length>0 &&
  1789. (@battlers[i].fainted? || @battlers[i].captured)
  1790. haveexpall=(hasConst?(PBItems,:EXPALL) && $PokemonBag.pbHasItem?(:EXPALL))
  1791. # First count the number of participants
  1792. partic=0
  1793. expshare=0
  1794. for j in @battlers[i].participants
  1795. next if !@party1[j] || !pbIsOwner?(0,j)
  1796. partic+=1 if @party1[j].hp>0 && !@party1[j].egg?
  1797. end
  1798. if !haveexpall
  1799. for j in 0...@party1.length
  1800. next if !@party1[j] || !pbIsOwner?(0,j)
  1801. expshare+=1 if @party1[j].hp>0 && !@party1[j].egg? &&
  1802. (isConst?(@party1[j].item,PBItems,:EXPSHARE) ||
  1803. isConst?(@party1[j].itemInitial,PBItems,:EXPSHARE))
  1804. end
  1805. end
  1806. # Now calculate EXP for the participants
  1807. if partic>0 || expshare>0 || haveexpall
  1808. if !@opponent && successbegin && pbAllFainted?(@party2)
  1809. @scene.pbWildBattleSuccess
  1810. successbegin=false
  1811. end
  1812. for j in 0...@party1.length
  1813. next if !@party1[j] || !pbIsOwner?(0,j)
  1814. next if @party1[j].hp<=0 || @party1[j].egg?
  1815. haveexpshare=(isConst?(@party1[j].item,PBItems,:EXPSHARE) ||
  1816. isConst?(@party1[j].itemInitial,PBItems,:EXPSHARE))
  1817. next if !haveexpshare && !@battlers[i].participants.include?(j)
  1818. pbGainExpOne(j,@battlers[i],partic,expshare,haveexpall)
  1819. end
  1820. if haveexpall
  1821. showmessage=true
  1822. for j in 0...@party1.length
  1823. next if !@party1[j] || !pbIsOwner?(0,j)
  1824. next if @party1[j].hp<=0 || @party1[j].egg?
  1825. next if isConst?(@party1[j].item,PBItems,:EXPSHARE) ||
  1826. isConst?(@party1[j].itemInitial,PBItems,:EXPSHARE)
  1827. next if @battlers[i].participants.include?(j)
  1828. pbDisplayPaused(_INTL("The rest of your team gained Exp. Points thanks to the {1}!",
  1829. PBItems.getName(getConst(PBItems,:EXPALL)))) if showmessage
  1830. showmessage=false
  1831. pbGainExpOne(j,@battlers[i],partic,expshare,haveexpall,false)
  1832. end
  1833. end
  1834. end
  1835. # Now clear the participants array
  1836. @battlers[i].participants=[]
  1837. end
  1838. end
  1839. end
  1840.  
  1841. def pbGainExpOne(index,defeated,partic,expshare,haveexpall,showmessages=true)
  1842. thispoke=@party1[index]
  1843. # Original species, not current species
  1844. level=defeated.level
  1845. baseexp=defeated.pokemon.baseExp
  1846. evyield=defeated.pokemon.evYield
  1847. # Gain effort value points, using RS effort values
  1848. totalev=0
  1849. for k in 0...6
  1850. totalev+=thispoke.ev[k]
  1851. end
  1852. for k in 0...6
  1853. evgain=evyield[k]
  1854. evgain*=2 if isConst?(thispoke.item,PBItems,:MACHOBRACE) ||
  1855. isConst?(thispoke.itemInitial,PBItems,:MACHOBRACE)
  1856. case k
  1857. when PBStats::HP
  1858. evgain+=4 if isConst?(thispoke.item,PBItems,:POWERWEIGHT) ||
  1859. isConst?(thispoke.itemInitial,PBItems,:POWERWEIGHT)
  1860. when PBStats::ATTACK
  1861. evgain+=4 if isConst?(thispoke.item,PBItems,:POWERBRACER) ||
  1862. isConst?(thispoke.itemInitial,PBItems,:POWERBRACER)
  1863. when PBStats::DEFENSE
  1864. evgain+=4 if isConst?(thispoke.item,PBItems,:POWERBELT) ||
  1865. isConst?(thispoke.itemInitial,PBItems,:POWERBELT)
  1866. when PBStats::SPATK
  1867. evgain+=4 if isConst?(thispoke.item,PBItems,:POWERLENS) ||
  1868. isConst?(thispoke.itemInitial,PBItems,:POWERLENS)
  1869. when PBStats::SPDEF
  1870. evgain+=4 if isConst?(thispoke.item,PBItems,:POWERBAND) ||
  1871. isConst?(thispoke.itemInitial,PBItems,:POWERBAND)
  1872. when PBStats::SPEED
  1873. evgain+=4 if isConst?(thispoke.item,PBItems,:POWERANKLET) ||
  1874. isConst?(thispoke.itemInitial,PBItems,:POWERANKLET)
  1875. end
  1876. evgain*=2 if thispoke.pokerusStage>=1 # Infected or cured
  1877. if evgain>0
  1878. # Can't exceed overall limit
  1879. evgain-=totalev+evgain-PokeBattle_Pokemon::EVLIMIT if totalev+evgain>PokeBattle_Pokemon::EVLIMIT
  1880. # Can't exceed stat limit
  1881. evgain-=thispoke.ev[k]+evgain-PokeBattle_Pokemon::EVSTATLIMIT if thispoke.ev[k]+evgain>PokeBattle_Pokemon::EVSTATLIMIT
  1882. # Add EV gain
  1883. thispoke.ev[k]+=evgain
  1884. if thispoke.ev[k]>PokeBattle_Pokemon::EVSTATLIMIT
  1885. print "Single-stat EV limit #{PokeBattle_Pokemon::EVSTATLIMIT} exceeded.\r\nStat: #{k} EV gain: #{evgain} EVs: #{thispoke.ev.inspect}"
  1886. thispoke.ev[k]=PokeBattle_Pokemon::EVSTATLIMIT
  1887. end
  1888. totalev+=evgain
  1889. if totalev>PokeBattle_Pokemon::EVLIMIT
  1890. print "EV limit #{PokeBattle_Pokemon::EVLIMIT} exceeded.\r\nTotal EVs: #{totalev} EV gain: #{evgain} EVs: #{thispoke.ev.inspect}"
  1891. end
  1892. end
  1893. end
  1894. # Gain experience
  1895. ispartic=0
  1896. ispartic=1 if defeated.participants.include?(index)
  1897. haveexpshare=(isConst?(thispoke.item,PBItems,:EXPSHARE) ||
  1898. isConst?(thispoke.itemInitial,PBItems,:EXPSHARE)) ? 1 : 0
  1899. exp=0
  1900. if expshare>0
  1901. if partic==0 # No participants, all Exp goes to Exp Share holders
  1902. exp=(level*baseexp).floor
  1903. exp=(exp/(NOSPLITEXP ? 1 : expshare)).floor*haveexpshare
  1904. else
  1905. if NOSPLITEXP
  1906. exp=(level*baseexp).floor*ispartic
  1907. exp=(level*baseexp/2).floor*haveexpshare if ispartic==0
  1908. else
  1909. exp=(level*baseexp/2).floor
  1910. exp=(exp/partic).floor*ispartic + (exp/expshare).floor*haveexpshare
  1911. end
  1912. end
  1913. elsif ispartic==1
  1914. exp=(level*baseexp/(NOSPLITEXP ? 1 : partic)).floor
  1915. elsif haveexpall
  1916. exp=(level*baseexp/2).floor
  1917. end
  1918. return if exp<=0
  1919. exp=(exp*3/2).floor if @opponent
  1920. if USESCALEDEXPFORMULA
  1921. exp=(exp/5).floor
  1922. leveladjust=(2*level+10.0)/(level+thispoke.level+10.0)
  1923. leveladjust=leveladjust**5
  1924. leveladjust=Math.sqrt(leveladjust)
  1925. exp=(exp*leveladjust).floor
  1926. exp+=1 if ispartic>0 || haveexpshare>0
  1927. else
  1928. exp=(exp/7).floor
  1929. end
  1930. isOutsider=(thispoke.trainerID!=self.pbPlayer.id ||
  1931. (thispoke.language!=0 && thispoke.language!=self.pbPlayer.language))
  1932. if isOutsider
  1933. if thispoke.language!=0 && thispoke.language!=self.pbPlayer.language
  1934. exp=(exp*1.7).floor
  1935. else
  1936. exp=(exp*3/2).floor
  1937. end
  1938. end
  1939. exp=(exp*3/2).floor if isConst?(thispoke.item,PBItems,:LUCKYEGG) ||
  1940. isConst?(thispoke.itemInitial,PBItems,:LUCKYEGG)
  1941. growthrate=thispoke.growthrate
  1942. newexp=PBExperience.pbAddExperience(thispoke.exp,exp,growthrate)
  1943. exp=newexp-thispoke.exp
  1944. if exp>0
  1945. if showmessages
  1946. if isOutsider
  1947. pbDisplayPaused(_INTL("{1} gained a boosted {2} Exp. Points!",thispoke.name,exp))
  1948. else
  1949. pbDisplayPaused(_INTL("{1} gained {2} Exp. Points!",thispoke.name,exp))
  1950. end
  1951. end
  1952. newlevel=PBExperience.pbGetLevelFromExperience(newexp,growthrate)
  1953. tempexp=0
  1954. curlevel=thispoke.level
  1955. if newlevel<curlevel
  1956. debuginfo="#{thispoke.name}: #{thispoke.level}/#{newlevel} | #{thispoke.exp}/#{newexp} | gain: #{exp}"
  1957. raise RuntimeError.new(_INTL("The new level ({1}) is less than the Pokémon's\r\ncurrent level ({2}), which shouldn't happen.\r\n[Debug: {3}]",
  1958. newlevel,curlevel,debuginfo))
  1959. return
  1960. end
  1961. if thispoke.respond_to?("isShadow?") && thispoke.isShadow?
  1962. thispoke.exp+=exp
  1963. else
  1964. tempexp1=thispoke.exp
  1965. tempexp2=0
  1966. # Find battler
  1967. battler=pbFindPlayerBattler(index)
  1968. loop do
  1969. # EXP Bar animation
  1970. startexp=PBExperience.pbGetStartExperience(curlevel,growthrate)
  1971. endexp=PBExperience.pbGetStartExperience(curlevel+1,growthrate)
  1972. tempexp2=(endexp<newexp) ? endexp : newexp
  1973. thispoke.exp=tempexp2
  1974. @scene.pbEXPBar(thispoke,battler,startexp,endexp,tempexp1,tempexp2)
  1975. tempexp1=tempexp2
  1976. curlevel+=1
  1977. if curlevel>newlevel
  1978. thispoke.calcStats
  1979. battler.pbUpdate(false) if battler
  1980. @scene.pbRefresh
  1981. break
  1982. end
  1983. oldtotalhp=thispoke.totalhp
  1984. oldattack=thispoke.attack
  1985. olddefense=thispoke.defense
  1986. oldspeed=thispoke.speed
  1987. oldspatk=thispoke.spatk
  1988. oldspdef=thispoke.spdef
  1989. if battler && battler.pokemon && @internalbattle
  1990. battler.pokemon.changeHappiness("levelup")
  1991. end
  1992. thispoke.calcStats
  1993. battler.pbUpdate(false) if battler
  1994. @scene.pbRefresh
  1995. pbDisplayPaused(_INTL("{1} grew to Level {2}!",thispoke.name,curlevel))
  1996. @scene.pbLevelUp(thispoke,battler,oldtotalhp,oldattack,
  1997. olddefense,oldspeed,oldspatk,oldspdef)
  1998. # Finding all moves learned at this level
  1999. movelist=thispoke.getMoveList
  2000. for k in movelist
  2001. if k[0]==thispoke.level # Learned a new move
  2002. pbLearnMove(index,k[1])
  2003. end
  2004. end
  2005. end
  2006. end
  2007. end
  2008. end
  2009.  
  2010. ################################################################################
  2011. # Learning a move.
  2012. ################################################################################
  2013. def pbLearnMove(pkmnIndex,move)
  2014. pokemon=@party1[pkmnIndex]
  2015. return if !pokemon
  2016. pkmnname=pokemon.name
  2017. battler=pbFindPlayerBattler(pkmnIndex)
  2018. movename=PBMoves.getName(move)
  2019. for i in 0...4
  2020. return if pokemon.moves[i].id==move
  2021. if pokemon.moves[i].id==0
  2022. pokemon.moves[i]=PBMove.new(move)
  2023. battler.moves[i]=PokeBattle_Move.pbFromPBMove(self,pokemon.moves[i]) if battler
  2024. pbDisplayPaused(_INTL("{1} learned {2}!",pkmnname,movename))
  2025. PBDebug.log("[Learn move] #{pkmnname} learned #{movename}")
  2026. return
  2027. end
  2028. end
  2029. loop do
  2030. pbDisplayPaused(_INTL("{1} is trying to learn {2}.",pkmnname,movename))
  2031. pbDisplayPaused(_INTL("But {1} can't learn more than four moves.",pkmnname))
  2032. if pbDisplayConfirm(_INTL("Delete a move to make room for {1}?",movename))
  2033. pbDisplayPaused(_INTL("Which move should be forgotten?"))
  2034. forgetmove=@scene.pbForgetMove(pokemon,move)
  2035. if forgetmove>=0
  2036. oldmovename=PBMoves.getName(pokemon.moves[forgetmove].id)
  2037. pokemon.moves[forgetmove]=PBMove.new(move) # Replaces current/total PP
  2038. battler.moves[forgetmove]=PokeBattle_Move.pbFromPBMove(self,pokemon.moves[forgetmove]) if battler
  2039. pbDisplayPaused(_INTL("1, 2, and... ... ..."))
  2040. pbDisplayPaused(_INTL("Poof!"))
  2041. pbDisplayPaused(_INTL("{1} forgot {2}.",pkmnname,oldmovename))
  2042. pbDisplayPaused(_INTL("And..."))
  2043. pbDisplayPaused(_INTL("{1} learned {2}!",pkmnname,movename))
  2044. PBDebug.log("[Learn move] #{pkmnname} forgot #{oldmovename} and learned #{movename}")
  2045. return
  2046. elsif pbDisplayConfirm(_INTL("Should {1} stop learning {2}?",pkmnname,movename))
  2047. pbDisplayPaused(_INTL("{1} did not learn {2}.",pkmnname,movename))
  2048. return
  2049. end
  2050. elsif pbDisplayConfirm(_INTL("Should {1} stop learning {2}?",pkmnname,movename))
  2051. pbDisplayPaused(_INTL("{1} did not learn {2}.",pkmnname,movename))
  2052. return
  2053. end
  2054. end
  2055. end
  2056.  
  2057. ################################################################################
  2058. # Abilities.
  2059. ################################################################################
  2060. def pbOnActiveAll
  2061. for i in 0...4 # Currently unfainted participants will earn EXP even if they faint afterwards
  2062. @battlers[i].pbUpdateParticipants if pbIsOpposing?(i)
  2063. @amuletcoin=true if !pbIsOpposing?(i) &&
  2064. (isConst?(@battlers[i].item,PBItems,:AMULETCOIN) ||
  2065. isConst?(@battlers[i].item,PBItems,:LUCKINCENSE))
  2066. end
  2067. for i in 0...4
  2068. if !@battlers[i].fainted?
  2069. if @battlers[i].isShadow? && pbIsOpposing?(i)
  2070. pbCommonAnimation("Shadow",@battlers[i],nil)
  2071. pbDisplay(_INTL("Oh!\nA Shadow Pokémon!"))
  2072. end
  2073. end
  2074. end
  2075. # Weather-inducing abilities, Trace, Imposter, etc.
  2076. @usepriority=false
  2077. priority=pbPriority
  2078. for i in priority
  2079. i.pbAbilitiesOnSwitchIn(true)
  2080. end
  2081. # Check forms are correct
  2082. for i in 0...4
  2083. next if @battlers[i].fainted?
  2084. @battlers[i].pbCheckForm
  2085. end
  2086. end
  2087.  
  2088. def pbOnActiveOne(pkmn,onlyabilities=false,moldbreaker=false)
  2089. return false if pkmn.fainted?
  2090. if !onlyabilities
  2091. for i in 0...4 # Currently unfainted participants will earn EXP even if they faint afterwards
  2092. @battlers[i].pbUpdateParticipants if pbIsOpposing?(i)
  2093. @amuletcoin=true if !pbIsOpposing?(i) &&
  2094. (isConst?(@battlers[i].item,PBItems,:AMULETCOIN) ||
  2095. isConst?(@battlers[i].item,PBItems,:LUCKINCENSE))
  2096. end
  2097. if pkmn.isShadow? && pbIsOpposing?(pkmn.index)
  2098. pbCommonAnimation("Shadow",pkmn,nil)
  2099. pbDisplay(_INTL("Oh!\nA Shadow Pokémon!"))
  2100. end
  2101. # Healing Wish
  2102. if pkmn.effects[PBEffects::HealingWish]
  2103. PBDebug.log("[Lingering effect triggered] #{pkmn.pbThis}'s Healing Wish")
  2104. pbCommonAnimation("HealingWish",pkmn,nil)
  2105. pbDisplayPaused(_INTL("The healing wish came true for {1}!",pkmn.pbThis(true)))
  2106. pkmn.pbRecoverHP(pkmn.totalhp,true)
  2107. pkmn.pbCureStatus(false)
  2108. pkmn.effects[PBEffects::HealingWish]=false
  2109. end
  2110. # Lunar Dance
  2111. if pkmn.effects[PBEffects::LunarDance]
  2112. PBDebug.log("[Lingering effect triggered] #{pkmn.pbThis}'s Lunar Dance")
  2113. pbCommonAnimation("LunarDance",pkmn,nil)
  2114. pbDisplayPaused(_INTL("{1} became cloaked in mystical moonlight!",pkmn.pbThis))
  2115. pkmn.pbRecoverHP(pkmn.totalhp,true)
  2116. pkmn.pbCureStatus(false)
  2117. for i in 0...4
  2118. pkmn.moves[i].pp=pkmn.moves[i].totalpp
  2119. end
  2120. pkmn.effects[PBEffects::LunarDance]=false
  2121. end
  2122. # Spikes
  2123. if pkmn.pbOwnSide.effects[PBEffects::Spikes]>0 && !pkmn.isAirborne?(moldbreaker)
  2124. if !pkmn.hasWorkingAbility(:MAGICGUARD)
  2125. PBDebug.log("[Entry hazard] #{pkmn.pbThis} triggered Spikes")
  2126. spikesdiv=[8,6,4][pkmn.pbOwnSide.effects[PBEffects::Spikes]-1]
  2127. @scene.pbDamageAnimation(pkmn,0)
  2128. pkmn.pbReduceHP((pkmn.totalhp/spikesdiv).floor)
  2129. pbDisplayPaused(_INTL("{1} is hurt by the spikes!",pkmn.pbThis))
  2130. end
  2131. end
  2132. pkmn.pbFaint if pkmn.fainted?
  2133. # Stealth Rock
  2134. if pkmn.pbOwnSide.effects[PBEffects::StealthRock] && !pkmn.fainted?
  2135. if !pkmn.hasWorkingAbility(:MAGICGUARD)
  2136. atype=getConst(PBTypes,:ROCK) || 0
  2137. eff=PBTypes.getCombinedEffectiveness(atype,pkmn.type1,pkmn.type2,pkmn.effects[PBEffects::Type3])
  2138. if eff>0
  2139. PBDebug.log("[Entry hazard] #{pkmn.pbThis} triggered Stealth Rock")
  2140. @scene.pbDamageAnimation(pkmn,0)
  2141. pkmn.pbReduceHP(((pkmn.totalhp*eff)/64).floor)
  2142. pbDisplayPaused(_INTL("Pointed stones dug into {1}!",pkmn.pbThis))
  2143. end
  2144. end
  2145. end
  2146. pkmn.pbFaint if pkmn.fainted?
  2147. # Toxic Spikes
  2148. if pkmn.pbOwnSide.effects[PBEffects::ToxicSpikes]>0 && !pkmn.fainted?
  2149. if !pkmn.isAirborne?(moldbreaker)
  2150. if pkmn.pbHasType?(:POISON)
  2151. PBDebug.log("[Entry hazard] #{pkmn.pbThis} absorbed Toxic Spikes")
  2152. pkmn.pbOwnSide.effects[PBEffects::ToxicSpikes]=0
  2153. pbDisplayPaused(_INTL("{1} absorbed the poison spikes!",pkmn.pbThis))
  2154. elsif pkmn.pbCanPoisonSpikes?(moldbreaker)
  2155. PBDebug.log("[Entry hazard] #{pkmn.pbThis} triggered Toxic Spikes")
  2156. if pkmn.pbOwnSide.effects[PBEffects::ToxicSpikes]==2
  2157. pkmn.pbPoison(nil,_INTL("{1} was badly poisoned by the poison spikes!",pkmn.pbThis,true))
  2158. else
  2159. pkmn.pbPoison(nil,_INTL("{1} was poisoned by the poison spikes!",pkmn.pbThis))
  2160. end
  2161. end
  2162. end
  2163. end
  2164. # Sticky Web
  2165. if pkmn.pbOwnSide.effects[PBEffects::StickyWeb] && !pkmn.fainted? &&
  2166. !pkmn.isAirborne?(moldbreaker)
  2167. if pkmn.pbCanReduceStatStage?(PBStats::SPEED,nil,false,nil,moldbreaker)
  2168. PBDebug.log("[Entry hazard] #{pkmn.pbThis} triggered Sticky Web")
  2169. pkmn.pbReduceStat(PBStats::SPEED,1,nil,false,nil,true,moldbreaker)
  2170. pbDisplayPaused(_INTL("{1} was caught in a sticky web!",pkmn.pbThis))
  2171. end
  2172. end
  2173. end
  2174. pkmn.pbAbilityCureCheck
  2175. if pkmn.fainted?
  2176. pbGainEXP
  2177. pbJudge # pbSwitch
  2178. return false
  2179. end
  2180. # pkmn.pbAbilitiesOnSwitchIn(true)
  2181. if !onlyabilities
  2182. pkmn.pbCheckForm
  2183. pkmn.pbBerryCureCheck
  2184. end
  2185. return true
  2186. end
  2187.  
  2188. def pbPrimordialWeather
  2189. # End Primordial Sea, Desolate Land, Delta Stream
  2190. hasabil=false
  2191. case @weather
  2192. when PBWeather::HEAVYRAIN
  2193. for i in 0...4
  2194. if isConst?(@battlers[i].ability,PBAbilities,:PRIMORDIALSEA) &&
  2195. !@battlers[i].fainted?
  2196. hasabil=true; break
  2197. end
  2198. if !hasabil
  2199. @weather=0
  2200. pbDisplayBrief("The heavy rain has lifted!")
  2201. end
  2202. end
  2203. when PBWeather::HARSHSUN
  2204. for i in 0...4
  2205. if isConst?(@battlers[i].ability,PBAbilities,:DESOLATELAND) &&
  2206. !@battlers[i].fainted?
  2207. hasabil=true; break
  2208. end
  2209. if !hasabil
  2210. @weather=0
  2211. pbDisplayBrief("The harsh sunlight faded!")
  2212. end
  2213. end
  2214. when PBWeather::STRONGWINDS
  2215. for i in 0...4
  2216. if isConst?(@battlers[i].ability,PBAbilities,:DELTASTREAM) &&
  2217. !@battlers[i].fainted?
  2218. hasabil=true; break
  2219. end
  2220. if !hasabil
  2221. @weather=0
  2222. pbDisplayBrief("The mysterious air current has dissipated!")
  2223. end
  2224. end
  2225. end
  2226. end
  2227.  
  2228. ################################################################################
  2229. # Judging.
  2230. ################################################################################
  2231. def pbJudgeCheckpoint(attacker,move=0)
  2232. end
  2233.  
  2234. def pbDecisionOnTime
  2235. count1=0
  2236. count2=0
  2237. hptotal1=0
  2238. hptotal2=0
  2239. for i in @party1
  2240. next if !i
  2241. if i.hp>0 && !i.egg?
  2242. count1+=1
  2243. hptotal1+=i.hp
  2244. end
  2245. end
  2246. for i in @party2
  2247. next if !i
  2248. if i.hp>0 && !i.egg?
  2249. count2+=1
  2250. hptotal2+=i.hp
  2251. end
  2252. end
  2253. return 1 if count1>count2 # win
  2254. return 2 if count1<count2 # loss
  2255. return 1 if hptotal1>hptotal2 # win
  2256. return 2 if hptotal1<hptotal2 # loss
  2257. return 5 # draw
  2258. end
  2259.  
  2260. def pbDecisionOnTime2
  2261. count1=0
  2262. count2=0
  2263. hptotal1=0
  2264. hptotal2=0
  2265. for i in @party1
  2266. next if !i
  2267. if i.hp>0 && !i.egg?
  2268. count1+=1
  2269. hptotal1+=(i.hp*100/i.totalhp)
  2270. end
  2271. end
  2272. hptotal1/=count1 if count1>0
  2273. for i in @party2
  2274. next if !i
  2275. if i.hp>0 && !i.egg?
  2276. count2+=1
  2277. hptotal2+=(i.hp*100/i.totalhp)
  2278. end
  2279. end
  2280. hptotal2/=count2 if count2>0
  2281. return 1 if count1>count2 # win
  2282. return 2 if count1<count2 # loss
  2283. return 1 if hptotal1>hptotal2 # win
  2284. return 2 if hptotal1<hptotal2 # loss
  2285. return 5 # draw
  2286. end
  2287.  
  2288. def pbDecisionOnDraw
  2289. return 5 # draw
  2290. end
  2291.  
  2292. def pbJudge
  2293. # PBDebug.log("[Counts: #{pbPokemonCount(@party1)}/#{pbPokemonCount(@party2)}]")
  2294. if pbAllFainted?(@party1) && pbAllFainted?(@party2)
  2295. @decision=pbDecisionOnDraw() # Draw
  2296. return
  2297. end
  2298. if pbAllFainted?(@party1)
  2299. @decision=2 # Loss
  2300. return
  2301. end
  2302. if pbAllFainted?(@party2)
  2303. @decision=1 # Win
  2304. return
  2305. end
  2306. end
  2307.  
  2308. ################################################################################
  2309. # Messages and animations.
  2310. ################################################################################
  2311. def pbDisplay(msg)
  2312. @scene.pbDisplayMessage(msg)
  2313. end
  2314.  
  2315. def pbDisplayPaused(msg)
  2316. @scene.pbDisplayPausedMessage(msg)
  2317. end
  2318.  
  2319. def pbDisplayBrief(msg)
  2320. @scene.pbDisplayMessage(msg,true)
  2321. end
  2322.  
  2323. def pbDisplayConfirm(msg)
  2324. @scene.pbDisplayConfirmMessage(msg)
  2325. end
  2326.  
  2327. def pbShowCommands(msg,commands,cancancel=true)
  2328. @scene.pbShowCommands(msg,commands,cancancel)
  2329. end
  2330.  
  2331. def pbAnimation(move,attacker,opponent,hitnum=0)
  2332. if @battlescene
  2333. @scene.pbAnimation(move,attacker,opponent,hitnum)
  2334. end
  2335. end
  2336.  
  2337. def pbCommonAnimation(name,attacker,opponent,hitnum=0)
  2338. if @battlescene
  2339. @scene.pbCommonAnimation(name,attacker,opponent,hitnum)
  2340. end
  2341. end
  2342.  
  2343. ################################################################################
  2344. # Battle core.
  2345. ################################################################################
  2346. def pbStartBattle(canlose=false)
  2347. PBDebug.log("")
  2348. PBDebug.log("******************************************")
  2349. begin
  2350. pbStartBattleCore(canlose)
  2351. rescue BattleAbortedException
  2352. @decision=0
  2353. @scene.pbEndBattle(@decision)
  2354. end
  2355. return @decision
  2356. end
  2357.  
  2358. def pbStartBattleCore(canlose)
  2359. if !@fullparty1 && @party1.length>MAXPARTYSIZE
  2360. raise ArgumentError.new(_INTL("Party 1 has more than {1} Pokémon.",MAXPARTYSIZE))
  2361. end
  2362. if !@fullparty2 && @party2.length>MAXPARTYSIZE
  2363. raise ArgumentError.new(_INTL("Party 2 has more than {1} Pokémon.",MAXPARTYSIZE))
  2364. end
  2365. #========================
  2366. # Initialize wild Pokémon
  2367. #========================
  2368. if !@opponent
  2369. if @party2.length==1
  2370. if @doublebattle
  2371. raise _INTL("Only two wild Pokémon are allowed in double battles")
  2372. end
  2373. wildpoke=@party2[0]
  2374. @battlers[1].pbInitialize(wildpoke,0,false)
  2375. @peer.pbOnEnteringBattle(self,wildpoke)
  2376. pbSetSeen(wildpoke)
  2377. @scene.pbStartBattle(self)
  2378. pbDisplayPaused(_INTL("Wild {1} appeared!",wildpoke.name))
  2379. elsif @party2.length==2
  2380. if !@doublebattle
  2381. raise _INTL("Only one wild Pokémon is allowed in single battles")
  2382. end
  2383. @battlers[1].pbInitialize(@party2[0],0,false)
  2384. @battlers[3].pbInitialize(@party2[1],1,false)
  2385. @peer.pbOnEnteringBattle(self,@party2[0])
  2386. @peer.pbOnEnteringBattle(self,@party2[1])
  2387. pbSetSeen(@party2[0])
  2388. pbSetSeen(@party2[1])
  2389. @scene.pbStartBattle(self)
  2390. pbDisplayPaused(_INTL("Wild {1} and\r\n{2} appeared!",
  2391. @party2[0].name,@party2[1].name))
  2392. else
  2393. raise _INTL("Only one or two wild Pokémon are allowed")
  2394. end
  2395. #=======================================
  2396. # Initialize opponents in double battles
  2397. #=======================================
  2398. elsif @doublebattle
  2399. if @opponent.is_a?(Array)
  2400. if @opponent.length==1
  2401. @opponent=@opponent[0]
  2402. elsif @opponent.length!=2
  2403. raise _INTL("Opponents with zero or more than two people are not allowed")
  2404. end
  2405. end
  2406. if @player.is_a?(Array)
  2407. if @player.length==1
  2408. @player=@player[0]
  2409. elsif @player.length!=2
  2410. raise _INTL("Player trainers with zero or more than two people are not allowed")
  2411. end
  2412. end
  2413. @scene.pbStartBattle(self)
  2414. if @opponent.is_a?(Array)
  2415. pbDisplayPaused(_INTL("{1} and {2} want to battle!",@opponent[0].fullname,@opponent[1].fullname))
  2416. sendout1=pbFindNextUnfainted(@party2,0,pbSecondPartyBegin(1))
  2417. raise _INTL("Opponent 1 has no unfainted Pokémon") if sendout1<0
  2418. sendout2=pbFindNextUnfainted(@party2,pbSecondPartyBegin(1))
  2419. raise _INTL("Opponent 2 has no unfainted Pokémon") if sendout2<0
  2420. @battlers[1].pbInitialize(@party2[sendout1],sendout1,false)
  2421. pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",@opponent[0].fullname,@battlers[1].name))
  2422. pbSendOut(1,@party2[sendout1])
  2423. @battlers[3].pbInitialize(@party2[sendout2],sendout2,false)
  2424. pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",@opponent[1].fullname,@battlers[3].name))
  2425. pbSendOut(3,@party2[sendout2])
  2426. else
  2427. pbDisplayPaused(_INTL("{1}\r\nwould like to battle!",@opponent.fullname))
  2428. sendout1=pbFindNextUnfainted(@party2,0)
  2429. sendout2=pbFindNextUnfainted(@party2,sendout1+1)
  2430. if sendout1<0 || sendout2<0
  2431. raise _INTL("Opponent doesn't have two unfainted Pokémon")
  2432. end
  2433. @battlers[1].pbInitialize(@party2[sendout1],sendout1,false)
  2434. @battlers[3].pbInitialize(@party2[sendout2],sendout2,false)
  2435. pbDisplayBrief(_INTL("{1} sent\r\nout {2} and {3}!",
  2436. @opponent.fullname,@battlers[1].name,@battlers[3].name))
  2437. pbSendOut(1,@party2[sendout1])
  2438. pbSendOut(3,@party2[sendout2])
  2439. end
  2440. #======================================
  2441. # Initialize opponent in single battles
  2442. #======================================
  2443. else
  2444. sendout=pbFindNextUnfainted(@party2,0)
  2445. raise _INTL("Trainer has no unfainted Pokémon") if sendout<0
  2446. if @opponent.is_a?(Array)
  2447. raise _INTL("Opponent trainer must be only one person in single battles") if @opponent.length!=1
  2448. @opponent=@opponent[0]
  2449. end
  2450. if @player.is_a?(Array)
  2451. raise _INTL("Player trainer must be only one person in single battles") if @player.length!=1
  2452. @player=@player[0]
  2453. end
  2454. trainerpoke=@party2[sendout]
  2455. @scene.pbStartBattle(self)
  2456. pbDisplayPaused(_INTL("{1}\r\nwould like to battle!",@opponent.fullname))
  2457. @battlers[1].pbInitialize(trainerpoke,sendout,false)
  2458. pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",@opponent.fullname,@battlers[1].name))
  2459. pbSendOut(1,trainerpoke)
  2460. end
  2461. #=====================================
  2462. # Initialize players in double battles
  2463. #=====================================
  2464. if @doublebattle
  2465. if @player.is_a?(Array)
  2466. sendout1=pbFindNextUnfainted(@party1,0,pbSecondPartyBegin(0))
  2467. raise _INTL("Player 1 has no unfainted Pokémon") if sendout1<0
  2468. sendout2=pbFindNextUnfainted(@party1,pbSecondPartyBegin(0))
  2469. raise _INTL("Player 2 has no unfainted Pokémon") if sendout2<0
  2470. @battlers[0].pbInitialize(@party1[sendout1],sendout1,false)
  2471. @battlers[2].pbInitialize(@party1[sendout2],sendout2,false)
  2472. pbDisplayBrief(_INTL("{1} sent\r\nout {2}! Go! {3}!",
  2473. @player[1].fullname,@battlers[2].name,@battlers[0].name))
  2474. pbSetSeen(@party1[sendout1])
  2475. pbSetSeen(@party1[sendout2])
  2476. else
  2477. sendout1=pbFindNextUnfainted(@party1,0)
  2478. sendout2=pbFindNextUnfainted(@party1,sendout1+1)
  2479. if sendout1<0 || sendout2<0
  2480. raise _INTL("Player doesn't have two unfainted Pokémon")
  2481. end
  2482. @battlers[0].pbInitialize(@party1[sendout1],sendout1,false)
  2483. @battlers[2].pbInitialize(@party1[sendout2],sendout2,false)
  2484. pbDisplayBrief(_INTL("Go! {1} and {2}!",@battlers[0].name,@battlers[2].name))
  2485. end
  2486. pbSendOut(0,@party1[sendout1])
  2487. pbSendOut(2,@party1[sendout2])
  2488. #====================================
  2489. # Initialize player in single battles
  2490. #====================================
  2491. else
  2492. sendout=pbFindNextUnfainted(@party1,0)
  2493. if sendout<0
  2494. raise _INTL("Player has no unfainted Pokémon")
  2495. end
  2496. @battlers[0].pbInitialize(@party1[sendout],sendout,false)
  2497. pbDisplayBrief(_INTL("Go! {1}!",@battlers[0].name))
  2498. pbSendOut(0,@party1[sendout])
  2499. end
  2500. #==================
  2501. # Initialize battle
  2502. #==================
  2503. if @weather==PBWeather::SUNNYDAY
  2504. pbCommonAnimation("Sunny",nil,nil)
  2505. pbDisplay(_INTL("The sunlight is strong."))
  2506. elsif @weather==PBWeather::RAINDANCE
  2507. pbCommonAnimation("Rain",nil,nil)
  2508. pbDisplay(_INTL("It is raining."))
  2509. elsif @weather==PBWeather::SANDSTORM
  2510. pbCommonAnimation("Sandstorm",nil,nil)
  2511. pbDisplay(_INTL("A sandstorm is raging."))
  2512. elsif @weather==PBWeather::HAIL
  2513. pbCommonAnimation("Hail",nil,nil)
  2514. pbDisplay(_INTL("Hail is falling."))
  2515. elsif @weather==PBWeather::HEAVYRAIN
  2516. pbCommonAnimation("HeavyRain",nil,nil)
  2517. pbDisplay(_INTL("It is raining heavily."))
  2518. elsif @weather==PBWeather::HARSHSUN
  2519. pbCommonAnimation("HarshSun",nil,nil)
  2520. pbDisplay(_INTL("The sunlight is extremely harsh."))
  2521. elsif @weather==PBWeather::STRONGWINDS
  2522. pbCommonAnimation("StrongWinds",nil,nil)
  2523. pbDisplay(_INTL("The wind is strong."))
  2524. end
  2525. pbOnActiveAll # Abilities
  2526. @turncount=0
  2527. loop do # Now begin the battle loop
  2528. PBDebug.log("")
  2529. PBDebug.log("***Round #{@turncount+1}***")
  2530. if @debug && @turncount>=100
  2531. @decision=pbDecisionOnTime()
  2532. PBDebug.log("")
  2533. PBDebug.log("***Undecided after 100 rounds, aborting***")
  2534. pbAbort
  2535. break
  2536. end
  2537. PBDebug.logonerr{
  2538. pbCommandPhase
  2539. }
  2540. break if @decision>0
  2541. PBDebug.logonerr{
  2542. pbAttackPhase
  2543. }
  2544. break if @decision>0
  2545. PBDebug.logonerr{
  2546. pbEndOfRoundPhase
  2547. }
  2548. break if @decision>0
  2549. @turncount+=1
  2550. end
  2551. return pbEndOfBattle(canlose)
  2552. end
  2553.  
  2554. ################################################################################
  2555. # Command phase.
  2556. ################################################################################
  2557. def pbCommandMenu(i)
  2558. return @scene.pbCommandMenu(i)
  2559. end
  2560.  
  2561. def pbItemMenu(i)
  2562. return @scene.pbItemMenu(i)
  2563. end
  2564.  
  2565. def pbAutoFightMenu(i)
  2566. return false
  2567. end
  2568.  
  2569. def pbCommandPhase
  2570. @scene.pbBeginCommandPhase
  2571. # @scene.pbResetCommandIndices
  2572. for i in 0...4 # Reset choices if commands can be shown
  2573. @battlers[i].effects[PBEffects::SkipTurn]=false
  2574. if pbCanShowCommands?(i) || @battlers[i].fainted?
  2575. @choices[i][0]=0
  2576. @choices[i][1]=0
  2577. @choices[i][2]=nil
  2578. @choices[i][3]=-1
  2579. else
  2580. unless !@doublebattle && pbIsDoubleBattler?(i)
  2581. PBDebug.log("[Reusing commands] #{@battlers[i].pbThis(true)}")
  2582. end
  2583. end
  2584. end
  2585. # Reset choices to perform Mega Evolution if it wasn't done somehow
  2586. for i in 0...2
  2587. for j in 0...@megaEvolution[i].length
  2588. @megaEvolution[i][j]=-1 if @megaEvolution[i][j]>=0
  2589. end
  2590. end
  2591. for i in 0...4
  2592. break if @decision!=0
  2593. next if @choices[i][0]!=0
  2594. if !pbOwnedByPlayer?(i) || @controlPlayer
  2595. if !@battlers[i].fainted? && pbCanShowCommands?(i)
  2596. @scene.pbChooseEnemyCommand(i)
  2597. end
  2598. else
  2599. commandDone=false
  2600. commandEnd=false
  2601. if pbCanShowCommands?(i)
  2602. loop do
  2603. cmd=pbCommandMenu(i)
  2604. if cmd==0 # Fight
  2605. if pbCanShowFightMenu?(i)
  2606. commandDone=true if pbAutoFightMenu(i)
  2607. until commandDone
  2608. index=@scene.pbFightMenu(i)
  2609. if index<0
  2610. side=(pbIsOpposing?(i)) ? 1 : 0
  2611. owner=pbGetOwnerIndex(i)
  2612. if @megaEvolution[side][owner]==i
  2613. @megaEvolution[side][owner]=-1
  2614. end
  2615. break
  2616. end
  2617. next if !pbRegisterMove(i,index)
  2618. if @doublebattle
  2619. thismove=@battlers[i].moves[index]
  2620. target=@battlers[i].pbTarget(thismove)
  2621. if target==PBTargets::SingleNonUser # single non-user
  2622. target=@scene.pbChooseTarget(i,target)
  2623. next if target<0
  2624. pbRegisterTarget(i,target)
  2625. elsif target==PBTargets::UserOrPartner # Acupressure
  2626. target=@scene.pbChooseTarget(i,target)
  2627. next if target<0 || (target&1)==1
  2628. pbRegisterTarget(i,target)
  2629. end
  2630. end
  2631. commandDone=true
  2632. end
  2633. else
  2634. pbAutoChooseMove(i)
  2635. commandDone=true
  2636. end
  2637. elsif cmd!=0 && @battlers[i].effects[PBEffects::SkyDrop]
  2638. pbDisplay(_INTL("Sky Drop won't let {1} go!",@battlers[i].pbThis(true)))
  2639. elsif cmd==1 # Bag
  2640. if !@internalbattle
  2641. if pbOwnedByPlayer?(i)
  2642. pbDisplay(_INTL("Items can't be used here."))
  2643. end
  2644. else
  2645. item=pbItemMenu(i)
  2646. if item[0]>0
  2647. if pbRegisterItem(i,item[0],item[1])
  2648. commandDone=true
  2649. end
  2650. end
  2651. end
  2652. elsif cmd==2 # Pokémon
  2653. pkmn=pbSwitchPlayer(i,false,true)
  2654. if pkmn>=0
  2655. commandDone=true if pbRegisterSwitch(i,pkmn)
  2656. end
  2657. elsif cmd==3 # Run
  2658. run=pbRun(i)
  2659. if run>0
  2660. commandDone=true
  2661. return
  2662. elsif run<0
  2663. commandDone=true
  2664. side=(pbIsOpposing?(i)) ? 1 : 0
  2665. owner=pbGetOwnerIndex(i)
  2666. if @megaEvolution[side][owner]==i
  2667. @megaEvolution[side][owner]=-1
  2668. end
  2669. end
  2670. elsif cmd==4 # Call
  2671. thispkmn=@battlers[i]
  2672. @choices[i][0]=4 # "Call Pokémon"
  2673. @choices[i][1]=0
  2674. @choices[i][2]=nil
  2675. side=(pbIsOpposing?(i)) ? 1 : 0
  2676. owner=pbGetOwnerIndex(i)
  2677. if @megaEvolution[side][owner]==i
  2678. @megaEvolution[side][owner]=-1
  2679. end
  2680. commandDone=true
  2681. elsif cmd==-1 # Go back to first battler's choice
  2682. @megaEvolution[0][0]=-1 if @megaEvolution[0][0]>=0
  2683. @megaEvolution[1][0]=-1 if @megaEvolution[1][0]>=0
  2684. # Restore the item the player's first Pokémon was due to use
  2685. if @choices[0][0]==3 && $PokemonBag && $PokemonBag.pbCanStore?(@choices[0][1])
  2686. $PokemonBag.pbStoreItem(@choices[0][1])
  2687. end
  2688. pbCommandPhase
  2689. return
  2690. end
  2691. break if commandDone
  2692. end
  2693. end
  2694. end
  2695. end
  2696. end
  2697.  
  2698. ################################################################################
  2699. # Attack phase.
  2700. ################################################################################
  2701. def pbAttackPhase
  2702. @scene.pbBeginAttackPhase
  2703. for i in 0...4
  2704. @successStates[i].clear
  2705. if @choices[i][0]!=1 && @choices[i][0]!=2
  2706. @battlers[i].effects[PBEffects::DestinyBond]=false
  2707. @battlers[i].effects[PBEffects::Grudge]=false
  2708. end
  2709. @battlers[i].turncount+=1 if !@battlers[i].fainted?
  2710. @battlers[i].effects[PBEffects::Rage]=false if !pbChoseMove?(i,:RAGE)
  2711. end
  2712. # Calculate priority at this time
  2713. @usepriority=false
  2714. priority=pbPriority(false,true)
  2715. # Mega Evolution
  2716. megaevolved=[]
  2717. for i in priority
  2718. if @choices[i.index][0]==1 && !i.effects[PBEffects::SkipTurn]
  2719. side=(pbIsOpposing?(i.index)) ? 1 : 0
  2720. owner=pbGetOwnerIndex(i.index)
  2721. if @megaEvolution[side][owner]==i.index
  2722. pbMegaEvolve(i.index)
  2723. megaevolved.push(i.index)
  2724. end
  2725. end
  2726. end
  2727. if megaevolved.length>0
  2728. for i in priority
  2729. i.pbAbilitiesOnSwitchIn(true) if megaevolved.include?(i.index)
  2730. end
  2731. end
  2732. # Call at Pokémon
  2733. for i in priority
  2734. if @choices[i.index][0]==4 && !i.effects[PBEffects::SkipTurn]
  2735. pbCall(i.index)
  2736. end
  2737. end
  2738. # Switch out Pokémon
  2739. @switching=true
  2740. switched=[]
  2741. for i in priority
  2742. if @choices[i.index][0]==2 && !i.effects[PBEffects::SkipTurn]
  2743. index=@choices[i.index][1] # party position of Pokémon to switch to
  2744. newpokename=index
  2745. if isConst?(pbParty(i.index)[index].ability,PBAbilities,:ILLUSION)
  2746. newpokename=pbGetLastPokeInTeam(i.index)
  2747. end
  2748. self.lastMoveUser=i.index
  2749. if !pbOwnedByPlayer?(i.index)
  2750. owner=pbGetOwner(i.index)
  2751. pbDisplayBrief(_INTL("{1} withdrew {2}!",owner.fullname,i.name))
  2752. PBDebug.log("[Withdrew Pokémon] Opponent withdrew #{i.pbThis(true)}")
  2753. else
  2754. pbDisplayBrief(_INTL("{1}, that's enough!\r\nCome back!",i.name))
  2755. PBDebug.log("[Withdrew Pokémon] Player withdrew #{i.pbThis(true)}")
  2756. end
  2757. for j in priority
  2758. next if !i.pbIsOpposing?(j.index)
  2759. # if Pursuit and this target ("i") was chosen
  2760. if pbChoseMoveFunctionCode?(j.index,0x88) && # Pursuit
  2761. !j.hasMovedThisRound?
  2762. if j.status!=PBStatuses::SLEEP && j.status!=PBStatuses::FROZEN &&
  2763. !j.effects[PBEffects::SkyDrop] &&
  2764. (!j.hasWorkingAbility(:TRUANT) || !j.effects[PBEffects::Truant])
  2765. @choices[j.index][3]=i.index # Make sure to target the switching Pokémon
  2766. j.pbUseMove(@choices[j.index]) # This calls pbGainEXP as appropriate
  2767. j.effects[PBEffects::Pursuit]=true
  2768. @switching=false
  2769. return if @decision>0
  2770. end
  2771. end
  2772. break if i.fainted?
  2773. end
  2774. if !pbRecallAndReplace(i.index,index,newpokename)
  2775. # If a forced switch somehow occurs here in single battles
  2776. # the attack phase now ends
  2777. if !@doublebattle
  2778. @switching=false
  2779. return
  2780. end
  2781. else
  2782. switched.push(i.index)
  2783. end
  2784. end
  2785. end
  2786. if switched.length>0
  2787. for i in priority
  2788. i.pbAbilitiesOnSwitchIn(true) if switched.include?(i.index)
  2789. end
  2790. end
  2791. @switching=false
  2792. # Use items
  2793. for i in priority
  2794. if @choices[i.index][0]==3 && !i.effects[PBEffects::SkipTurn]
  2795. if pbIsOpposing?(i.index)
  2796. # Opponent use item
  2797. pbEnemyUseItem(@choices[i.index][1],i)
  2798. else
  2799. # Player use item
  2800. item=@choices[i.index][1]
  2801. if item>0
  2802. usetype=$ItemData[item][ITEMBATTLEUSE]
  2803. if usetype==1 || usetype==3
  2804. if @choices[i.index][2]>=0
  2805. pbUseItemOnPokemon(item,@choices[i.index][2],i,@scene)
  2806. end
  2807. elsif usetype==2 || usetype==4
  2808. if !ItemHandlers.hasUseInBattle(item) # Poké Ball/Poké Doll used already
  2809. pbUseItemOnBattler(item,@choices[i.index][2],i,@scene)
  2810. end
  2811. end
  2812. end
  2813. end
  2814. end
  2815. end
  2816. # Use attacks
  2817. for i in priority
  2818. next if i.effects[PBEffects::SkipTurn]
  2819. if pbChoseMoveFunctionCode?(i.index,0x115) # Focus Punch
  2820. pbCommonAnimation("FocusPunch",i,nil)
  2821. pbDisplay(_INTL("{1} is tightening its focus!",i.pbThis))
  2822. end
  2823. end
  2824. 10.times do
  2825. # Forced to go next
  2826. advance=false
  2827. for i in priority
  2828. next if !i.effects[PBEffects::MoveNext]
  2829. next if i.hasMovedThisRound? || i.effects[PBEffects::SkipTurn]
  2830. advance=i.pbProcessTurn(@choices[i.index])
  2831. break if advance
  2832. end
  2833. return if @decision>0
  2834. next if advance
  2835. # Regular priority order
  2836. for i in priority
  2837. next if i.effects[PBEffects::Quash]
  2838. next if i.hasMovedThisRound? || i.effects[PBEffects::SkipTurn]
  2839. advance=i.pbProcessTurn(@choices[i.index])
  2840. break if advance
  2841. end
  2842. return if @decision>0
  2843. next if advance
  2844. # Quashed
  2845. for i in priority
  2846. next if !i.effects[PBEffects::Quash]
  2847. next if i.hasMovedThisRound? || i.effects[PBEffects::SkipTurn]
  2848. advance=i.pbProcessTurn(@choices[i.index])
  2849. break if advance
  2850. end
  2851. return if @decision>0
  2852. next if advance
  2853. # Check for all done
  2854. for i in priority
  2855. advance=true if @choices[i.index][0]==1 && !i.hasMovedThisRound? &&
  2856. !i.effects[PBEffects::SkipTurn]
  2857. break if advance
  2858. end
  2859. next if advance
  2860. break
  2861. end
  2862. 10.times do
  2863. @scene.pbGraphicsUpdate
  2864. @scene.pbInputUpdate
  2865. @scene.pbFrameUpdate
  2866. end
  2867. end
  2868.  
  2869. ################################################################################
  2870. # End of round.
  2871. ################################################################################
  2872. def pbEndOfRoundPhase
  2873. PBDebug.log("[End of round]")
  2874. for i in 0...4
  2875. @battlers[i].effects[PBEffects::Electrify]=false
  2876. @battlers[i].effects[PBEffects::Endure]=false
  2877. @battlers[i].effects[PBEffects::FirstPledge]=0
  2878. @battlers[i].effects[PBEffects::HyperBeam]-=1 if @battlers[i].effects[PBEffects::HyperBeam]>0
  2879. @battlers[i].effects[PBEffects::KingsShield]=false
  2880. @battlers[i].effects[PBEffects::LifeOrb]=false
  2881. @battlers[i].effects[PBEffects::MoveNext]=false
  2882. @battlers[i].effects[PBEffects::Powder]=false
  2883. @battlers[i].effects[PBEffects::Protect]=false
  2884. @battlers[i].effects[PBEffects::ProtectNegation]=false
  2885. @battlers[i].effects[PBEffects::Quash]=false
  2886. @battlers[i].effects[PBEffects::Roost]=false
  2887. @battlers[i].effects[PBEffects::SpikyShield]=false
  2888. end
  2889. @usepriority=false # recalculate priority
  2890. priority=pbPriority(true) # Ignoring Quick Claw here
  2891. # Weather
  2892. case @weather
  2893. when PBWeather::SUNNYDAY
  2894. @weatherduration=@weatherduration-1 if @weatherduration>0
  2895. if @weatherduration==0
  2896. pbDisplay(_INTL("The sunlight faded."))
  2897. @weather=0
  2898. PBDebug.log("[End of effect] Sunlight weather ended")
  2899. else
  2900. pbCommonAnimation("Sunny",nil,nil)
  2901. # pbDisplay(_INTL("The sunlight is strong."))
  2902. if pbWeather==PBWeather::SUNNYDAY
  2903. for i in priority
  2904. if i.hasWorkingAbility(:SOLARPOWER)
  2905. PBDebug.log("[Ability triggered] #{i.pbThis}'s Solar Power")
  2906. @scene.pbDamageAnimation(i,0)
  2907. i.pbReduceHP((i.totalhp/8).floor)
  2908. pbDisplay(_INTL("{1} was hurt by the sunlight!",i.pbThis))
  2909. if i.fainted?
  2910. return if !i.pbFaint
  2911. end
  2912. end
  2913. end
  2914. end
  2915. end
  2916. when PBWeather::RAINDANCE
  2917. @weatherduration=@weatherduration-1 if @weatherduration>0
  2918. if @weatherduration==0
  2919. pbDisplay(_INTL("The rain stopped."))
  2920. @weather=0
  2921. PBDebug.log("[End of effect] Rain weather ended")
  2922. else
  2923. pbCommonAnimation("Rain",nil,nil)
  2924. # pbDisplay(_INTL("Rain continues to fall."))
  2925. end
  2926. when PBWeather::SANDSTORM
  2927. @weatherduration=@weatherduration-1 if @weatherduration>0
  2928. if @weatherduration==0
  2929. pbDisplay(_INTL("The sandstorm subsided."))
  2930. @weather=0
  2931. PBDebug.log("[End of effect] Sandstorm weather ended")
  2932. else
  2933. pbCommonAnimation("Sandstorm",nil,nil)
  2934. # pbDisplay(_INTL("The sandstorm rages."))
  2935. if pbWeather==PBWeather::SANDSTORM
  2936. PBDebug.log("[Lingering effect triggered] Sandstorm weather damage")
  2937. for i in priority
  2938. next if i.fainted?
  2939. if !i.pbHasType?(:GROUND) && !i.pbHasType?(:ROCK) && !i.pbHasType?(:STEEL) &&
  2940. !i.hasWorkingAbility(:SANDVEIL) &&
  2941. !i.hasWorkingAbility(:SANDRUSH) &&
  2942. !i.hasWorkingAbility(:SANDFORCE) &&
  2943. !i.hasWorkingAbility(:MAGICGUARD) &&
  2944. !i.hasWorkingAbility(:OVERCOAT) &&
  2945. !i.hasWorkingItem(:SAFETYGOGGLES) &&
  2946. ![0xCA,0xCB].include?(PBMoveData.new(i.effects[PBEffects::TwoTurnAttack]).function) # Dig, Dive
  2947. @scene.pbDamageAnimation(i,0)
  2948. i.pbReduceHP((i.totalhp/16).floor)
  2949. pbDisplay(_INTL("{1} is buffeted by the sandstorm!",i.pbThis))
  2950. if i.fainted?
  2951. return if !i.pbFaint
  2952. end
  2953. end
  2954. end
  2955. end
  2956. end
  2957. when PBWeather::HAIL
  2958. @weatherduration=@weatherduration-1 if @weatherduration>0
  2959. if @weatherduration==0
  2960. pbDisplay(_INTL("The hail stopped."))
  2961. @weather=0
  2962. PBDebug.log("[End of effect] Hail weather ended")
  2963. else
  2964. pbCommonAnimation("Hail",nil,nil)
  2965. # pbDisplay(_INTL("Hail continues to fall."))
  2966. if pbWeather==PBWeather::HAIL
  2967. PBDebug.log("[Lingering effect triggered] Hail weather damage")
  2968. for i in priority
  2969. next if i.fainted?
  2970. if !i.pbHasType?(:ICE) &&
  2971. !i.hasWorkingAbility(:ICEBODY) &&
  2972. !i.hasWorkingAbility(:SNOWCLOAK) &&
  2973. !i.hasWorkingAbility(:MAGICGUARD) &&
  2974. !i.hasWorkingAbility(:OVERCOAT) &&
  2975. !i.hasWorkingItem(:SAFETYGOGGLES) &&
  2976. ![0xCA,0xCB].include?(PBMoveData.new(i.effects[PBEffects::TwoTurnAttack]).function) # Dig, Dive
  2977. @scene.pbDamageAnimation(i,0)
  2978. i.pbReduceHP((i.totalhp/16).floor)
  2979. pbDisplay(_INTL("{1} is buffeted by the hail!",i.pbThis))
  2980. if i.fainted?
  2981. return if !i.pbFaint
  2982. end
  2983. end
  2984. end
  2985. end
  2986. end
  2987. when PBWeather::HEAVYRAIN
  2988. hasabil=false
  2989. for i in 0...4
  2990. if isConst?(@battlers[i].ability,PBAbilities,:PRIMORDIALSEA) && !@battlers[i].fainted?
  2991. hasabil=true; break
  2992. end
  2993. end
  2994. @weatherduration=0 if !hasabil
  2995. if @weatherduration==0
  2996. pbDisplay(_INTL("The heavy rain stopped."))
  2997. @weather=0
  2998. PBDebug.log("[End of effect] Primordial Sea's rain weather ended")
  2999. else
  3000. pbCommonAnimation("HeavyRain",nil,nil)
  3001. # pbDisplay(_INTL("It is raining heavily."))
  3002. end
  3003. when PBWeather::HARSHSUN
  3004. hasabil=false
  3005. for i in 0...4
  3006. if isConst?(@battlers[i].ability,PBAbilities,:DESOLATELAND) && !@battlers[i].fainted?
  3007. hasabil=true; break
  3008. end
  3009. end
  3010. @weatherduration=0 if !hasabil
  3011. if @weatherduration==0
  3012. pbDisplay(_INTL("The harsh sunlight faded."))
  3013. @weather=0
  3014. PBDebug.log("[End of effect] Desolate Land's sunlight weather ended")
  3015. else
  3016. pbCommonAnimation("HarshSun",nil,nil)
  3017. # pbDisplay(_INTL("The sunlight is extremely harsh."))
  3018. if pbWeather==PBWeather::HARSHSUN
  3019. for i in priority
  3020. if i.hasWorkingAbility(:SOLARPOWER)
  3021. PBDebug.log("[Ability triggered] #{i.pbThis}'s Solar Power")
  3022. @scene.pbDamageAnimation(i,0)
  3023. i.pbReduceHP((i.totalhp/8).floor)
  3024. pbDisplay(_INTL("{1} was hurt by the sunlight!",i.pbThis))
  3025. if i.fainted?
  3026. return if !i.pbFaint
  3027. end
  3028. end
  3029. end
  3030. end
  3031. end
  3032. when PBWeather::STRONGWINDS
  3033. hasabil=false
  3034. for i in 0...4
  3035. if isConst?(@battlers[i].ability,PBAbilities,:DELTASTREAM) && !@battlers[i].fainted?
  3036. hasabil=true; break
  3037. end
  3038. end
  3039. @weatherduration=0 if !hasabil
  3040. if @weatherduration==0
  3041. pbDisplay(_INTL("The air current subsided."))
  3042. @weather=0
  3043. PBDebug.log("[End of effect] Delta Stream's wind weather ended")
  3044. else
  3045. pbCommonAnimation("StrongWinds",nil,nil)
  3046. # pbDisplay(_INTL("The wind is strong."))
  3047. end
  3048. end
  3049. # Shadow Sky weather
  3050. if isConst?(@weather,PBWeather,:SHADOWSKY)
  3051. @weatherduration=@weatherduration-1 if @weatherduration>0
  3052. if @weatherduration==0
  3053. pbDisplay(_INTL("The shadow sky faded."))
  3054. @weather=0
  3055. PBDebug.log("[End of effect] Shadow Sky weather ended")
  3056. else
  3057. pbCommonAnimation("ShadowSky",nil,nil)
  3058. # pbDisplay(_INTL("The shadow sky continues."));
  3059. if isConst?(pbWeather,PBWeather,:SHADOWSKY)
  3060. PBDebug.log("[Lingering effect triggered] Shadow Sky weather damage")
  3061. for i in priority
  3062. next if i.fainted?
  3063. if !i.isShadow?
  3064. @scene.pbDamageAnimation(i,0)
  3065. i.pbReduceHP((i.totalhp/16).floor)
  3066. pbDisplay(_INTL("{1} was hurt by the shadow sky!",i.pbThis))
  3067. if i.fainted?
  3068. return if !i.pbFaint
  3069. end
  3070. end
  3071. end
  3072. end
  3073. end
  3074. end
  3075. # Future Sight/Doom Desire
  3076. for i in battlers # not priority
  3077. next if i.fainted?
  3078. if i.effects[PBEffects::FutureSight]>0
  3079. i.effects[PBEffects::FutureSight]-=1
  3080. if i.effects[PBEffects::FutureSight]==0
  3081. move=i.effects[PBEffects::FutureSightMove]
  3082. PBDebug.log("[Lingering effect triggered] #{PBMoves.getName(move)} struck #{i.pbThis(true)}")
  3083. pbDisplay(_INTL("{1} took the {2} attack!",i.pbThis,PBMoves.getName(move)))
  3084. moveuser=nil
  3085. for j in battlers
  3086. next if j.pbIsOpposing?(i.effects[PBEffects::FutureSightUserPos])
  3087. if j.pokemonIndex==i.effects[PBEffects::FutureSightUser] && !j.fainted?
  3088. moveuser=j; break
  3089. end
  3090. end
  3091. if !moveuser
  3092. party=pbParty(i.effects[PBEffects::FutureSightUserPos])
  3093. if party[i.effects[PBEffects::FutureSightUser]].hp>0
  3094. moveuser=PokeBattle_Battler.new(self,i.effects[PBEffects::FutureSightUserPos])
  3095. moveuser.pbInitDummyPokemon(party[i.effects[PBEffects::FutureSightUser]],
  3096. i.effects[PBEffects::FutureSightUser])
  3097. end
  3098. end
  3099. if !moveuser
  3100. pbDisplay(_INTL("But it failed!"))
  3101. else
  3102. @futuresight=true
  3103. moveuser.pbUseMoveSimple(move,-1,i.index)
  3104. @futuresight=false
  3105. end
  3106. i.effects[PBEffects::FutureSight]=0
  3107. i.effects[PBEffects::FutureSightMove]=0
  3108. i.effects[PBEffects::FutureSightUser]=-1
  3109. i.effects[PBEffects::FutureSightUserPos]=-1
  3110. if i.fainted?
  3111. return if !i.pbFaint
  3112. next
  3113. end
  3114. end
  3115. end
  3116. end
  3117. for i in priority
  3118. next if i.fainted?
  3119. # Rain Dish
  3120. if i.hasWorkingAbility(:RAINDISH) && i.effects[PBEffects::HealBlock]==0 &&
  3121. (pbWeather==PBWeather::RAINDANCE ||
  3122. pbWeather==PBWeather::HEAVYRAIN)
  3123. PBDebug.log("[Ability triggered] #{i.pbThis}'s Rain Dish")
  3124. hpgain=i.pbRecoverHP((i.totalhp/16).floor,true)
  3125. pbDisplay(_INTL("{1}'s {2} restored its HP a little!",i.pbThis,PBAbilities.getName(i.ability))) if hpgain>0
  3126. end
  3127. # Dry Skin
  3128. if i.hasWorkingAbility(:DRYSKIN)
  3129. if (pbWeather==PBWeather::RAINDANCE || pbWeather==PBWeather::HEAVYRAIN) &&
  3130. i.effects[PBEffects::HealBlock]==0
  3131. PBDebug.log("[Ability triggered] #{i.pbThis}'s Dry Skin (in rain)")
  3132. hpgain=i.pbRecoverHP((i.totalhp/8).floor,true)
  3133. pbDisplay(_INTL("{1}'s {2} was healed by the rain!",i.pbThis,PBAbilities.getName(i.ability))) if hpgain>0
  3134. elsif pbWeather==PBWeather::SUNNYDAY ||
  3135. pbWeather==PBWeather::HARSHSUN
  3136. PBDebug.log("[Ability triggered] #{i.pbThis}'s Dry Skin (in sun)")
  3137. @scene.pbDamageAnimation(i,0)
  3138. hploss=i.pbReduceHP((i.totalhp/8).floor)
  3139. pbDisplay(_INTL("{1}'s {2} was hurt by the sunlight!",i.pbThis,PBAbilities.getName(i.ability))) if hploss>0
  3140. end
  3141. end
  3142. # Ice Body
  3143. if i.hasWorkingAbility(:ICEBODY) && pbWeather==PBWeather::HAIL &&
  3144. i.effects[PBEffects::HealBlock]==0
  3145. PBDebug.log("[Ability triggered] #{i.pbThis}'s Ice Body")
  3146. hpgain=i.pbRecoverHP((i.totalhp/16).floor,true)
  3147. pbDisplay(_INTL("{1}'s {2} restored its HP a little!",i.pbThis,PBAbilities.getName(i.ability))) if hpgain>0
  3148. end
  3149. if i.fainted?
  3150. return if !i.pbFaint
  3151. end
  3152. end
  3153. # Wish
  3154. for i in priority
  3155. next if i.fainted?
  3156. if i.effects[PBEffects::Wish]>0
  3157. i.effects[PBEffects::Wish]-=1
  3158. if i.effects[PBEffects::Wish]==0
  3159. PBDebug.log("[Lingering effect triggered] #{i.pbThis}'s Wish")
  3160. hpgain=i.pbRecoverHP(i.effects[PBEffects::WishAmount],true)
  3161. if hpgain>0
  3162. wishmaker=pbThisEx(i.index,i.effects[PBEffects::WishMaker])
  3163. pbDisplay(_INTL("{1}'s wish came true!",wishmaker))
  3164. end
  3165. end
  3166. end
  3167. end
  3168. # Fire Pledge + Grass Pledge combination damage
  3169. for i in 0...2
  3170. if sides[i].effects[PBEffects::SeaOfFire]>0 &&
  3171. pbWeather!=PBWeather::RAINDANCE &&
  3172. pbWeather!=PBWeather::HEAVYRAIN
  3173. @battle.pbCommonAnimation("SeaOfFire",nil,nil) if i==0
  3174. @battle.pbCommonAnimation("SeaOfFireOpp",nil,nil) if i==1
  3175. for j in priority
  3176. next if (j.index&1)!=i
  3177. next if j.pbHasType?(:FIRE) || j.hasWorkingAbility(:MAGICGUARD)
  3178. @scene.pbDamageAnimation(j,0)
  3179. hploss=j.pbReduceHP((j.totalhp/8).floor)
  3180. pbDisplay(_INTL("{1} is hurt by the sea of fire!",j.pbThis)) if hploss>0
  3181. if j.fainted?
  3182. return if !j.pbFaint
  3183. end
  3184. end
  3185. end
  3186. end
  3187. for i in priority
  3188. next if i.fainted?
  3189. # Shed Skin, Hydration
  3190. if (i.hasWorkingAbility(:SHEDSKIN) && pbRandom(10)<3) ||
  3191. (i.hasWorkingAbility(:HYDRATION) && (pbWeather==PBWeather::RAINDANCE ||
  3192. pbWeather==PBWeather::HEAVYRAIN))
  3193. if i.status>0
  3194. PBDebug.log("[Ability triggered] #{i.pbThis}'s #{PBAbilities.getName(i.ability)}")
  3195. s=i.status
  3196. i.pbCureStatus(false)
  3197. case s
  3198. when PBStatuses::SLEEP
  3199. pbDisplay(_INTL("{1}'s {2} cured its sleep problem!",i.pbThis,PBAbilities.getName(i.ability)))
  3200. when PBStatuses::POISON
  3201. pbDisplay(_INTL("{1}'s {2} cured its poison problem!",i.pbThis,PBAbilities.getName(i.ability)))
  3202. when PBStatuses::BURN
  3203. pbDisplay(_INTL("{1}'s {2} healed its burn!",i.pbThis,PBAbilities.getName(i.ability)))
  3204. when PBStatuses::PARALYSIS
  3205. pbDisplay(_INTL("{1}'s {2} cured its paralysis!",i.pbThis,PBAbilities.getName(i.ability)))
  3206. when PBStatuses::FROZEN
  3207. pbDisplay(_INTL("{1}'s {2} thawed it out!",i.pbThis,PBAbilities.getName(i.ability)))
  3208. end
  3209. end
  3210. end
  3211. # Healer
  3212. if i.hasWorkingAbility(:HEALER) && pbRandom(10)<3
  3213. partner=i.pbPartner
  3214. if partner && partner.status>0
  3215. PBDebug.log("[Ability triggered] #{i.pbThis}'s #{PBAbilities.getName(i.ability)}")
  3216. s=partner.status
  3217. partner.pbCureStatus(false)
  3218. case s
  3219. when PBStatuses::SLEEP
  3220. pbDisplay(_INTL("{1}'s {2} cured its partner's sleep problem!",i.pbThis,PBAbilities.getName(i.ability)))
  3221. when PBStatuses::POISON
  3222. pbDisplay(_INTL("{1}'s {2} cured its partner's poison problem!",i.pbThis,PBAbilities.getName(i.ability)))
  3223. when PBStatuses::BURN
  3224. pbDisplay(_INTL("{1}'s {2} healed its partner's burn!",i.pbThis,PBAbilities.getName(i.ability)))
  3225. when PBStatuses::PARALYSIS
  3226. pbDisplay(_INTL("{1}'s {2} cured its partner's paralysis!",i.pbThis,PBAbilities.getName(i.ability)))
  3227. when PBStatuses::FROZEN
  3228. pbDisplay(_INTL("{1}'s {2} thawed its partner out!",i.pbThis,PBAbilities.getName(i.ability)))
  3229. end
  3230. end
  3231. end
  3232. end
  3233. for i in priority
  3234. next if i.fainted?
  3235. # Grassy Terrain (healing)
  3236. if @field.effects[PBEffects::GrassyTerrain]>0 && !i.isAirborne?
  3237. if i.effects[PBEffects::HealBlock]==0
  3238. hpgain=i.pbRecoverHP((i.totalhp/16).floor,true)
  3239. pbDisplay(_INTL("{1}'s HP was restored.",i.pbThis)) if hpgain>0
  3240. end
  3241. end
  3242. # Held berries/Leftovers/Black Sludge
  3243. i.pbBerryCureCheck(true)
  3244. if i.fainted?
  3245. return if !i.pbFaint
  3246. end
  3247. end
  3248. # Aqua Ring
  3249. for i in priority
  3250. next if i.fainted?
  3251. if i.effects[PBEffects::AquaRing]
  3252. PBDebug.log("[Lingering effect triggered] #{i.pbThis}'s Aqua Ring")
  3253. hpgain=(i.totalhp/16).floor
  3254. hpgain=(hpgain*1.3).floor if i.hasWorkingItem(:BIGROOT)
  3255. hpgain=i.pbRecoverHP(hpgain,true)
  3256. pbDisplay(_INTL("Aqua Ring restored {1}'s HP!",i.pbThis)) if hpgain>0
  3257. end
  3258. end
  3259. # Ingrain
  3260. for i in priority
  3261. next if i.fainted?
  3262. if i.effects[PBEffects::Ingrain]
  3263. PBDebug.log("[Lingering effect triggered] #{i.pbThis}'s Ingrain")
  3264. hpgain=(i.totalhp/16).floor
  3265. hpgain=(hpgain*1.3).floor if i.hasWorkingItem(:BIGROOT)
  3266. hpgain=i.pbRecoverHP(hpgain,true)
  3267. pbDisplay(_INTL("{1} absorbed nutrients with its roots!",i.pbThis)) if hpgain>0
  3268. end
  3269. end
  3270. # Leech Seed
  3271. for i in priority
  3272. next if i.fainted?
  3273. if i.effects[PBEffects::LeechSeed]>=0 && !i.hasWorkingAbility(:MAGICGUARD)
  3274. recipient=@battlers[i.effects[PBEffects::LeechSeed]]
  3275. if recipient && !recipient.fainted?
  3276. PBDebug.log("[Lingering effect triggered] #{i.pbThis}'s Leech Seed")
  3277. pbCommonAnimation("LeechSeed",recipient,i)
  3278. hploss=i.pbReduceHP((i.totalhp/8).floor,true)
  3279. if i.hasWorkingAbility(:LIQUIDOOZE)
  3280. recipient.pbReduceHP(hploss,true)
  3281. pbDisplay(_INTL("{1} sucked up the liquid ooze!",recipient.pbThis))
  3282. else
  3283. if recipient.effects[PBEffects::HealBlock]==0
  3284. hploss=(hploss*1.3).floor if recipient.hasWorkingItem(:BIGROOT)
  3285. recipient.pbRecoverHP(hploss,true)
  3286. end
  3287. pbDisplay(_INTL("{1}'s health was sapped by Leech Seed!",i.pbThis))
  3288. end
  3289. if i.fainted?
  3290. return if !i.pbFaint
  3291. end
  3292. if recipient.fainted?
  3293. return if !recipient.pbFaint
  3294. end
  3295. end
  3296. end
  3297. end
  3298. for i in priority
  3299. next if i.fainted?
  3300. # Poison/Bad poison
  3301. if i.status==PBStatuses::POISON
  3302. if i.statusCount>0
  3303. i.effects[PBEffects::Toxic]+=1
  3304. i.effects[PBEffects::Toxic]=[15,i.effects[PBEffects::Toxic]].min
  3305. end
  3306. if i.hasWorkingAbility(:POISONHEAL)
  3307. pbCommonAnimation("Poison",i,nil)
  3308. if i.effects[PBEffects::HealBlock]==0 && i.hp<i.totalhp
  3309. PBDebug.log("[Ability triggered] #{i.pbThis}'s Poison Heal")
  3310. i.pbRecoverHP((i.totalhp/8).floor,true)
  3311. pbDisplay(_INTL("{1} is healed by poison!",i.pbThis))
  3312. end
  3313. else
  3314. if !i.hasWorkingAbility(:MAGICGUARD)
  3315. PBDebug.log("[Status damage] #{i.pbThis} took damage from poison/toxic")
  3316. if i.statusCount==0
  3317. i.pbReduceHP((i.totalhp/8).floor)
  3318. else
  3319. i.pbReduceHP(((i.totalhp*i.effects[PBEffects::Toxic])/16).floor)
  3320. end
  3321. i.pbContinueStatus
  3322. end
  3323. end
  3324. end
  3325. # Burn
  3326. if i.status==PBStatuses::BURN
  3327. if !i.hasWorkingAbility(:MAGICGUARD)
  3328. PBDebug.log("[Status damage] #{i.pbThis} took damage from burn")
  3329. if i.hasWorkingAbility(:HEATPROOF)
  3330. PBDebug.log("[Ability triggered] #{i.pbThis}'s Heatproof")
  3331. i.pbReduceHP((i.totalhp/16).floor)
  3332. else
  3333. i.pbReduceHP((i.totalhp/8).floor)
  3334. end
  3335. end
  3336. i.pbContinueStatus
  3337. end
  3338. # Nightmare
  3339. if i.effects[PBEffects::Nightmare]
  3340. if i.status==PBStatuses::SLEEP
  3341. if !i.hasWorkingAbility(:MAGICGUARD)
  3342. PBDebug.log("[Lingering effect triggered] #{i.pbThis}'s nightmare")
  3343. i.pbReduceHP((i.totalhp/4).floor,true)
  3344. pbDisplay(_INTL("{1} is locked in a nightmare!",i.pbThis))
  3345. end
  3346. else
  3347. i.effects[PBEffects::Nightmare]=false
  3348. end
  3349. end
  3350. if i.fainted?
  3351. return if !i.pbFaint
  3352. next
  3353. end
  3354. end
  3355. # Curse
  3356. for i in priority
  3357. next if i.fainted?
  3358. if i.effects[PBEffects::Curse] && !i.hasWorkingAbility(:MAGICGUARD)
  3359. PBDebug.log("[Lingering effect triggered] #{i.pbThis}'s curse")
  3360. i.pbReduceHP((i.totalhp/4).floor,true)
  3361. pbDisplay(_INTL("{1} is afflicted by the curse!",i.pbThis))
  3362. end
  3363. if i.fainted?
  3364. return if !i.pbFaint
  3365. next
  3366. end
  3367. end
  3368. # Multi-turn attacks (Bind/Clamp/Fire Spin/Magma Storm/Sand Tomb/Whirlpool/Wrap)
  3369. for i in priority
  3370. next if i.fainted?
  3371. if i.effects[PBEffects::MultiTurn]>0
  3372. i.effects[PBEffects::MultiTurn]-=1
  3373. movename=PBMoves.getName(i.effects[PBEffects::MultiTurnAttack])
  3374. if i.effects[PBEffects::MultiTurn]==0
  3375. PBDebug.log("[End of effect] Trapping move #{movename} affecting #{i.pbThis} ended")
  3376. pbDisplay(_INTL("{1} was freed from {2}!",i.pbThis,movename))
  3377. else
  3378. if isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:BIND)
  3379. pbCommonAnimation("Bind",i,nil)
  3380. elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:CLAMP)
  3381. pbCommonAnimation("Clamp",i,nil)
  3382. elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:FIRESPIN)
  3383. pbCommonAnimation("FireSpin",i,nil)
  3384. elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:MAGMASTORM)
  3385. pbCommonAnimation("MagmaStorm",i,nil)
  3386. elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:SANDTOMB)
  3387. pbCommonAnimation("SandTomb",i,nil)
  3388. elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:WRAP)
  3389. pbCommonAnimation("Wrap",i,nil)
  3390. elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:INFESTATION)
  3391. pbCommonAnimation("Infestation",i,nil)
  3392. else
  3393. pbCommonAnimation("Wrap",i,nil)
  3394. end
  3395. if !i.hasWorkingAbility(:MAGICGUARD)
  3396. PBDebug.log("[Lingering effect triggered] #{i.pbThis} took damage from trapping move #{movename}")
  3397. @scene.pbDamageAnimation(i,0)
  3398. amt=(USENEWBATTLEMECHANICS) ? (i.totalhp/8).floor : (i.totalhp/16).floor
  3399. if @battlers[i.effects[PBEffects::MultiTurnUser]].hasWorkingItem(:BINDINGBAND)
  3400. amt=(USENEWBATTLEMECHANICS) ? (i.totalhp/6).floor : (i.totalhp/8).floor
  3401. end
  3402. i.pbReduceHP(amt)
  3403. pbDisplay(_INTL("{1} is hurt by {2}!",i.pbThis,movename))
  3404. end
  3405. end
  3406. end
  3407. if i.fainted?
  3408. return if !i.pbFaint
  3409. end
  3410. end
  3411. # Taunt
  3412. for i in priority
  3413. next if i.fainted?
  3414. if i.effects[PBEffects::Taunt]>0
  3415. i.effects[PBEffects::Taunt]-=1
  3416. if i.effects[PBEffects::Taunt]==0
  3417. pbDisplay(_INTL("{1}'s taunt wore off!",i.pbThis))
  3418. PBDebug.log("[End of effect] #{i.pbThis} is no longer taunted")
  3419. end
  3420. end
  3421. end
  3422. # Encore
  3423. for i in priority
  3424. next if i.fainted?
  3425. if i.effects[PBEffects::Encore]>0
  3426. if i.moves[i.effects[PBEffects::EncoreIndex]].id!=i.effects[PBEffects::EncoreMove]
  3427. i.effects[PBEffects::Encore]=0
  3428. i.effects[PBEffects::EncoreIndex]=0
  3429. i.effects[PBEffects::EncoreMove]=0
  3430. PBDebug.log("[End of effect] #{i.pbThis} is no longer encored (encored move was lost)")
  3431. else
  3432. i.effects[PBEffects::Encore]-=1
  3433. if i.effects[PBEffects::Encore]==0 || i.moves[i.effects[PBEffects::EncoreIndex]].pp==0
  3434. i.effects[PBEffects::Encore]=0
  3435. pbDisplay(_INTL("{1}'s encore ended!",i.pbThis))
  3436. PBDebug.log("[End of effect] #{i.pbThis} is no longer encored")
  3437. end
  3438. end
  3439. end
  3440. end
  3441. # Disable/Cursed Body
  3442. for i in priority
  3443. next if i.fainted?
  3444. if i.effects[PBEffects::Disable]>0
  3445. i.effects[PBEffects::Disable]-=1
  3446. if i.effects[PBEffects::Disable]==0
  3447. i.effects[PBEffects::DisableMove]=0
  3448. pbDisplay(_INTL("{1} is no longer disabled!",i.pbThis))
  3449. PBDebug.log("[End of effect] #{i.pbThis} is no longer disabled")
  3450. end
  3451. end
  3452. end
  3453. # Magnet Rise
  3454. for i in priority
  3455. next if i.fainted?
  3456. if i.effects[PBEffects::MagnetRise]>0
  3457. i.effects[PBEffects::MagnetRise]-=1
  3458. if i.effects[PBEffects::MagnetRise]==0
  3459. pbDisplay(_INTL("{1} stopped levitating.",i.pbThis))
  3460. PBDebug.log("[End of effect] #{i.pbThis} is no longer levitating by Magnet Rise")
  3461. end
  3462. end
  3463. end
  3464. # Telekinesis
  3465. for i in priority
  3466. next if i.fainted?
  3467. if i.effects[PBEffects::Telekinesis]>0
  3468. i.effects[PBEffects::Telekinesis]-=1
  3469. if i.effects[PBEffects::Telekinesis]==0
  3470. pbDisplay(_INTL("{1} stopped levitating.",i.pbThis))
  3471. PBDebug.log("[End of effect] #{i.pbThis} is no longer levitating by Telekinesis")
  3472. end
  3473. end
  3474. end
  3475. # Heal Block
  3476. for i in priority
  3477. next if i.fainted?
  3478. if i.effects[PBEffects::HealBlock]>0
  3479. i.effects[PBEffects::HealBlock]-=1
  3480. if i.effects[PBEffects::HealBlock]==0
  3481. pbDisplay(_INTL("{1}'s Heal Block wore off!",i.pbThis))
  3482. PBDebug.log("[End of effect] #{i.pbThis} is no longer Heal Blocked")
  3483. end
  3484. end
  3485. end
  3486. # Embargo
  3487. for i in priority
  3488. next if i.fainted?
  3489. if i.effects[PBEffects::Embargo]>0
  3490. i.effects[PBEffects::Embargo]-=1
  3491. if i.effects[PBEffects::Embargo]==0
  3492. pbDisplay(_INTL("{1} can use items again!",i.pbThis(true)))
  3493. PBDebug.log("[End of effect] #{i.pbThis} is no longer affected by an embargo")
  3494. end
  3495. end
  3496. end
  3497. # Yawn
  3498. for i in priority
  3499. next if i.fainted?
  3500. if i.effects[PBEffects::Yawn]>0
  3501. i.effects[PBEffects::Yawn]-=1
  3502. if i.effects[PBEffects::Yawn]==0 && i.pbCanSleepYawn?
  3503. PBDebug.log("[Lingering effect triggered] #{i.pbThis}'s Yawn")
  3504. i.pbSleep
  3505. i.pbBerryCureCheck
  3506. end
  3507. end
  3508. end
  3509. # Perish Song
  3510. perishSongUsers=[]
  3511. for i in priority
  3512. next if i.fainted?
  3513. if i.effects[PBEffects::PerishSong]>0
  3514. i.effects[PBEffects::PerishSong]-=1
  3515. pbDisplay(_INTL("{1}'s perish count fell to {2}!",i.pbThis,i.effects[PBEffects::PerishSong]))
  3516. PBDebug.log("[Lingering effect triggered] #{i.pbThis}'s Perish Song count dropped to #{i.effects[PBEffects::PerishSong]}")
  3517. if i.effects[PBEffects::PerishSong]==0
  3518. perishSongUsers.push(i.effects[PBEffects::PerishSongUser])
  3519. i.pbReduceHP(i.hp,true)
  3520. end
  3521. end
  3522. if i.fainted?
  3523. return if !i.pbFaint
  3524. end
  3525. end
  3526. if perishSongUsers.length>0
  3527. # If all remaining Pokemon fainted by a Perish Song triggered by a single side
  3528. if (perishSongUsers.find_all{|item| pbIsOpposing?(item) }.length==perishSongUsers.length) ||
  3529. (perishSongUsers.find_all{|item| !pbIsOpposing?(item) }.length==perishSongUsers.length)
  3530. pbJudgeCheckpoint(@battlers[perishSongUsers[0]])
  3531. end
  3532. end
  3533. if @decision>0
  3534. pbGainEXP
  3535. return
  3536. end
  3537. # Reflect
  3538. for i in 0...2
  3539. if sides[i].effects[PBEffects::Reflect]>0
  3540. sides[i].effects[PBEffects::Reflect]-=1
  3541. if sides[i].effects[PBEffects::Reflect]==0
  3542. pbDisplay(_INTL("Your team's Reflect faded!")) if i==0
  3543. pbDisplay(_INTL("The opposing team's Reflect faded!")) if i==1
  3544. PBDebug.log("[End of effect] Reflect ended on the player's side") if i==0
  3545. PBDebug.log("[End of effect] Reflect ended on the opponent's side") if i==1
  3546. end
  3547. end
  3548. end
  3549. # Light Screen
  3550. for i in 0...2
  3551. if sides[i].effects[PBEffects::LightScreen]>0
  3552. sides[i].effects[PBEffects::LightScreen]-=1
  3553. if sides[i].effects[PBEffects::LightScreen]==0
  3554. pbDisplay(_INTL("Your team's Light Screen faded!")) if i==0
  3555. pbDisplay(_INTL("The opposing team's Light Screen faded!")) if i==1
  3556. PBDebug.log("[End of effect] Light Screen ended on the player's side") if i==0
  3557. PBDebug.log("[End of effect] Light Screen ended on the opponent's side") if i==1
  3558. end
  3559. end
  3560. end
  3561. # Safeguard
  3562. for i in 0...2
  3563. if sides[i].effects[PBEffects::Safeguard]>0
  3564. sides[i].effects[PBEffects::Safeguard]-=1
  3565. if sides[i].effects[PBEffects::Safeguard]==0
  3566. pbDisplay(_INTL("Your team is no longer protected by Safeguard!")) if i==0
  3567. pbDisplay(_INTL("The opposing team is no longer protected by Safeguard!")) if i==1
  3568. PBDebug.log("[End of effect] Safeguard ended on the player's side") if i==0
  3569. PBDebug.log("[End of effect] Safeguard ended on the opponent's side") if i==1
  3570. end
  3571. end
  3572. end
  3573. # Mist
  3574. for i in 0...2
  3575. if sides[i].effects[PBEffects::Mist]>0
  3576. sides[i].effects[PBEffects::Mist]-=1
  3577. if sides[i].effects[PBEffects::Mist]==0
  3578. pbDisplay(_INTL("Your team's Mist faded!")) if i==0
  3579. pbDisplay(_INTL("The opposing team's Mist faded!")) if i==1
  3580. PBDebug.log("[End of effect] Mist ended on the player's side") if i==0
  3581. PBDebug.log("[End of effect] Mist ended on the opponent's side") if i==1
  3582. end
  3583. end
  3584. end
  3585. # Tailwind
  3586. for i in 0...2
  3587. if sides[i].effects[PBEffects::Tailwind]>0
  3588. sides[i].effects[PBEffects::Tailwind]-=1
  3589. if sides[i].effects[PBEffects::Tailwind]==0
  3590. pbDisplay(_INTL("Your team's Tailwind petered out!")) if i==0
  3591. pbDisplay(_INTL("The opposing team's Tailwind petered out!")) if i==1
  3592. PBDebug.log("[End of effect] Tailwind ended on the player's side") if i==0
  3593. PBDebug.log("[End of effect] Tailwind ended on the opponent's side") if i==1
  3594. end
  3595. end
  3596. end
  3597. # Lucky Chant
  3598. for i in 0...2
  3599. if sides[i].effects[PBEffects::LuckyChant]>0
  3600. sides[i].effects[PBEffects::LuckyChant]-=1
  3601. if sides[i].effects[PBEffects::LuckyChant]==0
  3602. pbDisplay(_INTL("Your team's Lucky Chant faded!")) if i==0
  3603. pbDisplay(_INTL("The opposing team's Lucky Chant faded!")) if i==1
  3604. PBDebug.log("[End of effect] Lucky Chant ended on the player's side") if i==0
  3605. PBDebug.log("[End of effect] Lucky Chant ended on the opponent's side") if i==1
  3606. end
  3607. end
  3608. end
  3609. # End of Pledge move combinations
  3610. for i in 0...2
  3611. if sides[i].effects[PBEffects::Swamp]>0
  3612. sides[i].effects[PBEffects::Swamp]-=1
  3613. if sides[i].effects[PBEffects::Swamp]==0
  3614. pbDisplay(_INTL("The swamp around your team disappeared!")) if i==0
  3615. pbDisplay(_INTL("The swamp around the opposing team disappeared!")) if i==1
  3616. PBDebug.log("[End of effect] Grass Pledge's swamp ended on the player's side") if i==0
  3617. PBDebug.log("[End of effect] Grass Pledge's swamp ended on the opponent's side") if i==1
  3618. end
  3619. end
  3620. if sides[i].effects[PBEffects::SeaOfFire]>0
  3621. sides[i].effects[PBEffects::SeaOfFire]-=1
  3622. if sides[i].effects[PBEffects::SeaOfFire]==0
  3623. pbDisplay(_INTL("The sea of fire around your team disappeared!")) if i==0
  3624. pbDisplay(_INTL("The sea of fire around the opposing team disappeared!")) if i==1
  3625. PBDebug.log("[End of effect] Fire Pledge's sea of fire ended on the player's side") if i==0
  3626. PBDebug.log("[End of effect] Fire Pledge's sea of fire ended on the opponent's side") if i==1
  3627. end
  3628. end
  3629. if sides[i].effects[PBEffects::Rainbow]>0
  3630. sides[i].effects[PBEffects::Rainbow]-=1
  3631. if sides[i].effects[PBEffects::Rainbow]==0
  3632. pbDisplay(_INTL("The rainbow around your team disappeared!")) if i==0
  3633. pbDisplay(_INTL("The rainbow around the opposing team disappeared!")) if i==1
  3634. PBDebug.log("[End of effect] Water Pledge's rainbow ended on the player's side") if i==0
  3635. PBDebug.log("[End of effect] Water Pledge's rainbow ended on the opponent's side") if i==1
  3636. end
  3637. end
  3638. end
  3639. # Gravity
  3640. if @field.effects[PBEffects::Gravity]>0
  3641. @field.effects[PBEffects::Gravity]-=1
  3642. if @field.effects[PBEffects::Gravity]==0
  3643. pbDisplay(_INTL("Gravity returned to normal."))
  3644. PBDebug.log("[End of effect] Strong gravity ended")
  3645. end
  3646. end
  3647. # Trick Room
  3648. if @field.effects[PBEffects::TrickRoom]>0
  3649. @field.effects[PBEffects::TrickRoom]-=1
  3650. if @field.effects[PBEffects::TrickRoom]==0
  3651. pbDisplay(_INTL("The twisted dimensions returned to normal."))
  3652. PBDebug.log("[End of effect] Trick Room ended")
  3653. end
  3654. end
  3655. # Wonder Room
  3656. if @field.effects[PBEffects::WonderRoom]>0
  3657. @field.effects[PBEffects::WonderRoom]-=1
  3658. if @field.effects[PBEffects::WonderRoom]==0
  3659. pbDisplay(_INTL("Wonder Room wore off, and the Defense and Sp. Def stats returned to normal!"))
  3660. PBDebug.log("[End of effect] Wonder Room ended")
  3661. end
  3662. end
  3663. # Magic Room
  3664. if @field.effects[PBEffects::MagicRoom]>0
  3665. @field.effects[PBEffects::MagicRoom]-=1
  3666. if @field.effects[PBEffects::MagicRoom]==0
  3667. pbDisplay(_INTL("The area returned to normal."))
  3668. PBDebug.log("[End of effect] Magic Room ended")
  3669. end
  3670. end
  3671. # Mud Sport
  3672. if @field.effects[PBEffects::MudSportField]>0
  3673. @field.effects[PBEffects::MudSportField]-=1
  3674. if @field.effects[PBEffects::MudSportField]==0
  3675. pbDisplay(_INTL("The effects of Mud Sport have faded."))
  3676. PBDebug.log("[End of effect] Mud Sport ended")
  3677. end
  3678. end
  3679. # Water Sport
  3680. if @field.effects[PBEffects::WaterSportField]>0
  3681. @field.effects[PBEffects::WaterSportField]-=1
  3682. if @field.effects[PBEffects::WaterSportField]==0
  3683. pbDisplay(_INTL("The effects of Water Sport have faded."))
  3684. PBDebug.log("[End of effect] Water Sport ended")
  3685. end
  3686. end
  3687. # Electric Terrain
  3688. if @field.effects[PBEffects::ElectricTerrain]>0
  3689. @field.effects[PBEffects::ElectricTerrain]-=1
  3690. if @field.effects[PBEffects::ElectricTerrain]==0
  3691. pbDisplay(_INTL("The electric current disappeared from the battlefield."))
  3692. PBDebug.log("[End of effect] Electric Terrain ended")
  3693. end
  3694. end
  3695. # Grassy Terrain (counting down)
  3696. if @field.effects[PBEffects::GrassyTerrain]>0
  3697. @field.effects[PBEffects::GrassyTerrain]-=1
  3698. if @field.effects[PBEffects::GrassyTerrain]==0
  3699. pbDisplay(_INTL("The grass disappeared from the battlefield."))
  3700. PBDebug.log("[End of effect] Grassy Terrain ended")
  3701. end
  3702. end
  3703. # Misty Terrain
  3704. if @field.effects[PBEffects::MistyTerrain]>0
  3705. @field.effects[PBEffects::MistyTerrain]-=1
  3706. if @field.effects[PBEffects::MistyTerrain]==0
  3707. pbDisplay(_INTL("The mist disappeared from the battlefield."))
  3708. PBDebug.log("[End of effect] Misty Terrain ended")
  3709. end
  3710. end
  3711. # Uproar
  3712. for i in priority
  3713. next if i.fainted?
  3714. if i.effects[PBEffects::Uproar]>0
  3715. for j in priority
  3716. if !j.fainted? && j.status==PBStatuses::SLEEP && !j.hasWorkingAbility(:SOUNDPROOF)
  3717. PBDebug.log("[Lingering effect triggered] Uproar woke up #{j.pbThis(true)}")
  3718. j.pbCureStatus(false)
  3719. pbDisplay(_INTL("{1} woke up in the uproar!",j.pbThis))
  3720. end
  3721. end
  3722. i.effects[PBEffects::Uproar]-=1
  3723. if i.effects[PBEffects::Uproar]==0
  3724. pbDisplay(_INTL("{1} calmed down.",i.pbThis))
  3725. PBDebug.log("[End of effect] #{i.pbThis} is no longer uproaring")
  3726. else
  3727. pbDisplay(_INTL("{1} is making an uproar!",i.pbThis))
  3728. end
  3729. end
  3730. end
  3731. for i in priority
  3732. next if i.fainted?
  3733. # Speed Boost
  3734. # A Pokémon's turncount is 0 if it became active after the beginning of a round
  3735. if i.turncount>0 && i.hasWorkingAbility(:SPEEDBOOST)
  3736. if i.pbIncreaseStatWithCause(PBStats::SPEED,1,i,PBAbilities.getName(i.ability))
  3737. PBDebug.log("[Ability triggered] #{i.pbThis}'s #{PBAbilities.getName(i.ability)}")
  3738. end
  3739. end
  3740. # Bad Dreams
  3741. if i.status==PBStatuses::SLEEP && !i.hasWorkingAbility(:MAGICGUARD)
  3742. if i.pbOpposing1.hasWorkingAbility(:BADDREAMS) ||
  3743. i.pbOpposing2.hasWorkingAbility(:BADDREAMS)
  3744. PBDebug.log("[Ability triggered] #{i.pbThis}'s opponent's Bad Dreams")
  3745. hploss=i.pbReduceHP((i.totalhp/8).floor,true)
  3746. pbDisplay(_INTL("{1} is having a bad dream!",i.pbThis)) if hploss>0
  3747. end
  3748. end
  3749. if i.fainted?
  3750. return if !i.pbFaint
  3751. next
  3752. end
  3753. # Pickup
  3754. if i.hasWorkingAbility(:PICKUP) && i.item<=0
  3755. item=0; index=-1; use=0
  3756. for j in 0...4
  3757. next if j==i.index
  3758. if @battlers[j].effects[PBEffects::PickupUse]>use
  3759. item=@battlers[j].effects[PBEffects::PickupItem]
  3760. index=j
  3761. use=@battlers[j].effects[PBEffects::PickupUse]
  3762. end
  3763. end
  3764. if item>0
  3765. i.item=item
  3766. @battlers[index].effects[PBEffects::PickupItem]=0
  3767. @battlers[index].effects[PBEffects::PickupUse]=0
  3768. @battlers[index].pokemon.itemRecycle=0 if @battlers[index].pokemon.itemRecycle==item
  3769. if !@opponent && # In a wild battle
  3770. i.pokemon.itemInitial==0 &&
  3771. @battlers[index].pokemon.itemInitial==item
  3772. i.pokemon.itemInitial=item
  3773. @battlers[index].pokemon.itemInitial=0
  3774. end
  3775. pbDisplay(_INTL("{1} found one {2}!",i.pbThis,PBItems.getName(item)))
  3776. i.pbBerryCureCheck(true)
  3777. end
  3778. end
  3779. # Harvest
  3780. if i.hasWorkingAbility(:HARVEST) && i.item<=0 && i.pokemon.itemRecycle>0
  3781. if pbIsBerry?(i.pokemon.itemRecycle) &&
  3782. (pbWeather==PBWeather::SUNNYDAY ||
  3783. pbWeather==PBWeather::HARSHSUN || pbRandom(10)<5)
  3784. i.item=i.pokemon.itemRecycle
  3785. i.pokemon.itemRecycle=0
  3786. i.pokemon.itemInitial=i.item if i.pokemon.itemInitial==0
  3787. pbDisplay(_INTL("{1} harvested one {2}!",i.pbThis,PBItems.getName(i.item)))
  3788. i.pbBerryCureCheck(true)
  3789. end
  3790. end
  3791. # Moody
  3792. if i.hasWorkingAbility(:MOODY)
  3793. randomup=[]; randomdown=[]
  3794. for j in [PBStats::ATTACK,PBStats::DEFENSE,PBStats::SPEED,PBStats::SPATK,
  3795. PBStats::SPDEF,PBStats::ACCURACY,PBStats::EVASION]
  3796. randomup.push(j) if i.pbCanIncreaseStatStage?(j,i)
  3797. randomdown.push(j) if i.pbCanReduceStatStage?(j,i)
  3798. end
  3799. if randomup.length>0
  3800. PBDebug.log("[Ability triggered] #{i.pbThis}'s Moody (raise stat)")
  3801. r=pbRandom(randomup.length)
  3802. i.pbIncreaseStatWithCause(randomup[r],2,i,PBAbilities.getName(i.ability))
  3803. for j in 0...randomdown.length
  3804. if randomdown[j]==randomup[r]
  3805. randomdown[j]=nil; randomdown.compact!
  3806. break
  3807. end
  3808. end
  3809. end
  3810. if randomdown.length>0
  3811. PBDebug.log("[Ability triggered] #{i.pbThis}'s Moody (lower stat)")
  3812. r=pbRandom(randomdown.length)
  3813. i.pbReduceStatWithCause(randomdown[r],1,i,PBAbilities.getName(i.ability))
  3814. end
  3815. end
  3816. end
  3817. for i in priority
  3818. next if i.fainted?
  3819. # Toxic Orb
  3820. if i.hasWorkingItem(:TOXICORB) && i.status==0 && i.pbCanPoison?(nil,false)
  3821. PBDebug.log("[Item triggered] #{i.pbThis}'s Toxic Orb")
  3822. i.pbPoison(nil,_INTL("{1} was badly poisoned by its {2}!",i.pbThis,
  3823. PBItems.getName(i.item)),true)
  3824. end
  3825. # Flame Orb
  3826. if i.hasWorkingItem(:FLAMEORB) && i.status==0 && i.pbCanBurn?(nil,false)
  3827. PBDebug.log("[Item triggered] #{i.pbThis}'s Flame Orb")
  3828. i.pbBurn(nil,_INTL("{1} was burned by its {2}!",i.pbThis,PBItems.getName(i.item)))
  3829. end
  3830. # Sticky Barb
  3831. if i.hasWorkingItem(:STICKYBARB) && !i.hasWorkingAbility(:MAGICGUARD)
  3832. PBDebug.log("[Item triggered] #{i.pbThis}'s Sticky Barb")
  3833. @scene.pbDamageAnimation(i,0)
  3834. i.pbReduceHP((i.totalhp/8).floor)
  3835. pbDisplay(_INTL("{1} is hurt by its {2}!",i.pbThis,PBItems.getName(i.item)))
  3836. end
  3837. if i.fainted?
  3838. return if !i.pbFaint
  3839. end
  3840. end
  3841. # Slow Start's end message
  3842. if i.hasWorkingAbility(:SLOWSTART) && i.turncount==6
  3843. pbDisplay(_INTL("{1} finally got its act together!",i.pbThis))
  3844. end
  3845. # Form checks
  3846. for i in 0...4
  3847. next if @battlers[i].fainted?
  3848. @battlers[i].pbCheckForm
  3849. end
  3850. pbGainEXP
  3851. pbSwitch
  3852. return if @decision>0
  3853. for i in priority
  3854. next if i.fainted?
  3855. i.pbAbilitiesOnSwitchIn(false)
  3856. end
  3857. # Healing Wish/Lunar Dance - should go here
  3858. # Spikes/Toxic Spikes/Stealth Rock - should go here (in order of their 1st use)
  3859. for i in 0...4
  3860. if @battlers[i].turncount>0 && @battlers[i].hasWorkingAbility(:TRUANT)
  3861. @battlers[i].effects[PBEffects::Truant]=!@battlers[i].effects[PBEffects::Truant]
  3862. end
  3863. if @battlers[i].effects[PBEffects::LockOn]>0 # Also Mind Reader
  3864. @battlers[i].effects[PBEffects::LockOn]-=1
  3865. @battlers[i].effects[PBEffects::LockOnPos]=-1 if @battlers[i].effects[PBEffects::LockOn]==0
  3866. end
  3867. @battlers[i].effects[PBEffects::Flinch]=false
  3868. @battlers[i].effects[PBEffects::FollowMe]=0
  3869. @battlers[i].effects[PBEffects::HelpingHand]=false
  3870. @battlers[i].effects[PBEffects::MagicCoat]=false
  3871. @battlers[i].effects[PBEffects::Snatch]=false
  3872. @battlers[i].effects[PBEffects::Charge]-=1 if @battlers[i].effects[PBEffects::Charge]>0
  3873. @battlers[i].lastHPLost=0
  3874. @battlers[i].tookDamage=false
  3875. @battlers[i].lastAttacker.clear
  3876. @battlers[i].effects[PBEffects::Counter]=-1
  3877. @battlers[i].effects[PBEffects::CounterTarget]=-1
  3878. @battlers[i].effects[PBEffects::MirrorCoat]=-1
  3879. @battlers[i].effects[PBEffects::MirrorCoatTarget]=-1
  3880. end
  3881. for i in 0...2
  3882. if !@sides[i].effects[PBEffects::EchoedVoiceUsed]
  3883. @sides[i].effects[PBEffects::EchoedVoiceCounter]=0
  3884. end
  3885. @sides[i].effects[PBEffects::EchoedVoiceUsed]=false
  3886. @sides[i].effects[PBEffects::MatBlock]= false
  3887. @sides[i].effects[PBEffects::QuickGuard]=false
  3888. @sides[i].effects[PBEffects::WideGuard]=false
  3889. @sides[i].effects[PBEffects::CraftyShield]=false
  3890. @sides[i].effects[PBEffects::Round]=0
  3891. end
  3892. @field.effects[PBEffects::FusionBolt]=false
  3893. @field.effects[PBEffects::FusionFlare]=false
  3894. @field.effects[PBEffects::IonDeluge]=false
  3895. @field.effects[PBEffects::FairyLock]-=1 if @field.effects[PBEffects::FairyLock]>0
  3896. # invalidate stored priority
  3897. @usepriority=false
  3898. end
  3899.  
  3900. ################################################################################
  3901. # End of battle.
  3902. ################################################################################
  3903. def pbEndOfBattle(canlose=false)
  3904. case @decision
  3905. ##### WIN #####
  3906. when 1
  3907. PBDebug.log("")
  3908. PBDebug.log("***Player won***")
  3909. if @opponent
  3910. @scene.pbTrainerBattleSuccess
  3911. #bugtrainer_01 battle
  3912. if $game_switches[130] and pbPokemonCount(@party2)==0
  3913. @scene.pbShowOpponent(0)
  3914. pbDisplayPaused(_INTL("????: Ratatta, NO!"))
  3915. pbDisplayPaused(_INTL("Rusty: We win! Great job, Pikachu!"))
  3916. pbDisplayPaused(_INTL("????: Hey, That's Cheating!"))
  3917. pbDisplayPaused(_INTL("???: And that's not even a Pikachu!"))
  3918. pbDisplayPaused(_INTL("Rusty: Hah. Classic rival move. Can't admit when he's defeated."))
  3919. pbDisplayPaused(_INTL("????: We are NOT rivals anymore."))
  3920. pbDisplayPaused(_INTL("????: I'm going HOME!"))
  3921. pbSEPlay("Battle flee.ogg")
  3922. @scene.pbHideOpponent
  3923. pbDisplayPaused(_INTL("Rusty: Coward!"))
  3924. #add here
  3925. end
  3926. if @opponent.is_a?(Array)
  3927. pbDisplayPaused(_INTL("{1} defeated {2} and {3}!",self.pbPlayer.name,@opponent[0].fullname,@opponent[1].fullname))
  3928. else
  3929. pbDisplayPaused(_INTL("{1} defeated\r\n{2}!",self.pbPlayer.name,@opponent.fullname))
  3930. end
  3931. @scene.pbShowOpponent(0)
  3932. pbDisplayPaused(@endspeech.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
  3933. if @opponent.is_a?(Array)
  3934. @scene.pbHideOpponent
  3935. @scene.pbShowOpponent(1)
  3936. pbDisplayPaused(@endspeech2.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
  3937. end
  3938. # Calculate money gained for winning
  3939. if @internalbattle
  3940. tmoney=0
  3941. if @opponent.is_a?(Array) # Double battles
  3942. maxlevel1=0; maxlevel2=0; limit=pbSecondPartyBegin(1)
  3943. for i in 0...limit
  3944. if @party2[i]
  3945. maxlevel1=@party2[i].level if maxlevel1<@party2[i].level
  3946. end
  3947. if @party2[i+limit]
  3948. maxlevel2=@party2[i+limit].level if maxlevel1<@party2[i+limit].level
  3949. end
  3950. end
  3951. tmoney+=maxlevel1*@opponent[0].moneyEarned
  3952. tmoney+=maxlevel2*@opponent[1].moneyEarned
  3953. else
  3954. maxlevel=0
  3955. for i in @party2
  3956. next if !i
  3957. maxlevel=i.level if maxlevel<i.level
  3958. end
  3959. tmoney+=maxlevel*@opponent.moneyEarned
  3960. end
  3961. # If Amulet Coin/Luck Incense's effect applies, double money earned
  3962. tmoney*=2 if @amuletcoin
  3963. # If Happy Hour's effect applies, double money earned
  3964. tmoney*=2 if @doublemoney
  3965. oldmoney=self.pbPlayer.money
  3966. self.pbPlayer.money+=tmoney
  3967. moneygained=self.pbPlayer.money-oldmoney
  3968. if moneygained>0
  3969. pbDisplayPaused(_INTL("{1} got ${2}\r\nfor winning!",self.pbPlayer.name,pbCommaNumber(tmoney)))
  3970. end
  3971. end
  3972. end
  3973. if @internalbattle && @extramoney>0
  3974. @extramoney*=2 if @amuletcoin
  3975. @extramoney*=2 if @doublemoney
  3976. oldmoney=self.pbPlayer.money
  3977. self.pbPlayer.money+=@extramoney
  3978. moneygained=self.pbPlayer.money-oldmoney
  3979. if moneygained>0
  3980. pbDisplayPaused(_INTL("{1} picked up ${2}!",self.pbPlayer.name,pbCommaNumber(@extramoney)))
  3981. end
  3982. end
  3983. for pkmn in @snaggedpokemon
  3984. pbStorePokemon(pkmn)
  3985. self.pbPlayer.shadowcaught=[] if !self.pbPlayer.shadowcaught
  3986. self.pbPlayer.shadowcaught[pkmn.species]=true
  3987. end
  3988. @snaggedpokemon.clear
  3989. ##### LOSE, DRAW #####
  3990. when 2, 5
  3991. PBDebug.log("")
  3992. PBDebug.log("***Player lost***") if @decision==2
  3993. PBDebug.log("***Player drew with opponent***") if @decision==5
  3994. if @internalbattle
  3995. moneylost=pbMaxLevelFromIndex(0) # Player's Pokémon only, not partner's
  3996. multiplier=[8,16,24,36,48,64,80,100,120]
  3997. moneylost*=multiplier[[multiplier.length-1,self.pbPlayer.numbadges].min]
  3998. moneylost=self.pbPlayer.money if moneylost>self.pbPlayer.money
  3999. moneylost=0 if $game_switches[NO_MONEY_LOSS]
  4000. oldmoney=self.pbPlayer.money
  4001. self.pbPlayer.money-=moneylost
  4002. lostmoney=oldmoney-self.pbPlayer.money
  4003. if @opponent
  4004. if @opponent.is_a?(Array)
  4005. pbDisplayPaused(_INTL("You lost against {1} and {2}!",@opponent[0].fullname,@opponent[1].fullname))
  4006. else
  4007. pbDisplayPaused(_INTL("You lost against\r\n{1}!",@opponent.fullname))
  4008. end
  4009. if moneylost>0
  4010. pbDisplayPaused(_INTL("You gave ${1} to the winner...",pbCommaNumber(lostmoney)))
  4011. end
  4012. else
  4013. pbDisplayPaused(_INTL("You have no more Pokémon that can fight!"))
  4014. if moneylost>0
  4015. pbDisplayPaused(_INTL("You panicked and dropped\r\n${1}...",pbCommaNumber(lostmoney)))
  4016. end
  4017. end
  4018. pbDisplayPaused(_INTL("You blacked out!")) if !canlose
  4019. elsif @decision==2
  4020. @scene.pbShowOpponent(0)
  4021. pbDisplayPaused(@endspeechwin.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
  4022. if @opponent.is_a?(Array)
  4023. @scene.pbHideOpponent
  4024. @scene.pbShowOpponent(1)
  4025. pbDisplayPaused(@endspeechwin2.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
  4026. end
  4027. end
  4028. end
  4029. # Pass on Pokérus within the party
  4030. infected=[]
  4031. for i in 0...$Trainer.party.length
  4032. if $Trainer.party[i].pokerusStage==1
  4033. infected.push(i)
  4034. end
  4035. end
  4036. if infected.length>=1
  4037. for i in infected
  4038. strain=$Trainer.party[i].pokerusStrain
  4039. if i>0 && $Trainer.party[i-1].pokerusStage==0
  4040. $Trainer.party[i-1].givePokerus(strain) if rand(3)==0
  4041. end
  4042. if i<$Trainer.party.length-1 && $Trainer.party[i+1].pokerusStage==0
  4043. $Trainer.party[i+1].givePokerus(strain) if rand(3)==0
  4044. end
  4045. end
  4046. end
  4047. @scene.pbEndBattle(@decision)
  4048. for i in @battlers
  4049. i.pbResetForm
  4050. if i.hasWorkingAbility(:NATURALCURE)
  4051. i.status=0
  4052. end
  4053. end
  4054. for i in $Trainer.party
  4055. i.setItem(i.itemInitial)
  4056. i.itemInitial=i.itemRecycle=0
  4057. i.belch=false
  4058. end
  4059. return @decision
  4060. end
  4061. end
Add Comment
Please, Sign In to add comment