Advertisement
Guest User

Untitled

a guest
Nov 4th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 188.95 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. # Battle Peer.
  10. ################################################################################
  11. class PokeBattle_NullBattlePeer
  12. def pbStorePokemon(player,pokemon)
  13. if player.party.length<6
  14. player.party[player.party.length]=pokemon
  15. else
  16. return -1
  17. end
  18. end
  19.  
  20. def pbOnEnteringBattle(battle,pokemon)
  21. end
  22.  
  23. def pbGetStorageCreator()
  24. return nil
  25. end
  26.  
  27. def pbCurrentBox()
  28. return -1
  29. end
  30.  
  31. def pbBoxName(box)
  32. return ""
  33. end
  34. end
  35.  
  36.  
  37.  
  38. class PokeBattle_BattlePeer
  39. def self.create
  40. return PokeBattle_NullBattlePeer.new()
  41. end
  42. end
  43.  
  44.  
  45.  
  46. ################################################################################
  47. # Success State.
  48. ################################################################################
  49. class PokeBattle_SuccessState
  50. attr_accessor :typemod
  51. attr_accessor :useState # 0 - not used, 1 - failed, 2 - succeeded
  52. attr_accessor :protected
  53. attr_accessor :skill # Used in Battle Arena
  54.  
  55. def initialize
  56. clear
  57. end
  58.  
  59. def clear
  60. @typemod=4
  61. @useState=0
  62. @protected=false
  63. @skill=0
  64. end
  65.  
  66. def updateSkill
  67. if @useState==1 && !@protected
  68. @skill-=2
  69. elsif @useState==2
  70. if @typemod>4
  71. @skill+=2 # "Super effective"
  72. elsif @typemod>=1 && @typemod<4
  73. @skill-=1 # "Not very effective"
  74. elsif @typemod==0
  75. @skill-=2 # Ineffective
  76. else
  77. @skill+=1
  78. end
  79. end
  80. @typemod=4
  81. @useState=0
  82. @protected=false
  83. end
  84. end
  85.  
  86.  
  87.  
  88. ################################################################################
  89. # Catching and storing Pokémon.
  90. ################################################################################
  91. module PokeBattle_BattleCommon
  92. def pbStorePokemon(pokemon)
  93. if !(pokemon.isShadow? rescue false)
  94. if pbDisplayConfirm(_INTL("Would you like to give a nickname to {1}?",pokemon.name))
  95. species=PBSpecies.getName(pokemon.species)
  96. nickname=@scene.pbNameEntry(_INTL("{1}'s nickname?",species),pokemon)
  97. pokemon.name=nickname if nickname!=""
  98. end
  99. end
  100. oldcurbox=@peer.pbCurrentBox()
  101. storedbox=@peer.pbStorePokemon(self.pbPlayer,pokemon)
  102. creator=@peer.pbGetStorageCreator()
  103. return if storedbox<0
  104. curboxname=@peer.pbBoxName(oldcurbox)
  105. boxname=@peer.pbBoxName(storedbox)
  106. if storedbox!=oldcurbox
  107. if creator
  108. pbDisplayPaused(_INTL("Box \"{1}\" on {2}'s PC was full.",curboxname,creator))
  109. else
  110. pbDisplayPaused(_INTL("Box \"{1}\" on someone's PC was full.",curboxname))
  111. end
  112. pbDisplayPaused(_INTL("{1} was transferred to box \"{2}\".",pokemon.name,boxname))
  113. else
  114. if creator
  115. pbDisplayPaused(_INTL("{1} was transferred to {2}'s PC.",pokemon.name,creator))
  116. else
  117. pbDisplayPaused(_INTL("{1} was transferred to someone's PC.",pokemon.name))
  118. end
  119. pbDisplayPaused(_INTL("It was stored in box \"{1}\".",boxname))
  120. end
  121. end
  122.  
  123. def pbThrowPokeBall(idxPokemon,ball,rareness=nil,showplayer=false)
  124. itemname=PBItems.getName(ball)
  125. battler=nil
  126. if pbIsOpposing?(idxPokemon)
  127. battler=self.battlers[idxPokemon]
  128. else
  129. battler=self.battlers[idxPokemon].pbOppositeOpposing
  130. end
  131. if battler.isFainted?
  132. battler=battler.pbPartner
  133. end
  134. pbDisplayBrief(_INTL("{1} threw one {2}!",self.pbPlayer.name,itemname))
  135. if battler.isFainted?
  136. pbDisplay(_INTL("But there was no target..."))
  137. return
  138. end
  139. if @opponent && !pbIsSnagBall?(ball)
  140. @scene.pbThrowAndDeflect(ball,1)
  141. if $game_switches[290]==false
  142. pbDisplay(_INTL("The Trainer blocked the Ball!\nDon't be a thief!"))
  143. else
  144. pbDisplay(_INTL("The Pokémon knocked the ball away!"))
  145. end
  146. else
  147. if $game_switches[290]==true
  148. pbDisplay(_INTL("The Pokémon knocked the ball away!"))
  149. return
  150. end
  151. pokemon=battler.pokemon
  152. species=pokemon.species
  153. if $DEBUG && Input.press?(Input::CTRL)
  154. shakes=4
  155. else
  156. if !rareness
  157. dexdata=pbOpenDexData
  158. pbDexDataOffset(dexdata,species,16)
  159. rareness=dexdata.fgetb # Get rareness from dexdata file
  160. dexdata.close
  161. end
  162. a=battler.totalhp
  163. b=battler.hp
  164. rareness=BallHandlers.modifyCatchRate(ball,rareness,self,battler)
  165. x=(((a*3-b*2)*rareness)/(a*3)).floor
  166. if battler.status==PBStatuses::SLEEP || battler.status==PBStatuses::FROZEN
  167. x*=2
  168. elsif battler.status!=0
  169. x=(x*3/2).floor
  170. end
  171. shakes=0
  172. if x>255 || BallHandlers.isUnconditional?(ball,self,battler)
  173. shakes=4
  174. else
  175. x=1 if x==0
  176. y = 0x000FFFF0 / (Math.sqrt(Math.sqrt( 0x00FF0000/x ) ) )
  177. shakes+=1 if pbRandom(65536)<y
  178. shakes+=1 if pbRandom(65536)<y
  179. shakes+=1 if pbRandom(65536)<y
  180. shakes+=1 if pbRandom(65536)<y
  181. end
  182. end
  183. @scene.pbThrow(ball,shakes,battler.index,showplayer)
  184. case shakes
  185. when 0
  186. pbDisplay(_INTL("Oh no! The Pokémon broke free!"))
  187. BallHandlers.onFailCatch(ball,self,pokemon)
  188. when 1
  189. pbDisplay(_INTL("Aww... It appeared to be caught!"))
  190. BallHandlers.onFailCatch(ball,self,pokemon)
  191. when 2
  192. pbDisplay(_INTL("Aargh! Almost had it!"))
  193. BallHandlers.onFailCatch(ball,self,pokemon)
  194. when 3
  195. pbDisplay(_INTL("Shoot! It was so close, too!"))
  196. BallHandlers.onFailCatch(ball,self,pokemon)
  197. when 4
  198. pbDisplayBrief(_INTL("Gotcha! {1} was caught!",pokemon.name))
  199. @scene.pbThrowSuccess
  200. if pbIsSnagBall?(ball) && @opponent
  201. pbRemoveFromParty(battler.index,battler.pokemonIndex)
  202. battler.pbReset
  203. battler.participants=[]
  204. else
  205. @decision=4
  206. end
  207. if pbIsSnagBall?(ball)
  208. pokemon.ot=self.pbPlayer.name
  209. pokemon.trainerID=self.pbPlayer.id
  210. end
  211. BallHandlers.onCatch(ball,self,pokemon)
  212. pokemon.ballused=pbGetBallType(ball)
  213. pokemon.pbRecordFirstMoves
  214. if !self.pbPlayer.owned[species]
  215. self.pbPlayer.owned[species]=true
  216. if $Trainer.pokedex
  217. pbDisplayPaused(_INTL("{1}'s data was added to the Pokédex.",pokemon.name))
  218. @scene.pbShowPokedex(species)
  219. end
  220. end
  221. @scene.pbHideCaptureBall
  222. if pbIsSnagBall?(ball) && @opponent
  223. pokemon.pbUpdateShadowMoves rescue nil
  224. @snaggedpokemon.push(pokemon)
  225. else
  226. pbStorePokemon(pokemon)
  227. end
  228. end
  229. end
  230. end
  231. end
  232.  
  233.  
  234.  
  235. ################################################################################
  236. # Main battle class.
  237. ################################################################################
  238. class PokeBattle_Battle
  239. attr_reader(:scene) # Scene object for this battle
  240. attr_accessor(:decision) # Decision: 0=undecided; 1=win; 2=loss; 3=escaped; 4=caught
  241. attr_accessor(:internalbattle) # Internal battle flag
  242. attr_accessor(:doublebattle) # Double battle flag
  243. attr_accessor(:cantescape) # True if player can't escape
  244. attr_accessor(:shiftStyle) # Shift/Set "battle style" option
  245. attr_accessor(:battlescene) # "Battle scene" option
  246. attr_accessor(:debug) # Debug flag
  247. attr_reader(:player) # Player trainer
  248. attr_reader(:opponent) # Opponent trainer
  249. attr_reader(:party1) # Player's Pokémon party
  250. attr_reader(:party2) # Foe's Pokémon party
  251. attr_reader(:partyorder) # Order of Pokémon in the player's party
  252. attr_accessor(:fullparty1) # True if player's party's max size is 6 instead of 3
  253. attr_accessor(:fullparty2) # True if opponent's party's max size is 6 instead of 3
  254. attr_reader(:battlers) # Currently active Pokémon
  255. attr_accessor(:items) # Items held by opponents
  256. attr_reader(:sides) # Effects common to each side of a battle
  257. attr_reader(:field) # Effects common to the whole of a battle
  258. attr_accessor(:environment) # Battle surroundings
  259. attr_accessor(:weather) # Current weather, custom methods should use pbWeather instead
  260. attr_accessor(:weatherduration) # Duration of current weather, or -1 if indefinite
  261. attr_reader(:switching) # True if during the switching phase of the round
  262. attr_reader(:struggle) # The Struggle move
  263. attr_accessor(:choices) # Choices made by each Pokémon this round
  264. attr_reader(:successStates) # Success states
  265. attr_accessor(:lastMoveUsed) # Last move used
  266. attr_accessor(:lastMoveUser) # Last move user
  267. attr_accessor(:synchronize) # Synchronize state
  268. attr_accessor(:megaEvolution) # Battle index of each trainer's Pokémon to Mega Evolve
  269. attr_accessor(:amuletcoin) # Whether Amulet Coin's effect applies
  270. attr_accessor(:extramoney) # Money gained in battle by using Pay Day
  271. attr_accessor(:endspeech) # Speech by opponent when player wins
  272. attr_accessor(:endspeech2) # Speech by opponent when player wins
  273. attr_accessor(:endspeechwin) # Speech by opponent when opponent wins
  274. attr_accessor(:endspeechwin2) # Speech by opponent when opponent wins
  275. attr_accessor(:trickroom)
  276. #### KUROTSUNE - 015 - START
  277. attr_accessor(:switchedOut)
  278. #### KUROTSUNE - 015 - END
  279. attr_accessor(:previousMove) # Move used directly previously
  280. attr_accessor(:rules)
  281. attr_reader(:turncount)
  282. attr_accessor :controlPlayer
  283. include PokeBattle_BattleCommon
  284.  
  285. MAXPARTYSIZE = 6
  286.  
  287. class BattleAbortedException < Exception; end
  288.  
  289. def pbAbort
  290. raise BattleAbortedException.new("Battle aborted")
  291. end
  292.  
  293. def pbDebugUpdate
  294. end
  295.  
  296. def pbRandom(x)
  297. return rand(x)
  298. end
  299.  
  300. def pbAIRandom(x)
  301. return rand(x)
  302. end
  303.  
  304. ################################################################################
  305. # Initialise battle class.
  306. ################################################################################
  307. def initialize(scene,p1,p2,player,opponent)
  308. if p1.length==0
  309. raise ArgumentError.new(_INTL("Party 1 has no Pokémon."))
  310. return
  311. end
  312. if p2.length==0
  313. raise ArgumentError.new(_INTL("Party 2 has no Pokémon."))
  314. return
  315. end
  316. if p2.length>2 && !opponent
  317. raise ArgumentError.new(_INTL("Wild battles with more than two Pokémon are not allowed."))
  318. return
  319. end
  320. @scene = scene
  321. @decision = 0
  322. @internalbattle = true
  323. @doublebattle = false
  324. @cantescape = false
  325. @shiftStyle = true
  326. @battlescene = true
  327. @debug = false
  328. @debugupdate = 0
  329. if opponent && player.is_a?(Array) && player.length==0
  330. player = player[0]
  331. end
  332. if opponent && opponent.is_a?(Array) && opponent.length==0
  333. opponent = opponent[0]
  334. end
  335. @player = player # PokeBattle_Trainer object
  336. @opponent = opponent # PokeBattle_Trainer object
  337. @party1 = p1
  338. @party2 = p2
  339. @partyorder = []
  340. for i in 0...6; @partyorder.push(i); end
  341. @fullparty1 = false
  342. @fullparty2 = false
  343. @battlers = []
  344. @items = nil
  345. @sides = [PokeBattle_ActiveSide.new, # Player's side
  346. PokeBattle_ActiveSide.new] # Foe's side
  347. @field = PokeBattle_ActiveField.new # Whole field (gravity/rooms)
  348. @environment = PBEnvironment::None # e.g. Tall grass, cave, still water
  349. @weather = 0
  350. @weatherduration = 0
  351. @switching = false
  352. @choices = [ [0,0,nil,-1],[0,0,nil,-1],[0,0,nil,-1],[0,0,nil,-1] ]
  353. @successStates = []
  354. for i in 0...4
  355. @successStates.push(PokeBattle_SuccessState.new)
  356. end
  357. @lastMoveUsed = -1
  358. @lastMoveUser = -1
  359. @synchronize = [-1,-1,0]
  360. @megaEvolution = []
  361. if @player.is_a?(Array)
  362. @megaEvolution[0]=[-1]*@player.length
  363. else
  364. @megaEvolution[0]=[-1]
  365. end
  366. if @opponent.is_a?(Array)
  367. @megaEvolution[1]=[-1]*@opponent.length
  368. else
  369. @megaEvolution[1]=[-1]
  370. end
  371. @amuletcoin = false
  372. #### KUROTSUNE - 015 - START
  373. @switchedOut = []
  374. #### KUROTSUNE - 015 - END
  375. @extramoney = 0
  376. @endspeech = ""
  377. @endspeech2 = ""
  378. @endspeechwin = ""
  379. @endspeechwin2 = ""
  380. @rules = {}
  381. @turncount = 0
  382. @peer = PokeBattle_BattlePeer.create()
  383. @trickroom = 0
  384. @priority = []
  385. @usepriority = false
  386. @snaggedpokemon = []
  387. @runCommand = 0
  388. if hasConst?(PBMoves,:STRUGGLE)
  389. @struggle = PokeBattle_Move.pbFromPBMove(self,PBMove.new(getConst(PBMoves,:STRUGGLE)))
  390. else
  391. @struggle = PokeBattle_Struggle.new(self,nil)
  392. end
  393. @struggle.pp = -1
  394. for i in 0...4
  395. battlers[i] = PokeBattle_Battler.new(self,i)
  396. end
  397. for i in @party1
  398. next if !i
  399. i.itemRecycle = 0
  400. i.itemInitial = i.item
  401. end
  402. for i in @party2
  403. next if !i
  404. i.itemRecycle = 0
  405. i.itemInitial = i.item
  406. end
  407. end
  408.  
  409. ################################################################################
  410. # Info about battle.
  411. ################################################################################
  412. def pbIsWild?
  413. return !@opponent? true : false
  414. end
  415.  
  416. def pbDoubleBattleAllowed?
  417. if !@fullparty1 && @party1.length>MAXPARTYSIZE
  418. return false
  419. end
  420. if !@fullparty2 && @party2.length>MAXPARTYSIZE
  421. return false
  422. end
  423. _opponent=@opponent
  424. _player=@player
  425. if !_opponent
  426. if @party2.length==1
  427. return false
  428. elsif @party2.length==2
  429. return true
  430. else
  431. return false
  432. end
  433. else
  434. if _opponent.is_a?(Array)
  435. if _opponent.length==1
  436. _opponent=_opponent[0]
  437. elsif _opponent.length!=2
  438. return false
  439. end
  440. end
  441. _player=_player
  442. if _player.is_a?(Array)
  443. if _player.length==1
  444. _player=_player[0]
  445. elsif _player.length!=2
  446. return false
  447. end
  448. end
  449. if _opponent.is_a?(Array)
  450. sendout1=pbFindNextUnfainted(@party2,0,pbSecondPartyBegin(1))
  451. sendout2=pbFindNextUnfainted(@party2,pbSecondPartyBegin(1))
  452. return false if sendout1<0 || sendout2<0
  453. else
  454. sendout1=pbFindNextUnfainted(@party2,0)
  455. sendout2=pbFindNextUnfainted(@party2,sendout1+1)
  456. return false if sendout1<0 || sendout2<0
  457. end
  458. end
  459. if _player.is_a?(Array)
  460. sendout1=pbFindNextUnfainted(@party1,0,pbSecondPartyBegin(0))
  461. sendout2=pbFindNextUnfainted(@party1,pbSecondPartyBegin(0))
  462. return false if sendout1<0 || sendout2<0
  463. else
  464. sendout1=pbFindNextUnfainted(@party1,0)
  465. sendout2=pbFindNextUnfainted(@party1,sendout1+1)
  466. return false if sendout1<0 || sendout2<0
  467. end
  468. return true
  469. end
  470.  
  471. def pbCheckSideAbility(a,pkmn) #checks to see if your side has a pokemon with a certain ability.
  472. for i in 0...4 # in order from own first, opposing first, own second, opposing second
  473. if @battlers[i].hasWorkingAbility(a)
  474. if @battlers[i]==pkmn || @battlers[i]==pkmn.pbPartner
  475. return @battlers[i]
  476. end
  477. end
  478. end
  479. return nil
  480. end
  481.  
  482. def pbWeather
  483. for i in 0...4
  484. if @battlers[i].hasWorkingAbility(:CLOUDNINE) ||
  485. @battlers[i].hasWorkingAbility(:AIRLOCK) ||
  486. $fefieldeffect == 22
  487. return 0
  488. end
  489. end
  490. return @weather
  491. end
  492.  
  493. ################################################################################
  494. # Get battler info.
  495. ################################################################################
  496. def pbIsOpposing?(index)
  497. return (index%2)==1
  498. end
  499.  
  500. def pbOwnedByPlayer?(index)
  501. return false if pbIsOpposing?(index)
  502. return false if @player.is_a?(Array) && index==2
  503. return true
  504. end
  505.  
  506. def pbIsDoubleBattler?(index)
  507. return (index>=2)
  508. end
  509.  
  510. def pbThisEx(battlerindex,pokemonindex)
  511. party=pbParty(battlerindex)
  512. if pbIsOpposing?(battlerindex)
  513. if @opponent
  514. return _INTL("The foe {1}",party[pokemonindex].name)
  515. else
  516. return _INTL("The wild {1}",party[pokemonindex].name)
  517. end
  518. else
  519. return _INTL("{1}",party[pokemonindex].name)
  520. end
  521. end
  522.  
  523. # Checks whether an item can be removed from a Pokémon.
  524. def pbIsUnlosableItem(pkmn,item)
  525. return true if pbIsMail?(item)
  526. return false if pkmn.effects[PBEffects::Transform]
  527. if isConst?(pkmn.ability,PBAbilities,:MULTITYPE) &&
  528. (isConst?(item,PBItems,:FISTPLATE) ||
  529. isConst?(item,PBItems,:SKYPLATE) ||
  530. isConst?(item,PBItems,:TOXICPLATE) ||
  531. isConst?(item,PBItems,:EARTHPLATE) ||
  532. isConst?(item,PBItems,:STONEPLATE) ||
  533. isConst?(item,PBItems,:INSECTPLATE) ||
  534. isConst?(item,PBItems,:SPOOKYPLATE) ||
  535. isConst?(item,PBItems,:IRONPLATE) ||
  536. isConst?(item,PBItems,:FLAMEPLATE) ||
  537. isConst?(item,PBItems,:SPLASHPLATE) ||
  538. isConst?(item,PBItems,:MEADOWPLATE) ||
  539. isConst?(item,PBItems,:ZAPPLATE) ||
  540. isConst?(item,PBItems,:MINDPLATE) ||
  541. isConst?(item,PBItems,:ICICLEPLATE) ||
  542. isConst?(item,PBItems,:DRACOPLATE) ||
  543. isConst?(item,PBItems,:PIXIEPLATE) ||
  544. isConst?(item,PBItems,:DREADPLATE))
  545. return true
  546. end
  547. if isConst?(pkmn.species,PBSpecies,:GIRATINA) &&
  548. isConst?(item,PBItems,:GRISEOUSORB)
  549. return true
  550. end
  551. if isConst?(pkmn.species,PBSpecies,:GENESECT) &&
  552. (isConst?(item,PBItems,:SHOCKDRIVE) ||
  553. isConst?(item,PBItems,:BURNDRIVE) ||
  554. isConst?(item,PBItems,:CHILLDRIVE) ||
  555. isConst?(item,PBItems,:DOUSEDRIVE))
  556. return true
  557. end
  558. if isConst?(pkmn.species,PBSpecies,:VENUSAUR) &&
  559. isConst?(item,PBItems,:VENUSAURITE)
  560. return true
  561. end
  562. if isConst?(pkmn.species,PBSpecies,:CHARIZARD) &&
  563. (isConst?(item,PBItems,:CHARIZARDITEX) ||
  564. isConst?(item,PBItems,:CHARIZARDITEY))
  565. return true
  566. end
  567. if isConst?(pkmn.species,PBSpecies,:BLASTOISE) &&
  568. isConst?(item,PBItems,:BLASTOISINITE)
  569. return true
  570. end
  571. if isConst?(pkmn.species,PBSpecies,:ABOMBASNOW) &&
  572. isConst?(item,PBItems,:ABOMASITE)
  573. return true
  574. end
  575. if isConst?(pkmn.species,PBSpecies,:ABSOL) &&
  576. isConst?(item,PBItems,:ABSOLITE)
  577. return true
  578. end
  579. if isConst?(pkmn.species,PBSpecies,:AERODACTYL) &&
  580. isConst?(item,PBItems,:AERODACTYLITE)
  581. return true
  582. end
  583. if isConst?(pkmn.species,PBSpecies,:AGGRON) &&
  584. isConst?(item,PBItems,:AGGRONITE)
  585. return true
  586. end
  587. if isConst?(pkmn.species,PBSpecies,:ALAKAZAM) &&
  588. isConst?(item,PBItems,:ALAKAZITE)
  589. return true
  590. end
  591. if isConst?(pkmn.species,PBSpecies,:AMPHAROS) &&
  592. isConst?(item,PBItems,:AMPHAROSITE)
  593. return true
  594. end
  595. if isConst?(pkmn.species,PBSpecies,:BANETTE) &&
  596. isConst?(item,PBItems,:BANETTITITE)
  597. return true
  598. end
  599. if isConst?(pkmn.species,PBSpecies,:BLAZIKEN) &&
  600. isConst?(item,PBItems,:BLAZIKENITE)
  601. return true
  602. end
  603. if isConst?(pkmn.species,PBSpecies,:GARCHOMP) &&
  604. isConst?(item,PBItems,:GARCHOMPITE)
  605. return true
  606. end
  607. if isConst?(pkmn.species,PBSpecies,:GARDEVOIR) &&
  608. isConst?(item,PBItems,:GARDEVOIRITE)
  609. return true
  610. end
  611. if isConst?(pkmn.species,PBSpecies,:GENGAR) &&
  612. isConst?(item,PBItems,:GENGARITE)
  613. return true
  614. end
  615. if isConst?(pkmn.species,PBSpecies,:GYARADOS) &&
  616. isConst?(item,PBItems,:GYARADOSITE)
  617. return true
  618. end
  619. if isConst?(pkmn.species,PBSpecies,:HERACROSS) &&
  620. isConst?(item,PBItems,:HERACROSSITE)
  621. return true
  622. end
  623. if isConst?(pkmn.species,PBSpecies,:HOUNDOOM) &&
  624. isConst?(item,PBItems,:HOUNDOOMITE)
  625. return true
  626. end
  627. if isConst?(pkmn.species,PBSpecies,:KANGASKHAN) &&
  628. isConst?(item,PBItems,:KANGASKHANITE)
  629. return true
  630. end
  631. if isConst?(pkmn.species,PBSpecies,:LUCARIO) &&
  632. isConst?(item,PBItems,:LUCARIONITE)
  633. return true
  634. end
  635. if isConst?(pkmn.species,PBSpecies,:MANECTRIC) &&
  636. isConst?(item,PBItems,:MANECTITE)
  637. return true
  638. end
  639. if isConst?(pkmn.species,PBSpecies,:MAWILE) &&
  640. isConst?(item,PBItems,:MAWILITE)
  641. return true
  642. end
  643. if isConst?(pkmn.species,PBSpecies,:MEDICHAM) &&
  644. isConst?(item,PBItems,:MEDICHAMITE)
  645. return true
  646. end
  647. if isConst?(pkmn.species,PBSpecies,:MEWTWO) &&
  648. (isConst?(item,PBItems,:MEWTWONITEX) ||
  649. isConst?(item,PBItems,:MEWTWONITEY))
  650. return true
  651. end
  652. if isConst?(pkmn.species,PBSpecies,:PINSIR) &&
  653. isConst?(item,PBItems,:PINSIRITE)
  654. return true
  655. end
  656. if isConst?(pkmn.species,PBSpecies,:SCIZOR) &&
  657. isConst?(item,PBItems,:SCIZORITE)
  658. return true
  659. end
  660. if isConst?(pkmn.species,PBSpecies,:TYRANITAR) &&
  661. isConst?(item,PBItems,:TYRANITARITE)
  662. return true
  663. end
  664. if isConst?(pkmn.species,PBSpecies,:BEEDRILL) &&
  665. isConst?(item,PBItems,:BEEDRILLITE)
  666. return true
  667. end
  668. if isConst?(pkmn.species,PBSpecies,:PIDGEOT) &&
  669. isConst?(item,PBItems,:PIDGEOTITE)
  670. return true
  671. end
  672. if isConst?(pkmn.species,PBSpecies,:SLOWBRO) &&
  673. isConst?(item,PBItems,:SLOWBRONITE)
  674. return true
  675. end
  676. if isConst?(pkmn.species,PBSpecies,:STEELIX) &&
  677. isConst?(item,PBItems,:STEELIXITE)
  678. return true
  679. end
  680. if isConst?(pkmn.species,PBSpecies,:SCEPTILE) &&
  681. isConst?(item,PBItems,:SCEPTILITE)
  682. return true
  683. end
  684. if isConst?(pkmn.species,PBSpecies,:SWAMPERT) &&
  685. isConst?(item,PBItems,:SWAMPERTITE)
  686. return true
  687. end
  688. if isConst?(pkmn.species,PBSpecies,:SHARPEDO) &&
  689. isConst?(item,PBItems,:SHARPEDONITE)
  690. return true
  691. end
  692. if isConst?(pkmn.species,PBSpecies,:SABLEYE) &&
  693. isConst?(item,PBItems,:SABLENITE)
  694. return true
  695. end
  696. if isConst?(pkmn.species,PBSpecies,:CAMERUPT) &&
  697. isConst?(item,PBItems,:CAMERUPTITE)
  698. return true
  699. end
  700. if isConst?(pkmn.species,PBSpecies,:ALTARIA) &&
  701. isConst?(item,PBItems,:ALTARIANITE)
  702. return true
  703. end
  704. if isConst?(pkmn.species,PBSpecies,:GLALIE) &&
  705. isConst?(item,PBItems,:GLALITITE)
  706. return true
  707. end
  708. if isConst?(pkmn.species,PBSpecies,:SALAMENCE) &&
  709. isConst?(item,PBItems,:SALAMENCITE)
  710. return true
  711. end
  712. if isConst?(pkmn.species,PBSpecies,:METAGROSS) &&
  713. isConst?(item,PBItems,:METAGROSSITE)
  714. return true
  715. end
  716. if isConst?(pkmn.species,PBSpecies,:LOPUNNY) &&
  717. isConst?(item,PBItems,:LOPUNNITE)
  718. return true
  719. end
  720. if isConst?(pkmn.species,PBSpecies,:GALLADE) &&
  721. isConst?(item,PBItems,:GALLADITE)
  722. return true
  723. end
  724. if isConst?(pkmn.species,PBSpecies,:AUDINO) &&
  725. isConst?(item,PBItems,:AUDINITE)
  726. return true
  727. end
  728. if isConst?(pkmn.species,PBSpecies,:DIANCIE) &&
  729. isConst?(item,PBItems,:DIANCITE)
  730. return true
  731. end
  732. if isConst?(pkmn.species,PBSpecies,:GROUDON) &&
  733. isConst?(item,PBItems,:REDORB)
  734. return true
  735. end
  736. if isConst?(pkmn.species,PBSpecies,:KYOGRE) &&
  737. isConst?(item,PBItems,:BLUEORB)
  738. return true
  739. end
  740. if isConst?(item,PBItems,:PULSEHOLD)
  741. return true
  742. end
  743. return false
  744. end
  745.  
  746.  
  747. def pbCheckGlobalAbility(a)
  748. for i in 0...4 # in order from own first, opposing first, own second, opposing second
  749. if @battlers[i].hasWorkingAbility(a)
  750. return @battlers[i]
  751. end
  752. end
  753. return nil
  754. end
  755.  
  756. ################################################################################
  757. # Player-related info.
  758. ################################################################################
  759. def pbPlayer
  760. if @player.is_a?(Array)
  761. return @player[0]
  762. else
  763. return @player
  764. end
  765. end
  766.  
  767. def pbGetOwnerItems(battlerIndex)
  768. return [] if !@items
  769. if pbIsOpposing?(battlerIndex)
  770. if @opponent.is_a?(Array)
  771. return (battlerIndex==1) ? @items[0] : @items[1]
  772. else
  773. return @items
  774. end
  775. else
  776. return []
  777. end
  778. end
  779.  
  780. def pbSetSeen(pokemon)
  781. if pokemon && @internalbattle
  782. self.pbPlayer.seen[pokemon.species]=true
  783. pbSeenForm(pokemon)
  784. end
  785. end
  786.  
  787. ################################################################################
  788. # Get party info, manipulate parties.
  789. ################################################################################
  790. def pbPokemonCount(party)
  791. count=0
  792. for i in party
  793. next if !i
  794. count+=1 if i.hp>0 && !i.isEgg?
  795. end
  796. return count
  797. end
  798.  
  799. def pbAllFainted?(party)
  800. pbPokemonCount(party)==0
  801. end
  802.  
  803. def pbMaxLevel(party)
  804. lv=0
  805. for i in party
  806. next if !i
  807. lv=i.level if lv<i.level
  808. end
  809. return lv
  810. end
  811.  
  812. def pbParty(index)
  813. return pbIsOpposing?(index) ? party2 : party1
  814. end
  815.  
  816. def pbSecondPartyBegin(battlerIndex)
  817. if pbIsOpposing?(battlerIndex)
  818. return @fullparty2 ? 6 : 3
  819. else
  820. return @fullparty1 ? 6 : 3
  821. end
  822. end
  823.  
  824. def pbFindNextUnfainted(party,start,finish=-1)
  825. finish=party.length if finish<0
  826. for i in start...finish
  827. next if !party[i]
  828. return i if party[i].hp>0 && !party[i].isEgg?
  829. end
  830. return -1
  831. end
  832.  
  833. def pbFindPlayerBattler(pkmnIndex)
  834. battler=nil
  835. for k in 0...4
  836. if !pbIsOpposing?(k) && @battlers[k].pokemonIndex==pkmnIndex
  837. battler=@battlers[k]
  838. break
  839. end
  840. end
  841. return battler
  842. end
  843.  
  844. def pbIsOwner?(battlerIndex,partyIndex)
  845. secondParty=pbSecondPartyBegin(battlerIndex)
  846. if !pbIsOpposing?(battlerIndex)
  847. return true if !@player || !@player.is_a?(Array)
  848. return (battlerIndex==0) ? partyIndex<secondParty : partyIndex>=secondParty
  849. else
  850. return true if !@opponent || !@opponent.is_a?(Array)
  851. return (battlerIndex==1) ? partyIndex<secondParty : partyIndex>=secondParty
  852. end
  853. end
  854.  
  855. def pbGetOwner(battlerIndex)
  856. if pbIsOpposing?(battlerIndex)
  857. if @opponent.is_a?(Array)
  858. return (battlerIndex==1) ? @opponent[0] : @opponent[1]
  859. else
  860. return @opponent
  861. end
  862. else
  863. if @player.is_a?(Array)
  864. return (battlerIndex==0) ? @player[0] : @player[1]
  865. else
  866. return @player
  867. end
  868. end
  869. end
  870.  
  871. def pbGetOwnerPartner(battlerIndex)
  872. if pbIsOpposing?(battlerIndex)
  873. if @opponent.is_a?(Array)
  874. return (battlerIndex==1) ? @opponent[1] : @opponent[0]
  875. else
  876. return @opponent
  877. end
  878. else
  879. if @player.is_a?(Array)
  880. return (battlerIndex==0) ? @player[1] : @player[0]
  881. else
  882. return @player
  883. end
  884. end
  885. end
  886.  
  887. def pbGetOwnerIndex(battlerIndex)
  888. if pbIsOpposing?(battlerIndex)
  889. return (@opponent.is_a?(Array)) ? ((battlerIndex==1) ? 0 : 1) : 0
  890. else
  891. return (@player.is_a?(Array)) ? ((battlerIndex==0) ? 0 : 1) : 0
  892. end
  893. end
  894.  
  895. def pbBelongsToPlayer?(battlerIndex)
  896. if @player.is_a?(Array) && @player.length>1
  897. return battlerIndex==0
  898. else
  899. return (battlerIndex%2)==0
  900. end
  901. return false
  902. end
  903.  
  904. def pbPartyGetOwner(battlerIndex,partyIndex)
  905. secondParty=pbSecondPartyBegin(battlerIndex)
  906. if !pbIsOpposing?(battlerIndex)
  907. return @player if !@player || !@player.is_a?(Array)
  908. return (partyIndex<secondParty) ? @player[0] : @player[1]
  909. else
  910. return @opponent if !@opponent || !@opponent.is_a?(Array)
  911. return (partyIndex<secondParty) ? @opponent[0] : @opponent[1]
  912. end
  913. end
  914.  
  915. def pbAddToPlayerParty(pokemon)
  916. party=pbParty(0)
  917. for i in 0...party.length
  918. party[i]=pokemon if pbIsOwner?(0,i) && !party[i]
  919. end
  920. end
  921.  
  922. def pbRemoveFromParty(battlerIndex,partyIndex)
  923. party=pbParty(battlerIndex)
  924. side=(pbIsOpposing?(battlerIndex)) ? @opponent : @player
  925. party[partyIndex]=nil
  926. if !side || !side.is_a?(Array) # Wild or single opponent
  927. party.compact!
  928. for i in battlerIndex...party.length
  929. for j in 0..3
  930. next if !@battlers[j]
  931. if pbGetOwner(j)==side && @battlers[j].pokemonIndex==i
  932. @battlers[j].pokemonIndex-=1
  933. break
  934. end
  935. end
  936. end
  937. else
  938. if battlerIndex<pbSecondPartyBegin(battlerIndex)-1
  939. for i in battlerIndex...pbSecondPartyBegin(battlerIndex)
  940. if i>=pbSecondPartyBegin(battlerIndex)-1
  941. party[i]=nil
  942. else
  943. party[i]=party[i+1]
  944. end
  945. end
  946. else
  947. for i in battlerIndex...party.length
  948. if i>=party.length-1
  949. party[i]=nil
  950. else
  951. party[i]=party[i+1]
  952. end
  953. end
  954. end
  955. end
  956. end
  957.  
  958. ################################################################################
  959. # Check whether actions can be taken.
  960. ################################################################################
  961. def pbCanShowCommands?(idxPokemon)
  962. thispkmn=@battlers[idxPokemon]
  963. return false if thispkmn.isFainted?
  964. return false if thispkmn.effects[PBEffects::TwoTurnAttack]>0
  965. return false if thispkmn.effects[PBEffects::HyperBeam]>0
  966. return false if thispkmn.effects[PBEffects::Rollout]>0
  967. return false if thispkmn.effects[PBEffects::Outrage]>0
  968. return false if thispkmn.effects[PBEffects::Rage]==true && $fefieldeffect == 24
  969. return false if thispkmn.effects[PBEffects::Uproar]>0
  970. return false if thispkmn.effects[PBEffects::Bide]>0
  971. #### KUROTSUNE - 022 - START
  972. return false if thispkmn.effects[PBEffects::SkyDrop]
  973. #### KUROTSUNE - 022 - END
  974. return true
  975. end
  976.  
  977. ################################################################################
  978. # Attacking.
  979. ################################################################################
  980. def pbCanShowFightMenu?(idxPokemon)
  981. thispkmn=@battlers[idxPokemon]
  982. if !pbCanShowCommands?(idxPokemon)
  983. return false
  984. end
  985. # No moves that can be chosen
  986. if !pbCanChooseMove?(idxPokemon,0,false) &&
  987. !pbCanChooseMove?(idxPokemon,1,false) &&
  988. !pbCanChooseMove?(idxPokemon,2,false) &&
  989. !pbCanChooseMove?(idxPokemon,3,false)
  990. return false
  991. end
  992. # Encore
  993. return false if thispkmn.effects[PBEffects::Encore]>0
  994. return true
  995. end
  996.  
  997. def pbCanChooseMove?(idxPokemon,idxMove,showMessages,sleeptalk=false)
  998. thispkmn=@battlers[idxPokemon]
  999. thismove=thispkmn.moves[idxMove]
  1000. opp1=thispkmn.pbOpposing1
  1001. opp2=thispkmn.pbOpposing2
  1002. if !thismove||thismove.id==0
  1003. return false
  1004. end
  1005. if thismove.pp<=0 && thismove.totalpp>0 && !sleeptalk
  1006. if showMessages
  1007. pbDisplayPaused(_INTL("There's no PP left for this move!"))
  1008. end
  1009. return false
  1010. end
  1011. if thispkmn.effects[PBEffects::ChoiceBand]>=0 &&
  1012. (thispkmn.hasWorkingItem(:CHOICEBAND) ||
  1013. thispkmn.hasWorkingItem(:CHOICESPECS) ||
  1014. thispkmn.hasWorkingItem(:CHOICESCARF))
  1015. hasmove=false
  1016. for i in 0...4
  1017. if thispkmn.moves[i].id==thispkmn.effects[PBEffects::ChoiceBand]
  1018. hasmove=true
  1019. break
  1020. end
  1021. end
  1022. if hasmove && thismove.id!=thispkmn.effects[PBEffects::ChoiceBand]
  1023. if showMessages
  1024. pbDisplayPaused(_INTL("{1} allows the use of only {2}!",
  1025. PBItems.getName(thispkmn.item),
  1026. PBMoves.getName(thispkmn.effects[PBEffects::ChoiceBand])))
  1027. end
  1028. return false
  1029. end
  1030. end
  1031. #### KUROTSUNE - 018 - START
  1032.  
  1033. if isConst?(thispkmn.item,PBItems,:ASSAULTVEST) && !(thismove.pbIsPhysical?(thismove.type) || thismove.pbIsSpecial?(thismove.type))
  1034. if showMessages
  1035. pbDisplayPaused(_INTL("{1} doesn't allow use of non-attacking moves!",
  1036. PBItems.getName(thispkmn.item)))
  1037. end
  1038. return false
  1039. end
  1040.  
  1041. #### KUROTSUNE - 018 - END
  1042.  
  1043. if opp1.effects[PBEffects::Imprison]
  1044. if thismove.id==opp1.moves[0].id ||
  1045. thismove.id==opp1.moves[1].id ||
  1046. thismove.id==opp1.moves[2].id ||
  1047. thismove.id==opp1.moves[3].id
  1048. if showMessages
  1049. pbDisplayPaused(_INTL("{1} can't use the sealed {2}!",thispkmn.pbThis,thismove.name))
  1050. end
  1051. #PBDebug.log("[CanChoose][#{opp1.pbThis} has: #{opp1.moves[0].name}, #{opp1.moves[1].name},#{opp1.moves[2].name},#{opp1.moves[3].name}]") if $INTERNAL
  1052. return false
  1053. end
  1054. end
  1055. if opp2.effects[PBEffects::Imprison]
  1056. if thismove.id==opp2.moves[0].id ||
  1057. thismove.id==opp2.moves[1].id ||
  1058. thismove.id==opp2.moves[2].id ||
  1059. thismove.id==opp2.moves[3].id
  1060. if showMessages
  1061. pbDisplayPaused(_INTL("{1} can't use the sealed {2}!",thispkmn.pbThis,thismove.name))
  1062. end
  1063. #PBDebug.log("[CanChoose][#{opp2.pbThis} has: #{opp2.moves[0].name}, #{opp2.moves[1].name},#{opp2.moves[2].name},#{opp2.moves[3].name}]") if $INTERNAL
  1064. return false
  1065. end
  1066. end
  1067. if thispkmn.effects[PBEffects::Taunt]>0 && thismove.basedamage==0
  1068. if showMessages
  1069. pbDisplayPaused(_INTL("{1} can't use {2} after the Taunt!",thispkmn.pbThis,thismove.name))
  1070. end
  1071. return false
  1072. end
  1073. if thispkmn.effects[PBEffects::Torment]
  1074. if thismove.id==thispkmn.lastMoveUsed
  1075. if showMessages
  1076. pbDisplayPaused(_INTL("{1} can't use the same move in a row due to the torment!",thispkmn.pbThis))
  1077. end
  1078. return false
  1079. end
  1080. end
  1081. if thismove.id==thispkmn.effects[PBEffects::DisableMove] && !sleeptalk
  1082. if showMessages
  1083. pbDisplayPaused(_INTL("{1}'s {2} is disabled!",thispkmn.pbThis,thismove.name))
  1084. end
  1085. return false
  1086. end
  1087. if thispkmn.effects[PBEffects::Encore]>0 && idxMove!=thispkmn.effects[PBEffects::EncoreIndex]
  1088. return false
  1089. end
  1090. return true
  1091. end
  1092.  
  1093. def pbAutoChooseMove(idxPokemon,showMessages=true)
  1094. thispkmn=@battlers[idxPokemon]
  1095. if thispkmn.isFainted?
  1096. @choices[idxPokemon][0]=0
  1097. @choices[idxPokemon][1]=0
  1098. @choices[idxPokemon][2]=nil
  1099. return
  1100. end
  1101. if thispkmn.effects[PBEffects::Encore]>0 &&
  1102. pbCanChooseMove?(idxPokemon,thispkmn.effects[PBEffects::EncoreIndex],false)
  1103. PBDebug.log("[Auto choosing Encore move...]") if $INTERNAL
  1104. @choices[idxPokemon][0]=1 # "Use move"
  1105. @choices[idxPokemon][1]=thispkmn.effects[PBEffects::EncoreIndex] # Index of move
  1106. @choices[idxPokemon][2]=thispkmn.moves[thispkmn.effects[PBEffects::EncoreIndex]]
  1107. @choices[idxPokemon][3]=-1 # No target chosen yet
  1108. if @doublebattle
  1109. thismove=thispkmn.moves[thispkmn.effects[PBEffects::EncoreIndex]]
  1110. target=thispkmn.pbTarget(thismove)
  1111. if target==PBTargets::SingleNonUser
  1112. target=@scene.pbChooseTarget(idxPokemon)
  1113. pbRegisterTarget(idxPokemon,target) if target>=0
  1114. elsif target==PBTargets::UserOrPartner
  1115. target=@scene.pbChooseTarget(idxPokemon)
  1116. pbRegisterTarget(idxPokemon,target) if target>=0 && (target&1)==(idxPokemon&1)
  1117. end
  1118. end
  1119. else
  1120. if !pbIsOpposing?(idxPokemon)
  1121. pbDisplayPaused(_INTL("{1} has no moves left!",thispkmn.name)) if showMessages
  1122. end
  1123. @choices[idxPokemon][0]=1 # "Use move"
  1124. @choices[idxPokemon][1]=-1 # Index of move to be used
  1125. @choices[idxPokemon][2]=@struggle # Use Struggle
  1126. @choices[idxPokemon][3]=-1 # No target chosen yet
  1127. end
  1128. end
  1129.  
  1130. def pbRegisterMove(idxPokemon,idxMove,showMessages=true)
  1131. thispkmn=@battlers[idxPokemon]
  1132. thismove=thispkmn.moves[idxMove]
  1133. #### KUROTSUNE - 010 - START
  1134. thispkmn.selectedMove = thismove.id
  1135. #### KUROTSUNE - 010 - END
  1136. return false if !pbCanChooseMove?(idxPokemon,idxMove,showMessages)
  1137. @choices[idxPokemon][0]=1 # "Use move"
  1138. @choices[idxPokemon][1]=idxMove # Index of move to be used
  1139. @choices[idxPokemon][2]=thismove # PokeBattle_Move object of the move
  1140. @choices[idxPokemon][3]=-1 # No target chosen yet
  1141. return true
  1142. end
  1143.  
  1144. def pbChoseMove?(i,move)
  1145. return false if @battlers[i].isFainted?
  1146. if @choices[i][0]==1 && @choices[i][1]>=0
  1147. choice=@choices[i][1]
  1148. return isConst?(@battlers[i].moves[choice].id,PBMoves,move)
  1149. end
  1150. return false
  1151. end
  1152.  
  1153. def pbChoseMoveFunctionCode?(i,code)
  1154. return false if @battlers[i].isFainted?
  1155. if @choices[i][0]==1 && @choices[i][1]>=0
  1156. choice=@choices[i][1]
  1157. return @battlers[i].moves[choice].function==code
  1158. end
  1159. return false
  1160. end
  1161.  
  1162. def pbRegisterTarget(idxPokemon,idxTarget)
  1163. @choices[idxPokemon][3]=idxTarget # Set target of move
  1164. return true
  1165. end
  1166.  
  1167. # UPDATE 11/23/2013
  1168. # implementing STALL
  1169. def pbPriority(ignorequickclaw = false)
  1170. if @usepriority
  1171. # use stored priority if round isn't over yet
  1172. return @priority
  1173. end
  1174. speeds=[]
  1175. quickclaw=[]
  1176. stall=[] # <--- Add this here
  1177. lagtail=[] # <--- This too
  1178. incense=[] # <--- ... and this
  1179. priorities=[]
  1180. temp=[]
  1181. @priority.clear
  1182. maxpri=0
  1183. minpri=0
  1184. # Calculate each Pokémon's speed
  1185. ### Simplified below
  1186. #speeds[0]=@battlers[0].pbSpeed
  1187. #speeds[1]=@battlers[1].pbSpeed
  1188. #speeds[2]=@battlers[2].pbSpeed
  1189. #speeds[3]=@battlers[3].pbSpeed
  1190. #quickclaw[0]=isConst?(@battlers[0].item,PBItems,:QUICKCLAW)
  1191. #quickclaw[1]=isConst?(@battlers[1].item,PBItems,:QUICKCLAW)
  1192. #quickclaw[2]=isConst?(@battlers[2].item,PBItems,:QUICKCLAW)
  1193. #quickclaw[3]=isConst?(@battlers[3].item,PBItems,:QUICKCLAW)
  1194. ###
  1195. # Find the maximum and minimum priority
  1196. for i in 0..3
  1197. ### add these here
  1198. speeds[i] = @battlers[i].pbSpeed
  1199. quickclaw[i] = isConst?(@battlers[i].item, PBItems, :QUICKCLAW)
  1200. # && !ignorequickclaw && @choices[i][0] == 1
  1201. stall[i] = isConst?(@battlers[i].ability, PBAbilities, :STALL)
  1202. lagtail[i] = isConst?(@battlers[i].item, PBItems, :LAGGINGTAIL)
  1203. incense[i] = isConst?(@battlers[i].item, PBItems, :FULLINCENSE)
  1204. ###
  1205. # For this function, switching and using items
  1206. # is the same as using a move with a priority of 0
  1207. pri=0
  1208. if @choices[i][0]==1 # Is a move
  1209. pri=@choices[i][2].priority
  1210. pri+=1 if isConst?(@battlers[i].ability,PBAbilities,:PRANKSTER) &&
  1211. @choices[i][2].basedamage==0 # Is status move
  1212. pri+=1 if isConst?(@battlers[i].ability,PBAbilities,:GALEWINGS) && @choices[i][2].type==2
  1213. # pri-=1 if $fefieldeffect == 6 &&
  1214. # @battlers[i].effects[PBEffects::TwoTurnAttack] !=0 &&
  1215. # (@choices[i][2].id==156 || @choices[i][2].id==157)
  1216.  
  1217. end
  1218. priorities[i]=pri
  1219. if i==0
  1220. maxpri=pri
  1221. minpri=pri
  1222. else
  1223. maxpri=pri if maxpri<pri
  1224. minpri=pri if minpri>pri
  1225. end
  1226. end
  1227. # Find and order all moves with the same priority
  1228. curpri=maxpri
  1229. loop do
  1230. temp.clear
  1231. for j in 0...4
  1232. if priorities[j]==curpri
  1233. temp[temp.length]=j
  1234. end
  1235. end
  1236. # Sort by speed
  1237. if temp.length==1
  1238. @priority[@priority.length]=@battlers[temp[0]]
  1239. else
  1240. n=temp.length
  1241. usequickclaw=(pbRandom(100)<20)
  1242. for m in 0..n-2
  1243. for i in 1..n-1
  1244. if quickclaw[temp[i]] && usequickclaw
  1245. cmp=(quickclaw[temp[i-1]]) ? 0 : -1 #Rank higher if without Quick Claw, or equal if with it
  1246. elsif quickclaw[temp[i-1]] && usequickclaw
  1247. cmp=1 # Rank lower
  1248. # UPDATE 11/23/2013
  1249. # stall ability
  1250. # add the following two elsif blocks
  1251. ####
  1252. # ignored if we have full incense or lagging tail
  1253. elsif stall[temp[i]] && !(incense[temp[i]] || lagtail[temp[i]])
  1254. # if they also have stall
  1255. if stall[temp[i-1]] && !(incense[temp[i-1]] || lagtail[temp[i-1]])
  1256. # higher speed -> lower priority
  1257. cmp=speeds[temp[i]] > speeds[temp[i-1]] ? 1 : -1
  1258. elsif lagtail[temp[i-1]] || incense[temp[i-1]]
  1259. cmp=-1
  1260. else
  1261. cmp=1
  1262. end
  1263. elsif stall[temp[i-1]] && !(incense[temp[i-1]] || lagtail[temp[i-1]])
  1264. cmp= lagtail[temp[i]] || incense[temp[i]] ? 1 : -1
  1265. # end of update
  1266. elsif speeds[temp[i]]!=speeds[temp[i-1]]
  1267. cmp=(speeds[temp[i]]>speeds[temp[i-1]]) ? -1 : 1 #Rank higher to higher-speed battler
  1268. else
  1269. cmp=0
  1270. end
  1271. # UPDATE implementing Trick Room
  1272. if cmp<0 && @trickroom==0
  1273. # put higher-speed Pokémon first
  1274. swaptmp=temp[i]
  1275. temp[i]=temp[i-1]
  1276. temp[i-1]=swaptmp
  1277. elsif cmp>0 && @trickroom>0
  1278. swaptmp=temp[i]
  1279. temp[i]=temp[i-1]
  1280. temp[i-1]=swaptmp
  1281.  
  1282. elsif cmp==0
  1283. # END OF UPDATE
  1284. # swap at random if speeds are equal
  1285. if pbRandom(2)==0
  1286. swaptmp=temp[i]
  1287. temp[i]=temp[i-1]
  1288. temp[i-1]=swaptmp
  1289. end
  1290. end
  1291. end
  1292. end
  1293. #Now add the temp array to priority
  1294. for i in temp
  1295. @priority[@priority.length]=@battlers[i]
  1296. end
  1297. end
  1298. curpri-=1
  1299. break unless curpri>=minpri
  1300. end
  1301. =begin
  1302. prioind=[
  1303. @priority[0].index,
  1304. @priority[1].index,
  1305. @priority[2] ? @priority[2].index : -1,
  1306. @priority[3] ? @priority[3].index : -1
  1307. ]
  1308. print("#{speeds.inspect} #{prioind.inspect}")
  1309. =end
  1310. @usepriority=true
  1311. return @priority
  1312. end
  1313.  
  1314. ##### KUROTSUNE - 011 - START
  1315. # Makes target pokemon move last
  1316. def pbMoveLast(target)
  1317. priorityTarget = pbGetPriority(target)
  1318. priority = @priority
  1319. case priorityTarget
  1320. when 0
  1321. # Opponent has likely already moved
  1322. return false
  1323. when 1
  1324. aux = priority[3]
  1325. priority[3] = target
  1326. priority[1] = aux
  1327. aux = priority[2]
  1328. priority[2] = priority[1]
  1329. priority[1] = aux
  1330. @priority = priority
  1331. return true
  1332. when 2
  1333. aux = priority[2]
  1334. priority[2] = priority[3]
  1335. priority[3] = aux
  1336. @priority = priority
  1337. return true
  1338. when 3
  1339. return false
  1340. end
  1341. end
  1342.  
  1343.  
  1344. # Makes the second pokemon move after the first.
  1345. def pbMoveAfter(first, second)
  1346. priorityFirst = pbGetPriority(first)
  1347. priority = @priority
  1348. case priorityFirst
  1349. when 0
  1350. if second == priority[1]
  1351. # Nothing to do here
  1352. return false
  1353. elsif second == priority[2]
  1354. aux = priority[1]
  1355. priority[1] = second
  1356. priority[2] = aux
  1357. @priority = priority
  1358. return true
  1359. elsif second == priority[3]
  1360. aux = priority[1]
  1361. priority[1] = second
  1362. priority[3] = aux
  1363. aux = priority[2]
  1364. priority[2] = priority[3]
  1365. priority[3] = aux
  1366. @priority = priority
  1367. return true
  1368. end
  1369. when 1
  1370. if second == priority[0] || second == priority[2]
  1371. # Nothing to do here
  1372. return false
  1373. elsif second == priority[3]
  1374. aux = priority[2]
  1375. priority[2] = priority[3]
  1376. priority[3] = aux
  1377. @priority = priority
  1378. return true
  1379. end
  1380. when 2
  1381. return false
  1382. when 3
  1383. return false
  1384. end
  1385. end
  1386. ##### KUROTSUNE - 011 - END
  1387.  
  1388. def pbGetPriority(mon)
  1389. for i in 0..3
  1390. if @priority[i] == mon
  1391. return i
  1392. end
  1393. end
  1394. return -1
  1395. end
  1396.  
  1397. def pbClearChoices(index)
  1398. choices[index][0] = -1
  1399. choices[index][1] = -1
  1400. choices[index][2] = -1
  1401. choices[index][3] = -1
  1402. end
  1403. ################################################################################
  1404. # Switching Pokémon.
  1405. ################################################################################
  1406. def pbCanSwitchLax?(idxPokemon,pkmnidxTo,showMessages)
  1407. if pkmnidxTo>=0
  1408. party=pbParty(idxPokemon)
  1409. if pkmnidxTo>=party.length
  1410. return false
  1411. end
  1412. if !party[pkmnidxTo]
  1413. return false
  1414. end
  1415. if party[pkmnidxTo].isEgg?
  1416. pbDisplayPaused(_INTL("An Egg can't battle!")) if showMessages
  1417. return false
  1418. end
  1419. if !pbIsOwner?(idxPokemon,pkmnidxTo)
  1420. owner=pbPartyGetOwner(idxPokemon,pkmnidxTo)
  1421. pbDisplayPaused(_INTL("You can't switch {1}'s Pokémon with one of yours!",owner.name)) if showMessages
  1422. return false
  1423. end
  1424. if party[pkmnidxTo].hp<=0
  1425. pbDisplayPaused(_INTL("{1} has no energy left to battle!",party[pkmnidxTo].name)) if showMessages
  1426. return false
  1427. end
  1428. if @battlers[idxPokemon].pokemonIndex==pkmnidxTo
  1429. pbDisplayPaused(_INTL("{1} is already in battle!",party[pkmnidxTo].name)) if showMessages
  1430. return false
  1431. end
  1432. if @battlers[idxPokemon].pbPartner.pokemonIndex==pkmnidxTo
  1433. pbDisplayPaused(_INTL("{1} is already in battle!",party[pkmnidxTo].name)) if showMessages
  1434. return false
  1435. end
  1436. end
  1437. return true
  1438. end
  1439.  
  1440. def pbCanSwitch?(idxPokemon,pkmnidxTo,showMessages)
  1441. thispkmn=@battlers[idxPokemon]
  1442. # Multi-Turn Attacks/Mean Look
  1443. if !pbCanSwitchLax?(idxPokemon,pkmnidxTo,showMessages)
  1444. return false
  1445. end
  1446. # UPDATE 11/16/2013
  1447. # Ghost type can now escape from anything
  1448. if thispkmn.pbHasType?(:GHOST)
  1449. return true
  1450. end
  1451. isOpposing=pbIsOpposing?(idxPokemon)
  1452. party=pbParty(idxPokemon)
  1453. for i in 0...4
  1454. next if isOpposing!=pbIsOpposing?(i)
  1455. if choices[i][0]==2 && choices[i][1]==pkmnidxTo
  1456. pbDisplayPaused(_INTL("{1} has already been selected.",party[pkmnidxTo].name)) if showMessages
  1457. return false
  1458. end
  1459. end
  1460. if thispkmn.hasWorkingItem(:SHEDSHELL)
  1461. return true
  1462. end
  1463. if thispkmn.effects[PBEffects::MultiTurn]>0 ||
  1464. thispkmn.effects[PBEffects::MeanLook]>=0 ||
  1465. field.effects[PBEffects::FairyLock]==1
  1466. pbDisplayPaused(_INTL("{1} can't be switched out!",thispkmn.pbThis)) if showMessages
  1467. return false
  1468. end
  1469. # Ingrain
  1470. if thispkmn.effects[PBEffects::Ingrain]
  1471. pbDisplayPaused(_INTL("{1} can't be switched out!",thispkmn.pbThis)) if showMessages
  1472. return false
  1473. end
  1474. opp1=thispkmn.pbOpposing1
  1475. opp2=thispkmn.pbOpposing2
  1476. opp=nil
  1477. if thispkmn.pbHasType?(:STEEL)
  1478. opp=opp1 if opp1.hasWorkingAbility(:MAGNETPULL)
  1479. opp=opp2 if opp2.hasWorkingAbility(:MAGNETPULL)
  1480. end
  1481. if !thispkmn.isAirborne?
  1482. opp=opp1 if opp1.hasWorkingAbility(:ARENATRAP)
  1483. opp=opp2 if opp2.hasWorkingAbility(:ARENATRAP)
  1484. end
  1485. if !thispkmn.hasWorkingAbility(:SHADOWTAG)
  1486. opp=opp1 if opp1.hasWorkingAbility(:SHADOWTAG)
  1487. opp=opp2 if opp2.hasWorkingAbility(:SHADOWTAG)
  1488. end
  1489. if opp
  1490. abilityname=PBAbilities.getName(opp.ability)
  1491. pbDisplayPaused(_INTL("{1}'s {2} prevents switching!",opp.pbThis,abilityname)) if showMessages
  1492. # UPDATE 11/16
  1493. # now displays the proper fleeing message iff you are attempting to flee
  1494. # Note: not very elegant, but it should work.
  1495. pbDisplayPaused(_INTL("{1} prevents escaping with {2}!", opp.pbThis, abilityname)) if !showMessages && pkmnidxTo == -1
  1496. return false
  1497. end
  1498. return true
  1499. end
  1500.  
  1501. def pbRegisterSwitch(idxPokemon,idxOther)
  1502. return false if !pbCanSwitch?(idxPokemon,idxOther,false)
  1503. @choices[idxPokemon][0]=2 # "Switch Pokémon"
  1504. @choices[idxPokemon][1]=idxOther # Index of other Pokémon to switch with
  1505. @choices[idxPokemon][2]=nil
  1506. side=(pbIsOpposing?(idxPokemon)) ? 1 : 0
  1507. owner=pbGetOwnerIndex(idxPokemon)
  1508. if @megaEvolution[side][owner]==idxPokemon
  1509. @megaEvolution[side][owner]=-1
  1510. end
  1511. return true
  1512. end
  1513.  
  1514. def pbCanChooseNonActive?(index)
  1515. party=pbParty(index)
  1516. for i in 0..party.length-1
  1517. return true if pbCanSwitchLax?(index,i,false)
  1518. end
  1519. return false
  1520. end
  1521.  
  1522. def pbJudgeSwitch(favorDraws=false)
  1523. if !favorDraws
  1524. return if @decision>0
  1525. pbJudge()
  1526. return if @decision>0
  1527. else
  1528. return if @decision==5
  1529. pbJudge()
  1530. return if @decision>0
  1531. end
  1532. end
  1533.  
  1534. def pbSwitch(favorDraws=false)
  1535. if !favorDraws
  1536. return if @decision>0
  1537. pbJudge()
  1538. return if @decision>0
  1539. else
  1540. return if @decision==5
  1541. pbJudge()
  1542. return if @decision>0
  1543. end
  1544. firstbattlerhp=@battlers[0].hp
  1545. switched=[]
  1546. for index in 0...4
  1547. next if !@doublebattle && pbIsDoubleBattler?(index)
  1548. next if @battlers[index] && !@battlers[index].isFainted?
  1549. next if !pbCanChooseNonActive?(index)
  1550. if !pbOwnedByPlayer?(index)
  1551. if !pbIsOpposing?(index) || (@opponent && pbIsOpposing?(index))
  1552. newenemy=pbSwitchInBetween(index,false,false)
  1553. #### JERICHO - 001 - START
  1554. if !pbIsOpposing?(index)
  1555. if isConst?(@party1[newenemy].ability,PBAbilities,:ILLUSION) #ILLUSION
  1556. party3=@party1.find_all {|item| item && !item.egg? && item.hp>0 }
  1557. if party3[@party1.length-1] != @party1[newenemy]
  1558. illusionpoke = party3[party3.length-1]
  1559. end
  1560. end #ILLUSION
  1561. newname = illusionpoke != nil ? illusionpoke.name : @party1[newenemy].name #ILLUSION
  1562. else
  1563. if isConst?(@party2[newenemy].ability,PBAbilities,:ILLUSION) #ILLUSION
  1564. party3=@party1.find_all {|item| item && !item.egg? && item.hp>0 }
  1565. if party3[@party1.length-1] != @party1[newenemy]
  1566. illusionpoke = party3[party3.length-1]
  1567. end
  1568. end #ILLUSION
  1569. newname = illusionpoke != nil ? illusionpoke.name : @party2[newenemy].name #ILLUSION
  1570. end
  1571. #### JERICHO - 001 - END
  1572. opponent=pbGetOwner(index)
  1573. if !@doublebattle && firstbattlerhp>0 && @shiftStyle && @opponent &&
  1574. @internalbattle && pbCanChooseNonActive?(0) && pbIsOpposing?(index) &&
  1575. @battlers[0].effects[PBEffects::Outrage]==0
  1576. #### JERICHO - 001 - START
  1577. pbDisplayPaused(_INTL("{1} is about to send in {2}.",opponent.fullname,newname)) #ILLUSION
  1578. #### JERICHO - 001 - END
  1579. if pbDisplayConfirm(_INTL("Will {1} change Pokémon?",self.pbPlayer.name))
  1580. newpoke=pbSwitchPlayer(0,true,true)
  1581. if newpoke>=0
  1582. pbDisplayBrief(_INTL("{1}, that's enough! Come back!",@battlers[0].name))
  1583. pbRecallAndReplace(0,newpoke)
  1584. switched.push(0)
  1585. end
  1586. end
  1587. end
  1588. pbRecallAndReplace(index,newenemy)
  1589. switched.push(index)
  1590. end
  1591. elsif @opponent
  1592. newpoke=pbSwitchInBetween(index,true,false)
  1593. pbRecallAndReplace(index,newpoke)
  1594. switched.push(index)
  1595. else
  1596. switch=false
  1597. if !pbDisplayConfirm(_INTL("Use next Pokémon?"))
  1598. switch=(pbRun(index,true)<=0)
  1599. else
  1600. switch=true
  1601. end
  1602. if switch
  1603. newpoke=pbSwitchInBetween(index,true,false)
  1604. pbRecallAndReplace(index,newpoke)
  1605. switched.push(index)
  1606. end
  1607. end
  1608. end
  1609. if switched.length>0
  1610. priority=pbPriority
  1611. for i in priority
  1612. i.pbAbilitiesOnSwitchIn(true) if switched.include?(i.index)
  1613. end
  1614. end
  1615. end
  1616.  
  1617. def pbSendOut(index,pokemon)
  1618. pbSetSeen(pokemon)
  1619. @peer.pbOnEnteringBattle(self,pokemon)
  1620. if pbIsOpposing?(index)
  1621. # in-battle text
  1622. @scene.pbTrainerSendOut(index,pokemon)
  1623. # Last Pokemon script; credits to venom12 and HelioAU
  1624. if !@opponent.is_a?(Array)
  1625. trainertext = @opponent
  1626. if pbPokemonCount(@party2)==1
  1627. # Define any trainers that you want to activate this script below
  1628. # For each defined trainer, add the BELOW section for them
  1629. if isConst?(trainertext.trainertype,PBTrainers,:POKEMONTRAINER_Brendan2)
  1630. if $game_variables[226] == 0
  1631. @scene.pbShowOpponent(0)
  1632. pbDisplayPaused(_INTL("Beginner's luck quickly runs out."))
  1633. @scene.pbHideOpponent
  1634. elsif $game_variables[226] == 1
  1635. @scene.pbShowOpponent(0)
  1636. pbDisplayPaused(_INTL("I'm warning you, stay out of this."))
  1637. @scene.pbHideOpponent
  1638. elsif $game_variables[226] == 6
  1639. @scene.pbShowOpponent(0)
  1640. pbDisplayPaused(_INTL("Whatever it takes."))
  1641. @scene.pbHideOpponent
  1642. elsif $game_variables[226] == 15
  1643. @scene.pbShowOpponent(0)
  1644. pbDisplayPaused(_INTL("Am I pushed this far up already?"))
  1645. @scene.pbHideOpponent
  1646. end
  1647. elsif isConst?(trainertext.trainertype,PBTrainers,:GYMLEADER)
  1648. if $game_variables[226] == 0
  1649. @scene.pbShowOpponent(0)
  1650. pbBGMPlay("Final Pokemon",100,100)
  1651. pbDisplayPaused(_INTL("WHATTTT THEEEEE FUUCKKK?!"))
  1652. @scene.pbHideOpponent
  1653. end
  1654. elsif isConst?(trainertext.trainertype,PBTrainers,:SCOUTER)
  1655. if $game_variables[226] == 0
  1656. @scene.pbShowOpponent(0)
  1657. pbDisplayPaused(_INTL("Invigorated yet? I know I am!"))
  1658. @scene.pbHideOpponent
  1659. elsif $game_variables[226] == 1
  1660. @scene.pbShowOpponent(0)
  1661. pbDisplayPaused(_INTL("Two badges don't mean nothin'! I'm not done yet!"))
  1662. @scene.pbHideOpponent
  1663. end
  1664. elsif isConst?(trainertext.trainertype,PBTrainers,:POKEMONTRAINER_Brendan)
  1665. if $game_variables[226] == 0
  1666. @scene.pbShowOpponent(0)
  1667. pbDisplayPaused(_INTL("Beginner's luck quickly runs out."))
  1668. @scene.pbHideOpponent
  1669. elsif $game_variables[226] == 1
  1670. @scene.pbShowOpponent(0)
  1671. pbDisplayPaused(_INTL("I'm warning you, stay out of this."))
  1672. @scene.pbHideOpponent
  1673. elsif $game_variables[226] == 6
  1674. @scene.pbShowOpponent(0)
  1675. pbDisplayPaused(_INTL("Whatever it takes."))
  1676. @scene.pbHideOpponent
  1677. elsif $game_variables[226] == 15
  1678. @scene.pbShowOpponent(0)
  1679. pbDisplayPaused(_INTL("Am I pushed this far up already?"))
  1680. @scene.pbHideOpponent
  1681. end
  1682. elsif isConst?(trainertext.trainertype,PBTrainers,:STUDENT)
  1683. if $game_variables[226] == 2
  1684. @scene.pbShowOpponent(0)
  1685. pbDisplayPaused(_INTL("Huff n' puff! I'm not done yet! Check this out!"))
  1686. @scene.pbHideOpponent
  1687. elsif $game_variables[226] == 4
  1688. @scene.pbShowOpponent(0)
  1689. pbDisplayPaused(_INTL("Your stance is all over the place! Move more like this!"))
  1690. @scene.pbHideOpponent
  1691. end
  1692. elsif isConst?(trainertext.trainertype,PBTrainers,:Leader_Koga)
  1693. if $game_variables[226] == 0
  1694. @scene.pbShowOpponent(0)
  1695. pbBGMPlay("Final Pokemon",100,100)
  1696. pbDisplayPaused(_INTL("Once a broken man, now is whole once again..."))
  1697. @scene.pbHideOpponent
  1698. end
  1699. elsif isConst?(trainertext.trainertype,PBTrainers,:REVENANT)
  1700. if $game_variables[226] == 0
  1701. pbBGMPlay("Final Pokemon",100,100)
  1702. @scene.pbShowOpponent(0)
  1703. pbDisplayPaused(_INTL("I feel myself fading with every moment that passes by."))
  1704. @scene.pbHideOpponent
  1705. end
  1706. elsif isConst?(trainertext.trainertype,PBTrainers,:LEADER_Misty)
  1707. if $game_variables[226] == 0
  1708. @scene.pbShowOpponent(0)
  1709. pbDisplayPaused(_INTL("Wait... I don't think this is how it was supposed to go."))
  1710. @scene.pbHideOpponent
  1711. end
  1712. elsif isConst?(trainertext.trainertype,PBTrainers,:XENOPERATIVE)
  1713. if $game_variables[226] == 1
  1714. @scene.pbShowOpponent(0)
  1715. pbDisplayPaused(_INTL("You can't be serious? I've only begun your torture! "))
  1716. @scene.pbHideOpponent
  1717. end
  1718. elsif isConst?(trainertext.trainertype,PBTrainers,:XENINITIATIVE)
  1719. if $game_variables[226] == 0
  1720. @scene.pbShowOpponent(0)
  1721. pbDisplayPaused(_INTL("You think you've won because I'm on my last leg? You're a fuckin' idiot."))
  1722. @scene.pbHideOpponent
  1723. elsif $game_variables[226] == 1
  1724. @scene.pbShowOpponent(0)
  1725. pbDisplayPaused(_INTL("I have the power of the legendary Pokemon Giratina! I will not fall here!"))
  1726. @scene.pbHideOpponent
  1727. end
  1728. elsif isConst?(trainertext.trainertype,PBTrainers,:XENWARDEN)
  1729. if $game_variables[226] == 0
  1730. @scene.pbShowOpponent(0)
  1731. pbDisplayPaused(_INTL("You're leaving me with no choice. No more holding back!"))
  1732. @scene.pbHideOpponent
  1733. end
  1734. elsif isConst?(trainertext.trainertype,PBTrainers,:LEADER_Erika)
  1735. if $game_variables[226] == 0
  1736. @scene.pbShowOpponent(0)
  1737. pbBGMPlay("Final Pokemon",100,100)
  1738. pbDisplayPaused(_INTL("What will I whisper when all the wisps have gone home?"))
  1739. @scene.pbHideOpponent
  1740. end
  1741. elsif isConst?(trainertext.trainertype,PBTrainers,:APPRENTICE)
  1742. if $game_variables[226] == 0
  1743. @scene.pbShowOpponent(0)
  1744. pbDisplayPaused(_INTL("Wait, holy crap..."))
  1745. @scene.pbHideOpponent
  1746. elsif $game_variables[226] == 1
  1747. @scene.pbShowOpponent(0)
  1748. pbDisplayPaused(_INTL("This is so frustrating! I want to win damnit!"))
  1749. @scene.pbHideOpponent
  1750. end
  1751. elsif isConst?(trainertext.trainertype,PBTrainers,:ENIGMA)
  1752. if $game_variables[226] == 0
  1753. @scene.pbShowOpponent(0)
  1754. pbDisplayPaused(_INTL("You've grown so fast in such a small amount of time. It's remarkable! "))
  1755. @scene.pbHideOpponent
  1756. end
  1757. elsif isConst?(trainertext.trainertype,PBTrainers,:MARINEBIOLOGIST)
  1758. if $game_variables[226] == 0 || $game_variables[226] == 1
  1759. @scene.pbShowOpponent(0)
  1760. pbBGMPlay("Final Pokemon",100,100)
  1761. pbDisplayPaused(_INTL("Like at the break of night. The waves grow calm. Does this signify the end?"))
  1762. @scene.pbHideOpponent
  1763. end
  1764. elsif isConst?(trainertext.trainertype,PBTrainers,:ENTOMOLOGIST)
  1765. if $game_variables[226] == 0
  1766. @scene.pbShowOpponent(0)
  1767. pbBGMPlay("Final Pokemon",100,100)
  1768. pbDisplayPaused(_INTL("Don't you know how hard it is to kill a bug?"))
  1769. @scene.pbHideOpponent
  1770. end
  1771. elsif isConst?(trainertext.trainertype,PBTrainers,:FAITHFULSERVANT)
  1772. if $game_variables[226] == 0
  1773. @scene.pbShowOpponent(0)
  1774. pbBGMPlay("Final Pokemon",100,100)
  1775. pbDisplayPaused(_INTL("It's too hot! I'm feeling too warm! Cold... is the answer...!"))
  1776. @scene.pbHideOpponent
  1777. end
  1778. elsif isConst?(trainertext.trainertype,PBTrainers,:MUSICENTHUSIAST)
  1779. if $game_variables[226] == 0
  1780. @scene.pbShowOpponent(0)
  1781. pbBGMPlay("Final Pokemon",100,100)
  1782. pbDisplayPaused(_INTL("I'm not breakin' a sweat!"))
  1783. @scene.pbHideOpponent
  1784. end
  1785. elsif isConst?(trainertext.trainertype,PBTrainers,:ESOTERIC)
  1786. if $game_variables[226] == 0
  1787. @scene.pbShowOpponent(0)
  1788. pbBGMPlay("Final Pokemon",100,100)
  1789. pbDisplayPaused(_INTL("You think you'll be safe by beating me? The outcome is the same! Indriad doesn't care... he doesn't..."))
  1790. @scene.pbHideOpponent
  1791. end
  1792. elsif isConst?(trainertext.trainertype,PBTrainers,:GHOSTKID)
  1793. if $game_variables[226] == 0
  1794. @scene.pbShowOpponent(0)
  1795. pbBGMPlay("Final Pokemon",100,100)
  1796. pbDisplayPaused(_INTL("I use the Pokemon I prefer over what's technically the best. Have you noticed? Well, anyway, it's almost over now."))
  1797. @scene.pbHideOpponent
  1798. end
  1799. elsif isConst?(trainertext.trainertype,PBTrainers,:BOTANIST)
  1800. if $game_variables[226] == 0
  1801. @scene.pbShowOpponent(0)
  1802. pbBGMPlay("Final Pokemon",100,100)
  1803. pbDisplayPaused(_INTL("Are you kidding me? Who said you could turn this around?"))
  1804. @scene.pbHideOpponent
  1805. end
  1806. elsif isConst?(trainertext.trainertype,PBTrainers,:BOTANIST_1)
  1807. if $game_variables[226] == 0
  1808. @scene.pbShowOpponent(0)
  1809. pbBGMPlay("Final Pokemon",100,100)
  1810. pbDisplayPaused(_INTL("It seems like I'm being placed in a corner. Funny how things turn south so quickly."))
  1811. @scene.pbHideOpponent
  1812. end
  1813. elsif isConst?(trainertext.trainertype,PBTrainers,:TECHKID)
  1814. if $game_variables[226] == 0
  1815. @scene.pbShowOpponent(0)
  1816. pbBGMPlay("Final Pokemon",100,100)
  1817. pbDisplayPaused(_INTL("It seems we are starting to have technical difficulties. Please stand by!"))
  1818. @scene.pbHideOpponent
  1819. end
  1820. end
  1821. end
  1822. # For each defined trainer, add the ABOVE section for them
  1823. end
  1824. else
  1825. @scene.pbSendOut(index,pokemon)
  1826. end
  1827. @scene.pbResetMoveIndex(index)
  1828. end
  1829.  
  1830. def pbReplace(index,newpoke,batonpass=false)
  1831. party=pbParty(index)
  1832. if pbOwnedByPlayer?(index)
  1833. # Reorder the party for this battle
  1834. bpo=-1; bpn=-1
  1835. for i in 0...6
  1836. bpo=i if @partyorder[i]==@battlers[index].pokemonIndex
  1837. bpn=i if @partyorder[i]==newpoke
  1838. end
  1839. poke1=@partyorder[bpo]
  1840. @partyorder[bpo]=@partyorder[bpn]
  1841. @partyorder[bpn]=poke1
  1842. @battlers[index].pbInitialize(party[newpoke],newpoke,batonpass)
  1843. pbSendOut(index,party[newpoke])
  1844. else
  1845. @battlers[index].pbInitialize(party[newpoke],newpoke,batonpass)
  1846. pbSetSeen(party[newpoke])
  1847. if pbIsOpposing?(index)
  1848. pbSendOut(index,party[newpoke])
  1849. else
  1850. pbSendOut(index,party[newpoke])
  1851. end
  1852. end
  1853. end
  1854.  
  1855. def pbRecallAndReplace(index,newpoke,batonpass=false)
  1856. if @battlers[index].effects[PBEffects::Illusion]
  1857. @battlers[index].effects[PBEffects::Illusion] = nil
  1858. end
  1859. @switchedOut[index] = true
  1860. pbClearChoices(index)
  1861. @battlers[index].pbResetForm
  1862. if !@battlers[index].isFainted?
  1863. @scene.pbRecall(index)
  1864. end
  1865. pbMessagesOnReplace(index,newpoke)
  1866. pbReplace(index,newpoke,batonpass)
  1867. return pbOnActiveOne(@battlers[index])
  1868. end
  1869.  
  1870. def pbMessagesOnReplace(index,newpoke)
  1871. party=pbParty(index)
  1872. if pbOwnedByPlayer?(index)
  1873. # if !party[newpoke]
  1874. # p [index,newpoke,party[newpoke],pbAllFainted?(party)]
  1875. # PBDebug.log([index,newpoke,party[newpoke],"pbMOR"].inspect)
  1876. # for i in 0...party.length
  1877. # PBDebug.log([i,party[i].hp].inspect)
  1878. # end
  1879. # raise BattleAbortedException.new
  1880. # end
  1881. #### JERICHO - 001 - start
  1882. if isConst?(party[newpoke].ability,PBAbilities,:ILLUSION) #ILLUSION
  1883. party2=party.find_all {|item| item && !item.egg? && item.hp>0 }
  1884. if party2[party.length-1] != party[newpoke]
  1885. illusionpoke = party[party.length-1]
  1886. end
  1887. end #ILLUSION
  1888. newname = illusionpoke != nil ? illusionpoke.name : party[newpoke].name
  1889. opposing=@battlers[index].pbOppositeOpposing
  1890. if opposing.hp<=0 || opposing.hp==opposing.totalhp
  1891. pbDisplayBrief(_INTL("Go! {1}!",newname))
  1892. elsif opposing.hp>=(opposing.totalhp/2)
  1893. pbDisplayBrief(_INTL("Do it! {1}!",newname))
  1894. elsif opposing.hp>=(opposing.totalhp/4)
  1895. pbDisplayBrief(_INTL("Go for it, {1}!",newname))
  1896. else
  1897. pbDisplayBrief(_INTL("Your foe's weak!\nGet 'em, {1}!",newname))
  1898. end
  1899. #### JERICHO - 001 - END
  1900. else
  1901. # if !party[newpoke]
  1902. # p [index,newpoke,party[newpoke],pbAllFainted?(party)]
  1903. # PBDebug.log([index,newpoke,party[newpoke],"pbMOR"].inspect)
  1904. # for i in 0...party.length
  1905. # PBDebug.log([i,party[i].hp].inspect)
  1906. # end
  1907. # raise BattleAbortedException.new
  1908. # end
  1909. #### JERICHO - 001 - START
  1910. if isConst?(party[newpoke].ability,PBAbilities,:ILLUSION) #ILLUSION
  1911. party2=party.find_all {|item| item && !item.egg? && item.hp>0 }
  1912. if party2[party.length-1] != party[newpoke]
  1913. illusionpoke = party[party.length-1]
  1914. end
  1915. end #ILLUSION
  1916. newname = illusionpoke != nil ? illusionpoke.name : party[newpoke].name #ILLUSION
  1917. owner=pbGetOwner(index)
  1918. pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",owner.fullname,newname)) #ILLUSION
  1919. #### JERICHO - 001 - END
  1920. end
  1921. end
  1922.  
  1923. def pbSwitchInBetween(index,lax,cancancel)
  1924. if !pbOwnedByPlayer?(index)
  1925. return @scene.pbChooseNewEnemy(index,pbParty(index))
  1926. else
  1927. return pbSwitchPlayer(index,lax,cancancel)
  1928. end
  1929. end
  1930.  
  1931. def pbSwitchPlayer(index,lax,cancancel)
  1932. if @debug
  1933. return @scene.pbChooseNewEnemy(index,pbParty(index))
  1934. else
  1935. return @scene.pbSwitch(index,lax,cancancel)
  1936. end
  1937. end
  1938.  
  1939. ################################################################################
  1940. # Using an item.
  1941. ################################################################################
  1942. # Uses an item on a Pokémon in the player's party.
  1943. def pbUseItemOnPokemon(item,pkmnIndex,userPkmn,scene)
  1944. pokemon=@party1[pkmnIndex]
  1945. battler=nil
  1946. name=pbGetOwner(userPkmn.index).fullname
  1947. name=pbGetOwner(userPkmn.index).name if pbBelongsToPlayer?(userPkmn.index)
  1948. pbDisplayBrief(_INTL("{1} used the\r\n{2}.",name,PBItems.getName(item)))
  1949. ret=false
  1950. if pokemon.egg?
  1951. pbDisplay(_INTL("But it had no effect!"))
  1952. else
  1953. for i in 0...4
  1954. if !pbIsOpposing?(i) && @battlers[i].pokemonIndex==pkmnIndex
  1955. battler=@battlers[i]
  1956. end
  1957. end
  1958. ret=ItemHandlers.triggerBattleUseOnPokemon(item,pokemon,battler,scene)
  1959. end
  1960. if !ret && pbBelongsToPlayer?(userPkmn.index)
  1961. if $PokemonBag.pbCanStore?(item)
  1962. $PokemonBag.pbStoreItem(item)
  1963. else
  1964. raise _INTL("Couldn't return unused item to Bag somehow.")
  1965. end
  1966. end
  1967. return ret
  1968. end
  1969.  
  1970. # Uses an item on an active Pokémon.
  1971. def pbUseItemOnBattler(item,index,userPkmn,scene)
  1972. ret=ItemHandlers.triggerBattleUseOnBattler(item,@battlers[index],scene)
  1973. if !ret && pbBelongsToPlayer?(userPkmn.index)
  1974. if $PokemonBag.pbCanStore?(item)
  1975. $PokemonBag.pbStoreItem(item)
  1976. else
  1977. raise _INTL("Couldn't return unused item to Bag somehow.")
  1978. end
  1979. end
  1980. return ret
  1981. end
  1982.  
  1983. def pbRegisterItem(idxPokemon,idxItem,idxTarget=nil)
  1984. if ItemHandlers.hasUseInBattle(idxItem)
  1985. if idxPokemon==0
  1986. if ItemHandlers.triggerBattleUseOnBattler(idxItem,@battlers[idxPokemon],self)
  1987. ItemHandlers.triggerUseInBattle(idxItem,@battlers[idxPokemon],self)
  1988. if @doublebattle
  1989. @choices[idxPokemon+2][0]=3 # "Use an item"
  1990. @choices[idxPokemon+2][1]=idxItem # ID of item to be used
  1991. @choices[idxPokemon+2][2]=idxTarget # Index of Pokémon to use item on
  1992. end
  1993. else
  1994. return false
  1995. end
  1996. else
  1997. if ItemHandlers.triggerBattleUseOnBattler(idxItem,@battlers[idxPokemon],self)
  1998. pbDisplay(_INTL("It's impossible to aim without being focused!"))
  1999. end
  2000. return false
  2001. end
  2002. end
  2003. @choices[idxPokemon][0]=3 # "Use an item"
  2004. @choices[idxPokemon][1]=idxItem # ID of item to be used
  2005. @choices[idxPokemon][2]=idxTarget # Index of Pokémon to use item on
  2006. side=(pbIsOpposing?(idxPokemon)) ? 1 : 0
  2007. owner=pbGetOwnerIndex(idxPokemon)
  2008. if @megaEvolution[side][owner]==idxPokemon
  2009. @megaEvolution[side][owner]=-1
  2010. end
  2011. return true
  2012. end
  2013.  
  2014. def pbEnemyUseItem(item,battler)
  2015. return 0 if !@internalbattle
  2016. items=pbGetOwnerItems(battler.index)
  2017. return if !items
  2018. opponent=pbGetOwner(battler.index)
  2019. for i in 0...items.length
  2020. if items[i]==item
  2021. items.delete_at(i)
  2022. break
  2023. end
  2024. end
  2025. itemname=PBItems.getName(item)
  2026. pbDisplayBrief(_INTL("{1} used the\r\n{2}!",opponent.fullname,itemname))
  2027. if isConst?(item,PBItems,:POTION)
  2028. battler.pbRecoverHP(20,true)
  2029. pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
  2030. elsif isConst?(item,PBItems,:SUPERPOTION)
  2031. battler.pbRecoverHP(50,true)
  2032. pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
  2033. elsif isConst?(item,PBItems,:HYPERPOTION)
  2034. battler.pbRecoverHP(200,true)
  2035. pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
  2036. elsif isConst?(item,PBItems,:ULTRAPOTION)
  2037. battler.pbRecoverHP(120,true)
  2038. pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
  2039. elsif isConst?(item,PBItems,:MOOMOOMILK)
  2040. battler.pbRecoverHP(110,true)
  2041. pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
  2042. elsif isConst?(item,PBItems,:STRAWBIC)
  2043. battler.pbRecoverHP(90,true)
  2044. pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
  2045. elsif isConst?(item,PBItems,:CHOCOLATEIC)
  2046. battler.pbRecoverHP(70,true)
  2047. pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
  2048. elsif isConst?(item,PBItems,:MAXPOTION)
  2049. battler.pbRecoverHP(battler.totalhp-battler.hp,true)
  2050. pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
  2051. elsif isConst?(item,PBItems,:FULLRESTORE)
  2052. fullhp=(battler.hp==battler.totalhp)
  2053. battler.pbRecoverHP(battler.totalhp-battler.hp,true)
  2054. battler.status=0; battler.statusCount=0
  2055. battler.effects[PBEffects::Confusion]=0
  2056. if fullhp
  2057. pbDisplay(_INTL("{1} became healthy!",battler.pbThis))
  2058. else
  2059. pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
  2060. end
  2061. elsif isConst?(item,PBItems,:FULLHEAL)
  2062. battler.status=0; battler.statusCount=0
  2063. battler.effects[PBEffects::Confusion]=0
  2064. pbDisplay(_INTL("{1} became healthy!",battler.pbThis))
  2065. elsif isConst?(item,PBItems,:XATTACK)
  2066. if battler.pbCanIncreaseStatStage?(PBStats::ATTACK)
  2067. battler.pbIncreaseStat(PBStats::ATTACK,1,true)
  2068. end
  2069. elsif isConst?(item,PBItems,:XDEFEND)
  2070. if battler.pbCanIncreaseStatStage?(PBStats::DEFENSE)
  2071. battler.pbIncreaseStat(PBStats::DEFENSE,1,true)
  2072. end
  2073. elsif isConst?(item,PBItems,:XSPEED)
  2074. if battler.pbCanIncreaseStatStage?(PBStats::SPEED)
  2075. battler.pbIncreaseStat(PBStats::SPEED,1,true)
  2076. end
  2077. elsif isConst?(item,PBItems,:XSPECIAL)
  2078. if battler.pbCanIncreaseStatStage?(PBStats::SPATK)
  2079. battler.pbIncreaseStat(PBStats::SPATK,1,true)
  2080. end
  2081. elsif isConst?(item,PBItems,:XSPDEF)
  2082. if battler.pbCanIncreaseStatStage?(PBStats::SPDEF)
  2083. battler.pbIncreaseStat(PBStats::SPDEF,1,true)
  2084. end
  2085. elsif isConst?(item,PBItems,:XACCURACY)
  2086. if battler.pbCanIncreaseStatStage?(PBStats::ACCURACY)
  2087. battler.pbIncreaseStat(PBStats::ACCURACY,1,true)
  2088. end
  2089. end
  2090. end
  2091.  
  2092.  
  2093. ################################################################################
  2094. # Fleeing from battle.
  2095. ################################################################################
  2096. def pbCanRun?(idxPokemon)
  2097. return false if @opponent
  2098. thispkmn=@battlers[idxPokemon]
  2099. return true if thispkmn.hasWorkingItem(:SMOKEBALL)
  2100. return true if thispkmn.hasWorkingAbility(:RUNAWAY)
  2101. return pbCanSwitch?(idxPokemon,-1,false)
  2102. end
  2103.  
  2104. def pbRun(idxPokemon,duringBattle=false)
  2105. thispkmn=@battlers[idxPokemon]
  2106. if pbIsOpposing?(idxPokemon)
  2107. return 0 if @opponent
  2108. @choices[i][0]=5 # run
  2109. @choices[i][1]=0
  2110. @choices[i][2]=nil
  2111. return -1
  2112. end
  2113. if @opponent
  2114. if $DEBUG && Input.press?(Input::CTRL)
  2115. if pbDisplayConfirm(_INTL("Treat this battle as a win?"))
  2116. @decision=1
  2117. return 1
  2118. elsif pbDisplayConfirm(_INTL("Treat this battle as a loss?"))
  2119. @decision=2
  2120. return 1
  2121. end
  2122. elsif @internalbattle
  2123. pbDisplayPaused(_INTL("No! There's no running from a Trainer battle!"))
  2124. elsif pbDisplayConfirm(_INTL("Would you like to forfeit the match and quit now?"))
  2125. pbDisplay(_INTL("{1} forfeited the match!",self.pbPlayer.name))
  2126. @decision=3
  2127. return 1
  2128. end
  2129. return 0
  2130. end
  2131. if $DEBUG && Input.press?(Input::CTRL)
  2132. pbDisplayPaused(_INTL("Got away safely!"))
  2133. @decision=3
  2134. return 1
  2135. end
  2136. if @cantescape
  2137. pbDisplayPaused(_INTL("Can't escape!"))
  2138. return 0
  2139. end
  2140. if thispkmn.hasWorkingItem(:SMOKEBALL)
  2141. if duringBattle
  2142. pbDisplayPaused(_INTL("Got away safely!"))
  2143. else
  2144. pbDisplayPaused(_INTL("{1} fled using its {2}!",thispkmn.pbThis,PBItems.getName(thispkmn.item)))
  2145. end
  2146. @decision=3
  2147. return 1
  2148. end
  2149. if thispkmn.hasWorkingAbility(:RUNAWAY)
  2150. if duringBattle
  2151. pbDisplayPaused(_INTL("Got away safely!"))
  2152. else
  2153. pbDisplayPaused(_INTL("{1} fled using Run Away!",thispkmn.pbThis))
  2154. end
  2155. @decision=3
  2156. return 1
  2157. end
  2158. if !duringBattle && !pbCanSwitch?(idxPokemon,-1,false) # TODO: Use real messages
  2159. pbDisplayPaused(_INTL("Can't escape!"))
  2160. return 0
  2161. end
  2162. # Note: not pbSpeed, because using unmodified Speed
  2163. speedPlayer=@battlers[idxPokemon].speed
  2164. opposing=@battlers[idxPokemon].pbOppositeOpposing
  2165. if opposing.isFainted?
  2166. opposing=opposing.pbPartner
  2167. end
  2168. if !opposing.isFainted?
  2169. speedEnemy=opposing.speed
  2170. if speedPlayer>speedEnemy
  2171. rate=256
  2172. else
  2173. speedEnemy=1 if speedEnemy<=0
  2174. rate=speedPlayer*128/speedEnemy
  2175. rate+=@runCommand*30
  2176. rate&=0xFF
  2177. end
  2178. else
  2179. rate=256
  2180. end
  2181. ret=1
  2182. if pbAIRandom(256)<rate
  2183. pbDisplayPaused(_INTL("Got away safely!"))
  2184. @decision=3
  2185. else
  2186. pbDisplayPaused(_INTL("Can't escape!"))
  2187. ret=-1
  2188. end
  2189. if !duringBattle
  2190. @runCommand+=1
  2191. end
  2192. return ret
  2193. end
  2194.  
  2195. ################################################################################
  2196. # Mega Evolve battler.
  2197. ################################################################################
  2198. def pbCanMegaEvolve?(index)
  2199. return false if $game_switches[NO_MEGA_EVOLUTION]
  2200. return false if !@battlers[index].hasMega?
  2201. return false if pbBelongsToPlayer?(index) && !$PokemonGlobal.megaRing
  2202. side=(pbIsOpposing?(index)) ? 1 : 0
  2203. owner=pbGetOwnerIndex(index)
  2204. return false if @megaEvolution[side][owner]!=-1
  2205. return true
  2206. end
  2207.  
  2208. def pbRegisterMegaEvolution(index)
  2209. side=(pbIsOpposing?(index)) ? 1 : 0
  2210. owner=pbGetOwnerIndex(index)
  2211. @megaEvolution[side][owner]=index
  2212. end
  2213.  
  2214. def pbMegaEvolve(index)
  2215. return if !@battlers[index] || !@battlers[index].pokemon
  2216. return if !(@battlers[index].hasMega? rescue false)
  2217. return if (@battlers[index].isMega? rescue true)
  2218. ownername=pbGetOwner(index).fullname
  2219. ownername=pbGetOwner(index).name if pbBelongsToPlayer?(index)
  2220. if $game_switches[987]
  2221. pbDisplay(_INTL("{1}'s {2} is being corrupted!",
  2222. @battlers[index].pbThis,
  2223. PBItems.getName(@battlers[index].item),
  2224. ownername))
  2225. #### KUROTSUNE - 005 - START
  2226. elsif isConst?(@battlers[index].species, PBSpecies, :RAYQUAZA)
  2227. pbDisplay(_INTL("{1}'s fervent wish has reached {2}!",
  2228. ownername,
  2229. @battlers[index].pbThis))
  2230. #### KUROTSUNE - 005 - END
  2231. else
  2232. pbDisplay(_INTL("{1}'s {2} is reacting to {3}'s Mega Ring!",
  2233. @battlers[index].pbThis,
  2234. PBItems.getName(@battlers[index].item),
  2235. ownername))
  2236. end
  2237. pbCommonAnimation("MegaEvolution",@battlers[index],nil)
  2238. @battlers[index].pokemon.makeMega
  2239. @battlers[index].form=@battlers[index].pokemon.form
  2240. @battlers[index].pbUpdate(true)
  2241. @scene.pbChangePokemon(@battlers[index],@battlers[index].pokemon)
  2242. meganame=@battlers[index].pokemon.megaName
  2243. if !meganame || meganame==""
  2244. meganame=_INTL("Mega {1}",PBSpecies.getName(@battlers[index].pokemon.species))
  2245. end
  2246. if $game_switches[987]
  2247. pbDisplay(_INTL("{1} has corrupted into {2}!",@battlers[index].pbThis,meganame))
  2248. else
  2249. pbDisplay(_INTL("{1} has Mega Evolved into {2}!",@battlers[index].pbThis,meganame))
  2250. end
  2251. side=(pbIsOpposing?(index)) ? 1 : 0
  2252. owner=pbGetOwnerIndex(index)
  2253. @megaEvolution[side][owner]=-2
  2254. #### KUROTSUNE - 006 - START
  2255. @battlers[index].pbAbilitiesOnSwitchIn(true)
  2256. #### KUROTSUNE - 006 - END
  2257. end
  2258.  
  2259.  
  2260. ################################################################################
  2261. # Call battler.
  2262. ################################################################################
  2263. def pbCall(index)
  2264. owner=pbGetOwner(index)
  2265. pbDisplay(_INTL("{1} called {2}!",owner.name,@battlers[index].name))
  2266. pbDisplay(_INTL("{1}!",@battlers[index].name))
  2267. if @battlers[index].isShadow?
  2268. if @battlers[index].inHyperMode?
  2269. @battlers[index].pokemon.hypermode=false
  2270. @battlers[index].pokemon.adjustHeart(-300)
  2271. pbDisplay(_INTL("{1} came to its senses from the Trainer's call!",@battlers[index].pbThis))
  2272. else
  2273. pbDisplay(_INTL("But nothing happened!"))
  2274. end
  2275. elsif @battlers[index].status!=PBStatuses::SLEEP &&
  2276. @battlers[index].pbCanIncreaseStatStage?(PBStats::ACCURACY)
  2277. @battlers[index].pbIncreaseStat(PBStats::ACCURACY,1,true)
  2278. else
  2279. pbDisplay(_INTL("But nothing happened!"))
  2280. end
  2281. end
  2282.  
  2283. ################################################################################
  2284. # Gaining Experience.
  2285. ################################################################################
  2286. def pbGainEXP
  2287. return if !@internalbattle
  2288. successbegin=true
  2289. for i in 0...4 # Not ordered by priority
  2290. if !@doublebattle && pbIsDoubleBattler?(i)
  2291. @battlers[i].participants=[]
  2292. next
  2293. end
  2294. if pbIsOpposing?(i) && @battlers[i].participants.length>0 && @battlers[i].isFainted?
  2295. battlerSpecies=@battlers[i].pokemon.species
  2296. # Original species, not current species
  2297. baseexp=@battlers[i].pokemon.baseExp
  2298. level=@battlers[i].level
  2299. # First count the number of participants
  2300. partic=0
  2301. expshare=0
  2302. for j in @battlers[i].participants
  2303. next if !@party1[j] || !pbIsOwner?(0,j)
  2304. partic+=1 if @party1[j].hp>0 && !@party1[j].isEgg?
  2305. end
  2306. for j in 0...@party1.length
  2307. next if !@party1[j] || !pbIsOwner?(0,j)
  2308. expshare+=1 if @party1[j].hp>0 && !@party1[j].isEgg? &&
  2309. (isConst?(@party1[j].item,PBItems,:EXPSHARE) ||
  2310. isConst?(@party1[j].itemInitial,PBItems,:EXPSHARE))
  2311. end
  2312. # Now calculate EXP for the participants
  2313. if partic>0 || expshare>0
  2314. if !@opponent && successbegin && pbAllFainted?(@party2)
  2315. @scene.pbWildBattleSuccess
  2316. successbegin=false
  2317. end
  2318. for j in 0...@party1.length
  2319. thispoke=@party1[j]
  2320. next if !@party1[j] || !pbIsOwner?(0,j)
  2321. ispartic=0
  2322. haveexpshare=(isConst?(thispoke.item,PBItems,:EXPSHARE) ||
  2323. isConst?(thispoke.itemInitial,PBItems,:EXPSHARE)) ? 1 : 0
  2324. for k in @battlers[i].participants
  2325. ispartic=1 if k==j
  2326. end
  2327. if thispoke.hp>0 && !thispoke.isEgg?
  2328. exp=0
  2329. if expshare>0
  2330. if partic==0
  2331. exp=(level*baseexp).floor
  2332. exp=(exp/expshare).floor*haveexpshare
  2333. else
  2334. exp=(level*baseexp/2).floor
  2335. exp=(exp/partic).floor*ispartic + (exp/expshare).floor*haveexpshare
  2336. end
  2337. elsif ispartic==1
  2338. exp=(level*baseexp/partic).floor
  2339. end
  2340. exp=(exp*3/2).floor if @opponent
  2341. if USENEWEXPFORMULA # Use new (Gen 5) Exp. formula
  2342. exp=(exp/5).floor
  2343. leveladjust=(2*level+10.0)/(level+thispoke.level+10.0)
  2344. leveladjust=leveladjust**5
  2345. leveladjust=Math.sqrt(leveladjust)
  2346. exp=(exp*leveladjust).floor
  2347. exp+=1 if ispartic>0 || haveexpshare>0
  2348. else # Use old (Gen 1-4) Exp. formula
  2349. exp=(exp/7).floor
  2350. end
  2351. isOutsider=(thispoke.trainerID!=self.pbPlayer.id ||
  2352. (thispoke.language!=0 && thispoke.language!=self.pbPlayer.language))
  2353. if isOutsider
  2354. if thispoke.language!=0 && thispoke.language!=self.pbPlayer.language
  2355. exp=(exp*17/10).floor
  2356. else
  2357. exp=(exp*3/2).floor
  2358. end
  2359. end
  2360. exp=(exp*3/2).floor if isConst?(thispoke.item,PBItems,:LUCKYEGG) ||
  2361. isConst?(thispoke.itemInitial,PBItems,:LUCKYEGG)
  2362. growthrate=thispoke.growthrate
  2363. newexp=PBExperience.pbAddExperience(thispoke.exp,exp,growthrate)
  2364. exp=newexp-thispoke.exp
  2365. if exp > 0
  2366. #### KUROTSUNE - 020 - START
  2367. if isOutsider || isConst?(thispoke.item,PBItems,:LUCKYEGG)
  2368. #### KUROTSUNE - 020 - END
  2369. pbDisplayPaused(_INTL("{1} gained a boosted {2} Exp. Points!",thispoke.name,exp))
  2370. else
  2371. pbDisplayPaused(_INTL("{1} gained {2} Exp. Points!",thispoke.name,exp))
  2372. end
  2373. #Gain effort value points, using RS effort values
  2374. totalev=0
  2375. for k in 0..5
  2376. totalev+=thispoke.ev[k]
  2377. end
  2378. # Original species, not current species
  2379. evyield=@battlers[i].pokemon.evYield
  2380. for k in 0..5
  2381. evgain=evyield[k]
  2382. evgain*=2 if isConst?(thispoke.item,PBItems,:MACHOBRACE) ||
  2383. isConst?(thispoke.itemInitial,PBItems,:MACHOBRACE)
  2384. case k
  2385. when 0
  2386. if isConst?(thispoke.item,PBItems,:POWERWEIGHT)
  2387. evgain+=4
  2388. end
  2389. when 1
  2390. if isConst?(thispoke.item,PBItems,:POWERBRACER)
  2391. evgain+=4
  2392. end
  2393. when 2
  2394. if isConst?(thispoke.item,PBItems,:POWERBELT)
  2395. evgain+=4
  2396. end
  2397. when 3
  2398. if isConst?(thispoke.item,PBItems,:POWERANKLET)
  2399. evgain+=4
  2400. end
  2401. when 4
  2402. if isConst?(thispoke.item,PBItems,:POWERLENS)
  2403. evgain+=4
  2404. end
  2405. when 5
  2406. if isConst?(thispoke.item,PBItems,:POWERBAND)
  2407. evgain+=4
  2408. end
  2409. end
  2410. evgain*=2 if thispoke.pokerusStage>=1 # Infected or cured
  2411. if evgain>0
  2412. # Can't exceed overall limit
  2413. if totalev+evgain>510
  2414. evgain-=totalev+evgain-510
  2415. end
  2416. # Can't exceed stat limit
  2417. if thispoke.ev[k]+evgain>252
  2418. evgain-=thispoke.ev[k]+evgain-252
  2419. end
  2420. # Add EV gain
  2421. thispoke.ev[k]+=evgain
  2422. if thispoke.ev[k]>252
  2423. print "Single-stat EV limit 252 exceeded.\r\nStat: #{k} EV gain: #{evgain} EVs: #{thispoke.ev.inspect}"
  2424. thispoke.ev[k]=252
  2425. end
  2426. totalev+=evgain
  2427. if totalev>510
  2428. print "EV limit 510 exceeded.\r\nTotal EVs: #{totalev} EV gain: #{evgain} EVs: #{thispoke.ev.inspect}"
  2429. end
  2430. end
  2431. end
  2432. newlevel=PBExperience.pbGetLevelFromExperience(newexp,growthrate)
  2433. tempexp=0
  2434. curlevel=thispoke.level
  2435. thisPokeSpecies=thispoke.species
  2436. if newlevel<curlevel
  2437. debuginfo="#{thispoke.name}: #{thispoke.level}/#{newlevel} | #{thispoke.exp}/#{newexp} | gain: #{exp}"
  2438. raise RuntimeError.new(
  2439. _INTL("The new level ({1}) is less than the Pokémon's\r\ncurrent level ({2}), which shouldn't happen.\r\n[Debug: {3}]",
  2440. newlevel,curlevel,debuginfo))
  2441. return
  2442. end
  2443. if thispoke.respond_to?("isShadow?") && thispoke.isShadow?
  2444. thispoke.exp+=exp
  2445. else
  2446. tempexp1=thispoke.exp
  2447. tempexp2=0
  2448. # Find battler
  2449. battler=pbFindPlayerBattler(j)
  2450. loop do
  2451. #EXP Bar animation
  2452. startexp=PBExperience.pbGetStartExperience(curlevel,growthrate)
  2453. endexp=PBExperience.pbGetStartExperience(curlevel+1,growthrate)
  2454. tempexp2=(endexp<newexp) ? endexp : newexp
  2455. thispoke.exp=tempexp2
  2456. @scene.pbEXPBar(thispoke,battler,startexp,endexp,tempexp1,tempexp2)
  2457. tempexp1=tempexp2
  2458. curlevel+=1
  2459. if curlevel>newlevel
  2460. thispoke.calcStats
  2461. battler.pbUpdate(false) if battler
  2462. @scene.pbRefresh
  2463. break
  2464. end
  2465. oldtotalhp=thispoke.totalhp
  2466. oldattack=thispoke.attack
  2467. olddefense=thispoke.defense
  2468. oldspeed=thispoke.speed
  2469. oldspatk=thispoke.spatk
  2470. oldspdef=thispoke.spdef
  2471. if battler
  2472. if battler.pokemon && @internalbattle
  2473. battler.pokemon.changeHappiness("level up")
  2474. end
  2475. end
  2476. thispoke.calcStats
  2477. battler.pbUpdate(false) if battler
  2478. @scene.pbRefresh
  2479. pbDisplayPaused(_INTL("{1} grew to Level {2}!",thispoke.name,curlevel))
  2480. @scene.pbLevelUp(thispoke,battler,oldtotalhp,oldattack,
  2481. olddefense,oldspeed,oldspatk,oldspdef)
  2482. # Finding all moves learned at this level
  2483. movelist=thispoke.getMoveList
  2484. for k in movelist
  2485. if k[0]==thispoke.level # Learned a new move
  2486. pbLearnMove(j,k[1])
  2487. end
  2488. end
  2489. end
  2490. end
  2491. end
  2492. end
  2493. end
  2494. end
  2495. # Now clear the participants array
  2496. @battlers[i].participants=[]
  2497. end
  2498. end
  2499. end
  2500.  
  2501.  
  2502. ################################################################################
  2503. # Learning a move.
  2504. ################################################################################
  2505. def pbLearnMove(pkmnIndex,move)
  2506. pokemon=@party1[pkmnIndex]
  2507. return if !pokemon
  2508. pkmnname=pokemon.name
  2509. battler=pbFindPlayerBattler(pkmnIndex)
  2510. movename=PBMoves.getName(move)
  2511. for i in 0...4
  2512. if pokemon.moves[i].id==move
  2513. return
  2514. end
  2515. if pokemon.moves[i].id==0
  2516. pokemon.moves[i]=PBMove.new(move)
  2517. battler.moves[i]=PokeBattle_Move.pbFromPBMove(self,pokemon.moves[i]) if battler
  2518. pbDisplayPaused(_INTL("{1} learned {2}!",pkmnname,movename))
  2519. return
  2520. end
  2521. end
  2522. loop do
  2523. pbDisplayPaused(_INTL("{1} is trying to learn {2}.",pkmnname,movename))
  2524. pbDisplayPaused(_INTL("But {1} can't learn more than four moves.",pkmnname))
  2525. if pbDisplayConfirm(_INTL("Delete a move to make room for {1}?",movename))
  2526. pbDisplayPaused(_INTL("Which move should be forgotten?"))
  2527. forgetmove=@scene.pbForgetMove(pokemon,move)
  2528. if forgetmove >=0
  2529. oldmovename=PBMoves.getName(pokemon.moves[forgetmove].id)
  2530. pokemon.moves[forgetmove]=PBMove.new(move) # Replaces current/total PP
  2531. battler.moves[forgetmove]=PokeBattle_Move.pbFromPBMove(self,pokemon.moves[forgetmove]) if battler
  2532. pbDisplayPaused(_INTL("1, 2, and... ... ..."))
  2533. pbDisplayPaused(_INTL("Poof!"))
  2534. pbDisplayPaused(_INTL("{1} forgot {2}.",pkmnname,oldmovename))
  2535. pbDisplayPaused(_INTL("And..."))
  2536. pbDisplayPaused(_INTL("{1} learned {2}!",pkmnname,movename))
  2537. return
  2538. elsif pbDisplayConfirm(_INTL("Should {1} stop learning {2}?",pkmnname,movename))
  2539. pbDisplayPaused(_INTL("{1} did not learn {2}.",pkmnname,movename))
  2540. return
  2541. end
  2542. elsif pbDisplayConfirm(_INTL("Should {1} stop learning {2}?",pkmnname,movename))
  2543. pbDisplayPaused(_INTL("{1} did not learn {2}.",pkmnname,movename))
  2544. return
  2545. end
  2546. end
  2547. end
  2548.  
  2549. ################################################################################
  2550. # Abilities.
  2551. ################################################################################
  2552. def pbOnActiveAll
  2553. for i in 0...4 # Currently unfainted participants will earn EXP even if they faint afterwards
  2554. @battlers[i].pbUpdateParticipants if pbIsOpposing?(i)
  2555. @amuletcoin=true if !pbIsOpposing?(i) &&
  2556. (isConst?(@battlers[i].item,PBItems,:AMULETCOIN) ||
  2557. isConst?(@battlers[i].item,PBItems,:LUCKINCENSE))
  2558. end
  2559. for i in 0...4
  2560. if !@battlers[i].isFainted?
  2561. if @battlers[i].isShadow? && pbIsOpposing?(i)
  2562. pbCommonAnimation("Shadow",@battlers[i],nil)
  2563. pbDisplay(_INTL("Oh!\nA Shadow Pokemon!"))
  2564. end
  2565. end
  2566. end
  2567. # Weather-inducing abilities, Trace, Imposter, etc.
  2568. @usepriority=false
  2569. priority=pbPriority
  2570. for i in priority
  2571. i.pbAbilitiesOnSwitchIn(true)
  2572. end
  2573. # Check forms are correct
  2574. for i in 0...4
  2575. next if @battlers[i].isFainted?
  2576. @battlers[i].pbCheckForm
  2577. end
  2578. end
  2579.  
  2580. def pbOnActiveOne(pkmn,onlyabilities=false)
  2581. return false if pkmn.isFainted?
  2582. if !onlyabilities
  2583. for i in 0...4 # Currently unfainted participants will earn EXP even if they faint afterwards
  2584. @battlers[i].pbUpdateParticipants if pbIsOpposing?(i)
  2585. @amuletcoin=true if !pbIsOpposing?(i) &&
  2586. (isConst?(@battlers[i].item,PBItems,:AMULETCOIN) ||
  2587. isConst?(@battlers[i].item,PBItems,:LUCKINCENSE))
  2588. end
  2589. if pkmn.isShadow? && pbIsOpposing?(pkmn.index)
  2590. pbCommonAnimation("Shadow",pkmn,nil)
  2591. pbDisplay(_INTL("Oh!\nA Shadow Pokemon!"))
  2592. end
  2593. # Healing Wish
  2594. if pkmn.effects[PBEffects::HealingWish]
  2595. pkmn.pbRecoverHP(pkmn.totalhp,true)
  2596. pkmn.status=0
  2597. pkmn.statusCount=0
  2598. pbDisplayPaused(_INTL("The healing wish came true for {1}!",pkmn.pbThis(true)))
  2599. pkmn.effects[PBEffects::HealingWish]=false
  2600. end
  2601. # Lunar Dance
  2602. if pkmn.effects[PBEffects::LunarDance]
  2603. pkmn.pbRecoverHP(pkmn.totalhp,true)
  2604. pkmn.status=0
  2605. pkmn.statusCount=0
  2606. for i in 0...4
  2607. pkmn.moves[i].pp=pkmn.moves[i].totalpp
  2608. end
  2609. pbDisplayPaused(_INTL("{1} became cloaked in mystical moonlight!",pkmn.pbThis))
  2610. pkmn.effects[PBEffects::LunarDance]=false
  2611. end
  2612. # Spikes
  2613. pkmn.pbOwnSide.effects[PBEffects::Spikes]=0 if $fefieldeffect == 21 ||
  2614. $fefieldeffect == 26
  2615. if pkmn.pbOwnSide.effects[PBEffects::Spikes]>0
  2616. if !pkmn.isAirborne?
  2617. if !pkmn.hasWorkingAbility(:MAGICGUARD)
  2618. spikesdiv=[8,8,6,4][pkmn.pbOwnSide.effects[PBEffects::Spikes]]
  2619. @scene.pbDamageAnimation(pkmn,0)
  2620. pkmn.pbReduceHP([(pkmn.totalhp/spikesdiv).floor,1].max)
  2621. pbDisplayPaused(_INTL("{1} was hurt by spikes!",pkmn.pbThis))
  2622. end
  2623. end
  2624. end
  2625. pkmn.pbFaint if pkmn.isFainted?
  2626. # Stealth Rock
  2627. if pkmn.pbOwnSide.effects[PBEffects::StealthRock]
  2628. if !pkmn.hasWorkingAbility(:MAGICGUARD)
  2629. atype=getConst(PBTypes,:ROCK) || 0
  2630. if $fefieldeffect == 25
  2631. randtype = pbRandom(4)
  2632. case randtype
  2633. when 0
  2634. atype=getConst(PBTypes,:WATER) || 0
  2635. when 1
  2636. atype=getConst(PBTypes,:GRASS) || 0
  2637. when 2
  2638. atype=getConst(PBTypes,:FIRE) || 0
  2639. when 3
  2640. atype=getConst(PBTypes,:PSYCHIC) || 0
  2641. end
  2642. end
  2643. eff=PBTypes.getCombinedEffectiveness(atype,pkmn.type1,pkmn.type2)
  2644. if eff>0
  2645. if $fefieldeffect == 14 || $fefieldeffect == 23
  2646. eff = eff*2
  2647. end
  2648. @scene.pbDamageAnimation(pkmn,0)
  2649. pkmn.pbReduceHP([(pkmn.totalhp*eff/32).floor,1].max)
  2650. if $fefieldeffect == 25
  2651. pbDisplayPaused(_INTL("{1} was hurt by the crystalized stealth rocks!",pkmn.pbThis))
  2652. else
  2653. pbDisplayPaused(_INTL("{1} was hurt by stealth rocks!",pkmn.pbThis))
  2654. end
  2655. end
  2656. end
  2657. end
  2658. pkmn.pbFaint if pkmn.isFainted?
  2659. # Corrosive Field Entry
  2660. if $fefieldeffect == 10 || $fefieldeffect == 35
  2661. if !pkmn.hasWorkingAbility(:MAGICGUARD) &&
  2662. !pkmn.hasWorkingAbility(:POISONHEAL) &&
  2663. !pkmn.hasWorkingAbility(:IMMUNITY) &&
  2664. !pkmn.hasWorkingAbility(:WONDERGUARD) &&
  2665. !pkmn.hasWorkingAbility(:TOXICBOOST)
  2666. if !pkmn.isAirborne?
  2667. if !pkmn.pbHasType?(:POISON) && !pkmn.pbHasType?(:STEEL)
  2668. atype=getConst(PBTypes,:POISON) || 0
  2669. eff=PBTypes.getCombinedEffectiveness(atype,pkmn.type1,pkmn.type2)
  2670. if eff>0
  2671. eff=eff*2
  2672. @scene.pbDamageAnimation(pkmn,0)
  2673. pkmn.pbReduceHP([(pkmn.totalhp*eff/32).floor,1].max)
  2674. pbDisplayPaused(_INTL("{1} was seared by the toxic ground!",pkmn.pbThis))
  2675. end
  2676. end
  2677. end
  2678. end
  2679. end
  2680. pkmn.pbFaint if pkmn.hp<=0
  2681. # Sticky Web
  2682. if pkmn.pbOwnSide.effects[PBEffects::StickyWeb]
  2683. if !pkmn.isAirborne?
  2684. if $fefieldeffect == 15
  2685. pkmn.pbReduceStat(PBStats::SPEED, 2, true)
  2686. else
  2687. pkmn.pbReduceStat(PBStats::SPEED, 1, true)
  2688. end
  2689. end
  2690. end
  2691. # Toxic Spikes
  2692. pkmn.pbOwnSide.effects[PBEffects::ToxicSpikes]=0 if $fefieldeffect == 21 ||
  2693. $fefieldeffect == 26
  2694. if pkmn.pbOwnSide.effects[PBEffects::ToxicSpikes]>0
  2695. if !pkmn.isAirborne?
  2696. if pkmn.pbHasType?(:POISON) && $fefieldeffect != 10
  2697. pkmn.pbOwnSide.effects[PBEffects::ToxicSpikes]=0
  2698. pbDisplayPaused(_INTL("{1} absorbed the poison spikes!",pkmn.pbThis)) elsif pkmn.pbCanPoisonSpikes?
  2699. if pkmn.pbOwnSide.effects[PBEffects::ToxicSpikes]==2
  2700. pkmn.pbPoison(pkmn,true)
  2701. pbDisplayPaused(_INTL("{1} was badly poisoned!",pkmn.pbThis))
  2702. else
  2703. pkmn.pbPoison(pkmn)
  2704. pbDisplayPaused(_INTL("{1} was poisoned!",pkmn.pbThis))
  2705. end
  2706. end
  2707. end
  2708. end
  2709. end
  2710. pkmn.pbAbilityCureCheck
  2711. if pkmn.isFainted?
  2712. pbGainEXP
  2713. #pbSwitch
  2714. return false
  2715. end
  2716. #pkmn.pbAbilitiesOnSwitchIn(true)
  2717. if !onlyabilities
  2718. pkmn.pbCheckForm
  2719. pkmn.pbBerryCureCheck
  2720. end
  2721. return true
  2722. end
  2723.  
  2724. ################################################################################
  2725. # Judging.
  2726. ################################################################################
  2727. def pbJudgeCheckpoint(attacker,move=0)
  2728. end
  2729.  
  2730. def pbDecisionOnTime
  2731. count1=0
  2732. count2=0
  2733. hptotal1=0
  2734. hptotal2=0
  2735. for i in @party1
  2736. next if !i
  2737. if i.hp>0 && !i.isEgg?
  2738. count1+=1
  2739. hptotal1+=i.hp
  2740. end
  2741. end
  2742. for i in @party2
  2743. next if !i
  2744. if i.hp>0 && !i.isEgg?
  2745. count2+=1
  2746. hptotal2+=i.hp
  2747. end
  2748. end
  2749. return 1 if count1>count2 # win
  2750. return 2 if count1<count2 # loss
  2751. return 1 if hptotal1>hptotal2 # win
  2752. return 2 if hptotal1<hptotal2 # loss
  2753. return 5 # draw
  2754. end
  2755.  
  2756. def pbDecisionOnTime2
  2757. count1=0
  2758. count2=0
  2759. hptotal1=0
  2760. hptotal2=0
  2761. for i in @party1
  2762. next if !i
  2763. if i.hp>0 && !i.isEgg?
  2764. count1+=1
  2765. hptotal1+=(i.hp*100/i.totalhp)
  2766. end
  2767. end
  2768. hptotal1/=count1 if count1>0
  2769. for i in @party2
  2770. next if !i
  2771. if i.hp>0 && !i.isEgg?
  2772. count2+=1
  2773. hptotal2+=(i.hp*100/i.totalhp)
  2774. end
  2775. end
  2776. hptotal2/=count2 if count2>0
  2777. return 1 if count1>count2 # win
  2778. return 2 if count1<count2 # loss
  2779. return 1 if hptotal1>hptotal2 # win
  2780. return 2 if hptotal1<hptotal2 # loss
  2781. return 5 # draw
  2782. end
  2783.  
  2784. def pbDecisionOnDraw
  2785. return 5 # draw
  2786. end
  2787.  
  2788. def pbJudge
  2789. # PBDebug.log("[Counts: #{pbPokemonCount(@party1)}/#{pbPokemonCount(@party2)}]")
  2790. if pbAllFainted?(@party1) && pbAllFainted?(@party2)
  2791. @decision=pbDecisionOnDraw() # Draw
  2792. return
  2793. end
  2794. if pbAllFainted?(@party1)
  2795. @decision=2 # Loss
  2796. return
  2797. end
  2798. if pbAllFainted?(@party2)
  2799. @decision=1 # Win
  2800. return
  2801. end
  2802. end
  2803.  
  2804. ################################################################################
  2805. # Messages and animations.
  2806. ################################################################################
  2807. def pbApplySceneBG(sprite,filename)
  2808. @scene.pbApplyBGSprite(sprite,filename)
  2809. end
  2810.  
  2811. def pbDisplay(msg)
  2812. @scene.pbDisplayMessage(msg)
  2813. end
  2814.  
  2815. def pbDisplayPaused(msg)
  2816. @scene.pbDisplayPausedMessage(msg)
  2817. end
  2818.  
  2819. def pbDisplayBrief(msg)
  2820. @scene.pbDisplayMessage(msg,true)
  2821. end
  2822.  
  2823. def pbDisplayConfirm(msg)
  2824. @scene.pbDisplayConfirmMessage(msg)
  2825. end
  2826.  
  2827. def pbShowCommands(msg,commands,cancancel=true)
  2828. @scene.pbShowCommands(msg,commands,cancancel)
  2829. end
  2830.  
  2831. def pbAnimation(move,attacker,opponent,hitnum=0)
  2832. if @battlescene
  2833. @scene.pbAnimation(move,attacker,opponent,hitnum)
  2834. end
  2835. end
  2836.  
  2837. def pbCommonAnimation(name,attacker,opponent,hitnum=0)
  2838. if @battlescene
  2839. @scene.pbCommonAnimation(name,attacker,opponent,hitnum)
  2840. end
  2841. end
  2842.  
  2843. def pbChangeBGSprite
  2844. case $fefieldeffect
  2845. when 0 # indoor
  2846. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgIndoorA.png")
  2847. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseIndoorA.png")
  2848. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseIndoorA.png")
  2849. when 1 # electric
  2850. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgElectric.png")
  2851. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseElectric.png")
  2852. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseElectric.png")
  2853. when 2 # grassy
  2854. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgGrassy.png")
  2855. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseGrassy.png")
  2856. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseGrassy.png")
  2857. when 3 # misty
  2858. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgMisty.png")
  2859. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseMisty.png")
  2860. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseMisty.png")
  2861. when 4 # dark crystal cavern
  2862. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgDarkCrystalCavern.png")
  2863. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseDarkCrystalCavern.png")
  2864. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseDarkCrystalCavern.png")
  2865. when 5 # chess
  2866. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgChess.png")
  2867. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseChess.png")
  2868. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseChess.png")
  2869. when 6 # bigtop
  2870. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgBigtop.png")
  2871. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseBigtop.png")
  2872. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseBigtop.png")
  2873. when 7 # burning
  2874. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgVolcano.png")
  2875. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseVolcano.png")
  2876. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseVolcano.png")
  2877. when 8 # swamp
  2878. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgSwamp.png")
  2879. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseSwamp.png")
  2880. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseSwamp.png")
  2881. when 9 # rainbow
  2882. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgRainbow.png")
  2883. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseRainbow.png")
  2884. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseRainbow.png")
  2885. when 10 # corrosive
  2886. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgCorrosive.png")
  2887. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseCorrosive.png")
  2888. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseCorrosive.png")
  2889. when 11 # corrosive mist
  2890. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgCorrosiveMist.png")
  2891. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseCorrosiveMist.png")
  2892. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseCorrosiveMist.png")
  2893. when 12 # desert
  2894. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgDesert.png")
  2895. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseDesert.png")
  2896. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseDesert.png")
  2897. when 13 # icy
  2898. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgIcy.png")
  2899. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseIcy.png")
  2900. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseIcy.png")
  2901. when 14 # rocky
  2902. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgRocky.png")
  2903. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseRocky.png")
  2904. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseRocky.png")
  2905. when 15 # forest
  2906. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgForest.png")
  2907. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseForest.png")
  2908. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseForest.png")
  2909. when 16 # superheated
  2910. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgVoltop.png")
  2911. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseVoltop.png")
  2912. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseVoltop.png")
  2913. when 17 # factory
  2914. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgFactory.png")
  2915. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseFactory.png")
  2916. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseFactory.png")
  2917. when 18 # short-circuit
  2918. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgShortcircuit.png")
  2919. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseShortcircuit.png")
  2920. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseShortcircuit.png")
  2921. when 19 # wasteland
  2922. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgWasteland.png")
  2923. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseWasteland.png")
  2924. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseWasteland.png")
  2925. when 20 # ashen beach
  2926. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgAshenBeach.png")
  2927. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseAshenBeach.png")
  2928. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseAshenBeach.png")
  2929. when 21 # water surface
  2930. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgWater.png")
  2931. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseWater.png")
  2932. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseWater.png")
  2933. when 22 # underwater
  2934. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgUnderwater.png")
  2935. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseUnderwater.png")
  2936. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseUnderwater.png")
  2937. when 23 # cave
  2938. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgCave.png")
  2939. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseCave.png")
  2940. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseCave.png")
  2941. when 24 # glitch
  2942. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgGlitch.png")
  2943. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseGlitch.png")
  2944. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseGlitch.png")
  2945. when 25 # crystal cavern
  2946. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgCrystalCavern.png")
  2947. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseCrystalCavern.png")
  2948. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseCrystalCavern.png")
  2949. when 26 # murkwater surface
  2950. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgMurkwaterSurface.png")
  2951. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseMurkwaterSurface.png")
  2952. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseMurkwaterSurface.png")
  2953. when 27 # mountain
  2954. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgMountain.png")
  2955. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseMountain.png")
  2956. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseMountain.png")
  2957. when 28 # snowymountain
  2958. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgSnowyMountain.png")
  2959. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseSnowyMountain.png")
  2960. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseSnowyMountain.png")
  2961. when 29 # holy
  2962. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgRuin.png")
  2963. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseRuin.png")
  2964. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseRuin.png")
  2965. when 30 # mirror
  2966. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgMirror.png")
  2967. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseMirror.png")
  2968. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseMirror.png")
  2969. when 31 # Dimensional
  2970. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgDimensional.png")
  2971. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseDimensional.png")
  2972. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseDimensional.png")
  2973. when 32 # Angie
  2974. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgAngie.png")
  2975. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseAngie.png")
  2976. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseAngie.png")
  2977. when 33 # Psychic
  2978. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgPsychic.png")
  2979. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbasePsychic.png")
  2980. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybasePsychic.png")
  2981. when 34 # Haunted
  2982. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgHaunted.png")
  2983. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseHaunted.png")
  2984. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseHaunted.png")
  2985. when 35 # Corrupted
  2986. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgCorrupted.png")
  2987. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseCorrupted.png")
  2988. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseCorrupted.png")
  2989. when 38 # Darchlight
  2990. pbApplySceneBG("battlebg","Graphics/Battlebacks/battlebgDarchlight.png")
  2991. pbApplySceneBG("playerbase","Graphics/Battlebacks/playerbaseDarchlight.png")
  2992. pbApplySceneBG("enemybase","Graphics/Battlebacks/enemybaseDarchlight.png")
  2993. end
  2994. end
  2995.  
  2996. ################################################################################
  2997. # Battle core.
  2998. ################################################################################
  2999. def pbStartBattle(canlose=false)
  3000. begin
  3001. pbStartBattleCore(canlose)
  3002. rescue BattleAbortedException
  3003. @decision=0
  3004. @scene.pbEndBattle(@decision)
  3005. end
  3006. return @decision
  3007. end
  3008.  
  3009. def pbStartBattleCore(canlose)
  3010. if !@fullparty1 && @party1.length>MAXPARTYSIZE
  3011. raise ArgumentError.new(_INTL("Party 1 has more than {1} Pokémon.",MAXPARTYSIZE))
  3012. end
  3013. if !@fullparty2 && @party2.length>MAXPARTYSIZE
  3014. raise ArgumentError.new(_INTL("Party 2 has more than {1} Pokémon.",MAXPARTYSIZE))
  3015. end
  3016. if !@opponent
  3017. #========================
  3018. # Initialize wild Pokémon
  3019. #========================
  3020. if @party2.length==1
  3021. if @doublebattle
  3022. raise _INTL("Only two wild Pokémon are allowed in double battles")
  3023. end
  3024. wildpoke=@party2[0]
  3025. @battlers[1].pbInitialize(wildpoke,0,false)
  3026. @peer.pbOnEnteringBattle(self,wildpoke)
  3027. pbSetSeen(wildpoke)
  3028. @scene.pbStartBattle(self)
  3029. pbDisplayPaused(_INTL("Wild {1} appeared!",wildpoke.name))
  3030. elsif @party2.length==2
  3031. if !@doublebattle
  3032. raise _INTL("Only one wild Pokémon is allowed in single battles")
  3033. end
  3034. @battlers[1].pbInitialize(@party2[0],0,false)
  3035. @battlers[3].pbInitialize(@party2[1],0,false)
  3036. @peer.pbOnEnteringBattle(self,@party2[0])
  3037. @peer.pbOnEnteringBattle(self,@party2[1])
  3038. pbSetSeen(@party2[0])
  3039. pbSetSeen(@party2[1])
  3040. @scene.pbStartBattle(self)
  3041. pbDisplayPaused(_INTL("Wild {1} and\r\n{2} appeared!",
  3042. @party2[0].name,@party2[1].name))
  3043. else
  3044. raise _INTL("Only one or two wild Pokémon are allowed")
  3045. end
  3046. elsif @doublebattle
  3047. #=======================================
  3048. # Initialize opponents in double battles
  3049. #=======================================
  3050. if @opponent.is_a?(Array)
  3051. if @opponent.length==1
  3052. @opponent=@opponent[0]
  3053. elsif @opponent.length!=2
  3054. raise _INTL("Opponents with zero or more than two people are not allowed")
  3055. end
  3056. end
  3057. if @player.is_a?(Array)
  3058. if @player.length==1
  3059. @player=@player[0]
  3060. elsif @player.length!=2
  3061. raise _INTL("Player trainers with zero or more than two people are not allowed")
  3062. end
  3063. end
  3064. @scene.pbStartBattle(self)
  3065. if @opponent.is_a?(Array)
  3066. pbDisplayBrief(_INTL("{1} and {2} want to battle!",@opponent[0].fullname,@opponent[1].fullname))
  3067. sendout1=pbFindNextUnfainted(@party2,0,pbSecondPartyBegin(1))
  3068. raise _INTL("Opponent 1 has no unfainted Pokémon") if sendout1<0
  3069. sendout2=pbFindNextUnfainted(@party2,pbSecondPartyBegin(1))
  3070. raise _INTL("Opponent 2 has no unfainted Pokémon") if sendout2<0
  3071. # pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",@opponent[0].fullname,@party2[sendout1].name))
  3072. #### JERICHO - 001 - START
  3073. @battlers[1].pbInitialize(@party2[sendout1],sendout1,false)
  3074. @battlers[3].pbInitialize(@party2[sendout2],sendout2,false)
  3075. pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",@opponent[0].fullname,@battlers[1].name)) #ILLUSION
  3076. pbSendOut(1,@party2[sendout1])
  3077. pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",@opponent[1].fullname,@battlers[3].name)) #ILLUSION
  3078. #### JERICHO - 001 - END
  3079. pbSendOut(3,@party2[sendout2])
  3080. else
  3081. pbDisplayBrief(_INTL("{1}\r\nwould like to battle!",@opponent.fullname))
  3082. sendout1=pbFindNextUnfainted(@party2,0)
  3083. sendout2=pbFindNextUnfainted(@party2,sendout1+1)
  3084. if sendout1<0 || sendout2<0
  3085. raise _INTL("Opponent doesn't have two unfainted Pokémon")
  3086. end
  3087. #### JERICHO - 001 - START
  3088. @battlers[1].pbInitialize(@party2[sendout1],sendout1,false) #ILLUSION
  3089. @battlers[3].pbInitialize(@party2[sendout2],sendout2,false)
  3090. pbDisplayBrief(_INTL("{1} sent\r\nout {2} and {3}!",
  3091. @opponent.fullname,@battlers[1].name,@battlers[3].name)) #ILLUSION
  3092. #### JERICHO - 001 - END
  3093. pbSendOut(1,@party2[sendout1])
  3094. pbSendOut(3,@party2[sendout2])
  3095. end
  3096. else
  3097. #======================================
  3098. # Initialize opponent in single battles
  3099. #======================================
  3100. sendout=pbFindNextUnfainted(@party2,0)
  3101. raise _INTL("Trainer has no unfainted Pokémon") if sendout<0
  3102. if @opponent.is_a?(Array)
  3103. raise _INTL("Opponent trainer must be only one person in single battles") if @opponent.length!=1
  3104. @opponent=@opponent[0]
  3105. end
  3106. if @player.is_a?(Array)
  3107. raise _INTL("Player trainer must be only one person in single battles") if @player.length!=1
  3108. @player=@player[0]
  3109. end
  3110. trainerpoke=@party2[sendout]
  3111. @scene.pbStartBattle(self)
  3112. pbDisplayBrief(_INTL("{1}\r\nwould like to battle!",@opponent.fullname))
  3113. #### JERICHO - 001 - START
  3114. @battlers[1].pbInitialize(trainerpoke,sendout,false) #ILLUSION
  3115. pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",@opponent.fullname,@battlers[1].name))
  3116. #### JERICHO - 001 - END
  3117. pbSendOut(1,trainerpoke)
  3118. end
  3119. #=====================================
  3120. # Initialize players in double battles
  3121. #=====================================
  3122. if @doublebattle
  3123. if @player.is_a?(Array)
  3124. sendout1=pbFindNextUnfainted(@party1,0,pbSecondPartyBegin(0))
  3125. raise _INTL("Player 1 has no unfainted Pokémon") if sendout1<0
  3126. sendout2=pbFindNextUnfainted(@party1,pbSecondPartyBegin(0))
  3127. raise _INTL("Player 2 has no unfainted Pokémon") if sendout2<0
  3128. #### JERICHO - 001 - START
  3129. @battlers[0].pbInitialize(@party1[sendout1],sendout1,false) #ILLUSION
  3130. @battlers[2].pbInitialize(@party1[sendout2],sendout2,false)
  3131. pbDisplayBrief(_INTL("{1} sent\r\nout {2}! Go! {3}!",
  3132. @player[1].fullname,@battlers[2].name,@battlers[0].name))#ILLUSION
  3133. #### JERICHO - 001 - END
  3134. pbSetSeen(@party1[sendout1])
  3135. pbSetSeen(@party1[sendout2])
  3136. else
  3137. sendout1=pbFindNextUnfainted(@party1,0)
  3138. sendout2=pbFindNextUnfainted(@party1,sendout1+1)
  3139. if sendout1<0 || sendout2<0
  3140. raise _INTL("Player doesn't have two unfainted Pokémon")
  3141. end
  3142. #### JERICHO - 001 - START
  3143. @battlers[0].pbInitialize(@party1[sendout1],sendout1,false) #ILLUSION
  3144. @battlers[2].pbInitialize(@party1[sendout2],sendout2,false)
  3145. pbDisplayBrief(_INTL("Go! {1} and {2}!",@battlers[0].name,@battlers[2].name)) #ILLUSION
  3146. end
  3147. #### JERICHO - 001 - END
  3148. pbSendOut(0,@party1[sendout1])
  3149. pbSendOut(2,@party1[sendout2])
  3150. else
  3151. #====================================
  3152. # Initialize player in single battles
  3153. #====================================
  3154. sendout=pbFindNextUnfainted(@party1,0)
  3155. if sendout<0
  3156. raise _INTL("Player has no unfainted Pokémon")
  3157. end
  3158. playerpoke=@party1[sendout]
  3159. #### JERICHO - 001 - START
  3160. @battlers[0].pbInitialize(playerpoke,sendout,false) #Illusion
  3161. pbDisplayBrief(_INTL("Go! {1}!",@battlers[0].name))
  3162. #### JERICHO - 001 - END
  3163. pbSendOut(0,playerpoke)
  3164. end
  3165. #==================
  3166. # Initialize battle
  3167. #==================
  3168. if @weather==PBWeather::SUNNYDAY
  3169. pbCommonAnimation("Sunny",nil,nil)
  3170. pbDisplay(_INTL("The sunlight is strong."))
  3171. elsif @weather==PBWeather::RAINDANCE
  3172. pbCommonAnimation("Rain",nil,nil)
  3173. pbDisplay(_INTL("It is raining."))
  3174. elsif @weather==PBWeather::SANDSTORM
  3175. pbCommonAnimation("Sandstorm",nil,nil)
  3176. pbDisplay(_INTL("A sandstorm is raging."))
  3177. elsif @weather==PBWeather::HAIL
  3178. pbCommonAnimation("Hail",nil,nil)
  3179. pbDisplay(_INTL("Hail is falling."))
  3180. elsif @weather==PBWeather::STRONGWINDS
  3181. pbDisplay(_INTL("The wind is strong."))
  3182. end
  3183. # Field Effects BEGIN UPDATE
  3184. case $fefieldeffect
  3185. when 1
  3186. pbDisplay(_INTL("The terrain became electrified!"))
  3187. when 2
  3188. pbDisplay(_INTL("The The field is incredibly grassy!"))
  3189. when 3
  3190. pbDisplay(_INTL("Mist settles around the field."))
  3191. when 4
  3192. pbDisplay(_INTL("Darkness is gathering..."))
  3193. when 5
  3194. pbDisplay(_INTL("Opening variation set."))
  3195. when 6
  3196. pbDisplay(_INTL("Now presenting...!"))
  3197. when 7
  3198. pbDisplay(_INTL("The heat is intense..."))
  3199. when 8
  3200. pbDisplay(_INTL("The field is swamped."))
  3201. when 9
  3202. pbDisplay(_INTL("What does it mean?"))
  3203. when 10
  3204. pbDisplay(_INTL("The field is corrupted!"))
  3205. when 11
  3206. pbDisplay(_INTL("Corrosive mist settles on the field!"))
  3207. when 12
  3208. pbDisplay(_INTL("The field is rife with sand."))
  3209. when 13
  3210. pbDisplay(_INTL("The field is covered in ice."))
  3211. when 14
  3212. pbDisplay(_INTL("The field is littered with rocks."))
  3213. when 15
  3214. pbDisplay(_INTL("There are an abundance of trees around..."))
  3215. when 16
  3216. pbDisplay(_INTL("The Volcano's heat is intense!"))
  3217. when 17
  3218. pbDisplay(_INTL("Machines whir in the background."))
  3219. when 18
  3220. pbDisplay(_INTL("Bzzt!"))
  3221. when 19
  3222. pbDisplay(_INTL("The waste is watching..."))
  3223. when 20
  3224. pbDisplay(_INTL("Ash and sand line the field."))
  3225. when 21
  3226. pbDisplay(_INTL("The waves crash elegantly."))
  3227. when 22
  3228. pbDisplay(_INTL("Blub blub..."))
  3229. when 23
  3230. pbDisplay(_INTL("The cave is vast..."))
  3231. when 24
  3232. pbDisplay(_INTL("1n!taliz3 .b//////attl3"))
  3233. when 25
  3234. pbDisplay(_INTL("The cave is littered with crystals."))
  3235. when 26
  3236. pbDisplay(_INTL("The water is tainted..."))
  3237. when 27
  3238. pbDisplay(_INTL("High up!"))
  3239. when 28
  3240. pbDisplay(_INTL("The snow glows white on the mountain..."))
  3241. when 29
  3242. pbDisplay(_INTL("The light of Arceus shines upon us..."))
  3243. when 30
  3244. pbDisplay(_INTL("Mirror, mirror, on the field,"))
  3245. pbDisplay(_INTL("Who shalt this fractured power wield?"))
  3246. when 31
  3247. pbDisplay(_INTL("The pain of the suffering echoes loudly..."))
  3248. when 32
  3249. pbDisplay(_INTL("The rage continues..."))
  3250. when 33
  3251. pbDisplay(_INTL("The psychic energy is strong..."))
  3252. when 34
  3253. pbDisplay(_INTL("The field is haunted!"))
  3254. when 35
  3255. pbDisplay(_INTL("The cave is corrupted!"))
  3256. when 36
  3257. pbDisplay(_INTL("The field is supercharged!"))
  3258. when 38
  3259. pbDisplay(_INTL("Everlasting glow and glamour!"))
  3260. end
  3261. # END OF UPDATE
  3262. pbOnActiveAll # Abilities
  3263. @turncount=0
  3264. loop do # Now begin the battle loop
  3265. PBDebug.log("***Round #{@turncount+1}***") if $INTERNAL
  3266. if @debug && @turncount>=100
  3267. @decision=pbDecisionOnTime()
  3268. PBDebug.log("***[Undecided after 100 rounds]")
  3269. pbAbort
  3270. break
  3271. end
  3272. PBDebug.logonerr{
  3273. pbCommandPhase
  3274. }
  3275. break if @decision>0
  3276. PBDebug.logonerr{
  3277. pbAttackPhase
  3278. }
  3279. break if @decision>0
  3280. PBDebug.logonerr{
  3281. pbEndOfRoundPhase
  3282. }
  3283. break if @decision>0
  3284. @turncount+=1
  3285. end
  3286. return pbEndOfBattle(canlose)
  3287. end
  3288.  
  3289. ################################################################################
  3290. # Command phase.
  3291. ################################################################################
  3292. def pbCommandMenu(i)
  3293. return @scene.pbCommandMenu(i)
  3294. end
  3295.  
  3296. def pbItemMenu(i)
  3297. return @scene.pbItemMenu(i)
  3298. end
  3299.  
  3300. def pbAutoFightMenu(i)
  3301. return false
  3302. end
  3303.  
  3304. def pbCommandPhase
  3305. @scene.pbBeginCommandPhase
  3306. @scene.pbResetCommandIndices
  3307. for i in 0...4 # Reset choices if commands can be shown
  3308. if pbCanShowCommands?(i) || @battlers[i].isFainted?
  3309. @choices[i][0]=0
  3310. @choices[i][1]=0
  3311. @choices[i][2]=nil
  3312. @choices[i][3]=-1
  3313. else
  3314. battler=@battlers[i]
  3315. PBDebug.log("[reusing commands for #{battler.pbThis}]") unless !@doublebattle && pbIsDoubleBattler?(i)
  3316. end
  3317. end
  3318. # Reset choices to perform Mega Evolution if it wasn't done somehow
  3319. for i in 0...@megaEvolution[0].length
  3320. @megaEvolution[0][i]=-1 if @megaEvolution[0][i]>=0
  3321. end
  3322. for i in 0...@megaEvolution[1].length
  3323. @megaEvolution[1][i]=-1 if @megaEvolution[1][i]>=0
  3324. end
  3325. for i in 0...4
  3326. break if @decision!=0
  3327. next if @choices[i][0]!=0
  3328. if !pbOwnedByPlayer?(i) || @controlPlayer
  3329. if !@battlers[i].isFainted? && pbCanShowCommands?(i)
  3330. @scene.pbChooseEnemyCommand(i)
  3331. end
  3332. else
  3333. commandDone=false
  3334. commandEnd=false
  3335. if pbCanShowCommands?(i)
  3336. loop do
  3337. cmd=pbCommandMenu(i)
  3338. if cmd==0 # Fight
  3339. if pbCanShowFightMenu?(i)
  3340. commandDone=true if pbAutoFightMenu(i)
  3341. until commandDone
  3342. index=@scene.pbFightMenu(i)
  3343. if index<0
  3344. side=(pbIsOpposing?(i)) ? 1 : 0
  3345. owner=pbGetOwnerIndex(i)
  3346. if @megaEvolution[side][owner]==i
  3347. @megaEvolution[side][owner]=-1
  3348. end
  3349. break
  3350. end
  3351. next if !pbRegisterMove(i,index)
  3352. if @doublebattle
  3353. thismove=@battlers[i].moves[index]
  3354. target=@battlers[i].pbTarget(thismove)
  3355. if target==PBTargets::SingleNonUser # single non-user
  3356. target=@scene.pbChooseTarget(i)
  3357. next if target<0
  3358. pbRegisterTarget(i,target)
  3359. elsif target==PBTargets::UserOrPartner # Acupressure
  3360. target=@scene.pbChooseTarget(i)
  3361. next if target<0 || (target&1)==1
  3362. pbRegisterTarget(i,target)
  3363. end
  3364. end
  3365. commandDone=true
  3366. end
  3367. else
  3368. pbAutoChooseMove(i)
  3369. commandDone=true
  3370. end
  3371. elsif cmd==1 # Bag
  3372. if !@internalbattle
  3373. if pbOwnedByPlayer?(i)
  3374. pbDisplay(_INTL("Items can't be used here."))
  3375. end
  3376. else
  3377. item=pbItemMenu(i)
  3378. if item[0]>0
  3379. if pbRegisterItem(i,item[0],item[1])
  3380. commandDone=true
  3381. end
  3382. end
  3383. end
  3384. elsif cmd==2 # Pokémon
  3385. pkmn=pbSwitchPlayer(i,false,true)
  3386. if pkmn>=0
  3387. commandDone=true if pbRegisterSwitch(i,pkmn)
  3388. end
  3389. elsif cmd==3 # Run
  3390. run=pbRun(i)
  3391. if run>0
  3392. commandDone=true
  3393. return
  3394. elsif run<0
  3395. commandDone=true
  3396. side=(pbIsOpposing?(i)) ? 1 : 0
  3397. owner=pbGetOwnerIndex(i)
  3398. if @megaEvolution[side][owner]==i
  3399. @megaEvolution[side][owner]=-1
  3400. end
  3401. end
  3402. elsif cmd==4 # Call
  3403. thispkmn=@battlers[i]
  3404. @choices[i][0]=4 # "Call Pokémon"
  3405. @choices[i][1]=0
  3406. @choices[i][2]=nil
  3407. side=(pbIsOpposing?(i)) ? 1 : 0
  3408. owner=pbGetOwnerIndex(i)
  3409. if @megaEvolution[side][owner]==i
  3410. @megaEvolution[side][owner]=-1
  3411. end
  3412. commandDone=true
  3413. elsif cmd==-1 # Go back to first battler's choice
  3414. @megaEvolution[0][0]=-1 if @megaEvolution[0][0]>=0
  3415. @megaEvolution[1][0]=-1 if @megaEvolution[1][0]>=0
  3416. # Restore the item the player's first Pokémon was due to use
  3417. if @choices[0][0]==3 && $PokemonBag && $PokemonBag.pbCanStore?(@choices[0][1])
  3418. $PokemonBag.pbStoreItem(@choices[0][1])
  3419. end
  3420. pbCommandPhase
  3421. return
  3422. end
  3423. break if commandDone
  3424. end
  3425. end
  3426. end
  3427. end
  3428. end
  3429.  
  3430. ################################################################################
  3431. # Attack phase.
  3432. ################################################################################
  3433. def pbAttackPhase
  3434. @scene.pbBeginAttackPhase
  3435. for i in 0...4
  3436. @successStates[i].clear
  3437. if @choices[i][0]!=1 && @choices[i][0]!=2
  3438. @battlers[i].effects[PBEffects::DestinyBond]=false
  3439. @battlers[i].effects[PBEffects::Grudge]=false
  3440. end
  3441. @battlers[i].turncount+=1 if !@battlers[i].isFainted?
  3442. @battlers[i].effects[PBEffects::Rage]=false if !pbChoseMove?(i,:RAGE)
  3443. end
  3444. # Calculate priority at this time
  3445. @usepriority=false
  3446. priority=pbPriority
  3447. # Mega Evolution
  3448. for i in priority
  3449. next if @choices[i.index][0]!=1
  3450. side=(pbIsOpposing?(i.index)) ? 1 : 0
  3451. owner=pbGetOwnerIndex(i.index)
  3452. if @megaEvolution[side][owner]==i.index
  3453. pbMegaEvolve(i.index)
  3454. end
  3455. end
  3456. # Call at Pokémon
  3457. for i in priority
  3458. if @choices[i.index][0]==4
  3459. pbCall(i.index)
  3460. end
  3461. end
  3462. # Switch out Pokémon
  3463. @switching=true
  3464. switched=[]
  3465. for i in priority
  3466. if @choices[i.index][0]==2
  3467. index=@choices[i.index][1] # party position of Pokémon to switch to
  3468. self.lastMoveUser=i.index
  3469. if !pbOwnedByPlayer?(i.index)
  3470. owner=pbGetOwner(i.index)
  3471. pbDisplayBrief(_INTL("{1} withdrew {2}!",owner.fullname,i.name))
  3472. else
  3473. pbDisplayBrief(_INTL("{1}, that's enough!\r\nCome back!",i.name))
  3474. end
  3475. for j in priority
  3476. next if !i.pbIsOpposing?(j.index)
  3477. # if Pursuit and this target ("i") was chosen
  3478. if pbChoseMoveFunctionCode?(j.index,0x88) &&
  3479. !j.effects[PBEffects::Pursuit] &&
  3480. (@choices[j.index][3]==-1 || @choices[j.index][3]==i.index)
  3481. if j.status!=PBStatuses::SLEEP &&
  3482. j.status!=PBStatuses::FROZEN &&
  3483. (!j.hasWorkingAbility(:TRUANT) || !j.effects[PBEffects::Truant])
  3484. j.pbUseMove(@choices[j.index])
  3485. j.effects[PBEffects::Pursuit]=true
  3486. # UseMove calls pbGainEXP as appropriate
  3487. @switching=false
  3488. return if @decision>0
  3489. end
  3490. end
  3491. break if i.isFainted?
  3492. end
  3493. if !pbRecallAndReplace(i.index,index)
  3494. # If a forced switch somehow occurs here in single battles
  3495. # the attack phase now ends
  3496. if !@doublebattle
  3497. @switching=false
  3498. return
  3499. end
  3500. else
  3501. switched.push(i.index)
  3502. end
  3503. end
  3504. end
  3505. if switched.length>0
  3506. for i in priority
  3507. i.pbAbilitiesOnSwitchIn(true) if switched.include?(i.index)
  3508. end
  3509. end
  3510. @switching=false
  3511. # Use items
  3512. for i in priority
  3513. if pbIsOpposing?(i.index) && @choices[i.index][0]==3
  3514. pbEnemyUseItem(@choices[i.index][1],i)
  3515. i.itemUsed = true
  3516. elsif @choices[i.index][0]==3
  3517. # Player use item
  3518. item=@choices[i.index][1]
  3519. if item>0
  3520. usetype=$ItemData[item][ITEMBATTLEUSE]
  3521. if usetype==1 || usetype==3
  3522. if @choices[i.index][2]>=0
  3523. pbUseItemOnPokemon(item,@choices[i.index][2],i,@scene)
  3524. i.itemUsed = true
  3525. end
  3526. elsif usetype==2 || usetype==4
  3527. if !ItemHandlers.hasUseInBattle(item) # Poké Ball/Poké Doll used already
  3528. pbUseItemOnBattler(item,@choices[i.index][2],i,@scene)
  3529. i.itemUsed = true
  3530. end
  3531. end
  3532. end
  3533. end
  3534. end
  3535. #### KUROTSUNE - 014 - START
  3536. if @field.effects[PBEffects::WonderRoom] > 0
  3537. for i in @battlers
  3538. if !i.wonderroom
  3539. i.pbSwapDefenses
  3540. end
  3541. end
  3542. end
  3543. #### KUROTSUNE - 014 - END
  3544. symbiosis = pbSymbiosisCheck(priority)
  3545. # Use Attacks
  3546. for i in priority
  3547. if pbChoseMoveFunctionCode?(i.index,0x115) # Focus Punch
  3548. pbCommonAnimation("FocusPunch",i,nil)
  3549. pbDisplay(_INTL("{1} is tightening its focus!",i.pbThis))
  3550. end
  3551. end
  3552. for i in priority
  3553. i.pbProcessTurn(@choices[i.index])
  3554. if i.effects[PBEffects::Round]
  3555. i.pbPartner.selectedMove = 297
  3556. end
  3557.  
  3558. if symbiosis
  3559. for s in symbiosis
  3560. if s.item == 0 && s.pbPartner.item
  3561. pbDisplay(_INTL("{1} received {2}'s {3} from symbiosis! ",s.pbThis, s.pbPartner.pbThis, PBItems.getName(s.pbPartner.item)))
  3562. s.item = s.pbPartner.item
  3563. s.pokemon.itemInitial = s.pbPartner.item
  3564. s.pbPartner.pokemon.itemInitial = 0
  3565. s.pbPartner.item=0
  3566. end
  3567. end
  3568. end
  3569. return if @decision>0
  3570. end
  3571. pbWait(20)
  3572. end
  3573.  
  3574. # Checks if anyone is eligible to receive an item through symbiosis
  3575. def pbSymbiosisCheck(battlers)
  3576. result = Array.new
  3577. count = 0
  3578. for i in battlers
  3579. if i.item != 0 && i.pokemon.itemInitial != 0 &&
  3580. i.pbPartner.item != 0 && i.pbPartner.pokemon.itemInitial != 0 &&
  3581. i.pbPartner.hasWorkingAbility(:SYMBIOSIS)
  3582. result[count] = i
  3583. count += 1
  3584. end
  3585. end
  3586. if result.any?
  3587. return result
  3588. else
  3589. return false
  3590. end
  3591. end
  3592.  
  3593.  
  3594. ################################################################################
  3595. # End of round.
  3596. ################################################################################
  3597. def pbEndOfRoundPhase
  3598. for i in 0...4
  3599. @battlers[i].effects[PBEffects::Roost]=false
  3600. @battlers[i].effects[PBEffects::Protect]=false
  3601. @battlers[i].effects[PBEffects::KingsShield]=false # add this line
  3602. @battlers[i].effects[PBEffects::ProtectNegation]=false
  3603. @battlers[i].effects[PBEffects::Endure]=false
  3604. @battlers[i].effects[PBEffects::HyperBeam]-=1 if @battlers[i].effects[PBEffects::HyperBeam]>0
  3605. @battlers[i].effects[PBEffects::SpikyShield]=false
  3606. #### KUROTSUNE - 023 - START
  3607. @battlers[i].effects[PBEffects::Powder] = false
  3608. #### KUROTSUNE - 023 - END
  3609. #### KUROTSUNE - 032 - START
  3610. @battlers[i].effects[PBEffects::MeFirst] = false
  3611. #### KUROTSUNE - 032 - END
  3612. @battlers[i].itemUsed = false
  3613. end
  3614. #### KUROTSUNE - 013 - START
  3615. @field.effects[PBEffects::IonDeluge] = false
  3616. #### KUROTSUNE - 013 - END
  3617. for i in 0...2
  3618. sides[i].effects[PBEffects::QuickGuard]=false
  3619. sides[i].effects[PBEffects::WideGuard]=false
  3620. sides[i].effects[PBEffects::MatBlock]=false
  3621. end
  3622. @usepriority=false # recalculate priority
  3623. priority=pbPriority(true) # Ignoring Quick Claw here
  3624. if @trickroom > 0
  3625. @trickroom=@trickroom-1
  3626. if @trickroom == 0
  3627. Kernel.pbMessage("The twisted dimensions returned to normal!")
  3628. end
  3629. end
  3630. #### KUROTSUNE - 014 - START
  3631. if @field.effects[PBEffects::WonderRoom] > 0
  3632. @field.effects[PBEffects::WonderRoom] -= 1
  3633. if @field.effects[PBEffects::WonderRoom] == 0
  3634. for i in @battlers
  3635. if i.wonderroom
  3636. i.pbSwapDefenses
  3637. end
  3638. end
  3639. Kernel.pbMessage("Wonder Room wore off, and the Defense and Sp. Def stats returned to normal!")
  3640. end
  3641. end
  3642. #### KUROTSUNE - 014 - END
  3643. priority=pbPriority(true) # Ignoring Quick Claw here
  3644. #### AME - 003 - START
  3645. # Field Effects
  3646. for i in priority
  3647. next if i.isFainted?
  3648. case $fefieldeffect
  3649. when 2 # Grassy Field
  3650. next if i.hp<=0
  3651. if !i.isAirborne?
  3652. if i.effects[PBEffects::HealBlock]==0 && i.totalhp != i.hp
  3653. hpgain=(i.totalhp/16).floor
  3654. hpgain=(hpgain*1.3).floor if isConst?(i.item,PBItems,:BIGROOT)
  3655. hpgain=i.pbRecoverHP(hpgain,true)
  3656. pbDisplayPaused(_INTL("The grassy terrain healed {1}.",i.pbThis))
  3657. end
  3658. end
  3659. when 38 # Darchlight
  3660. next if i.hp<=0 || !i.pbHasType?(:GRASS)
  3661. if !i.isAirborne?
  3662. if i.effects[PBEffects::HealBlock]==0 && i.totalhp != i.hp
  3663. hpgain=(i.totalhp/16).floor
  3664. hpgain=(hpgain*1.3).floor if isConst?(i.item,PBItems,:BIGROOT)
  3665. hpgain=i.pbRecoverHP(hpgain,true)
  3666. pbDisplayPaused(_INTL("The field healed {1}.",i.pbThis))
  3667. end
  3668. end
  3669. when 7 # Volcanic
  3670. next if i.hp<=0
  3671. if !i.isAirborne?
  3672. if isConst?(i.ability,PBAbilities,:FLASHFIRE)
  3673. if !i.effects[PBEffects::FlashFire]
  3674. i.effects[PBEffects::FlashFire]=true
  3675. pbDisplayPaused(_INTL("{1}'s {2} raised its Fire power!",
  3676. i.pbThis,PBAbilities.getName(i.ability)))
  3677. end
  3678. end
  3679. if !i.pbHasType?(:FIRE) &&
  3680. !isConst?(i.ability,PBAbilities,:FLAREBOOST) &&
  3681. !isConst?(i.ability,PBAbilities,:WATERVEIL) &&
  3682. !isConst?(i.ability,PBAbilities,:FLASHFIRE) &&
  3683. !isConst?(i.ability,PBAbilities,:HEATPROOF) &&
  3684. !isConst?(i.ability,PBAbilities,:MAGMAARMOR) &&
  3685. !isConst?(i.ability,PBAbilities,:FLAMEBODY) &&
  3686. !isConst?(i.ability,PBAbilities,:MAGICGUARD) &&
  3687. ![0xCA,0xCB].include?(PBMoveData.new(i.effects[PBEffects::TwoTurnAttack]).function) # Dig, Dive
  3688. atype=getConst(PBTypes,:FIRE) || 0
  3689. eff=PBTypes.getCombinedEffectiveness(atype,i.type1,i.type2)
  3690. if eff>0
  3691. @scene.pbDamageAnimation(i,0)
  3692. if isConst?(i.ability,PBAbilities,:LEAFGUARD) ||
  3693. isConst?(i.ability,PBAbilities,:ICEBODY) ||
  3694. isConst?(i.ability,PBAbilities,:GRASSPELT)
  3695. eff = eff*2
  3696. end
  3697. i.pbReduceHP([(i.totalhp*eff/32).floor,1].max)
  3698. pbDisplayPaused(_INTL("{1} was burned by the field!",i.pbThis))
  3699. if i.hp<=0
  3700. return if !i.pbFaint
  3701. end
  3702. end
  3703. end
  3704. end
  3705. when 35 # CorroCave
  3706. next if i.hp<=0
  3707. if i.hasWorkingAbility(:GRASSPELT)
  3708. @scene.pbDamageAnimation(i,0)
  3709. i.pbReduceHP((i.totalhp/8).floor)
  3710. pbDisplay(_INTL("{1}'s Pelt was toxified!",i.pbThis)) if hpgain>0
  3711. if i.hp<=0
  3712. return if !i.pbFaint
  3713. end
  3714. end
  3715. if i.hasWorkingAbility(:POISONHEAL)
  3716. if !i.isAirborne?
  3717. if i.effects[PBEffects::HealBlock]==0
  3718. if i.hp<i.totalhp
  3719. pbCommonAnimation("Poison",i,nil)
  3720. i.pbRecoverHP((i.totalhp/8).floor,true)
  3721. pbDisplay(_INTL("{1} was healed by poison!",i.pbThis))
  3722. end
  3723. end
  3724. end
  3725. end
  3726. when 35 # CorroCave
  3727. if i.pbCanPoison?(false)
  3728. i.pbPoison(i)
  3729. pbDisplayPaused(_INTL("{1} was poisoned by the corroded mist!",i.pbThis))
  3730. end
  3731. if isConst?(i.ability,PBAbilities,:POISONHEAL)
  3732. if i.effects[PBEffects::HealBlock]==0
  3733. if i.hp<i.totalhp
  3734. pbCommonAnimation("Poison",i,nil)
  3735. i.pbRecoverHP((i.totalhp/8).floor,true)
  3736. pbDisplay(_INTL("{1} was healed by poison!",i.pbThis))
  3737. end
  3738. end
  3739. end
  3740. when 15 # Forest Field
  3741. next if i.hp<=0
  3742. if i.hasWorkingAbility(:SAPSIPPER) && i.effects[PBEffects::HealBlock]==0
  3743. hpgain=(i.totalhp/16).floor
  3744. hpgain=i.pbRecoverHP(hpgain,true)
  3745. pbDisplay(_INTL("{1} drank tree sap to recover!",i.pbThis)) if hpgain>0
  3746. end
  3747. when 18 # Shortcircuit Field
  3748. next if i.hp<=0
  3749. if i.hasWorkingAbility(:VOLTABSORB) && i.effects[PBEffects::HealBlock]==0
  3750. hpgain=(i.totalhp/16).floor
  3751. hpgain=i.pbRecoverHP(hpgain,true)
  3752. pbDisplay(_INTL("{1} absorbed stray electricity!",i.pbThis)) if hpgain>0
  3753. end
  3754. when 19 # Wasteland
  3755. if i.hasWorkingAbility(:POISONHEAL)
  3756. if !i.isAirborne?
  3757. if i.effects[PBEffects::HealBlock]==0
  3758. if i.hp<i.totalhp
  3759. pbCommonAnimation("Poison",i,nil)
  3760. i.pbRecoverHP((i.totalhp/8).floor,true)
  3761. pbDisplay(_INTL("{1} was healed by poison!",i.pbThis))
  3762. end
  3763. end
  3764. end
  3765. end
  3766. when 21 # Water Surface
  3767. next if i.hp<=0
  3768. if i.hasWorkingAbility(:WATERABSORB) && i.effects[PBEffects::HealBlock]==0
  3769. hpgain=(i.totalhp/16).floor
  3770. hpgain=i.pbRecoverHP(hpgain,true)
  3771. pbDisplay(_INTL("{1} absorbed some of the water!",i.pbThis)) if hpgain>0
  3772. end
  3773. when 22# Underwater
  3774. next if i.hp<=0
  3775. if !i.pbHasType?(:WATER) &&
  3776. !i.hasWorkingAbility(:SWIFTSWIM) &&
  3777. !i.hasWorkingAbility(:MAGICGUARD)
  3778. atype=getConst(PBTypes,:WATER) || 0
  3779. eff=PBTypes.getCombinedEffectiveness(atype,i.type1,i.type2)
  3780. if eff>4
  3781. @scene.pbDamageAnimation(i,0)
  3782. if i.hasWorkingAbility(:FLAMEBODY) ||
  3783. i.hasWorkingAbility(:MAGMAARMOR)
  3784. eff = eff*2
  3785. end
  3786. i.pbReduceHP([(i.totalhp*eff/32).floor,1].max)
  3787. pbDisplayPaused(_INTL("{1} struggled in the water!",i.pbThis))
  3788. if i.hp<=0
  3789. return if !i.pbFaint
  3790. end
  3791. end
  3792. end
  3793. when 26 # Murkwater Surface
  3794. if !i.pbHasType?(:STEEL) && !i.pbHasType?(:POISON) &&
  3795. !i.hasWorkingAbility(:POISONHEAL) &&
  3796. !i.hasWorkingAbility(:MAGICGUARD) &&
  3797. !i.hasWorkingAbility(:WONDERGUARD) &&
  3798. !i.hasWorkingAbility(:TOXICBOOST) &&
  3799. !i.hasWorkingAbility(:IMMUNITY)
  3800. atype=getConst(PBTypes,:POISON) || 0
  3801. eff=PBTypes.getCombinedEffectiveness(atype,i.type1,i.type2)
  3802. if i.hasWorkingAbility(:FLAMEBODY) ||
  3803. i.hasWorkingAbility(:MAGMAARMOR) ||
  3804. i.hasWorkingAbility(:DRYSKIN) ||
  3805. i.hasWorkingAbility(:WATERABSORB)
  3806. eff = eff*2
  3807. end
  3808. if PBMoveData.new(i.effects[PBEffects::TwoTurnAttack]).function==0xCB # Dive
  3809. @scene.pbDamageAnimation(i,0)
  3810. i.pbReduceHP([(i.totalhp*eff/8).floor,1].max)
  3811. pbDisplayPaused(_INTL("{1} suffocated underneath the toxic water!",i.pbThis))
  3812. else
  3813. if !i.isAirborne?
  3814. @scene.pbDamageAnimation(i,0)
  3815. i.pbReduceHP([(i.totalhp*eff/32).floor,1].max)
  3816. pbDisplayPaused(_INTL("{1} was hurt by the toxic water!",i.pbThis))
  3817. end
  3818. end
  3819. end
  3820. if i.isFainted?
  3821. return if !i.pbFaint
  3822. end
  3823. if i.hasWorkingAbility(:POISONHEAL)
  3824. if !i.isAirborne?
  3825. if i.effects[PBEffects::HealBlock]==0
  3826. if i.hp<i.totalhp
  3827. pbCommonAnimation("Poison",i,nil)
  3828. i.pbRecoverHP((i.totalhp/8).floor,true)
  3829. pbDisplay(_INTL("{1} was healed by poisoned water!",i.pbThis))
  3830. end
  3831. end
  3832. end
  3833. end
  3834. if i.pbHasType?(:POISON) && (i.hasWorkingAbility(:DRYSKIN) ||
  3835. i.hasWorkingAbility(:WATERABSORB))
  3836. if !i.isAirborne?
  3837. if i.effects[PBEffects::HealBlock]==0
  3838. if i.hp<i.totalhp
  3839. pbCommonAnimation("Poison",i,nil)
  3840. i.pbRecoverHP((i.totalhp/8).floor,true)
  3841. pbDisplay(_INTL("{1} was healed by the poisoned water!",i.pbThis))
  3842. end
  3843. end
  3844. end
  3845. end
  3846. end
  3847. end
  3848. # End Field stuff
  3849. #### AME - 003 - END # Weather
  3850. if $fefieldeffect != 22
  3851. if @weather != PBWeather::HAIL && $fefieldeffect == 99
  3852. $fecounter = 0
  3853. end
  3854. case @weather
  3855. when PBWeather::SUNNYDAY
  3856. @weatherduration=@weatherduration-1 if @weatherduration>0
  3857. if @weatherduration==0
  3858. pbDisplay(_INTL("The sunlight faded."))
  3859. @weather=0
  3860. else
  3861. pbCommonAnimation("Sunny",nil,nil)
  3862. # pbDisplay(_INTL("The sunlight is strong."));
  3863. for i in priority
  3864. if i.hasWorkingAbility(:SOLARPOWER)
  3865. pbDisplay(_INTL("{1} was hurt by the sunlight!",i.pbThis))
  3866. @scene.pbDamageAnimation(i,0)
  3867. i.pbReduceHP((i.totalhp/8).floor)
  3868. if i.isFainted?
  3869. return if !i.pbFaint
  3870. end
  3871. end
  3872. end
  3873. end
  3874. when PBWeather::RAINDANCE
  3875. @weatherduration=@weatherduration-1 if @weatherduration>0
  3876. if @weatherduration==0
  3877. pbDisplay(_INTL("The rain stopped."))
  3878. @weather=0
  3879. else
  3880. pbCommonAnimation("Rain",nil,nil)
  3881. # pbDisplay(_INTL("Rain continues to fall."));
  3882. if $fefieldeffect == 7 # Burning Field
  3883. if $fefieldeffect == $febackup
  3884. $fefieldeffect = 0
  3885. else
  3886. $fefieldeffect = $febackup
  3887. end
  3888. pbChangeBGSprite
  3889. pbDisplay(_INTL("The rain snuffed out the flame!"));
  3890. end
  3891. end
  3892. when PBWeather::SANDSTORM
  3893. @weatherduration=@weatherduration-1 if @weatherduration>0
  3894. if @weatherduration==0
  3895. pbDisplay(_INTL("The sandstorm subsided."))
  3896. @weather=0
  3897. else
  3898. pbCommonAnimation("Sandstorm",nil,nil)
  3899. # pbDisplay(_INTL("The sandstorm rages."))
  3900. if $fefieldeffect == 7 # Burning Field
  3901. if $fefieldeffect == $febackup
  3902. $fefieldeffect = 0
  3903. else
  3904. $fefieldeffect = $febackup
  3905. end
  3906. pbChangeBGSprite
  3907. pbDisplay(_INTL("The sand snuffed out the flame!"));
  3908. end
  3909. if pbWeather==PBWeather::SANDSTORM
  3910. for i in priority
  3911. next if i.isFainted?
  3912. if !i.pbHasType?(:GROUND) && !i.pbHasType?(:ROCK) && !i.pbHasType?(:STEEL) &&
  3913. !i.hasWorkingAbility(:SANDVEIL) &&
  3914. !i.hasWorkingAbility(:SANDRUSH) &&
  3915. !i.hasWorkingAbility(:SANDFORCE) &&
  3916. !i.hasWorkingAbility(:MAGICGUARD) &&
  3917. !isConst?(i.item,PBItems,:SAFETYGOGGLES) &&
  3918. !i.hasWorkingAbility(:OVERCOAT) &&
  3919. ![0xCA,0xCB].include?(PBMoveData.new(i.effects[PBEffects::TwoTurnAttack]).function) # Dig, Dive
  3920. pbDisplay(_INTL("{1} is buffeted by the sandstorm!",i.pbThis))
  3921. @scene.pbDamageAnimation(i,0)
  3922. i.pbReduceHP((i.totalhp/16).floor)
  3923. if i.isFainted?
  3924. return if !i.pbFaint
  3925. end
  3926. end
  3927. end
  3928. end
  3929. end
  3930. when PBWeather::HAIL
  3931. @weatherduration=@weatherduration-1 if @weatherduration>0
  3932. if @weatherduration==0
  3933. pbDisplay(_INTL("The hail stopped."))
  3934. @weather=0
  3935. elsif $fefieldeffect == 16
  3936. pbDisplay(_INTL("The hail melted away."))
  3937. @weather=0
  3938. else
  3939. pbCommonAnimation("Hail",nil,nil)
  3940. # pbDisplay(_INTL("Hail continues to fall."))
  3941. if pbWeather==PBWeather::HAIL
  3942. for i in priority
  3943. next if i.isFainted?
  3944. if !i.pbHasType?(:ICE) &&
  3945. !i.hasWorkingAbility(:ICEBODY) &&
  3946. !i.hasWorkingAbility(:SNOWCLOAK) &&
  3947. !i.hasWorkingAbility(:MAGICGUARD) &&
  3948. !isConst?(i.item,PBItems,:SAFETYGOGGLES) &&
  3949. !i.hasWorkingAbility(:OVERCOAT) &&
  3950. ![0xCA,0xCB].include?(PBMoveData.new(i.effects[PBEffects::TwoTurnAttack]).function) # Dig, Dive
  3951. pbDisplay(_INTL("{1} is buffeted by the hail!",i.pbThis))
  3952. @scene.pbDamageAnimation(i,0)
  3953. i.pbReduceHP((i.totalhp/16).floor)
  3954. if i.isFainted?
  3955. return if !i.pbFaint
  3956. end
  3957. end
  3958. end
  3959. if $fefieldeffect == 27
  3960. $fecounter+=1
  3961. if $fecounter == 3
  3962. $fecounter = 0
  3963. $fefieldeffect = 28
  3964. pbChangeBGSprite
  3965. pbDisplay(_INTL("The mountain was covered in snow!"))
  3966. end
  3967. end
  3968. end
  3969. end
  3970. end
  3971. end
  3972. # Shadow Sky weather
  3973. if isConst?(@weather,PBWeather,:SHADOWSKY)
  3974. @weatherduration=@weatherduration-1 if @weatherduration>0
  3975. if @weatherduration==0
  3976. pbDisplay(_INTL("The shadow sky faded."))
  3977. @weather=0
  3978. else
  3979. pbCommonAnimation("ShadowSky",nil,nil)
  3980. # pbDisplay(_INTL("The shadow sky continues."));
  3981. if isConst?(pbWeather,PBWeather,:SHADOWSKY)
  3982. for i in priority
  3983. next if i.isFainted?
  3984. if !i.isShadow?
  3985. pbDisplay(_INTL("{1} was hurt by the shadow sky!",i.pbThis))
  3986. @scene.pbDamageAnimation(i,0)
  3987. i.pbReduceHP((i.totalhp/16).floor)
  3988. if i.isFainted?
  3989. return if !i.pbFaint
  3990. end
  3991. end
  3992. end
  3993. end
  3994. end
  3995. end
  3996. # Future Sight/Doom Desire
  3997. for i in battlers # not priority
  3998. next if i.isFainted?
  3999. if i.effects[PBEffects::FutureSight]>0
  4000. i.effects[PBEffects::FutureSight]-=1
  4001. if i.effects[PBEffects::FutureSight]==0
  4002. move=PokeBattle_Move.pbFromPBMove(self,PBMove.new(i.effects[PBEffects::FutureSightMove]))
  4003. pbDisplay(_INTL("{1} took the {2} attack!",i.pbThis,move.name))
  4004. moveuser=@battlers[i.effects[PBEffects::FutureSightUser]]
  4005. if i.isFainted? || move.pbAccuracyCheck(moveuser,i)
  4006. damage=((i.effects[PBEffects::FutureSightDamage]*85)/100).floor
  4007. damage=1 if damage<1
  4008. i.damagestate.reset
  4009. pbCommonAnimation("FutureSight",i,nil)
  4010. move.pbReduceHPDamage(damage,nil,i)
  4011. else
  4012. pbDisplay(_INTL("But it failed!"))
  4013. end
  4014. i.effects[PBEffects::FutureSight]=0
  4015. i.effects[PBEffects::FutureSightMove]=0
  4016. i.effects[PBEffects::FutureSightDamage]=0
  4017. i.effects[PBEffects::FutureSightUser]=-1
  4018. if i.isFainted?
  4019. return if !i.pbFaint
  4020. next
  4021. end
  4022. end
  4023. end
  4024. end
  4025. for i in priority
  4026. next if i.isFainted?
  4027. # Rain Dish
  4028. if pbWeather==PBWeather::RAINDANCE && i.hasWorkingAbility(:RAINDISH)
  4029. hpgain=i.pbRecoverHP((i.totalhp/16).floor,true)
  4030. pbDisplay(_INTL("{1}'s Rain Dish restored its HP a little!",i.pbThis)) if hpgain>0
  4031. end
  4032. # Dry Skin
  4033. if isConst?(i.ability,PBAbilities,:DRYSKIN)
  4034. if pbWeather==PBWeather::RAINDANCE && i.effects[PBEffects::HealBlock]==0
  4035. hpgain=i.pbRecoverHP((i.totalhp/8).floor,true)
  4036. pbDisplay(_INTL("{1}'s Dry Skin was healed by the rain!",i.pbThis)) if hpgain>0
  4037. elsif pbWeather==PBWeather::SUNNYDAY
  4038. @scene.pbDamageAnimation(i,0)
  4039. hploss=i.pbReduceHP((i.totalhp/8).floor)
  4040. pbDisplay(_INTL("{1}'s Dry Skin was hurt by the sunlight!",i.pbThis)) if hploss>0
  4041. elsif $fefieldeffect == 11 && !i.pbHasType?(:STEEL)
  4042. if !i.pbHasType?(:POISON)
  4043. @scene.pbDamageAnimation(i,0)
  4044. hploss=i.pbReduceHP((i.totalhp/8).floor)
  4045. pbDisplay(_INTL("{1}'s Dry Skin absorbed the poison!",i.pbThis)) if hploss>0
  4046. elsif i.effects[PBEffects::HealBlock]==0
  4047. hpgain=i.pbRecoverHP((i.totalhp/8).floor,true)
  4048. pbDisplay(_INTL("{1}'s Dry Skin was healed by the poison!",i.pbThis)) if hpgain>0
  4049. end
  4050. elsif $fefieldeffect == 12
  4051. @scene.pbDamageAnimation(i,0)
  4052. hploss=i.pbReduceHP((i.totalhp/8).floor)
  4053. pbDisplay(_INTL("{1}'s Dry Skin was hurt by the desert air!",i.pbThis)) if hploss>0
  4054. elsif $fefieldeffect == 3 || $fefieldeffect == 8 && # Misty/Swamp Field
  4055. i.effects[PBEffects::HealBlock]==0
  4056. hpgain=(i.totalhp/16).floor
  4057. hpgain=i.pbRecoverHP(hpgain,true)
  4058. pbDisplay(_INTL("{1}'s Dry Skin was healed by the mist!",i.pbThis)) if hpgain>0
  4059. elsif $fefieldeffect == 21 || $fefieldeffect == 22 && #Water fields
  4060. i.effects[PBEffects::HealBlock]==0
  4061. hpgain=(i.totalhp/16).floor
  4062. hpgain=i.pbRecoverHP(hpgain,true)
  4063. pbDisplay(_INTL("{1}'s Dry Skin was healed by the water!",i.pbThis)) if hpgain>0
  4064. end
  4065. end
  4066. # Ice Body
  4067. if (pbWeather==PBWeather::HAIL || $fefieldeffect == 13 ||
  4068. $fefieldeffefct == 32) &&
  4069. i.hasWorkingAbility(:ICEBODY) && i.effects[PBEffects::HealBlock]==0
  4070. hpgain=i.pbRecoverHP((i.totalhp/16).floor,true)
  4071. pbDisplay(_INTL("{1}'s Ice Body restored its HP a little!",i.pbThis)) if hpgain>0
  4072. end
  4073. if i.isFainted?
  4074. return if !i.pbFaint
  4075. next
  4076. end
  4077. end
  4078. # Wish
  4079. for i in priority
  4080. next if i.isFainted?
  4081. if i.effects[PBEffects::Wish]>0
  4082. i.effects[PBEffects::Wish]-=1
  4083. if i.effects[PBEffects::Wish]==0
  4084. hpgain=i.pbRecoverHP(i.effects[PBEffects::WishAmount],true)
  4085. if hpgain>0
  4086. wishmaker=pbThisEx(i.index,i.effects[PBEffects::WishMaker])
  4087. pbDisplay(_INTL("{1}'s wish came true!",wishmaker))
  4088. end
  4089. end
  4090. end
  4091. end
  4092. # Fire Pledge + Grass Pledge combination damage - should go here
  4093. for i in priority
  4094. next if i.isFainted?
  4095. # Shed Skin
  4096. if i.hasWorkingAbility(:SHEDSKIN)
  4097. if pbRandom(10)<3 && i.status>0
  4098. case i.status
  4099. when PBStatuses::SLEEP
  4100. pbDisplay(_INTL("{1}'s Shed Skin cured its sleep problem!",i.pbThis))
  4101. when PBStatuses::FROZEN
  4102. pbDisplay(_INTL("{1}'s Shed Skin cured its ice problem!",i.pbThis))
  4103. when PBStatuses::BURN
  4104. pbDisplay(_INTL("{1}'s Shed Skin cured its burn problem!",i.pbThis))
  4105. when PBStatuses::POISON
  4106. pbDisplay(_INTL("{1}'s Shed Skin cured its poison problem!",i.pbThis))
  4107. when PBStatuses::PARALYSIS
  4108. pbDisplay(_INTL("{1}'s Shed Skin cured its paralysis problem!",i.pbThis))
  4109. end
  4110. i.status=0
  4111. i.statusCount=0
  4112. end
  4113. end
  4114. # Hydration
  4115. if i.hasWorkingAbility(:HYDRATION) && (pbWeather==PBWeather::RAINDANCE ||
  4116. $fefieldeffect == 21 || $fefieldeffect == 22)
  4117. if i.status>0
  4118. case i.status
  4119. when PBStatuses::SLEEP
  4120. pbDisplay(_INTL("{1}'s Hydration cured its sleep problem!",i.pbThis))
  4121. when PBStatuses::FROZEN
  4122. pbDisplay(_INTL("{1}'s Hydration cured its ice problem!",i.pbThis))
  4123. when PBStatuses::BURN
  4124. pbDisplay(_INTL("{1}'s Hydration cured its burn problem!",i.pbThis))
  4125. when PBStatuses::POISON
  4126. pbDisplay(_INTL("{1}'s Hydration cured its poison problem!",i.pbThis))
  4127. when PBStatuses::PARALYSIS
  4128. pbDisplay(_INTL("{1}'s Hydration cured its paralysis problem!",i.pbThis))
  4129. end
  4130. i.status=0
  4131. i.statusCount=0
  4132. end
  4133. end
  4134. if i.hasWorkingAbility(:WATERVEIL) && ($fefieldeffect == 21 ||
  4135. $fefieldeffect == 22)
  4136. if i.status>0
  4137. pbDisplay(_INTL("{1}'s Water Veil cured its status problem!",i.pbThis))
  4138. i.status=0
  4139. i.statusCount=0
  4140. end
  4141. end
  4142. # Healer
  4143. if i.hasWorkingAbility(:HEALER)
  4144. partner=i.pbPartner
  4145. if partner
  4146. if pbRandom(10)<3 && partner.status>0
  4147. case partner.status
  4148. when PBStatuses::SLEEP
  4149. pbDisplay(_INTL("{1}'s Healer cured its partner's sleep problem!",i.pbThis))
  4150. when PBStatuses::FROZEN
  4151. pbDisplay(_INTL("{1}'s Healer cured its partner's ice problem!",i.pbThis))
  4152. when PBStatuses::BURN
  4153. pbDisplay(_INTL("{1}'s Healer cured its partner's burn problem!",i.pbThis))
  4154. when PBStatuses::POISON
  4155. pbDisplay(_INTL("{1}'s Healer cured its partner's poison problem!",i.pbThis))
  4156. when PBStatuses::PARALYSIS
  4157. pbDisplay(_INTL("{1}'s Healer cured its partner's paralysis problem!",i.pbThis))
  4158. end
  4159. partner.status=0
  4160. partner.statusCount=0
  4161. end
  4162. end
  4163. end
  4164. end
  4165. # Held berries/Leftovers/Black Sludge
  4166. for i in priority
  4167. next if i.isFainted?
  4168. i.pbBerryCureCheck(true)
  4169. if i.isFainted?
  4170. return if !i.pbFaint
  4171. next
  4172. end
  4173. end
  4174. # Aqua Ring
  4175. for i in priority
  4176. next if i.hp<=0
  4177. if i.effects[PBEffects::AquaRing]
  4178. if $fefieldeffect == 11 &&
  4179. !i.pbHasType?(:STEEL) && !i.pbHasType?(:POISON)
  4180. @scene.pbDamageAnimation(i,0)
  4181. i.pbReduceHP((i.totalhp/16).floor)
  4182. pbDisplay(_INTL("{1}'s Aqua Ring absorbed poison!",i.pbThis)) if hpgain>0
  4183. if i.hp<=0
  4184. return if !i.pbFaint
  4185. end
  4186. elsif i.effects[PBEffects::HealBlock]==0
  4187. hpgain=(i.totalhp/16).floor
  4188. hpgain=(hpgain*1.3).floor if isConst?(i.item,PBItems,:BIGROOT)
  4189. hpgain=(hpgain*2).floor if $fefieldeffect == 3 ||
  4190. $fefieldeffect == 8 || $fefieldeffect == 21 || $fefieldeffect == 22
  4191. hpgain=i.pbRecoverHP(hpgain,true)
  4192. pbDisplay(_INTL("{1}'s Aqua Ring restored its HP a little!",i.pbThis)) if hpgain>0
  4193. end
  4194. end
  4195. end
  4196. # Ingrain
  4197. for i in priority
  4198. next if i.hp<=0
  4199. if i.effects[PBEffects::Ingrain]
  4200. if $fefieldeffect == 99 || ($fefieldeffect == 99 &&
  4201. !i.pbHasType?(:STEEL) && !i.pbHasType?(:POISON))
  4202. @scene.pbDamageAnimation(i,0)
  4203. i.pbReduceHP((i.totalhp/16).floor)
  4204. pbDisplay(_INTL("{1} absorbed foul nutrients with its roots!",i.pbThis))
  4205. if i.hp<=0
  4206. return if !i.pbFaint
  4207. end
  4208. else
  4209. if $fefieldeffect == 15
  4210. hpgain=(i.totalhp/8).floor
  4211. elsif i.effects[PBEffects::HealBlock]==0
  4212. hpgain=(i.totalhp/16).floor
  4213. end
  4214. hpgain=(hpgain*1.3).floor if isConst?(i.item,PBItems,:BIGROOT)
  4215. hpgain=i.pbRecoverHP(hpgain,true)
  4216. pbDisplay(_INTL("{1} absorbed nutrients with its roots!",i.pbThis)) if hpgain>0
  4217. end
  4218. end
  4219. end
  4220. # Leech Seed
  4221. for i in priority
  4222. next if i.isFainted?
  4223. if i.effects[PBEffects::LeechSeed]>=0
  4224. recipient=@battlers[i.effects[PBEffects::LeechSeed]]
  4225. if recipient && !recipient.isFainted? &&
  4226. !i.hasWorkingAbility(:MAGICGUARD) # if recipient exists
  4227. pbCommonAnimation("LeechSeed",recipient,i)
  4228. hploss=i.pbReduceHP((i.totalhp/8).floor,true)
  4229. hploss= hploss * 2 if $fefieldeffect == 19
  4230. if i.hasWorkingAbility(:LIQUIDOOZE)
  4231. recipient.pbReduceHP(hploss,true)
  4232. pbDisplay(_INTL("{1} sucked up the liquid ooze!",recipient.pbThis))
  4233. hploss= hploss / 2 if $fefieldeffect == 19 || $fefieldeffect == 26
  4234. elsif recipient.effects[PBEffects::HealBlock]==0
  4235. hploss=(hploss*1.3).floor if recipient.hasWorkingItem(:BIGROOT)
  4236. recipient.pbRecoverHP(hploss,true)
  4237. pbDisplay(_INTL("{1}'s health was sapped by Leech Seed!",i.pbThis))
  4238. end
  4239. if i.isFainted?
  4240. return if !i.pbFaint
  4241. end
  4242. if recipient.isFainted?
  4243. return if !recipient.pbFaint
  4244. end
  4245. end
  4246. end
  4247. end
  4248. for i in priority
  4249. next if i.isFainted?
  4250. # Poison/Bad poison
  4251. if i.status==PBStatuses::POISON &&
  4252. !i.hasWorkingAbility(:MAGICGUARD)
  4253. if i.hasWorkingAbility(:POISONHEAL)
  4254. if i.effects[PBEffects::HealBlock]==0
  4255. if i.hp<i.totalhp
  4256. pbCommonAnimation("Poison",i,nil)
  4257. i.pbRecoverHP((i.totalhp/8).floor,true)
  4258. pbDisplay(_INTL("{1} is healed by poison!",i.pbThis))
  4259. end
  4260. if i.statusCount>0
  4261. i.effects[PBEffects::Toxic]+=1
  4262. i.effects[PBEffects::Toxic]=[15,i.effects[PBEffects::Toxic]].min
  4263. end
  4264. end
  4265. else
  4266. i.pbContinueStatus
  4267. if i.statusCount==0
  4268. i.pbReduceHP((i.totalhp/8).floor)
  4269. else
  4270. i.effects[PBEffects::Toxic]+=1
  4271. i.effects[PBEffects::Toxic]=[15,i.effects[PBEffects::Toxic]].min
  4272. i.pbReduceHP((i.totalhp/16).floor*i.effects[PBEffects::Toxic])
  4273. end
  4274. end
  4275. end
  4276. # Burn
  4277. if i.status==PBStatuses::BURN &&
  4278. !i.hasWorkingAbility(:MAGICGUARD)
  4279. i.pbContinueStatus
  4280. if i.hasWorkingAbility(:HEATPROOF) || $fefieldeffect == 13
  4281. i.pbReduceHP((i.totalhp/16).floor)
  4282. else
  4283. i.pbReduceHP((i.totalhp/8).floor)
  4284. end
  4285. end
  4286. # Nightmare
  4287. if i.effects[PBEffects::Nightmare] &&
  4288. !i.hasWorkingAbility(:MAGICGUARD) &&
  4289. $fefieldeffect != 9
  4290. if i.status==PBStatuses::SLEEP
  4291. pbDisplay(_INTL("{1} is locked in a nightmare!",i.pbThis))
  4292. i.pbReduceHP((i.totalhp/4).floor,true)
  4293. else
  4294. i.effects[PBEffects::Nightmare]=false
  4295. end
  4296. end
  4297. if i.isFainted?
  4298. return if !i.pbFaint
  4299. next
  4300. end
  4301. end
  4302. # Curse
  4303. for i in priority
  4304. next if i.isFainted?
  4305. if $fefieldeffect == 29 && i.effects[PBEffects::Curse]
  4306. i.effects[PBEffects::Curse] = false
  4307. pbDisplay(_INTL("{1}'s curse was lifted!",i.pbThis))
  4308. end
  4309. if i.effects[PBEffects::Curse] &&
  4310. !i.hasWorkingAbility(:MAGICGUARD)
  4311. pbDisplay(_INTL("{1} is afflicted by the curse!",i.pbThis))
  4312. i.pbReduceHP((i.totalhp/4).floor,true)
  4313. end
  4314. if i.isFainted?
  4315. return if !i.pbFaint
  4316. next
  4317. end
  4318. end
  4319. # Multi-turn attacks (Bind/Clamp/Fire Spin/Magma Storm/Sand Tomb/Whirlpool/Wrap)
  4320. for i in priority
  4321. next if i.isFainted?
  4322. if i.effects[PBEffects::MultiTurn]>0
  4323. i.effects[PBEffects::MultiTurn]-=1
  4324. movename=PBMoves.getName(i.effects[PBEffects::MultiTurnAttack])
  4325. if i.effects[PBEffects::MultiTurn]==0
  4326. pbDisplay(_INTL("{1} was freed from {2}!",i.pbThis,movename))
  4327. $bindingband=0
  4328. else
  4329. pbDisplay(_INTL("{1} is hurt by {2}!",i.pbThis,movename))
  4330. if isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:BIND)
  4331. pbCommonAnimation("Bind",i,nil)
  4332. elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:CLAMP)
  4333. pbCommonAnimation("Clamp",i,nil)
  4334. elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:FIRESPIN)
  4335. pbCommonAnimation("FireSpin",i,nil)
  4336. elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:MAGMASTORM)
  4337. pbCommonAnimation("MagmaStorm",i,nil)
  4338. elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:SANDTOMB)
  4339. pbCommonAnimation("SandTomb",i,nil)
  4340. elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:WRAP)
  4341. pbCommonAnimation("Wrap",i,nil)
  4342. else
  4343. pbCommonAnimation("Wrap",i,nil)
  4344. end
  4345. @scene.pbDamageAnimation(i,0)
  4346. if $bindingband==1
  4347. i.pbReduceHP((i.totalhp/6).floor)
  4348. elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:SANDTOMB) &&
  4349. $fefieldeffect == 12
  4350. i.pbReduceHP((i.totalhp/6).floor)
  4351. elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:WHIRLPOOL) &&
  4352. ($fefieldeffect == 21 || $fefieldeffect == 22)
  4353. i.pbReduceHP((i.totalhp/6).floor)
  4354. elsif isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:INFESTATION) &&
  4355. $fefieldeffect == 15
  4356. i.pbReduceHP((i.totalhp/6).floor)
  4357. else
  4358. i.pbReduceHP((i.totalhp/8).floor)
  4359. end
  4360. if isConst?(i.effects[PBEffects::MultiTurnAttack],PBMoves,:SANDTOMB) &&
  4361. $fefieldeffect == 20
  4362. i.pbCanReduceStatStage?(PBStats::ACCURACY)
  4363. i.pbReduceStat(PBStats::ACCURACY,1,true)
  4364. end
  4365. end
  4366. end
  4367. if i.hp<=0
  4368. return if !i.pbFaint
  4369. next
  4370. end
  4371. end
  4372. # Taunt
  4373. for i in priority
  4374. next if i.isFainted?
  4375. if i.effects[PBEffects::Taunt]>0
  4376. i.effects[PBEffects::Taunt]-=1
  4377. if i.effects[PBEffects::Taunt]==0
  4378. pbDisplay(_INTL("{1} recovered from the taunting!",i.pbThis))
  4379. end
  4380. end
  4381. end
  4382. # Encore
  4383. for i in priority
  4384. next if i.isFainted?
  4385. if i.effects[PBEffects::Encore]>0
  4386. if i.moves[i.effects[PBEffects::EncoreIndex]].id!=i.effects[PBEffects::EncoreMove]
  4387. i.effects[PBEffects::Encore]=0
  4388. i.effects[PBEffects::EncoreIndex]=0
  4389. i.effects[PBEffects::EncoreMove]=0
  4390. else
  4391. i.effects[PBEffects::Encore]-=1
  4392. if i.effects[PBEffects::Encore]==0 || i.moves[i.effects[PBEffects::EncoreIndex]].pp==0
  4393. i.effects[PBEffects::Encore]=0
  4394. pbDisplay(_INTL("{1}'s encore ended!",i.pbThis))
  4395. end
  4396. end
  4397. end
  4398. end
  4399. # Disable/Cursed Body
  4400. for i in priority
  4401. next if i.isFainted?
  4402. if i.effects[PBEffects::Disable]>0
  4403. i.effects[PBEffects::Disable]-=1
  4404. if i.effects[PBEffects::Disable]==0
  4405. i.effects[PBEffects::DisableMove]=0
  4406. pbDisplay(_INTL("{1} is disabled no more!",i.pbThis))
  4407. end
  4408. end
  4409. end
  4410. # Magnet Rise
  4411. for i in priority
  4412. next if i.isFainted?
  4413. if i.effects[PBEffects::MagnetRise]>0
  4414. i.effects[PBEffects::MagnetRise]-=1
  4415. if i.effects[PBEffects::MagnetRise]==0
  4416. pbDisplay(_INTL("{1} stopped levitating.",i.pbThis))
  4417. end
  4418. end
  4419. end
  4420. # Telekinesis
  4421. for i in priority
  4422. next if i.isFainted?
  4423. if i.effects[PBEffects::Telekinesis]>0
  4424. i.effects[PBEffects::Telekinesis]-=1
  4425. if i.effects[PBEffects::Telekinesis]==0
  4426. pbDisplay(_INTL("{1} stopped levitating.",i.pbThis))
  4427. end
  4428. end
  4429. end
  4430. # Heal Block
  4431. for i in priority
  4432. next if i.isFainted?
  4433. if i.effects[PBEffects::HealBlock]>0
  4434. i.effects[PBEffects::HealBlock]-=1
  4435. if i.effects[PBEffects::HealBlock]==0
  4436. pbDisplay(_INTL("The heal block on {1} ended.",i.pbThis))
  4437. end
  4438. end
  4439. end
  4440. # Embargo
  4441. for i in priority
  4442. next if i.isFainted?
  4443. if i.effects[PBEffects::Embargo]>0
  4444. i.effects[PBEffects::Embargo]-=1
  4445. if i.effects[PBEffects::Embargo]==0
  4446. pbDisplay(_INTL("The embargo on {1} was lifted.",i.pbThis(true)))
  4447. end
  4448. end
  4449. end
  4450. # Yawn
  4451. for i in priority
  4452. next if i.isFainted?
  4453. if i.effects[PBEffects::Yawn]>0
  4454. i.effects[PBEffects::Yawn]-=1
  4455. if i.effects[PBEffects::Yawn]==0 && i.pbCanSleepYawn?
  4456. i.pbSleep
  4457. pbDisplay(_INTL("{1} fell asleep!",i.pbThis))
  4458. end
  4459. end
  4460. end
  4461. # Perish Song
  4462. perishSongUsers=[]
  4463. for i in priority
  4464. next if i.isFainted?
  4465. if i.effects[PBEffects::PerishSong]>0
  4466. i.effects[PBEffects::PerishSong]-=1
  4467. pbDisplay(_INTL("{1}'s Perish count fell to {2}!",i.pbThis,i.effects[PBEffects::PerishSong]))
  4468. if i.effects[PBEffects::PerishSong]==0
  4469. perishSongUsers.push(i.effects[PBEffects::PerishSongUser])
  4470. i.pbReduceHP(i.hp,true)
  4471. end
  4472. end
  4473. if i.isFainted?
  4474. return if !i.pbFaint
  4475. end
  4476. end
  4477. if perishSongUsers.length>0
  4478. # If all remaining Pokemon fainted by a Perish Song triggered by a single side
  4479. if (perishSongUsers.find_all{|item| pbIsOpposing?(item) }.length==perishSongUsers.length) ||
  4480. (perishSongUsers.find_all{|item| !pbIsOpposing?(item) }.length==perishSongUsers.length)
  4481. pbJudgeCheckpoint(@battlers[perishSongUsers[0]])
  4482. end
  4483. end
  4484. if @decision>0
  4485. pbGainEXP
  4486. return
  4487. end
  4488. # Reflect
  4489. for i in 0...2
  4490. if sides[i].effects[PBEffects::Reflect]>0
  4491. sides[i].effects[PBEffects::Reflect]-=1
  4492. if sides[i].effects[PBEffects::Reflect]==0
  4493. pbDisplay(_INTL("Your team's Reflect faded!")) if i==0
  4494. pbDisplay(_INTL("The opposing team's Reflect faded!")) if i==1
  4495. end
  4496. end
  4497. end
  4498. # Light Screen
  4499. for i in 0...2
  4500. if sides[i].effects[PBEffects::LightScreen]>0
  4501. sides[i].effects[PBEffects::LightScreen]-=1
  4502. if sides[i].effects[PBEffects::LightScreen]==0
  4503. pbDisplay(_INTL("Your team's Light Screen faded!")) if i==0
  4504. pbDisplay(_INTL("The opposing team's Light Screen faded!")) if i==1
  4505. end
  4506. end
  4507. end
  4508. # Safeguard
  4509. for i in 0...2
  4510. if sides[i].effects[PBEffects::Safeguard]>0
  4511. sides[i].effects[PBEffects::Safeguard]-=1
  4512. if sides[i].effects[PBEffects::Safeguard]==0
  4513. pbDisplay(_INTL("Your team is no longer protected by Safeguard!")) if i==0
  4514. pbDisplay(_INTL("The opposing team is no longer protected by Safeguard!")) if i==1
  4515. end
  4516. end
  4517. end
  4518. # Mist
  4519. for i in 0...2
  4520. if sides[i].effects[PBEffects::Mist]>0
  4521. sides[i].effects[PBEffects::Mist]-=1
  4522. if sides[i].effects[PBEffects::Mist]==0
  4523. pbDisplay(_INTL("Your team's Mist faded!")) if i==0
  4524. pbDisplay(_INTL("The opposing team's Mist faded!")) if i==1
  4525. end
  4526. end
  4527. end
  4528. # Tailwind
  4529. for i in 0...2
  4530. if sides[i].effects[PBEffects::Tailwind]>0
  4531. sides[i].effects[PBEffects::Tailwind]-=1
  4532. if sides[i].effects[PBEffects::Tailwind]==0
  4533. pbDisplay(_INTL("Your team's tailwind stopped blowing!")) if i==0
  4534. pbDisplay(_INTL("The opposing team's tailwind stopped blowing!")) if i==1
  4535. end
  4536. end
  4537. end
  4538. # Lucky Chant
  4539. for i in 0...2
  4540. if sides[i].effects[PBEffects::LuckyChant]>0
  4541. sides[i].effects[PBEffects::LuckyChant]-=1
  4542. if sides[i].effects[PBEffects::LuckyChant]==0
  4543. pbDisplay(_INTL("Your team's Lucky Chant faded!")) if i==0
  4544. pbDisplay(_INTL("The opposing team's Lucky Chant faded!")) if i==1
  4545. end
  4546. end
  4547. end
  4548. # Mud Sport
  4549. if @field.effects[PBEffects::MudSport]>0
  4550. @field.effects[PBEffects::MudSport]-=1
  4551. if @field.effects[PBEffects::MudSport]==0
  4552. pbDisplay(_INTL("The effects of Mud Sport faded."))
  4553. end
  4554. end
  4555. # Water Sport
  4556. if @field.effects[PBEffects::WaterSport]>0
  4557. @field.effects[PBEffects::WaterSport]-=1
  4558. if @field.effects[PBEffects::WaterSport]==0
  4559. pbDisplay(_INTL("The effects of Water Sport faded."))
  4560. end
  4561. end
  4562. # Gravity
  4563. if @field.effects[PBEffects::Gravity]>0
  4564. @field.effects[PBEffects::Gravity]-=1
  4565. if @field.effects[PBEffects::Gravity]==0
  4566. pbDisplay(_INTL("Gravity returned to normal."))
  4567. end
  4568. end
  4569. # Terrain
  4570. if @field.effects[PBEffects::Terrain]>0
  4571. terrain=[@field.effects[PBEffects::Terrain]].max
  4572. terrain-=1
  4573. @field.effects[PBEffects::Terrain] = terrain
  4574. if terrain==0
  4575. $fefieldeffect = $febackup
  4576. pbDisplay(_INTL("The terrain returned to normal."))
  4577. pbChangeBGSprite
  4578. end
  4579. end
  4580. # Trick Room - should go here
  4581. # Wonder Room - should go here
  4582. # Magic Room
  4583. if @field.effects[PBEffects::MagicRoom]>0
  4584. @field.effects[PBEffects::MagicRoom]-=1
  4585. if @field.effects[PBEffects::MagicRoom]==0
  4586. pbDisplay(_INTL("The area returned to normal."))
  4587. end
  4588. end
  4589. # Fairy Lock
  4590. if @field.effects[PBEffects::FairyLock]>0
  4591. @field.effects[PBEffects::FairyLock]-=1
  4592. if @field.effects[PBEffects::FairyLock]==0
  4593. # Fairy Lock seems to have no end-of-effect text so I've added some.
  4594. pbDisplay(_INTL("The Fairy Lock was released."))
  4595. end
  4596. end
  4597. # Uproar
  4598. for i in priority
  4599. next if i.isFainted?
  4600. if i.effects[PBEffects::Uproar]>0
  4601. for j in priority
  4602. if !j.isFainted? && j.status==PBStatuses::SLEEP && !j.hasWorkingAbility(:SOUNDPROOF)
  4603. j.effects[PBEffects::Nightmare]=false
  4604. j.status=0
  4605. j.statusCount=0
  4606. pbDisplay(_INTL("{1} woke up in the uproar!",j.pbThis))
  4607. end
  4608. end
  4609. i.effects[PBEffects::Uproar]-=1
  4610. if i.effects[PBEffects::Uproar]==0
  4611. pbDisplay(_INTL("{1} calmed down.",i.pbThis))
  4612. else
  4613. pbDisplay(_INTL("{1} is making an uproar!",i.pbThis))
  4614. end
  4615. end
  4616. end
  4617.  
  4618. #Wasteland hazard interaction
  4619. if $fefieldeffect == 19
  4620. for i in priority
  4621. next if i.isFainted?
  4622. # SR
  4623. if i.pbOwnSide.effects[PBEffects::StealthRock]==true
  4624. pbDisplay(_INTL("The waste swallowed up the pointed stones!"))
  4625. i.pbOwnSide.effects[PBEffects::StealthRock]=false
  4626. pbDisplay(_INTL("...Rocks spewed out from the ground below!"))
  4627. atype=getConst(PBTypes,:ROCK) || 0
  4628. if !i.isFainted?
  4629. eff=PBTypes.getCombinedEffectiveness(atype,i.type1,i.type2)
  4630. if eff>0
  4631. @scene.pbDamageAnimation(i,0)
  4632. i.pbReduceHP([(i.totalhp*eff/16).floor,1].max)
  4633. end
  4634. end
  4635. partner=i.pbPartner
  4636. if partner && !partner.isFainted?
  4637. eff=PBTypes.getCombinedEffectiveness(atype,partner.type1,partner.type2)
  4638. if eff>0
  4639. @scene.pbDamageAnimation(partner,0)
  4640. partner.pbReduceHP([(partner.totalhp*eff/16).floor,1].max)
  4641. end
  4642. end
  4643. end
  4644. # Spikes
  4645. if i.pbOwnSide.effects[PBEffects::Spikes]>0
  4646. pbDisplay(_INTL("The waste swallowed up the spikes!"))
  4647. i.pbOwnSide.effects[PBEffects::Spikes]=0
  4648. pbDisplay(_INTL("...Stalagmites burst up from the ground!"))
  4649. if !i.isFainted? && !i.isAirborne?
  4650. @scene.pbDamageAnimation(i,0)
  4651. i.pbReduceHP([(i.totalhp/3).floor,1].max)
  4652. end
  4653. partner=i.pbPartner
  4654. if partner && !partner.isFainted?
  4655. if !partner.isAirborne?
  4656. @scene.pbDamageAnimation(partner,0)
  4657. partner.pbReduceHP([(partner.totalhp/3).floor,1].max)
  4658. end
  4659. end
  4660. end
  4661. # TSpikes
  4662. if i.pbOwnSide.effects[PBEffects::ToxicSpikes]>0
  4663. pbDisplay(_INTL("The waste swallowed up the toxic spikes!"))
  4664. i.pbOwnSide.effects[PBEffects::ToxicSpikes]=0
  4665. pbDisplay(_INTL("...Poison needles shot up from the ground!"))
  4666. if !i.isFainted? && !i.isAirborne?
  4667. @scene.pbDamageAnimation(i,0)
  4668. i.pbReduceHP([(i.totalhp/8).floor,1].max)
  4669. if i.status==0 && i.pbCanPoison?(false)
  4670. i.status=PBStatuses::POISON
  4671. i.statusCount=1
  4672. i.effects[PBEffects::Toxic]=0
  4673. pbCommonAnimation("Poison",i,nil)
  4674. end
  4675. end
  4676. partner=i.pbPartner
  4677. if partner && !partner.isFainted?
  4678. if !partner.isAirborne?
  4679. @scene.pbDamageAnimation(partner,0)
  4680. partner.pbReduceHP([(partner.totalhp/8).floor,1].max)
  4681. if partner.status==0 && partner.pbCanPoison?(false)
  4682. partner.status=PBStatuses::POISON
  4683. partner.statusCount=1
  4684. partner.effects[PBEffects::Toxic]=0
  4685. pbCommonAnimation("Poison",i,nil)
  4686. end
  4687. end
  4688. end
  4689. end
  4690. # StickyWeb
  4691. if i.pbOwnSide.effects[PBEffects::StickyWeb]
  4692. pbDisplay(_INTL("The waste swallowed up the sticky web!"))
  4693. i.pbOwnSide.effects[PBEffects::StickyWeb]=false
  4694. pbDisplay(_INTL("...Sticky string shot out of the ground!"))
  4695. if !i.isFainted?
  4696. if !i.pbTooLow?(PBStats::SPEED)
  4697. i.pbReduceStatBasic(PBStats::SPEED,4)
  4698. pbCommonAnimation("StatDown",i,nil)
  4699. pbDisplay(_INTL("{1}'s Speed was severely lowered!",i.pbThis))
  4700. end
  4701. end
  4702. partner=i.pbPartner
  4703. if partner && !partner.isFainted?
  4704. if !partner.pbTooLow?(PBStats::SPEED)
  4705. partner.pbReduceStatBasic(PBStats::SPEED,4)
  4706. pbCommonAnimation("StatDown",partner,nil)
  4707. pbDisplay(_INTL("{1}'s Speed was severely lowered!",partner.pbThis))
  4708. end
  4709. end
  4710. end
  4711. if i.hp<=0
  4712. return if !i.pbFaint
  4713. next
  4714. end
  4715. end
  4716. end
  4717. # End Wasteland hazards
  4718. for i in priority
  4719. next if i.isFainted?
  4720. # Speed Boost
  4721. # A Pokémon's turncount is 0 if it became active after the beginning of a round
  4722. if i.turncount>0 && i.hasWorkingAbility(:SPEEDBOOST)
  4723. if !i.pbTooHigh?(PBStats::SPEED)
  4724. i.pbIncreaseStatBasic(PBStats::SPEED,1)
  4725. pbCommonAnimation("StatUp",i,nil)
  4726. pbDisplay(_INTL("{1}'s Speed Boost raised its Speed!",i.pbThis))
  4727. end
  4728. end
  4729. if i.turncount>0 && $fefieldeffect == 8 && # Swamp Field
  4730. !isConst?(i.ability,PBAbilities,:WHITESMOKE) &&
  4731. !isConst?(i.ability,PBAbilities,:CLEARBODY) &&
  4732. !isConst?(i.ability,PBAbilities,:QUICKFEET) &&
  4733. !isConst?(i.ability,PBAbilities,:SWIFTSWIM)
  4734. if !i.isAirborne?
  4735. if !i.pbTooLow?(PBStats::SPEED)
  4736. i.pbReduceStatBasic(PBStats::SPEED,1)
  4737. pbCommonAnimation("StatDown",i,nil)
  4738. pbDisplay(_INTL("{1}'s Speed sank...",i.pbThis))
  4739. end
  4740. end
  4741. end
  4742. #sleepyswamp
  4743. if i.status==PBStatuses::SLEEP && !isConst?(i.ability,PBAbilities,:MAGICGUARD)
  4744. if $fefieldeffect == 8 # Swamp Field
  4745. hploss=i.pbReduceHP((i.totalhp/16).floor,true)
  4746. pbDisplay(_INTL("{1}'s strength is sapped by the swamp!",i.pbThis)) if hploss>0
  4747. end
  4748. end
  4749. if i.hp<=0
  4750. return if !i.pbFaint
  4751. next
  4752. end
  4753. #sleepyrainbow
  4754. if i.status==PBStatuses::SLEEP
  4755. if $fefieldeffect == 9 && i.effects[PBEffects::HealBlock]==0#Rainbow Field
  4756. hpgain=(i.totalhp/16).floor
  4757. hpgain=(hpgain*1.3).floor if isConst?(i.item,PBItems,:BIGROOT)
  4758. hpgain=i.pbRecoverHP(hpgain,true)
  4759. pbDisplay(_INTL("{1} recovered health in its peaceful sleep!",i.pbThis))
  4760. end
  4761. end
  4762. #DimenSleep
  4763. if i.status==PBStatuses::SLEEP &&
  4764. $fefieldeffect == 31 # Dimen
  4765. hploss=i.pbReduceHP((i.totalhp/16).floor,true)
  4766. pbDisplay(_INTL("{1}'s dream is corrupted by the dimension!",i.pbThis)) if hploss>0
  4767. end
  4768. if i.hp<=0
  4769. return if !i.pbFaint
  4770. next
  4771. end
  4772. #HauntedSleep
  4773. if i.status==PBStatuses::SLEEP &&
  4774. $fefieldeffect == 34 # Haunted
  4775. hploss=i.pbReduceHP((i.totalhp/16).floor,true)
  4776. pbDisplay(_INTL("{1}'s dream is corrupted by the evil spirits!",i.pbThis)) if hploss>0
  4777. end
  4778. if i.hp<=0
  4779. return if !i.pbFaint
  4780. next
  4781. end
  4782. #FairyRingSleep
  4783. if i.status==PBStatuses::SLEEP &&
  4784. $fefieldeffect == 38 # Haunted
  4785. hploss=i.pbReduceHP((i.totalhp/6).floor,true)
  4786. pbDisplay(_INTL("{1}'s dream is corrupted by the evil spirits!",i.pbThis)) if hploss>0
  4787. end
  4788. if i.hp<=0
  4789. return if !i.pbFaint
  4790. next
  4791. end
  4792. # Bad Dreams
  4793. if i.status==PBStatuses::SLEEP && !isConst?(i.ability,PBAbilities,:MAGICGUARD) &&
  4794. $fefieldeffect != 9
  4795. if i.pbOpposing1.hasWorkingAbility(:BADDREAMS) ||
  4796. i.pbOpposing2.hasWorkingAbility(:BADDREAMS)
  4797. hploss=i.pbReduceHP((i.totalhp/8).floor,true)
  4798. pbDisplay(_INTL("{1} is having a bad dream!",i.pbThis)) if hploss>0
  4799. end
  4800. end
  4801. if i.isFainted?
  4802. return if !i.pbFaint
  4803. next
  4804. end
  4805. # Harvest
  4806. if i.hasWorkingAbility(:HARVEST) && i.item<=0 && i.pokemon.itemRecycle>0 #if an item was recycled, check
  4807. if pbIsBerry?(i.pokemon.itemRecycle) && (rand(100)>50 || pbWeather==PBWeather::SUNNYDAY)
  4808. i.item=i.pokemon.itemRecycle
  4809. i.pokemon.itemInitial=i.pokemon.itemRecycle
  4810. i.pokemon.itemRecycle=0
  4811. firstberryletter=PBItems.getName(i.item).split(//).first
  4812. if firstberryletter=="A" || firstberryletter=="E" || firstberryletter=="I" ||
  4813. firstberryletter=="O" || firstberryletter=="U"
  4814. pbDisplay(_INTL("{1} harvested an {2}!",i.pbThis,PBItems.getName(i.item)))
  4815. else
  4816. pbDisplay(_INTL("{1} harvested a {2}!",i.pbThis,PBItems.getName(i.item)))
  4817. end
  4818. i.pbBerryCureCheck(true)
  4819. end
  4820. end
  4821. # Moody
  4822. if i.hasWorkingAbility(:CLOUDNINE) && $fefieldeffect == 9
  4823. randoms=[]
  4824. loop do
  4825. rand=1+self.pbRandom(7)
  4826. if !i.pbTooHigh?(rand)
  4827. randoms.push(rand)
  4828. break
  4829. end
  4830. end
  4831. statnames=[_INTL("Attack"),_INTL("Defense"),_INTL("Speed"),_INTL("Special Attack"),
  4832. _INTL("Special Defense"),_INTL("accuracy"),_INTL("evasiveness")]
  4833. i.stages[randoms[0]]+=1
  4834. i.stages[randoms[0]]=6 if i.stages[randoms[0]]>6
  4835. pbCommonAnimation("StatUp",i,nil)
  4836. pbDisplay(_INTL("{1}'s Cloud Nine raised its {2}!",i.pbThis,statnames[randoms[0]-1]))
  4837. end
  4838. if i.hasWorkingAbility(:MOODY)
  4839. randoms=[]
  4840. loop do
  4841. rand=1+self.pbRandom(7)
  4842. if !i.pbTooHigh?(rand)
  4843. randoms.push(rand)
  4844. break
  4845. end
  4846. end
  4847. loop do
  4848. rand=1+self.pbRandom(7)
  4849. if !i.pbTooLow?(rand) && rand!=randoms[0]
  4850. randoms.push(rand)
  4851. break
  4852. end
  4853. end
  4854. statnames=[_INTL("Attack"),_INTL("Defense"),_INTL("Speed"),_INTL("Special Attack"),
  4855. _INTL("Special Defense"),_INTL("accuracy"),_INTL("evasiveness")]
  4856. i.stages[randoms[0]]+=2
  4857. i.stages[randoms[0]]=6 if i.stages[randoms[0]]>6
  4858. pbCommonAnimation("StatUp",i,nil)
  4859. pbDisplay(_INTL("{1}'s Moody sharply raised its {2}!",i.pbThis,statnames[randoms[0]-1]))
  4860. i.stages[randoms[1]]-=1
  4861. pbCommonAnimation("StatDown",i,nil)
  4862. pbDisplay(_INTL("{1}'s Moody lowered its {2}!",i.pbThis,statnames[randoms[1]-1]))
  4863. end
  4864. end
  4865. for i in priority
  4866. next if i.isFainted?
  4867. # Toxic Orb
  4868. if i.hasWorkingItem(:TOXICORB) && i.status==0 && i.pbCanPoison?(false)
  4869. i.status=PBStatuses::POISON
  4870. i.statusCount=1
  4871. i.effects[PBEffects::Toxic]=0
  4872. pbCommonAnimation("Poison",i,nil)
  4873. pbDisplay(_INTL("{1} was poisoned by its {2}!",i.pbThis,PBItems.getName(i.item)))
  4874. end
  4875. # Flame Orb
  4876. if i.hasWorkingItem(:FLAMEORB) && i.status==0 && i.pbCanBurn?(false)
  4877. i.status=PBStatuses::BURN
  4878. i.statusCount=0
  4879. pbCommonAnimation("Burn",i,nil)
  4880. pbDisplay(_INTL("{1} was burned by its {2}!",i.pbThis,PBItems.getName(i.item)))
  4881. end
  4882. # Sticky Barb
  4883. if i.hasWorkingItem(:STICKYBARB) && !i.hasWorkingAbility(:MAGICGUARD)
  4884. pbDisplay(_INTL("{1} is hurt by its {2}!",i.pbThis,PBItems.getName(i.item)))
  4885. @scene.pbDamageAnimation(i,0)
  4886. i.pbReduceHP((i.totalhp/8).floor)
  4887. end
  4888. if i.isFainted?
  4889. return if !i.pbFaint
  4890. next
  4891. end
  4892. end
  4893. # Form checks
  4894. for i in 0...4
  4895. next if @battlers[i].isFainted?
  4896. @battlers[i].pbCheckForm
  4897. end
  4898. pbGainEXP
  4899. ##### KUROTSUNE - 009 - START
  4900. # Checks if a pokemon on either side has fainted on this turn
  4901. # for retaliate
  4902. player = priority[0]
  4903. opponent = priority[1]
  4904. if player.isFainted? ||
  4905. (@doublebattle && player.pbPartner.isFainted?)
  4906. player.pbOwnSide.effects[PBEffects::Retaliate] = true
  4907. else
  4908. # No pokemon has fainted in this side this turn
  4909. player.pbOwnSide.effects[PBEffects::Retaliate] = false
  4910. end
  4911.  
  4912. if opponent.isFainted? ||
  4913. (@doublebattle && player.pbPartner.isFainted?)
  4914. opponent.pbOwnSide.effects[PBEffects::Retaliate] = true
  4915. else
  4916. opponent.pbOwnSide.effects[PBEffects::Retaliate] = false
  4917. end
  4918. ##### KUROTSUNE - 009 - END
  4919. pbSwitch
  4920. return if @decision>0
  4921. for i in priority
  4922. next if i.isFainted?
  4923. i.pbAbilitiesOnSwitchIn(false)
  4924. end
  4925. # Healing Wish/Lunar Dance - should go here
  4926. # Spikes/Toxic Spikes/Stealth Rock - should go here (in order of their 1st use)
  4927. for i in 0...4
  4928. if @battlers[i].turncount>0 && @battlers[i].hasWorkingAbility(:TRUANT)
  4929. @battlers[i].effects[PBEffects::Truant]=!@battlers[i].effects[PBEffects::Truant]
  4930. end
  4931. if @battlers[i].effects[PBEffects::LockOn]>0 # Also Mind Reader
  4932. @battlers[i].effects[PBEffects::LockOn]-=1
  4933. @battlers[i].effects[PBEffects::LockOnPos]=-1 if @battlers[i].effects[PBEffects::LockOn]==0
  4934. end
  4935. @battlers[i].effects[PBEffects::Flinch]=false
  4936. @battlers[i].effects[PBEffects::FollowMe]=false
  4937. @battlers[i].effects[PBEffects::HelpingHand]=false
  4938. @battlers[i].effects[PBEffects::MagicCoat]=false
  4939. @battlers[i].effects[PBEffects::Snatch]=false
  4940. #### KUROTSUNE - 024 - START
  4941. @battlers[i].effects[PBEffects::Electrify]=false
  4942. #### KUROTSUNE - 024 - END
  4943. @battlers[i].effects[PBEffects::Charge]-=1 if @battlers[i].effects[PBEffects::Charge]>0
  4944. @battlers[i].lastHPLost=0
  4945. @battlers[i].lastAttacker=-1
  4946. @battlers[i].effects[PBEffects::Counter]=-1
  4947. @battlers[i].effects[PBEffects::CounterTarget]=-1
  4948. @battlers[i].effects[PBEffects::MirrorCoat]=-1
  4949. @battlers[i].effects[PBEffects::MirrorCoatTarget]=-1
  4950. end
  4951. # invalidate stored priority
  4952. @usepriority=false
  4953. end
  4954.  
  4955. ################################################################################
  4956. # End of battle.
  4957. ################################################################################
  4958. def pbEndOfBattle(canlose=false)
  4959. case @decision
  4960. ##### WIN #####
  4961. when 1
  4962. if @opponent
  4963. @scene.pbTrainerBattleSuccess
  4964. if @opponent.is_a?(Array)
  4965. pbDisplayPaused(_INTL("{1} defeated {2} and {3}!",self.pbPlayer.name,@opponent[0].fullname,@opponent[1].fullname))
  4966. else
  4967. pbDisplayPaused(_INTL("{1} defeated\r\n{2}!",self.pbPlayer.name,@opponent.fullname))
  4968. end
  4969. @scene.pbShowOpponent(0)
  4970. pbDisplayPaused(@endspeech.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
  4971. if @opponent.is_a?(Array)
  4972. @scene.pbHideOpponent
  4973. @scene.pbShowOpponent(1)
  4974. pbDisplayPaused(@endspeech2.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
  4975. end
  4976. # Calculate money gained for winning
  4977. if @internalbattle
  4978. maxlevel=0
  4979. for i in @party2
  4980. next if !i
  4981. maxlevel=i.level if maxlevel<i.level
  4982. end
  4983. if @opponent.is_a?(Array)
  4984. maxlevel*=@opponent[0].moneyEarned+@opponent[1].moneyEarned
  4985. else
  4986. maxlevel*=@opponent.moneyEarned
  4987. end
  4988. # If Amulet Coin/Luck Incense's effect applies, double money earned
  4989. maxlevel*=2 if @amuletcoin
  4990. maxlevel = DifficultModes.applyMoneyProcedure(maxlevel)
  4991. oldmoney=self.pbPlayer.money
  4992. self.pbPlayer.money+=maxlevel
  4993. moneygained=self.pbPlayer.money-oldmoney
  4994. if moneygained>0
  4995. pbDisplayPaused(_INTL("{1} got ${2}\r\nfor winning!",self.pbPlayer.name,maxlevel))
  4996. end
  4997. end
  4998. end
  4999. if @internalbattle && @extramoney>0
  5000. @extramoney*=2 if @amuletcoin
  5001. pbDisplayPaused(_INTL("{1} picked up ${2}!",self.pbPlayer.name,@extramoney))
  5002. self.pbPlayer.money+=@extramoney
  5003. end
  5004. for pkmn in @snaggedpokemon
  5005. pbStorePokemon(pkmn)
  5006. self.pbPlayer.shadowcaught=[] if !self.pbPlayer.shadowcaught
  5007. self.pbPlayer.shadowcaught[pkmn.species]=true
  5008. end
  5009. @snaggedpokemon.clear
  5010. ##### LOSE, DRAW #####
  5011. when 2, 5
  5012. if @internalbattle
  5013. pbDisplayPaused(_INTL("{1} is out of usable Pokémon!",self.pbPlayer.name))
  5014. moneylost=pbMaxLevel(@party1)
  5015. multiplier=[8,16,24,36,48,60,80,100,120]
  5016. moneylost*=multiplier[[multiplier.length-1,self.pbPlayer.numbadges].min]
  5017. moneylost=self.pbPlayer.money if moneylost>self.pbPlayer.money
  5018. moneylost=0 if $game_switches[NO_MONEY_LOSS]
  5019. self.pbPlayer.money-=moneylost
  5020. if @opponent
  5021. if @opponent.is_a?(Array)
  5022. pbDisplayPaused(_INTL("{1} lost against {2} and {3}!",self.pbPlayer.name,@opponent[0].fullname,@opponent[1].fullname))
  5023. else
  5024. pbDisplayPaused(_INTL("{1} lost against\r\n{2}!",self.pbPlayer.name,@opponent.fullname))
  5025. end
  5026. if moneylost>0
  5027. pbDisplayPaused(_INTL("{1} paid ${2}\r\nas the prize money...",self.pbPlayer.name,moneylost))
  5028. pbDisplayPaused(_INTL("...")) if !canlose
  5029. end
  5030. else
  5031. if moneylost>0
  5032. pbDisplayPaused(_INTL("{1} panicked and lost\r\n${2}...",self.pbPlayer.name,moneylost))
  5033. pbDisplayPaused(_INTL("...")) if !canlose
  5034. end
  5035. end
  5036. pbDisplayPaused(_INTL("{1} blacked out!",self.pbPlayer.name)) if !canlose
  5037. elsif @decision==2
  5038. @scene.pbShowOpponent(0)
  5039. pbDisplayPaused(@endspeechwin.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
  5040. if @opponent.is_a?(Array)
  5041. @scene.pbHideOpponent
  5042. @scene.pbShowOpponent(1)
  5043. pbDisplayPaused(@endspeechwin2.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
  5044. end
  5045. elsif @decision==5
  5046. PBDebug.log("***[Draw game]") if $INTERNAL
  5047. end
  5048. end
  5049. # Pass on Pokérus within the party
  5050. infected=[]
  5051. for i in 0...$Trainer.party.length
  5052. if $Trainer.party[i].pokerusStage==1
  5053. infected.push(i)
  5054. end
  5055. end
  5056. if infected.length>=1
  5057. for i in infected
  5058. strain=$Trainer.party[i].pokerus/16
  5059. if i>0 && $Trainer.party[i-1].pokerusStage==0
  5060. $Trainer.party[i-1].givePokerus(strain) if rand(3)==0
  5061. end
  5062. if i<$Trainer.party.length-1 && $Trainer.party[i+1].pokerusStage==0
  5063. $Trainer.party[i+1].givePokerus(strain) if rand(3)==0
  5064. end
  5065. end
  5066. end
  5067. @scene.pbEndBattle(@decision)
  5068. for i in @battlers
  5069. i.pbResetForm
  5070. end
  5071. for i in $Trainer.party
  5072. i.setItem(i.itemInitial)
  5073. i.itemInitial=i.itemRecycle=0
  5074. end
  5075. return @decision
  5076. end
  5077. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement