Advertisement
Nyaruko69

Untitled

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