Advertisement
M3rein

PokeBattle_Battler stock

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