Advertisement
Guest User

Untitled

a guest
Jun 15th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 134.87 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. @battle.pbPrimordialWeather
  1028. # Trace
  1029. if self.hasWorkingAbility(:TRACE)
  1030. choices=[]
  1031. for i in 0...4
  1032. foe=@battle.battlers[i]
  1033. if pbIsOpposing?(i) && !foe.isFainted?
  1034. abil=foe.ability
  1035. if abil>0 &&
  1036. !isConst?(abil,PBAbilities,:TRACE) &&
  1037. !isConst?(abil,PBAbilities,:MULTITYPE) &&
  1038. !isConst?(abil,PBAbilities,:ILLUSION) &&
  1039. !isConst?(abil,PBAbilities,:FLOWERGIFT) &&
  1040. !isConst?(abil,PBAbilities,:IMPOSTER) &&
  1041. !isConst?(abil,PBAbilities,:STANCECHANGE)
  1042. choices.push(i)
  1043. end
  1044. end
  1045. end
  1046. if choices.length>0
  1047. choice=choices[@battle.pbRandom(choices.length)]
  1048. battlername=@battle.battlers[choice].pbThis(true)
  1049. battlerability=@battle.battlers[choice].ability
  1050. @ability=battlerability
  1051. abilityname=PBAbilities.getName(battlerability)
  1052. @battle.pbDisplay(_INTL("{1} traced {2}'s {3}!",pbThis,battlername,abilityname))
  1053. PBDebug.log("[Ability triggered] #{pbThis}'s Trace turned into #{abilityname} from #{battlername}")
  1054. end
  1055. end
  1056. # Intimidate
  1057. if self.hasWorkingAbility(:INTIMIDATE) && onactive
  1058. PBDebug.log("[Ability triggered] #{pbThis}'s Intimidate")
  1059. for i in 0...4
  1060. if pbIsOpposing?(i) && !@battle.battlers[i].isFainted?
  1061. @battle.battlers[i].pbReduceAttackStatIntimidate(self)
  1062. end
  1063. end
  1064. end
  1065. # Download
  1066. if self.hasWorkingAbility(:DOWNLOAD) && onactive
  1067. odef=ospdef=0
  1068. if pbOpposing1 && !pbOpposing1.isFainted?
  1069. odef+=pbOpposing1.defense
  1070. ospdef+=pbOpposing1.spdef
  1071. end
  1072. if pbOpposing2 && !pbOpposing2.isFainted?
  1073. odef+=pbOpposing2.defense
  1074. ospdef+=pbOpposing1.spdef
  1075. end
  1076. if ospdef>odef
  1077. if pbIncreaseStatWithCause(PBStats::ATTACK,1,self,PBAbilities.getName(ability))
  1078. PBDebug.log("[Ability triggered] #{pbThis}'s Download (raising Attack)")
  1079. end
  1080. else
  1081. if pbIncreaseStatWithCause(PBStats::SPATK,1,self,PBAbilities.getName(ability))
  1082. PBDebug.log("[Ability triggered] #{pbThis}'s Download (raising Special Attack)")
  1083. end
  1084. end
  1085. end
  1086. # Frisk
  1087. if self.hasWorkingAbility(:FRISK) && @battle.pbOwnedByPlayer?(@index) && onactive
  1088. foes=[]
  1089. foes.push(pbOpposing1) if pbOpposing1.item>0 && !pbOpposing1.isFainted?
  1090. foes.push(pbOpposing2) if pbOpposing2.item>0 && !pbOpposing2.isFainted?
  1091. if USENEWBATTLEMECHANICS
  1092. PBDebug.log("[Ability triggered] #{pbThis}'s Frisk") if foes.length>0
  1093. for i in foes
  1094. itemname=PBItems.getName(i.item)
  1095. @battle.pbDisplay(_INTL("{1} frisked {2} and found its {3}!",pbThis,i.pbThis(true),itemname))
  1096. end
  1097. elsif foes.length>0
  1098. PBDebug.log("[Ability triggered] #{pbThis}'s Frisk")
  1099. foe=foes[@battle.pbRandom(foes.length)]
  1100. itemname=PBItems.getName(foe.item)
  1101. @battle.pbDisplay(_INTL("{1} frisked the foe and found one {2}!",pbThis,itemname))
  1102. end
  1103. end
  1104. # Anticipation
  1105. if self.hasWorkingAbility(:ANTICIPATION) && @battle.pbOwnedByPlayer?(@index) && onactive
  1106. PBDebug.log("[Ability triggered] #{pbThis} has Anticipation")
  1107. found=false
  1108. for foe in [pbOpposing1,pbOpposing2]
  1109. next if foe.isFainted?
  1110. for j in foe.moves
  1111. movedata=PBMoveData.new(j.id)
  1112. eff=PBTypes.getCombinedEffectiveness(movedata.type,type1,type2)
  1113. if (movedata.basedamage>0 && eff>4) ||
  1114. (movedata.function==0x70 && eff>0) # OHKO
  1115. found=true
  1116. break
  1117. end
  1118. end
  1119. break if found
  1120. end
  1121. @battle.pbDisplay(_INTL("{1} shuddered with anticipation!",pbThis)) if found
  1122. end
  1123. # Forewarn
  1124. if self.hasWorkingAbility(:FOREWARN) && @battle.pbOwnedByPlayer?(@index) && onactive
  1125. PBDebug.log("[Ability triggered] #{pbThis} has Forewarn")
  1126. highpower=0
  1127. fwmoves=[]
  1128. for foe in [pbOpposing1,pbOpposing2]
  1129. next if foe.isFainted?
  1130. for j in foe.moves
  1131. movedata=PBMoveData.new(j.id)
  1132. power=movedata.basedamage
  1133. power=160 if movedata.function==0x70 # OHKO
  1134. power=150 if movedata.function==0x8B # Eruption
  1135. power=120 if movedata.function==0x71 || # Counter
  1136. movedata.function==0x72 || # Mirror Coat
  1137. movedata.function==0x73 || # Metal Burst
  1138. power=80 if movedata.function==0x6A || # SonicBoom
  1139. movedata.function==0x6B || # Dragon Rage
  1140. movedata.function==0x6D || # Night Shade
  1141. movedata.function==0x6E || # Endeavor
  1142. movedata.function==0x6F || # Psywave
  1143. movedata.function==0x89 || # Return
  1144. movedata.function==0x8A || # Frustration
  1145. movedata.function==0x8C || # Crush Grip
  1146. movedata.function==0x8D || # Gyro Ball
  1147. movedata.function==0x90 || # Hidden Power
  1148. movedata.function==0x96 || # Natural Gift
  1149. movedata.function==0x97 || # Trump Card
  1150. movedata.function==0x98 || # Flail
  1151. movedata.function==0x9A # Grass Knot
  1152. if power>highpower
  1153. fwmoves=[j.id]; highpower=power
  1154. elsif power==highpower
  1155. fwmoves.push(j.id)
  1156. end
  1157. end
  1158. end
  1159. if fwmoves.length>0
  1160. fwmove=fwmoves[@battle.pbRandom(fwmoves.length)]
  1161. movename=PBMoves.getName(fwmove)
  1162. @battle.pbDisplay(_INTL("{1}'s Forewarn alerted it to {2}!",pbThis,movename))
  1163. end
  1164. end
  1165. # Pressure message
  1166. if self.hasWorkingAbility(:PRESSURE) && onactive
  1167. @battle.pbDisplay(_INTL("{1} is exerting its pressure!",pbThis))
  1168. end
  1169. # Mold Breaker message
  1170. if self.hasWorkingAbility(:MOLDBREAKER) && onactive
  1171. @battle.pbDisplay(_INTL("{1} breaks the mold!",pbThis))
  1172. end
  1173. # Turboblaze message
  1174. if self.hasWorkingAbility(:TURBOBLAZE) && onactive
  1175. @battle.pbDisplay(_INTL("{1} is radiating a blazing aura!",pbThis))
  1176. end
  1177. # Teravolt message
  1178. if self.hasWorkingAbility(:TERAVOLT) && onactive
  1179. @battle.pbDisplay(_INTL("{1} is radiating a bursting aura!",pbThis))
  1180. end
  1181. # Dark Aura message
  1182. if self.hasWorkingAbility(:DARKAURA) && onactive
  1183. @battle.pbDisplay(_INTL("{1} is radiating a dark aura!",pbThis))
  1184. end
  1185. # Fairy Aura message
  1186. if self.hasWorkingAbility(:FAIRYAURA) && onactive
  1187. @battle.pbDisplay(_INTL("{1} is radiating a fairy aura!",pbThis))
  1188. end
  1189. # Aura Break message
  1190. if self.hasWorkingAbility(:AURABREAK) && onactive
  1191. @battle.pbDisplay(_INTL("{1} reversed all other Pokémon's auras!",pbThis))
  1192. end
  1193. # Imposter
  1194. if self.hasWorkingAbility(:IMPOSTER) && !@effects[PBEffects::Transform] && onactive
  1195. choice=pbOppositeOpposing
  1196. blacklist=[
  1197. 0xC9, # Fly
  1198. 0xCA, # Dig
  1199. 0xCB, # Dive
  1200. 0xCC, # Bounce
  1201. 0xCD, # Shadow Force
  1202. 0xCE, # Sky Drop
  1203. 0x14D # Phantom Force
  1204. ]
  1205. if choice.effects[PBEffects::Transform] ||
  1206. choice.effects[PBEffects::Illusion] ||
  1207. choice.effects[PBEffects::Substitute]>0 ||
  1208. choice.effects[PBEffects::SkyDrop] ||
  1209. blacklist.include?(PBMoveData.new(choice.effects[PBEffects::TwoTurnAttack]).function)
  1210. PBDebug.log("[Ability triggered] #{pbThis}'s Imposter couldn't transform")
  1211. else
  1212. PBDebug.log("[Ability triggered] #{pbThis}'s Imposter")
  1213. @battle.pbAnimation(getConst(PBMoves,:TRANSFORM),self,choice)
  1214. @effects[PBEffects::Transform]=true
  1215. @type1=choice.type1
  1216. @type2=choice.type2
  1217. @effects[PBEffects::Type3]=-1
  1218. @ability=choice.ability
  1219. @attack=choice.attack
  1220. @defense=choice.defense
  1221. @speed=choice.speed
  1222. @spatk=choice.spatk
  1223. @spdef=choice.spdef
  1224. for i in [PBStats::ATTACK,PBStats::DEFENSE,PBStats::SPEED,
  1225. PBStats::SPATK,PBStats::SPDEF,PBStats::ACCURACY,PBStats::EVASION]
  1226. @stages[i]=choice.stages[i]
  1227. end
  1228. for i in 0...4
  1229. @moves[i]=PokeBattle_Move.pbFromPBMove(@battle,PBMove.new(choice.moves[i].id))
  1230. @moves[i].pp=5
  1231. @moves[i].totalpp=5
  1232. end
  1233. @effects[PBEffects::Disable]=0
  1234. @effects[PBEffects::DisableMove]=0
  1235. @battle.pbDisplay(_INTL("{1} transformed into {2}!",pbThis,choice.pbThis(true)))
  1236. PBDebug.log("[Pokémon transformed] #{pbThis} transformed into #{choice.pbThis(true)}")
  1237. end
  1238. end
  1239. # Air Balloon message
  1240. if self.hasWorkingItem(:AIRBALLOON) && onactive
  1241. @battle.pbDisplay(_INTL("{1} floats in the air with its {2}!",pbThis,PBItems.getName(self.item)))
  1242. end
  1243. end
  1244.  
  1245. def pbEffectsOnDealingDamage(move,user,target,damage)
  1246. movetype=move.pbType(move.type,user,target)
  1247. if damage>0 && move.isContactMove?
  1248. if !target.damagestate.substitute
  1249. if target.hasWorkingItem(:STICKYBARB,true) && user.item==0 && !user.isFainted?
  1250. user.item=target.item
  1251. target.item=0
  1252. target.effects[PBEffects::Unburden]=true
  1253. if !@battle.opponent && !@battle.pbIsOpposing?(user.index)
  1254. if user.pokemon.itemInitial==0 && target.pokemon.itemInitial==user.item
  1255. user.pokemon.itemInitial=user.item
  1256. target.pokemon.itemInitial=0
  1257. end
  1258. end
  1259. @battle.pbDisplay(_INTL("{1}'s {2} was transferred to {3}!",
  1260. target.pbThis,PBItems.getName(user.item),user.pbThis(true)))
  1261. PBDebug.log("[Item triggered] #{target.pbThis}'s Sticky Barb moved to #{user.pbThis(true)}")
  1262. end
  1263. if target.hasWorkingItem(:ROCKYHELMET,true) && !user.isFainted?
  1264. if !user.hasWorkingAbility(:MAGICGUARD)
  1265. PBDebug.log("[Item triggered] #{target.pbThis}'s Rocky Helmet")
  1266. @battle.scene.pbDamageAnimation(user,0)
  1267. user.pbReduceHP((user.totalhp/6).floor)
  1268. @battle.pbDisplay(_INTL("{1} was hurt by the {2}!",user.pbThis,
  1269. PBItems.getName(target.item)))
  1270. end
  1271. end
  1272. if target.hasWorkingAbility(:AFTERMATH,true) && target.isFainted? &&
  1273. !user.isFainted?
  1274. if !@battle.pbCheckGlobalAbility(:DAMP) &&
  1275. !user.hasMoldBreaker && !user.hasWorkingAbility(:MAGICGUARD)
  1276. PBDebug.log("[Ability triggered] #{target.pbThis}'s Aftermath")
  1277. @battle.scene.pbDamageAnimation(user,0)
  1278. user.pbReduceHP((user.totalhp/4).floor)
  1279. @battle.pbDisplay(_INTL("{1} was caught in the aftermath!",user.pbThis))
  1280. end
  1281. end
  1282. if target.hasWorkingAbility(:CUTECHARM) && @battle.pbRandom(10)<3
  1283. if !user.isFainted? && user.pbCanAttract?(target,false)
  1284. PBDebug.log("[Ability triggered] #{target.pbThis}'s Cute Charm")
  1285. user.pbAttract(target,_INTL("{1}'s {2} made {3} fall in love!",target.pbThis,
  1286. PBAbilities.getName(target.ability),user.pbThis(true)))
  1287. end
  1288. end
  1289. if target.hasWorkingAbility(:EFFECTSPORE,true) && @battle.pbRandom(10)<3
  1290. if USENEWBATTLEMECHANICS &&
  1291. (user.pbHasType?(:GRASS) ||
  1292. user.hasWorkingAbility(:OVERCOAT) ||
  1293. user.hasWorkingItem(:SAFETYGOGGLES))
  1294. else
  1295. PBDebug.log("[Ability triggered] #{target.pbThis}'s Effect Spore")
  1296. case @battle.pbRandom(3)
  1297. when 0
  1298. if user.pbCanPoison?(nil,false)
  1299. user.pbPoison(target,_INTL("{1}'s {2} poisoned {3}!",target.pbThis,
  1300. PBAbilities.getName(target.ability),user.pbThis(true)))
  1301. end
  1302. when 1
  1303. if user.pbCanSleep?(nil,false)
  1304. user.pbSleep(_INTL("{1}'s {2} made {3} fall asleep!",target.pbThis,
  1305. PBAbilities.getName(target.ability),user.pbThis(true)))
  1306. end
  1307. when 2
  1308. if user.pbCanParalyze?(nil,false)
  1309. user.pbParalyze(target,_INTL("{1}'s {2} paralyzed {3}! It may be unable to move!",
  1310. target.pbThis,PBAbilities.getName(target.ability),user.pbThis(true)))
  1311. end
  1312. end
  1313. end
  1314. end
  1315. if target.hasWorkingAbility(:FLAMEBODY,true) && @battle.pbRandom(10)<3 &&
  1316. user.pbCanBurn?(nil,false)
  1317. PBDebug.log("[Ability triggered] #{target.pbThis}'s Flame Body")
  1318. user.pbBurn(target,_INTL("{1}'s {2} burned {3}!",target.pbThis,
  1319. PBAbilities.getName(target.ability),user.pbThis(true)))
  1320. end
  1321. if target.hasWorkingAbility(:MUMMY,true) && !user.isFainted?
  1322. if !isConst?(user.ability,PBAbilities,:MULTITYPE) &&
  1323. !isConst?(user.ability,PBAbilities,:STANCECHANGE) &&
  1324. !isConst?(user.ability,PBAbilities,:MUMMY)
  1325. PBDebug.log("[Ability triggered] #{target.pbThis}'s Mummy copied onto #{user.pbThis(true)}")
  1326. user.ability=getConst(PBAbilities,:MUMMY) || 0
  1327. @battle.pbDisplay(_INTL("{1} was mummified by {2}!",
  1328. user.pbThis,target.pbThis(true)))
  1329. end
  1330. end
  1331. if target.hasWorkingAbility(:POISONPOINT,true) && @battle.pbRandom(10)<3 &&
  1332. user.pbCanPoison?(nil,false)
  1333. PBDebug.log("[Ability triggered] #{target.pbThis}'s Poison Point")
  1334. user.pbPoison(target,_INTL("{1}'s {2} poisoned {3}!",target.pbThis,
  1335. PBAbilities.getName(target.ability),user.pbThis(true)))
  1336. end
  1337. if (target.hasWorkingAbility(:ROUGHSKIN,true) ||
  1338. target.hasWorkingAbility(:IRONBARBS,true)) && !user.isFainted?
  1339. if !user.hasWorkingAbility(:MAGICGUARD)
  1340. PBDebug.log("[Ability triggered] #{target.pbThis}'s #{PBAbilities.getName(target.ability)}")
  1341. @battle.scene.pbDamageAnimation(user,0)
  1342. user.pbReduceHP((user.totalhp/8).floor)
  1343. @battle.pbDisplay(_INTL("{1}'s {2} hurt {3}!",target.pbThis,
  1344. PBAbilities.getName(target.ability),user.pbThis(true)))
  1345. end
  1346. end
  1347. if target.hasWorkingAbility(:STATIC,true) && @battle.pbRandom(10)<3 &&
  1348. user.pbCanParalyze?(nil,false)
  1349. PBDebug.log("[Ability triggered] #{target.pbThis}'s Static")
  1350. user.pbParalyze(target,_INTL("{1}'s {2} paralyzed {3}! It may be unable to move!",
  1351. target.pbThis,PBAbilities.getName(target.ability),user.pbThis(true)))
  1352. end
  1353. if target.hasWorkingAbility(:GOOEY,true)
  1354. if user.pbReduceStatWithCause(PBStats::SPEED,1,target,PBAbilities.getName(target.ability))
  1355. PBDebug.log("[Ability triggered] #{target.pbThis}'s Gooey")
  1356. end
  1357. end
  1358. if user.hasWorkingAbility(:POISONTOUCH,true) &&
  1359. target.pbCanPoison?(nil,false) && @battle.pbRandom(10)<3
  1360. PBDebug.log("[Ability triggered] #{user.pbThis}'s Poison Touch")
  1361. target.pbPoison(user,_INTL("{1}'s {2} poisoned {3}!",user.pbThis,
  1362. PBAbilities.getName(user.ability),target.pbThis(true)))
  1363. end
  1364. end
  1365. end
  1366. if damage>0
  1367. if !target.damagestate.substitute
  1368. if target.hasWorkingAbility(:CURSEDBODY,true) && @battle.pbRandom(10)<3
  1369. if user.effects[PBEffects::Disable]<=0 && move.pp>0 && !user.isFainted?
  1370. user.effects[PBEffects::Disable]=3
  1371. user.effects[PBEffects::DisableMove]=move.id
  1372. @battle.pbDisplay(_INTL("{1}'s {2} disabled {3}!",target.pbThis,
  1373. PBAbilities.getName(target.ability),user.pbThis(true)))
  1374. PBDebug.log("[Ability triggered] #{target.pbThis}'s Cursed Body disabled #{user.pbThis(true)}")
  1375. end
  1376. end
  1377. if target.hasWorkingAbility(:JUSTIFIED) && isConst?(movetype,PBTypes,:DARK)
  1378. if target.pbIncreaseStatWithCause(PBStats::ATTACK,1,target,PBAbilities.getName(target.ability))
  1379. PBDebug.log("[Ability triggered] #{target.pbThis}'s Justified")
  1380. end
  1381. end
  1382. if target.hasWorkingAbility(:RATTLED) &&
  1383. (isConst?(movetype,PBTypes,:BUG) ||
  1384. isConst?(movetype,PBTypes,:DARK) ||
  1385. isConst?(movetype,PBTypes,:GHOST))
  1386. if target.pbIncreaseStatWithCause(PBStats::SPEED,1,target,PBAbilities.getName(target.ability))
  1387. PBDebug.log("[Ability triggered] #{target.pbThis}'s Rattled")
  1388. end
  1389. end
  1390. if target.hasWorkingAbility(:WEAKARMOR) && move.pbIsPhysical?(movetype)
  1391. if target.pbReduceStatWithCause(PBStats::DEFENSE,1,target,PBAbilities.getName(target.ability))
  1392. PBDebug.log("[Ability triggered] #{target.pbThis}'s Weak Armor (lower Defense)")
  1393. end
  1394. if target.pbIncreaseStatWithCause(PBStats::SPEED,1,target,PBAbilities.getName(target.ability))
  1395. PBDebug.log("[Ability triggered] #{target.pbThis}'s Weak Armor (raise Speed)")
  1396. end
  1397. end
  1398. if target.hasWorkingItem(:AIRBALLOON,true)
  1399. PBDebug.log("[Item triggered] #{target.pbThis}'s Air Balloon popped")
  1400. @battle.pbDisplay(_INTL("{1}'s Air Balloon popped!",target.pbThis))
  1401. target.pbConsumeItem(true,false)
  1402. elsif target.hasWorkingItem(:ABSORBBULB) && isConst?(movetype,PBTypes,:WATER)
  1403. if target.pbIncreaseStatWithCause(PBStats::SPATK,1,target,PBItems.getName(target.item))
  1404. PBDebug.log("[Item triggered] #{target.pbThis}'s #{PBItems.getName(target.item)}")
  1405. target.pbConsumeItem
  1406. end
  1407. elsif target.hasWorkingItem(:LUMINOUSMOSS) && isConst?(movetype,PBTypes,:WATER)
  1408. if target.pbIncreaseStatWithCause(PBStats::SPDEF,1,target,PBItems.getName(target.item))
  1409. PBDebug.log("[Item triggered] #{target.pbThis}'s #{PBItems.getName(target.item)}")
  1410. target.pbConsumeItem
  1411. end
  1412. elsif target.hasWorkingItem(:CELLBATTERY) && isConst?(movetype,PBTypes,:ELECTRIC)
  1413. if target.pbIncreaseStatWithCause(PBStats::ATTACK,1,target,PBItems.getName(target.item))
  1414. PBDebug.log("[Item triggered] #{target.pbThis}'s #{PBItems.getName(target.item)}")
  1415. target.pbConsumeItem
  1416. end
  1417. elsif target.hasWorkingItem(:SNOWBALL) && isConst?(movetype,PBTypes,:ICE)
  1418. if target.pbIncreaseStatWithCause(PBStats::ATTACK,1,target,PBItems.getName(target.item))
  1419. PBDebug.log("[Item triggered] #{target.pbThis}'s #{PBItems.getName(target.item)}")
  1420. target.pbConsumeItem
  1421. end
  1422. elsif target.hasWorkingItem(:WEAKNESSPOLICY) && target.damagestate.typemod>8
  1423. showanim=true
  1424. if target.pbIncreaseStatWithCause(PBStats::ATTACK,2,target,PBItems.getName(target.item),showanim)
  1425. PBDebug.log("[Item triggered] #{target.pbThis}'s Weakness Policy (Attack)")
  1426. showanim=false
  1427. end
  1428. if target.pbIncreaseStatWithCause(PBStats::SPATK,2,target,PBItems.getName(target.item),showanim)
  1429. PBDebug.log("[Item triggered] #{target.pbThis}'s Weakness Policy (Special Attack)")
  1430. showanim=false
  1431. end
  1432. target.pbConsumeItem if !showanim
  1433. elsif target.hasWorkingItem(:ENIGMABERRY) && target.damagestate.typemod>8
  1434. target.pbActivateBerryEffect
  1435. elsif (target.hasWorkingItem(:JABOCABERRY) && move.pbIsPhysical?(movetype)) ||
  1436. (target.hasWorkingItem(:ROWAPBERRY) && move.pbIsSpecial?(movetype))
  1437. if !user.hasWorkingAbility(:MAGICGUARD) && !user.isFainted?
  1438. PBDebug.log("[Item triggered] #{target.pbThis}'s #{PBItems.getName(target.item)}")
  1439. @battle.scene.pbDamageAnimation(user,0)
  1440. user.pbReduceHP((user.totalhp/8).floor)
  1441. @battle.pbDisplay(_INTL("{1} consumed its {2} and hurt {3}!",target.pbThis,
  1442. PBItems.getName(target.item),user.pbThis(true)))
  1443. target.pbConsumeItem
  1444. end
  1445. elsif target.hasWorkingItem(:KEEBERRY) && move.pbIsPhysical?(movetype)
  1446. target.pbActivateBerryEffect
  1447. elsif target.hasWorkingItem(:MARANGABERRY) && move.pbIsSpecial?(movetype)
  1448. target.pbActivateBerryEffect
  1449. end
  1450. end
  1451. if target.hasWorkingAbility(:ANGERPOINT)
  1452. if target.damagestate.critical && !target.damagestate.substitute &&
  1453. target.pbCanIncreaseStatStage?(PBStats::ATTACK,target)
  1454. PBDebug.log("[Ability triggered] #{target.pbThis}'s Anger Point")
  1455. target.stages[PBStats::ATTACK]=6
  1456. @battle.pbCommonAnimation("StatUp",target,nil)
  1457. @battle.pbDisplay(_INTL("{1}'s {2} maxed its {3}!",
  1458. target.pbThis,PBAbilities.getName(target.ability),PBStats.getName(PBStats::ATTACK)))
  1459. end
  1460. end
  1461. end
  1462. user.pbAbilityCureCheck
  1463. target.pbAbilityCureCheck
  1464. end
  1465.  
  1466. def pbEffectsAfterHit(user,target,thismove,turneffects)
  1467. return if turneffects[PBEffects::TotalDamage]==0
  1468. if !(user.hasWorkingAbility(:SHEERFORCE) && thismove.addlEffect>0)
  1469. # Target's held items:
  1470. # Red Card
  1471. if target.hasWorkingItem(:REDCARD) && @battle.pbCanSwitch?(user.index,-1,false)
  1472. user.effects[PBEffects::Roar]=true
  1473. @battle.pbDisplay(_INTL("{1} held up its {2} against the {3}!",
  1474. target.pbThis,PBItems.getName(target.item),user.pbThis(true)))
  1475. target.pbConsumeItem
  1476. # Eject Button
  1477. elsif target.hasWorkingItem(:EJECTBUTTON) && @battle.pbCanChooseNonActive?(target.index)
  1478. target.effects[PBEffects::Uturn]=true
  1479. @battle.pbDisplay(_INTL("{1} is switched out with the {2}!",
  1480. target.pbThis,PBItems.getName(target.item)))
  1481. target.pbConsumeItem
  1482. end
  1483. # User's held items:
  1484. # Shell Bell
  1485. if user.hasWorkingItem(:SHELLBELL) && user.effects[PBEffects::HealBlock]==0
  1486. PBDebug.log("[Item triggered] #{user.pbThis}'s Shell Bell (total damage=#{turneffects[PBEffects::TotalDamage]})")
  1487. hpgain=user.pbRecoverHP((turneffects[PBEffects::TotalDamage]/8).floor,true)
  1488. if hpgain>0
  1489. @battle.pbDisplay(_INTL("{1} restored a little HP using its {2}!",
  1490. user.pbThis,PBItems.getName(user.item)))
  1491. end
  1492. end
  1493. # Life Orb
  1494. if user.hasWorkingItem(:LIFEORB) && !user.hasWorkingAbility(:MAGICGUARD)
  1495. PBDebug.log("[Item triggered] #{user.pbThis}'s Life Orb (recoil)")
  1496. hploss=user.pbReduceHP((user.totalhp/10).floor,true)
  1497. if hploss>0
  1498. @battle.pbDisplay(_INTL("{1} lost some of its HP!",user.pbThis))
  1499. end
  1500. end
  1501. user.pbFaint if user.isFainted? # no return
  1502. # Color Change
  1503. movetype=thismove.pbType(thismove.type,user,target)
  1504. if target.hasWorkingAbility(:COLORCHANGE) &&
  1505. !PBTypes.isPseudoType?(movetype) && !target.pbHasType?(movetype)
  1506. PBDebug.log("[Ability triggered] #{target.pbThis}'s Color Change made it #{PBTypes.getName(movetype)}-type")
  1507. target.type1=movetype
  1508. target.type2=movetype
  1509. target.effects[PBEffects::Type3]=-1
  1510. @battle.pbDisplay(_INTL("{1}'s {2} made it the {3} type!",target.pbThis,
  1511. PBAbilities.getName(target.ability),PBTypes.getName(movetype)))
  1512. end
  1513. end
  1514. # Moxie
  1515. if user.hasWorkingAbility(:MOXIE) && target.isFainted?
  1516. if user.pbIncreaseStatWithCause(PBStats::ATTACK,1,user,PBAbilities.getName(user.ability))
  1517. PBDebug.log("[Ability triggered] #{user.pbThis}'s Moxie")
  1518. end
  1519. end
  1520. # Magician
  1521. if user.hasWorkingAbility(:MAGICIAN)
  1522. if target.item>0 && user.item==0 &&
  1523. user.effects[PBEffects::Substitute]==0 &&
  1524. target.effects[PBEffects::Substitute]==0 &&
  1525. !target.hasWorkingAbility(:STICKYHOLD) &&
  1526. !@battle.pbIsUnlosableItem(target,target.item) &&
  1527. !@battle.pbIsUnlosableItem(user,target.item) &&
  1528. (@battle.opponent || !@battle.pbIsOpposing?(user.index))
  1529. user.item=target.item
  1530. target.item=0
  1531. target.effects[PBEffects::Unburden]=true
  1532. if !@battle.opponent && # In a wild battle
  1533. user.pokemon.itemInitial==0 &&
  1534. target.pokemon.itemInitial==user.item
  1535. user.pokemon.itemInitial=user.item
  1536. target.pokemon.itemInitial=0
  1537. end
  1538. @battle.pbDisplay(_INTL("{1} stole {2}'s {3} with {4}!",user.pbThis,
  1539. target.pbThis(true),PBItems.getName(user.item),PBAbilities.getName(user.ability)))
  1540. PBDebug.log("[Ability triggered] #{user.pbThis}'s Magician stole #{target.pbThis(true)}'s #{PBItems.getName(user.item)}")
  1541. end
  1542. end
  1543. # Pickpocket
  1544. if target.hasWorkingAbility(:PICKPOCKET)
  1545. if target.item==0 && user.item>0 &&
  1546. user.effects[PBEffects::Substitute]==0 &&
  1547. target.effects[PBEffects::Substitute]==0 &&
  1548. !user.hasWorkingAbility(:STICKYHOLD) &&
  1549. !@battle.pbIsUnlosableItem(user,user.item) &&
  1550. !@battle.pbIsUnlosableItem(target,user.item) &&
  1551. (@battle.opponent || !@battle.pbIsOpposing?(target.index))
  1552. target.item=user.item
  1553. user.item=0
  1554. user.effects[PBEffects::Unburden]=true
  1555. if !@battle.opponent && # In a wild battle
  1556. target.pokemon.itemInitial==0 &&
  1557. user.pokemon.itemInitial==target.item
  1558. target.pokemon.itemInitial=target.item
  1559. user.pokemon.itemInitial=0
  1560. end
  1561. @battle.pbDisplay(_INTL("{1} pickpocketed {2}'s {3}!",target.pbThis,
  1562. user.pbThis(true),PBItems.getName(target.item)))
  1563. PBDebug.log("[Ability triggered] #{target.pbThis}'s Pickpocket stole #{user.pbThis(true)}'s #{PBItems.getName(target.item)}")
  1564. end
  1565. end
  1566. end
  1567.  
  1568. def pbAbilityCureCheck
  1569. return if self.isFainted?
  1570. case self.status
  1571. when PBStatuses::SLEEP
  1572. if self.hasWorkingAbility(:VITALSPIRIT) || self.hasWorkingAbility(:INSOMNIA)
  1573. PBDebug.log("[Ability triggered] #{pbThis}'s #{PBAbilities.getName(@ability)}")
  1574. pbCureStatus(false)
  1575. @battle.pbDisplay(_INTL("{1}'s {2} woke it up!",pbThis,PBAbilities.getName(@ability)))
  1576. end
  1577. when PBStatuses::POISON
  1578. if self.hasWorkingAbility(:IMMUNITY)
  1579. PBDebug.log("[Ability triggered] #{pbThis}'s #{PBAbilities.getName(@ability)}")
  1580. pbCureStatus(false)
  1581. @battle.pbDisplay(_INTL("{1}'s {2} cured its poisoning!",pbThis,PBAbilities.getName(@ability)))
  1582. end
  1583. when PBStatuses::BURN
  1584. if self.hasWorkingAbility(:WATERVEIL)
  1585. PBDebug.log("[Ability triggered] #{pbThis}'s #{PBAbilities.getName(@ability)}")
  1586. pbCureStatus(false)
  1587. @battle.pbDisplay(_INTL("{1}'s {2} healed its burn!",pbThis,PBAbilities.getName(@ability)))
  1588. end
  1589. when PBStatuses::PARALYSIS
  1590. if self.hasWorkingAbility(:LIMBER)
  1591. PBDebug.log("[Ability triggered] #{pbThis}'s #{PBAbilities.getName(@ability)}")
  1592. pbCureStatus(false)
  1593. @battle.pbDisplay(_INTL("{1}'s {2} cured its paralysis!",pbThis,PBAbilities.getName(@ability)))
  1594. end
  1595. when PBStatuses::FROZEN
  1596. if self.hasWorkingAbility(:MAGMAARMOR)
  1597. PBDebug.log("[Ability triggered] #{pbThis}'s #{PBAbilities.getName(@ability)}")
  1598. pbCureStatus(false)
  1599. @battle.pbDisplay(_INTL("{1}'s {2} defrosted it!",pbThis,PBAbilities.getName(@ability)))
  1600. end
  1601. end
  1602. if @effects[PBEffects::Confusion]>0 && self.hasWorkingAbility(:OWNTEMPO)
  1603. PBDebug.log("[Ability triggered] #{pbThis}'s #{PBAbilities.getName(@ability)} (attract)")
  1604. pbCureConfusion(false)
  1605. @battle.pbDisplay(_INTL("{1}'s {2} snapped it out of its confusion!",pbThis,PBAbilities.getName(@ability)))
  1606. end
  1607. if @effects[PBEffects::Attract]>=0 && self.hasWorkingAbility(:OBLIVIOUS)
  1608. PBDebug.log("[Ability triggered] #{pbThis}'s #{PBAbilities.getName(@ability)}")
  1609. pbCureAttract
  1610. @battle.pbDisplay(_INTL("{1}'s {2} cured its infatuation status!",pbThis,PBAbilities.getName(@ability)))
  1611. end
  1612. if USENEWBATTLEMECHANICS && @effects[PBEffects::Taunt]>0 && self.hasWorkingAbility(:OBLIVIOUS)
  1613. PBDebug.log("[Ability triggered] #{pbThis}'s #{PBAbilities.getName(@ability)} (taunt)")
  1614. @effects[PBEffects::Taunt]=0
  1615. @battle.pbDisplay(_INTL("{1}'s {2} made its taunt wear off!",pbThis,PBAbilities.getName(@ability)))
  1616. end
  1617. end
  1618.  
  1619. ################################################################################
  1620. # Held item effects
  1621. ################################################################################
  1622. def pbConsumeItem(recycle=true,pickup=true)
  1623. itemname=PBItems.getName(self.item)
  1624. @pokemon.itemRecycle=self.item if recycle
  1625. @pokemon.itemInitial=0 if @pokemon.itemInitial==self.item
  1626. if pickup
  1627. @effects[PBEffects::PickupItem]=self.item
  1628. @effects[PBEffects::PickupUse]=@battle.nextPickupUse
  1629. end
  1630. self.item=0
  1631. self.effects[PBEffects::Unburden]=true
  1632. # Symbiosis
  1633. if pbPartner && pbPartner.hasWorkingAbility(:SYMBIOSIS) && recycle
  1634. if pbPartner.item>0 &&
  1635. !@battle.pbIsUnlosableItem(pbPartner,pbPartner.item) &&
  1636. !@battle.pbIsUnlosableItem(self,pbPartner.item)
  1637. @battle.pbDisplay(_INTL("{1}'s {2} let it share its {3} with {4}!",
  1638. pbPartner.pbThis,PBAbilities.getName(pbPartner.ability),
  1639. PBItems.getName(pbPartner.item),pbThis(true)))
  1640. self.item=pbPartner.item
  1641. pbPartner.item=0
  1642. pbPartner.effects[PBEffects::Unburden]=true
  1643. pbBerryCureCheck
  1644. end
  1645. end
  1646. end
  1647.  
  1648. def pbConfusionBerry(flavor,message1,message2)
  1649. amt=self.pbRecoverHP((self.totalhp/8).floor,true)
  1650. if amt>0
  1651. @battle.pbDisplay(message1)
  1652. if (self.nature%5)==flavor && (self.nature/5).floor!=(self.nature%5)
  1653. @battle.pbDisplay(message2)
  1654. pbConfuseSelf
  1655. end
  1656. return true
  1657. end
  1658. return false
  1659. end
  1660.  
  1661. def pbStatIncreasingBerry(stat,berryname)
  1662. return pbIncreaseStatWithCause(stat,1,self,berryname)
  1663. end
  1664.  
  1665. def pbActivateBerryEffect(berry=0,consume=true)
  1666. berry=self.item if berry==0
  1667. berryname=(berry==0) ? "" : PBItems.getName(berry)
  1668. PBDebug.log("[Item triggered] #{pbThis}'s #{berryname}")
  1669. consumed=false
  1670. if isConst?(berry,PBItems,:ORANBERRY)
  1671. amt=self.pbRecoverHP(10,true)
  1672. if amt>0
  1673. @battle.pbDisplay(_INTL("{1} restored its health using its {2}!",pbThis,berryname))
  1674. consumed=true
  1675. end
  1676. elsif isConst?(berry,PBItems,:SITRUSBERRY) ||
  1677. isConst?(berry,PBItems,:ENIGMABERRY)
  1678. amt=self.pbRecoverHP((self.totalhp/4).floor,true)
  1679. if amt>0
  1680. @battle.pbDisplay(_INTL("{1} restored its health using its {2}!",pbThis,berryname))
  1681. consumed=true
  1682. end
  1683. elsif isConst?(berry,PBItems,:CHESTOBERRY)
  1684. if self.status==PBStatuses::SLEEP
  1685. pbCureStatus(false)
  1686. @battle.pbDisplay(_INTL("{1}'s {2} cured its sleep problem.",pbThis,berryname))
  1687. consumed=true
  1688. end
  1689. elsif isConst?(berry,PBItems,:PECHABERRY)
  1690. if self.status==PBStatuses::POISON
  1691. pbCureStatus(false)
  1692. @battle.pbDisplay(_INTL("{1}'s {2} cured its poisoning.",pbThis,berryname))
  1693. consumed=true
  1694. end
  1695. elsif isConst?(berry,PBItems,:RAWSTBERRY)
  1696. if self.status==PBStatuses::BURN
  1697. pbCureStatus(false)
  1698. @battle.pbDisplay(_INTL("{1}'s {2} healed its burn.",pbThis,berryname))
  1699. consumed=true
  1700. end
  1701. elsif isConst?(berry,PBItems,:CHERIBERRY)
  1702. if self.status==PBStatuses::PARALYSIS
  1703. pbCureStatus(false)
  1704. @battle.pbDisplay(_INTL("{1}'s {2} cured its paralysis.",pbThis,berryname))
  1705. consumed=true
  1706. end
  1707. elsif isConst?(berry,PBItems,:ASPEARBERRY)
  1708. if self.status==PBStatuses::FROZEN
  1709. pbCureStatus(false)
  1710. @battle.pbDisplay(_INTL("{1}'s {2} thawed it out.",pbThis,berryname))
  1711. consumed=true
  1712. end
  1713. elsif isConst?(berry,PBItems,:LEPPABERRY)
  1714. found=[]
  1715. for i in 0...@pokemon.moves.length
  1716. if @pokemon.moves[i].id!=0
  1717. if (consume && @pokemon.moves[i].pp==0) ||
  1718. (!consume && @pokemon.moves[i].pp<@pokemon.moves[i].totalpp)
  1719. found.push(i)
  1720. end
  1721. end
  1722. end
  1723. if found.length>0
  1724. choice=(consume) ? found[0] : found[@battle.pbRandom(found.length)]
  1725. pokemove=@pokemon.moves[choice]
  1726. pokemove.pp+=10
  1727. pokemove.pp=pokemove.totalpp if pokemove.pp>pokemove.totalpp
  1728. self.moves[choice].pp=pokemove.pp
  1729. movename=PBMoves.getName(pokemove.id)
  1730. @battle.pbDisplay(_INTL("{1}'s {2} restored {3}'s PP!",pbThis,berryname,movename))
  1731. consumed=true
  1732. end
  1733. elsif isConst?(berry,PBItems,:PERSIMBERRY)
  1734. if @effects[PBEffects::Confusion]>0
  1735. pbCureConfusion(false)
  1736. @battle.pbDisplay(_INTL("{1}'s {2} snapped it out of its confusion!",pbThis,berryname))
  1737. consumed=true
  1738. end
  1739. elsif isConst?(berry,PBItems,:LUMBERRY)
  1740. if self.status>0 || @effects[PBEffects::Confusion]>0
  1741. st=self.status; conf=(@effects[PBEffects::Confusion]>0)
  1742. pbCureStatus(false)
  1743. pbCureConfusion(false)
  1744. case st
  1745. when PBStatuses::SLEEP
  1746. @battle.pbDisplay(_INTL("{1}'s {2} woke it up!",pbThis,berryname))
  1747. when PBStatuses::POISON
  1748. @battle.pbDisplay(_INTL("{1}'s {2} cured its poisoning!",pbThis,berryname))
  1749. when PBStatuses::BURN
  1750. @battle.pbDisplay(_INTL("{1}'s {2} healed its burn!",pbThis,berryname))
  1751. when PBStatuses::PARALYSIS
  1752. @battle.pbDisplay(_INTL("{1}'s {2} cured its paralysis!",pbThis,berryname))
  1753. when PBStatuses::FROZEN
  1754. @battle.pbDisplay(_INTL("{1}'s {2} defrosted it!",pbThis,berryname))
  1755. end
  1756. if conf
  1757. @battle.pbDisplay(_INTL("{1}'s {2} snapped it out of its confusion!",pbThis,berryname))
  1758. end
  1759. consumed=true
  1760. end
  1761. elsif isConst?(berry,PBItems,:FIGYBERRY)
  1762. consumed=pbConfusionBerry(0,
  1763. _INTL("{1}'s {2} restored health!",pbThis,berryname),
  1764. _INTL("For {1}, the {2} was too spicy!",pbThis(true),berryname))
  1765. elsif isConst?(berry,PBItems,:WIKIBERRY)
  1766. consumed=pbConfusionBerry(3,
  1767. _INTL("{1}'s {2} restored health!",pbThis,berryname),
  1768. _INTL("For {1}, the {2} was too dry!",pbThis(true),berryname))
  1769. elsif isConst?(berry,PBItems,:MAGOBERRY)
  1770. consumed=pbConfusionBerry(2,
  1771. _INTL("{1}'s {2} restored health!",pbThis,berryname),
  1772. _INTL("For {1}, the {2} was too sweet!",pbThis(true),berryname))
  1773. elsif isConst?(berry,PBItems,:AGUAVBERRY)
  1774. consumed=pbConfusionBerry(4,
  1775. _INTL("{1}'s {2} restored health!",pbThis,berryname),
  1776. _INTL("For {1}, the {2} was too bitter!",pbThis(true),berryname))
  1777. elsif isConst?(berry,PBItems,:IAPAPABERRY)
  1778. consumed=pbConfusionBerry(1,
  1779. _INTL("{1}'s {2} restored health!",pbThis,berryname),
  1780. _INTL("For {1}, the {2} was too sour!",pbThis(true),berryname))
  1781. elsif isConst?(berry,PBItems,:LIECHIBERRY)
  1782. consumed=pbStatIncreasingBerry(PBStats::ATTACK,berryname)
  1783. elsif isConst?(berry,PBItems,:GANLONBERRY) ||
  1784. isConst?(berry,PBItems,:KEEBERRY)
  1785. consumed=pbStatIncreasingBerry(PBStats::DEFENSE,berryname)
  1786. elsif isConst?(berry,PBItems,:SALACBERRY)
  1787. consumed=pbStatIncreasingBerry(PBStats::SPEED,berryname)
  1788. elsif isConst?(berry,PBItems,:PETAYABERRY)
  1789. consumed=pbStatIncreasingBerry(PBStats::SPATK,berryname)
  1790. elsif isConst?(berry,PBItems,:APICOTBERRY) ||
  1791. isConst?(berry,PBItems,:MARANGABERRY)
  1792. consumed=pbStatIncreasingBerry(PBStats::SPDEF,berryname)
  1793. elsif isConst?(berry,PBItems,:LANSATBERRY)
  1794. if @effects[PBEffects::FocusEnergy]<2
  1795. @effects[PBEffects::FocusEnergy]=2
  1796. @battle.pbDisplay(_INTL("{1} used its {2} to get pumped!",pbThis,berryname))
  1797. consumed=true
  1798. end
  1799. elsif isConst?(berry,PBItems,:MICLEBERRY)
  1800. if !@effects[PBEffects::MicleBerry]
  1801. @effects[PBEffects::MicleBerry]=true
  1802. @battle.pbDisplay(_INTL("{1} boosted the accuracy of its next move using its {2}!",
  1803. pbThis,berryname))
  1804. consumed=true
  1805. end
  1806. elsif isConst?(berry,PBItems,:STARFBERRY)
  1807. stats=[]
  1808. for i in [PBStats::ATTACK,PBStats::DEFENSE,PBStats::SPATK,PBStats::SPDEF,PBStats::SPEED]
  1809. stats.push(i) if pbCanIncreaseStatStage?(i,self)
  1810. end
  1811. if stats.length>0
  1812. stat=stats[@battle.pbRandom(stats.length)]
  1813. consumed=pbIncreaseStatWithCause(stat,2,self,berryname)
  1814. end
  1815. end
  1816. if consumed
  1817. # Cheek Pouch
  1818. if hasWorkingAbility(:CHEEKPOUCH)
  1819. amt=self.pbRecoverHP((@totalhp/3).floor,true)
  1820. if amt>0
  1821. @battle.pbDisplay(_INTL("{1}'s {2} restored its health!",
  1822. pbThis,PBAbilities.getName(ability)))
  1823. end
  1824. end
  1825. pbConsumeItem if consume
  1826. self.pokemon.belch=true if self.pokemon
  1827. end
  1828. end
  1829.  
  1830. def pbBerryCureCheck(hpcure=false)
  1831. return if self.isFainted?
  1832. unnerver=(pbOpposing1.hasWorkingAbility(:UNNERVE) ||
  1833. pbOpposing2.hasWorkingAbility(:UNNERVE))
  1834. itemname=(self.item==0) ? "" : PBItems.getName(self.item)
  1835. if hpcure
  1836. if self.hasWorkingItem(:BERRYJUICE) && self.hp<=(self.totalhp/2).floor
  1837. amt=self.pbRecoverHP(20,true)
  1838. if amt>0
  1839. @battle.pbCommonAnimation("UseItem",self,nil)
  1840. @battle.pbDisplay(_INTL("{1} restored its health using its {2}!",pbThis,itemname))
  1841. pbConsumeItem
  1842. return
  1843. end
  1844. end
  1845. end
  1846. if !unnerver
  1847. if hpcure
  1848. if self.hp<=(self.totalhp/2).floor
  1849. if self.hasWorkingItem(:ORANBERRY) ||
  1850. self.hasWorkingItem(:SITRUSBERRY)
  1851. pbActivateBerryEffect
  1852. return
  1853. end
  1854. if self.hasWorkingItem(:FIGYBERRY) ||
  1855. self.hasWorkingItem(:WIKIBERRY) ||
  1856. self.hasWorkingItem(:MAGOBERRY) ||
  1857. self.hasWorkingItem(:AGUAVBERRY) ||
  1858. self.hasWorkingItem(:IAPAPABERRY)
  1859. pbActivateBerryEffect
  1860. return
  1861. end
  1862. end
  1863. end
  1864. if (self.hasWorkingAbility(:GLUTTONY) && self.hp<=(self.totalhp/2).floor) ||
  1865. self.hp<=(self.totalhp/4).floor
  1866. if self.hasWorkingItem(:LIECHIBERRY) ||
  1867. self.hasWorkingItem(:GANLONBERRY) ||
  1868. self.hasWorkingItem(:SALACBERRY) ||
  1869. self.hasWorkingItem(:PETAYABERRY) ||
  1870. self.hasWorkingItem(:APICOTBERRY)
  1871. pbActivateBerryEffect
  1872. return
  1873. end
  1874. if self.hasWorkingItem(:LANSATBERRY) ||
  1875. self.hasWorkingItem(:STARFBERRY)
  1876. pbActivateBerryEffect
  1877. return
  1878. end
  1879. if self.hasWorkingItem(:MICLEBERRY)
  1880. pbActivateBerryEffect
  1881. return
  1882. end
  1883. end
  1884. if self.hasWorkingItem(:LEPPABERRY)
  1885. pbActivateBerryEffect
  1886. return
  1887. end
  1888. if self.hasWorkingItem(:CHESTOBERRY) ||
  1889. self.hasWorkingItem(:PECHABERRY) ||
  1890. self.hasWorkingItem(:RAWSTBERRY) ||
  1891. self.hasWorkingItem(:CHERIBERRY) ||
  1892. self.hasWorkingItem(:ASPEARBERRY) ||
  1893. self.hasWorkingItem(:PERSIMBERRY) ||
  1894. self.hasWorkingItem(:LUMBERRY)
  1895. pbActivateBerryEffect
  1896. return
  1897. end
  1898. end
  1899. if self.hasWorkingItem(:WHITEHERB)
  1900. reducedstats=false
  1901. for i in [PBStats::ATTACK,PBStats::DEFENSE,
  1902. PBStats::SPEED,PBStats::SPATK,PBStats::SPDEF,
  1903. PBStats::ACCURACY,PBStats::EVASION]
  1904. if @stages[i]<0
  1905. @stages[i]=0; reducedstats=true
  1906. end
  1907. end
  1908. if reducedstats
  1909. PBDebug.log("[Item triggered] #{pbThis}'s #{itemname}")
  1910. @battle.pbCommonAnimation("UseItem",self,nil)
  1911. @battle.pbDisplay(_INTL("{1} restored its status using its {2}!",pbThis,itemname))
  1912. pbConsumeItem
  1913. return
  1914. end
  1915. end
  1916. if self.hasWorkingItem(:MENTALHERB) &&
  1917. (@effects[PBEffects::Attract]>=0 ||
  1918. @effects[PBEffects::Taunt]>0 ||
  1919. @effects[PBEffects::Encore]>0 ||
  1920. @effects[PBEffects::Torment] ||
  1921. @effects[PBEffects::Disable]>0 ||
  1922. @effects[PBEffects::HealBlock]>0)
  1923. PBDebug.log("[Item triggered] #{pbThis}'s #{itemname}")
  1924. @battle.pbCommonAnimation("UseItem",self,nil)
  1925. @battle.pbDisplay(_INTL("{1} cured its infatuation status using its {2}.",pbThis,itemname)) if @effects[PBEffects::Attract]>=0
  1926. @battle.pbDisplay(_INTL("{1}'s taunt wore off!",pbThis)) if @effects[PBEffects::Taunt]>0
  1927. @battle.pbDisplay(_INTL("{1}'s encore ended!",pbThis)) if @effects[PBEffects::Encore]>0
  1928. @battle.pbDisplay(_INTL("{1}'s torment wore off!",pbThis)) if @effects[PBEffects::Torment]
  1929. @battle.pbDisplay(_INTL("{1} is no longer disabled!",pbThis)) if @effects[PBEffects::Disable]>0
  1930. @battle.pbDisplay(_INTL("{1}'s Heal Block wore off!",pbThis)) if @effects[PBEffects::HealBlock]>0
  1931. self.pbCureAttract
  1932. @effects[PBEffects::Taunt]=0
  1933. @effects[PBEffects::Encore]=0
  1934. @effects[PBEffects::EncoreMove]=0
  1935. @effects[PBEffects::EncoreIndex]=0
  1936. @effects[PBEffects::Torment]=false
  1937. @effects[PBEffects::Disable]=0
  1938. @effects[PBEffects::HealBlock]=0
  1939. pbConsumeItem
  1940. return
  1941. end
  1942. if hpcure && self.hasWorkingItem(:LEFTOVERS) && self.hp!=self.totalhp &&
  1943. @effects[PBEffects::HealBlock]==0
  1944. PBDebug.log("[Item triggered] #{pbThis}'s Leftovers")
  1945. @battle.pbCommonAnimation("UseItem",self,nil)
  1946. pbRecoverHP((self.totalhp/16).floor,true)
  1947. @battle.pbDisplay(_INTL("{1} restored a little HP using its {2}!",pbThis,itemname))
  1948. end
  1949. if hpcure && self.hasWorkingItem(:BLACKSLUDGE)
  1950. if pbHasType?(:POISON)
  1951. if self.hp!=self.totalhp &&
  1952. (!USENEWBATTLEMECHANICS || @effects[PBEffects::HealBlock]==0)
  1953. PBDebug.log("[Item triggered] #{pbThis}'s Black Sludge (heal)")
  1954. @battle.pbCommonAnimation("UseItem",self,nil)
  1955. pbRecoverHP((self.totalhp/16).floor,true)
  1956. @battle.pbDisplay(_INTL("{1} restored a little HP using its {2}!",pbThis,itemname))
  1957. end
  1958. elsif !self.hasWorkingAbility(:MAGICGUARD)
  1959. PBDebug.log("[Item triggered] #{pbThis}'s Black Sludge (damage)")
  1960. @battle.pbCommonAnimation("UseItem",self,nil)
  1961. pbReduceHP((self.totalhp/8).floor,true)
  1962. @battle.pbDisplay(_INTL("{1} was hurt by its {2}!",pbThis,itemname))
  1963. end
  1964. pbFaint if self.isFainted?
  1965. end
  1966. end
  1967.  
  1968. ################################################################################
  1969. # Move user and targets
  1970. ################################################################################
  1971. def pbFindUser(choice,targets)
  1972. move=choice[2]
  1973. target=choice[3]
  1974. user=self # Normally, the user is self
  1975. # Targets in normal cases
  1976. case pbTarget(move)
  1977. when PBTargets::SingleNonUser
  1978. if target>=0
  1979. targetBattler=@battle.battlers[target]
  1980. if !pbIsOpposing?(targetBattler.index)
  1981. if !pbAddTarget(targets,targetBattler)
  1982. pbAddTarget(targets,pbOpposing2) if !pbAddTarget(targets,pbOpposing1)
  1983. end
  1984. else
  1985. pbAddTarget(targets,targetBattler.pbPartner) if !pbAddTarget(targets,targetBattler)
  1986. end
  1987. else
  1988. pbRandomTarget(targets)
  1989. end
  1990. when PBTargets::SingleOpposing
  1991. if target>=0
  1992. targetBattler=@battle.battlers[target]
  1993. if !pbIsOpposing?(targetBattler.index)
  1994. if !pbAddTarget(targets,targetBattler)
  1995. pbAddTarget(targets,pbOpposing2) if !pbAddTarget(targets,pbOpposing1)
  1996. end
  1997. else
  1998. pbAddTarget(targets,targetBattler.pbPartner) if !pbAddTarget(targets,targetBattler)
  1999. end
  2000. else
  2001. pbRandomTarget(targets)
  2002. end
  2003. when PBTargets::OppositeOpposing
  2004. pbAddTarget(targets,pbOppositeOpposing) if !pbAddTarget(targets,pbOppositeOpposing2)
  2005. when PBTargets::RandomOpposing
  2006. pbRandomTarget(targets)
  2007. when PBTargets::AllOpposing
  2008. # Just pbOpposing1 because partner is determined late
  2009. pbAddTarget(targets,pbOpposing2) if !pbAddTarget(targets,pbOpposing1)
  2010. when PBTargets::AllNonUsers
  2011. for i in 0...4 # not ordered by priority
  2012. pbAddTarget(targets,@battle.battlers[i]) if i!=@index
  2013. end
  2014. when PBTargets::UserOrPartner
  2015. if target>=0 # Pre-chosen target
  2016. targetBattler=@battle.battlers[target]
  2017. pbAddTarget(targets,targetBattler.pbPartner) if !pbAddTarget(targets,targetBattler)
  2018. else
  2019. pbAddTarget(targets,self)
  2020. end
  2021. when PBTargets::Partner
  2022. pbAddTarget(targets,pbPartner)
  2023. else
  2024. move.pbAddTarget(targets,self)
  2025. end
  2026. return user
  2027. end
  2028.  
  2029. def pbChangeUser(thismove,user)
  2030. priority=@battle.pbPriority
  2031. # Change user to user of Snatch
  2032. if thismove.canSnatch?
  2033. for i in priority
  2034. if i.effects[PBEffects::Snatch]
  2035. @battle.pbDisplay(_INTL("{1} snatched {2}'s move!",i.pbThis,user.pbThis(true)))
  2036. PBDebug.log("[Lingering effect triggered] #{i.pbThis}'s Snatch made it use #{user.pbThis(true)}'s #{thismove.name}")
  2037. i.effects[PBEffects::Snatch]=false
  2038. target=user
  2039. user=i
  2040. # Snatch's PP is reduced if old user has Pressure
  2041. userchoice=@battle.choices[user.index][1]
  2042. if target.hasWorkingAbility(:PRESSURE) && user.pbIsOpposing?(target.index) && userchoice>=0
  2043. pressuremove=user.moves[userchoice]
  2044. pbSetPP(pressuremove,pressuremove.pp-1) if pressuremove.pp>0
  2045. end
  2046. break if USENEWBATTLEMECHANICS
  2047. end
  2048. end
  2049. end
  2050. return user
  2051. end
  2052.  
  2053. def pbTarget(move)
  2054. target=move.target
  2055. if move.function==0x10D && pbHasType?(:GHOST) # Curse
  2056. target=PBTargets::OppositeOpposing
  2057. end
  2058. return target
  2059. end
  2060.  
  2061. def pbAddTarget(targets,target)
  2062. if !target.isFainted?
  2063. targets[targets.length]=target
  2064. return true
  2065. end
  2066. return false
  2067. end
  2068.  
  2069. def pbRandomTarget(targets)
  2070. choices=[]
  2071. pbAddTarget(choices,pbOpposing1)
  2072. pbAddTarget(choices,pbOpposing2)
  2073. if choices.length>0
  2074. pbAddTarget(targets,choices[@battle.pbRandom(choices.length)])
  2075. end
  2076. end
  2077.  
  2078. def pbChangeTarget(thismove,userandtarget,targets)
  2079. priority=@battle.pbPriority
  2080. changeeffect=0
  2081. user=userandtarget[0]
  2082. target=userandtarget[1]
  2083. # Lightningrod
  2084. if targets.length==1 && isConst?(thismove.pbType(thismove.type,user,target),PBTypes,:ELECTRIC) &&
  2085. !target.hasWorkingAbility(:LIGHTNINGROD)
  2086. for i in priority # use Pokémon earliest in priority
  2087. next if target.index==i.index
  2088. if i.hasWorkingAbility(:LIGHTNINGROD)
  2089. PBDebug.log("[Ability triggered] #{i.pbThis}'s Lightningrod (change target)")
  2090. target=i # X's Lightningrod took the attack!
  2091. changeeffect=1
  2092. break
  2093. end
  2094. end
  2095. end
  2096. # Storm Drain
  2097. if targets.length==1 && isConst?(thismove.pbType(thismove.type,user,target),PBTypes,:WATER) &&
  2098. !target.hasWorkingAbility(:STORMDRAIN)
  2099. for i in priority # use Pokémon earliest in priority
  2100. next if target.index==i.index
  2101. if i.hasWorkingAbility(:STORMDRAIN)
  2102. PBDebug.log("[Ability triggered] #{i.pbThis}'s Storm Drain (change target)")
  2103. target=i # X's Storm Drain took the attack!
  2104. changeeffect=1
  2105. break
  2106. end
  2107. end
  2108. end
  2109. # Change target to user of Follow Me (overrides Magic Coat
  2110. # because check for Magic Coat below uses this target)
  2111. if PBTargets.targetsOneOpponent?(thismove)
  2112. newtarget=nil; strength=100
  2113. for i in priority # use Pokémon latest in priority
  2114. next if !pbIsOpposing?(i.index)
  2115. if !i.isFainted? && !@battle.switching && !i.effects[PBEffects::SkyDrop] &&
  2116. i.effects[PBEffects::FollowMe]>0 && i.effects[PBEffects::FollowMe]<strength
  2117. PBDebug.log("[Lingering effect triggered] #{i.pbThis}'s Follow Me")
  2118. newtarget=i; strength=i.effects[PBEffects::FollowMe]
  2119. changeeffect=0
  2120. end
  2121. end
  2122. target=newtarget if newtarget
  2123. end
  2124. # TODO: Pressure here is incorrect if Magic Coat redirects target
  2125. if user.index!=target.index && target.hasWorkingAbility(:PRESSURE)
  2126. PBDebug.log("[Ability triggered] #{target.pbThis}'s Pressure (in pbChangeTarget)")
  2127. pbReducePP(thismove) # Reduce PP
  2128. end
  2129. # Change user to user of Snatch
  2130. if thismove.canSnatch?
  2131. for i in priority
  2132. if i.effects[PBEffects::Snatch]
  2133. @battle.pbDisplay(_INTL("{1} Snatched {2}'s move!",i.pbThis,user.pbThis(true)))
  2134. PBDebug.log("[Lingering effect triggered] #{i.pbThis}'s Snatch made it use #{user.pbThis(true)}'s #{thismove.name}")
  2135. i.effects[PBEffects::Snatch]=false
  2136. target=user
  2137. user=i
  2138. # Snatch's PP is reduced if old user has Pressure
  2139. userchoice=@battle.choices[user.index][1]
  2140. if target.hasWorkingAbility(:PRESSURE) && userchoice>=0
  2141. PBDebug.log("[Ability triggered] #{target.pbThis}'s Pressure (part of Snatch)")
  2142. pressuremove=user.moves[userchoice]
  2143. pbSetPP(pressuremove,pressuremove.pp-1) if pressuremove.pp>0
  2144. end
  2145. end
  2146. end
  2147. end
  2148. if thismove.canMagicCoat?
  2149. if target.effects[PBEffects::MagicCoat]
  2150. # switch user and target
  2151. PBDebug.log("[Lingering effect triggered] #{i.pbThis}'s Magic Coat made it use #{user.pbThis(true)}'s #{thismove.name}")
  2152. changeeffect=3
  2153. tmp=user
  2154. user=target
  2155. target=tmp
  2156. # Magic Coat's PP is reduced if old user has Pressure
  2157. userchoice=@battle.choices[user.index][1]
  2158. if target.hasWorkingAbility(:PRESSURE) && user.pbIsOpposing?(target.index) && userchoice>=0
  2159. PBDebug.log("[Ability triggered] #{target.pbThis}'s Pressure (part of Magic Coat)")
  2160. pressuremove=user.moves[userchoice]
  2161. pbSetPP(pressuremove,pressuremove.pp-1) if pressuremove.pp>0
  2162. end
  2163. elsif !user.hasMoldBreaker && target.hasWorkingAbility(:MAGICBOUNCE)
  2164. # switch user and target
  2165. PBDebug.log("[Ability triggered] #{target.pbThis}'s Magic Bounce made it use #{user.pbThis(true)}'s #{thismove.name}")
  2166. changeeffect=3
  2167. tmp=user
  2168. user=target
  2169. target=tmp
  2170. end
  2171. end
  2172. if changeeffect==1
  2173. @battle.pbDisplay(_INTL("{1}'s {2} took the move!",target.pbThis,PBAbilities.getName(target.ability)))
  2174. elsif changeeffect==3
  2175. @battle.pbDisplay(_INTL("{1} bounced the {2} back!",user.pbThis,thismove.name))
  2176. end
  2177. userandtarget[0]=user
  2178. userandtarget[1]=target
  2179. if !user.hasMoldBreaker && target.hasWorkingAbility(:SOUNDPROOF) &&
  2180. thismove.isSoundBased? &&
  2181. thismove.function!=0xE5 && # Perish Song handled elsewhere
  2182. thismove.function!=0x151 # Parting Shot handled elsewhere
  2183. PBDebug.log("[Ability triggered] #{target.pbThis}'s Soundproof blocked #{user.pbThis(true)}'s #{thismove.name}")
  2184. @battle.pbDisplay(_INTL("{1}'s {2} blocks {3}!",target.pbThis,
  2185. PBAbilities.getName(target.ability),thismove.name))
  2186. return false
  2187. end
  2188. return true
  2189. end
  2190.  
  2191. ################################################################################
  2192. # Move PP
  2193. ################################################################################
  2194. def pbSetPP(move,pp)
  2195. move.pp=pp
  2196. # Not effects[PBEffects::Mimic], since Mimic can't copy Mimic
  2197. if move.thismove && move.id==move.thismove.id && !@effects[PBEffects::Transform]
  2198. move.thismove.pp=pp
  2199. end
  2200. end
  2201.  
  2202. def pbReducePP(move)
  2203. #TODO: Pressure
  2204. if @effects[PBEffects::TwoTurnAttack]>0 ||
  2205. @effects[PBEffects::Bide]>0 ||
  2206. @effects[PBEffects::Outrage]>0 ||
  2207. @effects[PBEffects::Rollout]>0 ||
  2208. @effects[PBEffects::HyperBeam]>0 ||
  2209. @effects[PBEffects::Uproar]>0
  2210. # No need to reduce PP if two-turn attack
  2211. return true
  2212. end
  2213. return true if move.pp<0 # No need to reduce PP for special calls of moves
  2214. return true if move.totalpp==0 # Infinite PP, can always be used
  2215. return false if move.pp==0
  2216. if move.pp>0
  2217. pbSetPP(move,move.pp-1)
  2218. end
  2219. return true
  2220. end
  2221.  
  2222. def pbReducePPOther(move)
  2223. pbSetPP(move,move.pp-1) if move.pp>0
  2224. end
  2225.  
  2226. ################################################################################
  2227. # Using a move
  2228. ################################################################################
  2229. def pbObedienceCheck?(choice)
  2230. return true if choice[0]!=1
  2231. if @battle.pbOwnedByPlayer?(@index) && @battle.internalbattle
  2232. badgelevel=10
  2233. badgelevel=20 if @battle.pbPlayer.numbadges>=1
  2234. badgelevel=30 if @battle.pbPlayer.numbadges>=2
  2235. badgelevel=40 if @battle.pbPlayer.numbadges>=3
  2236. badgelevel=50 if @battle.pbPlayer.numbadges>=4
  2237. badgelevel=60 if @battle.pbPlayer.numbadges>=5
  2238. badgelevel=70 if @battle.pbPlayer.numbadges>=6
  2239. badgelevel=80 if @battle.pbPlayer.numbadges>=7
  2240. badgelevel=100 if @battle.pbPlayer.numbadges>=8
  2241. move=choice[2]
  2242. disobedient=false
  2243. if @pokemon.isForeign?(@battle.pbPlayer) && @level>badgelevel
  2244. a=((@level+badgelevel)*@battle.pbRandom(256)/255).floor
  2245. disobedient|=a<badgelevel
  2246. end
  2247. if self.respond_to?("pbHyperModeObedience")
  2248. disobedient|=!self.pbHyperModeObedience(move)
  2249. end
  2250. if disobedient
  2251. PBDebug.log("[Disobedience] #{pbThis} disobeyed")
  2252. @effects[PBEffects::Rage]=false
  2253. if self.status==PBStatuses::SLEEP &&
  2254. (move.function==0x11 || move.function==0xB4) # Snore, Sleep Talk
  2255. @battle.pbDisplay(_INTL("{1} ignored orders while asleep!",pbThis))
  2256. return false
  2257. end
  2258. b=((@level+badgelevel)*@battle.pbRandom(256)/255).floor
  2259. if b<badgelevel
  2260. return false if !@battle.pbCanShowFightMenu?(@index)
  2261. othermoves=[]
  2262. for i in 0...4
  2263. next if i==choice[1]
  2264. othermoves[othermoves.length]=i if @battle.pbCanChooseMove?(@index,i,false)
  2265. end
  2266. if othermoves.length>0
  2267. @battle.pbDisplay(_INTL("{1} ignored orders!",pbThis))
  2268. newchoice=othermoves[@battle.pbRandom(othermoves.length)]
  2269. choice[1]=newchoice
  2270. choice[2]=@moves[newchoice]
  2271. choice[3]=-1
  2272. end
  2273. return true
  2274. elsif self.status!=PBStatuses::SLEEP
  2275. c=@level-b
  2276. r=@battle.pbRandom(256)
  2277. if r<c && pbCanSleep?(self,false)
  2278. pbSleepSelf()
  2279. @battle.pbDisplay(_INTL("{1} took a nap!",pbThis))
  2280. return false
  2281. end
  2282. r-=c
  2283. if r<c
  2284. @battle.pbDisplay(_INTL("It hurt itself in its confusion!"))
  2285. pbConfusionDamage
  2286. else
  2287. message=@battle.pbRandom(4)
  2288. @battle.pbDisplay(_INTL("{1} ignored orders!",pbThis)) if message==0
  2289. @battle.pbDisplay(_INTL("{1} turned away!",pbThis)) if message==1
  2290. @battle.pbDisplay(_INTL("{1} is loafing around!",pbThis)) if message==2
  2291. @battle.pbDisplay(_INTL("{1} pretended not to notice!",pbThis)) if message==3
  2292. end
  2293. return false
  2294. end
  2295. end
  2296. return true
  2297. else
  2298. return true
  2299. end
  2300. end
  2301.  
  2302. def pbSuccessCheck(thismove,user,target,accuracy=true)
  2303. if user.effects[PBEffects::TwoTurnAttack]>0
  2304. return true
  2305. end
  2306. # TODO: "Before Protect" applies to Counter/Mirror Coat
  2307. if thismove.function==0xDE && target.status!=PBStatuses::SLEEP # Dream Eater
  2308. @battle.pbDisplay(_INTL("{1} wasn't affected!",target.pbThis))
  2309. PBDebug.log("[Move failed] #{user.pbThis}'s Dream Eater's target isn't asleep")
  2310. return false
  2311. end
  2312. if thismove.function==0x113 && user.effects[PBEffects::Stockpile]==0 # Spit Up
  2313. @battle.pbDisplay(_INTL("But it failed to spit up a thing!"))
  2314. PBDebug.log("[Move failed] #{user.pbThis}'s Spit Up did nothing as Stockpile's count is 0")
  2315. return false
  2316. end
  2317. if target.effects[PBEffects::Protect] && thismove.canProtectAgainst? &&
  2318. !target.effects[PBEffects::ProtectNegation]
  2319. @battle.pbDisplay(_INTL("{1} protected itself!",target.pbThis))
  2320. @battle.successStates[user.index].protected=true
  2321. PBDebug.log("[Move failed] #{target.pbThis}'s Protect stopped the attack")
  2322. return false
  2323. end
  2324. p=thismove.priority
  2325. if USENEWBATTLEMECHANICS
  2326. p+=1 if user.hasWorkingAbility(:PRANKSTER) && thismove.pbIsStatus?
  2327. p+=1 if user.hasWorkingAbility(:GALEWINGS) && isConst?(thismove.type,PBTypes,:FLYING)
  2328. end
  2329. if target.pbOwnSide.effects[PBEffects::QuickGuard] && thismove.canProtectAgainst? &&
  2330. p>0 && !target.effects[PBEffects::ProtectNegation]
  2331. @battle.pbDisplay(_INTL("{1} was protected by Quick Guard!",target.pbThis))
  2332. PBDebug.log("[Move failed] The opposing side's Quick Guard stopped the attack")
  2333. return false
  2334. end
  2335. if target.pbOwnSide.effects[PBEffects::WideGuard] &&
  2336. PBTargets.hasMultipleTargets?(thismove) && !thismove.pbIsStatus? &&
  2337. !target.effects[PBEffects::ProtectNegation]
  2338. @battle.pbDisplay(_INTL("{1} was protected by Wide Guard!",target.pbThis))
  2339. PBDebug.log("[Move failed] The opposing side's Wide Guard stopped the attack")
  2340. return false
  2341. end
  2342. if target.pbOwnSide.effects[PBEffects::CraftyShield] && thismove.pbIsStatus? &&
  2343. thismove.function!=0xE5 # Perish Song
  2344. @battle.pbDisplay(_INTL("Crafty Shield protected {1}!",target.pbThis(true)))
  2345. PBDebug.log("[Move failed] The opposing side's Crafty Shield stopped the attack")
  2346. return false
  2347. end
  2348. if target.pbOwnSide.effects[PBEffects::MatBlock] && !thismove.pbIsStatus? &&
  2349. thismove.canProtectAgainst? && !target.effects[PBEffects::ProtectNegation]
  2350. @battle.pbDisplay(_INTL("{1} was blocked by the kicked-up mat!",thismove.name))
  2351. PBDebug.log("[Move failed] The opposing side's Mat Block stopped the attack")
  2352. return false
  2353. end
  2354. # TODO: Mind Reader/Lock-On
  2355. # --Sketch/FutureSight/PsychUp work even on Fly/Bounce/Dive/Dig
  2356. if thismove.pbMoveFailed(user,target) # TODO: Applies to Snore/Fake Out
  2357. @battle.pbDisplay(_INTL("But it failed!"))
  2358. PBDebug.log(sprintf("[Move failed] Failed pbMoveFailed (function code %02X)",thismove.function))
  2359. return false
  2360. end
  2361. # King's Shield (purposely after pbMoveFailed)
  2362. if target.effects[PBEffects::KingsShield] && !thismove.pbIsStatus? &&
  2363. thismove.canProtectAgainst? && !target.effects[PBEffects::ProtectNegation]
  2364. @battle.pbDisplay(_INTL("{1} protected itself!",target.pbThis))
  2365. @battle.successStates[user.index].protected=true
  2366. PBDebug.log("[Move failed] #{target.pbThis}'s King's Shield stopped the attack")
  2367. if thismove.isContactMove?
  2368. user.pbReduceStat(PBStats::ATTACK,2,nil,false)
  2369. end
  2370. return false
  2371. end
  2372. # Spiky Shield
  2373. if target.effects[PBEffects::SpikyShield] && thismove.canProtectAgainst? &&
  2374. !target.effects[PBEffects::ProtectNegation]
  2375. @battle.pbDisplay(_INTL("{1} protected itself!",target.pbThis))
  2376. @battle.successStates[user.index].protected=true
  2377. PBDebug.log("[Move failed] #{user.pbThis}'s Spiky Shield stopped the attack")
  2378. if thismove.isContactMove?
  2379. amt=target.pbReduceHP((target.totalhp/8).floor) if !target.isFainted?
  2380. @battle.pbDisplay(_INTL("{1} was hurt!",user.pbThis)) if amt>0
  2381. end
  2382. return false
  2383. end
  2384. # Immunity to powder-based moves
  2385. if USENEWBATTLEMECHANICS && thismove.isPowderMove? &&
  2386. (target.pbHasType?(:GRASS) ||
  2387. (!user.hasMoldBreaker && target.hasWorkingAbility(:OVERCOAT)) ||
  2388. target.hasWorkingItem(:SAFETYGOGGLES))
  2389. @battle.pbDisplay(_INTL("It doesn't affect\r\n{1}...",target.pbThis(true)))
  2390. PBDebug.log("[Move failed] #{target.pbThis} is immune to powder-based moves somehow")
  2391. return false
  2392. end
  2393. if thismove.basedamage>0 && thismove.function!=0x02 && # Struggle
  2394. thismove.function!=0x111 # Future Sight
  2395. type=thismove.pbType(thismove.type,user,target)
  2396. typemod=thismove.pbTypeModifier(type,user,target)
  2397. # Airborne-based immunity to Ground moves
  2398. if isConst?(type,PBTypes,:GROUND) && target.isAirborne?(user.hasMoldBreaker) &&
  2399. !target.hasWorkingItem(:RINGTARGET) && thismove.function!=0x11C # Smack Down
  2400. if !user.hasMoldBreaker && target.hasWorkingAbility(:LEVITATE)
  2401. @battle.pbDisplay(_INTL("{1} makes Ground moves miss with Levitate!",target.pbThis))
  2402. PBDebug.log("[Ability triggered] #{target.pbThis}'s Levitate made the Ground-type move miss")
  2403. return false
  2404. end
  2405. if target.hasWorkingItem(:AIRBALLOON)
  2406. @battle.pbDisplay(_INTL("{1}'s Air Balloon makes Ground moves miss!",target.pbThis))
  2407. PBDebug.log("[Item triggered] #{target.pbThis}'s Air Balloon made the Ground-type move miss")
  2408. return false
  2409. end
  2410. if target.effects[PBEffects::MagnetRise]>0
  2411. @battle.pbDisplay(_INTL("{1} makes Ground moves miss with Magnet Rise!",target.pbThis))
  2412. PBDebug.log("[Lingering effect triggered] #{target.pbThis}'s Magnet Rise made the Ground-type move miss")
  2413. return false
  2414. end
  2415. if target.effects[PBEffects::Telekinesis]>0
  2416. @battle.pbDisplay(_INTL("{1} makes Ground moves miss with Telekinesis!",target.pbThis))
  2417. PBDebug.log("[Lingering effect triggered] #{target.pbThis}'s Telekinesis made the Ground-type move miss")
  2418. return false
  2419. end
  2420. end
  2421. if !user.hasMoldBreaker && target.hasWorkingAbility(:WONDERGUARD) &&
  2422. type>=0 && typemod<=8
  2423. @battle.pbDisplay(_INTL("{1} avoided damage with Wonder Guard!",target.pbThis))
  2424. PBDebug.log("[Ability triggered] #{target.pbThis}'s Wonder Guard")
  2425. return false
  2426. end
  2427. if typemod==0
  2428. @battle.pbDisplay(_INTL("It doesn't affect\r\n{1}...",target.pbThis(true)))
  2429. PBDebug.log("[Move failed] Type immunity")
  2430. return false
  2431. end
  2432. end
  2433. if accuracy
  2434. if target.effects[PBEffects::LockOn]>0 && target.effects[PBEffects::LockOnPos]==user.index
  2435. PBDebug.log("[Lingering effect triggered] #{target.pbThis}'s Lock-On")
  2436. return true
  2437. end
  2438. miss=false; override=false
  2439. invulmove=PBMoveData.new(target.effects[PBEffects::TwoTurnAttack]).function
  2440. case invulmove
  2441. when 0xC9, 0xCC # Fly, Bounce
  2442. miss=true unless thismove.function==0x08 || # Thunder
  2443. thismove.function==0x15 || # Hurricane
  2444. thismove.function==0x77 || # Gust
  2445. thismove.function==0x78 || # Twister
  2446. thismove.function==0x11B || # Sky Uppercut
  2447. thismove.function==0x11C || # Smack Down
  2448. isConst?(thismove.id,PBMoves,:WHIRLWIND)
  2449. when 0xCA # Dig
  2450. miss=true unless thismove.function==0x76 || # Earthquake
  2451. thismove.function==0x95 # Magnitude
  2452. when 0xCB # Dive
  2453. miss=true unless thismove.function==0x75 || # Surf
  2454. thismove.function==0xD0 # Whirlpool
  2455. when 0xCD # Shadow Force
  2456. miss=true
  2457. when 0xCE # Sky Drop
  2458. miss=true unless thismove.function==0x08 || # Thunder
  2459. thismove.function==0x15 || # Hurricane
  2460. thismove.function==0x77 || # Gust
  2461. thismove.function==0x78 || # Twister
  2462. thismove.function==0x11B || # Sky Uppercut
  2463. thismove.function==0x11C # Smack Down
  2464. when 0x14D # Phantom Force
  2465. miss=true
  2466. end
  2467. if target.effects[PBEffects::SkyDrop]
  2468. miss=true unless thismove.function==0x08 || # Thunder
  2469. thismove.function==0x15 || # Hurricane
  2470. thismove.function==0x77 || # Gust
  2471. thismove.function==0x78 || # Twister
  2472. thismove.function==0x11B || # Sky Uppercut
  2473. thismove.function==0x11C # Smack Down
  2474. end
  2475. miss=false if user.hasWorkingAbility(:NOGUARD) ||
  2476. target.hasWorkingAbility(:NOGUARD) ||
  2477. @battle.futuresight
  2478. override=true if USENEWBATTLEMECHANICS && thismove.function==0x06 && # Toxic
  2479. thismove.basedamage==0 && user.pbHasType?(:POISON)
  2480. if !override && (miss || !thismove.pbAccuracyCheck(user,target)) # Includes Counter/Mirror Coat
  2481. PBDebug.log(sprintf("[Move failed] Failed pbAccuracyCheck (function code %02X) or target is semi-invulnerable",thismove.function))
  2482. if thismove.target==PBTargets::AllOpposing &&
  2483. (!user.pbOpposing1.isFainted? ? 1 : 0) + (!user.pbOpposing2.isFainted? ? 1 : 0) > 1
  2484. @battle.pbDisplay(_INTL("{1} avoided the attack!",target.pbThis))
  2485. elsif thismove.target==PBTargets::AllNonUsers &&
  2486. (!user.pbOpposing1.isFainted? ? 1 : 0) + (!user.pbOpposing2.isFainted? ? 1 : 0) + (!user.pbPartner.isFainted? ? 1 : 0) > 1
  2487. @battle.pbDisplay(_INTL("{1} avoided the attack!",target.pbThis))
  2488. elsif target.effects[PBEffects::TwoTurnAttack]>0
  2489. @battle.pbDisplay(_INTL("{1} avoided the attack!",target.pbThis))
  2490. elsif thismove.function==0xDC # Leech Seed
  2491. @battle.pbDisplay(_INTL("{1} evaded the attack!",target.pbThis))
  2492. else
  2493. @battle.pbDisplay(_INTL("{1}'s attack missed!",user.pbThis))
  2494. end
  2495. return false
  2496. end
  2497. end
  2498. return true
  2499. end
  2500.  
  2501. def pbTryUseMove(choice,thismove,turneffects)
  2502. return true if turneffects[PBEffects::PassedTrying]
  2503. # TODO: Return true if attack has been Mirror Coated once already
  2504. return false if !pbObedienceCheck?(choice)
  2505. if @effects[PBEffects::SkyDrop] # Intentionally no message here
  2506. PBDebug.log("[Move failed] #{pbThis} can't use #{thismove.name} because of being Sky Dropped")
  2507. return false
  2508. end
  2509. if @battle.field.effects[PBEffects::Gravity]>0 && thismove.unusableInGravity?
  2510. @battle.pbDisplay(_INTL("{1} can't use {2} because of gravity!",pbThis,thismove.name))
  2511. PBDebug.log("[Move failed] #{pbThis} can't use #{thismove.name} because of Gravity")
  2512. return false
  2513. end
  2514. if @effects[PBEffects::Taunt]>0 && thismove.basedamage==0
  2515. @battle.pbDisplay(_INTL("{1} can't use {2} after the taunt!",pbThis,thismove.name))
  2516. PBDebug.log("[Move failed] #{pbThis} can't use #{thismove.name} because of Taunt")
  2517. return false
  2518. end
  2519. if @effects[PBEffects::HealBlock]>0 && thismove.isHealingMove?
  2520. @battle.pbDisplay(_INTL("{1} can't use {2} because of Heal Block!",pbThis,thismove.name))
  2521. PBDebug.log("[Move failed] #{pbThis} can't use #{thismove.name} because of Heal Block")
  2522. return false
  2523. end
  2524. if @effects[PBEffects::Torment] && thismove.id==@lastMoveUsed &&
  2525. thismove.id!=@battle.struggle.id && @effects[PBEffects::TwoTurnAttack]==0
  2526. @battle.pbDisplayPaused(_INTL("{1} can't use the same move in a row due to the torment!",pbThis))
  2527. PBDebug.log("[Move failed] #{pbThis} can't use #{thismove.name} because of Torment")
  2528. return false
  2529. end
  2530. if pbOpposing1.effects[PBEffects::Imprison] && !pbOpposing1.isFainted?
  2531. if thismove.id==pbOpposing1.moves[0].id ||
  2532. thismove.id==pbOpposing1.moves[1].id ||
  2533. thismove.id==pbOpposing1.moves[2].id ||
  2534. thismove.id==pbOpposing1.moves[3].id
  2535. @battle.pbDisplay(_INTL("{1} can't use the sealed {2}!",pbThis,thismove.name))
  2536. PBDebug.log("[Move failed] #{thismove.name} can't use #{thismove.name} because of #{pbOpposing1.pbThis(true)}'s Imprison")
  2537. return false
  2538. end
  2539. end
  2540. if pbOpposing2.effects[PBEffects::Imprison] && !pbOpposing2.isFainted?
  2541. if thismove.id==pbOpposing2.moves[0].id ||
  2542. thismove.id==pbOpposing2.moves[1].id ||
  2543. thismove.id==pbOpposing2.moves[2].id ||
  2544. thismove.id==pbOpposing2.moves[3].id
  2545. @battle.pbDisplay(_INTL("{1} can't use the sealed {2}!",pbThis,thismove.name))
  2546. PBDebug.log("[Move failed] #{thismove.name} can't use #{thismove.name} because of #{pbOpposing2.pbThis(true)}'s Imprison")
  2547. return false
  2548. end
  2549. end
  2550. if @effects[PBEffects::Disable]>0 && thismove.id==@effects[PBEffects::DisableMove] &&
  2551. !@battle.switching # Pursuit ignores if it's disabled
  2552. @battle.pbDisplayPaused(_INTL("{1}'s {2} is disabled!",pbThis,thismove.name))
  2553. PBDebug.log("[Move failed] #{pbThis}'s #{thismove.name} is disabled")
  2554. return false
  2555. end
  2556. if choice[1]==-2 # Battle Palace
  2557. @battle.pbDisplay(_INTL("{1} appears incapable of using its power!",pbThis))
  2558. PBDebug.log("[Move failed] Battle Palace: #{pbThis} is incapable of using its power")
  2559. return false
  2560. end
  2561. if @effects[PBEffects::HyperBeam]>0
  2562. @battle.pbDisplay(_INTL("{1} must recharge!",pbThis))
  2563. PBDebug.log("[Move failed] #{pbThis} must recharge after using #{PokeBattle_Move.pbFromPBMove(@battle,PBMove.new(@currentMove)).name}")
  2564. return false
  2565. end
  2566. if self.hasWorkingAbility(:TRUANT) && @effects[PBEffects::Truant]
  2567. @battle.pbDisplay(_INTL("{1} is loafing around!",pbThis))
  2568. PBDebug.log("[Ability triggered] #{pbThis}'s Truant")
  2569. return false
  2570. end
  2571. if self.status==PBStatuses::SLEEP
  2572. self.statusCount-=1
  2573. if self.statusCount<=0
  2574. self.pbCureStatus
  2575. else
  2576. self.pbContinueStatus
  2577. PBDebug.log("[Status] #{pbThis} remained asleep (count: #{self.statusCount})")
  2578. if !thismove.pbCanUseWhileAsleep? # Snore/Sleep Talk/Outrage
  2579. PBDebug.log("[Move failed] #{pbThis} couldn't use #{thismove.name} while asleep")
  2580. return false
  2581. end
  2582. end
  2583. end
  2584. if self.status==PBStatuses::FROZEN
  2585. if thismove.canThawUser?
  2586. PBDebug.log("[Move effect triggered] #{pbThis} was defrosted by using #{thismove.name}")
  2587. self.pbCureStatus(false)
  2588. @battle.pbDisplay(_INTL("{1} melted the ice!",pbThis))
  2589. pbCheckForm
  2590. elsif @battle.pbRandom(10)<2
  2591. self.pbCureStatus
  2592. pbCheckForm
  2593. elsif !thismove.canThawUser?
  2594. self.pbContinueStatus
  2595. PBDebug.log("[Status] #{pbThis} remained frozen and couldn't move")
  2596. return false
  2597. end
  2598. end
  2599. if @effects[PBEffects::Confusion]>0
  2600. @effects[PBEffects::Confusion]-=1
  2601. if @effects[PBEffects::Confusion]<=0
  2602. pbCureConfusion
  2603. else
  2604. pbContinueConfusion
  2605. PBDebug.log("[Status] #{pbThis} remained confused (count: #{@effects[PBEffects::Confusion]})")
  2606. if @battle.pbRandom(2)==0
  2607. pbConfusionDamage
  2608. @battle.pbDisplay(_INTL("It hurt itself in its confusion!"))
  2609. PBDebug.log("[Status] #{pbThis} hurt itself in its confusion and couldn't move")
  2610. return false
  2611. end
  2612. end
  2613. end
  2614. if @effects[PBEffects::Flinch]
  2615. @effects[PBEffects::Flinch]=false
  2616. @battle.pbDisplay(_INTL("{1} flinched and couldn't move!",self.pbThis))
  2617. PBDebug.log("[Lingering effect triggered] #{pbThis} flinched")
  2618. if self.hasWorkingAbility(:STEADFAST)
  2619. if pbIncreaseStatWithCause(PBStats::SPEED,1,self,PBAbilities.getName(self.ability))
  2620. PBDebug.log("[Ability triggered] #{pbThis}'s Steadfast")
  2621. end
  2622. end
  2623. return false
  2624. end
  2625. if @effects[PBEffects::Attract]>=0
  2626. pbAnnounceAttract(@battle.battlers[@effects[PBEffects::Attract]])
  2627. if @battle.pbRandom(2)==0
  2628. pbContinueAttract
  2629. PBDebug.log("[Lingering effect triggered] #{pbThis} was infatuated and couldn't move")
  2630. return false
  2631. end
  2632. end
  2633. if self.status==PBStatuses::PARALYSIS
  2634. if @battle.pbRandom(4)==0
  2635. pbContinueStatus
  2636. PBDebug.log("[Status] #{pbThis} was fully paralysed and couldn't move")
  2637. return false
  2638. end
  2639. end
  2640. turneffects[PBEffects::PassedTrying]=true
  2641. return true
  2642. end
  2643.  
  2644. def pbConfusionDamage
  2645. self.damagestate.reset
  2646. confmove=PokeBattle_Confusion.new(@battle,nil)
  2647. confmove.pbEffect(self,self)
  2648. pbFaint if self.isFainted?
  2649. end
  2650.  
  2651. def pbUpdateTargetedMove(thismove,user)
  2652. # TODO: Snatch, moves that use other moves
  2653. # TODO: All targeting cases
  2654. # Two-turn attacks, Magic Coat, Future Sight, Counter/MirrorCoat/Bide handled
  2655. end
  2656.  
  2657. def pbProcessMoveAgainstTarget(thismove,user,target,numhits,turneffects,nocheck=false,alltargets=nil,showanimation=true)
  2658. realnumhits=0
  2659. totaldamage=0
  2660. destinybond=false
  2661. for i in 0...numhits
  2662. target.damagestate.reset
  2663. # Check success (accuracy/evasion calculation)
  2664. if !nocheck &&
  2665. !pbSuccessCheck(thismove,user,target,i==0 || thismove.successCheckPerHit?)
  2666. if thismove.function==0xBF && realnumhits>0 # Triple Kick
  2667. break # Considered a success if Triple Kick hits at least once
  2668. elsif thismove.function==0x10B # Hi Jump Kick, Jump Kick
  2669. if !user.hasWorkingAbility(:MAGICGUARD)
  2670. PBDebug.log("[Move effect triggered] #{user.pbThis} took crash damage")
  2671. #TODO: Not shown if message is "It doesn't affect XXX..."
  2672. @battle.pbDisplay(_INTL("{1} kept going and crashed!",user.pbThis))
  2673. damage=(user.totalhp/2).floor
  2674. if damage>0
  2675. @battle.scene.pbDamageAnimation(user,0)
  2676. user.pbReduceHP(damage)
  2677. end
  2678. user.pbFaint if user.isFainted?
  2679. end
  2680. end
  2681. user.effects[PBEffects::Outrage]=0 if thismove.function==0xD2 # Outrage
  2682. user.effects[PBEffects::Rollout]=0 if thismove.function==0xD3 # Rollout
  2683. user.effects[PBEffects::FuryCutter]=0 if thismove.function==0x91 # Fury Cutter
  2684. user.effects[PBEffects::Stockpile]=0 if thismove.function==0x113 # Spit Up
  2685. return
  2686. end
  2687. # Add to counters for moves which increase them when used in succession
  2688. if thismove.function==0x91 # Fury Cutter
  2689. user.effects[PBEffects::FuryCutter]+=1 if user.effects[PBEffects::FuryCutter]<4
  2690. else
  2691. user.effects[PBEffects::FuryCutter]=0
  2692. end
  2693. if thismove.function==0x92 # Echoed Voice
  2694. if !user.pbOwnSide.effects[PBEffects::EchoedVoiceUsed] &&
  2695. user.pbOwnSide.effects[PBEffects::EchoedVoiceCounter]<5
  2696. user.pbOwnSide.effects[PBEffects::EchoedVoiceCounter]+=1
  2697. end
  2698. user.pbOwnSide.effects[PBEffects::EchoedVoiceUsed]=true
  2699. end
  2700. # Count a hit for Parental Bond if it applies
  2701. user.effects[PBEffects::ParentalBond]-=1 if user.effects[PBEffects::ParentalBond]>0
  2702. # This hit will happen; count it
  2703. realnumhits+=1
  2704. # Damage calculation and/or main effect
  2705. damage=thismove.pbEffect(user,target,i,alltargets,showanimation) # Recoil/drain, etc. are applied here
  2706. totaldamage+=damage if damage>0
  2707. # Message and consume for type-weakening berries
  2708. if target.damagestate.berryweakened
  2709. @battle.pbDisplay(_INTL("The {1} weakened the damage to {2}!",
  2710. PBItems.getName(target.item),target.pbThis(true)))
  2711. target.pbConsumeItem
  2712. end
  2713. # Illusion
  2714. if target.effects[PBEffects::Illusion] && target.hasWorkingAbility(:ILLUSION) &&
  2715. damage>0 && !target.damagestate.substitute
  2716. PBDebug.log("[Ability triggered] #{target.pbThis}'s Illusion ended")
  2717. target.effects[PBEffects::Illusion]=nil
  2718. @battle.scene.pbChangePokemon(target,target.pokemon)
  2719. @battle.pbDisplay(_INTL("{1}'s {2} wore off!",target.pbThis,
  2720. PBAbilities.getName(target.ability)))
  2721. end
  2722. if user.isFainted?
  2723. user.pbFaint # no return
  2724. end
  2725. return if numhits>1 && target.damagestate.calcdamage<=0
  2726. @battle.pbJudgeCheckpoint(user,thismove)
  2727. # Additional effect
  2728. if target.damagestate.calcdamage>0 &&
  2729. !user.hasWorkingAbility(:SHEERFORCE) &&
  2730. (user.hasMoldBreaker || !target.hasWorkingAbility(:SHIELDDUST))
  2731. addleffect=thismove.addlEffect
  2732. addleffect*=2 if (user.hasWorkingAbility(:SERENEGRACE) ||
  2733. user.pbOwnSide.effects[PBEffects::Rainbow]>0) &&
  2734. thismove.function!=0xA4 # Secret Power
  2735. addleffect=100 if $DEBUG && Input.press?(Input::CTRL)
  2736. if @battle.pbRandom(100)<addleffect
  2737. PBDebug.log("[Move effect triggered] #{thismove.name}'s added effect")
  2738. thismove.pbAdditionalEffect(user,target)
  2739. end
  2740. end
  2741. # Ability effects
  2742. pbEffectsOnDealingDamage(thismove,user,target,damage)
  2743. # Grudge
  2744. if !user.isFainted? && target.isFainted?
  2745. if target.effects[PBEffects::Grudge] && target.pbIsOpposing?(user.index)
  2746. thismove.pp=0
  2747. @battle.pbDisplay(_INTL("{1}'s {2} lost all its PP due to the grudge!",
  2748. user.pbThis,thismove.name))
  2749. PBDebug.log("[Lingering effect triggered] #{target.pbThis}'s Grudge made #{thismove.name} lose all its PP")
  2750. end
  2751. end
  2752. if target.isFainted?
  2753. destinybond=destinybond || target.effects[PBEffects::DestinyBond]
  2754. target.pbFaint # no return
  2755. end
  2756. user.pbFaint if user.isFainted? # no return
  2757. break if user.isFainted?
  2758. break if target.isFainted?
  2759. # Make the target flinch
  2760. if target.damagestate.calcdamage>0 && !target.damagestate.substitute
  2761. if user.hasMoldBreaker || !target.hasWorkingAbility(:SHIELDDUST)
  2762. canflinch=false
  2763. if (user.hasWorkingItem(:KINGSROCK) || user.hasWorkingItem(:RAZORFANG)) &&
  2764. thismove.canKingsRock?
  2765. canflinch=true
  2766. end
  2767. if user.hasWorkingAbility(:STENCH) &&
  2768. thismove.function!=0x09 && # Thunder Fang
  2769. thismove.function!=0x0B && # Fire Fang
  2770. thismove.function!=0x0E && # Ice Fang
  2771. thismove.function!=0x0F && # flinch-inducing moves
  2772. thismove.function!=0x10 && # Stomp
  2773. thismove.function!=0x11 && # Snore
  2774. thismove.function!=0x12 && # Fake Out
  2775. thismove.function!=0x78 && # Twister
  2776. thismove.function!=0xC7 # Sky Attack
  2777. canflinch=true
  2778. end
  2779. if canflinch && @battle.pbRandom(10)==0
  2780. PBDebug.log("[Item/ability triggered] #{user.pbThis}'s King's Rock/Razor Fang or Stench")
  2781. target.pbFlinch(user)
  2782. end
  2783. end
  2784. end
  2785. if target.damagestate.calcdamage>0 && !target.isFainted?
  2786. # Defrost
  2787. if target.status==PBStatuses::FROZEN &&
  2788. (isConst?(thismove.pbType(thismove.type,user,target),PBTypes,:FIRE) ||
  2789. (USENEWBATTLEMECHANICS && isConst?(thismove.id,PBMoves,:SCALD)))
  2790. target.pbCureStatus
  2791. end
  2792. # Rage
  2793. if target.effects[PBEffects::Rage] && target.pbIsOpposing?(user.index)
  2794. # TODO: Apparently triggers if opposing Pokémon uses Future Sight after a Future Sight attack
  2795. if target.pbIncreaseStatWithCause(PBStats::ATTACK,1,target,"",true,false)
  2796. PBDebug.log("[Lingering effect triggered] #{target.pbThis}'s Rage")
  2797. @battle.pbDisplay(_INTL("{1}'s rage is building!",target.pbThis))
  2798. end
  2799. end
  2800. end
  2801. target.pbFaint if target.isFainted? # no return
  2802. user.pbFaint if user.isFainted? # no return
  2803. break if user.isFainted? || target.isFainted?
  2804. # Berry check (maybe just called by ability effect, since only necessary Berries are checked)
  2805. for j in 0...4
  2806. @battle.battlers[j].pbBerryCureCheck
  2807. end
  2808. break if user.isFainted? || target.isFainted?
  2809. target.pbUpdateTargetedMove(thismove,user)
  2810. break if target.damagestate.calcdamage<=0
  2811. end
  2812. turneffects[PBEffects::TotalDamage]+=totaldamage if totaldamage>0
  2813. # Battle Arena only - attack is successful
  2814. @battle.successStates[user.index].useState=2
  2815. @battle.successStates[user.index].typemod=target.damagestate.typemod
  2816. # Type effectiveness
  2817. if numhits>1
  2818. if target.damagestate.typemod>8
  2819. if alltargets.length>1
  2820. @battle.pbDisplay(_INTL("It's super effective on {1}!",target.pbThis(true)))
  2821. else
  2822. @battle.pbDisplay(_INTL("It's super effective!"))
  2823. end
  2824. elsif target.damagestate.typemod>=1 && target.damagestate.typemod<8
  2825. if alltargets.length>1
  2826. @battle.pbDisplay(_INTL("It's not very effective on {1}...",target.pbThis(true)))
  2827. else
  2828. @battle.pbDisplay(_INTL("It's not very effective..."))
  2829. end
  2830. end
  2831. if realnumhits==1
  2832. @battle.pbDisplay(_INTL("Hit {1} time!",realnumhits))
  2833. else
  2834. @battle.pbDisplay(_INTL("Hit {1} times!",realnumhits))
  2835. end
  2836. end
  2837. PBDebug.log("Move did #{numhits} hit(s), total damage=#{turneffects[PBEffects::TotalDamage]}")
  2838. # Faint if 0 HP
  2839. target.pbFaint if target.isFainted? # no return
  2840. user.pbFaint if user.isFainted? # no return
  2841. thismove.pbEffectAfterHit(user,target,turneffects)
  2842. target.pbFaint if target.isFainted? # no return
  2843. user.pbFaint if user.isFainted? # no return
  2844. # Destiny Bond
  2845. if !user.isFainted? && target.isFainted?
  2846. if destinybond && target.pbIsOpposing?(user.index)
  2847. PBDebug.log("[Lingering effect triggered] #{target.pbThis}'s Destiny Bond")
  2848. @battle.pbDisplay(_INTL("{1} took its attacker down with it!",target.pbThis))
  2849. user.pbReduceHP(user.hp)
  2850. user.pbFaint # no return
  2851. @battle.pbJudgeCheckpoint(user)
  2852. end
  2853. end
  2854. pbEffectsAfterHit(user,target,thismove,turneffects)
  2855. # Berry check
  2856. for j in 0...4
  2857. @battle.battlers[j].pbBerryCureCheck
  2858. end
  2859. target.pbUpdateTargetedMove(thismove,user)
  2860. end
  2861.  
  2862. def pbUseMoveSimple(moveid,index=-1,target=-1)
  2863. choice=[]
  2864. choice[0]=1 # "Use move"
  2865. choice[1]=index # Index of move to be used in user's moveset
  2866. choice[2]=PokeBattle_Move.pbFromPBMove(@battle,PBMove.new(moveid)) # PokeBattle_Move object of the move
  2867. choice[2].pp=-1
  2868. choice[3]=target # Target (-1 means no target yet)
  2869. if index>=0
  2870. @battle.choices[@index][1]=index
  2871. end
  2872. PBDebug.log("#{pbThis} used simple move #{choice[2].name}")
  2873. pbUseMove(choice,true)
  2874. return
  2875. end
  2876.  
  2877. def pbUseMove(choice,specialusage=false)
  2878. # TODO: lastMoveUsed is not to be updated on nested calls
  2879. # Note: user.lastMoveUsedType IS to be updated on nested calls; is used for Conversion 2
  2880. turneffects=[]
  2881. turneffects[PBEffects::SpecialUsage]=specialusage
  2882. turneffects[PBEffects::PassedTrying]=false
  2883. turneffects[PBEffects::TotalDamage]=0
  2884. # Start using the move
  2885. pbBeginTurn(choice)
  2886. # Force the use of certain moves if they're already being used
  2887. if @effects[PBEffects::TwoTurnAttack]>0 ||
  2888. @effects[PBEffects::HyperBeam]>0 ||
  2889. @effects[PBEffects::Outrage]>0 ||
  2890. @effects[PBEffects::Rollout]>0 ||
  2891. @effects[PBEffects::Uproar]>0 ||
  2892. @effects[PBEffects::Bide]>0
  2893. choice[2]=PokeBattle_Move.pbFromPBMove(@battle,PBMove.new(@currentMove))
  2894. turneffects[PBEffects::SpecialUsage]=true
  2895. PBDebug.log("Continuing multi-turn move #{choice[2].name}")
  2896. elsif @effects[PBEffects::Encore]>0
  2897. if @battle.pbCanShowCommands?(@index) &&
  2898. @battle.pbCanChooseMove?(@index,@effects[PBEffects::EncoreIndex],false)
  2899. if choice[1]!=@effects[PBEffects::EncoreIndex] # Was Encored mid-round
  2900. choice[1]=@effects[PBEffects::EncoreIndex]
  2901. choice[2]=@moves[@effects[PBEffects::EncoreIndex]]
  2902. choice[3]=-1 # No target chosen
  2903. end
  2904. PBDebug.log("Using Encored move #{choice[2].name}")
  2905. end
  2906. end
  2907. thismove=choice[2]
  2908. return if !thismove || thismove.id==0 # if move was not chosen
  2909. if !turneffects[PBEffects::SpecialUsage]
  2910. # TODO: Quick Claw message
  2911. end
  2912. # Stance Change
  2913. if hasWorkingAbility(:STANCECHANGE) && isConst?(species,PBSpecies,:AEGISLASH) &&
  2914. !@effects[PBEffects::Transform]
  2915. if thismove.pbIsDamaging? && self.form!=1
  2916. self.form=1
  2917. pbUpdate(true)
  2918. @battle.scene.pbChangePokemon(self,@pokemon)
  2919. @battle.pbDisplay(_INTL("{1} changed to Blade Forme",pbThis))
  2920. PBDebug.log("[Form changed] #{pbThis} changed to Blade Forme")
  2921. elsif isConst?(thismove.id,PBMoves,:KINGSSHIELD) && self.form!=0
  2922. self.form=0
  2923. pbUpdate(true)
  2924. @battle.scene.pbChangePokemon(self,@pokemon)
  2925. @battle.pbDisplay(_INTL("{1} changed to Shield Forme",pbThis))
  2926. PBDebug.log("[Form changed] #{pbThis} changed to Shield Forme")
  2927. end
  2928. end
  2929. # Try to use the move
  2930. if !pbTryUseMove(choice,thismove,turneffects)
  2931. self.lastMoveUsed=-1
  2932. self.lastMoveUsedType=-1
  2933. if !turneffects[PBEffects::SpecialUsage]
  2934. self.lastMoveUsedSketch=-1 if self.effects[PBEffects::TwoTurnAttack]==0
  2935. self.lastRegularMoveUsed=-1
  2936. self.lastRoundMoved=@battle.turncount
  2937. end
  2938. pbCancelMoves
  2939. @battle.pbGainEXP
  2940. pbEndTurn(choice)
  2941. @battle.pbJudge # @battle.pbSwitch
  2942. return
  2943. end
  2944. if !turneffects[PBEffects::SpecialUsage]
  2945. if !pbReducePP(thismove)
  2946. @battle.pbDisplay(_INTL("{1} used\r\n{2}!",pbThis,thismove.name))
  2947. @battle.pbDisplay(_INTL("But there was no PP left for the move!"))
  2948. self.lastMoveUsed=-1
  2949. self.lastMoveUsedType=-1
  2950. self.lastMoveUsedSketch=-1 if self.effects[PBEffects::TwoTurnAttack]==0
  2951. self.lastRegularMoveUsed=-1
  2952. self.lastRoundMoved=@battle.turncount
  2953. pbEndTurn(choice)
  2954. @battle.pbJudge # @battle.pbSwitch
  2955. PBDebug.log("[Move failed] #{thismove.name} has no PP left")
  2956. return
  2957. end
  2958. end
  2959. # Remember that user chose a two-turn move
  2960. if thismove.pbTwoTurnAttack(self)
  2961. # Beginning use of two-turn attack
  2962. @effects[PBEffects::TwoTurnAttack]=thismove.id
  2963. @currentMove=thismove.id
  2964. else
  2965. @effects[PBEffects::TwoTurnAttack]=0 # Cancel use of two-turn attack
  2966. end
  2967. # Charge up Metronome item
  2968. if self.lastMoveUsed==thismove.id
  2969. self.effects[PBEffects::Metronome]+=1
  2970. else
  2971. self.effects[PBEffects::Metronome]=0
  2972. end
  2973. # "X used Y!" message
  2974. case thismove.pbDisplayUseMessage(self)
  2975. when 2 # Continuing Bide
  2976. if !turneffects[PBEffects::SpecialUsage]
  2977. self.lastRoundMoved=@battle.turncount
  2978. end
  2979. return
  2980. when 1 # Starting Bide
  2981. self.lastMoveUsed=thismove.id
  2982. self.lastMoveUsedType=thismove.pbType(thismove.type,self,nil)
  2983. if !turneffects[PBEffects::SpecialUsage]
  2984. self.lastMoveUsedSketch=thismove.id if self.effects[PBEffects::TwoTurnAttack]==0
  2985. self.lastRegularMoveUsed=thismove.id
  2986. self.lastRoundMoved=@battle.turncount
  2987. end
  2988. @battle.lastMoveUsed=thismove.id
  2989. @battle.lastMoveUser=self.index
  2990. @battle.successStates[self.index].useState=2
  2991. @battle.successStates[self.index].typemod=8
  2992. return
  2993. when -1 # Was hurt while readying Focus Punch, fails use
  2994. self.lastMoveUsed=thismove.id
  2995. self.lastMoveUsedType=thismove.pbType(thismove.type,self,nil)
  2996. if !turneffects[PBEffects::SpecialUsage]
  2997. self.lastMoveUsedSketch=thismove.id if self.effects[PBEffects::TwoTurnAttack]==0
  2998. self.lastRegularMoveUsed=thismove.id
  2999. self.lastRoundMoved=@battle.turncount
  3000. end
  3001. @battle.lastMoveUsed=thismove.id
  3002. @battle.lastMoveUser=self.index
  3003. @battle.successStates[self.index].useState=2 # somehow treated as a success
  3004. @battle.successStates[self.index].typemod=8
  3005. PBDebug.log("[Move failed] #{pbThis} was hurt while readying Focus Punch")
  3006. return
  3007. end
  3008. # Find the user and target(s)
  3009. targets=[]
  3010. user=pbFindUser(choice,targets)
  3011. # Battle Arena only - assume failure
  3012. @battle.successStates[user.index].useState=1
  3013. @battle.successStates[user.index].typemod=8
  3014. # Check whether Selfdestruct works
  3015. selffaint=(thismove.function==0xE0) # Selfdestruct
  3016. if !thismove.pbOnStartUse(user) # Selfdestruct, Natural Gift, Beat Up can return false here
  3017. PBDebug.log(sprintf("[Move failed] Failed pbOnStartUse (function code %02X)",thismove.function))
  3018. user.lastMoveUsed=thismove.id
  3019. user.lastMoveUsedType=thismove.pbType(thismove.type,user,nil)
  3020. if !turneffects[PBEffects::SpecialUsage]
  3021. user.lastMoveUsedSketch=thismove.id if user.effects[PBEffects::TwoTurnAttack]==0
  3022. user.lastRegularMoveUsed=thismove.id
  3023. user.lastRoundMoved=@battle.turncount
  3024. end
  3025. @battle.lastMoveUsed=thismove.id
  3026. @battle.lastMoveUser=user.index
  3027. return
  3028. end
  3029. if selffaint
  3030. user.hp=0
  3031. user.pbFaint # no return
  3032. end
  3033. # Primordial Sea, Desolate Land
  3034. if thismove.pbIsDamaging?
  3035. case @battle.pbWeather
  3036. when PBWeather::HEAVYRAIN
  3037. if isConst?(thismove.pbType(thismove.type,user,nil),PBTypes,:FIRE)
  3038. PBDebug.log("[Move failed] Primordial Sea's rain cancelled the Fire-type #{thismove.name}")
  3039. @battle.pbDisplay(_INTL("The Fire-type attack fizzled out in the heavy rain!"))
  3040. user.lastMoveUsed=thismove.id
  3041. user.lastMoveUsedType=thismove.pbType(thismove.type,user,nil)
  3042. if !turneffects[PBEffects::SpecialUsage]
  3043. user.lastMoveUsedSketch=thismove.id if user.effects[PBEffects::TwoTurnAttack]==0
  3044. user.lastRegularMoveUsed=thismove.id
  3045. user.lastRoundMoved=@battle.turncount
  3046. end
  3047. @battle.lastMoveUsed=thismove.id
  3048. @battle.lastMoveUser=user.index
  3049. return
  3050. end
  3051. when PBWeather::HARSHSUN
  3052. if isConst?(thismove.pbType(thismove.type,user,nil),PBTypes,:WATER)
  3053. PBDebug.log("[Move failed] Desolate Land's sun cancelled the Water-type #{thismove.name}")
  3054. @battle.pbDisplay(_INTL("The Water-type attack evaporated in the harsh sunlight!"))
  3055. user.lastMoveUsed=thismove.id
  3056. user.lastMoveUsedType=thismove.pbType(thismove.type,user,nil)
  3057. if !turneffects[PBEffects::SpecialUsage]
  3058. user.lastMoveUsedSketch=thismove.id if user.effects[PBEffects::TwoTurnAttack]==0
  3059. user.lastRegularMoveUsed=thismove.id
  3060. user.lastRoundMoved=@battle.turncount
  3061. end
  3062. @battle.lastMoveUsed=thismove.id
  3063. @battle.lastMoveUser=user.index
  3064. return
  3065. end
  3066. end
  3067. end
  3068. # Powder
  3069. if user.effects[PBEffects::Powder] && isConst?(thismove.pbType(thismove.type,user,nil),PBTypes,:FIRE)
  3070. PBDebug.log("[Lingering effect triggered] #{pbThis}'s Powder cancelled the Fire move")
  3071. @battle.pbCommonAnimation("Powder",user,nil)
  3072. @battle.pbDisplay(_INTL("When the flame touched the powder on the Pokémon, it exploded!"))
  3073. user.pbReduceHP(1+(user.totalhp/4).floor) if !user.hasWorkingAbility(:MAGICGUARD)
  3074. user.lastMoveUsed=thismove.id
  3075. user.lastMoveUsedType=thismove.pbType(thismove.type,user,nil)
  3076. if !turneffects[PBEffects::SpecialUsage]
  3077. user.lastMoveUsedSketch=thismove.id if user.effects[PBEffects::TwoTurnAttack]==0
  3078. user.lastRegularMoveUsed=thismove.id
  3079. user.lastRoundMoved=@battle.turncount
  3080. end
  3081. @battle.lastMoveUsed=thismove.id
  3082. @battle.lastMoveUser=user.index
  3083. user.pbFaint if user.isFainted?
  3084. pbEndTurn(choice)
  3085. return
  3086. end
  3087. # Protean
  3088. if user.hasWorkingAbility(:PROTEAN) &&
  3089. thismove.function!=0xAE && # Mirror Move
  3090. thismove.function!=0xAF && # Copycat
  3091. thismove.function!=0xB0 && # Me First
  3092. thismove.function!=0xB3 && # Nature Power
  3093. thismove.function!=0xB4 && # Sleep Talk
  3094. thismove.function!=0xB5 && # Assist
  3095. thismove.function!=0xB6 # Metronome
  3096. movetype=thismove.pbType(thismove.type,user,nil)
  3097. if !user.pbHasType?(movetype)
  3098. typename=PBTypes.getName(movetype)
  3099. PBDebug.log("[Ability triggered] #{pbThis}'s Protean made it #{typename}-type")
  3100. user.type1=movetype
  3101. user.type2=movetype
  3102. user.effects[PBEffects::Type3]=-1
  3103. @battle.pbDisplay(_INTL("{1} transformed into the {2} type!",user.pbThis,typename))
  3104. end
  3105. end
  3106. # Try to use move against user if there aren't any targets
  3107. if targets.length==0
  3108. user=pbChangeUser(thismove,user)
  3109. if thismove.target==PBTargets::SingleNonUser ||
  3110. thismove.target==PBTargets::RandomOpposing ||
  3111. thismove.target==PBTargets::AllOpposing ||
  3112. thismove.target==PBTargets::AllNonUsers ||
  3113. thismove.target==PBTargets::Partner ||
  3114. thismove.target==PBTargets::UserOrPartner ||
  3115. thismove.target==PBTargets::SingleOpposing ||
  3116. thismove.target==PBTargets::OppositeOpposing
  3117. @battle.pbDisplay(_INTL("But there was no target..."))
  3118. else
  3119. PBDebug.logonerr{
  3120. thismove.pbEffect(user,nil)
  3121. }
  3122. end
  3123. else
  3124. # We have targets
  3125. showanimation=true
  3126. alltargets=[]
  3127. for i in 0...targets.length
  3128. alltargets.push(targets[i].index) if !targets.include?(targets[i].index)
  3129. end
  3130. # For each target in turn
  3131. i=0; loop do break if i>=targets.length
  3132. # Get next target
  3133. userandtarget=[user,targets[i]]
  3134. success=pbChangeTarget(thismove,userandtarget,targets)
  3135. user=userandtarget[0]
  3136. target=userandtarget[1]
  3137. if i==0 && thismove.target==PBTargets::AllOpposing
  3138. # Add target's partner to list of targets
  3139. pbAddTarget(targets,target.pbPartner)
  3140. end
  3141. # If couldn't get the next target
  3142. if !success
  3143. i+=1
  3144. next
  3145. end
  3146. # Get the number of hits
  3147. numhits=thismove.pbNumHits(user)
  3148. # Reset damage state, set Focus Band/Focus Sash to available
  3149. target.damagestate.reset
  3150. # Use move against the current target
  3151. pbProcessMoveAgainstTarget(thismove,user,target,numhits,turneffects,false,alltargets,showanimation)
  3152. showanimation=false
  3153. i+=1
  3154. end
  3155. # Pokémon switching caused by Roar, Whirlwind, Circle Throw, Dragon Tail, Red Card
  3156. if !user.isFainted?
  3157. switched=[]
  3158. for i in 0...4
  3159. if @battle.battlers[i].effects[PBEffects::Roar]
  3160. @battle.battlers[i].effects[PBEffects::Roar]=false
  3161. @battle.battlers[i].effects[PBEffects::Uturn]=false
  3162. next if @battle.battlers[i].isFainted?
  3163. next if !@battle.pbCanSwitch?(i,-1,false)
  3164. choices=[]
  3165. party=@battle.pbParty(i)
  3166. for j in 0...party.length
  3167. choices.push(j) if @battle.pbCanSwitchLax?(i,j,false)
  3168. end
  3169. if choices.length>0
  3170. newpoke=choices[@battle.pbRandom(choices.length)]
  3171. newpokename=newpoke
  3172. if isConst?(party[newpoke].ability,PBAbilities,:ILLUSION)
  3173. newpokename=pbGetLastPokeInTeam(i)
  3174. end
  3175. switched.push(i)
  3176. @battle.battlers[i].pbResetForm
  3177. @battle.pbRecallAndReplace(i,newpoke,newpokename,false,user.hasMoldBreaker)
  3178. @battle.pbDisplay(_INTL("{1} was dragged out!",@battle.battlers[i].pbThis))
  3179. end
  3180. end
  3181. end
  3182. for i in @battle.pbPriority
  3183. next if !switched.include?(i.index)
  3184. i.pbAbilitiesOnSwitchIn(true)
  3185. end
  3186. end
  3187. # Pokémon switching caused by U-Turn, Volt Switch, Eject Button
  3188. switched=[]
  3189. for i in 0...4
  3190. if @battle.battlers[i].effects[PBEffects::Uturn]
  3191. @battle.battlers[i].effects[PBEffects::Uturn]=false
  3192. @battle.battlers[i].effects[PBEffects::Roar]=false
  3193. if !@battle.battlers[i].isFainted? && @battle.pbCanChooseNonActive?(i) &&
  3194. !@battle.pbAllFainted?(@battle.pbOpposingParty(i))
  3195. # TODO: Pursuit should go here, and negate this effect if it KO's attacker
  3196. @battle.pbDisplay(_INTL("{1} went back to {2}!",@battle.battlers[i].pbThis,@battle.pbGetOwner(i).name))
  3197. newpoke=0
  3198. newpoke=@battle.pbSwitchInBetween(i,true,false)
  3199. newpokename=newpoke
  3200. if isConst?(@battle.pbParty(i)[newpoke].ability,PBAbilities,:ILLUSION)
  3201. newpokename=pbGetLastPokeInTeam(i)
  3202. end
  3203. switched.push(i)
  3204. @battle.battlers[i].pbResetForm
  3205. @battle.pbRecallAndReplace(i,newpoke,newpokename,@battle.battlers[i].effects[PBEffects::BatonPass])
  3206. end
  3207. end
  3208. end
  3209. for i in @battle.pbPriority
  3210. next if !switched.include?(i.index)
  3211. i.pbAbilitiesOnSwitchIn(true)
  3212. end
  3213. # Baton Pass
  3214. if user.effects[PBEffects::BatonPass]
  3215. user.effects[PBEffects::BatonPass]=false
  3216. if !user.isFainted? && @battle.pbCanChooseNonActive?(user.index) &&
  3217. !@battle.pbAllFainted?(@battle.pbParty(target.index))
  3218. newpoke=0
  3219. newpoke=@battle.pbSwitchInBetween(user.index,true,false)
  3220. newpokename=newpoke
  3221. if isConst?(@battle.pbParty(user.index)[newpoke].ability,PBAbilities,:ILLUSION)
  3222. newpokename=pbGetLastPokeInTeam(user.index)
  3223. end
  3224. user.pbResetForm
  3225. @battle.pbRecallAndReplace(user.index,newpoke,newpokename,true)
  3226. user.pbAbilitiesOnSwitchIn(true)
  3227. end
  3228. end
  3229. end
  3230. # Record move as having been used
  3231. user.lastMoveUsed=thismove.id
  3232. user.lastMoveUsedType=thismove.pbType(thismove.type,user,nil)
  3233. if !turneffects[PBEffects::SpecialUsage]
  3234. user.lastMoveUsedSketch=thismove.id if user.effects[PBEffects::TwoTurnAttack]==0
  3235. user.lastRegularMoveUsed=thismove.id
  3236. user.movesUsed.push(thismove.id) if !user.movesUsed.include?(thismove.id) # For Last Resort
  3237. user.lastRoundMoved=@battle.turncount
  3238. end
  3239. @battle.lastMoveUsed=thismove.id
  3240. @battle.lastMoveUser=user.index
  3241. # Gain Exp
  3242. @battle.pbGainEXP
  3243. # Battle Arena only - update skills
  3244. for i in 0...4
  3245. @battle.successStates[i].updateSkill
  3246. end
  3247. # End of move usage
  3248. pbEndTurn(choice)
  3249. @battle.pbJudge # @battle.pbSwitch
  3250. return
  3251. end
  3252.  
  3253. def pbCancelMoves
  3254. # If failed pbTryUseMove or have already used Pursuit to chase a switching foe
  3255. # Cancel multi-turn attacks (note: Hyper Beam effect is not canceled here)
  3256. @effects[PBEffects::TwoTurnAttack]=0 if @effects[PBEffects::TwoTurnAttack]>0
  3257. @effects[PBEffects::Outrage]=0
  3258. @effects[PBEffects::Rollout]=0
  3259. @effects[PBEffects::Uproar]=0
  3260. @effects[PBEffects::Bide]=0
  3261. @currentMove=0
  3262. # Reset counters for moves which increase them when used in succession
  3263. @effects[PBEffects::FuryCutter]=0
  3264. PBDebug.log("Cancelled using the move")
  3265. end
  3266.  
  3267. ################################################################################
  3268. # Turn processing
  3269. ################################################################################
  3270. def pbBeginTurn(choice)
  3271. # Cancel some lingering effects which only apply until the user next moves
  3272. @effects[PBEffects::DestinyBond]=false
  3273. @effects[PBEffects::Grudge]=false
  3274. # Reset Parental Bond's count
  3275. @effects[PBEffects::ParentalBond]=0
  3276. # Encore's effect ends if the encored move is no longer available
  3277. if @effects[PBEffects::Encore]>0 &&
  3278. @moves[@effects[PBEffects::EncoreIndex]].id!=@effects[PBEffects::EncoreMove]
  3279. PBDebug.log("Resetting Encore effect")
  3280. @effects[PBEffects::Encore]=0
  3281. @effects[PBEffects::EncoreIndex]=0
  3282. @effects[PBEffects::EncoreMove]=0
  3283. end
  3284. # Wake up in an uproar
  3285. if self.status==PBStatuses::SLEEP && !self.hasWorkingAbility(:SOUNDPROOF)
  3286. for i in 0...4
  3287. if @battle.battlers[i].effects[PBEffects::Uproar]>0
  3288. pbCureStatus(false)
  3289. @battle.pbDisplay(_INTL("{1} woke up in the uproar!",pbThis))
  3290. end
  3291. end
  3292. end
  3293. end
  3294.  
  3295. def pbEndTurn(choice)
  3296. # True end(?)
  3297. if @effects[PBEffects::ChoiceBand]<0 && @lastMoveUsed>=0 && !self.isFainted? &&
  3298. (self.hasWorkingItem(:CHOICEBAND) ||
  3299. self.hasWorkingItem(:CHOICESPECS) ||
  3300. self.hasWorkingItem(:CHOICESCARF))
  3301. @effects[PBEffects::ChoiceBand]=@lastMoveUsed
  3302. end
  3303. @battle.pbPrimordialWeather
  3304. for i in 0...4
  3305. @battle.battlers[i].pbBerryCureCheck
  3306. end
  3307. for i in 0...4
  3308. @battle.battlers[i].pbAbilityCureCheck
  3309. end
  3310. for i in 0...4
  3311. @battle.battlers[i].pbAbilitiesOnSwitchIn(false)
  3312. end
  3313. for i in 0...4
  3314. @battle.battlers[i].pbCheckForm
  3315. end
  3316. end
  3317.  
  3318. def pbProcessTurn(choice)
  3319. # Can't use a move if fainted
  3320. return false if self.isFainted?
  3321. # Wild roaming Pokémon always flee if possible
  3322. if !@battle.opponent && @battle.pbIsOpposing?(self.index) &&
  3323. @battle.rules["alwaysflee"] && @battle.pbCanRun?(self.index)
  3324. pbBeginTurn(choice)
  3325. @battle.pbDisplay(_INTL("{1} fled!",self.pbThis))
  3326. @battle.decision=3
  3327. pbEndTurn(choice)
  3328. PBDebug.log("[Escape] #{pbThis} fled")
  3329. return true
  3330. end
  3331. # If this battler's action for this round wasn't "use a move"
  3332. if choice[0]!=1
  3333. # Clean up effects that end at battler's turn
  3334. pbBeginTurn(choice)
  3335. pbEndTurn(choice)
  3336. return false
  3337. end
  3338. # Turn is skipped if Pursuit was used during switch
  3339. if @effects[PBEffects::Pursuit]
  3340. @effects[PBEffects::Pursuit]=false
  3341. pbCancelMoves
  3342. pbEndTurn(choice)
  3343. @battle.pbJudge # @battle.pbSwitch
  3344. return false
  3345. end
  3346. # Use the move
  3347. # @battle.pbDisplayPaused("Before: [#{@lastMoveUsedSketch},#{@lastMoveUsed}]")
  3348. PBDebug.log("#{pbThis} used #{choice[2].name}")
  3349. PBDebug.logonerr{
  3350. pbUseMove(choice,choice[2]==@battle.struggle)
  3351. }
  3352. # @battle.pbDisplayPaused("After: [#{@lastMoveUsedSketch},#{@lastMoveUsed}]")
  3353. return true
  3354. end
  3355. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement