Advertisement
luiscesjr

Core

Jul 18th, 2014
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 41.13 KB | None | 0 0
  1. #===============================================================================
  2. # ***Time and Period System***
  3. #
  4. # Author:     eugene222 (Evgenij)
  5. # Version:    1.2
  6. # Date:       18.05.2014
  7. # Requires:   ---
  8. #===============================================================================
  9. # Changelog:
  10. #
  11. #   03.04.2014 - V. 1.0-alpha1 - script created
  12. #   05.04.2014 - V. 1.0        - fixed some bugs, added new Script Calls
  13. #   06.04.2014 - V. 1.0a       - Game_Time now updates in Scene_*.update_basic
  14. #   09.04.2014 - V. 1.1              - refactored the code
  15. #   18.05.2014 - V. 1.2        - Days, Months and Years added
  16. #
  17. #===============================================================================
  18. # Terms of Use:
  19. #   You can use this script for free and commercial projects as long as you give
  20. #   credits.
  21. #===============================================================================
  22. # Description:
  23. #   This script adds a time system to your game.
  24. #
  25. #   It doesnt add, windows, tints or other features. For other features use the
  26. #   addons.
  27. #  
  28. #   Released Addons:
  29. #     - Tints for Periods
  30. #     - Period PopUp
  31. #     - Clock Window
  32. #     - Phases and Weather
  33. #    
  34. #   Planed:
  35. #
  36. #     - Khas Awesome Light Support
  37. #    
  38. #
  39. #===============================================================================
  40. # ScriptCalls:
  41. #  
  42. #  Since V. 1.2:
  43. #
  44. #-------------------------------------------------------------------------------
  45. #
  46. # IMPORTANT: the calls jump_to_date, set_day, set_month and set year dont change
  47. #            the weekday. If its thursday the 3rd and you change the day to
  48. #            the 10th it stays thursday.
  49. #            I will try to fix it in the future.
  50. #
  51. #-------------------------------------------------------------------------------
  52. #   $game_time.current_day          # Current Day (as number)
  53. #
  54. #-------------------------------------------------------------------------------
  55. #   $game_time.current_day_vocab    # Current Day Vocab
  56. #
  57. #-------------------------------------------------------------------------------
  58. #   $game_time.current_week_day     # Weekday as number
  59. #
  60. #-------------------------------------------------------------------------------
  61. #   # Short Vocab of current day:
  62. #       $game_time.current_day_vocab_short
  63. #
  64. #-------------------------------------------------------------------------------
  65. #   $game_time.current_month        # Current month as number
  66. #
  67. #-------------------------------------------------------------------------------
  68. #   $game_time.current_month_vocab  # Current month vocab
  69. #
  70. #-------------------------------------------------------------------------------
  71. #   # Short vocab of current month:
  72. #       $game_time.current_month_vocab_short
  73. #
  74. #-------------------------------------------------------------------------------
  75. #
  76. #   # Set the date: (period ist optional)
  77. #       $game_time.jump_to_date(year, month, day [, period])
  78. #
  79. #-------------------------------------------------------------------------------
  80. #   $game_time.set_day(day)     # Set day in current month
  81. #
  82. #-------------------------------------------------------------------------------
  83. #   $game_time.set_month(month) # Set month in current year
  84. #
  85. #-------------------------------------------------------------------------------
  86. #   $game_time.set_year(year)   # Set year
  87. #
  88. #-------------------------------------------------------------------------------
  89. #   $game_time.add_day(a)       # increase days
  90. #
  91. #-------------------------------------------------------------------------------
  92. #   $game_time.reduce_day(a)    # decrease days
  93. #
  94. #-------------------------------------------------------------------------------
  95. #   $game_time.add_month(a)     # increase month
  96. #
  97. #-------------------------------------------------------------------------------
  98. #   $game_time.reduce_month(a)  # decrease month
  99. #
  100. #-------------------------------------------------------------------------------
  101. #   $game_time.add_year(a)      # increase years
  102. #
  103. #-------------------------------------------------------------------------------
  104. #   $game_time.reduce_year(a)   # decrease years
  105. #
  106. #-------------------------------------------------------------------------------
  107. #
  108. #   ---------- Old Scriptcalls: ----------
  109. #
  110. #   $game_time.period_text      # return current period vocab
  111. #   $game_time.hour             # return current hour
  112. #   $game_time.minute           # return current minute
  113. #
  114. #   $game_time.stop_time        # stop timeflow
  115. #   $game_time.resume_time      # resume timeflow with default speed
  116. #
  117. #   $game_time.jump_to(:p)      # time jumps to period :p    
  118. #   $game_time.set_time(t)      # change time to (0 - 1439)
  119. #   &game_time.add_time(n)      # increase minutes
  120. #   $game_time.reduce_time(n)   # decrease minutes
  121. #  
  122. #   &game_time.set_speed(s)     # set time speed to s. If s is high, the speed is low
  123. #
  124. #   $game_time.full_speed       # set time speed to fastest
  125. #   $game_time.double_speed     # double time speed
  126. #   $game_time.half_speed       # half time speed
  127. #   $game_time.default_speed    # set time speed to default
  128. #
  129. #--------------------------------------------------------------------------------
  130. #
  131. #   You can set indoor maps
  132. #   You need to write <indoor> at your indoor maps notetags.
  133. #  
  134. #   Returns true if current map is indoor:
  135. #
  136. #     $game_map.indoor?          
  137. #                              
  138. #--------------------------------------------------------------------------------
  139. #
  140. #   Return true if one of the arguments is the current period
  141. #
  142. #     $game_time.period_is?(:period1, :period2, ... )
  143. #
  144. #--------------------------------------------------------------------------------
  145. #
  146. #   Returns true if one of the arguments is NOT the current period
  147. #
  148. #     $game_time.period_is_not?(:period1, period2, ... )
  149. #
  150. #--------------------------------------------------------------------------------
  151. #
  152. #   Return true if the current time is between start_time and end_time
  153. #  
  154. #     $game_time.time_now_between?(start_time, end_time)
  155. #
  156. #--------------------------------------------------------------------------------
  157. #
  158. #   Return true if the current time is NOT between start_time and end_time
  159. #  
  160. #     $game_time.time_now_not_between?(start_time, end_time)
  161. #
  162. #===============================================================================
  163. module TPS_CONFIG
  164.  
  165.   #-----------------------------------------------------------------------------
  166.   # DEFAULT SPEED (60 Frames = 1 Second)
  167.   #-----------------------------------------------------------------------------
  168.   FRAME_COUNT = 60
  169.    
  170.   #-----------------------------------------------------------------------------
  171.   # DEFAULT START TIME (0 - 1439)
  172.   #-----------------------------------------------------------------------------
  173.   START_TIME = 360    # New Game starts at 6 O'Clock
  174.  
  175.   #-----------------------------------------------------------------------------
  176.   # Start Year
  177.   #-----------------------------------------------------------------------------
  178.   START_YEAR = 1
  179.  
  180.   #-----------------------------------------------------------------------------
  181.   # HOW MANY DAYS SHOULD A MONTH HAVE?
  182.   #-----------------------------------------------------------------------------
  183.   DAYS_IN_MONTH = 31
  184.  
  185.   #-----------------------------------------------------------------------------
  186.   # SHOULD THE TIME UPDATE IN BATTLE?
  187.   #-----------------------------------------------------------------------------
  188.   UPDATE_IN_BATTLE = true
  189.    
  190.   #-----------------------------------------------------------------------------
  191.   # SHOULD THE TIME UPDATE IN MENU
  192.   #  - I highly recommend false
  193.   #-----------------------------------------------------------------------------
  194.   UPDATE_IN_MENU = false
  195.  
  196.   #-----------------------------------------------------------------------------
  197.   # SHOULD THE TIME UPDATE IN INDOOR MAPS?
  198.   #-----------------------------------------------------------------------------
  199.   UPDATE_INDOOR = true
  200.  
  201.   #-----------------------------------------------------------------------------
  202.   # SHOULD THE TIME UPDATE DURING MESSAGE WINDOWS?
  203.   #  - I highly recommend keeping this false
  204.   #-----------------------------------------------------------------------------
  205.   UPDATE_DURING_MESSAGE = false
  206.      
  207.   #-----------------------------------------------------------------------------
  208.   # SAVES CURRENT TIME IN THE VARIABLE WITH THIS ID
  209.   #  Set to false if you dont want to use this
  210.   #-----------------------------------------------------------------------------
  211.   TIME_VARIABlE_ID = 12   # number or false
  212.  
  213.   #-----------------------------------------------------------------------------
  214.   # SAVES CURRENT DAY IN THIS VARIABLE
  215.   #-----------------------------------------------------------------------------
  216.   DAY_VARIABLE_ID = false
  217.  
  218.   #-----------------------------------------------------------------------------
  219.   # SAVES CURRENT MONTH IN THIS VARIABLE
  220.   #-----------------------------------------------------------------------------                
  221.   MONTH_VARIABLE_ID = false
  222.  
  223.   #-----------------------------------------------------------------------------
  224.   # SAVES CURRENT YEAR IN THIS VARIABLE
  225.   #-----------------------------------------------------------------------------
  226.   YEAR_VARIABLE_ID = false
  227.  
  228.   #-----------------------------------------------------------------------------
  229.   PERIOD_TIMES = { # Diese Zeile nicht verändern
  230.   #-----------------------------------------------------------------------------
  231.   # START TIMES FOR THE PERIODS
  232.   #
  233.   # KEEP THE ORDER FROM LOWEST TIME TO HIGHEST TIME
  234.   # YOU CAN ADD AS MANY PERIODS AS YOU WISH, YOU JUST NEED TO ADD THEM TO ALL
  235.   # ADDONS, AND VOCAB HASHES
  236.   #
  237.   # PERIODS STARTS WITH DOUBlEPOINTS:   :period
  238.   #-----------------------------------------------------------------------------
  239.   # !!!!KEEP THE ORDER FROM LOWEST TIME TO HIGHEST TIME!!!!
  240.   #-----------------------------------------------------------------------------
  241.     #---------------------------------------------------------------------------
  242.     # 0 = 0 AM, 360 = 6 AM, 720 = 0 PM etc.
  243.     #---------------------------------------------------------------------------
  244.     :morning    => 360,     # ab  6 Uhr (360)
  245.     :forenoon   => 600,     # ab 10 Uhr (600)
  246.     :noon       => 720,     # ab 12 Uhr (720)
  247.     :afternoon  => 780,     # ab 13 Uhr (780)
  248.     :evening    => 1020,    # ab 17 Uhr (1020)
  249.     :night      => 1320,    # ab 22 Uhr (1320)
  250.        
  251.   #-----------------------------------------------------------------------------
  252.   }# Diese Zeile nicht verändern!
  253.   #-----------------------------------------------------------------------------
  254.   # DO YOU WANT TO USE SWITCHES FOR THE PERIODS?
  255.   #-----------------------------------------------------------------------------
  256.  
  257.   USE_SWITCHES = true
  258.  
  259.   #-----------------------------------------------------------------------------
  260.   # DEFINE SWITCH IDS FOR THE PERIODS
  261.   #-----------------------------------------------------------------------------
  262.   PERIOD_SWITCH_IDs = { # Diese Zeile nicht verändern!
  263.   #-----------------------------------------------------------------------------
  264.  
  265.     :morning    => 1,    
  266.     :forenoon   => 2,    
  267.     :noon       => 3,    
  268.     :afternoon  => 4,    
  269.     :evening    => 5,  
  270.     :night      => 6    
  271.      
  272.   #-----------------------------------------------------------------------------
  273.   }# Diese Zeile nicht verändern!
  274.   #-----------------------------------------------------------------------------
  275.   # VOCAB FOR THE PERIODS
  276.   #-----------------------------------------------------------------------------
  277.   PERIOD_VOCABS = {
  278.    
  279.     :morning    => "Manhã Cedo",    
  280.     :forenoon   => "Manhã",    
  281.     :noon       => "Meio dia",    
  282.     :afternoon  => "Tarde",    
  283.     :evening    => "Noite",  
  284.     :night      => "Noite Tarde",
  285.      
  286.   #-----------------------------------------------------------------------------    
  287.   }# Diese Zeile nicht verändern!
  288.   #-----------------------------------------------------------------------------
  289.   # HERE YOU NEED TO DEFINE THE MONTH. THE SIZE DOESNT MATTER.
  290.   #
  291.   # OTHER EXAMPLE (LIKE Harvest Moon):
  292.   #   MONTHS = ["Frühling", "Sommer", "Herbst", "Winter"]
  293.   #-----------------------------------------------------------------------------
  294.  
  295.   MONTHS = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho",
  296.             "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"]
  297.            
  298.   MONTHS_SHORT = ["Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago",
  299.                   "Set", "Out", "Nov", "Dez"]
  300.  
  301.   #-----------------------------------------------------------------------------
  302.   # HERE YOU NEED TO DEFINE THE WEEKDAYS
  303.   #-----------------------------------------------------------------------------
  304.   DAYS   = ["Segunda", "Terça",  "Quarta",  "Quinta", "Sexta",
  305.             "Sábado", "Domingo" ]
  306.  
  307.   DAYS_SHORT = ["Seg.", "Ter.", "Qua.", "Qui.", "Sex.", "Sab.", "Dom."]
  308.  
  309.   #-----------------------------------------------------------------------------
  310.   # CONFIG END
  311.   #-----------------------------------------------------------------------------
  312.  
  313.   #-----------------------------------------------------------------------------
  314.   # IGNORE THIS
  315.   #
  316.   # Fürs Debugging:
  317.   # Optionen:
  318.   #   false     - no Debugging
  319.   #   :day      -
  320.   #   :month    -
  321.   #   :year     -
  322.   #-----------------------------------------------------------------------------
  323.   DEBUG_TICKS = false
  324.  
  325.   #-----------------------------------------------------------------------------
  326. end
  327. #===============================================================================
  328. # END OF CONFIG
  329. #===============================================================================
  330. $imported ||= {}
  331. $imported[:e222_tps_core] = 1.2
  332. #===============================================================================
  333. # Data_Manager
  334. #===============================================================================
  335. module DataManager
  336.   #--------------------------------------------------------------------------
  337.   # alias
  338.   #--------------------------------------------------------------------------
  339.   class << self
  340.     alias game_time_cgo    create_game_objects
  341.     alias game_time_msc    make_save_contents
  342.     alias game_time_esc    extract_save_contents
  343.   end
  344.   #--------------------------------------------------------------------------
  345.   # * Create Game Objects
  346.   #--------------------------------------------------------------------------
  347.   def self.create_game_objects
  348.     game_time_cgo
  349.     $game_time = Game_Time.new
  350.   end
  351.   #--------------------------------------------------------------------------
  352.   # * Create Save Contents
  353.   #--------------------------------------------------------------------------
  354.   def self.make_save_contents
  355.     contents = game_time_msc
  356.     contents[:time] = $game_time
  357.     contents
  358.   end
  359.   #--------------------------------------------------------------------------
  360.   # * Extract Save Contents
  361.   #--------------------------------------------------------------------------
  362.   def self.extract_save_contents(contents)
  363.     game_time_esc(contents)
  364.     $game_time = contents[:time] if contents[:time]
  365.     $game_time.reinitialize
  366.   end
  367.   #--------------------------------------------------------------------------
  368. end
  369. #===============================================================================
  370. # New Class Game_Time, handles the time processing
  371. #===============================================================================
  372. class Game_Time
  373.   #-----------------------------------------------------------------------------
  374.   include TPS_CONFIG
  375.   #-----------------------------------------------------------------------------
  376.   attr_reader     :current_time
  377.   attr_reader     :current_period
  378.   attr_reader     :current_day
  379.   attr_reader     :current_month
  380.   attr_reader     :current_year
  381.   attr_reader     :time_progress
  382.   attr_accessor   :time_progress_for_transfer
  383.   #-----------------------------------------------------------------------------
  384.   # initialize all values
  385.   #-----------------------------------------------------------------------------
  386.   def initialize
  387.     reinitialize
  388.   end
  389.   #-----------------------------------------------------------------------------
  390.   # Reinitialize
  391.   #-----------------------------------------------------------------------------
  392.   def reinitialize
  393.     @time_progress                  = true  if @time_progress.nil?
  394.     @time_progress_for_transfer = true  if @time_progress_for_transfer.nil?
  395.     @current_time               ||= start_time
  396.     @time_speed                 ||= time_speed
  397.     @current_day                ||= 0
  398.     @week_day                   ||= 0
  399.     @current_month              ||= 0
  400.     @current_year               ||= START_YEAR
  401.     @year_counter               ||= 1
  402.     make_cache
  403.   end
  404.   #-----------------------------------------------------------------------------
  405.   # Make Cache
  406.   #-----------------------------------------------------------------------------
  407.   def make_cache
  408.     setup_period_hash
  409.   end
  410.   #-----------------------------------------------------------------------------
  411.   # Start Time
  412.   #-----------------------------------------------------------------------------
  413.   def start_time
  414.     return 0 unless (0..1439).include?(START_TIME)
  415.     START_TIME
  416.   end
  417.   #-----------------------------------------------------------------------------
  418.   # Time Speed
  419.   #-----------------------------------------------------------------------------
  420.   def time_speed
  421.     return FRAME_COUNT
  422.   end
  423.   #-----------------------------------------------------------------------------
  424.   # Setup Period Hash
  425.   #   1. Hole die Keys aus PERIOD_TIMES (.keys)
  426.   #   2. Kopiere den letzten Key an die erste Stelle im Array (.unshift)
  427.   #   3. Mache ein Enumerator aus den Zeiten (.each_cons(2))
  428.   #     3.1. Füge den Enumerator mit dem Key Array zusammen (.zip)
  429.   #          Bsp: [:night, [0, 360]]
  430.   #   4. Iteriere durch das Array und mache ein Hash daraus (.each_with_object)
  431.   #
  432.   #   Der Hash sieht am Ende so aus:
  433.   #   [0 => :night, 1 => :night, ..., 378 => :morning, ...]
  434.   #
  435.   #   Das ganze ermöglicht einen schnellen Zugriff auf die momentane Periode
  436.   #   abhängig von der Zeit.
  437.   #-----------------------------------------------------------------------------
  438.   def setup_period_hash
  439.     @period_hash = PERIOD_TIMES.
  440.                     keys.
  441.                       unshift(PERIOD_TIMES.keys.last).  
  442.                         zip([0, * PERIOD_TIMES.values, 1440,].each_cons(2)).
  443.                           each_with_object({}) do |(period, (from, to)), hash|
  444.                             (from..to).each do |time|
  445.                               hash[time] = period
  446.                             end  
  447.                           end
  448.   end
  449.   #-----------------------------------------------------------------------------
  450.   # Update Method
  451.   #-----------------------------------------------------------------------------
  452.   def update
  453.     return unless need_update?
  454.     if (Graphics.frame_count % @time_speed).zero?
  455.       case DEBUG_TICKS
  456.       when false
  457.         next_minute
  458.       when :day
  459.         next_day
  460.       when :month
  461.         next_month
  462.       when :year
  463.         next_year
  464.       end
  465.       update_period
  466.     end
  467.   end
  468.   #-----------------------------------------------------------------------------
  469.   # Initialize Period
  470.   #-----------------------------------------------------------------------------
  471.   def initialize_period
  472.     @current_period = return_period(@current_time)
  473.     refresh_period_switches
  474.   end
  475.   #-----------------------------------------------------------------------------
  476.   # Update Period
  477.   #-----------------------------------------------------------------------------
  478.   def update_period
  479.     return unless period_need_update?
  480.     @current_period = return_period(@current_time)
  481.     refresh_period
  482.   end
  483.   #-----------------------------------------------------------------------------
  484.   # Refresh Period
  485.   #-----------------------------------------------------------------------------
  486.   def refresh_period
  487.     refresh_period_switches
  488.   end
  489.   #-----------------------------------------------------------------------------
  490.   # Next Minute
  491.   #-----------------------------------------------------------------------------
  492.   def next_minute
  493.     @current_time += 1
  494.     next_day if @current_time > 1439
  495.     refresh_time_variable
  496.   end
  497.   #-----------------------------------------------------------------------------
  498.   # Next Day
  499.   #-----------------------------------------------------------------------------
  500.   def next_day
  501.     @current_time = 0
  502.     @current_day += 1
  503.     @week_day = (@week_day + 1) % days_in_week
  504.     next_month if @current_day >= days_in_month#
  505.     update_day_variable
  506.   end
  507.   #-----------------------------------------------------------------------------
  508.   # Next Month
  509.   #-----------------------------------------------------------------------------
  510.   def next_month
  511.     @current_day = 0
  512.     @current_month += 1
  513.     next_year if @current_month >= months_in_year
  514.   end
  515.   #-----------------------------------------------------------------------------
  516.   # Next Year
  517.   #-----------------------------------------------------------------------------
  518.   def next_year
  519.     @current_month = 0
  520.     @current_year += 1
  521.     @year_counter += 1
  522.   end
  523.   #-----------------------------------------------------------------------------
  524.   #  Refresh Time Variable
  525.   #-----------------------------------------------------------------------------
  526.   def refresh_time_variable
  527.     return unless TIME_VARIABlE_ID
  528.     $game_variables[TIME_VARIABlE_ID] = @current_time
  529.   end
  530.   #-----------------------------------------------------------------------------
  531.   # Refresh Period Switches
  532.   #-----------------------------------------------------------------------------
  533.   def refresh_period_switches
  534.     return unless USE_SWITCHES
  535.     PERIOD_SWITCH_IDs.each_value { |id| $game_switches[id] = false }
  536.     $game_switches[PERIOD_SWITCH_IDs[@current_period]] = true
  537.   end
  538.   #-----------------------------------------------------------------------------
  539.   #  Return Period
  540.   #-----------------------------------------------------------------------------
  541.   def return_period(time)
  542.     @period_hash[time]
  543.   end
  544.   #-----------------------------------------------------------------------------
  545.   #  Days in Week
  546.   #-----------------------------------------------------------------------------
  547.   def days_in_week
  548.     DAYS.size
  549.   end
  550.   #-----------------------------------------------------------------------------
  551.   #  Days in Month
  552.   #-----------------------------------------------------------------------------
  553.   def days_in_month
  554.     return days_in_week if DAYS_IN_MONTH < days_in_week
  555.     DAYS_IN_MONTH
  556.   end
  557.   #-----------------------------------------------------------------------------
  558.   #  Months in Year
  559.   #-----------------------------------------------------------------------------
  560.   def months_in_year
  561.     MONTHS.size
  562.   end
  563.   #-----------------------------------------------------------------------------
  564.   #  Update Day Variable
  565.   #-----------------------------------------------------------------------------
  566.   def update_day_variable
  567.     return unless DAY_VARIABLE_ID
  568.     $game_variables[DAY_VARIABLE_ID] = current_day
  569.   end
  570.   #-----------------------------------------------------------------------------
  571.   #  Update Month Variable
  572.   #-----------------------------------------------------------------------------
  573.   def update_month_variable
  574.     return unless MONTH_VARIABLE_ID
  575.     $game_variables[MONTH_VARIABLE_ID] = current_month
  576.   end
  577.   #-----------------------------------------------------------------------------
  578.   #  Update Year Variable
  579.   #-----------------------------------------------------------------------------
  580.   def update_year_variable
  581.     return unless YEAR_VARIABLE_ID
  582.     $game_variables[MONTH_VARIABLE_ID] = @current_year
  583.   end
  584. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  585. # Boolean Methods:
  586. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  587.  
  588.   #-----------------------------------------------------------------------------
  589.   # Time Need Update?
  590.   #-----------------------------------------------------------------------------
  591.   def need_update?
  592.     return false unless @time_progress
  593.     return false unless @time_progress_for_transfer
  594.     return false if     $game_message.visible && !UPDATE_DURING_MESSAGE
  595.     return false if     $game_map.indoor? && !UPDATE_INDOOR
  596.     return true
  597.   end
  598.   #-----------------------------------------------------------------------------
  599.   # Period Need Update?
  600.   #-----------------------------------------------------------------------------
  601.   def period_need_update?
  602.     @current_period != return_period(@current_time)
  603.   end
  604. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  605. # Period and Time Changing Script Calls:
  606. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  607.  
  608.   #-----------------------------------------------------------------------------
  609.   # Jump to Period
  610.   #-----------------------------------------------------------------------------
  611.   def jump_to(period)
  612.     set_time(PERIOD_TIMES[period])
  613.   end
  614.   #-----------------------------------------------------------------------------
  615.   # Jump to Date
  616.   #-----------------------------------------------------------------------------
  617.   def jump_to_date(year, month = 0, day = 0, period = nil)
  618.     set_year(year)
  619.     set_month(month)
  620.     set_day(day)
  621.     jump_to(period || return_period(0))
  622.   end
  623.   #-----------------------------------------------------------------------------
  624.   # Set Time
  625.   #-----------------------------------------------------------------------------
  626.   def set_time(time)
  627.     return unless (0..1439).include?(time)
  628.     @current_time = time
  629.     refresh_time_variable
  630.     update_period
  631.   end
  632.   #-----------------------------------------------------------------------------
  633.   # Set Day
  634.   #-----------------------------------------------------------------------------
  635.   def set_day(day)
  636.     return unless (0..days_in_month).include?(day - 1)
  637.     @current_day = day - 1
  638.     update_day_variable
  639.   end
  640.   #-----------------------------------------------------------------------------
  641.   # Set Month
  642.   #-----------------------------------------------------------------------------
  643.   def set_month(month)
  644.     return unless (0..months_in_year).include?(month - 1)
  645.     @current_month = month - 1
  646.     update_month_variable
  647.   end
  648.   #-----------------------------------------------------------------------------
  649.   # Set Year
  650.   #-----------------------------------------------------------------------------
  651.   def set_year(year)
  652.     @current_year = year
  653.     update_year_variable
  654.   end
  655.   #-----------------------------------------------------------------------------
  656.   #  Add Time
  657.   #-----------------------------------------------------------------------------
  658.   def add_time(amount)
  659.     change_time(amount.abs)
  660.   end
  661.   #-----------------------------------------------------------------------------
  662.   # Reduce Time
  663.   #-----------------------------------------------------------------------------
  664.   def reduce_time(amount)
  665.     change_time(amount.abs * (-1))
  666.   end
  667.   #-----------------------------------------------------------------------------
  668.   # Add Day
  669.   #-----------------------------------------------------------------------------
  670.   def add_day(amount)
  671.     change_day(amount.abs)
  672.   end
  673.   #-----------------------------------------------------------------------------
  674.   # Reduce Day
  675.   #-----------------------------------------------------------------------------
  676.   def reduce_day(amount)
  677.     change_day(amount.abs * (-1))
  678.   end
  679.   #-----------------------------------------------------------------------------
  680.   # Add Month
  681.   #-----------------------------------------------------------------------------
  682.   def add_month(amount)
  683.     change_month(amount.abs)
  684.   end
  685.   #-----------------------------------------------------------------------------
  686.   # Reduce Month
  687.   #-----------------------------------------------------------------------------
  688.   def reduce_month(amount)
  689.     change_month(amount.abs * (-1))
  690.   end
  691.   #-----------------------------------------------------------------------------
  692.   # Add Year
  693.   #-----------------------------------------------------------------------------
  694.   def add_year(amount)
  695.     change_year(amount.abs)
  696.   end
  697.   #-----------------------------------------------------------------------------
  698.   # Reduce Year
  699.   #-----------------------------------------------------------------------------
  700.   def reduce_year(amount)
  701.     change_year(amount.abs * (-1))
  702.   end
  703.   #-----------------------------------------------------------------------------
  704.   # Change Time
  705.   #-----------------------------------------------------------------------------
  706.   def change_time(amount)
  707.     change_day((@current_time + amount) / 1440)
  708.     @current_time = (@current_time + amount) % 1440
  709.     refresh_time_variable
  710.   end
  711.   #-----------------------------------------------------------------------------
  712.   # Change Day
  713.   #-----------------------------------------------------------------------------
  714.   def change_day(amount)
  715.     change_month((@current_day + amount) / days_in_month)
  716.     @current_day = (@current_day + amount) % days_in_month
  717.     @week_day = (@week_day + amount) % days_in_week
  718.     update_day_variable
  719.   end
  720.   #-----------------------------------------------------------------------------
  721.   # Change Month
  722.   #-----------------------------------------------------------------------------
  723.   def change_month(amount)
  724.     change_year((@current_month + amount) / months_in_year)
  725.     @current_month = (@current_month + amount) % months_in_year
  726.     update_month_variable
  727.   end
  728.   #-----------------------------------------------------------------------------
  729.   # Change Year
  730.   #-----------------------------------------------------------------------------
  731.   def change_year(amount)
  732.     @current_year = [(@current_year + amount), 0].max
  733.     update_period
  734.     update_year_variable
  735.   end
  736.   #-----------------------------------------------------------------------------
  737.   # Stop Time
  738.   #-----------------------------------------------------------------------------
  739.   def stop_time
  740.     @time_progress = false
  741.   end
  742.   #-----------------------------------------------------------------------------
  743.   # Resume Time
  744.   #-----------------------------------------------------------------------------
  745.   def resume_time
  746.     @time_progress = true
  747.     @time_progress_for_transfer = true
  748.   end
  749. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  750. # Speed Changing Script Calls:
  751. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  752.   #-----------------------------------------------------------------------------
  753.   #  Full Speed
  754.   #-----------------------------------------------------------------------------
  755.   def full_speed
  756.     @time_speed = 1
  757.   end
  758.   #-----------------------------------------------------------------------------
  759.   #  Double Speed
  760.   #-----------------------------------------------------------------------------
  761.   def double_speed
  762.     @time_speed /= 2
  763.     @time_speed = 1 if @time_speed < 1
  764.   end
  765.   #-----------------------------------------------------------------------------
  766.   #  Half Speed
  767.   #-----------------------------------------------------------------------------
  768.   def half_speed
  769.     @time_speed *= 2
  770.   end
  771.   #-----------------------------------------------------------------------------
  772.   # Default Speed
  773.   #-----------------------------------------------------------------------------
  774.   def default_speed
  775.     @time_speed = time_speed
  776.     resume_time
  777.   end
  778. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  779. # Boolean Returning Script Calls:
  780. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-  
  781.  
  782.   #-----------------------------------------------------------------------------
  783.   #  Current Period Is One Of Periods?
  784.   #-----------------------------------------------------------------------------
  785.   def period_is?(*periods)
  786.     periods.any? { |period| @current_period == period }
  787.   end
  788.   #-----------------------------------------------------------------------------
  789.   #  Current Period Is None Of Periods?
  790.   #-----------------------------------------------------------------------------
  791.   def period_is_not?(*periods)
  792.     !period_is?(*periods)
  793.   end
  794.   #-----------------------------------------------------------------------------
  795.   #  Time-Now between Start Time and End Time?
  796.   #-----------------------------------------------------------------------------
  797.   def time_now_between?(start_time, end_time)
  798.     (start_time..end_time).include?(@current_time)
  799.   end
  800.   #-----------------------------------------------------------------------------
  801.   #  Time-Now not between Start Time and End Time?
  802.   #-----------------------------------------------------------------------------
  803.   def time_now_not_between?(start_time, end_time)
  804.     !time_now_between?(start_time, end_time)
  805.   end
  806. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  807. # Text or Value Returning Script Calls:
  808. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  809.  
  810.   #-----------------------------------------------------------------------------
  811.   #  Current Day
  812.   #-----------------------------------------------------------------------------
  813.   def current_day
  814.     return @current_day + 1
  815.   end
  816.   #-----------------------------------------------------------------------------
  817.   #  Current Month
  818.   #-----------------------------------------------------------------------------
  819.   def current_month
  820.     return @current_month + 1
  821.   end
  822.   #-----------------------------------------------------------------------------
  823.   #  Current Year
  824.   #-----------------------------------------------------------------------------
  825.   def current_year
  826.     return @current_year
  827.   end
  828.   #-----------------------------------------------------------------------------
  829.   #  Current Month Vocab Short
  830.   #-----------------------------------------------------------------------------
  831.   def current_month_vocab
  832.     return MONTHS[@current_month]
  833.   end
  834.   #-----------------------------------------------------------------------------
  835.   #  Current Month Vocab Short
  836.   #-----------------------------------------------------------------------------
  837.   def current_month_vocab_short
  838.     return MONTHS[@current_month]
  839.   end
  840.   #-----------------------------------------------------------------------------
  841.   #  Current Day Vocab
  842.   #-----------------------------------------------------------------------------
  843.   def current_day_vocab
  844.     return DAYS[@week_day]
  845.   end
  846.   #-----------------------------------------------------------------------------
  847.   #  Current Day Vocab Short
  848.   #-----------------------------------------------------------------------------
  849.   def current_day_vocab_short
  850.     return DAYS_SHORT[@week_day]
  851.   end
  852.   #-----------------------------------------------------------------------------
  853.   # Period Name
  854.   #-----------------------------------------------------------------------------
  855.   def period_text
  856.     return PERIOD_VOCABS[@current_period]
  857.   end
  858.   #-----------------------------------------------------------------------------
  859.   # Hour
  860.   #-----------------------------------------------------------------------------
  861.   def hour
  862.     @current_time / 60
  863.   end
  864.   #-----------------------------------------------------------------------------
  865.   # Minute
  866.   #-----------------------------------------------------------------------------
  867.   def minute
  868.     @current_time % 60
  869.   end
  870.   #-----------------------------------------------------------------------------
  871.   # Current Weather
  872.   #-----------------------------------------------------------------------------
  873.   def current_weather
  874.     screen_weather
  875.   end
  876.   #-----------------------------------------------------------------------------
  877.   # Screen Weather
  878.   #-----------------------------------------------------------------------------
  879.   def screen_weather
  880.     $game_map.screen.weather_type
  881.   end
  882.   #-----------------------------------------------------------------------------
  883. end # //Game_Time
  884. #===============================================================================
  885. # Game_Map
  886. #   new_methods: indoor?
  887. #===============================================================================
  888. class Game_Map
  889.   #-----------------------------------------------------------------------------
  890.   # return if the current map notetag include <indoor>
  891.   #-----------------------------------------------------------------------------
  892.   def indoor?
  893.     return false if $BTEST
  894.     return false unless @map
  895.     @map.note.include?("<indoor>")
  896.   end
  897.   #-----------------------------------------------------------------------------
  898. end
  899. #===============================================================================
  900. # Scene_Base
  901. #   aliased_methods: update
  902. #===============================================================================
  903. class Scene_Base
  904.   #-----------------------------------------------------------------------------
  905.   # Update Basic
  906.   #-----------------------------------------------------------------------------
  907.   alias :scene_base_update_basic_e222             :update_basic
  908.   #-----------------------------------------------------------------------------
  909.   def update_basic
  910.     scene_base_update_basic_e222
  911.     update_gametime
  912.   end
  913.   #-----------------------------------------------------------------------------
  914.   # Update Game Time
  915.   #-----------------------------------------------------------------------------
  916.   def update_gametime
  917.     return
  918.   end
  919.   #-----------------------------------------------------------------------------
  920. end
  921. #===============================================================================
  922. # Scene_Map
  923. #   aliased_methods: start, pre_transfer, post_transfer
  924. #===============================================================================
  925. class Scene_Map
  926.   #-----------------------------------------------------------------------------
  927.   # Start
  928.   #-----------------------------------------------------------------------------
  929.   alias :scene_map_start_e222               :start
  930.   #-----------------------------------------------------------------------------
  931.   def start
  932.     scene_map_start_e222
  933.     $game_time.initialize_period
  934.   end
  935.   #--------------------------------------------------------------------------
  936.   # * Preprocessing for Transferring Player
  937.   #--------------------------------------------------------------------------
  938.   alias :scene_map_pre_transfer_e222       :pre_transfer
  939.   def pre_transfer
  940.     scene_map_pre_transfer_e222
  941.     $game_time.time_progress_for_transfer = false
  942.   end
  943.   #-----------------------------------------------------------------------------
  944.   # Post Transfer
  945.   #-----------------------------------------------------------------------------
  946.   alias :scene_map_post_transfer_e222       :post_transfer
  947.   #-----------------------------------------------------------------------------
  948.   def post_transfer
  949.     $game_time.initialize_period
  950.     scene_map_post_transfer_e222
  951.     $game_time.time_progress_for_transfer = true if $game_time.time_progress
  952.   end
  953.   #-----------------------------------------------------------------------------
  954.   # Update Game Time
  955.   #-----------------------------------------------------------------------------
  956.   def update_gametime
  957.     $game_time.update
  958.   end
  959. end
  960. #===============================================================================
  961. # Scene_MenuBase
  962. #===============================================================================
  963. class Scene_MenuBase
  964.   #-----------------------------------------------------------------------------
  965.   # Update Game Time
  966.   #-----------------------------------------------------------------------------
  967.   def update_gametime
  968.     $game_time.update if TPS_CONFIG::UPDATE_IN_MENU
  969.   end  
  970. end
  971. #===============================================================================
  972. # Scene_Battle
  973. #   aliased_methods: start
  974. #===============================================================================
  975. class Scene_Battle
  976.   #-----------------------------------------------------------------------------
  977.   # Start
  978.   #-----------------------------------------------------------------------------
  979.   alias :scene_battle_start_e222      :start
  980.   #-----------------------------------------------------------------------------
  981.   def start
  982.     scene_battle_start_e222
  983.     $game_time.initialize_period if $BTEST
  984.   end
  985.   #-----------------------------------------------------------------------------
  986.   # Update Game Time
  987.   #-----------------------------------------------------------------------------
  988.   def update_gametime
  989.     $game_time.update if TPS_CONFIG::UPDATE_IN_BATTLE
  990.   end
  991.  #------------------------------------------------------------------------------
  992. end
  993. #===============================================================================
  994. # SCRIPT END
  995. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement