Advertisement
Archeia

Yanfly Engine Ace - Instant Cast v1.03

Mar 30th, 2014
831
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 12.43 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. # ▼ Yanfly Engine Ace - Instant Cast v1.03
  4. # -- Last Updated: 2012.07.17
  5. # -- Level: Normal
  6. # -- Requires: n/a
  7. #
  8. #==============================================================================
  9.  
  10. $imported = {} if $imported.nil?
  11. $imported["YEA-InstantCast"] = true
  12.  
  13. #==============================================================================
  14. # ▼  Updates
  15. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  16. # 2012.07.17 - Instant doesn't take up a turn if a characterh as additional
  17. #              actions/can attack twice.
  18. # 2012.01.12 - Anti-crash methods implemented.
  19. # 2011.12.26 - Bug Fixed: If actor gets stunned while doing an instant cast,
  20. #              the actor will not be reselected.
  21. # 2011.12.21 - Started Script and Finished.
  22. #
  23. #==============================================================================
  24. # ▼  Introduction
  25. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  26. # From the VX Yanfly Engines, instant cast properties have been a staple skill
  27. # and item property. Instant cast makes a return in RPG Maker VX Ace. There's
  28. # a few changes made with instant casts.
  29. #
  30. # 1) For actors with multiple actions, instants will only occur if the first
  31. #    action is an instant. If the first action is not an instant the follow-up
  32. #    actions contain an instant, the instant will be treated as normal.
  33. #
  34. # 2) Any actions added on by instants will automatically trigger immediately
  35. #    after the instant finishes and will be treated as instants. This includes
  36. #    Active Chain Skills triggering from an instant.
  37. #
  38. # 3) If an enemy uses an instant, the enemy will gain an additional skill to
  39. #    use after using the said instant. This will apply whenever an enemy uses
  40. #    an instant skill, even if it was after the enemy's first action.
  41. #
  42. #==============================================================================
  43. # ▼  Instructions
  44. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  45. # To install this script, open up your script editor and copy/paste this script
  46. # to an open slot below ▼  Materials/‘fÞ but above ▼  Main. Remember to save.
  47. #
  48. # -----------------------------------------------------------------------------
  49. # Skill Notetags - These notetags go in the skills notebox in the database.
  50. # -----------------------------------------------------------------------------
  51. # <instant>
  52. # Causes the action to be an instant action. If an instant action is selected
  53. # first, then the action will be performed before the battle phase starts. If
  54. # placed behind a non-instant action, the would-be instant action will be
  55. # considered a normal action. If an enemy uses an instant action, no matter if
  56. # it was used first or after, the enemy gains an additional action.
  57. #
  58. # -----------------------------------------------------------------------------
  59. # Item Notetags - These notetags go in the items notebox in the database.
  60. # -----------------------------------------------------------------------------
  61. # <instant>
  62. # Causes the action to be an instant action. If an instant action is selected
  63. # first, then the action will be performed before the battle phase starts. If
  64. # placed behind a non-instant action, the would-be instant action will be
  65. # considered a normal action. If an enemy uses an instant action, no matter if
  66. # it was used first or after, the enemy gains an additional action.
  67. #
  68. #==============================================================================
  69. # ▼  Compatibility
  70. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  71. # This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
  72. # it will run with RPG Maker VX without adjusting.
  73. #
  74. # This script is compatible with Yanfly Engine Ace - Ace Battle Engine v1.00+.
  75. # Place this script under Ace Battle Engine in the script listing
  76. #
  77. #==============================================================================
  78. # ▼  Editting anything past this point may potentially result in causing
  79. # computer damage, incontinence, explosion of user's head, coma, death, and/or
  80. # halitosis so edit at your own risk.
  81. #==============================================================================
  82.  
  83. module YEA
  84.   module REGEXP
  85.   module USABLEITEM
  86.    
  87.     INSTANT = /<(?:INSTANT|instant)>/i
  88.    
  89.   end # USABLEITEM
  90.   end # REGEXP
  91. end # YEA
  92.  
  93. #==============================================================================
  94. # ¡ DataManager
  95. #==============================================================================
  96.  
  97. module DataManager
  98.  
  99.   #--------------------------------------------------------------------------
  100.   # alias method: load_database
  101.   #--------------------------------------------------------------------------
  102.   class <<self; alias load_database_instant load_database; end
  103.   def self.load_database
  104.     load_database_instant
  105.     load_notetags_instant
  106.   end
  107.  
  108.   #--------------------------------------------------------------------------
  109.   # new method: load_notetags_instant
  110.   #--------------------------------------------------------------------------
  111.   def self.load_notetags_instant
  112.     groups = [$data_skills, $data_items]
  113.     for group in groups
  114.       for obj in group
  115.         next if obj.nil?
  116.         obj.load_notetags_instant
  117.       end
  118.     end
  119.   end
  120.  
  121. end # DataManager
  122.  
  123. #==============================================================================
  124. # ¡ RPG::UsableItem
  125. #==============================================================================
  126.  
  127. class RPG::UsableItem < RPG::BaseItem
  128.  
  129.   #--------------------------------------------------------------------------
  130.   # public instance variables
  131.   #--------------------------------------------------------------------------
  132.   attr_accessor :instant
  133.  
  134.   #--------------------------------------------------------------------------
  135.   # common cache: load_notetags_instant
  136.   #--------------------------------------------------------------------------
  137.   def load_notetags_instant
  138.     @instant = false
  139.     #---
  140.     self.note.split(/[\r\n]+/).each { |line|
  141.       case line
  142.       #---
  143.       when YEA::REGEXP::USABLEITEM::INSTANT
  144.         @instant = true
  145.       #---
  146.       end
  147.     } # self.note.split
  148.     #---
  149.   end
  150.  
  151. end # RPG::UsableItem
  152.  
  153. #==============================================================================
  154. # ¡ Game_Actor
  155. #==============================================================================
  156.  
  157. class Game_Actor < Game_Battler
  158.  
  159.   #--------------------------------------------------------------------------
  160.   # new method: check_instant_action
  161.   #--------------------------------------------------------------------------
  162.   def check_instant_action
  163.     @backup_actions_instant = []
  164.     @actions.each { |action|
  165.       next unless action
  166.       if action.item.nil?
  167.         @backup_actions_instant.push(action.dup)
  168.         next
  169.       end
  170.       unless action.item.instant
  171.         @backup_actions_instant.push(action.dup)
  172.         action.clear
  173.       end
  174.     }
  175.   end
  176.  
  177.   #--------------------------------------------------------------------------
  178.   # new method: restore_instant_action
  179.   #--------------------------------------------------------------------------
  180.   def restore_instant_action
  181.     @backup_actions_instant.each_index { |i|
  182.       @actions[i] = @backup_actions_instant[i]
  183.     }
  184.     @backup_actions_instant.clear
  185.     i = 0
  186.     @actions.each { |action| if action.item.nil?; break; end; i += 1 }
  187.     @action_input_index = i
  188.   end
  189.  
  190. end # Game_Actor
  191.  
  192. #==============================================================================
  193. # ¡ Game_Enemy
  194. #==============================================================================
  195.  
  196. class Game_Enemy < Game_Battler
  197.  
  198.   #--------------------------------------------------------------------------
  199.   # new method: add_extra_action
  200.   #--------------------------------------------------------------------------
  201.   def add_extra_action
  202.     action_list = enemy.actions.select {|a| action_valid?(a) }
  203.     return if action_list.empty?
  204.     rating_max = action_list.collect {|a| a.rating }.max
  205.     rating_zero = rating_max - 3
  206.     action_list.reject! {|a| a.rating <= rating_zero }
  207.     action = Game_Action.new(self)
  208.     action.set_enemy_action(select_enemy_action(action_list, rating_zero))
  209.     @actions.push(action)
  210.   end
  211.  
  212. end # Game_Enemy
  213.  
  214. #==============================================================================
  215. # ¡ Scene_Battle
  216. #==============================================================================
  217.  
  218. class Scene_Battle < Scene_Base
  219.  
  220.   #--------------------------------------------------------------------------
  221.   # alias method: next_command
  222.   #--------------------------------------------------------------------------
  223.   alias scene_battle_next_command_instant next_command
  224.   def next_command
  225.     if instant_action?
  226.       perform_instant_action
  227.     else
  228.       scene_battle_next_command_instant
  229.     end
  230.   end
  231.  
  232.   #--------------------------------------------------------------------------
  233.   # new method: instant_action?
  234.   #--------------------------------------------------------------------------
  235.   def instant_action?
  236.     return false if BattleManager.actor.nil?
  237.     return false if BattleManager.actor.input.nil?
  238.     action = BattleManager.actor.input.item
  239.     return false if action.nil?
  240.     return action.instant
  241.   end
  242.  
  243.   #--------------------------------------------------------------------------
  244.   # new method: perform_instant_action
  245.   #--------------------------------------------------------------------------
  246.   def perform_instant_action
  247.     hide_instant_action_windows
  248.     @subject = BattleManager.actor
  249.     @subject.check_instant_action
  250.     execute_action if @subject.current_action.valid?
  251.     process_event
  252.     loop do
  253.       @subject.remove_current_action
  254.       break if $game_troop.all_dead?
  255.       break unless @subject.current_action
  256.       @subject.current_action.prepare
  257.       execute_action if @subject.current_action.valid?
  258.     end
  259.     process_action_end
  260.     @subject.make_actions
  261.     @subject.restore_instant_action
  262.     @subject = nil
  263.     show_instant_action_windows
  264.   end
  265.  
  266.   #--------------------------------------------------------------------------
  267.   # new method: hide_instant_action_windows
  268.   #--------------------------------------------------------------------------
  269.   def hide_instant_action_windows
  270.     if $imported["YEA-BattleEngine"]
  271.       @info_viewport.visible = true
  272.       @status_aid_window.hide
  273.       @status_window.show
  274.       @actor_command_window.show
  275.     end
  276.   end
  277.  
  278.   #--------------------------------------------------------------------------
  279.   # new method: show_instant_action_windows
  280.   #--------------------------------------------------------------------------
  281.   def show_instant_action_windows
  282.     if $imported["YEA-BattleEngine"]
  283.       @info_viewport.visible = true
  284.     end
  285.     start_actor_command_selection
  286.     status_redraw_target(BattleManager.actor)
  287.     next_command unless BattleManager.actor.inputable?
  288.   end
  289.  
  290.   #--------------------------------------------------------------------------
  291.   # new method: status_redraw_target
  292.   #--------------------------------------------------------------------------
  293.   def status_redraw_target(target)
  294.     return unless target.actor?
  295.     @status_window.draw_item($game_party.battle_members.index(target))
  296.   end
  297.  
  298.   #--------------------------------------------------------------------------
  299.   # alias method: execute_action
  300.   #--------------------------------------------------------------------------
  301.   alias scene_battle_execute_action_instant execute_action
  302.   def execute_action
  303.     scene_battle_execute_action_instant
  304.     enemy_add_actions
  305.   end
  306.  
  307.   #--------------------------------------------------------------------------
  308.   # new method: enemy_add_actions
  309.   #--------------------------------------------------------------------------
  310.   def enemy_add_actions
  311.     return if @subject.actor?
  312.     return if @subject.current_action.nil?
  313.     return if @subject.current_action.item.nil?
  314.     return unless @subject.current_action.item.instant
  315.     @subject.add_extra_action
  316.   end
  317.  
  318. end # Scene_Battle
  319.  
  320. #==============================================================================
  321. #
  322. # ▼  End of File
  323. #
  324. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement