Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-------------------------------------------------------------------------------#
- #-------------------------------------------------------------------------------#
- # Script : Repartir Exp 5.5 #
- # Selfish - Público #
- # Remember to give Credits! #
- #-------------------------------------------------------------------------------#
- #-------------------------------------------------------------------------------#
- # Creado para RPG Maker XP con base Essentials #
- # Compatible : versión 16.2 #
- #-------------------------------------------------------------------------------#
- #-------------------------------------------------------------------------------#
- class PokeBattle_Trainer
- attr_accessor(:expall) # Mejora el Repartir experiencia
- end
- class PokeBattle_Pokemon
- attr_accessor(:expshare) # Repartir experiencia
- end
- class PokemonPartyPanel < SpriteWrapper
- alias initialize_old initialize
- def initialize(pokemon,index,viewport=nil)
- initialize_old(pokemon,index,viewport)
- @expiconXOffset=227
- @expiconYOffset=68
- @expicon = Sprite.new(viewport)
- @expicon.bitmap = Bitmap.new("Graphics/Pictures/expicon")
- @expicon.z=self.z+3 # For compatibility with RGSS2
- end
- alias refresh_old refresh
- def refresh
- refresh_old
- if @expicon && !@expicon.disposed?
- @expicon.visible=(@pokemon.expshare)
- if @expicon.visible
- @expicon.x=self.x+@expiconXOffset
- @expicon.y=self.y+@expiconYOffset
- @expicon.color=self.color
- end
- end
- end
- end
- class PokemonPartyScreen
- def pbPokemonScreen
- @scene.pbStartScene(@party,@party.length>1 ? _INTL("Elige un Pokémon.") : _INTL("Elige un Pokémon o cancela."),nil)
- loop do
- @scene.pbSetHelpText(@party.length>1 ? _INTL("Elige un Pokémon.") : _INTL("Elige un Pokémon o cancela."))
- pkmnid=@scene.pbChoosePokemon
- break if pkmnid<0
- pkmn=@party[pkmnid]
- commands = []
- cmdSummary = -1
- cmdDebug = -1
- cmdExpShare= -1
- cmdMoves = [-1,-1,-1,-1]
- cmdSwitch = -1
- cmdMail = -1
- cmdItem = -1
- # Build the commands
- commands[cmdSummary=commands.length] = _INTL("Datos")
- commands[cmdExpShare = commands.length] = _INTL("Repartir Exp") if (hasConst?(PBItems,:EXPSHARE2) && $PokemonBag.pbQuantity(:EXPSHARE2)>0)
- commands[cmdDebug=commands.length] = _INTL("Depurador") if $DEBUG
- for i in 0...pkmn.moves.length
- move=pkmn.moves[i]
- # Check for hidden moves and add any that were found
- if !pkmn.isEgg? && (isConst?(move.id,PBMoves,:MILKDRINK) ||
- isConst?(move.id,PBMoves,:SOFTBOILED) ||
- HiddenMoveHandlers.hasHandler(move.id))
- commands[cmdMoves[i]=commands.length] = PBMoves.getName(move.id)
- end
- end
- commands[cmdSwitch=commands.length] = _INTL("Mover") if @party.length>1
- if !pkmn.isEgg?
- if pkmn.mail
- commands[cmdMail=commands.length] = _INTL("Carta")
- else
- commands[cmdItem=commands.length] = _INTL("Objeto")
- end
- end
- commands[commands.length] = _INTL("Salir")
- command=@scene.pbShowCommands(_INTL("¿Qué hacer con {1}?",pkmn.name),commands)
- havecommand=false
- for i in 0...4
- if cmdMoves[i]>=0 && command==cmdMoves[i]
- havecommand=true
- if isConst?(pkmn.moves[i].id,PBMoves,:SOFTBOILED) ||
- isConst?(pkmn.moves[i].id,PBMoves,:MILKDRINK)
- amt=[(pkmn.totalhp/5).floor,1].max
- if pkmn.hp<=amt
- pbDisplay(_INTL("No tiene PS suficientes..."))
- break
- end
- @scene.pbSetHelpText(_INTL("¿En cuál Pokémon usarlo?"))
- oldpkmnid=pkmnid
- loop do
- @scene.pbPreSelect(oldpkmnid)
- pkmnid=@scene.pbChoosePokemon(true,pkmnid)
- break if pkmnid<0
- newpkmn=@party[pkmnid]
- if pkmnid==oldpkmnid
- pbDisplay(_INTL("¡{1} no puede usar {2} en sí mismo!",pkmn.name,PBMoves.getName(pkmn.moves[i].id)))
- elsif newpkmn.isEgg?
- pbDisplay(_INTL("¡{1} no puede usarse en un Huevo!",PBMoves.getName(pkmn.moves[i].id)))
- elsif newpkmn.hp==0 || newpkmn.hp==newpkmn.totalhp
- pbDisplay(_INTL("{1} no puede usarse en ese Pokémon.",PBMoves.getName(pkmn.moves[i].id)))
- else
- pkmn.hp-=amt
- hpgain=pbItemRestoreHP(newpkmn,amt)
- @scene.pbDisplay(_INTL("{1} recuperó {2} puntos de salud.",newpkmn.name,hpgain))
- pbRefresh
- end
- break if pkmn.hp<=amt
- end
- break
- elsif Kernel.pbCanUseHiddenMove?(pkmn,pkmn.moves[i].id)
- @scene.pbEndScene
- if isConst?(pkmn.moves[i].id,PBMoves,:FLY)
- scene=PokemonRegionMapScene.new(-1,false)
- screen=PokemonRegionMap.new(scene)
- ret=screen.pbStartFlyScreen
- if ret
- $PokemonTemp.flydata=ret
- return [pkmn,pkmn.moves[i].id]
- end
- @scene.pbStartScene(@party,
- @party.length>1 ? _INTL("Elige un Pokémon.") : _INTL("Elige un Pokémon o cancela."))
- break
- end
- return [pkmn,pkmn.moves[i].id]
- else
- break
- end
- end
- end
- next if havecommand
- if cmdSummary>=0 && command==cmdSummary
- @scene.pbSummary(pkmnid)
- elsif cmdDebug>=0 && command==cmdDebug
- pbPokemonDebug(pkmn,pkmnid)
- elsif cmdExpShare>=0 && command==cmdExpShare
- if pkmn.expshare
- if pbConfirm(_INTL("¿Quieres desactivar el Repartir Experiencia en este Pokémon?"))
- pkmn.expshare=false
- end
- else
- if pbConfirm(_INTL("¿Quieres activar el Repartir Experiencia en este Pokémon?"))
- pkmn.expshare=true
- end
- end
- elsif cmdSwitch>=0 && command==cmdSwitch
- @scene.pbSetHelpText(_INTL("¿A qué posición mover?"))
- oldpkmnid=pkmnid
- pkmnid=@scene.pbChoosePokemon(true)
- if pkmnid>=0 && pkmnid!=oldpkmnid
- pbSwitch(oldpkmnid,pkmnid)
- end
- elsif cmdMail>=0 && command==cmdMail
- command=@scene.pbShowCommands(_INTL("¿Qué quieres hacer con la carta?"),
- [_INTL("Leer"),_INTL("Quitar"),_INTL("Salir")])
- case command
- when 0 # Read
- pbFadeOutIn(99999){
- pbDisplayMail(pkmn.mail,pkmn)
- }
- when 1 # Take
- pbTakeMail(pkmn)
- pbRefreshSingle(pkmnid)
- end
- elsif cmdItem>=0 && command==cmdItem
- itemcommands = []
- cmdUseItem = -1
- cmdGiveItem = -1
- cmdTakeItem = -1
- cmdMoveItem = -1
- # Build the commands
- itemcommands[cmdUseItem=itemcommands.length] = _INTL("Usar")
- itemcommands[cmdGiveItem=itemcommands.length] = _INTL("Dar")
- itemcommands[cmdTakeItem=itemcommands.length] = _INTL("Quitar") if pkmn.hasItem?
- itemcommands[cmdMoveItem=itemcommands.length] = _INTL("Mover") if pkmn.hasItem? && !pbIsMail?(pkmn.item)
- itemcommands[itemcommands.length] = _INTL("Salir")
- command=@scene.pbShowCommands(_INTL("¿Qué quieres hacer con él?"),itemcommands)
- if cmdUseItem>=0 && command==cmdUseItem # Use
- item=@scene.pbUseItem($PokemonBag,pkmn)
- if item>0
- pbUseItemOnPokemon(item,pkmn,self)
- pbRefreshSingle(pkmnid)
- end
- elsif cmdGiveItem>=0 && command==cmdGiveItem # Give
- item=@scene.pbChooseItem($PokemonBag)
- if item>0
- pbGiveMail(item,pkmn,pkmnid)
- pbRefreshSingle(pkmnid)
- end
- elsif cmdTakeItem>=0 && command==cmdTakeItem # Take
- pbTakeMail(pkmn)
- pbRefreshSingle(pkmnid)
- elsif cmdMoveItem>=0 && command==cmdMoveItem # Move
- item=pkmn.item
- itemname=PBItems.getName(item)
- @scene.pbSetHelpText(_INTL("¿A qué Pokémon quieres darle {1}?",itemname))
- oldpkmnid=pkmnid
- loop do
- @scene.pbPreSelect(oldpkmnid)
- pkmnid=@scene.pbChoosePokemon(true,pkmnid)
- break if pkmnid<0
- newpkmn=@party[pkmnid]
- if pkmnid==oldpkmnid
- break
- elsif newpkmn.isEgg?
- pbDisplay(_INTL("Un Huevo no puede llevar un objeto."))
- elsif !newpkmn.hasItem?
- newpkmn.setItem(item)
- pkmn.setItem(0)
- pbRefresh
- pbDisplay(_INTL("Le has dado {2} a {1}.",newpkmn.name,itemname))
- break
- elsif pbIsMail?(newpkmn.item)
- pbDisplay(_INTL("Debes tomar la carta de {1} antes de darle otro objeto.",newpkmn.name))
- else
- newitem=newpkmn.item
- newitemname=PBItems.getName(newitem)
- pbDisplay(_INTL("{1} ya está llevando {2}.\1",newpkmn.name,newitemname))
- if pbConfirm(_INTL("¿Quieres intercambiar estos objetos?"))
- newpkmn.setItem(item)
- pkmn.setItem(newitem)
- pbRefresh
- pbDisplay(_INTL("Le has dado {2} a {1}.",newpkmn.name,itemname))
- pbDisplay(_INTL("Le has dado {2} a {1}.",pkmn.name,newitemname))
- break
- end
- end
- end
- end
- end
- end
- @scene.pbEndScene
- return nil
- end
- end
- class PokeBattle_Battle
- def pbGainEXP
- return if !@internalbattle
- successbegin=true
- @finalMessage=false
- for i in 0...4 # Not ordered by priority
- if !@doublebattle && pbIsDoubleBattler?(i)
- @battlers[i].participants=[]
- next
- end
- if pbIsOpposing?(i) && @battlers[i].participants.length>0 &&
- (@battlers[i].isFainted? || @battlers[i].captured)
- haveexpall=$Trainer.expall
- # First count the number of participants
- partic=0
- expshare=0
- for j in @battlers[i].participants
- next if !@party1[j] || !pbIsOwner?(0,j)
- partic+=1 if @party1[j].hp>0 && !@party1[j].isEgg?
- end
- if !haveexpall
- for j in 0...@party1.length
- next if !@party1[j] || !pbIsOwner?(0,j)
- expshare+=1 if @party1[j].hp>0 && !@party1[j].isEgg? &&
- (isConst?(@party1[j].item,PBItems,:EXPSHARE) ||
- isConst?(@party1[j].itemInitial,PBItems,:EXPSHARE))
- partic+=1 if @party1[j].hp>0 && !@party1[j].isEgg? &&
- @party1[j].expshare && @party1[j] &&
- !@battlers[i].participants.include?(j)
- end
- end
- # Now calculate EXP for the participants
- if partic>0 || expshare>0 || haveexpall
- if !@opponent && successbegin && pbAllFainted?(@party2)
- @scene.pbWildBattleSuccess
- successbegin=false
- end
- for j in 0...@party1.length
- next if !@party1[j] || !pbIsOwner?(0,j)
- next if @party1[j].hp<=0 || @party1[j].isEgg?
- haveexpshare=(isConst?(@party1[j].item,PBItems,:EXPSHARE) ||
- isConst?(@party1[j].itemInitial,PBItems,:EXPSHARE))
- next if !haveexpshare && !@battlers[i].participants.include?(j)&& !@party1[j].expshare
- pbGainExpOne(j,@battlers[i],partic,expshare,haveexpall)
- end
- if haveexpall
- showmessage=true
- for j in 0...@party1.length
- next if !@party1[j] || !pbIsOwner?(0,j)
- next if @party1[j].hp<=0 || @party1[j].isEgg?
- next if isConst?(@party1[j].item,PBItems,:EXPSHARE) ||
- isConst?(@party1[j].itemInitial,PBItems,:EXPSHARE)
- next if @battlers[i].participants.include?(j)
- next if !(@party1[j].expshare)
- pbDisplayPaused(_INTL("¡Tus otros Pokémon también han ganado Puntos de Experiencia gracias al Repartir Experiencia!")) if showmessage
- showmessage=false
- pbGainExpOne(j,@battlers[i],partic,expshare,haveexpall,false)
- end
- elsif @finalMessage
- pbDisplayPaused(_INTL("¡Tus otros Pokémon también han ganado Puntos de Experiencia gracias al Repartir Experiencia!"))
- end
- end
- # Now clear the participants array
- @battlers[i].participants=[]
- end
- end
- end
- def pbGainExpOne(index,defeated,partic,expshare,haveexpall,showmessages=true)
- thispoke=@party1[index]
- # Original species, not current species
- level=defeated.level
- baseexp=defeated.pokemon.baseExp
- evyield=defeated.pokemon.evYield
- # Gain effort value points, using RS effort values
- totalev=0
- for k in 0...6
- totalev+=thispoke.ev[k]
- end
- for k in 0...6
- evgain=evyield[k]
- evgain*=2 if isConst?(thispoke.item,PBItems,:MACHOBRACE) ||
- isConst?(thispoke.itemInitial,PBItems,:MACHOBRACE)
- case k
- when PBStats::HP
- evgain+=4 if isConst?(thispoke.item,PBItems,:POWERWEIGHT) ||
- isConst?(thispoke.itemInitial,PBItems,:POWERWEIGHT)
- when PBStats::ATTACK
- evgain+=4 if isConst?(thispoke.item,PBItems,:POWERBRACER) ||
- isConst?(thispoke.itemInitial,PBItems,:POWERBRACER)
- when PBStats::DEFENSE
- evgain+=4 if isConst?(thispoke.item,PBItems,:POWERBELT) ||
- isConst?(thispoke.itemInitial,PBItems,:POWERBELT)
- when PBStats::SPATK
- evgain+=4 if isConst?(thispoke.item,PBItems,:POWERLENS) ||
- isConst?(thispoke.itemInitial,PBItems,:POWERLENS)
- when PBStats::SPDEF
- evgain+=4 if isConst?(thispoke.item,PBItems,:POWERBAND) ||
- isConst?(thispoke.itemInitial,PBItems,:POWERBAND)
- when PBStats::SPEED
- evgain+=4 if isConst?(thispoke.item,PBItems,:POWERANKLET) ||
- isConst?(thispoke.itemInitial,PBItems,:POWERANKLET)
- end
- evgain*=2 if thispoke.pokerusStage>=1 # Infected or cured
- if evgain>0
- # Can't exceed overall limit
- evgain-=totalev+evgain-PokeBattle_Pokemon::EVLIMIT if totalev+evgain>PokeBattle_Pokemon::EVLIMIT
- # Can't exceed stat limit
- evgain-=thispoke.ev[k]+evgain-PokeBattle_Pokemon::EVSTATLIMIT if thispoke.ev[k]+evgain>PokeBattle_Pokemon::EVSTATLIMIT
- # Add EV gain
- thispoke.ev[k]+=evgain
- if thispoke.ev[k]>PokeBattle_Pokemon::EVSTATLIMIT
- print "Single-stat EV limit #{PokeBattle_Pokemon::EVSTATLIMIT} exceeded.\r\nStat: #{k} EV gain: #{evgain} EVs: #{thispoke.ev.inspect}"
- thispoke.ev[k]=PokeBattle_Pokemon::EVSTATLIMIT
- end
- totalev+=evgain
- if totalev>PokeBattle_Pokemon::EVLIMIT
- print "EV limit #{PokeBattle_Pokemon::EVLIMIT} exceeded.\r\nTotal EVs: #{totalev} EV gain: #{evgain} EVs: #{thispoke.ev.inspect}"
- end
- end
- end
- # Gain experience
- @finalMessage = true if !(defeated.participants.include?(index)) && thispoke.expshare
- ispartic=0
- ispartic=1 if defeated.participants.include?(index) || thispoke.expshare
- haveexpshare=(isConst?(thispoke.item,PBItems,:EXPSHARE) ||
- isConst?(thispoke.itemInitial,PBItems,:EXPSHARE)) ? 1 : 0
- exp=0
- if expshare>0
- if partic==0 # No participants, all Exp goes to Exp Share holders
- exp=(level*baseexp).floor
- exp=(exp/(NOSPLITEXP ? 1 : expshare)).floor*haveexpshare
- else
- if NOSPLITEXP
- exp=(level*baseexp).floor*ispartic
- exp=(level*baseexp/2).floor*haveexpshare if ispartic==0
- else
- exp=(level*baseexp/2).floor
- exp=(exp/partic).floor*ispartic + (exp/expshare).floor*haveexpshare
- end
- end
- elsif ispartic==1
- exp=(level*baseexp/(NOSPLITEXP ? 1 : partic)).floor
- elsif haveexpall
- exp=(level*baseexp/2).floor
- end
- return if exp<=0
- exp=(exp*3/2).floor if @opponent
- if USESCALEDEXPFORMULA
- exp=(exp/5).floor
- leveladjust=(2*level+10.0)/(level+thispoke.level+10.0)
- leveladjust=leveladjust**5
- leveladjust=Math.sqrt(leveladjust)
- exp=(exp*leveladjust).floor
- exp+=1 if ispartic>0 || haveexpshare>0
- else
- exp=(exp/7).floor
- end
- isOutsider=(thispoke.trainerID!=self.pbPlayer.id ||
- (thispoke.language!=0 && thispoke.language!=self.pbPlayer.language))
- if isOutsider
- if thispoke.language!=0 && thispoke.language!=self.pbPlayer.language
- exp=(exp*1.7).floor
- else
- exp=(exp*3/2).floor
- end
- end
- exp=(exp*3/2).floor if isConst?(thispoke.item,PBItems,:LUCKYEGG) ||
- isConst?(thispoke.itemInitial,PBItems,:LUCKYEGG)
- exp=(exp*1.1).floor if $expboost
- growthrate=thispoke.growthrate
- newexp=PBExperience.pbAddExperience(thispoke.exp,exp,growthrate)
- exp=newexp-thispoke.exp
- if exp>0
- if showmessages
- if isOutsider
- pbDisplayPaused(_INTL("¡{1} ha ganado un total de {2} Puntos de Experiencia!",thispoke.name,exp)) if defeated.participants.include?(index)
- else
- pbDisplayPaused(_INTL("¡{1} ha ganado {2} Puntos de Experiencia!",thispoke.name,exp)) if defeated.participants.include?(index)
- end
- end
- newlevel=PBExperience.pbGetLevelFromExperience(newexp,growthrate)
- tempexp=0
- curlevel=thispoke.level
- if newlevel<curlevel
- debuginfo="#{thispoke.name}: #{thispoke.level}/#{newlevel} | #{thispoke.exp}/#{newexp} | gain: #{exp}"
- 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}]",
- newlevel,curlevel,debuginfo))
- return
- end
- if thispoke.respond_to?("isShadow?") && thispoke.isShadow?
- thispoke.exp+=exp
- else
- tempexp1=thispoke.exp
- tempexp2=0
- # Find battler
- battler=pbFindPlayerBattler(index)
- loop do
- # EXP Bar animation
- startexp=PBExperience.pbGetStartExperience(curlevel,growthrate)
- endexp=PBExperience.pbGetStartExperience(curlevel+1,growthrate)
- tempexp2=(endexp<newexp) ? endexp : newexp
- thispoke.exp=tempexp2
- @scene.pbEXPBar(thispoke,battler,startexp,endexp,tempexp1,tempexp2)
- tempexp1=tempexp2
- curlevel+=1
- if curlevel>newlevel
- thispoke.calcStats
- battler.pbUpdate(false) if battler
- @scene.pbRefresh
- break
- end
- oldtotalhp=thispoke.totalhp
- oldattack=thispoke.attack
- olddefense=thispoke.defense
- oldspeed=thispoke.speed
- oldspatk=thispoke.spatk
- oldspdef=thispoke.spdef
- if battler && battler.pokemon && @internalbattle
- battler.pokemon.changeHappiness("level up")
- end
- thispoke.calcStats
- battler.pbUpdate(false) if battler
- @scene.pbRefresh
- pbDisplayPaused(_INTL("¡{1} subió al nivel {2}!",thispoke.name,curlevel))
- @scene.pbLevelUp(thispoke,battler,oldtotalhp,oldattack,
- olddefense,oldspeed,oldspatk,oldspdef)
- # Determina todos los movimientos aprendidos a este nivel
- movelist=thispoke.getMoveList
- for k in movelist
- if k[0]==thispoke.level # Aprendió un movimiento nuevo
- pbLearnMove(index,k[1])
- end
- end
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement