Advertisement
Guest User

Passive Exp

a guest
Dec 9th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.57 KB | None | 0 0
  1. ################################################################################
  2. # Gaining Experience.
  3. ################################################################################
  4.   def pbGainEXP
  5.     return if !@internalbattle
  6.     successbegin=true
  7.     for i in 0...4 # Not ordered by priority
  8.       if !@doublebattle && pbIsDoubleBattler?(i)
  9.         @battlers[i].participants=[]
  10.         next
  11.       end
  12.       if pbIsOpposing?(i) && @battlers[i].participants.length>0 &&
  13.          (@battlers[i].fainted? || @battlers[i].captured)
  14.         haveexpall=@party1.length > 1
  15.         # First count the number of participants
  16.         partic=0
  17.         expshare=0
  18.         for j in @battlers[i].participants
  19.           next if !@party1[j] || !pbIsOwner?(0,j)
  20.           partic+=1 if @party1[j].hp>0 && !@party1[j].egg?
  21.         end
  22.         if !haveexpall
  23.           for j in 0...@party1.length
  24.             next if !@party1[j] || !pbIsOwner?(0,j)
  25.             expshare+=1 if @party1[j].hp>0 && !@party1[j].egg? &&
  26.                            (isConst?(@party1[j].item,PBItems,:EXPSHARE) ||
  27.                            isConst?(@party1[j].itemInitial,PBItems,:EXPSHARE))
  28.           end
  29.         end
  30.         # Now calculate EXP for the participants
  31.         if partic>0 || expshare>0 || haveexpall
  32.           if !@opponent && successbegin && pbAllFainted?(@party2)
  33.             @scene.pbWildBattleSuccess
  34.             successbegin=false
  35.           end
  36.           for j in 0...@party1.length
  37.             next if !@party1[j] || !pbIsOwner?(0,j)
  38.             next if @party1[j].hp<=0 || @party1[j].egg?
  39.             haveexpshare=(isConst?(@party1[j].item,PBItems,:EXPSHARE) ||
  40.                           isConst?(@party1[j].itemInitial,PBItems,:EXPSHARE))
  41.             next if !haveexpshare && !@battlers[i].participants.include?(j)
  42.             pbGainExpOne(j,@battlers[i],partic,expshare,haveexpall)
  43.           end
  44.           if haveexpall
  45.             showmessage=true
  46.             for j in 0...@party1.length
  47.               next if !@party1[j] || !pbIsOwner?(0,j)
  48.               next if @party1[j].hp<=0 || @party1[j].egg?
  49.                            next if @party1[j].hp<=0 || @party1[j].egg?
  50.               next if isConst?(@party1[j].item,PBItems,:EXPSHARE) ||
  51.                       isConst?(@party1[j].itemInitial,PBItems,:EXPSHARE)
  52.               next if @battlers[i].participants.include?(j)
  53.                 pbDisplayPaused(_INTL("The rest of your team gained Exp. Points!")) if showmessage
  54.               showmessage=false
  55.               pbGainExpOne(j,@battlers[i],partic,expshare,haveexpall,false)
  56.             end
  57.           end
  58.         end
  59.         # Now clear the participants array
  60.         @battlers[i].participants=[]
  61.       end
  62.     end
  63.   end
  64.  
  65.   def pbGainExpOne(index,defeated,partic,expshare,haveexpall,showmessages=true)
  66.     thispoke=@party1[index]
  67.     # Original species, not current species
  68.     level=defeated.level
  69.     baseexp=defeated.pokemon.baseExp
  70.     evyield=defeated.pokemon.evYield
  71.     # Gain effort value points, using RS effort values
  72.     totalev=0
  73.     for k in 0...6
  74.       totalev+=thispoke.ev[k]
  75.     end
  76.     for k in 0...6
  77.       evgain=evyield[k]
  78.       evgain*=2 if isConst?(thispoke.item,PBItems,:MACHOBRACE) ||
  79.                    isConst?(thispoke.itemInitial,PBItems,:MACHOBRACE)
  80.       case k
  81.       when PBStats::HP
  82.         evgain+=4 if isConst?(thispoke.item,PBItems,:POWERWEIGHT) ||
  83.                      isConst?(thispoke.itemInitial,PBItems,:POWERWEIGHT)
  84.       when PBStats::ATTACK
  85.         evgain+=4 if isConst?(thispoke.item,PBItems,:POWERBRACER) ||
  86.                      isConst?(thispoke.itemInitial,PBItems,:POWERBRACER)
  87.       when PBStats::DEFENSE
  88.         evgain+=4 if isConst?(thispoke.item,PBItems,:POWERBELT) ||
  89.                      isConst?(thispoke.itemInitial,PBItems,:POWERBELT)
  90.       when PBStats::SPATK
  91.         evgain+=4 if isConst?(thispoke.item,PBItems,:POWERLENS) ||
  92.                      isConst?(thispoke.itemInitial,PBItems,:POWERLENS)
  93.       when PBStats::SPDEF
  94.         evgain+=4 if isConst?(thispoke.item,PBItems,:POWERBAND) ||
  95.                      isConst?(thispoke.itemInitial,PBItems,:POWERBAND)
  96.       when PBStats::SPEED
  97.         evgain+=4 if isConst?(thispoke.item,PBItems,:POWERANKLET) ||
  98.                      isConst?(thispoke.itemInitial,PBItems,:POWERANKLET)
  99.       end
  100.       evgain*=2 if thispoke.pokerusStage>=1 # Infected or cured
  101.       if evgain>0
  102.         # Can't exceed overall limit
  103.         evgain-=totalev+evgain-PokeBattle_Pokemon::EVLIMIT if totalev+evgain>PokeBattle_Pokemon::EVLIMIT
  104.         # Can't exceed stat limit
  105.         evgain-=thispoke.ev[k]+evgain-PokeBattle_Pokemon::EVSTATLIMIT if thispoke.ev[k]+evgain>PokeBattle_Pokemon::EVSTATLIMIT
  106.         # Add EV gain
  107.         thispoke.ev[k]+=evgain
  108.         if thispoke.ev[k]>PokeBattle_Pokemon::EVSTATLIMIT
  109.           print "Single-stat EV limit #{PokeBattle_Pokemon::EVSTATLIMIT} exceeded.\r\nStat: #{k}  EV gain: #{evgain}  EVs: #{thispoke.ev.inspect}"
  110.           thispoke.ev[k]=PokeBattle_Pokemon::EVSTATLIMIT
  111.         end
  112.         totalev+=evgain
  113.         if totalev>PokeBattle_Pokemon::EVLIMIT
  114.           print "EV limit #{PokeBattle_Pokemon::EVLIMIT} exceeded.\r\nTotal EVs: #{totalev} EV gain: #{evgain}  EVs: #{thispoke.ev.inspect}"
  115.         end
  116.       end
  117.     end
  118.     # Gain experience
  119.     ispartic=0
  120.     ispartic=1 if defeated.participants.include?(index)
  121.     haveexpshare=(isConst?(thispoke.item,PBItems,:EXPSHARE) ||
  122.                   isConst?(thispoke.itemInitial,PBItems,:EXPSHARE)) ? 1 : 0
  123.     exp=0
  124.     if expshare>0
  125.       if partic==0 # No participants, all Exp goes to Exp Share holders
  126.         exp=(level*baseexp).floor
  127.         exp=(exp/(NOSPLITEXP ? 1 : expshare)).floor*haveexpshare
  128.       else
  129.         if NOSPLITEXP
  130.           exp=(level*baseexp).floor*ispartic
  131.           exp=(level*baseexp/2).floor*haveexpshare if ispartic==0
  132.         else
  133.           exp=(level*baseexp/2).floor
  134.           exp=(exp/partic).floor*ispartic + (exp/expshare).floor*haveexpshare
  135.         end
  136.       end
  137.     elsif ispartic==1
  138.       exp=(level*baseexp/(NOSPLITEXP ? 1 : partic)).floor
  139.     elsif haveexpall
  140.       exp=(level*baseexp/2).floor
  141.     end
  142.     return if exp<=0
  143.     exp=(exp*3/2).floor if @opponent
  144.     if USESCALEDEXPFORMULA
  145.       exp=(exp/5).floor
  146.       leveladjust=(2*level+10.0)/(level+thispoke.level+10.0)
  147.       leveladjust=leveladjust**5
  148.       leveladjust=Math.sqrt(leveladjust)
  149.       exp=(exp*leveladjust).floor
  150.       exp+=1 if ispartic>0 || haveexpshare>0
  151.     else
  152.       exp=(exp/7).floor
  153.     end
  154.     isOutsider=(thispoke.trainerID!=self.pbPlayer.id ||
  155.                (thispoke.language!=0 && thispoke.language!=self.pbPlayer.language))
  156.     if isOutsider
  157.       if thispoke.language!=0 && thispoke.language!=self.pbPlayer.language
  158.         exp=(exp*1.7).floor
  159.       else
  160.         exp=(exp*3/2).floor
  161.       end
  162.     end
  163.     exp=(exp*3/2).floor if isConst?(thispoke.item,PBItems,:LUCKYEGG) ||
  164.                            isConst?(thispoke.itemInitial,PBItems,:LUCKYEGG)
  165.     growthrate=thispoke.growthrate
  166.     newexp=PBExperience.pbAddExperience(thispoke.exp,exp,growthrate)
  167.     exp=newexp-thispoke.exp
  168.     if exp>0
  169.       if showmessages
  170.         if isOutsider
  171.           pbDisplayPaused(_INTL("{1} gained a boosted {2} Exp. Points!",thispoke.name,exp))
  172.         else
  173.           pbDisplayPaused(_INTL("{1} gained {2} Exp. Points!",thispoke.name,exp))
  174.         end
  175.       end
  176.       newlevel=PBExperience.pbGetLevelFromExperience(newexp,growthrate)
  177.       tempexp=0
  178.       curlevel=thispoke.level
  179.       if newlevel<curlevel
  180.         debuginfo="#{thispoke.name}: #{thispoke.level}/#{newlevel} | #{thispoke.exp}/#{newexp} | gain: #{exp}"
  181.         raise RuntimeError.new(_INTL("The new level ({1}) is less than the Pokémon's\r\ncurrent level ({2}), which shouldn't happen.\r\n[Debug: {3}]",
  182.                                newlevel,curlevel,debuginfo))
  183.         return
  184.       end
  185.       if thispoke.respond_to?("isShadow?") && thispoke.isShadow?
  186.         thispoke.exp+=exp
  187.       else
  188.         tempexp1=thispoke.exp
  189.         tempexp2=0
  190.         # Find battler
  191.         battler=pbFindPlayerBattler(index)
  192.         loop do
  193.           # EXP Bar animation
  194.           startexp=PBExperience.pbGetStartExperience(curlevel,growthrate)
  195.           endexp=PBExperience.pbGetStartExperience(curlevel+1,growthrate)
  196.           tempexp2=(endexp<newexp) ? endexp : newexp
  197.           thispoke.exp=tempexp2
  198.           @scene.pbEXPBar(thispoke,battler,startexp,endexp,tempexp1,tempexp2)
  199.           tempexp1=tempexp2
  200.           curlevel+=1
  201.           if curlevel>newlevel
  202.             thispoke.calcStats
  203.             battler.pbUpdate(false) if battler
  204.             @scene.pbRefresh
  205.             break
  206.           end
  207.           oldtotalhp=thispoke.totalhp
  208.           oldattack=thispoke.attack
  209.           olddefense=thispoke.defense
  210.           oldspeed=thispoke.speed
  211.           oldspatk=thispoke.spatk
  212.           oldspdef=thispoke.spdef
  213.           if battler && battler.pokemon && @internalbattle
  214.             battler.pokemon.changeHappiness("levelup")
  215.           end
  216.           thispoke.calcStats
  217.           battler.pbUpdate(false) if battler
  218.           @scene.pbRefresh
  219.           pbDisplayPaused(_INTL("{1} grew to Level {2}!",thispoke.name,curlevel))
  220.           @scene.pbLevelUp(thispoke,battler,oldtotalhp,oldattack,
  221.                            olddefense,oldspeed,oldspatk,oldspdef)
  222.           # Finding all moves learned at this level
  223.           movelist=thispoke.getMoveList
  224.           for k in movelist
  225.             if k[0]==thispoke.level   # Learned a new move
  226.               pbLearnMove(index,k[1])
  227.             end
  228.           end
  229.         end
  230.       end
  231.     end
  232.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement