Class: Battle::Logic::BattleInfo
- Defined in:
- scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb
Overview
Class describing the informations about the battle
Constant Summary collapse
- MONEY_ITEMS =
List of item decupling money
%i[amulet_coin luck_incense]
- AI_LEVELS_BASE_MONEY =
List of base money giving AI levels (if strictly below the value)
[16, 20, 36, 48, 80, 100, 200, Float::INFINITY]
Instance Attribute Summary collapse
-
#additional_money ⇒ Integer
Get the additionnal money.
- #ai_levels ⇒ Array<Array<Integer>>
-
#bags ⇒ Array<Array<PFM::Bag>>
List of the bags of the battlers according to the bank.
-
#base_moneys ⇒ Array<Array<Integer>>
List of the base money of the battlers according to the bank.
-
#battle_bgm ⇒ String
Get the battle bgm.
-
#battle_id ⇒ Integer
ID of the battle (for event loading).
-
#battlers ⇒ Array<Array<String>>
List of the battler (image) name of the battlers according to the bank.
-
#caught_pokemon ⇒ PFM::PokemonBattler
Get the caught Pokemon.
-
#classes ⇒ Array<Array<String>>
List of the classes of the battlers according to the bank & their position.
-
#defeat_texts ⇒ Array<String>
Get the defeat text.
-
#fishing ⇒ Boolean
Tell if the battle follows a fishing attempt.
-
#flee_attempt_count ⇒ Integer
Get the number of time the player tried to flee.
-
#max_level ⇒ Integer?
Maximum level allowed for the battle.
-
#names ⇒ Array<Array<String>>
List of the name of the battlers according to the bank & their position.
-
#parties ⇒ Array<Array<Array<PFM::Pokemon>>>
List of the “Party” of the battlers according to the bank & their position.
-
#trainer_is_couple ⇒ Boolean
If the trainer battle is a “couple” battle.
-
#victory_bgm ⇒ String
Get the victory BGM.
-
#victory_texts ⇒ Array<String>
Get the victory text.
-
#vs_type ⇒ Integer
Number of Pokemon fighting at the same time.
-
#wild_battle_reason ⇒ Integer
Reason of the wild battle.
Class Method Summary collapse
-
.add_trainer(battle_info, bank, id_trainer)
Add a trainer to the battle_info object.
-
.ai_level(base_money) ⇒ Integer
Guess the AI level based on the base money (or a variable).
-
.from_old_psdk_settings(id_trainer1, id_trainer2 = 0, id_friend = 0) ⇒ Battle::Logic::BattleInfo
Configure a PSDK battle from old settings.
Instance Method Summary collapse
-
#add_party(bank, party, name = nil, klass = nil, battler = nil, bag = nil, base_money = nil, ai_level = nil, victory_text = nil, defeat_text = nil)
Add a party to a bank.
-
#bag(battler) ⇒ PFM::Bag
Get the bag of a battler.
-
#base_money(battler) ⇒ Integer
Get the base money of a battler.
-
#disallow_exp? ⇒ Boolean
Tell if the battle allow exp.
-
#initialize(hash = {}) ⇒ BattleInfo
constructor
Create a new Battle Info.
-
#party(battler) ⇒ Array<PFM::Pokemon>
Get the party of a battler.
-
#player_basic_info ⇒ Array
Return the basic info about the player.
-
#total_money(logic)
Get the total money.
-
#trainer_battle? ⇒ Boolean
Tell if the battle is a trainer battle.
-
#trainer_class(battler) ⇒ String
Get the trainer class of a battler.
-
#trainer_name(battler) ⇒ String
Get the trainer name of a battler.
Constructor Details
#initialize(hash = {}) ⇒ BattleInfo
Create a new Battle Info
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 60 def initialize(hash = {}) @names = hash[:names] || [[], []] @classes = hash[:classes] || [[], []] @battlers = hash[:battlers] || [[], []] @bags = hash[:bags] || [[], []] @parties = hash[:parties] || [[], []] @ai_levels = hash[:ai_levels] || [[], []] @base_moneys = hash[:base_moneys] || [[], []] @max_level = hash[:max_level] || nil @vs_type = hash[:vs_type] || 1 @trainer_is_couple = hash[:couple] || false @battle_id = hash[:battle_id] || -1 @flee_attempt_count = 0 @fishing = hash[:fishing] || false @victory_bgm = hash[:victory_bgm] || guess_victory_bgm @battle_bgm = hash[:battle_bgm] || guess_battle_bgm @additional_money = 0 @victory_texts = hash[:victory_texts] || [] @defeat_texts = hash [:defeat_texts] || [] end |
Instance Attribute Details
#additional_money ⇒ Integer
Get the additionnal money
50 51 52 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 50 def additional_money @additional_money end |
#ai_levels ⇒ Array<Array<Integer>>
20 21 22 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 20 def ai_levels @ai_levels end |
#bags ⇒ Array<Array<PFM::Bag>>
Returns List of the bags of the battlers according to the bank.
16 17 18 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 16 def bags @bags end |
#base_moneys ⇒ Array<Array<Integer>>
Returns List of the base money of the battlers according to the bank.
22 23 24 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 22 def base_moneys @base_moneys end |
#battle_bgm ⇒ String
Get the battle bgm
47 48 49 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 47 def battle_bgm @battle_bgm end |
#battle_id ⇒ Integer
Returns ID of the battle (for event loading).
32 33 34 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 32 def battle_id @battle_id end |
#battlers ⇒ Array<Array<String>>
Returns List of the battler (image) name of the battlers according to the bank.
14 15 16 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 14 def battlers @battlers end |
#caught_pokemon ⇒ PFM::PokemonBattler
Get the caught Pokemon
41 42 43 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 41 def caught_pokemon @caught_pokemon end |
#classes ⇒ Array<Array<String>>
Returns List of the classes of the battlers according to the bank & their position.
12 13 14 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 12 def classes @classes end |
#defeat_texts ⇒ Array<String>
Get the defeat text
56 57 58 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 56 def defeat_texts @defeat_texts end |
#fishing ⇒ Boolean
Tell if the battle follows a fishing attempt
38 39 40 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 38 def fishing @fishing end |
#flee_attempt_count ⇒ Integer
Get the number of time the player tried to flee
35 36 37 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 35 def flee_attempt_count @flee_attempt_count end |
#max_level ⇒ Integer?
Returns Maximum level allowed for the battle.
24 25 26 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 24 def max_level @max_level end |
#names ⇒ Array<Array<String>>
Returns List of the name of the battlers according to the bank & their position.
10 11 12 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 10 def names @names end |
#parties ⇒ Array<Array<Array<PFM::Pokemon>>>
Returns List of the “Party” of the battlers according to the bank & their position.
18 19 20 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 18 def parties @parties end |
#trainer_is_couple ⇒ Boolean
Returns if the trainer battle is a “couple” battle.
30 31 32 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 30 def trainer_is_couple @trainer_is_couple end |
#victory_bgm ⇒ String
Get the victory BGM
44 45 46 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 44 def victory_bgm @victory_bgm end |
#victory_texts ⇒ Array<String>
Get the victory text
53 54 55 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 53 def victory_texts @victory_texts end |
#vs_type ⇒ Integer
Returns Number of Pokemon fighting at the same time.
26 27 28 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 26 def vs_type @vs_type end |
#wild_battle_reason ⇒ Integer
Returns Reason of the wild battle.
28 29 30 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 28 def wild_battle_reason @wild_battle_reason end |
Class Method Details
.add_trainer(battle_info, bank, id_trainer)
Add a trainer to the battle_info object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 111 def add_trainer(battle_info, bank, id_trainer) trainer = data_trainer(id_trainer) klass = trainer.class_name battler = trainer.battler name = trainer.name party = trainer.party.map(&:to_creature) bag = PFM::Bag.new trainer.bag_entries.each { |bag_entry| bag.add_item(bag_entry[:dbSymbol], bag_entry[:amount]) } battle_info.add_party(bank, party, name, klass, battler, bag, nil, trainer.ai) # We add the base money only for the enemy side (prevents the ally to have a base money) battle_info.base_moneys[bank] << trainer.base_money if bank == 1 battle_info.trainer_is_couple = battle_info.parties[1].size == 1 if bank == 1 && trainer.vs_type == 2 battle_info.battle_id = trainer.battle_id if trainer.battle_id != 0 end |
.ai_level(base_money) ⇒ Integer
Guess the AI level based on the base money (or a variable)
129 130 131 132 133 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 129 def ai_level(base_money) return $game_variables[Yuki::Var::AI_LEVEL] if $game_variables[Yuki::Var::AI_LEVEL] > 0 return AI_LEVELS_BASE_MONEY.find_index { |base_money_limit| base_money < base_money_limit } || 1 end |
.from_old_psdk_settings(id_trainer1, id_trainer2 = 0, id_friend = 0) ⇒ Battle::Logic::BattleInfo
Configure a PSDK battle from old settings
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 93 def from_old_psdk_settings(id_trainer1, id_trainer2 = 0, id_friend = 0) battle_info = BattleInfo.new # Add Player party battle_info.add_party(0, *battle_info.player_basic_info) # Add 1st enemy add_trainer(battle_info, 1, id_trainer1) # Add 2nd enemy add_trainer(battle_info, 1, id_trainer2) if id_trainer2 != 0 # Add friend add_trainer(battle_info, 0, id_friend) if id_friend != 0 battle_info.vs_type = 2 if battle_info.trainer_is_couple || battle_info.parties[1]&.size == 2 return battle_info end |
Instance Method Details
#add_party(bank, party, name = nil, klass = nil, battler = nil, bag = nil, base_money = nil, ai_level = nil, victory_text = nil, defeat_text = nil)
Add a party to a bank
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 159 def add_party(bank, party, name = nil, klass = nil, battler = nil, bag = nil, base_money = nil, ai_level = nil, victory_text = nil, defeat_text = nil) @parties[bank] ||= [] @parties[bank] << party @names[bank] ||= [] @names[bank] << name if name @classes[bank] ||= [] @classes[bank] << klass if klass @battlers[bank] ||= [] @battlers[bank] << battler if battler @bags[bank] ||= [] @bags[bank] << (bag || PFM::Bag.new) @base_moneys[bank] ||= [] @base_moneys[bank] << base_money if base_money @ai_levels[bank] ||= [] @ai_levels[bank] << ai_level if bank == 1 @victory_texts << victory_text @defeat_texts << defeat_text end end |
#bag(battler) ⇒ PFM::Bag
Get the bag of a battler
197 198 199 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 197 def bag(battler) return @bags[battler.bank][party_index(battler)] end |
#base_money(battler) ⇒ Integer
Get the base money of a battler
213 214 215 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 213 def base_money(battler) return @base_moneys.dig(battler.bank, party_index(battler)) || 1 end |
#disallow_exp? ⇒ Boolean
Tell if the battle allow exp
83 84 85 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 83 def disallow_exp? return @max_level || $game_switches[Yuki::Sw::BT_NoExp] end |
#party(battler) ⇒ Array<PFM::Pokemon>
Get the party of a battler
204 205 206 207 208 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 204 def party(battler) return @parties[battler.bank][party_index(battler)] if battler.bank @parties.find { |parties| parties.any? { |party| party.include?(battler.original) } }&.find { |party| party.include?(battler.original) } end |
#player_basic_info ⇒ Array
Return the basic info about the player
144 145 146 147 148 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 144 def player_basic_info battler_name = $game_actors[1].battler_name battler_name = $game_player.charset_base if !battler_name || battler_name.empty? return $actors, $trainer.name, data_trainer(0).class_name, battler_name, $bag end |
#total_money(logic)
Get the total money
219 220 221 222 223 224 225 226 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 219 def total_money(logic) # @type [Array<PFM::PokemonBattler>] pokemon = $game_temp.vs_type.times.map { |i| logic.battler(1, i) }.compact money = additional_money + pokemon.reduce(0) { |acc, curr| curr.level * base_money(curr) + acc } money *= 2 if logic.terrain_effects.has?(:happy_hour) money *= 2 if $game_temp.vs_type.times.any? { |i| MONEY_ITEMS.include?(logic.battler(0, i)&.item_db_symbol) } return money end |
#trainer_battle? ⇒ Boolean
Tell if the battle is a trainer battle
138 139 140 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 138 def trainer_battle? !@names[1].empty? end |
#trainer_class(battler) ⇒ String
Get the trainer class of a battler
190 191 192 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 190 def trainer_class(battler) return @classes[battler.bank][party_index(battler)] end |
#trainer_name(battler) ⇒ String
Get the trainer name of a battler
183 184 185 |
# File 'scripts/01600 Alpha 25 Battle Engine/00200 Battle_Logic/00001 Battle_Info.rb', line 183 def trainer_name(battler) return @names[battler.bank][party_index(battler)] end |