Nyaruko69

Untitled

Nov 6th, 2020
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.56 KB | None | 0 0
  1. #-------------------------------------------------------------------------------#
  2. #-------------------------------------------------------------------------------#
  3. # Script : Repartir Exp 5.5 #
  4. # Selfish - Público #
  5. # Remember to give Credits! #
  6. #-------------------------------------------------------------------------------#
  7. #-------------------------------------------------------------------------------#
  8. # Creado para RPG Maker XP con base Essentials #
  9. # Compatible : versión 16.2 #
  10. #-------------------------------------------------------------------------------#
  11. #-------------------------------------------------------------------------------#
  12.  
  13. class PokeBattle_Trainer
  14. attr_accessor(:expall) # Mejora el Repartir experiencia
  15. end
  16.  
  17. class PokeBattle_Pokemon
  18. attr_accessor(:expshare) # Repartir experiencia
  19. end
  20.  
  21.  
  22. class PokemonPartyPanel < SpriteWrapper
  23.  
  24. alias initialize_old initialize
  25. def initialize(pokemon,index,viewport=nil)
  26. initialize_old(pokemon,index,viewport)
  27. @expiconXOffset=227
  28. @expiconYOffset=68
  29. @expicon = Sprite.new(viewport)
  30. @expicon.bitmap = Bitmap.new("Graphics/Pictures/expicon")
  31. @expicon.z=self.z+3 # For compatibility with RGSS2
  32. end
  33.  
  34. alias refresh_old refresh
  35. def refresh
  36. refresh_old
  37. if @expicon && [email protected]?
  38. @expicon.visible=(@pokemon.expshare)
  39. if @expicon.visible
  40. @expicon.x=self.x+@expiconXOffset
  41. @expicon.y=self.y+@expiconYOffset
  42. @expicon.color=self.color
  43. end
  44. end
  45. end
  46. end
  47. class PokemonPartyScreen
  48. def pbPokemonScreen
  49. @scene.pbStartScene(@party,@party.length>1 ? _INTL("Elige un Pokémon.") : _INTL("Elige un Pokémon o cancela."),nil)
  50. loop do
  51. @scene.pbSetHelpText(@party.length>1 ? _INTL("Elige un Pokémon.") : _INTL("Elige un Pokémon o cancela."))
  52. break if pkmnid<0
  53. pkmn=@party[pkmnid]
  54. commands = []
  55. cmdSummary = -1
  56. cmdDebug = -1
  57. cmdExpShare= -1
  58. cmdMoves = [-1,-1,-1,-1]
  59. cmdSwitch = -1
  60. cmdMail = -1
  61. cmdItem = -1
  62. # Build the commands
  63. commands[cmdSummary=commands.length] = _INTL("Datos")
  64. commands[cmdExpShare = commands.length] = _INTL("Repartir Exp") if (hasConst?(PBItems,:EXPSHARE2) && $PokemonBag.pbQuantity(:EXPSHARE2)>0)
  65. commands[cmdDebug=commands.length] = _INTL("Depurador") if $DEBUG
  66. for i in 0...pkmn.moves.length
  67. move=pkmn.moves[i]
  68. # Check for hidden moves and add any that were found
  69. if !pkmn.isEgg? && (isConst?(move.id,PBMoves,:MILKDRINK) ||
  70. isConst?(move.id,PBMoves,:SOFTBOILED) ||
  71. HiddenMoveHandlers.hasHandler(move.id))
  72. commands[cmdMoves[i]=commands.length] = PBMoves.getName(move.id)
  73. end
  74. end
  75. commands[cmdSwitch=commands.length] = _INTL("Mover") if @party.length>1
  76. if !pkmn.isEgg?
  77. if pkmn.mail
  78. commands[cmdMail=commands.length] = _INTL("Carta")
  79. else
  80. commands[cmdItem=commands.length] = _INTL("Objeto")
  81. end
  82. end
  83. commands[commands.length] = _INTL("Salir")
  84. [email protected](_INTL("¿Qué hacer con {1}?",pkmn.name),commands)
  85. havecommand=false
  86. for i in 0...4
  87. if cmdMoves[i]>=0 && command==cmdMoves[i]
  88. havecommand=true
  89. if isConst?(pkmn.moves[i].id,PBMoves,:SOFTBOILED) ||
  90. isConst?(pkmn.moves[i].id,PBMoves,:MILKDRINK)
  91. amt=[(pkmn.totalhp/5).floor,1].max
  92. if pkmn.hp<=amt
  93. pbDisplay(_INTL("No tiene PS suficientes..."))
  94. break
  95. end
  96. @scene.pbSetHelpText(_INTL("¿En cuál Pokémon usarlo?"))
  97. oldpkmnid=pkmnid
  98. loop do
  99. @scene.pbPreSelect(oldpkmnid)
  100. [email protected](true,pkmnid)
  101. break if pkmnid<0
  102. newpkmn=@party[pkmnid]
  103. if pkmnid==oldpkmnid
  104. pbDisplay(_INTL("¡{1} no puede usar {2} en sí mismo!",pkmn.name,PBMoves.getName(pkmn.moves[i].id)))
  105. elsif newpkmn.isEgg?
  106. pbDisplay(_INTL("¡{1} no puede usarse en un Huevo!",PBMoves.getName(pkmn.moves[i].id)))
  107. elsif newpkmn.hp==0 || newpkmn.hp==newpkmn.totalhp
  108. pbDisplay(_INTL("{1} no puede usarse en ese Pokémon.",PBMoves.getName(pkmn.moves[i].id)))
  109. else
  110. pkmn.hp-=amt
  111. hpgain=pbItemRestoreHP(newpkmn,amt)
  112. @scene.pbDisplay(_INTL("{1} recuperó {2} puntos de salud.",newpkmn.name,hpgain))
  113. pbRefresh
  114. end
  115. break if pkmn.hp<=amt
  116. end
  117. break
  118. elsif Kernel.pbCanUseHiddenMove?(pkmn,pkmn.moves[i].id)
  119. @scene.pbEndScene
  120. if isConst?(pkmn.moves[i].id,PBMoves,:FLY)
  121. scene=PokemonRegionMapScene.new(-1,false)
  122. screen=PokemonRegionMap.new(scene)
  123. ret=screen.pbStartFlyScreen
  124. if ret
  125. $PokemonTemp.flydata=ret
  126. return [pkmn,pkmn.moves[i].id]
  127. end
  128. @scene.pbStartScene(@party,
  129. @party.length>1 ? _INTL("Elige un Pokémon.") : _INTL("Elige un Pokémon o cancela."))
  130. break
  131. end
  132. return [pkmn,pkmn.moves[i].id]
  133. else
  134. break
  135. end
  136. end
  137. end
  138. next if havecommand
  139. if cmdSummary>=0 && command==cmdSummary
  140. @scene.pbSummary(pkmnid)
  141. elsif cmdDebug>=0 && command==cmdDebug
  142. pbPokemonDebug(pkmn,pkmnid)
  143. elsif cmdExpShare>=0 && command==cmdExpShare
  144. if pkmn.expshare
  145. if pbConfirm(_INTL("¿Quieres desactivar el Repartir Experiencia en este Pokémon?"))
  146. pkmn.expshare=false
  147. end
  148. else
  149. if pbConfirm(_INTL("¿Quieres activar el Repartir Experiencia en este Pokémon?"))
  150. pkmn.expshare=true
  151. end
  152. end
  153. elsif cmdSwitch>=0 && command==cmdSwitch
  154. @scene.pbSetHelpText(_INTL("¿A qué posición mover?"))
  155. oldpkmnid=pkmnid
  156. if pkmnid>=0 && pkmnid!=oldpkmnid
  157. pbSwitch(oldpkmnid,pkmnid)
  158. end
  159. elsif cmdMail>=0 && command==cmdMail
  160. [email protected](_INTL("¿Qué quieres hacer con la carta?"),
  161. [_INTL("Leer"),_INTL("Quitar"),_INTL("Salir")])
  162. case command
  163. when 0 # Read
  164. pbFadeOutIn(99999){
  165. pbDisplayMail(pkmn.mail,pkmn)
  166. }
  167. when 1 # Take
  168. pbTakeMail(pkmn)
  169. pbRefreshSingle(pkmnid)
  170. end
  171. elsif cmdItem>=0 && command==cmdItem
  172. itemcommands = []
  173. cmdUseItem = -1
  174. cmdGiveItem = -1
  175. cmdTakeItem = -1
  176. cmdMoveItem = -1
  177. # Build the commands
  178. itemcommands[cmdUseItem=itemcommands.length] = _INTL("Usar")
  179. itemcommands[cmdGiveItem=itemcommands.length] = _INTL("Dar")
  180. itemcommands[cmdTakeItem=itemcommands.length] = _INTL("Quitar") if pkmn.hasItem?
  181. itemcommands[cmdMoveItem=itemcommands.length] = _INTL("Mover") if pkmn.hasItem? && !pbIsMail?(pkmn.item)
  182. itemcommands[itemcommands.length] = _INTL("Salir")
  183. [email protected](_INTL("¿Qué quieres hacer con él?"),itemcommands)
  184. if cmdUseItem>=0 && command==cmdUseItem # Use
  185. [email protected]($PokemonBag,pkmn)
  186. if item>0
  187. pbUseItemOnPokemon(item,pkmn,self)
  188. pbRefreshSingle(pkmnid)
  189. end
  190. elsif cmdGiveItem>=0 && command==cmdGiveItem # Give
  191. [email protected]($PokemonBag)
  192. if item>0
  193. pbGiveMail(item,pkmn,pkmnid)
  194. pbRefreshSingle(pkmnid)
  195. end
  196. elsif cmdTakeItem>=0 && command==cmdTakeItem # Take
  197. pbTakeMail(pkmn)
  198. pbRefreshSingle(pkmnid)
  199. elsif cmdMoveItem>=0 && command==cmdMoveItem # Move
  200. item=pkmn.item
  201. itemname=PBItems.getName(item)
  202. @scene.pbSetHelpText(_INTL("¿A qué Pokémon quieres darle {1}?",itemname))
  203. oldpkmnid=pkmnid
  204. loop do
  205. @scene.pbPreSelect(oldpkmnid)
  206. [email protected](true,pkmnid)
  207. break if pkmnid<0
  208. newpkmn=@party[pkmnid]
  209. if pkmnid==oldpkmnid
  210. break
  211. elsif newpkmn.isEgg?
  212. pbDisplay(_INTL("Un Huevo no puede llevar un objeto."))
  213. elsif !newpkmn.hasItem?
  214. newpkmn.setItem(item)
  215. pkmn.setItem(0)
  216. pbRefresh
  217. pbDisplay(_INTL("Le has dado {2} a {1}.",newpkmn.name,itemname))
  218. break
  219. elsif pbIsMail?(newpkmn.item)
  220. pbDisplay(_INTL("Debes tomar la carta de {1} antes de darle otro objeto.",newpkmn.name))
  221. else
  222. newitem=newpkmn.item
  223. newitemname=PBItems.getName(newitem)
  224. pbDisplay(_INTL("{1} ya está llevando {2}.\1",newpkmn.name,newitemname))
  225. if pbConfirm(_INTL("¿Quieres intercambiar estos objetos?"))
  226. newpkmn.setItem(item)
  227. pkmn.setItem(newitem)
  228. pbRefresh
  229. pbDisplay(_INTL("Le has dado {2} a {1}.",newpkmn.name,itemname))
  230. pbDisplay(_INTL("Le has dado {2} a {1}.",pkmn.name,newitemname))
  231. break
  232. end
  233. end
  234. end
  235. end
  236. end
  237. end
  238. @scene.pbEndScene
  239. return nil
  240. end
  241. end
  242.  
  243. class PokeBattle_Battle
  244.  
  245. def pbGainEXP
  246. return if !@internalbattle
  247. successbegin=true
  248. @finalMessage=false
  249. for i in 0...4 # Not ordered by priority
  250. if !@doublebattle && pbIsDoubleBattler?(i)
  251. @battlers[i].participants=[]
  252. next
  253. end
  254. if pbIsOpposing?(i) && @battlers[i].participants.length>0 &&
  255. (@battlers[i].isFainted? || @battlers[i].captured)
  256. haveexpall=$Trainer.expall
  257. # First count the number of participants
  258. partic=0
  259. expshare=0
  260. for j in @battlers[i].participants
  261. next if !@party1[j] || !pbIsOwner?(0,j)
  262. partic+=1 if @party1[j].hp>0 && !@party1[j].isEgg?
  263. end
  264. if !haveexpall
  265. next if !@party1[j] || !pbIsOwner?(0,j)
  266. expshare+=1 if @party1[j].hp>0 && !@party1[j].isEgg? &&
  267. (isConst?(@party1[j].item,PBItems,:EXPSHARE) ||
  268. isConst?(@party1[j].itemInitial,PBItems,:EXPSHARE))
  269. partic+=1 if @party1[j].hp>0 && !@party1[j].isEgg? &&
  270. @party1[j].expshare && @party1[j] &&
  271. !@battlers[i].participants.include?(j)
  272. end
  273. end
  274. # Now calculate EXP for the participants
  275. if partic>0 || expshare>0 || haveexpall
  276. if !@opponent && successbegin && pbAllFainted?(@party2)
  277. @scene.pbWildBattleSuccess
  278. successbegin=false
  279. end
  280. next if !@party1[j] || !pbIsOwner?(0,j)
  281. next if @party1[j].hp<=0 || @party1[j].isEgg?
  282. haveexpshare=(isConst?(@party1[j].item,PBItems,:EXPSHARE) ||
  283. isConst?(@party1[j].itemInitial,PBItems,:EXPSHARE))
  284. next if !haveexpshare && !@battlers[i].participants.include?(j)&& !@party1[j].expshare
  285. pbGainExpOne(j,@battlers[i],partic,expshare,haveexpall)
  286. end
  287. if haveexpall
  288. showmessage=true
  289. next if !@party1[j] || !pbIsOwner?(0,j)
  290. next if @party1[j].hp<=0 || @party1[j].isEgg?
  291. next if isConst?(@party1[j].item,PBItems,:EXPSHARE) ||
  292. isConst?(@party1[j].itemInitial,PBItems,:EXPSHARE)
  293. next if @battlers[i].participants.include?(j)
  294. next if !(@party1[j].expshare)
  295. pbDisplayPaused(_INTL("¡Tus otros Pokémon también han ganado Puntos de Experiencia gracias al Repartir Experiencia!")) if showmessage
  296. showmessage=false
  297. pbGainExpOne(j,@battlers[i],partic,expshare,haveexpall,false)
  298. end
  299. elsif @finalMessage
  300. pbDisplayPaused(_INTL("¡Tus otros Pokémon también han ganado Puntos de Experiencia gracias al Repartir Experiencia!"))
  301. end
  302. end
  303. # Now clear the participants array
  304. @battlers[i].participants=[]
  305. end
  306. end
  307. end
  308.  
  309. def pbGainExpOne(index,defeated,partic,expshare,haveexpall,showmessages=true)
  310. thispoke=@party1[index]
  311. # Original species, not current species
  312. level=defeated.level
  313. baseexp=defeated.pokemon.baseExp
  314. evyield=defeated.pokemon.evYield
  315. # Gain effort value points, using RS effort values
  316. totalev=0
  317. for k in 0...6
  318. totalev+=thispoke.ev[k]
  319. end
  320. for k in 0...6
  321. evgain=evyield[k]
  322. evgain*=2 if isConst?(thispoke.item,PBItems,:MACHOBRACE) ||
  323. isConst?(thispoke.itemInitial,PBItems,:MACHOBRACE)
  324. case k
  325. when PBStats::HP
  326. evgain+=4 if isConst?(thispoke.item,PBItems,:POWERWEIGHT) ||
  327. isConst?(thispoke.itemInitial,PBItems,:POWERWEIGHT)
  328. when PBStats::ATTACK
  329. evgain+=4 if isConst?(thispoke.item,PBItems,:POWERBRACER) ||
  330. isConst?(thispoke.itemInitial,PBItems,:POWERBRACER)
  331. when PBStats::DEFENSE
  332. evgain+=4 if isConst?(thispoke.item,PBItems,:POWERBELT) ||
  333. isConst?(thispoke.itemInitial,PBItems,:POWERBELT)
  334. when PBStats::SPATK
  335. evgain+=4 if isConst?(thispoke.item,PBItems,:POWERLENS) ||
  336. isConst?(thispoke.itemInitial,PBItems,:POWERLENS)
  337. when PBStats::SPDEF
  338. evgain+=4 if isConst?(thispoke.item,PBItems,:POWERBAND) ||
  339. isConst?(thispoke.itemInitial,PBItems,:POWERBAND)
  340. when PBStats::SPEED
  341. evgain+=4 if isConst?(thispoke.item,PBItems,:POWERANKLET) ||
  342. isConst?(thispoke.itemInitial,PBItems,:POWERANKLET)
  343. end
  344. evgain*=2 if thispoke.pokerusStage>=1 # Infected or cured
  345. if evgain>0
  346. # Can't exceed overall limit
  347. evgain-=totalev+evgain-PokeBattle_Pokemon::EVLIMIT if totalev+evgain>PokeBattle_Pokemon::EVLIMIT
  348. # Can't exceed stat limit
  349. evgain-=thispoke.ev[k]+evgain-PokeBattle_Pokemon::EVSTATLIMIT if thispoke.ev[k]+evgain>PokeBattle_Pokemon::EVSTATLIMIT
  350. # Add EV gain
  351. thispoke.ev[k]+=evgain
  352. if thispoke.ev[k]>PokeBattle_Pokemon::EVSTATLIMIT
  353. print "Single-stat EV limit #{PokeBattle_Pokemon::EVSTATLIMIT} exceeded.\r\nStat: #{k} EV gain: #{evgain} EVs: #{thispoke.ev.inspect}"
  354. thispoke.ev[k]=PokeBattle_Pokemon::EVSTATLIMIT
  355. end
  356. totalev+=evgain
  357. if totalev>PokeBattle_Pokemon::EVLIMIT
  358. print "EV limit #{PokeBattle_Pokemon::EVLIMIT} exceeded.\r\nTotal EVs: #{totalev} EV gain: #{evgain} EVs: #{thispoke.ev.inspect}"
  359. end
  360. end
  361. end
  362. # Gain experience
  363. @finalMessage = true if !(defeated.participants.include?(index)) && thispoke.expshare
  364. ispartic=0
  365. ispartic=1 if defeated.participants.include?(index) || thispoke.expshare
  366. haveexpshare=(isConst?(thispoke.item,PBItems,:EXPSHARE) ||
  367. isConst?(thispoke.itemInitial,PBItems,:EXPSHARE)) ? 1 : 0
  368. exp=0
  369. if expshare>0
  370. if partic==0 # No participants, all Exp goes to Exp Share holders
  371. exp=(level*baseexp).floor
  372. exp=(exp/(NOSPLITEXP ? 1 : expshare)).floor*haveexpshare
  373. else
  374. if NOSPLITEXP
  375. exp=(level*baseexp).floor*ispartic
  376. exp=(level*baseexp/2).floor*haveexpshare if ispartic==0
  377. else
  378. exp=(level*baseexp/2).floor
  379. exp=(exp/partic).floor*ispartic + (exp/expshare).floor*haveexpshare
  380. end
  381. end
  382. elsif ispartic==1
  383. exp=(level*baseexp/(NOSPLITEXP ? 1 : partic)).floor
  384. elsif haveexpall
  385. exp=(level*baseexp/2).floor
  386. end
  387. return if exp<=0
  388. exp=(exp*3/2).floor if @opponent
  389. if USESCALEDEXPFORMULA
  390. exp=(exp/5).floor
  391. leveladjust=(2*level+10.0)/(level+thispoke.level+10.0)
  392. leveladjust=leveladjust**5
  393. leveladjust=Math.sqrt(leveladjust)
  394. exp=(exp*leveladjust).floor
  395. exp+=1 if ispartic>0 || haveexpshare>0
  396. else
  397. exp=(exp/7).floor
  398. end
  399. isOutsider=(thispoke.trainerID!=self.pbPlayer.id ||
  400. (thispoke.language!=0 && thispoke.language!=self.pbPlayer.language))
  401. if isOutsider
  402. if thispoke.language!=0 && thispoke.language!=self.pbPlayer.language
  403. exp=(exp*1.7).floor
  404. else
  405. exp=(exp*3/2).floor
  406. end
  407. end
  408. exp=(exp*3/2).floor if isConst?(thispoke.item,PBItems,:LUCKYEGG) ||
  409. isConst?(thispoke.itemInitial,PBItems,:LUCKYEGG)
  410. exp=(exp*1.1).floor if $expboost
  411. growthrate=thispoke.growthrate
  412. newexp=PBExperience.pbAddExperience(thispoke.exp,exp,growthrate)
  413. exp=newexp-thispoke.exp
  414. if exp>0
  415. if showmessages
  416. if isOutsider
  417. pbDisplayPaused(_INTL("¡{1} ha ganado un total de {2} Puntos de Experiencia!",thispoke.name,exp)) if defeated.participants.include?(index)
  418. else
  419. pbDisplayPaused(_INTL("¡{1} ha ganado {2} Puntos de Experiencia!",thispoke.name,exp)) if defeated.participants.include?(index)
  420. end
  421. end
  422. newlevel=PBExperience.pbGetLevelFromExperience(newexp,growthrate)
  423. tempexp=0
  424. curlevel=thispoke.level
  425. if newlevel<curlevel
  426. debuginfo="#{thispoke.name}: #{thispoke.level}/#{newlevel} | #{thispoke.exp}/#{newexp} | gain: #{exp}"
  427. raise RuntimeError.new(_INTL("El nivel nuevo ({1}) es menor que el nivel actual\r\ndel Pokémon ({2}), lo que no debería pasar.\r\n[Depurar: {3}]",
  428. newlevel,curlevel,debuginfo))
  429. return
  430. end
  431. if thispoke.respond_to?("isShadow?") && thispoke.isShadow?
  432. thispoke.exp+=exp
  433. else
  434. tempexp1=thispoke.exp
  435. tempexp2=0
  436. # Find battler
  437. battler=pbFindPlayerBattler(index)
  438. loop do
  439. # EXP Bar animation
  440. startexp=PBExperience.pbGetStartExperience(curlevel,growthrate)
  441. endexp=PBExperience.pbGetStartExperience(curlevel+1,growthrate)
  442. tempexp2=(endexp<newexp) ? endexp : newexp
  443. thispoke.exp=tempexp2
  444. @scene.pbEXPBar(thispoke,battler,startexp,endexp,tempexp1,tempexp2)
  445. tempexp1=tempexp2
  446. curlevel+=1
  447. if curlevel>newlevel
  448. thispoke.calcStats
  449. battler.pbUpdate(false) if battler
  450. @scene.pbRefresh
  451. break
  452. end
  453. oldtotalhp=thispoke.totalhp
  454. oldattack=thispoke.attack
  455. olddefense=thispoke.defense
  456. oldspeed=thispoke.speed
  457. oldspatk=thispoke.spatk
  458. oldspdef=thispoke.spdef
  459. if battler && battler.pokemon && @internalbattle
  460. battler.pokemon.changeHappiness("level up")
  461. end
  462. thispoke.calcStats
  463. battler.pbUpdate(false) if battler
  464. @scene.pbRefresh
  465. pbDisplayPaused(_INTL("¡{1} subió al nivel {2}!",thispoke.name,curlevel))
  466. @scene.pbLevelUp(thispoke,battler,oldtotalhp,oldattack,
  467. olddefense,oldspeed,oldspatk,oldspdef)
  468. # Determina todos los movimientos aprendidos a este nivel
  469. movelist=thispoke.getMoveList
  470. for k in movelist
  471. if k[0]==thispoke.level # Aprendió un movimiento nuevo
  472. pbLearnMove(index,k[1])
  473. end
  474. end
  475. end
  476. end
  477. end
  478. end
  479. end
Advertisement
Add Comment
Please, Sign In to add comment