Guest User

Untitled

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