Advertisement
Guest User

Untitled

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