设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1405|回复: 0
打印 上一主题 下一主题

[已经过期] 有事请教关于战斗顺序和战斗中换人

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
35 小时
注册时间
2014-4-23
帖子
7
跳转到指定楼层
1
发表于 2014-12-9 22:47:34 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
下面是战斗顺序和战斗中换人的两个脚本   就是进入战斗之后换人之后血条还不变还是之前的
应该怎么改啊







#==============================================================================
# +++ MOG - Battle Hud EX (v3.8) +++
#==============================================================================
# By Moghunter
# http://www.atelier-rgss.com
#==============================================================================
# Sistema avan?ado de Hud de batalha, voltado para artistas gráficos e
# usuários avan?ados.
#
# Compatível com :
#
# - Victor's Animated_battle (1.21)
# - Victor's Active Time Battle (1.05)
# - Victor's Map Turn Battle (1.09)
# - Victor's Target Arrows (1.08)
# - Yami's Battle Symphony (1.16)
# - Yanfly's Battle Engine (1.09)
# - Yanfly's Visual Battlers (1.01)
# - Yanfly's Enemy Target Info (1.02)
# - Kread-EX's Animated Battlers (1.08)
# - Galv's Animated Battlers (1.2)
# - Jet's Viewed Battle Systems (?)
# - Jet's Animated Battlers(?)
# - C Winter's Active Time Battle (1.62)
# - Enu's Tankentai SBS (v1.00)
#
#==============================================================================
#
# Coloque as imagens da hud na pasta.
#
# Graphics/Huds/Battle/
#==============================================================================
# Para ocultar ou apresentar a hud de batalha use o código abaixo.
#
# battle_hud_visible(false)
#
# ou
#
# battle_hud_visible(true)
#
#==============================================================================
# Para mudar o sprite da face do battler use o código abaixo.
#==============================================================================
#
# battler_face_name( ACTOR_ID, FIlE_NAME )
#
#==============================================================================

#==============================================================================
# Atualiza??es desta vers?o.
#============================================================================
# (Ver 3.8)
#     - Melhoria na posi??o Z da janelas.
#     - Melhoria de compatibilidade com alguns scripts.
# (Ver 3.7)
#     - A Hud n?o é mais influênciada pela tonalidade da tela, como nas
#       batalhas noturnas.
#==============================================================================
module MOG_BATTLE_HUD_EX
  
  #============================================================================
  #============================================================================
  # * HUD SPRITE (GENERAL)
  #============================================================================
  # Defini??o da quantidade maxima de personagens na batalha.
  #---------------------------------------------------------------------------
  MAX_BATTLE_MEMBERS = 4
  #---------------------------------------------------------------------------
  # Defini??o da prioridade da hud.
  #---------------------------------------------------------------------------
  HUD_Z = 50
  #---------------------------------------------------------------------------
  # Defini??o da posi??o geral da hud, influência em todos os sprites da hud.
  #---------------------------------------------------------------------------
  HUD_POSITION = [0,323]
  #---------------------------------------------------------------------------
  # Defini??o do espa?o entre os membros do grupo.
  # (Use apenas para ajustes)
  #---------------------------------------------------------------------------
  MEMBERS_SPACE = [0,0]
  #---------------------------------------------------------------------------
  # Defini??o fixa da hud se deseja posicionar a hud em lugares
  # específicos da tela.
  #
  # FIXED_POSITION[INDEX_ID] = [X,Y]
  #
  #---------------------------------------------------------------------------
  FIXED_HUD_POSITION = []
  # FIXED_HUD_POSITION[0] = [10,10]
  # FIXED_HUD_POSITION[1] = [410,10]
  # FIXED_HUD_POSITION[2] = [10,320]
  # FIXED_HUD_POSITION[3] = [410,320]
  #---------------------------------------------------------------------------
  # Defini??o da posi??o do comando quando a op??o de janelas fixa é ativada.
  #---------------------------------------------------------------------------
  FIXED_COMMAND_POSITION = []
  #FIXED_COMMAND_POSITION[0] = [130,10]
  # FIXED_COMMAND_POSITION[1] = [300,10]
  # FIXED_COMMAND_POSITION[2] = [130,290]
  # FIXED_COMMAND_POSITION[3] = [300,290]
  #---------------------------------------------------------------------------
  # Ocultar a HUD quando a janela de mensagem está ativa.
  #---------------------------------------------------------------------------
  MESSAGE_WINDOW_FADE_HUD = true
  #---------------------------------------------------------------------------
  # Defini??o da posi??o da janela de mensagem.
  #---------------------------------------------------------------------------
  # 0 - Acima
  # 1 - Centro
  # 2 - Abaixo
  #---------------------------------------------------------------------------
  BATTLE_MESSAGE_POSITION = 0  
  #---------------------------------------------------------------------------
  # Defini??o da porcentagem do parametro baixo, isso influência na cor
  # do número dos parametros de HP, MP e TP.
  #---------------------------------------------------------------------------
  LOW_PARAMETER_PERCENTAGE = 30
  #============================================================================
  #============================================================================
  
  
  #============================================================================
  #============================================================================
  # * NAME
  #============================================================================
  # Ativar o Sprite do nome do personagem.
  #---------------------------------------------------------------------------
  NAME_VISIBLE = false
  #---------------------------------------------------------------------------
  # Defini??o da prioridade do Sprite.
  #---------------------------------------------------------------------------  
  NAME_Z = 5
  #---------------------------------------------------------------------------
  # Defini??o da posi??o da Face. [X,Y]
  #---------------------------------------------------------------------------
  NAME_POSITION = [0,-7]
  #---------------------------------------------------------------------------
  # Defini??o do tipo alinhamento do nome.
  #
  # 0 - Esquerda
  # 1 - Centro
  # 2 - Direita
  #---------------------------------------------------------------------------  
  NAME_ALIGN_TYPE = 1
  #---------------------------------------------------------------------------
  # Defini??o do nome da fonte.
  #---------------------------------------------------------------------------
  NAME_FONT_NAME = "Georgia"
  #---------------------------------------------------------------------------
  # Defini??o do tamanho da fonte.
  #---------------------------------------------------------------------------   
  NAME_FONT_SIZE = 16
  #---------------------------------------------------------------------------
  # Ativar Bold.
  #---------------------------------------------------------------------------   
  NAME_FONT_BOLD = true
  #---------------------------------------------------------------------------
  # Ativar Italic.
  #---------------------------------------------------------------------------   
  NAME_FONT_ITALIC = true
  #---------------------------------------------------------------------------
  # Defini??o da cor da fonte
  #---------------------------------------------------------------------------     
  NAME_FONT_COLOR = Color.new(255,255,255,255)
  #---------------------------------------------------------------------------
  # Ativar Sombra
  #---------------------------------------------------------------------------  
  NAME_FONT_SHADOW = false
  #---------------------------------------------------------------------------
  # Defini??o da cor da sombra
  #---------------------------------------------------------------------------   
  NAME_FONT_SHADOW_COLOR = Color.new(0,0,0,255)
  #---------------------------------------------------------------------------
  # Defini??o da distancia da sombra.
  #---------------------------------------------------------------------------   
  NAME_FONT_SHADOW_POSITION = [2,2]  
  #============================================================================
  #============================================================================
   
  
  #============================================================================
  #============================================================================
  # * FACE
  #============================================================================
  # Ativar a face.
  # Será necessário o arquivo.
  #
  # ACTOR_NAME + _Face.png
  #
  # Eric_Face.png
  #
  #---------------------------------------------------------------------------
  FACE_VISIBLE = true
  # Ativar as Faces representando os battlers.
  # Deixe "false" se tiver problemas de compatibilidade com scripts.
  FACE_BATTLER = true
  #---------------------------------------------------------------------------
  # Defini??o da prioridade do sprite.
  #---------------------------------------------------------------------------  
  FACE_Z = -1
  #---------------------------------------------------------------------------
  # Defini??o da posi??o da Face. [X,Y]
  #---------------------------------------------------------------------------
  FACE_POSITION = [68,5]
  #---------------------------------------------------------------------------
  # Ativar faces animadas.
  # Será necessário ter uma imagem de 5 faces do personagem no mesmo arquivo.
  #
  # FACE1/FACE2/FACE3/FACE4
  #
  # A imagem será dividida por 4 frames, no caso de definir a fun??o como FALSE
  # a imagem será dividida por 1 frame
  #---------------------------------------------------------------------------  
  FACE_ANIMATION = true
  #---------------------------------------------------------------------------
  # Ativar o efeito de Zoom quando o personagem usar alguma a??o.
  #---------------------------------------------------------------------------
  FACE_ZOOM_ANIMATION = true
  #---------------------------------------------------------------------------
  # Ativar o efeito Mirror na anima??o de a??o do personagem.
  #---------------------------------------------------------------------------
  FACE_ZOOM_MIRROR_EFFECT = false
  #---------------------------------------------------------------------------
  # Defini??o do tempo dura??o da anima??o da face.
  #---------------------------------------------------------------------------  
  FACE_ANIMATION_DURATION = 40
  #---------------------------------------------------------------------------
  # Ativar o efeito tremor da face quando o personagem sofrer dano.
  #---------------------------------------------------------------------------  
  FACE_SHAKE_EFFECT = true
  #============================================================================
  #============================================================================
  
  
  #============================================================================
  #============================================================================
  # * TURN (ACTIVE INDICATOR)
  #============================================================================
  # Ativar o indicador de turno do personagem.
  # Será necessário o arquivo.
  #
  # Turn.png
  #
  #---------------------------------------------------------------------------
  TURN_SPRITE_VISIBLE = true
  #---------------------------------------------------------------------------
  # Defini??o da prioridade do Sprite.
  #---------------------------------------------------------------------------   
  TURN_SPRITE_Z = 0
  #---------------------------------------------------------------------------
  # Defini??o da posi??o do sprite de turno.
  #---------------------------------------------------------------------------  
  TURN_SPRITE_POSITION = [7,-30]
  #---------------------------------------------------------------------------  
  # Ativar o efeito de anima??o de piscar.
  #---------------------------------------------------------------------------  
  TURN_BLINK_EFFECT = true
  #---------------------------------------------------------------------------  
   
  
  #============================================================================
  #============================================================================
  # * HP
  #============================================================================
  # Ativar o número de HP.
  # Será necessário o arquivo.
  #
  # HP_Number.png
  #
  #---------------------------------------------------------------------------
  HP_NUMBER_VISIBLE = true
  #---------------------------------------------------------------------------
  # Defini??o da prioridade do Sprite.
  #---------------------------------------------------------------------------   
  HP_NUMBER_Z = 2
  #---------------------------------------------------------------------------
  # Defini??o da posi??o do número de HP. [X,Y]
  #---------------------------------------------------------------------------  
  HP_NUMBER_POSITION = [117,26]
  #---------------------------------------------------------------------------  
  # Ativar o número de HP Total.
  # Será necessário o arquivo.
  #
  # HP_Number_Max.png
  #
  #---------------------------------------------------------------------------
  HP_NUMBER_MAX_VISIBLE = false
  #---------------------------------------------------------------------------
  # Defini??o da posi??o do número de HP Total. [X,Y]
  #---------------------------------------------------------------------------  
  HP_NUMBER_MAX_POSITION = [165,30]
  #---------------------------------------------------------------------------
  # Defini??o do tipo alinhamento do número.
  #
  # 0 - Esquerda
  # 1 - Centro
  # 2 - Direita
  #---------------------------------------------------------------------------  
  HP_NUMBER_ALIGN_TYPE = 2
  #---------------------------------------------------------------------------
  # Ativa o efeito de alinhar os números em posi??es de Y diferentes.
  #---------------------------------------------------------------------------
  HP_NUMBER_WAVE_ALIGN_EFFECT = false
  #---------------------------------------------------------------------------
  # Apresentar os números em porcentagem.
  #---------------------------------------------------------------------------   
  HP_NUMBER_PERCENTAGE = false
  #---------------------------------------------------------------------------
  # Ativar números animados ("Rolantes").
  #---------------------------------------------------------------------------  
  HP_NUMBER_ANIMATION = true
  #---------------------------------------------------------------------------
  # Ativar a cor do HP baixo.
  # Será necessário ter a imagem com as duas cores do paramêtro no mesmo
  # arquivo de imagem, a imagem será dividida por 2 frames de altura.
  #
  # NORMAL_COLOR
  # LOW_PARAMETER_COLOR
  #
  # Caso definir a fun??o como FALSE a imagem será dividida apenas como
  # 1 frame de altura.
  #---------------------------------------------------------------------------  
  HP_NUMBER_LOW_COLOR = false
  #---------------------------------------------------------------------------
  # Ativar o medidor de HP.
  # Será necessário o arquivo.
  #
  # HP_Meter.png
  #  
  #---------------------------------------------------------------------------  
  HP_METER_VISIBLE = true
  #---------------------------------------------------------------------------
  # Defini??o da prioridade do sprite.
  #---------------------------------------------------------------------------   
  HP_METER_Z = 1
  #---------------------------------------------------------------------------
  # Defini??o da posi??o do medidor de HP. [X,Y]
  #---------------------------------------------------------------------------  
  HP_METER_POSITION = [38,39]
  #---------------------------------------------------------------------------
  # Defini??o do angulo do medidor.
  #---------------------------------------------------------------------------  
  HP_METER_ANGLE = 0
  #---------------------------------------------------------------------------
  # Ativar o efeito mirror, essa op??o faz com que o medidor tenha o movimento
  # inverso.
  #---------------------------------------------------------------------------  
  HP_METER_MIRROR_EFFECT = false
  #---------------------------------------------------------------------------
  # Ativar o efeito animado de dano no medidor.
  # Será necessário ter a imagem com as duas cores do paramêtro no mesmo
  # arquivo de imagem, a imagem será dividida por 2 frames de altura.
  #
  # NORMAL_COLOR
  # DAMAGE_COLOR
  #
  # Se definir como FALSE use apenas use uma imagem com o tamanho normal.
  #---------------------------------------------------------------------------  
  HP_METER_REDUCTION_ANIMATION = true
  #---------------------------------------------------------------------------
  # Ativar o efeito animado do "medidor fluindo".
  # Será necessário ter a imagem com a largura 3 vezes maior que o tamanho normal.
  # Essa imagem dever estar em gradiente para ter o efeito "fluindo".
  # Se definir como FALSE use apenas uma imagem com o tamanho normal.
  #---------------------------------------------------------------------------  
  HP_METER_GRADIENT_ANIMATION = true
  #---------------------------------------------------------------------------
  # Ativar HP em ícones.
  # Será necessário ter a imagem.
  #
  # HP_Icon.png
  #
  #---------------------------------------------------------------------------
  HP_ICON_VISIBLE = false
  #---------------------------------------------------------------------------
  # Defini??o da prioridade do Sprite.
  #---------------------------------------------------------------------------   
  HP_ICON_Z = 1
  #---------------------------------------------------------------------------
  # Posi??o do ícone de HP.
  #---------------------------------------------------------------------------  
  HP_ICON_POSITION = [200,0]
  #---------------------------------------------------------------------------
  # Ativar o sprite EX do ultimo ícone
  # Será necessário ter a imagem.
  #
  # HP_Icon_EX.png
  #
  #---------------------------------------------------------------------------
  HP_ICON_EX_VISIBLE = false
  #---------------------------------------------------------------------------
  # Posi??o do ícone Animado.
  #---------------------------------------------------------------------------  
  HP_ICON_EX_POSITION = [0,0]
  #---------------------------------------------------------------------------
  # Ativar o efeito de Zoom do Sprite.
  #---------------------------------------------------------------------------
  HP_ICON_EX_ZOOM_EFFECT = true
  #---------------------------------------------------------------------------
  # Espa?o entre os ícones.
  #---------------------------------------------------------------------------   
  HP_ICON_SPACE = [-10,-10]
  #---------------------------------------------------------------------------
  # Defini??o da quantidade maxima de ícones na horizontal.
  #---------------------------------------------------------------------------  
  HP_ICON_COL_MAX = 10
  #---------------------------------------------------------------------------
  # Defini??o da quantidade maxima de ícones na vertical.
  #---------------------------------------------------------------------------   
  HP_ICON_ROW_MAX = 2
  #---------------------------------------------------------------------------
  # Ativar o número de HP de ícones.
  # Será necessário ter a imagem.
  #
  # HP_Icon_Number.png
  #
  #---------------------------------------------------------------------------
  HP_ICON_NUMBER_VISIBLE = false
  #---------------------------------------------------------------------------
  # Defini??o da prioridade do sprite.
  #---------------------------------------------------------------------------
  HP_ICON_NUMBER_Z = 4
  #---------------------------------------------------------------------------
  # Posi??o do número do ícone
  #---------------------------------------------------------------------------  
  HP_ICON_NUMBER_POSITION = [0,0]
  #---------------------------------------------------------------------------
  # Defini??o do tipo alinhamento do número.
  #
  # 0 - Esquerda
  # 1 - Centro
  # 2 - Direita
  #---------------------------------------------------------------------------  
  HP_ICON_NUMBER_ALIGN_TYPE = 0   
  #============================================================================
  #============================================================================
  
  
  #============================================================================
  #============================================================================
  # * MP
  #============================================================================
  # Ativar o número de MP.
  # Será necessário o arquivo.
  #
  # MP_Number.png
  #  
  #---------------------------------------------------------------------------  
  MP_NUMBER_VISIBLE = true
  #---------------------------------------------------------------------------
  # Defini??o da prioridade do Sprite.
  #---------------------------------------------------------------------------   
  MP_NUMBER_Z = 2  
  #---------------------------------------------------------------------------
  # Defini??o da posi??o do número de MP. [X,Y]
  #---------------------------------------------------------------------------  
  MP_NUMBER_POSITION = [90,44]
  #---------------------------------------------------------------------------  
  # Ativar o número de MP Total.
  # Será necessário o arquivo.
  #
  # MP_Number_Max.png
  #
  #---------------------------------------------------------------------------
  MP_NUMBER_MAX_VISIBLE = false
  #---------------------------------------------------------------------------
  # Defini??o da posi??o do número de MP Total. [X,Y]
  #---------------------------------------------------------------------------  
  MP_NUMBER_MAX_POSITION = [128,53]
  #---------------------------------------------------------------------------
  # Defini??o do tipo alinhamento do número.
  #
  # 0 - Esquerda
  # 1 - Centro
  # 2 - Direita
  #---------------------------------------------------------------------------  
  MP_NUMBER_ALIGN_TYPE = 2
  #---------------------------------------------------------------------------
  # Ativa o efeito de alinhar os números em posi??es de Y diferentes.
  #---------------------------------------------------------------------------
  MP_NUMBER_WAVE_ALIGN_EFFECT = false   
  #---------------------------------------------------------------------------
  # Apresentar os números em porcentagem.
  #---------------------------------------------------------------------------   
  MP_NUMBER_PERCENTAGE = false
  #---------------------------------------------------------------------------
  # Ativar números animados ("Rolantes").
  #---------------------------------------------------------------------------  
  MP_NUMBER_ANIMATION = true
  #---------------------------------------------------------------------------
  # Ativar a cor do MP baixo.
  # Será necessário ter a imagem com as duas cores do paramêtro no mesmo
  # arquivo de imagem, a imagem será dividida por 2 frames de altura.
  #
  # NORMAL_COLOR
  # LOW_PARAMETER_COLOR
  #
  # Se definir como FALSE use apenas use uma imagem com o tamanho normal.
  #---------------------------------------------------------------------------  
  MP_NUMBER_LOW_COLOR = false
  #---------------------------------------------------------------------------
  # Ativar o medidor de MP.
  # Será necessário o arquivo.
  #
  # MP_Meter.png
  #   
  #---------------------------------------------------------------------------  
  MP_METER_VISIBLE = true
  #---------------------------------------------------------------------------
  # Defini??o da prioridade do sprite.
  #---------------------------------------------------------------------------   
  MP_METER_Z = 1  
  #---------------------------------------------------------------------------
  # Defini??o da posi??o do medidor de MP. [X,Y]
  #---------------------------------------------------------------------------  
  MP_METER_POSITION = [9,56]
  #---------------------------------------------------------------------------
  # Defini??o do angulo do medidor.
  #---------------------------------------------------------------------------  
  MP_METER_ANGLE = 0
  #---------------------------------------------------------------------------
  # Ativar o efeito mirror, essa op??o faz com que o medidor tenha o movimento
  # inverso.
  #---------------------------------------------------------------------------  
  MP_METER_MIRROR_EFFECT = false
  #---------------------------------------------------------------------------
  # Ativar o efeito animado de dano no medidor.
  # Será necessário ter a imagem com as duas cores do paramêtro no mesmo
  # arquivo de imagem, a imagem será dividida por 2 frames de altura.
  #
  # NORMAL_COLOR
  # DAMAGE_COLOR
  #
  # Se definir como FALSE use apenas use uma imagem com o tamanho normal.
  #---------------------------------------------------------------------------  
  MP_METER_REDUCTION_ANIMATION = true
  #---------------------------------------------------------------------------
  # Ativar o efeito animado do "medidor fluindo".
  # Será necessário ter a imagem com a largura 3 vezes maior que o tamanho normal.
  # Essa imagem dever estar em gradiente para ter o efeito "fluindo".
  # Se definir como FALSE use apenas uma imagem com o tamanho normal.
  #---------------------------------------------------------------------------  
  MP_METER_GRADIENT_ANIMATION = true
  #---------------------------------------------------------------------------
  # Ativar MP em ícones.
  # Será necessário ter a imagem.
  #
  # MP_Icon.png
  #
  #---------------------------------------------------------------------------
  MP_ICON_VISIBLE = false
  #---------------------------------------------------------------------------
  # Defini??o da prioridade do Sprite.
  #---------------------------------------------------------------------------   
  MP_ICON_Z = 1  
  #---------------------------------------------------------------------------
  # Posi??o do ícone de MP.
  #---------------------------------------------------------------------------  
  MP_ICON_POSITION = [200,64]
  #---------------------------------------------------------------------------
  # Ativar o sprite EX do ultimo ícone
  # Será necessário ter a imagem.
  #
  # MP_Icon_EX.png
  #
  #---------------------------------------------------------------------------
  MP_ICON_EX_VISIBLE = false
  #---------------------------------------------------------------------------
  # Posi??o do ícone Animado.
  #---------------------------------------------------------------------------  
  MP_ICON_EX_POSITION = [0,0]
  #---------------------------------------------------------------------------
  # Ativar o efeito de Zoom do Sprite.
  #---------------------------------------------------------------------------
  MP_ICON_EX_ZOOM_EFFECT = true
  #---------------------------------------------------------------------------
  # Espa?o entre os ícones.
  #---------------------------------------------------------------------------   
  MP_ICON_SPACE = [-10,-10]
  #---------------------------------------------------------------------------
  # Defini??o da quantidade maxima de ícones na horizontal.
  #---------------------------------------------------------------------------  
  MP_ICON_COL_MAX = 10
  #---------------------------------------------------------------------------
  # Defini??o da quantidade maxima de ícones na vertical.
  #---------------------------------------------------------------------------   
  MP_ICON_ROW_MAX = 2
  #---------------------------------------------------------------------------
  # Ativar o número de MP de ícones.
  # Será necessário ter a imagem.
  #
  # MP_Icon_Number.png
  #
  #---------------------------------------------------------------------------
  MP_ICON_NUMBER_VISIBLE = false
  #---------------------------------------------------------------------------
  # Defini??o da prioridade do sprite.
  #---------------------------------------------------------------------------
  MP_ICON_NUMBER_Z = 4
  #---------------------------------------------------------------------------
  # Posi??o do número do ícone
  #---------------------------------------------------------------------------  
  MP_ICON_NUMBER_POSITION = [0,64]
  #---------------------------------------------------------------------------
  # Defini??o do tipo alinhamento do número.
  #
  # 0 - Esquerda
  # 1 - Centro
  # 2 - Direita
  #---------------------------------------------------------------------------  
  MP_ICON_NUMBER_ALIGN_TYPE = 0   
  #============================================================================
  #============================================================================
  
  
  #============================================================================
  #============================================================================
  # * TP
  #============================================================================
  # Ativar o número de TP.
  # Será necessário o arquivo.
  #
  # TP_Number.png
  #   
  #---------------------------------------------------------------------------
  TP_NUMBER_VISIBLE = true
  #---------------------------------------------------------------------------
  # Defini??o da prioridade do sprite.
  #---------------------------------------------------------------------------
  TP_NUMBER_Z = 5  
  #---------------------------------------------------------------------------
  # Defini??o da posi??o do número de TP. [X,Y]
  #---------------------------------------------------------------------------  
  TP_NUMBER_POSITION = [19,23]
  #---------------------------------------------------------------------------  
  # Ativar o número de TP Total.
  # Será necessário o arquivo.
  #
  # TP_Number_Max.png
  #
  #---------------------------------------------------------------------------
  TP_NUMBER_MAX_VISIBLE = false
  #---------------------------------------------------------------------------
  # Defini??o da posi??o do número de TP Total. [X,Y]
  #---------------------------------------------------------------------------  
  TP_NUMBER_MAX_POSITION = [165,73]
  #---------------------------------------------------------------------------
  # Defini??o do tipo alinhamento do número.
  #
  # 0 - Esquerda
  # 1 - Centro
  # 2 - Direita
  #---------------------------------------------------------------------------  
  TP_NUMBER_ALIGN_TYPE = 1
  #---------------------------------------------------------------------------
  # Ativa o efeito de alinhar os números em posi??es de Y diferentes.
  #---------------------------------------------------------------------------
  TP_NUMBER_WAVE_ALIGN_EFFECT = false   
  #---------------------------------------------------------------------------
  # Apresentar os números em porcentagem.
  #---------------------------------------------------------------------------   
  TP_NUMBER_PERCENTAGE = false
  #---------------------------------------------------------------------------
  # Ativar números animados ("Rolantes").
  #---------------------------------------------------------------------------  
  TP_NUMBER_ANIMATION = true
  #---------------------------------------------------------------------------
  # Ativar a cor do TP baixo.
  # Será necessário ter a imagem com as duas cores do paramêtro no mesmo
  # arquivo de imagem, a imagem será dividida por 2 frames de altura.
  #
  # NORMAL_COLOR
  # LOW_PARAMETER_COLOR
  #
  # Se definir como FALSE use apenas use uma imagem com o tamanho normal.
  #---------------------------------------------------------------------------  
  TP_NUMBER_LOW_COLOR = false
  #---------------------------------------------------------------------------
  # Ativar o medidor de TP.
  # Será necessário o arquivo.
  #
  # TP_Meter.png
  #   
  #---------------------------------------------------------------------------  
  TP_METER_VISIBLE = false
  #---------------------------------------------------------------------------
  # Defini??o da prioridade do sprite.
  #---------------------------------------------------------------------------
  TP_METER_Z = 1  
  #---------------------------------------------------------------------------
  # Defini??o da posi??o do medidor de TP. [X,Y]
  #---------------------------------------------------------------------------  
  TP_METER_POSITION = [68,74]
  #---------------------------------------------------------------------------
  # Defini??o do angulo do medidor.
  #---------------------------------------------------------------------------  
  TP_METER_ANGLE = 0
  #---------------------------------------------------------------------------
  # Ativar o efeito mirror, essa op??o faz com que o medidor tenha o movimento
  # inverso.
  #---------------------------------------------------------------------------  
  TP_METER_MIRROR_EFFECT = false
  #---------------------------------------------------------------------------
  # Ativar o efeito animado de dano no medidor.
  # Será necessário ter a imagem com as duas cores do paramêtro no mesmo
  # arquivo de imagem, a imagem será dividida por 2 frames de altura.
  #
  # NORMAL_COLOR
  # DAMAGE_COLOR
  #
  # Se definir como FALSE use apenas use uma imagem com o tamanho normal.
  #---------------------------------------------------------------------------  
  TP_METER_REDUCTION_ANIMATION = true
  #---------------------------------------------------------------------------
  # Ativar o efeito animado do "medidor fluindo".
  # Será necessário ter a imagem com a largura 3 vezes maior que o tamanho normal.
  # Essa imagem dever estar em gradiente para ter o efeito "fluindo".
  # Se definir como FALSE use apenas uma imagem com o tamanho normal.
  #---------------------------------------------------------------------------  
  TP_METER_GRADIENT_ANIMATION = true
  #---------------------------------------------------------------------------
  # Ativar TP em ícones.
  # Será necessário ter a imagem.
  #
  # TP_Icon.png
  #
  #---------------------------------------------------------------------------
  TP_ICON_VISIBLE = false
  #---------------------------------------------------------------------------
  # Defini??o da prioridade do sprite.
  #---------------------------------------------------------------------------
  TP_ICON_Z = 1  
  #---------------------------------------------------------------------------
  # Posi??o do ícone de TP.
  #---------------------------------------------------------------------------  
  TP_ICON_POSITION = [200,128]
  #---------------------------------------------------------------------------
  # Ativar o sprite EX do ultimo ícone
  # Será necessário ter a imagem.
  #
  # TP_Icon_EX.png
  #
  #---------------------------------------------------------------------------
  TP_ICON_EX_VISIBLE = false
  #---------------------------------------------------------------------------
  # Posi??o do ícone Animado.
  #---------------------------------------------------------------------------  
  TP_ICON_EX_POSITION = [0,0]
  #---------------------------------------------------------------------------
  # Ativar o efeito de Zoom do Sprite.
  #---------------------------------------------------------------------------
  TP_ICON_EX_ZOOM_EFFECT = true
  #---------------------------------------------------------------------------
  # Espa?o entre os ícones.
  #---------------------------------------------------------------------------   
  TP_ICON_SPACE = [-10,-10]
  #---------------------------------------------------------------------------
  # Defini??o da quantidade maxima de ícones na horizontal.
  #---------------------------------------------------------------------------  
  TP_ICON_COL_MAX = 10
  #---------------------------------------------------------------------------
  # Defini??o da quantidade maxima de ícones na vertical.
  #---------------------------------------------------------------------------   
  TP_ICON_ROW_MAX = 2
  #---------------------------------------------------------------------------
  # Ativar o número de TP de ícones.
  # Será necessário ter a imagem.
  #
  # TP_Icon_Number.png
  #
  #---------------------------------------------------------------------------
  TP_ICON_NUMBER_VISIBLE = false
  #---------------------------------------------------------------------------
  # Defini??o da prioridade do sprite.
  #---------------------------------------------------------------------------
  TP_ICON_NUMBER_Z = 4
  #---------------------------------------------------------------------------
  # Posi??o do número do ícone
  #---------------------------------------------------------------------------  
  TP_ICON_NUMBER_POSITION = [0,128]
  #---------------------------------------------------------------------------
  # Defini??o do tipo alinhamento do número.
  #
  # 0 - Esquerda
  # 1 - Centro
  # 2 - Direita
  #---------------------------------------------------------------------------  
  TP_ICON_NUMBER_ALIGN_TYPE = 0   
  #============================================================================
  #============================================================================
  
  #============================================================================
  #============================================================================
  # * AT
  #============================================================================
  # Ativar o número de AT.
  # Será necessário o arquivo.
  #
  # AT_Number.png
  #
  #---------------------------------------------------------------------------
  AT_NUMBER_VISIBLE = false
  #---------------------------------------------------------------------------
  # Defini??o da prioridade do Sprite.
  #---------------------------------------------------------------------------   
  AT_NUMBER_Z = 2
  #---------------------------------------------------------------------------
  # Defini??o da posi??o do número de AT. [X,Y]
  #---------------------------------------------------------------------------  
  AT_NUMBER_POSITION = [125,-27]
  #---------------------------------------------------------------------------  
  # Ativar o número de AT Total.
  # Será necessário o arquivo.
  #
  # AT_Number_Max.png
  #
  #---------------------------------------------------------------------------
  AT_NUMBER_MAX_VISIBLE = false
  #---------------------------------------------------------------------------
  # Defini??o da posi??o do número de AT Total. [X,Y]
  #---------------------------------------------------------------------------  
  AT_NUMBER_MAX_POSITION = [165,-17]
  #---------------------------------------------------------------------------
  # Defini??o do tipo alinhamento do número.
  #
  # 0 - Esquerda
  # 1 - Centro
  # 2 - Direita
  #---------------------------------------------------------------------------  
  AT_NUMBER_ALIGN_TYPE = 2
  #---------------------------------------------------------------------------
  # Ativa o efeito de alinhar os números em posi??es de Y diferentes.
  #---------------------------------------------------------------------------
  AT_NUMBER_WAVE_ALIGN_EFFECT = false
  #---------------------------------------------------------------------------
  # Apresentar os números em porcentagem.
  #---------------------------------------------------------------------------   
  AT_NUMBER_PERCENTAGE = true
  #---------------------------------------------------------------------------
  # Ativar números animados ("Rolantes").
  #---------------------------------------------------------------------------  
  AT_NUMBER_ANIMATION = false
  #---------------------------------------------------------------------------
  # Ativar o medidor de AT.
  # Será necessário o arquivo.
  #
  # AT_Meter.png
  #  
  #---------------------------------------------------------------------------  
  AT_METER_VISIBLE = true
  #---------------------------------------------------------------------------
  # Defini??o da prioridade do sprite.
  #---------------------------------------------------------------------------   
  AT_METER_Z = 1
  #---------------------------------------------------------------------------
  # Defini??o da posi??o do medidor de AT. [X,Y]
  #---------------------------------------------------------------------------  
  AT_METER_POSITION = [38,76]
  #---------------------------------------------------------------------------
  # Defini??o do angulo do medidor.
  #---------------------------------------------------------------------------  
  AT_METER_ANGLE = 0
  #---------------------------------------------------------------------------
  # Ativar o efeito mirror, essa op??o faz com que o medidor tenha o movimento
  # inverso.
  #---------------------------------------------------------------------------  
  AT_METER_MIRROR_EFFECT = false
  #---------------------------------------------------------------------------
  # Ativar o efeito animado do "medidor fluindo".
  # Será necessário ter a imagem com a largura 3 vezes maior que o tamanho normal.
  # Essa imagem dever estar em gradiente para ter o efeito "fluindo".
  # Se definir como FALSE use apenas uma imagem com o tamanho normal.
  #---------------------------------------------------------------------------  
  AT_METER_GRADIENT_ANIMATION = true
  #============================================================================
  
  
  #============================================================================
  #============================================================================
  # * LEVEL
  #============================================================================
  # Ativar o número de Level.
  # Será necessário o arquivo.
  #
  # LV_Number.png
  #   
  #---------------------------------------------------------------------------
  LEVEL_NUMBER_VISIBLE = false
  #---------------------------------------------------------------------------
  # Defini??o da prioridade do Sprite.
  #---------------------------------------------------------------------------   
  LEVEL_NUMBER_Z = 2
  #---------------------------------------------------------------------------
  # Defini??o da posi??o do número do Level. [X,Y]
  #---------------------------------------------------------------------------  
  LEVEL_NUMBER_POSITION = [84,0]
  #---------------------------------------------------------------------------
  # Defini??o do tipo alinhamento do número.
  #
  # 0 - Esquerda
  # 1 - Centro
  # 2 - Direita
  #---------------------------------------------------------------------------  
  LEVEL_NUMBER_ALIGN_TYPE = 1     
  #============================================================================
  #============================================================================
  
  
  #============================================================================
  #============================================================================
  # * STATE
  #============================================================================
  # Ativar as condi??es.
  #---------------------------------------------------------------------------  
  STATES_VISIBLE = true
  #---------------------------------------------------------------------------
  # Defini??o da prioridade do sprite.
  #---------------------------------------------------------------------------   
  STATES_Z = 1
  #---------------------------------------------------------------------------
  # Defini??o da posi??o das condi??es. [X,Y]
  #---------------------------------------------------------------------------  
  STATES_POSITION = [7,65]
  #---------------------------------------------------------------------------
  # Ativar o efeito animado das condi??es deslizando.
  #---------------------------------------------------------------------------  
  STATES_SCROLLING_ANIMATION = false
  #---------------------------------------------------------------------------
  # Defini??o do angulo do sprite.
  #---------------------------------------------------------------------------   
  STATE_ANGLE = 0
  #---------------------------------------------------------------------------
  # Defini??o das condi??es que ser?o ocultadas pela hud.
  # EX - HIDE_STATES_ID = [9,10,12,14]
  #---------------------------------------------------------------------------   
  HIDE_STATES_ID = []
  #============================================================================
  #============================================================================

  #============================================================================
  #============================================================================
  # * SECOND LAYOUT (Overlayer)
  #============================================================================  
  # Ativar a segunda camada de Layout
  # Será necessário o arquivo.
  #
  # Layout_2.png
  #
  #============================================================================  
  SECOND_LAYOUT = false
  #---------------------------------------------------------------------------
  # Defini??o da prioridade do sprite.
  #---------------------------------------------------------------------------  
  SECOND_LAYOUT_Z = 4
  #---------------------------------------------------------------------------
  # Defini??o da posi??o do sprite.
  #---------------------------------------------------------------------------   
  SECOND_LAYOUT_POSITION = [-5,-10]
  #============================================================================
  #============================================================================
   
end

#============================================================================
#============================================================================
# * CUSTOM WINDOWS (GENERAL)
#============================================================================
module MOG_BATTLE_HUD_EX
  
#============================================================================
# * Ativar Janelas Customizadas.
#============================================================================
  ENABLE_CUSTOM_WINDOWS = true
  
#============================================================================
# * BATTLE LOG WINDOW
#============================================================================
#Defini??o da posi??o da janela de log.
  BATTLE_LOG_POSITION = [0,0]
#============================================================================
  
  
#============================================================================
# * SKILL WINDOW
#============================================================================
#Defini??o do tamanho da janela.
  SKILL_WINDOW_SIZE = [Graphics.width, 120]
#Defini??o da posi??o da janela.
  SKILL_WINDOW_POSITION = [0,0]
#Defini??o da transparência da janela.
  SKILL_WINDOW_OPACITY = 0
#Ativar a imagem de Layout. ("Layout_Skill.png")
  SKILL_WINDOW_LAYOUT = true
#Defini??o do layout.
  SKILL_WINDOW_LAYOUT_POSITION = [0,-7]  
#============================================================================
  
#============================================================================
# * ITEM WINDOW
#============================================================================
#Defini??o do tamanho da janela.  
  ITEM_WINDOW_SIZE = [Graphics.width, 120]
#Defini??o da posi??o da janela.
  ITEM_WINDOW_POSITION = [0,0]
#Defini??o da transparência da janela.
  ITEM_WINDOW_OPACITY = 0
#Ativar a imagem de Layout. ("Layout_Item.png")   
  ITEM_WINDOW_LAYOUT = true
#Defini??o do layout.  
  ITEM_WINDOW_LAYOUT_POSITION = [0,-7]   
#============================================================================

#============================================================================
# * COMMAND WINDOW
#============================================================================
#Ajustar automáticamente   
  AUTO_ADJUST_ACTOR_COMMAND = true
#Defini??o da posi??o da janela. (Apenas para Ajustes)
  ACTOR_COMMAND_POSITION = [0,-50]
#Defini??o da transparência da janela.
  ACTOR_COMMAND_OPACITY = 0
#Ativar a imagem de Layout. ("Layout_Command.png")   
  ACTOR_COMMAND_LAYOUT = true
#Defini??o do layout.   
  ACTOR_COMMAND_LAYOUT_POSITION = [0,0]
#============================================================================

#============================================================================
# * HELP WINDOW
#============================================================================
#Defini??o do tamanho da janela.   
  HELP_WINDOW_SIZE = [Graphics.width, 72]
#Defini??o do tamanho da janela.
  HELP_WINDOW_POSITION = [Graphics.width / 2, 0]  
#Defini??o da transparência da janela.
  HELP_WINDOW_OPACITY = 0
#Ativar a imagem de Layout. ("Layout_Help.png")   
  HELP_WINDOW_LAYOUT = true
#Defini??o do layout.
  HELP_WINDOW_LAYOUT_POSITION = [0,0]
#============================================================================

#============================================================================
# * TARGET ACTOR WINDOW
#============================================================================
#Defini??o do tamanho da janela.   
  ACTOR_WINDOW_SIZE = [Graphics.width, 120]  
#Defini??o do tamanho da janela.
  ACTOR_WINDOW_POSITION = [Graphics.width / 2, Graphics.height]
#Defini??o da transparência da janela.  
  ACTOR_WINDOW_OPACITY = 0
#Ativar a imagem de Layout. ("Layout_Target_Actor.png")
  ACTOR_WINDOW_LAYOUT = true
#Defini??o do layout.
  ACTOR_WINDOW_LAYOUT_POSITION = [0,0]
#============================================================================

#============================================================================
# * TARGET ENEMY WINDOW
#============================================================================
#Defini??o do tamanho da janela.
  ENEMY_WINDOW_SIZE = [Graphics.width, 120]
#Defini??o do tamanho da janela.  
  ENEMY_WINDOW_POSITION = [Graphics.width / 2, Graphics.height]
#Defini??o da transparência da janela.   
  ENEMY_WINDOW_OPACITY = 0
#Ativar a imagem de Layout. ("Layout_Target_Actor.png")
  ENEMY_WINDOW_LAYOUT = true
#Defini??o do layout.
  ENEMY_WINDOW_LAYOUT_POSITION = [0,0]
#============================================================================

#============================================================================
# * PARTY WINDOW (Fight/Escape)
#============================================================================
#Defini??o do tamanho da janela.  
  PARTY_COMMAND_POSITION = [Graphics.width / 2,Graphics.height / 2]
#Defini??o da transparência da janela.   
  PARTY_COMMAND_OPACITY = 0
#Ativar a imagem de Layout. ("Layout_Party.png")  
  PARTY_COMMAND_LAYOUT = true
#Defini??o do layout.  
  PARTY_COMMAND_LAYOUT_POSITION = [0,0]
#============================================================================

end

$imported = {} if $imported.nil?
$imported[:mog_battle_hud_ex] = true

#==============================================================================
# ** Cache
#==============================================================================
module Cache

  #--------------------------------------------------------------------------
  # * Hud
  #--------------------------------------------------------------------------
  def self.battle_hud(filename)
      load_bitmap("Graphics/Huds/Battle/", filename)
  end

end

#==============================================================================
# ** Game Temp
#==============================================================================
class Game_Temp
  
  attr_accessor :battler_face_pos
  attr_accessor :hud_pos
  attr_accessor :hud_pos_real
  attr_accessor :com_pos
  attr_accessor :mbhud_force_refresh
  attr_accessor :mbhud_window
  attr_accessor :command_visible
  attr_accessor :refresh_turn_sprite
  attr_accessor :battle_hud_visible
  attr_accessor :battle_hud_visible_refresh
  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------   
  alias mog_monogatari_bhud_initialize initialize
  def initialize
      @battler_face_pos = []
      @hud_pos = []
      @hud_pos_real = []
      @com_pos = []
      @mbhud_force_refresh = false
      @mbhud_window = [false,false,false,false,false,false,false]
      @command_visible = false
      @refresh_turn_sprite = false
      @battle_hud_visible = true
      @battle_hud_visible_refresh = [false,false]
      mog_monogatari_bhud_initialize
  end
  
  #--------------------------------------------------------------------------
  # * Check Screen Xyz
  #--------------------------------------------------------------------------   
  def check_screen_xyz_nil
      return if !SceneManager.face_battler?
      for actor in $game_party.battle_members
          actor.screen_x = 0 if actor.screen_x == nil
          actor.screen_y = 0 if actor.screen_y == nil
          actor.screen_z = 0 if actor.screen_z == nil
      end
  end  
  
end

#==============================================================================
# ** Game Interpreter
#==============================================================================
class Game_Interpreter
  
#--------------------------------------------------------------------------
# * Refresh Battle Hud
#--------------------------------------------------------------------------
def refresh_battle_hud
     $game_temp.check_screen_xyz_nil rescue nil
     $game_temp.mbhud_force_refresh = true
end
  
#--------------------------------------------------------------------------
# * Battler Face Name
#--------------------------------------------------------------------------
def battler_face_name(actor_id,face_name = "")
     for actor in $game_party.members
         actor.battler_face_name = face_name if actor.id == actor_id
     end
     refresh_battle_hud
end  
   
#--------------------------------------------------------------------------
# * Battler Hud Visible
#--------------------------------------------------------------------------
def battle_hud_visible(value)
     $game_temp.battle_hud_visible = value
end

#--------------------------------------------------------------------------
# * Command_129
#--------------------------------------------------------------------------
alias mog_monogatari_bhud_command_129 command_129
def command_129
     mog_monogatari_bhud_command_129     
     refresh_battle_hud if SceneManager.scene_is?(Scene_Battle)
end
  
end

#==============================================================================
# ** Game Actor
#==============================================================================
class Game_Actor < Game_Battler
  
  attr_accessor :face_animation
  attr_accessor :battler_face_name
  
  #--------------------------------------------------------------------------
  # * Setup
  #--------------------------------------------------------------------------
  alias mog_monogatari_face_animation setup
  def setup(actor_id)
      mog_monogatari_face_animation(actor_id)
      @face_animation = [0,0,0]
      @battler_face_name = "Face_" + actor_id.to_s
  end   
  
  #--------------------------------------------------------------------------
  # ● Real Next Level
  #--------------------------------------------------------------------------  
  def real_next_level
      next_level_exp - exp_for_level(level)
  end
  
  #--------------------------------------------------------------------------
  # ● Remain Exp
  #--------------------------------------------------------------------------  
  def remain_exp
      exp - exp_for_level(level)
  end
  
  #--------------------------------------------------------------------------
  # ● Gain Exp Test
  #--------------------------------------------------------------------------
  def gain_exp_test
      exp_r = rand(next_level_exp)
      change_exp(self.exp + (exp_r * final_exp_rate).to_i, false)
  end   
  
  #--------------------------------------------------------------------------
  # ● Low HP?
  #--------------------------------------------------------------------------   
  def low_hp?
      hp <= (mhp * MOG_BATTLE_HUD_EX::LOW_PARAMETER_PERCENTAGE) / 100
  end
  
  #--------------------------------------------------------------------------
  # ● Low MP?
  #--------------------------------------------------------------------------   
  def low_mp?
      mp <= (mmp * MOG_BATTLE_HUD_EX::LOW_PARAMETER_PERCENTAGE) / 100
  end  
  
  #--------------------------------------------------------------------------
  # ● Low TP?
  #--------------------------------------------------------------------------   
  def low_tp?
      tp <= (max_tp * MOG_BATTLE_HUD_EX::LOW_PARAMETER_PERCENTAGE) / 100
  end  
   
end

#==============================================================================
# ** Game Party
#==============================================================================
class Game_Party < Game_Unit
  
  #--------------------------------------------------------------------------
  # * Get Maximum Number of Battle Members
  #--------------------------------------------------------------------------
  def max_battle_members
      return MOG_BATTLE_HUD_EX::MAX_BATTLE_MEMBERS
  end
   
end

#==============================================================================
# ** BattleManager
#==============================================================================
module BattleManager
  
#--------------------------------------------------------------------------
# * Current Index
#--------------------------------------------------------------------------   
def self.current_index
     return 0 if @actor_index == nil
     return @actor_index != -1 ? @actor_index : 0
end
  
#--------------------------------------------------------------------------
# * Current Index Real
#--------------------------------------------------------------------------   
def self.current_index_real
     return -1 if @actor_index == nil
     return @actor_index
end

  #--------------------------------------------------------------------------
  # * Next Actor Avaliable
  #--------------------------------------------------------------------------
  def self.next_actor_avaliable?
      return false if @actor_index == nil
      next_index = @actor_index + 1
      return false if next_index >= $game_party.members.size
      return true
  end

  #--------------------------------------------------------------------------
  # * To Next Command Input
  #--------------------------------------------------------------------------
  def self.next_command_avaliable
    aindex = @actor_index
    begin      
      if !actor || !actor.next_command
        return false if actor == nil
        aindex += 1
        return false if aindex >= $game_party.members.size
      end
    end until actor.inputable?
    return true
  end  
  
  #--------------------------------------------------------------------------
  # * Can Enable Window?
  #--------------------------------------------------------------------------
  def self.can_enable_window?
      max_members = $game_party.members.size
      index_real = current_index_real + 1
      return false if index_real > max_members
      return false if in_turn?
      return false if $imported[:mog_battle_cursor]
      return true
  end
  
end

#==============================================================================
# ** SceneManager
#==============================================================================
module SceneManager
  
  #--------------------------------------------------------------------------
  # * Face Battler
  #--------------------------------------------------------------------------
  def self.face_battler?
      return false if !MOG_BATTLE_HUD_EX::FACE_BATTLER
      return false if $imported[:ve_animated_battle]
      return false if $imported[:ve_actor_battlers]
      return false if $imported["YES-BattleSymphony"]
      return false if $imported["YEA-VisualBattlers"]
      return false if $imported["Galv_Animated_Battlers"]
      return false if $imported['KRX-AnimatedBattlers']
      return false if $sv_camera != nil
      return false if BattleManager.true_surprise != nil rescue nil
      return false if $imported[:jet][:AnimatedBattlers] rescue nil      
      return true
  end
  
end

#==============================================================================
# ■ Sprite Picture
#==============================================================================
class Sprite_Picture < Sprite
  
  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------
  alias mog_battle_hud_initialize initialize
  def initialize(viewport, picture)
      mog_battle_hud_initialize(viewport, picture)
      self.viewport = nil if SceneManager.scene_is?(Scene_Battle)
  
  end  

  #--------------------------------------------------------------------------
  # * Update Position
  #--------------------------------------------------------------------------
  alias mog_battle_hud_update_position update_position
  def update_position
      mog_battle_hud_update_position
      self.z = @picture.number + 120 if SceneManager.scene_is?(Scene_Battle)
  end
   
end

#==============================================================================
# ■ Sprite Base
#==============================================================================
class Sprite_Base < Sprite
  
  
  #--------------------------------------------------------------------------
  # * Animation Set Sprite
  #--------------------------------------------------------------------------
  alias mog_battle_hud_ex_animation_set_sprites animation_set_sprites
  def animation_set_sprites(frame)
      mog_battle_hud_ex_animation_set_sprites(frame)
      update_sprite_z_animation rescue nil if SceneManager.scene_is?(Scene_Battle)
  end  
   
  #--------------------------------------------------------------------------
  # * Update Sprite Z Animation
  #--------------------------------------------------------------------------
  def update_sprite_z_animation  
      @ani_sprites.each_with_index do |sprite, i|
      sprite.viewport = nil ; sprite.z = 100 + i end
  end  
  
end

#==============================================================================
# ** Spriteset Battle
#==============================================================================
class Spriteset_Battle  

  #--------------------------------------------------------------------------
  # * Create Actors
  #--------------------------------------------------------------------------
  alias mog_battle_hud_create_actors create_actors
  def create_actors
      if can_create_max_members?
         @actor_sprites = Array.new($game_party.max_battle_members) { Sprite_Battler.new(@viewport1) }
         return
      end
      mog_battle_hud_create_actors
  end

  #--------------------------------------------------------------------------
  # * Can Create Max Members
  #--------------------------------------------------------------------------
  def can_create_max_members?
      return false if $imported[:ve_animated_battle]
      return false if $imported[:ve_actor_battlers]
      return false if $sv_camera != nil
      return true
  end
  
end

#==============================================================================
# ■ Scene Battle
#==============================================================================
class Scene_Battle < Scene_Base
  
#--------------------------------------------------------------------------
# ● Clear All Windows
#--------------------------------------------------------------------------
  alias mog_battle_hud_ex_start start
  def start
      setup_battle_hud_ex
      mog_battle_hud_ex_start
  end
  
#--------------------------------------------------------------------------
# ● Setup Battle Hud EX
#--------------------------------------------------------------------------
def setup_battle_hud_ex
     @force_clear_duration = 0
end
  
#--------------------------------------------------------------------------
# ● Clear All Windows
#--------------------------------------------------------------------------
def clear_all_windows
     if @actor_window != nil
        @actor_window.visible = false
        @actor_window.active = false
     end   
     if @status_window != nil
        @status_window.visible = false
        @status_window.active = false
     end   
     if @actor_command_window != nil
        @actor_command_window.visible = false
        @actor_command_window.active = false
     end
     if @party_command_window != nil
        @party_command_window.visible = false
        @party_command_window.active = false
     end
     if @help_window != nil
        @help_window.visible = false
     end  
end   
  
#--------------------------------------------------------------------------
# ● Update
#--------------------------------------------------------------------------
  alias mog_battle_hud_ex_update_main update
  def update
      mog_battle_hud_ex_update_main
      update_battle_hud_ex
  end
  
#--------------------------------------------------------------------------
# ● Update Battle Hud_ex
#--------------------------------------------------------------------------
  def update_battle_hud_ex
  end
  
end

if SceneManager.face_battler?
#==============================================================================
# ■ Game_Actor
#==============================================================================
class Game_Actor < Game_Battler
  
  attr_accessor :screen_x
  attr_accessor :screen_y
  attr_accessor :screen_z

  
#--------------------------------------------------------------------------
# ● Use Sprite?
#--------------------------------------------------------------------------
  def use_sprite?
      return true
  end
  
end

#==============================================================================
# ■ Sprite_Battler
#==============================================================================
class Sprite_Battler < Sprite_Base
  include MOG_BATTLE_HUD_EX
  #--------------------------------------------------------------------------
  # ● Update Collapse
  #--------------------------------------------------------------------------                          
   alias mog_battle_hud_update_collapse update_collapse
   def update_collapse
       return if face_can_cancel_method?
       mog_battle_hud_update_collapse
   end  
   
  #--------------------------------------------------------------------------
  # ● Update Instant Collapse
  #--------------------------------------------------------------------------                             
   alias mog_battle_hud_update_instant_collapse update_instant_collapse
   def update_instant_collapse
       return if face_can_cancel_method?
       mog_battle_hud_update_instant_collapse
   end  
  
  #--------------------------------------------------------------------------
  # ● Init Visibility
  #--------------------------------------------------------------------------                                
  alias mog_battle_face_init_visibility init_visibility
  def init_visibility
      return if face_can_cancel_method?
      mog_battle_face_init_visibility
  end
   
  #--------------------------------------------------------------------------
  # ● Face Can Cancel Method
  #--------------------------------------------------------------------------                                 
  def face_can_cancel_method?
      return false if !SceneManager.face_battler?
      return false if @battler.is_a?(Game_Enemy)
      self.opacity = 255 ; self.visible = true
      return true
  end  
   
  #--------------------------------------------------------------------------
  # ● Update Position
  #--------------------------------------------------------------------------                                 
  alias mog_battle_hud_ex_update_position update_position
  def update_position
      if !face_sprite_visible?
         self.y = -480
         return
      end   
      mog_battle_hud_ex_update_position
  end  
   
  #--------------------------------------------------------------------------
  # * Sprite Visible
  #--------------------------------------------------------------------------
  def face_sprite_visible?
      return false if $game_message.visible and MESSAGE_WINDOW_FADE_HUD
      return false if !$game_temp.battle_hud_visible
      return true
  end  
  
end

end

#==============================================================================
# ** Window_BattleStatus
#==============================================================================
class Window_BattleStatus < Window_Selectable
include MOG_BATTLE_HUD_EX

  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
      ACTOR_WINDOW_SIZE[0]
  end

#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------   
alias mog_monogatari_refresh refresh
def refresh
     mog_monogatari_refresh
     self.visible = false     
end  

end  

#==============================================================================
# ** Window Actor Command
#==============================================================================
class Window_ActorCommand < Window_Command
  
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------   
  alias mog_hud_battle_hud_ex_turn_sprite_update update
  def update
      mog_hud_battle_hud_ex_turn_sprite_update
      $game_temp.command_visible = self.visible
  end

end

if MOG_BATTLE_HUD_EX::ENABLE_CUSTOM_WINDOWS
  
#==============================================================================
# ** Window BattleLog
#==============================================================================
class Window_BattleLog < Window_Selectable
  
  include MOG_BATTLE_HUD_EX
  
#--------------------------------------------------------------------------
# * Initialize
#--------------------------------------------------------------------------   
  alias mog_battle_hud_ex_log_initialize initialize
  def initialize
      mog_battle_hud_ex_log_initialize
      self.x = BATTLE_LOG_POSITION[0]
      self.y = BATTLE_LOG_POSITION[1]
  end
  
#--------------------------------------------------------------------------
# * Create Back Sprite
#--------------------------------------------------------------------------   
  alias mog_battle_hud_ex_log_create_back_sprite create_back_sprite
  def create_back_sprite
      self.x = BATTLE_LOG_POSITION[0]
      self.y = BATTLE_LOG_POSITION[1]   
      mog_battle_hud_ex_log_create_back_sprite
  end
  
end  

#==============================================================================
# ** Window Actor Command
#==============================================================================
class Window_ActorCommand < Window_Command
  
  include MOG_BATTLE_HUD_EX
  
#--------------------------------------------------------------------------
# * Initialize
#--------------------------------------------------------------------------   
alias mog_monogatari_initialize initialize
def initialize
     mog_monogatari_initialize
     create_layout
end
  
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
alias mog_monogatari_actor_command_dispose dispose
def dispose
     mog_monogatari_actor_command_dispose
     dispose_layout
end

#--------------------------------------------------------------------------
# * Create Layout
#--------------------------------------------------------------------------   
def create_layout
     return if @layout != nil
     return if !ACTOR_COMMAND_LAYOUT
     return if $game_temp.mbhud_window[0]
     self.z = MOG_BATTLE_HUD_EX::HUD_Z + 150
     $game_temp.mbhud_window[0] = true
     @layout = Sprite.new
     @layout.bitmap = Cache.battle_hud("Layout_Command")
     @layout.z = self.z - 1
     @layout.x = self.x + ACTOR_COMMAND_LAYOUT_POSITION[0]
     @layout.y = self.y + ACTOR_COMMAND_LAYOUT_POSITION[1]
     @layout.visible = false
end

#--------------------------------------------------------------------------
# * Dispose Layout
#--------------------------------------------------------------------------
def dispose_layout
     return if @layout == nil
     @layout.dispose
     @layout = nil
end

#--------------------------------------------------------------------------
# * Refresh Layout
#--------------------------------------------------------------------------
def refresh_layout
     return if @layout == nil
     @layout.x = self.x + ACTOR_COMMAND_LAYOUT_POSITION[0]
     @layout.y = self.y + ACTOR_COMMAND_LAYOUT_POSITION[1]
     @layout.visible = self.active
     @layout.z = self.z - 1
end

#--------------------------------------------------------------------------
# * Select
#--------------------------------------------------------------------------  
alias mog_monogatari_select_actor_command select
def select(index)
     mog_monogatari_select_actor_command(index)
     set_command_position
end   
  
#--------------------------------------------------------------------------
# * Set Command Position
#--------------------------------------------------------------------------   
def set_command_position
     self.viewport = nil
     self.opacity = ACTOR_COMMAND_OPACITY
     battler_index = BattleManager.current_index rescue nil
     battler_index = 0 if battler_index == nil
     if @actor != nil and $game_temp.hud_pos[battler_index] != nil
        if FIXED_COMMAND_POSITION[battler_index] != nil
           self.x = FIXED_COMMAND_POSITION[battler_index][0]
           self.y = FIXED_COMMAND_POSITION[battler_index][1]              
        else  
           self.x = ACTOR_COMMAND_POSITION[0] + $game_temp.hud_pos[battler_index][0] - (self.width / 2)
           self.x = Graphics.width - self.width if self.x + self.width > Graphics.width
           self.x = 0 if self.x < 0
           self.y = ACTOR_COMMAND_POSITION[1] + $game_temp.hud_pos[battler_index][1] - self.height
        end   
     end      
     refresh_layout
end  

#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------   
alias mog_battle_hud_ex_refresh refresh
def refresh
     mog_battle_hud_ex_refresh
     $game_temp.refresh_turn_sprite = true
end

#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------  
alias mog_monogatari_actor_commnand_update update
def update     
     mog_monogatari_actor_commnand_update
     self.visible = self.active
     if @layout.visible != nil      
        refresh_layout if @layout.visible != self.visible
     end        
end

end

#==============================================================================
# ** Window_PartyCommand
#==============================================================================
class Window_PartyCommand < Window_Command

  include MOG_BATTLE_HUD_EX
  
#--------------------------------------------------------------------------
# * Initialize
#--------------------------------------------------------------------------   
  alias mog_monogatari_party_initialize initialize
  def initialize
      mog_monogatari_party_initialize
      create_layout
  end
  
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
alias mog_monogatari_party_window_dispose dispose
def dispose
     mog_monogatari_party_window_dispose
     dispose_layout
end

#--------------------------------------------------------------------------
# * Create Layout
#--------------------------------------------------------------------------   
def create_layout
     return if @layout != nil
     return if !PARTY_COMMAND_LAYOUT
     return if $game_temp.mbhud_window[1]
     self.z = MOG_BATTLE_HUD_EX::HUD_Z + 150
     $game_temp.mbhud_window[1] = true     
     @layout = Sprite.new
     @layout.bitmap = Cache.battle_hud("Layout_Party")
     @layout.z = self.z - 1
     refresh_layout
     @layout.visible = false
end

#--------------------------------------------------------------------------
# * Dispose Layout
#--------------------------------------------------------------------------
def dispose_layout
     return if @layout == nil
     @layout.dispose
     @layout = nil
end

#--------------------------------------------------------------------------
# * Refresh Layout
#--------------------------------------------------------------------------
def refresh_layout
     return if @layout == nil
     @layout.x = self.x + PARTY_COMMAND_LAYOUT_POSITION[0]
     @layout.y = self.y + PARTY_COMMAND_LAYOUT_POSITION[1]
     @layout.visible = self.visible   
end         

#--------------------------------------------------------------------------
# * Select
#--------------------------------------------------------------------------  
alias mog_monogatari_select_partycommand select
def select(index)
     mog_monogatari_select_partycommand(index)
     self.viewport = nil
     self.x = PARTY_COMMAND_POSITION[0] - (self.width / 2)
     self.y = PARTY_COMMAND_POSITION[1] - (self.height / 2)
     self.opacity = PARTY_COMMAND_OPACITY
end   
  
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------  
alias mog_monogatari_party_window_update update
def update
     mog_monogatari_party_window_update  
     self.visible = self.active
     if @layout != nil and @layout.visible != self.visible        
        refresh_layout
     end
end   

end

#==============================================================================
# ** Window_Help
#==============================================================================
class Window_Help < Window_Base
  
  include MOG_BATTLE_HUD_EX
  
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias mog_monogatari_battle_help_initialize initialize
  def initialize(line_number = 2)
      @battle_phase = false
      mog_monogatari_battle_help_initialize(line_number)
      if SceneManager.scene_is?(Scene_Battle)
         @battle_phase = true         
         self.width = HELP_WINDOW_SIZE[0]
         self.height = HELP_WINDOW_SIZE[1]      
         @org_position = [HELP_WINDOW_POSITION[0] - (self.width / 2),
                          HELP_WINDOW_POSITION[1]]         
         self.x = @org_position[0]
         self.y = @org_position[1]  
         self.opacity = HELP_WINDOW_OPACITY
         self.z = MOG_BATTLE_HUD_EX::HUD_Z + 150
         create_layout
      end     
end

#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
alias mog_monogatari_help_window_dispose dispose
def dispose
     mog_monogatari_help_window_dispose
     dispose_layout
end

#--------------------------------------------------------------------------
# * Create Layout
#--------------------------------------------------------------------------   
def create_layout
     return if @layout != nil
     return if !HELP_WINDOW_LAYOUT
     return if $game_temp.mbhud_window[2]
     return if !SceneManager.scene_is?(Scene_Battle)
     $game_temp.mbhud_window[2] = true
     @layout = Sprite.new
     @layout.bitmap = Cache.battle_hud("Layout_Help")
     @layout.z = self.z - 1
     refresh_layout
     @layout.visible = false
end

#--------------------------------------------------------------------------
# * Dispose Layout
#--------------------------------------------------------------------------
def dispose_layout
     return if @layout == nil
     @layout.dispose
     @layout = nil
end

#--------------------------------------------------------------------------
# * Refresh Layout
#--------------------------------------------------------------------------
def refresh_layout
     return if @layout == nil
     @layout.x = self.x + HELP_WINDOW_LAYOUT_POSITION[0]
     @layout.y = self.y + HELP_WINDOW_LAYOUT_POSITION[1]
     @layout.visible = self.visible   
end   
  
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  alias mog_monogatari_battle_help_refresh refresh
  def refresh
      mog_monogatari_battle_help_refresh
      if @battle_phase        
         self.x = @org_position[0]
         self.y = @org_position[1]
         self.opacity = HELP_WINDOW_OPACITY
      end
  end
  
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------  
alias mog_monogatari_help_window_update update
def update
     mog_monogatari_help_window_update
     if @layout != nil           
        refresh_layout if @layout.visible != self.visible
        @layout.visible = self.visible
     end
end   
  
end

#==============================================================================
# ** Window_BattleActor
#==============================================================================
class Window_BattleActor < Window_BattleStatus
  
  include MOG_BATTLE_HUD_EX
  
  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------   
  alias mog_monogatari_battle_actor_initialize initialize
  def initialize(info_viewport)
      @force_hide = can_force_hide?
      mog_monogatari_battle_actor_initialize(info_viewport)
      self.width = ACTOR_WINDOW_SIZE[0]
      self.height = ACTOR_WINDOW_SIZE[1]
      @org_position = [ACTOR_WINDOW_POSITION[0] - (self.width / 2),
                       ACTOR_WINDOW_POSITION[1] - self.height]
      @org_position[1] = Graphics.height + 64 if @force_hide
      self.x = @org_position[0]
      self.y = @org_position[1]
      self.opacity = ACTOR_WINDOW_OPACITY
      self.z = MOG_BATTLE_HUD_EX::HUD_Z + 151
      self.viewport = nil
      create_layout
  end
  
  #--------------------------------------------------------------------------
  # * Can Force Hide?
  #--------------------------------------------------------------------------   
  def can_force_hide?
      return true if $imported[:ve_target_arrow]
      return true if $imported[:mog_battle_cursor]
      return false
  end
  
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
alias mog_monogatari_actor_window_dispose dispose
def dispose
     mog_monogatari_actor_window_dispose
     dispose_layout
end

#--------------------------------------------------------------------------
# * Create Layout
#--------------------------------------------------------------------------   
def create_layout
     return if @layout != nil
     return if !ACTOR_WINDOW_LAYOUT
     return if $game_temp.mbhud_window[3]
     $game_temp.mbhud_window[3] = true     
     @layout = Sprite.new
     @layout.bitmap = Cache.battle_hud("Layout_Target_Actor")
     @layout.z = self.z - 1
     refresh_layout
     @layout.visible = false
end

#--------------------------------------------------------------------------
# * Dispose Layout
#--------------------------------------------------------------------------
def dispose_layout
     return if @layout == nil
     @layout.dispose
     @layout = nil
end

#--------------------------------------------------------------------------
# * Refresh Layout
#--------------------------------------------------------------------------
def refresh_layout
     return if @layout == nil
     @layout.x = self.x + ACTOR_WINDOW_LAYOUT_POSITION[0]
     @layout.y = self.y + ACTOR_WINDOW_LAYOUT_POSITION[1]
     @layout.visible = self.visible
end     
  
  if $imported[:ve_target_arrow]
  #--------------------------------------------------------------------------
  # * New method: show_actor
  #--------------------------------------------------------------------------
  alias mog_battle_hud_ex_show_actor show_actor
  def show_actor
      return true if SceneManager.face_battler?
      mog_battle_hud_ex_show_actor
  end
  end

#--------------------------------------------------------------------------
# * Select
#--------------------------------------------------------------------------  
alias mog_monogatari_select_actor select
def select(index)
     mog_monogatari_select_actor(index)
     self.viewport = nil
     self.visible = true
     self.x = @org_position[0]
     self.y = @org_position[1]   
     self.opacity = ACTOR_WINDOW_OPACITY
end   

#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------  
alias mog_monogatari_actor_window_update update
def update
     mog_monogatari_actor_window_update   
     self.visible = self.active
     self.visible = false if @force_hide
     if @layout != nil        
        refresh_layout if @layout.visible != self.visible
     end
end  

end

#==============================================================================
# ** Window_BattleEnemy
#==============================================================================
class Window_BattleEnemy < Window_Selectable
  
  include MOG_BATTLE_HUD_EX
  
  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------   
  alias mog_monogatari_battle_enemy_initialize initialize
  def initialize(info_viewport)
      @force_hide = can_force_hide?
      mog_monogatari_battle_enemy_initialize(info_viewport)
      self.width = ENEMY_WINDOW_SIZE[0]
      self.height = ENEMY_WINDOW_SIZE[1]      
      @org_position = [ENEMY_WINDOW_POSITION[0] - (self.width / 2),
                       ENEMY_WINDOW_POSITION[1] - self.height]
      @org_position[1] = Graphics.height + 64 if @force_hide               
      self.x = @org_position[0]
      self.y = @org_position[1]      
      self.opacity = ENEMY_WINDOW_OPACITY
      self.z = MOG_BATTLE_HUD_EX::HUD_Z + 151
      create_layout
  end  
  
  #--------------------------------------------------------------------------
  # * Can Force Hide?
  #--------------------------------------------------------------------------   
  def can_force_hide?
      return true if $imported[:ve_target_arrow]
      return true if $imported[:mog_battle_cursor]
      return false
  end   
  
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
alias mog_monogatari_enemy_window_dispose dispose
def dispose
     mog_monogatari_enemy_window_dispose
     dispose_layout
end

#--------------------------------------------------------------------------
# * Create Layout
#--------------------------------------------------------------------------   
def create_layout
     return if @layout != nil
     return if !ENEMY_WINDOW_LAYOUT
     return if $game_temp.mbhud_window[4]
     $game_temp.mbhud_window[4] = true     
     @layout = Sprite.new
     @layout.bitmap = Cache.battle_hud("Layout_Target_Enemy")
     @layout.z = self.z - 1
     refresh_layout
     @layout.visible = false
end

#--------------------------------------------------------------------------
# * Dispose Layout
#--------------------------------------------------------------------------
def dispose_layout
     return if @layout == nil
     @layout.dispose
     @layout = nil
end

#--------------------------------------------------------------------------
# * Refresh Layout
#--------------------------------------------------------------------------
def refresh_layout
     return if @layout == nil
     @layout.x = self.x + ENEMY_WINDOW_LAYOUT_POSITION[0]
     @layout.y = self.y + ENEMY_WINDOW_LAYOUT_POSITION[1]
     @layout.visible = self.visible   
end      
  
#--------------------------------------------------------------------------
# * Select
#--------------------------------------------------------------------------  
alias mog_monogatari_select_enemy select
def select(index)
     mog_monogatari_select_enemy(index)
     self.viewport = nil
     self.visible = true
     self.x = @org_position[0]
     self.y = @org_position[1]   
     self.opacity = ENEMY_WINDOW_OPACITY
  end   

#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------  
alias mog_monogatari_enemy_window_update update
def update
     mog_monogatari_enemy_window_update
     self.visible = false if @force_hide
     if @layout != nil and @layout.visible != self.visible        
        refresh_layout
     end
end   
  
  if $imported["YEA-BattleEngine"]
  #--------------------------------------------------------------------------
  # * Draw Item
  #--------------------------------------------------------------------------
  def draw_item(index)
      change_color(normal_color)
      name = $game_troop.alive_members[index].name
      draw_text(item_rect_for_text(index), name)
  end
  end

end

#==============================================================================
# ** Window_BattleSkill
#==============================================================================
class Window_BattleSkill < Window_SkillList
include MOG_BATTLE_HUD_EX

#--------------------------------------------------------------------------
# * Initialize
#--------------------------------------------------------------------------   
alias mog_monogatari_battle_skill_initialize initialize
def initialize(help_window, info_viewport)
     @force_hide = can_force_hide?
     @force_hide_active = can_force_hide_active?     
     mog_monogatari_battle_skill_initialize(help_window, info_viewport)
     self.width = SKILL_WINDOW_SIZE[0]
     self.height = SKILL_WINDOW_SIZE[1]   
     @org_position = [SKILL_WINDOW_POSITION[0],
          Graphics.height - self.height + SKILL_WINDOW_POSITION[1]]
     self.x = @org_position[0]
     self.y = @org_position[1]
     self.opacity = SKILL_WINDOW_OPACITY
     self.viewport = nil
     self.z = MOG_BATTLE_HUD_EX::HUD_Z + 150
     create_layout
end
  
#--------------------------------------------------------------------------
# * Can Force Hide Active?
#--------------------------------------------------------------------------   
def can_force_hide_active?
     return true if $imported[:ve_target_arrow]
     return true if $imported[:mog_battle_cursor] != nil
     return false
end   

  #--------------------------------------------------------------------------
  # * Can Force Hide?
  #--------------------------------------------------------------------------   
  def can_force_hide?
      return false
  end

#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
alias mog_monogatari_skill_window_dispose dispose
def dispose
     mog_monogatari_skill_window_dispose
     dispose_layout
end

#--------------------------------------------------------------------------
# * Create Layout
#--------------------------------------------------------------------------   
def create_layout
     return if @layout != nil
     return if !SKILL_WINDOW_LAYOUT
     return if $game_temp.mbhud_window[5]
     $game_temp.mbhud_window[5] = true     
     @layout = Sprite.new
     @layout.bitmap = Cache.battle_hud("Layout_Skill")
     @layout.z = self.z - 1
     refresh_layout
     @layout.visible = false
end

#--------------------------------------------------------------------------
# * Dispose Layout
#--------------------------------------------------------------------------
def dispose_layout
     return if @layout == nil
     @layout.dispose
     @layout = nil
end

#--------------------------------------------------------------------------
# * Refresh Layout
#--------------------------------------------------------------------------
def refresh_layout
     return if @layout == nil
     @layout.x = self.x + SKILL_WINDOW_LAYOUT_POSITION[0]
     @layout.y = self.y + SKILL_WINDOW_LAYOUT_POSITION[1]
     @layout.visible = self.visible   
end

#--------------------------------------------------------------------------
# * Select
#--------------------------------------------------------------------------  
alias mog_monogatari_select_battle_skill select
def select(index)
     mog_monogatari_select_battle_skill(index)
     self.x = @org_position[0]
     self.y = @org_position[1]
     self.opacity = SKILL_WINDOW_OPACITY
end   
  
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------  
alias mog_monogatari_skill_window_update update
def update
     mog_monogatari_skill_window_update
     self.visible = self.active if @force_hide_active
     self.visible = false if @force_hide
     if @layout != nil and @layout.visible != self.visible        
        refresh_layout
     end
end
  
end

#==============================================================================
# ** Window_BattleItem
#==============================================================================
class Window_BattleItem < Window_ItemList
  include MOG_BATTLE_HUD_EX

#--------------------------------------------------------------------------
# * Initialize
#--------------------------------------------------------------------------  
alias mog_monogatari_battle_item_initialize initialize
def initialize(help_window, info_viewport)
     @force_hide = can_force_hide?
     @force_hide_active = can_force_hide_active?
     mog_monogatari_battle_item_initialize(help_window, info_viewport)
     self.width = ITEM_WINDOW_SIZE[0]
     self.height = ITEM_WINDOW_SIZE[1]
     @org_position = [ITEM_WINDOW_POSITION[0],
          Graphics.height - self.height + ITEM_WINDOW_POSITION[1]]
     self.x = @org_position[0]
     self.y = @org_position[1]
     self.viewport = nil
     self.opacity = ITEM_WINDOW_OPACITY
     self.z = MOG_BATTLE_HUD_EX::HUD_Z + 150
     create_layout
end  

#--------------------------------------------------------------------------
# * Can Force Hide Active?
#--------------------------------------------------------------------------   
def can_force_hide_active?
     return true if $imported[:ve_target_arrow]
     return true if $imported[:mog_battle_cursor] != nil
     return false
end  

#--------------------------------------------------------------------------
# * Can Force Hide?
#--------------------------------------------------------------------------   
def can_force_hide?
     return false
end

#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
alias mog_monogatari_item_window_dispose dispose
def dispose
     mog_monogatari_item_window_dispose
     dispose_layout
end

#--------------------------------------------------------------------------
# * Create Layout
#--------------------------------------------------------------------------   
def create_layout
     return if @layout != nil
     return if !ITEM_WINDOW_LAYOUT
     return if $game_temp.mbhud_window[6]
     $game_temp.mbhud_window[6] = true     
     @layout = Sprite.new
     @layout.bitmap = Cache.battle_hud("Layout_Item")
     @layout.z = self.z - 1
     refresh_layout
     @layout.visible = false
end

#--------------------------------------------------------------------------
# * Dispose Layout
#--------------------------------------------------------------------------
def dispose_layout
     return if @layout == nil
     @layout.dispose
     @layout = nil
end

#--------------------------------------------------------------------------
# * Refresh Layout
#--------------------------------------------------------------------------
def refresh_layout
     return if @layout == nil
     @layout.x = self.x + ITEM_WINDOW_LAYOUT_POSITION[0]
     @layout.y = self.y + ITEM_WINDOW_LAYOUT_POSITION[1]
     @layout.visible = self.visible
end  

#--------------------------------------------------------------------------
# * Select
#--------------------------------------------------------------------------  
alias mog_monogatari_select_battle_item select
def select(index)
     mog_monogatari_select_battle_item(index)
     self.x = @org_position[0]
     self.y = @org_position[1]
     self.opacity = ITEM_WINDOW_OPACITY
end     
  
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------  
alias mog_monogatari_item_window_update update
def update
     mog_monogatari_item_window_update
     self.visible = self.active if @force_hide_active
     self.visible = false if @force_hide
     if @layout != nil
        refresh_layout if @layout.visible != self.visible
     end
end  

end

end


#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
#################################
if $imported["YEA-BattleEngine"]
#################################

#==============================================================================
# ** Window_BattleStatusAid
#==============================================================================
class Window_BattleStatusAid < Window_BattleStatus
  
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------   
  def refresh
      contents.clear
      self.visible = false
  end
   
end

#==============================================================================
# ** Window_BattleStatus
#==============================================================================
class Window_BattleStatus < Window_Selectable

#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
alias mog_monogatari_bhud_yf_update update
def update
     mog_monogatari_bhud_yf_update
     update_visible_yf
end

#--------------------------------------------------------------------------
# * Update Visible Yf
#--------------------------------------------------------------------------
def update_visible_yf
     self.visible = self.active
end

end  

#==============================================================================
# ■ Window ActorCommand
#==============================================================================
class Window_ActorCommand < Window_Command
  
#--------------------------------------------------------------------------
# * Show
#--------------------------------------------------------------------------
  alias mog_bhud_yf_command_show show
  def show
      return if !BattleManager.can_enable_window?
      mog_bhud_yf_command_show
  end
  
#--------------------------------------------------------------------------
# * Update
#--------------------------------------------------------------------------
alias mog_monogatari_bhud_yf_actorcommand_update update
def update
     mog_monogatari_bhud_yf_actorcommand_update
     update_visible_yf
end

#--------------------------------------------------------------------------
# * Update Visible Yf
#--------------------------------------------------------------------------
def update_visible_yf
     self.visible = self.active     
end

end

#==============================================================================
# ** Scene Battle
#==============================================================================
class Scene_Battle < Scene_Base
  
  include MOG_BATTLE_HUD_EX
  
  #--------------------------------------------------------------------------
  # alias method: create_skill_window
  #--------------------------------------------------------------------------
  alias mog_yf_scene_battle_create_skill_window create_skill_window
  def create_skill_window
      mog_yf_scene_battle_create_skill_window
      @skill_window.width = SKILL_WINDOW_SIZE[0]
      @skill_window.height = SKILL_WINDOW_SIZE[1]
      @skill_window.x = SKILL_WINDOW_POSITION[0]
      @skill_window.y = SKILL_WINDOW_POSITION[1]
  end
  
  #--------------------------------------------------------------------------
  # alias method: create_item_window
  #--------------------------------------------------------------------------
  alias mog_yf_scene_battle_create_item_window create_item_window
  def create_item_window
      mog_yf_scene_battle_create_item_window
      @item_window.width = ITEM_WINDOW_SIZE[0]
      @item_window.height = ITEM_WINDOW_SIZE[1]
      @item_window.x = ITEM_WINDOW_POSITION[0]
      @item_window.y = ITEM_WINDOW_POSITION[1]
  end  
  
#--------------------------------------------------------------------------
# * Next Command
#--------------------------------------------------------------------------
  def next_command
    if BattleManager.next_command
       @status_window.show
       redraw_current_status
       @actor_command_window.show
       @status_aid_window.hide      
       start_actor_command_selection
    else
      turn_start
    end
  end

#--------------------------------------------------------------------------
# ● Update Battle Hud_ex
#--------------------------------------------------------------------------
  alias mog_monogatari_yf_sb_update_battle_hud_ex update_battle_hud_ex
  def update_battle_hud_ex
      update_yf_visible
      mog_monogatari_yf_sb_update_battle_hud_ex         
  end
  
#--------------------------------------------------------------------------
# ● Update Yf Visible
#--------------------------------------------------------------------------
def update_yf_visible
     return if @force_clear_duration > 0
     @actor_window.visible = stw_can_visible?
     @status_window.visible = @actor_window.visible
     @status_window.opacity = @actor_window.opacity      
end  

#--------------------------------------------------------------------------
# * STW Can Visible
#--------------------------------------------------------------------------   
  def stw_can_visible?
      return false if !BattleManager.can_enable_window?
      return false if @item_window.visible
      return false if @skill_window.visible
      return true if @actor_window.active
      return false
  end

if $imported["YEA-CommandEquip"]
#--------------------------------------------------------------------------
# * Command Equip
#--------------------------------------------------------------------------   
  alias mog_yf_command_equip command_equip
  def command_equip
      @actor_command_window.visible = false
      @actor_command_window.update
      $game_temp.battle_hud_visible_refresh = [true,false]
      @spriteset.update_battle_hud_ex
      @spriteset.battler_sprites.each do |s| s.dispose_animation end
      mog_yf_command_equip
      $game_temp.battle_hud_visible_refresh = [true,true]
  end
  end
  
end

end
#--------------------------------------------------------------------------


######################################
if $imported["YEA-EnemyTargetInfo"]
######################################

#==============================================================================
# ■ Window_Comparison
#==============================================================================
class Window_Comparison < Window_Base
  
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------     
  alias mog_battle_hud_ex_yf_refresh refresh
  def refresh
      mog_battle_hud_ex_yf_refresh
      self.z = MOG_BATTLE_HUD_EX::HUD_Z + 152
      self.viewport = nil
  end
  
end

#==============================================================================
# ■ Window_ComparisonHelp
#==============================================================================
class Window_ComparisonHelp < Window_Base
  
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------     
  alias mog_battle_hud_ex_yf_refresh refresh
  def refresh
      mog_battle_hud_ex_yf_refresh
      self.z = MOG_BATTLE_HUD_EX::HUD_Z + 152
      self.viewport = nil
  end
  
end
end
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------


#################################
if $imported["YEA-EnemyTargetInfo"]
#################################
class Window_Comparison < Window_Base
  
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  alias mog_battle_hud_yf_wcomparison_initialize initialize
  def initialize(type)
      mog_battle_hud_yf_wcomparison_initialize(type)
      self.z = 102
  end  
  
end
end
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------

#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
#################################
if $imported["YSA-CATB"]
#################################

#==============================================================================
# ■ Enemy CATB Gauge Viewport
#==============================================================================
class Enemy_CATB_Gauge_Viewport < Viewport
  
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  alias mog_battle_hud_ex_yami_initialize initialize
  def initialize(battler, sprite, type)
      mog_battle_hud_ex_yami_initialize(battler, sprite, type)
      self.z = 90
  end

end
  
#==============================================================================
# ■ Game_Battler
#==============================================================================
class Game_Battler < Game_BattlerBase
  
  attr_accessor :catb_value  
  attr_accessor :max_atb
  
  #--------------------------------------------------------------------------
  # * Max ATB
  #--------------------------------------------------------------------------   
  def max_atb
      return MAX_CATB_VALUE
      return 1
  end
  
end

end
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------


#==============================================================================
# ** Spriteset_Battle
#==============================================================================
class Spriteset_Battle

  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------
  alias mog_battle_hud_ex_initialize initialize
  def initialize
      check_screen_xyz_nil rescue nil
      mog_battle_hud_ex_initialize
      create_battle_hud_ex
  end
  
  #--------------------------------------------------------------------------
  # * Check Screen Xyz
  #--------------------------------------------------------------------------   
  def check_screen_xyz_nil
      return if !SceneManager.face_battler?
      for actor in $game_party.battle_members
          actor.screen_x = 0 if actor.screen_x == nil
          actor.screen_y = 0 if actor.screen_y == nil
          actor.screen_z = 0 if actor.screen_z == nil
      end
  end
  
  #--------------------------------------------------------------------------
  # * Check Screen Xyz after
  #--------------------------------------------------------------------------     
  def check_screen_xyz_after
      return if !SceneManager.face_battler?
      $game_party.battle_members.each_with_index do |actor, index|
          actor.screen_x = $game_temp.battler_face_pos[index][0] rescue nil
          actor.screen_y = $game_temp.battler_face_pos[index][1] rescue nil
          actor.screen_z = $game_temp.battler_face_pos[index][2] rescue nil
      end   
  end
  
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------  
  alias mog_battle_hud_ex_dispose dispose
  def dispose
      dispose_battle_hud_ex
      mog_battle_hud_ex_dispose
  end
  
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------  
  alias mog_battle_hud_ex_update update
  def update
      mog_battle_hud_ex_update
      update_battle_hud_ex
  end
  
  #--------------------------------------------------------------------------
  # * Create Battle Hud EX
  #--------------------------------------------------------------------------   
  def create_battle_hud_ex
      return if @battle_hud_ex != nil
      $game_temp.battle_hud_visible = true
      @battle_hud_ex = Monogatari_Bhud.new(nil)
      check_screen_xyz_after
  end
  
  #--------------------------------------------------------------------------
  # * Dispose Battle Hud EX
  #--------------------------------------------------------------------------   
  def dispose_battle_hud_ex
      return if @battle_hud_ex == nil
      @battle_hud_ex.dispose
      @battle_hud_ex = nil
      $game_temp.mbhud_window = [false,false,false,false,false,false,false]
  end
  
  #--------------------------------------------------------------------------
  # * Update Battle Hud EX
  #--------------------------------------------------------------------------   
  def update_battle_hud_ex
      refresh_battle_hud if $game_temp.mbhud_force_refresh
      return if @battle_hud_ex == nil
      @battle_hud_ex.update
  end
  
  #--------------------------------------------------------------------------
  # * Refresh Battle Hud
  #--------------------------------------------------------------------------   
  def refresh_battle_hud
      $game_temp.mbhud_force_refresh = false
      check_screen_xyz_nil rescue nil
      dispose_battle_hud_ex
      create_battle_hud_ex
  end
  
end

#==============================================================================
# ** Monogatari Bhud
#==============================================================================
class Monogatari_Bhud
  
  include MOG_BATTLE_HUD_EX
  
  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------  
  def initialize(viewport)
      @pre_message_position = $game_message.position
      $game_message.position = MOG_BATTLE_HUD_EX::BATTLE_MESSAGE_POSITION
      @battle_hud = []
      $game_party.battle_members.each_with_index do |actor, index|
      @battle_hud.push(Battle_Hud_EX.new(actor,index,max_members,nil)) end
      create_turn_sprite(nil)
  end
  
  #--------------------------------------------------------------------------
  # * Max members
  #--------------------------------------------------------------------------   
  def max_members
      if $game_party.members.size > $game_party.max_battle_members
         return $game_party.max_battle_members
      end   
      return $game_party.members.size
  end
  
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------   
  def dispose
      @battle_hud.each {|sprite| sprite.dispose }
      dispose_turn_sprite
      $game_message.position = @pre_message_position
  end
  
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------   
  def update
      @battle_hud.each {|sprite| sprite.update }
      update_turn_sprite
      refresh_battle_hud_visible if $game_temp.battle_hud_visible_refresh[0]
  end
  
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------   
  def refresh_battle_hud_visible
      $game_temp.battle_hud_visible_refresh[0] = false
      @turn_sprite.visible = $game_temp.battle_hud_visible_refresh[1]
      @battle_hud.each {|sprite| sprite.refresh_visible($game_temp.battle_hud_visible_refresh[1]) }
  end
  
end

#==============================================================================
# ** Monogatari Bhud
#==============================================================================
class Monogatari_Bhud
  
#--------------------------------------------------------------------------
# * Can Update Turn Sprite
#--------------------------------------------------------------------------
  def can_refresh_turn_sprite?
      return true if @turn_sprite.visible != $game_temp.command_visible
      return true if $game_temp.refresh_turn_sprite
      return false
  end
  
#--------------------------------------------------------------------------
# * Create Turn Sprite
#--------------------------------------------------------------------------
  def create_turn_sprite(viewport)
      return if !TURN_SPRITE_VISIBLE
      return if @turn_sprite != nil
      @turn_sprite = Sprite.new
      @turn_sprite.bitmap = Cache.battle_hud("Turn")
      @turn_sprite.viewport = viewport
      @turn_sprite.z = HUD_Z + TURN_SPRITE_Z
      @turn_sprite.visible = false
      @turn_sprite_update_time = 5
      @turn_sprite_blink = [0,0]
  end
  
#--------------------------------------------------------------------------
# * Dispose Turn Sprite
#--------------------------------------------------------------------------
  def dispose_turn_sprite
      return if @turn_sprite == nil
      @turn_sprite.dispose
      @turn_sprite = nil
  end
  
#--------------------------------------------------------------------------
# * Update Turn Sprite
#--------------------------------------------------------------------------
  def update_turn_sprite
      return if @turn_sprite == nil
      if @turn_sprite_update_time > 0
         @turn_sprite_update_time -= 1
         return
      end  
      update_turn_visible if can_refresh_turn_sprite?
      update_turn_blink
  end
  
#--------------------------------------------------------------------------
# * Update Turn Visible
#--------------------------------------------------------------------------   
  def update_turn_visible
      $game_temp.refresh_turn_sprite = false
      @turn_sprite.visible = $game_temp.command_visible
      battler_index = BattleManager.current_index rescue nil
      battler_index = 0 if battler_index == nil
      x = $game_temp.hud_pos_real[battler_index][0] + TURN_SPRITE_POSITION[0]
      y = $game_temp.hud_pos_real[battler_index][1] + TURN_SPRITE_POSITION[1]
      @turn_sprite.x = x
      @turn_sprite.y = y  
end
  
#--------------------------------------------------------------------------
# * Update Turn Blink
#--------------------------------------------------------------------------   
def update_turn_blink
     return if !TURN_BLINK_EFFECT
     return if !@turn_sprite.visible
     @turn_sprite_blink[0] += 1
     case @turn_sprite_blink[0]
       when 0..30
          @turn_sprite_blink[1] += 3
       when 31..60
          @turn_sprite_blink[1] -= 3
       else
         @turn_sprite_blink = [0,0]
     end
     @turn_sprite.opacity = 150 + @turn_sprite_blink[1]
end

  
end

#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
  include MOG_BATTLE_HUD_EX
  
  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------  
  def initialize(actor = nil,index = 0, max_members = 0,viewport = nil)
      pre_cache
      setup(actor,index,max_members)
      create_sprites(viewport)
  end
  
  #--------------------------------------------------------------------------
  # * Setup
  #--------------------------------------------------------------------------   
  def setup(actor,index,max_members)
      @actor = actor
      @actor_index = index
      @max_members = max_members
      @actor.face_animation = [0,0,0]
      @hp_icon_max = -1
      @hp_icon_old = -1
      @hp_icon_col_max = HP_ICON_COL_MAX
      @hp_icon_col_max = 1 if @hp_icon_col_max <= 0
      @hp_icon_row_max = HP_ICON_ROW_MAX
      @hp_icon_row_max = 1 if @hp_icon_row_max <= 0
      @hp_icon_real_max = @hp_icon_col_max * @hp_icon_row_max
      @mp_icon_max = -1
      @mp_icon_old = -1
      @mp_icon_col_max = MP_ICON_COL_MAX
      @mp_icon_col_max = 1 if @mp_icon_col_max <= 0
      @mp_icon_row_max = MP_ICON_ROW_MAX
      @mp_icon_row_max = 1 if @mp_icon_row_max <= 0
      @mp_icon_real_max = @mp_icon_col_max * @mp_icon_row_max
      @tp_icon_max = -1
      @tp_icon_old = -1
      @tp_icon_col_max = TP_ICON_COL_MAX
      @tp_icon_col_max = 1 if @tp_icon_col_max <= 0
      @tp_icon_row_max = TP_ICON_ROW_MAX
      @tp_icon_row_max = 1 if @tp_icon_row_max <= 0
      @tp_icon_real_max = @tp_icon_col_max * @tp_icon_row_max
      @sprite_visible = true
      @sprite_visitle_wait = 0
      setup_actor
      setup_position
  end
     
  #--------------------------------------------------------------------------
  # * Setup Actor
  #--------------------------------------------------------------------------   
  def setup_actor
      return if @actor == nil
      @hp_number_refresh = true
      @hp_number2_refresh = true
      @hp_number_old = @actor.hp
      @hp_number2_old = @actor.mhp
      @hp_old_meter = 0      
      @mp_number_refresh = true
      @mp_number2_refresh = true
      @mp_number_old = @actor.mp
      @mp_number2_old = @actor.mmp
      @mp_old_meter = 0      
      @tp_number_refresh = true
      @tp_number2_refresh = true
      @tp_number_old = @actor.tp
      @tp_number2_old = @actor.max_tp  
      @tp_old_meter = 0
      @at_number_refresh = true
      @at_number2_refresh = true
      @at_number_old = actor_at
      @at_number2_old = actor_max_at
      @at_old_meter = 0
      catb = ATB::MAX_AP rescue nil
      @ccwinter_atb = true if catb != nil
  end  
  
  #--------------------------------------------------------------------------
  # * Terminate
  #--------------------------------------------------------------------------   
  def terminate
      @actor.atb = 0 rescue nil if $imported[:ve_active_time_battle]
  end
  
  #--------------------------------------------------------------------------
  # * AT
  #--------------------------------------------------------------------------  
  def actor_at
      return @actor.at if $imported[:mog_atb_system]
      return @actor.atb if $imported[:ve_active_time_battle]
      return @actor.catb_value if $imported["YSA-CATB"]
      return @actor.ap if @ccwinter_atb != nil
      return 0
  end
  
  #--------------------------------------------------------------------------
  # * Max AT
  #--------------------------------------------------------------------------  
  def actor_max_at
      return $game_system.at_max if $imported[:mog_atb_system]
      return @actor.max_atb if $imported[:ve_active_time_battle]
      return @actor.max_atb if $imported["YSA-CATB"]
      return ATB::MAX_AP if @ccwinter_atb != nil
      return 1
  end
  
  #--------------------------------------------------------------------------
  # ● Actor Cast
  #--------------------------------------------------------------------------            
  def actor_cast
      return @actor.at_cast[1] if $imported[:mog_atb_system]
      return @actor.atb if $imported[:ve_active_time_battle]
      return @actor.chant_count rescue 0 if @ccwinter_atb != nil
      return 0
  end
  
  #--------------------------------------------------------------------------
  # ● Actor Max Cast
  #--------------------------------------------------------------------------            
  def actor_max_cast
      return @actor.at_cast[0].speed.abs if $imported[:mog_atb_system]
      return @actor.max_atb if $imported[:ve_active_time_battle]
      return @actor.max_chant_count rescue 1 if @ccwinter_atb != nil
      return 1
  end
  
  #--------------------------------------------------------------------------
  # ● Actor Cast?
  #--------------------------------------------------------------------------            
  def actor_cast?   
      if $imported[:mog_atb_system]
         return true if [email protected]_cast.empty?
      end   
      if $imported[:ve_active_time_battle]
         return true if @actor.cast_action?
      end      
      if @ccwinter_atb
         return true if @actor.chanting?
      end
      return false
  end  
  
  #--------------------------------------------------------------------------
  # * Create Sprites
  #--------------------------------------------------------------------------   
  def create_sprites(viewport)
      dispose
      return if @actor == nil
      create_layout(viewport)
      create_layout_2(viewport)
      create_name(viewport)
      create_face(viewport)
      create_hp_number(viewport)
      create_hp_number_max(viewport)
      create_hp_meter(viewport)
      create_hp_icon(viewport)
      create_hp_icon_ex(viewport)
      create_hp_icon_number(viewport)
      create_mp_number(viewport)
      create_mp_number_max(viewport)
      create_mp_meter(viewport)
      create_mp_icon(viewport)
      create_mp_icon_ex(viewport)
      create_mp_icon_number(viewport)
      create_tp_number(viewport)
      create_tp_number_max(viewport)
      create_tp_meter(viewport)
      create_tp_icon(viewport)
      create_tp_icon_ex(viewport)
      create_tp_icon_number(viewport)
      create_at_number(viewport)
      create_at_number_max(viewport)
      create_at_meter(viewport)      
      create_level_number(viewport)
      create_states(viewport)
      update
  end   
  
  #--------------------------------------------------------------------------
  # * Sprite Visible
  #--------------------------------------------------------------------------
  def sprite_visible?
      return false if $game_message.visible and MESSAGE_WINDOW_FADE_HUD
      return false if !$game_temp.battle_hud_visible
      return true
  end
  
  #--------------------------------------------------------------------------
  # * Sprite Visible
  #--------------------------------------------------------------------------
  def sprite_visible(sprite)
      if @sprite_visible         
         sprite.opacity += 5 unless @sprite_visitle_wait > 0
      else
         sprite.opacity -= 10 ; @sprite_visitle_wait = 5
      end
  end
  
end

#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
  
  #--------------------------------------------------------------------------
  # * Setup Position
  #--------------------------------------------------------------------------
  def setup_position      
      sprite_width = (Graphics.width - 64) / 4
      sprite_center = sprite_width / 2  
      if $game_party.battle_members.size > 4
         members = $game_party.battle_members.size - 4
         fx = 32 * members
       else
         fx = 0
      end   
      space_x = MEMBERS_SPACE[0] - fx
      space_y = MEMBERS_SPACE[1]      
      center = Graphics.width / 2
      members_space = (Graphics.width + space_x) / @max_members
      members_space2 = (members_space * @actor_index)      
      members_space3 = ((members_space / 2) * (@max_members - 1))
      members_space_y = space_y * @actor_index
      x = HUD_POSITION[0] - sprite_center + center + members_space2 - members_space3
      screen_resize_y = 0
      screen_resize_y = (Graphics.height - 416) if Graphics.height > 416
      y = HUD_POSITION[1] + members_space_y + screen_resize_y
      @hud_position = [x,y]
      $game_temp.hud_pos_real[@actor_index] = [] if $game_temp.hud_pos_real[@actor_index] == nil
      $game_temp.hud_pos_real[@actor_index] = [x,y]
      x2 = x + sprite_center
      $game_temp.hud_pos[@actor_index] = [] if $game_temp.hud_pos[@actor_index] == nil
      $game_temp.hud_pos[@actor_index] = [x2,y]
      if FIXED_HUD_POSITION[@actor_index] != nil     
         @hud_position = [FIXED_HUD_POSITION[@actor_index][0],FIXED_HUD_POSITION[@actor_index][1]]
         $game_temp.hud_pos_real[@actor_index] = [@hud_position[0],@hud_position[1]]
         $game_temp.hud_pos[@actor_index] = [] if $game_temp.hud_pos[@actor_index] == nil
         $game_temp.hud_pos[@actor_index] = [Graphics.width / 2,(Graphics.height / 2) + 96]   
      end      
  end

end

#==============================================================================
# ** Game Temp
#==============================================================================
class Game_Temp
  
  attr_accessor :cache_bhud_sprites
  
  #--------------------------------------------------------------------------
  # * Cache Battle Hud
  #--------------------------------------------------------------------------  
  def cache_battle_hud      
      execute_cache_bhud_sprites if @cache_bhud_sprites == nil
  end
  
  #--------------------------------------------------------------------------
  # * Execute Cache Bhud Sprites
  #--------------------------------------------------------------------------  
  def execute_cache_bhud_sprites
   
      @cache_bhud_sprites = []
      windows = ["Layout_Command","Layout_Party","Layout_Help",
      "Layout_Target_Actor","Layout_Target_Enemy","Layout_Skill",
      "Layout_Item"]
      for s in windows
          @cache_bhud_sprites.push(Cache.battle_hud(s)) rescue nil
      end
      sprites = ["Layout","Layout_2",
    "MP_Number","Max_MP_Number","MP_Icon","MP_Icon_EX","MP_Icon_Number",
    "TP_Number","Max_TP_Number","TP_Icon","TP_Icon_EX","TP_Icon_Number",  
    "AT_Number","Max_AT_Number","AT_Icon","AT_Icon_EX","AT_Icon_Number",  
    "LV_Number","Turn","Iconset"
      ]
      for s in sprites
          @cache_bhud_sprites.push(Cache.battle_hud(s)) rescue nil
      end      
  end
  
end

#==============================================================================
# ** Spriteset_Map
#==============================================================================
class Spriteset_Map

  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------
  alias mog_monogatari_bhud_initialize initialize
  def initialize
      $game_temp.cache_battle_hud
      mog_monogatari_bhud_initialize
  end
  
end

#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX

  #--------------------------------------------------------------------------
  # * Pre Cache
  #--------------------------------------------------------------------------
  def pre_cache
      $game_temp.cache_battle_hud
      @force_hide = false
      @force_hide_time = 0
      @fade_hud = false
      @fade_hud_gold = false     
      @fade_hud_equip = false
      @layout_image = Cache.battle_hud("Layout")
      @layout_cw = @layout_image.width
      @layout_ch = @layout_image.height
      @layout2_image = Cache.battle_hud("Layout_2") rescue nil
      @layout2_cw = @layout2_image.width if @layout2_image != nil
      @layout2_ch = @layout2_image.height if @layout2_image != nil
      @layout2_cw = 0 if @layout2_cw == nil
      #------------------------------------------------
      # HP
      #------------------------------------------------
      if HP_NUMBER_VISIBLE
         @hp_number_image = Cache.battle_hud("HP_Number")
         @hp_number_cw = @hp_number_image.width / 10
         if HP_NUMBER_LOW_COLOR
            @hp_number_ch = @hp_number_image.height / 2
         else
            @hp_number_ch = @hp_number_image.height
         end   
         @hp_wave_number = HP_NUMBER_WAVE_ALIGN_EFFECT
         @hp_number_ch += (@hp_number_ch / 2) if @hp_wave_number      
      end
      if HP_NUMBER_MAX_VISIBLE
         @hp_number2_image = Cache.battle_hud("Max_HP_Number")
         @hp_number2_cw = @hp_number2_image.width / 10
         @hp_number2_ch = @hp_number2_image.height
      end
      if HP_METER_VISIBLE
         @hp_meter_image = Cache.battle_hud("HP_Meter")
         if HP_METER_GRADIENT_ANIMATION
            @hp_meter_cw = @hp_meter_image.width / 3
         else   
            @hp_meter_cw = @hp_meter_image.width
         end   
         if HP_METER_REDUCTION_ANIMATION
            @hp_meter_ch = @hp_meter_image.height / 2
         else
            @hp_meter_ch = @hp_meter_image.height
         end  
      end
      if HP_ICON_VISIBLE
         @hp_icon_image = Cache.battle_hud("HP_Icon")
         @hp_icon_cw = @hp_icon_image.width / 2
         @hp_icon_ch = @hp_icon_image.height
      end
      if HP_ICON_EX_VISIBLE
         @hp_icon2_image = Cache.battle_hud("HP_Icon_EX")
         @hp_icon2_cw = @hp_icon2_image.width
         @hp_icon2_ch = @hp_icon2_image.height        
      end      
      if HP_ICON_NUMBER_VISIBLE
         @hp_icon_number_image = Cache.battle_hud("HP_Icon_Number")
         @hp_icon_number_cw = @hp_icon_number_image.width / 10
         @hp_icon_number_ch = @hp_icon_number_image.height        
      end
      #------------------------------------------------
      # MP
      #------------------------------------------------
      if MP_NUMBER_VISIBLE
         @mp_number_image = Cache.battle_hud("MP_Number")
         @mp_number_cw = @mp_number_image.width / 10
         if MP_NUMBER_LOW_COLOR
            @mp_number_ch = @mp_number_image.height / 2
         else
            @mp_number_ch = @mp_number_image.height
        end
        @mp_wave_number = MP_NUMBER_WAVE_ALIGN_EFFECT
        @mp_number_ch += (@mp_number_ch / 2) if @mp_wave_number
      end
      if MP_NUMBER_MAX_VISIBLE
         @mp_number2_image = Cache.battle_hud("Max_MP_Number")
         @mp_number2_cw = @mp_number2_image.width / 10
         @mp_number2_ch = @mp_number2_image.height
      end
      if MP_METER_VISIBLE
         @mp_meter_image = Cache.battle_hud("MP_Meter")
         if MP_METER_GRADIENT_ANIMATION
            @mp_meter_cw = @mp_meter_image.width / 3
         else   
            @mp_meter_cw = @mp_meter_image.width
         end  
         if MP_METER_REDUCTION_ANIMATION
            @mp_meter_ch = @mp_meter_image.height / 2
         else
            @mp_meter_ch = @mp_meter_image.height
         end
      end
      if MP_ICON_VISIBLE
         @mp_icon_image = Cache.battle_hud("MP_Icon")
         @mp_icon_cw = @mp_icon_image.width / 2
         @mp_icon_ch = @mp_icon_image.height
      end
      if MP_ICON_EX_VISIBLE
         @mp_icon2_image = Cache.battle_hud("MP_Icon_EX")
         @mp_icon2_cw = @mp_icon2_image.width
         @mp_icon2_ch = @mp_icon2_image.height        
      end      
      if MP_ICON_NUMBER_VISIBLE
         @mp_icon_number_image = Cache.battle_hud("MP_Icon_Number")
         @mp_icon_number_cw = @mp_icon_number_image.width / 10
         @mp_icon_number_ch = @mp_icon_number_image.height        
      end
      #------------------------------------------------
      # TP
      #------------------------------------------------
      if TP_NUMBER_VISIBLE
         @tp_number_image = Cache.battle_hud("TP_Number")
         @tp_number_cw = @tp_number_image.width / 10
         if TP_NUMBER_LOW_COLOR
            @tp_number_ch = @tp_number_image.height / 2
         else
            @tp_number_ch = @tp_number_image.height
         end  
        @tp_wave_number = TP_NUMBER_WAVE_ALIGN_EFFECT
        @tp_number_ch += (@tp_number_ch / 2) if @tp_wave_number      
      end
      if TP_NUMBER_MAX_VISIBLE
         @tp_number2_image = Cache.battle_hud("Max_TP_Number")
         @tp_number2_cw = @tp_number2_image.width / 10
         @tp_number2_ch = @tp_number2_image.height
      end
      if TP_METER_VISIBLE
         @tp_meter_image = Cache.battle_hud("TP_Meter")
         if TP_METER_GRADIENT_ANIMATION
            @tp_meter_cw = @tp_meter_image.width / 3
         else   
            @tp_meter_cw = @tp_meter_image.width
         end  
         if TP_METER_REDUCTION_ANIMATION
            @tp_meter_ch = @tp_meter_image.height / 2      
         else
            @tp_meter_ch = @tp_meter_image.height
         end   
      end        
      if TP_ICON_VISIBLE
         @tp_icon_image = Cache.battle_hud("TP_Icon")
         @tp_icon_cw = @tp_icon_image.width / 2
         @tp_icon_ch = @tp_icon_image.height
      end  
      if TP_ICON_EX_VISIBLE
         @tp_icon2_image = Cache.battle_hud("TP_Icon_EX")
         @tp_icon2_cw = @tp_icon2_image.width
         @tp_icon2_ch = @tp_icon2_image.height        
      end      
      if TP_ICON_NUMBER_VISIBLE
         @tp_icon_number_image = Cache.battle_hud("TP_Icon_Number")
         @tp_icon_number_cw = @tp_icon_number_image.width / 10
         @tp_icon_number_ch = @tp_icon_number_image.height        
      end
      #------------------------------------------------
      # AT
      #------------------------------------------------
      if AT_NUMBER_VISIBLE
         @at_number_image = Cache.battle_hud("AT_Number")
         @at_number_cw = @at_number_image.width / 10
         @at_number_ch = @at_number_image.height
         @at_wave_number = AT_NUMBER_WAVE_ALIGN_EFFECT
         @at_number_ch += (@at_number_ch / 2) if @at_wave_number      
      end
      if AT_NUMBER_MAX_VISIBLE
         @at_number2_image = Cache.battle_hud("Max_AT_Number")
         @at_number2_cw = @at_number2_image.width / 10
         @at_number2_ch = @at_number2_image.height
      end
      if AT_METER_VISIBLE
         @at_meter_image = Cache.battle_hud("AT_Meter")
         if AT_METER_GRADIENT_ANIMATION
            @at_meter_cw = @at_meter_image.width / 3
         else   
            @at_meter_cw = @at_meter_image.width
         end   
         @at_meter_ch = @at_meter_image.height / 3
      end
      #------------------------------------------------
      # LV
      #------------------------------------------------  
      if LEVEL_NUMBER_VISIBLE
         @lv_number_image = Cache.battle_hud("LV_Number")
         @lv_number_cw = @lv_number_image.width / 10
         @lv_number_ch = @lv_number_image.height
      end      
      #------------------------------------------------
      # ICON
      #------------------------------------------------  
      if STATES_VISIBLE or EQUIPMENT_VISIBLE
         @icon_image = Cache.system("Iconset")
      end         
  end
  
  #--------------------------------------------------------------------------
  # * Check Icon Image
  #--------------------------------------------------------------------------         
  def check_icon_image
      if @icon_image == nil or @icon_image.disposed?
         @icon_image = Cache.system("Iconset")
      end   
  end  
  
end

#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
  
  #--------------------------------------------------------------------------
  # * Update Number
  #--------------------------------------------------------------------------   
  def update_number(type,value)
      actor_value = @actor.hp if type == 0
      actor_value = @actor.mp if type == 1
      actor_value = @actor.tp if type == 2
      actor_value = @actor.mhp if type == 3
      actor_value = @actor.mmp if type == 4
      actor_value = @actor.max_tp if type == 5
      actor_value = actor_at if type == 6
      actor_value = actor_max_at if type == 7
      if value < actor_value
         value += number_refresh_speed(actor_value,value)
         value = actor_value if value >= actor_value
         refresh_sprite_number(type,value)
     elsif value > actor_value
         value -= number_refresh_speed(actor_value,value)
         value = actor_value if value <= actor_value
         refresh_sprite_number(type,value)
     end  
  end
  
  #--------------------------------------------------------------------------
  # * Number Refresh Speed
  #--------------------------------------------------------------------------      
  def number_refresh_speed(actor_value,value)
      n =  1 * (actor_value - value).abs / 10
      return [[n, 99999999].min,1].max   
  end
  
  #--------------------------------------------------------------------------
  # * Update Number Fix
  #--------------------------------------------------------------------------      
  def update_number_fix(type)
      if type == 0
         @hp_number_old =  @actor.hp
         @hp_number_refresh = true
      elsif type == 1
         @mp_number_old =  @actor.mp
         @mp_number_refresh = true
      elsif type == 2
         @tp_number_old =  @actor.tp
         @tp_number_refresh = true  
      elsif type == 3
         @hp_number2_old =  @actor.mhp
         @hp_number2_refresh = true
      elsif type == 4
         @mp_number2_old =  @actor.mmp
         @mp_number2_refresh = true
      elsif type == 5
         @tp_number2_old =  @actor.max_tp
         @tp_number2_refresh = true  
      elsif type == 6
         @at_number_old =  actor_at
         @at_number_refresh = true         
      elsif type == 7
         @at_number2_old = actor_max_at
         @at_number2_refresh = true            
      end   
  end  
  
  #--------------------------------------------------------------------------
  # * Refresh Sprite Number
  #--------------------------------------------------------------------------   
  def refresh_sprite_number(type,value)   
      @hp_number_refresh = true if type == 0
      @hp_number_old = value if type == 0
      @mp_number_refresh = true if type == 1
      @mp_number_old = value if type == 1
      @tp_number_refresh = true if type == 2
      @tp_number_old = value if type == 2
      @hp_number2_refresh = true if type == 3
      @hp_number2_old = value if type == 3
      @mp_number2_refresh = true if type == 4
      @mp_number2_old = value if type == 4
      @tp_number2_refresh = true if type == 5
      @tp_number2_old = value if type == 5
      @at_number_refresh = true if type == 6
      @at_number_old = value if type == 6
      @at_number2_refresh = true if type == 7
      @at_number2_old = value if type == 7
  end  
  
  #--------------------------------------------------------------------------
  # * Refresh Number
  #--------------------------------------------------------------------------   
  def refresh_number(type,value,sprite,image,number_cw,number_ch,wave_number = false)
      sprite.bitmap.clear
      clear_number_refresh(type)
      number_color = low_number_color(type,number_ch)
      if type == 0 and HP_NUMBER_PERCENTAGE
         value_max = @actor.mhp
         value = value.to_f / value_max.to_f * 100
         value = 1 if (value < 0 and @actor.hp > 0) or @actor.hp == 1
      elsif type == 1 and MP_NUMBER_PERCENTAGE
         value_max = @actor.mmp
         value = value.to_f / value_max.to_f * 100
      elsif type == 2 and TP_NUMBER_PERCENTAGE
         value_max = @actor.max_tp
         value = value.to_f / value_max.to_f * 100  
      elsif type == 3 and HP_NUMBER_PERCENTAGE
         value = 100
      elsif type == 4 and MP_NUMBER_PERCENTAGE
         value = 100
      elsif type == 5 and TP_NUMBER_PERCENTAGE
         value = 100
      elsif type == 6 and AT_NUMBER_PERCENTAGE
         value_max = actor_max_at
         value = value.to_f / value_max.to_f * 100
      elsif type == 7 and AT_NUMBER_PERCENTAGE
         value = 100         
      end
      value = 9999999 if value > 9999999
      number_value = value.truncate.abs.to_s.split(//)
      wave_h = 0
      wave_h2 = wave_number ? (number_ch / 3) : 0
      wave_h3 = number_color != 0 ? wave_h2 : 0
      for r in 0..number_value.size - 1         
         number_value_abs = number_value[r].to_i
         wh = wave_h2 * wave_h
         wh2 = wave_h == 0 ? wave_h2 : 0
         nsrc_rect = Rect.new(number_cw * number_value_abs, number_color - wave_h3, number_cw, number_ch - wh2)
         sprite.bitmap.blt(number_cw *  r, wh, image, nsrc_rect)
         wave_h = wave_h == 0 ? 1 : 0
      end
      refresh_number_position(type,number_value.size,number_cw)
  end
  
  #--------------------------------------------------------------------------
  # * Refresh Number
  #--------------------------------------------------------------------------     
  def refresh_number_position(type,number_value,number_cw)
      cx = number_value * number_cw
      if type == 0
         case HP_NUMBER_ALIGN_TYPE
           when 0; @hp_number.x = @hud_position[0] + HP_NUMBER_POSITION[0]
           when 1; @hp_number.x = @hud_position[0] + HP_NUMBER_POSITION[0] - (cx / 2)
           when 2; @hp_number.x = @hud_position[0] + HP_NUMBER_POSITION[0] - cx
         end            
      elsif type == 1
         case MP_NUMBER_ALIGN_TYPE
           when 0; @mp_number.x = @hud_position[0] + MP_NUMBER_POSITION[0]
           when 1; @mp_number.x = @hud_position[0] + MP_NUMBER_POSITION[0] - (cx / 2)
           when 2; @mp_number.x = @hud_position[0] + MP_NUMBER_POSITION[0] - cx
         end     
      elsif type == 2  
         case TP_NUMBER_ALIGN_TYPE
           when 0; @tp_number.x = @hud_position[0] + TP_NUMBER_POSITION[0]
           when 1; @tp_number.x = @hud_position[0] + TP_NUMBER_POSITION[0] - (cx / 2)
           when 2; @tp_number.x = @hud_position[0] + TP_NUMBER_POSITION[0] - cx
         end           
      elsif type == 3   
         case HP_NUMBER_ALIGN_TYPE
           when 0; @hp_number2.x = @hud_position[0] + HP_NUMBER_MAX_POSITION[0]
           when 1; @hp_number2.x = @hud_position[0] + HP_NUMBER_MAX_POSITION[0] - (cx / 2)
           when 2; @hp_number2.x = @hud_position[0] + HP_NUMBER_MAX_POSITION[0] - cx
         end           
      elsif type ==  4
         case MP_NUMBER_ALIGN_TYPE
           when 0; @mp_number2.x = @hud_position[0] + MP_NUMBER_MAX_POSITION[0]
           when 1; @mp_number2.x = @hud_position[0] + MP_NUMBER_MAX_POSITION[0] - (cx / 2)
           when 2; @mp_number2.x = @hud_position[0] + MP_NUMBER_MAX_POSITION[0] - cx
         end         
      elsif type ==  5
         case TP_NUMBER_ALIGN_TYPE
           when 0; @tp_number2.x = @hud_position[0] + TP_NUMBER_MAX_POSITION[0]
           when 1; @tp_number2.x = @hud_position[0] + TP_NUMBER_MAX_POSITION[0] - (cx / 2)
           when 2; @tp_number2.x = @hud_position[0] + TP_NUMBER_MAX_POSITION[0] - cx
         end
      elsif type ==  6     
         case MP_NUMBER_ALIGN_TYPE
           when 0; @at_number.x = @hud_position[0] + AT_NUMBER_POSITION[0]
           when 1; @at_number.x = @hud_position[0] + AT_NUMBER_POSITION[0] - (cx / 2)
           when 2; @at_number.x = @hud_position[0] + AT_NUMBER_POSITION[0] - cx
         end            
      elsif type ==  7     
         case AT_NUMBER_ALIGN_TYPE
           when 0; @at_number2.x = @hud_position[0] + AT_NUMBER_POSITION[0]
           when 1; @at_number2.x = @hud_position[0] + AT_NUMBER_POSITION[0] - (cx / 2)
           when 2; @at_number2.x = @hud_position[0] + AT_NUMBER_POSITION[0] - cx
         end
      end  
  end
  
  #--------------------------------------------------------------------------
  # * Low Number Color
  #--------------------------------------------------------------------------      
  def low_number_color(type,number_ch)
      if type == 0
         if HP_NUMBER_LOW_COLOR
            return @actor.low_hp? ? number_ch : 0
         else
            return 0
         end  
      elsif type == 1
         if MP_NUMBER_LOW_COLOR   
            return @actor.low_mp? ? number_ch : 0
         else
            return 0
         end         
      elsif type == 2
         if TP_NUMBER_LOW_COLOR
            return @actor.low_tp? ? number_ch : 0
         else
            return 0
         end
      else   
         return 0  
      end     
  end
  
  #--------------------------------------------------------------------------
  # * Clear Number Refresh
  #--------------------------------------------------------------------------      
  def clear_number_refresh(type)
      @hp_number_refresh = false if type == 0
      @mp_number_refresh = false if type == 1
      @tp_number_refresh = false if type == 2
      @hp_number2_refresh = false if type == 3
      @mp_number2_refresh = false if type == 4
      @tp_number2_refresh = false if type == 5
      @at_number_refresh = false if type == 6
      @at_number2_refresh = false if type == 7
  end  
  
  #--------------------------------------------------------------------------
  # * Icon Limit
  #--------------------------------------------------------------------------      
  def icon_limit(value,value_max)
      n1 = value / value_max
      n2 = value - (n1 * value_max)
      n2 = value_max if (n2 == 0 and value > 0)
      return n2
  end  
  
end

#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX

  #--------------------------------------------------------------------------
  # * Create Layout
  #--------------------------------------------------------------------------   
  def create_layout(viewport)
      @layout = Sprite.new
      @layout.bitmap = @layout_image
      @layout.z = HUD_Z
      @layout.x = @hud_position[0]
      @layout.y = @hud_position[1]
      @layout.opacity = 0
      @layout.viewport = viewport
  end   
  
  #--------------------------------------------------------------------------
  # * Update Layout
  #--------------------------------------------------------------------------   
  def update_layout
      return if @layout == nil
      sprite_visible(@layout)
  end
  
  #--------------------------------------------------------------------------
  # * Create Layout
  #--------------------------------------------------------------------------   
  def create_layout_2(viewport)
      return if !SECOND_LAYOUT
      @layout2 = Sprite.new
      @layout2.bitmap = @layout2_image
      @layout2.z = HUD_Z + SECOND_LAYOUT_Z
      @layout2.x = @hud_position[0] + SECOND_LAYOUT_POSITION[0]
      @layout2.y = @hud_position[1] + SECOND_LAYOUT_POSITION[1]
      @layout2.opacity = 0
      @layout2.viewport = viewport
  end   
  
  #--------------------------------------------------------------------------
  # * Update Layout
  #--------------------------------------------------------------------------   
  def update_layout_2
      return if @layout2 == nil
      sprite_visible(@layout2)
  end  
  
end

#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
  
  #--------------------------------------------------------------------------
  # * Create Name
  #--------------------------------------------------------------------------      
  def create_name(viewport)
      return if !NAME_VISIBLE
      @name = Sprite.new
      @name.bitmap = Bitmap.new(160,32)
      @name.bitmap.font.name = NAME_FONT_NAME
      @name.bitmap.font.size = NAME_FONT_SIZE
      @name.bitmap.font.bold = NAME_FONT_BOLD
      @name.bitmap.font.italic = NAME_FONT_ITALIC
      @name.bitmap.font.color = NAME_FONT_COLOR
      @name.z = HUD_Z + NAME_Z
      @name.x = @hud_position[0] + NAME_POSITION[0]
      @name.y = @hud_position[1] + NAME_POSITION[1]
      @name.viewport = viewport
      @name.opacity = 0
      refresh_name
  end

  #--------------------------------------------------------------------------
  # * Refresh Name
  #--------------------------------------------------------------------------      
  def refresh_name
      return if @name == nil
      @name.bitmap.clear
      if NAME_FONT_SHADOW
         @name.bitmap.font.color = NAME_FONT_SHADOW_COLOR
         @name.bitmap.draw_text(NAME_FONT_SHADOW_POSITION[0],NAME_FONT_SHADOW_POSITION[1],160,32,@actor.name,NAME_ALIGN_TYPE)
         @name.bitmap.font.color = NAME_FONT_COLOR
      end   
      @name.bitmap.draw_text(0,0,160,32,@actor.name,NAME_ALIGN_TYPE)
  end
  
  #--------------------------------------------------------------------------
  # * Update Name
  #--------------------------------------------------------------------------        
  def update_name
      return if @name == nil
      sprite_visible(@name)
  end
  
end

#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
  
  #--------------------------------------------------------------------------
  # * Create HP Number
  #--------------------------------------------------------------------------  
  def create_hp_number(viewport)
      return if !HP_NUMBER_VISIBLE
      @hp_number = Sprite.new
      @hp_number.bitmap = Bitmap.new(@hp_number_cw * 4,@hp_number_ch)
      @hp_number.z = HUD_Z + HP_NUMBER_Z
      @hp_number.x = @hud_position[0] + HP_NUMBER_POSITION[0]
      @hp_number.y = @hud_position[1] + HP_NUMBER_POSITION[1]
      @hp_number.viewport = viewport
      @hp_number.opacity = 0
  end
  
  #--------------------------------------------------------------------------
  # * Create HP Number Max
  #--------------------------------------------------------------------------  
  def create_hp_number_max(viewport)
      return if !HP_NUMBER_MAX_VISIBLE
      @hp_number2 = Sprite.new
      @hp_number2.bitmap = Bitmap.new(@hp_number2_cw * 4,@hp_number2_ch)
      @hp_number2.z = HUD_Z + HP_NUMBER_Z
      @hp_number2.x = @hud_position[0] + HP_NUMBER_MAX_POSITION[0]
      @hp_number2.y = @hud_position[1] + HP_NUMBER_MAX_POSITION[1]
      @hp_number2.viewport = viewport
      @hp_number2.opacity = 0
  end  
  
  #--------------------------------------------------------------------------
  # * Create HP Meter
  #--------------------------------------------------------------------------   
  def create_hp_meter(viewport)
      return if !HP_METER_VISIBLE
      @hp_flow_max = @hp_meter_cw * 2
      @hp_flow = rand(@hp_flow_max)
      @hp_meter = Sprite.new
      @hp_meter.bitmap = Bitmap.new(@hp_meter_cw,@hp_meter_ch)
      @hp_meter.z = HUD_Z + HP_METER_Z
      @hp_meter.x = @hud_position[0] + HP_METER_POSITION[0]
      @hp_meter.y = @hud_position[1] + HP_METER_POSITION[1]
      @hp_meter.angle = HP_METER_ANGLE
      @hp_meter.mirror = HP_METER_MIRROR_EFFECT
      @hp_meter.viewport = viewport
      @hp_meter.opacity = 0
  end
  
  #--------------------------------------------------------------------------
  # ● Update Flow HP
  #--------------------------------------------------------------------------            
  def update_flow_hp
      @hp_meter.bitmap.clear
      @hp_flow = 0 if !HP_METER_GRADIENT_ANIMATION
      meter_width = @hp_meter_cw * @actor.hp / @actor.mhp rescue nil
      meter_width = 0 if meter_width == nil
      execute_hp_damage_flow(meter_width)      
      meter_src_rect = Rect.new(@hp_flow, 0,meter_width, @hp_meter_ch)
      @hp_meter.bitmap.blt(0,0, @hp_meter_image, meter_src_rect)  
      @hp_flow += 2
      @hp_flow = 0 if @hp_flow >= @hp_flow_max
  end  
   
  #--------------------------------------------------------------------------
  # ● Execute HP Damage Flow
  #--------------------------------------------------------------------------
  def execute_hp_damage_flow(meter_width)
      return if !HP_METER_REDUCTION_ANIMATION
      return if @hp_old_meter == meter_width
      n = (@hp_old_meter - meter_width).abs * 3 / 100
      damage_flow = [[n, 2].min,0.5].max
      @hp_old_meter -= damage_flow
      @hp_old_meter = meter_width if @hp_old_meter <= meter_width
      src_rect_old = Rect.new(0,@hp_meter_ch, @hp_old_meter, @hp_meter_ch)
      @hp_meter.bitmap.blt(0,0, @hp_meter_image, src_rect_old)      
  end

  #--------------------------------------------------------------------------
  # * Create HP Icon
  #--------------------------------------------------------------------------  
  def create_hp_icon(viewport)
      return if !HP_ICON_VISIBLE
      @hp_icon = Sprite.new
      icon_width = @hp_icon_col_max * (@hp_icon_cw + HP_ICON_SPACE[0].abs)
      icon_height = @hp_icon_row_max * (@hp_icon_ch + HP_ICON_SPACE[1].abs)
      @hp_icon.bitmap = Bitmap.new(icon_width,icon_height)      
      @hp_icon.z = HUD_Z + HP_ICON_Z
      @hp_icon.x = @hud_position[0] + HP_ICON_POSITION[0]
      @hp_icon.y = @hud_position[1] + HP_ICON_POSITION[1]
      @hp_icon.viewport = viewport
      @hp_icon.opacity = 0
  end
   
  #--------------------------------------------------------------------------
  # * Refresh HP Icon
  #--------------------------------------------------------------------------   
  def refresh_hp_icon
      @hp_icon_old = @actor.hp
      @hp_icon.bitmap.clear
      max_value = (@actor.mhp / @hp_icon_real_max) * @hp_icon_real_max
      if @actor.hp > max_value
         icon_max = icon_limit(@actor.mhp,@hp_icon_real_max)
      else   
         icon_max = @actor.mhp
      end      
      for i in 0...icon_max
          break if (i / @hp_icon_col_max) >= @hp_icon_row_max
          rx = (i * (@hp_icon_cw + HP_ICON_SPACE[0]) ) - ((i / @hp_icon_col_max) * (@hp_icon_cw + HP_ICON_SPACE[0]) * @hp_icon_col_max)
          ry = (i / @hp_icon_col_max) * (@hp_icon_ch + HP_ICON_SPACE[1])
          i_scr = Rect.new(0,0,@hp_icon_cw,@hp_icon_ch)
          @hp_icon.bitmap.blt(rx,ry,@hp_icon_image ,i_scr )      
      end      
      icon_max = icon_limit(@actor.hp,@hp_icon_real_max)
      rx = 0
      ry = 0
      for i in 0...icon_max
          break if (i / @hp_icon_col_max) >= @hp_icon_row_max
          rx = (i * (@hp_icon_cw + HP_ICON_SPACE[0]) ) - ((i / @hp_icon_col_max) * (@hp_icon_cw + HP_ICON_SPACE[0]) * @hp_icon_col_max)
          ry = (i / @hp_icon_col_max) * (@hp_icon_ch + HP_ICON_SPACE[1])
          i_scr = Rect.new(@hp_icon_cw,0,@hp_icon_cw,@hp_icon_ch)
          @hp_icon.bitmap.blt(rx,ry,@hp_icon_image ,i_scr )
      end
      refresh_hp_icon_ex(rx,ry)      
  end
  
  #--------------------------------------------------------------------------
  # * Create HP Icon EX
  #--------------------------------------------------------------------------  
  def create_hp_icon_ex(viewport)
      return if !HP_ICON_EX_VISIBLE
      @hp_icon3_anime_phase = 0
      @hp_icon3 = Sprite.new
      @hp_icon3.bitmap = Bitmap.new(@hp_icon2_cw,@hp_icon2_ch)
      @hp_icon3.ox = @hp_icon3.bitmap.width / 2
      @hp_icon3.oy = @hp_icon3.bitmap.height / 2
      @hp_icon3.z = HUD_Z + HP_ICON_Z + 2
      @hp_icon3_org = [@hud_position[0] + HP_ICON_POSITION[0] + HP_ICON_EX_POSITION[0] + @hp_icon3.ox,
                       @hud_position[1] + HP_ICON_POSITION[1] + HP_ICON_EX_POSITION[1] + @hp_icon3.oy]
      @hp_icon3.x = @hp_icon3_org[0]
      @hp_icon3.y = @hp_icon3_org[1]
      @hp_icon3.viewport = viewport
      @hp_icon3.opacity = 0
  end   
  
  #--------------------------------------------------------------------------
  # * Refresh HP Icon EX
  #--------------------------------------------------------------------------      
  def refresh_hp_icon_ex(rx,ry)
      return if @hp_icon3 == nil
      @hp_icon3.bitmap.clear
      return if @actor.hp == 0
      i_scr = Rect.new(0,0,@hp_icon2_cw,@hp_icon2_ch)
      @hp_icon3.bitmap.blt(0,0, @hp_icon2_image ,i_scr )
      @hp_icon3.x = @hp_icon3_org[0] + rx
      @hp_icon3.y = @hp_icon3_org[1] + ry     
  end
  
  #--------------------------------------------------------------------------
  # * Update Icon HP EX Anime
  #--------------------------------------------------------------------------  
  def update_icon_hp_ex_anime
      return if !HP_ICON_EX_ZOOM_EFFECT
      if @hp_icon3_anime_phase == 0
         @hp_icon3.zoom_x += 0.01
         if @hp_icon3.zoom_x >= 1.30
            @hp_icon3.zoom_x = 1.30
            @hp_icon3_anime_phase = 1
         end  
      else
        @hp_icon3.zoom_x -= 0.01
        if @hp_icon3.zoom_x <= 1.05
           @hp_icon3.zoom_x = 1.05
           @hp_icon3_anime_phase = 0
        end   
      end  
      @hp_icon3.zoom_y = @hp_icon3.zoom_x
  end
  
  #--------------------------------------------------------------------------
  # * Create HP Icon Nummber
  #--------------------------------------------------------------------------      
  def create_hp_icon_number(viewport)
      return if !HP_ICON_NUMBER_VISIBLE
      @hp_icon_number_old = [-1,-1]
      @hp_icon_number = Sprite.new
      @hp_icon_number.bitmap = Bitmap.new(@hp_icon_number_cw * 4,@hp_icon_number_ch)
      @hp_icon_number.z = HUD_Z + HP_ICON_NUMBER_Z
      @hp_icon_number.x = @hud_position[0] + HP_ICON_NUMBER_POSITION[0]
      @hp_icon_number.y = @hud_position[1] + HP_ICON_NUMBER_POSITION[1]
      @hp_icon_number.viewport = viewport
      @hp_icon_number.opacity = 0
  end
  
  #--------------------------------------------------------------------------
  # * Refresh Icon Number HP
  #--------------------------------------------------------------------------  
  def refresh_icon_number_hp
      @hp_icon_number_old[0] = @actor.hp
      @hp_icon_number_old[1] = @actor.mhp
      @hp_icon_number.bitmap.clear
      value = ((@actor.hp - 1) / @hp_icon_col_max) / @hp_icon_row_max
      value = 0 if value < 0
      number_value = value.truncate.abs.to_s.split(//)
      for r in 0..number_value.size - 1         
         number_value_abs = number_value[r].to_i
         nsrc_rect = Rect.new(@hp_icon_number_cw * number_value_abs, 0, @hp_icon_number_cw, @hp_icon_number_ch)
         @hp_icon_number.bitmap.blt(@hp_icon_number_cw *  r, 0, @hp_icon_number_image, nsrc_rect)
      end
      cx = (number_value.size * @hp_icon_number_cw)
      case HP_ICON_NUMBER_ALIGN_TYPE
         when 0; @hp_icon_number.x = @hud_position[0] + HP_ICON_NUMBER_POSITION[0]
         when 1; @hp_icon_number.x = @hud_position[0] + HP_ICON_NUMBER_POSITION[0] - (cx / 2)
         when 2; @hp_icon_number.x = @hud_position[0] + HP_ICON_NUMBER_POSITION[0] - cx
      end   
  end

  #--------------------------------------------------------------------------
  # * Can Refresh Icon Number HP
  #--------------------------------------------------------------------------  
  def can_refresh_icon_number_hp?
      return true if @hp_icon_number_old[0] != @actor.hp
      return true if @hp_icon_number_old[1] != @actor.mhp
      return false
  end
  
  #--------------------------------------------------------------------------
  # * Update HP
  #--------------------------------------------------------------------------   
  def update_hp
      if @hp_number != nil
         if HP_NUMBER_ANIMATION
            update_number(0,@hp_number_old)
         else   
            update_number_fix(0) if @hp_number_old != @actor.hp
         end
         sprite_visible(@hp_number)  
         refresh_number(0,@hp_number_old,@hp_number,@hp_number_image,@hp_number_cw,@hp_number_ch,@hp_wave_number) if @hp_number_refresh
      end
      if @hp_number2 != nil
         if HP_NUMBER_ANIMATION
            update_number(3,@hp_number2_old)
         else   
            update_number_fix(3) if @hp_number2_old != @actor.mhp
         end  
         refresh_number(3,@hp_number2_old,@hp_number2,@hp_number2_image,@hp_number2_cw,@hp_number2_ch,@hp_wave_number) if @hp_number2_refresh
         sprite_visible(@hp_number2)
      end
      if @hp_meter != nil
         sprite_visible(@hp_meter)
         update_flow_hp
      end   
      if @hp_icon != nil
         sprite_visible(@hp_icon)
         refresh_hp_icon if @hp_icon_old != @actor.hp
      end
      if @hp_icon3 != nil
         sprite_visible(@hp_icon3)
         update_icon_hp_ex_anime
      end      
      if @hp_icon_number != nil
         sprite_visible(@hp_icon_number)
         refresh_icon_number_hp if can_refresh_icon_number_hp?
      end  
  end  
   
end

#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
  
  #--------------------------------------------------------------------------
  # * Create MP Number
  #--------------------------------------------------------------------------  
  def create_mp_number(viewport)
      return if !MP_NUMBER_VISIBLE
      @mp_number = Sprite.new
      @mp_number.bitmap = Bitmap.new(@mp_number_cw * 4, @mp_number_ch)
      @mp_number.z = HUD_Z + MP_NUMBER_Z
      @mp_number.x = @hud_position[0] + MP_NUMBER_POSITION[0]
      @mp_number.y = @hud_position[1] + MP_NUMBER_POSITION[1]
      @mp_number.viewport = viewport
      @mp_number.opacity = 0
  end
  
  #--------------------------------------------------------------------------
  # * Create MP Number Max
  #--------------------------------------------------------------------------  
  def create_mp_number_max(viewport)
      return if !MP_NUMBER_MAX_VISIBLE
      @mp_number2 = Sprite.new
      @mp_number2.bitmap = Bitmap.new(@mp_number2_cw * 4, @mp_number2_ch)
      @mp_number2.z = HUD_Z + MP_NUMBER_Z
      @mp_number2.x = @hud_position[0] + MP_NUMBER_MAX_POSITION[0]
      @mp_number2.y = @hud_position[1] + MP_NUMBER_MAX_POSITION[1]
      @mp_number2.viewport = viewport
      @mp_number2.opacity = 0
  end  
  
  #--------------------------------------------------------------------------
  # * Create MP Meter
  #--------------------------------------------------------------------------   
  def create_mp_meter(viewport)
      return if !MP_METER_VISIBLE
      @mp_flow_max = @mp_meter_cw * 2
      @mp_flow = rand(@mp_flow_max)
      @mp_meter = Sprite.new
      @mp_meter.bitmap = Bitmap.new(@mp_meter_cw,@mp_meter_ch)
      @mp_meter.z = HUD_Z + MP_METER_Z
      @mp_meter.x = @hud_position[0] + MP_METER_POSITION[0]
      @mp_meter.y = @hud_position[1] + MP_METER_POSITION[1]
      @mp_meter.angle = MP_METER_ANGLE
      @mp_meter.mirror = MP_METER_MIRROR_EFFECT
      @mp_meter.viewport = viewport
      @mp_meter.opacity = 0
  end
  
  #--------------------------------------------------------------------------
  # ● Update Flow MP
  #--------------------------------------------------------------------------            
  def update_flow_mp
      @mp_meter.bitmap.clear
      @mp_flow = 0 if !MP_METER_GRADIENT_ANIMATION
      meter_width = @mp_meter_cw * @actor.mp / @actor.mmp rescue nil
      meter_width = 0 if meter_width == nil
      execute_mp_damage_flow(meter_width)      
      meter_src_rect = Rect.new(@mp_flow, 0,meter_width, @mp_meter_ch)
      @mp_meter.bitmap.blt(0,0, @mp_meter_image, meter_src_rect)  
      @mp_flow += 2
      @mp_flow = 0 if @mp_flow >= @mp_flow_max
  end  
   
  #--------------------------------------------------------------------------
  # ● Execute MP Damage Flow
  #--------------------------------------------------------------------------
  def execute_mp_damage_flow(meter_width)
      return if !MP_METER_REDUCTION_ANIMATION
      return if @mp_old_meter == meter_width
      n = (@mp_old_meter - meter_width).abs * 3 / 100
      damage_flow = [[n, 2].min,0.5].max
      @mp_old_meter -= damage_flow      
      @mp_old_meter = meter_width if @mp_old_meter <= meter_width
      src_rect_old = Rect.new(0,@mp_meter_ch, @mp_old_meter, @mp_meter_ch)
      @mp_meter.bitmap.blt(0,0, @mp_meter_image, src_rect_old)      
  end

  #--------------------------------------------------------------------------
  # * Create MP Icon
  #--------------------------------------------------------------------------  
  def create_mp_icon(viewport)
      return if !MP_ICON_VISIBLE
      @mp_icon = Sprite.new
      icon_width = @mp_icon_col_max * (@mp_icon_cw + MP_ICON_SPACE[0].abs)
      icon_height = @mp_icon_row_max * (@mp_icon_ch + MP_ICON_SPACE[1].abs)
      @mp_icon.bitmap = Bitmap.new(icon_width,icon_height)      
      @mp_icon.z = HUD_Z + MP_ICON_Z
      @mp_icon.x = @hud_position[0] + MP_ICON_POSITION[0]
      @mp_icon.y = @hud_position[1] + MP_ICON_POSITION[1]
      @mp_icon.viewport = viewport
      @mp_icon.opacity = 0
  end
   
  #--------------------------------------------------------------------------
  # * Refresh MP Icon
  #--------------------------------------------------------------------------   
  def refresh_mp_icon
      @mp_icon_old = @actor.mp
      @mp_icon.bitmap.clear
      max_value = (@actor.mmp / @mp_icon_real_max) * @mp_icon_real_max
      if @actor.mp > max_value
         icon_max = icon_limit(@actor.mmp,@mp_icon_real_max)
      else   
         icon_max = @actor.mmp
      end      
      for i in 0...icon_max
          break if (i / @mp_icon_col_max) >= @mp_icon_row_max
          rx = (i * (@mp_icon_cw + MP_ICON_SPACE[0]) ) - ((i / @mp_icon_col_max) * (@mp_icon_cw + MP_ICON_SPACE[0]) * @mp_icon_col_max)
          ry = (i / @mp_icon_col_max) * (@mp_icon_ch + MP_ICON_SPACE[1])
          i_scr = Rect.new(0,0,@mp_icon_cw,@mp_icon_ch)
          @mp_icon.bitmap.blt(rx,ry,@mp_icon_image ,i_scr )      
      end      
      icon_max = icon_limit(@actor.mp,@mp_icon_real_max)
      rx = 0
      ry = 0
      for i in 0...icon_max
          break if (i / @mp_icon_col_max) >= @mp_icon_row_max
          rx = (i * (@mp_icon_cw + MP_ICON_SPACE[0]) ) - ((i / @mp_icon_col_max) * (@mp_icon_cw + MP_ICON_SPACE[0]) * @mp_icon_col_max)
          ry = (i / @mp_icon_col_max) * (@mp_icon_ch + MP_ICON_SPACE[1])
          i_scr = Rect.new(@mp_icon_cw,0,@mp_icon_cw,@mp_icon_ch)
          @mp_icon.bitmap.blt(rx,ry,@mp_icon_image ,i_scr )
      end
      refresh_mp_icon_ex(rx,ry)      
  end
  
  #--------------------------------------------------------------------------
  # * Create MP Icon EX
  #--------------------------------------------------------------------------  
  def create_mp_icon_ex(viewport)
      return if !MP_ICON_EX_VISIBLE
      @mp_icon3_anime_phase = 0
      @mp_icon3 = Sprite.new
      @mp_icon3.bitmap = Bitmap.new(@mp_icon2_cw,@mp_icon2_ch)
      @mp_icon3.ox = @mp_icon3.bitmap.width / 2
      @mp_icon3.oy = @mp_icon3.bitmap.height / 2
      @mp_icon3.z = HUD_Z + MP_ICON_Z + 2
      @mp_icon3_org = [@hud_position[0] + MP_ICON_POSITION[0] + MP_ICON_EX_POSITION[0] + @mp_icon3.ox,
                       @hud_position[1] + MP_ICON_POSITION[1] + MP_ICON_EX_POSITION[1] + @mp_icon3.oy]
      @mp_icon3.x = @mp_icon3_org[0]
      @mp_icon3.y = @mp_icon3_org[1]
      @mp_icon3.viewport = viewport
      @mp_icon3.opacity = 0
  end   
  
  #--------------------------------------------------------------------------
  # * Refresh MP Icon EX
  #--------------------------------------------------------------------------      
  def refresh_mp_icon_ex(rx,ry)
      return if @mp_icon3 == nil
      @mp_icon3.bitmap.clear
      return if @actor.mp == 0
      i_scr = Rect.new(0,0,@mp_icon2_cw,@mp_icon2_ch)
      @mp_icon3.bitmap.blt(0,0, @mp_icon2_image ,i_scr )
      @mp_icon3.x = @mp_icon3_org[0] + rx
      @mp_icon3.y = @mp_icon3_org[1] + ry     
  end
  
  #--------------------------------------------------------------------------
  # * Update Icon MP EX Anime
  #--------------------------------------------------------------------------  
  def update_icon_mp_ex_anime
      return if !MP_ICON_EX_ZOOM_EFFECT
      if @mp_icon3_anime_phase == 0
         @mp_icon3.zoom_x += 0.01
         if @mp_icon3.zoom_x >= 1.30
            @mp_icon3.zoom_x = 1.30
            @mp_icon3_anime_phase = 1
         end  
      else
        @mp_icon3.zoom_x -= 0.01
        if @mp_icon3.zoom_x <= 1.05
           @mp_icon3.zoom_x = 1.05
           @mp_icon3_anime_phase = 0
        end   
      end  
      @mp_icon3.zoom_y = @mp_icon3.zoom_x
  end  
  
  #--------------------------------------------------------------------------
  # * Create MP Icon Number
  #--------------------------------------------------------------------------      
  def create_mp_icon_number(viewport)
      return if !MP_ICON_NUMBER_VISIBLE
      @mp_icon_number_old = [-1,-1]
      @mp_icon_number = Sprite.new
      @mp_icon_number.bitmap = Bitmap.new(@mp_icon_number_cw * 4,@mp_icon_number_ch)
      @mp_icon_number.z = HUD_Z + MP_ICON_NUMBER_Z
      @mp_icon_number.x = @hud_position[0] + MP_ICON_NUMBER_POSITION[0]
      @mp_icon_number.y = @hud_position[1] + MP_ICON_NUMBER_POSITION[1]
      @mp_icon_number.viewport = viewport
      @mp_icon_number.opacity = 0
  end
  
  #--------------------------------------------------------------------------
  # * Refresh Icon Number MP
  #--------------------------------------------------------------------------  
  def refresh_icon_number_mp
      @mp_icon_number_old[0] = @actor.mp
      @mp_icon_number_old[1] = @actor.mmp
      @mp_icon_number.bitmap.clear
      value = ((@actor.mp - 1) / @mp_icon_col_max) / @mp_icon_row_max
      value = 0 if value < 0
      number_value = value.truncate.abs.to_s.split(//)
      for r in 0..number_value.size - 1         
         number_value_abs = number_value[r].to_i
         nsrc_rect = Rect.new(@mp_icon_number_cw * number_value_abs, 0, @mp_icon_number_cw, @mp_icon_number_ch)
         @mp_icon_number.bitmap.blt(@mp_icon_number_cw *  r, 0, @mp_icon_number_image, nsrc_rect)
      end
      cx = (number_value.size * @mp_icon_number_cw)
      case MP_ICON_NUMBER_ALIGN_TYPE
         when 0; @mp_icon_number.x = @hud_position[0] + MP_ICON_NUMBER_POSITION[0]
         when 1; @mp_icon_number.x = @hud_position[0] + MP_ICON_NUMBER_POSITION[0] - (cx / 2)
         when 2; @mp_icon_number.x = @hud_position[0] + MP_ICON_NUMBER_POSITION[0] - cx
      end        
  end

  #--------------------------------------------------------------------------
  # * Can Refresh Icon Number MP
  #--------------------------------------------------------------------------  
  def can_refresh_icon_number_mp?
      return true if @mp_icon_number_old[0] != @actor.mp
      return true if @mp_icon_number_old[1] != @actor.mmp
      return false
  end   
  
  #--------------------------------------------------------------------------
  # * Update MP
  #--------------------------------------------------------------------------   
  def update_mp
      if @mp_number != nil
         sprite_visible(@mp_number)
         if MP_NUMBER_ANIMATION
            update_number(1,@mp_number_old)
         else
            update_number_fix(1) if @mp_number_old != @actor.mp
         end  
         refresh_number(1,@mp_number_old,@mp_number,@mp_number_image,@mp_number_cw,@mp_number_ch,@mp_wave_number) if @mp_number_refresh
      end
      if @mp_number2 != nil
         sprite_visible(@mp_number2)
         if MP_NUMBER_ANIMATION
            update_number(4,@mp_number2_old)
         else
            update_number_fix(4) if @mp_number2_old != @actor.mmp
         end  
         refresh_number(4,@mp_number2_old,@mp_number2,@mp_number2_image,@mp_number2_cw,@mp_number2_ch,@mp_wave_number) if @mp_number2_refresh
      end      
      if @mp_meter != nil
         sprite_visible(@mp_meter)
         update_flow_mp
      end
      if @mp_icon != nil
         sprite_visible(@mp_icon)
         refresh_mp_icon if @mp_icon_old != @actor.mp
      end
      if @mp_icon3 != nil
         sprite_visible(@mp_icon3)
         update_icon_mp_ex_anime
      end         
      if @mp_icon_number != nil
         sprite_visible(@mp_icon_number)
         refresh_icon_number_mp if can_refresh_icon_number_mp?
      end      
  end  
  
end

#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
  
  #--------------------------------------------------------------------------
  # * Create TP Number
  #--------------------------------------------------------------------------  
  def create_tp_number(viewport)
      return if !TP_NUMBER_VISIBLE
      @tp_number = Sprite.new
      @tp_number.bitmap = Bitmap.new(@tp_number_cw * 3, @tp_number_ch)
      @tp_number.z = HUD_Z + TP_NUMBER_Z
      @tp_number.x = @hud_position[0] + TP_NUMBER_POSITION[0]
      @tp_number.y = @hud_position[1] + TP_NUMBER_POSITION[1]
      @tp_number.viewport = viewport
      @tp_number.opacity = 0
  end
  
  #--------------------------------------------------------------------------
  # * Create TP Number MAX
  #--------------------------------------------------------------------------  
  def create_tp_number_max(viewport)
      return if !TP_NUMBER_MAX_VISIBLE
      @tp_number2 = Sprite.new
      @tp_number2.bitmap = Bitmap.new(@tp_number2_cw * 3, @tp_number2_ch)
      @tp_number2.z = HUD_Z + TP_NUMBER_Z
      @tp_number2.x = @hud_position[0] + TP_NUMBER_MAX_POSITION[0]
      @tp_number2.y = @hud_position[1] + TP_NUMBER_MAX_POSITION[1]
      @tp_number2.viewport = viewport
      @tp_number2.opacity = 0
  end  
  
  #--------------------------------------------------------------------------
  # * Create TP Meter
  #--------------------------------------------------------------------------   
  def create_tp_meter(viewport)
      return if !TP_METER_VISIBLE
      @tp_flow_max = @tp_meter_cw * 2
      @tp_flow = rand(@tp_flow_max)
      @tp_meter = Sprite.new
      @tp_meter.bitmap = Bitmap.new(@tp_meter_cw,@tp_meter_ch)
      @tp_meter.z = HUD_Z + TP_METER_Z
      @tp_meter.x = @hud_position[0] + TP_METER_POSITION[0]
      @tp_meter.y = @hud_position[1] + TP_METER_POSITION[1]
      @tp_meter.angle = TP_METER_ANGLE
      @tp_meter.mirror = TP_METER_MIRROR_EFFECT
      @tp_meter.viewport = viewport
      @tp_meter.opacity = 0
  end
  
  #--------------------------------------------------------------------------
  # ● Update Flow TP
  #--------------------------------------------------------------------------            
  def update_flow_tp
      @tp_meter.bitmap.clear      
      @tp_flow = 0 if !TP_METER_GRADIENT_ANIMATION
      meter_width = @tp_meter_cw * @actor.tp / @actor.max_tp rescue nil  
      meter_width = 0 if meter_width == nil
      execute_tp_damage_flow(meter_width)      
      meter_src_rect = Rect.new(@tp_flow, 0,meter_width, @tp_meter_ch)
      @tp_meter.bitmap.blt(0,0, @tp_meter_image, meter_src_rect)  
      @tp_flow += 2
      @tp_flow = 0 if @tp_flow >= @tp_flow_max
  end  
   
  #--------------------------------------------------------------------------
  # ● Execute TP Damage Flow
  #--------------------------------------------------------------------------
  def execute_tp_damage_flow(meter_width)
      return if !TP_METER_REDUCTION_ANIMATION
      return if @tp_old_meter == meter_width
      n = (@tp_old_meter - meter_width).abs * 3 / 100
      damage_flow = [[n, 2].min,0.5].max
      @tp_old_meter -= damage_flow
      @tp_old_meter = meter_width if @tp_old_meter <= meter_width
      src_rect_old = Rect.new(0,@tp_meter_ch, @tp_old_meter, @tp_meter_ch)
      @tp_meter.bitmap.blt(0,0, @tp_meter_image, src_rect_old)      
  end

  #--------------------------------------------------------------------------
  # * Create TP Icon
  #--------------------------------------------------------------------------  
  def create_tp_icon(viewport)
      return if !TP_ICON_VISIBLE
      @tp_icon = Sprite.new
      icon_width = @tp_icon_col_max * (@tp_icon_cw + TP_ICON_SPACE[0].abs)
      icon_height = @tp_icon_row_max * (@tp_icon_ch + TP_ICON_SPACE[1].abs)
      @tp_icon.bitmap = Bitmap.new(icon_width,icon_height)      
      @tp_icon.z = HUD_Z + TP_ICON_Z
      @tp_icon.x = @hud_position[0] + TP_ICON_POSITION[0]
      @tp_icon.y = @hud_position[1] + TP_ICON_POSITION[1]
      @tp_icon.viewport = viewport
      @tp_icon.opacity = 0
  end
   
  #--------------------------------------------------------------------------
  # * Refresh TP Icon
  #--------------------------------------------------------------------------   
  def refresh_tp_icon
      @tp_icon_old = @actor.tp
      @tp_icon.bitmap.clear
      max_value = (@actor.max_tp / @tp_icon_real_max) * @tp_icon_real_max
      if @actor.mp > max_value
         icon_max = icon_limit(@actor.max_tp,@tp_icon_real_max)
      else   
         icon_max = @actor.max_tp
      end      
      for i in 0...icon_max
          break if (i / @tp_icon_col_max) >= @tp_icon_row_max
          rx = (i * (@tp_icon_cw + TP_ICON_SPACE[0]) ) - ((i / @tp_icon_col_max) * (@tp_icon_cw + TP_ICON_SPACE[0]) * @tp_icon_col_max)
          ry = (i / @tp_icon_col_max) * (@tp_icon_ch + TP_ICON_SPACE[1])
          i_scr = Rect.new(0,0,@tp_icon_cw,@tp_icon_ch)
          @tp_icon.bitmap.blt(rx,ry,@tp_icon_image ,i_scr )      
      end      
      icon_max = icon_limit(@actor.tp,@tp_icon_real_max)
      rx = 0
      ry = 0
      for i in 0...icon_max
          break if (i / @tp_icon_col_max) >= @tp_icon_row_max
          rx = (i * (@tp_icon_cw + TP_ICON_SPACE[0]) ) - ((i / @tp_icon_col_max) * (@tp_icon_cw + TP_ICON_SPACE[0]) * @tp_icon_col_max)
          ry = (i / @tp_icon_col_max) * (@tp_icon_ch + TP_ICON_SPACE[1])
          i_scr = Rect.new(@mp_icon_cw,0,@tp_icon_cw,@tp_icon_ch)
          @tp_icon.bitmap.blt(rx,ry,@tp_icon_image ,i_scr )
      end
      refresh_tp_icon_ex(rx,ry)      
  end
  
  #--------------------------------------------------------------------------
  # * Create TP Icon EX
  #--------------------------------------------------------------------------  
  def create_tp_icon_ex(viewport)
      return if !TP_ICON_EX_VISIBLE
      @tp_icon3_anime_phase = 0
      @tp_icon3 = Sprite.new
      @tp_icon3.bitmap = Bitmap.new(@tp_icon2_cw,@tp_icon2_ch)
      @tp_icon3.ox = @tp_icon3.bitmap.width / 2
      @tp_icon3.oy = @tp_icon3.bitmap.height / 2
      @tp_icon3.z = HUD_Z + TP_ICON_Z + 2
      @tp_icon3_org = [@hud_position[0] + TP_ICON_POSITION[0] + TP_ICON_EX_POSITION[0] + @tp_icon3.ox,
                       @hud_position[1] + TP_ICON_POSITION[1] + TP_ICON_EX_POSITION[1] + @tp_icon3.oy]
      @tp_icon3.x = @tp_icon3_org[0]
      @tp_icon3.y = @tp_icon3_org[1]
      @tp_icon3.viewport = viewport
      @tp_icon3.opacity = 0
  end   
  
  #--------------------------------------------------------------------------
  # * Refresh TP Icon EX
  #--------------------------------------------------------------------------      
  def refresh_tp_icon_ex(rx,ry)
      return if @tp_icon3 == nil
      @tp_icon3.bitmap.clear
      return if @actor.tp == 0
      i_scr = Rect.new(0,0,@tp_icon2_cw,@tp_icon2_ch)
      @tp_icon3.bitmap.blt(0,0, @tp_icon2_image ,i_scr )
      @tp_icon3.x = @tp_icon3_org[0] + rx
      @tp_icon3.y = @tp_icon3_org[1] + ry     
  end
  
  #--------------------------------------------------------------------------
  # * Update Icon TP EX Anime
  #--------------------------------------------------------------------------  
  def update_icon_tp_ex_anime
      return if !MP_ICON_EX_ZOOM_EFFECT
      if @tp_icon3_anime_phase == 0
         @tp_icon3.zoom_x += 0.01
         if @tp_icon3.zoom_x >= 1.30
            @tp_icon3.zoom_x = 1.30
            @tp_icon3_anime_phase = 1
         end  
      else
        @tp_icon3.zoom_x -= 0.01
        if @tp_icon3.zoom_x <= 1.05
           @tp_icon3.zoom_x = 1.05
           @tp_icon3_anime_phase = 0
        end   
      end  
      @tp_icon3.zoom_y = @tp_icon3.zoom_x
  end   
  
  #--------------------------------------------------------------------------
  # * Create HP Icon Number
  #--------------------------------------------------------------------------      
  def create_tp_icon_number(viewport)
      return if !TP_ICON_NUMBER_VISIBLE
      @tp_icon_number_old = [-1,-1]
      @tp_icon_number = Sprite.new
      @tp_icon_number.bitmap = Bitmap.new(@tp_icon_number_cw * 3,@tp_icon_number_ch)
      @tp_icon_number.z = HUD_Z + TP_ICON_NUMBER_Z
      @tp_icon_number.x = @hud_position[0] + TP_ICON_NUMBER_POSITION[0]
      @tp_icon_number.y = @hud_position[1] + TP_ICON_NUMBER_POSITION[1]
      @tp_icon_number.viewport = viewport
      @tp_icon_number.opacity = 0
  end
  
  #--------------------------------------------------------------------------
  # * Refresh Icon Number TP
  #--------------------------------------------------------------------------  
  def refresh_icon_number_tp
      @tp_icon_number_old[0] = @actor.tp
      @tp_icon_number_old[1] = @actor.max_tp
      @tp_icon_number.bitmap.clear
      value = ((@actor.tp - 1) / @tp_icon_col_max) / @tp_icon_row_max
      value = 0 if value < 0
      number_value = value.truncate.abs.to_s.split(//)
      for r in 0..number_value.size - 1         
         number_value_abs = number_value[r].to_i
         nsrc_rect = Rect.new(@tp_icon_number_cw * number_value_abs, 0, @tp_icon_number_cw, @tp_icon_number_ch)
         @tp_icon_number.bitmap.blt(@tp_icon_number_cw *  r, 0, @tp_icon_number_image, nsrc_rect)
      end
      cx = (number_value.size * @tp_icon_number_cw)
      case TP_ICON_NUMBER_ALIGN_TYPE
         when 0; @tp_icon_number.x = @hud_position[0] + TP_ICON_NUMBER_POSITION[0]
         when 1; @tp_icon_number.x = @hud_position[0] + TP_ICON_NUMBER_POSITION[0] - (cx / 2)
         when 2; @tp_icon_number.x = @hud_position[0] + TP_ICON_NUMBER_POSITION[0] - cx
      end        
  end

  #--------------------------------------------------------------------------
  # * Can Refresh Icon Number TP
  #--------------------------------------------------------------------------  
  def can_refresh_icon_number_tp?
      return true if @tp_icon_number_old[0] != @actor.tp
      return true if @tp_icon_number_old[1] != @actor.max_tp
      return false
  end   
  
  #--------------------------------------------------------------------------
  # * Update TP
  #--------------------------------------------------------------------------   
  def update_tp
      if @tp_number != nil
         sprite_visible(@tp_number)
         if MP_NUMBER_ANIMATION
            update_number(2,@tp_number_old)
         else
            update_number_fix(2) if @tp_number_old != @actor.tp
         end           
         refresh_number(2,@tp_number_old,@tp_number,@tp_number_image,@tp_number_cw,@tp_number_ch,@tp_wave_number) if @tp_number_refresh         
      end   
      if @tp_number2 != nil
         sprite_visible(@tp_number2)
         if MP_NUMBER_ANIMATION
            update_number(5,@tp_number2_old)
         else
            update_number_fix(5) if @tp_number2_old != @actor.max_tp
         end           
         refresh_number(5,@tp_number2_old,@tp_number2,@tp_number2_image,@tp_number2_cw,@tp_number2_ch,@tp_wave_number) if @tp_number2_refresh
      end        
      if @tp_meter != nil
         sprite_visible(@tp_meter)
         update_flow_tp
      end
      if @tp_icon != nil
         sprite_visible(@tp_icon)
         refresh_tp_icon if @tp_icon_old != @actor.tp
      end
      if @tp_icon3 != nil
         sprite_visible(@tp_icon3)
         update_icon_tp_ex_anime
      end         
      if @tp_icon_number != nil
         sprite_visible(@tp_icon_number)
         refresh_icon_number_tp if can_refresh_icon_number_tp?
      end  
  end  
  
end

#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
  
  #--------------------------------------------------------------------------
  # * Create AT Number
  #--------------------------------------------------------------------------  
  def create_at_number(viewport)
      return if !AT_NUMBER_VISIBLE
      @at_number = Sprite.new
      @at_number.bitmap = Bitmap.new(@at_number_cw * 4,@at_number_ch)
      @at_number.z = HUD_Z + AT_NUMBER_Z
      @at_number.x = @hud_position[0] + AT_NUMBER_POSITION[0]
      @at_number.y = @hud_position[1] + AT_NUMBER_POSITION[1]
      @at_number.viewport = viewport
      @at_number.opacity = 0
  end
  
  #--------------------------------------------------------------------------
  # * Create AT Number Max
  #--------------------------------------------------------------------------  
  def create_at_number_max(viewport)
      return if !AT_NUMBER_MAX_VISIBLE
      @at_number2 = Sprite.new
      @at_number2.bitmap = Bitmap.new(@at_number2_cw * 4,@at_number2_ch)
      @at_number2.z = HUD_Z + AT_NUMBER_Z
      @at_number2.x = @hud_position[0] + AT_NUMBER_MAX_POSITION[0]
      @at_number2.y = @hud_position[1] + AT_NUMBER_MAX_POSITION[1]
      @at_number2.viewport = viewport
      @at_number2.opacity = 0
  end  
  
  #--------------------------------------------------------------------------
  # * Create AT Meter
  #--------------------------------------------------------------------------   
  def create_at_meter(viewport)
      return if !AT_METER_VISIBLE
      @at_flow_max = @at_meter_cw * 2
      @at_flow = rand(@at_flow_max)
      @at_meter = Sprite.new
      @at_meter.bitmap = Bitmap.new(@at_meter_cw,@at_meter_ch)
      @at_meter.z = HUD_Z + AT_METER_Z
      @at_meter.x = @hud_position[0] + AT_METER_POSITION[0]
      @at_meter.y = @hud_position[1] + AT_METER_POSITION[1]
      @at_meter.angle = AT_METER_ANGLE
      @at_meter.mirror = AT_METER_MIRROR_EFFECT
      @at_meter.viewport = viewport
      @at_meter.opacity = 0
  end
  
  #--------------------------------------------------------------------------
  # ● Update Flow AT
  #--------------------------------------------------------------------------            
  def update_flow_at
      @at_meter.bitmap.clear
      @at_flow = 0 if !AT_METER_GRADIENT_ANIMATION
      if actor_cast?
         meter_width = @at_meter_cw * actor_cast / actor_max_cast rescue nil
         meter_width = 0 if meter_width == nil
         ch = @at_meter_ch * 2
      else
         meter_width = @at_meter_cw * actor_at / actor_max_at rescue nil
         meter_width = 0 if meter_width == nil         
         ch = actor_at >= actor_max_at ? @at_meter_ch : 0
      end   
      meter_src_rect = Rect.new(@at_flow, ch,meter_width, @at_meter_ch)
      @at_meter.bitmap.blt(0,0, @at_meter_image, meter_src_rect)  
      @at_flow += 2
      @at_flow = 0 if @at_flow >= @at_flow_max
  end  
  
  #--------------------------------------------------------------------------
  # * Update AT
  #--------------------------------------------------------------------------   
  def update_at
      if @at_number != nil
         sprite_visible(@at_number)
         if AT_NUMBER_ANIMATION
            update_number(6,@at_number_old)
         else   
            update_number_fix(6) if @at_number_old != actor_at
         end  
         refresh_number(6,@at_number_old,@at_number,@at_number_image,@at_number_cw,@at_number_ch,@at_wave_number) if @at_number_refresh
      end
      if @at_number2 != nil
         sprite_visible(@at_number2)
         if AT_NUMBER_ANIMATION
            update_number(7,@at_number2_old)
         else   
            update_number_fix(7) if @at_number2_old != actor_max_at
         end  
         refresh_number(7,@at_number2_old,@at_number2,@at_number2_image,@at_number2_cw,@at_number2_ch,@at_wave_number) if @at_number2_refresh
      end
      if @at_meter != nil
         sprite_visible(@at_meter)
         update_flow_at
      end   
  end  
   
end

#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
  
  #--------------------------------------------------------------------------
  # * Create Level Number
  #--------------------------------------------------------------------------   
  def create_level_number(viewport)
      return if !LEVEL_NUMBER_VISIBLE
      @old_level = -1
      @lv_number = Sprite.new
      @lv_number.bitmap = Bitmap.new(@lv_number_cw * 2, @lv_number_ch)
      @lv_number.z = HUD_Z + LEVEL_NUMBER_Z
      @lv_number.x = @hud_position[0] + LEVEL_NUMBER_POSITION[0]
      @lv_number.y = @hud_position[1] + LEVEL_NUMBER_POSITION[1]
      @lv_number.viewport = viewport
      @lv_number.opacity = 0
  end
  
  #--------------------------------------------------------------------------
  # * Refresh Level Number
  #--------------------------------------------------------------------------  
  def refresh_level_number
      @lv_number.bitmap.clear
      @old_level = @actor.level      
      number_value = @actor.level.abs.to_s.split(//)
      for r in 0..number_value.size - 1         
         number_value_abs = number_value[r].to_i
         nsrc_rect = Rect.new(@lv_number_cw * number_value_abs, 0, @lv_number_cw, @lv_number_ch)
         @lv_number.bitmap.blt(@lv_number_cw *  r, 0, @lv_number_image, nsrc_rect)
      end
      cx = (number_value.size * @lv_number_cw)
      case LEVEL_NUMBER_ALIGN_TYPE
           when 0; @lv_number.x = @hud_position[0] + LEVEL_NUMBER_POSITION[0]
           when 1; @lv_number.x = @hud_position[0] + LEVEL_NUMBER_POSITION[0] - (cx / 2)
           when 2; @lv_number.x = @hud_position[0] + LEVEL_NUMBER_POSITION[0] - cx
      end
  end
  
  #--------------------------------------------------------------------------
  # * Update Level
  #--------------------------------------------------------------------------  
  def update_level
      return if @lv_number == nil
      sprite_visible(@lv_number)
      refresh_level_number if @old_level != @actor.level
  end
  
end

#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
  
  #--------------------------------------------------------------------------
  # * Create States
  #--------------------------------------------------------------------------  
  def create_states(viewport)
      return if !STATES_VISIBLE
      @status_old = nil
      @status_flow = [-24,0]
      @status_size_real = 0
      @status = Sprite.new
      @status.bitmap = Bitmap.new(24,24)
      @status.x = @hud_position[0] + STATES_POSITION[0]
      @status.y = @hud_position[1] + STATES_POSITION[1]
      @status.z = HUD_Z + STATES_Z
      @status.angle = STATE_ANGLE
      @status.viewport = viewport
      @status.opacity = 0
  end
  
  #--------------------------------------------------------------------------
  # * Refresh States
  #--------------------------------------------------------------------------        
  def refresh_states
      check_icon_image
      @status_size_real = set_real_states_size
      @status_old = @actor.states
      @status_flow = [0,0]
      @states_size = @status_size_real > 0 ? (26 * @status_size_real) : 24
      @actor_status.dispose if @actor_status != nil
      @actor_status = Bitmap.new(@states_size,24)
      index = 0
      for i in @actor.states
         next if HIDE_STATES_ID.include?(i.id)         
         rect = Rect.new(i.icon_index % 16 * 24, i.icon_index / 16 * 24, 24, 24)
         @actor_status.blt(26 * index , 0, @icon_image, rect)
         index += 1
      end
  end   
  
  #--------------------------------------------------------------------------
  # * Set Real States Size
  #--------------------------------------------------------------------------        
  def set_real_states_size
      n = 0
      for i in @actor.states
          next if HIDE_STATES_ID.include?(i.id)  
          n += 1
      end
      return n
  end
  
  #--------------------------------------------------------------------------
  # * Flow_Status
  #--------------------------------------------------------------------------         
  def flow_states
      return if @actor_status == nil
      @status.bitmap.clear
      return if @actor.states.size == 0
      st_src_rect = Rect.new(@status_flow[0],0, 24,24)
      @status.bitmap.blt(0,0, @actor_status, st_src_rect)
      if STATES_SCROLLING_ANIMATION
         @status_flow[0] += 1
         @status_flow[0] = -24 if @status_flow[0] >= @states_size + 2
      else   
         @status_flow[1] += 1 unless @actor.states.size <= 1
         if @status_flow[1] > 30
            @status_flow[1] = 0
            @status_flow[0] += 26
            @status_flow[0] = 0 if @status_flow[0] >= (@states_size - 0)
         end   
     end   
  end      
  
  #--------------------------------------------------------------------------
  # * Update States
  #--------------------------------------------------------------------------  
  def update_states
      return if @status == nil
      sprite_visible(@status)
      refresh_states if @status_old != @actor.states
      flow_states
  end  
  
end

#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
  
  #--------------------------------------------------------------------------
  # * Create Face
  #--------------------------------------------------------------------------   
  def create_face(viewport)
      return if !FACE_VISIBLE
      @face_old_hp = @actor.hp
      @face_old_mp = @actor.mp
      @face_old_tp = @actor.tp
      @face_name = ""
      @face = Sprite.new
      @face_org = [@hud_position[0] + FACE_POSITION[0], @hud_position[1] + FACE_POSITION[1]]
      @face.x = @face_org[0]
      @face.y = @face_org[1]
      @face.z = HUD_Z + FACE_Z
      @face.viewport = viewport
      @face.opacity = 0
      refresh_face_name
  end

  #--------------------------------------------------------------------------
  # * Refresh Face Name
  #--------------------------------------------------------------------------      
  def refresh_face_name      
      @face_image.dispose if @face_image != nil
      @face.bitmap.dispose if @face.bitmap != nil
      return if @actor == nil or @actor.id == nil
      @face_image = Cache.battle_hud(@actor.battler_face_name.to_s) rescue nil
      @face_image = Bitmap.new(32,32) if @face_image == nil
      @face_cw = FACE_ANIMATION ? @face_image.width / 5 : @face_image.width
      @face_ch = @face_image.height
      @face.ox = @face_cw / 2
      @face.oy = @face_ch / 2      
      @face.bitmap = Bitmap.new(@face_cw,@face_ch)
      @face_org = [@hud_position[0] + FACE_POSITION[0],
                   @hud_position[1] + @face.oy + FACE_POSITION[1]]
      if $game_temp.battler_face_pos[@actor_index] == nil
         $game_temp.battler_face_pos[@actor_index] = []
      end
      @face.x = @face_org[0]
      @face.y = @face_org[1]  
      limit_Y = (@hud_position[1] + FACE_POSITION[1] + @face_image.height)
      fy = @face_org[1]
      if limit_Y > Graphics.height
         @face.y = Graphics.height - (@face_image.height - @face.oy)
         fy = Graphics.height - 16
         @face_org[1] = @face.y
      end
      $game_temp.battler_face_pos[@actor_index][0] = @face_org[0]
      $game_temp.battler_face_pos[@actor_index][1] = fy
      $game_temp.battler_face_pos[@actor_index][2] = @face.z     
      clear_face_index
  end

  #--------------------------------------------------------------------------
  # * Refresh Face
  #--------------------------------------------------------------------------  
  def refresh_face
      @face.mirror = false
      @face.zoom_x = 1.00
      @face.zoom_y = 1.00
      @face_index = @actor.face_animation[1]
      @face.bitmap.clear
      if !FACE_ANIMATION
         f_scr = Rect.new(0,0,@face_cw,@face_ch)
      else
         f_scr = Rect.new(@face_index * @face_cw,0,@face_cw,@face_ch)
      end
      @face.bitmap.blt(0,0,@face_image,f_scr)
  end
   
  #--------------------------------------------------------------------------
  # * Update Face Duration
  #--------------------------------------------------------------------------   
  def update_face_duration
      return if @actor.face_animation[0] == 0
      @actor.face_animation[0] -= 1
      update_face_shake_effect
      update_face_zoom if @actor.face_animation[1] == 2
      return if @actor.face_animation[0] > 0
      clear_face_index
  end
  
  #--------------------------------------------------------------------------
  # * Clear Face Index
  #--------------------------------------------------------------------------      
  def clear_face_index
      @actor.face_animation[1] = @actor.low_hp? ? 3 : 0
      @actor.face_animation[1] = 4 if @actor.dead?
      refresh_face
  end
      
  #--------------------------------------------------------------------------
  # * Update Face Zoom
  #--------------------------------------------------------------------------      
  def update_face_zoom
      return if !FACE_ZOOM_ANIMATION
      case @actor.face_animation[0]
         when 30..60
            @face.zoom_x += 0.01
            @face.zoom_x = 1.30 if @face.zoom_x > 1.30
            @face.mirror = true unless !FACE_ZOOM_MIRROR_EFFECT
         when 1..29
            @face.zoom_x -= 0.01
            @face.zoom_x = 1.00 if @face.zoom_x < 1.00
            @face.mirror = false
         else
            @face.zoom_x = 1.00
            @face.mirror = false
      end
      @face.zoom_y = @face.zoom_x
  end
  
  #--------------------------------------------------------------------------
  # * Can Refresh Index MP TP?
  #--------------------------------------------------------------------------     
  def can_refresh_index_mp_tp?
      return true if @face_old_mp != @actor.mp
      return false
  end
  
  #--------------------------------------------------------------------------
  # * Refresh Face Index HP
  #--------------------------------------------------------------------------  
  def refresh_face_index_hp
      @actor.face_animation[0] = FACE_ANIMATION_DURATION
      @actor.face_animation[1] = @face_old_hp > @actor.hp ? 3 : 1
      @face_old_hp = @actor.hp
  end
  
  #--------------------------------------------------------------------------
  # * Refresh Face Index MP TP
  #--------------------------------------------------------------------------  
  def refresh_face_index_mp_tp
      if @face_old_mp < @actor.mp
         @actor.face_animation[0] = FACE_ANIMATION_DURATION
         @actor.face_animation[1] = 1
      end
      @face_old_mp = @actor.mp
      @face_old_tp = @actor.tp
  end  
  
  #--------------------------------------------------------------------------
  # * Update Face Shake Effect
  #--------------------------------------------------------------------------  
  def update_face_shake_effect
      return if !FACE_SHAKE_EFFECT
      if FACE_ANIMATION
         update_shake_animated_face
      else            
         update_shake_still_face
      end  
  end      

  #--------------------------------------------------------------------------
  # * Update Shake Still Effect Face
  #--------------------------------------------------------------------------   
  def update_shake_still_face
      if @actor.face_animation[0] > 0 and @actor.face_animation[1] == 3 and @actor.hp > 0
         @face.x = @face_org[0] - 4 + rand(8)
      else
         @face.x = @face_org[0]
      end     
  end
      
  #--------------------------------------------------------------------------
  # * Update Shake Animated Face
  #--------------------------------------------------------------------------   
  def update_shake_animated_face
      if @actor.face_animation[0] == 0
         @face.x = @face_org[0]
         return
      end
      if @actor.face_animation[1] == 3 and @actor.hp > 0
         @face.x = @face_org[0] - 4 + rand(8)
      else
         @face.x = @face_org[0]
      end         
  end
  
  #--------------------------------------------------------------------------
  # * Update Face
  #--------------------------------------------------------------------------   
  def update_face
      return if @face == nil
      sprite_visible(@face)
      refresh_face_index_hp if !FACE_ANIMATION and @face_old_hp != @actor.hp
      update_face_duration
      return if !FACE_ANIMATION
      refresh_face_index_mp_tp if can_refresh_index_mp_tp?
      refresh_face_index_hp if @face_old_hp != @actor.hp
      refresh_face if @face_index != @actor.face_animation[1]
  end  
  
end

#==============================================================================
# ■ Battle Manager
#==============================================================================
class << BattleManager
  
  #--------------------------------------------------------------------------
  # ● Battle End
  #--------------------------------------------------------------------------                    
  alias mog_battle_hud_battle_process_victory process_victory
  def process_victory
      execute_face_effect   
      mog_battle_hud_battle_process_victory
  end
  
  #--------------------------------------------------------------------------
  # ● Prepare
  #--------------------------------------------------------------------------                  
  def execute_face_effect
      $game_message.position = MOG_BATTLE_HUD_EX::BATTLE_MESSAGE_POSITION
      for i in $game_party.members
          i.face_animation = [120,1,0] if i.hp > 0   
      end  
  end
  
  #--------------------------------------------------------------------------
  # * Display EXP Earned
  #--------------------------------------------------------------------------
  alias mog_battle_hud_ex_message_battle_process_defeat process_defeat
  def process_defeat
      $game_message.position = MOG_BATTLE_HUD_EX::BATTLE_MESSAGE_POSITION
      mog_battle_hud_ex_message_battle_process_defeat
  end
  
  #--------------------------------------------------------------------------
  # * Process Escape
  #--------------------------------------------------------------------------
  alias mog_battle_hud_ex_message_battle_process_escape process_escape
  def process_escape
      $game_message.position = MOG_BATTLE_HUD_EX::BATTLE_MESSAGE_POSITION
      mog_battle_hud_ex_message_battle_process_escape
  end
   
  #--------------------------------------------------------------------------
  # * Display EXP Earned
  #--------------------------------------------------------------------------
  alias mog_battle_hud_ex_message_battle_display_exp display_exp
  def display_exp
      $game_message.position = MOG_BATTLE_HUD_EX::BATTLE_MESSAGE_POSITION
      mog_battle_hud_ex_message_battle_display_exp
  end
  
  #--------------------------------------------------------------------------
  # * Gold Acquisition and Display
  #--------------------------------------------------------------------------
  alias mog_battle_hud_ex_message_battle_gain_gold gain_gold
  def gain_gold
      $game_message.position = MOG_BATTLE_HUD_EX::BATTLE_MESSAGE_POSITION
      mog_battle_hud_ex_message_battle_gain_gold
  end

  #--------------------------------------------------------------------------
  # * Dropped Item Acquisition and Display
  #--------------------------------------------------------------------------
  alias mog_battle_hud_ex_message_battle_gain_drop_items gain_drop_items
  def gain_drop_items
      $game_message.position = MOG_BATTLE_HUD_EX::BATTLE_MESSAGE_POSITION
      mog_battle_hud_ex_message_battle_gain_drop_items
  end

  #--------------------------------------------------------------------------
  # * EXP Acquisition and Level Up Display
  #--------------------------------------------------------------------------
  alias mog_battle_hud_ex_message_battle_gain_exp gain_exp
  def gain_exp
      $game_message.position = MOG_BATTLE_HUD_EX::BATTLE_MESSAGE_POSITION
      mog_battle_hud_ex_message_battle_gain_exp
  end  

end

#==============================================================================
# ** Scene Battle
#==============================================================================
class Scene_Battle < Scene_Base

  #--------------------------------------------------------------------------
  # * Use Item
  #--------------------------------------------------------------------------      
  alias mog_monogatari_use_item use_item
  def use_item
      execute_face_animation
      mog_monogatari_use_item
  end

  #--------------------------------------------------------------------------
  # * Execute Face Animation
  #--------------------------------------------------------------------------  
  def execute_face_animation
      return if @subject.is_a?(Game_Enemy)
      @subject.face_animation = [60 ,2,0]   
  end
   
end

#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX

  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------  
  def dispose
      terminate
      dispose_layout
      dispose_layout_2
      dispose_name
      dispose_face
      dispose_hp_number
      dispose_hp_number_max
      dispose_hp_meter
      dispose_hp_icon
      dispose_hp_icon_ex
      dispose_hp_icon_number
      dispose_mp_number
      dispose_mp_number_max
      dispose_mp_meter
      dispose_mp_icon
      dispose_mp_icon_ex
      dispose_mp_icon_number
      dispose_tp_number
      dispose_tp_number_max
      dispose_tp_meter
      dispose_tp_icon
      dispose_tp_icon_ex
      dispose_tp_icon_number
      dispose_at_number
      dispose_at_number_max
      dispose_at_meter      
      dispose_lv_number
      dispose_states
  end
  
  #--------------------------------------------------------------------------
  # * Dispose Layout
  #--------------------------------------------------------------------------  
  def dispose_layout
      return if @layout == nil
      @layout.dispose
      @layout = nil
  end
  
  #--------------------------------------------------------------------------
  # * Dispose Layout 2
  #--------------------------------------------------------------------------  
  def dispose_layout_2
      return if @layout2 == nil
      @layout2.dispose
      @layout2 = nil
  end  
  
  #--------------------------------------------------------------------------
  # * Dispose Name
  #--------------------------------------------------------------------------         
  def dispose_name
      return if @name == nil
      @name.bitmap.dispose
      @name.dispose
      @name = nil
  end  
  
  #--------------------------------------------------------------------------
  # * Dispose Face
  #--------------------------------------------------------------------------        
  def dispose_face
      return if @face == nil      
      @face.bitmap.dispose if @face.bitmap != nil   
      @face.dispose
      @face = nil
      @face_image.dispose if @face_image != nil
  end  
  
  #--------------------------------------------------------------------------
  # * Dispose HP Number
  #--------------------------------------------------------------------------   
  def dispose_hp_number
      return if @hp_number == nil
      @hp_number.bitmap.dispose
      @hp_number.dispose
      @hp_number = nil
  end

  #--------------------------------------------------------------------------
  # * Dispose HP Number Max
  #--------------------------------------------------------------------------   
  def dispose_hp_number_max
      return if @hp_number2 == nil
      @hp_number2.bitmap.dispose
      @hp_number2.dispose
      @hp_number2 = nil
  end   
  
  #--------------------------------------------------------------------------
  # * Dispose HP Meter
  #--------------------------------------------------------------------------     
  def dispose_hp_meter
      return if @hp_meter == nil
      @hp_meter.bitmap.dispose
      @hp_meter.dispose
      @hp_meter = nil
  end   
  
  #--------------------------------------------------------------------------
  # * Dispose HP Icon
  #--------------------------------------------------------------------------      
  def dispose_hp_icon
      return if @hp_icon == nil
      @hp_icon.bitmap.dispose if @hp_icon.bitmap != nil
      @hp_icon.dispose
      @hp_icon = nil
  end   
  
  #--------------------------------------------------------------------------
  # * Dispose HP Icon EX
  #--------------------------------------------------------------------------      
  def dispose_hp_icon_ex
      return if @hp_icon3 == nil
      @hp_icon3.bitmap.dispose
      @hp_icon3.dispose
      @hp_icon3 = nil
  end      
  
  #--------------------------------------------------------------------------
  # * Dispose HP Icon Number
  #--------------------------------------------------------------------------  
  def dispose_hp_icon_number
      return if @hp_icon_number == nil
      @hp_icon_number.bitmap.dispose
      @hp_icon_number.dispose
      @hp_icon_number = nil
  end   
  
  #--------------------------------------------------------------------------
  # * Dispose MP Number
  #--------------------------------------------------------------------------   
  def dispose_mp_number
      return if @mp_number == nil
      @mp_number.bitmap.dispose
      @mp_number.dispose
      @mp_number = nil
  end   
  
  #--------------------------------------------------------------------------
  # * Dispose MP Number Max
  #--------------------------------------------------------------------------   
  def dispose_mp_number_max
      return if @mp_number2 == nil
      @mp_number2.bitmap.dispose
      @mp_number2.dispose
      @mp_number2 = nil
  end   
  
  #--------------------------------------------------------------------------
  # * Dispose MP Meter
  #--------------------------------------------------------------------------     
  def dispose_mp_meter
      return if @mp_meter == nil
      @mp_meter.bitmap.dispose
      @mp_meter.dispose
      @mp_meter = nil
  end     
  
  #--------------------------------------------------------------------------
  # * Dispose MP Icon
  #--------------------------------------------------------------------------      
  def dispose_mp_icon
      return if @mp_icon == nil
      @mp_icon.bitmap.dispose if @mp_icon.bitmap != nil
      @mp_icon.dispose
      @mp_icon = nil
  end     
  
  #--------------------------------------------------------------------------
  # * Dispose MP Icon EX
  #--------------------------------------------------------------------------      
  def dispose_mp_icon_ex
      return if @mp_icon3 == nil
      @mp_icon3.bitmap.dispose
      @mp_icon3.dispose
      @mp_icon3 = nil
  end        
  
  #--------------------------------------------------------------------------
  # * Dispose MP Icon Number
  #--------------------------------------------------------------------------  
  def dispose_mp_icon_number
      return if @mp_icon_number == nil
      @mp_icon_number.bitmap.dispose
      @mp_icon_number.dispose
      @mp_icon_number = nil
  end   
   
  #--------------------------------------------------------------------------
  # * Dispose TP Number
  #--------------------------------------------------------------------------   
  def dispose_tp_number
      return if @tp_number == nil
      @tp_number.bitmap.dispose
      @tp_number.dispose
      @tp_number = nil
  end
  
  #--------------------------------------------------------------------------
  # * Dispose TP Number Max
  #--------------------------------------------------------------------------   
  def dispose_tp_number_max
      return if @tp_number2 == nil
      @tp_number2.bitmap.dispose
      @tp_number2.dispose
      @tp_number2 = nil
  end  
  
  #--------------------------------------------------------------------------
  # * Dispose TP Meter
  #--------------------------------------------------------------------------     
  def dispose_tp_meter
      return if @tp_meter == nil
      @tp_meter.bitmap.dispose
      @tp_meter.dispose
      @tp_meter = nil
  end     
  
  #--------------------------------------------------------------------------
  # * Dispose TP Icon
  #--------------------------------------------------------------------------      
  def dispose_tp_icon
      return if @tp_icon == nil
      @tp_icon.bitmap.dispose if @tp_icon.bitmap != nil
      @tp_icon.dispose
      @tp_icon = nil
  end   
  
  #--------------------------------------------------------------------------
  # * Dispose TP Icon EX
  #--------------------------------------------------------------------------      
  def dispose_tp_icon_ex
      return if @tp_icon3 == nil
      @tp_icon3.bitmap.dispose
      @tp_icon3.dispose
      @tp_icon3 = nil
  end   
  
  #--------------------------------------------------------------------------
  # * Dispose TP Icon Number
  #--------------------------------------------------------------------------  
  def dispose_tp_icon_number
      return if @tp_icon_number == nil
      @tp_icon_number.bitmap.dispose
      @tp_icon_number.dispose
      @tp_icon_numbe = nil
  end     
  
  #--------------------------------------------------------------------------
  # * Dispose AT Number
  #--------------------------------------------------------------------------   
  def dispose_at_number
      return if @at_number == nil
      @at_number.bitmap.dispose
      @at_number.dispose
      @at_number = nil
  end

  #--------------------------------------------------------------------------
  # * Dispose AT Number Max
  #--------------------------------------------------------------------------   
  def dispose_at_number_max
      return if @at_number2 == nil
      @at_number2.bitmap.dispose
      @at_number2.dispose
      @at_number2 = nil
  end   
  
  #--------------------------------------------------------------------------
  # * Dispose AT Meter
  #--------------------------------------------------------------------------     
  def dispose_at_meter
      return if @at_meter == nil
      @at_meter.bitmap.dispose
      @at_meter.dispose
      @at_meter = nil
  end     
  
  #--------------------------------------------------------------------------
  # * Dispose Lv Number
  #--------------------------------------------------------------------------   
  def dispose_lv_number
      return if @lv_number == nil
      @lv_number.bitmap.dispose
      @lv_number.dispose
      @lv_number = nil
  end
  
  #--------------------------------------------------------------------------
  # * Dispose States
  #--------------------------------------------------------------------------      
  def dispose_states
      return if @status == nil
      @status.bitmap.dispose if @status.bitmap != nil
      @status.dispose
      @actor_status.dispose if @actor_status != nil
      @status = nil
  end
  
end

#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX

#--------------------------------------------------------------------------
# * Refresh Visible
#--------------------------------------------------------------------------  
def refresh_visible(vis)
     @layout.visible = vis if @layout
     @layout2.visible = vis if @layout2
     @name.visible = vis if @name
     @lv_number.visible = vis if @lv_number
     @status.visible = vis if @status
     @face.visible = vis if @face     
     @hp_number.visible = vis if @hp_number
     @hp_number2.visible = vis if @hp_number2
     @hp_meter.visible = vis if @hp_meter
     @hp_icon.visible = vis if @hp_icon
     @hp_icon3.visible = vis if @hp_icon3
     @hp_icon_number.visible = vis if @hp_icon_number     
     @mp_number.visible = vis if @mp_number
     @mp_number2.visible = vis if @mp_number2
     @mp_meter.visible = vis if @mp_meter
     @mp_icon.visible = vis if @mp_icon
     @mp_icon3.visible = vis if @mp_icon3
     @mp_icon_number.visible = vis if @mp_icon_number
     @tp_number.visible = vis if @tp_number
     @tp_number2.visible = vis if @tp_number2
     @tp_meter.visible = vis if @tp_meter
     @tp_icon.visible = vis if @tp_icon
     @tp_icon3.visible = vis if @tp_icon3
     @tp_icon_number.visible = vis if @tp_icon_number      
     @at_number.visible = vis if @at_number
     @at_number2.visible = vis if @at_number2
     @at_meter.visible = vis if @at_meter   
  end  
  
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------  
  def update
      return if @actor == nil
      @sprite_visible = sprite_visible?
      @sprite_visitle_wait -= 1 if @sprite_visitle_wait > 0
      update_layout ; update_layout_2 ; update_name
      update_face ; update_hp ; update_mp ; update_tp
      update_at ; update_level ; update_states
  end
  
end
if true
#==============================================================================
# +++ MOG - ATB System  (v 1.4) +++
#==============================================================================
# By Moghunter
# http://www.atelier-rgss.com/
#==============================================================================
# Sistema de batalha de turnos em tempo real.
#==============================================================================

#==============================================================================
# ● AT SYSTEM
#==============================================================================
# A velocidade de AT é baseaddo na agilidade do Battler.
# Em caso de batalhas preventivas (Preemptive) os aliados come?ar?o com AT em
# 80% e os inimigos come?ar?o com AT em 0 (Zero)
# Em batalhas surpresas (Surprise) é o inverso das batalhas preventivas.
# Em batalhas normais todos os battlers come?ar?o com AT em 40%.
#==============================================================================
# ● CAST TIME
#==============================================================================
# Para definir uma habilidade ou item com a fun??o de Cast Time basta definir
# o valor da velocidade (Speed) diferente de 0 (Zero).
#
# NOTA - N?o é possível ativar 2 ou mais habilidades com a fun??o Cast Time no
# mesmo turno. (Caso você esteja usando características de Multi Action em
# seu projeto.)
#==============================================================================
module MOG_AT_SYSTEM
  #Som quando o sistema AT estiver no maximo
  SE_ACTIVE = "Decision2"
  #Defini??o do valor de AT para ativar a a??o.(Gauge Meter).
  AT_GAUGE_METER = 5000
  # Defini??o do tipo de dura??o (Contagem/formula) de um turno.
  # Essa defini??o influência na ativa??o dos eventos de batalha.
  # (BATTLE EVENTS)
  #
  # 0 - Dura??o de um turno é um valor fixo.
  # 1 - Dura??o de um turno é multiplicado pela quantidade de batllers.
  # 2 - Dura??o de um turno é baseado na média de agilidade dos battlers.
  #
  TURN_DURATION_TYPE = 1
  # Defini??o de valor usado para calcular a dura??o de um turno.
  TURN_DURATION = 60
  # Defini??o da anima??o quando o battler usa habilidades de carregamento.
  CAST_ANIMATION = 49
  # Ativar a janela de LOG, deixe desativado se desejar uma batalha mais
  # dinamica.
  WAIT_LOG_WINDOW = false
  # Ativar a mensagem inicial com os nomes dos inimigos.
  MESSAGE_ENEMY_APPEAR = false
  # Tipo de posicionamento da Hud.
  # 0 - Posi??o fixa.
  # 1 - Posi??o baseado no valor X e Y do battler.
  AT_HUD_POSITION_TYPE = 0
  #Posi??o geral (Inicial) da Hud.
  AT_HUD_POSITION = [25,400]
  #Posi??o do medidor de AT
  AT_METER_POSITION = [29,1]
  #Defini??o da posi??o do espa?o da HUD entre os membros do grupo.
  #
  #MEMBERS_SPACE = [Horizontal ,Vertical]
  #
  MEMBERS_SPACE = [136,0]
  #Velocidade de anima??o do medidor de at, defina 0 se n?o quiser a anima??o.
  AT_METER_FLOW_SPEED = 3
  #Prioridade da Hud.
  BATTLE_HUD_Z = 0   
end

#==============================================================================
# ● Histórico (Version History)
#==============================================================================
# v 1.4 - Melhoria na velocidade da batalha.
#==============================================================================

$imported = {} if $imported.nil?
$imported[:mog_atb_system] = true

#==============================================================================
# ■ Game Temp
#==============================================================================
class Game_Temp
  
  attr_accessor :reset_turn_duration
  
  #--------------------------------------------------------------------------
  # ● Initialize
  #--------------------------------------------------------------------------         
  alias mog_atb_temp_initialize initialize
  def initialize
      @reset_turn_duration = false
      mog_atb_temp_initialize
  end

end
#==============================================================================
# ■ Game_System
#==============================================================================
class Game_System
  
  attr_accessor :at_max
  
  #--------------------------------------------------------------------------
  # ● Initialize
  #--------------------------------------------------------------------------         
  alias mog_at_system_initialize initialize
  def initialize
      @at_max = [[MOG_AT_SYSTEM::AT_GAUGE_METER, 999999].min, 100].max
      mog_at_system_initialize
  end
  
end

#==============================================================================
# ■ Game Interpreter
#==============================================================================
class Game_Interpreter
  
  #--------------------------------------------------------------------------
  # ● Reset Turn
  #--------------------------------------------------------------------------         
  def reset_turn
      $game_temp.reset_turn_duration = true
  end
  
end

#==============================================================================
# ■ Game Troop
#==============================================================================
class Game_Troop < Game_Unit
   
  #--------------------------------------------------------------------------
  # ● Set Turn
  #--------------------------------------------------------------------------         
  def set_turn(turn_value)
      @turn_count = turn_value
  end
      
end

#==============================================================================
# ■ BattleManager
#==============================================================================
module BattleManager
  
  #--------------------------------------------------------------------------
  # ● Battle Start
  #--------------------------------------------------------------------------  
  def self.battle_start
      $game_system.battle_count += 1
      $game_party.on_battle_start
      $game_troop.on_battle_start
      if MOG_AT_SYSTEM::MESSAGE_ENEMY_APPEAR
         $game_troop.enemy_names.each do |name|
         $game_message.add(sprintf(Vocab::Emerge, name))
         end
      end
      if @preemptive
         $game_message.add(sprintf(Vocab::Preemptive, $game_party.name))
      elsif @surprise
         $game_message.add(sprintf(Vocab::Surprise, $game_party.name))
      end
      wait_for_message
  end
  
  #--------------------------------------------------------------------------
  # ● Input Start
  #--------------------------------------------------------------------------
  def self.input_start_at(battler)
      if @phase != :input
         @phase = :input
         battler.make_actions
         clear_actor
      end
      return !@surprise && battler.inputable?
  end

  #--------------------------------------------------------------------------
  # ● Turn Start
  #--------------------------------------------------------------------------
  def self.turn_start
      @phase = :turn
      clear_actor
      make_action_orders
  end  
  
  #--------------------------------------------------------------------------
  # ● Preemtive Attack
  #--------------------------------------------------------------------------  
  def self.preemptive_attack
      @preemptive
  end  
  
  #--------------------------------------------------------------------------
  # ● Suprise Attack
  #--------------------------------------------------------------------------   
  def self.surprise_attack
      @surprise
  end   
  
end  

#==============================================================================
# ■ Game Action
#==============================================================================
class Game_Action  

  #--------------------------------------------------------------------------
  # ● Prepare
  #--------------------------------------------------------------------------            
  alias mog_at_system_prepare prepare
  def prepare
      mog_at_system_prepare
      set_cast_action
  end
  
  #--------------------------------------------------------------------------
  # ● Set Cast Action
  #--------------------------------------------------------------------------               
  def set_cast_action
      return if forcing
      if @item.object != nil and @item.object.speed != 0 and @subject.at_cast.empty?
         @subject.at_cast = [@item.object,@item.object.speed.abs,@target_index]
         @item.object = nil
         @subject.animation_id = MOG_AT_SYSTEM::CAST_ANIMATION
         @subject.at = 0
         BattleManager.turn_end if @subject.auto_battle?
      elsif [email protected]_cast.empty?
         if @subject.at_cast[1] == 0
            @item.object = @subject.at_cast[0]
            @target_index = @subject.at_cast[2]            
            @subject.at_cast.clear
         else   
            @item.object = nil
         end
      end  
  end  
  
end

#==============================================================================
# ■ Game Battler Base
#==============================================================================
class Game_BattlerBase  
  
  attr_accessor :hidden
  
  #--------------------------------------------------------------------------
  # ● Inputable?
  #--------------------------------------------------------------------------            
  def inputable?
      normal? && !auto_battle? && self.at == $game_system.at_max
  end
  
end

#==============================================================================
# ■ Game_Battler
#==============================================================================
class Game_Battler < Game_BattlerBase
  
   attr_accessor :at
   attr_accessor :at_cast
   attr_accessor :at_turn_duration
   attr_accessor :at_action
   attr_accessor :max_at
   
  #--------------------------------------------------------------------------
  # ● Initialize
  #--------------------------------------------------------------------------      
   alias mog_at_system_initialize initialize
   def initialize
       mog_at_system_initialize
       @at = 0
       @at_cast = []
       @at_cast_selectable = true
       @at_turn_duration = 0
       @at_action = nil      
       @wait_motion = $imported[:mog_battler_motion] != nil ? true : false
   end
     
  #--------------------------------------------------------------------------
  # ● At
  #--------------------------------------------------------------------------         
   def at
       return [[@at, max_at].min, 0].max
   end  
   
  #--------------------------------------------------------------------------
  # ● Max AT
  #--------------------------------------------------------------------------         
   def max_at
       return $game_system.at_max
   end   
   
  #--------------------------------------------------------------------------
  # ● Max AT?
  #--------------------------------------------------------------------------         
   def max_at?
       self.at >= max_at
   end
   
  #--------------------------------------------------------------------------
  # ● Added New State
  #--------------------------------------------------------------------------  
  alias mog_at_system_add_new_state add_new_state
  def add_new_state(state_id)
      mog_at_system_add_new_state(state_id)
      if restriction >= 4
         self.at_cast.clear
         self.at -= 1
         self.at = 0 if self.hp == 0
      end   
  end   
  
  #--------------------------------------------------------------------------
  # ● can AT?
  #--------------------------------------------------------------------------   
  def can_upd_at?
      return false if restriction >= 4
      return false if self.hp == 0
      return false if !self.at_cast.empty?
      return false if self.at_action != nil
      return false if self.hidden
      return false if @wait_motion && $game_temp.battler_in_motion
      return true
  end
  
end

#==============================================================================
# ■ Game Enemy
#==============================================================================
class Game_Enemy < Game_Battler
  
  #--------------------------------------------------------------------------
  # ● Tranform
  #--------------------------------------------------------------------------  
   alias mog_at_system_transform transform
   def transform(enemy_id)
       mog_at_system_transform(enemy_id)
       self.at = 0
       self.at_cast.clear
   end
end   

if !MOG_AT_SYSTEM::WAIT_LOG_WINDOW
#==============================================================================
# ■ BattleManager
#==============================================================================
class Window_BattleLog < Window_Selectable

  #--------------------------------------------------------------------------
  # ● Refresh
  #--------------------------------------------------------------------------   
  def refresh
  end  

  #--------------------------------------------------------------------------
  # ● Message Speed
  #--------------------------------------------------------------------------   
  def message_speed
      return 5
  end

  #--------------------------------------------------------------------------
  # * Wait for Effect
  #--------------------------------------------------------------------------
  def wait_for_effect
      return false
  end  
  
end

end

#==============================================================================
# ■ Scene Battle
#==============================================================================
class Scene_Battle < Scene_Base
  include MOG_AT_SYSTEM
  
  #--------------------------------------------------------------------------
  # ● AT Wait
  #--------------------------------------------------------------------------         
  alias mog_at_system_start start
  def start
      reset_at_parameter  
      mog_at_system_start
  end  
   
  #--------------------------------------------------------------------------
  # ● Battle Start
  #--------------------------------------------------------------------------
  def battle_start
      BattleManager.battle_start
      process_event
      set_turn_duration
  end
   
  #--------------------------------------------------------------------------
  # ● Reset AT Parameter
  #--------------------------------------------------------------------------  
  def reset_at_parameter
      return if @at_phase != nil
      $game_temp.reset_turn_duration = false
      @at_phase = 0
      nt = $game_system.at_max * 30 / 100
      st = $game_system.at_max * 20 / 100      
      pt = $game_system.at_max * 65 / 100
      all_battle_members.each do |battler|
          n_at = rand(nt)
          p_at = pt + rand(nt)
          s_at = rand(st)        
          if BattleManager.preemptive_attack
             battler.at = p_at if battler.is_a?(Game_Actor)
             battler.at = s_at if battler.is_a?(Game_Enemy)
          elsif BattleManager.surprise_attack   
             battler.at = p_at if battler.is_a?(Game_Enemy)
             battler.at = s_at if battler.is_a?(Game_Actor)
          else   
             battler.at = n_at
          end
          if battler.at >= $game_system.at_max
             battler.at = $game_system.at_max - 1
          end
          battler.at_cast.clear
        end
  end

  #--------------------------------------------------------------------------
  # ● Set Turn Duration
  #--------------------------------------------------------------------------
  def set_turn_duration
      max_battlers = all_battle_members.size > 0 ? all_battle_members.size : 1
      case TURN_DURATION_TYPE
        when 1
           n  = TURN_DURATION * max_battlers
        when 2
           turn_sp = 0
           all_battle_members.each do |battler|
               turn_sp += battler.agi
           end  
           n = TURN_DURATION + (turn_sp / max_battlers)
        else
           n = TURN_DURATION
      end
      turn_time_max = [[n, 9999].min, 120].max
      @turn_duration = [0, turn_time_max]
      if @status_window != nil
         @status_window.open
      end   
  end   
  
  #--------------------------------------------------------------------------
  # ● Turn End
  #--------------------------------------------------------------------------
  def turn_end
      @at_phase = 0
      all_battle_members.each do |battler|
         if battler.max_at?
            battler.at = 0
            refresh_status
            @log_window.display_auto_affected_status(battler)
            @log_window.wait_and_clear
         end
      end
      BattleManager.turn_end
  end
   
  #--------------------------------------------------------------------------
  # ● Update Turn Duration
  #--------------------------------------------------------------------------            
  def update_turn_duration
      return if @turn_duration == nil or @turn_duration[0] == nil
      update_force_reset_turn_duration if $game_temp.reset_turn_duration
      @turn_duration[0] += 1
      if @turn_duration[0] >= @turn_duration[1]
         @turn_duration[0] = 0
         $game_troop.increase_turn
         process_event
         check_states_effect_turn
      end  
  end
  
  #--------------------------------------------------------------------------
  # ● Update Force Reset Turn Duration
  #--------------------------------------------------------------------------            
  def update_force_reset_turn_duration
      $game_temp.reset_turn_duration = false
      @turn_duration[0] = 0
      $game_troop.set_turn(0)
  end
   
  #--------------------------------------------------------------------------
  # ● Check States Effect Turn
  #--------------------------------------------------------------------------               
  def check_states_effect_turn
      all_battle_members.each do |battler|  
          battler.on_turn_end if battler.restriction >= 4
      end  
  end  
  
  #--------------------------------------------------------------------------
  # ● Update AT System
  #--------------------------------------------------------------------------           
  def update_at_system      
      reset_at_parameter if @at_phase == nil
      set_turn_duration if @turn_duration == nil
      return if !can_update_at?
      update_turn_duration
      all_battle_members.each do |battler|
          update_battler_turn_duration(battler)
          if !battler.at_cast.empty?
             battler.at_cast[1] -= 1
             if battler.at_cast[1] <= 0
                execute_at_cast(battler)
                break
             end
          else
             battler.at += battler.agi unless !battler.can_upd_at?
          end   
          if battler.max_at?
             battler.on_turn_end
             update_at_actor(battler)
             update_at_enemy(battler)
             battler.current_action.prepare if battler.current_action
             if battler.at_cast.empty?
                @at_phase = 1
                turn_start if battler.is_a?(Game_Enemy)
             end            
             break
          end   
      end  
  end
   
  #--------------------------------------------------------------------------
  # ● Update Battler Turn Duration
  #--------------------------------------------------------------------------            
  def update_battler_turn_duration(battler)
      if battler.restriction >= 4
         battler.at_turn_duration += 1
         if battler.at_turn_duration >= $game_system.at_max
            battler.on_turn_end
            battler.at_turn_duration = 0
         end   
      else   
         battler.at_turn_duration = 0
      end  
  end  
  
  #--------------------------------------------------------------------------
  # ● Execute AT CAST
  #--------------------------------------------------------------------------            
  def execute_at_cast(battler)
      @subject = battler
      battler.make_actions  
      turn_start
  end  
  
  #--------------------------------------------------------------------------
  # ● Update AT Actor
  #--------------------------------------------------------------------------            
  def update_at_actor(battler)   
      return if !battler.is_a?(Game_Actor)
      Audio.se_play("Audio/SE/" + SE_ACTIVE,100,100)  
      start_party_command_selection_at(battler)
  end
  
  #--------------------------------------------------------------------------
  # ● Update AT Enemy
  #--------------------------------------------------------------------------            
  def update_at_enemy(battler)   
      return if !battler.is_a?(Game_Enemy)
      battler.make_actions
  end   
  
  #--------------------------------------------------------------------------
  # ● Can Update AT
  #--------------------------------------------------------------------------            
  def can_update_at?
      return false if $game_troop.interpreter.running?
      return false if BattleManager.action_forced?
      return false if @at_phase != 0
      return false if $game_message.visible
      return false if BattleManager.in_turn?
      return true
  end   
  
  #--------------------------------------------------------------------------
  # ● Star Party Command Selection at
  #--------------------------------------------------------------------------
  def start_party_command_selection_at(battler)
      unless scene_changing?
         refresh_status
         @status_window.unselect
         @status_window.open
         if BattleManager.input_start_at(battler)
            @actor_command_window.close
            next_command
         else
           turn_start
         end
      end
  end  
  
  #--------------------------------------------------------------------------
  # ● Update Basic
  #--------------------------------------------------------------------------        
  alias mog_at_system_update_basic update_basic
  def update_basic
      mog_at_system_update_basic
      update_at_system
      update_party_command
  end
  
  #--------------------------------------------------------------------------
  # ● Update Party Command
  #--------------------------------------------------------------------------      
  def update_party_command
      return if !@party_command_window.active
      return if !@actor_command_window.visible
      return if $game_message.visible
      if Input.trigger?(:B)
         next_command
         Sound.play_cancel
         @party_command_window.active = false
      end  
  end
     
end

unless $imported[:mog_battle_hud_ex]

#==============================================================================
# ■ Game Temp
#==============================================================================
class Game_Temp
  
  attr_accessor :cache_at_meter
  
  #--------------------------------------------------------------------------
  # ● Initialize
  #--------------------------------------------------------------------------      
  alias mog_at_meter_initialize initialize
  def initialize
      mog_at_meter_initialize
      cache_atmeter
  end
  
  #--------------------------------------------------------------------------
  # ● Cache ATmeter
  #--------------------------------------------------------------------------      
  def cache_atmeter
      @cache_at_meter = []
      @cache_at_meter.push(Cache.system("Battle_AT_Meter"))
      @cache_at_meter.push(Cache.system("Battle_AT_Layout"))
  end
  
end

#==============================================================================
# ■ AT Meter
#==============================================================================
class AT_Meter
  
  include MOG_AT_SYSTEM
  
  #--------------------------------------------------------------------------
  # ● Initialize
  #--------------------------------------------------------------------------   
  def initialize(actor)
      @actor = actor
      @flow_speed = 0
      if AT_HUD_POSITION_TYPE == 1 and @actor.use_sprite?
         @x = AT_HUD_POSITION[0] +  @actor.screen_x rescue 0
         @y = AT_HUD_POSITION[1] +  @actor.screnn_y rescue 0
      else   
         @x = AT_HUD_POSITION[0] + (MEMBERS_SPACE[0] * @actor.index)
         @y = AT_HUD_POSITION[1] + (MEMBERS_SPACE[1] * @actor.index)        
      end
      pre_cache
      create_layout
      create_at_meter
  end
  
  #--------------------------------------------------------------------------
  # ● Pre Cache
  #--------------------------------------------------------------------------      
  def pre_cache
      @meter = $game_temp.cache_at_meter[0]
      @meter_cw = @meter.width / 3
      @meter_ch = @meter.height / 3
  end
  
  #--------------------------------------------------------------------------
  # ● Create Layout
  #--------------------------------------------------------------------------      
  def create_layout
      @layout = Sprite.new
      @layout.bitmap = $game_temp.cache_at_meter[1]
      @layout.z = BATTLE_HUD_Z
      @layout.x = @x
      @layout.y = @y
  end
  
  #--------------------------------------------------------------------------
  # ● Create AT Meter
  #--------------------------------------------------------------------------      
  def create_at_meter
      @at_meter = Sprite.new
      @at_meter.bitmap = Bitmap.new(@meter_cw,@meter_ch)
      @at_meter.z =  BATTLE_HUD_Z + 50
      @at_meter.x = @x + AT_METER_POSITION[0]
      @at_meter.y = @y + AT_METER_POSITION[1]
      @at_flow = rand(@meter_cw * 2)
      at_flow_update
  end  
  
  #--------------------------------------------------------------------------
  # ● Dispose
  #--------------------------------------------------------------------------   
  def dispose
      return if @layout == nil
      @layout.dispose
      @layout = nil
      @at_meter.bitmap.dispose
      @at_meter.dispose
  end  
  
  #--------------------------------------------------------------------------
  # ● Update
  #--------------------------------------------------------------------------  
  def update
      return if @layout == nil
      at_position
      @flow_speed += 1
      if @flow_speed >= AT_METER_FLOW_SPEED
         @flow_speed = 0
         at_flow_update
      end
  end
  
  #--------------------------------------------------------------------------
  # ● Update
  #--------------------------------------------------------------------------   
  def at_position
      return unless AT_HUD_POSITION_TYPE == 1 and @actor.use_sprite?
      @x = AT_HUD_POSITION[0] +  @actor.screen_x rescue 0
      @y = AT_HUD_POSITION[1] +  @actor.screnn_y rescue 0
      @layout.x = @x
      @layout.y = @y
      @at_meter.x = @x + AT_METER_POSITION[0]
      @at_meter.y = @y + AT_METER_POSITION[1]
  end
   
  #--------------------------------------------------------------------------
  # ● AT Flow Update
  #--------------------------------------------------------------------------
  def at_flow_update
      @at_meter.bitmap.clear
      if [email protected]_cast.empty?
         max_cast = @actor.at_cast[0].speed.abs != 0 ? @actor.at_cast[0].speed.abs : 1
         at_width = @meter_cw * @actor.at_cast[1] / max_cast
         ch = @meter_ch * 2
      else
         at_width = @meter_cw * @actor.at / $game_system.at_max
         ch = @actor.at < $game_system.at_max ? 0 : @meter_ch
      end  
      src_rect = Rect.new(@at_flow, ch,at_width, @meter_ch)
      @at_meter.bitmap.blt(0,0, @meter, src_rect)
      @at_flow += AT_METER_FLOW_SPEED
      @at_flow = 0 if @at_flow >=  @meter_cw * 2      
  end   
  
end  

#==============================================================================
# ■ Spriteset Battle
#==============================================================================
class Spriteset_Battle
  
  #--------------------------------------------------------------------------
  # ● Initialize
  #--------------------------------------------------------------------------           
  alias mog_at_system_initialize initialize
  def initialize
      mog_at_system_initialize
      create_at_meter
  end  
  
  #--------------------------------------------------------------------------
  # ● Create AT Meter
  #--------------------------------------------------------------------------            
  def create_at_meter     
      @at_meter = []
      for i in $game_party.battle_members
          @at_meter.push(AT_Meter.new(i))
      end      
  end  
  
  #--------------------------------------------------------------------------
  # ● Dispose
  #--------------------------------------------------------------------------      
  alias mog_at_system_dispose dispose
  def dispose
      mog_at_system_dispose
      dispose_at_meter
  end
   
  #--------------------------------------------------------------------------
  # ● Dispose AT Meter
  #--------------------------------------------------------------------------        
  def dispose_at_meter
      return if @at_meter == nil
      @at_meter.each {|sprite| sprite.dispose }
      @at_meter = nil
  end  
  
  #--------------------------------------------------------------------------
  # ● Update
  #--------------------------------------------------------------------------        
  alias mog_at_system_update update
  def update
      mog_at_system_update
      update_at_meter
  end  
  
  #--------------------------------------------------------------------------
  # ● Update AT Meter
  #--------------------------------------------------------------------------         
  def update_at_meter
      return if @at_meter == nil
      @at_meter.each {|sprite| sprite.update }
  end  
  
end

end

end
#==============================================================================
# +++ MOG - Ayesha AT Gauge (ver 1.3) +++
#==============================================================================
# By Moghunter
# http://www.atelier-rgss.com
#==============================================================================
# Adiciona um medidor animado de AT, incluindo os ícones dos respectivos
# battlers.
#==============================================================================
# Arquivos necessários.
#
# ATB_Layout.png
# ATB_Enemy.png
# ATB_Actor.png
#
# Coloque as imagens na pasta
#
#            /Graphics/Ayesha_ATB/
#
#==============================================================================
# Opcional - ícones específicos dos battlers.
#==============================================================================
# Nomeie os arquivos das seguinte forma.
#
# Actor_ + ID.png
# Enemy_ + ID.png
#
#==============================================================================
# Compatível com :
#
# - MOG ATB System (v 1.0)
# - Victor's Active Time Battle (1.05)
# - C Winter's Active Time Battle (1.62)
#
#==============================================================================
# Histórico
#==============================================================================
# v1.3 - Melhoria no efeito de fade ao terminar a batalha.
# v1.2 - Op??o de definir a posi??o Z baseado na altura do sprite.
# v1.1 - Melhoria na transparência inicial.
#      - Op??o de ajustar o valor Z baseado na posi??o do ícone.
#==============================================================================
module AYESHA_ATB_GAUGE
  #Defini??o do tipo de medidor. (Nota - A imagem original deve ser na vertical)
  # 0 - Vertical  /  1 - Horizontal
  GAUGE_TYPE = 0
  #Posi??o geral do medidor
  LAYOUT_POS = [480,0]
  #Posi??o do ícones dos battlers.
  POINT_POS = [2,50]
  #Posi??o do ícone quando o battler estiver ativo.
  CENTER_POS = [11,9]
  #Tamanho do medidor. [Altura e largura]
  GAUGE_SIZE = [170,31]
  #Posi??o Z do sprite.
  SPRITE_Z = 51
  #Definir a posi??o z do sprite baseado na altura.
  Z_FIX = false
end

$imported = {} if $imported.nil?
$imported[:mog_ayesha_at_gauge] = true

#==============================================================================
# ■ Cache
#==============================================================================
module Cache

  #--------------------------------------------------------------------------
  # * Hud
  #--------------------------------------------------------------------------
  def self.ayesha_atb(filename)
   
      load_bitmap("Graphics/Ayesha_ATB/", filename)
#~       , filename
  end

end

#==============================================================================
# ■ Game BattlerBase
#==============================================================================
class Game_BattlerBase
   attr_accessor :hidden
end

#==============================================================================
# ■ Game Temp
#==============================================================================
class Game_Temp
  attr_accessor :ay_gauge_data
  
  #--------------------------------------------------------------------------
  # ● Initialize
  #--------------------------------------------------------------------------      
  alias mog_ayesha_gauge_initialize initialize
  def initialize
      @ay_gauge_data = [false,false,[0,0]]
      mog_ayesha_gauge_initialize
  end
  
end

#==============================================================================
# ■ Game System
#==============================================================================
class Game_System
  attr_accessor :ay_gauge_type
  
  #--------------------------------------------------------------------------
  # ● Initialize
  #--------------------------------------------------------------------------      
  alias mog_ayesha_gauge_sys_initialize initialize
  def initialize
      @ay_gauge_type = AYESHA_ATB_GAUGE::GAUGE_TYPE
      mog_ayesha_gauge_sys_initialize
  end  
  
end

#===============================================================================
# ■ Spriteset_Battle
#===============================================================================
class Spriteset_Battle
  include AYESHA_ATB_GAUGE
  #--------------------------------------------------------------------------
  # ● Update Battle Start
  #--------------------------------------------------------------------------        
  alias mog_ayesha_atb_initialize initialize
  def initialize
      mog_ayesha_atb_initialize
      create_ayesha_atb
  end  
  
  #--------------------------------------------------------------------------
  # ● Dispose
  #--------------------------------------------------------------------------  
  alias mog_ayesha_atb_dispose dispose
  def dispose
      dispose_ayesha_atb
      mog_ayesha_atb_dispose      
  end
  
  #--------------------------------------------------------------------------
  # ● Update
  #--------------------------------------------------------------------------         
  
alias mog_ayesha_atb_update update
  def update
      mog_ayesha_atb_update
      update_ayesha_atb
    end  
  #--------------------------------------------------------------------------
  # ● Create Ayesha ATB
  #--------------------------------------------------------------------------   
  def create_ayesha_atb
      return if @schala_atb != nil
      view = Z_FIX ? @viewport1 : nil
      @ayesha_atb = Ayesha_ATB_Gauge.new(view)
  end
  
  #--------------------------------------------------------------------------
  # ● Dispose ayesha ATB
  #--------------------------------------------------------------------------   
  def dispose_ayesha_atb
      return if @ayesha_atb == nil
      @ayesha_atb.dispose ; @ayesha_atb = nil
  end
  
  #--------------------------------------------------------------------------
  # ● Update Schala ATB
  #--------------------------------------------------------------------------   
  def update_ayesha_atb
      return if @ayesha_atb == nil      
      @ayesha_atb.update
  end
  
end

#==============================================================================
# ** Game Interpreter
#==============================================================================
class Game_Interpreter
  
#--------------------------------------------------------------------------
# * Command_129
#--------------------------------------------------------------------------
alias mog_ayesha_gauge_command_129 command_129
def command_129
     mog_ayesha_gauge_command_129
     $game_temp.ay_gauge_data[1] = true if SceneManager.scene_is?(Scene_Battle)
end
  
end

#==============================================================================
# ■ Ayesha ATB Gauge
#==============================================================================
class Ayesha_ATB_Gauge
  include AYESHA_ATB_GAUGE
  
  #--------------------------------------------------------------------------
  # ● Initialize
  #--------------------------------------------------------------------------            
  def initialize(viewport = nil)
      $game_temp.ay_gauge_data[0] = false ; @faces = [] ; create_sprites(viewport)
  end

  #--------------------------------------------------------------------------
  # ● Create Sprites
  #--------------------------------------------------------------------------            
  def create_sprites(viewport)
      return if $game_party.members.size == 0 or $game_troop.members.size == 0
      @layout = Sprite.new ; @layout.bitmap = Cache.ayesha_atb("ATB_Layout")
      @layout.z = SPRITE_Z ; @layout.opacity = 0 ; @layout.viewport = viewport
      $game_temp.ay_gauge_data[2] = [@layout.bitmap.width, @layout.height]
      @layout.x = LAYOUT_POS[0] + @layout.ox+100
      @layout.y = LAYOUT_POS[1] + @layout.oy
     (@layout.angle = 270 ; @layout.x += @layout.bitmap.width) if $game_system.ay_gauge_type == 1
      battlers.each do |i| @faces.push(Ayesha_Sprite_Icon.new(viewport,i)) end
  end   
      
  #--------------------------------------------------------------------------
  # ● Initialize
  #--------------------------------------------------------------------------
  def battlers
      return $game_troop.members + $game_party.battle_members
  end
  
  #--------------------------------------------------------------------------
  # ● Dispose
  #--------------------------------------------------------------------------
  def dispose
      @faces.each {|sprite| sprite.dipose_schala_point }
      return if @layout == nil
      @layout.bitmap.dispose ; @layout.dispose ; @layout = nil
  end
  
  #--------------------------------------------------------------------------
  # ● Update
  #--------------------------------------------------------------------------  
  def update
      return if @layout == nil
      @faces.each {|sprite| sprite.update_schala_point }
      @layout.opacity += $game_temp.ay_gauge_data[0] ? - 10 : 10
      @layout.visible = !$game_message.visible
      refresh_ayesha_gauge if $game_temp.ay_gauge_data[1]
  end
  
  #--------------------------------------------------------------------------
  # ● Refresh Ayesha Gauge
  #--------------------------------------------------------------------------   
  def refresh_ayesha_gauge
      $game_temp.ay_gauge_data[1] = false ; dispose ; create_sprites
  end
  
end

#=============================================================================
# ■ Ayesha Sprite Icon
#==============================================================================
class Ayesha_Sprite_Icon < Sprite
  include AYESHA_ATB_GAUGE
  
  #--------------------------------------------------------------------------
  # ● Initialize
  #--------------------------------------------------------------------------              
  def initialize(viewport = nil,battler)
      super(viewport)
      @target = battler ; @gauge_size = GAUGE_SIZE[0]
      return if @target == nil
      create_bitmap
      self.ox = @cw / 2 ; self.oy = @ch / 2 ; self.x = 0 ; self.y = 0
      self.z = @sz ; self.opacity = 0 ; @pos_y = 0
      @gy = $game_temp.ay_gauge_data[2][0] - self.oy
      if $game_system.ay_gauge_type == 1
         @x2 = self.ox + LAYOUT_POS[0] + POINT_POS[0] - (@gauge_size + 5)+100
         @y2 = self.oy + LAYOUT_POS[1] + POINT_POS[1] - @gy
         @y2 += GAUGE_SIZE[1] if @target.is_a?(Game_Enemy)      
      else  
         @x2 = self.ox + LAYOUT_POS[0] + POINT_POS[0]+100
         @y2 = self.oy + LAYOUT_POS[1] + POINT_POS[1] + @gauge_size
         @x2 += GAUGE_SIZE[1] if @target.is_a?(Game_Enemy)
      end
      @x = 0 ; @y = 0 ; @cast_time = [false,0] ; @wait_fade = 2
      @center = [LAYOUT_POS[0] + self.ox + 11,LAYOUT_POS[1] + self.oy + 9+100]
      catb = ATB::MAX_AP rescue nil ; @ccwinter_atb = true if catb != nil  
      @atb = actor_at ; create_charge
  end

  #--------------------------------------------------------------------------
  # ● Create Charge
  #--------------------------------------------------------------------------              
  def create_charge
      @charge = Sprite.new ; @charge.bitmap = Cache.ayesha_atb("Cast") rescue nil
      update_charge
  end

  #--------------------------------------------------------------------------
  # ● Update Charge
  #--------------------------------------------------------------------------              
  def update_charge
      @charge.z = self.z ; @charge.x = self.x ; @charge.y = self.y
      @charge.opacity = self.opacity
  end   
  
  #--------------------------------------------------------------------------
  # ● Create Bitmap
  #--------------------------------------------------------------------------            
  def create_bitmap
      @face_index = [0,0] ; @s_bitmap = []
      b_nm = @target.is_a?(Game_Actor) ? "Actor" : "Enemy"
      b_id = @target.is_a?(Game_Actor) ? @target.id : @target.enemy_id
      @s_bitmap.push(Cache.ayesha_atb(b_nm.to_s + "_" + b_id.to_s)) rescue nil
      @s_bitmap.push(Cache.ayesha_atb(b_nm.to_s + "_ATB")) if @s_bitmap[0] == nil rescue nil
      @s_bitmap[0] = Bitmap.new(32,32) if @s_bitmap[0] == nil
      @s_bitmap.push(Cache.ayesha_atb(b_nm.to_s + "_" + b_id.to_s + "B")) rescue nil
      @cw = @s_bitmap[0].width ; @ch = @s_bitmap[0].height ; @sz = SPRITE_Z + 1
      self.bitmap = @s_bitmap[0] ; refresh_bitmap
  end

  #--------------------------------------------------------------------------
  # ● Refresh Bitmap
  #--------------------------------------------------------------------------            
  def refresh_bitmap
      @face_index[1] = @face_index[0] ; self.bitmap = @s_bitmap[@face_index[0]]
      self.zoom_x = 1.00
      @center = [LAYOUT_POS[0] + self.ox + CENTER_POS[0]+100,LAYOUT_POS[1] + self.oy + CENTER_POS[1]]
      if self.bitmap == nil
         self.bitmap = @s_bitmap[0] ; self.zoom_x = 1.4
         @center = [LAYOUT_POS[0] + self.ox + CENTER_POS[0] + 6+100,LAYOUT_POS[1] + self.oy + CENTER_POS[1] + 7]
      end
  end
  
  #--------------------------------------------------------------------------
  # ● Dispose Schala Point
  #--------------------------------------------------------------------------            
  def dipose_schala_point
      return if self.bitmap == nil or self.bitmap.disposed?
      self.bitmap.dispose ; self.bitmap = nil ; dispose_charge
  end

  #--------------------------------------------------------------------------
  # ● Dispose Charge
  #--------------------------------------------------------------------------              
  def dispose_charge
      @charge.bitmap.dispose if @charge.bitmap != nil
      @charge.dispose
  end  
  
  #--------------------------------------------------------------------------
  # ● Update Schala Point
  #--------------------------------------------------------------------------              
  def update_schala_point
      return if self.bitmap == nil or self.bitmap.disposed? or !self.visible
      if can_update_atb?
         self.opacity += 10 unless @wait_fade > 0; update_atb
      else
         self.opacity -= 10 ; check_all_dead? if self.opacity == 0
         self.zoom_x = 1.00 ; @cast_time[0] = false ; @wait_fade = 2
      end
      execute_move(0,self.x,@x) ; execute_move(1,self.y,@y)      
      self.zoom_y = self.zoom_x ; self.opacity = 0 if $game_message.visible
      update_charge ; @wait_fade -= 1 if @wait_fade > 0
  end
  
  #--------------------------------------------------------------------------
  # ● Check All Dead?
  #--------------------------------------------------------------------------              
  def check_all_dead?
      return if [email protected]_a?(Game_Enemy)
      self.visible = false ; $game_temp.ay_gauge_data[0] = true
      $game_troop.members.each {|b| $game_temp.ay_gauge_data[0] = false if !b.dead?}
  end
  
  #--------------------------------------------------------------------------
  # ● Can Update ATB
  #--------------------------------------------------------------------------  
  def can_update_atb?
      return false if @target == nil or @target.dead? or @target.hidden
      return false if $game_temp.ay_gauge_data[0]
      return true
  end
  
  #--------------------------------------------------------------------------
  # ● Update ATB
  #--------------------------------------------------------------------------               
  def update_atb
      update_atb_type
      if atb_max?
         @x = @center[0]; @y = @center[1] ; @face_index[0] = 1
      else
        if $game_system.ay_gauge_type == 1
           if actor_cast?
              @x = @x2 + gauge_cast - (@gauge_size * @atb / @atb_max) ; @y = @y2
           else   
              @x = @x2 + @gauge_size * @atb / @atb_max ; @y = @y2
           end  
           self.z = @sz + @x if Z_FIX
        else
           if actor_cast?
              @y = @y2 - gauge_cast + (@gauge_size * @atb / @atb_max) ; @x = @x2
           else   
              @y = @y2 - @gauge_size * @atb / @atb_max ; @x = @x2
           end
           self.z = @sz + (@gauge_size - @y) if Z_FIX
        end   
        @face_index[0] = 0 ; self.zoom_x = 1.00
      end      
      refresh_bitmap if @face_index[0] != @face_index[1]
  end

  #--------------------------------------------------------------------------
  # ● ATB Max
  #--------------------------------------------------------------------------                  
  def atb_max?
      return true if @atb.abs >= @atb_max.abs
      return true if @cast_time[1] > 0
      return false
  end
   
  #--------------------------------------------------------------------------
  # ● Update ATB Type
  #--------------------------------------------------------------------------                  
  def update_atb_type
      if actor_cast?
         @atb_max = actor_max_cast ; @atb = actor_cast ; @cast_time = [true,0]
         @charge.visible = true
      else
         @atb_max = actor_max_at ; @atb = actor_at
         @cast_time[1] = cast_wait_time if @cast_time[0] ; @cast_time[1] -= 1 if @cast_time[1] > 0
         @cast_time[0] = false ; @charge.visible = false unless @cast_time[1] > 55
      end
      @atb_max = 1 if @atb_max == 0  
  end

  #--------------------------------------------------------------------------
  # ● Execute Move
  #--------------------------------------------------------------------------      
  def execute_move(type,cp,np)
      sp = 5 + ((cp - np).abs / 20)
      if cp > np
         cp -= sp ; cp = np if cp < np
      elsif cp < np
         cp += sp ; cp = np if cp > np
      end     
      self.x = cp if type == 0 ; self.y = cp if type == 1
  end   

  #--------------------------------------------------------------------------
  # * AT
  #--------------------------------------------------------------------------  
  def actor_at
      return @target.at if $imported[:mog_atb_system]
      return @target.atb if $imported[:ve_active_time_battle]
      return @target.catb_value if $imported["YSA-CATB"]
      return @target.ap if @ccwinter_atb != nil
      return 0
  end

  #--------------------------------------------------------------------------
  # * Max AT
  #--------------------------------------------------------------------------  
  def actor_max_at
      return $game_system.at_max if $imported[:mog_atb_system]
      return @target.max_atb if $imported[:ve_active_time_battle]
      return @target.max_atb if $imported["YSA-CATB"]
      return ATB::MAX_AP if @ccwinter_atb != nil
      return 1
  end

  #--------------------------------------------------------------------------
  # ● Actor Cast
  #--------------------------------------------------------------------------            
  def actor_cast
      return @target.at_cast[1] rescue nil if $imported[:mog_atb_system]
      return [email protected] if $imported[:ve_active_time_battle]
      return @target.chant_count rescue 0 if @ccwinter_atb != nil
      return 0
  end

  #--------------------------------------------------------------------------
  # ● Actor Max Cast
  #--------------------------------------------------------------------------            
  def actor_max_cast
      return @target.at_cast[0].speed.abs if $imported[:mog_atb_system]
      return @target.max_atb if $imported[:ve_active_time_battle]
      return [email protected]_chant_count rescue 1 if @ccwinter_atb != nil
      return 1
  end

  #--------------------------------------------------------------------------
  # ● Actor Max Cast
  #--------------------------------------------------------------------------            
  def gauge_cast
      return @gauge_size if $imported[:mog_atb_system]
      return 0
  end
  
  #--------------------------------------------------------------------------
  # ● Actor Cast?
  #--------------------------------------------------------------------------            
  def actor_cast?
      if $imported[:mog_atb_system]
         return true if [email protected]_cast.empty? rescue false
      end   
      if $imported[:ve_active_time_battle]
         return true if @target.cast_action? rescue false
      end      
      if @ccwinter_atb
         return true if @target.chanting? rescue false
      end
      return false
  end   
  
  #--------------------------------------------------------------------------
  # ● Cast Wait Time
  #--------------------------------------------------------------------------            
  def cast_wait_time
      return 10 if @ccwinter_atb
      return 60
  end
  
end

#==============================================================================
# ■ Game_Battler
#==============================================================================
class Game_Battler < Game_BattlerBase     
   attr_accessor :chant_count
   attr_accessor :max_chant_count
end

# ===========================================================================
# ◆ A1 Scripts ◆
#    A1共通処理(RGSS2/RGSS3共用)
#
# バージョン   : 4.50 (2012/01/26)
# 作者         : A1
# URL     : http://a1tktk.web.fc2.com/
# ---------------------------------------------------------------------------
# 更新履歴   :2011/11/11 Ver1.00 新規作成
#        :2011/12/22 Ver2.00 RGSS3用と同様の処理に変更
#        :2011/12/30 Ver2.10 RGSS3用メソッドを追加
#        :2011/12/30 Ver3.00 RGSS3用共通処理と統合
#        :2011/12/31 Ver3.10 マップチップサーチの仕様を変更
#        :2011/12/31 Ver3.10 拡張通行判定を追加
#        :2012/01/01 Ver3.11 クラス名の取得処理を追加
#              :2012/01/02 Ver3.20 配列を考慮したsplit処理を追加
#              :2012/01/02 Ver3.20 配列の全ての要素を整数にする処理を追加
#              :2012/01/02 Ver3.30 注釈の処理の仕様を変更
#              :2012/01/02 Ver3.40 「前のイベントコマンドの取得」を追加
#              :2012/01/03 Ver3.50 「フレーム更新」を追加
#              :2012/01/04 Ver3.60 「指定のウィンドウが開いている間ウェイト」追加
#              :2012/01/04 Ver3.70 RGSS2用処理見直し
#              :2012/01/05 Ver3.80 注釈文字列にエスケープコマンド対応
#              :2012/01/05 Ver3.80 多次元配列を考慮したsplit処理を追加
#              :2012/01/05 Ver3.80 注釈にスクリプト処理機能を追加
#              :2012/01/10 Ver3.90 文字縁取り描画を追加
#              :2012/01/11 Ver4.00 テキストビットマップのキャッシュを追加
#              :2012/01/13 Ver4.01 「タイルセットの変更」ができなくなる不具合を修正
#              :2012/01/14 Ver4.10 split処理を強化
#              :2012/01/14 Ver4.20 空白を含む注釈コマンドに対応
#              :2012/01/14 Ver4.21 split処理の不具合を修正
#              :2012/01/21 Ver4.30 メモの内容を取得する関数を追加
#              :2012/01/24 Ver4.40 メモの内容を取得する関数を追加
#              :2012/01/24 Ver4.50 メモの内容を取得する関数を追加
# ---------------------------------------------------------------------------
# 設置場所      
#  なるべく上の方
#
# 必要スクリプト
#    なし
#==============================================================================
$imported = {} if $imported == nil
$imported["A1_Common_Script"] = 4.50
#==============================================================================
# ■ Kernel
#==============================================================================
module Kernel
  #--------------------------------------------------------------------------
  # ○ RGSSのバージョン取得
  #--------------------------------------------------------------------------
  def rgss_version
    return 3 if defined? Graphics.play_movie
    return 2 if defined? Graphics.resize_screen
    return 1
  end
  #--------------------------------------------------------------------------
  # ○ コモンスクリプトのバージョン取得
  #--------------------------------------------------------------------------
  def common_version
    $imported["A1_Common_Script"]
  end
  #--------------------------------------------------------------------------
  # ○ コモンスクリプトのバージョンが古い
  #--------------------------------------------------------------------------
  def old_common_script(script_name, version)
    msgbox("#{script_name}にはA1共通スクリプトVer#{version}以上が必要です")
  end
end
#==============================================================================
# ■ A1_System
#==============================================================================
module A1_System
end
#==============================================================================
# ■ A1_System::CommonModule
#==============================================================================

class A1_System::CommonModule
  #--------------------------------------------------------------------------
  # ○ 定数
  #--------------------------------------------------------------------------
  TWOBYTE_LIST = {
                  " " => " ",
                  "=" => "=",
                  ":" => ":"
                  }
  #--------------------------------------------------------------------------
  # ○ オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    define_command
  end
  #--------------------------------------------------------------------------
  # ○ 変換対象の全角文字を半角に置換
  #--------------------------------------------------------------------------
  def replace_twobyte(str)
    for key in TWOBYTE_LIST.keys
      str.gsub!(key) {TWOBYTE_LIST[key]}
    end
    return str
  end
  #--------------------------------------------------------------------------
  # ○ マイナスが含まれている文字列を数値にする
  #--------------------------------------------------------------------------
  def minus_to_i(s)
    if s[0,0] == "-"
      s.gsub!("-","")
      return s.to_i * -1
    else
      return s.to_i
    end
  end
  #--------------------------------------------------------------------------
  # ○ ミリ秒単位の現在時間
  #--------------------------------------------------------------------------
  def now_usec
    now = Time.now
    hour = now.hour * 60 * 60
    min  = now.min * 60
    sec  = now.sec
    msec = (now.usec / 1000.0).round
    return (hour + min + sec) * 1000 + msec
  end
  #--------------------------------------------------------------------------
  # ○ イベントリストの作成
  #--------------------------------------------------------------------------
  def create_event_list(code, indent, parameters)
    list = RPG::EventCommand.new
    list.code       = code
    list.indent     = indent
    list.parameters = parameters
    return list
  end
  #--------------------------------------------------------------------------
  # ○ メソッド呼び出し
  #--------------------------------------------------------------------------
  def send_method(method_name)
    return send(method_name) if respond_to?(method_name)
  end
  #--------------------------------------------------------------------------
  # ○ オブジェクトの型を判断してStringならエンコード
  #--------------------------------------------------------------------------
  def encoding_string(obj)
    obj.force_encoding("UTF-8") if obj.is_a?(String)
    return obj
  end
  #--------------------------------------------------------------------------
  # ○ メモの内容から必要な情報を取得
  #--------------------------------------------------------------------------
  def note_data(note, key)
    result = []
    note.each_line {|line|
      next unless line =~ /<#{key}[ ]?(.*)>/
      return true if $1.empty?
      data = $a1_common.replace_twobyte($1).split(" ")
      for st in data
        result.push(st)
      end
    }
    return false if result.empty?
    return result
  end
  #--------------------------------------------------------------------------
  # ○ メモの内容からハッシュを作成
  #--------------------------------------------------------------------------
  def note_data_hash(note, key, data_default = nil, default = {}, ret = {})
    list = note_data_split(note, key)
    return default if list.empty?
    list.each {|data| ret[data[0]] = data[1] ? data[1] : data_default }
    return ret
  end
  #--------------------------------------------------------------------------
  # ○ メモの内容からカンマ区切りの多元配列を取得
  #--------------------------------------------------------------------------
  def note_data_split(note, key, default = [], ret = [])
    data = note_data(note, key)
    return default unless data.is_a?(Array)
    data.each {|str| ret.push(convert_integer_from_array(split_array(str)))}
    return ret
  end
  #--------------------------------------------------------------------------
  # ○ 配列の内容から数値があれば変換
  #--------------------------------------------------------------------------
  def convert_integer_from_array(data, ret = [])
    data.each {|str| ret.push(convert_integer(str))}
    return ret
  end
  #--------------------------------------------------------------------------
  # ○ 数値があれば変換
  #--------------------------------------------------------------------------
  def convert_integer(str)
    return $1.to_i if str =~ /(^[-]?[0-9]+$)/
    str.is_a?(Array) ? convert_integer_from_array(str) : str
  end
  #--------------------------------------------------------------------------
  # ○ メモの内容から単項目の数値を取得
  #--------------------------------------------------------------------------
  def note_data_one_value(note, key, default)
    data = note_data(note, key)
    return data[0].to_i if data.is_a?(Array)
    return default
  end
  #--------------------------------------------------------------------------
  # ○ メモの内容から単項目を取得
  #--------------------------------------------------------------------------
  def note_data_one(note, key, default)
    data = note_data(note, key)
    return data[0] if data.is_a?(Array)
    return default
  end
  #--------------------------------------------------------------------------
  # ○ メモの内容からカンマ区切りの文字列を取得
  #--------------------------------------------------------------------------
  def note_data_array_str(note, key, default)
    data = note_data(note, key)
    return data[0].split(",") if data.is_a?(Array)
    return default
  end
  #--------------------------------------------------------------------------
  # ○ メモの内容からカンマ区切りの数値を取得
  #--------------------------------------------------------------------------
  def note_data_array_value(note, key, default)
    data = note_data(note, key)
    return default unless data.is_a?(Array)
    return convert_integer_from_array(split_array(data[0]))
  end
  #--------------------------------------------------------------------------
  # ○ カンマ区切りの文字列メモを変換
  #--------------------------------------------------------------------------
  def note_data_array(note, key, type, default = nil, through = true)
    ret = []
    default.each {|dat| ret.push(dat)} if default != nil
   
    data = note_data(note, key)
    return ret unless data.is_a?(Array)
   
    data = data[0].split(",")
    for d in data
      next if ret.include?(d) if through
      ret.push(d.to_i) if type.is_a?(Integer)
      ret.push(d)      if type.is_a?(String)
    end
    return ret
  end
  #--------------------------------------------------------------------------
  # ○ ディレクトリの作成
  #--------------------------------------------------------------------------
  def make_directory(dir_name)
    Dir::mkdir(dir_name) unless FileTest.exist?(dir_name)
  end
  #--------------------------------------------------------------------------
  # ○ コマンドリスト
  #--------------------------------------------------------------------------
  def make_command(command, src = "", dect = "")
    src.gsub!("/","\\")
    dect.gsub!("/","\\")
    cmd = "#{command} \"#{src}\" \"#{dect}\""
    return cmd
  end
  #--------------------------------------------------------------------------
  # ○ 素材の拡張子を取得
  #--------------------------------------------------------------------------
  def material_ext(directory, file, direct = false)
    exts = []
    exts = [".png",".bmp",".jpg"]               if directory =~ /(.*)Graphics\/(.*)/
    exts = [".mid",".ogg",".wav",".mp3",".wma"] if directory =~ /(.*)Audio(.*)/
   
    find_file = sprintf("%s%s", directory, file) unless direct
    find_file = file if direct
   
    for ext in exts
      return ext if File.exist?(sprintf("%s%s", find_file, ext))
    end
    return nil
  end
  #--------------------------------------------------------------------------
  # ○ 素材が存在するかチェック
  #--------------------------------------------------------------------------
  def material_exist?(directory, file, direct = false)
    return false if material_ext(directory, file, direct) == nil
    return true
  end
  #--------------------------------------------------------------------------
  # ○ ファイルコピー
  #--------------------------------------------------------------------------
  def copy_file(src, dest)
    srcFile = File.open( src, "rb" )
    dstFile = File.open( dest, "wb" )
    dstFile.write( srcFile.read )
    srcFile.close
    dstFile.close
  end
  #--------------------------------------------------------------------------
  # ○ ファイルの存在を確認してファイルコピー
  #--------------------------------------------------------------------------
  def material_copy(src, dest, directory)
    ext = material_ext(directory, src, true)
    copy_file( src + ext, dest + ext ) if ext != nil
  end
  #--------------------------------------------------------------------------
  # ○ 配列からAudioを作成
  #--------------------------------------------------------------------------
  def set_audio(sound, kind)
    case kind
    when "BGM"; audio = RPG::BGM.new
    when "BGS"; audio = RPG::BGS.new
    when "ME";  audio = RPG::ME.new
    when "SE";  audio = RPG::SE.new
    end
    audio.name   = sound[0]
    audio.volume = sound[1]
    audio.pitch  = sound[2]
    return audio
  end
  #--------------------------------------------------------------------------
  # ○ 既に準拠識別子を持っているかチェック
  #--------------------------------------------------------------------------
  def chk_rtp(file_name, default)
    return "" if file_name =~ /^VX_.*/
    return "" if file_name =~ /^XP_.*/
    return "" if file_name =~ /^2000_.*/
    return "" if file_name =~ /^2003_.*/
    return default
  end
  #--------------------------------------------------------------------------
  # ○ 先頭の $ を切り出す
  #--------------------------------------------------------------------------
  def one_character(file_name)
    return file_name unless file_name[0] == "$"
    tmp = file_name.clone
    tmp[0] = ""
    return tmp
  end
  #--------------------------------------------------------------------------
  # ○ 配列を入れ替える
  #--------------------------------------------------------------------------
  def change_array(array, index1, index2)
    tmp = array[index1]
    array[index1] = array[index2]
    array[index2] = tmp
    return array
  end
  #--------------------------------------------------------------------------
  # ○ 移動ルートの作成
  #--------------------------------------------------------------------------
  def create_move_route(repeat, skippable, wait, list)
    move_route = RPG::MoveRoute.new
    move_route.repeat    = repeat
    move_route.skippable = skippable
    move_route.wait      = wait
    move_route.list      = list
    return move_route
  end
  #--------------------------------------------------------------------------
  # ○ 移動ルートコマンドの作成
  #--------------------------------------------------------------------------
  def create_move_command(code, parameters)
    list = RPG::MoveCommand.new
    list.code       = code
    list.parameters = parameters
    return list
  end
  #--------------------------------------------------------------------------
  # ○ インタプリタ起動用リストの作成
  #--------------------------------------------------------------------------
  def create_list(code, indent, parameters)
    list            = RPG::EventCommand.new
    list.code       = code
    list.indent     = indent
    list.parameters = parameters
    return list
  end
  #--------------------------------------------------------------------------
  # ○ クラス名の取得
  #--------------------------------------------------------------------------
  def class_name(class_instance)
    return class_instance.to_s.split(":")[0].gsub("#<","")
  end
  #--------------------------------------------------------------------------
  # ○ 配列を考慮したsplit
  #--------------------------------------------------------------------------
  def split_array(str)
    str = convert_escape_characters(str)
   
    ret       = []
    tmp_array = str.split(",")
   
    return strip_array_str(tmp_array) unless str.include?("[")
    tmp_str   = ""
    tmp_array.each {|s|
      if char_in_str(s, "[", "]") && tmp_str.empty?
        ret.push(s) unless s =~ /^\[/
        ret.push([s[1...s.size-1]]) if s =~ /^\[/
      else
        tmp_str = "#{tmp_str}#{s},"
        if char_in_str(tmp_str, "[", "]")
          unless tmp_str =~ /^\[/
            ret.push(tmp_str[0...tmp_str.size-1])
            tmp_str = ""
          else
            tmp_str = tmp_str[1...tmp_str.size-2]
            tmp_str = split_array(tmp_str) if tmp_str.include?("[")
            tmp_str = tmp_str.split(",") if tmp_str.include?(",")
            ret.push(tmp_str)   if tmp_str.is_a?(Array)
            ret.push([tmp_str]) if !tmp_str.is_a?(Array)
            tmp_str = ""
          end
        end
      end
    }
    return strip_array_str(ret)
  end
  #--------------------------------------------------------------------------
  # ○ 配列の中の文字列の先頭と末尾の空白を除去
  #--------------------------------------------------------------------------
  def strip_array_str(array, ret = [])
    array.each {|str| ret.push(strip_array_str(str)) if str.is_a?(Array); next if str.is_a?(Array); ret.push(str.strip) }
    return ret
  end
  #--------------------------------------------------------------------------
  # ○ 文字列の中に文字が何文字含まれているか調べて同数ならtrueを返す
  #--------------------------------------------------------------------------
  def char_in_str(str, c1, c2)
    num1 = 0
    num2 = 0
    (0...str.size).each {|i| num1 += 1 if str == c1; num2 += 1 if str == c2 }
    return num1 == num2
  end
  #--------------------------------------------------------------------------
  # ○ 制御文字の変換
  #--------------------------------------------------------------------------
  def convert_escape_characters(text)
    result = text.to_s.clone
    result.gsub!(/\\/)                           { "\e" }
    result.gsub!(/\e\e/)                         { "\\" }
    result.gsub!(/\eV\[(\d+)\]/i)                { $game_variables[$1.to_i] }
    result.gsub!(/\eV\[(\d+)\]/i)                { $game_variables[$1.to_i] }
    result.gsub!(/\eN\[(\d+)\]/i)                { actor_name($1.to_i) }
    result.gsub!(/\eP\[(\d+)\]/i)                { party_member_name($1.to_i) }
    result.gsub!(/\eG/i)                         { Vocab::currency_unit }
    loop { result = result.sub(/<s>(.+?)<\/s>/i) { eval($1) }; break unless $1 }
    result
  end
  #--------------------------------------------------------------------------
  # ○ アクター n 番の名前を取得
  #--------------------------------------------------------------------------
  def actor_name(n)
    actor = n >= 1 ? $game_actors[n] : nil
    actor ? actor.name : ""
  end
  #--------------------------------------------------------------------------
  # ○ パーティメンバー n 番の名前を取得
  #--------------------------------------------------------------------------
  def party_member_name(n)
    actor = n >= 1 ? $game_party.members[n - 1] : nil
    actor ? actor.name : ""
  end
  #--------------------------------------------------------------------------
  # ○ 配列を全て整数にする
  #--------------------------------------------------------------------------
  def params_to_i(params)
    ret = []
    params.each {|param| ret.push(param.to_i)}
    return ret
  end
  #--------------------------------------------------------------------------
  # ○ 注釈コマンド定義
  #--------------------------------------------------------------------------
  def define_command
    @cmd_108 = {}
  end
  #--------------------------------------------------------------------------
  # ○ 注釈コマンド定義取得
  #--------------------------------------------------------------------------
  def cmd_108
    @cmd_108
  end
  #--------------------------------------------------------------------------
  # ○ フレーム更新
  #--------------------------------------------------------------------------
  def update
  end
  #--------------------------------------------------------------------------
  # ○ 文字の幅と高さを取得
  #--------------------------------------------------------------------------
  def text_size(font, size, text)
    bitmap = Cache.system("")
    bitmap.font.name = font
    bitmap.font.size = size
    tw = bitmap.text_size(text).width
    th = bitmap.text_size(text).height
    bitmap.dispose
    return [tw, th]
  end
  #--------------------------------------------------------------------------
  # ○ 文字の幅を取得
  #--------------------------------------------------------------------------
  def text_width(font, text)
    texts = text.split("\n")
    @max_width = 0
    texts.each {|text|
      width = text_size(font.name, font.size, text)[0]
      @max_width = @max_width < width ? width : @max_width
    }
    return @max_width
  end
end
#==============================================================================
# ◆ RGSS3用処理
#==============================================================================
if rgss_version == 3
#==============================================================================
# ■ RPG::Tileset
#==============================================================================

class RPG::Tileset
  #--------------------------------------------------------------------------
  # ○ 拡張通行判定
  #--------------------------------------------------------------------------
  def ex_flags
    @ex_flags ||= Table.new(8192)
    return @ex_flags
  end
  #--------------------------------------------------------------------------
  # ○ 拡張通行判定初期化
  #--------------------------------------------------------------------------
  def init_ex_flags
    @ex_flags = Table.new(8192)
  end
end
#==============================================================================
# ■ Game_Interpreter
#------------------------------------------------------------------------------
#  イベントコマンドを実行するインタプリタです。このクラスは Game_Map クラス、
# Game_Troop クラス、Game_Event クラスの内部で使用されます。
#==============================================================================

class Game_Interpreter
  #--------------------------------------------------------------------------
  # ☆ オブジェクト初期化
  #     depth : ネストの深さ
  #--------------------------------------------------------------------------
  alias a1_common_gi_rgss3_initialize initialize
  def initialize(depth = 0, sub_interpreter = false)
    @sub_interpreter = sub_interpreter
    a1_common_gi_rgss3_initialize(depth)
  end
  #--------------------------------------------------------------------------
  # ☆ メッセージ表示がビジー状態の間ウェイト
  #--------------------------------------------------------------------------
  alias a1_common_gi_wait_for_message wait_for_message
  def wait_for_message
    return if @sub_interpreter
    a1_common_gi_wait_for_message
  end
end
#==============================================================================
# ■ Window_Message
#------------------------------------------------------------------------------
#  文章表示に使うメッセージウィンドウです。
#==============================================================================

class Window_Message < Window_Base
  #--------------------------------------------------------------------------
  # ☆ 通常文字の処理
  #--------------------------------------------------------------------------
  alias a1_common_wm_process_normal_character process_normal_character
  def process_normal_character(c, pos)
    wait_for_one_character_before
    a1_common_wm_process_normal_character(c, pos)
  end
  #--------------------------------------------------------------------------
  # ○ 一文字出力前のウェイト
  #--------------------------------------------------------------------------
  def wait_for_one_character_before
  end
end
#==============================================================================
# ■ RPG::Map
#==============================================================================

class RPG::Map
  #--------------------------------------------------------------------------
  # ○ マップチップを調べるか判定する
  #--------------------------------------------------------------------------
  def search_map_chip?
    return true if $a1_common.note_data(self.note, "マップチップサーチ")
    return false
  end
end
#==============================================================================
# ■ Game_Map
#------------------------------------------------------------------------------
#  マップを扱うクラスです。スクロールや通行可能判定などの機能を持っています。
# このクラスのインスタンスは $game_map で参照されます。
#==============================================================================

class Game_Map
  #--------------------------------------------------------------------------
  # ☆ セットアップ
  #--------------------------------------------------------------------------
  alias a1_common_gm_setup setup
  def setup(map_id)
    a1_common_gm_setup(map_id)
    setup_tileset
    map_chip_search if search_map_chip?
  end
  #--------------------------------------------------------------------------
  # ★ タイルセットの取得
  #--------------------------------------------------------------------------
  def tileset
    setup_tileset unless @tileset && @now_tileset_id == @tileset_id
    return @tileset
  end
  #--------------------------------------------------------------------------
  # ○ タイルセットのセットアップ
  #--------------------------------------------------------------------------
  def setup_tileset
    @tileset        = $data_tilesets[@tileset_id].clone
    @tileset.flags  = $data_tilesets[@tileset_id].flags.clone
    @now_tileset_id = @tileset_id
  end
  #--------------------------------------------------------------------------
  # ○ マップチップを調べるか判定する
  #--------------------------------------------------------------------------
  def search_map_chip?
    return @map.search_map_chip?
  end
  #--------------------------------------------------------------------------
  # ○ 指定座標の全レイヤーのフラグ判定(イベント含む)
  #--------------------------------------------------------------------------
  def all_tiles_flag?(x, y, bit)
    all_tiles(x, y).any? {|tile_id| tileset.flags[tile_id] & bit != 0 }
  end
  #--------------------------------------------------------------------------
  # ○ 指定座標の全レイヤーの拡張フラグ判定(イベント含む)
  #--------------------------------------------------------------------------
  def all_tiles_flag_ex?(x, y, bit)
    all_tiles(x, y).any? {|tile_id| tileset.ex_flags[tile_id] & bit != 0 }
  end
  #--------------------------------------------------------------------------
  # ○ 指定座標の全レイヤーの拡張フラグ判定
  #--------------------------------------------------------------------------
  def layered_tiles_flag_ex?(x, y, bit)
    layered_tiles(x, y).any? {|tile_id| tileset.ex_flags[tile_id] & bit != 0 }
  end
  #--------------------------------------------------------------------------
  # ○ 地形タグの取得(イベント含む)
  #--------------------------------------------------------------------------
  def terrain_tag_all_tailes(x, y)
    return 0 unless valid?(x, y)
    all_tiles(x, y).each do |tile_id|
      tag = tileset.flags[tile_id] >> 12
      return tag if tag > 0
    end
    return 0
  end
end
#==============================================================================
# ■ DataManager
#------------------------------------------------------------------------------
#  データベースとゲームオブジェクトを管理するモジュールです。ゲームで使用する
# ほぼ全てのグローバル変数はこのモジュールで初期化されます。
#==============================================================================

module DataManager
  #--------------------------------------------------------------------------
  # ○ エイリアス用特異メソッド
  #--------------------------------------------------------------------------
  class << self
    alias :a1_common_create_game_objects :create_game_objects
  end
  #--------------------------------------------------------------------------
  # ☆ 各種ゲームオブジェクトの作成
  #--------------------------------------------------------------------------
  def self.create_game_objects
    $a1_common ||= A1_System::CommonModule.new
    a1_common_create_game_objects
  end
end
#==============================================================================
# ■ Scene_Base
#------------------------------------------------------------------------------
#  ゲーム中の全てのシーンのスーパークラスです。
#==============================================================================

class Scene_Base
  #--------------------------------------------------------------------------
  # ☆ フレーム更新(基本)
  #--------------------------------------------------------------------------
  alias a1_common_sb_update_basic update_basic
  def update_basic
    a1_common_sb_update_basic
    $a1_common.update
  end
  #--------------------------------------------------------------------------
  # ○ 指定のウィンドウが開いている間ウェイト
  #--------------------------------------------------------------------------
  def wait_for_window_open(window)
    update_basic until window.openness == 0
  end
end
#==============================================================================
# ■ Window_Base
#------------------------------------------------------------------------------
#  ゲーム中の全てのウィンドウのスーパークラスです。
#==============================================================================

class Window_Base < Window
  #--------------------------------------------------------------------------
  # ★ 制御文字の事前変換
  #    実際の描画を始める前に、原則として文字列に変わるものだけを置き換える。
  #    文字「\」はエスケープ文字(\e)に変換。
  #--------------------------------------------------------------------------
  def convert_escape_characters(text)
    return $a1_common.convert_escape_characters(text)
  end
end
#==============================================================================
# ◆ RGSS2用処理
#==============================================================================
elsif rgss_version == 2
#==============================================================================
# ■ Window
#==============================================================================

class Window
  #--------------------------------------------------------------------------
  # ○ ウィンドウが開いている?
  #--------------------------------------------------------------------------
  def open?
    return self.openness == 255
  end
  #--------------------------------------------------------------------------
  # ○ ウィンドウが閉じている?
  #--------------------------------------------------------------------------
  def close?
    return self.openness == 0
  end
end
#==============================================================================
# ■ Cache
#------------------------------------------------------------------------------
#  各種グラフィックを読み込み、Bitmap オブジェクトを作成、保持するモジュール
# です。読み込みの高速化とメモリ節約のため、作成した Bitmap オブジェクトを内部
# のハッシュに保存し、同じビットマップが再度要求されたときに既存のオブジェクト
# を返すようになっています。
#==============================================================================

module Cache
  #--------------------------------------------------------------------------
  # ○ キャッシュ存在チェック
  #--------------------------------------------------------------------------
  def self.include?(key)
    @cache[key] && !@cache[key].disposed?
  end
end
#==============================================================================
# ■ Game_Interpreter
#------------------------------------------------------------------------------
#  イベントコマンドを実行するインタプリタです。このクラスは Game_Map クラス、
# Game_Troop クラス、Game_Event クラスの内部で使用されます。
#==============================================================================

class Game_Interpreter
  #--------------------------------------------------------------------------
  # ○ 注釈
  #--------------------------------------------------------------------------
  def command_108
    @comments = [@params[0]]
    while next_event_code == 408
      @index += 1
      @comments.push(@list[@index].parameters[0])
    end
  end
  #--------------------------------------------------------------------------
  # ★ イベントコマンドの実行
  #--------------------------------------------------------------------------
  def execute_command
    return rgss3_execute_command unless @index >= @list.size-1
    command_end
    return true
  end
  #--------------------------------------------------------------------------
  # ○ RGSS3風「イベントコマンドの実行」
  #--------------------------------------------------------------------------
  def rgss3_execute_command
    command = @list[@index]
    @params = command.parameters
    @indent = command.indent
    method_name = "command_#{command.code}"
    send(method_name) if respond_to?(method_name)
  end
  #--------------------------------------------------------------------------
  # ○ 次のイベントコマンドのコードを取得
  #--------------------------------------------------------------------------
  def next_event_code
    @list[@index + 1].code
  end
end
#==============================================================================
# ■ Game_Map
#------------------------------------------------------------------------------
#  マップを扱うクラスです。スクロールや通行可能判定などの機能を持っています。
# このクラスのインスタンスは $game_map で参照されます。
#==============================================================================

class Game_Map
  #--------------------------------------------------------------------------
  # ○ マップチップを調べるか判定する
  #--------------------------------------------------------------------------
  def search_map_chip?
    return $data_map_infos[@map_id].name =~ /\[サーチ\]/
  end
  #--------------------------------------------------------------------------
  # ○ 指定座標に存在するタイル扱いイベント(すり抜け以外)の配列取得
  #--------------------------------------------------------------------------
  def tile_events_xy(x, y)
    @tile_events.select {|event| event.pos_nt?(x, y) }
  end
  #--------------------------------------------------------------------------
  # ○ タイル扱いイベントの配列をリフレッシュ
  #--------------------------------------------------------------------------
  def refresh_tile_events
    @tile_events = @events.values.select {|event| event.tile? }
  end
end
#==============================================================================
# ■ Game_Character
#------------------------------------------------------------------------------
#  キャラクターを扱うクラスです。このクラスは Game_Player クラスと Game_Event
# クラスのスーパークラスとして使用されます。
#==============================================================================

class Game_Character
  #--------------------------------------------------------------------------
  # ○ タイル判定
  #--------------------------------------------------------------------------
  def tile?
    @tile_id > 0 && @priority_type == 0
  end
end
#==============================================================================
# ■ Scene_Title
#------------------------------------------------------------------------------
#  タイトル画面の処理を行うクラスです。
#==============================================================================

class Scene_Title < Scene_Base
  #--------------------------------------------------------------------------
  # ☆ データベースのロード
  #--------------------------------------------------------------------------
  alias a1_common_st_load_database load_database
  def load_database
    a1_common_st_load_database
    $data_map_infos = load_data("Data/MapInfos.rvdata")
  end
  #--------------------------------------------------------------------------
  # ☆ 各種ゲームオブジェクトの作成
  #--------------------------------------------------------------------------
  alias a1_common_st_create_game_objects create_game_objects
  def create_game_objects
    $a1_common ||= A1_System::CommonModule.new
    a1_common_st_create_game_objects
  end
end
#==============================================================================
# ◆ RGSS用処理
#==============================================================================
elsif rgss_version == 1
end
#==============================================================================
# ■ Cache
#------------------------------------------------------------------------------
#  各種グラフィックを読み込み、Bitmap オブジェクトを作成、保持するモジュール
# です。読み込みの高速化とメモリ節約のため、作成した Bitmap オブジェクトを内部
# のハッシュに保存し、同じビットマップが再度要求されたときに既存のオブジェクト
# を返すようになっています。
#==============================================================================

module Cache
  #--------------------------------------------------------------------------
  # ○ 拡大縮小したビットマップのロード
  #--------------------------------------------------------------------------
  def self.load_resize_bitmap(load_path, key, resize = nil)
    @cache ||= {}
    key = load_path if key == nil
    return @cache[key] if include?(key)
   
    @cache[key] = Bitmap.new(load_path)
    return @cache[key] if resize == nil
    return @cache[key] if @cache[key].width == resize[0] and @cache[key].height == resize[1]
   
    info = calc_size(resize, key)
    return resize_bitmap(@cache[key], info[0], info[1], key)
  end
  #--------------------------------------------------------------------------
  # ○ 拡大縮小した色相変化済みビットマップを作成/取得
  #--------------------------------------------------------------------------
  def self.load_resize_hue_changed_bitmap(load_path, path, hue, resize)
    key = [path, hue]
    return @cache[key] if include?(key)
   
    @cache[key] = load_resize_bitmap(load_path, path, resize).clone
    @cache[key].hue_change(hue)
    return @cache[key]
  end
  #--------------------------------------------------------------------------
  # ○ リサイズするサイズを取得
  #--------------------------------------------------------------------------
  def self.calc_size(resize, key)
    width  = resize[0]
    width  = @cache[key].width * width.abs if width < 0
    height = resize[1]
    height = @cache[key].height * height.abs if height < 0
    height = Integer(@cache[key].height * (width.to_f / @cache[key].width.to_f)) if height == 0
    return [width, height]
  end
  #--------------------------------------------------------------------------
  # ○ ビットマップの拡大縮小
  #--------------------------------------------------------------------------
  def self.resize_bitmap(bitmap, width, height, key)
    resize = Bitmap.new(width, height)
    resize.stretch_blt(resize.rect, bitmap, bitmap.rect)
    @cache[key] = resize
    return resize
  end
  #--------------------------------------------------------------------------
  # ○ テキストビットマップの取得
  #--------------------------------------------------------------------------
  def self.text_picture(text, font)
    load_text_bitmap(text, font)
  end
  #--------------------------------------------------------------------------
  # ○ フォントのキーを作成
  #--------------------------------------------------------------------------
  def self.make_font_key(text, font)
    [text, font.name, font.size, font.bold, font.italic, font.outline, font.shadow, font.color.to_s, font.out_color.to_s]
  end
  #--------------------------------------------------------------------------
  # ○ テキストビットマップの作成
  #--------------------------------------------------------------------------
  def self.load_text_bitmap(text, font)
    @cache ||= {}
    key = make_font_key(text, font)
    return @cache[key] if include?(key)
   
    # 計算用ダミービットマップ
    bitmap = Cache.system("")
    bitmap.font = font
    tw = bitmap.text_size(text).width + 8
   
    # ビットマップ作成
    bitmap = Bitmap.new(tw, bitmap.font.size + 4)
    bitmap.font = font
    bitmap.draw_text(0, 0, bitmap.width, bitmap.height, text, 1)
   
    @cache[key] = bitmap
    return @cache[key]
  end
end
#==============================================================================
# ■ Game_Interpreter
#------------------------------------------------------------------------------
#  イベントコマンドを実行するインタプリタです。このクラスは Game_Map クラス、
# Game_Troop クラス、Game_Event クラスの内部で使用されます。
#==============================================================================

class Game_Interpreter
  #--------------------------------------------------------------------------
  # ○ 注釈
  #--------------------------------------------------------------------------
  alias a1_common_command_108 command_108
  def command_108
    a1_common_command_108
    proc_comment(@comments)
  end
  #--------------------------------------------------------------------------
  # ○ 注釈の処理
  #--------------------------------------------------------------------------
  def proc_comment(comments)
    param = ""
    comments.each {|comment| param += comment }
    params = param.sub(/^(\S+)/, "")
    command = $1
    comment_parameters = $a1_common.split_array(params) if params
    proc_comment_command(command, comment_parameters)
  end
  #--------------------------------------------------------------------------
  # ○ 注釈の実行
  #--------------------------------------------------------------------------
  def proc_comment_command(command, params)
    cmd_108 = $a1_common.cmd_108[command]
    method(cmd_108).call(params) if cmd_108 != nil
  end
  #--------------------------------------------------------------------------
  # ○ 前のイベントコマンドを取得
  #--------------------------------------------------------------------------
  def prev_event
    @list[@index - 1]
  end
end
#==============================================================================
# ■ Game_Map
#------------------------------------------------------------------------------
#  マップを扱うクラスです。スクロールや通行可能判定などの機能を持っています。
# このクラスのインスタンスは $game_map で参照されます。
#==============================================================================

class Game_Map
  #--------------------------------------------------------------------------
  # ○ 全マップチップを調べる
  #--------------------------------------------------------------------------
  def map_chip_search
    tileset.init_ex_flags
    ([email protected]).each {|x| map_chip_search_y(x) }
  end
  #--------------------------------------------------------------------------
  # ○ x座標にあるy座標のマップチップを調べる
  #--------------------------------------------------------------------------
  def map_chip_search_y(x)
    ([email protected]).each {|y| map_pos_proc(x, y); map_chip_search_z(x, y) }
  end
  #--------------------------------------------------------------------------
  # ○ x,y座標にあるz座標のマップチップを調べる
  #--------------------------------------------------------------------------
  def map_chip_search_z(x, y)
    ([email protected]).each {|z| map_chip_proc(x, y, z) }
    tile_events_xy(x, y).collect {|ev| tile_event_proc(ev.tile_id) }
  end
  #--------------------------------------------------------------------------
  # ○ 座標に対して処理を行う
  #--------------------------------------------------------------------------
  def map_pos_proc(x, y)
  end
  #--------------------------------------------------------------------------
  # ○ マップチップに対して処理を行う
  #--------------------------------------------------------------------------
  def map_chip_proc(x, y, z)
  end
  #--------------------------------------------------------------------------
  # ○ タイルのイベントに対して処理を行う
  #--------------------------------------------------------------------------
  def tile_event_proc(tile_id)
  end
end
#==============================================================================
# ■ Window_Base
#------------------------------------------------------------------------------
#  ゲーム中の全てのウィンドウのスーパークラスです。
#==============================================================================

class Window_Base < Window
  #--------------------------------------------------------------------------
  # ○ 入力を受け付けるか?
  #--------------------------------------------------------------------------
  def can_input?
    @can_input
  end
  #--------------------------------------------------------------------------
  # ○ 入力受け付け設定
  #--------------------------------------------------------------------------
  def can_input=(flag)
    @can_input = flag
  end
end
#==============================================================================
# ■ Bitmap
#==============================================================================

class Bitmap
  #--------------------------------------------------------------------------
  # ○ 文字縁取り描画
  #--------------------------------------------------------------------------
  def draw_text_f(x, y, width, height, str, align = 0, color = Color.new(64,32,128))
    shadow = self.font.shadow
    b_color = self.font.color.dup
    font.shadow = false
    font.color = color
    draw_text(x + 1, y, width, height, str, align)
    draw_text(x - 1, y, width, height, str, align)
    draw_text(x, y + 1, width, height, str, align)
    draw_text(x, y - 1, width, height, str, align)
    font.color = b_color
    draw_text(x, y, width, height, str, align)
    font.shadow = shadow
  end
  #--------------------------------------------------------------------------
  # ○ 文字縁取り描画の矩形を取得
  #--------------------------------------------------------------------------
  def draw_text_f_rect(r, str, align = 0, color = Color.new(64,32,128))
    draw_text_f(r.x, r.y, r.width, r.height, str, align = 0, color)
  end
end


# ===========================================================================
# ◆ A1 Scripts ◆
#    A1バトル共通スクリプト(RGSS3)
#
# バージョン   : 1.23 (2012/01/27)
# 作者         : A1
# URL     : http://a1tktk.web.fc2.com/
# ---------------------------------------------------------------------------
# 更新履歴   :2012/01/18 Ver1.00 リリース
#                2012/01/21 Ver1.10 装備拡張対応
#                2012/01/21 Ver1.10 メンバー加入時の不具合を修正
#                2012/01/21 Ver1.10 メンバー加入時に既にパーティに居るさい何もしないように修正
#                2012/01/24 Ver1.20 スキル拡張対応
#                2012/01/24 Ver1.21 Window_BattleActorの不具合を修正
#                2012/01/26 Ver1.22 Window_BattleSkillの不具合を修正
#                2012/01/27 Ver1.23 戦闘行動がない際の不具合を修正
# ---------------------------------------------------------------------------
# 設置場所      
#  A1共通スクリプトより下
#    一部再定義メソッドがあるため、なるべく上の方
#
# 必要スクリプト
#    A1共通スクリプトVer4.30以上
#==============================================================================
$imported = {} if $imported == nil
if $imported["A1_Common_Script"]
$imported["A1_BattleCommonScript"] = true
old_common_script("A1バトル共通スクリプト", "4.30") if common_version < 4.30
#==============================================================================
# ■ Window_Base
#------------------------------------------------------------------------------
#  ゲーム中の全てのウィンドウのスーパークラスです。
#==============================================================================

class Window_Base < Window
  #--------------------------------------------------------------------------
  # ○ メソッドの定義
  #--------------------------------------------------------------------------
  def define_method(method, symbol)
    @method ||= {}
    @method[symbol] = method
  end
  #--------------------------------------------------------------------------
  # ○ メソッドのコール
  #--------------------------------------------------------------------------
  def call_method(symbol, *args)
    @method ||= {}
    @method[symbol].call(*args) if @method[symbol]
  end
  #--------------------------------------------------------------------------
  # ○ 顔グラフィックの描画(解放なし)
  #--------------------------------------------------------------------------
  def draw_face_no_dispose(face_name, face_index, x, y, enabled = true)
    bitmap = Cache.face(face_name)
    rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96, 96, 96)
    contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
  end
  #--------------------------------------------------------------------------
  # ○ 背景の描画
  #--------------------------------------------------------------------------
  def draw_background(rect)
    temp_rect = rect.clone
    temp_rect.width /= 2
    contents.gradient_fill_rect(temp_rect, back_color2, back_color1)
    temp_rect.x = temp_rect.width
    contents.gradient_fill_rect(temp_rect, back_color1, back_color2)
  end
  #--------------------------------------------------------------------------
  # ○ 背景色 1 の取得
  #--------------------------------------------------------------------------
  def back_color1
    Color.new(0, 0, 0, 192)
  end
  #--------------------------------------------------------------------------
  # ○ 背景色 2 の取得
  #--------------------------------------------------------------------------
  def back_color2
    Color.new(0, 0, 0, 0)
  end
end
#==============================================================================
# ■ Window_Help
#------------------------------------------------------------------------------
#  スキルやアイテムの説明、アクターのステータスなどを表示するウィンドウです。
#==============================================================================

class Window_Help < Window_Base
  #--------------------------------------------------------------------------
  # ○ センターにテキストを描画
  #--------------------------------------------------------------------------
  def draw_center_text(text)
    contents.clear
    draw_text(0, 0, contents.width, line_height, text, 1)
  end
end
#==============================================================================
# ■ Window_BattleActor
#------------------------------------------------------------------------------
#  バトル画面で、行動対象のアクターを選択するウィンドウです。
#==============================================================================

class Window_BattleActor < Window_BattleStatus
  #--------------------------------------------------------------------------
  # ★ ウィンドウの表示
  #--------------------------------------------------------------------------
  def show
    setup_remain if @info_viewport
    self.visible = true
    refresh
    open
    self
  end
  #--------------------------------------------------------------------------
  # ★ ウィンドウの非表示
  #--------------------------------------------------------------------------
  def hide
    close
    @info_viewport.rect.width = Graphics.width if @info_viewport
    call_method(:select_actor_end)
  end
  #--------------------------------------------------------------------------
  # ○ フレーム更新
  #--------------------------------------------------------------------------
  def update
    return update_basic unless self.visible
    super
    self.visible = false if self.openness == 0
  end
  #--------------------------------------------------------------------------
  # ○ フレーム更新(基本)
  #--------------------------------------------------------------------------
  def update_basic
    process_cursor_move
    process_handling
  end
  #--------------------------------------------------------------------------
  # ○ 項目の選択
  #--------------------------------------------------------------------------
  def select(index)
    super
    call_method(:select_actor, index)
  end
  #--------------------------------------------------------------------------
  # ○ ウィンドウの調整
  #--------------------------------------------------------------------------
  def setup_remain
    width_remain = Graphics.width - width
    self.x = width_remain
    @info_viewport.rect.width = width_remain
    select(0)
  end
end
#==============================================================================
# ■ Window_BattleEnemy
#------------------------------------------------------------------------------
#  バトル画面で、行動対象の敵キャラを選択するウィンドウです。
#==============================================================================

class Window_BattleEnemy < Window_Selectable
  #--------------------------------------------------------------------------
  # ★ ウィンドウの表示
  #--------------------------------------------------------------------------
  def show
    setup_remain if @info_viewport
    self.visible = true
    open
    self
  end
  #--------------------------------------------------------------------------
  # ★ ウィンドウの非表示
  #--------------------------------------------------------------------------
  def hide
    close
    @info_viewport.rect.width = Graphics.width if @info_viewport
    call_method(:select_enemy_end)
  end
  #--------------------------------------------------------------------------
  # ○ フレーム更新
  #--------------------------------------------------------------------------
  def update
    return update_basic unless self.visible
    super
    self.visible = false if self.openness == 0
  end
  #--------------------------------------------------------------------------
  # ○ フレーム更新(基本)
  #--------------------------------------------------------------------------
  def update_basic
    process_cursor_move
    process_handling
  end
  #--------------------------------------------------------------------------
  # ○ 項目の選択
  #--------------------------------------------------------------------------
  def select(index)
    super
    call_method(:select_enemy, index)
  end
  #--------------------------------------------------------------------------
  # ○ ウィンドウの調整
  #--------------------------------------------------------------------------
  def setup_remain
    width_remain = Graphics.width - width
    self.x = width_remain
    @info_viewport.rect.width = width_remain
    select(0)
  end
end
#==============================================================================
# ■ Window_BattleSkill
#------------------------------------------------------------------------------
#  バトル画面で、使用するスキルを選択するウィンドウです。
#==============================================================================

class Window_BattleSkill < Window_SkillList
  #--------------------------------------------------------------------------
  # ☆ オブジェクト初期化
  #     info_viewport : 情報表示用ビューポート
  #--------------------------------------------------------------------------
  alias a1_psw_wbs_initialize initialize
  def initialize(help_window, info_viewport)
    a1_psw_wbs_initialize(help_window, info_viewport)
    self.openness = 0
    self.visible  = true
    @help_window.openness = 0
    @help_window.visible = true
  end
  #--------------------------------------------------------------------------
  # ○ 高さを変える
  #--------------------------------------------------------------------------
  def resize_height(base_y)
    self.height = base_y - self.y
    create_contents
  end
  #--------------------------------------------------------------------------
  # ★ ウィンドウの表示
  #--------------------------------------------------------------------------
  def show
    self.visible = true
    @help_window.visible = true
    select_last
    open
    @help_window.open
    self
  end
  #--------------------------------------------------------------------------
  # ★ ウィンドウの非表示
  #--------------------------------------------------------------------------
  def hide
    close
    @help_window.close
    @info_viewport.rect.width = Graphics.width if @info_viewport
    call_method(:skill_item_window_hide)
  end
  #--------------------------------------------------------------------------
  # ○ オープン
  #--------------------------------------------------------------------------
  def open
    self.visible = true
    call_method(:skill_item_window_show)
    super
  end
  #--------------------------------------------------------------------------
  # ○ アクティブ化
  #--------------------------------------------------------------------------
  def activate
    open
    @help_window.open
    super
  end
end
#==============================================================================
# ■ Window_BattleItem
#------------------------------------------------------------------------------
#  バトル画面で、使用するアイテムを選択するウィンドウです。
#==============================================================================

class Window_BattleItem < Window_ItemList
  #--------------------------------------------------------------------------
  # ☆ オブジェクト初期化
  #     info_viewport : 情報表示用ビューポート
  #--------------------------------------------------------------------------
  alias a1_battle_common_wbi_initialize initialize
  def initialize(help_window, info_viewport)
    a1_battle_common_wbi_initialize(help_window, info_viewport)
    self.openness = 0
    self.visible  = true
    @help_window.openness = 0
    @help_window.visible = true
  end
  #--------------------------------------------------------------------------
  # ○ 高さを変える
  #--------------------------------------------------------------------------
  def resize_height(base_y)
    self.height = base_y - self.y
    create_contents
  end
  #--------------------------------------------------------------------------
  # ★ ウィンドウの表示
  #--------------------------------------------------------------------------
  def show
    self.visible = true
    @help_window.visible = true
    select_last
    open
    @help_window.open
    self
  end
  #--------------------------------------------------------------------------
  # ★ ウィンドウの非表示
  #--------------------------------------------------------------------------
  def hide
    close
    @help_window.close
    call_method(:skill_item_window_hide)
  end
  #--------------------------------------------------------------------------
  # ○ オープン
  #--------------------------------------------------------------------------
  def open
    self.visible = true
    call_method(:skill_item_window_show)
    super
  end
  #--------------------------------------------------------------------------
  # ○ アクティブ化
  #--------------------------------------------------------------------------
  def activate
    open
    @help_window.open
    super
  end
  #--------------------------------------------------------------------------
  # ○ フレーム更新
  #--------------------------------------------------------------------------
  def update
    return unless self.visible
    super
    self.visible = false if self.openness == 0
  end
end
#==============================================================================
# ■ Window_ActorCommand
#------------------------------------------------------------------------------
#  バトル画面で、アクターの行動を選択するウィンドウです。
#==============================================================================








#==============================================================================
# ■ Window_BattleStatus
#------------------------------------------------------------------------------
#  バトル画面で、パーティメンバーのステータスを表示するウィンドウです。
#==============================================================================

class Window_BattleStatus < Window_Selectable
  #--------------------------------------------------------------------------
  # ☆ リフレッシュ
  #--------------------------------------------------------------------------
  alias a1_battle_common_wbs_refresh refresh
  def refresh
    call_method(:refresh_statsu_window)
    return unless self.visible
    a1_battle_common_wbs_refresh
  end
  #--------------------------------------------------------------------------
  # ○ ウィンドウを開く
  #--------------------------------------------------------------------------
  def open
    super
    call_method(:open_status_window)
  end
  #--------------------------------------------------------------------------
  # ○ ウィンドウを閉じる
  #--------------------------------------------------------------------------
  def close
    super
    call_method(:close_status_window)
  end
  #--------------------------------------------------------------------------
  # ○ 項目の選択
  #--------------------------------------------------------------------------
  def select(index)
    super
    call_method(:select_status_window, index)
  end
  #--------------------------------------------------------------------------
  # ○ フレーム更新
  #--------------------------------------------------------------------------
  def update
    call_method(:update_status_window)
    return unless self.visible
    super
  end
  #--------------------------------------------------------------------------
  # ○ 解放
  #--------------------------------------------------------------------------
  def dispose
    super
    call_method(:dispose_status_window)
  end
end
#==============================================================================
# ■ Window_PersonalStatus
#==============================================================================

class Window_PersonalStatus < Window_Base
  #--------------------------------------------------------------------------
  # ○ オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(x, y, opacity = 0)
    super(x, y, Graphics.width / 2, 120)
    self.opacity  = opacity
    self.openness = 0
    @actor = nil
  end
  #--------------------------------------------------------------------------
  # ○ アクターの設定
  #--------------------------------------------------------------------------
  def actor=(actor)
    @actor = actor
    refresh
  end
  #--------------------------------------------------------------------------
  # ○ リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    draw_face(@actor.face_name, @actor.face_index, 0, 0)
    draw_text(116, line_height * 0, contents.width, line_height, @actor.name)
    draw_actor_level(@actor, 116, 0 + line_height * 1)
    draw_actor_icons(@actor, 180, 0 + line_height * 1)
    draw_actor_hp(@actor, 116, 0 + line_height * 2, 128)
    draw_actor_mp(@actor, 116, 0 + line_height * 3, 60)
    draw_actor_tp(@actor, 184, 0 + line_height * 3, 60) if $data_system.opt_display_tp
  end
  #--------------------------------------------------------------------------
  # ○ フレーム更新
  #--------------------------------------------------------------------------
  def update
    return unless self.visible
    super
    self.visible = false if self.openness == 0
  end
  #--------------------------------------------------------------------------
  # ○ オープン
  #--------------------------------------------------------------------------
  def open
    self.visible = true
    super
  end
  #--------------------------------------------------------------------------
  # ○ 顔グラフィックの描画
  #--------------------------------------------------------------------------
  def draw_face(face_name, face_index, x, y, enabled = true)
    draw_face_no_dispose(face_name, face_index, x, y, enabled)
  end
end
#==============================================================================
# ■ RPG::Enemy
#==============================================================================

class RPG::Enemy < RPG::BaseItem
  #--------------------------------------------------------------------------
  # ○ 初期装備
  #--------------------------------------------------------------------------
  def equips
    @equips ||= [0,0,0,0,0]
    @equips[0] ||= $a1_common.note_data_one(self.note, "エネミー武器", 0)
    return @equips
  end
end
#==============================================================================
# ■ Game_Enemy
#------------------------------------------------------------------------------
#  敵キャラを扱うクラスです。このクラスは Game_Troop クラス($game_troop)の
# 内部で使用されます。
#==============================================================================

class Game_Enemy < Game_Battler
  #--------------------------------------------------------------------------
  # ☆ オブジェクト初期化
  #--------------------------------------------------------------------------
  alias a1_battle_common_ge_initialize initialize
  def initialize(index, enemy_id)
    @equips = []
    a1_battle_common_ge_initialize(index, enemy_id)
    init_equips(enemy.equips)
  end
end
#==============================================================================
# ■ Game_Actor
#------------------------------------------------------------------------------
#  アクターを扱うクラスです。このクラスは Game_Actors クラス($game_actors)
# の内部で使用され、Game_Party クラス($game_party)からも参照されます。
#==============================================================================

class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # ★ 装備品の初期化
  #     equips : 初期装備の配列
  #--------------------------------------------------------------------------
  def init_equips(equips)
    super
  end
  #--------------------------------------------------------------------------
  # ★ 装備タイプからスロット ID に変換(空きを優先)
  #--------------------------------------------------------------------------
  def empty_slot(etype_id)
    super
  end
  #--------------------------------------------------------------------------
  # ★ 装備タイプからスロット ID のリストに変換
  #--------------------------------------------------------------------------
  def slot_list(etype_id)
    super
  end
  #--------------------------------------------------------------------------
  # ★ エディタで設定されたインデックスを装備タイプ ID に変換
  #--------------------------------------------------------------------------
  def index_to_etype_id(index)
    super
  end
  #--------------------------------------------------------------------------
  # ★ 装備スロットの配列を取得
  #--------------------------------------------------------------------------
  def equip_slots
    super
  end
  #--------------------------------------------------------------------------
  # ★ 装備品オブジェクトの配列取得
  #--------------------------------------------------------------------------
  def equips
    super
  end
  #--------------------------------------------------------------------------
  # ★ 武器オブジェクトの配列取得
  #--------------------------------------------------------------------------
  def weapons
    super
  end
  #--------------------------------------------------------------------------
  # ★ 通常能力値の加算値取得
  #--------------------------------------------------------------------------
  def param_plus(param_id)
    super
  end
  #--------------------------------------------------------------------------
  # ☆ 通常攻撃 アニメーション ID の取得
  #--------------------------------------------------------------------------
  alias a1_battle_common_ga_atk_animation_id1 atk_animation_id1
  def atk_animation_id1
    return a1_battle_common_ga_atk_animation_id1 if !@current_weapon || @current_weapon.is_a?(Array)
    @current_weapon.animation_id
  end
  #--------------------------------------------------------------------------
  # ☆ 通常攻撃 アニメーション ID の取得(二刀流:武器2)
  #--------------------------------------------------------------------------
  alias a1_battle_common_ga_atk_animation_id2 atk_animation_id2
  def atk_animation_id2
    return a1_battle_common_ga_atk_animation_id2 if !@current_weapon || @current_weapon.is_a?(Array)
    @current_weapon.animation_id
  end
  #--------------------------------------------------------------------------
  # ○ 装備タイプ名を取得
  #--------------------------------------------------------------------------
  def e_type_name(item)
    return $data_system.weapon_types[item.wtype_id] if item.is_a?(RPG::Weapon)
    return $data_system.armor_types[item.atype_id] if item.is_a?(RPG::Armor)
  end
end
#==============================================================================
# ■ Game_BattlerBase
#------------------------------------------------------------------------------
#  バトラーを扱う基本のクラスです。主に能力値計算のメソッドを含んでいます。こ
# のクラスは Game_Battler クラスのスーパークラスとして使用されます。
#==============================================================================

class Game_BattlerBase
  #--------------------------------------------------------------------------
  # ○ 二刀流?
  #--------------------------------------------------------------------------
  def two_sword_style?
    weapons[0] && weapons[1]
  end
  #--------------------------------------------------------------------------
  # ○ バトラーオブジェクト取得
  #--------------------------------------------------------------------------
  def battler
    return actor if self.actor?
    return enemy
  end
end
#==============================================================================
# ■ Game_Battler
#------------------------------------------------------------------------------
#  スプライトや行動に関するメソッドを追加したバトラーのクラスです。このクラス
# は Game_Actor クラスと Game_Enemy クラスのスーパークラスとして使用されます。
#==============================================================================

class Game_Battler < Game_BattlerBase
  #--------------------------------------------------------------------------
  # ○ 公開インスタンス変数
  #--------------------------------------------------------------------------
  attr_accessor :current_weapon
  attr_accessor :current_main
  #--------------------------------------------------------------------------
  # ○ 装備品の初期化
  #     equips : 初期装備の配列
  #--------------------------------------------------------------------------
  def init_equips(equips)
    @equips = Array.new(equip_slots.size) { Game_BaseItem.new }
    equips.each_with_index do |item_id, i|
      etype_id = index_to_etype_id(i)
      slot_id = empty_slot(etype_id)
      @equips[slot_id].set_equip(etype_id == 0, item_id) if slot_id
    end
    refresh
  end
  #--------------------------------------------------------------------------
  # ○ 装備タイプからスロット ID に変換(空きを優先)
  #--------------------------------------------------------------------------
  def empty_slot(etype_id)
    list = slot_list(etype_id)
    list.find {|i| @equips.is_nil? } || list[0]
  end
  #--------------------------------------------------------------------------
  # ○ 装備タイプからスロット ID のリストに変換
  #--------------------------------------------------------------------------
  def slot_list(etype_id)
    result = []
    equip_slots.each_with_index {|e, i| result.push(i) if e == etype_id }
    result
  end
  #--------------------------------------------------------------------------
  # ○ エディタで設定されたインデックスを装備タイプ ID に変換
  #--------------------------------------------------------------------------
  def index_to_etype_id(index)
    index == 1 && dual_wield? ? 0 : index
  end
  #--------------------------------------------------------------------------
  # ○ 装備スロットの配列を取得
  #--------------------------------------------------------------------------
  def equip_slots
    return [0,0,2,3,4] if dual_wield?       # 二刀流
    return [0,1,2,3,4]                      # 通常
  end
  #--------------------------------------------------------------------------
  # ○ 装備品オブジェクトの配列取得
  #--------------------------------------------------------------------------
  def equips
    @equips.collect {|item| item.object }
  end
  #--------------------------------------------------------------------------
  # ○ 武器オブジェクトの配列取得
  #--------------------------------------------------------------------------
  def weapons
    @equips.select {|item| item.is_weapon? }.collect {|item| item.object }
  end
  #--------------------------------------------------------------------------
  # ○ 通常能力値の加算値取得
  #--------------------------------------------------------------------------
  def param_plus(param_id)
    equips.compact.inject(super) {|r, item| r += item.params[param_id] + ex_item_params(item, param_id) }
  end
  #--------------------------------------------------------------------------
  # ○ アイテムにかける追加要素
  #--------------------------------------------------------------------------
  def ex_item_params(item, param_id)
    return 0
  end
  #--------------------------------------------------------------------------
  # ○ スキルを取得
  #--------------------------------------------------------------------------
  def skill(skill_id)
    $data_skills[skill_id]
  end
end
#==============================================================================
# ■ Game_Party
#------------------------------------------------------------------------------
#  パーティを扱うクラスです。所持金やアイテムなどの情報が含まれます。このクラ
# スのインスタンスは $game_party で参照されます。
#==============================================================================

class Game_Party < Game_Unit
  #--------------------------------------------------------------------------
  # ☆ アクターを加える
  #--------------------------------------------------------------------------
  alias a1_battle_common_gp_add_actor add_actor
  def add_actor(actor_id)
    return a1_battle_common_gp_add_actor(actor_id) unless in_battle
    return if @actors.include?(actor_id)
    prev_add_actor(battle_members)
    insert_actor(actor_id)
    post_add_actor($game_actors[actor_id])
  end
  #--------------------------------------------------------------------------
  # ○ アクターを加える
  #--------------------------------------------------------------------------
  def insert_actor(actor_id)
    @new_index = @remove_member_index ? @remove_member_index[0] : @actors.size
    @actors.insert(@new_index, actor_id) unless @actors.include?(actor_id)
    $game_player.refresh
    $game_map.need_refresh = true
    return unless @remove_member_index
    @remove_member_index.delete_at(0)
    @remove_member_index = nil if @remove_member_index.empty?
  end
  #--------------------------------------------------------------------------
  # ○ アクターを加えたIndexを取得
  #--------------------------------------------------------------------------
  def new_index
    @new_index
  end
  #--------------------------------------------------------------------------
  # ○ アクターを加える前処理
  #--------------------------------------------------------------------------
  def prev_add_actor(members)
    BattleManager.call_method(:prev_add_battler, members)
  end
  #--------------------------------------------------------------------------
  # ○ アクターを加えた後処理
  #--------------------------------------------------------------------------
  def post_add_actor(member)
    BattleManager.call_method(:post_add_battler, member)
  end
  #--------------------------------------------------------------------------
  # ☆ アクターを外す
  #--------------------------------------------------------------------------
  alias a1_battle_common_gp_remove_actor remove_actor
  def remove_actor(actor_id)
    prev_remove_actor($game_actors[actor_id]) if in_battle
    a1_battle_common_gp_remove_actor(actor_id)
    post_remove_actor if in_battle
  end
  #--------------------------------------------------------------------------
  # ○ アクターを外す前処理
  #--------------------------------------------------------------------------
  def prev_remove_actor(member)
    @remove_member_index ||= []
    @remove_member_index.push(member.index)
    BattleManager.call_method(:prev_remove_battler, member)
  end
  #--------------------------------------------------------------------------
  # ○ アクターを外した後処理
  #--------------------------------------------------------------------------
  def post_remove_actor
    BattleManager.call_method(:post_remove_battler)
  end
end
#==============================================================================
# ■ BattleManager
#------------------------------------------------------------------------------
#  戦闘の進行を管理するモジュールです。
#==============================================================================

module BattleManager
  #--------------------------------------------------------------------------
  # ○ エイリアス用特異メソッド
  #--------------------------------------------------------------------------
  class << self
    alias :a1_battle_common_bm_turn_end :turn_end
    alias :a1_battle_common_bm_turn_start :turn_start
    alias :a1_battle_common_bm_battle_end :battle_end
  end
  #--------------------------------------------------------------------------
  # ☆ ターン開始
  #--------------------------------------------------------------------------
  def self.turn_start
    @turn_end_wait = 0
    a1_battle_common_bm_turn_start
  end
  #--------------------------------------------------------------------------
  # ☆ ターン終了
  #--------------------------------------------------------------------------
  def self.turn_end
    call_method(:wait, @turn_end_wait) if @turn_end_wait > 0
    @turn_end_wait = 0
    a1_battle_common_bm_turn_end
  end
  #--------------------------------------------------------------------------
  # ○ メソッドの設定
  #--------------------------------------------------------------------------
  def self.define_method(method, symbol)
    @method ||= {}
    @method[symbol] = method
  end
  #--------------------------------------------------------------------------
  # ○ メソッドのコール
  #--------------------------------------------------------------------------
  def self.call_method(symbol, *args)
    @method[symbol].call(*args) if @method[symbol]
  end
  #--------------------------------------------------------------------------
  # ○ ターン終了後ウェイト設定
  #--------------------------------------------------------------------------
  def self.turn_end_wait=(flame)
    @turn_end_wait = flame if @turn_end_wait < flame || flame == 0
  end
  #--------------------------------------------------------------------------
  # ☆ 戦闘終了
  #     result : 結果(0:勝利 1:逃走 2:敗北)
  #--------------------------------------------------------------------------
  def self.battle_end(result)
    call_method(:battle_end, result)
    a1_battle_common_bm_battle_end(result)
  end
end
#==============================================================================
# ■ Game_Action
#------------------------------------------------------------------------------
#  戦闘行動を扱うクラスです。このクラスは Game_Battler クラスの内部で使用され
# ます。
#==============================================================================

class Game_Action
  #--------------------------------------------------------------------------
  # ☆ ターゲットの配列作成
  #--------------------------------------------------------------------------
  alias a1_battle_common_gac_make_targets make_targets
  def make_targets
    @targets ||= pre_make_targets
    return @targets
  end
  #--------------------------------------------------------------------------
  # ○ ターゲットの配列先行作成
  #--------------------------------------------------------------------------
  def pre_make_targets
    @targets = a1_battle_common_gac_make_targets
  end
  #--------------------------------------------------------------------------
  # ○ ターゲットの配列を取得
  #--------------------------------------------------------------------------
  def targets
    @targets.compact
  end
  #--------------------------------------------------------------------------
  # ○ ターゲットの配列をクリア
  #--------------------------------------------------------------------------
  def clear_targets
    @targets = nil
  end
end
#==============================================================================
# ■ Scene_Battle
#------------------------------------------------------------------------------
#  バトル画面の処理を行うクラスです。
#==============================================================================

class Scene_Battle < Scene_Base
  #--------------------------------------------------------------------------
  # ☆ 開始処理
  #--------------------------------------------------------------------------
  alias a1_battle_common_sb_start start
  def start
    a1_battle_common_sb_start
    define_battle_manager_method
  end
  #--------------------------------------------------------------------------
  # ○ バトルマネージャメソッドの定義
  #--------------------------------------------------------------------------
  def define_battle_manager_method
    BattleManager.define_method(method(:wait), :wait)
    BattleManager.define_method(method(:post_add_battler),       :post_add_battler)
    BattleManager.define_method(method(:post_remove_battler),    :post_remove_battler)
    BattleManager.define_method(method(:prev_remove_battler),    :prev_remove_battler)
    BattleManager.define_method(method(:prev_add_battler),       :prev_add_battler)
    BattleManager.define_method(method(:process_victory),        :process_victory)
    BattleManager.define_method(method(:battle_end),             :battle_end)
  end
  #--------------------------------------------------------------------------
  # ☆ ステータスウィンドウの作成
  #--------------------------------------------------------------------------
  alias a1_battle_common_sb_create_status_window create_status_window
  def create_status_window
    a1_battle_common_sb_create_status_window
    post_create_status_window
    define_status_window_method
  end
  #--------------------------------------------------------------------------
  # ○ ステータスウィンドウ作成の後処理
  #--------------------------------------------------------------------------
  def post_create_status_window
  end
  #--------------------------------------------------------------------------
  # ○ ステータスウィンドウメソッドの定義
  #--------------------------------------------------------------------------
  def define_status_window_method
    @status_window.define_method(method(:refresh_statsu_window), :refresh_statsu_window)
    @status_window.define_method(method(:close_status_window),   :close_status_window)
    @status_window.define_method(method(:open_status_window),    :open_status_window)
    @status_window.define_method(method(:select_status_window),  :select_status_window)
    @status_window.define_method(method(:update_status_window),  :update_status_window)
    @status_window.define_method(method(:dispose_status_window), :dispose_status_window)
  end
  #--------------------------------------------------------------------------
  # ○ ステータスウィンドウがリフレッシュされた時の処理
  #--------------------------------------------------------------------------
  def refresh_statsu_window
  end
  #--------------------------------------------------------------------------
  # ○ ステータスウィンドウがクローズされた時の処理
  #--------------------------------------------------------------------------
  def close_status_window
  end
  #--------------------------------------------------------------------------
  # ○ ステータスウィンドウがオープンされた時の処理
  #--------------------------------------------------------------------------
  def open_status_window
  end
  #--------------------------------------------------------------------------
  # ○ ステータスウィンドウがセレクトされた時の処理
  #--------------------------------------------------------------------------
  def select_status_window(index)
  end
  #--------------------------------------------------------------------------
  # ○ ステータスウィンドウが更新された時の処理
  #--------------------------------------------------------------------------
  def update_status_window
  end
  #--------------------------------------------------------------------------
  # ○ ステータスウィンドウが解放された時の処理
  #--------------------------------------------------------------------------
  def dispose_status_window
  end
  #--------------------------------------------------------------------------
  # ☆ 情報表示ビューポートの作成
  #--------------------------------------------------------------------------
  alias a1_battle_common_sb_create_info_viewport create_info_viewport
  def create_info_viewport
    a1_battle_common_sb_create_info_viewport
    post_create_info_viewport
  end
  #--------------------------------------------------------------------------
  # ○ 情報表示ビューポート作成の後処理
  #--------------------------------------------------------------------------
  def post_create_info_viewport
  end
  #--------------------------------------------------------------------------
  # ☆ スキルウィンドウの作成
  #--------------------------------------------------------------------------
  alias a1_battle_common_sb_create_skill_window create_skill_window
  def create_skill_window
    a1_battle_common_sb_create_skill_window
    post_create_skill_window
    define_skill_window_method
  end
  #--------------------------------------------------------------------------
  # ○ スキルウィンドウ作成の後処理
  #--------------------------------------------------------------------------
  def post_create_skill_window
  end
  #--------------------------------------------------------------------------
  # ○ スキルウィンドウメソッドの定義
  #--------------------------------------------------------------------------
  def define_skill_window_method
    @skill_window.define_method(method(:skill_item_window_show), :skill_item_window_show)
    @skill_window.define_method(method(:skill_item_window_hide), :skill_item_window_hide)
  end
  #--------------------------------------------------------------------------
  # ☆ アイテムウィンドウの作成
  #--------------------------------------------------------------------------
  alias a1_battle_common_sb_create_item_window create_item_window
  def create_item_window
    a1_battle_common_sb_create_item_window
    post_create_item_window
    define_item_window_method
  end
  #--------------------------------------------------------------------------
  # ○ アイテムウィンドウ作成の後処理
  #--------------------------------------------------------------------------
  def post_create_item_window
  end
  #--------------------------------------------------------------------------
  # ○ アイテムウィンドウメソッドの定義
  #--------------------------------------------------------------------------
  def define_item_window_method
    @item_window.define_method(method(:skill_item_window_show), :skill_item_window_show)
    @item_window.define_method(method(:skill_item_window_hide), :skill_item_window_hide)
  end
  #--------------------------------------------------------------------------
  # ○ スキル/アイテムウィンドウが表示された時の処理
  #--------------------------------------------------------------------------
  def skill_item_window_show
  end
  #--------------------------------------------------------------------------
  # ○ スキル/アイテムウィンドウが非表示になった時の処理
  #--------------------------------------------------------------------------
  def skill_item_window_hide
  end
  #--------------------------------------------------------------------------
  # ☆ パーティコマンドウィンドウの作成
  #--------------------------------------------------------------------------
  alias a1_battle_common_sb_create_actor_command_window create_actor_command_window
  def create_actor_command_window
    a1_battle_common_sb_create_actor_command_window
    post_create_actor_command_window
    define_actor_command_window_method
    define_actor_command_window_handle
  end
  #--------------------------------------------------------------------------
  # ○ パーティコマンドウィンドウ作成の後処理
  #--------------------------------------------------------------------------
  def post_create_actor_command_window
  end
  #--------------------------------------------------------------------------
  # ○ パーティコマンドウィンドウメソッドの定義
  #--------------------------------------------------------------------------
  def define_actor_command_window_method
  end
  #--------------------------------------------------------------------------
  # ○ パーティコマンドウィンドウハンドルの定義
  #--------------------------------------------------------------------------
  def define_actor_command_window_handle
  end
  #--------------------------------------------------------------------------
  # ☆ アクターウィンドウの作成
  #--------------------------------------------------------------------------
  alias a1_battle_common_sb_create_actor_window create_actor_window
  def create_actor_window
    a1_battle_common_sb_create_actor_window
    post_create_actor_window
    define_actor_window_method
  end
  #--------------------------------------------------------------------------
  # ○ アクターウィンドウ作成の後処理
  #--------------------------------------------------------------------------
  def post_create_actor_window
  end
  #--------------------------------------------------------------------------
  # ○ アクターウィンドウメソッドの定義
  #--------------------------------------------------------------------------
  def define_actor_window_method
    @actor_window.define_method(method(:select_actor),     :select_actor)
    @actor_window.define_method(method(:select_actor_end), :select_actor_end)
  end
  #--------------------------------------------------------------------------
  # ○ アクターウィンドウをセレクトした時の処理
  #--------------------------------------------------------------------------
  def select_actor(index)
  end
  #--------------------------------------------------------------------------
  # ○ アクターウィンドウをセレクト終了した時の処理
  #--------------------------------------------------------------------------
  def select_actor_end
  end
  #--------------------------------------------------------------------------
  # ☆ 敵キャラウィンドウの作成
  #--------------------------------------------------------------------------
  alias a1_battle_common_sb_create_enemy_window create_enemy_window
  def create_enemy_window
    a1_battle_common_sb_create_enemy_window
    post_create_enemy_window
    define_enemy_window_method
  end
  #--------------------------------------------------------------------------
  # ○ 敵キャラウィンドウ作成の後処理
  #--------------------------------------------------------------------------
  def post_create_enemy_window
  end
  #--------------------------------------------------------------------------
  # ○ 敵キャラウィンドウメソッドの定義
  #--------------------------------------------------------------------------
  def define_enemy_window_method
    @enemy_window.define_method(method(:select_enemy),     :select_enemy)
    @enemy_window.define_method(method(:select_enemy_end) ,:select_enemy_end)
  end
  #--------------------------------------------------------------------------
  # ○ 敵キャラウィンドウをセレクトした時の処理
  #--------------------------------------------------------------------------
  def select_enemy(index)
  end
  #--------------------------------------------------------------------------
  # ○ 敵キャラウィンドウをセレクト終了した時の処理
  #--------------------------------------------------------------------------
  def select_enemy_end
  end
  #--------------------------------------------------------------------------
  # ☆ アクターコマンドウィンドウの作成
  #--------------------------------------------------------------------------
  alias a1_battle_common_sb_start_create_actor_command_window create_actor_command_window
  def create_actor_command_window
    a1_battle_common_sb_start_create_actor_command_window
    post_create_actor_command_window
    define_actor_command_handle
    define_actor_command_window
  end
  #--------------------------------------------------------------------------
  # ○ アクターコマンドウィンドウ作成の後処理
  #--------------------------------------------------------------------------
  def post_create_actor_command_window
  end
  #--------------------------------------------------------------------------
  # ○ アクターコマンドウィンドウメソッドの定義
  #--------------------------------------------------------------------------
  def define_actor_command_window
    @actor_command_window.define_method(method(:actor_command_open),  :actor_command_open)
    @actor_command_window.define_method(method(:actor_command_close), :actor_command_close)
    @actor_command_window.define_method(method(:actor_command_setup), :actor_command_setup)
  end
  #--------------------------------------------------------------------------
  # ○ アクターコマンドウィンドウハンドルの定義
  #--------------------------------------------------------------------------
  def define_actor_command_handle
  end
  #--------------------------------------------------------------------------
  # ○ アクターコマンドウィンドウがオープンした時の処理
  #--------------------------------------------------------------------------
  def actor_command_open
  end
  #--------------------------------------------------------------------------
  # ○ アクターコマンドウィンドウがクローズした時の処理
  #--------------------------------------------------------------------------
  def actor_command_close
  end
  #--------------------------------------------------------------------------
  # ○ アクターコマンドウィンドウのセットアップ時の処理
  #--------------------------------------------------------------------------
  def actor_command_setup(actor)
  end
  #--------------------------------------------------------------------------
  # ☆ パーティコマンド選択の開始
  #--------------------------------------------------------------------------
  alias a1_battle_common_sb_start_party_command_selection start_party_command_selection
  def start_party_command_selection
    prev_start_party_command_selection
    a1_battle_common_sb_start_party_command_selection
    post_start_party_command_selection
  end
  #--------------------------------------------------------------------------
  # ○ パーティコマンド選択の開始の前処理
  #--------------------------------------------------------------------------
  def prev_start_party_command_selection
  end
  #--------------------------------------------------------------------------
  # ○ パーティコマンド選択の開始の後処理
  #--------------------------------------------------------------------------
  def post_start_party_command_selection
  end
  #--------------------------------------------------------------------------
  # ☆ 次のコマンド入力へ
  #--------------------------------------------------------------------------
  alias a1_battle_common_sb_next_command next_command
  def next_command
    prev_next_command
    a1_battle_common_sb_next_command
    post_next_command
  end
  #--------------------------------------------------------------------------
  # ○ 次のコマンド入力への前処理
  #--------------------------------------------------------------------------
  def prev_next_command
  end
  #--------------------------------------------------------------------------
  # ○ 次のコマンド入力への後処理
  #--------------------------------------------------------------------------
  def post_next_command
  end
  #--------------------------------------------------------------------------
  # ☆ 前のコマンド入力へ
  #--------------------------------------------------------------------------
  alias a1_battle_common_sb_prior_command prior_command
  def prior_command
    prev_prior_command
    a1_battle_common_sb_prior_command
    post_prior_command
  end
  #--------------------------------------------------------------------------
  # ○ 前のコマンド入力への前処理
  #--------------------------------------------------------------------------
  def prev_prior_command
  end
  #--------------------------------------------------------------------------
  # ○ 前のコマンド入力への後処理
  #--------------------------------------------------------------------------
  def post_prior_command
  end
  #--------------------------------------------------------------------------
  # ☆ ターン開始
  #--------------------------------------------------------------------------
  alias a1_battle_common_sb_turn_start turn_start
  def turn_start
    prev_turn_start
    a1_battle_common_sb_turn_start
    post_turn_start
  end
  #--------------------------------------------------------------------------
  # ○ ターン開始の前処理
  #--------------------------------------------------------------------------
  def prev_turn_start
  end
  #--------------------------------------------------------------------------
  # ○ ターン開始の後処理
  #--------------------------------------------------------------------------
  def post_turn_start
  end
  #--------------------------------------------------------------------------
  # ☆ ターン終了
  #--------------------------------------------------------------------------
  alias a1_battle_common_sb_turn_end turn_end
  def turn_end
    prev_turn_end
    a1_battle_common_sb_turn_end
    post_turn_end
  end
  #--------------------------------------------------------------------------
  # ○ ターン終了の前処理
  #--------------------------------------------------------------------------
  def prev_turn_end
  end
  #--------------------------------------------------------------------------
  # ○ ターン終了の後処理
  #--------------------------------------------------------------------------
  def post_turn_end
  end
  #--------------------------------------------------------------------------
  # ○ ウィンドウが閉じるまでウェイト
  #--------------------------------------------------------------------------
  def wait_fot_window_close(window)
    update_basic while window.close?
  end
  #--------------------------------------------------------------------------
  # ○ アクターのバトルメンバー取得
  #--------------------------------------------------------------------------
  def battle_members
    @party_battle_members ||= $game_party.battle_members
    return @party_battle_members
  end
  #--------------------------------------------------------------------------
  # ○ バトルメンバーの追加の前処理
  #--------------------------------------------------------------------------
  def prev_add_battler(members)
  end
  #--------------------------------------------------------------------------
  # ○ バトルメンバーの追加後の処理
  #--------------------------------------------------------------------------
  def post_add_battler(member)
    @party_battle_members = $game_party.battle_members
  end
  #--------------------------------------------------------------------------
  # ○ バトルメンバー削除の前処理
  #--------------------------------------------------------------------------
  def prev_remove_battler(member)
  end
  #--------------------------------------------------------------------------
  # ○ バトルメンバーの削除後の処理
  #--------------------------------------------------------------------------
  def post_remove_battler
    @party_battle_members = $game_party.battle_members
  end
  #--------------------------------------------------------------------------
  # ☆ 戦闘行動の実行
  #--------------------------------------------------------------------------
  alias a1_battle_common_sb_execute_action execute_action
  def execute_action
    prev_execute_action
    a1_battle_common_sb_execute_action
    post_execute_action
  end
  #--------------------------------------------------------------------------
  # ○ 戦闘行動の実行の前処理
  #--------------------------------------------------------------------------
  def prev_execute_action
    @subject.current_action.pre_make_targets
  end
  #--------------------------------------------------------------------------
  # ○ 戦闘行動の実行の後処理
  #--------------------------------------------------------------------------
  def post_execute_action
    @subject.current_action.clear_targets if @subject.current_action
  end
  #--------------------------------------------------------------------------
  # ☆ スキル/アイテムの使用
  #--------------------------------------------------------------------------
  alias a1_battle_common_sb_use_item use_item
  def use_item
    prev_use_item
    a1_battle_common_sb_use_item
    post_use_item
  end
  #--------------------------------------------------------------------------
  # ○ スキル/アイテムの使用の前処理
  #--------------------------------------------------------------------------
  def prev_use_item
  end
  #--------------------------------------------------------------------------
  # ○ スキル/アイテムの使用の後処理
  #--------------------------------------------------------------------------
  def post_use_item
  end
  #--------------------------------------------------------------------------
  # ○ 勝利の処理
  #--------------------------------------------------------------------------
  def process_victory
  end
  #--------------------------------------------------------------------------
  # ○ 戦闘終了
  #--------------------------------------------------------------------------
  def battle_end(result)
    $game_party.all_members.each {|member| init_member_battle_end(member) }
  end
  #--------------------------------------------------------------------------
  # ○ 戦闘終了時のメンバー初期化
  #--------------------------------------------------------------------------
  def init_member_battle_end(member)
    member.current_weapon = nil
    member.current_main   = nil
  end
end
end

#===========================================================================
# ◆ A1 Scripts ◆
#    戦闘中入れ替え(RGSS3)
#
# バージョン   : 1.00 (2012/01/18)
# 作者         : A1
# URL     : http://a1tktk.web.fc2.com/
#---------------------------------------------------------------------------
# 機能:
# ?戦闘中にメンバーを入れ替えます
#---------------------------------------------------------------------------
# 更新履歴   :2012/01/18 Ver1.00 リリース
#---------------------------------------------------------------------------
# 設置場所      
#    A1バトル共通スクリプト以下
#
# 必要スクリプト
#    A1バトル共通スクリプト
#---------------------------------------------------------------------------
# 使い方
#   導入することで適用されます
#==============================================================================
$imported ||= {}
if $imported["A1_BattleCommonScript"]
$imported["A1_ChangeMember"] = true
old_common_script("戦闘中入れ替え", "3.90") if common_version < 3.90
#==============================================================================
# ■ Window_PartyCommand
#==============================================================================

class Window_MemberChange < Window_Selectable
  #--------------------------------------------------------------------------
  # ○ オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    @form_actor_window = Window_PersonalStatus.new(0, Graphics.height - 120, 255)
    @to_actor_window   = Window_PersonalStatus.new(Graphics.width / 2, Graphics.height - 120, 255)
    setup_members
    width              = @battle_members.size * 48 + standard_padding * 2
    height             = (@all_members.size / @battle_members.size.to_f).ceil * 48 + standard_padding * 2 + 36
    super((Graphics.width - width) / 2, (Graphics.height - height) / 2, width, height)
    self.y = Graphics.height - @form_actor_window.height - height if self.y + height > Graphics.height - @form_actor_window.height
    self.index = 0
    @from_actor = -1
    self.openness = 0
  end
  #--------------------------------------------------------------------------
  # ○ アクティブ化
  #--------------------------------------------------------------------------
  def activate
    super
    refresh
    @form_actor_window.actor = @all_members[self.index]
  end
  #--------------------------------------------------------------------------
  # ○ メンバーのセットアップ
  #--------------------------------------------------------------------------
  def setup_members
    @all_members    = $game_party.all_members
    @battle_members = $game_party.battle_members
  end
  #--------------------------------------------------------------------------
  # ○ 項目の選択
  #--------------------------------------------------------------------------
  def select(index)
    super
    @form_actor_window.actor = @all_members[self.index] if @from_actor == -1
    @to_actor_window.actor   = @all_members[self.index] if @from_actor >= 0
   
  end
  #--------------------------------------------------------------------------
  # ○ 項目数の取得
  #--------------------------------------------------------------------------
  def item_max
    @all_members.size
  end
  #--------------------------------------------------------------------------
  # ○ 桁数の取得
  #--------------------------------------------------------------------------
  def col_max
    @battle_members.size
  end
  #--------------------------------------------------------------------------
  # ○ リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    super
    draw_horz_line(52)
  end
  #--------------------------------------------------------------------------
  # ○ 水平線の描画
  #--------------------------------------------------------------------------
  def draw_horz_line(y)
    line_y = y + line_height / 2 - 1
    contents.fill_rect(0, line_y, contents_width, 2, line_color)
  end
  #--------------------------------------------------------------------------
  # ○ 水平線の色を取得
  #--------------------------------------------------------------------------
  def line_color
    color = normal_color
    color.alpha = 128
    color
  end
  #--------------------------------------------------------------------------
  # ○ 項目の描画
  #--------------------------------------------------------------------------
  def draw_item(index)
    c_name  = member(index).character_name
    c_index = member(index).character_index
    rect    = item_rect(index)
    draw_character(c_name, c_index, rect.x + 24, rect.y + 40)
  end
  #--------------------------------------------------------------------------
  # ○ 項目を描画する矩形の取得
  #--------------------------------------------------------------------------
  def item_rect(index)
    rect = Rect.new
    rect.width = item_width
    rect.height = item_height
    rect.x = index % col_max * item_width
    rect.y = index / col_max * item_height
    rect.y += 24 if index > @battle_members.size - 1
    rect
  end
  #--------------------------------------------------------------------------
  # ○ 項目の幅を取得
  #--------------------------------------------------------------------------
  def item_width
    return 48
  end
  #--------------------------------------------------------------------------
  # ○ 項目の高さを取得
  #--------------------------------------------------------------------------
  def item_height
    return 48
  end
  #--------------------------------------------------------------------------
  # ○ ウィンドウ内容の高さを計算
  #--------------------------------------------------------------------------
  def contents_height
    row_max * item_height + 24
  end
  #--------------------------------------------------------------------------
  # ○ 下端パディングの更新
  #--------------------------------------------------------------------------
  def update_padding_bottom
    surplus = (height - standard_padding * 2) % item_height - 24
    self.padding_bottom = padding + surplus
  end
  #--------------------------------------------------------------------------
  # ○ メンバーの取得
  #--------------------------------------------------------------------------
  def member(index)
    @all_members[index]
  end
  #--------------------------------------------------------------------------
  # ○ 決定処理の有効状態を取得
  #--------------------------------------------------------------------------
  def ok_enabled?
    return true
  end
  #--------------------------------------------------------------------------
  # ○ 決定ボタンが押されたときの処理
  #--------------------------------------------------------------------------
  def process_ok
    Sound.play_ok
    Input.update
    return select_start_to_actor if @from_actor == -1
    return call_cancel_handler if @from_actor == self.index
    change_member if @from_actor >= 0
    post_change_member
  end
  #--------------------------------------------------------------------------
  # ○ メンバー入れ替え
  #--------------------------------------------------------------------------
  def change_member
    $game_party.swap_order(@from_actor, self.index)
   
  end
  #--------------------------------------------------------------------------
  # ○ メンバー入れ替え後の処理
  #--------------------------------------------------------------------------
  def post_change_member
    setup_members
    self.index  = @from_actor
    @form_actor_window.actor = @all_members[self.index]
    @from_actor = -1
    @to_actor_window.close
    p 1234567
   @battle_hud_ex = Monogatari_Bhud.new(nil)
   @battle_hud_ex.update
   
    refresh
  end
  #--------------------------------------------------------------------------
  # ○ 入れ替え先のアクター選択開始
  #--------------------------------------------------------------------------
  def select_start_to_actor
    @from_actor = self.index
    @to_actor_window.open
    self.index = self.index < @battle_members.size ? @battle_members.size : 0
    @to_actor_window.actor = @all_members[self.index]
  end
  #--------------------------------------------------------------------------
  # ○ 入れ替え元のアクター
  #--------------------------------------------------------------------------
  def from_actor
    @from_actor
  end
  #--------------------------------------------------------------------------
  # ○ オープン
  #--------------------------------------------------------------------------
  def open
    super
    @form_actor_window.open
  end
  #--------------------------------------------------------------------------
  # ○ キャンセルハンドラの呼び出し
  #--------------------------------------------------------------------------
  def call_cancel_handler
    super if @from_actor == -1
    @from_actor = -1
    @to_actor_window.close
    @form_actor_window.actor = @all_members[self.index]
    activate
  end
  #--------------------------------------------------------------------------
  # ○ クローズ
  #--------------------------------------------------------------------------
  def close
    super
    @form_actor_window.close
    @to_actor_window.close
  end
  #--------------------------------------------------------------------------
  # ○ フレーム更新
  #--------------------------------------------------------------------------
  def update
    super
    @form_actor_window.update
    @to_actor_window.update
  end
  #--------------------------------------------------------------------------
  # ○ 解放
  #--------------------------------------------------------------------------
  def dispose
    super
    @form_actor_window.dispose
    @to_actor_window.dispose
  end
end
#==============================================================================
# ■ Window_PartyCommand
#------------------------------------------------------------------------------
#  バトル画面で、戦うか逃げるかを選択するウィンドウです。
#==============================================================================

class Window_ActorCommand < Window_Command
  #--------------------------------------------------------------------------
  # ☆ コマンドリストの作成
  #--------------------------------------------------------------------------
  alias a1_cbm_wpc_make_command_list make_command_list
  def make_command_list
    a1_cbm_wpc_make_command_list
    add_command("替换", :member_change, $game_party.all_members.size > $game_party.max_battle_members&&$tihuan==true)
  end
end
#==============================================================================
# ■ Scene_Battle
#------------------------------------------------------------------------------
#  バトル画面の処理を行うクラスです。
#==============================================================================

class Scene_Battle < Scene_Base
  #--------------------------------------------------------------------------
  # ☆ 全ウィンドウの作成
  #--------------------------------------------------------------------------
  alias a1_cbm_wpc_create_all_windows create_all_windows
  def create_all_windows
    a1_cbm_wpc_create_all_windows
    create_member_change_window
  end
  #--------------------------------------------------------------------------
  # ○ 入れ替えウィンドウの作成
  #--------------------------------------------------------------------------
  def create_member_change_window
    @window_member_change = Window_MemberChange.new
    @window_member_change.set_handler(:cancel, method(:on_member_change_cancel))
  end
  #--------------------------------------------------------------------------
  # ☆ パーティコマンドウィンドウハンドルの定義
  #--------------------------------------------------------------------------
  alias a1_cbm_sb_define_actor_command_window_handle define_actor_command_window_handle
  def define_actor_command_window_handle
    a1_cbm_sb_define_actor_command_window_handle
    @actor_command_window.set_handler(:member_change,  method(:command_member_change))
  end
  #--------------------------------------------------------------------------
  # ○ 入れ替え
  #--------------------------------------------------------------------------
  def command_member_change
    @prev_battle_members = $game_party.battle_members
    @status_window.close
    @party_command_window.close
    @window_member_change.open
    @window_member_change.activate
  end
  #--------------------------------------------------------------------------
  # ○ 変更したメンバーを取得
  #--------------------------------------------------------------------------
  def change_diss_members(ret = [])
    $game_party.battle_members.each_with_index {|member, i| ret.push(member) if member != @prev_battle_members }
    return ret
  end
  #--------------------------------------------------------------------------
  # ○ メンバーチェンジ[キャンセル]
  #--------------------------------------------------------------------------
  def on_member_change_cancel
    @party_command_window.activate
    @status_window.refresh
    @status_window.open
    @party_command_window.open
    @window_member_change.close
    change_diss_members.each {|member| member.make_actions }
    @party_battle_members = $game_party.battle_members
  end
end
end
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-11-15 05:38

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表