Yet Another Time System

Rinobi

Veteran
Veteran
Joined
Mar 24, 2014
Messages
578
Reaction score
219
First Language
English
Primarily Uses
RMVXA
Yet Another Time System
by Rinobi

Yet another time system script! There's many to choose from already, and here's another one. It's super easy to use with lots of customization options to fiddle around with.

  • [03/03/2017] 1.00 Public Release
  • [03/08/2017] 1.01 Map Transition Update
  • Crappy UI... it can be disabled.
  • Customizable time scale.
  • Customizable calendar settings.
  • Customizable seasons and weather effects.
  • Lightning flashes and sounds added to storms.
  • Day/Night tinting with automatic tint distribution for smooth transitions
  • Variable settings and script calls to integrate system into game play.
  • Plug & Play. This script functions without any additional hassle
Storm.PNG Time_Window.PNG Variables.PNG
Code:
module RINOBI module TimeSystem # DO NOT MODIFY
#==============================================================================
#                          YET ANOTHER TIME SYSTEM
# -----------------------------------------------------------------------------
# This script adds a totally customizable time and weather system complete with
# day/night cycles, seasonal weather patterns and tilesets, and much more.
# The developer now has complete control over how time flows in their project.
#==============================================================================
# # VERSION HISTORY
# -----------------------------------------------------------------------------
# @ 0.60 [12/23/2015] Finished alpha version.
# @ 0.61 [12/23/2015] Added lightning & thunder effects.
# @ 0.62 [12/23/2015] Time process method reliability update.
# @ 0.63 [12/23/2015] Added time freeze method.
# @ 0.64 [12/25/2015] Updated set_weather method.
# @ 0.69 [05/18/2016] Added Time Display UI
# @ 0.70 [05/21/2016] Updated time_process method.
# @ 1.00 [03/03/2017] Public release.
# @ 1.01 [03/08/2017] Map Transition Update
#==============================================================================
# ** Settings Module
#------------------------------------------------------------------------------
# Adjust the below settings to your liking.
#------------------------------------------------------------------------------

  #============================================================================
  # * Time Variables
  # ---------------------------------------------------------------------------
  # Set variable IDs to keep track of time. Modifying the chosen variables
  # will not influence time passage. Please use script calls for that.
  # Set to false to disable.
  #============================================================================
  Var_Season    = false   # Season number in order listed in Settings Module.
  Var_Year      = false   # The Current Year.
  Var_Month     = false   # Month number in order listed in Settings Module.
  Var_Day       = false   # Day number within month.
  Var_Hour      = false   # The current hour.
  Var_Minute    = false   # The current minute.
  Var_Second    = false   # The current second.
  Var_Season_N  = false   # Current season name.
  Var_Month_N   = false   # Current month name.
  Var_Day_N     = false   # Current day name.
 
  #============================================================================
  # * Time Display Window (Work In Progress)
  # ---------------------------------------------------------------------------
  # A window displaying the current date and season.
  #============================================================================
  Display_Toggle = true    # Set to false to disable display window.
  Display_Key = :L         # See gamepad buttons for reference.
  Toggle_Key = :R          # See gamepad buttons for reference.
  Window_X = 0             # The X position of the display window.
  Window_Y = 0             # The Y position of the display window.
  Toggle_Variable = 99     # Variable used to toggle between window options.
  Display_Switch = 100     # Switch used to troggle time display.
  Date_Display_Width = 276 # Width of date only display window. (does nothing)
  Time_Display_Width = 186 # Width of time only display window. (does nothing)
 
  #============================================================================
  # * Start Date
  # ---------------------------------------------------------------------------
  # The initial date upon beginning a new game.
  #============================================================================
  # Year = Any integer you desire
  # Month = See 'Months' settings below.
  # Day = The day within the current month. See 'Months' settings below.
  # Hour = A number within 'Day_Length' setting below.
  # Minute = A number within 'Hour_Length' setting below.
  # Second = A number within 'Minute_Length' setting below.
  # ---------------------------------------------------------------------------
  Start_Date = {
    :Year => 2015, :Month  => 12, :Day    => 23,
    :Hour =>   19, :Minute => 30, :Second =>  0,
  } # StartDate
 
  Start_Weather = 0 # Default weather upon starting a new game.
 
  #============================================================================
  # * Timescale
  # ---------------------------------------------------------------------------
  # The rate at which time flows.
  #============================================================================
  Time_Scale    = 60 # A speed multiplier for time flow.
 
  Second_Length = 60 # Number of frames in a second.
  Minute_Length = 60 # Number of seconds in a minute.
  Hour_Length   = 60 # Number of minutes in an hour.
  Day_Length    = 23 # Number of hours in a day.
 
  #============================================================================
  # * Battle Time
  # ---------------------------------------------------------------------------
  # Set the passage of time per turn in battle.
  #============================================================================
  # [time_unit, value]
  # ---------------------------------------------------------------------------
  Battle_Time = true # Set to false to disable time passage during battle.
  Time_Per_Turn = ['minute', 10] # year, month, day, hour, minute, second.
 
  #============================================================================
  # * Indoor Settings
  # ---------------------------------------------------------------------------
  # For maps which should be unaffected or affected differently by
  # Day/Night screen tints and weather patterens
  #============================================================================
  # Indoor_Maps = An array of map IDs to be considered indoors.
  # Indoor_Tiles = An array of tileset IDs to be considered indoors.
  # Indoor_Tint = The screen tone used for indoor maps
  # ---------------------------------------------------------------------------
  Indoor_Maps  = [0, 0, 0, 0] # ID, ID, ID, ID
  Indoor_Tiles = [3, 4, 6, 7] # ID, ID, ID, ID
  Indoor_Tint  = [0, 0, 0, 0] # Red, Green, Blue, Grey
 
  #============================================================================
  # * Day/Night Cycle
  # ---------------------------------------------------------------------------
  # Adjust the outdoor tint levels based on a range of hours below. Each hour
  # of the day will be filled in automatically. See example below.
  #-
  # Module Setting Example
  # 1 => {:Tint => [ -75,  -75, 0,  50], :Range => (  5..10)},
  # 2 => {:Tint => [   0,    0, 0,   0], :Range => ( 10..10)},
  #-
  # Hours filled in for smooth transitions automatically
  # Hour 5  [ -75,  -75, 0,  50]
  # Hour 6  [ -60,  -60, 0,  40]
  # Hour 7  [ -45,  -45, 0,  30]
  # Hour 8  [ -30,  -30, 0,  20]
  # Hour 9  [ -15,  -15, 0,  10]
  # Hour 10 [   0,    0, 0,   0]
  #============================================================================
  Tint_Interval = 300 # Number of frames to fade from one tint to the next.
 
  Day_Cycle = { # Add or remove lines as you see fit.
    #     [Red, Green, Blue, Grey]        (Start_Hour..End_Hour)
    1 => {:Tint => [ -75,  -75, 0,  50], :Range => (  5..9)}, # Dawn
    2 => {:Tint => [   0,    0, 0,   0], :Range => ( 9..11)}, # Morning
    3 => {:Tint => [  45,   45, 0,   0], :Range => (11..16)}, # Noon
    4 => {:Tint => [   0,    0, 0,   0], :Range => (16..20)}, # Afternoon
    5 => {:Tint => [ -50,  -50, 0,  25], :Range => (20..22)}, # Evening
    6 => {:Tint => [ -75, -100, 0,  75], :Range => ( 22..0)}, # Night
    7 => {:Tint => [-125, -125, 0, 125], :Range => (  0..5)}, # Midnight
  } # <=== DO NOT REMOVE
 
  #============================================================================
  # * Week Days
  # ---------------------------------------------------------------------------
  # Adjust the length of one week by adding or removing week days.
  # Set the names of each week day and the order in which they appear.
  #============================================================================
  Days = {
    1 => 'Sunday',
    2 => 'Monday',
    3 => 'Tuesday',
    4 => 'Wednesday',
    5 => 'Thursday',
    6 => 'Friday',
    7 => 'Saturday',
  } # Days
 
  #============================================================================
  # * Month Settings
  # ---------------------------------------------------------------------------
  # Adjust the number of months in a year by adding or removing keys. Set the
  # names of each month and the order in which they appear. Set the number of
  # days each month has and the season each month appears within.
  #============================================================================
  # Name = A string containing the name of this month.
  # Days = The number of days within this month.
  # Season = Which season this month is a part of.
  # ---------------------------------------------------------------------------
  Months = {
    1 =>  {:Name => 'January'  , :Days => 31, :Season => 4},
    2 =>  {:Name => 'February' , :Days => 28, :Season => 4},
    3 =>  {:Name => 'March'    , :Days => 31, :Season => 1},
    4 =>  {:Name => 'April'    , :Days => 30, :Season => 1},
    5 =>  {:Name => 'May'      , :Days => 31, :Season => 1},
    6 =>  {:Name => 'June'     , :Days => 30, :Season => 2},
    7 =>  {:Name => 'July'     , :Days => 31, :Season => 2},
    8 =>  {:Name => 'August'   , :Days => 31, :Season => 2},
    9 =>  {:Name => 'September', :Days => 30, :Season => 3},
    10 => {:Name => 'October'  , :Days => 31, :Season => 3},
    11 => {:Name => 'November' , :Days => 30, :Season => 3},
    12 => {:Name => 'December' , :Days => 31, :Season => 4},
  } # Months
 
  #============================================================================
  # * Season Settings
  # ---------------------------------------------------------------------------
  # Adjust the number of seasons avaliable by adding or removing keys. Set the
  # names of each season; the order in which they appear within this hash is
  # unimportant. Set the tileset this season uses and the likelyhood of
  # pre-specified weather patterns to occur.
  #============================================================================
  # Automatically adjust tilesets during seasons?
  # ---------------------------------------------------------------------------
  Use_Tilesets = false # Set to true or false.
 
  # ---------------------------------------------------------------------------
  # IDs of seasonal tilesets. Add all tilesets elgible for change
  # during the seasons here.
  # ---------------------------------------------------------------------------
  Season_Tilesets = [5, 8, 9, 10]
 
  # ---------------------------------------------------------------------------
  # Name = A string containing the name of this season.
  # Tileset = The tileset used while this season is active.
  # Weathers = The type and likelyhood that this weather will affect the
  # outdoor maps. See 'Weather Settings' below.
  # ---------------------------------------------------------------------------
  Seasons = {
    1 => {
    :Name => 'Spring',
    :Tileset =>  9,
    :Weathers => {
      0 => {:Weight => 4}, # Clear       4/17
      1 => {:Weight => 5}, # Light Rain  5/17
      2 => {:Weight => 5}, # Normal Rain 5/17
      3 => {:Weight => 2}, # Heavy Rain  2/17
      4 => {:Weight => 1}, # Storm       1/17
    }}, # Spring
   
    2 => {
    :Name => 'Summer',
    :Tileset =>  5,
    :Weathers => {
      0 => {:Weight => 5}, # Clear       5/15
      1 => {:Weight => 1}, # Light Rain  1/15
      2 => {:Weight => 2}, # Normal Rain 2/15
      3 => {:Weight => 3}, # Heavy Rain  3/15
      4 => {:Weight => 4}, # Storm       4/15
    }}, # Summer
   
    3 => {
    :Name => 'Autumn',
    :Tileset =>  8,
    :Weathers => {
      0 => {:Weight => 5}, # Clear       5/12
      1 => {:Weight => 1}, # Light Rain  1/12
      2 => {:Weight => 1}, # Normal Rain 1/12
      5 => {:Weight => 1}, # Snow        1/12
      6 => {:Weight => 4}, # Windy       4/12
    }}, # Autumn
   
    4 => {
    :Name => 'Winter',
    :Tileset => 10,
    :Weathers => {
      0 => {:Weight => 1}, # Clear       1/10
      1 => {:Weight => 3}, # Light Rain  3/10
      2 => {:Weight => 1}, # Normal Rain 1/10
      5 => {:Weight => 5}, # Snow        5/10
    }}, # Winter
  } # Seasons
 
  #============================================================================
  # * Weather Settings
  # ---------------------------------------------------------------------------
  # Below is the selection of weathers accessible by script call or seasonal
  # weather patterns. Ensure that this hash includes any weathers listed above.
  #============================================================================
  BGS_Indoors    = 60.00   # Percentage to reduce weather sounds while indoors.
 
  Daily_Weather  = 50.00   # Chance per day that weather may change.
  Hourly_Weather = 10.00   # Chance per hour that weather may change.
  Minute_Weather =  1.00   # Chance per minute that weather may change.
  Second_Weather =  0.00   # Chance per second that weather may change.
 
  # ---------------------------------------------------------------------------
  # type = :none, :rain, :storm, :snow
  # power = 1 - 9, or 0 if type is set to :none
  # duration = frames to fade in/out
  # ---------------------------------------------------------------------------
  Weathers = { # Clear, Light Rain, Rain, Heavy Rain, Storm, Snow, Windy
    0 => {:Type => :none,  :Power => 0, :Duration =>   0,
          :Sound => ['',        0,   0],
          }, # Clear Weather / Indoors
    1 => {:Type => :rain,  :Power => 4, :Duration => 600,
          :Sound => ['Rain',   56, 100],
          }, # Light Rain
    2 => {:Type => :rain,  :Power => 9, :Duration => 600,
          :Sound => ['Rain',  100, 100],
          }, # Moderate Rain
    3 => {:Type => :storm, :Power => 7, :Duration => 600,
          :Sound => ['Storm',  70, 100],
          }, # Heavy Rain / Storm
    4 => {:Type => :storm, :Power => 9, :Duration => 600,
          :Sound => ['Storm', 100, 100],
          }, # Thunder Storm
    5 => {:Type => :snow,  :Power => 9, :Duration => 600,
          :Sound => ['',        0,   0],
          }, # Heavy Snow
    6 => {:Type => :none,  :Power => 0, :Duration => 600,
          :Sound => ['Wind',  100, 100],
          }, # Very Windy
  } # Weather
 
  # ---------------------------------------------------------------------------
  # How often lightning strikes occur during storms
  # Lower values increase the frequency of lightning strikes.
  # ---------------------------------------------------------------------------
  Frequency = 10
 
  # ---------------------------------------------------------------------------
  # The color of lightning flashes.
  # [Red, Green, Blue, Opacity, Duration]
  # ---------------------------------------------------------------------------
  Flash_Lightning = [255, 255, 255, 255, 15]
 
  # ---------------------------------------------------------------------------
  # The sound effects played when lightning strikes. The sound is chosen at
  # at random from the list below. Have as many or as few as you like.
  # File   = Sound Effect file name as string.
  # Volume = 0 - 100
  # Pitch  = 0 - 200, 100 is normal.
  # ---------------------------------------------------------------------------
  SE_Thunder = {
    1 => {:File => 'Thunder1', :Volume => 100, :Pitch =>  55},
    2 => {:File => 'Thunder5', :Volume => 100, :Pitch =>  35},
    3 => {:File => 'Thunder7', :Volume => 100, :Pitch =>  55},
    4 => {:File => 'Thunder9', :Volume => 100, :Pitch =>  55},
  } # SE_Thunder
 
