Kid02

help again

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