Advertisement
Guest User

Untitled

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