OGButtjuice

battler

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