Advertisement
Guest User

Untitled

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