Class: Scene_Battle

Inherits:
Scene_Base show all
Defined in:
Scene_Battle.rb

Overview

** Scene_Battle


This class performs battle screen processing.

Instance Method Summary (collapse)

Methods inherited from Scene_Base

#check_gameover, #create_main_viewport, #dispose_all_windows, #dispose_main_viewport, #fadeout_all, #main, #perform_transition, #return_scene, #scene_changing?, #transition_speed, #update_all_windows

Instance Method Details

- (Object) abs_wait(duration)


  • Wait (No Fast Forward)




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

def abs_wait(duration)
  duration.times {|i| update_for_wait }
end

- (Object) abs_wait_short


  • Short Wait (No Fast Forward)




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

def abs_wait_short
  abs_wait(15)
end

- (Object) all_battle_members


  • Get All Battle Members Including Enemies and Allies




507
508
509
# File 'Scene_Battle.rb', line 507

def all_battle_members
  $game_party.members + $game_troop.members
end

- (Object) apply_item_effects(target, item)


  • Apply Skill/Item Effect




604
605
606
607
608
# File 'Scene_Battle.rb', line 604

def apply_item_effects(target, item)
  target.item_apply(@subject, item)
  refresh_status
  @log_window.display_action_results(target, item)
end

- (Object) apply_substitute(target, item)


  • Apply Substitute




631
632
633
634
635
636
637
638
639
640
# File 'Scene_Battle.rb', line 631

def apply_substitute(target, item)
  if check_substitute(target, item)
    substitute = target.friends_unit.substitute_battler
    if substitute && target != substitute
      @log_window.display_substitute(substitute, target)
      return substitute
    end
  end
  target
end

- (Object) battle_start


  • Battle Start




473
474
475
476
477
# File 'Scene_Battle.rb', line 473

def battle_start
  BattleManager.battle_start
  process_event
  start_party_command_selection
end

- (Object) check_substitute(target, item)


  • Check Substitute Condition




644
645
646
# File 'Scene_Battle.rb', line 644

def check_substitute(target, item)
  target.hp < target.mhp / 4 && (!item || !item.certain?)
end

- (Object) command_attack


  • Attack

    Command




337
338
339
340
# File 'Scene_Battle.rb', line 337

def command_attack
  BattleManager.actor.input.set_attack
  select_enemy_selection
end

- (Object) command_escape


  • Escape

    Command




323
324
325
# File 'Scene_Battle.rb', line 323

def command_escape
  turn_start unless BattleManager.process_escape
end

- (Object) command_fight


  • Fight

    Command




317
318
319
# File 'Scene_Battle.rb', line 317

def command_fight
  next_command
end

- (Object) command_guard


  • Guard

    Command




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

def command_guard
  BattleManager.actor.input.set_guard
  next_command
end

- (Object) command_item


  • Item

    Command




360
361
362
363
# File 'Scene_Battle.rb', line 360

def command_item
  @item_window.refresh
  @item_window.show.activate
end

- (Object) command_skill


  • Skill

    Command




344
345
346
347
348
349
# File 'Scene_Battle.rb', line 344

def command_skill
  @skill_window.actor = BattleManager.actor
  @skill_window.stype_id = @actor_command_window.current_ext
  @skill_window.refresh
  @skill_window.show.activate
end

- (Object) create_actor_command_window


  • Create Actor Commands Window




222
223
224
225
226
227
228
229
230
231
# File 'Scene_Battle.rb', line 222

def create_actor_command_window
  @actor_command_window = Window_ActorCommand.new
  @actor_command_window.viewport = @info_viewport
  @actor_command_window.set_handler(:attack, method(:command_attack))
  @actor_command_window.set_handler(:skill,  method(:command_skill))
  @actor_command_window.set_handler(:guard,  method(:command_guard))
  @actor_command_window.set_handler(:item,   method(:command_item))
  @actor_command_window.set_handler(:cancel, method(:prior_command))
  @actor_command_window.x = Graphics.width
end

- (Object) create_actor_window


  • Create Actor Window




258
259
260
261
262
# File 'Scene_Battle.rb', line 258

def create_actor_window
  @actor_window = Window_BattleActor.new(@info_viewport)
  @actor_window.set_handler(:ok,     method(:on_actor_ok))
  @actor_window.set_handler(:cancel, method(:on_actor_cancel))
end

- (Object) create_all_windows


  • Create All Windows




157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'Scene_Battle.rb', line 157

def create_all_windows
  create_message_window
  create_scroll_text_window
  create_log_window
  create_status_window
  create_info_viewport
  create_party_command_window
  create_actor_command_window
  create_help_window
  create_skill_window
  create_item_window
  create_actor_window
  create_enemy_window
end

- (Object) create_enemy_window


  • Create Enemy Window




266
267
268
269
270
# File 'Scene_Battle.rb', line 266

def create_enemy_window
  @enemy_window = Window_BattleEnemy.new(@info_viewport)
  @enemy_window.set_handler(:ok,     method(:on_enemy_ok))
  @enemy_window.set_handler(:cancel, method(:on_enemy_cancel))
end

- (Object) create_help_window


  • Create Help Window




235
236
237
238
# File 'Scene_Battle.rb', line 235

def create_help_window
  @help_window = Window_Help.new
  @help_window.visible = false
end

- (Object) create_info_viewport


  • Create Information Display Viewport




201
202
203
204
205
206
207
208
# File 'Scene_Battle.rb', line 201

def create_info_viewport
  @info_viewport = Viewport.new
  @info_viewport.rect.y = Graphics.height - @status_window.height
  @info_viewport.rect.height = @status_window.height
  @info_viewport.z = 100
  @info_viewport.ox = 64
  @status_window.viewport = @info_viewport
end

- (Object) create_item_window


  • Create Item Window




250
251
252
253
254
# File 'Scene_Battle.rb', line 250

def create_item_window
  @item_window = Window_BattleItem.new(@help_window, @info_viewport)
  @item_window.set_handler(:ok,     method(:on_item_ok))
  @item_window.set_handler(:cancel, method(:on_item_cancel))
end

- (Object) create_log_window


  • Create Log Window




186
187
188
189
190
# File 'Scene_Battle.rb', line 186

def create_log_window
  @log_window = Window_BattleLog.new
  @log_window.method_wait = method(:wait)
  @log_window.method_wait_for_effect = method(:wait_for_effect)
end

- (Object) create_message_window


  • Create Message Window




174
175
176
# File 'Scene_Battle.rb', line 174

def create_message_window
  @message_window = Window_Message.new
end

- (Object) create_party_command_window


  • Create Party Commands Window




212
213
214
215
216
217
218
# File 'Scene_Battle.rb', line 212

def create_party_command_window
  @party_command_window = Window_PartyCommand.new
  @party_command_window.viewport = @info_viewport
  @party_command_window.set_handler(:fight,  method(:command_fight))
  @party_command_window.set_handler(:escape, method(:command_escape))
  @party_command_window.unselect
end

- (Object) create_scroll_text_window


  • Create Scrolling Text Window




180
181
182
# File 'Scene_Battle.rb', line 180

def create_scroll_text_window
  @scroll_text_window = Window_ScrollText.new
end

- (Object) create_skill_window


  • Create Skill Window




242
243
244
245
246
# File 'Scene_Battle.rb', line 242

def create_skill_window
  @skill_window = Window_BattleSkill.new(@help_window, @info_viewport)
  @skill_window.set_handler(:ok,     method(:on_skill_ok))
  @skill_window.set_handler(:cancel, method(:on_skill_cancel))
end

- (Object) create_spriteset


  • Create Sprite Set




145
146
147
# File 'Scene_Battle.rb', line 145

def create_spriteset
  @spriteset = Spriteset_Battle.new
end

- (Object) create_status_window


  • Create Status Window




194
195
196
197
# File 'Scene_Battle.rb', line 194

def create_status_window
  @status_window = Window_BattleStatus.new
  @status_window.x = 128
end

- (Object) dispose_spriteset


  • Free Sprite Set




151
152
153
# File 'Scene_Battle.rb', line 151

def dispose_spriteset
  @spriteset.dispose
end

- (Object) execute_action


  • Execute Battle Actions




571
572
573
574
575
# File 'Scene_Battle.rb', line 571

def execute_action
  @subject.sprite_effect_type = :whiten
  use_item
  @log_window.wait_and_clear
end

- (Object) invoke_counter_attack(target, item)


  • Invoke Counterattack




612
613
614
615
616
617
618
# File 'Scene_Battle.rb', line 612

def invoke_counter_attack(target, item)
  @log_window.display_counter(target, item)
  attack_skill = $data_skills[target.attack_skill_id]
  @subject.item_apply(target, attack_skill)
  refresh_status
  @log_window.display_action_results(@subject, attack_skill)
end

- (Object) invoke_item(target, item)


  • Invoke Skill/Item




591
592
593
594
595
596
597
598
599
600
# File 'Scene_Battle.rb', line 591

def invoke_item(target, item)
  if rand < target.item_cnt(@subject, item)
    invoke_counter_attack(target, item)
  elsif rand < target.item_mrf(@subject, item)
    invoke_magic_reflection(target, item)
  else
    apply_item_effects(apply_substitute(target, item), item)
  end
  @subject.last_target_index = target.index
end

- (Object) invoke_magic_reflection(target, item)


  • Invoke Magic Reflection




622
623
624
625
626
627
# File 'Scene_Battle.rb', line 622

def invoke_magic_reflection(target, item)
  @subject.magic_reflection = true
  @log_window.display_reflection(target, item)
  apply_item_effects(@subject, item)
  @subject.magic_reflection = false
end

- (Object) move_info_viewport(ox)


  • Move Information Display Viewport




125
126
127
128
129
# File 'Scene_Battle.rb', line 125

def move_info_viewport(ox)
  current_ox = @info_viewport.ox
  @info_viewport.ox = [ox, current_ox + 16].min if current_ox < ox
  @info_viewport.ox = [ox, current_ox - 16].max if current_ox > ox
end

- (Object) next_command


  • To Next Command Input




280
281
282
283
284
285
286
# File 'Scene_Battle.rb', line 280

def next_command
  if BattleManager.next_command
    start_actor_command_selection
  else
    turn_start
  end
end

- (Object) on_actor_cancel


  • Actor [Cancel]




384
385
386
387
388
389
390
391
392
# File 'Scene_Battle.rb', line 384

def on_actor_cancel
  @actor_window.hide
  case @actor_command_window.current_symbol
  when :skill
    @skill_window.activate
  when :item
    @item_window.activate
  end
end

- (Object) on_actor_ok


  • Actor [OK]




374
375
376
377
378
379
380
# File 'Scene_Battle.rb', line 374

def on_actor_ok
  BattleManager.actor.input.target_index = @actor_window.index
  @actor_window.hide
  @skill_window.hide
  @item_window.hide
  next_command
end

- (Object) on_enemy_cancel


  • Enemy [Cancel]




413
414
415
416
417
418
419
420
421
422
423
# File 'Scene_Battle.rb', line 413

def on_enemy_cancel
  @enemy_window.hide
  case @actor_command_window.current_symbol
  when :attack
    @actor_command_window.activate
  when :skill
    @skill_window.activate
  when :item
    @item_window.activate
  end
end

- (Object) on_enemy_ok


  • Enemy [OK]




403
404
405
406
407
408
409
# File 'Scene_Battle.rb', line 403

def on_enemy_ok
  BattleManager.actor.input.target_index = @enemy_window.enemy.index
  @enemy_window.hide
  @skill_window.hide
  @item_window.hide
  next_command
end

- (Object) on_item_cancel


  • Item [Cancel]




466
467
468
469
# File 'Scene_Battle.rb', line 466

def on_item_cancel
  @item_window.hide
  @actor_command_window.activate
end

- (Object) on_item_ok


  • Item [OK]




450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'Scene_Battle.rb', line 450

def on_item_ok
  @item = @item_window.item
  BattleManager.actor.input.set_item(@item.id)
  if !@item.need_selection?
    @item_window.hide
    next_command
  elsif @item.for_opponent?
    select_enemy_selection
  else
    select_actor_selection
  end
  $game_party.last_item.object = @item
end

- (Object) on_skill_cancel


  • Skill [Cancel]




443
444
445
446
# File 'Scene_Battle.rb', line 443

def on_skill_cancel
  @skill_window.hide
  @actor_command_window.activate
end

- (Object) on_skill_ok


  • Skill [OK]




427
428
429
430
431
432
433
434
435
436
437
438
439
# File 'Scene_Battle.rb', line 427

def on_skill_ok
  @skill = @skill_window.item
  BattleManager.actor.input.set_skill(@skill.id)
  BattleManager.actor.last_skill.object = @skill
  if !@skill.need_selection?
    @skill_window.hide
    next_command
  elsif @skill.for_opponent?
    select_enemy_selection
  else
    select_actor_selection
  end
end

- (Object) post_start


  • Post-Start Processing




20
21
22
23
# File 'Scene_Battle.rb', line 20

def post_start
  super
  battle_start
end

- (Object) pre_terminate


  • Pre-Termination Processing




27
28
29
30
31
# File 'Scene_Battle.rb', line 27

def pre_terminate
  super
  Graphics.fadeout(30) if SceneManager.scene_is?(Scene_Map)
  Graphics.fadeout(60) if SceneManager.scene_is?(Scene_Title)
