Advertisement
Guest User

Untitled

a guest
Oct 29th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 58.87 KB | None | 0 0
  1. #==============================================================================#
  2. # Script by: Tigurus Fay #
  3. #==============================================================================#
  4. # Script: One-Man Duel Battlesystem #
  5. # Version: v1.03 #
  6. # Install: Press F11 and place the Script directly above [Main]. #
  7. # Description: This script allows for a timed-based battlesytem which works #
  8. # only correctly with 1 party member. For a very nice experience #
  9. # make the Battler with an over-the-shoulder perspective. #
  10. #==============================================================================#
  11.  
  12. #==============================================================================
  13. # ** Game_Actor
  14. #------------------------------------------------------------------------------
  15. # This class handles the actor. It's used within the Game_Actors class
  16. # ($game_actors) and refers to the Game_Party class ($game_party).
  17. #==============================================================================
  18.  
  19. class Game_Actor < Game_Battler
  20.  
  21. #--------------------------------------------------------------------------
  22. # * Get Battle Screen X-Coordinate
  23. #--------------------------------------------------------------------------
  24. def screen_x
  25. # Return after calculating x-coordinate by order of members in party
  26. if self.index != nil
  27. return self.index * 160 + 320
  28. else
  29. return 0
  30. end
  31. end
  32. #--------------------------------------------------------------------------
  33. # * Get Battle Screen Y-Coordinate
  34. #--------------------------------------------------------------------------
  35. def screen_y
  36. return 480
  37. end
  38. #--------------------------------------------------------------------------
  39. # * Get Battle Screen Z-Coordinate
  40. #--------------------------------------------------------------------------
  41. def screen_z
  42. # Return after calculating z-coordinate by order of members in party
  43. if self.index != nil
  44. return 4 - self.index
  45. else
  46. return 0
  47. end
  48. end
  49. end
  50.  
  51. #==============================================================================
  52. # ** Game_Party
  53. #------------------------------------------------------------------------------
  54. # This class handles the party. It includes information on amount of gold
  55. # and items. Refer to "$game_party" for the instance of this class.
  56. #==============================================================================
  57.  
  58. class Game_Party
  59. #--------------------------------------------------------------------------
  60. # * Public Instance Variables
  61. #--------------------------------------------------------------------------
  62. attr_reader :actors # actors
  63. attr_reader :gold # amount of gold
  64. attr_reader :steps # number of steps
  65. #--------------------------------------------------------------------------
  66. # * Object Initialization
  67. #--------------------------------------------------------------------------
  68. def initialize
  69. # Create actor array
  70. @actors = []
  71. # Initialize amount of gold and steps
  72. @gold = 0
  73. @steps = 0
  74. # Create amount in possession hash for items, weapons, and armor
  75. @items = {}
  76. @weapons = {}
  77. @armors = {}
  78. end
  79. #--------------------------------------------------------------------------
  80. # * Initial Party Setup
  81. #--------------------------------------------------------------------------
  82. def setup_starting_members
  83. @actors = []
  84. for i in $data_system.party_members
  85. @actors.push($game_actors[i])
  86. end
  87. end
  88. #--------------------------------------------------------------------------
  89. # * Battle Test Party Setup
  90. #--------------------------------------------------------------------------
  91. def setup_battle_test_members
  92. @actors = []
  93. for battler in $data_system.test_battlers
  94. actor = $game_actors[battler.actor_id]
  95. actor.level = battler.level
  96. gain_weapon(battler.weapon_id, 1)
  97. gain_armor(battler.armor1_id, 1)
  98. gain_armor(battler.armor2_id, 1)
  99. gain_armor(battler.armor3_id, 1)
  100. gain_armor(battler.armor4_id, 1)
  101. actor.equip(0, battler.weapon_id)
  102. actor.equip(1, battler.armor1_id)
  103. actor.equip(2, battler.armor2_id)
  104. actor.equip(3, battler.armor3_id)
  105. actor.equip(4, battler.armor4_id)
  106. actor.recover_all
  107. @actors.push(actor)
  108. end
  109. @items = {}
  110. for i in 1...$data_items.size
  111. if $data_items[i].name != ""
  112. occasion = $data_items[i].occasion
  113. if occasion == 0 or occasion == 1
  114. @items[i] = 99
  115. end
  116. end
  117. end
  118. end
  119. #--------------------------------------------------------------------------
  120. # * Refresh Party Members
  121. #--------------------------------------------------------------------------
  122. def refresh
  123. # Actor objects split from $game_actors right after loading game data
  124. # Avoid this problem by resetting the actors each time data is loaded.
  125. new_actors = []
  126. for i in 0...@actors.size
  127. if $data_actors[@actors[i].id] != nil
  128. new_actors.push($game_actors[@actors[i].id])
  129. end
  130. end
  131. @actors = new_actors
  132. end
  133.  
  134. #--------------------------------------------------------------------------
  135. # * Add an Actor
  136. # actor_id : actor ID
  137. #--------------------------------------------------------------------------
  138. def add_actor(actor_id)
  139. # Get actor
  140. actor = $game_actors[actor_id]
  141. # If the party has less than 4 members and this actor is not in the party
  142. if @actors.size < 1 and not @actors.include?(actor)
  143. # Add actor
  144. @actors.push(actor)
  145. # Refresh player
  146. $game_player.refresh
  147. end
  148. end
  149. end
  150.  
  151.  
  152. #==============================================================================
  153. # ** Window_Filler
  154. #------------------------------------------------------------------------------
  155. # This window is used to select whether to fight or escape on the battle
  156. # screen.
  157. #==============================================================================
  158.  
  159. class Window_Filler < Window_Base
  160. def initialize
  161. super(160, 320, 320, 160)
  162. self.back_opacity = 160
  163. refresh
  164. end
  165. def refresh
  166. end
  167. end
  168.  
  169. #==============================================================================
  170. # ** Window_PartyCommand
  171. #------------------------------------------------------------------------------
  172. # This window is used to select whether to fight or escape on the battle
  173. # screen.
  174. #==============================================================================
  175.  
  176. class Window_PartyCommand < Window_Selectable
  177. #--------------------------------------------------------------------------
  178. # * Object Initialization
  179. #--------------------------------------------------------------------------
  180. def initialize
  181. super(0, 0, 640, 64)
  182. self.contents = Bitmap.new(width - 32, height - 32)
  183. @commands = ["Fight", "Escape"]
  184. @item_max = 2
  185. @column_max = 2
  186. draw_item(0, normal_color)
  187. draw_item(1, $game_temp.battle_can_escape ? normal_color : disabled_color)
  188. self.active = false
  189. self.visible = false
  190. self.index = 0
  191. end
  192. #--------------------------------------------------------------------------
  193. # * Draw Item
  194. # index : item number
  195. # color : text character color
  196. #--------------------------------------------------------------------------
  197. def draw_item(index, color)
  198. self.contents.font.color = color
  199. rect = Rect.new(160 + index * 160 + 4, 0, 128 - 10, 32)
  200. self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  201. self.contents.draw_text(rect, @commands[index], 1)
  202. end
  203. #--------------------------------------------------------------------------
  204. # * Cursor Rectangle Update
  205. #--------------------------------------------------------------------------
  206. def update_cursor_rect
  207. self.cursor_rect.set(160 + index * 160, 0, 128, 32)
  208. end
  209. end
  210.  
  211. #==============================================================================
  212. # ** Window_BattleStatus
  213. #------------------------------------------------------------------------------
  214. # This window displays the status of all party members on the battle screen.
  215. #==============================================================================
  216.  
  217. class Window_BattleStatus < Window_Base
  218. #--------------------------------------------------------------------------
  219. # * Object Initialization
  220. #--------------------------------------------------------------------------
  221. def initialize
  222. super(480, 320, 160, 160)
  223. self.contents = Bitmap.new(width - 32, height - 32)
  224. self.back_opacity = 120
  225. @level_up_flags = [false, false, false, false]
  226. refresh
  227. end
  228. #--------------------------------------------------------------------------
  229. # * Dispose
  230. #--------------------------------------------------------------------------
  231. def dispose
  232. super
  233. end
  234. #--------------------------------------------------------------------------
  235. # * Set Level Up Flag
  236. # actor_index : actor index
  237. #--------------------------------------------------------------------------
  238. def level_up(actor_index)
  239. @level_up_flags[actor_index] = true
  240. end
  241. #--------------------------------------------------------------------------
  242. # * Refresh
  243. #--------------------------------------------------------------------------
  244. def refresh
  245. self.contents.clear
  246. @item_max = $game_party.actors.size
  247. for i in 0...$game_party.actors.size
  248. actor = $game_party.actors[i]
  249. actor_x = i * 160 + 4
  250. draw_actor_name(actor, actor_x, 0)
  251. draw_actor_hp(actor, actor_x, 32, 120)
  252. draw_actor_sp(actor, actor_x, 64, 120)
  253. if @level_up_flags[i]
  254. self.contents.font.color = normal_color
  255. self.contents.draw_text(actor_x, 96, 120, 32, "LEVEL UP!")
  256. else
  257. draw_actor_state(actor, actor_x, 96)
  258. end
  259. end
  260. end
  261. #--------------------------------------------------------------------------
  262. # * Frame Update
  263. #--------------------------------------------------------------------------
  264. def update
  265. super
  266. # Slightly lower opacity level during main phase
  267. if $game_temp.battle_main_phase
  268. self.contents_opacity -= 4 if self.contents_opacity > 255
  269. else
  270. self.contents_opacity += 4 if self.contents_opacity < 255
  271. end
  272. end
  273. end
  274. #==============================================================================
  275. # ** Scene_Battle (part 1)
  276. #------------------------------------------------------------------------------
  277. # This class performs battle screen processing.
  278. #==============================================================================
  279.  
  280. class Scene_Battle
  281. #--------------------------------------------------------------------------
  282. # * Main Processing
  283. #--------------------------------------------------------------------------
  284. def main
  285. # Initialize each kind of temporary battle data
  286. $game_temp.in_battle = true
  287. $game_temp.battle_turn = 0
  288. $game_temp.battle_event_flags.clear
  289. $game_temp.battle_abort = false
  290. $game_temp.battle_main_phase = false
  291. $game_temp.battleback_name = $game_map.battleback_name
  292. $game_temp.forcing_battler = nil
  293. # Initialize battle event interpreter
  294. $game_system.battle_interpreter.setup(nil, 0)
  295. # Prepare troop
  296. @troop_id = $game_temp.battle_troop_id
  297. $game_troop.setup(@troop_id)
  298. # Make actor command window
  299. s1 = $data_system.words.attack
  300. s2 = $data_system.words.skill
  301. s3 = 'Item'
  302. s4 = 'Fugir'
  303. @actor_command_window = Window_Command.new(160, [s1, s2, s3, s4])
  304. @actor_command_window.y = 320
  305. @actor_command_window.back_opacity = 120
  306. @actor_command_window.active = false
  307. @actor_command_window.visible = true
  308. @actor_command_window.contents_opacity > 255
  309. # Make other windows
  310. @party_command_window = Window_PartyCommand.new
  311. @help_window = Window_Help.new
  312. @window_filler = Window_Filler.new
  313. @help_window.back_opacity = 160
  314. @help_window.visible = false
  315. @status_window = Window_BattleStatus.new
  316. @message_window = Window_Message.new
  317. # Make sprite set
  318. @spriteset = Spriteset_Battle.new
  319. # Initialize wait count
  320. @wait_count = 0
  321. # Execute transition
  322. if $data_system.battle_transition == ""
  323. Graphics.transition(20)
  324. else
  325. Graphics.transition(40, "Graphics/Transitions/" +
  326. $data_system.battle_transition)
  327. end
  328. # Start pre-battle phase
  329. start_phase1
  330. # Main loop
  331. loop do
  332. # Update game screen
  333. Graphics.update
  334. # Update input information
  335. Input.update
  336. # Frame update
  337. update
  338. # Abort loop if screen is changed
  339. if $scene != self
  340. break
  341. end
  342. end
  343. # Refresh map
  344. $game_map.refresh
  345. # Prepare for transition
  346. Graphics.freeze
  347. # Dispose of windows
  348. @actor_command_window.dispose
  349. @party_command_window.dispose
  350. @window_filler.dispose
  351. @help_window.dispose
  352. @status_window.dispose
  353. @message_window.dispose
  354. if @skill_window != nil
  355. @skill_window.dispose
  356. end
  357. if @item_window != nil
  358. @item_window.dispose
  359. end
  360. if @result_window != nil
  361. @result_window.dispose
  362. end
  363. # Dispose of sprite set
  364. @spriteset.dispose
  365. # If switching to title screen
  366. if $scene.is_a?(Scene_Title)
  367. # Fade out screen
  368. Graphics.transition
  369. Graphics.freeze
  370. end
  371. # If switching from battle test to any screen other than game over screen
  372. if $BTEST and not $scene.is_a?(Scene_Gameover)
  373. $scene = nil
  374. end
  375. end
  376.  
  377. def update_cursor_rect
  378. # If cursor position is less than 0
  379. if @index < 0
  380. self.cursor_rect.empty
  381. return
  382. end
  383. # Get current row
  384. row = @index / @column_max
  385. # If current row is before top row
  386. if row < self.top_row
  387. # Scroll so that current row becomes top row
  388. self.top_row = row
  389. end
  390. # If current row is more to back than back row
  391. if row > self.top_row + (self.page_row_max - 1)
  392. # Scroll so that current row becomes back row
  393. self.top_row = row - (self.page_row_max - 1)
  394. end
  395. # Calculate cursor width
  396. cursor_width = self.width / @column_max - 320
  397. # Calculate cursor coordinates
  398. x = @index % @column_max * (cursor_width + 32)
  399. y = @index / @column_max * 32 - self.oy
  400. # Update cursor rectangle
  401. self.cursor_rect.set(x, y, cursor_width, 32)
  402. end
  403. #--------------------------------------------------------------------------
  404. # * Determine Battle Win/Loss Results
  405. #--------------------------------------------------------------------------
  406. def judge
  407. # If all dead determinant is true, or number of members in party is 0
  408. if $game_party.all_dead? or $game_party.actors.size == 0
  409. # If possible to lose
  410. if $game_temp.battle_can_lose
  411. # Return to BGM before battle starts
  412. $game_system.bgm_play($game_temp.map_bgm)
  413. # Battle ends
  414. battle_end(2)
  415. # Return true
  416. return true
  417. end
  418. # Set game over flag
  419. $game_temp.gameover = true
  420. # Return true
  421. return true
  422. end
  423. # Return false if even 1 enemy exists
  424. for enemy in $game_troop.enemies
  425. if enemy.exist?
  426. return false
  427. end
  428. end
  429. # Start after battle phase (win)
  430. start_phase5
  431. # Return true
  432. return true
  433. end
  434. #--------------------------------------------------------------------------
  435. # * Battle Ends
  436. # result : results (0:win 1:lose 2:escape)
  437. #--------------------------------------------------------------------------
  438. def battle_end(result)
  439. # Clear in battle flag
  440. $game_temp.in_battle = false
  441. # Clear entire party actions flag
  442. $game_party.clear_actions
  443. # Remove battle states
  444. for actor in $game_party.actors
  445. actor.remove_states_battle
  446. end
  447. # Clear enemies
  448. $game_troop.enemies.clear
  449. # Call battle callback
  450. if $game_temp.battle_proc != nil
  451. $game_temp.battle_proc.call(result)
  452. $game_temp.battle_proc = nil
  453. end
  454. # Switch to map screen
  455. $scene = Scene_Map.new
  456. end
  457. #--------------------------------------------------------------------------
  458. # * Battle Event Setup
  459. #--------------------------------------------------------------------------
  460. def setup_battle_event
  461. # If battle event is running
  462. if $game_system.battle_interpreter.running?
  463. return
  464. end
  465. # Search for all battle event pages
  466. for index in 0...$data_troops[@troop_id].pages.size
  467. # Get event pages
  468. page = $data_troops[@troop_id].pages[index]
  469. # Make event conditions possible for reference with c
  470. c = page.condition
  471. # Go to next page if no conditions are appointed
  472. unless c.turn_valid or c.enemy_valid or
  473. c.actor_valid or c.switch_valid
  474. next
  475. end
  476. # Go to next page if action has been completed
  477. if $game_temp.battle_event_flags[index]
  478. next
  479. end
  480. # Confirm turn conditions
  481. if c.turn_valid
  482. n = $game_temp.battle_turn
  483. a = c.turn_a
  484. b = c.turn_b
  485. if (b == 0 and n != a) or
  486. (b > 0 and (n < 1 or n < a or n % b != a % b))
  487. next
  488. end
  489. end
  490. # Confirm enemy conditions
  491. if c.enemy_valid
  492. enemy = $game_troop.enemies[c.enemy_index]
  493. if enemy == nil or enemy.hp * 100.0 / enemy.maxhp > c.enemy_hp
  494. next
  495. end
  496. end
  497. # Confirm actor conditions
  498. if c.actor_valid
  499. actor = $game_actors[c.actor_id]
  500. if actor == nil or actor.hp * 100.0 / actor.maxhp > c.actor_hp
  501. next
  502. end
  503. end
  504. # Confirm switch conditions
  505. if c.switch_valid
  506. if $game_switches[c.switch_id] == false
  507. next
  508. end
  509. end
  510. # Set up event
  511. $game_system.battle_interpreter.setup(page.list, 0)
  512. # If this page span is [battle] or [turn]
  513. if page.span <= 1
  514. # Set action completed flag
  515. $game_temp.battle_event_flags[index] = true
  516. end
  517. return
  518. end
  519. end
  520. #--------------------------------------------------------------------------
  521. # * Frame Update
  522. #--------------------------------------------------------------------------
  523. def update
  524. # If battle event is running
  525. if $game_system.battle_interpreter.running?
  526. # Update interpreter
  527. $game_system.battle_interpreter.update
  528. # If a battler which is forcing actions doesn't exist
  529. if $game_temp.forcing_battler == nil
  530. # If battle event has finished running
  531. unless $game_system.battle_interpreter.running?
  532. # Rerun battle event set up if battle continues
  533. unless judge
  534. setup_battle_event
  535. end
  536. end
  537. # If not after battle phase
  538. if @phase != 5
  539. # Refresh status window
  540. @status_window.refresh
  541. end
  542. end
  543. end
  544. # Update system (timer) and screen
  545. $game_system.update
  546. $game_screen.update
  547. # If timer has reached 0
  548. if $game_system.timer_working and $game_system.timer == 0
  549. # Abort battle
  550. $game_temp.battle_abort = true
  551. end
  552. # Update windows
  553. @help_window.update
  554. @party_command_window.update
  555. @actor_command_window.update
  556. if !$game_temp.battle_can_escape
  557. @actor_command_window.disable_item(3)
  558. end
  559. @status_window.update
  560. @message_window.update
  561. # Update sprite set
  562. @spriteset.update
  563. # If transition is processing
  564. if $game_temp.transition_processing
  565. # Clear transition processing flag
  566. $game_temp.transition_processing = false
  567. # Execute transition
  568. if $game_temp.transition_name == ""
  569. Graphics.transition(20)
  570. else
  571. Graphics.transition(40, "Graphics/Transitions/" +
  572. $game_temp.transition_name)
  573. end
  574. end
  575. # If message window is showing
  576. if $game_temp.message_window_showing
  577. return
  578. end
  579. # If effect is showing
  580. if @spriteset.effect?
  581. return
  582. end
  583. # If game over
  584. if $game_temp.gameover
  585. # Switch to game over screen
  586. $scene = Scene_Gameover.new
  587. return
  588. end
  589. # If returning to title screen
  590. if $game_temp.to_title
  591. # Switch to title screen
  592. $scene = Scene_Title.new
  593. return
  594. end
  595. # If battle is aborted
  596. if $game_temp.battle_abort
  597. # Return to BGM used before battle started
  598. $game_system.bgm_play($game_temp.map_bgm)
  599. # Battle ends
  600. battle_end(1)
  601. return
  602. end
  603. # If waiting
  604. if @wait_count > 0
  605. # Decrease wait count
  606. @wait_count -= 1
  607. return
  608. end
  609. # If battler forcing an action doesn't exist,
  610. # and battle event is running
  611. if $game_temp.forcing_battler == nil and
  612. $game_system.battle_interpreter.running?
  613. return
  614. end
  615. # Branch according to phase
  616. case @phase
  617. when 1 # pre-battle phase
  618. update_phase1
  619. when 2 # party command phase
  620. update_phase2
  621. when 3 # actor command phase
  622. update_phase3
  623. when 4 # main phase
  624. update_phase4
  625. when 5 # after battle phase
  626. update_phase5
  627. end
  628. end
  629. end
  630.  
  631. #==============================================================================
  632. # ** Scene_Battle (part 2)
  633. #------------------------------------------------------------------------------
  634. # This class performs battle screen processing.
  635. #==============================================================================
  636.  
  637. class Scene_Battle
  638.  
  639.  
  640. #--------------------------------------------------------------------------
  641. # * Start Pre-Battle Phase
  642. #--------------------------------------------------------------------------
  643. def start_phase1
  644. # Shift to phase 1
  645. @phase = 1
  646. # Clear all party member actions
  647. $game_party.clear_actions
  648. # Set up battle event
  649. setup_battle_event
  650. end
  651. #--------------------------------------------------------------------------
  652. # * Frame Update (pre-battle phase)
  653. #--------------------------------------------------------------------------
  654. def update_phase1
  655. # Determine win/loss situation
  656. if judge
  657. # If won or lost: end method
  658. return
  659. end
  660. # Start party command phase
  661. start_phase2
  662. end
  663. #--------------------------------------------------------------------------
  664. # * Start Party Command Phase
  665. #--------------------------------------------------------------------------
  666. def start_phase2
  667. # Shift to phase 2
  668. @phase = 2
  669. # Set actor to non-selecting
  670. @actor_index = -1
  671. @active_battler = nil
  672. # Enable party command window
  673. @party_command_window.active = true
  674. @party_command_window.visible = true
  675. # Disable actor command window
  676. @actor_command_window.active = false
  677. @actor_command_window.visible = true
  678. @actor_command_window.contents_opacity = 0
  679. # Clear main phase flag
  680. $game_temp.battle_main_phase = false
  681. # Clear all party member actions
  682. $game_party.clear_actions
  683. # If impossible to input command
  684. unless $game_party.inputable?
  685. # Start main phase
  686. start_phase4
  687. end
  688. end
  689. #--------------------------------------------------------------------------
  690. # * Frame Update (party command phase)
  691. #--------------------------------------------------------------------------
  692. def update_phase2
  693. # If C button was pressed
  694. if Input.trigger?(Input::C)
  695. # Branch by party command window cursor position
  696. case @party_command_window.index
  697. when 0 # fight
  698. # Play decision SE
  699. $game_system.se_play($data_system.decision_se)
  700. # Start actor command phase
  701. start_phase3
  702. when 1 # escape
  703. # If it's not possible to escape
  704. if $game_temp.battle_can_escape == false
  705. # Play buzzer SE
  706. $game_system.se_play($data_system.buzzer_se)
  707. return
  708. end
  709. # Play decision SE
  710. $game_system.se_play($data_system.decision_se)
  711. # Escape processing
  712. update_phase2_escape
  713. end
  714. return
  715. end
  716. end
  717. #--------------------------------------------------------------------------
  718. # * Frame Update (party command phase: escape)
  719. #--------------------------------------------------------------------------
  720. def update_phase2_escape
  721. # Calculate enemy agility average
  722. enemies_agi = 0
  723. enemies_number = 0
  724. for enemy in $game_troop.enemies
  725. if enemy.exist?
  726. enemies_agi += enemy.agi
  727. enemies_number += 1
  728. end
  729. end
  730. if enemies_number > 0
  731. enemies_agi /= enemies_number
  732. end
  733. # Calculate actor agility average
  734. actors_agi = 0
  735. actors_number = 0
  736. for actor in $game_party.actors
  737. if actor.exist?
  738. actors_agi += actor.agi
  739. actors_number += 1
  740. end
  741. end
  742. if actors_number > 0
  743. actors_agi /= actors_number
  744. end
  745. # Determine if escape is successful
  746. success = rand(100) < 50 * actors_agi / enemies_agi
  747. # If escape is successful
  748. if success
  749. # Play escape SE
  750. $game_system.se_play($data_system.escape_se)
  751. # Return to BGM before battle started
  752. $game_system.bgm_play($game_temp.map_bgm)
  753. # Battle ends
  754. battle_end(1)
  755. # If escape is failure
  756. else
  757. # Clear all party member actions
  758. $game_party.clear_actions
  759. # Start main phase
  760. start_phase4
  761. end
  762. end
  763. #--------------------------------------------------------------------------
  764. # * Start After Battle Phase
  765. #--------------------------------------------------------------------------
  766. def start_phase5
  767. # Shift to phase 5
  768. @phase = 5
  769. # Play battle end ME
  770. $game_system.me_play($game_system.battle_end_me)
  771. # Return to BGM before battle started
  772. $game_system.bgm_play($game_temp.map_bgm)
  773. # Initialize EXP, amount of gold, and treasure
  774. exp = 0
  775. gold = 0
  776. treasures = []
  777. # Loop
  778. for enemy in $game_troop.enemies
  779. # If enemy is not hidden
  780. unless enemy.hidden
  781. # Add EXP and amount of gold obtained
  782. exp += enemy.exp
  783. gold += enemy.gold
  784. # Determine if treasure appears
  785. if rand(100) < enemy.treasure_prob
  786. if enemy.item_id > 0
  787. treasures.push($data_items[enemy.item_id])
  788. end
  789. if enemy.weapon_id > 0
  790. treasures.push($data_weapons[enemy.weapon_id])
  791. end
  792. if enemy.armor_id > 0
  793. treasures.push($data_armors[enemy.armor_id])
  794. end
  795. end
  796. end
  797. end
  798. # Treasure is limited to a maximum of 6 items
  799. treasures = treasures[0..5]
  800. # Obtaining EXP
  801. for i in 0...$game_party.actors.size
  802. actor = $game_party.actors[i]
  803. if actor.cant_get_exp? == false
  804. last_level = actor.level
  805. actor.exp += exp
  806. if actor.level > last_level
  807. @status_window.level_up(i)
  808. end
  809. end
  810. end
  811. # Obtaining gold
  812. $game_party.gain_gold(gold)
  813. # Obtaining treasure
  814. for item in treasures
  815. case item
  816. when RPG::Item
  817. $game_party.gain_item(item.id, 1)
  818. when RPG::Weapon
  819. $game_party.gain_weapon(item.id, 1)
  820. when RPG::Armor
  821. $game_party.gain_armor(item.id, 1)
  822. end
  823. end
  824. # Make battle result window
  825. @result_window = Window_BattleResult.new(exp, gold, treasures)
  826. # Set wait count
  827. @phase5_wait_count = 100
  828. end
  829. #--------------------------------------------------------------------------
  830. # * Frame Update (after battle phase)
  831. #--------------------------------------------------------------------------
  832. def update_phase5
  833. # If wait count is larger than 0
  834. if @phase5_wait_count > 0
  835. # Decrease wait count
  836. @phase5_wait_count -= 1
  837. # If wait count reaches 0
  838. if @phase5_wait_count == 0
  839. # Show result window
  840. @result_window.visible = true
  841. # Clear main phase flag
  842. $game_temp.battle_main_phase = false
  843. # Refresh status window
  844. @status_window.refresh
  845. end
  846. return
  847. end
  848. # If C button was pressed
  849. if Input.trigger?(Input::C)
  850. # Battle ends
  851. battle_end(0)
  852. end
  853. end
  854. end
  855.  
  856. #==============================================================================
  857. # ** Scene_Battle (part 3)
  858. #------------------------------------------------------------------------------
  859. # This class performs battle screen processing.
  860. #==============================================================================
  861.  
  862. class Scene_Battle
  863. #--------------------------------------------------------------------------
  864. # * Start Actor Command Phase
  865. #--------------------------------------------------------------------------
  866. def start_phase3
  867. # Shift to phase 3
  868. @phase = 3
  869. @actor_command_window.contents_opacity = 255
  870. # Set actor as unselectable
  871. @actor_index = -1
  872. @active_battler = nil
  873. # Go to command input for next actor
  874. phase3_next_actor
  875. end
  876. #--------------------------------------------------------------------------
  877. # * Go to Command Input for Next Actor
  878. #--------------------------------------------------------------------------
  879. def phase3_next_actor
  880. # Loop
  881. begin
  882. # Actor blink effect OFF
  883. if @active_battler != nil
  884. @active_battler.blink = false
  885. end
  886. # If last actor
  887. if @actor_index == $game_party.actors.size-1
  888. # Start main phase
  889. start_phase4
  890. return
  891. end
  892. # Advance actor index
  893. @actor_index += 1
  894. @active_battler = $game_party.actors[@actor_index]
  895. @active_battler.blink = true
  896. # Once more if actor refuses command input
  897. end until @active_battler.inputable?
  898. # Set up actor command window
  899. phase3_setup_command_window
  900. end
  901. #--------------------------------------------------------------------------
  902. # * Go to Command Input of Previous Actor
  903. #--------------------------------------------------------------------------
  904. def phase3_prior_actor
  905. # Loop
  906. begin
  907. # Actor blink effect OFF
  908. if @active_battler != nil
  909. @active_battler.blink = false
  910. end
  911. # If first actor
  912. if @actor_index == 0
  913. # Start party command phase
  914. start_phase2
  915. return
  916. end
  917. # Return to actor index
  918. @actor_index -= 1
  919. @active_battler = $game_party.actors[@actor_index]
  920. @active_battler.blink = true
  921. # Once more if actor refuses command input
  922. end until @active_battler.inputable?
  923. # Set up actor command window
  924. phase3_setup_command_window
  925. end
  926. #--------------------------------------------------------------------------
  927. # * Actor Command Window Setup
  928. #--------------------------------------------------------------------------
  929. def phase3_setup_command_window
  930. # Disable party command window
  931. @party_command_window.active = false
  932. @party_command_window.visible = false
  933. # Enable actor command window
  934. @actor_command_window.active = true
  935. @actor_command_window.visible = true
  936. # Set actor command window position
  937. @actor_command_window.x = @actor_index * 160
  938. # Set index to 0
  939. @actor_command_window.index = 0
  940. end
  941. #--------------------------------------------------------------------------
  942. # * Frame Update (actor command phase)
  943. #--------------------------------------------------------------------------
  944. def update_phase3
  945. # If enemy arrow is enabled
  946. if @enemy_arrow != nil
  947. update_phase3_enemy_select
  948. # If actor arrow is enabled
  949. elsif @actor_arrow != nil
  950. update_phase3_actor_select
  951. # If skill window is enabled
  952. elsif @skill_window != nil
  953. update_phase3_skill_select
  954. # If item window is enabled
  955. elsif @item_window != nil
  956. update_phase3_item_select
  957. # If actor command window is enabled
  958. elsif @actor_command_window.active
  959. update_phase3_basic_command
  960. end
  961. end
  962. #--------------------------------------------------------------------------
  963. # * Frame Update (actor command phase : basic command)
  964. #--------------------------------------------------------------------------
  965. def update_phase3_basic_command
  966. # If B button was pressed
  967. if Input.trigger?(Input::B)
  968. # Play cancel SE
  969. $game_system.se_play($data_system.cancel_se)
  970. # Go to command input for previous actor
  971. phase3_prior_actor
  972. return
  973. end
  974. # If C button was pressed
  975. if Input.trigger?(Input::C)
  976. # Branch by actor command window cursor position
  977. case @actor_command_window.index
  978. when 0 # attack
  979. # Play decision SE
  980. $game_system.se_play($data_system.decision_se)
  981. # Set action
  982. @active_battler.current_action.kind = 0
  983. @active_battler.current_action.basic = 0
  984. # Start enemy selection
  985. start_enemy_select
  986. when 1 # skill
  987. # Play decision SE
  988. $game_system.se_play($data_system.decision_se)
  989. # Set action
  990. @active_battler.current_action.kind = 1
  991. # Start skill selection
  992. start_skill_select
  993. when 2 #item
  994. # Play decision SE
  995. $game_system.se_play($data_system.decision_se)
  996. # Set action
  997. @active_battler.current_action.kind = 2
  998. # Start item selection
  999. start_item_select
  1000. when 3 #run # item
  1001. # Se não for possivel escapar
  1002. if $game_temp.battle_can_escape == false
  1003. # Reproduzir SE de Erro
  1004. $game_system.se_play($data_system.buzzer_se)
  1005. return
  1006. end
  1007. # Reproduzir SE de OK
  1008. $game_system.se_play($data_system.decision_se)
  1009. # Processamento da fuga
  1010. update_phase2_escape
  1011. end
  1012. return
  1013. end
  1014. end
  1015. #--------------------------------------------------------------------------
  1016. # * Frame Update (actor command phase : skill selection)
  1017. #--------------------------------------------------------------------------
  1018. def update_phase3_skill_select
  1019. # Make skill window visible
  1020. @skill_window.visible = true
  1021. # Update skill window
  1022. @skill_window.update
  1023. # If B button was pressed
  1024. if Input.trigger?(Input::B)
  1025. # Play cancel SE
  1026. $game_system.se_play($data_system.cancel_se)
  1027. # End skill selection
  1028. end_skill_select
  1029. return
  1030. end
  1031. # If C button was pressed
  1032. if Input.trigger?(Input::C)
  1033. # Get currently selected data on the skill window
  1034. @skill = @skill_window.skill
  1035. # If it can't be used
  1036. if @skill == nil or not @active_battler.skill_can_use?(@skill.id)
  1037. # Play buzzer SE
  1038. $game_system.se_play($data_system.buzzer_se)
  1039. return
  1040. end
  1041. # Play decision SE
  1042. $game_system.se_play($data_system.decision_se)
  1043. # Set action
  1044. @active_battler.current_action.skill_id = @skill.id
  1045. # Make skill window invisible
  1046. @skill_window.visible = false
  1047. # If effect scope is single enemy
  1048. if @skill.scope == 1
  1049. # Start enemy selection
  1050. start_enemy_select
  1051. # If effect scope is single ally
  1052. elsif @skill.scope == 3 or @skill.scope == 5
  1053. # Start actor selection
  1054. start_actor_select
  1055. # If effect scope is not single
  1056. else
  1057. # End skill selection
  1058. end_skill_select
  1059. # Go to command input for next actor
  1060. phase3_next_actor
  1061. end
  1062. return
  1063. end
  1064. end
  1065. #--------------------------------------------------------------------------
  1066. # * Frame Update (actor command phase : item selection)
  1067. #--------------------------------------------------------------------------
  1068. def update_phase3_item_select
  1069. # Make item window visible
  1070. @item_window.visible = true
  1071. # Update item window
  1072. @item_window.update
  1073. # If B button was pressed
  1074. if Input.trigger?(Input::B)
  1075. # Play cancel SE
  1076. $game_system.se_play($data_system.cancel_se)
  1077. # End item selection
  1078. end_item_select
  1079. return
  1080. end
  1081. # If C button was pressed
  1082. if Input.trigger?(Input::C)
  1083. # Get currently selected data on the item window
  1084. @item = @item_window.item
  1085. # If it can't be used
  1086. unless $game_party.item_can_use?(@item.id)
  1087. # Play buzzer SE
  1088. $game_system.se_play($data_system.buzzer_se)
  1089. return
  1090. end
  1091. # Play decision SE
  1092. $game_system.se_play($data_system.decision_se)
  1093. # Set action
  1094. @active_battler.current_action.item_id = @item.id
  1095. # Make item window invisible
  1096. @item_window.visible = false
  1097. # If effect scope is single enemy
  1098. if @item.scope == 1
  1099. # Start enemy selection
  1100. start_enemy_select
  1101. # If effect scope is single ally
  1102. elsif @item.scope == 3 or @item.scope == 5
  1103. # Start actor selection
  1104. start_actor_select
  1105. # If effect scope is not single
  1106. else
  1107. # End item selection
  1108. end_item_select
  1109. # Go to command input for next actor
  1110. phase3_next_actor
  1111. end
  1112. return
  1113. end
  1114. end
  1115. #--------------------------------------------------------------------------
  1116. # * Frame Updat (actor command phase : enemy selection)
  1117. #--------------------------------------------------------------------------
  1118. def update_phase3_enemy_select
  1119. # Update enemy arrow
  1120. @enemy_arrow.update
  1121. # If B button was pressed
  1122. if Input.trigger?(Input::B)
  1123. # Play cancel SE
  1124. $game_system.se_play($data_system.cancel_se)
  1125. # End enemy selection
  1126. end_enemy_select
  1127. return
  1128. end
  1129. # If C button was pressed
  1130. if Input.trigger?(Input::C)
  1131. # Play decision SE
  1132. $game_system.se_play($data_system.decision_se)
  1133. # Set action
  1134. @active_battler.current_action.target_index = @enemy_arrow.index
  1135. # End enemy selection
  1136. end_enemy_select
  1137. # If skill window is showing
  1138. if @skill_window != nil
  1139. # End skill selection
  1140. end_skill_select
  1141. end
  1142. # If item window is showing
  1143. if @item_window != nil
  1144. # End item selection
  1145. end_item_select
  1146. end
  1147. # Go to command input for next actor
  1148. phase3_next_actor
  1149. end
  1150. end
  1151. #--------------------------------------------------------------------------
  1152. # * Frame Update (actor command phase : actor selection)
  1153. #--------------------------------------------------------------------------
  1154. def update_phase3_actor_select
  1155. # Update actor arrow
  1156. @actor_arrow.update
  1157. # If B button was pressed
  1158. if Input.trigger?(Input::B)
  1159. # Play cancel SE
  1160. $game_system.se_play($data_system.cancel_se)
  1161. # End actor selection
  1162. end_actor_select
  1163. return
  1164. end
  1165. # If C button was pressed
  1166. if Input.trigger?(Input::C)
  1167. # Play decision SE
  1168. $game_system.se_play($data_system.decision_se)
  1169. # Set action
  1170. @active_battler.current_action.target_index = @actor_arrow.index
  1171. # End actor selection
  1172. end_actor_select
  1173. # If skill window is showing
  1174. if @skill_window != nil
  1175. # End skill selection
  1176. end_skill_select
  1177. end
  1178. # If item window is showing
  1179. if @item_window != nil
  1180. # End item selection
  1181. end_item_select
  1182. end
  1183. # Go to command input for next actor
  1184. phase3_next_actor
  1185. end
  1186. end
  1187. #--------------------------------------------------------------------------
  1188. # * Start Enemy Selection
  1189. #--------------------------------------------------------------------------
  1190. def start_enemy_select
  1191. # Make enemy arrow
  1192. @enemy_arrow = Arrow_Enemy.new(@spriteset.viewport1)
  1193. # Associate help window
  1194. @enemy_arrow.help_window = @help_window
  1195. # Disable actor command window
  1196. @actor_command_window.active = false
  1197. @actor_command_window.visible = true
  1198. @actor_command_window.contents_opacity = 0
  1199. end
  1200. #--------------------------------------------------------------------------
  1201. # * End Enemy Selection
  1202. #--------------------------------------------------------------------------
  1203. def end_enemy_select
  1204. # Dispose of enemy arrow
  1205. @enemy_arrow.dispose
  1206. @enemy_arrow = nil
  1207. # If command is [fight]
  1208. if @actor_command_window.index == 0
  1209. # Enable actor command window
  1210. @actor_command_window.active = true
  1211. @actor_command_window.visible = true
  1212. @actor_command_window.contents_opacity = 255
  1213. # Hide help window
  1214. @help_window.visible = false
  1215. end
  1216. end
  1217. #--------------------------------------------------------------------------
  1218. # * Start Actor Selection
  1219. #--------------------------------------------------------------------------
  1220. def start_actor_select
  1221. # Make actor arrow
  1222. @actor_arrow = Arrow_Actor.new(@spriteset.viewport2)
  1223. @actor_arrow.index = @actor_index
  1224. # Associate help window
  1225. @actor_arrow.help_window = @help_window
  1226. # Disable actor command window
  1227. @actor_command_window.active = false
  1228. @actor_command_window.visible = true
  1229. end
  1230. #--------------------------------------------------------------------------
  1231. # * End Actor Selection
  1232. #--------------------------------------------------------------------------
  1233. def end_actor_select
  1234. # Dispose of actor arrow
  1235. @actor_arrow.dispose
  1236. @actor_arrow = nil
  1237. end
  1238. #--------------------------------------------------------------------------
  1239. # * Start Skill Selection
  1240. #--------------------------------------------------------------------------
  1241. def start_skill_select
  1242. # Make skill window
  1243. @skill_window = Window_Skill.new(@active_battler)
  1244. # Associate help window
  1245. @skill_window.help_window = @help_window
  1246. # Disable actor command window
  1247. @actor_command_window.active = false
  1248. @actor_command_window.visible = true
  1249. @actor_command_window.contents_opacity = 0
  1250. end
  1251. #--------------------------------------------------------------------------
  1252. # * End Skill Selection
  1253. #--------------------------------------------------------------------------
  1254. def end_skill_select
  1255. # Dispose of skill window
  1256. @skill_window.dispose
  1257. @skill_window = nil
  1258. # Hide help window
  1259. @help_window.visible = false
  1260. # Enable actor command window
  1261. @actor_command_window.active = true
  1262. @actor_command_window.visible = true
  1263. @actor_command_window.contents_opacity = 255
  1264. end
  1265. #--------------------------------------------------------------------------
  1266. # * Start Item Selection
  1267. #--------------------------------------------------------------------------
  1268. def start_item_select
  1269. # Make item window
  1270. @item_window = Window_Item.new
  1271. # Associate help window
  1272. @item_window.help_window = @help_window
  1273. # Disable actor command window
  1274. @actor_command_window.active = false
  1275. @actor_command_window.visible = true
  1276. @actor_command_window.contents_opacity = 0
  1277. end
  1278. #--------------------------------------------------------------------------
  1279. # * End Item Selection
  1280. #--------------------------------------------------------------------------
  1281. def end_item_select
  1282. # Dispose of item window
  1283. @item_window.dispose
  1284. @item_window = nil
  1285. # Hide help window
  1286. @help_window.visible = false
  1287. # Enable actor command window
  1288. @actor_command_window.active = true
  1289. @actor_command_window.visible = true
  1290. @actor_command_window.contents_opacity = 255
  1291. end
  1292. end
  1293.  
  1294. #==============================================================================
  1295. # ** Scene_Battle (part 4)
  1296. #------------------------------------------------------------------------------
  1297. # This class performs battle screen processing.
  1298. #==============================================================================
  1299.  
  1300. class Scene_Battle
  1301. #--------------------------------------------------------------------------
  1302. # * Start Main Phase
  1303. #--------------------------------------------------------------------------
  1304. def start_phase4
  1305. # Shift to phase 4
  1306. @phase = 4
  1307. # Turn count
  1308. $game_temp.battle_turn += 1
  1309. # Search all battle event pages
  1310. for index in 0...$data_troops[@troop_id].pages.size
  1311. # Get event page
  1312. page = $data_troops[@troop_id].pages[index]
  1313. # If this page span is [turn]
  1314. if page.span == 1
  1315. # Clear action completed flags
  1316. $game_temp.battle_event_flags[index] = false
  1317. end
  1318. end
  1319. # Set actor as unselectable
  1320. @actor_index = -1
  1321. @active_battler = nil
  1322. # Enable party command window
  1323. @party_command_window.active = false
  1324. @party_command_window.visible = false
  1325. # Disable actor command window
  1326. @actor_command_window.active = false
  1327. @actor_command_window.visible = true
  1328. @actor_command_window.contents_opacity = 0
  1329. # Set main phase flag
  1330. $game_temp.battle_main_phase = true
  1331. # Make enemy action
  1332. for enemy in $game_troop.enemies
  1333. enemy.make_action
  1334. end
  1335. # Make action orders
  1336. make_action_orders
  1337. # Shift to step 1
  1338. @phase4_step = 1
  1339. end
  1340. #--------------------------------------------------------------------------
  1341. # * Make Action Orders
  1342. #--------------------------------------------------------------------------
  1343. def make_action_orders
  1344. # Initialize @action_battlers array
  1345. @action_battlers = []
  1346. # Add enemy to @action_battlers array
  1347. for enemy in $game_troop.enemies
  1348. @action_battlers.push(enemy)
  1349. end
  1350. # Add actor to @action_battlers array
  1351. for actor in $game_party.actors
  1352. @action_battlers.push(actor)
  1353. end
  1354. # Decide action speed for all
  1355. for battler in @action_battlers
  1356. battler.make_action_speed
  1357. end
  1358. # Line up action speed in order from greatest to least
  1359. @action_battlers.sort! {|a,b|
  1360. b.current_action.speed - a.current_action.speed }
  1361. end
  1362. #--------------------------------------------------------------------------
  1363. # * Frame Update (main phase)
  1364. #--------------------------------------------------------------------------
  1365. def update_phase4
  1366. case @phase4_step
  1367. when 1
  1368. update_phase4_step1
  1369. when 2
  1370. update_phase4_step2
  1371. when 3
  1372. update_phase4_step3
  1373. when 4
  1374. update_phase4_step4
  1375. when 5
  1376. update_phase4_step5
  1377. when 6
  1378. update_phase4_step6
  1379. end
  1380. end
  1381. #--------------------------------------------------------------------------
  1382. # * Frame Update (main phase step 1 : action preparation)
  1383. #--------------------------------------------------------------------------
  1384. def update_phase4_step1
  1385. # Hide help window
  1386. @help_window.visible = false
  1387. # Determine win/loss
  1388. if judge
  1389. # If won, or if lost : end method
  1390. return
  1391. end
  1392. # If an action forcing battler doesn't exist
  1393. if $game_temp.forcing_battler == nil
  1394. # Set up battle event
  1395. setup_battle_event
  1396. # If battle event is running
  1397. if $game_system.battle_interpreter.running?
  1398. return
  1399. end
  1400. end
  1401. # If an action forcing battler exists
  1402. if $game_temp.forcing_battler != nil
  1403. # Add to head, or move
  1404. @action_battlers.delete($game_temp.forcing_battler)
  1405. @action_battlers.unshift($game_temp.forcing_battler)
  1406. end
  1407. # If no actionless battlers exist (all have performed an action)
  1408. if @action_battlers.size == 0
  1409. # Start party command phase
  1410. start_phase2
  1411. return
  1412. end
  1413. # Initialize animation ID and common event ID
  1414. @animation1_id = 0
  1415. @animation2_id = 0
  1416. @common_event_id = 0
  1417. # Shift from head of actionless battlers
  1418. @active_battler = @action_battlers.shift
  1419. # If already removed from battle
  1420. if @active_battler.index == nil
  1421. return
  1422. end
  1423. # Slip damage
  1424. if @active_battler.hp > 0 and @active_battler.slip_damage?
  1425. @active_battler.slip_damage_effect
  1426. @active_battler.damage_pop = true
  1427. end
  1428. # Natural removal of states
  1429. @active_battler.remove_states_auto
  1430. # Refresh status window
  1431. @status_window.refresh
  1432. # Shift to step 2
  1433. @phase4_step = 2
  1434. end
  1435. #--------------------------------------------------------------------------
  1436. # * Frame Update (main phase step 2 : start action)
  1437. #--------------------------------------------------------------------------
  1438. def update_phase4_step2
  1439. # If not a forcing action
  1440. unless @active_battler.current_action.forcing
  1441. # If restriction is [normal attack enemy] or [normal attack ally]
  1442. if @active_battler.restriction == 2 or @active_battler.restriction == 3
  1443. # Set attack as an action
  1444. @active_battler.current_action.kind = 0
  1445. @active_battler.current_action.basic = 0
  1446. end
  1447. # If restriction is [cannot perform action]
  1448. if @active_battler.restriction == 4
  1449. # Clear battler being forced into action
  1450. $game_temp.forcing_battler = nil
  1451. # Shift to step 1
  1452. @phase4_step = 1
  1453. return
  1454. end
  1455. end
  1456. # Clear target battlers
  1457. @target_battlers = []
  1458. # Branch according to each action
  1459. case @active_battler.current_action.kind
  1460. when 0 # basic
  1461. make_basic_action_result
  1462. when 1 # skill
  1463. make_skill_action_result
  1464. when 2 # item
  1465. make_item_action_result
  1466. end
  1467. # Shift to step 3
  1468. if @phase4_step == 2
  1469. @phase4_step = 3
  1470. end
  1471. end
  1472. #--------------------------------------------------------------------------
  1473. # * Make Basic Action Results
  1474. #--------------------------------------------------------------------------
  1475. def make_basic_action_result
  1476. # If attack
  1477. if @active_battler.current_action.basic == 0
  1478. # Set anaimation ID
  1479. @animation1_id = @active_battler.animation1_id
  1480. @animation2_id = @active_battler.animation2_id
  1481. # If action battler is enemy
  1482. if @active_battler.is_a?(Game_Enemy)
  1483. if @active_battler.restriction == 3
  1484. target = $game_troop.random_target_enemy
  1485. elsif @active_battler.restriction == 2
  1486. target = $game_party.random_target_actor
  1487. else
  1488. index = @active_battler.current_action.target_index
  1489. target = $game_party.smooth_target_actor(index)
  1490. end
  1491. end
  1492. # If action battler is actor
  1493. if @active_battler.is_a?(Game_Actor)
  1494. if @active_battler.restriction == 3
  1495. target = $game_party.random_target_actor
  1496. elsif @active_battler.restriction == 2
  1497. target = $game_troop.random_target_enemy
  1498. else
  1499. index = @active_battler.current_action.target_index
  1500. target = $game_troop.smooth_target_enemy(index)
  1501. end
  1502. end
  1503. # Set array of targeted battlers
  1504. @target_battlers = [target]
  1505. # Apply normal attack results
  1506. for target in @target_battlers
  1507. target.attack_effect(@active_battler)
  1508. end
  1509. return
  1510. end
  1511. # If guard
  1512. if @active_battler.current_action.basic == 1
  1513. # Display "Guard" in help window
  1514. @help_window.set_text($data_system.words.guard, 1)
  1515. return
  1516. end
  1517. # If escape
  1518. if @active_battler.is_a?(Game_Enemy) and
  1519. @active_battler.current_action.basic == 2
  1520. # Display "Escape" in help window
  1521. @help_window.set_text("Escape", 1)
  1522. # Escape
  1523. @active_battler.escape
  1524. return
  1525. end
  1526. # If doing nothing
  1527. if @active_battler.current_action.basic == 3
  1528. # Clear battler being forced into action
  1529. $game_temp.forcing_battler = nil
  1530. # Shift to step 1
  1531. @phase4_step = 1
  1532. return
  1533. end
  1534. end
  1535. #--------------------------------------------------------------------------
  1536. # * Set Targeted Battler for Skill or Item
  1537. # scope : effect scope for skill or item
  1538. #--------------------------------------------------------------------------
  1539. def set_target_battlers(scope)
  1540. # If battler performing action is enemy
  1541. if @active_battler.is_a?(Game_Enemy)
  1542. # Branch by effect scope
  1543. case scope
  1544. when 1 # single enemy
  1545. index = @active_battler.current_action.target_index
  1546. @target_battlers.push($game_party.smooth_target_actor(index))
  1547. when 2 # all enemies
  1548. for actor in $game_party.actors
  1549. if actor.exist?
  1550. @target_battlers.push(actor)
  1551. end
  1552. end
  1553. when 3 # single ally
  1554. index = @active_battler.current_action.target_index
  1555. @target_battlers.push($game_troop.smooth_target_enemy(index))
  1556. when 4 # all allies
  1557. for enemy in $game_troop.enemies
  1558. if enemy.exist?
  1559. @target_battlers.push(enemy)
  1560. end
  1561. end
  1562. when 5 # single ally (HP 0)
  1563. index = @active_battler.current_action.target_index
  1564. enemy = $game_troop.enemies[index]
  1565. if enemy != nil and enemy.hp0?
  1566. @target_battlers.push(enemy)
  1567. end
  1568. when 6 # all allies (HP 0)
  1569. for enemy in $game_troop.enemies
  1570. if enemy != nil and enemy.hp0?
  1571. @target_battlers.push(enemy)
  1572. end
  1573. end
  1574. when 7 # user
  1575. @target_battlers.push(@active_battler)
  1576. end
  1577. end
  1578. # If battler performing action is actor
  1579. if @active_battler.is_a?(Game_Actor)
  1580. # Branch by effect scope
  1581. case scope
  1582. when 1 # single enemy
  1583. index = @active_battler.current_action.target_index
  1584. @target_battlers.push($game_troop.smooth_target_enemy(index))
  1585. when 2 # all enemies
  1586. for enemy in $game_troop.enemies
  1587. if enemy.exist?
  1588. @target_battlers.push(enemy)
  1589. end
  1590. end
  1591. when 3 # single ally
  1592. index = @active_battler.current_action.target_index
  1593. @target_battlers.push($game_party.smooth_target_actor(index))
  1594. when 4 # all allies
  1595. for actor in $game_party.actors
  1596. if actor.exist?
  1597. @target_battlers.push(actor)
  1598. end
  1599. end
  1600. when 5 # single ally (HP 0)
  1601. index = @active_battler.current_action.target_index
  1602. actor = $game_party.actors[index]
  1603. if actor != nil and actor.hp0?
  1604. @target_battlers.push(actor)
  1605. end
  1606. when 6 # all allies (HP 0)
  1607. for actor in $game_party.actors
  1608. if actor != nil and actor.hp0?
  1609. @target_battlers.push(actor)
  1610. end
  1611. end
  1612. when 7 # user
  1613. @target_battlers.push(@active_battler)
  1614. end
  1615. end
  1616. end
  1617. #--------------------------------------------------------------------------
  1618. # * Make Skill Action Results
  1619. #--------------------------------------------------------------------------
  1620. def make_skill_action_result
  1621. # Get skill
  1622. @skill = $data_skills[@active_battler.current_action.skill_id]
  1623. # If not a forcing action
  1624. unless @active_battler.current_action.forcing
  1625. # If unable to use due to SP running out
  1626. unless @active_battler.skill_can_use?(@skill.id)
  1627. # Clear battler being forced into action
  1628. $game_temp.forcing_battler = nil
  1629. # Shift to step 1
  1630. @phase4_step = 1
  1631. return
  1632. end
  1633. end
  1634. # Use up SP
  1635. @active_battler.sp -= @skill.sp_cost
  1636. # Refresh status window
  1637. @status_window.refresh
  1638. # Show skill name on help window
  1639. @help_window.set_text(@skill.name, 1)
  1640. # Set animation ID
  1641. @animation1_id = @skill.animation1_id
  1642. @animation2_id = @skill.animation2_id
  1643. # Set command event ID
  1644. @common_event_id = @skill.common_event_id
  1645. # Set target battlers
  1646. set_target_battlers(@skill.scope)
  1647. # Apply skill effect
  1648. for target in @target_battlers
  1649. target.skill_effect(@active_battler, @skill)
  1650. end
  1651. end
  1652. #--------------------------------------------------------------------------
  1653. # * Make Item Action Results
  1654. #--------------------------------------------------------------------------
  1655. def make_item_action_result
  1656. # Get item
  1657. @item = $data_items[@active_battler.current_action.item_id]
  1658. # If unable to use due to items running out
  1659. unless $game_party.item_can_use?(@item.id)
  1660. # Shift to step 1
  1661. @phase4_step = 1
  1662. return
  1663. end
  1664. # If consumable
  1665. if @item.consumable
  1666. # Decrease used item by 1
  1667. $game_party.lose_item(@item.id, 1)
  1668. end
  1669. # Display item name on help window
  1670. @help_window.set_text(@item.name, 1)
  1671. # Set animation ID
  1672. @animation1_id = @item.animation1_id
  1673. @animation2_id = @item.animation2_id
  1674. # Set common event ID
  1675. @common_event_id = @item.common_event_id
  1676. # Decide on target
  1677. index = @active_battler.current_action.target_index
  1678. target = $game_party.smooth_target_actor(index)
  1679. # Set targeted battlers
  1680. set_target_battlers(@item.scope)
  1681. # Apply item effect
  1682. for target in @target_battlers
  1683. target.item_effect(@item)
  1684. end
  1685. end
  1686. #--------------------------------------------------------------------------
  1687. # * Frame Update (main phase step 3 : animation for action performer)
  1688. #--------------------------------------------------------------------------
  1689. def update_phase4_step3
  1690. # Animation for action performer (if ID is 0, then white flash)
  1691. if @animation1_id == 0
  1692. @active_battler.white_flash = true
  1693. else
  1694. @active_battler.animation_id = @animation1_id
  1695. @active_battler.animation_hit = true
  1696. end
  1697. # Shift to step 4
  1698. @phase4_step = 4
  1699. end
  1700. #--------------------------------------------------------------------------
  1701. # * Frame Update (main phase step 4 : animation for target)
  1702. #--------------------------------------------------------------------------
  1703. def update_phase4_step4
  1704. # Animation for target
  1705. for target in @target_battlers
  1706. target.animation_id = @animation2_id
  1707. target.animation_hit = (target.damage != "Miss")
  1708. end
  1709. # Animation has at least 8 frames, regardless of its length
  1710. @wait_count = 8
  1711. # Shift to step 5
  1712. @phase4_step = 5
  1713. end
  1714. #--------------------------------------------------------------------------
  1715. # * Frame Update (main phase step 5 : damage display)
  1716. #--------------------------------------------------------------------------
  1717. def update_phase4_step5
  1718. # Hide help window
  1719. @help_window.visible = false
  1720. # Refresh status window
  1721. @status_window.refresh
  1722. # Display damage
  1723. for target in @target_battlers
  1724. if target.damage != nil
  1725. target.damage_pop = true
  1726. end
  1727. end
  1728. # Shift to step 6
  1729. @phase4_step = 6
  1730. end
  1731. #--------------------------------------------------------------------------
  1732. # * Frame Update (main phase step 6 : refresh)
  1733. #--------------------------------------------------------------------------
  1734. def update_phase4_step6
  1735. # Clear battler being forced into action
  1736. $game_temp.forcing_battler = nil
  1737. # If common event ID is valid
  1738. if @common_event_id > 0
  1739. # Set up event
  1740. common_event = $data_common_events[@common_event_id]
  1741. $game_system.battle_interpreter.setup(common_event.list, 0)
  1742. end
  1743. # Shift to step 1
  1744. @phase4_step = 1
  1745. end
  1746. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement