Advertisement
Guest User

Untitled

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