usernam3_

RTH Advanced_Time

Jan 15th, 2018
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.62 KB | None | 0 0
  1. ################################################################################
  2. ################################################################################
  3. ########################### Classe Advanced_Time #########################################
  4. ################################################################################
  5. ################################################################################
  6. #===============================================================================
  7. # Criado por Renan Tsuneo Hangai Junior
  8. #===============================================================================
  9.  
  10. module RTH
  11.  
  12.   MUDA_TOM_TELA = true
  13.  
  14. end
  15.  
  16. class Game_Advanced_Time
  17.  
  18.   attr_reader :tone
  19.   attr_reader :total_sec
  20.   attr_reader :rate
  21.   attr_reader :rated
  22.   attr_reader :minuto
  23.   attr_reader :hora
  24.  
  25.   def initialize
  26.     @ano = @initial_ano = PLANTACAO::DATA_INICIAL[5]
  27.     @mes = @initial_mes = @total_mes = PLANTACAO::DATA_INICIAL[4]
  28.     @dia = @initial_dia = @total_dia = PLANTACAO::DATA_INICIAL[3]
  29.     @hora = @initial_hora = @total_hora = PLANTACAO::DATA_INICIAL[2]
  30.     @minuto = @initial_minuto = @total_minuto = PLANTACAO::DATA_INICIAL[1]
  31.     @segundo = @initial_segundo = @total_sec = PLANTACAO::DATA_INICIAL[0]
  32.     @update_start_weather = false
  33.     @total_day_sec = 0
  34.     @tone = Tone.new(0, 0, 0, 0)
  35.     @rated = false
  36.     set_meses
  37.     set_dias
  38.     @now_rate = -1
  39.     set_rate(PLANTACAO::TIME_AD)
  40.     @chovendo = false
  41.     @total_weather_hora = @hora
  42.     @chovendo_chance = rand(100) < 10
  43.     update_tone
  44.   end
  45.  
  46.   def set_meses
  47.     @meses = []
  48.     for i in 0...PLANTACAO::TIME::MESES.size
  49.       next if PLANTACAO::TIME::MESES[i].nil?
  50.       begin
  51.         @meses[i] = Game_Month.new(*PLANTACAO::TIME::MESES[i])
  52.       rescue
  53.         @meses[i] = nil
  54.         print "O mês #{i} não foi ajustado direito"
  55.       end
  56.     end
  57.   end
  58.  
  59.   def mes_atual
  60.     return @meses[@mes]
  61.   end
  62.  
  63.   def set_dias
  64.   end
  65.  
  66.   def set_rate(valor)
  67.     return if @now_rate == valor
  68.     @now_rate = valor
  69.     @rated = false
  70.     @rate = valor.to_f * Graphics.frame_rate.to_f / 100.0
  71.     if @rate < 1.0
  72.       @rated = true
  73.       @rate = Graphics.frame_rate.to_f / valor.to_f
  74.     end
  75.   end
  76.  
  77.   def update
  78.     update_time
  79.     update_tone
  80.     update_weather
  81.   end
  82.  
  83.   def update_weather
  84.     @weather = @meses[@mes].type_weather(@dia)
  85.     @time_weather = @meses[@mes].time_weather(@dia)
  86.     @duration_weather = @meses[@mes].duration_weather(@dia)
  87.     @power_weather = @meses[@mes].power_weather(@dia)
  88.     if @total_weather_hora.between?(@time_weather, @time_weather + @duration_weather)
  89.       $game_screen.weather(@weather, @power_weather, rand(40) + 40)
  90.     else
  91.       @total_weather_hora = @hora
  92.       $game_screen.weather(0, 0, rand(40) + 40)
  93.     end
  94.   end
  95.  
  96.   def time_s
  97.     horas = sprintf("%02d:%02d:%02d", @hora, @minuto, @segundo)
  98.     data = sprintf("%02d/%02d/%04d", @dia, @mes, @ano)
  99.     return ("São #{horas} de #{data}")
  100.   end
  101.  
  102.   def time
  103.     return [@ano, @mes, @dia, @hora, @minuto, @segundo]
  104.   end
  105.  
  106.   def ano_duration_sec
  107.     return self.mes_duration_sec * 12
  108.   end
  109.  
  110.   def mes_duration_sec
  111.     return self.dia_duration_sec * 30
  112.   end
  113.  
  114.   def dia_duration_sec
  115.     return 3600 * 24
  116.   end
  117.  
  118.   def hora_duration_sec
  119.     return 3600
  120.   end
  121.  
  122.   def minuto_duration_sec
  123.     return 60
  124.   end
  125.  
  126.   def update_time
  127.     if @rated
  128.       @segundo += @rate
  129.     elsif Graphics.frame_count % @rate == 0
  130.       @segundo += 1
  131.     end
  132.     @total_sec += @rate
  133.     @total_day_sec = (@total_day_sec + @rate) % (3600 * 24)
  134.     premes = @mes
  135.     predia = @dia
  136.     if @segundo >= 60
  137.       @minuto += (@segundo.to_f / 60.0).truncate
  138.       if @minuto >= 60
  139.         @hora += (@minuto.to_f / 60.0).truncate
  140.         @total_weather_hora += (@minuto.to_f / 60.0).truncate
  141.         if @hora >= 24
  142.           @dia += (@hora.to_f / 24.0).truncate
  143.           if @dia >= (@meses[@mes].dias + 1)
  144.             @mes += (@dia.to_f / @meses[@mes].dias.to_f).truncate
  145.             @dia = 1
  146.             if @mes >= @meses.size
  147.               @ano += (@mes.to_f / (@meses.size.to_f - 1.0)).truncate
  148.               @mes = 1
  149.               for ames in @meses
  150.                 next if ames.nil?
  151.                 ames.set_chances
  152.               end              
  153.             end
  154.           end
  155.         end
  156.       end
  157.     end
  158.     @segundo %= 60
  159.     @minuto %= 60
  160.     @hora %= 24
  161.   end
  162.    
  163.   def update_tone
  164.     x = ((@total_day_sec.to_f / 3600.0) - 6) % 24
  165.     y = (Math::PI * x / (12.0)) % Math::PI
  166.     time = 0
  167.     max = -100
  168.     min = 70
  169.     txt = [(x <= 12 ? "max" : "min"), (x <= 12 ? max : min)]
  170.     eval("time = [#{txt[1]} * Math.sin(y) * (x <= 12 ? 2 : 1), #{txt[1]}].#{txt[0]} - 50")
  171.     @tone.set(time, time, time, 0)
  172.   end
  173.  
  174. end
  175.  
  176. RTH.ini_var_add(:gat, "Game_Advanced_Time")
  177. RTH.save_game_puts(:gat)
  178.  
  179. if RTH::MUDA_TOM_TELA
  180.  
  181.   class Scene_Map ; attr_reader :spriteset ; end
  182.    
  183.   class Game_Map
  184.    
  185.     def set_scene_refresh
  186.       if $scene.instance_of?(Scene_Map)
  187.         $scene.spriteset.reset_sprites
  188.       end
  189.     end
  190.    
  191.   end
  192.  
  193.   class Spriteset_Map
  194.  
  195.     def initialize_plant_variables
  196.       @spriteset_gat = Viewport.new(0, 0, 640, 480)
  197.       @spriteset_gat.z = 5001
  198.       @lanternas = []
  199.       @reseted = false
  200.     end
  201.    
  202.     def dispose_plant_variables
  203.       @spriteset_gat.dispose
  204.       for i in @lanternas
  205.         next if i.nil?
  206.         i.bitmap.dispose
  207.         i.dispose
  208.       end
  209.     end
  210.    
  211.     def update_plant_ini
  212.       @spriteset_gat.tone = $gat.tone
  213.     end
  214.    
  215.     def reset_sprites
  216.       for i in 0...@character_sprites.size
  217.         char = @character_sprites[i]
  218.         next if char.nil?
  219.         next if char.character.nil?
  220.         next if char.character == $game_player
  221.         zoom = nil
  222.         if char.character.comment_list.no_case_include?("lantern")
  223.           zoom = char.character.comment_value("intensidade")
  224.           zoom ||= 10.0
  225.           zoom /= 10.0
  226.           if @lanternas[i].nil?
  227.             @lanternas[i] = Sprite.new
  228.             @lanternas[i].bitmap = RPG::Cache.picture("Luz")
  229.             @lanternas[i].z = 1000000
  230.           end
  231.           @lanternas[i].zoom_x = zoom
  232.           @lanternas[i].zoom_y = zoom
  233.           @lanternas[i].ox = (@lanternas[i].bitmap.width / 2)
  234.           @lanternas[i].oy = (@lanternas[i].bitmap.height / 2) + 16
  235.         end
  236.       end
  237.       @reseted = true
  238.     end
  239.    
  240.     def update_plant_final
  241.       reset_sprites if @reseted.false?
  242.       for i in 0...@character_sprites.size
  243.         char = @character_sprites[i]
  244.         next if char.nil?
  245.         next if char.character.nil?
  246.         next if char.character == $game_player
  247.         unless @lanternas[i].nil?
  248.           @lanternas[i].x = char.x
  249.           @lanternas[i].y = char.y
  250.           @lanternas[i].opacity = ($gat.tone.green * 120.0 / -150.0)
  251.         end
  252.       end      
  253.     end
  254.    
  255.   end
  256.  
  257.   RTH.add_method_inside("Game_Map", "refresh", "set_scene_refresh", false, 1)
  258.   RTH.add_method_inside("Spriteset_Map", "initialize", "initialize_plant_variables")
  259.   RTH.add_method_inside("Spriteset_Map", "dispose", "dispose_plant_variables", false, 1)
  260.   RTH.add_method_inside("Spriteset_Map", "update", "update_plant_ini")
  261.   RTH.add_method_inside("Spriteset_Map", "update", "update_plant_final", false, 1)
  262.  
  263. end
  264.  
  265. RTH.add_method_inside("Scene_Map", "update", "$gat.update")
  266.  
  267. class Game_Month
  268.  
  269.   attr_reader :name, :dias
  270.  
  271.   def initialize(name, dias, rain, storm, snow)
  272.     @name = name
  273.     @dias = dias
  274.     @rain = rain
  275.     @storm = storm
  276.     @snow = snow
  277.     set_chances
  278.   end
  279.  
  280.   def set_chances
  281.     @tempo = []
  282.     @rain_days = []
  283.     @storm_days = []
  284.     @snow_days = []
  285.     for i in 1..@dias
  286.       next if set_array_chance(i, 24, @snow, 3, @snow_days)
  287.       next if set_array_chance(i, 24, @storm, 2, @storm_days)
  288.       next if set_array_chance(i, 24, @rain, 1, @rain_days)
  289.     end        
  290.   end
  291.  
  292.   def set_array_chance(i, number, array, tipo, days)
  293.     @tempo[i] = [-1, -1, tipo, 0]
  294.     return false if array == []
  295.     if (rand(100) + 1) < array[0]
  296.       @tempo[i] = [24 % number, ((rand(array[1]) + rand(array[1])) / 2) % number, tipo, rand(10) + 1]
  297.       days.push(i)
  298.       return true
  299.     end
  300.     return false
  301.   end
  302.  
  303.   def time_weather(dia)
  304.     return @tempo[dia][0]
  305.   end
  306.  
  307.   def duration_weather(dia)
  308.     return @tempo[dia][1]
  309.   end
  310.  
  311.   def type_weather(dia)
  312.     return @tempo[dia][2]
  313.   end
  314.  
  315.   def power_weather(dia)
  316.     return @tempo[dia][3]
  317.   end
  318.  
  319. end
  320.  
  321. class Game_Days
  322.  
  323.   attr_reader :name
  324.   attr_reader :id
  325.  
  326.   def initialize(name, id)
  327.     @name = name
  328.     @id = id
  329.   end
  330.  
  331. end
Advertisement
Add Comment
Please, Sign In to add comment