Class: PFM::Wild_Battle
- Defined in:
- scripts/01450 Systems/99991 Wild/00100 Wild Battle (manager).rb,
scripts/01450 Systems/99991 Wild/00101 Wild Battle (configuration).rb
Overview
The wild battle management
The main object is stored in $wild_battle and PFM.game_state.wild_battle
Constant Summary collapse
- WEAK_POKEMON_ABILITY =
List of ability that force strong Pokemon to battle (Intimidation / Regard vif)
%i[intimidate keen_eye]
- FISHING_BATTLES =
List of special wild battle that are actually fishing
%i[normal super mega]
- MAX_POKEMON_LEVEL_ABILITY =
List of ability giving the max level of the pokemon we can encounter
%i[hustle pressure vital_spirit]
- TOOL_MAPPING =
Mapping allowing to get the correct tool based on the input
{ normal: :OldRod, super: :GoodRod, mega: :SuperRod, rock: :RockSmash, headbutt: :HeadButt }
- FishIncRate =
Ability that increase the rate of any fishing rod # Glue / Ventouse
%i[sticky_hold suction_cups]
- CHANGE_POKEMON_CHANCE =
Hash describing which method to seek to change the Pokemon chances depending on the player's leading Pokemon's talent
{ keen_eye: :rate_intimidate_keen_eye, intimidate: :rate_intimidate_keen_eye, cute_charm: :rate_cute_charm, magnet_pull: :rate_magnet_pull, compound_eyes: :rate_compound_eyes, super_luck: :rate_compound_eyes, static: :rate_static, lightning_rod: :rate_static, flash_fire: :rate_flash_fire, synchronize: :rate_synchronize, storm_drain: :rate_storm_drain, harvest: :rate_harvest }
Instance Attribute Summary collapse
-
#game_state ⇒ PFM::GameState
Get the game state responsive of the whole game state.
-
#groups ⇒ Array<Studio::Group>
readonly
List of Remaining creature groups.
-
#roaming_pokemons ⇒ Array<PFM::Wild_RoamingInfo>
readonly
List of Roaming Pokemon.
Instance Method Summary collapse
-
#add_roaming_pokemon(chance, proc_id, pokemon_hash) ⇒ PFM::Pokemon
Add a roaming Pokemon.
-
#any_fish?(rod = :normal, start = false) ⇒ Boolean?
Test if there's any fish battle available and start it if asked.
-
#any_hidden_pokemon?(rod = :rock, start = false) ⇒ Boolean?
Test if there's any hidden battle available and start it if asked.
-
#available? ⇒ Boolean
Is a wild battle available ?.
-
#check_fishing_chances(type) ⇒ Boolean
Check if a Pokemon can be fished there with a specific fishing rod type.
-
#each_roaming_pokemon
yield a block on every available roaming Pokemon.
-
#init_battle(id, level = 70, *others)
Init a wild battle.
-
#initialize(game_state) ⇒ Wild_Battle
constructor
Create a new Wild_Battle manager.
-
#load_groups
Load the groups of Wild Pokemon (map change/ time change).
-
#on_map_viewed
Tell the roaming pokemon that the playe has look at their position.
-
#remove_roaming_pokemon(pokemon)
Remove a roaming Pokemon from the roaming Pokemon array.
-
#reset
Reset the wild battle.
-
#roaming?(pokemon) ⇒ Boolean
(also: #is_roaming?)
Test if a Pokemon is a roaming Pokemon (Usefull in battle).
-
#set(zone_type, tag, delta_level, vs_type, *data)
Define a group of remaining wild battle.
-
#setup(battle_id = 1) ⇒ Battle::Logic::BattleInfo?
Set the Battle::Info with the right information.
-
#start_battle(id, level = 70, *others, battle_id: 1)
Start a wild battle.
Constructor Details
#initialize(game_state) ⇒ Wild_Battle
Create a new Wild_Battle manager
32 33 34 35 36 37 |
# File 'scripts/01450 Systems/99991 Wild/00100 Wild Battle (manager).rb', line 32 def initialize(game_state) @roaming_pokemons = [] @forced_wild_battle = false @groups = [] @game_state = game_state end |
Instance Attribute Details
#game_state ⇒ PFM::GameState
Get the game state responsive of the whole game state
28 29 30 |
# File 'scripts/01450 Systems/99991 Wild/00100 Wild Battle (manager).rb', line 28 def game_state @game_state end |
#groups ⇒ Array<Studio::Group> (readonly)
List of Remaining creature groups
25 26 27 |
# File 'scripts/01450 Systems/99991 Wild/00100 Wild Battle (manager).rb', line 25 def groups @groups end |
#roaming_pokemons ⇒ Array<PFM::Wild_RoamingInfo> (readonly)
List of Roaming Pokemon
22 23 24 |
# File 'scripts/01450 Systems/99991 Wild/00100 Wild Battle (manager).rb', line 22 def roaming_pokemons @roaming_pokemons end |
Instance Method Details
#add_roaming_pokemon(chance, proc_id, pokemon_hash) ⇒ PFM::Pokemon
Add a roaming Pokemon
200 201 202 203 204 205 206 |
# File 'scripts/01450 Systems/99991 Wild/00100 Wild Battle (manager).rb', line 200 def add_roaming_pokemon(chance, proc_id, pokemon_hash) pokemon = ::PFM::Pokemon.generate_from_hash(pokemon_hash) PFM::Wild_RoamingInfo.unlock @roaming_pokemons << Wild_RoamingInfo.new(pokemon, chance, proc_id) PFM::Wild_RoamingInfo.lock return pokemon end |
#any_fish?(rod = :normal, start = false) ⇒ Boolean?
Test if there's any fish battle available and start it if asked.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'scripts/01450 Systems/99991 Wild/00100 Wild Battle (manager).rb', line 73 def any_fish?(rod = :normal, start = false) return false unless game_state.env.can_fish? system_tag = game_state.game_player.front_system_tag_db_symbol terrain_tag = game_state.game_player.front_terrain_tag tool = TOOL_MAPPING[rod] || :__undef__ current_group = @groups.find { |group| group.tool == tool && group.system_tag == system_tag && group.terrain_tag == terrain_tag } return false unless current_group if start @fish_battle = current_group if FISHING_BATTLES.include?(rod) @fished = true else @fished = false end return nil else return true end end |
#any_hidden_pokemon?(rod = :rock, start = false) ⇒ Boolean?
Test if there's any hidden battle available and start it if asked.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'scripts/01450 Systems/99991 Wild/00100 Wild Battle (manager).rb', line 99 def any_hidden_pokemon?(rod = :rock, start = false) system_tag = game_state.game_player.front_system_tag_db_symbol terrain_tag = game_state.game_player.front_terrain_tag tool = TOOL_MAPPING[rod] || :__undef__ current_group = @groups.find { |group| group.tool == tool && group.system_tag == system_tag && group.terrain_tag == terrain_tag } return false unless current_group if start @fish_battle = current_group @fished = false return nil else return true end end |
#available? ⇒ Boolean
Is a wild battle available ?
59 60 61 62 63 64 65 66 67 |
# File 'scripts/01450 Systems/99991 Wild/00100 Wild Battle (manager).rb', line 59 def available? return false if $scene.is_a?(Battle::Scene) return false if game_state.pokemon_alive == 0 return true if @fish_battle return true if roaming_battle_available? @forced_wild_battle = false return remaining_battle_available? end |
#check_fishing_chances(type) ⇒ Boolean
Check if a Pokemon can be fished there with a specific fishing rod type
220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'scripts/01450 Systems/99991 Wild/00100 Wild Battle (manager).rb', line 220 def check_fishing_chances(type) case type when :mega rate = 60 when :super rate = 45 else rate = 30 end rate *= 1.5 if FishIncRate.include?(creature_ability) return rate < rand(100) end |
#each_roaming_pokemon
yield a block on every available roaming Pokemon
234 235 236 237 238 |
# File 'scripts/01450 Systems/99991 Wild/00100 Wild Battle (manager).rb', line 234 def each_roaming_pokemon @roaming_pokemons.each do |roaming_info| yield(roaming_info.pokemon) end end |
#init_battle(id, level, *args) #init_battle(id, level, *args)
Does not start the battle
Init a wild battle
143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'scripts/01450 Systems/99991 Wild/00100 Wild Battle (manager).rb', line 143 def init_battle(id, level = 70, *others) if id.class == PFM::Pokemon @forced_wild_battle = [id, *others] else id = data_creature(id).id if id.is_a?(Symbol) @forced_wild_battle = [PFM::Pokemon.new(id, level)] 0.step(others.size - 1, 2) do |i| others[i] = data_creature(others[i]).id if others[i].is_a?(Symbol) @forced_wild_battle << PFM::Pokemon.new(others[i], others[i + 1]) end end end |
#load_groups
Load the groups of Wild Pokemon (map change/ time change)
51 52 53 54 55 |
# File 'scripts/01450 Systems/99991 Wild/00100 Wild Battle (manager).rb', line 51 def load_groups # @type [Array<Studio::Group>] groups = $env.get_current_zone_data.wild_groups.map { |group_name| data_group(group_name) } @groups = groups.select { |group| group.custom_conditions.reduce(true) { |prev, curr| curr.reduce_evaluate(prev) } } end |
#on_map_viewed
Tell the roaming pokemon that the playe has look at their position
241 242 243 244 245 |
# File 'scripts/01450 Systems/99991 Wild/00100 Wild Battle (manager).rb', line 241 def on_map_viewed @roaming_pokemons.each do |info| info.spotted = true end end |
#remove_roaming_pokemon(pokemon)
Remove a roaming Pokemon from the roaming Pokemon array
210 211 212 |
# File 'scripts/01450 Systems/99991 Wild/00100 Wild Battle (manager).rb', line 210 def remove_roaming_pokemon(pokemon) roaming_pokemons.delete_if { |i| i.pokemon == pokemon } end |
#reset
Reset the wild battle
40 41 42 43 44 45 46 47 48 |
# File 'scripts/01450 Systems/99991 Wild/00100 Wild Battle (manager).rb', line 40 def reset @groups&.clear @roaming_pokemons.each(&:update) @roaming_pokemons.delete_if(&:pokemon_dead?) PFM::Wild_RoamingInfo.lock # @forced_wild_battle=false @fished = false @fish_battle = nil end |
#roaming?(pokemon) ⇒ Boolean Also known as: is_roaming?
Test if a Pokemon is a roaming Pokemon (Usefull in battle)
190 191 192 |
# File 'scripts/01450 Systems/99991 Wild/00100 Wild Battle (manager).rb', line 190 def roaming?(pokemon) return roaming_pokemons.any? { |info| info.pokemon == pokemon } end |
#set(zone_type, tag, delta_level, vs_type, *data)
Define a group of remaining wild battle
184 185 186 |
# File 'scripts/01450 Systems/99991 Wild/00100 Wild Battle (manager).rb', line 184 def set(zone_type, tag, delta_level, vs_type, *data) raise 'This method is no longer supported' end |
#setup(battle_id = 1) ⇒ Battle::Logic::BattleInfo?
Set the Battle::Info with the right information
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'scripts/01450 Systems/99991 Wild/00100 Wild Battle (manager).rb', line 159 def setup(battle_id = 1) # If it was a forced battle return configure_battle(@forced_wild_battle, battle_id) if @forced_wild_battle # Security for when a Repel is used at the same time an encounter is happening return nil if PFM.game_state.repel_count > 0 return nil unless (group = current_selected_group) maxed = MAX_POKEMON_LEVEL_ABILITY.include?(creature_ability) && rand(100) < 50 all_creatures = (group.encounters * (group.is_double_battle ? 2 : 1)).map do |encounter| encounter.to_creature(maxed ? encounter.level_setup.range.end : nil) end creature_to_select = configure_creature(all_creatures) selected_creature = select_creature(group, creature_to_select) return configure_battle(selected_creature, battle_id) ensure @forced_wild_battle = false @fish_battle = nil end |
#start_battle(id, level, *args) #start_battle(id, level, *args)
Start a wild battle
126 127 128 129 130 131 |
# File 'scripts/01450 Systems/99991 Wild/00100 Wild Battle (manager).rb', line 126 def start_battle(id, level = 70, *others, battle_id: 1) init_battle(id, level, *others) Graphics.freeze $scene = Battle::Scene.new(setup(battle_id)) Yuki::FollowMe.set_battle_entry end |