Added class GameData::EncounterType

This commit is contained in:
Maruno17
2021-03-06 22:01:16 +00:00
parent ff0c2f00c8
commit 3a1b9b6dc6
18 changed files with 402 additions and 337 deletions

View File

@@ -62,7 +62,7 @@ module GameData
@map = hash[:map] @map = hash[:map]
@version = hash[:version] || 0 @version = hash[:version] || 0
@step_chances = hash[:step_chances] @step_chances = hash[:step_chances]
@types = hash[:types] || [] @types = hash[:types] || {}
end end
end end
end end

View File

@@ -1,94 +1,195 @@
module EncounterTypes module GameData
Land = 0 class EncounterType
LandDay = 1 attr_reader :id
LandNight = 2 attr_reader :real_name
LandMorning = 3 attr_reader :type # :land, :cave, :water, :fishing, :contest, :none
LandAfternoon = 4 attr_reader :trigger_chance
LandEvening = 5 attr_reader :old_slots
Cave = 6
CaveDay = 7
CaveNight = 8
CaveMorning = 9
CaveAfternoon = 10
CaveEvening = 11
Water = 12
WaterDay = 13
WaterNight = 14
WaterMorning = 15
WaterAfternoon = 16
WaterEvening = 17
OldRod = 18
GoodRod = 19
SuperRod = 20
RockSmash = 21
HeadbuttLow = 22
HeadbuttHigh = 23
BugContest = 24
Names = [ DATA = {}
"Land", "LandDay", "LandNight", "LandMorning", "LandAfternoon", "LandEvening",
"Cave", "CaveDay", "CaveNight", "CaveMorning", "CaveAfternoon", "CaveEvening",
"Water", "WaterDay", "WaterNight", "WaterMorning", "WaterAfternoon", "WaterEvening",
"OldRod", "GoodRod", "SuperRod", "RockSmash", "HeadbuttLow", "HeadbuttHigh",
"BugContest"
]
Probabilities = [
[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],
[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],
[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],
[60, 30, 5, 4, 1],
[60, 30, 5, 4, 1],
[60, 30, 5, 4, 1],
[60, 30, 5, 4, 1],
[60, 30, 5, 4, 1],
[60, 30, 5, 4, 1],
[70, 30],
[60, 20, 20],
[40, 40, 15, 4, 1],
[60, 30, 5, 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]
]
Chances_Per_Step = [
21, 21, 21, 21, 21, 21, # Lands
5, 5, 5, 5, 5, 5, # Caves
2, 2, 2, 2, 2, 2, # Waters
0, 0, 0, 50, 0, 0, 21
]
Kinds = [
1, 1, 1, 1, 1, 1, # Lands
2, 2, 2, 2, 2, 2, # Caves
3, 3, 3, 3, 3, 3, # Waters
0, 0, 0, 0, 0, 0, 1
]
def self.is_land_type?(enc_type) extend ClassMethodsSymbols
return self.is_normal_land_type?(enc_type) || enc_type == BugContest include InstanceMethods
end
def self.is_normal_land_type?(enc_type) def self.load; end
return [Land, LandDay, LandNight, LandMorning, LandAfternoon, LandEvening].include?(enc_type) def self.save; end
end
def self.is_cave_type?(enc_type) def initialize(hash)
return [Cave, CaveDay, CaveNight, CaveMorning, CaveAfternoon, CaveEvening].include?(enc_type) @id = hash[:id]
end @real_name = hash[:id].to_s || "Unnamed"
@type = hash[:type] || :none
def self.is_water_type?(enc_type) @trigger_chance = hash[:trigger_chance] || 0
return [Water, WaterDay, WaterNight, WaterMorning, WaterAfternoon, WaterEvening].include?(enc_type) @old_slots = hash[:old_slots]
end end
def self.is_fishing_type?(enc_type)
return [OldRod, GoodRod, SuperRod].include?(enc_type)
end end
end end
GameData::EncounterType.register({
:id => :Land,
:type => :land,
:trigger_chance => 21,
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
})
GameData::EncounterType.register({
:id => :LandDay,
:type => :land,
:trigger_chance => 21,
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
})
GameData::EncounterType.register({
:id => :LandNight,
:type => :land,
:trigger_chance => 21,
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
})
GameData::EncounterType.register({
:id => :LandMorning,
:type => :land,
:trigger_chance => 21,
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
})
GameData::EncounterType.register({
:id => :LandAfternoon,
:type => :land,
:trigger_chance => 21,
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
})
GameData::EncounterType.register({
:id => :LandEvening,
:type => :land,
:trigger_chance => 21,
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
})
GameData::EncounterType.register({
:id => :Cave,
:type => :cave,
:trigger_chance => 5,
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
})
GameData::EncounterType.register({
:id => :CaveDay,
:type => :cave,
:trigger_chance => 5,
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
})
GameData::EncounterType.register({
:id => :CaveNight,
:type => :cave,
:trigger_chance => 5,
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
})
GameData::EncounterType.register({
:id => :CaveMorning,
:type => :cave,
:trigger_chance => 5,
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
})
GameData::EncounterType.register({
:id => :CaveAfternoon,
:type => :cave,
:trigger_chance => 5,
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
})
GameData::EncounterType.register({
:id => :CaveEvening,
:type => :cave,
:trigger_chance => 5,
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
})
GameData::EncounterType.register({
:id => :Water,
:type => :water,
:trigger_chance => 2,
:old_slots => [60, 30, 5, 4, 1]
})
GameData::EncounterType.register({
:id => :WaterDay,
:type => :water,
:trigger_chance => 2,
:old_slots => [60, 30, 5, 4, 1]
})
GameData::EncounterType.register({
:id => :WaterNight,
:type => :water,
:trigger_chance => 2,
:old_slots => [60, 30, 5, 4, 1]
})
GameData::EncounterType.register({
:id => :WaterMorning,
:type => :water,
:trigger_chance => 2,
:old_slots => [60, 30, 5, 4, 1]
})
GameData::EncounterType.register({
:id => :WaterAfternoon,
:type => :water,
:trigger_chance => 2,
:old_slots => [60, 30, 5, 4, 1]
})
GameData::EncounterType.register({
:id => :WaterEvening,
:type => :water,
:trigger_chance => 2,
:old_slots => [60, 30, 5, 4, 1]
})
GameData::EncounterType.register({
:id => :OldRod,
:type => :fishing,
:old_slots => [70, 30]
})
GameData::EncounterType.register({
:id => :GoodRod,
:type => :fishing,
:old_slots => [60, 20, 20]
})
GameData::EncounterType.register({
:id => :SuperRod,
:type => :fishing,
:old_slots => [40, 40, 15, 4, 1]
})
GameData::EncounterType.register({
:id => :RockSmash,
:type => :none,
:trigger_chance => 50,
:old_slots => [60, 30, 5, 4, 1]
})
GameData::EncounterType.register({
:id => :HeadbuttLow,
:type => :none,
:old_slots => [30, 25, 20, 10, 5, 5, 4, 1]
})
GameData::EncounterType.register({
:id => :HeadbuttHigh,
:type => :none,
:old_slots => [30, 25, 20, 10, 5, 5, 4, 1]
})
GameData::EncounterType.register({
:id => :BugContest,
:type => :contest,
:trigger_chance => 21,
:old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1]
})

View File

@@ -162,9 +162,7 @@ BallHandlers::ModifyCatchRate.add(:LEVELBALL,proc { |ball,catchRate,battle,battl
BallHandlers::ModifyCatchRate.add(:LUREBALL,proc { |ball,catchRate,battle,battler,ultraBeast| BallHandlers::ModifyCatchRate.add(:LUREBALL,proc { |ball,catchRate,battle,battler,ultraBeast|
multiplier = (Settings::NEW_POKE_BALL_CATCH_RATES) ? 5 : 3 multiplier = (Settings::NEW_POKE_BALL_CATCH_RATES) ? 5 : 3
catchRate *= multiplier if $PokemonTemp.encounterType==EncounterTypes::OldRod || catchRate *= multiplier if GameData::EncounterType.get($PokemonTemp.encounterType).type == :fishing
$PokemonTemp.encounterType==EncounterTypes::GoodRod ||
$PokemonTemp.encounterType==EncounterTypes::SuperRod
next [catchRate,255].min next [catchRate,255].min
}) })

View File

@@ -371,21 +371,21 @@ Events.onChangeDirection += proc {
def pbBattleOnStepTaken(repel_active) def pbBattleOnStepTaken(repel_active)
return if $Trainer.able_pokemon_count == 0 return if $Trainer.able_pokemon_count == 0
return if !$PokemonEncounters.encounter_possible_here? return if !$PokemonEncounters.encounter_possible_here?
encounterType = $PokemonEncounters.encounter_type encounter_type = $PokemonEncounters.encounter_type
return if encounterType < 0 return if !encounter_type
return if !$PokemonEncounters.encounter_triggered?(encounterType, repel_active) return if !$PokemonEncounters.encounter_triggered?(encounter_type, repel_active)
$PokemonTemp.encounterType = encounterType $PokemonTemp.encounterType = encounter_type
encounter = $PokemonEncounters.choose_wild_pokemon(encounterType) encounter = $PokemonEncounters.choose_wild_pokemon(encounter_type)
encounter = EncounterModifier.trigger(encounter) encounter = EncounterModifier.trigger(encounter)
if $PokemonEncounters.allow_encounter?(encounter, repel_active) if $PokemonEncounters.allow_encounter?(encounter, repel_active)
if $PokemonEncounters.have_double_wild_battle? if $PokemonEncounters.have_double_wild_battle?
encounter2 = $PokemonEncounters.choose_wild_pokemon(encounterType) encounter2 = $PokemonEncounters.choose_wild_pokemon(encounter_type)
encounter2 = EncounterModifier.trigger(encounter2) encounter2 = EncounterModifier.trigger(encounter2)
pbDoubleWildBattle(encounter[0], encounter[1], encounter2[0], encounter2[1]) pbDoubleWildBattle(encounter[0], encounter[1], encounter2[0], encounter2[1])
else else
pbWildBattle(encounter[0], encounter[1]) pbWildBattle(encounter[0], encounter[1])
end end
$PokemonTemp.encounterType = -1 $PokemonTemp.encounterType = nil
$PokemonTemp.encounterTriggered = true $PokemonTemp.encounterTriggered = true
end end
$PokemonTemp.forceSingleBattle = false $PokemonTemp.forceSingleBattle = false

View File

@@ -40,9 +40,7 @@ def pbBattleAnimation(bgm=nil,battletype=0,foe=nil)
if $PokemonGlobal.surfing || $PokemonGlobal.diving if $PokemonGlobal.surfing || $PokemonGlobal.diving
location = 3 location = 3
elsif $PokemonTemp.encounterType && elsif $PokemonTemp.encounterType &&
($PokemonTemp.encounterType==EncounterTypes::OldRod || GameData::EncounterType.get($PokemonTemp.encounterType).type == :fishing
$PokemonTemp.encounterType==EncounterTypes::GoodRod ||
$PokemonTemp.encounterType==EncounterTypes::SuperRod)
location = 3 location = 3
elsif $PokemonEncounters.has_cave_encounters? elsif $PokemonEncounters.has_cave_encounters?
location = 2 location = 2

View File

@@ -169,9 +169,7 @@ def pbGetEnvironment
ret = :None ret = :None
map_metadata = GameData::MapMetadata.try_get($game_map.map_id) map_metadata = GameData::MapMetadata.try_get($game_map.map_id)
ret = map_metadata.battle_environment if map_metadata && map_metadata.battle_environment ret = map_metadata.battle_environment if map_metadata && map_metadata.battle_environment
if $PokemonTemp.encounterType == EncounterTypes::OldRod || if GameData::EncounterType.get($PokemonTemp.encounterType).type == :fishing
$PokemonTemp.encounterType == EncounterTypes::GoodRod ||
$PokemonTemp.encounterType == EncounterTypes::SuperRod
terrainTag = pbFacingTerrainTag terrainTag = pbFacingTerrainTag
else else
terrainTag = $game_player.terrain_tag terrainTag = $game_player.terrain_tag

View File

@@ -5,18 +5,18 @@ class PokemonEncounters
attr_reader :step_count attr_reader :step_count
def initialize def initialize
@step_chances = nil @step_chances = {}
@encounter_tables = [] @encounter_tables = {}
@chance_accumulator = 0 @chance_accumulator = 0
end end
def setup(map_ID) def setup(map_ID)
@step_count = 0 @step_count = 0
@step_chances = nil @step_chances = {}
@encounter_tables = [] @encounter_tables = {}
encounter_data = GameData::Encounter.get(map_ID, $PokemonGlobal.encounter_version) encounter_data = GameData::Encounter.get(map_ID, $PokemonGlobal.encounter_version)
if encounter_data if encounter_data
@step_chances = encounter_data.step_chances.clone encounter_data.step_chances.each { |type, value| @step_chances[type] = value }
@encounter_tables = Marshal.load(Marshal.dump(encounter_data.types)) @encounter_tables = Marshal.load(Marshal.dump(encounter_data.types))
end end
end end
@@ -31,7 +31,7 @@ class PokemonEncounters
# Returns whether encounters for the given encounter type have been defined # Returns whether encounters for the given encounter type have been defined
# for the current map. # for the current map.
def has_encounter_type?(enc_type) def has_encounter_type?(enc_type)
return false if enc_type < 0 return false if !enc_type
return @encounter_tables[enc_type] && @encounter_tables[enc_type].length > 0 return @encounter_tables[enc_type] && @encounter_tables[enc_type].length > 0
end end
@@ -40,7 +40,7 @@ class PokemonEncounters
# the map's BugContest encounter type to generate caught Pokémon for the other # the map's BugContest encounter type to generate caught Pokémon for the other
# contestants. # contestants.
def map_has_encounter_type?(map_ID, enc_type) def map_has_encounter_type?(map_ID, enc_type)
return false if enc_type < 0 return false if !enc_type
encounter_data = GameData::Encounter.get(map_ID, $PokemonGlobal.encounter_version) encounter_data = GameData::Encounter.get(map_ID, $PokemonGlobal.encounter_version)
return false if !encounter_data return false if !encounter_data
return encounter_data.types[enc_type] && encounter_data.types[enc_type].length > 0 return encounter_data.types[enc_type] && encounter_data.types[enc_type].length > 0
@@ -49,42 +49,39 @@ class PokemonEncounters
# Returns whether land-like encounters have been defined for the current map. # Returns whether land-like encounters have been defined for the current map.
# Applies only to encounters triggered by moving around. # Applies only to encounters triggered by moving around.
def has_land_encounters? def has_land_encounters?
return has_normal_land_encounters? || GameData::EncounterType.each do |enc_type|
has_encounter_type?(EncounterTypes::BugContest) next if ![:land, :contest].include?(enc_type.type)
return true if has_encounter_type?(enc_type.id)
end
return false
end end
# Returns whether land-like encounters have been defined for the current map # Returns whether land-like encounters have been defined for the current map
# (ignoring the Bug Catching Contest one). # (ignoring the Bug Catching Contest one).
# Applies only to encounters triggered by moving around. # Applies only to encounters triggered by moving around.
def has_normal_land_encounters? def has_normal_land_encounters?
return has_encounter_type?(EncounterTypes::Land) || GameData::EncounterType.each do |enc_type|
has_encounter_type?(EncounterTypes::LandDay) || return true if enc_type.type == :land && has_encounter_type?(enc_type.id)
has_encounter_type?(EncounterTypes::LandNight) || end
has_encounter_type?(EncounterTypes::LandMorning) || return false
has_encounter_type?(EncounterTypes::LandAfternoon) ||
has_encounter_type?(EncounterTypes::LandEvening)
end end
# Returns whether cave-like encounters have been defined for the current map. # Returns whether cave-like encounters have been defined for the current map.
# Applies only to encounters triggered by moving around. # Applies only to encounters triggered by moving around.
def has_cave_encounters? def has_cave_encounters?
return has_encounter_type?(EncounterTypes::Cave) || GameData::EncounterType.each do |enc_type|
has_encounter_type?(EncounterTypes::CaveDay) || return true if enc_type.type == :cave && has_encounter_type?(enc_type.id)
has_encounter_type?(EncounterTypes::CaveNight) || end
has_encounter_type?(EncounterTypes::CaveMorning) || return false
has_encounter_type?(EncounterTypes::CaveAfternoon) ||
has_encounter_type?(EncounterTypes::CaveEvening)
end end
# Returns whether water-like encounters have been defined for the current map. # Returns whether water-like encounters have been defined for the current map.
# Applies only to encounters triggered by moving around (i.e. not fishing). # Applies only to encounters triggered by moving around (i.e. not fishing).
def has_water_encounters? def has_water_encounters?
return has_encounter_type?(EncounterTypes::Water) || GameData::EncounterType.each do |enc_type|
has_encounter_type?(EncounterTypes::WaterDay) || return true if enc_type.type == :water && has_encounter_type?(enc_type.id)
has_encounter_type?(EncounterTypes::WaterNight) || end
has_encounter_type?(EncounterTypes::WaterMorning) || return false
has_encounter_type?(EncounterTypes::WaterAfternoon) ||
has_encounter_type?(EncounterTypes::WaterEvening)
end end
#============================================================================= #=============================================================================
@@ -103,8 +100,8 @@ class PokemonEncounters
# Returns whether a wild encounter should happen, based on its encounter # Returns whether a wild encounter should happen, based on its encounter
# chance. Called when taking a step and by Rock Smash. # chance. Called when taking a step and by Rock Smash.
def encounter_triggered?(enc_type, repel_active = false, triggered_by_step = true) def encounter_triggered?(enc_type, repel_active = false, triggered_by_step = true)
if enc_type < 0 || enc_type > EncounterTypes::Probabilities.length if !enc_type || !GameData::EncounterType.exists?(enc_type)
raise ArgumentError.new(_INTL("Encounter type out of range")) raise ArgumentError.new(_INTL("Encounter type {1} does not exist", enc_type))
end end
return false if $game_system.encounter_disabled return false if $game_system.encounter_disabled
return false if !$Trainer return false if !$Trainer
@@ -211,61 +208,47 @@ class PokemonEncounters
return false return false
end end
# Checks the defined encounters for the current map and returns the encounter
# type that the given time should produce. Only returns an encounter type if
# it has been defined for the current map.
def find_valid_encounter_type_for_time(base_type, time)
ret = nil
if PBDayNight.isDay?(time)
try_type = nil
if PBDayNight.isMorning?(time)
try_type = (base_type.to_s + "Morning").to_sym
elsif PBDayNight.isAfternoon?(time)
try_type = (base_type.to_s + "Afternoon").to_sym
elsif PBDayNight.isEvening?(time)
try_type = (base_type.to_s + "Evening").to_sym
end
ret = try_type if try_type && has_encounter_type?(try_type)
if !ret
try_type = (base_type.to_s + "Day").to_sym
ret = try_type if has_encounter_type?(try_type)
end
else
try_type = (base_type.to_s + "Night").to_sym
ret = try_type if has_encounter_type?(try_type)
end
return ret if ret
return (has_encounter_type?(base_type)) ? base_type : nil
end
# Returns the encounter method that the current encounter should be generated # Returns the encounter method that the current encounter should be generated
# from, depending on the player's current location. # from, depending on the player's current location.
def encounter_type def encounter_type
time = pbGetTimeNow time = pbGetTimeNow
ret = -1 ret = nil
if $PokemonGlobal.surfing if $PokemonGlobal.surfing
ret = EncounterTypes::Water if has_encounter_type?(EncounterTypes::Water) ret = find_valid_encounter_type_for_time(:Water, time)
if PBDayNight.isDay?(time) else # Land/Cave (can have both in the same map)
ret = EncounterTypes::WaterDay if has_encounter_type?(EncounterTypes::WaterDay) if has_land_encounters? && PBTerrain.isGrass?($game_map.terrain_tag($game_player.x, $game_player.y))
if PBDayNight.isMorning?(time) ret = :BugContest if pbInBugContest? && has_encounter_type?(:BugContest)
ret = EncounterTypes::WaterMorning if has_encounter_type?(EncounterTypes::WaterMorning) ret = find_valid_encounter_type_for_time(:Land, time) if !ret
elsif PBDayNight.isAfternoon?(time)
ret = EncounterTypes::WaterAfternoon if has_encounter_type?(EncounterTypes::WaterAfternoon)
elsif PBDayNight.isEvening?(time)
ret = EncounterTypes::WaterEvening if has_encounter_type?(EncounterTypes::WaterEvening)
end
else
ret = EncounterTypes::WaterNight if has_encounter_type?(EncounterTypes::WaterNight)
end end
else if !ret && has_cave_encounters?
check_land = false ret = find_valid_encounter_type_for_time(:Cave, time)
if has_cave_encounters?
check_land = PBTerrain.isGrass?($game_map.terrain_tag($game_player.x, $game_player.y))
ret = EncounterTypes::Cave if has_encounter_type?(EncounterTypes::Cave)
if PBDayNight.isDay?(time)
ret = EncounterTypes::CaveDay if has_encounter_type?(EncounterTypes::CaveDay)
if PBDayNight.isMorning?(time)
ret = EncounterTypes::CaveMorning if has_encounter_type?(EncounterTypes::CaveMorning)
elsif PBDayNight.isAfternoon?(time)
ret = EncounterTypes::CaveAfternoon if has_encounter_type?(EncounterTypes::CaveAfternoon)
elsif PBDayNight.isEvening?(time)
ret = EncounterTypes::CaveEvening if has_encounter_type?(EncounterTypes::CaveEvening)
end
else
ret = EncounterTypes::CaveNight if has_encounter_type?(EncounterTypes::CaveNight)
end
end
# Land
if has_land_encounters? || check_land
ret = EncounterTypes::Land if has_encounter_type?(EncounterTypes::Land)
if PBDayNight.isDay?(time)
ret = EncounterTypes::LandDay if has_encounter_type?(EncounterTypes::LandDay)
if PBDayNight.isMorning?(time)
ret = EncounterTypes::LandMorning if has_encounter_type?(EncounterTypes::LandMorning)
elsif PBDayNight.isAfternoon?(time)
ret = EncounterTypes::LandAfternoon if has_encounter_type?(EncounterTypes::LandAfternoon)
elsif PBDayNight.isEvening?(time)
ret = EncounterTypes::LandEvening if has_encounter_type?(EncounterTypes::LandEvening)
end
else
ret = EncounterTypes::LandNight if has_encounter_type?(EncounterTypes::LandNight)
end
if pbInBugContest? && has_encounter_type?(EncounterTypes::BugContest)
ret = EncounterTypes::BugContest
end
end end
end end
return ret return ret
@@ -277,8 +260,8 @@ class PokemonEncounters
# list for the given encounter type. Returns nil if there are none defined. # list for the given encounter type. Returns nil if there are none defined.
# A higher chance_rolls makes this method prefer rarer encounter slots. # A higher chance_rolls makes this method prefer rarer encounter slots.
def choose_wild_pokemon(enc_type, chance_rolls = 1) def choose_wild_pokemon(enc_type, chance_rolls = 1)
if enc_type < 0 || enc_type > EncounterTypes::Probabilities.length if !enc_type || !GameData::EncounterType.exists?(enc_type)
raise ArgumentError.new(_INTL("Encounter type out of range")) raise ArgumentError.new(_INTL("Encounter type {1} does not exist", enc_type))
end end
enc_list = @encounter_tables[enc_type] enc_list = @encounter_tables[enc_type]
return nil if !enc_list || enc_list.length == 0 return nil if !enc_list || enc_list.length == 0
@@ -348,8 +331,8 @@ class PokemonEncounters
# Used by the Bug Catching Contest to choose what the other participants # Used by the Bug Catching Contest to choose what the other participants
# caught. # caught.
def choose_wild_pokemon_for_map(map_ID, enc_type) def choose_wild_pokemon_for_map(map_ID, enc_type)
if enc_type < 0 || enc_type > EncounterTypes::Probabilities.length if !enc_type || !GameData::EncounterType.exists?(enc_type)
raise ArgumentError.new(_INTL("Encounter type out of range")) raise ArgumentError.new(_INTL("Encounter type {1} does not exist", enc_type))
end end
# Get the encounter table # Get the encounter table
encounter_data = GameData::Encounter.get(map_ID, $PokemonGlobal.encounter_version) encounter_data = GameData::Encounter.get(map_ID, $PokemonGlobal.encounter_version)
@@ -443,7 +426,7 @@ def pbEncounter(enc_type)
else else
pbWildBattle(encounter1[0], encounter1[1]) pbWildBattle(encounter1[0], encounter1[1])
end end
$PokemonTemp.encounterType = -1 $PokemonTemp.encounterType = nil
$PokemonTemp.forceSingleBattle = false $PokemonTemp.forceSingleBattle = false
EncounterModifier.triggerEncounterEnd EncounterModifier.triggerEncounterEnd
return true return true

View File

@@ -119,21 +119,18 @@ end
# method that will occur in the player's current position. # method that will occur in the player's current position.
def pbRoamingMethodAllowed(roamer_method) def pbRoamingMethodAllowed(roamer_method)
enc_type = $PokemonEncounters.encounter_type enc_type = $PokemonEncounters.encounter_type
type = GameData::EncounterType.get(enc_type).type
case roamer_method case roamer_method
when 0 # Any step-triggered method (except Bug Contest) when 0 # Any step-triggered method (except Bug Contest)
return EncounterTypes.is_normal_land_type?(enc_type) || return [:land, :cave, :water].include?(type)
EncounterTypes.is_cave_type?(enc_type) ||
EncounterTypes.is_water_type?(enc_type)
when 1 # Walking (except Bug Contest) when 1 # Walking (except Bug Contest)
return EncounterTypes.is_normal_land_type?(enc_type) || return [:land, :cave].include?(type)
EncounterTypes.is_cave_type?(enc_type)
when 2 # Surfing when 2 # Surfing
return EncounterTypes.is_water_type?(enc_type) return type == :water
when 3 # Fishing when 3 # Fishing
return EncounterTypes.is_fishing_type?(enc_type) return type == :fishing
when 4 # Water-based when 4 # Water-based
return EncounterTypes.is_water_type?(enc_type) || return [:water, :fishing].include?(type)
EncounterTypes.is_fishing_type?(enc_type)
end end
return false return false
end end

View File

@@ -545,7 +545,7 @@ def pbHeadbuttEffect(event=nil)
if rand(10)>=chance if rand(10)>=chance
pbMessage(_INTL("Nope. Nothing...")) pbMessage(_INTL("Nope. Nothing..."))
else else
enctype = (chance==1) ? EncounterTypes::HeadbuttLow : EncounterTypes::HeadbuttHigh enctype = (chance==1) ? :HeadbuttLow : :HeadbuttHigh
if !pbEncounter(enctype) if !pbEncounter(enctype)
pbMessage(_INTL("Nope. Nothing...")) pbMessage(_INTL("Nope. Nothing..."))
end end
@@ -592,8 +592,8 @@ HiddenMoveHandlers::UseMove.add(:HEADBUTT,proc { |move,pokemon|
# Rock Smash # Rock Smash
#=============================================================================== #===============================================================================
def pbRockSmashRandomEncounter def pbRockSmashRandomEncounter
if $PokemonEncounters.encounter_triggered?(EncounterTypes::RockSmash, false, false) if $PokemonEncounters.encounter_triggered?(:RockSmash, false, false)
pbEncounter(EncounterTypes::RockSmash) pbEncounter(:RockSmash)
end end
end end

View File

@@ -242,9 +242,9 @@ ItemHandlers::UseInField.add(:OLDROD,proc { |item|
pbMessage(_INTL("Can't use that here.")) pbMessage(_INTL("Can't use that here."))
next 0 next 0
end end
encounter = $PokemonEncounters.has_encounter_type?(EncounterTypes::OldRod) encounter = $PokemonEncounters.has_encounter_type?(:OldRod)
if pbFishing(encounter,1) if pbFishing(encounter,1)
pbEncounter(EncounterTypes::OldRod) pbEncounter(:OldRod)
end end
next 1 next 1
}) })
@@ -256,9 +256,9 @@ ItemHandlers::UseInField.add(:GOODROD,proc { |item|
pbMessage(_INTL("Can't use that here.")) pbMessage(_INTL("Can't use that here."))
next 0 next 0
end end
encounter = $PokemonEncounters.has_encounter_type?(EncounterTypes::GoodRod) encounter = $PokemonEncounters.has_encounter_type?(:GoodRod)
if pbFishing(encounter,2) if pbFishing(encounter,2)
pbEncounter(EncounterTypes::GoodRod) pbEncounter(:GoodRod)
end end
next 1 next 1
}) })
@@ -270,9 +270,9 @@ ItemHandlers::UseInField.add(:SUPERROD,proc { |item|
pbMessage(_INTL("Can't use that here.")) pbMessage(_INTL("Can't use that here."))
next 0 next 0
end end
encounter = $PokemonEncounters.has_encounter_type?(EncounterTypes::SuperRod) encounter = $PokemonEncounters.has_encounter_type?(:SuperRod)
if pbFishing(encounter,3) if pbFishing(encounter,3)
pbEncounter(EncounterTypes::SuperRod) pbEncounter(:SuperRod)
end end
next 1 next 1
}) })

View File

@@ -254,20 +254,11 @@ def pbEncounterSpecies(phonenum)
encounter_data = GameData::Encounter.get(phonenum[6], $PokemonGlobal.encounter_version) encounter_data = GameData::Encounter.get(phonenum[6], $PokemonGlobal.encounter_version)
return "" if !encounter_data return "" if !encounter_data
enc_tables = encounter_data.types enc_tables = encounter_data.types
species = pbRandomEncounterSpecies(enc_tables[EncounterTypes::Land]) species = pbRandomEncounterSpecies(enc_tables[:Land])
if !species if !species
species = pbRandomEncounterSpecies(enc_tables[EncounterTypes::Cave]) species = pbRandomEncounterSpecies(enc_tables[:Cave])
if !species if !species
species = pbRandomEncounterSpecies(enc_tables[EncounterTypes::LandDay]) species = pbRandomEncounterSpecies(enc_tables[:Water])
if !species
species = pbRandomEncounterSpecies(enc_tables[EncounterTypes::LandMorning])
if !species
species = pbRandomEncounterSpecies(enc_tables[EncounterTypes::LandNight])
if !species
species = pbRandomEncounterSpecies(enc_tables[EncounterTypes::Water])
end
end
end
end end
end end
return "" if !species return "" if !species

View File