#==============================================================================
# # SCRIPT CALLS
# -----------------------------------------------------------------------------
#

#-----------------------------------------------
# >> Basic Information
#-----------------------------------------------
# year       - Get the current year.
# month      - Get the current month. (integer)
# day        - Get the current day. (integer)
# hour       - Get the current hour.
# minute     - Get the current minute.
# second     - Get the current second.
# season     - Get the current season. (integer)
# weather    - Get the current weather.
# time_scale - Get the current time scale value.

#-----------------------------------------------
# >> set_weather(value)
# >> set_weather(value, fast)
#-----------------------------------------------
# @ sets the weather to a value within the module settings below.
# @ setting fast to true changes the weather instantly.

#-----------------------------------------------
# >> set_time(key, value)
#-----------------------------------------------
# @ Sets the current time to a chosen value.
# @ Where key is 'year', 'month', 'day', 'hour', 'minute', 'second'
# @ EX: set_time('month', 11)

#-----------------------------------------------
# >> add_time(key, value)
#-----------------------------------------------
# @ Adds to the current time.
# @ Where key is 'year', 'month', 'day', 'hour', 'minute', 'second'
# @ EX: add_time('hour', 8)

#-----------------------------------------------
# >> get_day_name
# >> get_day_name(day)
# >> get_day_name(day, month)
#-----------------------------------------------
# @ Returns the current or chosen day's name set in module settings below.

