Advertisement
M3rein

Old Gen 5-less Battler

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