Advertisement
dyalgi

BFK DayNight

Apr 24th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 53.24 KB | None | 0 0
  1.   #--------------------------------------------------------------------------
  2.   # SISTEMA DIA E NOITE (BY RAVEN) - v3.6 -
  3.   #--------------------------------------------------------------------------
  4.   # * COMO USAR O SISTEMA DE DIA E NOITE
  5.   # - BASTA QUE ESTE SCRIPT ESTEJA ACIMA DO MAIN
  6.   # - PARA MUDAR A HORA INICIAL BASTA ALTERAR a variavel "START_TIME_INGAME"
  7.   # - PARA MUDAR A VELOCIDADE DO TEMPO BASTA MUDAR A VARIAVEL "SEC_MIN" (< MAIS RAPIDO)
  8.   # - PARA ALTERAR O TEMPO DE CADA CICLO BASTA ALTERAR A VARIAVEL "CICLOS"
  9.   # - CONFORME ORIENTAÇÃO NOS COMENTARIOS
  10.   #
  11.   #********************************************************************
  12.   # COMANDOS PUBLICOS PARA SEREM USADOS NO MAPA OU EVENTOS
  13.   #********************************************************************
  14.   # <daynight: off> - Se colocado no espaço de notas do mapa fará com que o
  15.   #                   script não mude a tonalidade naquele mapa
  16.   # <daynight_time: 500> - Se colocado no espaço de notas do mapa fará com que o
  17.   #                   valor do tempo corrente acelerar ou diminuir (valor alto mais lento)
  18.   #
  19.   # <daynight_troop> ciclo = [tempo, id_troop, %] phase = [id_troop, %] </daynight_troop>
  20.   #                   - Se colocado no espaço de notas do mapa fará com que a
  21.   #                   Tropa com o id "id_troop", mude as chances de aparecer para
  22.   #                   a porcentagem (0~100) em "frequencia", durante o periodo
  23.   #                   especificado em "phase" (nota: so serão alterados
  24.   #                   tropas que estiverem na lista de encontros do mapa  
  25.   #
  26.   # <daynight_step> ciclo = [tempo,nºstep] phase = nº_step </daynight_step>
  27.   #                   - Se colocado no espaço de notas do mapa fará com que as
  28.   #                   chances de acontecer um encontro "steps" (menor mais chances)
  29.   #                   durante um periodo especifico "phase"
  30.   #                   caso o periodo não seja especificado, o valor de steps (passos)
  31.   #                   será mantido conforme original
  32.   #
  33.   # $game_daynight.altTime(["min",10],["day",-3],["mes",-20],["ano",1970,true])
  34.   #                 - pode alterar qualquer parte do tempo com qualquer valor
  35.   #                   positivos ou negativos, se um 3º argumento for informado
  36.   #                   (true) o valor será exato (não somara)
  37.   # $game_daynight.timeIngame
  38.   #                 - Imprime no debug a hora in game atual
  39.   # $game_daynight.dateIngame
  40.   #                 - Imprime no debug a data in game atual
  41.   # $game_daynight.which_phase_name?
  42.   #                 - Retorna o nome da fase do dia
  43.   # $game_daynight.which_phase_id?
  44.   #                 - Retorna o id da fase do dia (para popular variaveis)
  45.   # $game_daynight.how_many_min?
  46.   #                 - Retorna o minuto em jogo em formato 2 digitos
  47.   # $game_daynight.min_ingame
  48.   #                 - Retorna o minuto em jogo (para popular variaveis)
  49.   # $game_daynight.how_many_hour?
  50.   #                 - Retorna a hora em jogo em formato 2 digitos
  51.   # $game_daynight.hour_ingame
  52.   #                 - Retorna a hora em jogo (para popular variaveis)
  53.   # $game_daynight.how_many_day?
  54.   #                 - Retorna o dia em jogo eem formato 2 digitos
  55.   # $game_daynight.day_ingame
  56.   #                 - Retorna o dia em jogo (para popular variaveis)
  57.   # $game_daynight.how_many_month?
  58.   #                 - Retorna os meses em jogo em formato 2 digitos
  59.   # $game_daynight.month_ingame
  60.   #                 - Retorna os meses em jogo (para popular variaveis)
  61.   # $game_daynight.how_many_month_name?(abr=false)
  62.   #                 - Retorna os meses em formato de texto, se tiver argumento
  63.   #                   retorna a abreviação
  64.   # $game_daynight.how_many_year?
  65.   #                 - Retorna os anos em jogo em formato 4 digitos
  66.   # $game_daynight.year_ingame
  67.   #                 - Retorna os anos em jogo (para popular variaveis)
  68.   # $game_daynight.time_hud
  69.   #                 - Ativa e desativa o relogio (true/false) para funcionar a
  70.   #                   a variavel DISPLAY_HUD deve estar configurada em true.
  71.   #--------------------------------------------------------------------------
  72.   # COMANDOS PARA MENSAGENS
  73.   #--------------------------------------------------------------------------
  74.   # \Data   - Exibe na janela a data atual (dd/M/yyyy)
  75.   # \Time   - Exibe na janela a hora atual (H:m)
  76.   # \Phase  - Exibe na janela o periodo atual atual
  77.   # \Minute - Exibe na janela os minutos atuais
  78.   # \Hour   - Exibe na janela as horas atuais
  79.   # \Day    - Exibe na janela os dias atuais
  80.   # \Month  - Exibe na janela os meses atuais
  81.   # \Year   - Exibe na janela os anos atuais
  82.   #--------------------------------------------------------------------------
  83. $registro = [] if $registro.nil?
  84. $registro << ["BFK DayNight",3.6]
  85. class << DataManager
  86.   #--------------------------------------------------------------------------
  87.   # * Salvar a criação de conteúdo
  88.   #--------------------------------------------------------------------------
  89.   alias daynight_make_save_contents make_save_contents
  90.   def make_save_contents
  91.     contents = daynight_make_save_contents
  92.     contents[:daynight] = $game_daynight
  93.     contents
  94.   end
  95.   #--------------------------------------------------------------------------
  96.   # * Extrair conteúdo salvo
  97.   #     contents : matriz de quests
  98.   #--------------------------------------------------------------------------
  99.   alias daynight_extract_save_contents extract_save_contents
  100.   def extract_save_contents(contents)
  101.     daynight_extract_save_contents(contents)
  102.     $game_daynight = contents[:daynight]
  103.   end
  104. end
  105. #==============================================================================
  106. # ** MODULO BKF
  107. #------------------------------------------------------------------------------
  108. #  Este é o modulo principal para scripts feitos por este core
  109. #==============================================================================
  110. module BFK
  111.   self.modular("BFK Core",1.0)
  112.   #--------------------------------------------------------------------------
  113.   # * Aqui se encontra todas as variaveis para configuração e instalação
  114.   #--------------------------------------------------------------------------
  115.   module DayNight
  116.     #--------------------------------------------------------------------------
  117.     # * BFK_DayNight_Periodos = 1/Dia 2/tarde 3/Noite 4/Madrugada
  118.     #--------------------------------------------------------------------------
  119.     START_TIME_INGAME = [00,21,30,12,1979]   # (min,hora,dia, mes, ano) para o inicio do jogo
  120.     SEC_MIN = 60 # quantos milesimos segundos dura o minuto em jogo?
  121.     CICLOS = [60,24,30,12] # (minutos/hora, Horas/dias, dias/meses, meses ano)
  122.     MONTH_NAMES =  [["Meses","abrev"],["Janeiro","Ene"],["Fevereiro","Feb"],
  123.                     ["Março","Mar"],["Abril","Abr"],["Maio","May"],["Junho","Jun"],
  124.                     ["Julho","Jul"],["Agosto","Ago"],["Setembro","Sep"],
  125.                     ["Outubro","Oct"], ["Novembro","Nov"], ["Dezembro","Dic"]]
  126.     CICLOS_NAMES = [["horas","hora"],["minutos","min"],["dias","dia"],["meses","mes"], ["años","año"]]
  127.     PHASE = [
  128.       ["dia",Tone.new(0,0,0),[6,16]], # [ NOME_DO_CICLO, TONALIDADE, [HORA DE INICIO, HORA DO FIM]
  129.       ["tarde",Tone.new(-32,  -96, -66),[17,20]],
  130.       ["noche",Tone.new(-170, -153, -136),[21,3]],
  131.       ["madrugada",Tone.new(-66, -66, -66),[4,5]]
  132.       ]
  133.     PHASE_CICLO = CICLOS[1]
  134.     PHASE_D = (Graphics.frame_rate * CICLOS[0])/SEC_MIN #quanto vai demorar para a tansição completar
  135.     MENU_NAME = "Tiempo" #texto da Opção do Menu
  136.     MENU_ACTIVE = true # Ativa a Opção de controlar o tempo no menu
  137.     MENU_TIME = true # Ativa a janela de tempo no menu
  138.     MENU_DATE = true # Ativa a Janela de data no menu
  139.     MAX_DIGIT = 12 # (4 PARA SÓ AS HORAS, E 12 PARA DATA COMPLETA)
  140.     DISPLAY_HUD = true # Exibe a Janela de hora no mapa
  141.     DISPLAY_HUD_POS = 1 # Posição que ficará a janela de hoa no mapa,
  142.                           # 0 para canto superior esquerdo
  143.                           # 1 para canto superior direito
  144.                           # 2 para canto inferior direito
  145.                           # 3 para canto inferior esquerdo
  146.     #--------------------------------------------------------------------------
  147.     # * Comentando a linha a baixo, o programa não vai popular as variaveis
  148.     # será possivel apanhalas domente atraves dos metodos how_many e which_
  149.     #--------------------------------------------------------------------------
  150.     VARIABLE = [84,85,86,87,88,89]  # [VAR001 = phase, VAR002 = MIN, VAR003 = HORA,
  151.                               #  VAR004 = DIA, VAR005 = MES, VAR006 = ANO]
  152.     SWITCH = [81,82,83,84]        # [S001 = Dia, S002=Tarde, s003=Noite, S004 = Madrugada
  153.     #--------------------------------------------------------------------------
  154.     # * ATENÇÃO NÃO ALTERAR AS VARIAVEIS ABAIXO (ELAS PODEM MUDAR DEPENDENDO DA ATUALIZAÇÃO
  155.     #--------------------------------------------------------------------------
  156.     RGXMAP = /<(?:daynight):[ ]*(?:off)>/i
  157.     RGXMAP_SEC_MIN = /<(?:daynight_time):[ ]*(\d{1,})>/xi
  158.     #--------------------------------------------------------------------------
  159.     RGXMAP_STEP_ST = /<(?:DAYNIGHT_STEP|daynight step)>/i
  160.     RGXMAP_STEP_ED = /<\/(?:DAYNIGHT_STEP|daynight step)>/i
  161.     RGXMAP_TROOP_ST = /<(?:DAYNIGHT_TROOP|daynight troop)>/i
  162.     RGXMAP_TROOP_ED = /<\/(?:DAYNIGHT_TROOP|daynight troop)>/i
  163.     RGX_VALUES_STEPS = /(\w+)\s*[=]\s*\[?(\d{1,})[,]?(\d{1,})?\]?/xi
  164.     RGX_VALUES_TROOPS = /(\w+)\s*[=]\s*\[(\d{1,})[,]?(\d{1,})?[,]?(\d{1,})?\]/xi
  165.     MENU_SPACE = 18
  166.     MENU_RECT = 10
  167.     #--------------------------------------------------------------------------
  168.   end
  169. end
  170. #==============================================================================
  171. # ** DayNight
  172. #------------------------------------------------------------------------------
  173. #  Esta é a superclasse para todo o controle de tempo no jogo
  174. #==============================================================================
  175. class DayNight
  176.   attr_accessor :minutos
  177.   attr_accessor :phase_ingame
  178.   attr_accessor :trans
  179.   attr_accessor :time_hud
  180.   #--------------------------------------------------------------------------
  181.   # * Inicia o Objeto com as configurações iniciais
  182.   #--------------------------------------------------------------------------
  183.   def initialize
  184.     return if $game_map == nil
  185.     @minutos = change_minutes(BFK::DayNight::START_TIME_INGAME) unless @minutos
  186.     @min_seg = 0
  187.     @trans = nil
  188.     map = $game_map.get_map
  189.     @step_original = map.encounter_step
  190.     @time_hud = BFK::DayNight::DISPLAY_HUD
  191.     clear_daynight
  192.     refresh
  193.     # aqui é a saida do menu =) ele refaz o initialize
  194.   end
  195.   def time_hud=(value)
  196.     @time_hud = (BFK::DayNight::DISPLAY_HUD)? value : BFK::DayNight::DISPLAY_HUD
  197.   end
  198.  
  199.   def set_sec
  200.     map = $game_map.get_map
  201.     sec = map.note.scan(BFK::DayNight::RGXMAP_SEC_MIN)
  202.     return BFK::DayNight::SEC_MIN  if sec.empty?
  203.     return sec[0][0].to_i
  204.   end
  205.  
  206.   #--------------------------------------------------------------------------
  207.   # * Verifica o estado de transição
  208.   #--------------------------------------------------------------------------
  209.   def trans
  210.     @trans
  211.   end
  212.   #--------------------------------------------------------------------------
  213.   # * Recupera o valor original da lista de encontro
  214.   #--------------------------------------------------------------------------
  215.   def bak_enconterlist(map_id,id)
  216.     mapa = load_data(sprintf("Data/Map%03d.rvdata2",map_id))
  217.     return mapa.encounter_list[id]
  218.   end
  219.   #--------------------------------------------------------------------------
  220.   # * recupera o valor original dos passos
  221.   #--------------------------------------------------------------------------
  222.   def bak_enconterstep(map_id)
  223.     mapa = load_data(sprintf("Data/Map%03d.rvdata2",map_id))
  224.     return mapa.encounter_step
  225.   end
  226.   #--------------------------------------------------------------------------
  227.   # * Aqui define o index dos comandos que serão executados
  228.   # * Priorisa os comandos de cima para baixo.
  229.   #--------------------------------------------------------------------------
  230.   def index_stat_troops(conteudo)
  231.     i = 0
  232.     ary =[]
  233.     conteudo.each{|value|
  234.       if min_ingame == value[3].to_i && (value[0] == "min" || value[0] == "minute")
  235.         ary << i
  236.       elsif hour_ingame == value[3].to_i && (value[0] == "hour" || value[0] == "hora")
  237.         ary << i
  238.       elsif day_ingame == value[1].to_i && (value[0] == "day" || value[0] == "dia")
  239.         ary << i
  240.       elsif month_ingame == value[1].to_i && (value[0] == "month" || value[0] == "mes")
  241.         ary << i
  242.       elsif year_ingame == value[1].to_i && (value[0] == "year" || value[0] == "ano")
  243.         ary << i
  244.       elsif phase_ingame[1] == value[0]  
  245.         ary << i
  246.       end
  247.       i += 1
  248.     }
  249.     return ary.reverse!
  250.   end
  251.   #--------------------------------------------------------------------------
  252.   # * Aqui define como procede tropas nos encontros
  253.   # * Busca o valor <daynight_troops></daynight_troops>
  254.   # * Ira verificar se há alteração na taxa de encontros.
  255.   #--------------------------------------------------------------------------
  256.   def daynight_enconter_troop
  257.     map = $game_map.get_map
  258.     i = 0
  259.     rgxstart = BFK::DayNight::RGXMAP_TROOP_ST
  260.     rgxend = BFK::DayNight::RGXMAP_TROOP_ED
  261.     notas = BFK.search_rgx(map.note,rgxstart,rgxend)
  262.     unless notas.empty?
  263.       arys = notas.scan(BFK::DayNight::RGX_VALUES_TROOPS)
  264.       for troops in map.encounter_list
  265.         comand_alt = arys.collect{|condit| condit if condit[1].to_i == troops.troop_id}.compact
  266.         return if comand_alt.empty?
  267.         ix_chg_fq = index_stat_troops(comand_alt)
  268.         if ix_chg_fq.empty?
  269.           freq = bak_enconterlist($game_map.map_id,i).weight
  270.           $game_map.set_map_troop_freq(i,freq)
  271.         else
  272.           #mudar
  273.           ix_chg_fq.each{|troop|
  274.             freq = comand_alt[troop][2].to_i
  275.             frq = freq.between?( 0, 100)? freq : (freq > 100) ? 100 : 0
  276.             $game_map.set_map_troop_freq(i,frq)
  277.           }
  278.         end
  279.         i += 1
  280.       end
  281.     end    
  282.   end
  283.   #--------------------------------------------------------------------------
  284.   # * Aqui define como procede os passos nos encontros
  285.   # * Busca o valor <daynight_steps></daynight_steps>
  286.   # * Quanto menor o valor de passos mais encontros existirá.
  287.   #--------------------------------------------------------------------------
  288.   def daynight_enconter_rate
  289.     map = $game_map.get_map
  290.     rgxstart = BFK::DayNight::RGXMAP_STEP_ST
  291.     rgxend = BFK::DayNight::RGXMAP_STEP_ED
  292.     notas = BFK.search_rgx(map.note,rgxstart,rgxend)
  293.     unless notas.empty?
  294.       arys = notas.scan(BFK::DayNight::RGX_VALUES_STEPS)
  295.       steps_id = index_stat_steps(arys)
  296.       if steps_id
  297.         steps = (arys[steps_id][2])? arys[steps_id][2].to_i : arys[steps_id][1].to_i
  298.         $game_map.set_map_steps(steps)
  299.       else
  300.         $game_map.set_map_steps(bak_enconterstep($game_map.map_id))
  301.       end
  302.     end
  303.   end
  304.   #--------------------------------------------------------------------------
  305.   # Ajuda na veificação do status dos steps
  306.   #--------------------------------------------------------------------------
  307.   def index_stat_steps(conteudo)
  308.     return conteudo.index{|value|
  309.         if value[0] == "min" || value[0] == "minuto"
  310.           min_ingame == value[1].to_i
  311.         elsif value[0] == "hour" || value[0] == "hora"
  312.           hour_ingame == value[1].to_i
  313.         elsif (value[0] == "day" || value[0] == "dia") && value[2]
  314.           day_ingame == value[1].to_i
  315.         elsif value[0] == "month" || value[0] == "mes"
  316.           month_ingame == value[1].to_i
  317.         elsif value[0] == "year" || value[0] == "año"
  318.           year_ingame == value[1].to_i
  319.         elsif phase_ingame[1] == value[0]  
  320.           phase_ingame[1] == value[0]
  321.       end
  322.     }
  323.   end
  324.   #--------------------------------------------------------------------------
  325.   # * Atualiza quadro a quadro as opções de tempo
  326.   #--------------------------------------------------------------------------
  327.   def update
  328.     clear_daynight
  329.     set_sec
  330.     timer
  331.     refresh
  332.     daynight_enconter_troop
  333.     daynight_enconter_rate
  334.   end
  335.   #--------------------------------------------------------------------------
  336.   # * Inicia o timer
  337.   #--------------------------------------------------------------------------
  338.   def timer
  339.     @min_seg =  Graphics.frame_count % set_sec
  340.     if (@min_seg +1) == set_sec
  341.       @minutos += 1
  342.     end
  343.   end
  344.   #--------------------------------------------------------------------------
  345.   # * Atualizer de imediato as opções de tempo
  346.   #--------------------------------------------------------------------------
  347.   def refresh
  348.     update_phases
  349.     varable_refresh
  350.   end
  351.   #--------------------------------------------------------------------------
  352.   # * transforma o tempo em min
  353.   #--------------------------------------------------------------------------
  354.   def change_minutes(ary)
  355.     ciclos = BFK::DayNight::CICLOS
  356.     min = 0
  357.     min = ary[0]
  358.     min +=  (ary[1] * ciclos[0])
  359.     min +=  (((ary[2] - 1) * ciclos[1])*ciclos[0])
  360.     min +=  ((((ary[3].to_i - 1) * ciclos[2])*ciclos[1])*ciclos[0])
  361.     min +=  ((((ary[4] * ciclos[3])* ciclos[2])*ciclos[1])*ciclos[0])
  362.     return min
  363.   end
  364.   #--------------------------------------------------------------------------
  365.   # * limpa a tela caso o mapa tenha o dia e noite desligado
  366.   #--------------------------------------------------------------------------
  367.   def clear_daynight
  368.     @daynight_off = $game_map.daynight_off?
  369.     return if @daynight_off == false
  370.     set_trans(false)
  371.     $game_map.screen.start_tone_change(Tone.new(0, 0, 0), 0)
  372.   end
  373.   #--------------------------------------------------------------------------
  374.   # * Atualiza os periodos do dis (phases)
  375.   #--------------------------------------------------------------------------
  376.   def update_phases
  377.     max_hora = BFK::DayNight::PHASE_CICLO
  378.     p_phase = 0
  379.     BFK::DayNight::PHASE.each { |index|
  380.       hora = index[2]
  381.       if hora[0] > hora[1] # se for transição de 24h para 0h
  382.         if hour_ingame.between?( 0, hora[1] ) || hour_ingame.between?( hora[0] ,max_hora )
  383.           @phase_ingame = [p_phase,index[0]]
  384.           transitor_phase(index,p_phase) if @daynight_off == false
  385.         end
  386.       else
  387.         # se NÃO for transição de 24h para 0h
  388.         if hour_ingame.between?( hora[0], hora[1] )
  389.           @phase_ingame = [p_phase,index[0]]
  390.           transitor_phase(index,p_phase) if @daynight_off == false
  391.         end
  392.       end
  393.       p_phase += 1
  394.     } #do
  395.     $game_variables[BFK::DayNight::VARIABLE[0]] = @phase_ingame[0] if BFK::DayNight::VARIABLE
  396.     switch_refresh(@phase_ingame[0],BFK::DayNight::SWITCH)
  397.   end
  398.   #--------------------------------------------------------------------------
  399.   # * Atualiza a tela para as transições de tela dos periodos (phases)
  400.   #--------------------------------------------------------------------------
  401.   def transitor_phase(index,p_phase)
  402.     hora = index[2]
  403.     phase = BFK::DayNight::PHASE
  404.     duration = 0
  405.     duration =  (Graphics.frame_rate * BFK::DayNight::SEC_MIN)/3
  406.     rew = ((p_phase -1) < 0) ? (phase.count)-1 : (p_phase -1)
  407.     if hour_ingame == hora[0] && @trans == nil
  408.       #transição no começo da hora
  409.       $game_map.screen.start_tone_change(phase[rew][1], 0)
  410.       @trans = true
  411.       $game_map.screen.start_tone_change(index[1], duration)
  412.     elsif @trans == true
  413.       @trans = false if @tone_duration == 0
  414.     else
  415.       #fora da hora de transição
  416.       @trans = nil if @trans == false && hour_ingame != hora[0]
  417.       $game_map.screen.start_tone_change(index[1], 0)
  418.     end
  419.   end
  420.   #--------------------------------------------------------------------------
  421.   # * retorna os minutos em suas variaveis
  422.   #--------------------------------------------------------------------------
  423.   def min_ingame(min=nil)
  424.     unless min
  425.       return @minutos % BFK::DayNight::CICLOS[0]
  426.     else
  427.       return min % BFK::DayNight::CICLOS[0]
  428.     end
  429.   end
  430.   #--------------------------------------------------------------------------
  431.   # * retorna as horas em suas variaveis
  432.   #--------------------------------------------------------------------------
  433.   def hour_ingame(min=nil)
  434.     ciclos = BFK::DayNight::CICLOS
  435.     unless min
  436.       return  hour = (@minutos / ciclos[0]) % ciclos[1]
  437.     else
  438.       return  hour = (min / ciclos[0]) % ciclos[1]
  439.     end
  440.   end
  441.   #--------------------------------------------------------------------------
  442.   # * retorna os dias em suas variaveis
  443.   #--------------------------------------------------------------------------
  444.   def day_ingame(min=nil)
  445.     ciclos = BFK::DayNight::CICLOS
  446.     unless min
  447.       return day = (((@minutos / ciclos[0]) / ciclos[1])% ciclos[2]) +1
  448.     else
  449.       return day = (((min / ciclos[0]) / ciclos[1])% ciclos[2]) +1
  450.     end
  451.   end
  452.   #--------------------------------------------------------------------------
  453.   # * retorna os meses em suas variaveis
  454.   #--------------------------------------------------------------------------
  455.   def month_ingame(min=nil)
  456.     ciclos = BFK::DayNight::CICLOS
  457.     unless min
  458.       return month = ((((@minutos / ciclos[0]) / ciclos[1]) / ciclos[2]) % ciclos[3])+1
  459.     else
  460.       return month = ((((min / ciclos[0]) / ciclos[1]) / ciclos[2]) % ciclos[3])+1
  461.     end
  462.   end
  463.   #--------------------------------------------------------------------------
  464.   # * retorna os anos em suas variaveis
  465.   #--------------------------------------------------------------------------
  466.   def year_ingame(min=nil)
  467.     ciclos = BFK::DayNight::CICLOS
  468.     unless min
  469.       return year = ((((@minutos / ciclos[0]) / ciclos[1]) / ciclos[2]) / ciclos[3])
  470.     else
  471.       return year = ((((min / ciclos[0]) / ciclos[1]) / ciclos[2]) / ciclos[3])
  472.     end
  473.   end
  474.   #--------------------------------------------------------------------------
  475.   # * Atualiza as variaveis dos periodos
  476.   #--------------------------------------------------------------------------
  477.   def varable_refresh
  478.     if BFK::DayNight::VARIABLE
  479.       $game_variables[BFK::DayNight::VARIABLE[1]] = min_ingame
  480.       $game_variables[BFK::DayNight::VARIABLE[2]] = hour_ingame
  481.       $game_variables[BFK::DayNight::VARIABLE[3]] = day_ingame
  482.       $game_variables[BFK::DayNight::VARIABLE[4]] = month_ingame
  483.       $game_variables[BFK::DayNight::VARIABLE[5]] = year_ingame
  484.     end
  485.   end
  486.   #--------------------------------------------------------------------------
  487.   # * Atualiza as Switchs dos periodos do dias (phases)
  488.   #--------------------------------------------------------------------------
  489.   def switch_refresh(value,id_switch)
  490.     for id in id_switch
  491.       $game_switches[id.to_i] = (id_switch.index(id) == value.to_i) ? true : false
  492.     end
  493.   end
  494.   #--------------------------------------------------------------------------
  495.   # * define se a transição esta ocorrendo
  496.   #--------------------------------------------------------------------------
  497.   def set_trans(transition=nil)
  498.      @trans = transition
  499.   end
  500.   #--------------------------------------------------------------------------
  501.   # * Altera o tempo usar um array [tempo,valor,fixo] fixo é sempre true
  502.   #--------------------------------------------------------------------------
  503.   def altTime(*arg)
  504.     ciclos = BFK::DayNight::CICLOS
  505.     allmin= 0
  506.     arg.each{|value|
  507.       allmin = @minutos unless value[2]
  508.       case value[0]
  509.         when "min" , "minute" , "minuto"
  510.           allmin += value[1]
  511.         when "h" , "hour" , "hora"
  512.           allmin += (value[1] * ciclos[0])
  513.         when "d" , "day" , "dia"
  514.           allmin += (((value[1] -1) * ciclos[1])*ciclos[0])
  515.         when "m" , "mouth" , "mes"
  516.           allmin += ((((value[1] -1) * ciclos[2])*ciclos[1])*ciclos[0])
  517.         when "y" , "year" , "ano"
  518.           allmin += ((((value[1] * ciclos[3])* ciclos[2])*ciclos[1])*ciclos[0])
  519.       end
  520.     }
  521.     @minutos = allmin
  522.     set_trans(false)
  523.   end
  524.   #--------------------------------------------------------------------------
  525.   # * retorna uma String com a Hora do jogo
  526.   #--------------------------------------------------------------------------
  527.   def timeIngame
  528.     sprintf("%02d:%02d",hour_ingame,min_ingame )
  529.   end
  530.   #--------------------------------------------------------------------------
  531.   # * Retorna uma string com a data do jogo
  532.   #--------------------------------------------------------------------------
  533.   def dateIngame
  534.     mes = how_many_month_name?(true)
  535.     sprintf("%02d/%s/%s",day_ingame,mes,year_ingame )
  536.   end
  537.   #--------------------------------------------------------------------------
  538.   # * Retorna o nome do periodo (dia, tarde, noite, etc.)
  539.   #--------------------------------------------------------------------------
  540.   def which_phase_name?
  541.     @phase_ingame[1].capitalize
  542.   end
  543.   #--------------------------------------------------------------------------
  544.   # * Retorna o id da variavel do periodo (bom para usar com variaveis)
  545.   #--------------------------------------------------------------------------
  546.   def which_phase_id?
  547.     @phase_ingame[0].to_i
  548.   end
  549.   #--------------------------------------------------------------------------
  550.   # * Retorna o minuto atual (bom para usar com variaveis)
  551.   #--------------------------------------------------------------------------
  552.   def how_many_min?
  553.     sprintf("%02d",min_ingame )
  554.   end
  555.   #--------------------------------------------------------------------------
  556.   # * Retorna a hora atual (bom para usar com variaveis)
  557.   #--------------------------------------------------------------------------
  558.   def how_many_hour?
  559.     sprintf("%02d",hour_ingame )
  560.   end
  561.   #--------------------------------------------------------------------------
  562.   # * Retorna o dis atual (bom para usar com variaveis)
  563.   #--------------------------------------------------------------------------
  564.   def how_many_day?
  565.     sprintf("%02d",day_ingame )
  566.   end
  567.   #--------------------------------------------------------------------------
  568.   # * Retorna o mês atual (bom para usar com variaveis)
  569.   #--------------------------------------------------------------------------
  570.   def how_many_month?
  571.     sprintf("%02d",month_ingame )
  572.   end
  573.   #--------------------------------------------------------------------------
  574.   # * Retorna o mês atual (bom para usar com variaveis)
  575.   #--------------------------------------------------------------------------
  576.   def how_many_month_name?(abr=false)
  577.     if abr == false
  578.       BFK::DayNight::MONTH_NAMES[month_ingame.to_i][0]
  579.     else
  580.       BFK::DayNight::MONTH_NAMES[month_ingame.to_i][1]
  581.     end
  582.   end
  583.   #--------------------------------------------------------------------------
  584.   # * Retorna o ano atual (bom para usar com variaveis)
  585.   #--------------------------------------------------------------------------
  586.   def how_many_year?
  587.     sprintf("%04d",year_ingame )
  588.   end
  589. end
  590. #==============================================================================
  591. # ** Display_Phase
  592. #------------------------------------------------------------------------------
  593. #  Esta é a classe que controla o grsfico de periodo no relogio.
  594. #==============================================================================
  595. class Display_Phase < Sprite_Base
  596.   #--------------------------------------------------------------------------
  597.   # * Inicializa o sprite
  598.   #--------------------------------------------------------------------------
  599.   def initialize(x,y)
  600.     super(nil)
  601.     self.x = x+4
  602.     self.y = y +4
  603.     self.z += 2
  604.     self.bitmap = Cache.system("weather_mini")
  605.     refresh
  606.   end
  607.   #--------------------------------------------------------------------------
  608.   # * Atualiza o sprite no mapa
  609.   #--------------------------------------------------------------------------
  610.   def update_phase
  611.     @phase = $game_daynight.which_phase_id?
  612.     @index_phase_picy = @phase
  613.     @index_phase_picx = 0
  614.   end
  615.   #--------------------------------------------------------------------------
  616.   # * Inicializa o sprite
  617.   #--------------------------------------------------------------------------
  618.   def update_phase_pic
  619.     self.src_rect.set(64*@index_phase_picx, 64*@index_phase_picy, 64, 64)
  620.     self.zoom_x = 0.5
  621.     self.zoom_y = 0.5
  622.   end
  623.   #--------------------------------------------------------------------------
  624.   # * Metodo utilizado pela Scane para atualizar a imagem
  625.   #--------------------------------------------------------------------------
  626.   def refresh
  627.     self.bitmap = Cache.system("weather_mini") unless self.bitmap
  628.     update_phase
  629.     update_phase_pic
  630.   end
  631.  
  632.   def dispose
  633.     self.bitmap = nil
  634.     #super
  635.   end
  636.  
  637. end
  638. #==============================================================================
  639. # ** Window_Base
  640. #------------------------------------------------------------------------------
  641. #  Esta é a superclasse para todas as janelas no jogo.
  642. #==============================================================================
  643. class Window_Base < Window
  644.   alias daynight_convert_escape_characters convert_escape_characters
  645.   def convert_escape_characters(text)
  646.     result = daynight_convert_escape_characters(text)
  647.     result.gsub!(/\eDate/i)          { $game_daynight.dateIngame }
  648.     result.gsub!(/\eTime/i)          { $game_daynight.timeIngame }
  649.     result.gsub!(/\ePhase/i)          { $game_daynight.which_phase_name? }
  650.     result.gsub!(/\eMinute/i)          { $game_daynight.how_many_min? }
  651.     result.gsub!(/\eHour/i)          { $game_daynight.how_many_hour? }
  652.     result.gsub!(/\eDay/i)          { $game_daynight.how_many_day? }
  653.     result.gsub!(/\eMonth/i)          { $game_daynight.how_many_month? }
  654.     result.gsub!(/\eYear/i)          { $game_daynight.how_many_year? }
  655.     result
  656.   end
  657. end
  658. #==============================================================================
  659. # ** Window_Display_Time
  660. #------------------------------------------------------------------------------
  661. #  Janela do relogio do mapa
  662. #==============================================================================
  663. class Window_Display_HUD < Window_Base
  664.   #--------------------------------------------------------------------------
  665.   # * Inicialização do objeto
  666.   #--------------------------------------------------------------------------
  667.   def initialize
  668.     super(0, 0, window_width, fitting_height(1))
  669.     self.opacity = 0
  670.     refresh
  671.   end  
  672.   #--------------------------------------------------------------------------
  673.   # * define o tamanho da janela
  674.   #--------------------------------------------------------------------------  
  675.   def window_width
  676.     return 128
  677.   end
  678.   #--------------------------------------------------------------------------
  679.   # * Metodo utilizado pela Scane para atualizar a imagem
  680.   #--------------------------------------------------------------------------
  681.   def refresh
  682.     self.show
  683.     contents.clear
  684.     draw_background(contents.rect)
  685.     draw_text(contents.rect, hora, 1)
  686.   end
  687.   #--------------------------------------------------------------------------
  688.   # * Metodo para construir o Background do relogio
  689.   #--------------------------------------------------------------------------
  690.   def draw_background(rect)
  691.     temp_rect = rect.clone
  692.     temp_rect.width /= 2
  693.     contents.gradient_fill_rect(temp_rect, back_color2, back_color1)
  694.     temp_rect.x = temp_rect.width
  695.     contents.gradient_fill_rect(temp_rect, back_color1, back_color2)
  696.   end
  697.   #--------------------------------------------------------------------------
  698.   # * Metodo para definir a posição do  relogio
  699.   #--------------------------------------------------------------------------
  700.   def pos_window_time
  701.     x = 0
  702.     y = 0
  703.     case BFK::DayNight::DISPLAY_HUD_POS
  704.     when 1
  705.       x = Graphics.width - self.width
  706.     when 2
  707.       x = Graphics.width - self.width
  708.       y = Graphics.height - self.height
  709.     when 3
  710.       y = Graphics.height - self.height
  711.     end
  712.     self.x = x
  713.     self.y = y
  714.   end
  715.   #--------------------------------------------------------------------------
  716.   # * Aquisição do valor das horas
  717.   #--------------------------------------------------------------------------
  718.   def hora
  719.     $game_daynight.timeIngame
  720.   end
  721.   #--------------------------------------------------------------------------
  722.   # * Aquisição da cor do plano de fundo 1
  723.   #--------------------------------------------------------------------------
  724.   def back_color1
  725.     Color.new(0, 0, 0, 192)
  726.   end
  727.   #--------------------------------------------------------------------------
  728.   # * Aquisição da cor do plano de fundo 2
  729.   #--------------------------------------------------------------------------
  730.   def back_color2
  731.     Color.new(0, 0, 0, 0)
  732.   end
  733.   #--------------------------------------------------------------------------
  734.   # * Abertura da janela
  735.   #--------------------------------------------------------------------------
  736.   def open
  737.     refresh
  738.     super
  739.   end
  740.  
  741. end
  742. #==============================================================================
  743. # ** Window_DayNight_Time
  744. #------------------------------------------------------------------------------
  745. #  Esta é a classe para a janela de tempo do jogo.
  746. #==============================================================================
  747.  
  748. class Window_DayNight_Time < Window_Base
  749.   #--------------------------------------------------------------------------
  750.   # * Inicialização do objeto
  751.   #--------------------------------------------------------------------------
  752.   def initialize
  753.     @n = 0
  754.     @n += 1 if BFK::DayNight::MENU_DATE
  755.     @n += 1 if BFK::DayNight::MENU_TIME
  756.     super(0, 0, window_width, fitting_height(@n))
  757.     refresh
  758.   end
  759.   #--------------------------------------------------------------------------
  760.   # * Aquisição da largura da janela
  761.   #--------------------------------------------------------------------------
  762.   def window_width
  763.     return 160
  764.   end
  765.   #--------------------------------------------------------------------------
  766.   # * Desenho do tempo
  767.   #     hora   : hora
  768.   #     phase  : Periodo (phase)
  769.   #     x      : coordenada X
  770.   #     y      : coordenada Y
  771.   #     width  : largura
  772.   #--------------------------------------------------------------------------
  773.   def draw_daynight_time(hora, phase, x, y, width)
  774.     cx = text_size(hora).width
  775.     change_color(system_color)
  776.     draw_text(x, y, width -cx -2, line_height, phase, 1)
  777.     change_color(normal_color)
  778.     draw_text(x, y, width , line_height, hora,2)
  779.   end
  780.   #--------------------------------------------------------------------------
  781.   # * Desenho do tempo
  782.   #     hora   : hora
  783.   #     phase  : Periodo (phase)
  784.   #     x      : coordenada X
  785.   #     y      : coordenada Y
  786.   #     width  : largura
  787.   #--------------------------------------------------------------------------
  788.   def draw_daynight_date(date, x, y, width)
  789.     change_color(normal_color)
  790.     draw_text(x, y, width - 5, line_height, date,1)
  791.   end
  792.   #--------------------------------------------------------------------------
  793.   # * Renovação
  794.   #--------------------------------------------------------------------------
  795.   def refresh
  796.     contents.clear
  797.     ny = (@n >1) ?  line_height : 0
  798.     $game_daynight.update_phases
  799.     draw_daynight_time(hora,dayNight_Phase,0, 0, contents.width - 8) if BFK::DayNight::MENU_TIME
  800.     draw_daynight_date(date,4,ny, contents.width - 8) if BFK::DayNight::MENU_DATE
  801.   end
  802.   #--------------------------------------------------------------------------
  803.   # * Aquisição do valor das horas
  804.   #--------------------------------------------------------------------------
  805.   def hora
  806.     $game_daynight.timeIngame
  807.   end
  808.   #--------------------------------------------------------------------------
  809.   # * Aquisição do nome da Phase
  810.   #--------------------------------------------------------------------------
  811.   def dayNight_Phase
  812.     $game_daynight.which_phase_name?
  813.   end  
  814.   #--------------------------------------------------------------------------
  815.   # * Aquisição do valor da data
  816.   #--------------------------------------------------------------------------
  817.   def date
  818.     $game_daynight.dateIngame
  819.   end
  820.   #--------------------------------------------------------------------------
  821.   # * Abertura da janela
  822.   #--------------------------------------------------------------------------
  823.   def open
  824.     refresh
  825.     super
  826.   end
  827. end
  828. #==============================================================================
  829. # ** Window_NumberInput
  830. #------------------------------------------------------------------------------
  831. #  Esta janela é utilizada para o comando de eventos [Armazenar Número]
  832. #==============================================================================
  833. class Window_TimeInput < Window_Selectable
  834.   def initialize
  835.     super(0, 0, 0, 0)
  836.     @digits_max = BFK::DayNight::MAX_DIGIT #( 4 para alterar apenas hora - 12 para alteração completa )
  837.     @index = 0
  838.     @number = 0
  839.     @handler = {}
  840.     @matriz = define_matriz
  841.     self.z +=1
  842.   end
  843.   #--------------------------------------------------------------------------
  844.   # * Define um array com os digitos divididos que será
  845.   #--------------------------------------------------------------------------
  846.   def define_matriz
  847.     min = sprintf("%02d",$game_daynight.min_ingame)
  848.     hour = sprintf("%02d",$game_daynight.hour_ingame)
  849.     day = sprintf("%02d",$game_daynight.day_ingame)
  850.     month = sprintf("%02d",$game_daynight.month_ingame)
  851.     year = sprintf("%04d",$game_daynight.year_ingame)
  852.     return a =[
  853.     hour[0].to_i,hour[1].to_i,
  854.     min[0].to_i,min[1].to_i,
  855.     day[0].to_i,day[1].to_i,
  856.     month[0].to_i,month[1].to_i,
  857.     year[0].to_i,year[1].to_i,year[2].to_i,year[3].to_i
  858.     ]
  859.   end
  860.   #--------------------------------------------------------------------------
  861.   # * Define inicia a janela e seu conteudo
  862.   #--------------------------------------------------------------------------
  863.   def start
  864.     update_placement
  865.     create_contents
  866.     open
  867.     refresh
  868.     draw_labels
  869.     @index = 0
  870.   end
  871.   #--------------------------------------------------------------------------
  872.   # * Atualiza a caixa
  873.   #--------------------------------------------------------------------------
  874.   alias daynight_update update
  875.   def update
  876.     if open? && active
  877.       daynight_process_cursor_move
  878.       process_digit_change
  879.       update_cursor
  880.       refresh
  881.     end
  882.     daynight_update
  883.   end
  884.   #--------------------------------------------------------------------------
  885.   # * Renovação
  886.   #--------------------------------------------------------------------------
  887.   def refresh
  888.     contents.clear
  889.     draw_labels
  890.     change_color(normal_color)
  891.     @digits_max.times do |i|
  892.       rect = item_rect(i)
  893.       rect.x += 1
  894.       contents.font.size = 32
  895.       draw_text(rect, @matriz[i],1)
  896.       non_item_rect(i)
  897.     end
  898.   end
  899.    #--------------------------------------------------------------------------
  900.   # * Movimento do cursor para direita
  901.   #     wrap : cursor retornar a primeira ou ultima posição
  902.   #--------------------------------------------------------------------------
  903.   def daynight_cursor_right(wrap)
  904.     if @index < @digits_max - 1 || wrap
  905.       @index = (@index + 1) % @digits_max
  906.     end
  907.   end
  908.   #--------------------------------------------------------------------------
  909.   # * Movimento do cursor para esquerda
  910.   #     wrap : cursor retornar a primeira ou ultima posição
  911.   #--------------------------------------------------------------------------
  912.   def daynight_cursor_left(wrap)
  913.     if @index > 0 || wrap
  914.       @index = (@index + @digits_max - 1) % @digits_max
  915.     end
  916.   end
  917.   #--------------------------------------------------------------------------
  918.   # * Atualização do cursor
  919.   #--------------------------------------------------------------------------
  920.   alias dynight_update_cursor update_cursor
  921.   def update_cursor
  922.     cursor_rect.set(item_rect(@index))
  923.   end
  924.   #--------------------------------------------------------------------------
  925.   # * Execução do movimento do cursor
  926.   #--------------------------------------------------------------------------
  927.   def daynight_process_cursor_move
  928.     return unless active
  929.     last_index = @index
  930.     daynight_cursor_right(Input.trigger?(:RIGHT)) if Input.repeat?(:RIGHT)
  931.     daynight_cursor_left (Input.trigger?(:LEFT))  if Input.repeat?(:LEFT)
  932.     Sound.play_cursor if @index != last_index
  933.   end
  934.   #--------------------------------------------------------------------------
  935.   # * Aquisição do retangulo para desenhar o item
  936.   #     index : índice do item
  937.   #--------------------------------------------------------------------------
  938.   def item_rect(index)
  939.     a = 0
  940.     space = BFK::DayNight::MENU_SPACE
  941.     space2 = BFK::DayNight::MENU_RECT * 2
  942.     a = 1 if index > 1
  943.     a = 2 if index > 3
  944.     a = 3 if index > 5
  945.     a = 4 if index > 7
  946.     Rect.new(((index + a) * 20)+ space,space2, 20, line_height * 1.5)
  947.   end
  948.   #--------------------------------------------------------------------------
  949.   # * Definição das caixas de numeros para edição
  950.   #--------------------------------------------------------------------------
  951.   def non_item_rect(index)
  952.     space = BFK::DayNight::MENU_SPACE
  953.     space2 = BFK::DayNight::MENU_RECT * 2
  954.     draw_text((index  * 20)+ space, space2, 20, line_height * 1.5, ":",1) if index == 2
  955.     draw_text((index  * 20)+ space, space2, 20, line_height * 1.5, "-",1) if index == 5
  956.     draw_text((index  * 20)+ space, space2, 20, line_height * 1.5, "/",1) if index == 8
  957.     draw_text((index  * 20)+ space, space2, 20, line_height * 1.5, "/",1) if index == 11
  958.   end
  959.   #--------------------------------------------------------------------------
  960.   # * Execução da mudança de digito
  961.   #--------------------------------------------------------------------------
  962.   def process_digit_change()
  963.     return unless active
  964.     ciclo = [
  965.             BFK::DayNight::CICLOS[1].to_s,BFK::DayNight::CICLOS[1].to_s,
  966.             BFK::DayNight::CICLOS[0].to_s,BFK::DayNight::CICLOS[0].to_s,
  967.             BFK::DayNight::CICLOS[2].to_s,BFK::DayNight::CICLOS[2].to_s,
  968.             BFK::DayNight::CICLOS[3].to_s,BFK::DayNight::CICLOS[3].to_s
  969.             ]
  970.     if Input.repeat?(:UP) || Input.repeat?(:DOWN)
  971.       Sound.play_cursor
  972.       case @index
  973.         when 0,6
  974.           r = ciclo[@index][0].to_i + 1; u = 1; d = ciclo[@index][0].to_i
  975.         when 1,5
  976.           r = (@matriz[@index -1]< ciclo[@index][0].to_i) ? 10 :
  977.           (ciclo[@index][1].to_i < 1)? 1 : ciclo[@index][1].to_i; u = 1
  978.           d = (@matriz[@index -1]< ciclo[@index][0].to_i) ? 9 :
  979.           ciclo[@index][1].to_i - 1
  980.         when 2
  981.           r = (ciclo[@index][0].to_i < 1)? 1 : ciclo[@index][0].to_i; u = 1
  982.           d = ciclo[@index][1].to_i - 1
  983.         when 4
  984.           r = ciclo[@index][0].to_i + 1; u = 1;
  985.           d = (ciclo[@index][0].to_i > 0)? ciclo[@index][0].to_i - 1 : 9
  986.         when 7
  987.           r = (@matriz[@index -1]< ciclo[@index][0].to_i) ? 10 :
  988.           (ciclo[@index][1].to_i < 1)? 1 : ciclo[@index][1].to_i + 1; u = 1
  989.           d = (@matriz[@index -1]< ciclo[@index][0].to_i) ? 9 :
  990.           ciclo[@index][1].to_i - 1
  991.         else
  992.           r = 10; u = 1; d = 9
  993.       end
  994.       @matriz[@index] = (@matriz[@index] + u) % r  if Input.repeat?(:UP)
  995.       @matriz[@index] = (@matriz[@index] + d) % r if Input.repeat?(:DOWN)
  996.       #if numero quebrado resetar no maximo
  997.       @matriz[1] = 0 if @matriz[0] >= ciclo[0][0].to_i && @matriz[1] >= ciclo[0][1].to_i
  998.       @matriz[5] = 0 if @matriz[4] >= ciclo[4][0].to_i && @matriz[5] >= ciclo[4][1].to_i
  999.       @matriz[5] = 1 if @matriz[4] == 0 && @matriz[5]==0
  1000.       @matriz[7] = 0 if @matriz[6] >= ciclo[6][0].to_i && @matriz[7] > ciclo[6][1].to_i
  1001.     end
  1002.   end
  1003.   #--------------------------------------------------------------------------
  1004.   # * Define os Labeis do tempo
  1005.   #--------------------------------------------------------------------------
  1006.   def draw_labels
  1007.     names = BFK::DayNight::CICLOS_NAMES
  1008.     contents.font.size = 20
  1009.     change_color(system_color)
  1010.     space = BFK::DayNight::MENU_SPACE
  1011.     names.each_index do |i|
  1012.       return if @digits_max/2 == i
  1013.       w = text_size(names[i][0])
  1014.       draw_text( (i * 63)+space,0,w.width + space,line_height, names[i][1].capitalize)
  1015.     end
  1016.   end
  1017.   #--------------------------------------------------------------------------
  1018.   # * Atualização da posição da janela
  1019.   #--------------------------------------------------------------------------
  1020.   def update_placement
  1021.     self.width = @digits_max * 20 + padding * 2 +  BFK::DayNight::MENU_SPACE * 6
  1022.     self.height = fitting_height(3)
  1023.     self.x = (Graphics.width - width) / 2
  1024.     self.y = (Graphics.height - height) / 2
  1025.   end
  1026.   #--------------------------------------------------------------------------
  1027.   # * Atualização com ok da janela
  1028.   #--------------------------------------------------------------------------
  1029.   def daynight_ok_process
  1030.     Sound.play_ok
  1031.     a = [@matriz[2].to_s + @matriz[3].to_s, @matriz[0].to_s + @matriz[1].to_s, @matriz[4].to_s + @matriz[5].to_s,
  1032.     @matriz[6].to_s + @matriz[7].to_s, @matriz[8].to_s + @matriz[9].to_s + @matriz[10].to_s + @matriz[11].to_s]
  1033.     return a.collect!{|x| x.to_i}
  1034.     end
  1035. end
  1036. #==============================================================================
  1037. # ** Window_MenuCommand
  1038. #------------------------------------------------------------------------------
  1039. #  Esta janela exibe os comandos do menu.
  1040. #==============================================================================
  1041.  
  1042. class Window_MenuCommand < Window_Command
  1043.   #--------------------------------------------------------------------------
  1044.   # * Adição de comandos próprios
  1045.   #--------------------------------------------------------------------------
  1046.   alias dn_add_original_commands add_original_commands
  1047.   def add_original_commands
  1048.     dn_add_original_commands
  1049.     add_command(BFK::DayNight::MENU_NAME, :daynight, daynight_enabled)
  1050.   end
  1051.   #--------------------------------------------------------------------------
  1052.   # * Verifica se o mnu dia e noite pode ser exibido no menu
  1053.   #--------------------------------------------------------------------------
  1054.   def daynight_enabled
  1055.     BFK::DayNight::MENU_ACTIVE
  1056.   end
  1057. end
  1058. #==============================================================================
  1059. # ** Game_Map
  1060. #------------------------------------------------------------------------------
  1061. #  Esta classe altera o comportamento da classe original sem modifica-la
  1062. #==============================================================================
  1063. class Game_Map
  1064.   attr_reader :original_list
  1065.   attr_reader :original_step
  1066.   attr_reader :daynight_off
  1067.   #--------------------------------------------------------------------------
  1068.   # * FUNÇÃO QUE AUXILIA NA BUSCA DE TAGS (ESTA FUNÇÃO SERÁ MODIFICADA PELAS ATUALIZAÇÕES
  1069.   #--------------------------------------------------------------------------
  1070.   def find_map_note(rgx)
  1071.     l_note = @map.note.scan(rgx)
  1072.     l_note.each{ |off|
  1073.       return true if off
  1074.     }
  1075.       return false
  1076.     end
  1077.   #--------------------------------------------------------------------------
  1078.   # * Aqui verifica se o mapa aceita as transições
  1079.   #--------------------------------------------------------------------------
  1080.   def daynight_off?
  1081.     @daynight_off = BFK.find_map_note(BFK::DayNight::RGXMAP)
  1082.   end  
  1083.   #--------------------------------------------------------------------------
  1084.   # * Aqui faz as configurações original do mapa
  1085.   #--------------------------------------------------------------------------  
  1086.   alias daynight_setup setup
  1087.   def setup(map_id)
  1088.     daynight_setup(map_id)
  1089.     daynight_off?
  1090.     @original_step = @map.encounter_step
  1091.   end
  1092. end
  1093. #==============================================================================
  1094. # ** Scene_Menu
  1095. #------------------------------------------------------------------------------
  1096. #  Esta classe executa o processamento da tela de menu.
  1097. #==============================================================================
  1098.  
  1099. class Scene_Menu < Scene_MenuBase
  1100.   alias daynight_start start
  1101.   def start
  1102.     daynight_start
  1103.     create_window_daynight
  1104.     create_status_daynight_time if BFK::DayNight::MENU_TIME || BFK::DayNight::MENU_DATE
  1105.   end
  1106.   #--------------------------------------------------------------------------
  1107.   # * Criação da janela de atributos
  1108.   #--------------------------------------------------------------------------
  1109.   def create_window_daynight
  1110.     @window_daynight = Window_TimeInput.new
  1111.   end
  1112.   #--------------------------------------------------------------------------
  1113.   # * Cria a janela de tempo
  1114.   #--------------------------------------------------------------------------
  1115.   def create_status_daynight_time
  1116.     @daynight_window_time = Window_DayNight_Time.new
  1117.     @daynight_window_time.x = 0
  1118.     @daynight_window_time.y = @command_window.height
  1119.   end
  1120.   #--------------------------------------------------------------------------
  1121.   # * Criação da janela de comando
  1122.   #--------------------------------------------------------------------------
  1123.   alias daynight_create_command_window create_command_window
  1124.   def create_command_window
  1125.     daynight_create_command_window
  1126.     @command_window.set_handler(:daynight,  method(:command_daynight))
  1127.   end
  1128.   #--------------------------------------------------------------------------
  1129.   # * Comando [Tempo]
  1130.   #--------------------------------------------------------------------------
  1131.   def command_daynight
  1132.     @window_daynight.activate
  1133.     @window_daynight.start
  1134.     @window_daynight.set_handler(:ok,     method(:on_daynight_ok))
  1135.     @window_daynight.set_handler(:cancel, method(:on_daynight_cancel))
  1136.   end
  1137.   #--------------------------------------------------------------------------
  1138.   # * Comandos individuais [Confirmação]
  1139.   #--------------------------------------------------------------------------
  1140.   def on_daynight_ok
  1141.     Sound.play_ok
  1142.     $game_daynight.set_trans(false)
  1143.     $game_daynight.minutos = $game_daynight.change_minutes( @window_daynight.daynight_ok_process)
  1144.     @daynight_window_time.refresh
  1145.     @window_daynight.unselect
  1146.     @window_daynight.close
  1147.     @command_window.activate
  1148.   end
  1149.   #--------------------------------------------------------------------------
  1150.   # * Comandos individuais [Cancelamento]
  1151.   #--------------------------------------------------------------------------
  1152.   def on_daynight_cancel
  1153.     Sound.play_cancel
  1154.     @window_daynight.unselect
  1155.     @window_daynight.deactivate
  1156.     @window_daynight.close
  1157.     @command_window.activate
  1158.   end
  1159. end
  1160. #==============================================================================
  1161. # ** Scene_Map
  1162. #------------------------------------------------------------------------------
  1163. #  Esta classe executa o processamento da tela de mapa.
  1164. #==============================================================================
  1165. class Scene_Map < Scene_Base
  1166.   #--------------------------------------------------------------------------
  1167.   # * Inicialização do processo
  1168.   #--------------------------------------------------------------------------
  1169.   def initialize
  1170.     if $game_daynight
  1171.       $game_daynight.trans = false
  1172.       $game_daynight.refresh
  1173.     end
  1174.   end
  1175.   #--------------------------------------------------------------------------
  1176.   # * inicializa as janelas do menu, hud e o contador de tempo
  1177.   #--------------------------------------------------------------------------
  1178.   alias start_daynight start
  1179.   def start
  1180.     $game_daynight = DayNight.new unless $game_daynight
  1181.     if $game_daynight.time_hud == true
  1182.       @window_display_hud =  Window_Display_HUD.new
  1183.       @window_display_hud.pos_window_time
  1184.       @window_phase_hud = Display_Phase.new(@window_display_hud.x, @window_display_hud.y)
  1185.       @window_phase_hud.viewport = @window_display_hud.viewport
  1186.     elsif $game_daynight.time_hud == false
  1187.       @window_display_hud.hide
  1188.       #@window_phase_hud.hide
  1189.     end
  1190.     start_daynight
  1191.   end
  1192.   #--------------------------------------------------------------------------
  1193.   # * Atualiza o script
  1194.   #--------------------------------------------------------------------------
  1195.   alias daynight_update update
  1196.   def update
  1197.     $game_daynight.update
  1198.     if $game_daynight.time_hud == true
  1199.       @window_display_hud.refresh
  1200.       @window_phase_hud.refresh
  1201.     elsif $game_daynight.time_hud == false
  1202.       @window_display_hud.hide
  1203.       @window_phase_hud.dispose
  1204.     end
  1205.     daynight_update
  1206.   end
  1207.   #--------------------------------------------------------------------------
  1208.   # * Atualiza o a transição antes do fadeout
  1209.   #--------------------------------------------------------------------------
  1210.   alias post_transfer_daynight post_transfer
  1211.   def post_transfer
  1212.     $game_daynight.clear_daynight
  1213.     $game_daynight.refresh
  1214.     post_transfer_daynight
  1215.   end
  1216.   #--------------------------------------------------------------------------
  1217.   # * termina a scene
  1218.   #--------------------------------------------------------------------------
  1219.   alias pre_terminate_daylight pre_terminate
  1220.   def pre_terminate
  1221.     pre_terminate_daylight
  1222.     @window_phase_hud.dispose if @window_phase_hud
  1223.   end
  1224.  
  1225.   #--------------------------------------------------------------------------
  1226.   # * termina a scene
  1227.   #--------------------------------------------------------------------------
  1228.   alias terminate_daylight terminate
  1229.   def terminate
  1230.     terminate_daylight
  1231.     @window_phase_hud.dispose if @window_phase_hud
  1232.   end
  1233. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement