Module: BattleManager
- Defined in:
- lib/rgss3_default_scripts/BattleManager.rb
Overview
** BattleManager
This module manages battle progress.
Class Method Summary collapse
-
.abort ⇒ Object
————————————————————————– * Battle Abort ————————————————————————–.
-
.aborting? ⇒ Boolean
————————————————————————– * Determine if Battle Is Aborting ————————————————————————–.
-
.action_forced? ⇒ Boolean
————————————————————————– * Get Forced State of Battle Action ————————————————————————–.
-
.action_forced_battler ⇒ Object
————————————————————————– * Get Battler Subjected to Forced Action ————————————————————————–.
-
.actor ⇒ Object
————————————————————————– * Get Actor for Which Command Is Being Entered ————————————————————————–.
-
.battle_end(result) ⇒ Object
————————————————————————– * End Battle result : Result (0: Win 1: Escape 2: Lose) ————————————————————————–.
-
.battle_start ⇒ Object
————————————————————————– * Battle Start ————————————————————————–.
-
.can_escape? ⇒ Boolean
————————————————————————– * Get Whether Escape Is Possible ————————————————————————–.
-
.clear_action_force ⇒ Object
————————————————————————– * Clear Forcing of Battle Action ————————————————————————–.
-
.clear_actor ⇒ Object
————————————————————————– * Clear Actor for Which Command Is Being Entered ————————————————————————–.
-
.display_exp ⇒ Object
————————————————————————– * Display EXP Earned ————————————————————————–.
-
.event_proc=(proc) ⇒ Object
————————————————————————– * Set Proc for Callback to Event ————————————————————————–.
-
.force_action(battler) ⇒ Object
————————————————————————– * Force Action ————————————————————————–.
-
.gain_drop_items ⇒ Object
————————————————————————– * Dropped Item Acquisition and Display ————————————————————————–.
-
.gain_exp ⇒ Object
————————————————————————– * EXP Acquisition and Level Up Display ————————————————————————–.
-
.gain_gold ⇒ Object
————————————————————————– * Gold Acquisition and Display ————————————————————————–.
-
.in_turn? ⇒ Boolean
————————————————————————– * Determine if Turn Is Executing ————————————————————————–.
-
.init_members ⇒ Object
————————————————————————– * Initialize Member Variables ————————————————————————–.
-
.input_start ⇒ Object
————————————————————————– * Start Command Input ————————————————————————–.
-
.judge_win_loss ⇒ Object
————————————————————————– * Determine Win/Loss Results ————————————————————————–.
-
.make_action_orders ⇒ Object
————————————————————————– * Create Action Order ————————————————————————–.
-
.make_escape_ratio ⇒ Object
————————————————————————– * Create Escape Success Probability ————————————————————————–.
-
.method_wait_for_message=(method) ⇒ Object
————————————————————————– * Set Wait Method ————————————————————————–.
-
.next_command ⇒ Object
————————————————————————– * To Next Command Input ————————————————————————–.
-
.next_subject ⇒ Object
————————————————————————– * Get Next Action Subject Get the battler from the beginning of the action order list.
-
.on_encounter ⇒ Object
————————————————————————– * Processing at Encounter Time ————————————————————————–.
-
.play_battle_bgm ⇒ Object
————————————————————————– * Play Battle BGM ————————————————————————–.
-
.play_battle_end_me ⇒ Object
————————————————————————– * Play Battle End ME ————————————————————————–.
-
.prior_command ⇒ Object
————————————————————————– * To Previous Command Input ————————————————————————–.
-
.process_abort ⇒ Object
————————————————————————– * Abort Processing ————————————————————————–.
-
.process_defeat ⇒ Object
————————————————————————– * Defeat Processing ————————————————————————–.
-
.process_escape ⇒ Object
————————————————————————– * Escape Processing ————————————————————————–.
-
.process_victory ⇒ Object
————————————————————————– * Victory Processing ————————————————————————–.
-
.rate_preemptive ⇒ Object
————————————————————————– * Get Probability of Preemptive Attack ————————————————————————–.
-
.rate_surprise ⇒ Object
————————————————————————– * Get Probability of Surprise ————————————————————————–.
-
.replay_bgm_and_bgs ⇒ Object
————————————————————————– * Resume BGM and BGS ————————————————————————–.
-
.revive_battle_members ⇒ Object
————————————————————————– * Revive Battle Members (When Defeated) ————————————————————————–.
-
.save_bgm_and_bgs ⇒ Object
————————————————————————– * Save BGM and BGS ————————————————————————–.
-
.setup(troop_id, can_escape = true, can_lose = false) ⇒ Object
————————————————————————– * Setup ————————————————————————–.
-
.turn_end ⇒ Object
————————————————————————– * End Turn ————————————————————————–.
-
.turn_end? ⇒ Boolean
————————————————————————– * Determine if Turn Is Ending ————————————————————————–.
-
.turn_start ⇒ Object
————————————————————————– * Start Turn ————————————————————————–.
-
.wait_for_message ⇒ Object
————————————————————————– * Wait Until Message Display has Finished ————————————————————————–.
Class Method Details
.abort ⇒ Object
-
Battle Abort
184 185 186 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 184 def self.abort @phase = :aborting end |
.aborting? ⇒ Boolean
-
Determine if Battle Is Aborting
101 102 103 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 101 def self.aborting? @phase == :aborting end |
.action_forced? ⇒ Boolean
-
Get Forced State of Battle Action
363 364 365 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 363 def self.action_forced? @action_forced != nil end |
.action_forced_battler ⇒ Object
-
Get Battler Subjected to Forced Action
369 370 371 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 369 def self.action_forced_battler @action_forced end |
.actor ⇒ Object
-
Get Actor for Which Command Is Being Entered
113 114 115 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 113 def self.actor @actor_index >= 0 ? $game_party.members[@actor_index] : nil end |
.battle_end(result) ⇒ Object
-
End Battle
result : Result (0: Win 1: Escape 2: Lose)
268 269 270 271 272 273 274 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 268 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 ⇒ Object
-
Battle Start
167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 167 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 end |
.can_escape? ⇒ Boolean
-
Get Whether Escape Is Possible
107 108 109 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 107 def self.can_escape? @can_escape end |
.clear_action_force ⇒ Object
-
Clear Forcing of Battle Action
375 376 377 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 375 def self.clear_action_force @action_forced = nil end |
.clear_actor ⇒ Object
-
Clear Actor for Which Command Is Being Entered
119 120 121 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 119 def self.clear_actor @actor_index = -1 end |
.display_exp ⇒ Object
-
Display EXP Earned
307 308 309 310 311 312 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 307 def self.display_exp if $game_troop.exp_total > 0 text = sprintf(Vocab::ObtainExp, $game_troop.exp_total) $game_message.add('\.' + text) end end |
.event_proc=(proc) ⇒ Object
-
Set Proc for Callback to Event
149 150 151 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 149 def self.event_proc=(proc) @event_proc = proc end |
.force_action(battler) ⇒ Object
-
Force Action
356 357 358 359 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 356 def self.force_action(battler) @action_forced = battler @action_battlers.delete(battler) end |
.gain_drop_items ⇒ Object
-
Dropped Item Acquisition and Display
327 328 329 330 331 332 333 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 327 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 end |
.gain_exp ⇒ Object
-
EXP Acquisition and Level Up Display
337 338 339 340 341 342 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 337 def self.gain_exp $game_party.all_members.each do |actor| actor.gain_exp($game_troop.exp_total) end end |
.gain_gold ⇒ Object
-
Gold Acquisition and Display
316 317 318 319 320 321 322 323 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 316 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 end |
.in_turn? ⇒ Boolean
-
Determine if Turn Is Executing
89 90 91 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 89 def self.in_turn? @phase == :turn end |
.init_members ⇒ Object
-
Initialize Member Variables
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rgss3_default_scripts/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 |
.input_start ⇒ Object
-
Start Command Input
278 279 280 281 282 283 284 285 286 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 278 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 |
.judge_win_loss ⇒ Object
-
Determine Win/Loss Results
190 191 192 193 194 195 196 197 198 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 190 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 |
.make_action_orders ⇒ Object
-
Create Action Order
346 347 348 349 350 351 352 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 346 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 |
.make_escape_ratio ⇒ Object
-
Create Escape Success Probability
83 84 85 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 83 def self.make_escape_ratio @escape_ratio = 1.5 - 1.0 * $game_troop.agi / $game_party.agi end |
.method_wait_for_message=(method) ⇒ Object
-
Set Wait Method
155 156 157 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 155 def self.(method) @method_wait_for_message = method end |
.next_command ⇒ Object
-
To Next Command Input
125 126 127 128 129 130 131 132 133 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 125 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 |
.next_subject ⇒ Object
-
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.
384 385 386 387 388 389 390 391 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 384 def self.next_subject loop do battler = @action_battlers.shift return nil unless battler next unless battler.index && battler.alive? return battler end end |
.on_encounter ⇒ Object
-
Processing at Encounter Time
37 38 39 40 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 37 def self.on_encounter @preemptive = (rand < rate_preemptive) @surprise = (rand < rate_surprise && !@preemptive) end |
.play_battle_bgm ⇒ Object
-
Play Battle BGM
63 64 65 66 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 63 def self.play_battle_bgm $game_system.battle_bgm.play RPG::BGS.stop end |
.play_battle_end_me ⇒ Object
-
Play Battle End ME
70 71 72 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 70 def self.play_battle_end_me $game_system.battle_end_me.play end |
.prior_command ⇒ Object
-
To Previous Command Input
137 138 139 140 141 142 143 144 145 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 137 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 |
.process_abort ⇒ Object
-
Abort Processing
234 235 236 237 238 239 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 234 def self.process_abort replay_bgm_and_bgs SceneManager.return battle_end(1) return true end |
.process_defeat ⇒ Object
-
Defeat Processing
243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 243 def self.process_defeat $game_message.add(sprintf(Vocab::Defeat, $game_party.name)) if @can_lose revive_battle_members replay_bgm_and_bgs SceneManager.return else SceneManager.goto(Scene_Gameover) end battle_end(2) return true end |
.process_escape ⇒ Object
-
Escape Processing
217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 217 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 return success end |
.process_victory ⇒ Object
-
Victory Processing
202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 202 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 |
.rate_preemptive ⇒ Object
-
Get Probability of Preemptive Attack
44 45 46 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 44 def self.rate_preemptive $game_party.rate_preemptive($game_troop.agi) end |
.rate_surprise ⇒ Object
-
Get Probability of Surprise
50 51 52 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 50 def self.rate_surprise $game_party.rate_surprise($game_troop.agi) end |
.replay_bgm_and_bgs ⇒ Object
-
Resume BGM and BGS
76 77 78 79 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 76 def self.replay_bgm_and_bgs @map_bgm.replay unless $BTEST @map_bgs.replay unless $BTEST end |
.revive_battle_members ⇒ Object
-
Revive Battle Members (When Defeated)
259 260 261 262 263 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 259 def self.revive_battle_members $game_party.battle_members.each do |actor| actor.hp = 1 if actor.dead? end end |
.save_bgm_and_bgs ⇒ Object
-
Save BGM and BGS
56 57 58 59 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 56 def self.save_bgm_and_bgs @map_bgm = RPG::BGM.last @map_bgs = RPG::BGS.last end |
.setup(troop_id, can_escape = true, can_lose = false) ⇒ Object
-
Setup
11 12 13 14 15 16 17 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 11 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 |
.turn_end ⇒ Object
-
End Turn
299 300 301 302 303 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 299 def self.turn_end @phase = :turn_end @preemptive = false @surprise = false end |
.turn_end? ⇒ Boolean
-
Determine if Turn Is Ending
95 96 97 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 95 def self.turn_end? @phase == :turn_end end |
.turn_start ⇒ Object
-
Start Turn
290 291 292 293 294 295 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 290 def self.turn_start @phase = :turn clear_actor $game_troop.increase_turn make_action_orders end |
.wait_for_message ⇒ Object
-
Wait Until Message Display has Finished
161 162 163 |
# File 'lib/rgss3_default_scripts/BattleManager.rb', line 161 def self. @method_wait_for_message.call if @method_wait_for_message end |