#-----------------------------------------------
# >> get_month_name
# >> get_month_name(month_number)
#-----------------------------------------------
# @ Returns the current or chosen month's name set in module settings below.

#-----------------------------------------------
# >> set_time_scale(value)
#-----------------------------------------------
# @ Allows the time scale to be modified in-game. See module settings below.

#-----------------------------------------------
# >> time_freeze
#-----------------------------------------------
# @ Toggles time progression.

#-----------------------------------------------
# >> set_due_date(name, date)
#-----------------------------------------------
# @ Sets a date for later reference.
# @ Where name is any string or symbol and date is an array.
# @ date [year, month, day, hour, minute, second]
# @ EX: set_due_date('rental', year, month, day + 3, 8)

#-----------------------------------------------
# >> add_due_date(name, key, date)
#-----------------------------------------------
# @ Instead of setting a date manually, this method adds to the current time.
# @ name is any string EX: 'dinner party'.
# @ key is :year, :month, :day, :hour, :minute, or :second.
# @ date is an array of numbers.
#
# @ EX: add_due_date('paycheck!', :day, 3, 12)
#   Due date in 3 days and 12 hours.

#-----------------------------------------------
# >> get_due_date(name)
#-----------------------------------------------
# @ Simply returns a date array by name.

#-----------------------------------------------
# >> due_date?(name)
#-----------------------------------------------
# @ Returns true if date has arrived or passed

#-----------------------------------------------
# >> indoors?
#-----------------------------------------------
# @ returns true if the player is inside based on module settings below.

#==============================================================================
# # COMPATIBILITY
# -----------------------------------------------------------------------------
#
# Alias Methods:
#-
#  @ change_weather       in Game_Screen
#  @ initialize           in Game_Map
#  @ setup                in Game_Map
#  @ update_events        in Game_Map
#  @ update_sprite_storm  in Spriteset_Weather
#  @ create_spriteset     in Scene_Map
#  @ update               in Scene_Map
#==============================================================================
# # TERMS OF USE
#------------------------------------------------------------------------------
# 1. Preserve this header.
# 2. Do not re-upload this script.
# 3. Do not claim this script as your own work.
# 4. Do not release modified versions of this script.
# 5. Do not use this script within commercial projects.
#==============================================================================
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # END OF SETTINGS # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#------------------------------------------------------------------------------
#           Editing beyond this point may produce unintended results
#==============================================================================
end end # No Touchie!
#==============================================================================
# ** End of Settings
#------------------------------------------------------------------------------
$imported = {} if $imported.nil?
$imported[:RIN_RUDNWS] = true

#==============================================================================
# ** Game_Screen
#------------------------------------------------------------------------------
#  This class handles screen maintenance data, such as changes in color tone,
# flashes, etc. It's used within the Game_Map and Game_Troop classes.
#==============================================================================
class Game_Screen
  #--------------------------------------------------------------------------
  # * Alias Method: change_weather
  #--------------------------------------------------------------------------
  alias :rinchange_weather :change_weather
  def change_weather(type, power, duration)
    rinchange_weather(type, power, duration)
    if $game_map.indoors?
      dampen = RINOBI::TimeSystem::BGS_Indoors / 100.0
      file = RINOBI::TimeSystem::Weathers[$game_map.weather][:Sound][0]
      volume = RINOBI::TimeSystem::Weathers[$game_map.weather][:Sound][1]
      pitch = RINOBI::TimeSystem::Weathers[$game_map.weather][:Sound][2]
      volume *= dampen ; RPG::BGS.new(file, volume, pitch).play
    else
      file = RINOBI::TimeSystem::Weathers[$game_map.weather][:Sound][0]
      volume = RINOBI::TimeSystem::Weathers[$game_map.weather][:Sound][1]
      pitch = RINOBI::TimeSystem::Weathers[$game_map.weather][:Sound][2]
      RPG::BGS.new(file, volume, pitch).play
    end
  end # change_weather
end # Game_Screen

#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
#  A battler class with methods for sprites and actions added. This class
# is used as a super class of the Game_Actor class and Game_Enemy class.
#==============================================================================
class Game_Battler < Game_BattlerBase
  alias :rinbattle_end :on_battle_end
  def on_battle_end
    return rinbattle_end unless RINOBI::TimeSystem::Battle_Time
    btime = RINOBI::TimeSystem::Time_Per_Turn
    $game_map.add_time(btime[0], $game_troop.turn_count * btime[1])
    rinbattle_end
  end # on_battle_end
end # Game_Battler

