Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 135.58 KB | None | 0 0
  1. class PokeBattle_Battler
  2. attr_reader :battle
  3. attr_reader :pokemon
  4. attr_reader :name
  5. attr_reader :index
  6. attr_accessor :pokemonIndex
  7. attr_reader :totalhp
  8. attr_reader :fainted
  9. attr_accessor :lastAttacker
  10. attr_accessor :turncount
  11. attr_accessor :effects
  12. attr_accessor :species
  13. attr_accessor :type1
  14. attr_accessor :type2
  15. attr_accessor :ability
  16. attr_accessor :gender
  17. attr_accessor :attack
  18. attr_writer :defense
  19. attr_accessor :spatk
  20. attr_writer :spdef
  21. attr_accessor :speed
  22. attr_accessor :stages
  23. attr_accessor :iv
  24. attr_accessor :moves
  25. attr_accessor :participants
  26. attr_accessor :tookDamage
  27. attr_accessor :lastHPLost
  28. attr_accessor :lastMoveUsed
  29. attr_accessor :lastMoveUsedType
  30. attr_accessor :lastMoveUsedSketch
  31. attr_accessor :lastRegularMoveUsed
  32. attr_accessor :lastRoundMoved
  33. attr_accessor :movesUsed
  34. attr_accessor :currentMove
  35. attr_accessor :damagestate
  36. attr_accessor :captured
  37.  
  38. def inHyperMode?; return false; end
  39. def isShadow?; return false; end
  40.  
  41. ################################################################################
  42. # Complex accessors
  43. ################################################################################
  44. def defense
  45. return @battle.field.effects[PBEffects::WonderRoom]>0 ? @spdef : @defense
  46. end
  47.  
  48. def spdef
  49. return @battle.field.effects[PBEffects::WonderRoom]>0 ? @defense : @spdef
  50. end
  51.  
  52. def nature
  53. return (@pokemon) ? @pokemon.nature : 0
  54. end
  55.  
  56. def happiness
  57. return (@pokemon) ? @pokemon.happiness : 0
  58. end
  59.  
  60. def pokerusStage
  61. return (@pokemon) ? @pokemon.pokerusStage : 0
  62. end
  63.  
  64. attr_reader :form
  65.  
  66. def form=(value)
  67. @form=value
  68. @pokemon.form=value if @pokemon
  69. end
  70.  
  71. def hasMega?
  72. return false if @effects[PBEffects::Transform]
  73. if @pokemon
  74. return (@pokemon.hasMegaForm? rescue false)
  75. end
  76. return false
  77. end
  78.  
  79. def isMega?
  80. if @pokemon
  81. return (@pokemon.isMega? rescue false)
  82. end
  83. return false
  84. end
  85.  
  86. def hasPrimal?
  87. return false if @effects[PBEffects::Transform]
  88. if @pokemon
  89. return (@pokemon.hasPrimalForm? rescue false)
  90. end
  91. return false
  92. end
  93.  
  94. def isPrimal?
  95. if @pokemon
  96. return (@pokemon.isPrimal? rescue false)
  97. end
  98. return false
  99. end
  100.  
  101. attr_reader :level
  102.  
  103. def level=(value)
  104. @level=value
  105. @pokemon.level=(value) if @pokemon
  106. end
  107.  
  108. attr_reader :status
  109.  
  110. def status=(value)
  111. if @status==PBStatuses::SLEEP && value==0
  112. @effects[PBEffects::Truant]=false
  113. end
  114. @status=value
  115. @pokemon.status=value if @pokemon
  116. if value!=PBStatuses::POISON
  117. @effects[PBEffects::Toxic]=0
  118. end
  119. if value!=PBStatuses::POISON && value!=PBStatuses::SLEEP
  120. @statusCount=0
  121. @pokemon.statusCount=0 if @pokemon
  122. end
  123. end
  124.  
  125. attr_reader :statusCount
  126.  
  127. def statusCount=(value)
  128. @statusCount=value
  129. @pokemon.statusCount=value if @pokemon
  130. end
  131.  
  132. attr_reader :hp
  133.  
  134. def hp=(value)
  135. @hp=value.to_i
  136. @pokemon.hp=value.to_i if @pokemon
  137. end
  138.  
  139. attr_reader :item
  140.  
  141. def item=(value)
  142. @item=value
  143. @pokemon.setItem(value) if @pokemon
  144. end
  145.  
  146. def weight(attacker=nil)
  147. w=(@pokemon) ? @pokemon.weight : 500
  148. if !attacker || !attacker.hasMoldBreaker
  149. w*=2 if self.hasWorkingAbility(:HEAVYMETAL)
  150. w/=2 if self.hasWorkingAbility(:LIGHTMETAL)
  151. end
  152. w/=2 if self.hasWorkingItem(:FLOATSTONE)
  153. w+=@effects[PBEffects::WeightChange]
  154. w=w.floor
  155. w=1 if w<1
  156. return w
  157. end
  158.  
  159. def name
  160. if @effects[PBEffects::Illusion]
  161. return @effects[PBEffects::Illusion].name
  162. end
  163. return @name
  164. end
  165.  
  166. def displayGender
  167. if @effects[PBEffects::Illusion]
  168. return @effects[PBEffects::Illusion].gender
  169. end
  170. return self.gender
  171. end
  172.  
  173. def isShiny?
  174. if @effects[PBEffects::Illusion]
  175. return @effects[PBEffects::Illusion].isShiny?
  176. end
  177. return @pokemon.isShiny? if @pokemon
  178. return false
  179. end
  180.  
  181. def owned
  182. return (@pokemon) ? $Trainer.owned[@pokemon.species] && !@battle.opponent : false
  183. end
  184.  
  185. ################################################################################
  186. # Creating a battler
  187. ################################################################################
  188. def initialize(btl,index)
  189. @battle = btl
  190. @index = index
  191. @hp = 0
  192. @totalhp = 0
  193. @fainted = true
  194. @captured = false
  195. @stages = []
  196. @effects = []
  197. @damagestate = PokeBattle_DamageState.new
  198. pbInitBlank
  199. pbInitEffects(false)
  200. pbInitPermanentEffects
  201. end
  202.  
  203. def pbInitPokemon(pkmn,pkmnIndex)
  204. if pkmn.isEgg?
  205. raise _INTL("An egg can't be an active Pokémon")
  206. end
  207. @name = pkmn.name
  208. @species = pkmn.species
  209. @level = pkmn.level
  210. @hp = pkmn.hp
  211. @totalhp = pkmn.totalhp
  212. @gender = pkmn.gender
  213. @ability = pkmn.ability
  214. @item = pkmn.item
  215. @type1 = pkmn.type1
  216. @type2 = pkmn.type2
  217. @form = pkmn.form
  218. @attack = pkmn.attack
  219. @defense = pkmn.defense
  220. @speed = pkmn.speed
  221. @spatk = pkmn.spatk
  222. @spdef = pkmn.spdef
  223. @status = pkmn.status
  224. @statusCount = pkmn.statusCount
  225. @pokemon = pkmn
  226. @pokemonIndex = pkmnIndex
  227. @participants = [] # Participants will earn Exp. Points if this battler is defeated
  228. @moves = [
  229. PokeBattle_Move.pbFromPBMove(@battle,pkmn.moves[0]),
  230. PokeBattle_Move.pbFromPBMove(@battle,pkmn.moves[1]),
  231. PokeBattle_Move.pbFromPBMove(@battle,pkmn.moves[2]),
  232. PokeBattle_Move.pbFromPBMove(@battle,pkmn.moves[3])
  233. ]
  234. @iv = []
  235. @iv[0] = pkmn.iv[0]
  236. @iv[1] = pkmn.iv[1]
  237. @iv[2] = pkmn.iv[2]
  238. @iv[3] = pkmn.iv[3]
  239. @iv[4] = pkmn.iv[4]
  240. @iv[5] = pkmn.iv[5]
  241. end
  242.  
  243. def pbInitDummyPokemon(pkmn,pkmnIndex)
  244. if pkmn.isEgg?
  245. raise _INTL("An egg can't be an active Pokémon")
  246. end
  247. @name = pkmn.name
  248. @species = pkmn.species
  249. @level = pkmn.level
  250. @hp = pkmn.hp
  251. @totalhp = pkmn.totalhp
  252. @gender = pkmn.gender
  253. @type1 = pkmn.type1
  254. @type2 = pkmn.type2
  255. @form = pkmn.form
  256. @attack = pkmn.attack
  257. @defense = pkmn.defense
  258. @speed = pkmn.speed
  259. @spatk = pkmn.spatk
  260. @spdef = pkmn.spdef
  261. @status = pkmn.status
  262. @statusCount = pkmn.statusCount
  263. @pokemon = pkmn
  264. @pokemonIndex = pkmnIndex
  265. @participants = []
  266. @iv = []
  267. @iv[0] = pkmn.iv[0]
  268. @iv[1] = pkmn.iv[1]
  269. @iv[2] = pkmn.iv[2]
  270. @iv[3] = pkmn.iv[3]
  271. @iv[4] = pkmn.iv[4]
  272. @iv[5] = pkmn.iv[5]
  273. end
  274.  
  275. def pbInitBlank
  276. @name = ""
  277. @species = 0
  278. @level = 0
  279. @hp = 0
  280. @totalhp = 0
  281. @gender = 0
  282. @ability = 0
  283. @type1 = 0
  284. @type2 = 0
  285. @form = 0
  286. @attack = 0
  287. @defense = 0
  288. @speed = 0
  289. @spatk = 0
  290. @spdef = 0
  291. @status = 0
  292. @statusCount = 0
  293. @pokemon = nil
  294. @pokemonIndex = -1
  295. @participants = []
  296. @moves = [nil,nil,nil,nil]
  297. @iv = [0,0,0,0,0,0]
  298. @item = 0
  299. @weight = nil
  300. end
  301.  
  302. def pbInitPermanentEffects
  303. # These effects are always retained even if a Pokémon is replaced
  304. @effects[PBEffects::FutureSight] = 0
  305. @effects[PBEffects::FutureSightMove] = 0
  306. @effects[PBEffects::FutureSightUser] = -1
  307. @effects[PBEffects::FutureSightUserPos] = -1
  308. @effects[PBEffects::HealingWish] = false
  309. @effects[PBEffects::LunarDance] = false
  310. @effects[PBEffects::Wish] = 0
  311. @effects[PBEffects::WishAmount] = 0
  312. @effects[PBEffects::WishMaker] = -1
  313. end
  314.  
  315. def pbInitEffects(batonpass)
  316. if !batonpass
  317. # These effects are retained if Baton Pass is used
  318. @stages[PBStats::ATTACK] = 0
  319. @stages[PBStats::DEFENSE] = 0
  320. @stages[PBStats::SPEED] = 0
  321. @stages[PBStats::SPATK] = 0
  322. @stages[PBStats::SPDEF] = 0
  323. @stages[PBStats::EVASION] = 0
  324. @stages[PBStats::ACCURACY] = 0
  325. @lastMoveUsedSketch = -1
  326. @effects[PBEffects::AquaRing] = false
  327. @effects[PBEffects::Confusion] = 0
  328. @effects[PBEffects::Curse] = false
  329. @effects[PBEffects::Embargo] = 0
  330. @effects[PBEffects::FocusEnergy] = 0
  331. @effects[PBEffects::GastroAcid] = false
  332. @effects[PBEffects::HealBlock] = 0
  333. @effects[PBEffects::Ingrain] = false
  334. @effects[PBEffects::LeechSeed] = -1
  335. @effects[PBEffects::LockOn] = 0
  336. @effects[PBEffects::LockOnPos] = -1
  337. for i in 0...4
  338. next if !@battle.battlers[i]
  339. if @battle.battlers[i].effects[PBEffects::LockOnPos]==@index &&
  340. @battle.battlers[i].effects[PBEffects::LockOn]>0
  341. @battle.battlers[i].effects[PBEffects::LockOn]=0
  342. @battle.battlers[i].effects[PBEffects::LockOnPos]=-1
  343. end
  344. end
  345. @effects[PBEffects::MagnetRise] = 0
  346. @effects[PBEffects::PerishSong] = 0
  347. @effects[PBEffects::PerishSongUser] = -1
  348. @effects[PBEffects::PowerTrick] = false
  349. @effects[PBEffects::Substitute] = 0
  350. @effects[PBEffects::Telekinesis] = 0
  351. else
  352. if @effects[PBEffects::LockOn]>0
  353. @effects[PBEffects::LockOn]=2
  354. else
  355. @effects[PBEffects::LockOn]=0
  356. end
  357. if @effects[PBEffects::PowerTrick]
  358. @attack,@defense=@defense,@attack
  359. end
  360. end
  361. @damagestate.reset
  362. @fainted = false
  363. @lastAttacker = []
  364. @lastHPLost = 0
  365. @tookDamage = false
  366. @lastMoveUsed = -1
  367. @lastMoveUsedType = -1
  368. @lastRoundMoved = -1
  369. @movesUsed = []
  370. @turncount = 0
  371. @effects[PBEffects::Attract] = -1
  372. for i in 0...4
  373. next if !@battle.battlers[i]
  374. if @battle.battlers[i].effects[PBEffects::Attract]==@index
  375. @battle.battlers[i].effects[PBEffects::Attract]=-1
  376. end
  377. end
  378. @effects[PBEffects::BatonPass] = false
  379. @effects[PBEffects::Bide] = 0
  380. @effects[PBEffects::BideDamage] = 0
  381. @effects[PBEffects::BideTarget] = -1
  382. @effects[PBEffects::Charge] = 0
  383. @effects[PBEffects::ChoiceBand] = -1
  384. @effects[PBEffects::Counter] = -1
  385. @effects[PBEffects::CounterTarget] = -1
  386. @effects[PBEffects::DefenseCurl] = false
  387. @effects[PBEffects::DestinyBond] = false
  388. @effects[PBEffects::Disable] = 0
  389. @effects[PBEffects::DisableMove] = 0
  390. @effects[PBEffects::Electrify] = false
  391. @effects[PBEffects::Encore] = 0
  392. @effects[PBEffects::EncoreIndex] = 0
  393. @effects[PBEffects::EncoreMove] = 0
  394. @effects[PBEffects::Endure] = false
  395. @effects[PBEffects::FirstPledge] = 0
  396. @effects[PBEffects::FlashFire] = false
  397. @effects[PBEffects::Flinch] = false
  398. @effects[PBEffects::FollowMe] = 0
  399. @effects[PBEffects::Foresight] = false
  400. @effects[PBEffects::FuryCutter] = 0
  401. @effects[PBEffects::Grudge] = false
  402. @effects[PBEffects::HelpingHand] = false
  403. @effects[PBEffects::HyperBeam] = 0
  404. @effects[PBEffects::Illusion] = nil
  405. if self.hasWorkingAbility(:ILLUSION)
  406. lastpoke=@battle.pbGetLastPokeInTeam(@index)
  407. if lastpoke!=@pokemonIndex
  408. @effects[PBEffects::Illusion] = @battle.pbParty(@index)[lastpoke]
  409. end
  410. end
  411. @effects[PBEffects::Imprison] = false
  412. @effects[PBEffects::KingsShield] = false
  413. @effects[PBEffects::LifeOrb] = false
  414. @effects[PBEffects::MagicCoat] = false
  415. @effects[PBEffects::MeanLook] = -1
  416. for i in 0...4
  417. next if !@battle.battlers[i]
  418. if @battle.battlers[i].effects[PBEffects::MeanLook]==@index
  419. @battle.battlers[i].effects[PBEffects::MeanLook]=-1
  420. end
  421. end
  422. @effects[PBEffects::MeFirst] = false
  423. @effects[PBEffects::Metronome] = 0
  424. @effects[PBEffects::MicleBerry] = false
  425. @effects[PBEffects::Minimize] = false
  426. @effects[PBEffects::MiracleEye] = false
  427. @effects[PBEffects::GranCataclismo] = false #nuevo
  428. @effects[PBEffects::MirrorCoat] = -1
  429. @effects[PBEffects::MirrorCoatTarget] = -1
  430. @effects[PBEffects::MoveNext] = false
  431. @effects[PBEffects::MudSport] = false
  432. @effects[PBEffects::MultiTurn] = 0
  433. @effects[PBEffects::MultiTurnAttack] = 0
  434. @effects[PBEffects::MultiTurnUser] = -1
  435. for i in 0...4
  436. next if !@battle.battlers[i]
  437. if @battle.battlers[i].effects[PBEffects::MultiTurnUser]==@index
  438. @battle.battlers[i].effects[PBEffects::MultiTurn]=0
  439. @battle.battlers[i].effects[PBEffects::MultiTurnUser]=-1
  440. end
  441. end
  442. @effects[PBEffects::Nightmare] = false
  443. @effects[PBEffects::Outrage] = 0
  444. @effects[PBEffects::ParentalBond] = 0
  445. @effects[PBEffects::PickupItem] = 0
  446. @effects[PBEffects::PickupUse] = 0
  447. @effects[PBEffects::Pinch] = false
  448. @effects[PBEffects::Powder] = false
  449. @effects[PBEffects::Protect] = false
  450. @effects[PBEffects::ProtectNegation] = false
  451. @effects[PBEffects::ProtectRate] = 1
  452. @effects[PBEffects::Pursuit] = false
  453. @effects[PBEffects::Quash] = false
  454. @effects[PBEffects::Rage] = false
  455. @effects[PBEffects::Revenge] = 0
  456. @effects[PBEffects::Roar] = false
  457. @effects[PBEffects::Rollout] = 0
  458. @effects[PBEffects::Roost] = false
  459. @effects[PBEffects::SkipTurn] = false
  460. @effects[PBEffects::SkyDrop] = false
  461. @effects[PBEffects::SmackDown] = false
  462. @effects[PBEffects::Snatch] = false
  463. @effects[PBEffects::SpikyShield] = false
  464. @effects[PBEffects::Stockpile] = 0
  465. @effects[PBEffects::StockpileDef] = 0
  466. @effects[PBEffects::StockpileSpDef] = 0
  467. @effects[PBEffects::Taunt] = 0
  468. @effects[PBEffects::Torment] = false
  469. @effects[PBEffects::Toxic] = 0
  470. @effects[PBEffects::Transform] = false
  471. @effects[PBEffects::Truant] = false
  472. @effects[PBEffects::TwoTurnAttack] = 0
  473. @effects[PBEffects::Type3] = -1
  474. @effects[PBEffects::Unburden] = false
  475. @effects[PBEffects::Uproar] = 0
  476. @effects[PBEffects::Uturn] = false
  477. @effects[PBEffects::WaterSport] = false
  478. @effects[PBEffects::WeightChange] = 0
  479. @effects[PBEffects::Yawn] = 0
  480. end
  481.  
  482. def pbUpdate(fullchange=false)
  483. if @pokemon
  484. @pokemon.calcStats
  485. @level = @pokemon.level
  486. @hp = @pokemon.hp
  487. @totalhp = @pokemon.totalhp
  488. if !@effects[PBEffects::Transform]
  489. @attack = @pokemon.attack
  490. @defense = @pokemon.defense
  491. @speed = @pokemon.speed
  492. @spatk = @pokemon.spatk
  493. @spdef = @pokemon.spdef
  494. if fullchange
  495. @ability = @pokemon.ability
  496. @type1 = @pokemon.type1
  497. @type2 = @pokemon.type2
  498. end
  499. end
  500. end
  501. end
  502.  
  503. def pbInitialize(pkmn,index,batonpass)
  504. # Cure status of previous Pokemon with Natural Cure
  505. if self.hasWorkingAbility(:NATURALCURE)
  506. self.status=0
  507. end
  508. if self.hasWorkingAbility(:REGENERATOR)
  509. self.pbRecoverHP((totalhp/3).floor)
  510. end
  511. pbInitPokemon(pkmn,index)
  512. pbInitEffects(batonpass)
  513. end
  514.  
  515. # Used only to erase the battler of a Shadow Pokémon that has been snagged.
  516. def pbReset
  517. @pokemon = nil
  518. @pokemonIndex = -1
  519. self.hp = 0
  520. pbInitEffects(false)
  521. # reset status
  522. self.status = 0
  523. self.statusCount = 0
  524. @fainted = true
  525. # reset choice
  526. @battle.choices[@index] = [0,0,nil,-1]
  527. return true
  528. end
  529.  
  530. # Update Pokémon who will gain EXP if this battler is defeated
  531. def pbUpdateParticipants
  532. return if self.isFainted? # can't update if already fainted
  533. if @battle.pbIsOpposing?(@index)
  534. found1=false
  535. found2=false
  536. for i in @participants
  537. found1=true if i==pbOpposing1.pokemonIndex
  538. found2=true if i==pbOpposing2.pokemonIndex
  539. end
  540. if !found1 && !pbOpposing1.isFainted?
  541. @participants[@participants.length]=pbOpposing1.pokemonIndex
  542. end
  543. if !found2 && !pbOpposing2.isFainted?
  544. @participants[@participants.length]=pbOpposing2.pokemonIndex
  545. end
  546. end
  547. end
  548.  
  549. ################################################################################
  550. # About this battler
  551. ################################################################################
  552. def pbThis(lowercase=false)
  553. if @battle.pbIsOpposing?(@index)
  554. if @battle.opponent
  555. return lowercase ? _INTL("the opposing {1}",self.name) : _INTL("The opposing {1}",self.name)
  556. else
  557. return lowercase ? _INTL("the wild {1}",self.name) : _INTL("The wild {1}",self.name)
  558. end
  559. elsif @battle.pbOwnedByPlayer?(@index)
  560. return _INTL("{1}",self.name)
  561. else
  562. return lowercase ? _INTL("the ally {1}",self.name) : _INTL("The ally {1}",self.name)
  563. end
  564. end
  565.  
  566. def pbHasType?(type)
  567. ret=false
  568. if type.is_a?(Symbol) || type.is_a?(String)
  569. ret=isConst?(self.type1,PBTypes,type.to_sym) ||
  570. isConst?(self.type2,PBTypes,type.to_sym)
  571. if @effects[PBEffects::Type3]>=0
  572. ret|=isConst?(@effects[PBEffects::Type3],PBTypes,type.to_sym)
  573. end
  574. else
  575. ret=(self.type1==type || self.type2==type)
  576. if @effects[PBEffects::Type3]>=0
  577. ret|=(@effects[PBEffects::Type3]==type)
  578. end
  579. end
  580. return ret
  581. end
  582.  
  583. def pbHasMove?(id)
  584. if id.is_a?(String) || id.is_a?(Symbol)
  585. id=getID(PBMoves,id)
  586. end
  587. return false if !id || id==0
  588. for i in @moves
  589. return true if i.id==id
  590. end
  591. return false
  592. end
  593.  
  594. def pbHasMoveType?(type)
  595. if type.is_a?(String) || type.is_a?(Symbol)
  596. type=getID(PBTypes,type)
  597. end
  598. return false if !type || type<0
  599. for i in @moves
  600. return true if i.type==type
  601. end
  602. return false
  603. end
  604.  
  605. def pbHasMoveFunction?(code)
  606. return false if !code
  607. for i in @moves
  608. return true if i.function==code
  609. end
  610. return false
  611. end
  612.  
  613. def hasMovedThisRound?
  614. return false if !@lastRoundMoved
  615. return @lastRoundMoved==@battle.turncount
  616. end
  617.  
  618. def isFainted?
  619. return @hp<=0
  620. end
  621.  
  622. def hasMoldBreaker
  623. return true if hasWorkingAbility(:MOLDBREAKER) ||
  624. hasWorkingAbility(:TERAVOLT) ||
  625. hasWorkingAbility(:TURBOBLAZE)
  626. return false
  627. end
  628.  
  629. def hasWorkingAbility(ability,ignorefainted=false)
  630. return false if self.isFainted? && !ignorefainted
  631. return false if @effects[PBEffects::GastroAcid]
  632. return isConst?(@ability,PBAbilities,ability)
  633. end
  634.  
  635. def hasWorkingItem(item,ignorefainted=false)
  636. return false if self.isFainted? && !ignorefainted
  637. return false if @effects[PBEffects::Embargo]>0
  638. return false if @battle.field.effects[PBEffects::MagicRoom]>0
  639. return false if self.hasWorkingAbility(:KLUTZ,ignorefainted)
  640. return isConst?(@item,PBItems,item)
  641. end
  642.  
  643. def isAirborne?(ignoreability=false)
  644. return false if self.hasWorkingItem(:IRONBALL)
  645. return false if @effects[PBEffects::Ingrain]
  646. return false if @effects[PBEffects::SmackDown]
  647. return false if @battle.field.effects[PBEffects::Gravity]>0
  648. return true if self.pbHasType?(:FLYING) && !@effects[PBEffects::Roost]
  649. return true if self.hasWorkingAbility(:LEVITATE) && !ignoreability
  650. return true if self.hasWorkingItem(:AIRBALLOON)
  651. return true if @effects[PBEffects::MagnetRise]>0
  652. return true if @effects[PBEffects::Telekinesis]>0
  653. return false
  654. end
  655.  
  656. def pbSpeed()
  657. stagemul=[10,10,10,10,10,10,10,15,20,25,30,35,40]
  658. stagediv=[40,35,30,25,20,15,10,10,10,10,10,10,10]
  659. speed=@speed
  660. stage=@stages[PBStats::SPEED]+6
  661. speed=(speed*stagemul[stage]/stagediv[stage]).floor
  662. speedmult=0x1000
  663. case @battle.pbWeather
  664. when PBWeather::RAINDANCE, PBWeather::HEAVYRAIN
  665. speedmult=speedmult*2 if self.hasWorkingAbility(:SWIFTSWIM)
  666. when PBWeather::SUNNYDAY, PBWeather::HARSHSUN
  667. speedmult=speedmult*2 if self.hasWorkingAbility(:CHLOROPHYLL)
  668. when PBWeather::SANDSTORM
  669. speedmult=speedmult*2 if self.hasWorkingAbility(:SANDRUSH)
  670. end
  671. if self.hasWorkingAbility(:QUICKFEET) && self.status>0
  672. speedmult=(speedmult*1.5).round
  673. end
  674. if self.hasWorkingAbility(:UNBURDEN) && @effects[PBEffects::Unburden] &&
  675. self.item==0
  676. speedmult=speedmult*2
  677. end
  678. if self.hasWorkingAbility(:SLOWSTART) && self.turncount<=5
  679. speedmult=(speedmult/2).round
  680. end
  681. if self.hasWorkingItem(:MACHOBRACE) ||
  682. self.hasWorkingItem(:POWERWEIGHT) ||
  683. self.hasWorkingItem(:POWERBRACER) ||
  684. self.hasWorkingItem(:POWERBELT) ||
  685. self.hasWorkingItem(:POWERANKLET) ||
  686. self.hasWorkingItem(:POWERLENS) ||
  687. self.hasWorkingItem(:POWERBAND)
  688. speedmult=(speedmult/2).round
  689. end
  690. if self.hasWorkingItem(:CHOICESCARF)
  691. speedmult=(speedmult*1.5).round
  692. end
  693. if isConst?(self.item,PBItems,:IRONBALL)
  694. speedmult=(speedmult/2).round
  695. end
  696. if self.hasWorkingItem(:QUICKPOWDER) && isConst?(self.species,PBSpecies,:DITTO) &&
  697. !@effects[PBEffects::Transform]
  698. speedmult=speedmult*2
  699. end
  700. if self.pbOwnSide.effects[PBEffects::Tailwind]>0
  701. speedmult=speedmult*2
  702. end
  703. if self.pbOwnSide.effects[PBEffects::Swamp]>0
  704. speedmult=(speedmult/2).round
  705. end
  706. if self.status==PBStatuses::PARALYSIS && !self.hasWorkingAbility(:QUICKFEET)
  707. speedmult=(speedmult/4).round
  708. end
  709. if @battle.internalbattle && @battle.pbOwnedByPlayer?(@index) &&
  710. @battle.pbPlayer.numbadges>=BADGESBOOSTSPEED
  711. speedmult=(speedmult*1.1).round
  712. end
  713. speed=(speed*speedmult*1.0/0x1000).round
  714. return [speed,1].max
  715. end
  716.  
  717. ################################################################################
  718. # Change HP
  719. ################################################################################
  720. def pbReduceHP(amt,anim=false,registerDamage=true)
  721. if amt>=self.hp
  722. amt=self.hp
  723. elsif amt<1 && !self.isFainted?
  724. amt=1
  725. end
  726. oldhp=self.hp
  727. self.hp-=amt
  728. raise _INTL("HP less than 0") if self.hp<0
  729. raise _INTL("HP greater than total HP") if self.hp>@totalhp
  730. @battle.scene.pbHPChanged(self,oldhp,anim) if amt>0
  731. @tookDamage=true if amt>0 && registerDamage
  732. return amt
  733. end
  734.  
  735. def pbRecoverHP(amt,anim=false)
  736. if self.hp+amt>@totalhp
  737. amt=@totalhp-self.hp
  738. elsif amt<1 && self.hp!=@totalhp
  739. amt=1
  740. end
  741. oldhp=self.hp
  742. self.hp+=amt
  743. raise _INTL("HP less than 0") if self.hp<0
  744. raise _INTL("HP greater than total HP") if self.hp>@totalhp
  745. @battle.scene.pbHPChanged(self,oldhp,anim) if amt>0
  746. return amt
  747. end
  748.  
  749. def pbFaint(showMessage=true)
  750. if !self.isFainted?
  751. PBDebug.log("!!!***Can't faint with HP greater than 0")
  752. return true
  753. end
  754. if @fainted
  755. # PBDebug.log("!!!***Can't faint if already fainted")
  756. return true
  757. end
  758. @battle.scene.pbFainted(self)
  759. pbInitEffects(false)
  760. # Reset status
  761. self.status=0
  762. self.statusCount=0
  763. if @pokemon && @battle.internalbattle
  764. @pokemon.changeHappiness("faint")
  765. end
  766. if self.isMega?
  767. @pokemon.makeUnmega
  768. end
  769. if self.isPrimal?
  770. @pokemon.makeUnprimal
  771. end
  772. @fainted=true
  773. # reset choice
  774. @battle.choices[@index]=[0,0,nil,-1]
  775. pbOwnSide.effects[PBEffects::LastRoundFainted]=@battle.turncount
  776. @battle.pbDisplayPaused(_INTL("{1} fainted!",pbThis)) if showMessage
  777. PBDebug.log("[Pokémon fainted] #{pbThis}")
  778. return true
  779. end
  780. ################################################################################
  781. # Find other battlers/sides in relation to this battler
  782. ################################################################################
  783. # Returns the data structure for this battler's side
  784. def pbOwnSide
  785. return @battle.sides[@index&1] # Player: 0 and 2; Foe: 1 and 3
  786. end
  787.  
  788. # Returns the data structure for the opposing Pokémon's side
  789. def pbOpposingSide
  790. return @battle.sides[(@index&1)^1] # Player: 1 and 3; Foe: 0 and 2
  791. end
  792.  
  793. # Returns whether the position belongs to the opposing Pokémon's side
  794. def pbIsOpposing?(i)
  795. return (@index&1)!=(i&1)
  796. end
  797.  
  798. # Returns the battler's partner
  799. def pbPartner
  800. return @battle.battlers[(@index&1)|((@index&2)^2)]
  801. end
  802.  
  803. # Returns the battler's first opposing Pokémon
  804. def pbOpposing1
  805. return @battle.battlers[((@index&1)^1)]
  806. end
  807.  
  808. # Returns the battler's second opposing Pokémon
  809. def pbOpposing2
  810. return @battle.battlers[((@index&1)^1)+2]
  811. end
  812.  
  813. def pbOppositeOpposing
  814. return @battle.battlers[(@index^1)]
  815. end
  816.  
  817. def pbOppositeOpposing2
  818. return @battle.battlers[(@index^1)|((@index&2)^2)]
  819. end
  820.  
  821. def pbNonActivePokemonCount()
  822. count=0
  823. party=@battle.pbParty(self.index)
  824. for i in 0...party.length
  825. if (self.isFainted? || i!=self.pokemonIndex) &&
  826. (pbPartner.isFainted? || i!=self.pbPartner.pokemonIndex) &&
  827. party[i] && !party[i].isEgg? && party[i].hp>0
  828. count+=1
  829. end
  830. end
  831. return count
  832. end
  833.  
  834. ################################################################################
  835. # Forms
  836. ################################################################################
  837. def pbCheckForm
  838. return if @effects[PBEffects::Transform]
  839. return if self.isFainted?
  840. transformed=false
  841. # Forecast
  842. if isConst?(self.species,PBSpecies,:CASTFORM)
  843. if self.hasWorkingAbility(:FORECAST)
  844. case @battle.pbWeather
  845. when PBWeather::SUNNYDAY, PBWeather::HARSHSUN
  846. if self.form!=1
  847. self.form=1; transformed=true
  848. end
  849. when PBWeather::RAINDANCE, PBWeather::HEAVYRAIN
  850. if self.form!=2
  851. self.form=2; transformed=true
  852. end
  853. when PBWeather::HAIL
  854. if self.form!=3
  855. self.form=3; transformed=true
  856. end
  857. else
  858. if self.form!=0
  859. self.form=0; transformed=true
  860. end
  861. end
  862. else
  863. if self.form!=0
  864. self.form=0; transformed=true
  865. end
  866. end
  867. end
  868. # Cherrim
  869. if isConst?(self.species,PBSpecies,:CHERRIM)
  870. if self.hasWorkingAbility(:FLOWERGIFT) &&
  871. (@battle.pbWeather==PBWeather::SUNNYDAY ||
  872. @battle.pbWeather==PBWeather::HARSHSUN)
  873. if self.form!=1
  874. self.form=1; transformed=true
  875. end
  876. else
  877. if self.form!=0
  878. self.form=0; transformed=true
  879. end
  880. end
  881. end
  882. # Shaymin
  883. if isConst?(self.species,PBSpecies,:SHAYMIN)
  884. if self.form!=@pokemon.form
  885. self.form=@pokemon.form
  886. transformed=true
  887. end
  888. end
  889. # Giratina
  890. if isConst?(self.species,PBSpecies,:GIRATINA)
  891. if self.form!=@pokemon.form
  892. self.form=@pokemon.form
  893. transformed=true
  894. end
  895. end
  896. # Arceus
  897. if isConst?(self.ability,PBAbilities,:MULTITYPE) &&
  898. isConst?(self.species,PBSpecies,:ARCEUS)
  899. if self.form!=@pokemon.form
  900. self.form=@pokemon.form
  901. transformed=true
  902. end
  903. end
  904. # Zen Mode
  905. if isConst?(self.species,PBSpecies,:DARMANITAN)
  906. if self.hasWorkingAbility(:ZENMODE) && @hp<=((@totalhp/2).floor)
  907. if self.form!=1
  908. self.form=1; transformed=true
  909. end
  910. else
  911. if self.form!=0
  912. self.form=0; transformed=true
  913. end
  914. end
  915. end
  916. # Keldeo
  917. if isConst?(self.species,PBSpecies,:KELDEO)
  918. if self.form!=@pokemon.form
  919. self.form=@pokemon.form
  920. transformed=true
  921. end
  922. end
  923. # Genesect
  924. if isConst?(self.species,PBSpecies,:GENESECT)
  925. if self.form!=@pokemon.form
  926. self.form=@pokemon.form
  927. transformed=true
  928. end
  929. end
  930. if transformed
  931. pbUpdate(true)
  932. @battle.scene.pbChangePokemon(self,@pokemon)
  933. @battle.pbDisplay(_INTL("{1} transformed!",pbThis))
  934. PBDebug.log("[Form changed] #{pbThis} changed to form #{self.form}")
  935. end
  936. end
  937.  
  938. def pbResetForm
  939. if !@effects[PBEffects::Transform]
  940. if isConst?(self.species,PBSpecies,:CASTFORM) ||
  941. isConst?(self.species,PBSpecies,:CHERRIM) ||
  942. isConst?(self.species,PBSpecies,:DARMANITAN) ||
  943. isConst?(self.species,PBSpecies,:MELOETTA) ||
  944. isConst?(self.species,PBSpecies,:AEGISLASH) ||
  945. isConst?(self.species,PBSpecies,:XERNEAS)
  946. self.form=0
  947. end
  948. end
  949. pbUpdate(true)
  950. end
  951.  
  952. ################################################################################
  953. # Ability effects
  954. ################################################################################
  955. def pbAbilitiesOnSwitchIn(onactive)
  956. return if self.isFainted?
  957. if onactive
  958. @battle.pbPrimalReversion(self.index)
  959. end
  960. # Weather
  961. if onactive
  962. if self.hasWorkingAbility(:PRIMORDIALSEA) && @battle.weather!=PBWeather::HEAVYRAIN
  963. @battle.weather=PBWeather::HEAVYRAIN
  964. @battle.weatherduration=-1
  965. @battle.pbCommonAnimation("HeavyRain",nil,nil)
  966. @battle.pbDisplay(_INTL("{1}'s {2} made a heavy rain begin to fall!",pbThis,PBAbilities.getName(self.ability)))
  967. PBDebug.log("[Ability triggered] #{pbThis}'s Primordial Sea made it rain heavily")
  968. end
  969. if self.hasWorkingAbility(:DESOLATELAND) && @battle.weather!=PBWeather::HARSHSUN
  970. @battle.weather=PBWeather::HARSHSUN
  971. @battle.weatherduration=-1
  972. @battle.pbCommonAnimation("HarshSun",nil,nil)
  973. @battle.pbDisplay(_INTL("{1}'s {2} turned the sunlight extremely harsh!",pbThis,PBAbilities.getName(self.ability)))
  974. PBDebug.log("[Ability triggered] #{pbThis}'s Desolate Land made the sun shine harshly")
  975. end
  976. if self.hasWorkingAbility(:DELTASTREAM) && @battle.weather!=PBWeather::STRONGWINDS
  977. @battle.weather=PBWeather::STRONGWINDS
  978. @battle.weatherduration=-1
  979. @battle.pbCommonAnimation("StrongWinds",nil,nil)
  980. @battle.pbDisplay(_INTL("{1}'s {2} caused a mysterious air current that protects Flying-type Pokémon!",pbThis,PBAbilities.getName(self.ability)))
  981. PBDebug.log("[Ability triggered] #{pbThis}'s Delta Stream made an air current blow")
  982. end
  983. if @battle.weather!=PBWeather::HEAVYRAIN &&
  984. @battle.weather!=PBWeather::HARSHSUN &&
  985. @battle.weather!=PBWeather::STRONGWINDS
  986. if self.hasWorkingAbility(:DRIZZLE) && (@battle.weather!=PBWeather::RAINDANCE || @battle.weatherduration!=-1)
  987. @battle.weather=PBWeather::RAINDANCE
  988. if USENEWBATTLEMECHANICS
  989. @battle.weatherduration=5
  990. @battle.weatherduration=8 if hasWorkingItem(:DAMPROCK)
  991. else
  992. @battle.weatherduration=-1
  993. end
  994. @battle.pbCommonAnimation("Rain",nil,nil)
  995. @battle.pbDisplay(_INTL("{1}'s {2} made it rain!",pbThis,PBAbilities.getName(self.ability)))
  996. PBDebug.log("[Ability triggered] #{pbThis}'s Drizzle made it rain")
  997. end
  998. if self.hasWorkingAbility(:DROUGHT) && (@battle.weather!=PBWeather::SUNNYDAY || @battle.weatherduration!=-1)
  999. @battle.weather=PBWeather::SUNNYDAY
  1000. if USENEWBATTLEMECHANICS
  1001. @battle.weatherduration=5
  1002. @battle.weatherduration=8 if hasWorkingItem(:HEATROCK)
  1003. else
  1004. @battle.weatherduration=-1
  1005. end
  1006. @battle.pbCommonAnimation("Sunny",nil,nil)
  1007. @battle.pbDisplay(_INTL("{1}'s {2} intensified the sun's rays!",pbThis,PBAbilities.getName(self.ability)))
  1008. PBDebug.log("[Ability triggered] #{pbThis}'s Drought made it sunny")
  1009. end
  1010. if self.hasWorkingAbility(:SANDSTREAM) && (@battle.weather!=PBWeather::SANDSTORM || @battle.weatherduration!=-1)
  1011. @battle.weather=PBWeather::SANDSTORM
  1012. if USENEWBATTLEMECHANICS
  1013. @battle.weatherduration=5
  1014. @battle.weatherduration=8 if hasWorkingItem(:SMOOTHROCK)
  1015. else
  1016. @battle.weatherduration=-1
  1017. end
  1018. @battle.pbCommonAnimation("Sandstorm",nil,nil)
  1019. @battle.pbDisplay(_INTL("{1}'s {2} whipped up a sandstorm!",pbThis,PBAbilities.getName(self.ability)))
  1020. PBDebug.log("[Ability triggered] #{pbThis}'s Sand Stream made it sandstorm")
  1021. end
  1022. if self.hasWorkingAbility(:SNOWWARNING) && (@battle.weather!=PBWeather::HAIL || @battle.weatherduration!=-1)
  1023. @battle.weather=PBWeather::HAIL
  1024. if USENEWBATTLEMECHANICS
  1025. @battle.weatherduration=5
  1026. @battle.weatherduration=8 if hasWorkingItem(:ICYROCK)
  1027. else
  1028. @battle.weatherduration=-1
  1029. end
  1030. @battle.pbCommonAnimation("Hail",nil,nil)
  1031. @battle.pbDisplay(_INTL("{1}'s {2} made it hail!",pbThis,PBAbilities.getName(self.ability)))
  1032. PBDebug.log("[Ability triggered] #{pbThis}'s Snow Warning made it hail")
  1033. end
  1034. end
  1035. if self.hasWorkingAbility(:AIRLOCK) ||
  1036. self.hasWorkingAbility(:CLOUDNINE)
  1037. @battle.pbDisplay(_INTL("{1} has {2}!",pbThis,PBAbilities.getName(self.ability)))
  1038. @battle.pbDisplay(_INTL("The effects of the weather disappeared."))
  1039. end
  1040. end
  1041. @battle.pbPrimordialWeather
  1042. # Trace
  1043. if self.hasWorkingAbility(:TRACE)
  1044. choices=[]
  1045. for i in 0...4
  1046. foe=@battle.battlers[i]
  1047. if pbIsOpposing?(i) && !foe.isFainted?
  1048. abil=foe.ability
  1049. if abil>0 &&
  1050. !isConst?(abil,PBAbilities,:TRACE) &&
  1051. !isConst?(abil,PBAbilities,:MULTITYPE) &&
  1052. !isConst?(abil,PBAbilities,:ILLUSION) &&
  1053. !isConst?(abil,PBAbilities,:FLOWERGIFT) &&
  1054. !isConst?(abil,PBAbilities,:IMPOSTER) &&
  1055. !isConst?(abil,PBAbilities,:STANCECHANGE)
  1056. choices.push(i)
  1057. end
  1058. end
  1059. end
  1060. if choices.length>0
  1061. choice=choices[@battle.pbRandom(choices.length)]
  1062. battlername=@battle.battlers[choice].pbThis(true)
  1063. battlerability=@battle.battlers[choice].ability
  1064. @ability=battlerability
  1065. abilityname=PBAbilities.getName(battlerability)
  1066. @battle.pbDisplay(_INTL("{1} traced {2}'s {3}!",pbThis,battlername,abilityname))
  1067. PBDebug.log("[Ability triggered] #{pbThis}'s Trace turned into #{abilityname} from #{battlername}")
  1068. end
  1069. end
  1070. # Intimidate
  1071. if self.hasWorkingAbility(:INTIMIDATE) && onactive
  1072. PBDebug.log("[Ability triggered] #{pbThis}'s Intimidate")
  1073. for i in 0...4
  1074. if pbIsOpposing?(i) && !@battle.battlers[i].isFainted?
  1075. @battle.battlers[i].pbReduceAttackStatIntimidate(self)
  1076. end
  1077. end
  1078. end
  1079. # Download
  1080. if self.hasWorkingAbility(:DOWNLOAD) && onactive
  1081. odef=ospdef=0
  1082. if pbOpposing1 && !pbOpposing1.isFainted?
  1083. odef+=pbOpposing1.defense
  1084. ospdef+=pbOpposing1.spdef
  1085. end
  1086. if pbOpposing2 && !pbOpposing2.isFainted?
  1087. odef+=pbOpposing2.defense
  1088. ospdef+=pbOpposing1.spdef
  1089. end
  1090. if ospdef>odef
  1091. if pbIncreaseStatWithCause(PBStats::ATTACK,1,self,PBAbilities.getName(ability))
  1092. PBDebug.log("[Ability triggered] #{pbThis}'s Download (raising Attack)")
  1093. end
  1094. else
  1095. if pbIncreaseStatWithCause(PBStats::SPATK,1,self,PBAbilities.getName(ability))
  1096. PBDebug.log("[Ability triggered] #{pbThis}'s Download (raising Special Attack)")
  1097. end
  1098. end
  1099. end
  1100. # Frisk
  1101. if self.hasWorkingAbility(:FRISK) && @battle.pbOwnedByPlayer?(@index) && onactive
  1102. foes=[]
  1103. foes.push(pbOpposing1) if pbOpposing1.item>0 && !pbOpposing1.isFainted?
  1104. foes.push(pbOpposing2) if pbOpposing2.item>0 && !pbOpposing2.isFainted?
  1105. if USENEWBATTLEMECHANICS
  1106. PBDebug.log("[Ability triggered] #{pbThis}'s Frisk") if foes.length>0
  1107. for i in foes
  1108. itemname=PBItems.getName(i.item)
  1109. @battle.pbDisplay(_INTL("{1} frisked {2} and found its {3}!",pbThis,i.pbThis(true),itemname))
  1110. end
  1111. elsif foes.length>0
  1112. PBDebug.log("[Ability triggered] #{pbThis}'s Frisk")
  1113. foe=foes[@battle.pbRandom(foes.length)]
  1114. itemname=PBItems.getName(foe.item)
  1115. @battle.pbDisplay(_INTL("{1} frisked the foe and found one {2}!",pbThis,itemname))
  1116. end
  1117. end
  1118. # Anticipation
  1119. if self.hasWorkingAbility(:ANTICIPATION) && @battle.pbOwnedByPlayer?(@index) && onactive
  1120. PBDebug.log("[Ability triggered] #{pbThis} has Anticipation")
  1121. found=false
  1122. for foe in [pbOpposing1,pbOpposing2]
  1123. next if foe.isFainted?
  1124. for j in foe.moves
  1125. movedata=PBMoveData.new(j.id)
  1126. eff=PBTypes.getCombinedEffectiveness(movedata.type,type1,type2,@effects[PBEffects::Type3])
  1127. if (movedata.basedamage>0 && eff>8) ||
  1128. (movedata.function==0x70 && eff>0) # OHKO
  1129. found=true
  1130. break
  1131. end
  1132. end
  1133. break if found
  1134. end
  1135. @battle.pbDisplay(_INTL("{1} shuddered with anticipation!",pbThis)) if found
  1136. end
  1137. # Forewarn
  1138. if self.hasWorkingAbility(:FOREWARN) && @battle.pbOwnedByPlayer?(@index) && onactive
  1139. PBDebug.log("[Ability triggered] #{pbThis} has Forewarn")
  1140. highpower=0
  1141. fwmoves=[]
  1142. for foe in [pbOpposing1,pbOpposing2]
  1143. next if foe.isFainted?
  1144. for j in foe.moves
  1145. movedata=PBMoveData.new(j.id)
  1146. power=movedata.basedamage
  1147. power=160 if movedata.function==0x70 # OHKO
  1148. power=150 if movedata.function==0x8B # Eruption
  1149. power=120 if movedata.function==0x71 || # Counter
  1150. movedata.function==0x72 || # Mirror Coat
  1151. movedata.function==0x73 || # Metal Burst
  1152. power=80 if movedata.function==0x6A || # SonicBoom
  1153. movedata.function==0x6B || # Dragon Rage
  1154. movedata.function==0x6D || # Night Shade
  1155. movedata.function==0x6E || # Endeavor
  1156. movedata.function==0x6F || # Psywave
  1157. movedata.function==0x89 || # Return
  1158. movedata.function==0x8A || # Frustration
  1159. movedata.function==0x8C || # Crush Grip
  1160. movedata.function==0x8D || # Gyro Ball
  1161. movedata.function==0x90 || # Hidden Power
  1162. movedata.function==0x96 || # Natural Gift
  1163. movedata.function==0x97 || # Trump Card
  1164. movedata.function==0x98 || # Flail
  1165. movedata.function==0x9A # Grass Knot
  1166. if power>highpower
  1167. fwmoves=[j.id]; highpower=power
  1168. elsif power==highpower
  1169. fwmoves.push(j.id)
  1170. end
  1171. end
  1172. end
  1173. if fwmoves.length>0
  1174. fwmove=fwmoves[@battle.pbRandom(fwmoves.length)]
  1175. movename=PBMoves.getName(fwmove)
  1176. @battle.pbDisplay(_INTL("{1}'s Forewarn alerted it to {2}!",pbThis,movename))
  1177. end
  1178. end
  1179. # Pressure message
  1180. if self.hasWorkingAbility(:PRESSURE) && onactive
  1181. @battle.pbDisplay(_INTL("{1} is exerting its pressure!",pbThis))
  1182. end
  1183. # Mold Breaker message
  1184. if self.hasWorkingAbility(:MOLDBREAKER) && onactive
  1185. @battle.pbDisplay(_INTL("{1} breaks the mold!",pbThis))
  1186. end
  1187. # Turboblaze message
  1188. if self.hasWorkingAbility(:TURBOBLAZE) && onactive
  1189. @battle.pbDisplay(_INTL("{1} is radiating a blazing aura!",pbThis))
  1190. end
  1191. # Teravolt message
  1192. if self.hasWorkingAbility(:TERAVOLT) && onactive
  1193. @battle.pbDisplay(_INTL("{1} is radiating a bursting aura!",pbThis))
  1194. end
  1195. # Dark Aura message
  1196. if self.hasWorkingAbility(:DARKAURA) && onactive
  1197. @battle.pbDisplay(_INTL("{1} is radiating a dark aura!",pbThis))
  1198. end
  1199. # Fairy Aura message
  1200. if self.hasWorkingAbility(:FAIRYAURA) && onactive
  1201. @battle.pbDisplay(_INTL("{1} is radiating a fairy aura!",pbThis))
  1202. end
  1203. # Aura Break message
  1204. if self.hasWorkingAbility(:AURABREAK) && onactive
  1205. @battle.pbDisplay(_INTL("{1} reversed all other Pokémon's auras!",pbThis))
  1206. end
  1207. # Imposter
  1208. if self.hasWorkingAbility(:IMPOSTER) && !@effects[PBEffects::Transform] && onactive
  1209. choice=pbOppositeOpposing
  1210. blacklist=[
  1211. 0xC9, # Fly
  1212. 0xCA, # Dig
  1213. 0xCB, # Dive
  1214. 0xCC, # Bounce
  1215. 0xCD, # Shadow Force
  1216. 0xCE, # Sky Drop
  1217. 0x14D # Phantom Force
  1218. ]
  1219. if choice.effects[PBEffects::Transform] ||
  1220. choice.effects[PBEffects::Illusion] ||
  1221. choice.effects[PBEffects::Substitute]>0 ||
  1222. choice.effects[PBEffects::SkyDrop] ||
  1223. blacklist.include?(PBMoveData.new(choice.effects[PBEffects::TwoTurnAttack]).function)
  1224. PBDebug.log("[Ability triggered] #{pbThis}'s Imposter couldn't transform")
  1225. else
  1226. PBDebug.log("[Ability triggered] #{pbThis}'s Imposter")
  1227. @battle.pbAnimation(getConst(PBMoves,:TRANSFORM),self,choice)
  1228. @effects[PBEffects::Transform]=true
  1229. @type1=choice.type1
  1230. @type2=choice.type2
  1231. @effects[PBEffects::Type3]=-1
  1232. @ability=choice.ability
  1233. @attack=choice.attack
  1234. @defense=choice.defense
  1235. @speed=choice.speed
  1236. @spatk=choice.spatk
  1237. @spdef=choice.spdef
  1238. for i in [PBStats::ATTACK,PBStats::DEFENSE,PBStats::SPEED,
  1239. PBStats::SPATK,PBStats::SPDEF,PBStats::ACCURACY,PBStats::EVASION]
  1240. @stages[i]=choice.stages[i]
  1241. end
  1242. for i in 0...4
  1243. @moves[i]=PokeBattle_Move.pbFromPBMove(@battle,PBMove.new(choice.moves[i].id))
  1244. @moves[i].pp=5
  1245. @moves[i].totalpp=5
  1246. end
  1247. @effects[PBEffects::Disable]=0
  1248. @effects[PBEffects::DisableMove]=0
  1249. @battle.pbDisplay(_INTL("{1} transformed into {2}!",pbThis,choice.pbThis(true)))
  1250. PBDebug.log("[Pokémon transformed] #{pbThis} transformed into #{choice.pbThis(true)}")
  1251. end
  1252. end
  1253. # Air Balloon message
  1254. if self.hasWorkingItem(:AIRBALLOON) && onactive
  1255. @battle.pbDisplay(_INTL("{1} floats in the air with its {2}!",pbThis,PBItems.getName(self.item)))
  1256. end
  1257. end
  1258.  
  1259. def pbEffectsOnDealingDamage(move,user,target,damage)
  1260. movetype=move.pbType(move.type,user,target)
  1261. if damage>0 && move.isContactMove?
  1262. if !target.damagestate.substitute
  1263. if target.hasWorkingItem(:STICKYBARB,true) && user.item==0 && !user.isFainted?
  1264. user.item=target.item
  1265. target.item=0
  1266. target.effects[PBEffects::Unburden]=true
  1267. if !@battle.opponent && !@battle.pbIsOpposing?(user.index)
  1268. if user.pokemon.itemInitial==0 && target.pokemon.itemInitial==user.item
  1269. user.pokemon.itemInitial=user.item
  1270. target.pokemon.itemInitial=0
  1271. end
  1272. end
  1273. @battle.pbDisplay(_INTL("{1}'s {2} was transferred to {3}!",
  1274. target.pbThis,PBItems.getName(user.item),user.pbThis(true)))
  1275. PBDebug.log("[Item triggered] #{target.pbThis}'s Sticky Barb moved to #{user.pbThis(true)}")
  1276. end
  1277. if target.hasWorkingItem(:ROCKYHELMET,true) && !user.isFainted?
  1278. if !user.hasWorkingAbility(:MAGICGUARD)
  1279. PBDebug.log("[Item triggered] #{target.pbThis}'s Rocky Helmet")
  1280. @battle.scene.pbDamageAnimation(user,0)
  1281. user.pbReduceHP((user.totalhp/6).floor)
  1282. @battle.pbDisplay(_INTL("{1} was hurt by the {2}!",user.pbThis,
  1283. PBItems.getName(target.item)))
  1284. end
  1285. end
  1286. if target.hasWorkingAbility(:AFTERMATH,true) && target.isFainted? &&
  1287. !user.isFainted?
  1288. if !@battle.pbCheckGlobalAbility(:DAMP) &&
  1289. !user.hasMoldBreaker && !user.hasWorkingAbility(:MAGICGUARD)
  1290. PBDebug.log("[Ability triggered] #{target.pbThis}'s Aftermath")
  1291. @battle.scene.pbDamageAnimation(user,0)
  1292. user.pbReduceHP((user.totalhp/4).floor)
  1293. @battle.pbDisplay(_INTL("{1} was caught in the aftermath!",user.pbThis))
  1294. end
  1295. end
  1296. if target.hasWorkingAbility(:CUTECHARM) && @battle.pbRandom(10)<3
  1297. if !user.isFainted? && user.pbCanAttract?(target,false)
  1298. PBDebug.log("[Ability triggered] #{target.pbThis}'s Cute Charm")
  1299. user.pbAttract(target,_INTL("{1}'s {2} made {3} fall in love!",target.pbThis,
  1300. PBAbilities.getName(target.ability),user.pbThis(true)))
  1301. end
  1302. end
  1303. if target.hasWorkingAbility(:EFFECTSPORE,true) && @battle.pbRandom(10)<3
  1304. if USENEWBATTLEMECHANICS &&
  1305. (user.pbHasType?(:GRASS) ||
  1306. user.hasWorkingAbility(:OVERCOAT) ||
  1307. user.hasWorkingItem(:SAFETYGOGGLES))
  1308. else
  1309. PBDebug.log("[Ability triggered] #{target.pbThis}'s Effect Spore")
  1310. case @battle.pbRandom(3)
  1311. when 0
  1312. if user.pbCanPoison?(nil,false)
  1313. user.pbPoison(target,_INTL("{1}'s {2} poisoned {3}!",target.pbThis,
  1314. PBAbilities.getName(target.ability),user.pbThis(true)))
  1315. end
  1316. when 1
  1317. if user.pbCanSleep?(nil,false)
  1318. user.pbSleep(_INTL("{1}'s {2} made {3} fall asleep!",target.pbThis,
  1319. PBAbilities.getName(target.ability),user.pbThis(true)))
  1320. end
  1321. when 2
  1322. if user.pbCanParalyze?(nil,false)
  1323. user.pbParalyze(target,_INTL("{1}'s {2} paralyzed {3}! It may be unable to move!",
  1324. target.pbThis,PBAbilities.getName(target.ability),user.pbThis(true)))
  1325. end
  1326. end
  1327. end
  1328. end
  1329. if target.hasWorkingAbility(:FLAMEBODY,true) && @battle.pbRandom(10)<3 &&
  1330. user.pbCanBurn?(nil,false)
  1331. PBDebug.log("[Ability triggered] #{target.pbThis}'s Flame Body")
  1332. user.pbBurn(target,_INTL("{1}'s {2} burned {3}!",target.pbThis,
  1333. PBAbilities.getName(target.ability),user.pbThis(true)))
  1334. end
  1335. if target.hasWorkingAbility(:MUMMY,true) && !user.isFainted?
  1336. if !isConst?(user.ability,PBAbilities,:MULTITYPE) &&
  1337. !isConst?(user.ability,PBAbilities,:STANCECHANGE) &&
  1338. !isConst?(user.ability,PBAbilities,:MUMMY)
  1339. PBDebug.log("[Ability triggered] #{target.pbThis}'s Mummy copied onto #{user.pbThis(true)}")
  1340. user.ability=getConst(PBAbilities,:MUMMY) || 0
  1341. @battle.pbDisplay(_INTL("{1} was mummified by {2}!",
  1342. user.pbThis,target.pbThis(true)))
  1343. end
  1344. end
  1345. if target.hasWorkingAbility(:POISONPOINT,true) && @battle.pbRandom(10)<3 &&
  1346. user.pbCanPoison?(nil,false)
  1347. PBDebug.log("[Ability triggered] #{target.pbThis}'s Poison Point")
  1348. user.pbPoison(target,_INTL("{1}'s {2} poisoned {3}!",target.pbThis,
  1349. PBAbilities.getName(target.ability),user.pbThis(true)))
  1350. end
  1351. if (target.hasWorkingAbility(:ROUGHSKIN,true) ||
  1352. target.hasWorkingAbility(:IRONBARBS,true)) && !user.isFainted?
  1353. if !user.hasWorkingAbility(:MAGICGUARD)
  1354. PBDebug.log("[Ability triggered] #{target.pbThis}'s #{PBAbilities.getName(target.ability)}")
  1355. @battle.scene.pbDamageAnimation(user,0)
  1356. user.pbReduceHP((user.totalhp/8).floor)
  1357. @battle.pbDisplay(_INTL("{1}'s {2} hurt {3}!",target.pbThis,
  1358. PBAbilities.getName(target.ability),user.pbThis(true)))
  1359. end
  1360. end
  1361. if target.hasWorkingAbility(:STATIC,true) && @battle.pbRandom(10)<3 &&
  1362. user.pbCanParalyze?(nil,false)
  1363. PBDebug.log("[Ability triggered] #{target.pbThis}'s Static")
  1364. user.pbParalyze(target,_INTL("{1}'s {2} paralyzed {3}! It may be unable to move!",
  1365. target.pbThis,PBAbilities.getName(target.ability),user.pbThis(true)))
  1366. end
  1367. if target.hasWorkingAbility(:GOOEY,true)
  1368. if user.pbReduceStatWithCause(PBStats::SPEED,1,target,PBAbilities.getName(target.ability))
  1369. PBDebug.log("[Ability triggered] #{target.pbThis}'s Gooey")
  1370. end
  1371. end
  1372. if user.hasWorkingAbility(:POISONTOUCH,true) &&
  1373. target.pbCanPoison?(nil,false) && @battle.pbRandom(10)<3
  1374. PBDebug.log("[Ability triggered] #{user.pbThis}'s Poison Touch")
  1375. target.pbPoison(user,_INTL("{1}'s {2} poisoned {3}!",user.pbThis,
  1376. PBAbilities.getName(user.ability),target.pbThis(true)))
  1377. end
  1378. end
  1379. end
  1380. if damage>0
  1381. if !target.damagestate.substitute
  1382. if target.hasWorkingAbility(:CURSEDBODY,true) && @battle.pbRandom(10)<3
  1383. if user.effects[PBEffects::Disable]<=0 && move.pp>0 && !user.isFainted?
  1384. user.effects[PBEffects::Disable]=3
  1385. user.effects[PBEffects::DisableMove]=move.id
  1386. @battle.pbDisplay(_INTL("{1}'s {2} disabled {3}!",target.pbThis,
  1387. PBAbilities.getName(target.ability),user.pbThis(true)))
  1388. PBDebug.log("[Ability triggered] #{target.pbThis}'s Cursed Body disabled #{user.pbThis(true)}")
  1389. end
  1390. end
  1391. if target.hasWorkingAbility(:JUSTIFIED) && isConst?(movetype,PBTypes,:DARK)
  1392. if target.pbIncreaseStatWithCause(PBStats::ATTACK,1,target,PBAbilities.getName(target.ability))
  1393. PBDebug.log("[Ability triggered] #{target.pbThis}'s Justified")
  1394. end
  1395. end
  1396. if target.hasWorkingAbility(:RATTLED) &&
  1397. (isConst?(movetype,PBTypes,:BUG) ||
  1398. isConst?(movetype,PBTypes,:DARK) ||
  1399. isConst?(movetype,PBTypes,:GHOST))
  1400. if target.pbIncreaseStatWithCause(PBStats::SPEED,1,target,PBAbilities.getName(target.ability))
  1401. PBDebug.log("[Ability triggered] #{target.pbThis}'s Rattled")
  1402. end
  1403. end
  1404. if target.hasWorkingAbility(:WEAKARMOR) && move.pbIsPhysical?(movetype)
  1405. if target.pbReduceStatWithCause(PBStats::DEFENSE,1,target,PBAbilities.getName(target.ability))
  1406. PBDebug.log("[Ability triggered] #{target.pbThis}'s Weak Armor (lower Defense)")
  1407. end
  1408. if target.pbIncreaseStatWithCause(PBStats::SPEED,1,target,PBAbilities.getName(target.ability))
  1409. PBDebug.log("[Ability triggered] #{target.pbThis}'s Weak Armor (raise Speed)")
  1410. end
  1411. end
  1412. if target.hasWorkingItem(:AIRBALLOON,true)
  1413. PBDebug.log("[Item triggered] #{target.pbThis}'s Air Balloon popped")
  1414. @battle.pbDisplay(_INTL("{1}'s Air Balloon popped!",target.pbThis))
  1415. target.pbConsumeItem(true,false)
  1416. elsif target.hasWorkingItem(:ABSORBBULB) && isConst?(movetype,PBTypes,:WATER)
  1417. if target.pbIncreaseStatWithCause(PBStats::SPATK,1,target,PBItems.getName(target.item))
  1418. PBDebug.log("[Item triggered] #{target.pbThis}'s #{PBItems.getName(target.item)}")
  1419. target.pbConsumeItem
  1420. end
  1421. elsif target.hasWorkingItem(:LUMINOUSMOSS) && isConst?(movetype,PBTypes,:WATER)
  1422. if target.pbIncreaseStatWithCause(PBStats::SPDEF,1,target,PBItems.getName(target.item))
  1423. PBDebug.log("[Item triggered] #{target.pbThis}'s #{PBItems.getName(target.item)}")
  1424. target.pbConsumeItem
  1425. end
  1426. elsif target.hasWorkingItem(:CELLBATTERY) && isConst?(movetype,PBTypes,:ELECTRIC)
  1427. if target.pbIncreaseStatWithCause(PBStats::ATTACK,1,target,PBItems.getName(target.item))
  1428. PBDebug.log("[Item triggered] #{target.pbThis}'s #{PBItems.getName(target.item)}")
  1429. target.pbConsumeItem
  1430. end
  1431. elsif target.hasWorkingItem(:SNOWBALL) && isConst?(movetype,PBTypes,:ICE)
  1432. if target.pbIncreaseStatWithCause(PBStats::ATTACK,1,target,PBItems.getName(target.item))
  1433. PBDebug.log("[Item triggered] #{target.pbThis}'s #{PBItems.getName(target.item)}")
  1434. target.pbConsumeItem
  1435. end
  1436. elsif target.hasWorkingItem(:WEAKNESSPOLICY) && target.damagestate.typemod>8
  1437. showanim=true
  1438. if target.pbIncreaseStatWithCause(PBStats::ATTACK,2,target,PBItems.getName(target.item),showanim)
  1439. PBDebug.log("[Item triggered] #{target.pbThis}'s Weakness Policy (Attack)")
  1440. showanim=false
  1441. end
  1442. if target.pbIncreaseStatWithCause(PBStats::SPATK,2,target,PBItems.getName(target.item),showanim)
  1443. PBDebug.log("[Item triggered] #{target.pbThis}'s Weakness Policy (Special Attack)")
  1444. showanim=false
  1445. end
  1446. target.pbConsumeItem if !showanim
  1447. elsif target.hasWorkingItem(:ENIGMABERRY) && target.damagestate.typemod>8
  1448. target.pbActivateBerryEffect
  1449. elsif (target.hasWorkingItem(:JABOCABERRY) && move.pbIsPhysical?(movetype)) ||
  1450. (target.hasWorkingItem(:ROWAPBERRY) && move.pbIsSpecial?(movetype))
  1451. if !user.hasWorkingAbility(:MAGICGUARD) && !user.isFainted?
  1452. PBDebug.log("[Item triggered] #{target.pbThis}'s #{PBItems.getName(target.item)}")
  1453. @battle.scene.pbDamageAnimation(user,0)
  1454. user.pbReduceHP((user.totalhp/8).floor)
  1455. @battle.pbDisplay(_INTL("{1} consumed its {2} and hurt {3}!",target.pbThis,
  1456. PBItems.getName(target.item),user.pbThis(true)))
  1457. target.pbConsumeItem
  1458. end
  1459. elsif target.hasWorkingItem(:KEEBERRY) && move.pbIsPhysical?(movetype)
  1460. target.pbActivateBerryEffect
  1461. elsif target.hasWorkingItem(:MARANGABERRY) && move.pbIsSpecial?(movetype)
  1462. target.pbActivateBerryEffect
  1463. end
  1464. end
  1465. if target.hasWorkingAbility(:ANGERPOINT)
  1466. if target.damagestate.critical && !target.damagestate.substitute &&
  1467. target.pbCanIncreaseStatStage?(PBStats::ATTACK,target)
  1468. PBDebug.log("[Ability triggered] #{target.pbThis}'s Anger Point")
  1469. target.stages[PBStats::ATTACK]=6
  1470. @battle.pbCommonAnimation("StatUp",target,nil)
  1471. @battle.pbDisplay(_INTL("{1}'s {2} maxed its {3}!",
  1472. target.pbThis,PBAbilities.getName(target.ability),PBStats.getName(PBStats::ATTACK)))
  1473. end
  1474. end
  1475. end
  1476. user.pbAbilityCureCheck
  1477. target.pbAbilityCureCheck
  1478. end
  1479.  
  1480. def pbEffectsAfterHit(user,target,thismove,turneffects)
  1481. return if turneffects[PBEffects::TotalDamage]==0
  1482. if !(user.hasWorkingAbility(:SHEERFORCE) && thismove.addlEffect>0)
  1483. # Target's held items:
  1484. # Red Card
  1485. if target.hasWorkingItem(:REDCARD) && @battle.pbCanSwitch?(user.index,-1,false)
  1486. user.effects[PBEffects::Roar]=true
  1487. @battle.pbDisplay(_INTL("{1} held up its {2} against the {3}!",
  1488. target.pbThis,PBItems.getName(target.item),user.pbThis(true)))
  1489. target.pbConsumeItem
  1490. # Eject Button
  1491. elsif target.hasWorkingItem(:EJECTBUTTON) && @battle.pbCanChooseNonActive?(target.index)
  1492. target.effects[PBEffects::Uturn]=true
  1493. @battle.pbDisplay(_INTL("{1} is switched out with the {2}!",
  1494. target.pbThis,PBItems.getName(target.item)))
  1495. target.pbConsumeItem
  1496. end
  1497. # User's held items:
  1498. # Shell Bell
  1499. if user.hasWorkingItem(:SHELLBELL) && user.effects[PBEffects::HealBlock]==0
  1500. PBDebug.log("[Item triggered] #{user.pbThis}'s Shell Bell (total damage=#{turneffects[PBEffects::TotalDamage]})")
  1501. hpgain=user.pbRecoverHP((turneffects[PBEffects::TotalDamage]/8).floor,true)
  1502. if hpgain>0
  1503. @battle.pbDisplay(_INTL("{1} restored a little HP using its {2}!",
  1504. user.pbThis,PBItems.getName(user.item)))
  1505. end
  1506. end
  1507. # Life Orb
  1508. if user.effects[PBEffects::LifeOrb] && !user.hasWorkingAbility(:MAGICGUARD)
  1509. PBDebug.log("[Item triggered] #{user.pbThis}'s Life Orb (recoil)")
  1510. hploss=user.pbReduceHP((user.totalhp/10).floor,true)
  1511. if hploss>0
  1512. @battle.pbDisplay(_INTL("{1} lost some of its HP!",user.pbThis))
  1513. end
  1514. end
  1515. user.pbFaint if user.isFainted? # no return
  1516. # Color Change
  1517. movetype=thismove.pbType(thismove.type,user,target)
  1518. if target.hasWorkingAbility(:COLORCHANGE) &&
  1519. !PBTypes.isPseudoType?(movetype) && !target.pbHasType?(movetype)
  1520. PBDebug.log("[Ability triggered] #{target.pbThis}'s Color Change made it #{PBTypes.getName(movetype)}-type")
  1521. target.type1=movetype
  1522. target.type2=movetype
  1523. target.effects[PBEffects::Type3]=-1
  1524. @battle.pbDisplay(_INTL("{1}'s {2} made it the {3} type!",target.pbThis,
  1525. PBAbilities.getName(target.ability),PBTypes.getName(movetype)))
  1526. end
  1527. end
  1528. # Moxie
  1529. if user.hasWorkingAbility(:MOXIE) && target.isFainted?
  1530. if user.pbIncreaseStatWithCause(PBStats::ATTACK,1,user,PBAbilities.getName(user.ability))
  1531. PBDebug.log("[Ability triggered] #{user.pbThis}'s Moxie")
  1532. end
  1533. end
  1534. # Magician
  1535. if user.hasWorkingAbility(:MAGICIAN)
  1536. if target.item>0 && user.item==0 &&
  1537. user.effects[PBEffects::Substitute]==0 &&
  1538. target.effects[PBEffects::Substitute]==0 &&
  1539. !target.hasWorkingAbility(:STICKYHOLD) &&
  1540. !@battle.pbIsUnlosableItem(target,target.item) &&
  1541. !@battle.pbIsUnlosableItem(user,target.item) &&
  1542. (@battle.opponent || !@battle.pbIsOpposing?(user.index))
  1543. user.item=target.item
  1544. target.item=0
  1545. target.effects[PBEffects::Unburden]=true
  1546. if !@battle.opponent && # In a wild battle
  1547. user.pokemon.itemInitial==0 &&
  1548. target.pokemon.itemInitial==user.item
  1549. user.pokemon.itemInitial=user.item
  1550. target.pokemon.itemInitial=0
  1551. end
  1552. @battle.pbDisplay(_INTL("{1} stole {2}'s {3} with {4}!",user.pbThis,
  1553. target.pbThis(true),PBItems.getName(user.item),PBAbilities.getName(user.ability)))
  1554. PBDebug.log("[Ability triggered] #{user.pbThis}'s Magician stole #{target.pbThis(true)}'s #{PBItems.getName(user.item)}")
  1555. end
  1556. end
  1557. # Pickpocket
  1558. if target.hasWorkingAbility(:PICKPOCKET)
  1559. if target.item==0 && user.item>0 &&
  1560. user.effects[PBEffects::Substitute]==0 &&
  1561. target.effects[PBEffects::Substitute]==0 &&
  1562. !user.hasWorkingAbility(:STICKYHOLD) &&
  1563. !@battle.pbIsUnlosableItem(user,user.item) &&
  1564. !@battle.pbIsUnlosableItem(target,user.item) &&
  1565. (@battle.opponent || !@battle.pbIsOpposing?(target.index))
  1566. target.item=user.item
  1567. user.item=0
  1568. user.effects[PBEffects::Unburden]=true
  1569. if !@battle.opponent && # In a wild battle
  1570. target.pokemon.itemInitial==0 &&
  1571. user.pokemon.itemInitial==target.item
  1572. target.pokemon.itemInitial=target.item
  1573. user.pokemon.itemInitial=0
  1574. end
  1575. @battle.pbDisplay(_INTL("{1} pickpocketed {2}'s {3}!",target.pbThis,
  1576. user.pbThis(true),PBItems.getName(target.item)))
  1577. PBDebug.log("[Ability triggered] #{target.pbThis}'s Pickpocket stole #{user.pbThis(true)}'s #{PBItems.getName(target.item)}")
  1578. end
  1579. end
  1580. end
  1581.  
  1582. def pbAbilityCureCheck
  1583. return if self.isFainted?
  1584. case self.status
  1585. when PBStatuses::SLEEP
  1586. if self.hasWorkingAbility(:VITALSPIRIT) || self.hasWorkingAbility(:INSOMNIA)
  1587. PBDebug.log("[Ability triggered] #{pbThis}'s #{PBAbilities.getName(@ability)}")
  1588. pbCureStatus(false)
  1589. @battle.pbDisplay(_INTL("{1}'s {2} woke it up!",pbThis,PBAbilities.getName(@ability)))
  1590. end
  1591. when PBStatuses::POISON
  1592. if self.hasWorkingAbility(:IMMUNITY)
  1593. PBDebug.log("[Ability triggered] #{pbThis}'s #{PBAbilities.getName(@ability)}")
  1594. pbCureStatus(false)
  1595. @battle.pbDisplay(_INTL("{1}'s {2} cured its poisoning!",pbThis,PBAbilities.getName(@ability)))
  1596. end
  1597. when PBStatuses::BURN
  1598. if self.hasWorkingAbility(:WATERVEIL)
  1599. PBDebug.log("[Ability triggered] #{pbThis}'s #{PBAbilities.getName(@ability)}")
  1600. pbCureStatus(false)
  1601. @battle.pbDisplay(_INTL("{1}'s {2} healed its burn!",pbThis,PBAbilities.getName(@ability)))
  1602. end
  1603. when PBStatuses::PARALYSIS
  1604. if self.hasWorkingAbility(:LIMBER)
  1605. PBDebug.log("[Ability triggered] #{pbThis}'s #{PBAbilities.getName(@ability)}")
  1606. pbCureStatus(false)
  1607. @battle.pbDisplay(_INTL("{1}'s {2} cured its paralysis!",pbThis,PBAbilities.getName(@ability)))
  1608. end
  1609. when PBStatuses::FROZEN
  1610. if self.hasWorkingAbility(:MAGMAARMOR)
  1611. PBDebug.log("[Ability triggered] #{pbThis}'s #{PBAbilities.getName(@ability)}")
  1612. pbCureStatus(false)
  1613. @battle.pbDisplay(_INTL("{1}'s {2} defrosted it!",pbThis,PBAbilities.getName(@ability)))
  1614. end
  1615. end
  1616. if @effects[PBEffects::Confusion]>0 && self.hasWorkingAbility(:OWNTEMPO)
  1617. PBDebug.log("[Ability triggered] #{pbThis}'s #{PBAbilities.getName(@ability)} (attract)")
  1618. pbCureConfusion(false)
  1619. @battle.pbDisplay(_INTL("{1}'s {2} snapped it out of its confusion!",pbThis,PBAbilities.getName(@ability)))
  1620. end
  1621. if @effects[PBEffects::Attract]>=0 && self.hasWorkingAbility(:OBLIVIOUS)
  1622. PBDebug.log("[Ability triggered] #{pbThis}'s #{PBAbilities.getName(@ability)}")
  1623. pbCureAttract
  1624. @battle.pbDisplay(_INTL("{1}'s {2} cured its infatuation status!",pbThis,PBAbilities.getName(@ability)))
  1625. end
  1626. if USENEWBATTLEMECHANICS && @effects[PBEffects::Taunt]>0 && self.hasWorkingAbility(:OBLIVIOUS)
  1627. PBDebug.log("[Ability triggered] #{pbThis}'s #{PBAbilities.getName(@ability)} (taunt)")
  1628. @effects[PBEffects::Taunt]=0
  1629. @battle.pbDisplay(_INTL("{1}'s {2} made its taunt wear off!",pbThis,PBAbilities.getName(@ability)))
  1630. end
  1631. end
  1632.  
  1633. ################################################################################
  1634. # Held item effects
  1635. ################################################################################
  1636. def pbConsumeItem(recycle=true,pickup=true)
  1637. itemname=PBItems.getName(self.item)
  1638. @pokemon.itemRecycle=self.item if recycle
  1639. @pokemon.itemInitial=0 if @pokemon.itemInitial==self.item
  1640. if pickup
  1641. @effects[PBEffects::PickupItem]=self.item
  1642. @effects[PBEffects::PickupUse]=@battle.nextPickupUse
  1643. end
  1644. self.item=0
  1645. self.effects[PBEffects::Unburden]=true
  1646. # Symbiosis
  1647. if pbPartner && pbPartner.hasWorkingAbility(:SYMBIOSIS) && recycle
  1648. if pbPartner.item>0 &&
  1649. !@battle.pbIsUnlosableItem(pbPartner,pbPartner.item) &&
  1650. !@battle.pbIsUnlosableItem(self,pbPartner.item)
  1651. @battle.pbDisplay(_INTL("{1}'s {2} let it share its {3} with {4}!",
  1652. pbPartner.pbThis,PBAbilities.getName(pbPartner.ability),
  1653. PBItems.getName(pbPartner.item),pbThis(true)))
  1654. self.item=pbPartner.item
  1655. pbPartner.item=0
  1656. pbPartner.effects[PBEffects::Unburden]=true
  1657. pbBerryCureCheck
  1658. end
  1659. end
  1660. end
  1661.  
  1662. def pbConfusionBerry(flavor,message1,message2)
  1663. amt=self.pbRecoverHP((self.totalhp/8).floor,true)
  1664. if amt>0
  1665. @battle.pbDisplay(message1)
  1666. if (self.nature%5)==flavor && (self.nature/5).floor!=(self.nature%5)
  1667. @battle.pbDisplay(message2)
  1668. pbConfuseSelf
  1669. end
  1670. return true
  1671. end
  1672. return false
  1673. end
  1674.  
  1675. def pbStatIncreasingBerry(stat,berryname)
  1676. return pbIncreaseStatWithCause(stat,1,self,berryname)
  1677. end
  1678.  
  1679. def pbActivateBerryEffect(berry=0,consume=true)
  1680. berry=self.item if berry==0
  1681. berryname=(berry==0) ? "" : PBItems.getName(berry)
  1682. PBDebug.log("[Item triggered] #{pbThis}'s #{berryname}")
  1683. consumed=false
  1684. if isConst?(berry,PBItems,:ORANBERRY)
  1685. amt=self.pbRecoverHP(10,true)
  1686. if amt>0
  1687. @battle.pbDisplay(_INTL("{1} restored its health using its {2}!",pbThis,berryname))
  1688. consumed=true
  1689. end
  1690. elsif isConst?(berry,PBItems,:SITRUSBERRY) ||
  1691. isConst?(berry,PBItems,:ENIGMABERRY)
  1692. amt=self.pbRecoverHP((self.totalhp/4).floor,true)
  1693. if amt>0
  1694. @battle.pbDisplay(_INTL("{1} restored its health using its {2}!",pbThis,berryname))
  1695. consumed=true
  1696. end
  1697. elsif isConst?(berry,PBItems,:CHESTOBERRY)
  1698. if self.status==PBStatuses::SLEEP
  1699. pbCureStatus(false)
  1700. @battle.pbDisplay(_INTL("{1}'s {2} cured its sleep problem.",pbThis,berryname))
  1701. consumed=true
  1702. end
  1703. elsif isConst?(berry,PBItems,:PECHABERRY)
  1704. if self.status==PBStatuses::POISON
  1705. pbCureStatus(false)
  1706. @battle.pbDisplay(_INTL("{1}'s {2} cured its poisoning.",pbThis,berryname))
  1707. consumed=true
  1708. end
  1709. elsif isConst?(berry,PBItems,:RAWSTBERRY)
  1710. if self.status==PBStatuses::BURN
  1711. pbCureStatus(false)
  1712. @battle.pbDisplay(_INTL("{1}'s {2} healed its burn.",pbThis,berryname))
  1713. consumed=true
  1714. end
  1715. elsif isConst?(berry,PBItems,:CHERIBERRY)
  1716. if self.status==PBStatuses::PARALYSIS
  1717. pbCureStatus(false)
  1718. @battle.pbDisplay(_INTL("{1}'s {2} cured its paralysis.",pbThis,berryname))
  1719. consumed=true
  1720. end
  1721. elsif isConst?(berry,PBItems,:ASPEARBERRY)
  1722. if self.status==PBStatuses::FROZEN
  1723. pbCureStatus(false)
  1724. @battle.pbDisplay(_INTL("{1}'s {2} thawed it out.",pbThis,berryname))
  1725. consumed=true
  1726. end
  1727. elsif isConst?(berry,PBItems,:LEPPABERRY)
  1728. found=[]
  1729. for i in 0...@pokemon.moves.length
  1730. if @pokemon.moves[i].id!=0
  1731. if (consume && @pokemon.moves[i].pp==0) ||
  1732. (!consume && @pokemon.moves[i].pp<@pokemon.moves[i].totalpp)
  1733. found.push(i)
  1734. end
  1735. end
  1736. end
  1737. if found.length>0
  1738. choice=(consume) ? found[0] : found[@battle.pbRandom(found.length)]
  1739. pokemove=@pokemon.moves[choice]
  1740. pokemove.pp+=10
  1741. pokemove.pp=pokemove.totalpp if pokemove.pp>pokemove.totalpp
  1742. self.moves[choice].pp=pokemove.pp
  1743. movename=PBMoves.getName(pokemove.id)
  1744. @battle.pbDisplay(_INTL("{1}'s {2} restored {3}'s PP!",pbThis,berryname,movename))
  1745. consumed=true
  1746. end
  1747. elsif isConst?(berry,PBItems,:PERSIMBERRY)
  1748. if @effects[PBEffects::Confusion]>0
  1749. pbCureConfusion(false)
  1750. @battle.pbDisplay(_INTL("{1}'s {2} snapped it out of its confusion!",pbThis,berryname))
  1751. consumed=true
  1752. end
  1753. elsif isConst?(berry,PBItems,:LUMBERRY)
  1754. if self.status>0 || @effects[PBEffects::Confusion]>0
  1755. st=self.status; conf=(@effects[PBEffects::Confusion]>0)
  1756. pbCureStatus(false)
  1757. pbCureConfusion(false)
  1758. case st
  1759. when PBStatuses::SLEEP
  1760. @battle.pbDisplay(_INTL("{1}'s {2} woke it up!",pbThis,berryname))
  1761. when PBStatuses::POISON
  1762. @battle.pbDisplay(_INTL("{1}'s {2} cured its poisoning!",pbThis,berryname))
  1763. when PBStatuses::BURN
  1764. @battle.pbDisplay(_INTL("{1}'s {2} healed its burn!",pbThis,berryname))
  1765. when PBStatuses::PARALYSIS
  1766. @battle.pbDisplay(_INTL("{1}'s {2} cured its paralysis!",pbThis,berryname))
  1767. when PBStatuses::FROZEN
  1768. @battle.pbDisplay(_INTL("{1}'s {2} defrosted it!",pbThis,berryname))
  1769. end
  1770. if conf
  1771. @battle.pbDisplay(_INTL("{1}'s {2} snapped it out of its confusion!",pbThis,berryname))
  1772. end
  1773. consumed=true
  1774. end
  1775. elsif isConst?(berry,PBItems,:FIGYBERRY)
  1776. consumed=pbConfusionBerry(0,
  1777. _INTL("{1}'s {2} restored health!",pbThis,berryname),
  1778. _INTL("For {1}, the {2} was too spicy!",pbThis(true),berryname))
  1779. elsif isConst?(berry,PBItems,:WIKIBERRY)
  1780. consumed=pbConfusionBerry(3,
  1781. _INTL("{1}'s {2} restored health!",pbThis,berryname),
  1782. _INTL("For {1}, the {2} was too dry!",pbThis(true),berryname))
  1783. elsif isConst?(berry,PBItems,:MAGOBERRY)
  1784. consumed=pbConfusionBerry(2,
  1785. _INTL("{1}'s {2} restored health!",pbThis,berryname),
  1786. _INTL("For {1}, the {2} was too sweet!",pbThis(true),berryname))
  1787. elsif isConst?(berry,PBItems,:AGUAVBERRY)
  1788. consumed=pbConfusionBerry(4,
  1789. _INTL("{1}'s {2} restored health!",pbThis,berryname),
  1790. _INTL("For {1}, the {2} was too bitter!",pbThis(true),berryname))
  1791. elsif isConst?(berry,PBItems,:IAPAPABERRY)
  1792. consumed=pbConfusionBerry(1,
  1793. _INTL("{1}'s {2} restored health!",pbThis,berryname),
  1794. _INTL("For {1}, the {2} was too sour!",pbThis(true),berryname))
  1795. elsif isConst?(berry,PBItems,:LIECHIBERRY)
  1796. consumed=pbStatIncreasingBerry(PBStats::ATTACK,berryname)
  1797. elsif isConst?(berry,PBItems,:GANLONBERRY) ||
  1798. isConst?(berry,PBItems,:KEEBERRY)
  1799. consumed=pbStatIncreasingBerry(PBStats::DEFENSE,berryname)
  1800. elsif isConst?(berry,PBItems,:SALACBERRY)
  1801. consumed=pbStatIncreasingBerry(PBStats::SPEED,berryname)
  1802. elsif isConst?(berry,PBItems,:PETAYABERRY)
  1803. consumed=pbStatIncreasingBerry(PBStats::SPATK,berryname)
  1804. elsif isConst?(berry,PBItems,:APICOTBERRY) ||
  1805. isConst?(berry,PBItems,:MARANGABERRY)
  1806. consumed=pbStatIncreasingBerry(PBStats::SPDEF,berryname)
  1807. elsif isConst?(berry,PBItems,:LANSATBERRY)
  1808. if @effects[PBEffects::FocusEnergy]<2
  1809. @effects[PBEffects::FocusEnergy]=2
  1810. @battle.pbDisplay(_INTL("{1} used its {2} to get pumped!",pbThis,berryname))
  1811. consumed=true
  1812. end
  1813. elsif isConst?(berry,PBItems,:MICLEBERRY)
  1814. if !@effects[PBEffects::MicleBerry]
  1815. @effects[PBEffects::MicleBerry]=true
  1816. @battle.pbDisplay(_INTL("{1} boosted the accuracy of its next move using its {2}!",
  1817. pbThis,berryname))
  1818. consumed=true
  1819. end
  1820. elsif isConst?(berry,PBItems,:STARFBERRY)
  1821. stats=[]
  1822. for i in [PBStats::ATTACK,PBStats::DEFENSE,PBStats::SPATK,PBStats::SPDEF,PBStats::SPEED]
  1823. stats.push(i) if pbCanIncreaseStatStage?(i,self)
  1824. end
  1825. if stats.length>0
  1826. stat=stats[@battle.pbRandom(stats.length)]
  1827. consumed=pbIncreaseStatWithCause(stat,2,self,berryname)
  1828. end
  1829. end
  1830. if consumed
  1831. # Cheek Pouch
  1832. if hasWorkingAbility(:CHEEKPOUCH)
  1833. amt=self.pbRecoverHP((@totalhp/3).floor,true)
  1834. if amt>0
  1835. @battle.pbDisplay(_INTL("{1}'s {2} restored its health!",
  1836. pbThis,PBAbilities.getName(ability)))
  1837. end
  1838. end
  1839. pbConsumeItem if consume
  1840. self.pokemon.belch=true if self.pokemon
  1841. end
  1842. end
  1843.  
  1844. def pbBerryCureCheck(hpcure=false)
  1845. return if self.isFainted?
  1846. unnerver=(pbOpposing1.hasWorkingAbility(:UNNERVE) ||
  1847. pbOpposing2.hasWorkingAbility(:UNNERVE))
  1848. itemname=(self.item==0) ? "" : PBItems.getName(self.item)
  1849. if hpcure
  1850. if self.hasWorkingItem(:BERRYJUICE) && self.hp<=(self.totalhp/2).floor
  1851. amt=self.pbRecoverHP(20,true)
  1852. if amt>0
  1853. @battle.pbCommonAnimation("UseItem",self,nil)
  1854. @battle.pbDisplay(_INTL("{1} restored its health using its {2}!",pbThis,itemname))
  1855. pbConsumeItem
  1856. return
  1857. end
  1858. end
  1859. end
  1860. if !unnerver
  1861. if hpcure
  1862. if self.hp<=(self.totalhp/2).floor
  1863. if self.hasWorkingItem(:ORANBERRY) ||
  1864. self.hasWorkingItem(:SITRUSBERRY)
  1865. pbActivateBerryEffect
  1866. return
  1867. end
  1868. if self.hasWorkingItem(:FIGYBERRY) ||
  1869. self.hasWorkingItem(:WIKIBERRY) ||
  1870. self.hasWorkingItem(:MAGOBERRY) ||
  1871. self.hasWorkingItem(:AGUAVBERRY) ||
  1872. self.hasWorkingItem(:IAPAPABERRY)
  1873. pbActivateBerryEffect
  1874. return
  1875. end
  1876. end
  1877. end
  1878. if (self.hasWorkingAbility(:GLUTTONY) && self.hp<=(self.totalhp/2).floor) ||
  1879. self.hp<=(self.totalhp/4).floor
  1880. if self.hasWorkingItem(:LIECHIBERRY) ||
  1881. self.hasWorkingItem(:GANLONBERRY) ||
  1882. self.hasWorkingItem(:SALACBERRY) ||
  1883. self.hasWorkingItem(:PETAYABERRY) ||
  1884. self.hasWorkingItem(:APICOTBERRY)
  1885. pbActivateBerryEffect
  1886. return
  1887. end
  1888. if self.hasWorkingItem(:LANSATBERRY) ||
  1889. self.hasWorkingItem(:STARFBERRY)
  1890. pbActivateBerryEffect
  1891. return
  1892. end
  1893. if self.hasWorkingItem(:MICLEBERRY)
  1894. pbActivateBerryEffect
  1895. return
  1896. end
  1897. end
  1898. if self.hasWorkingItem(:LEPPABERRY)
  1899. pbActivateBerryEffect
  1900. return
  1901. end
  1902. if self.hasWorkingItem(:CHESTOBERRY) ||
  1903. self.hasWorkingItem(:PECHABERRY) ||
  1904. self.hasWorkingItem(:RAWSTBERRY) ||
  1905. self.hasWorkingItem(:CHERIBERRY) ||
  1906. self.hasWorkingItem(:ASPEARBERRY) ||
  1907. self.hasWorkingItem(:PERSIMBERRY) ||
  1908. self.hasWorkingItem(:LUMBERRY)
  1909. pbActivateBerryEffect
  1910. return
  1911. end
  1912. end
  1913. if self.hasWorkingItem(:WHITEHERB)
  1914. reducedstats=false
  1915. for i in [PBStats::ATTACK,PBStats::DEFENSE,
  1916. PBStats::SPEED,PBStats::SPATK,PBStats::SPDEF,
  1917. PBStats::ACCURACY,PBStats::EVASION]
  1918. if @stages[i]<0
  1919. @stages[i]=0; reducedstats=true
  1920. end
  1921. end
  1922. if reducedstats
  1923. PBDebug.log("[Item triggered] #{pbThis}'s #{itemname}")
  1924. @battle.pbCommonAnimation("UseItem",self,nil)
  1925. @battle.pbDisplay(_INTL("{1} restored its status using its {2}!",pbThis,itemname))
  1926. pbConsumeItem
  1927. return
  1928. end
  1929. end
  1930. if self.hasWorkingItem(:MENTALHERB) &&
  1931. (@effects[PBEffects::Attract]>=0 ||
  1932. @effects[PBEffects::Taunt]>0 ||
  1933. @effects[PBEffects::Encore]>0 ||
  1934. @effects[PBEffects::Torment] ||
  1935. @effects[PBEffects::Disable]>0 ||
  1936. @effects[PBEffects::HealBlock]>0)
  1937. PBDebug.log("[Item triggered] #{pbThis}'s #{itemname}")
  1938. @battle.pbCommonAnimation("UseItem",self,nil)
  1939. @battle.pbDisplay(_INTL("{1} cured its infatuation status using its {2}.",pbThis,itemname)) if @effects[PBEffects::Attract]>=0
  1940. @battle.pbDisplay(_INTL("{1}'s taunt wore off!",pbThis)) if @effects[PBEffects::Taunt]>0
  1941. @battle.pbDisplay(_INTL("{1}'s encore ended!",pbThis)) if @effects[PBEffects::Encore]>0
  1942. @battle.pbDisplay(_INTL("{1}'s torment wore off!",pbThis)) if @effects[PBEffects::Torment]
  1943. @battle.pbDisplay(_INTL("{1} is no longer disabled!",pbThis)) if @effects[PBEffects::Disable]>0
  1944. @battle.pbDisplay(_INTL("{1}'s Heal Block wore off!",pbThis)) if @effects[PBEffects::HealBlock]>0
  1945. self.pbCureAttract
  1946. @effects[PBEffects::Taunt]=0
  1947. @effects[PBEffects::Encore]=0
  1948. @effects[PBEffects::EncoreMove]=0
  1949. @effects[PBEffects::EncoreIndex]=0
  1950. @effects[PBEffects::Torment]=false
  1951. @effects[PBEffects::Disable]=0
  1952. @effects[PBEffects::HealBlock]=0
  1953. pbConsumeItem
  1954. return
  1955. end
  1956. if hpcure && self.hasWorkingItem(:LEFTOVERS) && self.hp!=self.totalhp &&
  1957. @effects[PBEffects::HealBlock]==0
  1958. PBDebug.log("[Item triggered] #{pbThis}'s Leftovers")
  1959. @battle.pbCommonAnimation("UseItem",self,nil)
  1960. pbRecoverHP((self.totalhp/16).floor,true)
  1961. @battle.pbDisplay(_INTL("{1} restored a little HP using its {2}!",pbThis,itemname))
  1962. end
  1963. if hpcure && self.hasWorkingItem(:BLACKSLUDGE)
  1964. if pbHasType?(:POISON)
  1965. if self.hp!=self.totalhp &&
  1966. (!USENEWBATTLEMECHANICS || @effects[PBEffects::HealBlock]==0)
  1967. PBDebug.log("[Item triggered] #{pbThis}'s Black Sludge (heal)")
  1968. @battle.pbCommonAnimation("UseItem",self,nil)
  1969. pbRecoverHP((self.totalhp/16).floor,true)
  1970. @battle.pbDisplay(_INTL("{1} restored a little HP using its {2}!",pbThis,itemname))
  1971. end
  1972. elsif !self.hasWorkingAbility(:MAGICGUARD)
  1973. PBDebug.log("[Item triggered] #{pbThis}'s Black Sludge (damage)")
  1974. @battle.pbCommonAnimation("UseItem",self,nil)
  1975. pbReduceHP((self.totalhp/8).floor,true)
  1976. @battle.pbDisplay(_INTL("{1} was hurt by its {2}!",pbThis,itemname))
  1977. end
  1978. pbFaint if self.isFainted?
  1979. end
  1980. end
  1981.  
  1982. ################################################################################
  1983. # Move user and targets
  1984. ################################################################################
  1985. def pbFindUser(choice,targets)
  1986. move=choice[2]
  1987. target=choice[3]
  1988. user=self # Normally, the user is self
  1989. # Targets in normal cases
  1990. case pbTarget(move)
  1991. when PBTargets::SingleNonUser
  1992. if target>=0
  1993. targetBattler=@battle.battlers[target]
  1994. if !pbIsOpposing?(targetBattler.index)
  1995. if !pbAddTarget(targets,targetBattler)
  1996. pbAddTarget(targets,pbOpposing2) if !pbAddTarget(targets,pbOpposing1)
  1997. end
  1998. else
  1999. pbAddTarget(targets,targetBattler.pbPartner) if !pbAddTarget(targets,targetBattler)
  2000. end
  2001. else
  2002. pbRandomTarget(targets)
  2003. end
  2004. when PBTargets::SingleOpposing
  2005. if target>=0
  2006. targetBattler=@battle.battlers[target]
  2007. if !pbIsOpposing?(targetBattler.index)
  2008. if !pbAddTarget(targets,targetBattler)
  2009. pbAddTarget(targets,pbOpposing2) if !pbAddTarget(targets,pbOpposing1)
  2010. end
  2011. else
  2012. pbAddTarget(targets,targetBattler.pbPartner) if !pbAddTarget(targets,targetBattler)
  2013. end
  2014. else
  2015. pbRandomTarget(targets)
  2016. end
  2017. when PBTargets::OppositeOpposing
  2018. pbAddTarget(targets,pbOppositeOpposing) if !pbAddTarget(targets,pbOppositeOpposing2)
  2019. when PBTargets::RandomOpposing
  2020. pbRandomTarget(targets)
  2021. when PBTargets::AllOpposing
  2022. # Just pbOpposing1 because partner is determined late
  2023. pbAddTarget(targets,pbOpposing2) if !pbAddTarget(targets,pbOpposing1)
  2024. when PBTargets::AllNonUsers
  2025. for i in 0...4 # not ordered by priority
  2026. pbAddTarget(targets,@battle.battlers[i]) if i!=@index
  2027. end
  2028. when PBTargets::UserOrPartner
  2029. if target>=0 # Pre-chosen target
  2030. targetBattler=@battle.battlers[target]
  2031. pbAddTarget(targets,targetBattler.pbPartner) if !pbAddTarget(targets,targetBattler)
  2032. else
  2033. pbAddTarget(targets,self)
  2034. end
  2035. when PBTargets::Partner
  2036. pbAddTarget(targets,pbPartner)
  2037. else
  2038. move.pbAddTarget(targets,self)
  2039. end
  2040. return user
  2041. end
  2042.  
  2043. def pbChangeUser(thismove,user)
  2044. priority=@battle.pbPriority
  2045. # Change user to user of Snatch
  2046. if thismove.canSnatch?
  2047. for i in priority
  2048. if i.effects[PBEffects::Snatch]
  2049. @battle.pbDisplay(_INTL("{1} snatched {2}'s move!",i.pbThis,user.pbThis(true)))
  2050. PBDebug.log("[Lingering effect triggered] #{i.pbThis}'s Snatch made it use #{user.pbThis(true)}'s #{thismove.name}")
  2051. i.effects[PBEffects::Snatch]=false
  2052. target=user
  2053. user=i
  2054. # Snatch's PP is reduced if old user has Pressure
  2055. userchoice=@battle.choices[user.index][1]
  2056. if target.hasWorkingAbility(:PRESSURE) && user.pbIsOpposing?(target.index) && userchoice>=0
  2057. pressuremove=user.moves[userchoice]
  2058. pbSetPP(pressuremove,pressuremove.pp-1) if pressuremove.pp>0
  2059. end
  2060. break if USENEWBATTLEMECHANICS
  2061. end
  2062. end
  2063. end
  2064. return user
  2065. end
  2066.  
  2067. def pbTarget(move)
  2068. target=move.target
  2069. if move.function==0x10D && pbHasType?(:GHOST) # Curse
  2070. target=PBTargets::OppositeOpposing
  2071. end
  2072. return target
  2073. end
  2074.  
  2075. def pbAddTarget(targets,target)
  2076. if !target.isFainted?
  2077. targets[targets.length]=target
  2078. return true
  2079. end
  2080. return false
  2081. end
  2082.  
  2083. def pbRandomTarget(targets)
  2084. choices=[]
  2085. pbAddTarget(choices,pbOpposing1)
  2086. pbAddTarget(choices,pbOpposing2)
  2087. if choices.length>0
  2088. pbAddTarget(targets,choices[@battle.pbRandom(choices.length)])
  2089. end
  2090. end
  2091.  
  2092. def pbChangeTarget(thismove,userandtarget,targets)
  2093. priority=@battle.pbPriority
  2094. changeeffect=0
  2095. user=userandtarget[0]
  2096. target=userandtarget[1]
  2097. # Lightningrod
  2098. if targets.length==1 && isConst?(thismove.pbType(thismove.type,user,target),PBTypes,:ELECTRIC) &&
  2099. !target.hasWorkingAbility(:LIGHTNINGROD)
  2100. for i in priority # use Pokémon earliest in priority
  2101. next if user.index==i.index || target.index==i.index
  2102. if i.hasWorkingAbility(:LIGHTNINGROD)
  2103. PBDebug.log("[Ability triggered] #{i.pbThis}'s Lightningrod (change target)")
  2104. target=i # X's Lightningrod took the attack!
  2105. changeeffect=1
  2106. break
  2107. end
  2108. end
  2109. end
  2110. # Storm Drain
  2111. if targets.length==1 && isConst?(thismove.pbType(thismove.type,user,target),PBTypes,:WATER) &&
  2112. !target.hasWorkingAbility(:STORMDRAIN)
  2113. for i in priority # use Pokémon earliest in priority
  2114. next if user.index==i.index || target.index==i.index
  2115. if i.hasWorkingAbility(:STORMDRAIN)
  2116. PBDebug.log("[Ability triggered] #{i.pbThis}'s Storm Drain (change target)")
  2117. target=i # X's Storm Drain took the attack!
  2118. changeeffect=1
  2119. break
  2120. end
  2121. end
  2122. end
  2123. # Change target to user of Follow Me (overrides Magic Coat
  2124. # because check for Magic Coat below uses this target)
  2125. if PBTargets.targetsOneOpponent?(thismove)
  2126. newtarget=nil; strength=100
  2127. for i in priority # use Pokémon latest in priority
  2128. next if !user.pbIsOpposing?(i.index)
  2129. if !i.isFainted? && !@battle.switching && !i.effects[PBEffects::SkyDrop] &&
  2130. i.effects[PBEffects::FollowMe]>0 && i.effects[PBEffects::FollowMe]<strength
  2131. PBDebug.log("[Lingering effect triggered] #{i.pbThis}'s Follow Me")
  2132. newtarget=i; strength=i.effects[PBEffects::FollowMe]
  2133. changeeffect=0
  2134. end
  2135. end
  2136. target=newtarget if newtarget
  2137. end
  2138. # TODO: Pressure here is incorrect if Magic Coat redirects target
  2139. if user.pbIsOpposing?(target.index) && target.hasWorkingAbility(:PRESSURE)
  2140. PBDebug.log("[Ability triggered] #{target.pbThis}'s Pressure (in pbChangeTarget)")
  2141. user.pbReducePP(thismove) # Reduce PP
  2142. end
  2143. # Change user to user of Snatch
  2144. if thismove.canSnatch?
  2145. for i in priority
  2146. if i.effects[PBEffects::Snatch]
  2147. @battle.pbDisplay(_INTL("{1} Snatched {2}'s move!",i.pbThis,user.pbThis(true)))
  2148. PBDebug.log("[Lingering effect triggered] #{i.pbThis}'s Snatch made it use #{user.pbThis(true)}'s #{thismove.name}")
  2149. i.effects[PBEffects::Snatch]=false
  2150. target=user
  2151. user=i
  2152. # Snatch's PP is reduced if old user has Pressure
  2153. userchoice=@battle.choices[user.index][1]
  2154. if target.hasWorkingAbility(:PRESSURE) && user.pbIsOpposing?(target.index) && userchoice>=0
  2155. PBDebug.log("[Ability triggered] #{target.pbThis}'s Pressure (part of Snatch)")
  2156. pressuremove=user.moves[userchoice]
  2157. pbSetPP(pressuremove,pressuremove.pp-1) if pressuremove.pp>0
  2158. end
  2159. end
  2160. end
  2161. end
  2162. if thismove.canMagicCoat?
  2163. if target.effects[PBEffects::MagicCoat]
  2164. # switch user and target
  2165. PBDebug.log("[Lingering effect triggered] #{i.pbThis}'s Magic Coat made it use #{user.pbThis(true)}'s #{thismove.name}")
  2166. changeeffect=3
  2167. tmp=user
  2168. user=target
  2169. target=tmp
  2170. # Magic Coat's PP is reduced if old user has Pressure
  2171. userchoice=@battle.choices[user.index][1]
  2172. if target.hasWorkingAbility(:PRESSURE) && user.pbIsOpposing?(target.index) && userchoice>=0
  2173. PBDebug.log("[Ability triggered] #{target.pbThis}'s Pressure (part of Magic Coat)")
  2174. pressuremove=user.moves[userchoice]
  2175. pbSetPP(pressuremove,pressuremove.pp-1) if pressuremove.pp>0
  2176. end
  2177. elsif !user.hasMoldBreaker && target.hasWorkingAbility(:MAGICBOUNCE)
  2178. # switch user and target
  2179. PBDebug.log("[Ability triggered] #{target.pbThis}'s Magic Bounce made it use #{user.pbThis(true)}'s #{thismove.name}")
  2180. changeeffect=3
  2181. tmp=user
  2182. user=target
  2183. target=tmp
  2184. end
  2185. end
  2186. if changeeffect==1
  2187. @battle.pbDisplay(_INTL("{1}'s {2} took the move!",target.pbThis,PBAbilities.getName(target.ability)))
  2188. elsif changeeffect==3
  2189. @battle.pbDisplay(_INTL("{1} bounced the {2} back!",user.pbThis,thismove.name))
  2190. end
  2191. userandtarget[0]=user
  2192. userandtarget[1]=target
  2193. if !user.hasMoldBreaker && target.hasWorkingAbility(:SOUNDPROOF) &&
  2194. thismove.isSoundBased? &&
  2195. thismove.function!=0xE5 && # Perish Song handled elsewhere
  2196. thismove.function!=0x151 # Parting Shot handled elsewhere
  2197. PBDebug.log("[Ability triggered] #{target.pbThis}'s Soundproof blocked #{user.pbThis(true)}'s #{thismove.name}")
  2198. @battle.pbDisplay(_INTL("{1}'s {2} blocks {3}!",target.pbThis,
  2199. PBAbilities.getName(target.ability),thismove.name))
  2200. return false
  2201. end
  2202. return true
  2203. end
  2204.  
  2205. ################################################################################
  2206. # Move PP
  2207. ################################################################################
  2208. def pbSetPP(move,pp)
  2209. move.pp=pp
  2210. # Not effects[PBEffects::Mimic], since Mimic can't copy Mimic
  2211. if move.thismove && move.id==move.thismove.id && !@effects[PBEffects::Transform]
  2212. move.thismove.pp=pp
  2213. end
  2214. end
  2215.  
  2216. def pbReducePP(move)
  2217. if @effects[PBEffects::TwoTurnAttack]>0 ||
  2218. @effects[PBEffects::Bide]>0 ||
  2219. @effects[PBEffects::Outrage]>0 ||
  2220. @effects[PBEffects::Rollout]>0 ||
  2221. @effects[PBEffects::HyperBeam]>0 ||
  2222. @effects[PBEffects::Uproar]>0
  2223. # No need to reduce PP if two-turn attack
  2224. return true
  2225. end
  2226. return true if move.pp<0 # No need to reduce PP for special calls of moves
  2227. return true if move.totalpp==0 # Infinite PP, can always be used
  2228. return false if move.pp==0
  2229. if move.pp>0
  2230. pbSetPP(move,move.pp-1)
  2231. end
  2232. return true
  2233. end
  2234.  
  2235. def pbReducePPOther(move)
  2236. pbSetPP(move,move.pp-1) if move.pp>0
  2237. end
  2238.  
  2239. ################################################################################
  2240. # Using a move
  2241. ################################################################################
  2242. def pbObedienceCheck?(choice)
  2243. return true if choice[0]!=1
  2244. if @battle.pbOwnedByPlayer?(@index) && @battle.internalbattle
  2245. badgelevel=10
  2246. badgelevel=20 if @battle.pbPlayer.numbadges>=1
  2247. badgelevel=30 if @battle.pbPlayer.numbadges>=2
  2248. badgelevel=40 if @battle.pbPlayer.numbadges>=3
  2249. badgelevel=50 if @battle.pbPlayer.numbadges>=4
  2250. badgelevel=60 if @battle.pbPlayer.numbadges>=5
  2251. badgelevel=70 if @battle.pbPlayer.numbadges>=6
  2252. badgelevel=80 if @battle.pbPlayer.numbadges>=7
  2253. badgelevel=100 if @battle.pbPlayer.numbadges>=8
  2254. move=choice[2]
  2255. disobedient=false
  2256. if @pokemon.isForeign?(@battle.pbPlayer) && @level>badgelevel
  2257. a=((@level+badgelevel)*@battle.pbRandom(256)/255).floor
  2258. disobedient|=a<badgelevel
  2259. end
  2260. if self.respond_to?("pbHyperModeObedience")
  2261. disobedient|=!self.pbHyperModeObedience(move)
  2262. end
  2263. if disobedient
  2264. PBDebug.log("[Disobedience] #{pbThis} disobeyed")
  2265. @effects[PBEffects::Rage]=false
  2266. if self.status==PBStatuses::SLEEP &&
  2267. (move.function==0x11 || move.function==0xB4) # Snore, Sleep Talk
  2268. @battle.pbDisplay(_INTL("{1} ignored orders while asleep!",pbThis))
  2269. return false
  2270. end
  2271. b=((@level+badgelevel)*@battle.pbRandom(256)/255).floor
  2272. if b<badgelevel
  2273. return false if !@battle.pbCanShowFightMenu?(@index)
  2274. othermoves=[]
  2275. for i in 0...4
  2276. next if i==choice[1]
  2277. othermoves[othermoves.length]=i if @battle.pbCanChooseMove?(@index,i,false)
  2278. end
  2279. if othermoves.length>0
  2280. @battle.pbDisplay(_INTL("{1} ignored orders!",pbThis))
  2281. newchoice=othermoves[@battle.pbRandom(othermoves.length)]
  2282. choice[1]=newchoice
  2283. choice[2]=@moves[newchoice]
  2284. choice[3]=-1
  2285. end
  2286. return true
  2287. elsif self.status!=PBStatuses::SLEEP
  2288. c=@level-b
  2289. r=@battle.pbRandom(256)
  2290. if r<c && pbCanSleep?(self,false)
  2291. pbSleepSelf()
  2292. @battle.pbDisplay(_INTL("{1} took a nap!",pbThis))
  2293. return false
  2294. end
  2295. r-=c
  2296. if r<c
  2297. @battle.pbDisplay(_INTL("It hurt itself in its confusion!"))
  2298. pbConfusionDamage
  2299. else
  2300. message=@battle.pbRandom(4)
  2301. @battle.pbDisplay(_INTL("{1} ignored orders!",pbThis)) if message==0
  2302. @battle.pbDisplay(_INTL("{1} turned away!",pbThis)) if message==1
  2303. @battle.pbDisplay(_INTL("{1} is loafing around!",pbThis)) if message==2
  2304. @battle.pbDisplay(_INTL("{1} pretended not to notice!",pbThis)) if message==3
  2305. end
  2306. return false
  2307. end
  2308. end
  2309. return true
  2310. else
  2311. return true
  2312. end
  2313. end
  2314.  
  2315. def pbSuccessCheck(thismove,user,target,turneffects,accuracy=true)
  2316. if user.effects[PBEffects::TwoTurnAttack]>0
  2317. return true
  2318. end
  2319. # TODO: "Before Protect" applies to Counter/Mirror Coat
  2320. if thismove.function==0xDE && target.status!=PBStatuses::SLEEP # Dream Eater
  2321. @battle.pbDisplay(_INTL("{1} wasn't affected!",target.pbThis))
  2322. PBDebug.log("[Move failed] #{user.pbThis}'s Dream Eater's target isn't asleep")
  2323. return false
  2324. end
  2325. if thismove.function==0x113 && user.effects[PBEffects::Stockpile]==0 # Spit Up
  2326. @battle.pbDisplay(_INTL("But it failed to spit up a thing!"))
  2327. PBDebug.log("[Move failed] #{user.pbThis}'s Spit Up did nothing as Stockpile's count is 0")
  2328. return false
  2329. end
  2330. if target.effects[PBEffects::Protect] && thismove.canProtectAgainst? &&
  2331. !target.effects[PBEffects::ProtectNegation]
  2332. @battle.pbDisplay(_INTL("{1} protected itself!",target.pbThis))
  2333. @battle.successStates[user.index].protected=true
  2334. PBDebug.log("[Move failed] #{target.pbThis}'s Protect stopped the attack")
  2335. return false
  2336. end
  2337. p=thismove.priority
  2338. if USENEWBATTLEMECHANICS
  2339. p+=1 if user.hasWorkingAbility(:PRANKSTER) && thismove.pbIsStatus?
  2340. p+=1 if user.hasWorkingAbility(:GALEWINGS) && isConst?(thismove.type,PBTypes,:FLYING)
  2341. end
  2342. if target.pbOwnSide.effects[PBEffects::QuickGuard] && thismove.canProtectAgainst? &&
  2343. p>0 && !target.effects[PBEffects::ProtectNegation]
  2344. @battle.pbDisplay(_INTL("{1} was protected by Quick Guard!",target.pbThis))
  2345. PBDebug.log("[Move failed] The opposing side's Quick Guard stopped the attack")
  2346. return false
  2347. end
  2348. if target.pbOwnSide.effects[PBEffects::WideGuard] &&
  2349. PBTargets.hasMultipleTargets?(thismove) && !thismove.pbIsStatus? &&
  2350. !target.effects[PBEffects::ProtectNegation]
  2351. @battle.pbDisplay(_INTL("{1} was protected by Wide Guard!",target.pbThis))
  2352. PBDebug.log("[Move failed] The opposing side's Wide Guard stopped the attack")
  2353. return false
  2354. end
  2355. if target.pbOwnSide.effects[PBEffects::CraftyShield] && thismove.pbIsStatus? &&
  2356. thismove.function!=0xE5 # Perish Song
  2357. @battle.pbDisplay(_INTL("Crafty Shield protected {1}!",target.pbThis(true)))
  2358. PBDebug.log("[Move failed] The opposing side's Crafty Shield stopped the attack")
  2359. return false
  2360. end
  2361. if target.pbOwnSide.effects[PBEffects::MatBlock] && !thismove.pbIsStatus? &&
  2362. thismove.canProtectAgainst? && !target.effects[PBEffects::ProtectNegation]
  2363. @battle.pbDisplay(_INTL("{1} was blocked by the kicked-up mat!",thismove.name))
  2364. PBDebug.log("[Move failed] The opposing side's Mat Block stopped the attack")
  2365. return false
  2366. end
  2367. # TODO: Mind Reader/Lock-On
  2368. # --Sketch/FutureSight/PsychUp work even on Fly/Bounce/Dive/Dig
  2369. if thismove.pbMoveFailed(user,target) # TODO: Applies to Snore/Fake Out
  2370. @battle.pbDisplay(_INTL("But it failed!"))
  2371. PBDebug.log(sprintf("[Move failed] Failed pbMoveFailed (function code %02X)",thismove.function))
  2372. return false
  2373. end
  2374. # King's Shield (purposely after pbMoveFailed)
  2375. if target.effects[PBEffects::KingsShield] && !thismove.pbIsStatus? &&
  2376. thismove.canProtectAgainst? && !target.effects[PBEffects::ProtectNegation]
  2377. @battle.pbDisplay(_INTL("{1} protected itself!",target.pbThis))
  2378. @battle.successStates[user.index].protected=true
  2379. PBDebug.log("[Move failed] #{target.pbThis}'s King's Shield stopped the attack")
  2380. if thismove.isContactMove?
  2381. user.pbReduceStat(PBStats::ATTACK,2,nil,false)
  2382. end
  2383. return false
  2384. end
  2385. # Spiky Shield
  2386. if target.effects[PBEffects::SpikyShield] && thismove.canProtectAgainst? &&
  2387. !target.effects[PBEffects::ProtectNegation]
  2388. @battle.pbDisplay(_INTL("{1} protected itself!",target.pbThis))
  2389. @battle.successStates[user.index].protected=true
  2390. PBDebug.log("[Move failed] #{user.pbThis}'s Spiky Shield stopped the attack")
  2391. if thismove.isContactMove? && !user.isFainted?
  2392. @battle.scene.pbDamageAnimation(user,0)
  2393. amt=user.pbReduceHP((user.totalhp/8).floor)
  2394. @battle.pbDisplay(_INTL("{1} was hurt!",user.pbThis)) if amt>0
  2395. end
  2396. return false
  2397. end
  2398. # Immunity to powder-based moves
  2399. if USENEWBATTLEMECHANICS && thismove.isPowderMove? &&
  2400. (target.pbHasType?(:GRASS) ||
  2401. (!user.hasMoldBreaker && target.hasWorkingAbility(:OVERCOAT)) ||
  2402. target.hasWorkingItem(:SAFETYGOGGLES))
  2403. @battle.pbDisplay(_INTL("It doesn't affect\r\n{1}...",target.pbThis(true)))
  2404. PBDebug.log("[Move failed] #{target.pbThis} is immune to powder-based moves somehow")
  2405. return false
  2406. end
  2407. if thismove.basedamage>0 && thismove.function!=0x02 && # Struggle
  2408. thismove.function!=0x111 # Future Sight
  2409. type=thismove.pbType(thismove.type,user,target)
  2410. typemod=thismove.pbTypeModifier(type,user,target)
  2411. # Airborne-based immunity to Ground moves
  2412. if isConst?(type,PBTypes,:GROUND) && target.isAirborne?(user.hasMoldBreaker) &&
  2413. !target.hasWorkingItem(:RINGTARGET) && thismove.function!=0x11C # Smack Down
  2414. if !user.hasMoldBreaker && target.hasWorkingAbility(:LEVITATE)
  2415. @battle.pbDisplay(_INTL("{1} makes Ground moves miss with Levitate!",target.pbThis))
  2416. PBDebug.log("[Ability triggered] #{target.pbThis}'s Levitate made the Ground-type move miss")
  2417. return false
  2418. end
  2419. if target.hasWorkingItem(:AIRBALLOON)
  2420. @battle.pbDisplay(_INTL("{1}'s Air Balloon makes Ground moves miss!",target.pbThis))
  2421. PBDebug.log("[Item triggered] #{target.pbThis}'s Air Balloon made the Ground-type move miss")
  2422. return false
  2423. end
  2424. if target.effects[PBEffects::MagnetRise]>0
  2425. @battle.pbDisplay(_INTL("{1} makes Ground moves miss with Magnet Rise!",target.pbThis))
  2426. PBDebug.log("[Lingering effect triggered] #{target.pbThis}'s Magnet Rise made the Ground-type move miss")
  2427. return false
  2428. end
  2429. if target.effects[PBEffects::Telekinesis]>0
  2430. @battle.pbDisplay(_INTL("{1} makes Ground moves miss with Telekinesis!",target.pbThis))
  2431. PBDebug.log("[Lingering effect triggered] #{target.pbThis}'s Telekinesis made the Ground-type move miss")
  2432. return false
  2433. end
  2434. end
  2435. if !user.hasMoldBreaker && target.hasWorkingAbility(:WONDERGUARD) &&
  2436. type>=0 && typemod<=8
  2437. @battle.pbDisplay(_INTL("{1} avoided damage with Wonder Guard!",target.pbThis))
  2438. PBDebug.log("[Ability triggered] #{target.pbThis}'s Wonder Guard")
  2439. return false
  2440. end
  2441. if typemod==0
  2442. @battle.pbDisplay(_INTL("It doesn't affect\r\n{1}...",target.pbThis(true)))
  2443. PBDebug.log("[Move failed] Type immunity")
  2444. return false
  2445. end
  2446. end
  2447. if accuracy
  2448. if target.effects[PBEffects::LockOn]>0 && target.effects[PBEffects::LockOnPos]==user.index
  2449. PBDebug.log("[Lingering effect triggered] #{target.pbThis}'s Lock-On")
  2450. return true
  2451. end
  2452. miss=false; override=false
  2453. invulmove=PBMoveData.new(target.effects[PBEffects::TwoTurnAttack]).function
  2454. case invulmove
  2455. when 0xC9, 0xCC # Fly, Bounce
  2456. miss=true unless thismove.function==0x08 || # Thunder
  2457. thismove.function==0x15 || # Hurricane
  2458. thismove.function==0x77 || # Gust
  2459. thismove.function==0x78 || # Twister
  2460. thismove.function==0x11B || # Sky Uppercut
  2461. thismove.function==0x11C || # Smack Down
  2462. isConst?(thismove.id,PBMoves,:WHIRLWIND)
  2463. when 0xCA # Dig
  2464. miss=true unless thismove.function==0x76 || # Earthquake
  2465. thismove.function==0x95 # Magnitude
  2466. when 0xCB # Dive
  2467. miss=true unless thismove.function==0x75 || # Surf
  2468. thismove.function==0xD0 # Whirlpool
  2469. when 0xCD # Shadow Force
  2470. miss=true
  2471. when 0xCE # Sky Drop
  2472. miss=true unless thismove.function==0x08 || # Thunder
  2473. thismove.function==0x15 || # Hurricane
  2474. thismove.function==0x77 || # Gust
  2475. thismove.function==0x78 || # Twister
  2476. thismove.function==0x11B || # Sky Uppercut
  2477. thismove.function==0x11C # Smack Down
  2478. when 0x14D # Phantom Force
  2479. miss=true
  2480. end
  2481. if target.effects[PBEffects::SkyDrop]
  2482. miss=true unless thismove.function==0x08 || # Thunder
  2483. thismove.function==0x15 || # Hurricane
  2484. thismove.function==0x77 || # Gust
  2485. thismove.function==0x78 || # Twister
  2486. thismove.function==0xCE || # Sky Drop
  2487. thismove.function==0x11B || # Sky Uppercut
  2488. thismove.function==0x11C # Smack Down
  2489. end
  2490. miss=false if user.hasWorkingAbility(:NOGUARD) ||
  2491. target.hasWorkingAbility(:NOGUARD) ||
  2492. @battle.futuresight
  2493. override=true if USENEWBATTLEMECHANICS && thismove.function==0x06 && # Toxic
  2494. thismove.basedamage==0 && user.pbHasType?(:POISON)
  2495. override=true if !miss && turneffects[PBEffects::SkipAccuracyCheck] # Called by another move
  2496. if !override && (miss || !thismove.pbAccuracyCheck(user,target)) # Includes Counter/Mirror Coat
  2497. PBDebug.log(sprintf("[Move failed] Failed pbAccuracyCheck (function code %02X) or target is semi-invulnerable",thismove.function))
  2498. if thismove.target==PBTargets::AllOpposing &&
  2499. (!user.pbOpposing1.isFainted? ? 1 : 0) + (!user.pbOpposing2.isFainted? ? 1 : 0) > 1
  2500. @battle.pbDisplay(_INTL("{1} avoided the attack!",target.pbThis))
  2501. elsif thismove.target==PBTargets::AllNonUsers &&
  2502. (!user.pbOpposing1.isFainted? ? 1 : 0) + (!user.pbOpposing2.isFainted? ? 1 : 0) + (!user.pbPartner.isFainted? ? 1 : 0) > 1
  2503. @battle.pbDisplay(_INTL("{1} avoided the attack!",target.pbThis))
  2504. elsif target.effects[PBEffects::TwoTurnAttack]>0
  2505. @battle.pbDisplay(_INTL("{1} avoided the attack!",target.pbThis))
  2506. elsif thismove.function==0xDC # Leech Seed
  2507. @battle.pbDisplay(_INTL("{1} evaded the attack!",target.pbThis))
  2508. else
  2509. @battle.pbDisplay(_INTL("{1}'s attack missed!",user.pbThis))
  2510. end
  2511. return false
  2512. end
  2513. end
  2514. return true
  2515. end
  2516.  
  2517. def pbTryUseMove(choice,thismove,turneffects)
  2518. return true if turneffects[PBEffects::PassedTrying]
  2519. # TODO: Return true if attack has been Mirror Coated once already
  2520. if !turneffects[PBEffects::SkipAccuracyCheck]
  2521. return false if !pbObedienceCheck?(choice)
  2522. end
  2523. if @effects[PBEffects::SkyDrop] # Intentionally no message here
  2524. PBDebug.log("[Move failed] #{pbThis} can't use #{thismove.name} because of being Sky Dropped")
  2525. return false
  2526. end
  2527. if @battle.field.effects[PBEffects::Gravity]>0 && thismove.unusableInGravity?
  2528. @battle.pbDisplay(_INTL("{1} can't use {2} because of gravity!",pbThis,thismove.name))
  2529. PBDebug.log("[Move failed] #{pbThis} can't use #{thismove.name} because of Gravity")
  2530. return false
  2531. end
  2532. if @effects[PBEffects::Taunt]>0 && thismove.basedamage==0
  2533. @battle.pbDisplay(_INTL("{1} can't use {2} after the taunt!",pbThis,thismove.name))
  2534. PBDebug.log("[Move failed] #{pbThis} can't use #{thismove.name} because of Taunt")
  2535. return false
  2536. end
  2537. if @effects[PBEffects::HealBlock]>0 && thismove.isHealingMove?
  2538. @battle.pbDisplay(_INTL("{1} can't use {2} because of Heal Block!",pbThis,thismove.name))
  2539. PBDebug.log("[Move failed] #{pbThis} can't use #{thismove.name} because of Heal Block")
  2540. return false
  2541. end
  2542. if @effects[PBEffects::Torment] && thismove.id==@lastMoveUsed &&
  2543. thismove.id!=@battle.struggle.id && @effects[PBEffects::TwoTurnAttack]==0
  2544. @battle.pbDisplayPaused(_INTL("{1} can't use the same move in a row due to the torment!",pbThis))
  2545. PBDebug.log("[Move failed] #{pbThis} can't use #{thismove.name} because of Torment")
  2546. return false
  2547. end
  2548. if pbOpposing1.effects[PBEffects::Imprison] && !pbOpposing1.isFainted?
  2549. if thismove.id==pbOpposing1.moves[0].id ||
  2550. thismove.id==pbOpposing1.moves[1].id ||
  2551. thismove.id==pbOpposing1.moves[2].id ||
  2552. thismove.id==pbOpposing1.moves[3].id
  2553. @battle.pbDisplay(_INTL("{1} can't use the sealed {2}!",pbThis,thismove.name))
  2554. PBDebug.log("[Move failed] #{thismove.name} can't use #{thismove.name} because of #{pbOpposing1.pbThis(true)}'s Imprison")
  2555. return false
  2556. end
  2557. end
  2558. if pbOpposing2.effects[PBEffects::Imprison] && !pbOpposing2.isFainted?
  2559. if thismove.id==pbOpposing2.moves[0].id ||
  2560. thismove.id==pbOpposing2.moves[1].id ||
  2561. thismove.id==pbOpposing2.moves[2].id ||
  2562. thismove.id==pbOpposing2.moves[3].id
  2563. @battle.pbDisplay(_INTL("{1} can't use the sealed {2}!",pbThis,thismove.name))
  2564. PBDebug.log("[Move failed] #{thismove.name} can't use #{thismove.name} because of #{pbOpposing2.pbThis(true)}'s Imprison")
  2565. return false
  2566. end
  2567. end
  2568. if @effects[PBEffects::Disable]>0 && thismove.id==@effects[PBEffects::DisableMove] &&
  2569. !@battle.switching # Pursuit ignores if it's disabled
  2570. @battle.pbDisplayPaused(_INTL("{1}'s {2} is disabled!",pbThis,thismove.name))
  2571. PBDebug.log("[Move failed] #{pbThis}'s #{thismove.name} is disabled")
  2572. return false
  2573. end
  2574. if choice[1]==-2 # Battle Palace
  2575. @battle.pbDisplay(_INTL("{1} appears incapable of using its power!",pbThis))
  2576. PBDebug.log("[Move failed] Battle Palace: #{pbThis} is incapable of using its power")
  2577. return false
  2578. end
  2579. if @effects[PBEffects::HyperBeam]>0
  2580. @battle.pbDisplay(_INTL("{1} must recharge!",pbThis))
  2581. PBDebug.log("[Move failed] #{pbThis} must recharge after using #{PokeBattle_Move.pbFromPBMove(@battle,PBMove.new(@currentMove)).name}")
  2582. return false
  2583. end
  2584. if self.hasWorkingAbility(:TRUANT) && @effects[PBEffects::Truant]
  2585. @battle.pbDisplay(_INTL("{1} is loafing around!",pbThis))
  2586. PBDebug.log("[Ability triggered] #{pbThis}'s Truant")
  2587. return false
  2588. end
  2589. if !turneffects[PBEffects::SkipAccuracyCheck]
  2590. if self.status==PBStatuses::SLEEP
  2591. self.statusCount-=1
  2592. if self.statusCount<=0
  2593. self.pbCureStatus
  2594. else
  2595. self.pbContinueStatus
  2596. PBDebug.log("[Status] #{pbThis} remained asleep (count: #{self.statusCount})")
  2597. if !thismove.pbCanUseWhileAsleep? # Snore/Sleep Talk/Outrage
  2598. PBDebug.log("[Move failed] #{pbThis} couldn't use #{thismove.name} while asleep")
  2599. return false
  2600. end
  2601. end
  2602. end
  2603. end
  2604. if self.status==PBStatuses::FROZEN
  2605. if thismove.canThawUser?
  2606. PBDebug.log("[Move effect triggered] #{pbThis} was defrosted by using #{thismove.name}")
  2607. self.pbCureStatus(false)
  2608. @battle.pbDisplay(_INTL("{1} melted the ice!",pbThis))
  2609. pbCheckForm
  2610. elsif @battle.pbRandom(10)<2 && !turneffects[PBEffects::SkipAccuracyCheck]
  2611. self.pbCureStatus
  2612. pbCheckForm
  2613. elsif !thismove.canThawUser?
  2614. self.pbContinueStatus
  2615. PBDebug.log("[Status] #{pbThis} remained frozen and couldn't move")
  2616. return false
  2617. end
  2618. end
  2619. if !turneffects[PBEffects::SkipAccuracyCheck]
  2620. if @effects[PBEffects::Confusion]>0
  2621. @effects[PBEffects::Confusion]-=1
  2622. if @effects[PBEffects::Confusion]<=0
  2623. pbCureConfusion
  2624. else
  2625. pbContinueConfusion
  2626. PBDebug.log("[Status] #{pbThis} remained confused (count: #{@effects[PBEffects::Confusion]})")
  2627. if @battle.pbRandom(2)==0
  2628. pbConfusionDamage
  2629. @battle.pbDisplay(_INTL("It hurt itself in its confusion!"))
  2630. PBDebug.log("[Status] #{pbThis} hurt itself in its confusion and couldn't move")
  2631. return false
  2632. end
  2633. end
  2634. end
  2635. end
  2636. if @effects[PBEffects::Flinch]
  2637. @effects[PBEffects::Flinch]=false
  2638. @battle.pbDisplay(_INTL("{1} flinched and couldn't move!",self.pbThis))
  2639. PBDebug.log("[Lingering effect triggered] #{pbThis} flinched")
  2640. if self.hasWorkingAbility(:STEADFAST)
  2641. if pbIncreaseStatWithCause(PBStats::SPEED,1,self,PBAbilities.getName(self.ability))
  2642. PBDebug.log("[Ability triggered] #{pbThis}'s Steadfast")
  2643. end
  2644. end
  2645. return false
  2646. end
  2647. if !turneffects[PBEffects::SkipAccuracyCheck]
  2648. if @effects[PBEffects::Attract]>=0
  2649. pbAnnounceAttract(@battle.battlers[@effects[PBEffects::Attract]])
  2650. if @battle.pbRandom(2)==0
  2651. pbContinueAttract
  2652. PBDebug.log("[Lingering effect triggered] #{pbThis} was infatuated and couldn't move")
  2653. return false
  2654. end
  2655. end
  2656. if self.status==PBStatuses::PARALYSIS
  2657. if @battle.pbRandom(4)==0
  2658. pbContinueStatus
  2659. PBDebug.log("[Status] #{pbThis} was fully paralysed and couldn't move")
  2660. return false
  2661. end
  2662. end
  2663. end
  2664. turneffects[PBEffects::PassedTrying]=true
  2665. return true
  2666. end
  2667.  
  2668. def pbConfusionDamage
  2669. self.damagestate.reset
  2670. confmove=PokeBattle_Confusion.new(@battle,nil)
  2671. confmove.pbEffect(self,self)
  2672. pbFaint if self.isFainted?
  2673. end
  2674.  
  2675. def pbUpdateTargetedMove(thismove,user)
  2676. # TODO: Snatch, moves that use other moves
  2677. # TODO: All targeting cases
  2678. # Two-turn attacks, Magic Coat, Future Sight, Counter/MirrorCoat/Bide handled
  2679. end
  2680.  
  2681. def pbProcessMoveAgainstTarget(thismove,user,target,numhits,turneffects,nocheck=false,alltargets=nil,showanimation=true)
  2682. realnumhits=0
  2683. totaldamage=0
  2684. destinybond=false
  2685. for i in 0...numhits
  2686. target.damagestate.reset
  2687. # Check success (accuracy/evasion calculation)
  2688. if !nocheck &&
  2689. !pbSuccessCheck(thismove,user,target,turneffects,i==0 || thismove.successCheckPerHit?)
  2690. if thismove.function==0xBF && realnumhits>0 # Triple Kick
  2691. break # Considered a success if Triple Kick hits at least once
  2692. elsif thismove.function==0x10B # Hi Jump Kick, Jump Kick
  2693. if !user.hasWorkingAbility(:MAGICGUARD)
  2694. PBDebug.log("[Move effect triggered] #{user.pbThis} took crash damage")
  2695. #TODO: Not shown if message is "It doesn't affect XXX..."
  2696. @battle.pbDisplay(_INTL("{1} kept going and crashed!",user.pbThis))
  2697. damage=(user.totalhp/2).floor
  2698. if damage>0
  2699. @battle.scene.pbDamageAnimation(user,0)
  2700. user.pbReduceHP(damage)
  2701. end
  2702. user.pbFaint if user.isFainted?
  2703. end
  2704. end
  2705. user.effects[PBEffects::Outrage]=0 if thismove.function==0xD2 # Outrage
  2706. user.effects[PBEffects::Rollout]=0 if thismove.function==0xD3 # Rollout
  2707. user.effects[PBEffects::FuryCutter]=0 if thismove.function==0x91 # Fury Cutter
  2708. user.effects[PBEffects::Stockpile]=0 if thismove.function==0x113 # Spit Up
  2709. return
  2710. end
  2711. # Add to counters for moves which increase them when used in succession
  2712. if thismove.function==0x91 # Fury Cutter
  2713. user.effects[PBEffects::FuryCutter]+=1 if user.effects[PBEffects::FuryCutter]<4
  2714. else
  2715. user.effects[PBEffects::FuryCutter]=0
  2716. end
  2717. if thismove.function==0x92 # Echoed Voice
  2718. if !user.pbOwnSide.effects[PBEffects::EchoedVoiceUsed] &&
  2719. user.pbOwnSide.effects[PBEffects::EchoedVoiceCounter]<5
  2720. user.pbOwnSide.effects[PBEffects::EchoedVoiceCounter]+=1
  2721. end
  2722. user.pbOwnSide.effects[PBEffects::EchoedVoiceUsed]=true
  2723. end
  2724. # Count a hit for Parental Bond if it applies
  2725. user.effects[PBEffects::ParentalBond]-=1 if user.effects[PBEffects::ParentalBond]>0
  2726. # This hit will happen; count it
  2727. realnumhits+=1
  2728. # Damage calculation and/or main effect
  2729. damage=thismove.pbEffect(user,target,i,alltargets,showanimation) # Recoil/drain, etc. are applied here
  2730. totaldamage+=damage if damage>0
  2731. # Message and consume for type-weakening berries
  2732. if target.damagestate.berryweakened
  2733. @battle.pbDisplay(_INTL("The {1} weakened the damage to {2}!",
  2734. PBItems.getName(target.item),target.pbThis(true)))
  2735. target.pbConsumeItem
  2736. end
  2737. # Illusion
  2738. if target.effects[PBEffects::Illusion] && target.hasWorkingAbility(:ILLUSION) &&
  2739. damage>0 && !target.damagestate.substitute
  2740. PBDebug.log("[Ability triggered] #{target.pbThis}'s Illusion ended")
  2741. target.effects[PBEffects::Illusion]=nil
  2742. @battle.scene.pbChangePokemon(target,target.pokemon)
  2743. @battle.pbDisplay(_INTL("{1}'s {2} wore off!",target.pbThis,
  2744. PBAbilities.getName(target.ability)))
  2745. end
  2746. if user.isFainted?
  2747. user.pbFaint # no return
  2748. end
  2749. return if numhits>1 && target.damagestate.calcdamage<=0
  2750. @battle.pbJudgeCheckpoint(user,thismove)
  2751. # Additional effect
  2752. if target.damagestate.calcdamage>0 &&
  2753. !user.hasWorkingAbility(:SHEERFORCE) &&
  2754. (user.hasMoldBreaker || !target.hasWorkingAbility(:SHIELDDUST))
  2755. addleffect=thismove.addlEffect
  2756. addleffect*=2 if (user.hasWorkingAbility(:SERENEGRACE) ||
  2757. user.pbOwnSide.effects[PBEffects::Rainbow]>0) &&
  2758. thismove.function!=0xA4 # Secret Power
  2759. addleffect=100 if $DEBUG && Input.press?(Input::CTRL)
  2760. if @battle.pbRandom(100)<addleffect
  2761. PBDebug.log("[Move effect triggered] #{thismove.name}'s added effect")
  2762. thismove.pbAdditionalEffect(user,target)
  2763. end
  2764. end
  2765. # Ability effects
  2766. pbEffectsOnDealingDamage(thismove,user,target,damage)
  2767. # Grudge
  2768. if !user.isFainted? && target.isFainted?
  2769. if target.effects[PBEffects::Grudge] && target.pbIsOpposing?(user.index)
  2770. thismove.pp=0
  2771. @battle.pbDisplay(_INTL("{1}'s {2} lost all its PP due to the grudge!",
  2772. user.pbThis,thismove.name))
  2773. PBDebug.log("[Lingering effect triggered] #{target.pbThis}'s Grudge made #{thismove.name} lose all its PP")
  2774. end
  2775. end
  2776. if target.isFainted?
  2777. destinybond=destinybond || target.effects[PBEffects::DestinyBond]
  2778. end
  2779. user.pbFaint if user.isFainted? # no return
  2780. break if user.isFainted?
  2781. break if target.isFainted?
  2782. # Make the target flinch
  2783. if target.damagestate.calcdamage>0 && !target.damagestate.substitute
  2784. if user.hasMoldBreaker || !target.hasWorkingAbility(:SHIELDDUST)
  2785. canflinch=false
  2786. if (user.hasWorkingItem(:KINGSROCK) || user.hasWorkingItem(:RAZORFANG)) &&
  2787. thismove.canKingsRock?
  2788. canflinch=true
  2789. end
  2790. if user.hasWorkingAbility(:STENCH) &&
  2791. thismove.function!=0x09 && # Thunder Fang
  2792. thismove.function!=0x0B && # Fire Fang
  2793. thismove.function!=0x0E && # Ice Fang
  2794. thismove.function!=0x0F && # flinch-inducing moves
  2795. thismove.function!=0x10 && # Stomp
  2796. thismove.function!=0x11 && # Snore
  2797. thismove.function!=0x12 && # Fake Out
  2798. thismove.function!=0x78 && # Twister
  2799. thismove.function!=0xC7 # Sky Attack
  2800. canflinch=true
  2801. end
  2802. if canflinch && @battle.pbRandom(10)==0
  2803. PBDebug.log("[Item/ability triggered] #{user.pbThis}'s King's Rock/Razor Fang or Stench")
  2804. target.pbFlinch(user)
  2805. end
  2806. end
  2807. end
  2808. if target.damagestate.calcdamage>0 && !target.isFainted?
  2809. # Defrost
  2810. if target.status==PBStatuses::FROZEN &&
  2811. (isConst?(thismove.pbType(thismove.type,user,target),PBTypes,:FIRE) ||
  2812. (USENEWBATTLEMECHANICS && isConst?(thismove.id,PBMoves,:SCALD)))
  2813. target.pbCureStatus
  2814. end
  2815. # Rage
  2816. if target.effects[PBEffects::Rage] && target.pbIsOpposing?(user.index)
  2817. # TODO: Apparently triggers if opposing Pokémon uses Future Sight after a Future Sight attack
  2818. if target.pbIncreaseStatWithCause(PBStats::ATTACK,1,target,"",true,false)
  2819. PBDebug.log("[Lingering effect triggered] #{target.pbThis}'s Rage")
  2820. @battle.pbDisplay(_INTL("{1}'s rage is building!",target.pbThis))
  2821. end
  2822. end
  2823. end
  2824. target.pbFaint if target.isFainted? # no return
  2825. user.pbFaint if user.isFainted? # no return
  2826. break if user.isFainted? || target.isFainted?
  2827. # Berry check (maybe just called by ability effect, since only necessary Berries are checked)
  2828. for j in 0...4
  2829. @battle.battlers[j].pbBerryCureCheck
  2830. end
  2831. break if user.isFainted? || target.isFainted?
  2832. target.pbUpdateTargetedMove(thismove,user)
  2833. break if target.damagestate.calcdamage<=0
  2834. end
  2835. turneffects[PBEffects::TotalDamage]+=totaldamage if totaldamage>0
  2836. # Battle Arena only - attack is successful
  2837. @battle.successStates[user.index].useState=2
  2838. @battle.successStates[user.index].typemod=target.damagestate.typemod
  2839. # Type effectiveness
  2840. if numhits>1
  2841. if target.damagestate.typemod>8
  2842. if alltargets.length>1
  2843. @battle.pbDisplay(_INTL("It's super effective on {1}!",target.pbThis(true)))
  2844. else
  2845. @battle.pbDisplay(_INTL("It's super effective!"))
  2846. end
  2847. elsif target.damagestate.typemod>=1 && target.damagestate.typemod<8
  2848. if alltargets.length>1
  2849. @battle.pbDisplay(_INTL("It's not very effective on {1}...",target.pbThis(true)))
  2850. else
  2851. @battle.pbDisplay(_INTL("It's not very effective..."))
  2852. end
  2853. end
  2854. if realnumhits==1
  2855. @battle.pbDisplay(_INTL("Hit {1} time!",realnumhits))
  2856. else
  2857. @battle.pbDisplay(_INTL("Hit {1} times!",realnumhits))
  2858. end
  2859. end
  2860. PBDebug.log("Move did #{numhits} hit(s), total damage=#{turneffects[PBEffects::TotalDamage]}")
  2861. # Faint if 0 HP
  2862. target.pbFaint if target.isFainted? # no return
  2863. user.pbFaint if user.isFainted? # no return
  2864. thismove.pbEffectAfterHit(user,target,turneffects)
  2865. target.pbFaint if target.isFainted? # no return
  2866. user.pbFaint if user.isFainted? # no return
  2867. # Destiny Bond
  2868. if !user.isFainted? && target.isFainted?
  2869. if destinybond && target.pbIsOpposing?(user.index)
  2870. PBDebug.log("[Lingering effect triggered] #{target.pbThis}'s Destiny Bond")
  2871. @battle.pbDisplay(_INTL("{1} took its attacker down with it!",target.pbThis))
  2872. user.pbReduceHP(user.hp)
  2873. user.pbFaint # no return
  2874. @battle.pbJudgeCheckpoint(user)
  2875. end
  2876. end
  2877. pbEffectsAfterHit(user,target,thismove,turneffects)
  2878. # Berry check
  2879. for j in 0...4
  2880. @battle.battlers[j].pbBerryCureCheck
  2881. end
  2882. target.pbUpdateTargetedMove(thismove,user)
  2883. end
  2884.  
  2885. def pbUseMoveSimple(moveid,index=-1,target=-1)
  2886. choice=[]
  2887. choice[0]=1 # "Use move"
  2888. choice[1]=index # Index of move to be used in user's moveset
  2889. choice[2]=PokeBattle_Move.pbFromPBMove(@battle,PBMove.new(moveid)) # PokeBattle_Move object of the move
  2890. choice[2].pp=-1
  2891. choice[3]=target # Target (-1 means no target yet)
  2892. if index>=0
  2893. @battle.choices[@index][1]=index
  2894. end
  2895. PBDebug.log("#{pbThis} used simple move #{choice[2].name}")
  2896. pbUseMove(choice,true)
  2897. return
  2898. end
  2899.  
  2900. def pbUseMove(choice,specialusage=false)
  2901. # TODO: lastMoveUsed is not to be updated on nested calls
  2902. # Note: user.lastMoveUsedType IS to be updated on nested calls; is used for Conversion 2
  2903. turneffects=[]
  2904. turneffects[PBEffects::SpecialUsage]=specialusage
  2905. turneffects[PBEffects::SkipAccuracyCheck]=specialusage
  2906. turneffects[PBEffects::PassedTrying]=false
  2907. turneffects[PBEffects::TotalDamage]=0
  2908. # Start using the move
  2909. pbBeginTurn(choice)
  2910. # Force the use of certain moves if they're already being used
  2911. if @effects[PBEffects::TwoTurnAttack]>0 ||
  2912. @effects[PBEffects::HyperBeam]>0 ||
  2913. @effects[PBEffects::Outrage]>0 ||
  2914. @effects[PBEffects::Rollout]>0 ||
  2915. @effects[PBEffects::Uproar]>0 ||
  2916. @effects[PBEffects::Bide]>0
  2917. choice[2]=PokeBattle_Move.pbFromPBMove(@battle,PBMove.new(@currentMove))
  2918. turneffects[PBEffects::SpecialUsage]=true
  2919. PBDebug.log("Continuing multi-turn move #{choice[2].name}")
  2920. elsif @effects[PBEffects::Encore]>0
  2921. if @battle.pbCanShowCommands?(@index) &&
  2922. @battle.pbCanChooseMove?(@index,@effects[PBEffects::EncoreIndex],false)
  2923. if choice[1]!=@effects[PBEffects::EncoreIndex] # Was Encored mid-round
  2924. choice[1]=@effects[PBEffects::EncoreIndex]
  2925. choice[2]=@moves[@effects[PBEffects::EncoreIndex]]
  2926. choice[3]=-1 # No target chosen
  2927. end
  2928. PBDebug.log("Using Encored move #{choice[2].name}")
  2929. end
  2930. end
  2931. thismove=choice[2]
  2932. return if !thismove || thismove.id==0 # if move was not chosen
  2933. if !turneffects[PBEffects::SpecialUsage]
  2934. # TODO: Quick Claw message
  2935. end
  2936. # Stance Change
  2937. if hasWorkingAbility(:STANCECHANGE) && isConst?(species,PBSpecies,:AEGISLASH) &&
  2938. !@effects[PBEffects::Transform]
  2939. if thismove.pbIsDamaging? && self.form!=1
  2940. self.form=1
  2941. pbUpdate(true)
  2942. @battle.scene.pbChangePokemon(self,@pokemon)
  2943. @battle.pbDisplay(_INTL("{1} changed to Blade Forme!",pbThis))
  2944. PBDebug.log("[Form changed] #{pbThis} changed to Blade Forme")
  2945. elsif isConst?(thismove.id,PBMoves,:KINGSSHIELD) && self.form!=0
  2946. self.form=0
  2947. pbUpdate(true)
  2948. @battle.scene.pbChangePokemon(self,@pokemon)
  2949. @battle.pbDisplay(_INTL("{1} changed to Shield Forme!",pbThis))
  2950. PBDebug.log("[Form changed] #{pbThis} changed to Shield Forme")
  2951. end
  2952. end
  2953. # Record that user has used a move this round (ot at least tried to)
  2954. self.lastRoundMoved=@battle.turncount
  2955. # Try to use the move
  2956. if !pbTryUseMove(choice,thismove,turneffects)
  2957. self.lastMoveUsed=-1
  2958. self.lastMoveUsedType=-1
  2959. if !turneffects[PBEffects::SpecialUsage]
  2960. self.lastMoveUsedSketch=-1 if self.effects[PBEffects::TwoTurnAttack]==0
  2961. self.lastRegularMoveUsed=-1
  2962. end
  2963. pbCancelMoves
  2964. @battle.pbGainEXP
  2965. pbEndTurn(choice)
  2966. @battle.pbJudge # @battle.pbSwitch
  2967. return
  2968. end
  2969. if !turneffects[PBEffects::SpecialUsage]
  2970. if !pbReducePP(thismove)
  2971. @battle.pbDisplay(_INTL("{1} used\r\n{2}!",pbThis,thismove.name))
  2972. @battle.pbDisplay(_INTL("But there was no PP left for the move!"))
  2973. self.lastMoveUsed=-1
  2974. self.lastMoveUsedType=-1
  2975. self.lastMoveUsedSketch=-1 if self.effects[PBEffects::TwoTurnAttack]==0
  2976. self.lastRegularMoveUsed=-1
  2977. pbEndTurn(choice)
  2978. @battle.pbJudge # @battle.pbSwitch
  2979. PBDebug.log("[Move failed] #{thismove.name} has no PP left")
  2980. return
  2981. end
  2982. end
  2983. # Remember that user chose a two-turn move
  2984. if thismove.pbTwoTurnAttack(self)
  2985. # Beginning use of two-turn attack
  2986. @effects[PBEffects::TwoTurnAttack]=thismove.id
  2987. @currentMove=thismove.id
  2988. else
  2989. @effects[PBEffects::TwoTurnAttack]=0 # Cancel use of two-turn attack
  2990. end
  2991. # Charge up Metronome item
  2992. if self.lastMoveUsed==thismove.id
  2993. self.effects[PBEffects::Metronome]+=1
  2994. else
  2995. self.effects[PBEffects::Metronome]=0
  2996. end
  2997. # "X used Y!" message
  2998. case thismove.pbDisplayUseMessage(self)
  2999. when 2 # Continuing Bide
  3000. return
  3001. when 1 # Starting Bide
  3002. self.lastMoveUsed=thismove.id
  3003. self.lastMoveUsedType=thismove.pbType(thismove.type,self,nil)
  3004. if !turneffects[PBEffects::SpecialUsage]
  3005. self.lastMoveUsedSketch=thismove.id if self.effects[PBEffects::TwoTurnAttack]==0
  3006. self.lastRegularMoveUsed=thismove.id
  3007. end
  3008. @battle.lastMoveUsed=thismove.id
  3009. @battle.lastMoveUser=self.index
  3010. @battle.successStates[self.index].useState=2
  3011. @battle.successStates[self.index].typemod=8
  3012. return
  3013. when -1 # Was hurt while readying Focus Punch, fails use
  3014. self.lastMoveUsed=thismove.id
  3015. self.lastMoveUsedType=thismove.pbType(thismove.type,self,nil)
  3016. if !turneffects[PBEffects::SpecialUsage]
  3017. self.lastMoveUsedSketch=thismove.id if self.effects[PBEffects::TwoTurnAttack]==0
  3018. self.lastRegularMoveUsed=thismove.id
  3019. end
  3020. @battle.lastMoveUsed=thismove.id
  3021. @battle.lastMoveUser=self.index
  3022. @battle.successStates[self.index].useState=2 # somehow treated as a success
  3023. @battle.successStates[self.index].typemod=8
  3024. PBDebug.log("[Move failed] #{pbThis} was hurt while readying Focus Punch")
  3025. return
  3026. end
  3027. # Find the user and target(s)
  3028. targets=[]
  3029. user=pbFindUser(choice,targets)
  3030. # Battle Arena only - assume failure
  3031. @battle.successStates[user.index].useState=1
  3032. @battle.successStates[user.index].typemod=8
  3033. # Check whether Selfdestruct works
  3034. if !thismove.pbOnStartUse(user) # Selfdestruct, Natural Gift, Beat Up can return false here
  3035. PBDebug.log(sprintf("[Move failed] Failed pbOnStartUse (function code %02X)",thismove.function))
  3036. user.lastMoveUsed=thismove.id
  3037. user.lastMoveUsedType=thismove.pbType(thismove.type,user,nil)
  3038. if !turneffects[PBEffects::SpecialUsage]
  3039. user.lastMoveUsedSketch=thismove.id if user.effects[PBEffects::TwoTurnAttack]==0
  3040. user.lastRegularMoveUsed=thismove.id
  3041. end
  3042. @battle.lastMoveUsed=thismove.id
  3043. @battle.lastMoveUser=user.index
  3044. return
  3045. end
  3046. # Primordial Sea, Desolate Land
  3047. if thismove.pbIsDamaging?
  3048. case @battle.pbWeather
  3049. when PBWeather::HEAVYRAIN
  3050. if isConst?(thismove.pbType(thismove.type,user,nil),PBTypes,:FIRE)
  3051. PBDebug.log("[Move failed] Primordial Sea's rain cancelled the Fire-type #{thismove.name}")
  3052. @battle.pbDisplay(_INTL("The Fire-type attack fizzled out in the heavy rain!"))
  3053. user.lastMoveUsed=thismove.id
  3054. user.lastMoveUsedType=thismove.pbType(thismove.type,user,nil)
  3055. if !turneffects[PBEffects::SpecialUsage]
  3056. user.lastMoveUsedSketch=thismove.id if user.effects[PBEffects::TwoTurnAttack]==0
  3057. user.lastRegularMoveUsed=thismove.id
  3058. end
  3059. @battle.lastMoveUsed=thismove.id
  3060. @battle.lastMoveUser=user.index
  3061. return
  3062. end
  3063. when PBWeather::HARSHSUN
  3064. if isConst?(thismove.pbType(thismove.type,user,nil),PBTypes,:WATER)
  3065. PBDebug.log("[Move failed] Desolate Land's sun cancelled the Water-type #{thismove.name}")
  3066. @battle.pbDisplay(_INTL("The Water-type attack evaporated in the harsh sunlight!"))
  3067. user.lastMoveUsed=thismove.id
  3068. user.lastMoveUsedType=thismove.pbType(thismove.type,user,nil)
  3069. if !turneffects[PBEffects::SpecialUsage]
  3070. user.lastMoveUsedSketch=thismove.id if user.effects[PBEffects::TwoTurnAttack]==0
  3071. user.lastRegularMoveUsed=thismove.id
  3072. end
  3073. @battle.lastMoveUsed=thismove.id
  3074. @battle.lastMoveUser=user.index
  3075. return
  3076. end
  3077. end
  3078. end
  3079. # Powder
  3080. if user.effects[PBEffects::Powder] && isConst?(thismove.pbType(thismove.type,user,nil),PBTypes,:FIRE)
  3081. PBDebug.log("[Lingering effect triggered] #{pbThis}'s Powder cancelled the Fire move")
  3082. @battle.pbCommonAnimation("Powder",user,nil)
  3083. @battle.pbDisplay(_INTL("When the flame touched the powder on the Pokémon, it exploded!"))
  3084. user.pbReduceHP(1+(user.totalhp/4).floor) if !user.hasWorkingAbility(:MAGICGUARD)
  3085. user.lastMoveUsed=thismove.id
  3086. user.lastMoveUsedType=thismove.pbType(thismove.type,user,nil)
  3087. if !turneffects[PBEffects::SpecialUsage]
  3088. user.lastMoveUsedSketch=thismove.id if user.effects[PBEffects::TwoTurnAttack]==0
  3089. user.lastRegularMoveUsed=thismove.id
  3090. end
  3091. @battle.lastMoveUsed=thismove.id
  3092. @battle.lastMoveUser=user.index
  3093. user.pbFaint if user.isFainted?
  3094. pbEndTurn(choice)
  3095. return
  3096. end
  3097. # Protean
  3098. if user.hasWorkingAbility(:PROTEAN) &&
  3099. thismove.function!=0xAE && # Mirror Move
  3100. thismove.function!=0xAF && # Copycat
  3101. thismove.function!=0xB0 && # Me First
  3102. thismove.function!=0xB3 && # Nature Power
  3103. thismove.function!=0xB4 && # Sleep Talk
  3104. thismove.function!=0xB5 && # Assist
  3105. thismove.function!=0xB6 # Metronome
  3106. movetype=thismove.pbType(thismove.type,user,nil)
  3107. if !user.pbHasType?(movetype)
  3108. typename=PBTypes.getName(movetype)
  3109. PBDebug.log("[Ability triggered] #{pbThis}'s Protean made it #{typename}-type")
  3110. user.type1=movetype
  3111. user.type2=movetype
  3112. user.effects[PBEffects::Type3]=-1
  3113. @battle.pbDisplay(_INTL("{1} transformed into the {2} type!",user.pbThis,typename))
  3114. end
  3115. end
  3116. # Try to use move against user if there aren't any targets
  3117. if targets.length==0
  3118. user=pbChangeUser(thismove,user)
  3119. if thismove.target==PBTargets::SingleNonUser ||
  3120. thismove.target==PBTargets::RandomOpposing ||
  3121. thismove.target==PBTargets::AllOpposing ||
  3122. thismove.target==PBTargets::AllNonUsers ||
  3123. thismove.target==PBTargets::Partner ||
  3124. thismove.target==PBTargets::UserOrPartner ||
  3125. thismove.target==PBTargets::SingleOpposing ||
  3126. thismove.target==PBTargets::OppositeOpposing
  3127. @battle.pbDisplay(_INTL("But there was no target..."))
  3128. else
  3129. PBDebug.logonerr{
  3130. thismove.pbEffect(user,nil)
  3131. }
  3132. end
  3133. else
  3134. # We have targets
  3135. showanimation=true
  3136. alltargets=[]
  3137. for i in 0...targets.length
  3138. alltargets.push(targets[i].index) if !targets.include?(targets[i].index)
  3139. end
  3140. # For each target in turn
  3141. i=0; loop do break if i>=targets.length
  3142. # Get next target
  3143. userandtarget=[user,targets[i]]
  3144. success=pbChangeTarget(thismove,userandtarget,targets)
  3145. user=userandtarget[0]
  3146. target=userandtarget[1]
  3147. if i==0 && thismove.target==PBTargets::AllOpposing
  3148. # Add target's partner to list of targets
  3149. pbAddTarget(targets,target.pbPartner)
  3150. end
  3151. # If couldn't get the next target
  3152. if !success
  3153. i+=1
  3154. next
  3155. end
  3156. # Get the number of hits
  3157. numhits=thismove.pbNumHits(user)
  3158. # Reset damage state, set Focus Band/Focus Sash to available
  3159. target.damagestate.reset
  3160. # Use move against the current target
  3161. pbProcessMoveAgainstTarget(thismove,user,target,numhits,turneffects,false,alltargets,showanimation)
  3162. showanimation=false
  3163. i+=1
  3164. end
  3165. end
  3166. # Pokémon switching caused by Roar, Whirlwind, Circle Throw, Dragon Tail, Red Card
  3167. if !user.isFainted?
  3168. switched=[]
  3169. for i in 0...4
  3170. if @battle.battlers[i].effects[PBEffects::Roar]
  3171. @battle.battlers[i].effects[PBEffects::Roar]=false
  3172. @battle.battlers[i].effects[PBEffects::Uturn]=false
  3173. next if @battle.battlers[i].isFainted?
  3174. next if !@battle.pbCanSwitch?(i,-1,false)
  3175. choices=[]
  3176. party=@battle.pbParty(i)
  3177. for j in 0...party.length
  3178. choices.push(j) if @battle.pbCanSwitchLax?(i,j,false)
  3179. end
  3180. if choices.length>0
  3181. newpoke=choices[@battle.pbRandom(choices.length)]
  3182. newpokename=newpoke
  3183. if isConst?(party[newpoke].ability,PBAbilities,:ILLUSION)
  3184. newpokename=pbGetLastPokeInTeam(i)
  3185. end
  3186. switched.push(i)
  3187. @battle.battlers[i].pbResetForm
  3188. @battle.pbRecallAndReplace(i,newpoke,newpokename,false,user.hasMoldBreaker)
  3189. @battle.pbDisplay(_INTL("{1} was dragged out!",@battle.battlers[i].pbThis))
  3190. @battle.choices[i]=[0,0,nil,-1] # Replacement Pokémon does nothing this round
  3191. end
  3192. end
  3193. end
  3194. for i in @battle.pbPriority
  3195. next if !switched.include?(i.index)
  3196. i.pbAbilitiesOnSwitchIn(true)
  3197. end
  3198. end
  3199. # Pokémon switching caused by U-Turn, Volt Switch, Eject Button
  3200. switched=[]
  3201. for i in 0...4
  3202. if @battle.battlers[i].effects[PBEffects::Uturn]
  3203. @battle.battlers[i].effects[PBEffects::Uturn]=false
  3204. @battle.battlers[i].effects[PBEffects::Roar]=false
  3205. if !@battle.battlers[i].isFainted? && @battle.pbCanChooseNonActive?(i) &&
  3206. !@battle.pbAllFainted?(@battle.pbOpposingParty(i))
  3207. # TODO: Pursuit should go here, and negate this effect if it KO's attacker
  3208. @battle.pbDisplay(_INTL("{1} went back to {2}!",@battle.battlers[i].pbThis,@battle.pbGetOwner(i).name))
  3209. newpoke=0
  3210. newpoke=@battle.pbSwitchInBetween(i,true,false)
  3211. newpokename=newpoke
  3212. if isConst?(@battle.pbParty(i)[newpoke].ability,PBAbilities,:ILLUSION)
  3213. newpokename=pbGetLastPokeInTeam(i)
  3214. end
  3215. switched.push(i)
  3216. @battle.battlers[i].pbResetForm
  3217. @battle.pbRecallAndReplace(i,newpoke,newpokename,@battle.battlers[i].effects[PBEffects::BatonPass])
  3218. @battle.choices[i]=[0,0,nil,-1] # Replacement Pokémon does nothing this round
  3219. end
  3220. end
  3221. end
  3222. for i in @battle.pbPriority
  3223. next if !switched.include?(i.index)
  3224. i.pbAbilitiesOnSwitchIn(true)
  3225. end
  3226. # Baton Pass
  3227. if user.effects[PBEffects::BatonPass]
  3228. user.effects[PBEffects::BatonPass]=false
  3229. if !user.isFainted? && @battle.pbCanChooseNonActive?(user.index) &&
  3230. !@battle.pbAllFainted?(@battle.pbParty(user.index))
  3231. newpoke=0
  3232. newpoke=@battle.pbSwitchInBetween(user.index,true,false)
  3233. newpokename=newpoke
  3234. if isConst?(@battle.pbParty(user.index)[newpoke].ability,PBAbilities,:ILLUSION)
  3235. newpokename=pbGetLastPokeInTeam(user.index)
  3236. end
  3237. user.pbResetForm
  3238. @battle.pbRecallAndReplace(user.index,newpoke,newpokename,true)
  3239. @battle.choices[user.index]=[0,0,nil,-1] # Replacement Pokémon does nothing this round
  3240. user.pbAbilitiesOnSwitchIn(true)
  3241. end
  3242. end
  3243. # Record move as having been used
  3244. user.lastMoveUsed=thismove.id
  3245. user.lastMoveUsedType=thismove.pbType(thismove.type,user,nil)
  3246. if !turneffects[PBEffects::SpecialUsage]
  3247. user.lastMoveUsedSketch=thismove.id if user.effects[PBEffects::TwoTurnAttack]==0
  3248. user.lastRegularMoveUsed=thismove.id
  3249. user.movesUsed.push(thismove.id) if !user.movesUsed.include?(thismove.id) # For Last Resort
  3250. end
  3251. @battle.lastMoveUsed=thismove.id
  3252. @battle.lastMoveUser=user.index
  3253. # Gain Exp
  3254. @battle.pbGainEXP
  3255. # Battle Arena only - update skills
  3256. for i in 0...4
  3257. @battle.successStates[i].updateSkill
  3258. end
  3259. # End of move usage
  3260. pbEndTurn(choice)
  3261. @battle.pbJudge # @battle.pbSwitch
  3262. return
  3263. end
  3264.  
  3265. def pbCancelMoves
  3266. # If failed pbTryUseMove or have already used Pursuit to chase a switching foe
  3267. # Cancel multi-turn attacks (note: Hyper Beam effect is not canceled here)
  3268. @effects[PBEffects::TwoTurnAttack]=0 if @effects[PBEffects::TwoTurnAttack]>0
  3269. @effects[PBEffects::Outrage]=0
  3270. @effects[PBEffects::Rollout]=0
  3271. @effects[PBEffects::Uproar]=0
  3272. @effects[PBEffects::Bide]=0
  3273. @currentMove=0
  3274. # Reset counters for moves which increase them when used in succession
  3275. @effects[PBEffects::FuryCutter]=0
  3276. PBDebug.log("Cancelled using the move")
  3277. end
  3278.  
  3279. ################################################################################
  3280. # Turn processing
  3281. ################################################################################
  3282. def pbBeginTurn(choice)
  3283. # Cancel some lingering effects which only apply until the user next moves
  3284. @effects[PBEffects::DestinyBond]=false
  3285. @effects[PBEffects::Grudge]=false
  3286. # Reset Parental Bond's count
  3287. @effects[PBEffects::ParentalBond]=0
  3288. # Encore's effect ends if the encored move is no longer available
  3289. if @effects[PBEffects::Encore]>0 &&
  3290. @moves[@effects[PBEffects::EncoreIndex]].id!=@effects[PBEffects::EncoreMove]
  3291. PBDebug.log("Resetting Encore effect")
  3292. @effects[PBEffects::Encore]=0
  3293. @effects[PBEffects::EncoreIndex]=0
  3294. @effects[PBEffects::EncoreMove]=0
  3295. end
  3296. # Wake up in an uproar
  3297. if self.status==PBStatuses::SLEEP && !self.hasWorkingAbility(:SOUNDPROOF)
  3298. for i in 0...4
  3299. if @battle.battlers[i].effects[PBEffects::Uproar]>0
  3300. pbCureStatus(false)
  3301. @battle.pbDisplay(_INTL("{1} woke up in the uproar!",pbThis))
  3302. end
  3303. end
  3304. end
  3305. end
  3306.  
  3307. def pbEndTurn(choice)
  3308. # True end(?)
  3309. if @effects[PBEffects::ChoiceBand]<0 && @lastMoveUsed>=0 && !self.isFainted? &&
  3310. (self.hasWorkingItem(:CHOICEBAND) ||
  3311. self.hasWorkingItem(:CHOICESPECS) ||
  3312. self.hasWorkingItem(:CHOICESCARF))
  3313. @effects[PBEffects::ChoiceBand]=@lastMoveUsed
  3314. end
  3315. @battle.pbPrimordialWeather
  3316. for i in 0...4
  3317. @battle.battlers[i].pbBerryCureCheck
  3318. end
  3319. for i in 0...4
  3320. @battle.battlers[i].pbAbilityCureCheck
  3321. end
  3322. for i in 0...4
  3323. @battle.battlers[i].pbAbilitiesOnSwitchIn(false)
  3324. end
  3325. for i in 0...4
  3326. @battle.battlers[i].pbCheckForm
  3327. end
  3328. end
  3329.  
  3330. def pbProcessTurn(choice)
  3331. # Can't use a move if fainted
  3332. return false if self.isFainted?
  3333. # Wild roaming Pokémon always flee if possible
  3334. if !@battle.opponent && @battle.pbIsOpposing?(self.index) &&
  3335. @battle.rules["alwaysflee"] && @battle.pbCanRun?(self.index)
  3336. pbBeginTurn(choice)
  3337. @battle.pbDisplay(_INTL("{1} fled!",self.pbThis))
  3338. @battle.decision=3
  3339. pbEndTurn(choice)
  3340. PBDebug.log("[Escape] #{pbThis} fled")
  3341. return true
  3342. end
  3343. # If this battler's action for this round wasn't "use a move"
  3344. if choice[0]!=1
  3345. # Clean up effects that end at battler's turn
  3346. pbBeginTurn(choice)
  3347. pbEndTurn(choice)
  3348. return false
  3349. end
  3350. # Turn is skipped if Pursuit was used during switch
  3351. if @effects[PBEffects::Pursuit]
  3352. @effects[PBEffects::Pursuit]=false
  3353. pbCancelMoves
  3354. pbEndTurn(choice)
  3355. @battle.pbJudge # @battle.pbSwitch
  3356. return false
  3357. end
  3358. # Use the move
  3359. # @battle.pbDisplayPaused("Before: [#{@lastMoveUsedSketch},#{@lastMoveUsed}]")
  3360. PBDebug.log("#{pbThis} used #{choice[2].name}")
  3361. PBDebug.logonerr{
  3362. pbUseMove(choice,choice[2]==@battle.struggle)
  3363. }
  3364. # @battle.pbDisplayPaused("After: [#{@lastMoveUsedSketch},#{@lastMoveUsed}]")
  3365. return true
  3366. end
  3367. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement