Class: Battle::Logic::BattleInfo

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ BattleInfo

Create a new Battle Info

Parameters:

  • hash (Hash) (defaults to: {})

    basic info about the battle



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_moneyInteger

Get the additionnal money

Returns:



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_levelsArray<Array<Integer>>

Returns:



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

#bagsArray<Array<PFM::Bag>>

Returns List of the bags of the battlers according to the bank.

Returns:

  • (Array<Array<PFM::Bag>>)

    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_moneysArray<Array<Integer>>

Returns List of the base money of the battlers according to the bank.

Returns:

  • (Array<Array<Integer>>)

    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_bgmString

Get the battle bgm

Returns:



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_idInteger

Returns ID of the battle (for event loading).

Returns:

  • (Integer)

    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

#battlersArray<Array<String>>

Returns List of the battler (image) name of the battlers according to the bank.

Returns:

  • (Array<Array<String>>)

    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_pokemonPFM::PokemonBattler

Get the caught Pokemon

Returns:



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

#classesArray<Array<String>>

Returns List of the classes of the battlers according to the bank & their position.

Returns:

  • (Array<Array<String>>)

    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_textsArray<String>

Get the defeat text

Returns:



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

#fishingBoolean

Tell if the battle follows a fishing attempt

Returns:

  • (Boolean)


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_countInteger

Get the number of time the player tried to flee

Returns:



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_levelInteger?

Returns Maximum level allowed for the battle.

Returns:

  • (Integer, nil)

    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

#namesArray<Array<String>>

Returns List of the name of the battlers according to the bank & their position.

Returns:

  • (Array<Array<String>>)

    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

#partiesArray<Array<Array<PFM::Pokemon>>>

Returns List of the “Party” of the battlers according to the bank & their position.

Returns:

  • (Array<Array<Array<PFM::Pokemon>>>)

    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_coupleBoolean

Returns if the trainer battle is a “couple” battle.

Returns:

  • (Boolean)

    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_bgmString

Get the victory BGM

Returns:



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_textsArray<String>

Get the victory text

Returns:



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_typeInteger

Returns Number of Pokemon fighting at the same time.

Returns:

  • (Integer)

    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_reasonInteger

Returns Reason of the wild battle.

Returns:

  • (Integer)

    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

Parameters:

  • battle_info (BattleInfo)
  • bank (Integer)

    bank of the trainer

  • id_trainer (Integer)

    ID of the trainer in the database



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)

Parameters:

Returns:



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

Parameters:

Returns:



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

Parameters:

  • bank (Integer)

    bank where the party should be defined

  • party (Array<PFM::Pokemon>)

    Pokemon of the battler

  • name (String, nil) (defaults to: nil)

    name of the battler (don't set it if Wild Battle)

  • klass (String, nil) (defaults to: nil)

    name of the battler (don't set it if Wild Battle)

  • battler (String, nil) (defaults to: nil)

    name of the battler image (don't set it if Wild Battle)

  • bag (String, nil) (defaults to: nil)

    bag used by the party

  • base_money (Integer) (defaults to: nil)
  • ai_level (Integer) (defaults to: nil)


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

Parameters:

Returns:



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

Parameters:

Returns:



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

Returns:

  • (Boolean)


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

Parameters:

Returns:



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_infoArray

Return the basic info about the player

Returns:

  • (Array)


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

Parameters:



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

Returns:

  • (Boolean)


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

Parameters:

Returns:



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

Parameters:

Returns:



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