Advertisement
Guest User

PokemonEncounters

a guest
Dec 26th, 2013
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.45 KB | None | 0 0
  1. module EncounterTypes
  2.   Land         = 0
  3.   Cave         = 1
  4.   Water        = 2
  5.   RockSmash    = 3
  6.   OldRod       = 4
  7.   GoodRod      = 5
  8.   SuperRod     = 6
  9.   HeadbuttLow  = 7
  10.   HeadbuttHigh = 8
  11.   LandMorning  = 9
  12.   LandDay      = 10
  13.   LandNight    = 11
  14.   BugContest   = 12
  15.   Flowers = 13
  16.   TallGrass = 14
  17.   Names=[
  18.      "Land",
  19.      "Cave",
  20.      "Water",
  21.      "RockSmash",
  22.      "OldRod",
  23.      "GoodRod",
  24.      "SuperRod",
  25.      "HeadbuttLow",
  26.      "HeadbuttHigh",
  27.      "LandMorning",
  28.      "LandDay",
  29.      "LandNight",
  30.      "BugContest",
  31.      "Flowers",
  32.      "TallGrass"
  33.   ]
  34.   EnctypeChances=[
  35.      [20,20,10,10,10,10,5,5,4,4,1,1],
  36.      [20,20,10,10,10,10,5,5,4,4,1,1],
  37.      [60,30,5,4,1],
  38.      [60,30,5,4,1],
  39.      [70,30],
  40.      [60,20,20],
  41.      [40,40,15,4,1],
  42.      [30,25,20,10,5,5,4,1],
  43.      [30,25,20,10,5,5,4,1],
  44.      [20,20,10,10,10,10,5,5,4,4,1,1],
  45.      [20,20,10,10,10,10,5,5,4,4,1,1],
  46.      [20,20,10,10,10,10,5,5,4,4,1,1],
  47.      [20,20,10,10,10,10,5,5,4,4,1,1],
  48.      [20,20,10,10,10,10,5,5,4,4,1,1],
  49.      [20,20,10,10,10,10,5,5,4,4,1,1]
  50.   ]
  51.   EnctypeDensities=[25,10,10,0,0,0,0,0,0,25,25,25,25,25,25]
  52.   EnctypeCompileDens=[1,2,3,0,0,0,0,0,0,1,1,1,1,1,1]
  53. end
  54.  
  55.  
  56.  
  57. class PokemonEncounters
  58.   def initialize
  59.     @enctypes=[]
  60.     @density=nil
  61.   end
  62.  
  63.   def stepcount
  64.     return @stepcount
  65.   end
  66.  
  67.   def clearStepCount
  68.     @stepcount=0
  69.   end
  70.  
  71.   def hasEncounter?(enc)
  72.     return false if @density==nil || enc<0
  73.     return @enctypes[enc] ? true : false  
  74.   end
  75.  
  76.   def isCave?
  77.     return false if @density==nil
  78.     return @enctypes[EncounterTypes::Cave] ? true : false
  79.   end
  80.  
  81.   def isGrass?
  82.     return false if @density==nil
  83.     return (@enctypes[EncounterTypes::Land] ||
  84.             @enctypes[EncounterTypes::Flowers] ||
  85.             @enctypes[EncounterTypes::TallGrass] ||
  86.             @enctypes[EncounterTypes::LandMorning] ||
  87.             @enctypes[EncounterTypes::LandDay] ||
  88.             @enctypes[EncounterTypes::LandNight] ||
  89.             @enctypes[EncounterTypes::BugContest]) ? true : false
  90.   end
  91.  
  92.   def isWater?
  93.     return false if @density==nil
  94.     return @enctypes[EncounterTypes::Water] ? true : false
  95.   end
  96.  
  97.   def isEncounterPossibleHere?
  98.     if $PokemonGlobal && $PokemonGlobal.surfing
  99.       return true
  100.     elsif pbGetTerrainTag($game_player)==PBTerrain::Ice
  101.       return false
  102.     elsif self.isCave?
  103.       return true
  104.     elsif self.isGrass?
  105.       return pbIsGrassTag?($game_map.terrain_tag($game_player.x,$game_player.y))
  106.     else
  107.       return false
  108.     end
  109.   end
  110.  
  111.   def pbEncounterType
  112.     if $PokemonGlobal && $PokemonGlobal.surfing
  113.       return EncounterTypes::Water
  114.     elsif self.isCave?
  115.       return EncounterTypes::Cave
  116.     elsif self.isGrass?
  117.       time=pbGetTimeNow
  118.       enctype=EncounterTypes::Land
  119.       enctype=EncounterTypes::TallGrass if pbGetTerrainTag($game_player)==PBTerrain::TallGrass
  120.       enctype=EncounterTypes::Flowers if pbGetTerrainTag($game_player)==PBTerrain::Flowers
  121.       enctype=EncounterTypes::LandNight if self.hasEncounter?(EncounterTypes::LandNight) && PBDayNight.isNight?(time)
  122.       enctype=EncounterTypes::LandDay if self.hasEncounter?(EncounterTypes::LandDay) && PBDayNight.isDay?(time)
  123.       enctype=EncounterTypes::LandMorning if self.hasEncounter?(EncounterTypes::LandMorning) && PBDayNight.isMorning?(time)
  124.       if pbInBugContest?
  125.         if self.hasEncounter?(EncounterTypes::BugContest)
  126.           enctype=EncounterTypes::BugContest
  127.         end
  128.       end
  129.       return enctype
  130.     else
  131.       return -1
  132.     end
  133.   end
  134.  
  135.   def setup(mapID)
  136.     @density=nil
  137.     @stepcount=0
  138.     @enctypes=[]
  139.     begin
  140.       data=load_data("Data/encounters.dat")
  141.       if data.is_a?(Hash) && data[mapID]
  142.         @density=data[mapID][0]
  143.         @enctypes=data[mapID][1]
  144.       else
  145.         @density=nil
  146.         @enctypes=[]
  147.       end
  148.       rescue
  149.       @density=nil
  150.       @enctypes=[]
  151.     end
  152.   end
  153.  
  154.   def pbMapHasEncounter?(mapID,enctype)
  155.     data=load_data("Data/encounters.dat")
  156.     if data.is_a?(Hash) && data[mapID]
  157.       enctypes=data[mapID][1]
  158.       density=data[mapID][0]
  159.     else
  160.       return false
  161.     end
  162.     return false if density==nil || enctype<0
  163.     return enctypes[enctype] ? true : false  
  164.   end
  165.  
  166.   def pbMapEncounter(mapID,enctype)
  167.     if enctype<0 || enctype>EncounterTypes::EnctypeChances.length
  168.       raise ArgumentError.new(_INTL("Encounter type out of range"))
  169.     end
  170.     data=load_data("Data/encounters.dat")
  171.     if data.is_a?(Hash) && data[mapID]
  172.       enctypes=data[mapID][1]
  173.     else
  174.       return nil
  175.     end
  176.     return nil if enctypes[enctype]==nil
  177.     chances=EncounterTypes::EnctypeChances[enctype]
  178.     chancetotal=0
  179.     chances.each {|a| chancetotal+=a}
  180.     rnd=rand(chancetotal)
  181.     chosenpkmn=0
  182.     chance=0
  183.     for i in 0...chances.length
  184.       chance+=chances[i]
  185.       if rnd<chance
  186.         chosenpkmn=i
  187.         break
  188.       end
  189.     end
  190.     encounter=enctypes[enctype][chosenpkmn]
  191.     level=encounter[1]+rand(1+encounter[2]-encounter[1])
  192.     return [encounter[0],level]
  193.   end
  194.  
  195.   def pbEncounteredPokemon(enctype)
  196.     if enctype<0 || enctype>EncounterTypes::EnctypeChances.length
  197.       raise ArgumentError.new(_INTL("Encounter type out of range"))
  198.     end
  199.     return nil if @enctypes[enctype]==nil
  200.     chances=EncounterTypes::EnctypeChances[enctype]
  201.     chancetotal=0
  202.     chances.each {|a| chancetotal+=a}
  203.     rnd=rand(chancetotal)
  204.     chosenpkmn=0
  205.     chance=0
  206.     for i in 0...chances.length
  207.       chance+=chances[i]
  208.       if rnd<chance
  209.         chosenpkmn=i
  210.         break
  211.       end
  212.     end
  213.     encounter=@enctypes[enctype][chosenpkmn]
  214.     return nil if !encounter
  215.     level=encounter[1]+rand(1+encounter[2]-encounter[1])
  216.     return [encounter[0],level]
  217.   end
  218.  
  219.   def pbCanEncounter?(encounter)
  220.     return false if !encounter || !$Trainer
  221.     if $PokemonGlobal.repel>0 && $Trainer.ablePokemonCount>0 &&
  222.        encounter[1]<=$Trainer.ablePokemonParty[0].level
  223.       return false
  224.     end
  225.     if $game_system.encounter_disabled || ($DEBUG && Input.press?(Input::CTRL))
  226.       return false
  227.     end
  228.     return true
  229.   end
  230.  
  231.   def pbGenerateEncounter(enctype)
  232.     if enctype<0 || enctype>EncounterTypes::EnctypeChances.length
  233.       raise ArgumentError.new(_INTL("Encounter type out of range"))
  234.     end
  235.     return nil if @density==nil
  236.     return nil if @density[enctype]==0 || !@density[enctype]
  237.     return nil if @enctypes[enctype]==nil
  238.     @stepcount+=1
  239.     return nil if @stepcount<=3 # Check three steps after battle ends
  240.     encount=@density[enctype]*16
  241.     if $PokemonGlobal.bicycle
  242.       encount=(encount*4/5)
  243.     end
  244.     if $PokemonMap.blackFluteUsed
  245.       encount/=2
  246.     end
  247.     if $PokemonMap.whiteFluteUsed
  248.       encount=(encount*3/2)
  249.     end
  250.     if $Trainer.party.length>0 && !$Trainer.party[0].egg?
  251.       if isConst?($Trainer.party[0].item,PBItems,:CLEANSETAG)
  252.         encount=(encount*2/3)
  253.       elsif isConst?($Trainer.party[0].item,PBItems,:PUREINCENSE)
  254.         encount=(encount*2/3)
  255.       end
  256.       if isConst?($Trainer.party[0].ability,PBAbilities,:STENCH)
  257.         encount=(encount/2)
  258.       elsif isConst?($Trainer.party[0].ability,PBAbilities,:WHITESMOKE)
  259.         encount=(encount/2)
  260.       elsif isConst?($Trainer.party[0].ability,PBAbilities,:QUICKFEET)
  261.         encount=(encount/2)
  262.       elsif isConst?($Trainer.party[0].ability,PBAbilities,:SNOWCLOAK) &&
  263.          $game_screen.weather_type==3
  264.         encount=(encount/2)
  265.       elsif isConst?($Trainer.party[0].ability,PBAbilities,:SANDVEIL) &&
  266.          $game_screen.weather_type==4
  267.         encount=(encount/2)
  268.       elsif isConst?($Trainer.party[0].ability,PBAbilities,:SWARM)
  269.         encount=(encount*3/2)
  270.       elsif isConst?($Trainer.party[0].ability,PBAbilities,:ILLUMINATE)
  271.         encount=(encount*2)
  272.       elsif isConst?($Trainer.party[0].ability,PBAbilities,:ARENATRAP)
  273.         encount=(encount*2)
  274.       elsif isConst?($Trainer.party[0].ability,PBAbilities,:NOGUARD)
  275.         encount=(encount*2)
  276.       end
  277.     end
  278.     return nil if rand(2874)>=encount
  279.     encpoke=pbEncounteredPokemon(enctype)
  280.     if $Trainer.party.length>0 && !$Trainer.party[0].egg?
  281.       if encpoke && isConst?($Trainer.party[0].ability,PBAbilities,:INTIMIDATE) &&
  282.          encpoke[1]<=$Trainer.party[0].level-5 && rand(2)==0
  283.         encpoke=nil
  284.       end
  285.       if encpoke && isConst?($Trainer.party[0].ability,PBAbilities,:KEENEYE) &&
  286.          encpoke[1]<=$Trainer.party[0].level-5 && rand(2)==0
  287.         encpoke=nil
  288.       end
  289.     end
  290.     return encpoke
  291.   end
  292. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement