This module manages battle progress.
- A
- B
- C
- D
- E
- F
- G
- I
- J
- M
- N
- O
- P
- R
- S
- T
- W
Battle Abort
Source: show
# File BattleManager.rb, line 205 def self.abort @phase = :aborting end
Determine if Battle Is Aborting
Source: show
# File BattleManager.rb, line 112 def self.aborting? @phase == :aborting end
Get Forced State of Battle Action
Source: show
# File BattleManager.rb, line 401 def self.action_forced? @action_forced != nil end
Get Battler Subjected to Forced Action
Source: show
# File BattleManager.rb, line 408 def self.action_forced_battler @action_forced end
Get Actor for Which Command Is Being Entered
Source: show
# File BattleManager.rb, line 126 def self.actor @actor_index >= 0 ? $game_party.members[@actor_index] : nil end
End Battle
result : Result (0: Win 1: Escape 2: Lose)
Source: show
# File BattleManager.rb, line 296 def self.battle_end(result) @phase = nil @event_proc.call(result) if @event_proc $game_party.on_battle_end $game_troop.on_battle_end SceneManager.exit if $BTEST end
Battle Start
Source: show
# File BattleManager.rb, line 187 def self.battle_start $game_system.battle_count += 1 $game_party.on_battle_start $game_troop.on_battle_start $game_troop.enemy_names.each do |name| $game_message.add(sprintf(Vocab::Emerge, name)) end if @preemptive $game_message.add(sprintf(Vocab::Preemptive, $game_party.name)) elsif @surprise $game_message.add(sprintf(Vocab::Surprise, $game_party.name)) end wait_for_message end
Get Whether Escape Is Possible
Source: show
# File BattleManager.rb, line 119 def self.can_escape? @can_escape end
Clear Forcing of Battle Action
Source: show
# File BattleManager.rb, line 415 def self.clear_action_force @action_forced = nil end
Clear Actor for Which Command Is Being Entered
Source: show
# File BattleManager.rb, line 133 def self.clear_actor @actor_index = -1 end
Display EXP Earned
Source: show
# File BattleManager.rb, line 339 def self.display_exp if $game_troop.exp_total > 0 text = sprintf(Vocab::ObtainExp, $game_troop.exp_total) $game_message.add('\.' + text) end end
Set Proc for Callback to Event
Source: show
# File BattleManager.rb, line 166 def self.event_proc=(proc) @event_proc = proc end
Force Action
Source: show
# File BattleManager.rb, line 393 def self.force_action(battler) @action_forced = battler @action_battlers.delete(battler) end
Dropped Item Acquisition and Display
Source: show
# File BattleManager.rb, line 361 def self.gain_drop_items $game_troop.make_drop_items.each do |item| $game_party.gain_item(item, 1) $game_message.add(sprintf(Vocab::ObtainItem, item.name)) end wait_for_message end
EXP Acquisition and Level Up Display
Source: show
# File BattleManager.rb, line 372 def self.gain_exp $game_party.all_members.each do |actor| actor.gain_exp($game_troop.exp_total) end wait_for_message end
Gold Acquisition and Display
Source: show
# File BattleManager.rb, line 349 def self.gain_gold if $game_troop.gold_total > 0 text = sprintf(Vocab::ObtainGold, $game_troop.gold_total) $game_message.add('\.' + text) $game_party.gain_gold($game_troop.gold_total) end wait_for_message end
Determine if Turn Is Executing
Source: show
# File BattleManager.rb, line 98 def self.in_turn? @phase == :turn end
Initialize Member Variables
Source: show
# File BattleManager.rb, line 21 def self.init_members @phase = :init # Battle Progress Phase @can_escape = false # Can Escape Flag @can_lose = false # Can Lose Flag @event_proc = nil # Event Callback @preemptive = false # Preemptive Attack Flag @surprise = false # Surprise Flag @actor_index = -1 # Actor for Which Command Is Being Entered @action_forced = nil # Force Action @map_bgm = nil # For Memorizing Pre-Battle BGM @map_bgs = nil # For Memorizing Pre-Battle BGS @action_battlers = [] # Action Order List end
Start Command Input
Source: show
# File BattleManager.rb, line 307 def self.input_start if @phase != :input @phase = :input $game_party.make_actions $game_troop.make_actions clear_actor end return !@surprise && $game_party.inputable? end
Determine Win/Loss Results
Source: show
# File BattleManager.rb, line 212 def self.judge_win_loss if @phase return process_abort if $game_party.members.empty? return process_defeat if $game_party.all_dead? return process_victory if $game_troop.all_dead? return process_abort if aborting? end return false end
Create Action Order
Source: show
# File BattleManager.rb, line 382 def self.make_action_orders @action_battlers = [] @action_battlers += $game_party.members unless @surprise @action_battlers += $game_troop.members unless @preemptive @action_battlers.each {|battler| battler.make_speed } @action_battlers.sort! {|a,b| b.speed - a.speed } end
Create Escape Success Probability
Source: show
# File BattleManager.rb, line 91 def self.make_escape_ratio @escape_ratio = 1.5 - 1.0 * $game_troop.agi / $game_party.agi end
Set Wait Method
Source: show
# File BattleManager.rb, line 173 def self.method_wait_for_message=(method) @method_wait_for_message = method end
To Next Command Input
Source: show
# File BattleManager.rb, line 140 def self.next_command begin if !actor || !actor.next_command @actor_index += 1 return false if @actor_index >= $game_party.members.size end end until actor.inputable? return true end
Get Next Action Subject
Get the battler from the beginning of the action order list. If an actor not currently in the party is obtained (occurs when index is nil, immediately after escaping in battle events etc.), skip them.
Source: show
# File BattleManager.rb, line 425 def self.next_subject loop do battler = @action_battlers.shift return nil unless battler next unless battler.index && battler.alive? return battler end end
Processing at Encounter Time
Source: show
# File BattleManager.rb, line 38 def self.on_encounter @preemptive = (rand < rate_preemptive) @surprise = (rand < rate_surprise && !@preemptive) end
Play Battle BGM
Source: show
# File BattleManager.rb, line 68 def self.play_battle_bgm $game_system.battle_bgm.play RPG::BGS.stop end
Play Battle End ME
Source: show
# File BattleManager.rb, line 76 def self.play_battle_end_me $game_system.battle_end_me.play end
To Previous Command Input
Source: show
# File BattleManager.rb, line 153 def self.prior_command begin if !actor || !actor.prior_command @actor_index -= 1 return false if @actor_index < 0 end end until actor.inputable? return true end
Abort Processing
Source: show
# File BattleManager.rb, line 259 def self.process_abort replay_bgm_and_bgs SceneManager.return battle_end(1) return true end
Defeat Processing
Source: show
# File BattleManager.rb, line 269 def self.process_defeat $game_message.add(sprintf(Vocab::Defeat, $game_party.name)) wait_for_message if @can_lose revive_battle_members replay_bgm_and_bgs SceneManager.return else SceneManager.goto(Scene_Gameover) end battle_end(2) return true end
Escape Processing
Source: show
# File BattleManager.rb, line 241 def self.process_escape $game_message.add(sprintf(Vocab::EscapeStart, $game_party.name)) success = @preemptive ? true : (rand < @escape_ratio) Sound.play_escape if success process_abort else @escape_ratio += 0.1 $game_message.add('\.' + Vocab::EscapeFailure) $game_party.clear_actions end wait_for_message return success end
Victory Processing
Source: show
# File BattleManager.rb, line 225 def self.process_victory play_battle_end_me replay_bgm_and_bgs $game_message.add(sprintf(Vocab::Victory, $game_party.name)) display_exp gain_gold gain_drop_items gain_exp SceneManager.return battle_end(0) return true end
Get Probability of Preemptive Attack
Source: show
# File BattleManager.rb, line 46 def self.rate_preemptive $game_party.rate_preemptive($game_troop.agi) end
Get Probability of Surprise
Source: show
# File BattleManager.rb, line 53 def self.rate_surprise $game_party.rate_surprise($game_troop.agi) end
Resume BGM and BGS
Source: show
# File BattleManager.rb, line 83 def self.replay_bgm_and_bgs @map_bgm.replay unless $BTEST @map_bgs.replay unless $BTEST end
Revive Battle Members (When Defeated)
Source: show
# File BattleManager.rb, line 286 def self.revive_battle_members $game_party.battle_members.each do |actor| actor.hp = 1 if actor.dead? end end
Save BGM and BGS
Source: show
# File BattleManager.rb, line 60 def self.save_bgm_and_bgs @map_bgm = RPG::BGM.last @map_bgs = RPG::BGS.last end
Setup
Source: show
# File BattleManager.rb, line 10 def self.setup(troop_id, can_escape = true, can_lose = false) init_members $game_troop.setup(troop_id) @can_escape = can_escape @can_lose = can_lose make_escape_ratio end
End Turn
Source: show
# File BattleManager.rb, line 330 def self.turn_end @phase = :turn_end @preemptive = false @surprise = false end
Determine if Turn Is Ending
Source: show
# File BattleManager.rb, line 105 def self.turn_end? @phase == :turn_end end