Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ################################################################################
- ################################################################################
- ########################### Classe Advanced_Time #########################################
- ################################################################################
- ################################################################################
- #===============================================================================
- # Criado por Renan Tsuneo Hangai Junior
- #===============================================================================
- module RTH
- MUDA_TOM_TELA = true
- end
- class Game_Advanced_Time
- attr_reader :tone
- attr_reader :total_sec
- attr_reader :rate
- attr_reader :rated
- attr_reader :minuto
- attr_reader :hora
- def initialize
- @ano = @initial_ano = PLANTACAO::DATA_INICIAL[5]
- @mes = @initial_mes = @total_mes = PLANTACAO::DATA_INICIAL[4]
- @dia = @initial_dia = @total_dia = PLANTACAO::DATA_INICIAL[3]
- @hora = @initial_hora = @total_hora = PLANTACAO::DATA_INICIAL[2]
- @minuto = @initial_minuto = @total_minuto = PLANTACAO::DATA_INICIAL[1]
- @segundo = @initial_segundo = @total_sec = PLANTACAO::DATA_INICIAL[0]
- @update_start_weather = false
- @total_day_sec = 0
- @tone = Tone.new(0, 0, 0, 0)
- @rated = false
- set_meses
- set_dias
- @now_rate = -1
- set_rate(PLANTACAO::TIME_AD)
- @chovendo = false
- @total_weather_hora = @hora
- @chovendo_chance = rand(100) < 10
- update_tone
- end
- def set_meses
- @meses = []
- for i in 0...PLANTACAO::TIME::MESES.size
- next if PLANTACAO::TIME::MESES[i].nil?
- begin
- @meses[i] = Game_Month.new(*PLANTACAO::TIME::MESES[i])
- rescue
- @meses[i] = nil
- print "O mês #{i} não foi ajustado direito"
- end
- end
- end
- def mes_atual
- return @meses[@mes]
- end
- def set_dias
- end
- def set_rate(valor)
- return if @now_rate == valor
- @now_rate = valor
- @rated = false
- @rate = valor.to_f * Graphics.frame_rate.to_f / 100.0
- if @rate < 1.0
- @rated = true
- @rate = Graphics.frame_rate.to_f / valor.to_f
- end
- end
- def update
- update_time
- update_tone
- update_weather
- end
- def update_weather
- @weather = @meses[@mes].type_weather(@dia)
- @time_weather = @meses[@mes].time_weather(@dia)
- @duration_weather = @meses[@mes].duration_weather(@dia)
- @power_weather = @meses[@mes].power_weather(@dia)
- if @total_weather_hora.between?(@time_weather, @time_weather + @duration_weather)
- $game_screen.weather(@weather, @power_weather, rand(40) + 40)
- else
- @total_weather_hora = @hora
- $game_screen.weather(0, 0, rand(40) + 40)
- end
- end
- def time_s
- horas = sprintf("%02d:%02d:%02d", @hora, @minuto, @segundo)
- data = sprintf("%02d/%02d/%04d", @dia, @mes, @ano)
- return ("São #{horas} de #{data}")
- end
- def time
- return [@ano, @mes, @dia, @hora, @minuto, @segundo]
- end
- def ano_duration_sec
- return self.mes_duration_sec * 12
- end
- def mes_duration_sec
- return self.dia_duration_sec * 30
- end
- def dia_duration_sec
- return 3600 * 24
- end
- def hora_duration_sec
- return 3600
- end
- def minuto_duration_sec
- return 60
- end
- def update_time
- if @rated
- @segundo += @rate
- elsif Graphics.frame_count % @rate == 0
- @segundo += 1
- end
- @total_sec += @rate
- @total_day_sec = (@total_day_sec + @rate) % (3600 * 24)
- premes = @mes
- predia = @dia
- if @segundo >= 60
- @minuto += (@segundo.to_f / 60.0).truncate
- if @minuto >= 60
- @hora += (@minuto.to_f / 60.0).truncate
- @total_weather_hora += (@minuto.to_f / 60.0).truncate
- if @hora >= 24
- @dia += (@hora.to_f / 24.0).truncate
- if @dia >= (@meses[@mes].dias + 1)
- @mes += (@dia.to_f / @meses[@mes].dias.to_f).truncate
- @dia = 1
- if @mes >= @meses.size
- @ano += (@mes.to_f / (@meses.size.to_f - 1.0)).truncate
- @mes = 1
- for ames in @meses
- next if ames.nil?
- ames.set_chances
- end
- end
- end
- end
- end
- end
- @segundo %= 60
- @minuto %= 60
- @hora %= 24
- end
- def update_tone
- x = ((@total_day_sec.to_f / 3600.0) - 6) % 24
- y = (Math::PI * x / (12.0)) % Math::PI
- time = 0
- max = -100
- min = 70
- txt = [(x <= 12 ? "max" : "min"), (x <= 12 ? max : min)]
- eval("time = [#{txt[1]} * Math.sin(y) * (x <= 12 ? 2 : 1), #{txt[1]}].#{txt[0]} - 50")
- @tone.set(time, time, time, 0)
- end
- end
- RTH.ini_var_add(:gat, "Game_Advanced_Time")
- RTH.save_game_puts(:gat)
- if RTH::MUDA_TOM_TELA
- class Scene_Map ; attr_reader :spriteset ; end
- class Game_Map
- def set_scene_refresh
- if $scene.instance_of?(Scene_Map)
- $scene.spriteset.reset_sprites
- end
- end
- end
- class Spriteset_Map
- def initialize_plant_variables
- @spriteset_gat = Viewport.new(0, 0, 640, 480)
- @spriteset_gat.z = 5001
- @lanternas = []
- @reseted = false
- end
- def dispose_plant_variables
- @spriteset_gat.dispose
- for i in @lanternas
- next if i.nil?
- i.bitmap.dispose
- i.dispose
- end
- end
- def update_plant_ini
- @spriteset_gat.tone = $gat.tone
- end
- def reset_sprites
- for i in 0...@character_sprites.size
- char = @character_sprites[i]
- next if char.nil?
- next if char.character.nil?
- next if char.character == $game_player
- zoom = nil
- if char.character.comment_list.no_case_include?("lantern")
- zoom = char.character.comment_value("intensidade")
- zoom ||= 10.0
- zoom /= 10.0
- if @lanternas[i].nil?
- @lanternas[i] = Sprite.new
- @lanternas[i].bitmap = RPG::Cache.picture("Luz")
- @lanternas[i].z = 1000000
- end
- @lanternas[i].zoom_x = zoom
- @lanternas[i].zoom_y = zoom
- @lanternas[i].ox = (@lanternas[i].bitmap.width / 2)
- @lanternas[i].oy = (@lanternas[i].bitmap.height / 2) + 16
- end
- end
- @reseted = true
- end
- def update_plant_final
- reset_sprites if @reseted.false?
- for i in 0...@character_sprites.size
- char = @character_sprites[i]
- next if char.nil?
- next if char.character.nil?
- next if char.character == $game_player
- unless @lanternas[i].nil?
- @lanternas[i].x = char.x
- @lanternas[i].y = char.y
- @lanternas[i].opacity = ($gat.tone.green * 120.0 / -150.0)
- end
- end
- end
- end
- RTH.add_method_inside("Game_Map", "refresh", "set_scene_refresh", false, 1)
- RTH.add_method_inside("Spriteset_Map", "initialize", "initialize_plant_variables")
- RTH.add_method_inside("Spriteset_Map", "dispose", "dispose_plant_variables", false, 1)
- RTH.add_method_inside("Spriteset_Map", "update", "update_plant_ini")
- RTH.add_method_inside("Spriteset_Map", "update", "update_plant_final", false, 1)
- end
- RTH.add_method_inside("Scene_Map", "update", "$gat.update")
- class Game_Month
- attr_reader :name, :dias
- def initialize(name, dias, rain, storm, snow)
- @name = name
- @dias = dias
- @rain = rain
- @storm = storm
- @snow = snow
- set_chances
- end
- def set_chances
- @tempo = []
- @rain_days = []
- @storm_days = []
- @snow_days = []
- for i in 1..@dias
- next if set_array_chance(i, 24, @snow, 3, @snow_days)
- next if set_array_chance(i, 24, @storm, 2, @storm_days)
- next if set_array_chance(i, 24, @rain, 1, @rain_days)
- end
- end
- def set_array_chance(i, number, array, tipo, days)
- @tempo[i] = [-1, -1, tipo, 0]
- return false if array == []
- if (rand(100) + 1) < array[0]
- @tempo[i] = [24 % number, ((rand(array[1]) + rand(array[1])) / 2) % number, tipo, rand(10) + 1]
- days.push(i)
- return true
- end
- return false
- end
- def time_weather(dia)
- return @tempo[dia][0]
- end
- def duration_weather(dia)
- return @tempo[dia][1]
- end
- def type_weather(dia)
- return @tempo[dia][2]
- end
- def power_weather(dia)
- return @tempo[dia][3]
- end
- end
- class Game_Days
- attr_reader :name
- attr_reader :id
- def initialize(name, id)
- @name = name
- @id = id
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment