Advertisement
Sir_Tman

Sir Tman's pb switch

Sep 17th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.10 KB | None | 0 0
  1. ################################################################################
  2. # Switching Pokémon.
  3. ################################################################################
  4. def pbCanSwitchLax?(idxPokemon,pkmnidxTo,showMessages)
  5. if pkmnidxTo>=0
  6. party=pbParty(idxPokemon)
  7. if pkmnidxTo>=party.length
  8. return false
  9. end
  10. if !party[pkmnidxTo]
  11. return false
  12. end
  13. if party[pkmnidxTo].isEgg?
  14. pbDisplayPaused(_INTL("An Egg can't battle!")) if showMessages
  15. return false
  16. end
  17. if !pbIsOwner?(idxPokemon,pkmnidxTo)
  18. owner=pbPartyGetOwner(idxPokemon,pkmnidxTo)
  19. pbDisplayPaused(_INTL("You can't switch {1}'s Pokémon with one of yours!",owner.name)) if showMessages
  20. return false
  21. end
  22. if party[pkmnidxTo].hp<=0
  23. pbDisplayPaused(_INTL("{1} has no energy left to battle!",party[pkmnidxTo].name)) if showMessages
  24. return false
  25. end
  26. if @battlers[idxPokemon].pokemonIndex==pkmnidxTo ||
  27. @battlers[idxPokemon].pbPartner.pokemonIndex==pkmnidxTo
  28. pbDisplayPaused(_INTL("{1} is already in battle!",party[pkmnidxTo].name)) if showMessages
  29. return false
  30. end
  31. if @skybattle && !pbCanSkyBattle?(party[pkmnidxTo])
  32. pbDisplayPaused(_INTL("{1} can't fight in a sky battle!",party[pkmnidxTo].name)) if showMessages
  33. return false
  34. end
  35. end
  36. return true
  37. end
  38.  
  39. def pbCanSwitch?(idxPokemon,pkmnidxTo,showMessages)
  40. thispkmn=@battlers[idxPokemon]
  41. # Multi-Turn Attacks/Mean Look
  42. if !pbCanSwitchLax?(idxPokemon,pkmnidxTo,showMessages)
  43. return false
  44. end
  45. isOpposing=pbIsOpposing?(idxPokemon)
  46. party=pbParty(idxPokemon)
  47. for i in 0...4
  48. next if isOpposing!=pbIsOpposing?(i)
  49. if choices[i][0]==2 && choices[i][1]==pkmnidxTo
  50. pbDisplayPaused(_INTL("{1} has already been selected.",party[pkmnidxTo].name)) if showMessages
  51. return false
  52. end
  53. end
  54. if thispkmn.hasWorkingItem(:SHEDSHELL)
  55. return true
  56. end
  57. if thispkmn.effects[PBEffects::MultiTurn]>0 ||
  58. thispkmn.effects[PBEffects::MeanLook]>=0
  59. pbDisplayPaused(_INTL("{1} can't be switched out!",thispkmn.pbThis)) if showMessages
  60. return false
  61. end
  62. # Ingrain
  63. if thispkmn.effects[PBEffects::Ingrain]
  64. pbDisplayPaused(_INTL("{1} can't be switched out!",thispkmn.pbThis)) if showMessages
  65. return false
  66. end
  67. opp1=thispkmn.pbOpposing1
  68. opp2=thispkmn.pbOpposing2
  69. opp=nil
  70. if thispkmn.pbHasType?(:STEEL)
  71. opp=opp1 if opp1.hasWorkingAbility(:MAGNETPULL)
  72. opp=opp2 if opp2.hasWorkingAbility(:MAGNETPULL)
  73. end
  74. if !thispkmn.isAirborne?
  75. opp=opp1 if (opp1.hasWorkingAbility(:ARENATRAP) && !(thispkmn.pbHasType?(:GHOST)))
  76. opp=opp2 if (opp2.hasWorkingAbility(:ARENATRAP) && !(thispkmn.pbHasType?(:GHOST)))
  77. end
  78. if !thispkmn.hasWorkingAbility(:SHADOWTAG)
  79. opp=opp1 if (opp1.hasWorkingAbility(:SHADOWTAG) && !(thispkmn.pbHasType?(:GHOST)))
  80. opp=opp2 if (opp2.hasWorkingAbility(:SHADOWTAG) && !(thispkmn.pbHasType?(:GHOST)))
  81. end
  82. if opp
  83. #pbDisplayEffect(opp)
  84. abilityname=PBAbilities.getName(opp.ability)
  85. if EFFECTMESSAGES
  86. pbDisplayPaused(_INTL("{1} can't be switched out!",thispkmn.pbThis))
  87. else
  88. pbDisplayPaused(_INTL("{1}'s {2} prevents switching!",opp.pbThis,abilityname)) if showMessages
  89. end
  90. return false
  91. end
  92. return true
  93. end
  94.  
  95. def pbRegisterSwitch(idxPokemon,idxOther)
  96. return false if !pbCanSwitch?(idxPokemon,idxOther,false)
  97. @choices[idxPokemon][0]=2 # "Switch Pokémon"
  98. @choices[idxPokemon][1]=idxOther # Index of other Pokémon to switch with
  99. @choices[idxPokemon][2]=nil
  100. side=(pbIsOpposing?(idxPokemon)) ? 1 : 0
  101. owner=pbGetOwnerIndex(idxPokemon)
  102. if @megaEvolution[side][owner]==idxPokemon
  103. @megaEvolution[side][owner]=-1
  104. end
  105. return true
  106. end
  107.  
  108. def pbCanChooseNonActive?(index)
  109. party=pbParty(index)
  110. for i in 0..party.length-1
  111. return true if pbCanSwitchLax?(index,i,false)
  112. end
  113. return false
  114. end
  115.  
  116. def pbSwitch(favorDraws=false)
  117. if !favorDraws
  118. return if @decision>0
  119. pbJudge()
  120. return if @decision>0
  121. else
  122. return if @decision==5
  123. pbJudge()
  124. return if @decision>0
  125. end
  126. firstbattlerhp=@battlers[0].hp
  127. switched=[]
  128. for index in 0...4
  129. next if !@doublebattle && pbIsDoubleBattler?(index)
  130. next if @battlers[index] && !@battlers[index].isFainted?
  131. next if !pbCanChooseNonActive?(index)
  132. if !pbOwnedByPlayer?(index)
  133. if !pbIsOpposing?(index) || (@opponent && pbIsOpposing?(index))
  134. newenemy=pbSwitchInBetween(index,false,false)
  135. if pbIsOpposing?(index) #Temp Edit
  136. if isConst?(@party2[newenemy].f,PBAbilities,:ILLUSION) #ILLUSION
  137. party3=@party2.find_all {|item| item && !item.egg? && item.hp>0 }
  138. if party3[@party2.length-1] != @party2[newenemy]
  139. illusionpoke = party3[party3.length-1]
  140. end
  141. end #ILLUSION
  142. newname = illusionpoke != nil ? illusionpoke.name : @party2[newenemy].name #ILLUSION
  143. end #Temp Edit
  144. opponent=pbGetOwner(index)
  145. if !@doublebattle && firstbattlerhp>0 && @shiftStyle && @opponent &&
  146. @internalbattle && pbCanChooseNonActive?(0) && pbIsOpposing?(index) &&
  147. @battlers[0].effects[PBEffects::Outrage]==0
  148. pbDisplayPaused(_INTL("{1} is about to send in {2}.",opponent.fullname,newname)) #ILLUSION
  149. if pbDisplayConfirm(_INTL("Will you switch your Pokémon?"))
  150. newpoke=pbSwitchPlayer(0,true,true)
  151. if newpoke>=0
  152. pbDisplayBrief(_INTL("{1}, switch out! Come back!",@battlers[0].name))
  153. pbRecallAndReplace(0,newpoke)
  154. switched.push(0)
  155. end
  156. end
  157. end
  158. pbRecallAndReplace(index,newenemy)
  159. switched.push(index)
  160. end
  161. elsif @opponent
  162. newpoke=pbSwitchInBetween(index,true,false)
  163. pbRecallAndReplace(index,newpoke)
  164. switched.push(index)
  165. else
  166. switch=false
  167. if !pbDisplayConfirm(_INTL("Use next Pokémon?"))
  168. switch=(pbRun(index,true)<=0)
  169. else
  170. switch=true
  171. end
  172. if switch
  173. newpoke=pbSwitchInBetween(index,true,false)
  174. pbRecallAndReplace(index,newpoke)
  175. switched.push(index)
  176. end
  177. end
  178. end
  179. if switched.length>0
  180. priority=pbPriority
  181. for i in priority
  182. i.pbAbilitiesOnSwitchIn(true) if switched.include?(i.index)
  183. end
  184. end
  185. end
  186.  
  187. def pbSendOut(index,pokemon)
  188. pbSetSeen(pokemon)
  189. @peer.pbOnEnteringBattle(self,pokemon)
  190. if pbIsOpposing?(index)
  191. @scene.pbTrainerSendOut(index,pokemon)
  192. else
  193. @scene.pbSendOut(index,pokemon)
  194. end
  195. @scene.pbResetMoveIndex(index)
  196. # Primal Reversion
  197. pbPrimalReversion(index)
  198. end
  199.  
  200. def pbReplace(index,newpoke,batonpass=false)
  201. party=pbParty(index)
  202. if pbOwnedByPlayer?(index)
  203. # Reorder the party for this battle
  204. bpo=-1; bpn=-1
  205. for i in 0...6
  206. bpo=i if @partyorder[i]==@battlers[index].pokemonIndex
  207. bpn=i if @partyorder[i]==newpoke
  208. end
  209. poke1=@partyorder[bpo]
  210. @partyorder[bpo]=@partyorder[bpn]
  211. @partyorder[bpn]=poke1
  212. @battlers[index].pbInitialize(party[newpoke],newpoke,batonpass)
  213. pbSendOut(index,party[newpoke])
  214. else
  215. @battlers[index].pbInitialize(party[newpoke],newpoke,batonpass)
  216. pbSetSeen(party[newpoke])
  217. if pbIsOpposing?(index)
  218. pbSendOut(index,party[newpoke])
  219. else
  220. pbSendOut(index,party[newpoke])
  221. end
  222. end
  223. if @weather==PBWeather::DELTASTREAM && !pbCheckGlobalAbility(:DELTASTREAM)
  224. @weather=0
  225. pbDisplayBrief("The air current faded.")
  226. elsif @weather==PBWeather::PRIMORDIALSEA && !pbCheckGlobalAbility(:PRIMORDIALSEA)
  227. @weather=0
  228. pbDisplayBrief("The heavy rain relented.")
  229. elsif @weather==PBWeather::DESOLATELAND && !pbCheckGlobalAbility(:DESOLATELAND)
  230. @weather=0
  231. pbDisplayBrief("The harsh sunlight faded.")
  232. end
  233. end
  234.  
  235. def pbRecallAndReplace(index,newpoke,batonpass=false)
  236. @battlers[index].pbResetForm
  237. if !@battlers[index].isFainted?
  238. @scene.pbRecall(index)
  239. end
  240. pbMessagesOnReplace(index,newpoke)
  241. pbReplace(index,newpoke,batonpass)
  242. return pbOnActiveOne(@battlers[index])
  243. end
  244.  
  245. def pbMessagesOnReplace(index,newpoke)
  246. party=pbParty(index)
  247. if pbOwnedByPlayer?(index)
  248. # if !party[newpoke]
  249. # p [index,newpoke,party[newpoke],pbAllFainted?(party)]
  250. # PBDebug.log([index,newpoke,party[newpoke],"pbMOR"].inspect)
  251. # for i in 0...party.length
  252. # PBDebug.log([i,party[i].hp].inspect)
  253. # end
  254. # raise BattleAbortedException.new
  255. # end
  256. if isConst?(party[newpoke].ability,PBAbilities,:ILLUSION) #ILLUSION
  257. party2=party.find_all {|item| item && !item.egg? && item.hp>0 }
  258. if party2[party.length-1] != party[newpoke]
  259. illusionpoke = party[party.length-1]
  260. end
  261. end #ILLUSION
  262. newname = illusionpoke != nil ? illusionpoke.name : party[newpoke].name
  263. opposing=@battlers[index].pbOppositeOpposing
  264. if opposing.hp<=0 || opposing.hp==opposing.totalhp
  265. pbDisplayBrief(_INTL("Go! {1}!",newname))
  266. elsif opposing.hp>=(opposing.totalhp/2)
  267. pbDisplayBrief(_INTL("Do it! {1}!",newname))
  268. elsif opposing.hp>=(opposing.totalhp/4)
  269. pbDisplayBrief(_INTL("Go for it, {1}!",newname))
  270. else
  271. pbDisplayBrief(_INTL("Your foe's weak!\nGet 'em, {1}!",newname))
  272. end
  273. PBDebug.log("[Player sent out #{party[newpoke].name}]")
  274. else
  275. # if !party[newpoke]
  276. # p [index,newpoke,party[newpoke],pbAllFainted?(party)]
  277. # PBDebug.log([index,newpoke,party[newpoke],"pbMOR"].inspect)
  278. # for i in 0...party.length
  279. # PBDebug.log([i,party[i].hp].inspect)
  280. # end
  281. # raise BattleAbortedException.new
  282. # end
  283. if isConst?(party[newpoke].ability,PBAbilities,:ILLUSION) #ILLUSION
  284. party2=party.find_all {|item| item && !item.egg? && item.hp>0 }
  285. if party2[party.length-1] != party[newpoke]
  286. illusionpoke = party[party.length-1]
  287. end
  288. end #ILLUSION
  289. newname = illusionpoke != nil ? illusionpoke.name : party[newpoke].name #ILLUSION
  290. owner=pbGetOwner(index)
  291. pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",owner.fullname,newname)) #ILLUSION
  292. PBDebug.log("[Opponent sent out #{party[newpoke].name}]")
  293. end
  294. end
  295.  
  296. def pbSwitchInBetween(index,lax,cancancel)
  297. if !pbOwnedByPlayer?(index)
  298. return @scene.pbChooseNewEnemy(index,pbParty(index))
  299. else
  300. return pbSwitchPlayer(index,lax,cancancel)
  301. end
  302. end
  303.  
  304. def pbSwitchPlayer(index,lax,cancancel)
  305. if @debug
  306. return @scene.pbChooseNewEnemy(index,pbParty(index))
  307. else
  308. return @scene.pbSwitch(index,lax,cancancel)
  309. end
  310. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement