Project1

标题: 跪求自动战斗脚本(强制自动战斗) [打印本页]

作者: qq987042370    时间: 2013-8-19 15:54
标题: 跪求自动战斗脚本(强制自动战斗)
RT                              
作者: 蛙仔    时间: 2013-8-20 10:37
特殊标志:自动战斗
作者: 3106345123    时间: 2013-8-20 10:41
  1. #==============================================================================
  2. #
  3. # ▼ Yanfly Engine Ace - Command Autobattle v1.01
  4. # -- Last Updated: 2011.12.26
  5. # -- Level: Normal
  6. # -- Requires: n/a
  7. #
  8. #==============================================================================

  9. $imported = {} if $imported.nil?
  10. $imported["YEA-CommandAutobattle"] = true

  11. #==============================================================================
  12. # ▼ Updates
  13. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  14. # 2011.12.26 - Bug Fixed: Autobattle cancelled after each battle.
  15. # 2011.12.12 - Started Script and Finished.
  16. #
  17. #==============================================================================
  18. # ▼ Introduction
  19. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  20. # Anyone remember the Autobattle command from RPG Maker 2000? Well, now it's
  21. # back and you can choose to tack it onto the Party Command Window or the Actor
  22. # Command Window. When autobattle is selected, it will let the game determine
  23. # what action to use for the party and/or actors depending on the game's A.I.
  24. #
  25. # Furthermore, there is an option to have Autobattle continously remain in
  26. # effect if selected from the Party Command Window. When Autobattle is selected
  27. # in the Actor Command Window, it'll cause the game to automatically choose an
  28. # action for that actor instead.
  29. #
  30. # In addition to this, there exists the functionality of having all battle
  31. # members but the first member autobattle. This feature can be turned off.
  32. #
  33. #==============================================================================
  34. # ▼ Instructions
  35. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  36. # To install this script, open up your script editor and copy/paste this script
  37. # to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.
  38. #
  39. # Adjust the settings in the module to your liking.
  40. #
  41. #==============================================================================
  42. # ▼ Compatibility
  43. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  44. # This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
  45. # it will run with RPG Maker VX without adjusting.
  46. #
  47. #==============================================================================

  48. module YEA
  49.   module AUTOBATTLE
  50.    
  51.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  52.     # - Party Autobattle Command Settings -
  53.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  54.     # Adjust the command settings for Autobattle under the Party Command Window
  55.     # here. If you decide to let Party Autobattle be continuous, it will keep
  56.     # going until the player decides to cancel it with X.
  57.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  58.     ENABLE_PARTY_AUTOBATTLE = true      # Enables autobattle in Party Window.
  59.     PARTY_COMMAND_NAME  = "自动"        # Text that appears for Autobattle.
  60.     PARTY_SHOW_SWITCH   = 0             # Switch used to show Autobattle.
  61.     PARTY_ENABLE_SWITCH = 0             # Switch used to enable Autobattle.
  62.     # Note: For both of the switches, if they are set to 0, then the feature
  63.     # will not be used at all. The command will always be shown and/or the
  64.     # command will always be enabled.
  65.    
  66.     # These settings adjust continous autobattle. If enabled, these settings
  67.     # will be applied. Otherwise, they won't be.
  68.     ENABLE_CONTINOUS = true             # If true, autobattle is continous.
  69.     DISABLE_MESSAGE = "自动战斗中"
  70.    
  71.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  72.     # - Actor Autobattle Command Settings -
  73.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  74.     # Adjust the command settings for Autobattle under the Actor Command Window
  75.     # here. Actors do not have continous autobattle. Instead, they just simply
  76.     # choose whatever action the game decides is most suitable for them.
  77.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  78.     ENABLE_ACTOR_AUTOBATTLE = true      # Enables autobattle in Party Window.
  79.     ACTOR_COMMAND_NAME  = "自动"        # Text that appears for Autobattle.
  80.     ACTOR_SHOW_SWITCH   = 0             # Switch used to show Autobattle.
  81.     ACTOR_ENABLE_SWITCH = 0             # Switch used to enable Autobattle.
  82.     # Note: For both of the switches, if they are set to 0, then the feature
  83.     # will not be used at all. The command will always be shown and/or the
  84.     # command will always be enabled.
  85.    
  86.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  87.     # - Secondary Members Autobattle -
  88.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  89.     # For those who only want to grant command control to the first actor in
  90.     # battle, enable the setting below. All of the battle members who aren't
  91.     # first in line will automatically choose their action for the turn.
  92.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  93.     ENABLE_SECONDARY_AUTOBATTLE = false
  94.    
  95.   end # AUTOBATTLE
  96. end # YEA

  97. #==============================================================================
  98. # ▼ Editting anything past this point may potentially result in causing
  99. # computer damage, incontinence, explosion of user's head, coma, death, and/or
  100. # halitosis so edit at your own risk.
  101. #==============================================================================

  102. #==============================================================================
  103. # ■ BattleManager
  104. #==============================================================================

  105. module BattleManager
  106.   
  107.   #--------------------------------------------------------------------------
  108.   # alias method: process_victory
  109.   #--------------------------------------------------------------------------
  110.   class <<self; alias battlemanager_process_victory_cab process_victory; end
  111.   def self.process_victory
  112.     SceneManager.scene.close_disable_autobattle_window
  113.     return battlemanager_process_victory_cab
  114.   end
  115.   
  116.   #--------------------------------------------------------------------------
  117.   # alias method: process_abort
  118.   #--------------------------------------------------------------------------
  119.   class <<self; alias battlemanager_process_abort_cab process_abort; end
  120.   def self.process_abort
  121.     SceneManager.scene.close_disable_autobattle_window
  122.     return battlemanager_process_abort_cab
  123.   end
  124.   
  125.   #--------------------------------------------------------------------------
  126.   # alias method: process_defeat
  127.   #--------------------------------------------------------------------------
  128.   class <<self; alias battlemanager_process_defeat_cab process_defeat; end
  129.   def self.process_defeat
  130.     SceneManager.scene.close_disable_autobattle_window
  131.     return battlemanager_process_defeat_cab
  132.   end
  133.   
  134. end # BattleManager

  135. #==============================================================================
  136. # ■ Game_Temp
  137. #==============================================================================

  138. class Game_Temp
  139.   
  140.   #--------------------------------------------------------------------------
  141.   # public instance variables
  142.   #--------------------------------------------------------------------------
  143.   attr_accessor :continous_autobattle
  144.   
  145. end # Game_Temp

  146. #==============================================================================
  147. # ■ Game_BattlerBase
  148. #==============================================================================

  149. class Game_BattlerBase
  150.   
  151.   #--------------------------------------------------------------------------
  152.   # alias method: auto_battle?
  153.   #--------------------------------------------------------------------------
  154.   alias game_battlerbase_auto_battle_cab auto_battle?
  155.   def auto_battle?
  156.     return true if continuous_autobattle?
  157.     return true if secondary_auto_battle?
  158.     return game_battlerbase_auto_battle_cab
  159.   end
  160.   
  161.   #--------------------------------------------------------------------------
  162.   # new method: continuous_autobattle?
  163.   #--------------------------------------------------------------------------
  164.   def continuous_autobattle?
  165.     return false unless actor?
  166.     return $game_temp.continous_autobattle
  167.   end
  168.   
  169.   #--------------------------------------------------------------------------
  170.   # new method: secondary_auto_battle?
  171.   #--------------------------------------------------------------------------
  172.   def secondary_auto_battle?
  173.     return false unless actor?
  174.     return false if index == 0
  175.     return YEA::AUTOBATTLE::ENABLE_SECONDARY_AUTOBATTLE
  176.   end
  177.   
  178. end # Game_BattlerBase

  179. #==============================================================================
  180. # ■ Game_Unit
  181. #==============================================================================

  182. class Game_Unit
  183.   
  184.   #--------------------------------------------------------------------------
  185.   # alias method: make_actions
  186.   #--------------------------------------------------------------------------
  187.   alias game_unit_make_actions_cab make_actions
  188.   def make_actions
  189.     game_unit_make_actions_cab
  190.     refresh_autobattler_status_window
  191.   end
  192.   
  193.   #--------------------------------------------------------------------------
  194.   # new method: refresh_autobattler_status_window
  195.   #--------------------------------------------------------------------------
  196.   def refresh_autobattler_status_window
  197.     return unless SceneManager.scene_is?(Scene_Battle)
  198.     return unless self.is_a?(Game_Party)
  199.     SceneManager.scene.refresh_autobattler_status_window
  200.   end
  201.   
  202. end # Game_Unit

  203. #==============================================================================
  204. # ■ Window_PartyCommand
  205. #==============================================================================

  206. class Window_PartyCommand < Window_Command
  207.   
  208.   #--------------------------------------------------------------------------
  209.   # alias method: make_command_list
  210.   #--------------------------------------------------------------------------
  211.   alias window_partycommand_cab make_command_list
  212.   def make_command_list
  213.     window_partycommand_cab
  214.     return if $imported["YEA-BattleCommandList"]
  215.     add_autobattle_command if YEA::AUTOBATTLE::ENABLE_PARTY_AUTOBATTLE
  216.   end
  217.   
  218.   #--------------------------------------------------------------------------
  219.   # new method: add_autobattle_command
  220.   #--------------------------------------------------------------------------
  221.   def add_autobattle_command
  222.     return unless show_autobattle?
  223.     text = YEA::AUTOBATTLE::PARTY_COMMAND_NAME
  224.     add_command(text, :autobattle, enable_autobattle?)
  225.   end
  226.   
  227.   #--------------------------------------------------------------------------
  228.   # new method: show_autobattle?
  229.   #--------------------------------------------------------------------------
  230.   def show_autobattle?
  231.     return true if YEA::AUTOBATTLE::PARTY_SHOW_SWITCH <= 0
  232.     return $game_switches[YEA::AUTOBATTLE::PARTY_SHOW_SWITCH]
  233.   end
  234.   
  235.   #--------------------------------------------------------------------------
  236.   # new method: enable_autobattle?
  237.   #--------------------------------------------------------------------------
  238.   def enable_autobattle?
  239.     return true if YEA::AUTOBATTLE::PARTY_ENABLE_SWITCH <= 0
  240.     return $game_switches[YEA::AUTOBATTLE::PARTY_ENABLE_SWITCH]
  241.   end
  242.   
  243. end # Window_PartyCommand

  244. #==============================================================================
  245. # ■ Window_ActorCommand
  246. #==============================================================================

  247. class Window_ActorCommand < Window_Command
  248.   
  249.   #--------------------------------------------------------------------------
  250.   # alias method: make_command_list
  251.   #--------------------------------------------------------------------------
  252.   alias window_actorcommand_make_command_list_cab make_command_list
  253.   def make_command_list
  254.     return if @actor.nil?
  255.     unless $imported["YEA-BattleCommandList"]
  256.       add_autobattle_command if YEA::AUTOBATTLE::ENABLE_ACTOR_AUTOBATTLE
  257.     end
  258.     window_actorcommand_make_command_list_cab
  259.   end
  260.   
  261.   #--------------------------------------------------------------------------
  262.   # new method: add_autobattle_command
  263.   #--------------------------------------------------------------------------
  264.   def add_autobattle_command
  265.     return unless show_autobattle?
  266.     text = YEA::AUTOBATTLE::ACTOR_COMMAND_NAME
  267.     add_command(text, :autobattle, enable_autobattle?)
  268.   end
  269.   
  270.   #--------------------------------------------------------------------------
  271.   # new method: show_autobattle?
  272.   #--------------------------------------------------------------------------
  273.   def show_autobattle?
  274.     return true if YEA::AUTOBATTLE::ACTOR_SHOW_SWITCH <= 0
  275.     return $game_switches[YEA::AUTOBATTLE::ACTOR_SHOW_SWITCH]
  276.   end
  277.   
  278.   #--------------------------------------------------------------------------
  279.   # new method: enable_autobattle?
  280.   #--------------------------------------------------------------------------
  281.   def enable_autobattle?
  282.     return true if YEA::AUTOBATTLE::ACTOR_ENABLE_SWITCH <= 0
  283.     return $game_switches[YEA::AUTOBATTLE::ACTOR_ENABLE_SWITCH]
  284.   end
  285.   
  286. end # Window_ActorCommand

  287. #==============================================================================
  288. # ■ Window_DisableAutobattle
  289. #==============================================================================

  290. class Window_DisableAutobattle < Window_Base
  291.   
  292.   #--------------------------------------------------------------------------
  293.   # initialize
  294.   #--------------------------------------------------------------------------
  295.   def initialize
  296.     super(64, 0, Graphics.width - 128, fitting_height(1))
  297.     self.y = Graphics.height - fitting_height(1) + 12
  298.     self.opacity = 0
  299.     self.z = 1000
  300.     hide
  301.     refresh
  302.   end
  303.   
  304.   #--------------------------------------------------------------------------
  305.   # refresh
  306.   #--------------------------------------------------------------------------
  307.   def refresh
  308.     contents.clear
  309.     draw_background(contents.rect)
  310.     text = YEA::AUTOBATTLE::DISABLE_MESSAGE
  311.     draw_text(contents.rect, text, 1)
  312.   end
  313.   
  314.   #--------------------------------------------------------------------------
  315.   # draw_background
  316.   #--------------------------------------------------------------------------
  317.   def draw_background(rect)
  318.     temp_rect = rect.clone
  319.     temp_rect.width /= 2
  320.     contents.gradient_fill_rect(temp_rect, back_color2, back_color1)
  321.     temp_rect.x = temp_rect.width
  322.     contents.gradient_fill_rect(temp_rect, back_color1, back_color2)
  323.   end
  324.   
  325.   #--------------------------------------------------------------------------
  326.   # back_color1
  327.   #--------------------------------------------------------------------------
  328.   def back_color1; return Color.new(0, 0, 0, 192); end
  329.   
  330.   #--------------------------------------------------------------------------
  331.   # back_color2
  332.   #--------------------------------------------------------------------------
  333.   def back_color2; return Color.new(0, 0, 0, 0); end
  334.   
  335. end # Window_DisableAutobattle

  336. #==============================================================================
  337. # ■ Scene_Battle
  338. #==============================================================================

  339. class Scene_Battle < Scene_Base
  340.   
  341.   #--------------------------------------------------------------------------
  342.   # alias method: create_all_windows
  343.   #--------------------------------------------------------------------------
  344.   alias scene_battle_create_all_windows_cab create_all_windows
  345.   def create_all_windows
  346.     $game_temp.continous_autobattle = false
  347.     scene_battle_create_all_windows_cab
  348.     create_disable_autobattle_window
  349.   end
  350.   
  351.   #--------------------------------------------------------------------------
  352.   # alias method: create_party_command_window
  353.   #--------------------------------------------------------------------------
  354.   alias create_party_command_window_cab create_party_command_window
  355.   def create_party_command_window
  356.     create_party_command_window_cab
  357.     @party_command_window.set_handler(:autobattle, method(:command_pautobattle))
  358.   end
  359.   
  360.   #--------------------------------------------------------------------------
  361.   # new method: command_pautobattle
  362.   #--------------------------------------------------------------------------
  363.   def command_pautobattle
  364.     for member in $game_party.battle_members
  365.       next unless member.inputable?
  366.       member.make_auto_battle_actions
  367.     end
  368.     $game_temp.continous_autobattle = YEA::AUTOBATTLE::ENABLE_CONTINOUS
  369.     @disable_autobattle_window.show if $game_temp.continous_autobattle
  370.     refresh_autobattler_status_window
  371.     turn_start
  372.   end
  373.   
  374.   #--------------------------------------------------------------------------
  375.   # new method: create_disable_autobattle_window
  376.   #--------------------------------------------------------------------------
  377.   def create_disable_autobattle_window
  378.     @disable_autobattle_window = Window_DisableAutobattle.new
  379.   end
  380.   
  381.   #--------------------------------------------------------------------------
  382.   # alias method: update
  383.   #--------------------------------------------------------------------------
  384.   alias scene_battle_update_cab update
  385.   def update
  386.     scene_battle_update_cab
  387.     update_continous_autobattle_window
  388.   end
  389.   
  390.   #--------------------------------------------------------------------------
  391.   # alias method: update_basic
  392.   #--------------------------------------------------------------------------
  393.   alias scene_battle_update_basic_cab update_basic
  394.   def update_basic
  395.     scene_battle_update_basic_cab
  396.     update_continous_autobattle_window
  397.   end
  398.   
  399.   #--------------------------------------------------------------------------
  400.   # new method: update_continous_autobattle_window
  401.   #--------------------------------------------------------------------------
  402.   def update_continous_autobattle_window
  403.     return unless @disable_autobattle_window.visible
  404.     opacity = $game_message.visible ? 0 : 255
  405.     @disable_autobattle_window.contents_opacity = opacity
  406.     close_disable_autobattle_window if Input.press?(:B)
  407.   end
  408.   
  409.   #--------------------------------------------------------------------------
  410.   # new method: close_disable_autobattle_window
  411.   #--------------------------------------------------------------------------
  412.   def close_disable_autobattle_window
  413.     Sound.play_cancel if Input.press?(:B) && @disable_autobattle_window.visible
  414.     $game_temp.continous_autobattle = false
  415.     @disable_autobattle_window.hide
  416.   end
  417.   
  418.   #--------------------------------------------------------------------------
  419.   # alias method: create_actor_command_window
  420.   #--------------------------------------------------------------------------
  421.   alias create_actor_command_window_cab create_actor_command_window
  422.   def create_actor_command_window
  423.     create_actor_command_window_cab
  424.     @actor_command_window.set_handler(:autobattle, method(:command_aautobattle))
  425.   end
  426.   
  427.   #--------------------------------------------------------------------------
  428.   # new method: command_aautobattle
  429.   #--------------------------------------------------------------------------
  430.   def command_aautobattle
  431.     BattleManager.actor.make_auto_battle_actions
  432.     next_command
  433.   end
  434.   
  435.   #--------------------------------------------------------------------------
  436.   # new method: refresh_autobattler_status_window
  437.   #--------------------------------------------------------------------------
  438.   def refresh_autobattler_status_window
  439.     for member in $game_party.battle_members
  440.       next unless member.auto_battle?
  441.       @status_window.draw_item(member.index)
  442.     end
  443.   end
  444.   
  445. end # Scene_Battle

  446. #==============================================================================
  447. #
  448. # ▼ End of File
  449. #
  450. #==============================================================================
复制代码





欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1