#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
#  This class handles maps. It includes scrolling and passage determination
# functions. The instance of this class is referenced by $game_map.
#==============================================================================
class Game_Map
 
  #--------------------------------------------------------------------------
  # * Attributes: year, month, day, hour, minute, calendar
  #--------------------------------------------------------------------------
  attr_accessor :season
  attr_accessor :year
  attr_accessor :month
  attr_accessor :day
  attr_accessor :hour
  attr_accessor :minute
  attr_accessor :second
  attr_accessor :weather
  attr_accessor :calendar
  attr_accessor :dates_hash
  attr_accessor :time_scale
 
  #--------------------------------------------------------------------------
  # * Alias Methods: initialize, update_events, setup
  #--------------------------------------------------------------------------
  alias :time_init :initialize
  alias :time_setup :setup
  alias :time_update_events :update_events
 
  #--------------------------------------------------------------------------
  # * Alias Method: initialize
  #--------------------------------------------------------------------------
  def initialize
    time_init ; @frame = 0
    @time_scale = RINOBI::TimeSystem::Time_Scale
    start_date = RINOBI::TimeSystem::Start_Date
    months     = RINOBI::TimeSystem::Months
    days       = RINOBI::TimeSystem::Days
    @weather   = RINOBI::TimeSystem::Start_Weather
    @year   = start_date[:Year]
    @month  = start_date[:Month]
    @day    = start_date[:Day]
    @hour   = start_date[:Hour]
    @minute = start_date[:Minute]
    @second = start_date[:Second]
    @season = months[@month][:Season]
    @week   = days.count
    @time_freeze = false
    @dates_hash = Hash.new
    generate_calendar
  end # initialize
 
  #--------------------------------------------------------------------------
  # * Alias Method: setup
  #--------------------------------------------------------------------------
  def setup(map_id)
    time_setup(map_id) ; light_cycle
    set_weather(@weather, true)
    return if indoors?
    return unless RINOBI::TimeSystem::Use_Tilesets
    return unless RINOBI::TimeSystem::Season_Tilesets.include?(@tileset_id)
    change_tileset(RINOBI::TimeSystem::Seasons[season][:Tileset])
  end # setup
 
  #--------------------------------------------------------------------------
  # * New Method: Generate Calendar
  #--------------------------------------------------------------------------
  def generate_calendar
    days = RINOBI::TimeSystem::Days
    @calendar = Hash.new ; m_start = 0, m_end = 0 ; month = 1 ; count = 0
    while month <= RINOBI::TimeSystem::Months.count
      cmonth = month
      while cmonth > 0
        m_end += RINOBI::TimeSystem::Months[cmonth][:Days]
        cmonth -= 1
      end # cmonth > 0
      m_start = (1 + m_end) - RINOBI::TimeSystem::Months[month][:Days]
      @calendar[month] = Hash[(m_start..m_end).map {|n|[n, days[count]]}]
      @calendar[month].count.times do |s|
        count = 0 unless count < @week
        count += 1 ; @calendar[month][s+1] = RINOBI::TimeSystem::Days[count]
      end # @calendar[month]count.times do |s|
      month += 1 ; m_end = 0
    end # month <= RINOBI::TimeSystem::Months.count
  end
 
  #--------------------------------------------------------------------------
  # * New Methods: year, month, day, hour, minute, calendar
  #--------------------------------------------------------------------------
  define_method(:year)   {@year}
  define_method(:month)  {@month}
  define_method(:day)    {@day}
  define_method(:hour)   {@hour}
  define_method(:minute) {@minute}
  define_method(:second) {@second}
  define_method(:weather) {@weather}
  define_method(:calendar) {@calendar}
  define_method(:total_days) {@total_days}
  define_method(:time_scale) {@time_scale}
  define_method(:season) {@season = RINOBI::TimeSystem::Months[month][:Season]}
 
  #--------------------------------------------------------------------------
  # * New Method: distribute
  #--------------------------------------------------------------------------
  def distribute(begin_value, end_value, array_size, return_ints = false)
    diff = 1.0 * (end_value - begin_value)
    n = [array_size-1, 1].max
    (0..(array_size-1)).map do |i|
      v = begin_value + i * diff / n
      return_ints ? v.round : v
    end
  end # distribute
 
  #--------------------------------------------------------------------------
  # * New Method: time_process
  #--------------------------------------------------------------------------
  def time_process
    until @frame < RINOBI::TimeSystem::Second_Length
      @frame -= RINOBI::TimeSystem::Second_Length
      add_time("second", 1)
      auto_weather if rand(100.0) < RINOBI::TimeSystem::Second_Weather
    end #- Frames to Seconds
    until second < RINOBI::TimeSystem::Minute_Length
      @second -= RINOBI::TimeSystem::Minute_Length
      add_time("minute", 1)
      auto_weather if rand(100.0) < RINOBI::TimeSystem::Minute_Weather
    end #- Seconds to Minutes
    until minute < RINOBI::TimeSystem::Hour_Length
      @minute -= RINOBI::TimeSystem::Hour_Length
      add_time("hour", 1) ; light_cycle
      auto_weather if rand(100.0) < RINOBI::TimeSystem::Hourly_Weather
    end #- Minutes to Hours
    until hour < RINOBI::TimeSystem::Day_Length
      @hour -= RINOBI::TimeSystem::Day_Length
      add_time("day", 1)
      auto_weather if rand(100.0) < RINOBI::TimeSystem::Daily_Weather
    end #- Hours to Days
    until day <= RINOBI::TimeSystem::Months[month][:Days]
      @day -= RINOBI::TimeSystem::Months[month][:Days]
      add_time("month", 1)
      until month <= RINOBI::TimeSystem::Months.count
        @month -= RINOBI::TimeSystem::Months.count
        add_time("year", 1)
      end #- Months to Years
    end #- Days to Months
    until month <= RINOBI::TimeSystem::Months.count
      @month -= RINOBI::TimeSystem::Months.count
      add_time("year", 1)
    end #- Months to Years
    update_variables
  end # time_process
 
  #--------------------------------------------------------------------------
  # * New Method: update_variables
  #--------------------------------------------------------------------------
  def update_variables
    ts = RINOBI::TimeSystem
    $game_variables[ts::Var_Season]   = season if ts::Var_Season
    $game_variables[ts::Var_Year]     = year if ts::Var_Year
    $game_variables[ts::Var_Month]    = month if ts::Var_Month
    $game_variables[ts::Var_Day]      = day if ts::Var_Day
    $game_variables[ts::Var_Hour]     = hour if ts::Var_Hour
    $game_variables[ts::Var_Minute]   = minute if ts::Var_Minute
    $game_variables[ts::Var_Second]   = second if ts::Var_Second
    $game_variables[ts::Var_Season_N] = get_season_name if ts::Var_Season_N
    $game_variables[ts::Var_Month_N]  = get_month_name if ts::Var_Month_N
    $game_variables[ts::Var_Day_N]    = get_day_name if ts::Var_Day_N
  end
 
  #--------------------------------------------------------------------------
  # * New Method: light_cycle
  #--------------------------------------------------------------------------
  def light_cycle
    range = RINOBI::TimeSystem::Day_Cycle
    range.count.times do |r|
      if range[r+1][:Range].include?(hour)
        return tint_level(r+1)
      end
    end
  end # light_cycle
 
  #--------------------------------------------------------------------------
  # * New Method: tint_level
  #--------------------------------------------------------------------------
  def tint_level(value)
    cycle = RINOBI::TimeSystem::Day_Cycle
    it = RINOBI::TimeSystem::Indoor_Tint
    if indoors?
      return @screen.start_tone_change(Tone.new(it[0],it[1],it[2],it[3]),0)
    end
    tint1 = RINOBI::TimeSystem::Day_Cycle[value][:Tint]
    if value == cycle.count then tint2 = RINOBI::TimeSystem::Day_Cycle[1][:Tint]
    else tint2 = RINOBI::TimeSystem::Day_Cycle[value+1][:Tint] end
    range = RINOBI::TimeSystem::Day_Cycle[value][:Range].to_a
    t = []
    t << distribute(tint1[0], tint2[0], range.count, true)
    t << distribute(tint1[1], tint2[1], range.count, true)
    t << distribute(tint1[2], tint2[2], range.count, true)
    t << distribute(tint1[3], tint2[3], range.count, true)
    r = range.index(hour)
    i = RINOBI::TimeSystem::Tint_Interval
    i = 0 if $game_player.transferring
    screen.start_tone_change(Tone.new(t[0][r],t[1][r],t[2][r],t[3][r]),i)
  end # tint_level
 
  #--------------------------------------------------------------------------
  # * New Method: auto_weather
  #--------------------------------------------------------------------------
  def auto_weather
    weather = []
    RINOBI::TimeSystem::Seasons[season][:Weathers].keys.each do |s|
      RINOBI::TimeSystem::Seasons[season][:Weathers][s][:Weight].times do
        index = RINOBI::TimeSystem::Seasons[season][:Weathers].keys.index(s)
        weather << RINOBI::TimeSystem::Seasons[season][:Weathers].keys[index]
      end #---
    end #--
    set_weather(weather.sample)
  end # auto_weather
 
  #--------------------------------------------------------------------------
  # * New Method: calculate_date
  #--------------------------------------------------------------------------
  def calculate_date(value)
    ts = RINOBI::TimeSystem
    ts_current_month = ts::Months[month][:Days]
    until value[5] < ts::Second_Length
      value[5] -= ts::Second_Length
      value[4] += 1
    end
    until value[4] < ts::Minute_Length
      value[4] -= ts::Minute_Length
      value[3] += 1
    end
    until value[3] < ts::Hour_Length
      value[3] -= ts::Hour_Length
      value[2] += 1
    end
    until value[2] < ts::Day_Length
      value[2] -= ts::Day_Length
      value[1] += 1
    end
    until value[1] < ts_current_month
      value[1] -= ts_current_month
      value[0] += 1
    end
    return value
  end
 
  #--------------------------------------------------------------------------
  # * New Method: set_weather
  #--------------------------------------------------------------------------
  def set_weather(value, fast = false)
    @weather = value
    if indoors?
      type = RINOBI::TimeSystem::Weathers[0][:Type]
      power = RINOBI::TimeSystem::Weathers[0][:Power]
      duration = RINOBI::TimeSystem::Weathers[0][:Duration]
      screen.change_weather(type, power, duration)
    else
      type = RINOBI::TimeSystem::Weathers[value][:Type]
      power = RINOBI::TimeSystem::Weathers[value][:Power]
      if fast then duration = 0
      else duration = RINOBI::TimeSystem::Weathers[value][:Duration] end
      screen.change_weather(type, power, duration)
    end
  end # set_weather
 
  #--------------------------------------------------------------------------
  # * New Method: set_time
  #--------------------------------------------------------------------------
  def set_time(key, value)
    return unless instance_variable_defined?(("@" + key).intern)
    instance_variable_set(("@" + key).intern, value)
  end # set_time
 
  #--------------------------------------------------------------------------
  # * New Method: add_time
  #--------------------------------------------------------------------------
  def add_time(key, value)
    return unless instance_variable_defined?(("@" + key).intern)
    current = instance_variable_get(("@" + key).intern)
    instance_variable_set(("@" + key).intern, current + value)
  end # add_time
 
  #--------------------------------------------------------------------------
  # * New Method: get_time
  #--------------------------------------------------------------------------
  def get_time(key)
    return unless instance_variable_defined?(("@" + key).intern)
    return instance_variable_get(("@" + key).intern)
  end # get_time
 
  #--------------------------------------------------------------------------
  # * New Method: get week day
  #--------------------------------------------------------------------------
  def get_day_name(day = @day, month = @month)
    calendar[month][day]
  end # get_week_day
 
  #--------------------------------------------------------------------------
  # * New Method: get_month_name
  #--------------------------------------------------------------------------
  def get_month_name(month = @month)
    RINOBI::TimeSystem::Months[month][:Name]
  end # get_month_name
 
  #--------------------------------------------------------------------------
  # * New Method: get_season_name (necessary?)
  #--------------------------------------------------------------------------
  def get_season_name
    seasons = RINOBI::TimeSystem::Seasons ; months = RINOBI::TimeSystem::Months
    return seasons[months[get_time('month')][:Season]][:Name]
  end # get_season
 
  #--------------------------------------------------------------------------
  # * New Method: set_due_date
  # >> year, month, day, hour, minute, second
  # >> set_due_date('dinner', year, month, day, 20, 30)
  #--------------------------------------------------------------------------
  def set_due_date(name, *date)
    @dates_hash[name] = date
  end
 
  #--------------------------------------------------------------------------
  # * New Method: add_due_date
  # >> Adjusts date automatically
  # >> add_due_date('holliday', :months, 2, 10)
  #--------------------------------------------------------------------------
  def add_due_date(name, key, *value)
    case key
    when :months  then value.insert(0, 0)
    when :days    then value.insert(0, 0, 0) ; print value
    when :hours   then value.insert(0, 0, 0, 0)
    when :minutes then value.insert(0, 0, 0, 0, 0)
    when :seconds then value.insert(0, 0, 0, 0, 0, 0)
    end
    value.push(0) until value.size > 6
    set_due_date(name, calculate_date(value))
  end
 
  #--------------------------------------------------------------------------
  # * New Method: get_due_date
  # >> year, month, day, hour, minute, second
  #--------------------------------------------------------------------------
  def get_due_date(name)
    @dates_hash[name]
  end
 
  #--------------------------------------------------------------------------
  # * New Method: due_date (testing)
  #--------------------------------------------------------------------------
  def due_date?(name)
    return unless @dates_hash
    array = @dates_hash[name]
    return true if year > array[0]
    return true if year   == array[0] && month  > array[1]
    return true if month  == array[1] && day    > array[2]
    return true if day    == array[2] && hour   > array[3]
    return true if hour   == array[3] && minute > array[4]
    return true if minute == array[4] && second > array[5]
    return false
  end # due_date?
 
  #--------------------------------------------------------------------------
  # * New Method: freeze_time
  #--------------------------------------------------------------------------
  def time_freeze
    @time_freeze ? @time_freeze = false : @time_freeze = true
  end # freeze_time
 
  #--------------------------------------------------------------------------
  # * New Method: time_frozen?
  #--------------------------------------------------------------------------
  def time_frozen?
    return @time_freeze
  end # time_frozen?
 
  #--------------------------------------------------------------------------
  # * New Method: indoors?
  #--------------------------------------------------------------------------
  def indoors?
    return true if RINOBI::TimeSystem::Indoor_Maps.include?(map_id)
    return true if RINOBI::TimeSystem::Indoor_Tiles.include?(tileset.id)
    return false
  end # indoors?
 
  #--------------------------------------------------------------------------
  # * Alias Method: update_events
  #--------------------------------------------------------------------------
  def update_events
    time_update_events
    @frame += time_scale unless time_frozen?
    time_process
  end
end # Game_Map

#==============================================================================
# ** Game_Player
#------------------------------------------------------------------------------
#  This class handles the player. It includes event starting determinants and
# map scrolling functions. The instance of this class is referenced by
# $game_player.
#==============================================================================
class Game_Player < Game_Character
  attr_reader :transferring
end # Game_Player

#==============================================================================
# ** Game_Interpreter
#------------------------------------------------------------------------------
#  An interpreter for executing event commands. This class is used within the
# Game_Map, Game_Troop, and Game_Event classes.
#==============================================================================
class Game_Interpreter
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader     :year
  attr_reader     :month
  attr_reader     :day
  attr_reader     :hour
  attr_reader     :minute
  attr_reader     :second
  attr_reader     :season
  attr_reader     :weather
  attr_reader     :time_scale
  #--------------------------------------------------------------------------
  # * Simple Methods
  #--------------------------------------------------------------------------
  define_method(:year)        {$game_map.year      }
  define_method(:month)       {$game_map.month     }
  define_method(:day)         {$game_map.day       }
  define_method(:hour)        {$game_map.hour      }
  define_method(:minute)      {$game_map.minute    }
  define_method(:second)      {$game_map.second    }
  define_method(:season)      {$game_map.season    }
  define_method(:weather)     {$game_map.weather   }
  define_method(:time_scale)  {$game_map.time_scale}
  #--------------------------------------------------------------------------
  # * Set Weather
  #--------------------------------------------------------------------------
  def set_weather(value, fast = false)
    $game_map.set_weather(value, fast)
  end
  #--------------------------------------------------------------------------
  # * Set Time
  #--------------------------------------------------------------------------
  def set_time(key, value)
    $game_map.set_time(key, value)
  end
  #--------------------------------------------------------------------------
  # * Add Time
  #--------------------------------------------------------------------------
  def add_time(key, value)
    $game_map.add_time(key, value)
  end
  #--------------------------------------------------------------------------
  # * Get Time
  #--------------------------------------------------------------------------
  def get_time(key)
    $game_map.get_time(key)
  end
  #--------------------------------------------------------------------------
  # * Get Day Name
  #--------------------------------------------------------------------------
  def get_day_name(day = $game_map.day, month = $game_map.month)
    $game_map.get_day_name(day, month)
  end
  #--------------------------------------------------------------------------
  # * Get Month Name
  #--------------------------------------------------------------------------
  def get_month_name(month = @month)
    RINOBI::TimeSystem::Months[month][:Name]
  end
  #--------------------------------------------------------------------------
  # * Set Time Scale
  #--------------------------------------------------------------------------
  def set_time_scale(value)
    $game_map.time_scale = value
  end
  #--------------------------------------------------------------------------
  # * Time Freeze
  #--------------------------------------------------------------------------
  def time_freeze
    if $game_map.time_frozen?
      $game_map.time_freeze = false
    else
      $game_map.time_freeze = true
    end
  end
  #--------------------------------------------------------------------------
  # * Set Due Date
  #--------------------------------------------------------------------------
  def set_due_date(name, *date)
    $game_map.set_due_date(name, *date)
  end
 
  #--------------------------------------------------------------------------
  # * Add Due Date
  #--------------------------------------------------------------------------
  def add_due_date(name, key, *value)
    $game_map.add_due_date(name, key, *value)
  end
 
  #--------------------------------------------------------------------------
  # * Get Due Date
  #--------------------------------------------------------------------------
  def get_due_date(name)
    $game_map.get_due_date(name)
  end
  #--------------------------------------------------------------------------
  # * Check Due Date
  #--------------------------------------------------------------------------
  def due_date?(name)
    $game_map.due_date?(name)
  end
  #--------------------------------------------------------------------------
  # * Indoors?
  #--------------------------------------------------------------------------
  def indoors?
    $game_map.indoors?
  end
