Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #--------------------------------------------------------------------------
- # SISTEMA DIA E NOITE (BY RAVEN) - v3.6 -
- #--------------------------------------------------------------------------
- # * COMO USAR O SISTEMA DE DIA E NOITE
- # - BASTA QUE ESTE SCRIPT ESTEJA ACIMA DO MAIN
- # - PARA MUDAR A HORA INICIAL BASTA ALTERAR a variavel "START_TIME_INGAME"
- # - PARA MUDAR A VELOCIDADE DO TEMPO BASTA MUDAR A VARIAVEL "SEC_MIN" (< MAIS RAPIDO)
- # - PARA ALTERAR O TEMPO DE CADA CICLO BASTA ALTERAR A VARIAVEL "CICLOS"
- # - CONFORME ORIENTAÇÃO NOS COMENTARIOS
- #
- #********************************************************************
- # COMANDOS PUBLICOS PARA SEREM USADOS NO MAPA OU EVENTOS
- #********************************************************************
- # <daynight: off> - Se colocado no espaço de notas do mapa fará com que o
- # script não mude a tonalidade naquele mapa
- # <daynight_time: 500> - Se colocado no espaço de notas do mapa fará com que o
- # valor do tempo corrente acelerar ou diminuir (valor alto mais lento)
- #
- # <daynight_troop> ciclo = [tempo, id_troop, %] phase = [id_troop, %] </daynight_troop>
- # - Se colocado no espaço de notas do mapa fará com que a
- # Tropa com o id "id_troop", mude as chances de aparecer para
- # a porcentagem (0~100) em "frequencia", durante o periodo
- # especificado em "phase" (nota: so serão alterados
- # tropas que estiverem na lista de encontros do mapa
- #
- # <daynight_step> ciclo = [tempo,nºstep] phase = nº_step </daynight_step>
- # - Se colocado no espaço de notas do mapa fará com que as
- # chances de acontecer um encontro "steps" (menor mais chances)
- # durante um periodo especifico "phase"
- # caso o periodo não seja especificado, o valor de steps (passos)
- # será mantido conforme original
- #
- # $game_daynight.altTime(["min",10],["day",-3],["mes",-20],["ano",1970,true])
- # - pode alterar qualquer parte do tempo com qualquer valor
- # positivos ou negativos, se um 3º argumento for informado
- # (true) o valor será exato (não somara)
- # $game_daynight.timeIngame
- # - Imprime no debug a hora in game atual
- # $game_daynight.dateIngame
- # - Imprime no debug a data in game atual
- # $game_daynight.which_phase_name?
- # - Retorna o nome da fase do dia
- # $game_daynight.which_phase_id?
- # - Retorna o id da fase do dia (para popular variaveis)
- # $game_daynight.how_many_min?
- # - Retorna o minuto em jogo em formato 2 digitos
- # $game_daynight.min_ingame
- # - Retorna o minuto em jogo (para popular variaveis)
- # $game_daynight.how_many_hour?
- # - Retorna a hora em jogo em formato 2 digitos
- # $game_daynight.hour_ingame
- # - Retorna a hora em jogo (para popular variaveis)
- # $game_daynight.how_many_day?
- # - Retorna o dia em jogo eem formato 2 digitos
- # $game_daynight.day_ingame
- # - Retorna o dia em jogo (para popular variaveis)
- # $game_daynight.how_many_month?
- # - Retorna os meses em jogo em formato 2 digitos
- # $game_daynight.month_ingame
- # - Retorna os meses em jogo (para popular variaveis)
- # $game_daynight.how_many_month_name?(abr=false)
- # - Retorna os meses em formato de texto, se tiver argumento
- # retorna a abreviação
- # $game_daynight.how_many_year?
- # - Retorna os anos em jogo em formato 4 digitos
- # $game_daynight.year_ingame
- # - Retorna os anos em jogo (para popular variaveis)
- # $game_daynight.time_hud
- # - Ativa e desativa o relogio (true/false) para funcionar a
- # a variavel DISPLAY_HUD deve estar configurada em true.
- #--------------------------------------------------------------------------
- # COMANDOS PARA MENSAGENS
- #--------------------------------------------------------------------------
- # \Data - Exibe na janela a data atual (dd/M/yyyy)
- # \Time - Exibe na janela a hora atual (H:m)
- # \Phase - Exibe na janela o periodo atual atual
- # \Minute - Exibe na janela os minutos atuais
- # \Hour - Exibe na janela as horas atuais
- # \Day - Exibe na janela os dias atuais
- # \Month - Exibe na janela os meses atuais
- # \Year - Exibe na janela os anos atuais
- #--------------------------------------------------------------------------
- $registro = [] if $registro.nil?
- $registro << ["BFK DayNight",3.6]
- class << DataManager
- #--------------------------------------------------------------------------
- # * Salvar a criação de conteúdo
- #--------------------------------------------------------------------------
- alias daynight_make_save_contents make_save_contents
- def make_save_contents
- contents = daynight_make_save_contents
- contents[:daynight] = $game_daynight
- contents
- end
- #--------------------------------------------------------------------------
- # * Extrair conteúdo salvo
- # contents : matriz de quests
- #--------------------------------------------------------------------------
- alias daynight_extract_save_contents extract_save_contents
- def extract_save_contents(contents)
- daynight_extract_save_contents(contents)
- $game_daynight = contents[:daynight]
- end
- end
- #==============================================================================
- # ** MODULO BKF
- #------------------------------------------------------------------------------
- # Este é o modulo principal para scripts feitos por este core
- #==============================================================================
- module BFK
- self.modular("BFK Core",1.0)
- #--------------------------------------------------------------------------
- # * Aqui se encontra todas as variaveis para configuração e instalação
- #--------------------------------------------------------------------------
- module DayNight
- #--------------------------------------------------------------------------
- # * BFK_DayNight_Periodos = 1/Dia 2/tarde 3/Noite 4/Madrugada
- #--------------------------------------------------------------------------
- START_TIME_INGAME = [00,21,30,12,1979] # (min,hora,dia, mes, ano) para o inicio do jogo
- SEC_MIN = 60 # quantos milesimos segundos dura o minuto em jogo?
- CICLOS = [60,24,30,12] # (minutos/hora, Horas/dias, dias/meses, meses ano)
- MONTH_NAMES = [["Meses","abrev"],["Janeiro","Ene"],["Fevereiro","Feb"],
- ["Março","Mar"],["Abril","Abr"],["Maio","May"],["Junho","Jun"],
- ["Julho","Jul"],["Agosto","Ago"],["Setembro","Sep"],
- ["Outubro","Oct"], ["Novembro","Nov"], ["Dezembro","Dic"]]
- CICLOS_NAMES = [["horas","hora"],["minutos","min"],["dias","dia"],["meses","mes"], ["años","año"]]
- PHASE = [
- ["dia",Tone.new(0,0,0),[6,16]], # [ NOME_DO_CICLO, TONALIDADE, [HORA DE INICIO, HORA DO FIM]
- ["tarde",Tone.new(-32, -96, -66),[17,20]],
- ["noche",Tone.new(-170, -153, -136),[21,3]],
- ["madrugada",Tone.new(-66, -66, -66),[4,5]]
- ]
- PHASE_CICLO = CICLOS[1]
- PHASE_D = (Graphics.frame_rate * CICLOS[0])/SEC_MIN #quanto vai demorar para a tansição completar
- MENU_NAME = "Tiempo" #texto da Opção do Menu
- MENU_ACTIVE = true # Ativa a Opção de controlar o tempo no menu
- MENU_TIME = true # Ativa a janela de tempo no menu
- MENU_DATE = true # Ativa a Janela de data no menu
- MAX_DIGIT = 12 # (4 PARA SÓ AS HORAS, E 12 PARA DATA COMPLETA)
- DISPLAY_HUD = true # Exibe a Janela de hora no mapa
- DISPLAY_HUD_POS = 1 # Posição que ficará a janela de hoa no mapa,
- # 0 para canto superior esquerdo
- # 1 para canto superior direito
- # 2 para canto inferior direito
- # 3 para canto inferior esquerdo
- #--------------------------------------------------------------------------
- # * Comentando a linha a baixo, o programa não vai popular as variaveis
- # será possivel apanhalas domente atraves dos metodos how_many e which_
- #--------------------------------------------------------------------------
- VARIABLE = [84,85,86,87,88,89] # [VAR001 = phase, VAR002 = MIN, VAR003 = HORA,
- # VAR004 = DIA, VAR005 = MES, VAR006 = ANO]
- SWITCH = [81,82,83,84] # [S001 = Dia, S002=Tarde, s003=Noite, S004 = Madrugada
- #--------------------------------------------------------------------------
- # * ATENÇÃO NÃO ALTERAR AS VARIAVEIS ABAIXO (ELAS PODEM MUDAR DEPENDENDO DA ATUALIZAÇÃO
- #--------------------------------------------------------------------------
- RGXMAP = /<(?:daynight):[ ]*(?:off)>/i
- RGXMAP_SEC_MIN = /<(?:daynight_time):[ ]*(\d{1,})>/xi
- #--------------------------------------------------------------------------
- RGXMAP_STEP_ST = /<(?:DAYNIGHT_STEP|daynight step)>/i
- RGXMAP_STEP_ED = /<\/(?:DAYNIGHT_STEP|daynight step)>/i
- RGXMAP_TROOP_ST = /<(?:DAYNIGHT_TROOP|daynight troop)>/i
- RGXMAP_TROOP_ED = /<\/(?:DAYNIGHT_TROOP|daynight troop)>/i
- RGX_VALUES_STEPS = /(\w+)\s*[=]\s*\[?(\d{1,})[,]?(\d{1,})?\]?/xi
- RGX_VALUES_TROOPS = /(\w+)\s*[=]\s*\[(\d{1,})[,]?(\d{1,})?[,]?(\d{1,})?\]/xi
- MENU_SPACE = 18
- MENU_RECT = 10
- #--------------------------------------------------------------------------
- end
- end
- #==============================================================================
- # ** DayNight
- #------------------------------------------------------------------------------
- # Esta é a superclasse para todo o controle de tempo no jogo
- #==============================================================================
- class DayNight
- attr_accessor :minutos
- attr_accessor :phase_ingame
- attr_accessor :trans
- attr_accessor :time_hud
- #--------------------------------------------------------------------------
- # * Inicia o Objeto com as configurações iniciais
- #--------------------------------------------------------------------------
- def initialize
- return if $game_map == nil
- @minutos = change_minutes(BFK::DayNight::START_TIME_INGAME) unless @minutos
- @min_seg = 0
- @trans = nil
- map = $game_map.get_map
- @step_original = map.encounter_step
- @time_hud = BFK::DayNight::DISPLAY_HUD
- clear_daynight
- refresh
- # aqui é a saida do menu =) ele refaz o initialize
- end
- def time_hud=(value)
- @time_hud = (BFK::DayNight::DISPLAY_HUD)? value : BFK::DayNight::DISPLAY_HUD
- end
- def set_sec
- map = $game_map.get_map
- sec = map.note.scan(BFK::DayNight::RGXMAP_SEC_MIN)
- return BFK::DayNight::SEC_MIN if sec.empty?
- return sec[0][0].to_i
- end
- #--------------------------------------------------------------------------
- # * Verifica o estado de transição
- #--------------------------------------------------------------------------
- def trans
- @trans
- end
- #--------------------------------------------------------------------------
- # * Recupera o valor original da lista de encontro
- #--------------------------------------------------------------------------
- def bak_enconterlist(map_id,id)
- mapa = load_data(sprintf("Data/Map%03d.rvdata2",map_id))
- return mapa.encounter_list[id]
- end
- #--------------------------------------------------------------------------
- # * recupera o valor original dos passos
- #--------------------------------------------------------------------------
- def bak_enconterstep(map_id)
- mapa = load_data(sprintf("Data/Map%03d.rvdata2",map_id))
- return mapa.encounter_step
- end
- #--------------------------------------------------------------------------
- # * Aqui define o index dos comandos que serão executados
- # * Priorisa os comandos de cima para baixo.
- #--------------------------------------------------------------------------
- def index_stat_troops(conteudo)
- i = 0
- ary =[]
- conteudo.each{|value|
- if min_ingame == value[3].to_i && (value[0] == "min" || value[0] == "minute")
- ary << i
- elsif hour_ingame == value[3].to_i && (value[0] == "hour" || value[0] == "hora")
- ary << i
- elsif day_ingame == value[1].to_i && (value[0] == "day" || value[0] == "dia")
- ary << i
- elsif month_ingame == value[1].to_i && (value[0] == "month" || value[0] == "mes")
- ary << i
- elsif year_ingame == value[1].to_i && (value[0] == "year" || value[0] == "ano")
- ary << i
- elsif phase_ingame[1] == value[0]
- ary << i
- end
- i += 1
- }
- return ary.reverse!
- end
- #--------------------------------------------------------------------------
- # * Aqui define como procede tropas nos encontros
- # * Busca o valor <daynight_troops></daynight_troops>
- # * Ira verificar se há alteração na taxa de encontros.
- #--------------------------------------------------------------------------
- def daynight_enconter_troop
- map = $game_map.get_map
- i = 0
- rgxstart = BFK::DayNight::RGXMAP_TROOP_ST
- rgxend = BFK::DayNight::RGXMAP_TROOP_ED
- notas = BFK.search_rgx(map.note,rgxstart,rgxend)
- unless notas.empty?
- arys = notas.scan(BFK::DayNight::RGX_VALUES_TROOPS)
- for troops in map.encounter_list
- comand_alt = arys.collect{|condit| condit if condit[1].to_i == troops.troop_id}.compact
- return if comand_alt.empty?
- ix_chg_fq = index_stat_troops(comand_alt)
- if ix_chg_fq.empty?
- freq = bak_enconterlist($game_map.map_id,i).weight
- $game_map.set_map_troop_freq(i,freq)
- else
- #mudar
- ix_chg_fq.each{|troop|
- freq = comand_alt[troop][2].to_i
- frq = freq.between?( 0, 100)? freq : (freq > 100) ? 100 : 0
- $game_map.set_map_troop_freq(i,frq)
- }
- end
- i += 1
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Aqui define como procede os passos nos encontros
- # * Busca o valor <daynight_steps></daynight_steps>
- # * Quanto menor o valor de passos mais encontros existirá.
- #--------------------------------------------------------------------------
- def daynight_enconter_rate
- map = $game_map.get_map
- rgxstart = BFK::DayNight::RGXMAP_STEP_ST
- rgxend = BFK::DayNight::RGXMAP_STEP_ED
- notas = BFK.search_rgx(map.note,rgxstart,rgxend)
- unless notas.empty?
- arys = notas.scan(BFK::DayNight::RGX_VALUES_STEPS)
- steps_id = index_stat_steps(arys)
- if steps_id
- steps = (arys[steps_id][2])? arys[steps_id][2].to_i : arys[steps_id][1].to_i
- $game_map.set_map_steps(steps)
- else
- $game_map.set_map_steps(bak_enconterstep($game_map.map_id))
- end
- end
- end
- #--------------------------------------------------------------------------
- # Ajuda na veificação do status dos steps
- #--------------------------------------------------------------------------
- def index_stat_steps(conteudo)
- return conteudo.index{|value|
- if value[0] == "min" || value[0] == "minuto"
- min_ingame == value[1].to_i
- elsif value[0] == "hour" || value[0] == "hora"
- hour_ingame == value[1].to_i
- elsif (value[0] == "day" || value[0] == "dia") && value[2]
- day_ingame == value[1].to_i
- elsif value[0] == "month" || value[0] == "mes"
- month_ingame == value[1].to_i
- elsif value[0] == "year" || value[0] == "año"
- year_ingame == value[1].to_i
- elsif phase_ingame[1] == value[0]
- phase_ingame[1] == value[0]
- end
- }
- end
- #--------------------------------------------------------------------------
- # * Atualiza quadro a quadro as opções de tempo
- #--------------------------------------------------------------------------
- def update
- clear_daynight
- set_sec
- timer
- refresh
- daynight_enconter_troop
- daynight_enconter_rate
- end
- #--------------------------------------------------------------------------
- # * Inicia o timer
- #--------------------------------------------------------------------------
- def timer
- @min_seg = Graphics.frame_count % set_sec
- if (@min_seg +1) == set_sec
- @minutos += 1
- end
- end
- #--------------------------------------------------------------------------
- # * Atualizer de imediato as opções de tempo
- #--------------------------------------------------------------------------
- def refresh
- update_phases
- varable_refresh
- end
- #--------------------------------------------------------------------------
- # * transforma o tempo em min
- #--------------------------------------------------------------------------
- def change_minutes(ary)
- ciclos = BFK::DayNight::CICLOS
- min = 0
- min = ary[0]
- min += (ary[1] * ciclos[0])
- min += (((ary[2] - 1) * ciclos[1])*ciclos[0])
- min += ((((ary[3].to_i - 1) * ciclos[2])*ciclos[1])*ciclos[0])
- min += ((((ary[4] * ciclos[3])* ciclos[2])*ciclos[1])*ciclos[0])
- return min
- end
- #--------------------------------------------------------------------------
- # * limpa a tela caso o mapa tenha o dia e noite desligado
- #--------------------------------------------------------------------------
- def clear_daynight
- @daynight_off = $game_map.daynight_off?
- return if @daynight_off == false
- set_trans(false)
- $game_map.screen.start_tone_change(Tone.new(0, 0, 0), 0)
- end
- #--------------------------------------------------------------------------
- # * Atualiza os periodos do dis (phases)
- #--------------------------------------------------------------------------
- def update_phases
- max_hora = BFK::DayNight::PHASE_CICLO
- p_phase = 0
- BFK::DayNight::PHASE.each { |index|
- hora = index[2]
- if hora[0] > hora[1] # se for transição de 24h para 0h
- if hour_ingame.between?( 0, hora[1] ) || hour_ingame.between?( hora[0] ,max_hora )
- @phase_ingame = [p_phase,index[0]]
- transitor_phase(index,p_phase) if @daynight_off == false
- end
- else
- # se NÃO for transição de 24h para 0h
- if hour_ingame.between?( hora[0], hora[1] )
- @phase_ingame = [p_phase,index[0]]
- transitor_phase(index,p_phase) if @daynight_off == false
- end
- end
- p_phase += 1
- } #do
- $game_variables[BFK::DayNight::VARIABLE[0]] = @phase_ingame[0] if BFK::DayNight::VARIABLE
- switch_refresh(@phase_ingame[0],BFK::DayNight::SWITCH)
- end
- #--------------------------------------------------------------------------
- # * Atualiza a tela para as transições de tela dos periodos (phases)
- #--------------------------------------------------------------------------
- def transitor_phase(index,p_phase)
- hora = index[2]
- phase = BFK::DayNight::PHASE
- duration = 0
- duration = (Graphics.frame_rate * BFK::DayNight::SEC_MIN)/3
- rew = ((p_phase -1) < 0) ? (phase.count)-1 : (p_phase -1)
- if hour_ingame == hora[0] && @trans == nil
- #transição no começo da hora
- $game_map.screen.start_tone_change(phase[rew][1], 0)
- @trans = true
- $game_map.screen.start_tone_change(index[1], duration)
- elsif @trans == true
- @trans = false if @tone_duration == 0
- else
- #fora da hora de transição
- @trans = nil if @trans == false && hour_ingame != hora[0]
- $game_map.screen.start_tone_change(index[1], 0)
- end
- end
- #--------------------------------------------------------------------------
- # * retorna os minutos em suas variaveis
- #--------------------------------------------------------------------------
- def min_ingame(min=nil)
- unless min
- return @minutos % BFK::DayNight::CICLOS[0]
- else
- return min % BFK::DayNight::CICLOS[0]
- end
- end
- #--------------------------------------------------------------------------
- # * retorna as horas em suas variaveis
- #--------------------------------------------------------------------------
- def hour_ingame(min=nil)
- ciclos = BFK::DayNight::CICLOS
- unless min
- return hour = (@minutos / ciclos[0]) % ciclos[1]
- else
- return hour = (min / ciclos[0]) % ciclos[1]
- end
- end
- #--------------------------------------------------------------------------
- # * retorna os dias em suas variaveis
- #--------------------------------------------------------------------------
- def day_ingame(min=nil)
- ciclos = BFK::DayNight::CICLOS
- unless min
- return day = (((@minutos / ciclos[0]) / ciclos[1])% ciclos[2]) +1
- else
- return day = (((min / ciclos[0]) / ciclos[1])% ciclos[2]) +1
- end
- end
- #--------------------------------------------------------------------------
- # * retorna os meses em suas variaveis
- #--------------------------------------------------------------------------
- def month_ingame(min=nil)
- ciclos = BFK::DayNight::CICLOS
- unless min
- return month = ((((@minutos / ciclos[0]) / ciclos[1]) / ciclos[2]) % ciclos[3])+1
- else
- return month = ((((min / ciclos[0]) / ciclos[1]) / ciclos[2]) % ciclos[3])+1
- end
- end
- #--------------------------------------------------------------------------
- # * retorna os anos em suas variaveis
- #--------------------------------------------------------------------------
- def year_ingame(min=nil)
- ciclos = BFK::DayNight::CICLOS
- unless min
- return year = ((((@minutos / ciclos[0]) / ciclos[1]) / ciclos[2]) / ciclos[3])
- else
- return year = ((((min / ciclos[0]) / ciclos[1]) / ciclos[2]) / ciclos[3])
- end
- end
- #--------------------------------------------------------------------------
- # * Atualiza as variaveis dos periodos
- #--------------------------------------------------------------------------
- def varable_refresh
- if BFK::DayNight::VARIABLE
- $game_variables[BFK::DayNight::VARIABLE[1]] = min_ingame
- $game_variables[BFK::DayNight::VARIABLE[2]] = hour_ingame
- $game_variables[BFK::DayNight::VARIABLE[3]] = day_ingame
- $game_variables[BFK::DayNight::VARIABLE[4]] = month_ingame
- $game_variables[BFK::DayNight::VARIABLE[5]] = year_ingame
- end
- end
- #--------------------------------------------------------------------------
- # * Atualiza as Switchs dos periodos do dias (phases)
- #--------------------------------------------------------------------------
- def switch_refresh(value,id_switch)
- for id in id_switch
- $game_switches[id.to_i] = (id_switch.index(id) == value.to_i) ? true : false
- end
- end
- #--------------------------------------------------------------------------
- # * define se a transição esta ocorrendo
- #--------------------------------------------------------------------------
- def set_trans(transition=nil)
- @trans = transition
- end
- #--------------------------------------------------------------------------
- # * Altera o tempo usar um array [tempo,valor,fixo] fixo é sempre true
- #--------------------------------------------------------------------------
- def altTime(*arg)
- ciclos = BFK::DayNight::CICLOS
- allmin= 0
- arg.each{|value|
- allmin = @minutos unless value[2]
- case value[0]
- when "min" , "minute" , "minuto"
- allmin += value[1]
- when "h" , "hour" , "hora"
- allmin += (value[1] * ciclos[0])
- when "d" , "day" , "dia"
- allmin += (((value[1] -1) * ciclos[1])*ciclos[0])
- when "m" , "mouth" , "mes"
- allmin += ((((value[1] -1) * ciclos[2])*ciclos[1])*ciclos[0])
- when "y" , "year" , "ano"
- allmin += ((((value[1] * ciclos[3])* ciclos[2])*ciclos[1])*ciclos[0])
- end
- }
- @minutos = allmin
- set_trans(false)
- end
- #--------------------------------------------------------------------------
- # * retorna uma String com a Hora do jogo
- #--------------------------------------------------------------------------
- def timeIngame
- sprintf("%02d:%02d",hour_ingame,min_ingame )
- end
- #--------------------------------------------------------------------------
- # * Retorna uma string com a data do jogo
- #--------------------------------------------------------------------------
- def dateIngame
- mes = how_many_month_name?(true)
- sprintf("%02d/%s/%s",day_ingame,mes,year_ingame )
- end
- #--------------------------------------------------------------------------
- # * Retorna o nome do periodo (dia, tarde, noite, etc.)
- #--------------------------------------------------------------------------
- def which_phase_name?
- @phase_ingame[1].capitalize
- end
- #--------------------------------------------------------------------------
- # * Retorna o id da variavel do periodo (bom para usar com variaveis)
- #--------------------------------------------------------------------------
- def which_phase_id?
- @phase_ingame[0].to_i
- end
- #--------------------------------------------------------------------------
- # * Retorna o minuto atual (bom para usar com variaveis)
- #--------------------------------------------------------------------------
- def how_many_min?
- sprintf("%02d",min_ingame )
- end
- #--------------------------------------------------------------------------
- # * Retorna a hora atual (bom para usar com variaveis)
- #--------------------------------------------------------------------------
- def how_many_hour?
- sprintf("%02d",hour_ingame )
- end
- #--------------------------------------------------------------------------
- # * Retorna o dis atual (bom para usar com variaveis)
- #--------------------------------------------------------------------------
- def how_many_day?
- sprintf("%02d",day_ingame )
- end
- #--------------------------------------------------------------------------
- # * Retorna o mês atual (bom para usar com variaveis)
- #--------------------------------------------------------------------------
- def how_many_month?
- sprintf("%02d",month_ingame )
- end
- #--------------------------------------------------------------------------
- # * Retorna o mês atual (bom para usar com variaveis)
- #--------------------------------------------------------------------------
- def how_many_month_name?(abr=false)
- if abr == false
- BFK::DayNight::MONTH_NAMES[month_ingame.to_i][0]
- else
- BFK::DayNight::MONTH_NAMES[month_ingame.to_i][1]
- end
- end
- #--------------------------------------------------------------------------
- # * Retorna o ano atual (bom para usar com variaveis)
- #--------------------------------------------------------------------------
- def how_many_year?
- sprintf("%04d",year_ingame )
- end
- end
- #==============================================================================
- # ** Display_Phase
- #------------------------------------------------------------------------------
- # Esta é a classe que controla o grsfico de periodo no relogio.
- #==============================================================================
- class Display_Phase < Sprite_Base
- #--------------------------------------------------------------------------
- # * Inicializa o sprite
- #--------------------------------------------------------------------------
- def initialize(x,y)
- super(nil)
- self.x = x+4
- self.y = y +4
- self.z += 2
- self.bitmap = Cache.system("weather_mini")
- refresh
- end
- #--------------------------------------------------------------------------
- # * Atualiza o sprite no mapa
- #--------------------------------------------------------------------------
- def update_phase
- @phase = $game_daynight.which_phase_id?
- @index_phase_picy = @phase
- @index_phase_picx = 0
- end
- #--------------------------------------------------------------------------
- # * Inicializa o sprite
- #--------------------------------------------------------------------------
- def update_phase_pic
- self.src_rect.set(64*@index_phase_picx, 64*@index_phase_picy, 64, 64)
- self.zoom_x = 0.5
- self.zoom_y = 0.5
- end
- #--------------------------------------------------------------------------
- # * Metodo utilizado pela Scane para atualizar a imagem
- #--------------------------------------------------------------------------
- def refresh
- self.bitmap = Cache.system("weather_mini") unless self.bitmap
- update_phase
- update_phase_pic
- end
- def dispose
- self.bitmap = nil
- #super
- end
- end
- #==============================================================================
- # ** Window_Base
- #------------------------------------------------------------------------------
- # Esta é a superclasse para todas as janelas no jogo.
- #==============================================================================
- class Window_Base < Window
- alias daynight_convert_escape_characters convert_escape_characters
- def convert_escape_characters(text)
- result = daynight_convert_escape_characters(text)
- result.gsub!(/\eDate/i) { $game_daynight.dateIngame }
- result.gsub!(/\eTime/i) { $game_daynight.timeIngame }
- result.gsub!(/\ePhase/i) { $game_daynight.which_phase_name? }
- result.gsub!(/\eMinute/i) { $game_daynight.how_many_min? }
- result.gsub!(/\eHour/i) { $game_daynight.how_many_hour? }
- result.gsub!(/\eDay/i) { $game_daynight.how_many_day? }
- result.gsub!(/\eMonth/i) { $game_daynight.how_many_month? }
- result.gsub!(/\eYear/i) { $game_daynight.how_many_year? }
- result
- end
- end
- #==============================================================================
- # ** Window_Display_Time
- #------------------------------------------------------------------------------
- # Janela do relogio do mapa
- #==============================================================================
- class Window_Display_HUD < Window_Base
- #--------------------------------------------------------------------------
- # * Inicialização do objeto
- #--------------------------------------------------------------------------
- def initialize
- super(0, 0, window_width, fitting_height(1))
- self.opacity = 0
- refresh
- end
- #--------------------------------------------------------------------------
- # * define o tamanho da janela
- #--------------------------------------------------------------------------
- def window_width
- return 128
- end
- #--------------------------------------------------------------------------
- # * Metodo utilizado pela Scane para atualizar a imagem
- #--------------------------------------------------------------------------
- def refresh
- self.show
- contents.clear
- draw_background(contents.rect)
- draw_text(contents.rect, hora, 1)
- end
- #--------------------------------------------------------------------------
- # * Metodo para construir o Background do relogio
- #--------------------------------------------------------------------------
- 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
- #--------------------------------------------------------------------------
- # * Metodo para definir a posição do relogio
- #--------------------------------------------------------------------------
- def pos_window_time
- x = 0
- y = 0
- case BFK::DayNight::DISPLAY_HUD_POS
- when 1
- x = Graphics.width - self.width
- when 2
- x = Graphics.width - self.width
- y = Graphics.height - self.height
- when 3
- y = Graphics.height - self.height
- end
- self.x = x
- self.y = y
- end
- #--------------------------------------------------------------------------
- # * Aquisição do valor das horas
- #--------------------------------------------------------------------------
- def hora
- $game_daynight.timeIngame
- end
- #--------------------------------------------------------------------------
- # * Aquisição da cor do plano de fundo 1
- #--------------------------------------------------------------------------
- def back_color1
- Color.new(0, 0, 0, 192)
- end
- #--------------------------------------------------------------------------
- # * Aquisição da cor do plano de fundo 2
- #--------------------------------------------------------------------------
- def back_color2
- Color.new(0, 0, 0, 0)
- end
- #--------------------------------------------------------------------------
- # * Abertura da janela
- #--------------------------------------------------------------------------
- def open
- refresh
- super
- end
- end
- #==============================================================================
- # ** Window_DayNight_Time
- #------------------------------------------------------------------------------
- # Esta é a classe para a janela de tempo do jogo.
- #==============================================================================
- class Window_DayNight_Time < Window_Base
- #--------------------------------------------------------------------------
- # * Inicialização do objeto
- #--------------------------------------------------------------------------
- def initialize
- @n = 0
- @n += 1 if BFK::DayNight::MENU_DATE
- @n += 1 if BFK::DayNight::MENU_TIME
- super(0, 0, window_width, fitting_height(@n))
- refresh
- end
- #--------------------------------------------------------------------------
- # * Aquisição da largura da janela
- #--------------------------------------------------------------------------
- def window_width
- return 160
- end
- #--------------------------------------------------------------------------
- # * Desenho do tempo
- # hora : hora
- # phase : Periodo (phase)
- # x : coordenada X
- # y : coordenada Y
- # width : largura
- #--------------------------------------------------------------------------
- def draw_daynight_time(hora, phase, x, y, width)
- cx = text_size(hora).width
- change_color(system_color)
- draw_text(x, y, width -cx -2, line_height, phase, 1)
- change_color(normal_color)
- draw_text(x, y, width , line_height, hora,2)
- end
- #--------------------------------------------------------------------------
- # * Desenho do tempo
- # hora : hora
- # phase : Periodo (phase)
- # x : coordenada X
- # y : coordenada Y
- # width : largura
- #--------------------------------------------------------------------------
- def draw_daynight_date(date, x, y, width)
- change_color(normal_color)
- draw_text(x, y, width - 5, line_height, date,1)
- end
- #--------------------------------------------------------------------------
- # * Renovação
- #--------------------------------------------------------------------------
- def refresh
- contents.clear
- ny = (@n >1) ? line_height : 0
- $game_daynight.update_phases
- draw_daynight_time(hora,dayNight_Phase,0, 0, contents.width - 8) if BFK::DayNight::MENU_TIME
- draw_daynight_date(date,4,ny, contents.width - 8) if BFK::DayNight::MENU_DATE
- end
- #--------------------------------------------------------------------------
- # * Aquisição do valor das horas
- #--------------------------------------------------------------------------
- def hora
- $game_daynight.timeIngame
- end
- #--------------------------------------------------------------------------
- # * Aquisição do nome da Phase
- #--------------------------------------------------------------------------
- def dayNight_Phase
- $game_daynight.which_phase_name?
- end
- #--------------------------------------------------------------------------
- # * Aquisição do valor da data
- #--------------------------------------------------------------------------
- def date
- $game_daynight.dateIngame
- end
- #--------------------------------------------------------------------------
- # * Abertura da janela
- #--------------------------------------------------------------------------
- def open
- refresh
- super
- end
- end
- #==============================================================================
- # ** Window_NumberInput
- #------------------------------------------------------------------------------
- # Esta janela é utilizada para o comando de eventos [Armazenar Número]
- #==============================================================================
- class Window_TimeInput < Window_Selectable
- def initialize
- super(0, 0, 0, 0)
- @digits_max = BFK::DayNight::MAX_DIGIT #( 4 para alterar apenas hora - 12 para alteração completa )
- @index = 0
- @number = 0
- @handler = {}
- @matriz = define_matriz
- self.z +=1
- end
- #--------------------------------------------------------------------------
- # * Define um array com os digitos divididos que será
- #--------------------------------------------------------------------------
- def define_matriz
- min = sprintf("%02d",$game_daynight.min_ingame)
- hour = sprintf("%02d",$game_daynight.hour_ingame)
- day = sprintf("%02d",$game_daynight.day_ingame)
- month = sprintf("%02d",$game_daynight.month_ingame)
- year = sprintf("%04d",$game_daynight.year_ingame)
- return a =[
- hour[0].to_i,hour[1].to_i,
- min[0].to_i,min[1].to_i,
- day[0].to_i,day[1].to_i,
- month[0].to_i,month[1].to_i,
- year[0].to_i,year[1].to_i,year[2].to_i,year[3].to_i
- ]
- end
- #--------------------------------------------------------------------------
- # * Define inicia a janela e seu conteudo
- #--------------------------------------------------------------------------
- def start
- update_placement
- create_contents
- open
- refresh
- draw_labels
- @index = 0
- end
- #--------------------------------------------------------------------------
- # * Atualiza a caixa
- #--------------------------------------------------------------------------
- alias daynight_update update
- def update
- if open? && active
- daynight_process_cursor_move
- process_digit_change
- update_cursor
- refresh
- end
- daynight_update
- end
- #--------------------------------------------------------------------------
- # * Renovação
- #--------------------------------------------------------------------------
- def refresh
- contents.clear
- draw_labels
- change_color(normal_color)
- @digits_max.times do |i|
- rect = item_rect(i)
- rect.x += 1
- contents.font.size = 32
- draw_text(rect, @matriz[i],1)
- non_item_rect(i)
- end
- end
- #--------------------------------------------------------------------------
- # * Movimento do cursor para direita
- # wrap : cursor retornar a primeira ou ultima posição
- #--------------------------------------------------------------------------
- def daynight_cursor_right(wrap)
- if @index < @digits_max - 1 || wrap
- @index = (@index + 1) % @digits_max
- end
- end
- #--------------------------------------------------------------------------
- # * Movimento do cursor para esquerda
- # wrap : cursor retornar a primeira ou ultima posição
- #--------------------------------------------------------------------------
- def daynight_cursor_left(wrap)
- if @index > 0 || wrap
- @index = (@index + @digits_max - 1) % @digits_max
- end
- end
- #--------------------------------------------------------------------------
- # * Atualização do cursor
- #--------------------------------------------------------------------------
- alias dynight_update_cursor update_cursor
- def update_cursor
- cursor_rect.set(item_rect(@index))
- end
- #--------------------------------------------------------------------------
- # * Execução do movimento do cursor
- #--------------------------------------------------------------------------
- def daynight_process_cursor_move
- return unless active
- last_index = @index
- daynight_cursor_right(Input.trigger?(:RIGHT)) if Input.repeat?(:RIGHT)
- daynight_cursor_left (Input.trigger?(:LEFT)) if Input.repeat?(:LEFT)
- Sound.play_cursor if @index != last_index
- end
- #--------------------------------------------------------------------------
- # * Aquisição do retangulo para desenhar o item
- # index : índice do item
- #--------------------------------------------------------------------------
- def item_rect(index)
- a = 0
- space = BFK::DayNight::MENU_SPACE
- space2 = BFK::DayNight::MENU_RECT * 2
- a = 1 if index > 1
- a = 2 if index > 3
- a = 3 if index > 5
- a = 4 if index > 7
- Rect.new(((index + a) * 20)+ space,space2, 20, line_height * 1.5)
- end
- #--------------------------------------------------------------------------
- # * Definição das caixas de numeros para edição
- #--------------------------------------------------------------------------
- def non_item_rect(index)
- space = BFK::DayNight::MENU_SPACE
- space2 = BFK::DayNight::MENU_RECT * 2
- draw_text((index * 20)+ space, space2, 20, line_height * 1.5, ":",1) if index == 2
- draw_text((index * 20)+ space, space2, 20, line_height * 1.5, "-",1) if index == 5
- draw_text((index * 20)+ space, space2, 20, line_height * 1.5, "/",1) if index == 8
- draw_text((index * 20)+ space, space2, 20, line_height * 1.5, "/",1) if index == 11
- end
- #--------------------------------------------------------------------------
- # * Execução da mudança de digito
- #--------------------------------------------------------------------------
- def process_digit_change()
- return unless active
- ciclo = [
- BFK::DayNight::CICLOS[1].to_s,BFK::DayNight::CICLOS[1].to_s,
- BFK::DayNight::CICLOS[0].to_s,BFK::DayNight::CICLOS[0].to_s,
- BFK::DayNight::CICLOS[2].to_s,BFK::DayNight::CICLOS[2].to_s,
- BFK::DayNight::CICLOS[3].to_s,BFK::DayNight::CICLOS[3].to_s
- ]
- if Input.repeat?(:UP) || Input.repeat?(:DOWN)
- Sound.play_cursor
- case @index
- when 0,6
- r = ciclo[@index][0].to_i + 1; u = 1; d = ciclo[@index][0].to_i
- when 1,5
- r = (@matriz[@index -1]< ciclo[@index][0].to_i) ? 10 :
- (ciclo[@index][1].to_i < 1)? 1 : ciclo[@index][1].to_i; u = 1
- d = (@matriz[@index -1]< ciclo[@index][0].to_i) ? 9 :
- ciclo[@index][1].to_i - 1
- when 2
- r = (ciclo[@index][0].to_i < 1)? 1 : ciclo[@index][0].to_i; u = 1
- d = ciclo[@index][1].to_i - 1
- when 4
- r = ciclo[@index][0].to_i + 1; u = 1;
- d = (ciclo[@index][0].to_i > 0)? ciclo[@index][0].to_i - 1 : 9
- when 7
- r = (@matriz[@index -1]< ciclo[@index][0].to_i) ? 10 :
- (ciclo[@index][1].to_i < 1)? 1 : ciclo[@index][1].to_i + 1; u = 1
- d = (@matriz[@index -1]< ciclo[@index][0].to_i) ? 9 :
- ciclo[@index][1].to_i - 1
- else
- r = 10; u = 1; d = 9
- end
- @matriz[@index] = (@matriz[@index] + u) % r if Input.repeat?(:UP)
- @matriz[@index] = (@matriz[@index] + d) % r if Input.repeat?(:DOWN)
- #if numero quebrado resetar no maximo
- @matriz[1] = 0 if @matriz[0] >= ciclo[0][0].to_i && @matriz[1] >= ciclo[0][1].to_i
- @matriz[5] = 0 if @matriz[4] >= ciclo[4][0].to_i && @matriz[5] >= ciclo[4][1].to_i
- @matriz[5] = 1 if @matriz[4] == 0 && @matriz[5]==0
- @matriz[7] = 0 if @matriz[6] >= ciclo[6][0].to_i && @matriz[7] > ciclo[6][1].to_i
- end
- end
- #--------------------------------------------------------------------------
- # * Define os Labeis do tempo
- #--------------------------------------------------------------------------
- def draw_labels
- names = BFK::DayNight::CICLOS_NAMES
- contents.font.size = 20
- change_color(system_color)
- space = BFK::DayNight::MENU_SPACE
- names.each_index do |i|
- return if @digits_max/2 == i
- w = text_size(names[i][0])
- draw_text( (i * 63)+space,0,w.width + space,line_height, names[i][1].capitalize)
- end
- end
- #--------------------------------------------------------------------------
- # * Atualização da posição da janela
- #--------------------------------------------------------------------------
- def update_placement
- self.width = @digits_max * 20 + padding * 2 + BFK::DayNight::MENU_SPACE * 6
- self.height = fitting_height(3)
- self.x = (Graphics.width - width) / 2
- self.y = (Graphics.height - height) / 2
- end
- #--------------------------------------------------------------------------
- # * Atualização com ok da janela
- #--------------------------------------------------------------------------
- def daynight_ok_process
- Sound.play_ok
- 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,
- @matriz[6].to_s + @matriz[7].to_s, @matriz[8].to_s + @matriz[9].to_s + @matriz[10].to_s + @matriz[11].to_s]
- return a.collect!{|x| x.to_i}
- end
- end
- #==============================================================================
- # ** Window_MenuCommand
- #------------------------------------------------------------------------------
- # Esta janela exibe os comandos do menu.
- #==============================================================================
- class Window_MenuCommand < Window_Command
- #--------------------------------------------------------------------------
- # * Adição de comandos próprios
- #--------------------------------------------------------------------------
- alias dn_add_original_commands add_original_commands
- def add_original_commands
- dn_add_original_commands
- add_command(BFK::DayNight::MENU_NAME, :daynight, daynight_enabled)
- end
- #--------------------------------------------------------------------------
- # * Verifica se o mnu dia e noite pode ser exibido no menu
- #--------------------------------------------------------------------------
- def daynight_enabled
- BFK::DayNight::MENU_ACTIVE
- end
- end
- #==============================================================================
- # ** Game_Map
- #------------------------------------------------------------------------------
- # Esta classe altera o comportamento da classe original sem modifica-la
- #==============================================================================
- class Game_Map
- attr_reader :original_list
- attr_reader :original_step
- attr_reader :daynight_off
- #--------------------------------------------------------------------------
- # * FUNÇÃO QUE AUXILIA NA BUSCA DE TAGS (ESTA FUNÇÃO SERÁ MODIFICADA PELAS ATUALIZAÇÕES
- #--------------------------------------------------------------------------
- def find_map_note(rgx)
- l_note = @map.note.scan(rgx)
- l_note.each{ |off|
- return true if off
- }
- return false
- end
- #--------------------------------------------------------------------------
- # * Aqui verifica se o mapa aceita as transições
- #--------------------------------------------------------------------------
- def daynight_off?
- @daynight_off = BFK.find_map_note(BFK::DayNight::RGXMAP)
- end
- #--------------------------------------------------------------------------
- # * Aqui faz as configurações original do mapa
- #--------------------------------------------------------------------------
- alias daynight_setup setup
- def setup(map_id)
- daynight_setup(map_id)
- daynight_off?
- @original_step = @map.encounter_step
- end
- end
- #==============================================================================
- # ** Scene_Menu
- #------------------------------------------------------------------------------
- # Esta classe executa o processamento da tela de menu.
- #==============================================================================
- class Scene_Menu < Scene_MenuBase
- alias daynight_start start
- def start
- daynight_start
- create_window_daynight
- create_status_daynight_time if BFK::DayNight::MENU_TIME || BFK::DayNight::MENU_DATE
- end
- #--------------------------------------------------------------------------
- # * Criação da janela de atributos
- #--------------------------------------------------------------------------
- def create_window_daynight
- @window_daynight = Window_TimeInput.new
- end
- #--------------------------------------------------------------------------
- # * Cria a janela de tempo
- #--------------------------------------------------------------------------
- def create_status_daynight_time
- @daynight_window_time = Window_DayNight_Time.new
- @daynight_window_time.x = 0
- @daynight_window_time.y = @command_window.height
- end
- #--------------------------------------------------------------------------
- # * Criação da janela de comando
- #--------------------------------------------------------------------------
- alias daynight_create_command_window create_command_window
- def create_command_window
- daynight_create_command_window
- @command_window.set_handler(:daynight, method(:command_daynight))
- end
- #--------------------------------------------------------------------------
- # * Comando [Tempo]
- #--------------------------------------------------------------------------
- def command_daynight
- @window_daynight.activate
- @window_daynight.start
- @window_daynight.set_handler(:ok, method(:on_daynight_ok))
- @window_daynight.set_handler(:cancel, method(:on_daynight_cancel))
- end
- #--------------------------------------------------------------------------
- # * Comandos individuais [Confirmação]
- #--------------------------------------------------------------------------
- def on_daynight_ok
- Sound.play_ok
- $game_daynight.set_trans(false)
- $game_daynight.minutos = $game_daynight.change_minutes( @window_daynight.daynight_ok_process)
- @daynight_window_time.refresh
- @window_daynight.unselect
- @window_daynight.close
- @command_window.activate
- end
- #--------------------------------------------------------------------------
- # * Comandos individuais [Cancelamento]
- #--------------------------------------------------------------------------
- def on_daynight_cancel
- Sound.play_cancel
- @window_daynight.unselect
- @window_daynight.deactivate
- @window_daynight.close
- @command_window.activate
- end
- end
- #==============================================================================
- # ** Scene_Map
- #------------------------------------------------------------------------------
- # Esta classe executa o processamento da tela de mapa.
- #==============================================================================
- class Scene_Map < Scene_Base
- #--------------------------------------------------------------------------
- # * Inicialização do processo
- #--------------------------------------------------------------------------
- def initialize
- if $game_daynight
- $game_daynight.trans = false
- $game_daynight.refresh
- end
- end
- #--------------------------------------------------------------------------
- # * inicializa as janelas do menu, hud e o contador de tempo
- #--------------------------------------------------------------------------
- alias start_daynight start
- def start
- $game_daynight = DayNight.new unless $game_daynight
- if $game_daynight.time_hud == true
- @window_display_hud = Window_Display_HUD.new
- @window_display_hud.pos_window_time
- @window_phase_hud = Display_Phase.new(@window_display_hud.x, @window_display_hud.y)
- @window_phase_hud.viewport = @window_display_hud.viewport
- elsif $game_daynight.time_hud == false
- @window_display_hud.hide
- #@window_phase_hud.hide
- end
- start_daynight
- end
- #--------------------------------------------------------------------------
- # * Atualiza o script
- #--------------------------------------------------------------------------
- alias daynight_update update
- def update
- $game_daynight.update
- if $game_daynight.time_hud == true
- @window_display_hud.refresh
- @window_phase_hud.refresh
- elsif $game_daynight.time_hud == false
- @window_display_hud.hide
- @window_phase_hud.dispose
- end
- daynight_update
- end
- #--------------------------------------------------------------------------
- # * Atualiza o a transição antes do fadeout
- #--------------------------------------------------------------------------
- alias post_transfer_daynight post_transfer
- def post_transfer
- $game_daynight.clear_daynight
- $game_daynight.refresh
- post_transfer_daynight
- end
- #--------------------------------------------------------------------------
- # * termina a scene
- #--------------------------------------------------------------------------
- alias pre_terminate_daylight pre_terminate
- def pre_terminate
- pre_terminate_daylight
- @window_phase_hud.dispose if @window_phase_hud
- end
- #--------------------------------------------------------------------------
- # * termina a scene
- #--------------------------------------------------------------------------
- alias terminate_daylight terminate
- def terminate
- terminate_daylight
- @window_phase_hud.dispose if @window_phase_hud
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement