Class: Scene_Battle

Inherits:
Scene_Base show all
Defined in:
lib/rgss3_default_scripts/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

#abs_wait(duration) ⇒ Object


  • Wait (No Fast Forward)




84
85
86
# File 'lib/rgss3_default_scripts/Scene_Battle.rb', line 84

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

#abs_wait_shortObject


  • Short Wait (No Fast Forward)




90
91
92
# File 'lib/rgss3_default_scripts/Scene_Battle.rb', line 90

def abs_wait_short
  abs_wait(15)
end

#all_battle_membersObject


  • Get All Battle Members Including Enemies and Allies




507
508
509
# File 'lib/rgss3_default_scripts/Scene_Battle.rb', line 507

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

#apply_item_effects(target, item) ⇒ Object


  • Apply Skill/Item Effect




604
605
606
607
608
# File 'lib/rgss3_default_scripts/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

#apply_substitute(target, item) ⇒ Object


  • Apply Substitute




631
632
633
634
635
636
637
638
639
640
# File 'lib/rgss3_default_scripts/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

#battle_startObject


  • Battle Start




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

def battle_start
  BattleManager.battle_start
  process_event
  start_party_command_selection
end

#check_substitute(target, item) ⇒ Object


  • Check Substitute Condition




644
645
646
# File 'lib/rgss3_default_scripts/Scene_Battle.rb', line 644

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

#command_attackObject


  • Attack

    Command




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

def command_attack
  BattleManager.actor.input.set_attack
  select_enemy_selection
end

#command_escapeObject


  • Escape

    Command




323
324
325
# File 'lib/rgss3_default_scripts/Scene_Battle.rb', line 323

def command_escape
  turn_start unless BattleManager.process_escape
end

#command_fightObject


  • Fight

    Command




317
318
319
# File 'lib/rgss3_default_scripts/Scene_Battle.rb', line 317

def command_fight
  next_command
end

#command_guardObject


  • Guard

    Command




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

def command_guard
  BattleManager.actor.input.set_guard
  next_command
end

#command_itemObject


  • Item

    Command




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

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

#command_skillObject


  • Skill

    Command




344
345
346
347
348
349
# File 'lib/rgss3_default_scripts/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

#create_actor_command_windowObject


  • Create Actor Commands Window




222
223
224
225
226
227
228
229
230
231
# File 'lib/rgss3_default_scripts/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

#create_actor_windowObject


  • Create Actor Window




258
259
260
261
262
# File 'lib/rgss3_default_scripts/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

#create_all_windowsObject


  • Create All Windows




157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/rgss3_default_scripts/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

#create_enemy_windowObject


  • Create Enemy Window




266
267
268
269
270
# File 'lib/rgss3_default_scripts/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

#create_help_windowObject


  • Create Help Window




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

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

#create_info_viewportObject


  • Create Information Display Viewport




201
202
203
204
205
206
207
208
# File 'lib/rgss3_default_scripts/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

#create_item_windowObject


  • Create Item Window




250
251
252
253
254
# File 'lib/rgss3_default_scripts/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

#create_log_windowObject


  • Create Log Window




186
187
188
189
190
# File 'lib/rgss3_default_scripts/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

#create_message_windowObject


  • Create Message Window




174
175
176
# File 'lib/rgss3_default_scripts/Scene_Battle.rb', line 174

def create_message_window
  @message_window = Window_Message.new
end

#create_party_command_windowObject


  • Create Party Commands Window




212
213
214
215
216
217
218
# File 'lib/rgss3_default_scripts/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

#create_scroll_text_windowObject


  • Create Scrolling Text Window




180
181
182
# File 'lib/rgss3_default_scripts/Scene_Battle.rb', line 180

def create_scroll_text_window
  @scroll_text_window = Window_ScrollText.new
end

#create_skill_windowObject


  • Create Skill Window




242
243
244
245
246
# File 'lib/rgss3_default_scripts/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

#create_spritesetObject


  • Create Sprite Set




145
146
147
# File 'lib/rgss3_default_scripts/Scene_Battle.rb', line 145

def create_spriteset
  @spriteset = Spriteset_Battle.new
end

#create_status_windowObject


  • Create Status Window




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

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

#dispose_spritesetObject


  • Free Sprite Set




151
152
153
# File 'lib/rgss3_default_scripts/Scene_Battle.rb', line 151

def dispose_spriteset
  @spriteset.dispose
end

#execute_actionObject


  • Execute Battle Actions




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

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

#invoke_counter_attack(target, item) ⇒ Object


  • Invoke Counterattack




612
613
614
615
616
617
618
# File 'lib/rgss3_default_scripts/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

#invoke_item(target, item) ⇒ Object


  • Invoke Skill/Item




591
592
593
594
595
596
597
598
599
600
# File 'lib/rgss3_default_scripts/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

#invoke_magic_reflection(target, item) ⇒ Object


  • Invoke Magic Reflection




622
623
624
625
626
627
# File 'lib/rgss3_default_scripts/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

#move_info_viewport(ox) ⇒ Object


  • Move Information Display Viewport




125
126
127
128
129
# File 'lib/rgss3_default_scripts/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

#next_commandObject


  • To Next Command Input




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

def next_command
  if BattleManager.next_command
    start_actor_command_selection
  else
    turn_start
  end
end

#on_actor_cancelObject


  • Actor [Cancel]




384
385
386
387
388
389
390
391
392
# File 'lib/rgss3_default_scripts/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

#on_actor_okObject


  • Actor [OK]




374
375
376
377
378
379
380
# File 'lib/rgss3_default_scripts/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

#on_enemy_cancelObject


  • Enemy [Cancel]




413
414
415
416
417
418
419
420
421
422
423
# File 'lib/rgss3_default_scripts/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

#on_enemy_okObject


  • Enemy [OK]




403
404
405
406
407
408
409
# File 'lib/rgss3_default_scripts/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

#on_item_cancelObject


  • Item [Cancel]




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

def on_item_cancel
  @item_window.hide
  @actor_command_window.activate
end

#on_item_okObject


  • Item [OK]




450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'lib/rgss3_default_scripts/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

#on_skill_cancelObject


  • Skill [Cancel]




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

def on_skill_cancel
  @skill_window.hide
  @actor_command_window.activate
end

#on_skill_okObject


  • Skill [OK]




427
428
429
430
431
432
433
434
435
436
437
438
439
# File 'lib/rgss3_default_scripts/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

#post_startObject


  • Post-Start Processing




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

def post_start
  super
  battle_start
end

#pre_terminateObject


  • Pre-Termination Processing




27
28
29
30
31
# File 'lib/rgss3_default_scripts/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

#prior_commandObject


  • To Previous Command Input




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

def prior_command
  if BattleManager.prior_command
    start_actor_command_selection
  else
    start_party_command_selection
  end
end

#process_actionObject


  • Battle Action Processing




540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
# File 'lib/rgss3_default_scripts/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

#process_action_endObject


  • Processing at End of Action




559
560
561
562
563
564
565
566
567
# File 'lib/rgss3_default_scripts/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

#process_eventObject


  • Event Processing




513
514
515
516
517
518
519
520
521
522
523
524
# File 'lib/rgss3_default_scripts/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

#process_forced_actionObject


  • Forced Action Processing




528
529
530
531
532
533
534
535
536
# File 'lib/rgss3_default_scripts/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

#refresh_statusObject


  • Update Status Window Information




274
275
276
# File 'lib/rgss3_default_scripts/Scene_Battle.rb', line 274

def refresh_status
  @status_window.refresh
end

#select_actor_selectionObject


  • Start Actor Selection




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

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

#select_enemy_selectionObject


  • Start Enemy Selection




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

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

#show_animation(targets, animation_id) ⇒ Object


  • Show Animation

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



652
653
654
655
656
657
658
659
660
# File 'lib/rgss3_default_scripts/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

#show_attack_animation(targets) ⇒ Object


  • 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 'lib/rgss3_default_scripts/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

#show_fast?Boolean


  • Determine if Fast Forward


Returns:

  • (Boolean)


78
79
80
# File 'lib/rgss3_default_scripts/Scene_Battle.rb', line 78

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

#show_normal_animation(targets, animation_id, mirror = false) ⇒ Object


  • 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 'lib/rgss3_default_scripts/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

#startObject


  • Start Processing




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

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

#start_actor_command_selectionObject


  • Start Actor Command Selection




329
330
331
332
333
# File 'lib/rgss3_default_scripts/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

#start_party_command_selectionObject


  • Start Party Command Selection




300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/rgss3_default_scripts/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

#terminateObject


  • Termination Processing




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

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

#turn_endObject


  • End Turn




493
494
495
496
497
498
499
500
501
502
503
# File 'lib/rgss3_default_scripts/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

#turn_startObject


  • Start Turn




481
482
483
484
485
486
487
488
489
# File 'lib/rgss3_default_scripts/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

#updateObject


  • Frame Update




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

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

#update_basicObject


  • Update Frame (Basic)




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

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

#update_for_waitObject


  • Update Frame (for Wait)




66
67
68
# File 'lib/rgss3_default_scripts/Scene_Battle.rb', line 66

def update_for_wait
  update_basic
end

#update_info_viewportObject


  • Update Information Display Viewport




117
118
119
120
121
# File 'lib/rgss3_default_scripts/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

#update_message_openObject


  • 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 'lib/rgss3_default_scripts/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

#use_itemObject


  • Use Skill/Item




579
580
581
582
583
584
585
586
587
# File 'lib/rgss3_default_scripts/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

#wait(duration) ⇒ Object


  • Wait




72
73
74
# File 'lib/rgss3_default_scripts/Scene_Battle.rb', line 72

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

#wait_for_animationObject


  • Wait Until Animation Display has Finished




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

def wait_for_animation
  update_for_wait
  update_for_wait while @spriteset.animation?
end

#wait_for_effectObject


  • Wait Until Effect Execution Ends




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

def wait_for_effect
  update_for_wait
  update_for_wait while @spriteset.effect?
end

#wait_for_messageObject


  • Wait Until Message Display has Finished




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

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