Class: Game_Party

Inherits:
Game_Unit show all
Defined in:
Game_Party.rb

Overview

** Game_Party


This class handles parties. Information such as gold and items is included.

Instances of this class are referenced by $game_party.

Constant Summary

ABILITY_ENCOUNTER_HALF =

  • Constants


0
ABILITY_ENCOUNTER_NONE =

halve encounters

1
ABILITY_CANCEL_SURPRISE =

disable encounters

2
ABILITY_RAISE_PREEMPTIVE =

disable surprise

3
ABILITY_GOLD_DOUBLE =

increase preemptive strike rate

4
ABILITY_DROP_ITEM_DOUBLE =

double money earned

5

Instance Attribute Summary (collapse)

Attributes inherited from Game_Unit

#in_battle

Instance Method Summary (collapse)

Methods inherited from Game_Unit

#agi, #alive_members, #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_Party) initialize


  • Object Initialization




27
28
29
30
31
32
33
34
35
36
# File 'Game_Party.rb', line 27

def initialize
  super
  @gold = 0
  @steps = 0
  @last_item = Game_BaseItem.new
  @menu_actor_id = 0
  @target_actor_id = 0
  @actors = []
  init_all_items
end

Instance Attribute Details

- (Object) gold (readonly)


  • Public Instance Variables




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

def gold
  @gold
end

- (Object) last_item (readonly)

for cursor memorization: item



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

def last_item
  @last_item
end

- (Object) steps (readonly)

number of steps



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

def steps
  @steps
end

Instance Method Details

- (Object) add_actor(actor_id)


  • Add an Actor




172
173
174
175
176
# File 'Game_Party.rb', line 172

def add_actor(actor_id)
  @actors.push(actor_id) unless @actors.include?(actor_id)
  $game_player.refresh
  $game_map.need_refresh = true
end

- (Boolean) all_dead?


  • Determine if Everyone is Dead


Returns:

  • (Boolean)


301
302
303
# File 'Game_Party.rb', line 301

def all_dead?
  super && ($game_party.in_battle || members.size > 0)
end

- (Object) all_items


  • Get Array of All Item Objects




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

def all_items
  items + equip_items
end

- (Object) all_members


  • Get All Members




60
61
62
# File 'Game_Party.rb', line 60

def all_members
  @actors.collect {|id| $game_actors[id] }
end

- (Object) armors


  • Get Armor Object Array




96
97
98
# File 'Game_Party.rb', line 96

def armors
  @armors.keys.sort.collect {|id| $data_armors[id] }
end

- (Object) battle_members


  • Get Battle Members




66
67
68
# File 'Game_Party.rb', line 66

def battle_members
  all_members[0, max_battle_members].select {|actor| actor.exist? }
end

- (Boolean) cancel_surprise?


  • Disable Surprise?


Returns:

  • (Boolean)


386
387
388
# File 'Game_Party.rb', line 386

def cancel_surprise?
  party_ability(ABILITY_CANCEL_SURPRISE)
end

- (Object) characters_for_savefile


  • Character Image Information for Save File Display




360
361
362
363
364
# File 'Game_Party.rb', line 360

def characters_for_savefile
  battle_members.collect do |actor|
    [actor.character_name, actor.character_index]
  end
end

- (Object) consume_item(item)


  • Consume Items

    If the specified object is a consumable item, the number in investory
    will be reduced by 1.



282
283
284
285
# File 'Game_Party.rb', line 282

def consume_item(item)
  lose_item(item, 1) if item.is_a?(RPG::Item) && item.consumable
  $game_variables[187] = item.id if item.is_a?(RPG::Item)
end

- (Object) discard_members_equip(item, amount)


  • Discard Members' Equipment




261
262
263
264
265
266
267
268
269
# File 'Game_Party.rb', line 261

def discard_members_equip(item, amount)
  n = amount
  members.each do |actor|
    while n > 0 && actor.equips.include?(item)
      actor.discard_equip(item)
      n -= 1
    end
  end
end

- (Boolean) drop_item_double?


  • Double Item Acquisition Rate?


Returns:

  • (Boolean)


404
405
406
# File 'Game_Party.rb', line 404

def drop_item_double?
  party_ability(ABILITY_DROP_ITEM_DOUBLE)
end

- (Boolean) encounter_half?


  • Halve Encounters?


Returns:

  • (Boolean)


374
375
376
# File 'Game_Party.rb', line 374

def encounter_half?
  party_ability(ABILITY_ENCOUNTER_HALF)
end

- (Boolean) encounter_none?


  • Disable Encounters?


Returns:

  • (Boolean)


380
381
382
# File 'Game_Party.rb', line 380

def encounter_none?
  party_ability(ABILITY_ENCOUNTER_NONE)
end

- (Object) equip_items


  • Get Array of All Equipment Objects




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

def equip_items
  weapons + armors
end

- (Object) exists


  • Determine Existence




48
49
50
# File 'Game_Party.rb', line 48

