Guest User

Untitled

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