end

#==============================================================================
# ** Spriteset_Weather
#------------------------------------------------------------------------------
#  A class for weather effects (rain, storm, and snow). It is used within the
# Spriteset_Map class.
#==============================================================================
class Spriteset_Weather
  #--------------------------------------------------------------------------
  # * Alias Method: Update Sprite [Storm]
  #--------------------------------------------------------------------------
  alias :time_update_storm :update_sprite_storm
  def update_sprite_storm(sprite)
    time_update_storm(sprite)
    return unless rand((RINOBI::TimeSystem::Frequency * 10000.0) / @power) < 1
    total = RINOBI::TimeSystem::SE_Thunder.count
    selection = 1 + rand(total - 1)
    red     = RINOBI::TimeSystem::Flash_Lightning[0]
    green   = RINOBI::TimeSystem::Flash_Lightning[1]
    blue    = RINOBI::TimeSystem::Flash_Lightning[2]
    opacity = RINOBI::TimeSystem::Flash_Lightning[3]
    frames  = RINOBI::TimeSystem::Flash_Lightning[4]
    file   = RINOBI::TimeSystem::SE_Thunder[selection][:File]
    volume = RINOBI::TimeSystem::SE_Thunder[selection][:Volume]
    pitch  = RINOBI::TimeSystem::SE_Thunder[selection][:Pitch]
    $game_map.screen.start_flash(Color.new(red,green,blue,opacity),frames)
    RPG::SE.new(file, volume, pitch).play
  end # update_sprite_storm
end # Spriteset_Weather

#==============================================================================
# ** Class: Time Window Option 1
#==============================================================================
class Time_Window1 < Window_Base
  #--------------------------------------------------------------------------
  # * New Method: Initialize
  #--------------------------------------------------------------------------
  def initialize
    window_x = RINOBI::TimeSystem::Window_X
    window_y = RINOBI::TimeSystem::Window_Y
    super(window_x, window_y, window_width, fitting_height(2))
    self.openness = 255
    self.opacity = 255
    refresh
  end # initialize
  #--------------------------------------------------------------------------
  # * New Method: Window Width
  #--------------------------------------------------------------------------
  def window_width
    return 276
  end # window_width
  #--------------------------------------------------------------------------
  # * New Method: Refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    change_color(text_color(0))
    season = $game_map.get_season_name
    year = $game_map.get_time('year')
    month_integer = $game_map.get_time('month')
    month_string = RINOBI::TimeSystem::Months[$game_map.get_time('month')][:Name]
    day_integer = $game_map.get_time('day')
    day_string = $game_map.calendar[month_integer][day_integer]
    hour = $game_map.get_time('hour')
    minute = sprintf("%02d", $game_map.get_time('minute'))
    apm = '' ; if hour > 11 then apm = 'PM' else apm = 'AM' end
    if hour < 1  then hour += 12 end ; if hour > 12 then hour -= 12 end
    hour = sprintf("%02d", hour)
    line1 = "#{month_string} #{day_integer}, #{year}[#{season}]"
    line2 = "#{day_string}, #{hour}:#{minute}#{apm}"
    draw_text(0, 0, contents.width, line_height, line1)
    draw_text(0, 0, contents.width, fitting_height(2), line2)
  end # refresh
end # Time_Window1 < Window_Base

