#==============================================================================
# Auto Battle Addon for DBS
# by Fantasist
# Version: Alpha 2 (0.2 or something)
#
# Rough sketch of features:
# - Automatic battle actions (think CP!)
# - Wierd-looking selection window for action choosing (attack, defend, repeat)
# - Config addon for default status screen (think CP again!)
# - Memorize option in the status config saves the last action with the savefile, and is
# globally remembered
#
# Useless facts (alpha version exclusive!):
# - This is not really 100% optimized, only about 80% is what I think.
# - The code for the 'wierd selection window' is more than the actual code for the auto battle
# mechanism.
# - I made this script in a state of mind where my efficiency is less than 50%. I deprived myself
# of sleep for about 18 hours and still ploughed on, just because looking at the code game me
# interesting ideas for stories.
# - Finally, this is my 5th significant script I did myself, and am proud of (compared to
# - mighty Blizzard's many!)
#==============================================================================
#==============================================================================
# ** Game_Battler
#==============================================================================
class Game_Battler
attr_accessor :prior_action
attr_accessor :default_action
attr_accessor :memorize_action
alias fant_auto_battle_game_battler_init initialize
def initialize
fant_auto_battle_game_battler_init
@prior_action = Game_BattleAction.new
@default_action = Game_BattleAction.new
@default_action.kind, @default_action.basic = 0, 1
@memorize_action = false
end
def current_action=(action)
if action.is_a?(Game_BattleAction)
@current_action = action
end
end
end
#==============================================================================
# ** Scene_Battle
#==============================================================================
class Scene_Battle
alias fant_auto_battle_scene_battle_main main
def main
$game_party.actors.each {|actor| actor.prior_action = actor.default_action.clone}
fant_auto_battle_scene_battle_main
end
alias fant_auto_battle_scene_battle_start_phase1 start_phase1
def start_phase1
fant_auto_battle_scene_battle_start_phase1
end
alias fant_auto_battle_scene_battle_upd_phase2 update_phase2
def update_phase2
if Input.trigger?(Input::C) && @party_command_window.index == 2 # auto battle
case @party_command_window.scroll_window.index
when 0
$game_party.actors.each {|actor| actor.current_action = actor.prior_action.clone}
when 1
$game_party.actors.each {|actor| actor.current_action.kind = actor.current_action.basic = 0}
when 2
$game_party.actors.each {|actor| actor.current_action.kind, actor.current_action.basic = 0, 1}
end
start_phase4
end
fant_auto_battle_scene_battle_upd_phase2
end
alias fant_auto_battle_scene_battle_start_phase4 start_phase4
def start_phase4
fant_auto_battle_scene_battle_start_phase4
$game_party.actors.each {|actor|
actor.prior_action = actor.current_action.clone
actor.default_action = actor.current_action.clone if actor.memorize_action}
end
end
#==============================================================================
# ** Window_PartyCommand
#==============================================================================
class Window_PartyCommand < Window_Selectable
attr_reader :scroll_window
def initialize
super(0, 0, 640, 64)
self.contents = Bitmap.new(width - 32, height - 32)
self.back_opacity = 160
@commands = ['Fight', 'Escape', 'Auto']
@item_max = 3
@column_max = 3
draw_item(0, normal_color)
draw_item(1, $game_temp.battle_can_escape ? normal_color : disabled_color)
draw_item(2, normal_color)
self.active = self.visible = false
self.index = 0
@scroll_window = Window_AutoBattle.new(110, ['Repeat', 'Attack', 'Defend'])
@scroll_window.visible, @scroll_window.active = false, false
@scroll_window.x, @scroll_window.y = 467, self.y
@scroll_window.index, @scroll_window.opacity = 0, 160
end
def y=(val)
super(val)
@scroll_window.y = y - @scroll_window.index * 32 if @scroll_window
end
def update
super
if Input.repeat?(Input::RIGHT) || Input.repeat?(Input::LEFT)
@scroll_window.active = @scroll_window.visible = (@index == 2 && self.active)
draw_item(2, @index == 2 ? Color.new(0, 0, 0, 0) : normal_color)
end
@scroll_window.update if @scroll_window && @scroll_window.active
end
def visible=(val)
super(val)
@scroll_window.visible = false if !val && @scroll_window
@scroll_window.visible = true if val && @scroll_window && @index == 2
end
def active=(val)
super(val)
@scroll_window.active = false if !val && @scroll_window
@scroll_window.active = true if val && @scroll_window && @index == 2
end
def draw_item(index, color)
self.contents.font.color = color
rect = Rect.new(index * 608 / @column_max, 0, 608 / @column_max, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
unless @index == 2 && @scroll_window.visible
self.contents.draw_text(rect, @commands[index], 1)
end
end
def update_cursor_rect
self.cursor_rect.set(index * 608 / @column_max, 0, 608 / @column_max, 32)
end
def dispose
super
@scroll_window.dispose if @scroll_window
end
end
#==============================================================================
# ** Window_AutoBattle
#==============================================================================
class Window_AutoBattle < Window_Command
attr_reader :commands
def draw_item(index, color)
self.contents.font.color = color
rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @commands[index], 1)
end
def update
if self.active && @item_max > 0 && @index >= 0
if Input.repeat?(Input::DOWN)
return if @index == @item_max - 1
$game_system.se_play($data_system.cursor_se)
@index = (@index + 1) % @item_max
self.y -= 32
end
if Input.repeat?(Input::UP)
return if @index == 0
$game_system.se_play($data_system.cursor_se)
@index = (@index - 1 + @item_max) % @item_max
self.y += 32
end
end
update_help if self.active && @help_window != nil
end
def update_cursor_rect
end
end
#==============================================================================
# ** Window_Status
#==============================================================================
class Window_Status < Window_Selectable
X, Y, W = 320, 128, 184
def initialize(actor)
super(0, 0, 640, 480)
self.contents = Bitmap.new(width - 32, height - 32)
@actor = actor
refresh
@cmds = ['Attack', 'Defend', 'Memorize']
if @actor.default_action.kind == 0 && @actor.default_action.basic == 0
self.index = 0
elsif @actor.default_action.kind == 0 && @actor.default_action.basic == 1
self.index = 1
end
self.index = 2 if @actor.memorize_action
self.contents.draw_text(X, Y, W, 32, 'Default Battle Action: ')
self.contents.draw_text(X+W, Y, 96, 32, @cmds[@index], 1)
end
def update_cursor_rect
self.cursor_rect.set(X+W, Y, 96, 32)
end
def update
super
update_cursor_rect
return if @index < 0
if Input.repeat?(Input::RIGHT)
$game_system.se_play($data_system.cursor_se)
@index = (@index + 1) % @cmds.size
self.contents.fill_rect(X+W, Y, 96, 32, Color.new(0, 0, 0, 0))
self.contents.draw_text(X+W, Y, 96, 32, @cmds[@index], 1)
case @index
when 0
@actor.default_action.kind = @actor.default_action.basic = 0
when 1
@actor.default_action.kind, @actor.default_action.basic = 0, 1
when 2
@actor.memorize_action = true
end
end
if Input.repeat?(Input::LEFT)
$game_system.se_play($data_system.cursor_se)
@index = (@index - 1) % @cmds.size
self.contents.fill_rect(X+W, Y, 96, 32, Color.new(0, 0, 0, 0))
self.contents.draw_text(X+W, Y, 96, 32, @cmds[@index], 1)
case @index
when 0
@actor.default_action.kind = @actor.default_action.basic = 0
when 1
@actor.default_action.kind, @actor.default_action.basic = 0, 1
when 2
@actor.memorize_action = true
end
end
if self.active and @help_window != nil
update_help
end
end
def refresh
self.contents.clear
draw_actor_graphic(@actor, 40, 112)
draw_actor_name(@actor, 4, 0)
draw_actor_class(@actor, 4 + 144, 0)
draw_actor_level(@actor, 96, 32)
draw_actor_state(@actor, 96, 64)
draw_actor_hp(@actor, 96, 112, 172)
draw_actor_sp(@actor, 96, 144, 172)
draw_actor_parameter(@actor, 96, 192, 0)
draw_actor_parameter(@actor, 96, 224, 1)
draw_actor_parameter(@actor, 96, 256, 2)
draw_actor_parameter(@actor, 96, 304, 3)
draw_actor_parameter(@actor, 96, 336, 4)
draw_actor_parameter(@actor, 96, 368, 5)
draw_actor_parameter(@actor, 96, 400, 6)
self.contents.font.color = system_color
self.contents.draw_text(320, 48, 80, 32, "EXP")
self.contents.draw_text(320, 80, 80, 32, "NEXT")
self.contents.font.color = normal_color
self.contents.draw_text(320 + 80, 48, 84, 32, @actor.exp_s, 2)
self.contents.draw_text(320 + 80, 80, 84, 32, @actor.next_rest_exp_s, 2)
self.contents.font.color = system_color
self.contents.draw_text(320, 160, 96, 32, "equipment")
draw_item_name($data_weapons[@actor.weapon_id], 320 + 16, 208)
draw_item_name($data_armors[@actor.armor1_id], 320 + 16, 256)
draw_item_name($data_armors[@actor.armor2_id], 320 + 16, 304)
draw_item_name($data_armors[@actor.armor3_id], 320 + 16, 352)
draw_item_name($data_armors[@actor.armor4_id], 320 + 16, 400)
end
def dummy
self.contents.font.color = system_color
self.contents.draw_text(320, 112, 96, 32, $data_system.words.weapon)
self.contents.draw_text(320, 176, 96, 32, $data_system.words.armor1)
self.contents.draw_text(320, 240, 96, 32, $data_system.words.armor2)
self.contents.draw_text(320, 304, 96, 32, $data_system.words.armor3)
self.contents.draw_text(320, 368, 96, 32, $data_system.words.armor4)
draw_item_name($data_weapons[@actor.weapon_id], 320 + 24, 144)
draw_item_name($data_armors[@actor.armor1_id], 320 + 24, 208)
draw_item_name($data_armors[@actor.armor2_id], 320 + 24, 272)
draw_item_name($data_armors[@actor.armor3_id], 320 + 24, 336)
draw_item_name($data_armors[@actor.armor4_id], 320 + 24, 400)
end
end
#==============================================================================
# ** Scene_Status
#==============================================================================
class Scene_Status
alias fant_auto_battle_scene_status_upd update
def update
@status_window.update
fant_auto_battle_scene_status_upd
end
end