Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # +++ MOG - Active Chain Commands (v2.0) +++
- #==============================================================================
- # By Moghunter
- # http://www.atelier-rgss.com/
- #==============================================================================
- # 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.
- #==============================================================================
- # ● Version History
- #==============================================================================
- # 2.0 - Possibilidade de escolher o tempo limite diferente para
- # cada sequência de botões.
- # - Correção do Bug relativo aos alvos abatidos.
- # - Melhoria na posição do medidor do combo.
- #==============================================================================
- 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 = {
- 128=>["Z"],
- 129=>["Z"],
- 130=>["Z"],
- 131=>["Z"],
- 132=>["Z"],
- 133=>["Z"],
- 134=>["Z"],
- 135=>["Z"],
- 136=>["Z"],
- 137=>["Z"],
- 138=>["Z"],
- 139=>["Z"],
- 140=>["Z"],
- 141=>["Z"],
- 142=>["A"],
- 80=>["X"],
- 81=>["X"],
- 85=>["X"],
- 86=>["X"],
- 87=>["X"],
- 88=>["X"],
- }
- #Definição padrão do tempo limite para pressionar o botão.
- CHAIN_DEFAULT_INPUT_DURATION = 60 #60 = 1s
- #Definição do tempo limite para pressionar o botão.
- CHAIN_INPUT_DURATION = {
- 138=>60,
- 139=>40,
- 140=>30
- #141=>160,
- #240=>2000
- }
- #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,-15]
- #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 = "OBHandel"
- #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 = 150
- end
- $imported = {} if $imported.nil?
- $imported[:mog_active_chain] = true
- #==============================================================================
- # ■ Game Temp
- #==============================================================================
- class Game_Temp
- attr_accessor :chain_actions
- attr_accessor :active_chain
- #--------------------------------------------------------------------------
- # ● Initialize
- #--------------------------------------------------------------------------
- alias mog_chain_actions_initialize initialize
- def initialize
- @chain_actions = [0,0,0,false]
- @active_chain = 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 or targets.empty?
- 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
- if targets == nil or targets.empty?
- @pre_target = nil
- @pre_target_hp = nil
- return
- end
- 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
- $game_temp.active_chain = false
- 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,action_id)
- chain_sq = Chain_Actions.new(chain_command_sequence,$game_temp.chain_actions)
- loop do
- unless @spriteset.animation?
- chain_sq.update
- Input.update
- end
- $game_temp.active_chain = true
- 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
- set_chain_skill(action_id) if action_id != nil
- end
- $game_temp.active_chain = false
- end
- #--------------------------------------------------------------------------
- # ● Set Chain Skill
- #--------------------------------------------------------------------------
- def set_chain_skill(action_id)
- 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,action_id = nil)
- return false if @subject == nil
- return false if chain_command_sequence == nil
- skill = $data_skills[action_id] rescue nil
- return false if skill == nil
- targets = @subject.current_action.make_targets.compact
- return false if targets == nil or targets.empty?
- if skill.scope == 9 or skill.scope == 10
- for actor in $game_party.battle_members
- return true if actor.dead?
- end
- return false
- end
- 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
- targets = @subject.current_action.make_targets.compact rescue nil
- return false if targets == nil or targets.empty?
- 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
- #==============================================================================
- # ■ Game Temp
- #==============================================================================
- class Game_Temp
- attr_accessor :cache_active_chain
- #--------------------------------------------------------------------------
- # ● Initialize
- #--------------------------------------------------------------------------
- alias mog_active_chain_initialize initialize
- def initialize
- mog_active_chain_initialize
- cache_act_chain
- end
- #--------------------------------------------------------------------------
- # ● Cache Act Chain
- #--------------------------------------------------------------------------
- def cache_act_chain
- @cache_active_chain = []
- @cache_active_chain.push(Cache.system("IconSet"))
- @cache_active_chain.push(Cache.system("Chain_Battle_Layout"))
- @cache_active_chain.push(Cache.system("Chain_Battle_Meter"))
- @cache_active_chain.push(Cache.system("Chain_Battle_Command"))
- end
- end
- #==============================================================================
- # ■ Spriteset Battle
- #==============================================================================
- class Spriteset_Battle
- #--------------------------------------------------------------------------
- # ● Initialize
- #--------------------------------------------------------------------------
- alias mog_active_chain_commands_initialize initialize
- def initialize
- $game_temp.cache_act_chain
- $game_temp.active_chain = false
- mog_active_chain_commands_initialize
- 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]
- @y = (Graphics.height - 36) if @y > (Graphics.height - 36)
- @y = 0 if @y < 0
- @skill = $data_skills[chain_temp[2]]
- @skillname = @skill.name
- if CHAIN_INPUT_DURATION[chain_temp[2]] != nil
- @duration = [CHAIN_INPUT_DURATION[chain_temp[2]],CHAIN_INPUT_DURATION[chain_temp[2]]]
- else
- @duration = [CHAIN_DEFAULT_INPUT_DURATION, CHAIN_DEFAULT_INPUT_DURATION]
- end
- @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 = $game_temp.cache_active_chain[0]
- @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 = $game_temp.cache_active_chain[1]
- @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 = $game_temp.cache_active_chain[2]
- @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 = $game_temp.cache_active_chain[3]
- @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
- $game_temp.active_chain = false
- end
- #--------------------------------------------------------------------------
- # ● Dispose Icon Sprite
- #--------------------------------------------------------------------------
- def dispose_icon_sprite
- return if @icon_sprite == nil
- @icon_sprite.bitmap.dispose
- @icon_sprite.dispose
- @icon_sprite = 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_sprite == nil
- @button_sprite.bitmap.dispose
- @button_sprite.dispose
- @button_sprite = nil
- end
- #--------------------------------------------------------------------------
- # ● Dispose Meter
- #--------------------------------------------------------------------------
- def dispose_meter
- return if @meter_layout == nil
- @meter_layout.dispose
- @meter_layout = nil
- @meter.bitmap.dispose
- @meter.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?(:X)
- check_command(0)
- elsif Input.trigger?(:Z)
- check_command(1)
- elsif Input.trigger?(:Y)
- check_command(2)
- elsif Input.trigger?(:A)
- check_command(3)
- elsif Input.trigger?(:C)
- check_command(4)
- elsif Input.trigger?(:B)
- check_command(5)
- elsif Input.trigger?(:L)
- check_command(6)
- elsif Input.trigger?(:R)
- check_command(7)
- elsif Input.trigger?(:RIGHT)
- check_command(8)
- elsif Input.trigger?(:LEFT)
- check_command(9)
- elsif Input.trigger?(:DOWN)
- check_command(10)
- elsif Input.trigger?(: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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement