module EncounterTypes
Land=0
Cave=1
Water=2
RockSmash=3
OldRod=4
GoodRod=5
SuperRod=6
HeadbuttLow=7
HeadbuttHigh=8
LandMorning=9
LandDay=10
LandNight=11
BugContest=12
Names=[
"Land",
"Cave",
"Water",
"RockSmash",
"OldRod",
"GoodRod",
"SuperRod",
"HeadbuttLow",
"HeadbuttHigh",
"LandMorning",
"LandDay",
"LandNight",
"BugContest"
]
EnctypeChances=[
[20,20,10,10,10,10,5,5,4,4,1,1],
[20,20,10,10,10,10,5,5,4,4,1,1],
[60,30,5,4,1],
[60,30,5,4,1],
[70,30],
[60,20,20],
[40,40,15,4,1],
[30,25,20,10,5,5,4,1],
[30,25,20,10,5,5,4,1],
[20,20,10,10,10,10,5,5,4,4,1,1],
[20,20,10,10,10,10,5,5,4,4,1,1],
[20,20,10,10,10,10,5,5,4,4,1,1],
[20,20,10,10,10,10,5,5,4,4,1,1]
]
end
class PokemonEncounters
def initialize
@enctypes=[]
@density=nil
end
def stepcount
return @stepcount
end
def clearStepCount
@stepcount=0
end
def hasEncounter?(enc)
return false if @density==nil || enc<0
return @enctypes[enc] ? true : false
end
def isCave?
return false if @density==nil
return @enctypes[1] ? true : false
end
def isGrass?
return false if @density==nil
return (@enctypes[0] || @enctypes[9] || @enctypes[10] || @enctypes[11] || @enctypes[12]) ? true : false
end
def isEncounterPossibleHere?
if $PokemonGlobal && $PokemonGlobal.surfing
return true
elsif self.isCave?
return true
elsif self.isGrass?
return pbIsGrassTag?($game_map.terrain_tag($game_player.x,$game_player.y))
else
return false
end
end
def pbEncounterType
if $PokemonGlobal && $PokemonGlobal.surfing
return EncounterTypes::Water
elsif self.isCave?
return EncounterTypes::Cave
elsif self.isGrass?
hour=Time.now.hour
enctype=EncounterTypes::Land
if pbInBugContest?
if self.hasEncounter?(EncounterTypes::BugContest)
enctype=EncounterTypes::BugContest
end
elsif hour<6 || hour>=20
if self.hasEncounter?(EncounterTypes::LandNight)
enctype=EncounterTypes::LandNight
end
elsif hour<12
if self.hasEncounter?(EncounterTypes::LandMorning)
enctype=EncounterTypes::LandMorning
end
else
if self.hasEncounter?(EncounterTypes::LandDay)
enctype=EncounterTypes::LandDay
end
end
return enctype
else
return -1
end
end
def setup(mapID)
@density=nil
@stepcount=0
@enctypes=[]
begin
data=load_data("Data/encounters.dat")
if data.is_a?(Hash) && data[mapID]
@density=data[mapID][0]
@enctypes=data[mapID][1]
else
@density=nil
@enctypes=[]
end
rescue
@density=nil
@enctypes=[]
end
end
def pbMapHasEncounter?(mapID,enctype)
data=load_data("Data/encounters.dat")
if data.is_a?(Hash) && data[mapID]
enctypes=data[mapID][1]
density=data[mapID][0]
else
return false
end
return false if density==nil || enctype<0
return enctypes[enctype] ? true : false
end
def pbMapEncounter(mapID,enctype)
if enctype<0 || enctype>EncounterTypes::EnctypeChances.length
raise ArgumentError.new(_INTL("Encounter type out of range"))
end
data=load_data("Data/encounters.dat")
if data.is_a?(Hash) && data[mapID]
enctypes=data[mapID][1]
else
return nil
end
return nil if enctypes[enctype]==nil
chances=EncounterTypes::EnctypeChances[enctype]
rnd=rand(100)
chosenpkmn=0
chance=0
for i in 0...chances.length
chance+=chances[i]
if rnd<chance
chosenpkmn=i
break
end
end
encounter=enctypes[enctype][chosenpkmn]
level=encounter[1]+rand(1+encounter[2]-encounter[1])
return [encounter[0],level]
end
def pbEncounteredPokemon(enctype)
if enctype<0 || enctype>EncounterTypes::EnctypeChances.length
raise ArgumentError.new(_INTL("Encounter type out of range"))
end
return nil if @enctypes[enctype]==nil
chances=EncounterTypes::EnctypeChances[enctype]
rnd=rand(100)
chosenpkmn=0
chance=0
for i in 0...chances.length
chance+=chances[i]
if rnd<chance
chosenpkmn=i
break
end
end
encounter=@enctypes[enctype][chosenpkmn]
return nil if !encounter
level=encounter[1]+rand(1+encounter[2]-encounter[1])
return [encounter[0],level]
end
def pbGenerateEncounter(enctype)
if enctype<0 || enctype>EncounterTypes::EnctypeChances.length
raise ArgumentError.new(_INTL("Encounter type out of range"))
end
return nil if @density==nil
return nil if @density[enctype]==0 || !@density[enctype]
return nil if @enctypes[enctype]==nil
@stepcount+=1
return nil if @stepcount<=3 # Check three steps after battle ends
encount=@density[enctype]*16
if $PokemonGlobal.bicycle
encount=(encount*4/5)
end
if $PokemonMap.blackFluteUsed
encount/=2
end
if $PokemonMap.whiteFluteUsed
encount=(encount*3/2)
end
if $Trainer.party.length>0
if isConst?($Trainer.party[0].item,PBItems,:CLEANSETAG)
encount=(encount*2/3)
else
if isConst?($Trainer.party[0].ability,PBAbilities,:STENCH)
encount=(encount*1/2)
elsif isConst?($Trainer.party[0].ability,PBAbilities,:ILLUMINATE)
encount=(encount*2/3)
end
end
end
return nil if rand(2874)>=encount
encpoke=pbEncounteredPokemon(enctype)
return nil if !encpoke
if $PokemonGlobal.repel>0 &&
$Trainer.party.length>0 &&
encpoke[1]<=$Trainer.party[0].level
return nil
end
return encpoke
end
end