Guest User

Untitled

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