Advertisement
Guest User

Battle Code

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