end

- (Object) prior_command


  • To Previous Command Input




290
291
292
293
294
295
296
# File 'Scene_Battle.rb', line 290

def prior_command
  if BattleManager.prior_command
    start_actor_command_selection
  else
    start_party_command_selection
  end
end

- (Object) process_action


  • Battle Action Processing




540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
# File 'Scene_Battle.rb', line 540

def process_action
  return if scene_changing?
  if !@subject || !@subject.current_action
    @subject = BattleManager.next_subject
  end
  return turn_end unless @subject
  if @subject.current_action
    @subject.current_action.prepare
    if @subject.current_action.valid?
      @status_window.open
      execute_action
    end
    @subject.remove_current_action
  end
  process_action_end unless @subject.current_action
end

- (Object) process_action_end


  • Processing at End of Action




559
560
561
562
563
564
565
566
567
# File 'Scene_Battle.rb', line 559

def process_action_end
  @subject.on_action_end
  refresh_status
  @log_window.display_auto_affected_status(@subject)
  @log_window.wait_and_clear
  @log_window.display_current_state(@subject)
  @log_window.wait_and_clear
  BattleManager.judge_win_loss
end

- (Object) process_event


  • Event Processing




513
514
515
516
517
518
519
520
521
522
523
524
# File 'Scene_Battle.rb', line 513

def process_event
  while !scene_changing?
    $game_troop.interpreter.update
    $game_troop.setup_battle_event
    wait_for_message
    wait_for_effect if $game_troop.all_dead?
    process_forced_action
    BattleManager.judge_win_loss
    break unless $game_troop.interpreter.running?
    update_for_wait
  end
end

- (Object) process_forced_action


  • Forced Action Processing




528
529
530
531
532
533
534
535
536
# File 'Scene_Battle.rb', line 528

def process_forced_action
  if BattleManager.action_forced?
    last_subject = @subject
    @subject = BattleManager.action_forced_battler
    BattleManager.clear_action_force
    process_action
    @subject = last_subject
  end
end

- (Object) refresh_status


  • Update Status Window Information




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

def refresh_status
  @status_window.refresh
end

- (Object) select_actor_selection


  • Start Actor Selection




367
368
369
370
# File 'Scene_Battle.rb', line 367

def select_actor_selection
  @actor_window.refresh
  @actor_window.show.activate
end

- (Object) select_enemy_selection


  • Start Enemy Selection




396
397
398
399
# File 'Scene_Battle.rb', line 396

def select_enemy_selection
  @enemy_window.refresh
  @enemy_window.show.activate
end

- (Object) show_animation(targets, animation_id)


  • Show Animation

    targets      : Target array
    animation_id : Animation ID (-1:  Same as normal attack)



652
653
654
655
656
657
658
659
660
# File 'Scene_Battle.rb', line 652

def show_animation(targets, animation_id)
  if animation_id < 0
    show_attack_animation(targets)
  else
    show_normal_animation(targets, animation_id)
  end
  @log_window.wait
  wait_for_animation
end

- (Object) show_attack_animation(targets)


  • Show Attack Animation

     targets : Target array
    Account for dual wield in the case of an actor (flip left hand weapon
    display). If enemy, play the [Enemy Attack] SE and wait briefly.



667
668
669
670
671
672
673
674
675
# File 'Scene_Battle.rb', line 667

def show_attack_animation(targets)
  if @subject.actor?
    show_normal_animation(targets, @subject.atk_animation_id1, false)
    show_normal_animation(targets, @subject.atk_animation_id2, true)
  else
    Sound.play_enemy_attack
    abs_wait_short
  end
end

- (Boolean) show_fast?


  • Determine if Fast Forward


Returns:

  • (Boolean)


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

def show_fast?
  Input.press?(:A) || Input.press?(:C)
end

- (Object) show_normal_animation(targets, animation_id, mirror = false)


  • Show Normal Animation

    targets      : Target array
    animation_id : Animation ID
    mirror       : Flip horizontal



682
683
684
685
686
687
688
689
690
691
692
# File 'Scene_Battle.rb', line 682

def show_normal_animation(targets, animation_id, mirror = false)
  animation = $data_animations[animation_id]
  if animation
    targets.each do |target|
      target.animation_id = animation_id
      target.animation_mirror = mirror
      abs_wait_short unless animation.to_screen?
    end
    abs_wait_short if animation.to_screen?
  end
end

- (Object) start


  • Start Processing




11
12
13
14
15
16
# File 'Scene_Battle.rb', line 11

def start
  super
  create_spriteset
  create_all_windows
  BattleManager.method_wait_for_message = method(:wait_for_message)
end

- (Object) start_actor_command_selection


  • Start Actor Command Selection




329
330
331
332
333
# File 'Scene_Battle.rb', line 329

def start_actor_command_selection
  @status_window.select(BattleManager.actor.index)
  @party_command_window.close
  @actor_command_window.setup(BattleManager.actor)
end

- (Object) start_party_command_selection


  • Start Party Command Selection




300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'Scene_Battle.rb', line 300

def start_party_command_selection
  unless scene_changing?
    refresh_status
    @status_window.unselect
    @status_window.open
    if BattleManager.input_start
      @actor_command_window.close
      @party_command_window.setup
    else
      @party_command_window.deactivate
      turn_start
    end
  end
end

- (Object) terminate


  • Termination Processing




35
36
37
38
39
40
# File 'Scene_Battle.rb', line 35

def terminate
  super
  dispose_spriteset
  @info_viewport.dispose
  RPG::ME.stop
end

- (Object) turn_end


  • End Turn




493
494
495
496
497
498
499
500
501
502
503
# File 'Scene_Battle.rb', line 493

def turn_end
  all_battle_members.each do |battler|
    battler.on_turn_end
    refresh_status
    @log_window.display_auto_affected_status(battler)
    @log_window.wait_and_clear
  end
  BattleManager.turn_end
  process_event
  start_party_command_selection
end

- (Object) turn_start


  • Start Turn




481
482
483
484
485
486
487
488
489
# File 'Scene_Battle.rb', line 481

def turn_start
  @party_command_window.close
  @actor_command_window.close
  @status_window.unselect
  @subject =  nil
  BattleManager.turn_start
  @log_window.wait
  @log_window.clear
end

- (Object) update


  • Frame Update




44
45
46
47
48
49
50
51
# File 'Scene_Battle.rb', line 44

def update
  super
  if BattleManager.in_turn?
    process_event
    process_action
  end
  BattleManager.judge_win_loss
end

- (Object) update_basic


  • Update Frame (Basic)




55
56
57
58
59
60
61
62
# File 'Scene_Battle.rb', line 55

def update_basic
  super
  $game_timer.update
  $game_troop.update
  @spriteset.update
  update_info_viewport
  update_message_open
end

- (Object) update_for_wait


  • Update Frame (for Wait)




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

def update_for_wait
  update_basic
end

- (Object) update_info_viewport


  • Update Information Display Viewport




117
118
119
120
121
# File 'Scene_Battle.rb', line 117

def update_info_viewport
  move_info_viewport(0)   if @party_command_window.active
  move_info_viewport(128) if @actor_command_window.active
  move_info_viewport(64)  if BattleManager.in_turn?
end

- (Object) update_message_open


  • Update Processing for Opening Message Window

    Set openness to 0 until the status window and so on are finished closing.



134
135
136
137
138
139
140
141
# File 'Scene_Battle.rb', line 134

def update_message_open
  if $game_message.busy? && !@status_window.close?
    @message_window.openness = 0
    @status_window.close
    @party_command_window.close
    @actor_command_window.close
  end
end

- (Object) use_item


  • Use Skill/Item




579
580
581
582
583
584
585
586
587
# File 'Scene_Battle.rb', line 579

def use_item
  item = @subject.current_action.item
  @log_window.display_use_item(@subject, item)
  @subject.use_item(item)
  refresh_status
  targets = @subject.current_action.make_targets.compact
  show_animation(targets, item.animation_id)
  targets.each {|target| item.repeats.times { invoke_item(target, item) } }
end

- (Object) wait(duration)


  • Wait




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

def wait(duration)
  duration.times {|i| update_for_wait if i < duration / 2 || !show_fast? }
end

- (Object) wait_for_animation


  • Wait Until Animation Display has Finished




103
104
105
106
# File 'Scene_Battle.rb', line 103

def wait_for_animation
  update_for_wait
  update_for_wait while @spriteset.animation?
end

- (Object) wait_for_effect


  • Wait Until Effect Execution Ends




110
111
112
113
# File 'Scene_Battle.rb', line 110

def wait_for_effect
  update_for_wait
  update_for_wait while @spriteset.effect?
end

- (Object) wait_for_message


  • Wait Until Message Display has Finished




96
97
98
99
# File 'Scene_Battle.rb', line 96

def wait_for_message
  @message_window.update
  update_for_wait while $game_message.visible
end