Project1

标题: 日期与时间脚本 [打印本页]

作者: creeper0924    时间: 2015-8-27 18:36
标题: 日期与时间脚本
本帖最后由 creeper0924 于 2015-8-30 13:35 编辑

RUBY 代码复制
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  2. # 进阶版时间与天气系统
  3. # 黑暗骑士◎汉化修改
  4. # 版本号  : 1.02
  5. # 制作日期: 20.3.2015
  6. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  7. #
  8. # 脚本冲突率:
  9. # 经测试,本脚本与99%的其他脚本能够兼容!但是修改了资料,存档就不可以再用了。
  10. # 这点请注意。
  11. #
  12. # 特性:
  13. #
  14. #   - 容易操纵和控制时间以及天气
  15. #   - 可定制的日夜的色调
  16. #   - 可选HUD时钟
  17. #   - 更容易控制、比DDNS更强大
  18. #
  19. # 使用说明:
  20. #     ATES.on
  21. #   Turns ATES on.
  22. #
  23. #     ATES.off
  24. #   Turns ATES off.
  25. #
  26. #     ATES.tint_on
  27. #   Turns ATES's screen tinting on.
  28. #
  29. #     ATES.tint_off
  30. #   Turns ATES's screen tinting off.
  31. #
  32. #     ATES.clock_on
  33. #   Turns ATES's clock display on.
  34. #
  35. #     ATES.clock_off
  36. #   Turns ATES's clock display off.
  37. #
  38. #     ATES.active?
  39. #   Returns true if ATES is turned on, otherwise false.
  40. #
  41. #     ATES.tinting?
  42. #   Returns true if ATES tinting is turned on, otherwise false.
  43. #
  44. #     ATES.day?
  45. #   Returns true if it's day, otherwise false. Alternatively you can check the
  46. #   assigned switch instead.
  47. #
  48. #     ATES.night?
  49. #   Returns true if it's night, otherwise false. Alternatively you can check
  50. #   the assigned switch instead.
  51. #   
  52. #     ATES.advance(MINUTE, HOUR, DAY, MONTH, YEAR)
  53. #   This will make the time advanced by the specified values.
  54. #   
  55. #     ATES.make_it_day
  56. #   This is a feature from DDNS which allows you to quickly jump to the
  57. #   daytime.
  58. #   
  59. #     ATES.make_it_night
  60. #   This is a feature from DDNS which allows you to quickly jump to the
  61. #   nighttime.
  62. #   
  63. #     ATES.weather_on
  64. #   This allows you to turn on the weather system.
  65. #
  66. #     ATES.weather_off
  67. #   This allows you to turn off the weather system.
  68. #
  69. #     ATES.lock_weather
  70. #   This allows you to lock the current weather in place without disabling the
  71. #   weather system entirely.
  72. #
  73. #     ATES.unlock_weather
  74. #   This command unlocks the current weather.
  75. #
  76. #     ATES.weather_active?
  77. #   Returns true if the weather system is turned on, otherwise false.
  78. #
  79. #     ATES.set_time(TIME_INDEX or TIME_NAME)
  80. #   Sets the current time to the time at the index of TIME_INDEX or with the
  81. #   name of TIME_NAME. Its better to use TIME_NAME because some bugs may occur
  82. #   from using TIME_INDEX.
  83. #
  84. #     ATES.go_inside
  85. #   A feature from the DDNS which allows you to change the lighting mode to
  86. #   inside.
  87. #
  88. #     ATES.go_inside_dark
  89. #   A feature from the DDNS which allows you to change the lighting mode to
  90. #   inside dark.
  91. #
  92. #     ATES.go_outside
  93. #   A feature from the DDNS which allows you to change the lighting mode to
  94. #   outside.
  95. #
  96. #     ATES.set_weather(INDEX)
  97. #   Sets the current weather to the weather at index INDEX.
  98. #
  99. #     ATES.terrain=(TERRAIN_NAME)
  100. #   Sets the terrain to the terrain named TERRAIN_NAME.
  101. #
  102. #     ATES.time_name
  103. #   Returns the name of the current time of day.
  104. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  105.  
  106. module ATES
  107.  
  108. #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  109. # START Configuration
  110. #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  111.   # switch ID of the "day" switch
  112.   DSWITCH = 51
  113.   # switch ID of the "night" switch
  114.   NSWITCH = 52
  115.   # variable ID of the temperature
  116.   TVARIABLE = 51
  117.   # length of a day in seconds in-game, can't be less than 36, is being
  118.   # quantized into intervals of 36 seconds
  119.   LENGTH = 144
  120.   # the amount to multiply weather sound by when inside
  121.   INSIDE_SOUND = 0.7
  122.   # the amount to multiply tone red, green, blue and gray by when inside
  123.   INSIDE_TONE = 0.0
  124.   # the tone for dark interiors
  125.   DARK_INSIDE_TONE = Tone.new(-85, -85, -85, 85)
  126.   # weather setup, create new types of weather here
  127.   #  note - if you don't want a certain effect such as weather, fog, or sound,
  128.   #    just leave the array for that effect empty
  129.   #          ['NAME', WEATHER_SEVERITY, [WEATHER_TYPE, LOW_STRENGTH..HIGH_STRENGTH],
  130.   #            [SOUND_NAME, SOUND_VOLUME_MIN..SOUND_VOLUME_MAX, SOUND_PITCH], [FOG_NAME, FOG_OPACITY, FOG_HUE,
  131.   #            FOG_ZOOM, FOG_SX, FOG_SY, [TONE_RED, TONE_GREEN, TONE_BLUE, TONE_GRAY]],
  132.   #            [SOUND_EFFECT_NAME, SOUND_VOLUME_MIN..SOUND_VOLUME_MAX, SOUND_PITCH, EFFECT_PROBABILITY,
  133.   #            FLASH_DURATION, [FLASH_COLOR_RED, FLASH_COLOR_GREEN, FLASH_COLOR_BLUE]]]
  134.   WEATHER = [['细雨', 0, 1..4, [1], ['005-Rain01', 65..80, 100], [], []],
  135.              ['雨天', 0, 5..8, [1], ['006-Rain02', 75..90, 100], [], ['061-Thunderclap01', 60..85, 100, 0.07, 4, [255, 255, 255]]],
  136.              ['暴风', 1, 9..10, [1], ['007-Rain03', 80..100, 100], [], ['061-Thunderclap01', 70..95, 110, 0.08, 6, [255, 255, 255]]],
  137.              ['多风', 0, 1..1, [], [], ['002-Clouds01', 60, 0, 200, 4, 3, [0, 0, 0, 0]], []],
  138.              ['雨天', 0, 1..4, [2], ['006-Rain02', 70..85, 100], [], ['061-Thunderclap01', 65..90, 110, 0.08, 6, [255, 255, 255]]],
  139.              ['暴风', 1, 5..8, [2], ['007-Rain03', 75..90, 100], [], ['061-Thunderclap01', 70..95, 110, 0.09, 7, [255, 255, 255]]],
  140.              ['暴风', 2, 9..10, [2], ['007-Rain03', 90..100, 100], [], ['061-Thunderclap01', 85..100, 110, 0.11, 7, [255, 255, 255]]],
  141.              ['小雪', 1, 1..4, [3], ['002-Wind02', 70..85, 100], [], []],
  142.              ['大雪', 1, 5..8, [3], ['003-Wind03', 80..95, 100], [], []],
  143.              ['暴雪', 2, 9..10, [3], ['004-Wind04', 85..100, 100], [], []]]
  144.   # normal weather duration in seconds
  145.   WEATHER_DURATION = 57
  146.   # variance of the weather duration in seconds
  147.   WEATHER_VARIANCE = 24
  148.   # the name of the default weather type (what gets shown in the clock when
  149.   #   there is no weather)
  150.   DEFAULT_WEATHER_NAME = '晴天'
  151.   # season setup, create a new season by using this template
  152.   #          ['NAME', START_DAY, START_MONTH, MIN_TEMP..MAX_TEMP, WEATHER_PROBABILITY,
  153.   #            BAD_WEATHER_PROBABILITY, VERY_BAD_WEATHER_PROBABILITY, WEATHER_POSSIBILITIES]
  154.   SEASONS = [
  155.              ['春', 22,  3,   0..25, 0.003, 0.3, 0.05, [0, 1, 2, 3, 4, 5]] ,
  156.              ['夏', 21,  6,  20..35, 0.003, 0.1, 0.2, [0, 1, 3, 4, 5, 6]]  ,
  157.              ['秋', 20,  9,   0..25, 0.003, 0.2, 0.1, [0, 2, 3, 4, 5, 7]]  ,
  158.              ['冬', 21, 12, -20..5, 0.003, 0.5, 0.1, [0, 2, 3, 4, 7, 8, 9]]
  159.             ]
  160.   # terrain setup, create a new terrain by using this template
  161.   #          ['NAME', MIN_TEMP..MAX_TEMP, WEATHER_EXCLUSIONS]
  162.   TERRAINS = [
  163.               ['Forest', -7..0, [3]],
  164.               ['Desert', 11..16, [8, 9]],
  165.               ['Mountain', -9..-4, []],
  166.               ['Plains', -2..0, []],
  167.               ['Beach', -5..-2, [8, 9]]
  168.              ]
  169.   # longest day date, the longest night date is half a year later/earlier
  170.   LONGEST = [21, 6]
  171.   # the tone at which day starts
  172.   DAY_START = "Sunrise"
  173.   # the tone at which night starts
  174.   NIGHT_START = "Dusk"
  175.   # the different screen tones and temperature modifiers at certain points during the day on the longest and shortest days
  176.   # to make a new time of day, add this into TIMES: NAME => [RED, GREEN, BLUE, GRAY, TEMPERATURE_MODIFIER]
  177.   TIMES = {
  178.            "Dawn" => [-17, -17, 17, 0, -4],
  179.            "Sunrise" => [48, 30, 30, 0, -2],
  180.            "Noon" => [24, 10, 10, 0, 5],
  181.            "Sunset" => [57, -17, -17, 0, 1],
  182.            "Dusk" => [-17, -17, 17, 0, -3],
  183.            "Night" => [-150, -120, -120, 200, -8]
  184.           }
  185.   # once you have customized the tones, put the tones into LONG_TIMES and SHORT_TIMES with [name_of_time, hour, minute]
  186.   LONG_TIMES = [["Dawn", 4, 30],
  187.                 ["Sunrise", 5, 30],
  188.                 ["Noon", 13, 00],
  189.                 ["Sunset", 21, 00],
  190.                 ["Dusk", 22, 00],
  191.                 ["Night", 1, 30]]
  192.   SHORT_TIMES = [["Dawn", 6, 30],
  193.                 ["Sunrise", 7, 30],
  194.                 ["Noon", 13, 00],
  195.                 ["Sunset", 16, 30],
  196.                 ["Dusk", 17, 00],
  197.                 ["Night", 23, 30]]
  198.   # makes the screen brighter during "summer" days
  199.   OVERLIGHTING = true
  200.   # makes the screen darker during the night, not recommended
  201.   OVERDARKENING = false
  202.   # the first year in your calender, the player can't scroll further back
  203.   FYEAR = 1990
  204.   # the last year in your calender, the player can't scroll further forth
  205.   LYEAR = 2099
  206.   # the suffix for temperature
  207.   TEMP_SUFFIX = "°C"
  208.   # the different holidays and their dates
  209.   #   the format for adding a new holiday is:
  210.   #     [NAME, SETUP_TYPE, MONTH, (DAY or WEEKDAY, NUMBER)]
  211.   #   whether to use DAY or WEEKDAY, NUMBER depends on SETUP_TYPE:
  212.   #     (0 - DAY; 1 - WDAY, NUMBER)
  213.   # note - the current holiday will replace the weekday in the clock if it is a
  214.   #   holiday
  215.   HOLIDAYS = [
  216.                ["圣诞节", 0, 11, 24],
  217.                ["新年", 0, 0, 0],
  218.                ["感恩节", 1, 10, 4, 4],
  219.                ["情人节", 0, 1, 13],
  220.                ["地球日", 0, 3, 21],
  221.                ["植树节", 1, 3, 5, -1],
  222.                ["母亲节", 1, 2, 7, 2],
  223.                ["父亲节", 1, 5, 7, 3],
  224.                ["万圣节", 0, 9, 30],
  225.              ]
  226.   # HUD clock format
  227.   # default : ['%H:%M%s', '%A', '%d/%m/%Y', '%S']
  228.   # use [] for no clock
  229.   # it means: 1st row - "HOURS:MINUTES SUFFIX"
  230.   #           2nd row - "WEEKDAY"
  231.   #           3rd row - "DAY/MONTH/YEAR"
  232.   #           4th row - "SEASON"
  233.   # different combinations to input ATES information into the clock
  234.   #   %H - Hour
  235.   #   %M - Minute
  236.   #   %s - Suffix (AM or PM) (only if not using 24 hour time)
  237.   #   %A - Weekday
  238.   #   %d - Day of the Month
  239.   #   %D - Day of the Year
  240.   #   %m - Month
  241.   #   %n - Month Name
  242.   #   %l - Month Length
  243.   #   %Y - Year
  244.   #   %L - Year Length
  245.   #   %S - Season
  246.   #   %w - Weather  #   %t - Terrain
  247.   #   %T - Temperature
  248.   #   %p - Time of Day
  249.   CFORMAT = ['%H:%M', '%d/%m/%Y', '%A', '%w']
  250.   # the width of the clock
  251.   CWIDTH = 180
  252.   # names of your days, automatically sets up a week's length
  253.   WEEKDAYS = ['星期天', '星期一', '星期二', '星期三', '星期四', '星期五',
  254.               '星期六']
  255.   WEEKDAY_ABBREVIATIONS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
  256.   # names of your months, automatically sets up a year's length
  257.   MONTHS = ['一月', '二月', '三月', '四月', '五月', '六月', '七月',
  258.             '八月', '九月', '十月', '十一月', '十二月']
  259.   # abbreviations for month names
  260.   MONTH_ABBREVIATIONS = ['Jan', 'Feb', 'March', 'Apr', 'May', 'June', 'July',
  261.                          'Aug', 'Sept', 'Oct', 'Nov', 'Dec']
  262.   # days in each month
  263.   MONTHDAYS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
  264.   # the first day in the game [DAY, MONTH, YEAR, WEEKDAY]
  265.   # set this option to [] if you want the game to start "now"
  266.   START = [24, 11, 2007, 7]
  267.   # set this option to true to turn on military time (24 hour time)
  268.   HOUR24 = true
  269. #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  270. # END Configuration
  271. #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  272.  
  273.   mon = (LONGEST[1] + MONTHS.length / 2) % 12
  274.   mon = 12 if mon == 0
  275.   day = LONGEST[0] + (MONTHS.length % 2) == 1 ? MONTHDAYS[mon - 1] / 2 : 0
  276.   while day > MONTHDAYS[mon - 1]
  277.     day -= MONTHDAYS[mon - 1]
  278.     mon = (mon + 1) % 12
  279.     mon = 12 if mon == 0
  280.   end
  281.   SHORTEST = [day, mon]
  282.  
  283.   $ates = 1.01
  284.  
  285.   #============================================================================
  286.   # ATES::Time
  287.   #============================================================================
  288.  
  289.   class Time
  290.  
  291.     attr_accessor :min
  292.     attr_accessor :hour
  293.     attr_accessor :day
  294.     attr_accessor :mon
  295.     attr_accessor :year
  296.     attr_accessor :wday
  297.  
  298.     def initialize(m, h, d, mon, y, w)
  299.       @min, @hour, @day, @mon, @year, @wday = m, h, d, mon, y, w
  300.     end
  301.  
  302.   end
  303.  
  304.   def self.on
  305.     $game_system.ates.active = true
  306.     return true
  307.   end
  308.  
  309.   def self.off
  310.     $game_system.ates.active = false
  311.     return true
  312.   end
  313.  
  314.   def self.tint_on(frames = 0)
  315.     $game_screen.start_tone_change($game_system.ates.get_environment[0], frames)
  316.     $game_system.ates.tinting = true
  317.     return true
  318.   end
  319.  
  320.   def self.tint_off(reset = true)
  321.     $game_screen.start_tone_change(Tone.new(0, 0, 0, 0), 0) if reset
  322.     $game_system.ates.tinting = false
  323.     return true
  324.   end
  325.  
  326.   def self.weather_off
  327.     $game_system.ates.weather.weather_enabled = false
  328.     $game_system.ates.weather.pause_weather(0) if $game_system.ates.weather.current_weather and $game_system.ates.weather.current_weather != -1
  329.     return true
  330.   end
  331.  
  332.   def self.weather_on
  333.     $game_system.ates.weather.weather_enabled = true
  334.     $game_system.ates.weather.resume_weather(0) if $game_system.ates.weather.current_weather and $game_system.ates.weather.current_weather != -1
  335.     return true
  336.   end
  337.  
  338.   def self.weather_active?
  339.     return $game_system.ates.weather.weather_enabled
  340.   end
  341.  
  342.   def self.lock_weather
  343.     $game_system.ates.weather.locked = true
  344.   end
  345.  
  346.   def self.unlock_weather
  347.     $game_system.ates.weather.locked = false
  348.     return true
  349.   end
  350.  
  351.   def self.clock_on
  352.     $game_system.show_clock = true
  353.     return true
  354.   end
  355.  
  356.   def self.clock_off
  357.     $game_system.show_clock = false
  358.     return true
  359.   end
  360.  
  361.   def self.active?
  362.     return $game_system.ates.active
  363.   end
  364.  
  365.   def self.tinting?
  366.     return $game_system.ates.tinting
  367.   end
  368.  
  369.   def self.day?
  370.     i = $game_system.ates.time_index
  371.     while true
  372.       if $game_system.ates.current_times[i][0] == DAY_START
  373.         return true
  374.       elsif $game_system.ates.current_times[i][0] == NIGHT_START
  375.         return false
  376.       end
  377.  
  378.       i = (i + $game_system.ates.current_times.length - 1) % $game_system.ates.current_times.length
  379.     end
  380.   end
  381.  
  382.   def self.night?
  383.     return !(self.day?)
  384.   end
  385.  
  386.   def self.make_it_day
  387.     time = $game_system.ates.current_times.select { |time| time[0] == DAY_START }
  388.     h, m = time[0][1], time[0][2]
  389.     $game_system.ates.time.hour = h
  390.     $game_system.ates.time.min = m
  391.     return true
  392.   end
  393.  
  394.   def self.make_it_night
  395.     time = $game_system.ates.current_times.select { |time| time[0] == NIGHT_START }
  396.     h, m = time[0][1], time[0][2]
  397.     $game_system.ates.time.hour = h
  398.     $game_system.ates.time.min = m
  399.     return true
  400.   end
  401.  
  402.   def self.set_time(time = 0)
  403.     return unless $game_system
  404.     if time.is_a?(Fixnum)
  405.       time = $game_system.ates.current_times[time.to_i]
  406.     else
  407.       time = $game_system.ates.current_times.select { |current_time| current_time[0] == time }[0]
  408.     end
  409.     h, m = time[1], time[2]
  410.     $game_system.ates.time.hour = h
  411.     $game_system.ates.time.min = m
  412.     return true
  413.   end
  414.  
  415.   def self.day_start
  416.     return DAY_START
  417.   end
  418.  
  419.   def self.night_start
  420.     return NIGHT_START
  421.   end
  422.  
  423.   def self.go_inside_dark
  424.     weather = $game_system.ates.weather.current_weather
  425.     $game_system.ates.map_type = 2
  426.     self.tint_on
  427.     $game_system.ates.weather.pause_weather(0)
  428.     return true if weather == -1
  429.     low, high = weather[2].first, weather[2].last
  430.     intensity = $game_system.ates.weather.current_intensity
  431.     if weather[4].length > 0
  432.       volume = ATES::INSIDE_SOUND * weather[4][1].first + (weather[4][1].last - weather[4][1].first) * (high - intensity).to_f / (high - low)
  433.       bgm = RPG::AudioFile.new(weather[4][0], volume, weather[4][2])
  434.       $game_system.bgs_play(bgm)
  435.     end
  436.     return true
  437.   end
  438.  
  439.   def self.go_inside
  440.     weather = $game_system.ates.weather.current_weather
  441.     $game_system.ates.map_type = 1
  442.     self.tint_on
  443.     $game_system.ates.weather.pause_weather(0)
  444.     return true if weather == -1
  445.     low, high = weather[2].first, weather[2].last
  446.     intensity = $game_system.ates.weather.current_intensity
  447.     if weather[4].length > 0
  448.       volume = ATES::INSIDE_SOUND * weather[4][1].first + (weather[4][1].last - weather[4][1].first) * (high - intensity).to_f / (high - low)
  449.       bgm = RPG::AudioFile.new(weather[4][0], volume, weather[4][2])
  450.       $game_system.bgs_play(bgm)
  451.     end
  452.     return true
  453.   end
  454.  
  455.   def self.go_outside
  456.     $game_system.ates.weather.resume_weather(0)
  457.     $game_system.ates.map_type = 0
  458.     self.tint_on
  459.     return true
  460.   end
  461.  
  462.   def self.set_weather(id)
  463.     $game_system.ates.weather.set_weather(WEATHER[id])
  464.     return true
  465.   end
  466.  
  467.   def self.terrain=(terrain)
  468.     terrain = TERRAINS[terrain.to_i][0] if terrain.is_a?(Fixnum)
  469.     $game_system.ates.terrain = terrain
  470.     return true
  471.   end
  472.  
  473.   def self.advance(m, h, d, mon, y)
  474.     changed = false
  475.     h += ($game_system.ates.time.min + m) / 60
  476.     $game_system.ates.time.min = ($game_system.ates.time.min + m) % 60
  477.     d += ($game_system.ates.time.hour + h) / 24
  478.     changed = true if d > 0
  479.     $game_system.ates.time.hour = ($game_system.ates.time.hour + h) % 24
  480.     while d > 0
  481.       if $game_system.ates.time.day < MONTHDAYS[mon]
  482.         $game_system.ates.time.day += 1
  483.       else
  484.         $game_system.ates.time.day = 0
  485.         mon = (mon + 1) % MONTHS.size
  486.       end
  487.       $game_system.ates.time.wday += 1
  488.       $game_system.ates.time.wday %= WEEKDAYS.size
  489.       d -= 1
  490.     end
  491.     y += ($game_system.ates.time.mon + mon) / MONTHS.size
  492.     $game_system.ates.time.mon = ($game_system.ates.time.mon + mon) % MONTHS.size
  493.     $game_system.ates.time.year += y
  494.     $game_system.ates.current_times = $game_system.ates.setup_times if changed
  495.   end
  496.  
  497.   def self.time_name
  498.     return $game_system.ates.current_times[$game_system.ates.time_index][0]
  499.   end
  500.  
  501. end
  502.  
  503. if ATES::MONTHS.size > ATES::MONTHDAYS.size
  504.   raise 'ATEScfgError: Not all months have a length in days specified!'
  505. #elsif ATES::DAY_START > ATES::NIGHT_START
  506. #  raise 'ATEScfgError: A night can\'t start earlier than a day.'
  507. elsif ATES::LENGTH < 36
  508.   raise 'ATEScfgError: A day\'s length must be equal to or greater than 36 seconds!'
  509. end
  510.  
  511. #==============================================================================
  512. # Weather
  513. #==============================================================================
  514.  
  515. class Weather
  516.   attr_accessor :current_weather, :current_intensity, :weather_enabled, :locked
  517.  
  518.   def initialize
  519.     @current_weather = -1
  520.     @current_intensity = 0
  521.     @normal_weather = []
  522.     @bad_weather = []
  523.     @very_bad_weather = []
  524.     @weather_enabled = true
  525.     @locked = false
  526.   end
  527.  
  528.   def decimal_places(num)
  529.     if num.is_a?(Float)
  530.       return num.to_s.split('.')[1].length
  531.     else
  532.       return 0
  533.     end
  534.   end
  535.  
  536.   def get_weather(severity = 0)
  537.     weather = []
  538.     season = $game_system.ates.get_full_season
  539.     ATES::WEATHER.each_with_index { |el, ind|
  540.       weather.push(el) if el[1] == severity and season[7].include?(ind)
  541.     }
  542.     return weather
  543.   end
  544.  
  545.   def update
  546.     season = $game_system.ates.get_full_season
  547.     if !@season or @season != season
  548.       @normal_weather = get_weather
  549.       @bad_weather = get_weather(1)
  550.       @very_bad_weather = get_weather(2)
  551.       @season = season
  552.     end
  553.     unless @locked
  554.       places = [decimal_places(season[4]), decimal_places(season[5]), decimal_places(season[6])]
  555.       if rand(10 ** places[0]) <= season[4] * (10 ** places[0]) and season[7].length > 0
  556.         if rand(10 ** places[1]) <= season[4] * (10 ** places[1]) and @bad_weather.length > 0
  557.           weather = rand(@bad_weather.length)
  558.           weather = @bad_weather[weather]
  559.           set_weather(weather)
  560.         elsif rand(10 ** places[2]) <= season[4] * (10 ** places[2]) and @very_bad_weather.length > 0
  561.           weather = rand(@very_bad_weather.length)
  562.           weather = @very_bad_weather[weather]
  563.           set_weather(weather)
  564.         elsif @normal_weather.length > 0
  565.           weather = rand(@normal_weather.length)
  566.           weather = @normal_weather[weather]
  567.           set_weather(weather)
  568.         end
  569.       end
  570.     end
  571.     if @current_weather != -1
  572.       update_effect if @weather_enabled and @current_weather[6].length > 0
  573.       @weather_count += 1
  574.       if @weather_count >= @weather_duration
  575.         stop_weather unless @locked
  576.       end
  577.     end
  578.   end
  579.  
  580.   def update_effect
  581.     weather = @current_weather
  582.     places = decimal_places(weather[6][3])
  583.     if rand(10 ** places) <= weather[6][3] * 10 ** places
  584.       high, low = weather[2].first, weather[2].last
  585.       vol = weather[6][1].first + (weather[6][1].last - weather[6][1].first) * (high - @current_intensity).to_f / (high - low)
  586.       vol *= ATES::INSIDE_SOUND if $game_system.ates.map_type > 0
  587.       sound = RPG::AudioFile.new(weather[6][0], vol, weather[6][2])
  588.       $game_system.se_play(sound)
  589.       col = Color.new(0, 0, 0)
  590.       $game_screen.start_flash(Color.new(*weather[6][5]), weather[6][4])
  591.     end
  592.   end
  593.  
  594.   def stop_weather(speed = -1)
  595.     return if @current_weather == -1
  596.     speed = speed == -1 ? rand(10) + 60 : speed
  597.     if @current_weather[3].length > 0
  598.       $game_screen.weather(0, 1, speed)
  599.     end
  600.     if @current_weather[4].length > 0
  601.       $game_system.bgs_fade(speed.to_f / 40)
  602.     end
  603.     if @current_weather[5].length > 0
  604.       $game_map.fog_name = ''
  605.     end
  606.     @current_weather = -1
  607.   end
  608.  
  609.   def pause_weather(speed = -1)
  610.     return if @current_weather == -1
  611.     $game_system.ates.show_weather = false
  612.     speed = speed == -1 ? rand(10) + 60 : speed
  613.     if @current_weather[3].length > 0
  614.       $game_screen.weather(0, 1, speed)
  615.     end
  616.     if @current_weather[4].length > 0
  617.       $game_system.bgs_fade(speed.to_f / 40)
  618.     end
  619.     if @current_weather[5].length > 0
  620.       $game_map.fog_name = ''
  621.     end
  622.   end
  623.  
  624.   def resume_weather(speed = -1)
  625.     return if @current_weather == -1
  626.     $game_system.ates.show_weather = true
  627.     weather = @current_weather
  628.     intensity = @current_intensity
  629.     low, high = weather[2].first, weather[2].last
  630.     speed = speed == -1 ? rand(10) + 60 : speed
  631.     if weather[3].length > 0
  632.       $game_screen.weather(weather[3][0], intensity, speed)
  633.     end
  634.     if weather[4].length > 0
  635.       volume = weather[4][1].first + (weather[4][1].last - weather[4][1].first) * (high - intensity).to_f / (high - low)
  636.       bgm = RPG::AudioFile.new(weather[4][0], volume, weather[4][2])
  637.       $game_system.bgs_play(bgm)
  638.     end
  639.     if weather[5].length > 0
  640.       $game_map.fog_name = weather[5][0]
  641.       $game_map.fog_opacity = weather[5][1]
  642.       $game_map.fog_hue = weather[5][2]
  643.       $game_map.fog_zoom = weather[5][3]
  644.       $game_map.fog_sx = weather[5][4]
  645.       $game_map.fog_sy = weather[5][5]
  646.       $game_map.start_fog_tone_change(Tone.new(*weather[5][6]), 0)
  647.     end
  648.   end
  649.  
  650.   def set_weather(weather, speed = -1)
  651.     stop_weather if @current_weather != -1
  652.     @weather_count = 0
  653.     @weather_duration = ATES::WEATHER_DURATION + rand(ATES::WEATHER_VARIANCE)
  654.     low, high = weather[2].first, weather[2].last
  655.     intensity = rand(high + 1 - low) + low
  656.     @current_weather = weather
  657.     @current_intensity = intensity
  658.     return unless @weather_enabled
  659.     if weather.is_a?(Fixnum)
  660.       weather = WEATHER[weather]
  661.     end
  662.     speed = speed == -1 ? rand(10) + 60 : speed
  663.     if weather[4].length > 0
  664.       volume = weather[4][1].first + (weather[4][1].last - weather[4][1].first) * (high - intensity).to_f / (high - low)
  665.       volume *= ATES::INSIDE_SOUND if $game_system.ates.map_type > 0
  666.       bgm = RPG::AudioFile.new(weather[4][0], volume, weather[4][2])
  667.       $game_system.bgs_play(bgm)
  668.     end
  669.     return if $game_system.ates.map_type > 0
  670.     if weather[3].length > 0
  671.       if $modified_aws and weather[3].length > 1
  672.         $game_screen.weather(weather[3][0], intensity, speed, weather[3][1])
  673.       else
  674.         $game_screen.weather(weather[3][0], intensity, speed)
  675.       end
  676.     end
  677.     if weather[5].length > 0
  678.       $game_map.fog_name = weather[5][0]
  679.       $game_map.fog_opacity = weather[5][1]
  680.       $game_map.fog_hue = weather[5][2]
  681.       $game_map.fog_zoom = weather[5][3]
  682.       $game_map.fog_sx = weather[5][4]
  683.       $game_map.fog_sy = weather[5][5]
  684.       $game_map.start_fog_tone_change(Tone.new(*weather[5][6]), 0)
  685.     end
  686.   end
  687. end
  688.  
  689. #==============================================================================
  690. # Game_System
  691. #==============================================================================
  692.  
  693. class Game_System
  694.  
  695.   attr_accessor :ates
  696.   attr_accessor :show_clock
  697.  
  698.   alias init_ates_later initialize
  699.   def initialize
  700.     init_ates_later
  701.     @ates = Game_ATES.new
  702.     @show_clock = (ATES::CFORMAT != [])
  703.   end
  704.  
  705. end
  706.  
  707. #==============================================================================
  708. # Game_ATES
  709. #==============================================================================
  710.  
  711. class Game_ATES
  712.  
  713.   attr_accessor :active
  714.   attr_accessor :tinting
  715.   attr_accessor :time
  716.   attr_accessor :weather
  717.   attr_accessor :frame_count
  718.   attr_accessor :current_times
  719.   attr_accessor :tone
  720.   attr_accessor :map_type
  721.   attr_accessor :show_weather
  722.   attr_accessor :terrain
  723.   attr_accessor :temp
  724.   attr_reader   :holiday
  725.   attr_reader   :time_index
  726.  
  727.   def initialize
  728.     if ATES::START.size == 4
  729.       @time = ATES::Time.new(0, 0, ATES::START[0], ATES::START[1],
  730.           ATES::START[2], ATES::START[3])
  731.     else
  732.       @time = Time.now
  733.       @time = ATES::Time.new(@time.min, @time.hour, @time.mday, @time.mon, @time.year, @time.wday)
  734.     end
  735.     @weather = Weather.new
  736.  
  737.     @long_times = ATES::LONG_TIMES.sort { |t1, t2| t1[1] * 100 + t1[2] <=> t2[1] * 100 + t2[2] }
  738.     @short_times = ATES::SHORT_TIMES.sort { |t1, t2| t1[1] * 100 + t1[2] <=> t2[1] * 100 + t2[2] }
  739.  
  740.     @year_length = ATES::MONTHDAYS.inject { |sum, x| sum + x }
  741.  
  742.     @terrain = ''
  743.     @current_times = setup_times
  744.     @temp_modifier = (rand(201) - 100) / 100.0
  745.     @tone, @temp = get_environment
  746.     @holiday = get_holiday(@time.mon, @time.day, @time.wday)
  747.     @s_time = get_time(@time.min, @time.hour)
  748.     $game_screen.start_tone_change(@tone, 0) if $game_screen
  749.  
  750.     @active = true
  751.     @tinting = true
  752.     @show_weather = true
  753.     @map_type = 0
  754.     @frame_count = 0
  755.   end
  756.  
  757.   def get_holiday(month, day, wday)
  758.     ATES::HOLIDAYS.select { |i|
  759.       case i[1]
  760.       when 0:
  761.         i[2..3] == [month, day]
  762.       when 1:
  763.         if i[4] > 0
  764.           i[2] == month and i[3] == wday and i[4] == (day.to_f / 7 + 1).floor
  765.         elsif i[4] < 0
  766.           i[2] == month and i[3] == wday and -i[4] == ((ATES::MONTHDAYS[month] - 1 - day).to_f / 7 + 1).floor
  767.         end
  768.       end
  769.     }[0]
  770.   end
  771.  
  772.   def get_environment
  773.  
  774.     red = 0
  775.     green = 0
  776.     blue = 0
  777.     grey = 0
  778.     @temp_modifier += (rand(3) - 1) / 100.0 if rand(10) == 0
  779.  
  780.     changed = false
  781.  
  782.     for i in [email]0...@current_times.length[/email]
  783.       time1 = get_time(@current_times[i][2], @current_times[i][1])
  784.       time2 = get_time(@current_times[(i + 1) % @current_times.length][2], @current_times[(i + 1) % @current_times.length][1])
  785.       current = get_time(@time.min, @time.hour)
  786.       if time2 < time1
  787.         time2 += 24 * 60
  788.       end
  789.       if current < time1
  790.         current += 24 * 60
  791.       end
  792.  
  793.       if time1 <= current and time2 >= current
  794.  
  795.         changed = true
  796.         tone1 = @current_times[i]
  797.         tone2 = @current_times[(i + 1) % @current_times.length]
  798.         tone1 = ATES::TIMES[tone1[0]]
  799.         tone2 = ATES::TIMES[tone2[0]]
  800.         max = time2 - time1
  801.  
  802.         ratios = [(current - time1).to_f / max, (time2 - current).to_f / max]
  803.         red = tone1[0] * ratios[1] + tone2[0] * ratios[0]
  804.         green = tone1[1] * ratios[1] + tone2[1] * ratios[0]
  805.         blue = tone1[2] * ratios[1] + tone2[2] * ratios[0]
  806.         grey = tone1[3] * ratios[1] + tone2[3] * ratios[0]
  807.  
  808.         temp_range = get_full_season[3]
  809.         temp_range = [temp_range.first, temp_range.last].sort
  810.         unless @base_temp
  811.           temp = temp_range[0] + rand(temp_range[1] - temp_range[0] + 1)
  812.           if @terrain != ''
  813.             modifier = ATES::TERRAINS.select { |terrain| terrain[0] == @terrain }[0][1]
  814.             modifier = [modifier.first, modifier.last].sort
  815.             modifier = modifier[0] + rand(modifier[1] - modifier[0] + 1)
  816.             temp += modifier
  817.           end
  818.           @base_temp = temp
  819.         else
  820.           temp = @base_temp
  821.         end
  822.  
  823.         temp_mod = round(tone1[4] * ratios[1] + tone2[4] * ratios[0], 2)
  824.         temp += temp_mod + @temp_modifier
  825.  
  826.         @time_index = ratios[0] < 0.5 ? i : (i + 1) % @current_times.length
  827.         break
  828.       end
  829.     end
  830.  
  831.     print "not right" unless changed
  832.  
  833.     if @map_type == 1
  834.       return Tone.new(red * ATES::INSIDE_TONE, green * ATES::INSIDE_TONE, blue * ATES::INSIDE_TONE, grey * ATES::INSIDE_TONE), temp
  835.     elsif @map_type == 2
  836.       return ATES::DARK_INSIDE_TONE, temp
  837.     else
  838.       return Tone.new(red, green, blue, grey), temp
  839.     end
  840.   end
  841.  
  842.   def setup_times
  843.     current_date = [@time.day, @time.mon]
  844.     if current_date == ATES::LONGEST or @long_times == @short_times
  845.       return @long_times
  846.     elsif current_date == ATES::SHORTEST
  847.       return @short_times
  848.     end
  849.  
  850.     short_times = @long_times.clone
  851.     addons = @short_times.clone
  852.     current_date = get_date(*current_date)
  853.     long, short = get_date(*ATES::LONGEST), get_date(*ATES::SHORTEST)
  854.     dists = []
  855.     if (current_date >= short and current_date <= long)
  856.       dists = [current_date - short, long - current_date]
  857.     elsif (current_date >= short and short >= long)
  858.       dists = [current_date - short, long + @year_length - current_date]
  859.     elsif (current_date <= long and long <= short)
  860.       dists = [current_date + @year_length - short, long - current_date]
  861.     elsif (current_date >= long and current_date <= short)
  862.       dists = [current_date - long, short - current_date]
  863.     elsif (current_date <= short and short <= long)
  864.       dists = [current_date + @year_length - long, short - current_date]
  865.     elsif (current_date >= long and long >= short)
  866.       dists = [current_date - long, short + @year_length - current_date]
  867.     end
  868.     sum = dists.inject { |sum, x| sum + x }
  869.     short_times.each { |tone|
  870.       addons.each { |addon|
  871.         if tone[0] == addon[0]
  872.           ts = [tone[1] * 100 + tone[2] * 50 / 30.0, addon[1] * 100 + addon[2] * 50 / 30.0]
  873.           ts = ts[0] * dists[0] / sum.to_f + ts[1] * dists[1] / sum.to_f
  874.           h = (ts / 100).floor
  875.           m = ((ts - h * 100) * 30 / 50).floor
  876.           tone[1], tone[2] = h, m
  877.         end
  878.       }
  879.     }
  880.  
  881.     return short_times.sort { |x, y| get_time(x[2], x[1]) <=> get_time(y[2], y[1]) }
  882.   end
  883.  
  884.   def round(num, places = 0)
  885.     return ((num * 10 ** places).round.to_f) / (10 ** places)
  886.   end
  887.  
  888.   def get_time(minutes, hours)
  889.     return minutes + hours * 60
  890.   end
  891.  
  892.   def get_season
  893.     season_list = ATES::SEASONS.sort { |x, y| get_date(x[1], x[2]) <=> get_date(y[1], y[2]) }
  894.     day = @time.day
  895.     month = @time.mon
  896.     current = get_date(day, month)
  897.     for i in 0...season_list.length
  898.       seasons = [season_list[i], season_list[(i + 1) % season_list.length]]
  899.       times = [get_date(seasons[0][1], seasons[0][2]), get_date(seasons[1][1], seasons[1][2])]
  900.       if times[0] <= current and current < times[1]
  901.         return seasons[0][0]
  902.       end
  903.     end
  904.     return season_list[0][0]
  905.   end
  906.  
  907.   def get_full_season
  908.     season_list = ATES::SEASONS.sort { |x, y| get_date(x[1], x[2]) <=> get_date(y[1], y[2]) }
  909.     day = @time.day
  910.     month = @time.mon
  911.     current = get_date(day, month)
  912.     for i in 0...season_list.length
  913.       seasons = [season_list[i], season_list[(i + 1) % season_list.length]]
  914.       times = [get_date(seasons[0][1], seasons[0][2]), get_date(seasons[1][1], seasons[1][2])]
  915.       if times[0] <= current and current < times[1]
  916.         return seasons[0]
  917.       end
  918.     end
  919.     return season_list[0]
  920.   end
  921.  
  922.   def get_date(day, month)
  923.     month = ATES::MONTHS.length if month == 0
  924.     return (ATES::MONTHDAYS[0...month - 1].inject { |sum, x| sum + x } or 0) + day
  925.   end
  926.  
  927.   def update
  928.     if @active
  929.       @frame_count += 1
  930.       if @frame_count % (ATES::LENGTH / 36) == 0
  931.         tmp = @time.day
  932.         ATES.advance(1, 0, 0, 0, 0)
  933.         if @time.day != tmp
  934.           @holiday = get_holiday(@time.mon, @time.day, @time.wday)
  935.         end
  936.         @weather.update
  937.       end
  938.     end
  939.     if ATES.day?
  940.       $game_map.need_refresh = true if $game_switches[ATES::NSWITCH]
  941.       $game_switches[ATES::DSWITCH] = true
  942.       $game_switches[ATES::NSWITCH] = false
  943.     else
  944.       $game_map.need_refresh = true if $game_switches[ATES::DSWITCH]
  945.       $game_switches[ATES::DSWITCH] = false
  946.       $game_switches[ATES::NSWITCH] = true
  947.     end
  948.     @tone, @temp = get_environment
  949.     tmp = get_time(@time.min, @time.hour)
  950.     $game_screen.start_tone_change(@tone, ((@s_time - tmp).abs < [1440 / ATES::LENGTH, 1].max ? 0 : 20)) if @tinting
  951.   end
  952.  
  953. end
  954.  
  955. #==============================================================================
  956. # Bitmap
  957. #==============================================================================
  958.  
  959. class Bitmap
  960.  
  961.   if $tons_version == nil || $tons_version < 1.6
  962.     alias draw_text_shaded_later draw_text
  963.   end
  964.   def draw_text_full(x2, y2, w2 = 0, h2 = 0, text2 = '', a2 = 0)
  965.     if x2.is_a?(Rect)
  966.       x, y, w, h, text, a = x2.x, x2.y, x2.width, x2.height, y2, w2
  967.     else
  968.       x, y, w, h, text, a = x2, y2, w2, h2, text2, a2
  969.     end
  970.     save_color = self.font.color.clone
  971.     self.font.color = Color.new(0, 0, 0)
  972.     [x-1, x+1].each {|xx| [y-1, y+1].each {|yy|
  973.             draw_text_shaded_later(xx, yy, w, h, text, a)}}
  974.     self.font.color = save_color
  975.     draw_text_shaded_later(x, y, w, h, text, a)
  976.   end
  977.  
  978. end
  979.  
  980. #==============================================================================
  981. # Clock_Sprite
  982. #==============================================================================
  983.  
  984. class Clock_Sprite < Sprite
  985.  
  986.   def initialize
  987.     super
  988.     self.x, self.y, self.z = 640 - 8 - ATES::CWIDTH, 8, 5000
  989.     self.bitmap = Bitmap.new(ATES::CWIDTH, ATES::CFORMAT.length * 32)
  990.     if $fontface != nil
  991.       self.bitmap.font.name = $fontface
  992.     elsif $defaultfonttype != nil
  993.       self.bitmap.font.name = $defaultfonttype
  994.     end
  995.     self.bitmap.font.size = 26
  996.     @odd = 0
  997.     draw if $game_system.ates.active
  998.   end
  999.  
  1000.   def draw
  1001.     self.bitmap.clear
  1002.     hours = $game_system.ates.time.hour
  1003.     minutes = sprintf('%02d', $game_system.ates.time.min)
  1004.     weekday = ATES::WEEKDAYS[$game_system.ates.time.wday - 1]
  1005.     wday_abbr = ATES::WEEKDAY_ABBREVIATIONS[$game_system.ates.time.wday - 1]
  1006.     day = $game_system.ates.time.day + 1
  1007.     month = $game_system.ates.time.mon + 1
  1008.     yday = ATES::MONTHDAYS[0..month - 1].inject { |s, r| s + r } + day
  1009.     month_name = ATES::MONTHS[month - 1]
  1010.     month_abbr = ATES::MONTH_ABBREVIATIONS[month - 1]
  1011.     month_days = ATES::MONTHDAYS[month - 1]
  1012.     year = $game_system.ates.time.year
  1013.     year_days = ATES::MONTHDAYS.inject { |s, r| s + r }
  1014.     season = $game_system.ates.get_season
  1015.     terrain = $game_system.ates.terrain
  1016.     temp = $game_system.ates.temp.to_s + ATES::TEMP_SUFFIX
  1017.     weather = $game_system.ates.weather.current_weather == -1 ? ATES::DEFAULT_WEATHER_NAME : $game_system.ates.weather.current_weather[0]
  1018.     tod = $game_system.ates.current_times[$game_system.ates.time_index][0]
  1019.     hday = $game_system.ates.holiday
  1020.     if hday != nil
  1021.       weekday = hday[0]
  1022.     end
  1023.     clock_text = ATES::CFORMAT.map { |ln| ln.clone }
  1024.     unless ATES::HOUR24
  1025.       suffix = "PM"
  1026.       if hours < 12
  1027.         suffix = "AM"
  1028.         hours = 12 if hours == 0
  1029.       elsif hours > 12
  1030.         suffix = "PM"
  1031.         hours -= 12
  1032.       end
  1033.     else
  1034.       suffix = ""
  1035.       hours = 24 if hours == 0
  1036.       hours = sprintf('%02d', hours)
  1037.     end
  1038.     colon = @odd % 2 == 0 ? " " : ":"
  1039.     clock_text.each { |ln|
  1040.       ln.gsub!(/%M/, minutes)
  1041.       ln.gsub!(/%H/, hours.to_s)
  1042.       ln.gsub!(/%A/, weekday)
  1043.       ln.gsub!(/%s/, " " + suffix)
  1044.       ln.gsub!(/:/, colon)
  1045.       ln.gsub!(/%m/, month.to_s)
  1046.       ln.gsub!(/%n/, month_name)
  1047.       ln.gsub!(/%l/, month_days.to_s)
  1048.       ln.gsub!(/%Y/, year.to_s)
  1049.       ln.gsub!(/%L/, year_days.to_s)
  1050.       ln.gsub!(/%d/, day.to_s)
  1051.       ln.gsub!(/%D/, yday.to_s)
  1052.       ln.gsub!(/%S/, season)
  1053.       ln.gsub!(/%w/, weather)
  1054.       ln.gsub!(/%t/, terrain)
  1055.       ln.gsub!(/%T/, temp)
  1056.       ln.gsub!(/%p/, tod)
  1057.     }
  1058.     if @odd % 2 == 0
  1059.       string = "#{hours} #{minutes}"
  1060.     else
  1061.       string = "#{hours}:#{minutes}"
  1062.     end
  1063.     string += " #{suffix}" unless ATES::HOUR24
  1064.     for i in 0...clock_text.length
  1065.       self.bitmap.draw_text_full(0, i * 32, self.bitmap.width, 32, clock_text[i], 1)
  1066.     end
  1067.     @odd = (@odd + 1) % 2
  1068.   end
  1069.  
  1070. end
  1071.  
  1072. #==============================================================================
  1073. # Scene_Map
  1074. #==============================================================================
  1075.  
  1076. class Scene_Map
  1077.  
  1078.   alias main_ates_later main
  1079.   def main
  1080.     @clock = Clock_Sprite.new if $game_system.show_clock
  1081.     main_ates_later
  1082.     @clock.dispose if @clock != nil
  1083.   end
  1084.  
  1085.   alias update_ates_later update
  1086.   def update
  1087.     $game_system.ates.update
  1088.     update_ates_later
  1089.     if $game_system.show_clock
  1090.       @clock = Clock_Sprite.new if @clock == nil
  1091.       @clock.draw if $game_system.ates.frame_count % 20 == 0
  1092.     elsif @clock != nil
  1093.       @clock.dispose
  1094.       @clock = nil
  1095.     end
  1096.   end
  1097.  
  1098. end
  1099.  
  1100. #==============================================================================
  1101. # Scene_Battle
  1102. #==============================================================================
  1103.  
  1104. class Scene_Battle
  1105.   alias update_ates_later update
  1106.   def update
  1107.     $game_system.ates.update
  1108.     update_ates_later
  1109.   end
  1110.  
  1111. end
  1112.  
  1113. #==============================================================================
  1114. # Game_Map
  1115. #==============================================================================
  1116.  
  1117. class Game_Map
  1118.   alias setup_ates_later setup
  1119.   def setup(map_id)
  1120.     $game_system.ates.update
  1121.     setup_ates_later(map_id)
  1122.     if $game_system.ates.show_weather and $game_system.ates.weather.current_weather and $game_system.ates.weather.current_weather != -1
  1123.       weather = $game_system.ates.weather.current_weather
  1124.       if weather[5].length > 0
  1125.         $game_map.fog_name = weather[5][0]
  1126.         $game_map.fog_opacity = weather[5][1]
  1127.         $game_map.fog_hue = weather[5][2]
  1128.         $game_map.fog_zoom = weather[5][3]
  1129.         $game_map.fog_sx = weather[5][4]
  1130.         $game_map.fog_sy = weather[5][5]
  1131.         $game_map.start_fog_tone_change(Tone.new(*weather[5][6]), 0)
  1132.       end
  1133.     end
  1134.  
  1135.     @events.each { |ev|
  1136.       ev = ev[1]
  1137.       if ev.list and ev.list.length > 0 and ev.list[0].code == 108 and ev.list[0].parameters[0] =~ /Terrain='(.+)'/
  1138.         $game_system.ates.terrain = $1
  1139.       end
  1140.     }
  1141.   end  
  1142. end
  1143.  
  1144. #==============================================================================
  1145. # Scene_Calendar
  1146. #==============================================================================
  1147.  
  1148. class Scene_Calendar
  1149.   def main
  1150.     # Make calendar window
  1151.     @calendar_window = Window_Calendar.new
  1152.     @calendar_window.active = true
  1153.     @calendar_window.z = 1000
  1154.     #@day_window = Window_Day.new
  1155.     #@day_window.z = 1010
  1156.     #@day_window.visible = false
  1157.     #@dir = rand(4)
  1158.     # Make spriteset
  1159.     @spriteset = Spriteset_Map.new
  1160.     # Execute transition
  1161.     Graphics.transition
  1162.     # Main loop
  1163.     loop do
  1164.       # Update game screen
  1165.       Graphics.update
  1166.       # Update input information
  1167.       Input.update
  1168.       # Frame update
  1169.       update
  1170.       # Abort loop if screen is changed
  1171.       if $scene != self
  1172.         break
  1173.       end
  1174.     end
  1175.     # Prepare for transition
  1176.     Graphics.freeze
  1177.     # Dispose of window
  1178.     @calendar_window.dispose
  1179.     #@day_window.dispose
  1180.     # Dispose of spriteset
  1181.     @spriteset.dispose
  1182.   end
  1183.  
  1184.   def update
  1185.     @calendar_window.update
  1186.     #@day_window.update
  1187.     #if @calendar_window.active
  1188.       #if Input.trigger?(Input::C)
  1189.       #  @day_window.visible = true
  1190.       #  @day_window.active = true
  1191.       #  @calendar_window.active = false
  1192.       #  @day_window.x, @day_window.y = 80, 80
  1193.       #  @day_window.appear(@dir)
  1194.       #  @dir = rand(4)
  1195.       #end
  1196.       if Input.trigger?(Input::B)
  1197.         $game_system.se_play($data_system.cancel_se)
  1198.         $scene = Scene_Map.new
  1199.       end
  1200.     #elsif @day_window.active
  1201.       #if Input.trigger?(Input::B)
  1202.       #  @day_window.disappear(@dir)
  1203.       #  @day_window.active = false
  1204.       #  @calendar_window.active = true
  1205.       #end
  1206.     #end
  1207.   end
  1208. end
  1209.  
  1210. #==============================================================================
  1211. # Window_Calendar
  1212. #==============================================================================
  1213.  
  1214. class Window_Calendar < Window_Base
  1215.   def initialize
  1216.     super(48, 48, 544, 384)
  1217.     self.contents = Bitmap.new(width - 32, height - 32)
  1218.     @month, @day, @wday, @year = $game_system.ates.time.mon, $game_system.ates.time.day, $game_system.ates.time.wday, $game_system.ates.time.year
  1219.     update
  1220.     refresh
  1221.   end
  1222.  
  1223.   def update
  1224.     prev_mon = @month
  1225.     if Input.repeat?(Input::LEFT)
  1226.       $game_system.se_play($data_system.cursor_se)
  1227.       continue = true
  1228.       @day -= 1
  1229.       if @day == 0
  1230.         @month -= 1
  1231.         if @month == 0
  1232.           unless @year == ATES::FYEAR
  1233.             @year -= 1
  1234.             @month = ATES::MONTHS.length
  1235.           else
  1236.             @day = 1
  1237.             @month = 1
  1238.             continue = false
  1239.           end
  1240.         end
  1241.         @day = ATES::MONTHDAYS[@month - 1]
  1242.       end
  1243.       if continue
  1244.         @wday = (@wday + ATES::WEEKDAYS.length - 1) % ATES::WEEKDAYS.length
  1245.         @wday = ATES::WEEKDAYS.length if @wday == 0
  1246.       end
  1247.     end
  1248.     if Input.repeat?(Input::RIGHT)
  1249.       $game_system.se_play($data_system.cursor_se)
  1250.       continue = true
  1251.       @day += 1
  1252.       if @day == ATES::MONTHDAYS[@month - 1] + 1
  1253.         @month += 1
  1254.         if @month == ATES::MONTHS.length + 1
  1255.           unless @year == ATES::LYEAR
  1256.             @year += 1
  1257.             @month = 1
  1258.           else
  1259.             @month = ATES::MONTHS.length
  1260.             @day = ATES::MONTHDAYS[@month - 1]
  1261.             continue = false
  1262.           end
  1263.         end
  1264.         @day = 1
  1265.       end
  1266.       if continue
  1267.         @wday = (@wday + 1) % ATES::WEEKDAYS.length
  1268.         @wday = ATES::WEEKDAYS.length if @wday == 0
  1269.       end
  1270.     end
  1271.     if Input.repeat?(Input::UP)
  1272.       $game_system.se_play($data_system.cursor_se)
  1273.       continue = true
  1274.       tmpday = @day
  1275.       @day -= ATES::WEEKDAYS.length
  1276.       if @day <= 0
  1277.         @month -= 1
  1278.         if @month == 0
  1279.           unless @year == ATES::FYEAR
  1280.             @year -= 1
  1281.             @month = ATES::MONTHS.length
  1282.           else
  1283.             @day = tmpday
  1284.             @month = 1
  1285.             continue = false
  1286.           end
  1287.         end
  1288.         if continue
  1289.           tmp = (@wday + ATES::WEEKDAYS.length - @day) % ATES::WEEKDAYS.length
  1290.           tmp = ATES::WEEKDAYS.length if tmp == 0
  1291.           if @wday > tmp
  1292.             tmp = tmp + ATES::WEEKDAYS.length - @wday
  1293.           else
  1294.             tmp = tmp - @wday
  1295.           end
  1296.           @day = ATES::MONTHDAYS[@month - 1]
  1297.           @day -= tmp
  1298.         end
  1299.       end
  1300.     end
  1301.     if Input.repeat?(Input::DOWN)
  1302.       $game_system.se_play($data_system.cursor_se)
  1303.       continue = true
  1304.       tmpday = @day
  1305.       @day += ATES::WEEKDAYS.length
  1306.       if @day >= ATES::MONTHDAYS[@month - 1] + 1
  1307.         @month += 1
  1308.         if @month == ATES::MONTHS.length + 1
  1309.           unless @year == ATES::LYEAR
  1310.             @year += 1
  1311.             @month = 1
  1312.           else
  1313.             @day = tmpday
  1314.             @month = ATES::MONTHS.length
  1315.             continue = false
  1316.           end
  1317.         end
  1318.         if continue
  1319.           tmp = (@wday + ATES::MONTHDAYS[@month - 2] - @day) % ATES::WEEKDAYS.length
  1320.           tmp = ATES::WEEKDAYS.length if tmp == 0
  1321.           if @wday <= tmp
  1322.             tmp -= ATES::WEEKDAYS.length
  1323.           end
  1324.           @day = @wday - tmp
  1325.         end
  1326.       end
  1327.     end
  1328.     super()
  1329.     refresh if prev_mon != @month
  1330.     row_count = (ATES::MONTHDAYS.max - 2) / ATES::WEEKDAYS.length + 2
  1331.     row_height = height - 116
  1332.     top_margin = ((row_height % row_count) / 2.0).ceil
  1333.     row_height -= row_height % row_count
  1334.     row_height /= row_count
  1335.     colwidth = width - 32
  1336.     margin = ((colwidth % ATES::WEEKDAY_ABBREVIATIONS.length) / 2.0).ceil
  1337.     colwidth -= colwidth % ATES::WEEKDAY_ABBREVIATIONS.length
  1338.     colwidth /= ATES::WEEKDAY_ABBREVIATIONS.length
  1339.     start_wday = (@wday + ATES::WEEKDAYS.length - (@day - 1) % ATES::WEEKDAYS.length) % ATES::WEEKDAYS.length
  1340.     start_wday = ATES::WEEKDAYS.length if start_wday == 0
  1341.     row = (@day + start_wday - 2) / ATES::WEEKDAYS.length
  1342.     self.cursor_rect.set(margin + (@wday - 1) * colwidth, 84 + top_margin + row * row_height, colwidth, 32)
  1343.   end
  1344.  
  1345.   def refresh
  1346.     self.contents.clear
  1347.     self.contents.font.size = 32
  1348.     self.contents.font.color = system_color
  1349.     self.contents.draw_text_full(Rect.new(0, 0, width - 32, 32), ATES::MONTHS[@month - 1] + " " + @year.to_s, 1)
  1350.     self.contents.font.size = 24
  1351.  
  1352.     colwidth = width - 32
  1353.     margin = ((colwidth % ATES::WEEKDAY_ABBREVIATIONS.length) / 2.0).ceil
  1354.     colwidth -= colwidth % ATES::WEEKDAY_ABBREVIATIONS.length
  1355.     colwidth /= ATES::WEEKDAY_ABBREVIATIONS.length
  1356.  
  1357.     for i in 0...ATES::WEEKDAY_ABBREVIATIONS.length
  1358.       self.contents.draw_text_full(Rect.new(margin + i * colwidth, 40, colwidth, 32), ATES::WEEKDAY_ABBREVIATIONS[i], 1)
  1359.     end
  1360.     self.contents.fill_rect(Rect.new(0, 76, width - 32, 2), system_color)
  1361.  
  1362.     row_count = (ATES::MONTHDAYS.max - 2) / ATES::WEEKDAYS.length + 2
  1363.     row_height = height - 116
  1364.     top_margin = ((row_height % row_count) / 2.0).ceil
  1365.     row_height -= row_height % row_count
  1366.     row_height /= row_count
  1367.     cur_wday = (@wday + ATES::WEEKDAYS.length - (@day - 1) % ATES::WEEKDAYS.length) % ATES::WEEKDAYS.length
  1368.     cur_wday = ATES::WEEKDAYS.length if cur_wday == 0
  1369.     start_wday = cur_wday
  1370.     cur_day = 1
  1371.     cur_row = (cur_day - 1) / 7
  1372.     while cur_day <= ATES::MONTHDAYS[@month - 1]
  1373.       if (cur_day == $game_system.ates.time.day and @month == $game_system.ates.time.mon and @year == $game_system.ates.time.year)
  1374.         self.contents.font.color = Color.new(240, 40, 40)
  1375.       elsif $game_system.ates.get_holiday(@month - 1, cur_day - 1, cur_wday) != nil
  1376.         self.contents.font.color = Color.new(150, 150, 0)
  1377.       else
  1378.         self.contents.font.color = normal_color
  1379.       end
  1380.       self.contents.draw_text_full(Rect.new(margin + (cur_wday - 1) * colwidth, 84 + top_margin + cur_row * row_height, colwidth, 32), cur_day.to_s, 1)
  1381.       cur_day += 1
  1382.       cur_wday = cur_wday + 1
  1383.       if cur_wday > ATES::WEEKDAYS.length
  1384.         cur_wday -= ATES::WEEKDAYS.length
  1385.         cur_row += 1
  1386.       end
  1387.     end
  1388.   end
  1389. end
  1390.  
  1391. #==============================================================================
  1392. # Window_Day
  1393. #==============================================================================
  1394.  
  1395. class Window_Day < Window_Base
  1396.   def initialize
  1397.     #(dir == 2 ? 320 : 48), (dir == 3 ? 240 : 48), (dir % 2 == 0 ? 272 : 544), (dir % 2 == 1 ? 192 : 384)
  1398.     super(80, 80, 480, 320)
  1399.     self.contents = Bitmap.new(width - 32, height - 32)
  1400.   end
  1401.  
  1402.   def appear(dir, duration = 40)
  1403.     @d_pos = [self.x, self.y]
  1404.     case dir
  1405.     when 0:
  1406.       self.x = -480
  1407.     when 1:
  1408.       self.y = -320
  1409.     when 2:
  1410.       self.x = 640
  1411.     when 3:
  1412.       self.y = 480
  1413.     end
  1414.     @s_pos = [self.x, self.y]
  1415.     @dir = dir
  1416.     @duration = duration
  1417.     @frames = 0
  1418.     @moving = true
  1419.   end
  1420.  
  1421.   def disappear(dir, duration = 40)
  1422.     @s_pos = [self.x, self.y]
  1423.     case dir
  1424.     when 0:
  1425.       self.x += 560
  1426.     when 1:
  1427.       self.y -= 400
  1428.     when 2:
  1429.       self.x += 560
  1430.     when 3:
  1431.       self.y += 400
  1432.     end
  1433.     @d_pos = [self.x, self.y]
  1434.     self.x, self.y = *@s_pos
  1435.     @dir = dir
  1436.     @duration = duration
  1437.     @frames = 0
  1438.     @moving = true
  1439.   end
  1440.  
  1441.   def update
  1442.     if @moving
  1443.       self.x = (@d_pos[0] * @frames + @s_pos[0] * (@duration - @frames)) / @duration
  1444.       self.y = (@d_pos[1] * @frames + @s_pos[1] * (@duration - @frames)) / @duration
  1445.       @moving = ([self.x, self.y] != @d_pos)
  1446.       @frames += 1
  1447.     end
  1448.     super()
  1449.   end
  1450. end
  1451.  
  1452. class Window_Text < Window_Base
  1453.   def initialize
  1454.     super(48, 48, 544, 384)
  1455.     self.contents = Bitmap.new(width - 32, height - 32)
  1456.  
  1457.     @dual_keys = ['`','1','2','3','4','5','6','7','8','9','0','A','B','C','D','E',
  1458.                   'F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U',
  1459.                   'V','W','X','Y','Z','-','=','[',']','\\',';','\'',',','.','/']
  1460.     @single_keys = ['NumberPad 0','NumberPad 1','NumberPad 2','NumberPad 3',
  1461.                     'NumberPad 4','NumberPad 5','NumberPad 6','NumberPad 7',
  1462.                     'NumberPad 8','NumberPad 9','Space','Enter','Tab']
  1463.     @chars1 = ['`','1','2','3','4','5','6','7','8','9','0','a','b','c','d','e','f',
  1464.                'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w',
  1465.                'x','y','z','-','=','[',']','/',';','\'',',','.','\\']
  1466.     @chars2 = ['~','!','@','#','$','%','^','&','*','(',')','A','B','C','D','E','F',
  1467.                'G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W',
  1468.                'X','Y','Z','_','+','{','}','?',':','"','<','>','|']
  1469.     @chars = ['0','1','2','3','4','5','6','7','8','9',' ','\n','\t']
  1470.  
  1471.     @text = ""
  1472.     @cursor = true
  1473.   end
  1474.  
  1475.   def update
  1476.     @dual_keys.each_with_index { |i, ind|
  1477.       if Input.repeat?(Input::Key[i])
  1478.         @text += (Input.press?(Input::Key['Shift']) ? @chars2[ind] : @chars1[ind])
  1479.       end
  1480.     }
  1481.     @single_keys.each_with_index { |i, ind|
  1482.       if Input.repeat?(Input::Key[i])
  1483.         @text += @chars[ind]
  1484.       end
  1485.     }
  1486.     if Input.repeat?(Input::Key['Backspace'])
  1487.       @text = @text.split('')
  1488.       tmp = @text.pop()
  1489.       if (tmp == 'n' or tmp == 't') and @text[@text.length - 1] == '\\'
  1490.         @text.pop()
  1491.       end
  1492.       @text = @text.join('')
  1493.     end
  1494.     @cursor = !@cursor if Graphics.frame_count % 20 == 0
  1495.     refresh
  1496.   end
  1497.  
  1498.   def refresh
  1499.     self.contents.clear
  1500.  
  1501.     tmp = @text.gsub(/((?:\\n)+)\z/, '')
  1502.     y_mod = $1 ? $1.length / 2 : 0
  1503.     x_pos = y_mod > 0
  1504.     lns = tmp.gsub(/\\t/,'    ').split(/\\n/)
  1505.     y = 0
  1506.     x = 0
  1507.     lns.each_with_index { |ln, ind|
  1508.       rect = self.contents.text_size(ln)
  1509.       rect.height = self.contents.text_size('a').height
  1510.       rect.width += 1 unless ln.index(/[vVAwf\/\\]\z/).nil?
  1511.       rect.y = y
  1512.       self.contents.draw_text(rect, ln)
  1513.       y += rect.height
  1514.       x = rect.width
  1515.     }
  1516.     #p lns if lns.length > 1
  1517.     height = self.contents.text_size('a').height
  1518.     y -= height unless lns.last.nil?
  1519.     y += y_mod * height
  1520.     x = (x_pos ? 0 : x + 1)
  1521.     self.contents.fill_rect(Rect.new(x, y, 2, height), Color.new(0, 0, 0)) if @cursor
  1522.     #@cursor = !@cursor
  1523.   end
  1524. end
  1525.  
  1526.  
  1527. if !$BlizzABS && !defined?(RMXOS) && (!$tons_version ||
  1528.   !TONS_OF_ADDONS::CUSTOM_CONTROLS)
  1529.  
  1530. #==============================================================================
  1531. # module Input
  1532. #==============================================================================
  1533.  
  1534. module Input
  1535.  
  1536.   #----------------------------------------------------------------------------
  1537.   # Simple ASCII table
  1538.   #----------------------------------------------------------------------------
  1539.   Key = {'A' => 65, 'B' => 66, 'C' => 67, 'D' => 68, 'E' => 69, 'F' => 70,
  1540.          'G' => 71, 'H' => 72, 'I' => 73, 'J' => 74, 'K' => 75, 'L' => 76,
  1541.          'M' => 77, 'N' => 78, 'O' => 79, 'P' => 80, 'Q' => 81, 'R' => 82,
  1542.          'S' => 83, 'T' => 84, 'U' => 85, 'V' => 86, 'W' => 87, 'X' => 88,
  1543.          'Y' => 89, 'Z' => 90,
  1544.          '0' => 48, '1' => 49, '2' => 50, '3' => 51, '4' => 52, '5' => 53,
  1545.          '6' => 54, '7' => 55, '8' => 56, '9' => 57,
  1546.          'NumberPad 0' => 45, 'NumberPad 1' => 35, 'NumberPad 2' => 40,
  1547.          'NumberPad 3' => 34, 'NumberPad 4' => 37, 'NumberPad 5' => 12,
  1548.          'NumberPad 6' => 39, 'NumberPad 7' => 36, 'NumberPad 8' => 38,
  1549.          'NumberPad 9' => 33,
  1550.          'F1' => 112, 'F2' => 113, 'F3' => 114, 'F4' => 115, 'F5' => 116,
  1551.          'F6' => 117, 'F7' => 118, 'F8' => 119, 'F9' => 120, 'F10' => 121,
  1552.          'F11' => 122, 'F12' => 123,
  1553.          ';' => 186, '=' => 187, ',' => 188, '-' => 189, '.' => 190, '/' => 220,
  1554.          '\\' => 191, '\'' => 222, '[' => 219, ']' => 221, '`' => 192,
  1555.          'Backspace' => 8, 'Tab' => 9, 'Enter' => 13, 'Shift' => 16,
  1556.          'Left Shift' => 160, 'Right Shift' => 161, 'Left Ctrl' => 162,
  1557.          'Right Ctrl' => 163, 'Left Alt' => 164, 'Right Alt' => 165,
  1558.          'Ctrl' => 17, 'Alt' => 18, 'Esc' => 27, 'Space' => 32, 'Page Up' => 33,
  1559.          'Page Down' => 34, 'End' => 35, 'Home' => 36, 'Insert' => 45,
  1560.          'Delete' => 46, 'Arrow Left' => 37, 'Arrow Up' => 38,
  1561.          'Arrow Right' => 39, 'Arrow Down' => 40,
  1562.          'Mouse Left' => 1, 'Mouse Right' => 2, 'Mouse Middle' => 4,
  1563.          'Mouse 4' => 5, 'Mouse 5' => 6}
  1564. #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  1565. # START Configuration
  1566. #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  1567.   UP = [Key['Arrow Up']]
  1568.   LEFT = [Key['Arrow Left']]
  1569.   DOWN = [Key['Arrow Down']]
  1570.   RIGHT = [Key['Arrow Right']]
  1571.   A = [Key['Shift']]
  1572.   B = [Key['Esc'], Key['NumberPad 0'], Key['X']]
  1573.   C = [Key['Space'], Key['Enter'], Key['C']]
  1574.   X = [Key['A']]
  1575.   Y = [Key['S']]
  1576.   Z = [Key['D']]
  1577.   L = [Key['Q'], Key['Page Down']]
  1578.   R = [Key['W'], Key['Page Up']]
  1579.   F5 = [Key['F5']]
  1580.   F6 = [Key['F6']]
  1581.   F7 = [Key['F7']]
  1582.   F8 = [Key['F8']]
  1583.   F9 = [Key['F9']]
  1584.   SHIFT = [Key['Shift']]
  1585.   CTRL = [Key['Ctrl']]
  1586.   ALT = [Key['Alt']]
  1587. #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  1588. # END Configuration
  1589. #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  1590.   # All keys
  1591.   KEY_COUNT = 256
  1592.   ALL_KEYS = (0...KEY_COUNT).to_a
  1593.   # Win32 API calls
  1594.   GetKeyboardState = Win32API.new('user32', 'GetKeyboardState', 'P', 'I')
  1595.   GetKeyboardLayout = Win32API.new('user32', 'GetKeyboardLayout', 'L', 'L')
  1596.   MapVirtualKeyEx = Win32API.new('user32', 'MapVirtualKeyEx', 'IIL', 'I')
  1597.   ToUnicodeEx = Win32API.new('user32', 'ToUnicodeEx', 'LLPPILL', 'L')
  1598.   # some other constants
  1599.   DOWN_STATE_MASK = 0x80
  1600.   DEAD_KEY_MASK = 0x80000000
  1601.   # data
  1602.   @state = "\0" * KEY_COUNT
  1603.   @triggered = Array.new(KEY_COUNT, false)
  1604.   @pressed = Array.new(KEY_COUNT, false)
  1605.   @released = Array.new(KEY_COUNT, false)
  1606.   @repeatedKey = -1
  1607.   @repeatedCount = 0
  1608.   #----------------------------------------------------------------------------
  1609.   # update
  1610.   #  Updates input.
  1611.   #----------------------------------------------------------------------------
  1612.   def self.update
  1613.     # get current language layout
  1614.     @language_layout = GetKeyboardLayout.call(0)
  1615.     # get new keyboard state
  1616.     GetKeyboardState.call(@state)
  1617.     # this special code is used because Ruby 1.9.x does not return a char
  1618.     # when using String#[] but another String
  1619.     key = 0
  1620.     @state.each_byte {|byte|
  1621.         # if pressed state
  1622.         if (byte & DOWN_STATE_MASK) == DOWN_STATE_MASK
  1623.           # not released anymore
  1624.           @released[key] = false
  1625.           # if not pressed yet
  1626.           if !@pressed[key]
  1627.             # pressed and triggered
  1628.             @pressed[key] = true
  1629.             @triggered[key] = true
  1630.             @repeatedKey = key
  1631.             @repeatedCount = 0
  1632.           else
  1633.             # not triggered anymore
  1634.             @triggered[key] = false
  1635.           end
  1636.           # update of repeat counter
  1637.           if key == @repeatedKey
  1638.             @repeatedCount < 17 ? @repeatedCount += 1 : @repeatedCount = 15
  1639.           end
  1640.         # not released yet
  1641.         elsif !@released[key]
  1642.           # if still pressed
  1643.           if @pressed[key]
  1644.             # not triggered, pressed or repeated, but released
  1645.             @triggered[key] = false
  1646.             @pressed[key] = false
  1647.             @released[key] = true
  1648.             if key == @repeatedKey
  1649.               @repeatedKey = -1
  1650.               @repeatedCount = 0
  1651.             end
  1652.           end
  1653.         else
  1654.           # not released anymore
  1655.           @released[key] = false
  1656.         end
  1657.         key += 1}
  1658.   end
  1659.   #----------------------------------------------------------------------------
  1660.   # dir4
  1661.   #  4 direction check.
  1662.   #----------------------------------------------------------------------------
  1663.   def self.dir4
  1664.     return 2 if self.press?(DOWN)
  1665.     return 4 if self.press?(LEFT)
  1666.     return 6 if self.press?(RIGHT)
  1667.     return 8 if self.press?(UP)
  1668.     return 0
  1669.   end
  1670.   #----------------------------------------------------------------------------
  1671.   # dir8
  1672.   #  8 direction check.
  1673.   #----------------------------------------------------------------------------
  1674.   def self.dir8
  1675.     down = self.press?(DOWN)
  1676.     left = self.press?(LEFT)
  1677.     return 1 if down && left
  1678.     right = self.press?(RIGHT)
  1679.     return 3 if down && right
  1680.     up = self.press?(UP)
  1681.     return 7 if up && left
  1682.     return 9 if up && right
  1683.     return 2 if down
  1684.     return 4 if left
  1685.     return 6 if right
  1686.     return 8 if up
  1687.     return 0
  1688.   end
  1689.   #----------------------------------------------------------------------------
  1690.   # trigger?
  1691.   #  Test if key was triggered once.
  1692.   #----------------------------------------------------------------------------
  1693.   def self.trigger?(keys)
  1694.     keys = [keys] unless keys.is_a?(Array)
  1695.     return keys.any? {|key| @triggered[key]}
  1696.   end
  1697.   #----------------------------------------------------------------------------
  1698.   # press?
  1699.   #  Test if key is being pressed.
  1700.   #----------------------------------------------------------------------------
  1701.   def self.press?(keys)
  1702.     keys = [keys] unless keys.is_a?(Array)
  1703.     return keys.any? {|key| @pressed[key]}
  1704.   end
  1705.   #----------------------------------------------------------------------------
  1706.   # repeat?
  1707.   #  Test if key is being pressed for repeating.
  1708.   #----------------------------------------------------------------------------
  1709.   def self.repeat?(keys)
  1710.     keys = [keys] unless keys.is_a?(Array)
  1711.     return (@repeatedKey >= 0 && keys.include?(@repeatedKey) &&
  1712.         (@repeatedCount == 1 || @repeatedCount == 16))
  1713.   end
  1714.   #----------------------------------------------------------------------------
  1715.   # release?
  1716.   #  Test if key was released.
  1717.   #----------------------------------------------------------------------------
  1718.   def self.release?(keys)
  1719.     keys = [keys] unless keys.is_a?(Array)
  1720.     return keys.any? {|key| @released[key]}
  1721.   end
  1722.   #----------------------------------------------------------------------------
  1723.   # get_character
  1724.   #  vk - virtual key
  1725.   #  Gets the character from keyboard input using the input locale identifier
  1726.   #  (formerly called keyboard layout handles).
  1727.   #----------------------------------------------------------------------------
  1728.   def self.get_character(vk)
  1729.     # get corresponding character from virtual key
  1730.     c = MapVirtualKeyEx.call(vk, 2, @language_layout)
  1731.     # stop if character is non-printable and not a dead key
  1732.     return '' if c < 32 && (c & DEAD_KEY_MASK != DEAD_KEY_MASK)
  1733.     # get scan code
  1734.     vsc = MapVirtualKeyEx.call(vk, 0, @language_layout)
  1735.     # result string is never longer than 4 bytes (Unicode)
  1736.     result = "\0" * 4
  1737.     # get input string from Win32 API
  1738.     length = ToUnicodeEx.call(vk, vsc, @state, result, 4, 0, @language_layout)
  1739.     return (length == 0 ? '' : result)
  1740.   end
  1741.   #----------------------------------------------------------------------------
  1742.   # get_input_string
  1743.   #  Gets the string that was entered using the keyboard over the input locale
  1744.   #  identifier (formerly called keyboard layout handles).
  1745.   #----------------------------------------------------------------------------
  1746.   def self.get_input_string
  1747.     result = ''
  1748.     # check every key
  1749.     ALL_KEYS.each {|key|
  1750.         # if repeated
  1751.         if self.repeat?(key)
  1752.           # get character from keyboard state
  1753.           c = self.get_character(key)
  1754.           # add character if there is a character
  1755.           result += c if c != ''
  1756.         end}
  1757.     # empty if result is empty
  1758.     return '' if result == ''
  1759.     # convert string from Unicode to UTF-8
  1760.     return self.unicode_to_utf8(result)
  1761.   end
  1762.   #----------------------------------------------------------------------------
  1763.   # unicode_to_utf8
  1764.   #  string - string in Unicode format
  1765.   #  Converts a string from Unicode format to UTF-8 format as RGSS does not
  1766.   #  support Unicode.
  1767.   #----------------------------------------------------------------------------
  1768.   def self.unicode_to_utf8(string)
  1769.     result = ''
  1770.     # L* format means a bunch of 4-byte wide-chars
  1771.     string.unpack('L*').each {|c|
  1772.         # characters under 0x80 are 1 byte characters
  1773.         if c < 0x0080
  1774.           result += c.chr
  1775.         # other characters under 0x800 are 2 byte characters
  1776.         elsif c < 0x0800
  1777.           result += (0xC0 | (c >> 6)).chr
  1778.           result += (0x80 | (c & 0x3F)).chr
  1779.         # other characters under 0x10000 are 3 byte characters
  1780.         elsif c < 0x10000
  1781.           result += (0xE0 | (c >> 12)).chr
  1782.           result += (0x80 | ((c >> 6) & 0x3F)).chr
  1783.           result += (0x80 | (c & 0x3F)).chr
  1784.         # other characters under 0x200000 are 4 byte characters
  1785.         elsif c < 0x200000
  1786.           result += (0xF0 | (c >> 18)).chr
  1787.           result += (0x80 | ((c >> 12) & 0x3F)).chr
  1788.           result += (0x80 | ((c >> 6) & 0x3F)).chr
  1789.           result += (0x80 | (c & 0x3F)).chr
  1790.         # other characters under 0x4000000 are 5 byte characters
  1791.         elsif c < 0x4000000
  1792.           result += (0xF8 | (c >> 24)).chr
  1793.           result += (0x80 | ((c >> 18) & 0x3F)).chr
  1794.           result += (0x80 | ((c >> 12) & 0x3F)).chr
  1795.           result += (0x80 | ((c >> 6) & 0x3F)).chr
  1796.           result += (0x80 | (c & 0x3F)).chr
  1797.         # other characters under 0x80000000 are 6 byte characters
  1798.         elsif c < 0x80000000
  1799.           result += (0xFC | (c >> 30)).chr
  1800.           result += (0x80 | ((c >> 24) & 0x3F)).chr
  1801.           result += (0x80 | ((c >> 18) & 0x3F)).chr
  1802.           result += (0x80 | ((c >> 12) & 0x3F)).chr
  1803.           result += (0x80 | ((c >> 6) & 0x3F)).chr
  1804.           result += (0x80 | (c & 0x3F)).chr
  1805.         end}
  1806.     return result
  1807.   end
  1808. end
  1809. end
     
作者: 欧买歌    时间: 2015-8-27 22:57
https://rpg.blue/forum.php?mod=viewthread&tid=373991
作者: creeper0924    时间: 2015-8-27 23:24
欧买歌 发表于 2015-8-27 22:57
https://rpg.blue/forum.php?mod=viewthread&tid=373991

有没有显示出来的脚本??
比如画面右上角显示一个框框=》
XX年XX月XX日 XX:XX时
作者: VIPArcher    时间: 2015-8-28 11:38
本帖最后由 RyanBern 于 2015-8-28 14:37 编辑

自己去找个显示变量之类的窗口脚本然后显示
  1. Time.new.strftime("%Y年%m月%d日 %X时")
复制代码

========================禁止追问分割线============================
作者: chd114    时间: 2015-8-29 22:36
以前看到过的一个办法···t=Time.new
p t.min就是分钟什么的···




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1