Advertisement
Guest User

Untitled

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