Class: Game_Troop

Inherits:
Game_Unit show all
Defined in:
Game_Troop.rb

Overview

** Game_Troop


This class handles enemy groups and battle-related data. Also performs

battle events. The instance of this class is referenced by $game_troop.

Constant Summary

LETTER_TABLE_HALF =

  • Characters to be added to the end of enemy names


[' A',' B',' C',' D',' E',' F',' G',' H',' I',' J',
' K',' L',' M',' N',' O',' P',' Q',' R',' S',' T',
' U',' V',' W',' X',' Y',' Z']
LETTER_TABLE_FULL =
['','','','','','','','','','',
'','','','','','','','','','',
'','','','','','']

Instance Attribute Summary (collapse)

Attributes inherited from Game_Unit

#in_battle

Instance Method Summary (collapse)

Methods inherited from Game_Unit

#agi, #alive_members, #all_dead?, #clear_actions, #clear_results, #dead_members, #make_actions, #movable_members, #on_battle_end, #on_battle_start, #random_dead_target, #random_target, #smooth_dead_target, #smooth_target, #substitute_battler, #tgr_sum

Constructor Details

- (Game_Troop) initialize


  • Object Initialization




29
30
31
32
33
34
35
# File 'Game_Troop.rb', line 29

def initialize
  super
  @screen = Game_Screen.new
  @interpreter = Game_Interpreter.new
  @event_flags = {}
  clear
end

Instance Attribute Details

- (Object) event_flags (readonly)

battle event executed flag



23
24
25
# File 'Game_Troop.rb', line 23

def event_flags
  @event_flags
end

- (Object) interpreter (readonly)

battle event interpreter



22
23
24
# File 'Game_Troop.rb', line 22

def interpreter
  @interpreter
end

- (Object) name_counts (readonly)

hash for enemy name appearance



25
26
27
# File 'Game_Troop.rb', line 25

def name_counts
  @name_counts
end

- (Object) screen (readonly)


  • Public Instance Variables




21
22
23
# File 'Game_Troop.rb', line 21

def screen
  @screen
end

- (Object) turn_count (readonly)

number of turns



24
25
26
# File 'Game_Troop.rb', line 24

def turn_count
  @turn_count
end

Instance Method Details

- (Object) clear


  • Clear




45
46
47
48
49
50
51
52
# File 'Game_Troop.rb', line 45

def clear
  @screen.clear
  @interpreter.clear
  @event_flags.clear
  @enemies = []
  @turn_count = 0
  @names_count = {}
end

- (Boolean) conditions_met?(page)


  • Determine if Battle Event (Page) Conditions Are Met


Returns:

  • (Boolean)


127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'Game_Troop.rb', line 127

def conditions_met?(page)
  c = page.condition
  if !c.turn_ending && !c.turn_valid && !c.enemy_valid &&
     !c.actor_valid && !c.switch_valid
    return false      # Conditions not set: not executed
  end
  if @event_flags[page]
    return false      # Executed
  end
  if c.turn_ending    # At turn end
    return false unless BattleManager.turn_end?
  end
  if c.turn_valid     # Number of turns
    n = @turn_count
    a = c.turn_a
    b = c.turn_b
    return false if (b == 0 && n != a)
    return false if (b > 0 && (n < 1 || n < a || n % b != a % b))
  end
  if c.enemy_valid    # Enemy
    enemy = $game_troop.members[c.enemy_index]
    return false if enemy == nil
    return false if enemy.hp_rate * 100 > c.enemy_hp
  end
  if c.actor_valid    # Actor
    actor = $game_actors[c.actor_id]
    return false if actor == nil 
    return false if actor.hp_rate * 100 > c.actor_hp
  end
  if c.switch_valid   # Switch
    return false if !$game_switches[c.switch_id]
  end
  return true         # Condition met
end

- (Object) enemy_names


  • Get Enemy Name Array

    For display at start of battle. Overlapping names are removed.



115
116
117
118
119
120
121
122
123
# File 'Game_Troop.rb', line 115

def enemy_names
  names = []
  members.each do |enemy|
    next unless enemy.alive?
    next if names.include?(enemy.original_name)
    names.push(enemy.original_name)
  end
  names
end

- (Object) exp_total


  • Calculate Total Experience




184
185
186
# File 'Game_Troop.rb', line 184

def exp_total
  dead_members.inject(0) {|r, enemy| r += enemy.exp }
end

- (Object) gold_rate


  • Get Multiplier for Gold




196
197
198
# File 'Game_Troop.rb', line 196

def gold_rate
  $game_party.gold_double? ? 2 : 1
end

- (Object) gold_total


  • Calculate Total Gold




190
191
192
# File 'Game_Troop.rb', line 190

def gold_total
  dead_members.inject(0) {|r, enemy| r += enemy.gold } * gold_rate
end

- (Object) increase_turn


  • Increase Turns




177
178
179
180
# File 'Game_Troop.rb', line 177

def increase_turn
  troop.pages.each {|page| @event_flags[page] = false if page.span == 1 }
  @turn_count += 1
end

- (Object) init_screen_tone


  • Initialize Screen Tone




80
81
82
# File 'Game_Troop.rb', line 80

def init_screen_tone
  @screen.start_tone_change($game_map.screen.tone, 0) if $game_map
end

- (Object) letter_table


  • Get Text Table to Place Behind Enemy Name




102
103
104
# File 'Game_Troop.rb', line 102

def letter_table
  $game_system.japanese? ? LETTER_TABLE_FULL : LETTER_TABLE_HALF
end

- (Object) make_drop_items


  • Create Array of Dropped Items




202
203
204
# File 'Game_Troop.rb', line 202

def make_drop_items
  dead_members.inject([]) {|r, enemy| r += enemy.make_drop_items }
end

- (Object) make_unique_names


  • Add letters (ABC, etc) to enemy characters with the same name




86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'Game_Troop.rb', line 86

def make_unique_names
  members.each do |enemy|
    next unless enemy.alive?
    next unless enemy.letter.empty?
    n = @names_count[enemy.original_name] || 0
    enemy.letter = letter_table[n % letter_table.size]
    @names_count[enemy.original_name] = n + 1
  end
  members.each do |enemy|
    n = @names_count[enemy.original_name] || 0
    enemy.plural = true if n >= 2
  end
end

- (Object) members


  • Get Members




39
40
41
# File 'Game_Troop.rb', line 39

def members
  @enemies
end

- (Object) setup(troop_id)


  • Setup




62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'Game_Troop.rb', line 62

def setup(troop_id)
  clear
  @troop_id = troop_id
  @enemies = []
  troop.members.each do |member|
    next unless $data_enemies[member.enemy_id]
    enemy = Game_Enemy.new(@enemies.size, member.enemy_id)
    enemy.hide if member.hidden
    enemy.screen_x = member.x
    enemy.screen_y = member.y
    @enemies.push(enemy)
  end
  init_screen_tone
  make_unique_names
end

- (Object) setup_battle_event


  • Battle Event Setup




164
165
166
167
168
169
170
171
172
173
# File 'Game_Troop.rb', line 164

def setup_battle_event
  return if @interpreter.running?
  return if @interpreter.setup_reserved_common_event
  troop.pages.each do |page|
    next unless conditions_met?(page)
    @interpreter.setup(page.list)
    @event_flags[page] = true if page.span <= 1
    return
  end
end

- (Object) troop


  • Get Troop Objects




56
57
58
# File 'Game_Troop.rb', line 56

def troop
  $data_troops[@troop_id]
end

- (Object) update


  • Frame Update




108
109
110
# File 'Game_Troop.rb', line 108

def update
  @screen.update
end