#==============================================================================
# ** Class: Time Window Option 2
#==============================================================================
class Time_Window2 < Window_Base
  #--------------------------------------------------------------------------
  # * New Method: Initialize
  #--------------------------------------------------------------------------
  def initialize
    window_x = RINOBI::TimeSystem::Window_X
    window_y = RINOBI::TimeSystem::Window_Y
    super(window_x, window_y, window_width, fitting_height(1))
    self.openness = 255
    self.opacity = 255
    refresh
  end # initialize
  #--------------------------------------------------------------------------
  # * New Method: Window Width
  #--------------------------------------------------------------------------
  def window_width
    return 186
  end # window_width
  #--------------------------------------------------------------------------
  # * New Method: Refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    change_color(text_color(0))
    month_integer = $game_map.get_time('month')
    day_integer = $game_map.get_time('day')
    day_string = $game_map.calendar[month_integer][day_integer]
    hour = $game_map.get_time('hour')
    minute = sprintf("%02d", $game_map.get_time('minute'))
    apm = '' ; if hour > 11 then apm = 'PM' else apm = 'AM' end
    if hour < 1  then hour += 12 end ; if hour > 12 then hour -= 12 end
    hour = sprintf("%02d", hour)
    line1 = "#{day_string}, #{hour}:#{minute}#{apm}"
    draw_text(0, 0, contents.width, line_height, line1)
  end # refresh
end # Time_Window2 < Window_Base

#==============================================================================
# ** Class: Time Window Option 3
#==============================================================================
class Time_Window3 < Window_Base
  #--------------------------------------------------------------------------
  # * New Method: Initialize
  #--------------------------------------------------------------------------
  def initialize
    window_x = RINOBI::TimeSystem::Window_X
    window_y = RINOBI::TimeSystem::Window_Y
    super(window_x, window_y, window_width, fitting_height(1))
    self.openness = 255
    self.opacity = 255
    refresh
  end # initialize
  #--------------------------------------------------------------------------
  # * New Method: Window Width
  #--------------------------------------------------------------------------
  def window_width
    return 276
  end # window_width
  #--------------------------------------------------------------------------
  # * New Method: Refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    change_color(text_color(0))
    season = $game_map.get_season_name
    year = $game_map.get_time('year')
    month_integer = $game_map.get_time('month')
    month_string = RINOBI::TimeSystem::Months[$game_map.get_time('month')][:Name]
    day_integer = $game_map.get_time('day')
    line1 = "#{month_string} #{day_integer}, #{year}[#{season}]"
    draw_text(0, 0, contents.width, line_height, line1)
  end # refresh
end # Time_Window3 < Window_Base

#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs the map screen processing.
#==============================================================================
class Scene_Map < Scene_Base
  #--------------------------------------------------------------------------
  # * Alias Method: Create Spriteset
  #--------------------------------------------------------------------------
  alias :time_spriteset :create_spriteset
  def create_spriteset
    time_spriteset
    create_time_hud if RINOBI::TimeSystem::Display_Toggle
  end # create_spriteset
  #--------------------------------------------------------------------------
  # * New Method: Create Intial HUD Display
  #--------------------------------------------------------------------------
  def create_time_hud
    @time_hud = Time_Window1.new
    $game_switches[RINOBI::TimeSystem::Display_Switch] = true
  end # create_time_hud
  #--------------------------------------------------------------------------
  # * New Method: Toggle Time HUD Display
  #--------------------------------------------------------------------------
  def time_hud_toggle
    if Input.trigger?(RINOBI::TimeSystem::Display_Key)
      $game_switches[RINOBI::TimeSystem::Display_Switch] ^= true
    end
  end # time_hud_toggle
  #--------------------------------------------------------------------------
  # * New Method: Toggle Time Type Display
  #--------------------------------------------------------------------------
  def time_type_toggle
    if Input.trigger?(RINOBI::TimeSystem::Toggle_Key)
      $game_variables[RINOBI::TimeSystem::Toggle_Variable] += 1
      if $game_variables[RINOBI::TimeSystem::Toggle_Variable] > 2
        $game_variables[RINOBI::TimeSystem::Toggle_Variable] = 0
      end
      adjust_time_window
    end
  end # time_type_toggle
  #--------------------------------------------------------------------------
  # * New Method: Adjust Time Window
  #--------------------------------------------------------------------------
  def adjust_time_window
    case $game_variables[RINOBI::TimeSystem::Toggle_Variable]
    when 0 then @time_hud = Time_Window1.new
    when 1 then @time_hud = Time_Window2.new
    when 2 then @time_hud = Time_Window3.new
    end
    @time_hud.refresh
  end # adjust_time_window
  #--------------------------------------------------------------------------
  # * New Method: Close Time Window
  #--------------------------------------------------------------------------
  def close_time_window
    return if $game_switches[RINOBI::TimeSystem::Display_Switch]
    @time_hud.close
  end # close_time_window
  #--------------------------------------------------------------------------
  # * New Method: Open Time Window
  #--------------------------------------------------------------------------
  def open_time_window
    return unless $game_switches[RINOBI::TimeSystem::Display_Switch]
    @time_hud.open
  end # open_time_window
  #--------------------------------------------------------------------------
  # * Alias Method: Update
  #--------------------------------------------------------------------------
  alias :time_hud_update :update
  def update
    time_hud_update
    return unless RINOBI::TimeSystem::Display_Toggle
    time_hud_toggle
    time_type_toggle
    close_time_window
    open_time_window
    return unless @track != $game_map.minute
    @time_hud.refresh
    @track = $game_map.minute
  end # update
end # Scene_Map < Scene_Base
  • Redesign UI. It was originally designed for testing.
  • Update calendar generation. It's a mess.
  • Create calendar display. The data is there already.
  • Design a demo making use of script calls.
 

Attachments

Last edited:

ddanny023

Warper
Member
Joined
Mar 13, 2017
Messages
1
Reaction score
0
First Language
Español
Primarily Uses
RMVXA
How do i use it?
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

How do you cure sleep problem? It has been 7 months and it's 3 AM now..
Darn you, Seals! Why do you gotta be so cute when on land?:kaoluv:
So dragonbones getting laggy xD
I even removed the fingers armatures.

Have to remake this guy after crashing ( corrupted file).
:rtear:

Although limited to only this shop for room decorations, I like this aspect for previewing items.

Forum statistics

Threads
100,837
Messages
980,130
Members
132,487
Latest member
AnthonyDewitt
Top