def exists
  !@actors.empty?
end

- (Object) gain_gold(amount)


  • Increase Gold




188
189
190
# File 'Game_Party.rb', line 188

def gain_gold(amount)
  @gold = [[@gold + amount, 0].max, max_gold].min
end

- (Object) gain_item(item, amount, include_equip = false)


  • Increase/Decrease Items

    include_equip : Include equipped items



246
247
248
249
250
251
252
253
254
255
256
257
# File 'Game_Party.rb', line 246

def gain_item(item, amount, include_equip = false)
  container = item_container(item.class)
  return unless container
  last_number = item_number(item)
  new_number = last_number + amount
  container[item.id] = [[new_number, 0].max, max_item_number(item)].min
  container.delete(item.id) if container[item.id] == 0
  if include_equip && new_number < 0
    discard_members_equip(item, -new_number)
  end
  $game_map.need_refresh = true
end

- (Boolean) gold_double?


  • Double Money Earned?


Returns:

  • (Boolean)


398
399
400
# File 'Game_Party.rb', line 398

def gold_double?
  party_ability(ABILITY_GOLD_DOUBLE)
end

- (Boolean) has_item?(item, include_equip = false)


  • Determine Item Possession Status

    include_equip : Include equipped items

Returns:

  • (Boolean)


232
233
234
235
# File 'Game_Party.rb', line 232

def has_item?(item, include_equip = false)
  return true if item_number(item) > 0
  return include_equip ? members_equip_include?(item) : false
end

- (Object) highest_level


  • Get Highest Level of Party Members




166
167
168
# File 'Game_Party.rb', line 166

def highest_level
  lv = members.collect {|actor| actor.level }.max
end

- (Object) increase_steps


  • Increase Steps




206
207
208
# File 'Game_Party.rb', line 206

def increase_steps
  @steps += 1
end

- (Object) init_all_items


  • Initialize All Item Lists




40
41
42
43
44
# File 'Game_Party.rb', line 40

def init_all_items
  @items = {}
  @weapons = {}
  @armors = {}
end

- (Boolean) inputable?


  • Determine Command Inputability During Battle


Returns:

  • (Boolean)


295
296
297
# File 'Game_Party.rb', line 295

def inputable?
  members.any? {|actor| actor.inputable? }
end

- (Object) item_container(item_class)


  • Get Container Object Corresponding to Item Class




114
115
116
117
118
119
# File 'Game_Party.rb', line 114

def item_container(item_class)
  return @items   if item_class == RPG::Item
  return @weapons if item_class == RPG::Weapon
  return @armors  if item_class == RPG::Armor
  return nil
end

- (Boolean) item_max?(item)


  • Determine if Maximum Number of Items Are Possessed


Returns:

  • (Boolean)


225
226
227
# File 'Game_Party.rb', line 225

def item_max?(item)
  item_number(item) >= max_item_number(item)
end

- (Object) item_number(item)


  • Get Number of Items Possessed




212
213
214
215
# File 'Game_Party.rb', line 212

def item_number(item)
  container = item_container(item.class)
  container ? container[item.id] || 0 : 0
end

- (Object) items


  • Get Item Object Array




84
85
86
# File 'Game_Party.rb', line 84

def items
  @items.keys.sort.collect {|id| $data_items[id] }
end

- (Object) leader


  • Get Leader




78
79
80
# File 'Game_Party.rb', line 78

def leader
  battle_members[0]
end

- (Object) lose_gold(amount)


  • Decrease Gold




194
195
196
# File 'Game_Party.rb', line 194

def lose_gold(amount)
  gain_gold(-amount)
end

- (Object) lose_item(item, amount, include_equip = false)


  • Lose Items

    include_equip : Include equipped items



274
275
276
# File 'Game_Party.rb', line 274

def lose_item(item, amount, include_equip = false)
  gain_item(item, -amount, include_equip)
end

- (Object) max_battle_members


  • Get Maximum Number of Battle Members




72
73
74
# File 'Game_Party.rb', line 72

def max_battle_members
  return 4
end

- (Object) max_gold


  • Get Maximum Value of Gold




200
201
202
# File 'Game_Party.rb', line 200

def max_gold
  return 99999999
end

- (Object) max_item_number(item)


  • Get Maximum Number of Items Possessed




219
220
221
# File 'Game_Party.rb', line 219

def max_item_number(item)
  return 99
end

- (Object) members


  • Get Members




54
55
56
# File 'Game_Party.rb', line 54

def members
  in_battle ? battle_members : all_members
end

- (Boolean) members_equip_include?(item)


  • Determine if Specified Item Is Included in Members' Equipment


Returns:

  • (Boolean)


239
240
241
# File 'Game_Party.rb', line 239

def members_equip_include?(item)
  members.any? {|actor| actor.equips.include?(item) }
end

  • Get Actor Selected on Menu Screen




313
314
315
# File 'Game_Party.rb', line 313

def menu_actor
  $game_actors[@menu_actor_id] || members[0]
end

  • Set Actor Selected on Menu Screen




319
320
321
# File 'Game_Party.rb', line 319

def menu_actor=(actor)
  @menu_actor_id = actor.id
end

  • Select Next Actor on Menu Screen




325
326
327
328
329
# File 'Game_Party.rb', line 325

def menu_actor_next
  index = members.index(menu_actor) || -1
  index = (index + 1) % members.size
  self.menu_actor = members[index]
end

  • Select Previous Actor on Menu Screen




333
334
335
336
337
# File 'Game_Party.rb', line 333

def menu_actor_prev
  index = members.index(menu_actor) || 1
  index = (index + members.size - 1) % members.size
  self.menu_actor = members[index]
end

- (Object) name


  • Get Party Name

    If there is only one, returns the actor's name.
    If there are more, returns "XX's Party".



131
132
133
134
135
# File 'Game_Party.rb', line 131

def name
  return ""           if battle_members.size == 0
  return leader.name  if battle_members.size == 1
  return sprintf(Vocab::PartyName, leader.name)
end

- (Object) on_player_walk


  • Processing Performed When Player Takes 1 Step




307
308
309
# File 'Game_Party.rb', line 307

def on_player_walk
  members.each {|actor| actor.on_player_walk }
end

- (Object) party_ability(ability_id)


  • Determine Party Ability




368
369
370
# File 'Game_Party.rb', line 368

def party_ability(ability_id)
  battle_members.any? {|actor| actor.party_ability(ability_id) }
end

- (Boolean) raise_preemptive?


  • Increase Preemptive Strike Rate?


Returns:

  • (Boolean)


392
393
394
# File 'Game_Party.rb', line 392

def raise_preemptive?
  party_ability(ABILITY_RAISE_PREEMPTIVE)
end

- (Object) rate_preemptive(troop_agi)


  • Calculate Probability of Preemptive Attack




410
411
412
# File 'Game_Party.rb', line 410

def rate_preemptive(troop_agi)
  (agi >= troop_agi ? 0.05 : 0.03) * (raise_preemptive? ? 4 : 1)
end

- (Object) rate_surprise(troop_agi)


  • Calculate Probability of Surprise




416
417
418
# File 'Game_Party.rb', line 416

def rate_surprise(troop_agi)
  cancel_surprise? ? 0 : (agi >= troop_agi ? 0.03 : 0.05)
end

- (Object) remove_actor(actor_id)


  • Remove Actor




180
181
182
183
184
# File 'Game_Party.rb', line 180

def remove_actor(actor_id)
  @actors.delete(actor_id)
  $game_player.refresh
  $game_map.need_refresh = true
end

- (Object) setup_battle_test


  • Set Up Battle Test




139
140
141
142
# File 'Game_Party.rb', line 139

def setup_battle_test
  setup_battle_test_members
  setup_battle_test_items
end

- (Object) setup_battle_test_items


  • Set Up Items for Battle Test




158
159
160
161
162
# File 'Game_Party.rb', line 158

def setup_battle_test_items
  $data_items.each do |item|
    gain_item(item, max_item_number(item)) if item && !item.name.empty?
  end
end

- (Object) setup_battle_test_members


  • Battle Test Party Setup




146
147
148
149
150
151
152
153
154
# File 'Game_Party.rb', line 146

def setup_battle_test_members
  $data_system.test_battlers.each do |battler|
    actor = $game_actors[battler.actor_id]
    actor.change_level(battler.level, false)
    actor.init_equips(battler.equips)
    actor.recover_all
    add_actor(actor.id)
  end
end

- (Object) setup_starting_members


  • Initial Party Setup




123
124
125
# File 'Game_Party.rb', line 123

def setup_starting_members
  @actors = $data_system.party_members.clone
end

- (Object) swap_order(index1, index2)


  • Change Order




353
354
355
356
# File 'Game_Party.rb', line 353

def swap_order(index1, index2)
  @actors[index1], @actors[index2] = @actors[index2], @actors[index1]
  $game_player.refresh
end

- (Object) target_actor


  • Get Actor Targeted by Skill/Item Use




341
342
343
# File 'Game_Party.rb', line 341

def target_actor
  $game_actors[@target_actor_id] || members[0]
end

- (Object) target_actor=(actor)


  • Set Actor Targeted by Skill/Item Use




347
348
349
# File 'Game_Party.rb', line 347

def target_actor=(actor)
  @target_actor_id = actor.id
end

- (Boolean) usable?(item)


  • Determine Skill/Item Usability


Returns:

  • (Boolean)


289
290
291
# File 'Game_Party.rb', line 289

def usable?(item)
  members.any? {|actor| actor.usable?(item) }
end

- (Object) weapons


  • Get Weapon Object Array




90
91
92
# File 'Game_Party.rb', line 90

def weapons
  @weapons.keys.sort.collect {|id| $data_weapons[id] }
end