Advertisement
eugene222

TPS Core

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