@@ -150,7 +150,7 @@ end
# Event handlers # Event handlers
################################################################################ ################################################################################
EncounterModifier.register(proc { |encounter| EncounterModifier.register(proc { |encounter|
if !EncounterTypes.is_normal_land_type?($PokemonTemp.encounterType) || if GameData::EncounterType.get($PokemonTemp.encounterType).type != :land ||
$PokemonGlobal.bicycle || $PokemonGlobal.partner $PokemonGlobal.bicycle || $PokemonGlobal.partner
pbPokeRadarCancel pbPokeRadarCancel
next encounter next encounter

View File

@@ -279,11 +279,9 @@ class PokemonPokedexInfo_Scene
def pbFindEncounter(enc_types, species) def pbFindEncounter(enc_types, species)
return false if !enc_types return false if !enc_types
enc_types.each do |enc_type| enc_types.each_value do |slots|
next if !enc_type next if !slots
enc_type.each do |slot| slots.each { |slot| return true if GameData::Species.get(slot[1]).species == species }
return true if GameData::Species.get(slot[1]).species == species
end
end end
return false return false
end end

View File

@@ -105,9 +105,9 @@ class BugContestState
end end
end end
end end
enctype=EncounterTypes::BugContest enctype = :BugContest
if !$PokemonEncounters.map_has_encounter_type?(@contestMap, enctype) if !$PokemonEncounters.map_has_encounter_type?(@contestMap, enctype)
enctype=EncounterTypes::Land enctype = :Land
end end
for cont in @contestants for cont in @contestants
enc=$PokemonEncounters.choose_wild_pokemon_for_map(@contestMap,enctype) enc=$PokemonEncounters.choose_wild_pokemon_for_map(@contestMap,enctype)

View File

@@ -201,7 +201,7 @@ DebugMenuCommands.register("testwildbattle", {
level = pbMessageChooseNumber(_INTL("Set the wild {1}'s level.", level = pbMessageChooseNumber(_INTL("Set the wild {1}'s level.",
GameData::Species.get(species).name), params) GameData::Species.get(species).name), params)
if level > 0 if level > 0
$PokemonTemp.encounterType = -1 $PokemonTemp.encounterType = nil
pbWildBattle(species, level) pbWildBattle(species, level)
end end
end end
@@ -231,7 +231,7 @@ DebugMenuCommands.register("testwildbattleadvanced", {
next next
end end
setBattleRule(sprintf("%dv%d", size0, pkmn.length)) setBattleRule(sprintf("%dv%d", size0, pkmn.length))
$PokemonTemp.encounterType = -1 $PokemonTemp.encounterType = nil
pbWildBattleCore(*pkmn) pbWildBattleCore(*pkmn)
break break
elsif pkmnCmd == pkmnCmds.length - 2 # Set player side size elsif pkmnCmd == pkmnCmds.length - 2 # Set player side size

View File

@@ -48,8 +48,8 @@ def pbEncountersEditor
:id => key, :id => key,
:map => new_map_ID, :map => new_map_ID,
:version => new_version, :version => new_version,
:step_chances => [], :step_chances => {},
:types => [] :types => {}
} }
GameData::Encounter.register(encounter_hash) GameData::Encounter.register(encounter_hash)
maps.push([new_map_ID, new_version]) maps.push([new_map_ID, new_version])
@@ -73,21 +73,23 @@ def pbEncountersEditor
if GameData::Encounter.exists?(new_map_ID, new_version) if GameData::Encounter.exists?(new_map_ID, new_version)
pbMessage(_INTL("A set of encounters for map {1} version {2} already exists.", new_map_ID, new_version)) pbMessage(_INTL("A set of encounters for map {1} version {2} already exists.", new_map_ID, new_version))
else else
types = []
GameData::Encounter.get(this_set[0], this_set[1]).types.each_with_index do |enc_type, i|
next if !enc_type
types[i] = []
enc_type.each { |slot| types[i].push(slot.clone) }
end
# Construct encounter hash # Construct encounter hash
key = sprintf("%s_%d", new_map_ID, new_version).to_sym key = sprintf("%s_%d", new_map_ID, new_version).to_sym
encounter_hash = { encounter_hash = {
:id => key, :id => key,
:map => new_map_ID, :map => new_map_ID,
:version => new_version, :version => new_version,
:step_chances => GameData::Encounter.get(this_set[0], this_set[1]).step_chances.clone, :step_chances => {},
:types => types :types => {}
} }
GameData::Encounter.get(this_set[0], this_set[1]).step_chances.each do |type, value|
encounter_hash[:step_chances][type] = value
end
GameData::Encounter.get(this_set[0], this_set[1]).types.each do |type, slots|
next if !type || !slots || slots.length == 0
encounter_hash[:types][type] = []
slots.each { |slot| encounter_hash[:types][type].push(slot.clone) }
end
GameData::Encounter.register(encounter_hash) GameData::Encounter.register(encounter_hash)
maps.push([new_map_ID, new_version]) maps.push([new_map_ID, new_version])
maps.sort! { |a, b| (a[0] == b[0]) ? a[1] <=> b[1] : a[0] <=> b[0] } maps.sort! { |a, b| (a[0] == b[0]) ? a[1] <=> b[1] : a[0] <=> b[0] }
@@ -142,10 +144,10 @@ def pbEncounterMapVersionEditor(enc_data)
commands.push(_INTL("Map ID={1}", enc_data.map)) commands.push(_INTL("Map ID={1}", enc_data.map))
end end
commands.push(_INTL("Version={1}", enc_data.version)) commands.push(_INTL("Version={1}", enc_data.version))
enc_data.types.each_with_index do |enc_type, i| enc_data.types.each do |enc_type, slots|
next if !enc_type next if !enc_type || !slots || slots.length == 0
commands.push(_INTL("{1} (x{2})", EncounterTypes::Names[i], enc_type.length)) commands.push(_INTL("{1} (x{2})", enc_type.to_s, slots.length))
enc_types.push(i) enc_types.push(enc_type)
end end
commands.push(_INTL("[Add new encounter type]")) commands.push(_INTL("[Add new encounter type]"))
need_refresh = false need_refresh = false
@@ -182,16 +184,16 @@ def pbEncounterMapVersionEditor(enc_data)
elsif ret == commands.length - 1 # Add new encounter type elsif ret == commands.length - 1 # Add new encounter type
new_type_commands = [] new_type_commands = []
new_types = [] new_types = []
EncounterTypes::Names.each_with_index do |new_type, i| GameData::EncounterType.each do |enc|
next if enc_data.types[i] next if enc_data.types[enc.id]
new_type_commands.push(new_type) new_type_commands.push(enc.real_name)
new_types.push(i) new_types.push(enc.id)
end end
if new_type_commands.length > 0 if new_type_commands.length > 0
chosen_type_cmd = pbShowCommands(nil, new_type_commands, -1) chosen_type_cmd = pbShowCommands(nil, new_type_commands, -1)
if chosen_type_cmd >= 0 if chosen_type_cmd >= 0
new_type = new_types[chosen_type_cmd] new_type = new_types[chosen_type_cmd]
enc_data.step_chances[new_type] = 0 enc_data.step_chances[new_type] = GameData::EncounterType.get(new_type).trigger_chance
enc_data.types[new_type] = [] enc_data.types[new_type] = []
pbEncounterTypeEditor(enc_data, new_type) pbEncounterTypeEditor(enc_data, new_type)
enc_types.push(new_type) enc_types.push(new_type)
@@ -210,10 +212,10 @@ def pbEncounterMapVersionEditor(enc_data)
when 1 # Copy when 1 # Copy
new_type_commands = [] new_type_commands = []
new_types = [] new_types = []
EncounterTypes::Names.each_with_index do |new_type, i| GameData::EncounterType.each do |enc|
next if enc_data.types[i] next if enc_data.types[enc.id]
new_type_commands.push(new_type) new_type_commands.push(enc.real_name)
new_types.push(i) new_types.push(enc.id)
end end
if new_type_commands.length > 0 if new_type_commands.length > 0
chosen_type_cmd = pbMessage(_INTL("Choose an encounter type to copy to."), chosen_type_cmd = pbMessage(_INTL("Choose an encounter type to copy to."),
@@ -222,7 +224,7 @@ def pbEncounterMapVersionEditor(enc_data)
new_type = new_types[chosen_type_cmd] new_type = new_types[chosen_type_cmd]
enc_data.step_chances[new_type] = enc_data.step_chances[this_type] enc_data.step_chances[new_type] = enc_data.step_chances[this_type]
enc_data.types[new_type] = [] enc_data.types[new_type] = []
enc_data.types[this_type].each { |enc| enc_data.types[new_type].push(enc.clone) } enc_data.types[this_type].each { |slot| enc_data.types[new_type].push(slot.clone) }
enc_types.push(new_type) enc_types.push(new_type)
ret = enc_types.sort.index(new_type) + 2 ret = enc_types.sort.index(new_type) + 2
need_refresh = true need_refresh = true
@@ -231,9 +233,9 @@ def pbEncounterMapVersionEditor(enc_data)
pbMessage(_INTL("There are no unused encounter types to copy to.")) pbMessage(_INTL("There are no unused encounter types to copy to."))
end end
when 2 # Delete when 2 # Delete
if pbConfirmMessage(_INTL("Delete the encounter type {1}?", EncounterTypes::Names[this_type])) if pbConfirmMessage(_INTL("Delete the encounter type {1}?", GameData::EncounterType.get(this_type).real_name))
enc_data.step_chances[this_type] = nil enc_data.step_chances.delete(this_type)
enc_data.types[this_type] = nil enc_data.types.delete(this_type)
need_refresh = true need_refresh = true
end end
end end
@@ -258,9 +260,10 @@ def pbEncounterTypeEditor(enc_data, enc_type)
need_refresh = true need_refresh = true
loop do loop do
if need_refresh if need_refresh
enc_type_name = GameData::EncounterType.get(enc_type).real_name
commands.clear commands.clear
commands.push(_INTL("Step chance={1}%", enc_data.step_chances[enc_type] || 0)) commands.push(_INTL("Step chance={1}%", enc_data.step_chances[enc_type] || 0))
commands.push(_INTL("Encounter type={1}", EncounterTypes::Names[enc_type])) commands.push(_INTL("Encounter type={1}", enc_type_name))
if enc_data.types[enc_type] && enc_data.types[enc_type].length > 0 if enc_data.types[enc_type] && enc_data.types[enc_type].length > 0
enc_data.types[enc_type].each do |slot| enc_data.types[enc_type].each do |slot|
commands.push(EncounterSlotProperty.format(slot)) commands.push(EncounterSlotProperty.format(slot))
@@ -281,24 +284,24 @@ def pbEncounterTypeEditor(enc_data, enc_type)
new_type_commands = [] new_type_commands = []
new_types = [] new_types = []
chosen_type_cmd = 0 chosen_type_cmd = 0
EncounterTypes::Names.each_with_index do |type_name, i| GameData::EncounterType.each do |enc|
next if enc_data.types[i] && i != enc_type next if enc_data.types[enc.id] && enc.id != enc_type
new_type_commands.push(type_name) new_type_commands.push(enc.real_name)
new_types.push(i) new_types.push(enc.id)
chosen_type_cmd = new_type_commands.length - 1 if i == enc_type chosen_type_cmd = new_type_commands.length - 1 if enc.id == enc_type
end end
chosen_type_cmd = pbShowCommands(nil, new_type_commands, -1, chosen_type_cmd) chosen_type_cmd = pbShowCommands(nil, new_type_commands, -1, chosen_type_cmd)
if chosen_type_cmd >= 0 && new_types[chosen_type_cmd] != enc_type if chosen_type_cmd >= 0 && new_types[chosen_type_cmd] != enc_type
new_type = new_types[chosen_type_cmd] new_type = new_types[chosen_type_cmd]
enc_data.step_chances[new_type] = enc_data.step_chances[enc_type] enc_data.step_chances[new_type] = enc_data.step_chances[enc_type]
enc_data.step_chances[enc_type] = nil enc_data.step_chances.delete(enc_type)
enc_data.types[new_type] = enc_data.types[enc_type] enc_data.types[new_type] = enc_data.types[enc_type]
enc_data.types[enc_type] = nil enc_data.types.delete(enc_type)
enc_type = new_type enc_type = new_type
need_refresh = true need_refresh = true
end end
elsif ret == commands.length - 1 # Add new encounter slot elsif ret == commands.length - 1 # Add new encounter slot
new_slot_data = EncounterSlotProperty.set(EncounterTypes::Names[enc_type], nil) new_slot_data = EncounterSlotProperty.set(enc_type_name, nil)
if new_slot_data if new_slot_data
enc_data.types[enc_type].push(new_slot_data) enc_data.types[enc_type].push(new_slot_data)
need_refresh = true need_refresh = true
@@ -307,7 +310,7 @@ def pbEncounterTypeEditor(enc_data, enc_type)
case pbShowCommands(nil, [_INTL("Edit"), _INTL("Copy"), _INTL("Delete"), _INTL("Cancel")], 4) case pbShowCommands(nil, [_INTL("Edit"), _INTL("Copy"), _INTL("Delete"), _INTL("Cancel")], 4)
when 0 # Edit when 0 # Edit
old_slot_data = enc_data.types[enc_type][ret - 2] old_slot_data = enc_data.types[enc_type][ret - 2]
new_slot_data = EncounterSlotProperty.set(EncounterTypes::Names[enc_type], old_slot_data.clone) new_slot_data = EncounterSlotProperty.set(enc_type_name, old_slot_data.clone)
if new_slot_data && new_slot_data != old_slot_data if new_slot_data && new_slot_data != old_slot_data
enc_data.types[enc_type][ret - 2] = new_slot_data enc_data.types[enc_type][ret - 2] = new_slot_data
need_refresh = true need_refresh = true

View File

@@ -876,17 +876,17 @@ module Compiler
encounter_hash = nil encounter_hash = nil
step_chances = nil step_chances = nil
need_step_chances = false # Not needed for new format only need_step_chances = false # Not needed for new format only
probabilities = nil probabilities = nil # Not needed for new format only
current_type = -1 current_type = nil
expected_lines = 0 expected_lines = 0
max_level = GameData::GrowthRate.max_level max_level = GameData::GrowthRate.max_level
pbCompilerEachPreppedLine("PBS/encounters.txt") { |line, line_no| pbCompilerEachPreppedLine("PBS/encounters.txt") { |line, line_no|
next if line.length == 0 next if line.length == 0
if expected_lines > 0 && line[/^\d+,/] && new_format # Species line if expected_lines > 0 && line[/^\d+,/] && new_format # Species line (new format)
values = line.split(',') values = line.split(',').collect! { |v| v.strip }
if !values || values.length < 3 if !values || values.length < 3
raise _INTL("Expected a species entry line for encounter type {1} for map '{2}', got \"{3}\" instead.\r\n{4}", raise _INTL("Expected a species entry line for encounter type {1} for map '{2}', got \"{3}\" instead.\r\n{4}",
EncounterTypes::Names[current_type], encounter_hash[:map], line, FileLineData.linereport) GameData::EncounterType.get(current_type).real_name, encounter_hash[:map], line, FileLineData.linereport)
end end
values = pbGetCsvRecord(line, line_no, [0, "vevV", nil, :Species]) values = pbGetCsvRecord(line, line_no, [0, "vevV", nil, :Species])
values[3] = values[2] if !values[3] values[3] = values[2] if !values[3]
@@ -898,11 +898,11 @@ module Compiler
raise _INTL("Minimum level is greater than maximum level: {1}\r\n{2}", line, FileLineData.linereport) raise _INTL("Minimum level is greater than maximum level: {1}\r\n{2}", line, FileLineData.linereport)
end end
encounter_hash[:types][current_type].push(values) encounter_hash[:types][current_type].push(values)
elsif expected_lines > 0 && !new_format # Expect a species line and nothing else elsif expected_lines > 0 && !new_format # Expect a species line and nothing else (old format)
values = line.split(',') values = line.split(',').collect! { |v| v.strip }
if !values || values.length < 2 if !values || values.length < 2
raise _INTL("Expected a species entry line for encounter type {1} for map '{2}', got \"{3}\" instead.\r\n{4}", raise _INTL("Expected a species entry line for encounter type {1} for map '{2}', got \"{3}\" instead.\r\n{4}",
EncounterTypes::Names[current_type], encounter_hash[:map], line, FileLineData.linereport) GameData::EncounterType.get(current_type).real_name, encounter_hash[:map], line, FileLineData.linereport)
end end
values = pbGetCsvRecord(line, line_no, [0, "evV", :Species]) values = pbGetCsvRecord(line, line_no, [0, "evV", :Species])
values[2] = values[1] if !values[2] values[2] = values[1] if !values[2]
@@ -921,26 +921,25 @@ module Compiler
raise _INTL("Can't mix old and new formats.\r\n{1}", FileLineData.linereport) raise _INTL("Can't mix old and new formats.\r\n{1}", FileLineData.linereport)
end end
new_format = true new_format = true
values = $~[1].split(',') values = $~[1].split(',').collect! { |v| v.strip.to_i }
values.collect! { |v| v.strip.to_i }
values[1] = 0 if !values[1] || values[1] == "" values[1] = 0 if !values[1] || values[1] == ""
map_number = values[0] map_number = values[0]
map_version = values[1] map_version = values[1]
# Add map encounter's data to records # Add map encounter's data to records
if encounter_hash if encounter_hash
encounter_hash[:types].each do |encounters| encounter_hash[:types].each_value do |slots|
next if !encounters || encounters.length == 0 next if !slots || slots.length == 0
encounters.each_with_index do |enc, i| slots.each_with_index do |slot, i|
next if !enc next if !slot
encounters.each_with_index do |other_enc, j| slots.each_with_index do |other_slot, j|
next if i == j || !other_enc next if i == j || !other_slot
next if enc[1] != other_enc[1] || enc[2] != other_enc[2] || enc[3] != other_enc[3] next if slot[1] != other_slot[1] || slot[2] != other_slot[2] || slot[3] != other_slot[3]
enc[0] += other_enc[0] slot[0] += other_slot[0]
encounters[j] = nil slots[j] = nil
end end
end end
encounters.compact! slots.compact!
encounters.sort! { |a, b| (a[0] == b[0]) ? a[1].to_s <=> b[1].to_s : b[0] <=> a[0] } slots.sort! { |a, b| (a[0] == b[0]) ? a[1].to_s <=> b[1].to_s : b[0] <=> a[0] }
end end
GameData::Encounter.register(encounter_hash) GameData::Encounter.register(encounter_hash)
end end
@@ -949,16 +948,16 @@ module Compiler
if GameData::Encounter::DATA[key] if GameData::Encounter::DATA[key]
raise _INTL("Encounters for map '{1}' are defined twice.\r\n{2}", map_number, FileLineData.linereport) raise _INTL("Encounters for map '{1}' are defined twice.\r\n{2}", map_number, FileLineData.linereport)
end end
step_chances = [] step_chances = {}
# Construct encounter hash # Construct encounter hash
encounter_hash = { encounter_hash = {
:id => key, :id => key,
:map => map_number, :map => map_number,
:version => map_version, :version => map_version,
:step_chances => step_chances, :step_chances => step_chances,
:types => [] :types => {}
} }
current_type = -1 current_type = nil
need_step_chances = true need_step_chances = true
expected_lines = 0 expected_lines = 0
elsif line[/^(\d+)$/] # Map ID line (old format) elsif line[/^(\d+)$/] # Map ID line (old format)
@@ -969,19 +968,19 @@ module Compiler
map_number = $~[1].to_i map_number = $~[1].to_i
# Add map encounter's data to records # Add map encounter's data to records
if encounter_hash if encounter_hash
encounter_hash[:types].each do |encounters| encounter_hash[:types].each_value do |slots|
next if !encounters || encounters.length == 0 next if !slots || slots.length == 0
encounters.each_with_index do |enc, i| slots.each_with_index do |slot, i|
next if !enc next if !slot
encounters.each_with_index do |other_enc, j| slots.each_with_index do |other_slot, j|
next if i == j || !other_enc next if i == j || !other_slot
next if enc[1] != other_enc[1] || enc[2] != other_enc[2] || enc[3] != other_enc[3] next if slot[1] != other_slot[1] || slot[2] != other_slot[2] || slot[3] != other_slot[3]
enc[0] += other_enc[0] slot[0] += other_slot[0]
encounters[j] = nil slots[j] = nil
end end
end end
encounters.compact! slots.compact!
encounters.sort! { |a, b| (a[0] == b[0]) ? a[1].to_s <=> b[1].to_s : b[0] <=> a[0] } slots.sort! { |a, b| (a[0] == b[0]) ? a[1].to_s <=> b[1].to_s : b[0] <=> a[0] }
end end
GameData::Encounter.register(encounter_hash) GameData::Encounter.register(encounter_hash)
end end
@@ -990,16 +989,16 @@ module Compiler
if GameData::Encounter::DATA[key] if GameData::Encounter::DATA[key]
raise _INTL("Encounters for map '{1}' are defined twice.\r\n{2}", map_number, FileLineData.linereport) raise _INTL("Encounters for map '{1}' are defined twice.\r\n{2}", map_number, FileLineData.linereport)
end end
step_chances = EncounterTypes::Chances_Per_Step.clone step_chances = {}
# Construct encounter hash # Construct encounter hash
encounter_hash = { encounter_hash = {
:id => key, :id => key,
:map => map_number, :map => map_number,
:version => 0, :version => 0,
:step_chances => step_chances, :step_chances => step_chances,
:types => [] :types => {}
} }
current_type = -1 current_type = nil
need_step_chances = true need_step_chances = true
elsif !encounter_hash # File began with something other than a map ID line elsif !encounter_hash # File began with something other than a map ID line
raise _INTL("Expected a map number, got \"{1}\" instead.\r\n{2}", line, FileLineData.linereport) raise _INTL("Expected a map number, got \"{1}\" instead.\r\n{2}", line, FileLineData.linereport)
@@ -1010,50 +1009,49 @@ module Compiler
end end
need_step_chances = false need_step_chances = false
values = pbGetCsvRecord(line, line_no, [0, "vvv"]) values = pbGetCsvRecord(line, line_no, [0, "vvv"])
for type in 0...step_chances.length GameData::EncounterType.each do |enc_type|
next if EncounterTypes::Kinds[type] == 0 case enc_type.id
step_chances[type] = values[EncounterTypes::Kinds[type] - 1] when :land, :contest then step_chances[enc_type.id] = values[0]
when :cave then step_chances[enc_type.id] = values[1]
when :water then step_chances[enc_type.id] = values[2]
end
end end
else else
# Check if line is an encounter method name or not # Check if line is an encounter method name or not
values = line.split(',') values = line.split(',').collect! { |v| v.strip }
values.collect! { |v| v.strip } current_type = (values[0] && !values[0].empty?) ? values[0].to_sym : nil
current_type = findIndex(EncounterTypes::Names) { |val| val == values[0] } if current_type && GameData::EncounterType.exists?(current_type) # Start of a new encounter method
if current_type >= 0 # Start of a new encounter method
need_step_chances = false need_step_chances = false
if values[1] && !values[1].empty? step_chances[current_type] = values[1].to_i if values[1] && !values[1].empty?
step_chances[current_type] = values[1].to_i step_chances[current_type] ||= GameData::EncounterType.get(current_type).trigger_chance
elsif new_format probabilities = GameData::EncounterType.get(current_type).old_slots
step_chances[current_type] = 0
end
probabilities = EncounterTypes::Probabilities[current_type].clone
expected_lines = probabilities.length expected_lines = probabilities.length
encounter_hash[:types][current_type] = [] encounter_hash[:types][current_type] = []
else else
raise _INTL("Undefined encounter type \"{1}\" for map '{2}'.\r\n{2}", raise _INTL("Undefined encounter type \"{1}\" for map '{2}'.\r\n{3}",
line, encounter_hash[:map], FileLineData.linereport) line, encounter_hash[:map], FileLineData.linereport)
end end
end end
} }
if expected_lines > 0 && !new_format if expected_lines > 0 && !new_format
raise _INTL("Not enough encounter lines given for encounter type {1} for map '{2}' (expected {3}).\r\n{4}", raise _INTL("Not enough encounter lines given for encounter type {1} for map '{2}' (expected {3}).\r\n{4}",
EncounterTypes::Names[current_type], encounter_hash[:map], probabilities.length, FileLineData.linereport) GameData::EncounterType.get(current_type).real_name, encounter_hash[:map], probabilities.length, FileLineData.linereport)
end end
# Add last map's encounter data to records # Add last map's encounter data to records
if encounter_hash if encounter_hash
encounter_hash[:types].each do |encounters| encounter_hash[:types].each_value do |slots|
next if !encounters || encounters.length == 0 next if !slots || slots.length == 0
encounters.each_with_index do |enc, i| slots.each_with_index do |slot, i|
next if !enc next if !slot
encounters.each_with_index do |other_enc, j| slots.each_with_index do |other_slot, j|
next if i == j || !other_enc next if i == j || !other_slot
next if enc[1] != other_enc[1] || enc[2] != other_enc[2] || enc[3] != other_enc[3] next if slot[1] != other_slot[1] || slot[2] != other_slot[2] || slot[3] != other_slot[3]
enc[0] += other_enc[0] slot[0] += other_slot[0]
encounters[j] = nil slots[j] = nil
end end
end end
encounters.compact! slots.compact!
encounters.sort! { |a, b| (a[0] == b[0]) ? a[1].to_s <=> b[1].to_s : b[0] <=> a[0] } slots.sort! { |a, b| (a[0] == b[0]) ? a[1].to_s <=> b[1].to_s : b[0] <=> a[0] }
end end
GameData::Encounter.register(encounter_hash) GameData::Encounter.register(encounter_hash)
end end

View File

@@ -543,18 +543,18 @@ module Compiler
else else
f.write(sprintf("[%03d]%s\r\n", encounter_data.map, map_name)) f.write(sprintf("[%03d]%s\r\n", encounter_data.map, map_name))
end end
encounter_data.types.each_with_index do |entries, type| encounter_data.types.each do |type, slots|
next if !entries || entries.length == 0 next if !slots || slots.length == 0
if encounter_data.step_chances[type] && encounter_data.step_chances[type] > 0 if encounter_data.step_chances[type] && encounter_data.step_chances[type] > 0
f.write(sprintf("%s,%d\r\n", EncounterTypes::Names[type], encounter_data.step_chances[type])) f.write(sprintf("%s,%d\r\n", type.to_s, encounter_data.step_chances[type]))
else else
f.write(sprintf("%s\r\n", EncounterTypes::Names[type])) f.write(sprintf("%s\r\n", type.to_s))
end end
entries.each do |entry| slots.each do |slot|
if entry[2] == entry[3] if slot[2] == slot[3]
f.write(sprintf(" %d,%s,%d\r\n", entry[0], entry[1], entry[2])) f.write(sprintf(" %d,%s,%d\r\n", slot[0], slot[1], slot[2]))
else else
f.write(sprintf(" %d,%s,%d,%d\r\n", entry[0], entry[1], entry[2], entry[3])) f.write(sprintf(" %d,%s,%d,%d\r\n", slot[0], slot[1], slot[2], slot[3]))
end end
end end
end end