#==============================================================================
# +++ MOG - Active Chain Commands (v1.0) +++
#==============================================================================
# By Moghunter
#==============================================================================
# Permite combinar (Linkar) ataques consecutivos através do uso de
# sequência de botões.
#==============================================================================
# Arquivos necessários. Graphics/System/
#
# Chain_Command.png
# Chain_Battle_Layout.png
# Chain_Battle_Meter.png
#
#==============================================================================
# UTILIZAÇÃO
#==============================================================================
# No banco de dados use o sequinte comentário para linkar as ações.
#
# <Chain Action = X>
#
# X - ID da habilidade.
#==============================================================================
module MOG_CHAIN_ACTIONS
#==============================================================================
# CHAIN_ACTIONS = { SKILL_ID => [COMMAND] }
#
# SKILL_ID = ID da habilidade no banco de dados.
# COMMANDS = Defina aqui a sequência de botões.
# (Para fazer a sequência use os comandos abaixo)
#
# "Down" ,"Up" ,"Left" ,"Right" ,"Shift" ,"D" ,"S" ,"A" ,"Z" ,"X" ,"Q" ,"W"
#
# Exemplo de utilização
#
# CHAIN_SWITCH_COMMAND = {
# 25=>["Down","D","S","Right"],
# 59=>["Down","Up","Left","Right","Shift","D","S","A","Z","X","Q","W"],
# 80=>["Shift","D"]
# }
#==============================================================================
CHAIN_ACTIONS = {
29=>["Left","Up","Right","Down"],
52=>["Up","Down","Left","Right","Z"],
70=>["X","Right","Left","Z","Z"],
138=>["X"],
139=>["A","S"],
140=>["Z","D","X"],
141=>["Up","Down"],
142=>["Left","Right","Z"],
999=>["Left","Right","Left","Right","Left","Right","Q","Z","Up","A","S",
"Down","D","Z","Right","Up","Up","Z","W","Left","Down","D","A","W"]
}
#Definição do tempo limite para pressionar o botão.
CHAIN_INPUT_DURATION = 60 #60 = 1s
#Som ao acertar.
CHAIN_RIGHT_SE = "Chime1"
#Som ao errar.
CHAIN_WRONG_SE = "Buzzer1"
#Definição do som ao ativar o sistema de chain.
CHAIN_START_SE = "Open1"
#Definição da posição do botão.
CHAIN_SPRITE_POSITION = [0,0]
#Posição do layout do medidor.
CHAIN_LAYOUT_POSITION = [1,-7]
#Posição do medidor de tempo.
CHAIN_METER_POSITION = [0,-6]
#Posição do Ícone
CHAIN_ICON_POSITION = [0,-32]
#Definição da palavra Chain.
CHAIN_COMMAND_WORD = "Chain Action!"
#Definição das palavras de erro.
CHAIN_MISSED_WORDS = ["Missed!", "Timeover"]
#Definição da posição da palavra.
CHAIN_COMMAND_WORD_POSITION = [0,0]
#Definição do nome da fonte.
CHAIN_WORD_FONT_NAME = "Georgia"
#Definição do tamanho da fonte
CHAIN_WORD_FONT_SIZE = 20
#Definição da cor da fonte
CHAIN_WORD_FONT_COLOR = Color.new(255,255,255)
#Prioridade do sprite.
CHAIN_SPRITE_Z = 100
end
#==============================================================================
# ■ Game Temp
#==============================================================================
class Game_Temp
attr_accessor :chain_actions
#--------------------------------------------------------------------------
# ● Initialize
#--------------------------------------------------------------------------
alias mog_chain_actions_initialize initialize
def initialize
@chain_actions = [0,0,0,false]
mog_chain_actions_initialize
end
end
#==============================================================================
# ■ Scene_Battle
#==============================================================================
class Scene_Battle < Scene_Base
#--------------------------------------------------------------------------
# ● Use Item
#--------------------------------------------------------------------------
alias mog_chain_actions_use_item use_item
def use_item
check_chain_targets
mog_chain_actions_use_item
execute_chain_actions
end
#--------------------------------------------------------------------------
# ● Check Chain Command Position
#--------------------------------------------------------------------------
def check_chain_command_position
targets = @subject.current_action.make_targets.compact
return if targets == nil
for i in targets
$game_temp.chain_actions = [i.screen_x,i.screen_y,true]
break
end
end
#--------------------------------------------------------------------------
# ● Check Chain Targets
#--------------------------------------------------------------------------
def check_chain_targets
return if @subject == nil
targets = @subject.current_action.make_targets.compact
return if targets == nil
if @subject.current_action.item.scope == 1 or
@subject.current_action.item.scope == 7 or
@subject.current_action.item.scope == 9 or
@subject.current_action.item.scope == 10 or
@subject.current_action.item.scope == 11
@pre_target = targets[0]
@pre_target_hp = @pre_target.hp
else
@pre_target = nil
@pre_target_hp = nil
end
end
#--------------------------------------------------------------------------
# ● Execute Chain Actions
#--------------------------------------------------------------------------
def execute_chain_actions
return if !can_execute_chain_actions_base?
if @pre_target != nil
return if @pre_target.dead?
return if !@pre_target.result.hit? and @pre_target.hp == @pre_target_hp
end
check_chain_command_position
action_id = @subject.current_action.item.note =~ /<Chain Action = (\d+)>/i ? $1.to_i : nil
return if action_id == nil or action_id < 1
chain_command_sequence = MOG_CHAIN_ACTIONS::CHAIN_ACTIONS[action_id]
$game_temp.chain_actions[2] = action_id
if can_execute_chain_sequence?(chain_command_sequence)
chain_sq = Chain_Actions.new(chain_command_sequence,$game_temp.chain_actions)
loop do
unless @spriteset.animation?
chain_sq.update
Input.update
end
chain_sq.update_skill_name
@spriteset.update
Graphics.update
break if chain_sq.phase == 9
end
action_id = nil if !chain_sq.success
chain_sq.dispose
end
return if action_id == nil
@subject.input.set_skill(action_id)
$game_temp.chain_actions = [0,0,0,false]
execute_action
end
#--------------------------------------------------------------------------
# ● Can Execute Chain Sequence?
#--------------------------------------------------------------------------
def can_execute_chain_sequence?(chain_command_sequence = nil)
return false if chain_command_sequence == nil
return true
end
#--------------------------------------------------------------------------
# ● Can Execute Chain Actions Base
#--------------------------------------------------------------------------
def can_execute_chain_actions_base?
return false if @subject == nil
return false if @subject.dead?
return false if @subject.is_a?(Game_Enemy)
return false if @subject.current_action == nil
for i in @subject.states
return false if i.restriction > 0
end
return false if $game_party.members.empty?
return false if $game_party.all_dead?
return false if $game_troop.all_dead?
return true
end
end
#==============================================================================
# ■ Chain Actions
#==============================================================================
class Chain_Actions
include MOG_CHAIN_ACTIONS
attr_accessor :phase
attr_accessor :success
#--------------------------------------------------------------------------
# ● Initialize
#--------------------------------------------------------------------------
def initialize(sequence,chain_temp)
$game_temp.chain_actions[3] = true
@chain_command = sequence
@x = chain_temp[0] + CHAIN_SPRITE_POSITION[0]
@y = chain_temp[1] + CHAIN_SPRITE_POSITION[1]
@skill = $data_skills[chain_temp[2]]
@skillname = @skill.name
@duration = [CHAIN_INPUT_DURATION, CHAIN_INPUT_DURATION]
@phase = 0
@success = false
@com = 0
@com_index = 0
@initial_wait = 1
@wrong_commnad = [false,0,0]
Audio.se_play("Audio/SE/" + CHAIN_START_SE, 100, 100) rescue nil
create_button_sprite
create_skill_name
create_icon
create_meter
end
#--------------------------------------------------------------------------
# ● Create Icon
#--------------------------------------------------------------------------
def create_icon
@icon_image = Cache.system("IconSet")
@icon_sprite = Sprite.new
@icon_sprite.bitmap = Bitmap.new(24,24)
@icon_sprite.z = CHAIN_SPRITE_Z + 1
@org_x2 = @x - 12 + CHAIN_ICON_POSITION[0] - @center
@icon_sprite.x = @org_x2 - 50
@icon_sprite.y = @y + CHAIN_ICON_POSITION[1]
icon_rect = Rect.new(@skill.icon_index % 16 * 24, @skill.icon_index / 16 * 24, 24, 24)
@icon_sprite.bitmap.blt(0,0, @icon_image, icon_rect)
end
#--------------------------------------------------------------------------
# ● Create Meter
#--------------------------------------------------------------------------
def create_meter
@meter_layout = Sprite.new
@meter_layout.bitmap = Cache.system("Chain_Battle_Layout")
@meter_layout.z = CHAIN_SPRITE_Z
@meter_layout.x = @x - (@meter_layout.width / 2) + CHAIN_LAYOUT_POSITION[0]
@meter_layout.y = @y + CHAIN_LAYOUT_POSITION[1]
@meter_image = Cache.system("Chain_Battle_Meter")
@meter_cw = @meter_image.width
@meter_ch = @meter_image.height
@meter = Sprite.new
@meter.bitmap = Bitmap.new(@meter_image.width, @meter_image.height)
@meter.z = CHAIN_SPRITE_Z + 1
@meter.x = @x - (@meter_image.width / 2) + CHAIN_METER_POSITION[0]
@meter.y = @y + CHAIN_METER_POSITION[1]
@meter.visible = false
@meter_layout.visible = false
update_meter
end
#--------------------------------------------------------------------------
# ● Update Meter
#--------------------------------------------------------------------------
def update_meter
return if @meter == nil
@meter.bitmap.clear
range = @meter_cw * @duration[0] / @duration[1]
m_scr = Rect.new(0,0,range,@meter_ch )
@meter.bitmap.blt(0,0, @meter_image ,m_scr)
end
#--------------------------------------------------------------------------
# ● Initialize
#--------------------------------------------------------------------------
def create_skill_name
@skill_name = Sprite.new
@skill_name.bitmap = Bitmap.new(200,32)
@skill_name.bitmap.font.name = CHAIN_WORD_FONT_NAME
@skill_name.bitmap.font.size = CHAIN_WORD_FONT_SIZE
@skill_name.bitmap.font.color = CHAIN_WORD_FONT_COLOR
@skill_name.z = CHAIN_SPRITE_Z
@skill_name.y = @y - 32 + CHAIN_COMMAND_WORD_POSITION[1]
refresh_skill_name
end
#--------------------------------------------------------------------------
# ● Refresh Skill Name
#--------------------------------------------------------------------------
def refresh_skill_name
cm = @skillname.to_s.split(//).size
@center = ((200 / @skill_name.bitmap.font.size) * cm / 2) + 5
@org_x = @x - (@button_cw / 2) - 85 + CHAIN_COMMAND_WORD_POSITION[0]
@skill_name.x = @org_x - 50
@skill_name.bitmap.draw_text(0,0,200,32,@skillname.to_s,1)
end
#--------------------------------------------------------------------------
# ● Create Button Sprite
#--------------------------------------------------------------------------
def create_button_sprite
@button_image = Cache.system("Chain_Command")
@button_cw = @button_image.width / 13
@button_ch = @button_image.height
@button_sprite = Sprite.new
@button_sprite.bitmap = Bitmap.new(@button_cw,@button_ch)
@button_sprite.z = CHAIN_SPRITE_Z + 1
@button_sprite.ox = @button_cw / 2
@button_sprite.oy = @button_ch / 2
@button_sprite.x = @x + @button_sprite.ox - (@button_cw / 2)
@button_sprite.y = @y + @button_sprite.oy
end
#--------------------------------------------------------------------------
# ● Refresh Button Command
#--------------------------------------------------------------------------
def refresh_button_command
return if @button_sprite == nil
@duration[0] = @duration[1]
command_list_check(@chain_command[@com_index])
@button_sprite.bitmap.clear
button_scr = Rect.new(@com * @button_cw , 0,@button_cw,@button_ch)
@button_sprite.bitmap.blt(0,0,@button_image,button_scr)
@button_sprite.zoom_x = 2
@button_sprite.zoom_y = 2
@button_sprite.opacity = 255
end
#--------------------------------------------------------------------------
# ● Dispose
#--------------------------------------------------------------------------
def dispose
dispose_button
dispose_meter
dispose_name
dispose_icon_sprite
$game_temp.chain_actions[3] = false
end
#--------------------------------------------------------------------------
# ● Dispose Icon Sprite
#--------------------------------------------------------------------------
def dispose_icon_sprite
return if @icon_image == nil
@icon_sprite.bitmap.dispose
@icon_sprite.dispose
@icon_image.dispose
@icon_image = nil
end
#--------------------------------------------------------------------------
# ● Dispose Name
#--------------------------------------------------------------------------
def dispose_name
return if @skill_name == nil
@skill_name.bitmap.dispose
@skill_name.dispose
@skill_name = nil
end
#--------------------------------------------------------------------------
# ● Dispose Button
#--------------------------------------------------------------------------
def dispose_button
return if @button_image == nil
@button_sprite.bitmap.dispose
@button_sprite.dispose
@button_image.dispose
@button_image = nil
end
#--------------------------------------------------------------------------
# ● Dispose Meter
#--------------------------------------------------------------------------
def dispose_meter
return if @meter_layout == nil
@meter_layout.bitmap.dispose
@meter_layout.dispose
@meter_layout = nil
@meter.bitmap.dispose
@meter.dispose
@meter_image.dispose
end
#--------------------------------------------------------------------------
# ● Update
#--------------------------------------------------------------------------
def update
if @initial_wait > 0
@initial_wait -= 1
if @initial_wait == 0
refresh_button_command
@meter.visible = true
@meter_layout.visible = true
end
return
end
if @wrong_commnad[0]
update_fade_command
return
end
update_command
update_sprite_button
update_time
update_meter
end
#--------------------------------------------------------------------------
# ● Update Skill Name
#--------------------------------------------------------------------------
def update_fade_command
fade_speed = 6
@skill_name.opacity -= fade_speed
@meter.opacity -= fade_speed
@meter_layout.opacity -= fade_speed
@icon_sprite.opacity -= fade_speed
@button_sprite.opacity -= fade_speed * 2
missed if @meter.opacity == 0
end
#--------------------------------------------------------------------------
# ● Update Skill Name
#--------------------------------------------------------------------------
def update_skill_name
return if @skill_name == nil
if @skill_name.x < @org_x
@skill_name.x += 3
@icon_sprite.x += 3
if @skill_name.x > @org_x
@skill_name.x = @org_x
@icon_sprite.x = @org_x2
end
end
end
#--------------------------------------------------------------------------
# ● Update Time
#--------------------------------------------------------------------------
def update_time
return if @button_sprite == nil
@duration[0] -= 1 if @duration[0] > 0
wrong_command(1) if @duration[0] == 0
end
#--------------------------------------------------------------------------
# ● Update Sprite Button
#--------------------------------------------------------------------------
def update_sprite_button
return if @button_sprite == nil
if @button_sprite.zoom_x > 1.00
@button_sprite.zoom_x -= 0.05
@button_sprite.zoom_x = 1.00 if @button_sprite.zoom_x < 1.00
end
@button_sprite.zoom_y = @button_sprite.zoom_x
end
#--------------------------------------------------------------------------
# ● Update Command
#--------------------------------------------------------------------------
def update_command
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(8)
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 "Shift"
@com = 3
when "Z"
@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)
right_input = true
end
if right_input
next_command
else
wrong_command(0)
end
end
#--------------------------------------------------------------------------
# ● Next Command
#--------------------------------------------------------------------------
def next_command
@com_index += 1
Audio.se_play("Audio/SE/" + CHAIN_RIGHT_SE, 100, 100)
if @com_index == @chain_command.size
@phase = 9
@success = true
return
end
refresh_button_command
end
#--------------------------------------------------------------------------
# ● wrong_command
#--------------------------------------------------------------------------
def wrong_command(type = 0)
@wrong_commnad[0] = true
@wrong_commnad[1] = type
@skill_name.bitmap.clear
Audio.se_play("Audio/SE/" + CHAIN_WRONG_SE, 100, 100)
wname = type == 0 ? CHAIN_MISSED_WORDS[0] : CHAIN_MISSED_WORDS[1]
@skill_name.bitmap.draw_text(0,0,200,32,wname.to_s,1)
end
#--------------------------------------------------------------------------
# ● missed
#--------------------------------------------------------------------------
def missed
@success = false
@phase = 9
end
end
$mog_rgss3_active_chain_commands = true