#===============================================================================
# +++ Chain Commands v1.0 +++ (2011/03/10)
#===============================================================================
# By Moghunter
# http://www.atelier-rgss.com
#===============================================================================
# Sistema de sequência de botões para ativar switchs ou skills caso você estiver
# usando o sistema XAS.(Opcional, não é obrigatório usar o XAS)
#
# Serão necessárias as seguintes imagens. (Graphics/Windowskins)
#
# Cursor.png
# Chain_Command.png
# Chain_Layout.png
# Chain_Timer_Layout.png
# Chain_Timer_Meter.png
#
#===============================================================================
#
# Para ativar o script use o comando abaixo. (*Call Script)
#
# $scene = Chain_Commands.new(ID)
#
# ID - Id da switch, essa switch será ativada caso jogador tiver sucesso na
# sequência de comandos.
#
#===============================================================================
module MOG_CHAIN_COMMANDS
#==============================================================================
# CHAIN_COMMAND = { SWITCH_ID => [COMMAND] }
#
# SWITCH_ID = ID da switch (ou habilidade no sistema XAS)
# COMMANDS = Defina aqui a sequência de botões.
# (Para fazer a sequência use os comandos abaixo)
#
# "Down" ,"Up" ,"Left" ,"Right" ,"C" ,"D" ,"S" ,"A" ,"Z" ,"X" ,"Q" ,"W"
#
#--------------------#
# A B C X Y Z L R # < Input
#--------------------#
# Z X C A S D Q W # < Keyboard/Joystick
#--------------------#
#
# Exenplo de utilização
#
# CHAIN_SWITCH_COMMAND = {
# 25=>["Down","D","S","Right"],
# 59=>["Down","Up","Left","Right","C","D","S","A","Z","X","Q","W"],
# 80=>["C","D"]
# }
#==============================================================================
CHAIN_SWITCH_COMMAND = {
26=>["X","Right","Left","C","Z"],
27=>["Left","Right","Left","Right","Left","Right","C","Q","Z","Up","A","S",
"Down","D","Z","Right","Up","Up","Z","W","Left","Down","D","A","W"],
1001=>["Up","Down","Left","Right","X"]
}
# A função abaixo só serve se você estiver usando o sistema XAS.
CHAIN_ACTION_COMMAND = {
}
#Duração para colocar os comandos. (A duração é multiplicado pela quantidade
#de comandos) *40 = 1 sec
CHAIN_INPUT_DURATION = 20
#Som ao acertar.
CHAIN_RIGHT_SE = RPG::AudioFile.new("055-Right01", 100, 100)
#Som ao errar.
CHAIN_WRONG_SE = RPG::AudioFile.new("057-Wrong01", 100, 100)
#Switch que ativa o modo automático.
CHAIN_AUTOMATIC_MODE_SWITCH_ID = 25
end
#===============================================================================
# ■ Chain Commands
#===============================================================================
class Chain_Commands
include MOG_CHAIN_COMMANDS
#--------------------------------------------------------------------------
# ● Initialize
#--------------------------------------------------------------------------
def initialize(action_id,xas = false)
@xas = xas
@action_id = action_id
if @xas
$game_temp.chain_action_id = 0
$game_temp.chain_active = false
@chain_command = CHAIN_ACTION_COMMAND[@action_id]
else
@chain_command = CHAIN_SWITCH_COMMAND[@action_id]
end
@chain_command = ["?"] if @chain_command == nil
duration = [[CHAIN_INPUT_DURATION, 1].max, 9999].min
@timer_max = duration * @chain_command.size
@timer = @timer_max
@slide_time = [[40 / duration, 5].max, 40].min
@change_time = 0
if $game_switches[CHAIN_AUTOMATIC_MODE_SWITCH_ID]
@auto = true
else
@auto = false
end
@com = 0
end
#--------------------------------------------------------------------------
# ● Main
#--------------------------------------------------------------------------
def main
@spriteset = Spriteset_Map.new
create_chain_command
create_cusrsor
create_layout
create_meter
create_text
create_number
Graphics.transition
loop do
Graphics.update
Input.update
update
break if $scene != self
end
pre_dispose
Graphics.freeze
dispose
end
#--------------------------------------------------------------------------
# ● Create Cursor
#--------------------------------------------------------------------------
def create_cusrsor
@fy_time = 0
@fy = 0
@com_index = 0
@cursor = Sprite.new
@cursor.bitmap = RPG::Cache.windowskin("Cursor")
@cursor.z = 4
@cursor_space = ((@bitmap_cw + 5) * @chain_command.size) / 2
if @chain_command.size <= 20
@cursor.x = (640 / 2) - @cursor_space + @cursor_space * @com_index
else
@cursor.x = (640 / 2)
end
@cursor.y = 480 / 2
end
#--------------------------------------------------------------------------
# ● Create Chain Command
#--------------------------------------------------------------------------
def create_chain_command
@image = RPG::Cache.windowskin("Chain_Command")
width_max = ((@image.width / 13) + 5) * @chain_command.size
@bitmap = Bitmap.new(width_max,@image.height * 2)
@bitmap_cw = @image.width / 13
@bitmap_ch = @image.height
index = 0
for i in @chain_command
command_list_check(i)
bitmap_src_rect = Rect.new(@com * @bitmap_cw, 0, @bitmap_cw, @bitmap_ch)
if index == 0
@bitmap.blt(index * (@bitmap_cw + 5) , 0, @image, bitmap_src_rect)
else
@bitmap.blt(index * (@bitmap_cw + 5) , @bitmap_ch, @image, bitmap_src_rect)
end
index += 1
end
@sprite = Sprite.new
@sprite.bitmap = @bitmap
if @chain_command.size <= 20
@sprite.x = (640 / 2) - ((@bitmap_cw + 5) * @chain_command.size) / 2
@new_x = 0
else
@sprite.x = (640 / 2)
@new_x = @sprite.x
end
@sprite.y = (480 / 2) - @bitmap_ch - 15
@sprite.z = 3
@sprite.zoom_x = 1.5
@sprite.zoom_y = 1.5
end
#--------------------------------------------------------------------------
# * create_layout
#--------------------------------------------------------------------------
def create_layout
@back = Plane.new
@back.bitmap = RPG::Cache.windowskin("Chain_Layout")
@back.z = 0
@layout = Sprite.new
@layout.bitmap = RPG::Cache.windowskin("Chain_Timer_Layout")
@layout.z = 1
@layout.x = 180
@layout.y = 150
end
#--------------------------------------------------------------------------
# * create_meter
#--------------------------------------------------------------------------
def create_meter
@meter_flow = 0
@meter_image = RPG::Cache.windowskin("Chain_Timer_Meter")
@meter_bitmap = Bitmap.new(@meter_image.width,@meter_image.height)
@meter_range = @meter_image.width / 3
@meter_width = @meter_range * @timer / @timer_max
@meter_height = @meter_image.height
@meter_src_rect = Rect.new(@meter_range, 0, @meter_width, @meter_height)
@meter_bitmap.blt(0,0, @meter_image, @meter_src_rect)
@meter_sprite = Sprite.new
@meter_sprite.bitmap = @meter_bitmap
@meter_sprite.z = 2
@meter_sprite.x = 240
@meter_sprite.y = 159
update_flow
end
#--------------------------------------------------------------------------
# ● Create Text
#--------------------------------------------------------------------------
def create_text
@text = Sprite.new
@text.bitmap = Bitmap.new(200,32)
@text.z = 2
@text.bitmap.font.name = "Georgia"
@text.bitmap.font.size = 30
@text.bitmap.font.bold = true
@text.bitmap.font.italic = true
@text.x = 240
@text.y = 100
end
#--------------------------------------------------------------------------
# ● Create Number
#--------------------------------------------------------------------------
def create_number
@combo = 0
@number = Sprite.new
@number.bitmap = Bitmap.new(200,64)
@number.z = 2
@number.bitmap.font.name = "Arial"
@number.bitmap.font.size = 24
@number.bitmap.font.bold = true
@number.bitmap.font.color.set(0, 255, 255,200)
@number.bitmap.draw_text(0, 0, 200, 32, "Ready",1)
@number.x = 40
@number.y = 120
end
#--------------------------------------------------------------------------
# ● Pre Dispose
#--------------------------------------------------------------------------
def pre_dispose
for i in 0..25
@sprite.x += 5
@sprite.opacity -= 25
@layout.x -= 5
@meter_sprite.x -= 5
@layout.opacity -= 25
@meter_sprite.opacity -= 25
@text.x -= 2
if i < 10 and @text.zoom_x < 1.5
@text.zoom_x += 0.1
@text.zoom_y += 0.1
end
@cursor.visible = false
if @number.zoom_x > 1
@number.zoom_x -= 0.1
@number.zoom_y -= 0.1
end
Graphics.update
end
end
#--------------------------------------------------------------------------
# ● Dispose
#--------------------------------------------------------------------------
def dispose
@spriteset.dispose
@bitmap.dispose
@sprite.bitmap.dispose
@sprite.dispose
@cursor.bitmap.dispose
@cursor.dispose
@meter_image.dispose
@meter_bitmap.dispose
@meter_sprite.bitmap.dispose
@meter_sprite.dispose
@layout.bitmap.dispose
@layout.dispose
@back.bitmap.dispose
@back.dispose
@text.bitmap.dispose
@text.dispose
@number.bitmap.dispose
@number.dispose
@image.dispose
end
#--------------------------------------------------------------------------
# ● Update
#--------------------------------------------------------------------------
def update
update_command
update_cursor_slide
update_flow
update_change_time
end
#--------------------------------------------------------------------------
# ● Change_Time
#--------------------------------------------------------------------------
def update_change_time
return unless @auto
@change_time += 1
check_command(-1) if @change_time >= CHAIN_INPUT_DURATION - 1
end
#--------------------------------------------------------------------------
# ● Update Flow
#--------------------------------------------------------------------------
def update_flow
@timer -= 1
@meter_sprite.bitmap.clear
@meter_width = @meter_range * @timer / @timer_max
@meter_src_rect = Rect.new(@meter_flow, 0, @meter_width, @meter_height)
@meter_bitmap.blt(0,0, @meter_image, @meter_src_rect)
@meter_flow += 20
@meter_flow = 0 if @meter_flow >= @meter_image.width - @meter_range
wrong_command if @timer == 0 and @auto == false
end
#--------------------------------------------------------------------------
# ● Update Command
#--------------------------------------------------------------------------
def update_command
return if @auto
if Input.trigger?(Input::X)
check_command(0)
elsif Input.trigger?(Input::Z)
check_command(1)
elsif Input.trigger?(Input::Y)
check_command(2)
elsif Input.trigger?(Input::A)
check_command(3)
elsif Input.trigger?(Input::C)
check_command(4)
elsif Input.trigger?(Input::B)
check_command(5)
elsif Input.trigger?(Input::L)
check_command(6)
elsif Input.trigger?(Input::R)
check_command(7)
elsif Input.trigger?(Input::RIGHT)
check_command(
elsif Input.trigger?(Input::LEFT)
check_command(9)
elsif Input.trigger?(Input::DOWN)
check_command(10)
elsif Input.trigger?(Input::UP)
check_command(11)
end
end
#--------------------------------------------------------------------------
# ● command_list_check
#--------------------------------------------------------------------------
def command_list_check(command)
case command
when "A"
@com = 0
when "D"
@com = 1
when "S"
@com = 2
when "Z"
@com = 3
when "C"
@com = 4
when "X"
@com = 5
when "Q"
@com = 6
when "W"
@com = 7
when "Right"
@com = 8
when "Left"
@com = 9
when "Down"
@com = 10
when "Up"
@com = 11
else
@com = 12
end
end
#--------------------------------------------------------------------------
# ● check_command
#--------------------------------------------------------------------------
def check_command(com)
index = 0
if com != -1
right_input = false
for i in @chain_command
if index == @com_index
command_list_check(i)
right_input = true if @com == com
end
index += 1
end
else
command_list_check(@com_index)
@change_time = 0
right_input = true
end
if right_input
refresh_number
next_command
else
wrong_command
end
end
#--------------------------------------------------------------------------
# ● Next Command
#--------------------------------------------------------------------------
def next_command
@com_index += 1
$game_system.se_play(CHAIN_RIGHT_SE)
if @com_index == @chain_command.size
if @xas
$game_temp.chain_active = true
$game_temp.chain_action_id = @action_id
else
$game_switches[@action_id] = true
end
$scene = Scene_Map.new
$game_map.need_refresh = true
end
refresh_command
refresh_text(0)
end
#--------------------------------------------------------------------------
# ● wrong_command
#--------------------------------------------------------------------------
def wrong_command
$game_system.se_play(CHAIN_WRONG_SE)
if @xas
$game_temp.chain_action_id = 0
$game_temp.chain_active = false
end
refresh_text(1)
$scene = Scene_Map.new
end
#--------------------------------------------------------------------------
# ● Refresh Command
#--------------------------------------------------------------------------
def refresh_command
@sprite.bitmap.clear
index = 0
for i in @chain_command
command_list_check(i)
bitmap_src_rect = Rect.new(@com * @bitmap_cw, 0, @bitmap_cw, @bitmap_ch)
if @com_index == index
@bitmap.blt(index * (@bitmap_cw + 5) , 0, @image, bitmap_src_rect)
else
@bitmap.blt(index * (@bitmap_cw + 5) , @bitmap_ch, @image, bitmap_src_rect)
end
index += 1
end
if @chain_command.size > 20
@new_x = (640 / 2) - ((@bitmap_cw + 5) * @com_index)
else
@cursor.x = (640 / 2) - @cursor_space + ((@bitmap_cw + 5) * @com_index)
end
end
#--------------------------------------------------------------------------
# ● Refresh Text
#--------------------------------------------------------------------------
def refresh_text(type)
@text.bitmap.clear
if type == 0
@text.bitmap.font.color.set(255, 255, 255,255)
if @com_index == @chain_command.size
@text.bitmap.draw_text(0, 0, 200, 32, "Perfect!",1)
else
@text.bitmap.draw_text(0, 0, 200, 32, "Success!",1)
end
else
@text.bitmap.font.color.set(255, 155, 55,255)
if @timer == 0
@text.bitmap.draw_text(0, 0, 200, 32, "Time Limit!",1)
else
@text.bitmap.draw_text(0, 0, 200, 32, "Fail!",1)
end
end
@text.x = 240
@text.opacity = 255
end
#--------------------------------------------------------------------------
# ● Refresh Number
#--------------------------------------------------------------------------
def refresh_number
@combo += 1
@number.bitmap.clear
@number.bitmap.font.size = 38
@number.bitmap.font.color.set(255, 255, 255,200)
@number.bitmap.draw_text(0, 0, 200, 32, @combo.to_s,1)
@number.opacity = 255
@number.zoom_x = 2
@number.zoom_y = 2
end
#--------------------------------------------------------------------------
# ● Update Cursor Slide
#--------------------------------------------------------------------------
def update_cursor_slide
@sprite.zoom_x -= 0.1 if @sprite.zoom_x > 1
@sprite.zoom_y -= 0.1 if @sprite.zoom_y > 1
@text.x -= 2 if @text.x > 220
@text.opacity -= 4 if @text.opacity > 0
@sprite.x -= @slide_time if @sprite.x > @new_x and @chain_command.size > 20
if @number.zoom_x > 1
@number.zoom_x -= 0.1
@number.zoom_y -= 0.1
end
if @fy_time > 15
@fy += 1
elsif @fy_time > 0
@fy -= 1
else
@fy = 0
@fy_time = 30
end
@fy_time -= 1
@cursor.oy = @fy
end
end
if $xrxs_xas != nil
#===============================================================================
# ■ Game_Character
#===============================================================================
class Game_Temp
attr_accessor :chain_active
attr_accessor :chain_action_id
#--------------------------------------------------------------------------
# ● Initialize
#--------------------------------------------------------------------------
alias chain_command_initialize initialize
def initialize
chain_command_initialize
@chain_active = false
@chain_action_id = 0
end
end
#===============================================================================
# ■ XAS_ACTION
#===============================================================================
module XAS_ACTION
#--------------------------------------------------------------------------
# ● Shoot Effect
#--------------------------------------------------------------------------
alias mog_chain_command_can_shoot can_shoot?
def can_shoot?(action_id,skill)
if self.battler.is_a?(Game_Actor)
if MOG_CHAIN_COMMANDS::CHAIN_ACTION_COMMAND.include?(action_id) and
$game_temp.chain_active == false
$scene = Chain_Commands.new(action_id,true)
return true
end
end
$game_temp.chain_active = false
mog_chain_command_can_shoot(action_id,skill)
end
end
#===============================================================================
# ■ Game_Player
#===============================================================================
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# ● update_force_action
#--------------------------------------------------------------------------
alias chain_command_update_force_action update_force_action
def update_force_action
chain_command_update_force_action
if $game_temp.chain_action_id != 0 and not
(self.knockbacking? or @actor.state_sleep or @actor.stop)
if seal_state?(0)
seal_text
return false
end
action_id = $game_temp.chain_action_id
self.shoot(action_id)
$game_temp.chain_action_id = 0
end
end
end
end
$mog_rgss_chain_commands = true