=begin #============================================================================== ** Command Setup Author: Hime Date: May 25, 2012 ------------------------------------------------------------------------------ ** Change log May 25 - fixed issue where Marshal.dump doesn't accept Method objects - initial release ------------------------------------------------------------------------------ This script allows you customize your list of actor commands in battle. You can also assign certain skills to be "command skills" If a skill should be a command skill, tag it with You can customize how many commands an actor can use by tagging it with The following script calls increase or decrease an actor's number of command slots gain_commands(actor_id, n) lose_commands(actor_id, n) For some integer n #============================================================================== =end $imported = {} if $imported.nil? $imported["Tsuki_CommandSetup"] = true #============================================================================== # ** Configuration #============================================================================== module Tsuki module Command_Setup Command_Name = "Battle Commands" Command_Handler = :command_setup Default_Max_Commands = 5 CmdSkill_Handler = :use_skill Skill_Type_Regex = //i Max_Command_Regex = //i end end #============================================================================== # ** Rest of the script. #============================================================================== module RPG class Skill < UsableItem include Tsuki::Command_Setup def skill_type return @skill_type unless @skill_type.nil? res = Skill_Type_Regex.match(self.note) return @skill_type = res ? res[1].to_i : 0 end def is_skill_command? skill_type == 1 end def is_normal_skill? skill_type == 0 end end class Actor < BaseItem def max_commands return @max_commands unless @max_commands.nil? res = Tsuki::Command_Setup::Max_Command_Regex.match(self.note) return @max_command = res ? res[1].to_i : Tsuki::Command_Setup::Default_Max_Commands end end end # contains details about the type of command class Actor_Command attr_reader :name attr_reader :sym attr_reader :enabled attr_reader :ext attr_reader :description attr_reader :tp_cost attr_reader :mp_cost def initialize(name="", sym=nil, enabled=true, ext=nil) @name = name @sym = sym @enabled = enabled @ext = ext setup end def setup @description = "" @tp_cost = 0 @mp_cost = 0 if @sym == Tsuki::Command_Setup::CmdSkill_Handler @description = $data_skills[@ext].description @tp_cost = $data_skills[@ext].tp_cost @mp_cost = $data_skills[@ext].mp_cost end end end class Game_Actor < Game_Battler include Tsuki::Command_Setup attr_reader :command_list attr_reader :max_commands alias :th_command_setup_setup_actor :setup def setup(actor_id) th_command_setup_setup_actor(actor_id) @max_commands = actor.max_commands setup_command_list setup_battle_commands end # list of commands that the actor is using in battle def setup_battle_commands @battle_commands = [] @battle_commands << @command_list[0] @battle_commands << @command_list[1] @battle_commands << @command_list[2] end # list of commands that the actor can choose from def setup_command_list @command_list = [] setup_basic_commands setup_stype_commands setup_skill_commands end def setup_basic_commands @command_list << Actor_Command.new(Vocab::attack, :attack, true, attack_skill_id) #@command_list << Actor_Command.new(Vocab::guard, :guard, true, guard_skill_id) @command_list << Actor_Command.new(Vocab::item, :item) end def setup_stype_commands added_skill_types.sort.each do |stype_id| name = $data_system.skill_types[stype_id] @command_list << Actor_Command.new(name, :skill, true, stype_id) end end # skills that should be treated directly as commands def setup_skill_commands skills.each do |skill| @command_list << Actor_Command.new(skill.name, :use_skill, true, skill.id) if skill.is_skill_command? end end def can_add_command?(cmd) @battle_commands.size < @max_commands end def add_command(cmd) @battle_commands << cmd end def remove_command(cmd) @battle_commands.delete(cmd) end def battle_commands @battle_commands end def available_commands @command_list end def increase_max_commands(amount) @max_commands += amount end # also need to remove extra commands def decrease_max_commands(amount) @max_commands = [@max_commands - amount, 1].max @battle_commands = @battle_commands.first(@max_commands) end end class Window_CmdSelectStatus < Window_Base def initialize(x, y) super(x, y, Graphics.width - x, window_height(y)) @actor = $game_actors[1]#nil refresh end def actor=(actor) return if @actor == actor @actor = actor refresh end def window_height(y) Graphics.height - y - 224 end def draw_info draw_actor_face(@actor, 0, 0) end def refresh return unless @actor contents.clear draw_info end end class Window_CmdSelectList < Window_Selectable def initialize(x, y) super(x, y, Graphics.width - x, Graphics.height - y) @actor = nil @data = [] select(0) end def actor=(actor) return if @actor == actor @actor = actor refresh end def col_max return 1 end def item @data && index >= 0 ? @data[index] : nil end def item_max @data ? @data.size : 1 end def make_item_list @data = @actor.available_commands end def draw_item(index) cmd = @data[index] if cmd rect = item_rect(index) rect.width -= 4 draw_command_name(cmd, rect.x, rect.y, can_add?(cmd)) draw_command_cost(cmd, rect, can_add?(cmd)) end end def draw_command_name(cmd, x, y, enabled=true) change_color(normal_color, enabled) draw_text(x, y, 172, line_height, cmd.name) end def draw_command_cost(cmd, rect, enable) if cmd.tp_cost > 0 change_color(tp_cost_color, enable) draw_text(rect, cmd.tp_cost, 2) elsif cmd.mp_cost > 0 change_color(mp_cost_color, enable) draw_text(rect, cmd.mp_cost, 2) end end def update_help @help_window.set_item(item) end def refresh make_item_list create_contents draw_all_items end def can_add?(cmd) !@actor.battle_commands.include?(cmd) && @actor.can_add_command?(cmd) end def add_item if @actor.battle_commands.include?(item) @actor.remove_command(item) else if can_add?(item) @actor.add_command(item) else Sound.play_buzzer end end refresh end end class Window_CmdSelectCommand < Window_Selectable def initialize(x, y) super(x, y, window_width, Graphics.height - y) @actor = nil end def window_width Graphics.width - 344 end def actor=(actor) return if @actor == actor @actor = actor refresh end def make_item_list @data = @actor.battle_commands end def item_max @data ? @data.size : 1 end def draw_item(index) cmd = @data[index] if cmd rect = item_rect(index) rect.width -= 4 draw_command_name(cmd, rect.x, rect.y) end end def draw_command_name(cmd, x, y, enabled=true) return unless cmd change_color(normal_color, enabled) draw_text(x, y, 172, line_height, cmd.name) end def draw_item_count text = sprintf("%d / %d", @actor.battle_commands.size, @actor.max_commands) draw_text(self.x, self.height - self.y, self.width - 24, line_height, text, 2) end def refresh make_item_list create_contents draw_all_items draw_item_count end end class Scene_Command_Setup < Scene_MenuBase def start super create_all_windows activate_list_window end def create_all_windows create_help_window create_actor_cmd_window create_status_window create_command_list_window end def create_help_window @help_window = Window_Help.new end # displays commands the actor currently uses def create_actor_cmd_window wy = @help_window.height @command_window = Window_CmdSelectCommand.new(0, @help_window.height) @command_window.actor = @actor end # display the current actor def create_status_window wx = @command_window.width wy = @help_window.height @status_window = Window_CmdSelectStatus.new(wx, wy) @status_window.actor = @actor end # list of commands the actor can choose from def create_command_list_window wx = @command_window.width wy = @status_window.y + @status_window.height @list_window = Window_CmdSelectList.new(wx, wy) @list_window.help_window = @help_window @list_window.actor = @actor @list_window.set_handler(:ok, method(:on_item_ok)) @list_window.set_handler(:cancel, method(:return_scene)) @list_window.set_handler(:pagedown, method(:next_actor)) @list_window.set_handler(:pageup, method(:prev_actor)) end def activate_list_window @list_window.activate end def on_item_ok @list_window.add_item @command_window.refresh activate_list_window end def on_actor_change @list_window.actor = @actor @status_window.actor = @actor @command_window.actor = @actor activate_list_window end end #============================================================================== # * Add menu command to party menu #============================================================================== class Window_MenuCommand < Window_Command alias :th_command_setup_commands :add_main_commands def add_main_commands th_command_setup_commands add_command(Tsuki::Command_Setup::Command_Name, Tsuki::Command_Setup::Command_Handler) end end class Scene_Menu < Scene_MenuBase alias :th_command_setup_command_window :create_command_window def create_command_window th_command_setup_command_window @command_window.set_handler(Tsuki::Command_Setup::Command_Handler, method(:command_personal)) end alias :th_command_setup_personal_ok :on_personal_ok def on_personal_ok case @command_window.current_symbol when Tsuki::Command_Setup::Command_Handler SceneManager.call(Scene_Command_Setup) end th_command_setup_personal_ok end end class Window_SkillList < Window_Selectable def include?(item) item && item.stype_id == @stype_id && item.is_normal_skill? end end #============================================================================== # Overwrite battle actor command window #============================================================================== class Window_ActorCommand < Window_Command # overwrite def make_command_list return unless @actor add_actor_commands end # new method to draw from actor battle commands def add_actor_commands @actor.battle_commands.each do |cmd| if cmd.sym == :attack || cmd.sym == :guard || cmd.sym == :use_skill usable = @actor.usable?($data_skills[cmd.ext]) add_command(cmd.name, cmd.sym, usable, cmd.ext) else add_command(cmd.name, cmd.sym, cmd.enabled, cmd.ext) end end end end class Scene_Battle < Scene_Base include Tsuki::Command_Setup alias :th_cmd_setup_actor_cmd_window :create_actor_command_window def create_actor_command_window th_cmd_setup_actor_cmd_window @actor_command_window.set_handler(CmdSkill_Handler, method(:command_use_skill)) end alias :th_cmd_setup_enemy_cancel :on_enemy_cancel def on_enemy_cancel th_cmd_setup_enemy_cancel case @actor_command_window.current_symbol when CmdSkill_Handler @actor_command_window.activate end end def command_use_skill @skill = $data_skills[@actor_command_window.current_data[:ext]] BattleManager.actor.input.set_skill(@skill.id) BattleManager.actor.last_skill.object = @skill if !@skill.need_selection? next_command elsif @skill.for_opponent? select_enemy_selection else select_actor_selection end end end class Game_Interpreter def gain_commands(actor_id, amount) $game_actors[actor_id].increase_max_commands(amount) end def lose_commands(actor_id, amount) $game_actors[actor_id].decrease_max_commands(amount) end end