Guest User

Untitled

a guest
Nov 17th, 2016
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 63.19 KB | None | 0 0
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  2. # Dynamic Time and Light System
  3. # Version: 2.05
  4. # Author: TimeKeeper
  5. # Date: 2014-10-05
  6. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  7. #
  8. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  9. # Introduction
  10. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  11. #
  12. # Formally: Advanced Dynamic Light System
  13. #
  14. # This system add dynamic light circle including a time system which vary the tint
  15. # of the night. The light circle can also be animated using a random pattern,
  16. # a wave pattern or a combination of both.
  17. #
  18. # The script is really fast. I found a 2 to 3 FPS drop with about 115 animated
  19. # light circle in a 50x50 map.
  20. #
  21. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  22. # Features
  23. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  24. #
  25. # - Really fast
  26. # - Dynamic light circle for the events
  27. # - Dynamic light circle for the player
  28. # - All light circle can be turn off on on with switch
  29. # - Time system which vary the night tint
  30. # - Night tinting color base on time of year
  31. # - Multiple night and time setting (climate)
  32. #
  33. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  34. # Instructions
  35. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  36. #
  37. #--------------------------------------------------------------------------
  38. # System activtion configuration
  39. #--------------------------------------------------------------------------
  40. #
  41. # To activate a function of this script you can set the part to activate in the
  42. # configuration or you one os the fallowing command with the script command of
  43. # the event:
  44. #
  45. # DTLS.Activate(value): Activate or deactivate the entire script
  46. # DTLS.ActivateTime(value): Activate or deactivate the time part
  47. # DTLS.ActivateTimeWindow(value): Activate or deactivate the time window
  48. # DTLS.ActivateNight(value): Activate or deactivate the night (dark
  49. # screen and light)
  50. # DTLS.ActivateLight(value): Activate or deactivate the light only
  51. #
  52. #--------------------------------------------------------------------------
  53. # Light circle basic configuration
  54. #--------------------------------------------------------------------------
  55. #
  56. # To create a light circle the first comment must start with either of the
  57. # following comment (The filename is optional):
  58. # light_event filename
  59. # light_player filename
  60. #
  61. # You can also add the following comment to modify to the light circle:
  62. # follow value
  63. # zoom value
  64. # opacity value
  65. # switch value
  66. #
  67. # The effect of the parameter:
  68. # - follow: The light will be in the direction of the event or player. It
  69. # require 4 picture with "_D", "_L", "_R" and "_U" after the
  70. # filename. The default value is false
  71. # - zoom: Change the size of the light. The default value if 1.0
  72. # - opacity: Change the opacity of the light. The default value if 255
  73. # - switch: Set a switch to turn of the light of that event or the player.
  74. # The default value if 0
  75. #
  76. # Those parameter will activate the light circle depending on the time of day.
  77. # Note: Adding both parameter will make the light always active.
  78. # night_only
  79. # day_only
  80. #
  81. # The effect of the parameter:
  82. # - night_only: Will activate the light circle when it's the night.
  83. # - day_only: Will activate the light circle when it's the day.
  84. #
  85. #--------------------------------------------------------------------------
  86. # Light circle animation configuration
  87. #--------------------------------------------------------------------------
  88. #
  89. # Those parameter add a random effect:
  90. # rand_zoom_frame value
  91. # rand_zoom value
  92. # rand_opacity_frame value
  93. # rand_opacity value
  94. #
  95. # The effect of the parameter:
  96. # - rand_zoom_frame and rand_opacity_frame:
  97. # The set the number of frame between the random update of
  98. # either the random zoom or opacity animation. I recommend not
  99. # updating every frame because it can cause weird graphical
  100. # glitch. The default value is 5.
  101. # - rand_zoom: The maximum value that the zoom can change. The default
  102. # value is 5
  103. # - rand_opacity: The maximum value that the opacity can change. The default
  104. # value is 5
  105. #
  106. # Those parameter add wave effect:
  107. # wave_zoom_frame value
  108. # wave_zoom value step
  109. # wave_opacity_frame value
  110. # wave_opacity value step
  111. #
  112. # The effect of the parameter:
  113. # - rand_zoom_frame and rand_opacity_frame:
  114. # The set the number of frame between the random update of
  115. # either the random zoom or opacity animation. I recommend not
  116. # updeting every frame because it can cause weird graphical
  117. # glitch. The default value is 5.
  118. # - wave_zoom: The maximum value that the zoom can change. And also set the
  119. # step the zoom will change every frame (the step is optional).
  120. # The default value is 0 and the default step is 0.01.
  121. # - wave_opacity: The maximum value that the opacity can change. And also set
  122. # the step the opacity will change every frame (the step is
  123. # optional). The default value is 0 and the default step is 0.01.
  124. #
  125. #--------------------------------------------------------------------------
  126. # Map setting
  127. #--------------------------------------------------------------------------
  128. #
  129. # To modify the setting of the map the first comment must start with the
  130. # following comment:
  131. # set_map
  132. #
  133. # To change the climate of a map you must use the following comment after
  134. # 'set_map':
  135. # climate value
  136. #
  137. # To create permanent night tint you must use the following comment after
  138. # 'set_map':
  139. # night red green blue alpha transition
  140. # - Transtion: This parameter will set the time for the transition
  141. # between the current color and the new color. This
  142. # parameter is optionnal.
  143. #
  144. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  145. # Compatibility
  146. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  147. #
  148. # Should be compatible with everything
  149. #
  150. # NOTE: Some change to improve the animation of the light circle make this
  151. # version of the script incompatible with previous configuration
  152. #
  153. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  154. # Credits and Thanks
  155. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  156. #
  157. # TimeKeeper
  158. # Fabien and kellessdee for the inspiration
  159. # ArcaneAlchemy for the idea of a Day and night system
  160. # schmoggi for the night transition idea
  161. #
  162. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  163.  
  164.  
  165. module DTLS
  166. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  167. # Start of the configuration
  168. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  169.  
  170. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  171. # * Activation configuration
  172. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  173. Activate = true
  174. ActivateTime = false
  175. ActivateTimeWindow = false
  176. ActivateNight = true
  177. ActivateLight = true
  178.  
  179. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  180. # * Time system configuration
  181. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  182.  
  183. #--------------------------------------------------------------------------
  184. # * Day and night switch
  185. #--------------------------------------------------------------------------
  186. IsNightSwitch = 1
  187. IsDaySwitch = 2
  188.  
  189. #--------------------------------------------------------------------------
  190. # * Time variable
  191. #--------------------------------------------------------------------------
  192. MinuteVariable = 1
  193. HourVariable = 2
  194. DayVariable = 3
  195. MonthVariable = 4
  196. YearVariable = 5
  197.  
  198. #--------------------------------------------------------------------------
  199. # * Initial time
  200. #--------------------------------------------------------------------------
  201. # Set the initial time = [minute, hour, day, month, year]
  202. # The initial time will ajust to the maximum time value if the time set is
  203. # invalid.
  204. InitialTime = [1023, 12, 27, 12, 0]
  205.  
  206. #--------------------------------------------------------------------------
  207. # * Time setup
  208. #--------------------------------------------------------------------------
  209. # Set the maximum of the number of hour in a day and minute in a hour
  210. DaySetup = [24, 60]
  211. # Set the name and the number of day for each month. The number of month in a
  212. # year will be set by the size of the array.
  213. MonthSetup = [['January', 31], ['February', 28], ['March', 31], ['April', 30],
  214. ['May', 31], ['June', 30], ['July', 31], ['August', 31], ['September', 30],
  215. ['October', 31], ['November', 30], ['December', 31]]
  216.  
  217. #--------------------------------------------------------------------------
  218. # * Time length
  219. #--------------------------------------------------------------------------
  220. # Set the number of minute between each update of the time window.
  221. CountLength = 5
  222. # Set the number of minute add each update.
  223. CountMinute = 1
  224.  
  225. #--------------------------------------------------------------------------
  226. # * Set the parameter of the season
  227. #--------------------------------------------------------------------------
  228. # Set the the setting for each season. The 'season_name' is use to get the
  229. # color of the night.
  230. #
  231. # Season = { 'climate_name' => [ first month, first day, 'season_name',
  232. # day_hour, day_minure, night_hour, night_minute ], ... ], ... }
  233. Season = {
  234. 'desert' => [[0, 0, 'summer', 5, 0, 19, 0]],
  235.  
  236. 'snow' => [[3, 21, 'snow_springfall', 9, 0, 15, 0],
  237. [6, 21, 'snow_summer', 6, 0, 18, 0],
  238. [9, 21, 'snow_springfall', 9, 0, 15, 0],
  239. [12, 21, 'snow_winter', 10, 0, 14, 0]]
  240. }
  241. # Set the default season when no climate are specified
  242. Season.default = [[3, 21, 'spring_fall', 6, 0, 18, 0],
  243. [6, 21, 'summer', 5, 0, 19, 0],
  244. [9, 21, 'spring_fall', 6, 0, 18, 0],
  245. [12, 21, 'winter', 7, 0, 17, 0]]
  246.  
  247. #--------------------------------------------------------------------------
  248. # * Set the time of the day and night
  249. #--------------------------------------------------------------------------
  250. # Set the color of the night at specific time of day.
  251. #
  252. # NightColor = { 'season_name' => [ [ hour, minute, red, green, blue,
  253. # alpha], ...], ... }
  254. NightColor = {
  255. # Normal climate and deset climat (summe only)
  256. 'winter' => [[0, 0, 230, 230, 230, 255], # Night
  257. [6, 0, 210, 210, 210, 255], # Sunrise
  258. [8, 0, 20, 20, 20, 255], # Dawn
  259. [12, 0, 0, 0, 0, 255], # Day
  260. [18, 0, 20, 20, 20, 255], # Sundown
  261. [20, 0, 210, 210, 210, 255]], # Dusk
  262.  
  263. 'spring_fall' => [[0, 0, 200, 200, 200, 255], # Night
  264. [5, 0, 180, 180, 180, 255], # Sunrise
  265. [7, 0, 20, 20, 20, 255], # Dawn
  266. [12, 0, 0, 0, 0, 255], # Day
  267. [17, 0, 20, 20, 20, 255], # Sundown
  268. [19, 0, 180, 180, 180, 255]], # Dusk
  269.  
  270. 'summer' => [[0, 0, 175, 175, 175, 255], # Night
  271. [4, 0, 155, 155, 155, 255], # Sunrise
  272. [6, 0, 20, 20, 20, 255], # Dawn
  273. [12, 0, 0, 0, 0, 255], # Day
  274. [16, 0, 20, 20, 20, 255], # Sundown
  275. [18, 0, 155, 155, 155, 255]], # Dusk
  276.  
  277. # Snow climate
  278. 'snow_winter' => [[0, 0, 240, 240, 240, 255], # Night
  279. [9, 0, 220, 220, 220, 255], # Sunrise
  280. [11, 0, 20, 20, 20, 255], # Dawn
  281. [12, 0, 0, 0, 0, 255], # Day
  282. [13, 0, 20, 20, 20, 255], # Sundown
  283. [15, 0, 220, 220, 220, 255]], # Dusk
  284.  
  285. 'snow_springfall' => [[0, 0, 230, 230, 230, 255], # Night
  286. [5, 0, 210, 210, 210, 255], # Sunrise
  287. [7, 0, 20, 20, 20, 255], # Dawn
  288. [12, 0, 0, 0, 0, 255], # Day
  289. [17, 0, 20, 20, 20, 255], # Sundown
  290. [19, 0, 210, 210, 210, 255]], # Dusk
  291.  
  292. 'snow_summer' => [[0, 0, 200, 200, 200, 255], # Night
  293. [4, 0, 180, 180, 180, 255], # Sunrise
  294. [6, 0, 20, 20, 20, 255], # Dawn
  295. [12, 0, 0, 0, 0, 255], # Day
  296. [16, 0, 20, 20, 20, 255], # Sundown
  297. [18, 0, 180, 180, 180, 255]], # Dusk
  298. }
  299. # Set the default night color when no season are specified.
  300. NightColor.default = [[0, 0, 175, 175, 175, 255], # Night
  301. [4, 0, 155, 155, 155, 255], # Sunrise
  302. [6, 0, 20, 20, 20, 255], # Dawn
  303. [12, 0, 0, 0, 0, 255], # Day
  304. [16, 0, 20, 20, 20, 255], # Sundown
  305. [18, 0, 155, 155, 155, 255]] # Dusk
  306.  
  307. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  308. # Configuration of the default value
  309. #-----------------------------------------------------------------------------
  310. # WARNING : Be carful when modifing those value, changing the default value
  311. # can cause weird graphical glitch. I chose the default value to have the
  312. # best looking animation.
  313. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  314.  
  315. #--------------------------------------------------------------------------
  316. # * Default value of the basic parameter
  317. #--------------------------------------------------------------------------
  318. DefaultPicture = 'light'
  319. DefaultFollow = false
  320. DefaultZoom = 1.0
  321. DefaultOpacity = 255
  322. DefaultSwitch = 0
  323.  
  324. #--------------------------------------------------------------------------
  325. # * Default value of the random animation
  326. #--------------------------------------------------------------------------
  327. DefaultRandZoomFrame = 5
  328. DefaultRandZoom = 0.0
  329. DefaultRandOpacityFrame = 5
  330. DefaultRandOpacity = 0.0
  331.  
  332. #--------------------------------------------------------------------------
  333. # * Default value of the wave animation
  334. #--------------------------------------------------------------------------
  335. DefaultWaveZoomFrame = 1
  336. DefaultWaveZoomMax = 0.0
  337. DefaultWaveZoomStep = 0.001
  338. DefaultWaveOpacityFrame = 5
  339. DefaultWaveOpacityMax = 0.0
  340. DefaultWaveOpacityStep = 1
  341.  
  342. #--------------------------------------------------------------------------
  343. # * Default value of the night only and day only switch
  344. #--------------------------------------------------------------------------
  345. DefaultNightOnly = false
  346. DefaultDayOnly = false
  347.  
  348. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  349. # End of the configuration
  350. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  351.  
  352. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  353. # Shortcut for the Time system
  354. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  355.  
  356. #--------------------------------------------------------------------------
  357. # * Shortcut for $game_map.ActivateTime
  358. #--------------------------------------------------------------------------
  359. def self.ActivateTime(bool)
  360. $game_system.activate_time = bool
  361. end
  362. #--------------------------------------------------------------------------
  363. # * Shortcut for $game_map.activate_time_window
  364. #--------------------------------------------------------------------------
  365. def self.ActivateTimeWindow(bool)
  366. $game_system.activate_time_window = bool
  367. end
  368. #--------------------------------------------------------------------------
  369. # * Shortcut for changing the climate
  370. #--------------------------------------------------------------------------
  371. def self.ChangeClimate(name)
  372. $game_system.time.change_climate(name)
  373. end
  374. #--------------------------------------------------------------------------
  375. # * Shortcut for setting the time to a specific date
  376. #--------------------------------------------------------------------------
  377. def self.SetTime(minute, hour, day, month, year)
  378. $game_system.time.set_time(minute, hour, day, month, year)
  379. end
  380.  
  381. #--------------------------------------------------------------------------
  382. # * Shortcut for $game_system.activate_dtls
  383. #--------------------------------------------------------------------------
  384. def self.Activate(bool)
  385. $game_system.activate_dtls = bool
  386. end
  387. #--------------------------------------------------------------------------
  388. # * Shortcut for $game_map.activate_night
  389. #--------------------------------------------------------------------------
  390. def self.ActivateNight(bool)
  391. $game_system.activate_night = bool
  392. end
  393. #--------------------------------------------------------------------------
  394. # * Shortcut for $game_map.activate_light
  395. #--------------------------------------------------------------------------
  396. def self.ActivateLight(bool)
  397. $game_system.activate_light = bool
  398. end
  399. #--------------------------------------------------------------------------
  400. # * Shortcut for adding minute
  401. #--------------------------------------------------------------------------
  402. def self.AddMinute(minute)
  403. $game_system.time.add_minute(minute)
  404. end
  405. #--------------------------------------------------------------------------
  406. # * Shortcut for adding hour
  407. #--------------------------------------------------------------------------
  408. def self.AddHour(hour)
  409. $game_system.time.add_hour(hour)
  410. end
  411. #--------------------------------------------------------------------------
  412. # * Shortcut for adding day
  413. #--------------------------------------------------------------------------
  414. def self.AddDay(day)
  415. $game_system.time.add_day(day)
  416. end
  417. #--------------------------------------------------------------------------
  418. # * Shortcut for adding month
  419. #--------------------------------------------------------------------------
  420. def self.AddMonth(month)
  421. $game_system.time.add_month(month)
  422. end
  423. #--------------------------------------------------------------------------
  424. # * Shortcut for adding year
  425. #--------------------------------------------------------------------------
  426. def self.AddYear(year)
  427. $game_system.time.add_year(year)
  428. end
  429.  
  430. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  431. # Shortcut for the Night system
  432. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  433.  
  434. #--------------------------------------------------------------------------
  435. # * Shortcut for $game_map.remove_light_player
  436. #--------------------------------------------------------------------------
  437. def self.ChangeNightColor(r, g, b, a, time = 0)
  438. $game_map.night_color = [r, g, b, a]
  439. $game_map.night_tansition = time
  440. end
  441. #--------------------------------------------------------------------------
  442. # * Shortcut for $game_map.remove_light_player
  443. #--------------------------------------------------------------------------
  444. def self.RemoveNightColor()
  445. $game_map.night_color = []
  446. $game_map.night_tansition = 0
  447. end
  448.  
  449. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  450. # Shortcut for the Light system
  451. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  452.  
  453. #--------------------------------------------------------------------------
  454. # * Shortcut for $game_map.change_light_event
  455. #--------------------------------------------------------------------------
  456. def self.ChangeEvent(event_id, filename = nil, follow = nil, zoom = nil,
  457. opacity = nil, switch = nil, rand = [], wave = [], sin = [], time = [])
  458. $game_map.change_light_event(event_id, filename, follow, zoom, opacity,
  459. switch, rand, wave, sin, time)
  460. end
  461. #--------------------------------------------------------------------------
  462. # * Shortcut for $game_map.remove_light_event
  463. #--------------------------------------------------------------------------
  464. def self.RemoveEvent(event_id)
  465. $game_map.remove_light_event(event_id)
  466. end
  467. #--------------------------------------------------------------------------
  468. # * Shortcut for $game_map.change_light_player
  469. #--------------------------------------------------------------------------
  470. def self.ChangePlayer(filename = nil, follow = nil, zoom = nil,
  471. opacity = nil, switch = nil, rand = [], wave = [], sin = [], time = [])
  472. $game_map.change_light_player(event_id, filename, follow, zoom, opacity,
  473. switch, rand, wave, sin, time)
  474. end
  475. #--------------------------------------------------------------------------
  476. # * Shortcut for $game_map.remove_light_player
  477. #--------------------------------------------------------------------------
  478. def self.RemovePlayer
  479. $game_map.remove_light_player
  480. end
  481.  
  482. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  483. # End of Shortcut
  484. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  485.  
  486. end
  487.  
  488.  
  489. #==============================================================================
  490. # ** Time_System
  491. #------------------------------------------------------------------------------
  492. # This class handles data the time system.
  493. #==============================================================================
  494.  
  495. class Time_System
  496. #--------------------------------------------------------------------------
  497. # * Public Instance Variables
  498. #--------------------------------------------------------------------------
  499. attr_reader :climate
  500. attr_accessor :minute
  501. attr_accessor :hour
  502. attr_accessor :day
  503. attr_accessor :month
  504. attr_accessor :year
  505. attr_reader :night_color
  506. attr_accessor :last_map
  507. #--------------------------------------------------------------------------
  508. # * Object Initialization
  509. #--------------------------------------------------------------------------
  510. def initialize
  511. # Initialize the season and climate
  512. @season = 0
  513. @climate = nil
  514. # Set the initial night color
  515. @night_color = DTLS::NightColor[DTLS::Season[@climate][@season][2]]
  516. # Set the initial day time and night time
  517. @time_day = DTLS::Season[@climate][@season][3] * 60 + DTLS::Season[@climate][@season][4]
  518. @time_night = DTLS::Season[@climate][@season][5] * 60 + DTLS::Season[@climate][@season][6]
  519. # Set the initial minute
  520. @minute = [(DTLS::InitialTime[4] - DTLS::InitialTime[4] % DTLS::CountMinute), 0].max
  521. # Set the initial hour
  522. @hour = [DTLS::InitialTime[3], 0].max
  523. # Set the initial day with a minimum of 1
  524. @day = [DTLS::InitialTime[2], 1].max
  525. # Set the initial month with a minimum of 1
  526. @month = [DTLS::InitialTime[1], 1].max
  527. # Set the initial year
  528. @year = [DTLS::InitialTime[0], 0].max
  529. # Update the time data
  530. check_time
  531. # Update the season data
  532. update_season
  533. end
  534. #--------------------------------------------------------------------------
  535. # * Get New Climate
  536. #--------------------------------------------------------------------------
  537. def change_climate(name)
  538. # Check if the new climate is diferent for the curent one
  539. if @climate != name
  540. # Change the climate name
  541. @climate = name
  542. # Update the season data
  543. update_season
  544. end
  545. end
  546. #--------------------------------------------------------------------------
  547. # * Get Date
  548. #--------------------------------------------------------------------------
  549. def get_date(month, day)
  550. # Set the number of day to the current date
  551. day_month = day
  552. # If its not the first month
  553. if @month > 1
  554. # Cycle from the first month to the current month
  555. (1..(month)).each { |i|
  556. # Add the nimber of day in the month to the current date
  557. day_month += DTLS::MonthSetup[i - 1][1]
  558. }
  559. end
  560. # Return the current date
  561. return day_month
  562. end
  563. #--------------------------------------------------------------------------
  564. # * Set Time
  565. #--------------------------------------------------------------------------
  566. def set_time(minute, hour, day, month, year)
  567. # Set the new minute with a minimum of 0
  568. @minute = [(minute - minute % DTLS::CountMinute), 0].max
  569. # Set the new hour with a minimum of 0
  570. @hour = [hour, 0].max
  571. # Set the new day with a minimum of 1
  572. @day = [day, 1].max
  573. # Set the new month with a minimum of 1
  574. @month = [month, 1].max
  575. # Set the new year with a minimum of 0
  576. @year = [year, 0].max
  577. # Check the time to put it in the right format
  578. check_time
  579. end
  580. #--------------------------------------------------------------------------
  581. # * Add minute
  582. #--------------------------------------------------------------------------
  583. def add_minute(minute)
  584. # Set the new minute with a minimum of 0
  585. @minute = [((@minute + minute) - (@minute + minute) % DTLS::CountMinute), 0].max
  586. # Check the time to put it in the right format
  587. check_time
  588. end
  589. #--------------------------------------------------------------------------
  590. # * Set Time
  591. #--------------------------------------------------------------------------
  592. def add_hour(hour)
  593. # Set the new hour with a minimum of 0
  594. @hour = [(@hour + hour), 0].max
  595. # Check the time to put it in the right format
  596. check_time
  597. end
  598. #--------------------------------------------------------------------------
  599. # * Set Time
  600. #--------------------------------------------------------------------------
  601. def sdd_day(day)
  602. # Set the new day with a minimum of 1
  603. @day = [(@day + day), 1].max
  604. # Check the time to put it in the right format
  605. check_time
  606. end
  607. #--------------------------------------------------------------------------
  608. # * Set Time
  609. #--------------------------------------------------------------------------
  610. def add_month(month)
  611. # Set the new month with a minimum of 1
  612. @month = [(@month + month), 1].max
  613. # Check the time to put it in the right format
  614. check_time
  615. end
  616. #--------------------------------------------------------------------------
  617. # * Set Time
  618. #--------------------------------------------------------------------------
  619. def add_year(year)
  620. # Set the new year with a minimum of 0
  621. @year = [(@year + year), 0].max
  622. # Check the time to put it in the right format
  623. check_time
  624. end
  625. #--------------------------------------------------------------------------
  626. # * Check Time
  627. #--------------------------------------------------------------------------
  628. def check_time
  629. # Check if the minutes are greater than the maximum value
  630. if @minute >= DTLS::DaySetup[1]
  631. # Increase the number of hour with the extra minutes
  632. @hour += (@minute / DTLS::DaySetup[1]).floor
  633. # Remove the extra minutes
  634. @minute %= DTLS::DaySetup[1]
  635. # Check if the hours are greater than the maximum value
  636. if @hour >= DTLS::DaySetup[0]
  637. # Increase the number of hour with the extra hours
  638. @day += (@hour / DTLS::DaySetup[0]).floor
  639. # Remove the extra hours
  640. @hour %= DTLS::DaySetup[0]
  641. # Check if the days are greater than the maximum value
  642. if @day > DTLS::MonthSetup[@month - 1][1]
  643. # Cylcle thought the extra month
  644. while @day > DTLS::MonthSetup[@month - 1][1] do
  645. # Remove the number of day in the month to the day
  646. @day -= DTLS::MonthSetup[@month - 1][1]
  647. # Increase the nunber of month by one
  648. @month += 1
  649. # Check if the month are greater than the maximum value
  650. if @month > DTLS::MonthSetup.size
  651. # Increase the number of year by one
  652. @year += 1
  653. # Remove the extra month
  654. @month %= DTLS::MonthSetup.size
  655. end
  656. end
  657. # Update the season data if the number of month change
  658. update_season
  659. end
  660. end
  661. end
  662. end
  663. #--------------------------------------------------------------------------
  664. # * Update Season
  665. #--------------------------------------------------------------------------
  666. def update_season
  667. # Check if the number of season is biger than 1
  668. if DTLS::Season[@climate].size > 1
  669. # Get the curent date
  670. current_date = get_date(@month, @day)
  671. # Sort the season by date
  672. season_data = DTLS::Season[@climate].sort { |x, y| get_date(x[0], x[1]) <=> get_date(y[0], y[1]) }
  673. # Cycle thought the season
  674. season_data.each_index { |s|
  675. # Get the next season id
  676. ns = (s + 1) % DTLS::Season[@climate].size
  677. # Get the date of the start and the end of the season
  678. season_start = get_date(season_data[s][0], season_data[s][1])
  679. season_end = get_date(season_data[ns][0], season_data[ns][1])
  680. # Check if the current date between the start and the end of the season
  681. if current_date >= season_start && current_date < season_end
  682. # Set the season id
  683. @season = s
  684. # Get the two ration for the linear interpolation
  685. ratio_start = (season_end - current_date).to_f / (season_end - season_start)
  686. ratio_end = (current_date - season_start).to_f / (season_end - season_start)
  687. # Get the night time color value
  688. night_time_start = DTLS::NightColor[DTLS::Season[@climate][s][2]]
  689. night_time_start.sort { |x,y| x[0] <=> y[0] }
  690. night_time_end = DTLS::NightColor[DTLS::Season[@climate][ns][2]]
  691. night_time_end.sort { |x,y| x[0] <=> y[0] }
  692. # Cycle throught the night color value
  693. night_time_start.each_index { |i|
  694. night_time_start[i].each_index { |j|
  695. @night_color[i][j] = night_time_start[i][j] * ratio_start + night_time_end[i][j] * ratio_end
  696. }
  697. }
  698. # Get the current season day and night time
  699. time_day_start = DTLS::Season[@climate][s][3] * 60 + DTLS::Season[@climate][s][4]
  700. time_night_start = DTLS::Season[@climate][s][5] * 60 + DTLS::Season[@climate][s][6]
  701. # Get the next season day and night time
  702. time_day_end = DTLS::Season[@climate][ns][3] * 60 + DTLS::Season[@climate][ns][4]
  703. time_night_end = DTLS::Season[@climate][ns][5] * 60 + DTLS::Season[@climate][ns][6]
  704. # Calculate the time of day and night
  705. @time_day = time_day_start * ratio_start + time_day_end * ratio_end
  706. @time_night = time_night_start * ratio_start + time_night_end * ratio_end
  707. end
  708. }
  709. else
  710. # Set the season id to 0
  711. @season = 0
  712. # Get the night color for the only season
  713. @night_color = DTLS::NightColor[DTLS::Season[@climate][0][2]]
  714. # Get the day time for the only season
  715. @time_day = DTLS::Season[@climate][0][3] * 60 + DTLS::Season[@climate][0][4]
  716. # Get the night time for the only season
  717. @time_night = DTLS::Season[@climate][0][5] * 60 + DTLS::Season[@climate][0][6]
  718. end
  719. end
  720. #--------------------------------------------------------------------------
  721. # * Day?
  722. #--------------------------------------------------------------------------
  723. def day?
  724. # Check if its the day
  725. return (@hour * 60 + @minute) <= @time_night && (@hour * 60 + @minute) >= @time_day
  726. end
  727. #--------------------------------------------------------------------------
  728. # * Day?
  729. #--------------------------------------------------------------------------
  730. def night?
  731. # Check if it's not the day
  732. return !day?
  733. end
  734. #--------------------------------------------------------------------------
  735. # * Season
  736. #--------------------------------------------------------------------------
  737. def season?
  738. # Return the season name
  739. return DTLS::Season[@climate][@season][2]
  740. end
  741. #--------------------------------------------------------------------------
  742. # * Frame Update
  743. #--------------------------------------------------------------------------
  744. def update
  745. # Check if the system and the time are activated
  746. if $game_system.activate_dtls && $game_system.activate_time
  747. # Increase the minute count
  748. @minute += DTLS::CountMinute
  749. # Update the time data
  750. check_time
  751. if day?
  752. $game_switches[DTLS::IsNightSwitch] = false
  753. $game_switches[DTLS::IsDaySwitch] = true
  754. else
  755. $game_switches[DTLS::IsNightSwitch] = true
  756. $game_switches[DTLS::IsDaySwitch] = false
  757. end
  758. $game_variables[DTLS::MinuteVariable] = @minute
  759. $game_variables[DTLS::HourVariable] = @hour
  760. $game_variables[DTLS::DayVariable] = @day
  761. $game_variables[DTLS::MonthVariable] = @month
  762. $game_variables[DTLS::YearVariable] = @year
  763. $game_map.need_refresh = true
  764. end
  765. end
  766. end
  767.  
  768.  
  769. #==============================================================================
  770. # ** Game_System
  771. #------------------------------------------------------------------------------
  772. # This class handles data surrounding the system. Backround music, etc.
  773. # is managed here as well. Refer to "$game_system" for the instance of
  774. # this class.
  775. #==============================================================================
  776.  
  777. class Game_System
  778. #--------------------------------------------------------------------------
  779. # * Public Instance Variables
  780. #--------------------------------------------------------------------------
  781. attr_reader :time
  782. attr_accessor :activate_dtls
  783. attr_accessor :activate_time
  784. attr_accessor :activate_night
  785. attr_accessor :activate_light
  786. attr_accessor :activate_time_window
  787. #--------------------------------------------------------------------------
  788. # * Object Initialization
  789. #--------------------------------------------------------------------------
  790. alias dtls_initialize initialize
  791. def initialize
  792. dtls_initialize
  793. # Set the activation parameter
  794. @activate_dtls = DTLS::Activate
  795. @activate_time = DTLS::ActivateTime
  796. @activate_night = DTLS::ActivateNight
  797. @activate_light = DTLS::ActivateLight
  798. @activate_time_window = DTLS::ActivateTimeWindow
  799. # Set the time system
  800. @time = Time_System.new
  801. end
  802. end
  803.  
  804.  
  805. #==============================================================================
  806. # ** Game_Map
  807. #------------------------------------------------------------------------------
  808. # This class handles the map. It includes scrolling and passable determining
  809. # functions. Refer to "$game_map" for the instance of this class.
  810. #==============================================================================
  811.  
  812. class Game_Map
  813. #--------------------------------------------------------------------------
  814. # * Public Instance Variables
  815. #--------------------------------------------------------------------------
  816. attr_accessor :light_event
  817. attr_accessor :light_player
  818. attr_accessor :night_color
  819. attr_accessor :night_tansition
  820. #--------------------------------------------------------------------------
  821. # * Setup
  822. # map_id : map ID
  823. #--------------------------------------------------------------------------
  824. alias dtls_setup setup
  825. def setup(map_id)
  826. dtls_setup (map_id)
  827. # Create the light event list
  828. @light_event = {}
  829. # Create the light player list
  830. @light_player = []
  831. # Create the night color
  832. @night_color = []
  833. # Night time transition
  834. @night_tansition = 0
  835. # Set all the light data list
  836. create_light_list
  837. end
  838. #--------------------------------------------------------------------------
  839. # * Create light list
  840. #--------------------------------------------------------------------------
  841. def create_light_list
  842. climate = nil
  843. # Verify all event on the map for light comment
  844. if @events != {} && @events != nil
  845. @events.each_value { |event|
  846. # Nest event if empty
  847. next if event.list == nil
  848. # Create light a light around the event if the first comment is
  849. # 'light_event'
  850. if event.list[0].code == 108
  851. # Add the light to the event light list
  852. if event.list[0].parameters[0].split[0] == 'light_event'
  853. # Add the light data to the light event list
  854. @light_event[event.id] = get_light_data(event)
  855.  
  856. # Set the player list
  857. elsif event.list[0].parameters[0].split[0] == 'light_player'
  858. # Get the filename after the creation comment on the first comment.
  859. # If their is no filename get the default name.
  860. filename = [DTLS::DefaultPicture, '']
  861. if event.list[0].parameters[0].split[1] != nil
  862. filename[0] = event.list[0].parameters[0].split[1]
  863. end
  864. # Add the light data to the light player list
  865. @light_player = get_light_data(event)
  866.  
  867. # Get constant night color
  868. elsif event.list[0].parameters[0].split[0] == 'set_map'
  869. # Cycle thought the other line of the event to see if their is other
  870. # configuration in comment
  871. (1..event.list.size).each { |i|
  872. # Check if the line is a comment
  873. if event.list[i] != nil && event.list[i].code == 108
  874. # Fix the value of the night to the specicied color
  875. if event.list[i].parameters[0].split[0] == 'night'
  876. @night_color = [event.list[i].parameters[0].split[1].to_i,
  877. event.list[i].parameters[0].split[2].to_i,
  878. event.list[i].parameters[0].split[3].to_i,
  879. event.list[i].parameters[0].split[4].to_i]
  880. if event.list[i].parameters[0].split[5] != nil
  881. @night_tansition = event.list[i].parameters[0].split[5].to_i
  882. end
  883. # Set the climate the the specified value
  884. elsif event.list[i].parameters[0].split[0] == 'climate'
  885. climate = event.list[0].parameters[0].split[1]
  886. end
  887. end
  888. }
  889. # Change the climate in the time system
  890. # $game_system.time.change_climate(climate)
  891. end
  892. end
  893. }
  894. end
  895. end
  896. #--------------------------------------------------------------------------
  897. # * Get Light Data
  898. #--------------------------------------------------------------------------
  899. def get_light_data(event)
  900. # Get the filename after the creation comment on the first comment.
  901. # If their is no filename get the default name.
  902. filename = DTLS::DefaultPicture
  903. if event.list[0].parameters[0].split[1] != nil
  904. filename = event.list[0].parameters[0].split[1]
  905. end
  906. # Set the default tag
  907. follow = DTLS::DefaultFollow
  908. # Set the default zoom
  909. zoom = DTLS::DefaultZoom
  910. # Set the default opacity
  911. opacity = DTLS::DefaultOpacity
  912. # Set the default switch
  913. switch = DTLS::DefaultSwitch
  914. # Set the default random animation variable
  915. rand = [DTLS::DefaultRandZoomFrame, DTLS::DefaultRandZoom, 0.0,
  916. DTLS::DefaultRandOpacityFrame, DTLS::DefaultRandOpacity, 0.0]
  917. # Set the default wave animation variable
  918. wave = [DTLS::DefaultWaveZoomFrame, DTLS::DefaultWaveZoomMax,
  919. DTLS::DefaultWaveZoomStep, 0.0, DTLS::DefaultWaveOpacityFrame,
  920. DTLS::DefaultWaveOpacityMax, DTLS::DefaultWaveOpacityStep, 0.0]
  921. # Set the day and night only tag
  922. time = [DTLS::DefaultNightOnly, DTLS::DefaultDayOnly]
  923. # Cycle thought the other line of the event to see if their is other
  924. # configuration in comment
  925. (1..event.list.size).each { |i|
  926. # Check if the line is a comment
  927. if event.list[i] != nil && event.list[i].code == 108
  928. # Get the tag to see if the light will follow the direction of the
  929. # event
  930. if event.list[i].parameters[0].split[0] == 'follow'
  931. follow = true
  932. # Get the value of the zoom on the light image
  933. elsif event.list[i].parameters[0].split[0] == 'zoom'
  934. zoom = event.list[i].parameters[0].split[1].to_f
  935. # Get the opacity of the light image
  936. elsif event.list[i].parameters[0].split[0] == 'opacity'
  937. opacity = event.list[i].parameters[0].split[1].to_i
  938. # Get the switch id that will turn on or off this particuliar light
  939. elsif event.list[i].parameters[0].split[0] == 'switch'
  940. switch = event.list[i].parameters[0].split[1].to_i
  941. # Get the number of frame beetween each random animation update
  942. elsif event.list[i].parameters[0].split[0] == 'rand_zoom_frame'
  943. rand[0] = event.list[i].parameters[0].split[1].to_i
  944. # Get the maximum value of the zoom for random animation
  945. elsif event.list[i].parameters[0].split[0] == 'rand_zoom'
  946. rand[1] = event.list[i].parameters[0].split[1].to_f
  947. # Get the number of frame beetween each random animation update
  948. elsif event.list[i].parameters[0].split[0] == 'rand_opacity_frame'
  949. rand[3] = event.list[i].parameters[0].split[1].to_i
  950. # Get the maximum value of the opacity for random animation
  951. elsif event.list[i].parameters[0].split[0] == 'rand_opacity'
  952. rand[4] = event.list[i].parameters[0].split[1].to_f
  953. # Get the number of frame beetween each wave zoom animation update
  954. elsif event.list[i].parameters[0].split[0] == 'wave_zoom_frame'
  955. wave[0] = event.list[i].parameters[0].split[1].to_i
  956. # Get the amplitude of zoom and the value increase between each
  957. # update.
  958. elsif event.list[i].parameters[0].split[0] == 'wave_zoom'
  959. wave[1] = event.list[i].parameters[0].split[1].to_f
  960. if event.list[i].parameters[0].split[2] != nil
  961. wave[2] = event.list[i].parameters[0].split[1].to_f
  962. end
  963. # Get the number of frame beetween each wave opacity animation
  964. # update
  965. elsif event.list[i].parameters[0].split[0] == 'wave_opacity_frame'
  966. wave[4] = event.list[i].parameters[0].split[1].to_i
  967. # Get the amplitude of opacity and the value increase between each
  968. # update.
  969. elsif event.list[i].parameters[0].split[0] == 'wave_opacity'
  970. wave[5] = event.list[i].parameters[0].split[1].to_f
  971. if event.list[i].parameters[0].split[2] != nil
  972. wave[6] = event.list[i].parameters[0].split[1].to_f
  973. end
  974. # Get the tag for the light that are only active during the night
  975. elsif event.list[i].parameters[0].split[0] == 'night_only'
  976. time[0] = true
  977. # Get the tag for the light that are only active during the day
  978. elsif event.list[i].parameters[0].split[0] == 'day_only'
  979. time[1] = true
  980. end
  981. end
  982. }
  983. # Add the light to the event light list
  984. return [filename, follow, zoom, opacity, switch, rand, wave, time]
  985. end
  986. #--------------------------------------------------------------------------
  987. # * Change Light Event
  988. #--------------------------------------------------------------------------
  989. def change_light_event(event_id, filename = nil, follow = nil, zoom = nil,
  990. opacity = nil, switch = nil, rand = [], wave = [], sin = [], time = [])
  991. # Get new filename
  992. filename = filename != nil ? filename : DTLS::DefaultPicture
  993. # Get new follow flag
  994. follow = follow != nil ? follow : DTLS::DefaultFollow
  995. # Get new zoom
  996. zoom = zoom != nil ? zoom : DTLS::DefaultZoom
  997. # Get new opacity
  998. opacity = opacity != nil ? opacity : DTLS::DefaultOpacity
  999. # Get new switch
  1000. switch = switch != nil ? switch : DTLS::DefaultSwitch
  1001. # Set the default random animation variable
  1002. rand = [DTLS::DefaultRandZoomFrame, DTLS::DefaultRandZoom, 0.0,
  1003. DTLS::DefaultRandOpacityFrame, DTLS::DefaultRandOpacity, 0.0]
  1004. if rand != []
  1005. # Get new random animation frame
  1006. rand[0] = rand[0] != nil ? rand[0] : DTLS::DefaultRandZoomFrame
  1007. # Get new random zoom animation
  1008. rand[1] = rand[1] != nil ? rand[1] : DTLS::DefaultRandZoom
  1009. # Set the random variable
  1010. rand[2] = 0.0
  1011. # Get new random animation frame
  1012. rand[3] = rand[3] != nil ? rand[3] : DTLS::DefaultRandOpacityFrame
  1013. # Get new random opacity animation
  1014. rand[4] = rand[4] != nil ? rand[4] : DTLS::DefaultRandOpacity
  1015. # Set the random variable
  1016. rand[5] = 0.0
  1017. end
  1018. # Set the default wave animation variable
  1019. wave = [DTLS::DefaultWaveZoomFrame, DTLS::DefaultWaveZoomMax,
  1020. DTLS::DefaultWaveZoomStep, 0.0, DTLS::DefaultWaveOpacityFrame,
  1021. DTLS::DefaultWaveOpacityMax, DTLS::DefaultWaveOpacityStep, 0.0]
  1022. if wave != []
  1023. # Get new wave zoom animation frame
  1024. wave[0] = wave[0] != nil ? wave[0] : DTLS::DefaultWaveZoomFrame
  1025. # Get new wave zoom animation
  1026. wave[1] = wave[1] != nil ? wave[1] : DTLS::DefaultWaveZoomMax
  1027. wave[2] = wave[2] != nil ? wave[2] : DTLS::DefaultWaveZoomStep
  1028. # Set the wave zoom variable
  1029. wave[3] = 0.0
  1030. # Get new wave zoom animation frame
  1031. wave[4] = wave[4] != nil ? wave[4] : DTLS::DefaultWaveOpacityFrame
  1032. # Get new wave opacity animation
  1033. wave[5] = wave[5] != nil ? wave[5] : DTLS::DefaultWaveOpacityMax
  1034. wave[6] = wave[6] != nil ? wave[6] : DTLS::DefaultWaveOpacityStep
  1035. # Set the wave opacity variable
  1036. wave[7] = 0.0
  1037. end
  1038. # Set the day and night only tag
  1039. time = [DTLS::DefaultNightOnly, DTLS::DefaultDayOnly]
  1040. if time != []
  1041. # Get the day only and night only tag
  1042. time[0] = time[0] != nil ? time[0] : DTLS::DefaultNightOnly
  1043. time[1] = time[1] != nil ? time[1] : DTLS::DefaultDayOnly
  1044. end
  1045. # Modified light event list
  1046. @light_event[event_id] = [filename, follow, zoom, opacity, switch, rand,
  1047. wave, time]
  1048. end
  1049. #--------------------------------------------------------------------------
  1050. # * Remove Light Event
  1051. #--------------------------------------------------------------------------
  1052. def remove_light_event(event_id)
  1053. @light_event.delete(event_id)
  1054. end
  1055. #--------------------------------------------------------------------------
  1056. # * Change Light Player
  1057. #--------------------------------------------------------------------------
  1058. def change_light_player(filename = nil, follow = nil, zoom = nil,
  1059. opacity = nil, switch = nil, rand = [], wave = [], sin = [], time = [])
  1060. # Get new filename
  1061. filename = filename != nil ? filename : DTLS::DefaultPicture
  1062. # Get new follow flag
  1063. follow = follow != nil ? follow : DTLS::DefaultFollow
  1064. # Get new zoom
  1065. zoom = zoom != nil ? zoom : DTLS::DefaultZoom
  1066. # Get new opacity
  1067. opacity = opacity != nil ? opacity : DTLS::DefaultOpacity
  1068. # Get new switch
  1069. switch = switch != nil ? switch : DTLS::DefaultSwitch
  1070. # Set the default random animation variable
  1071. rand = [DTLS::DefaultRandZoomFrame, DTLS::DefaultRandZoom, 0.0,
  1072. DTLS::DefaultRandOpacityFrame, DTLS::DefaultRandOpacity, 0.0]
  1073. if rand != []
  1074. # Get new random animation frame
  1075. rand[0] = rand[0] != nil ? rand[0] : DTLS::DefaultRandZoomFrame
  1076. # Get new random zoom animation
  1077. rand[1] = rand[1] != nil ? rand[1] : DTLS::DefaultRandZoom
  1078. # Set the random variable
  1079. rand[2] = 0.0
  1080. # Get new random animation frame
  1081. rand[3] = rand[3] != nil ? rand[3] : DTLS::DefaultRandOpacityFrame
  1082. # Get new random opacity animation
  1083. rand[4] = rand[4] != nil ? rand[4] : DTLS::DefaultRandOpacity
  1084. # Set the random variable
  1085. rand[5] = 0.0
  1086. end
  1087. # Set the default wave animation variable
  1088. wave = [DTLS::DefaultWaveZoomFrame, DTLS::DefaultWaveZoomMax,
  1089. DTLS::DefaultWaveZoomStep, 0.0, DTLS::DefaultWaveOpacityFrame,
  1090. DTLS::DefaultWaveOpacityMax, DTLS::DefaultWaveOpacityStep, 0.0]
  1091. if wave != []
  1092. # Get new wave zoom animation frame
  1093. wave[0] = wave[0] != nil ? wave[0] : DTLS::DefaultWaveZoomFrame
  1094. # Get new wave zoom animation
  1095. wave[1] = wave[1] != nil ? wave[1] : DTLS::DefaultWaveZoomMax
  1096. wave[2] = wave[2] != nil ? wave[2] : DTLS::DefaultWaveZoomStep
  1097. # Set the wave zoom variable
  1098. wave[3] = 0.0
  1099. # Get new wave zoom animation frame
  1100. wave[4] = wave[4] != nil ? wave[4] : DTLS::DefaultWaveOpacityFrame
  1101. # Get new wave opacity animation
  1102. wave[5] = wave[5] != nil ? wave[5] : DTLS::DefaultWaveOpacityMax
  1103. wave[6] = wave[6] != nil ? wave[6] : DTLS::DefaultWaveOpacityStep
  1104. # Set the wave opacity variable
  1105. wave[7] = 0.0
  1106. end
  1107. # Set the day and night only tag
  1108. time = [DTLS::DefaultNightOnly, DTLS::DefaultDayOnly]
  1109. if time != []
  1110. # Get the day only and night only tag
  1111. time[0] = time[0] != nil ? time[0] : DTLS::DefaultNightOnly
  1112. time[1] = time[1] != nil ? time[1] : DTLS::DefaultDayOnly
  1113. end
  1114. # Modified light event list
  1115. @light_player = [filename, follow, zoom, opacity, switch, rand, wave,
  1116. time]
  1117. end
  1118. #--------------------------------------------------------------------------
  1119. # * Remove Light Player
  1120. #--------------------------------------------------------------------------
  1121. def remove_light_player
  1122. @light_player = []
  1123. end
  1124. end
  1125.  
  1126.  
  1127. #==============================================================================
  1128. # ** Spriteset_Map
  1129. #------------------------------------------------------------------------------
  1130. # This class brings together map screen sprites, tilemaps, etc.
  1131. # It's used within the Scene_Map class.
  1132. #==============================================================================
  1133.  
  1134. class Spriteset_Map
  1135. #--------------------------------------------------------------------------
  1136. # * Object Initialization
  1137. #--------------------------------------------------------------------------
  1138. alias dtls_initialize initialize
  1139. def initialize
  1140. # Set the frame count for the animation
  1141. @frame = 0
  1142. # Get the color of the night sprite for the current time
  1143. @current_color = [0, 0, 0, 0]
  1144. # Get the time for the fixed night color transition
  1145. @night_tansition = $game_map.night_tansition
  1146. # Create the night and light sprite
  1147. @light = Sprite.new
  1148. @light.bitmap = Bitmap.new(640,480)
  1149. # Set the sprite blend type to substract
  1150. @light.blend_type = 2
  1151. # Set the other sprite parameter
  1152. @light.z = 100
  1153. @light.opacity = 255
  1154. # Original initialize
  1155. dtls_initialize
  1156. end
  1157. #--------------------------------------------------------------------------
  1158. # * Dispose
  1159. #--------------------------------------------------------------------------
  1160. alias dtls_dispose dispose
  1161. def dispose
  1162. # Original dispose
  1163. dtls_dispose
  1164. # Dispose of the light sprite
  1165. @light.dispose
  1166. # Reset the event and player light list
  1167. @light_list = {}
  1168. @player_light = []
  1169. end
  1170. #--------------------------------------------------------------------------
  1171. # * Frame Update
  1172. #--------------------------------------------------------------------------
  1173. alias dtls_update update
  1174. def update
  1175. # Original update
  1176. dtls_update
  1177. # Display light and night when night switch is off
  1178. if $game_system.activate_dtls && $game_system.activate_night
  1179. # Display the night
  1180. if $game_map.night_color != []
  1181. if @night_tansition > 0
  1182. night_color_corr = []
  1183. ratio_start = @night_tansition.to_f / $game_map.night_tansition
  1184. ratio_end = ($game_map.night_tansition - @night_tansition).to_f / $game_map.night_tansition
  1185. $game_map.night_color.each_index { |i|
  1186. night_color_corr[i] = @current_color[i] * ratio_start + $game_map.night_color[i] * ratio_end
  1187. }
  1188. # Draw the night with a fixe color
  1189. @light.bitmap.fill_rect(@light.bitmap.rect, Color.new(night_color_corr[0], night_color_corr[1], night_color_corr[2], night_color_corr[3]))
  1190. else
  1191. # Draw the night with a fixe color
  1192. @light.bitmap.fill_rect(@light.bitmap.rect, Color.new($game_map.night_color[0], $game_map.night_color[1], $game_map.night_color[2], $game_map.night_color[3]))
  1193. end
  1194. @night_tansition -= 1
  1195. else
  1196. # Get the night color value base on the time of day
  1197. update_night
  1198. # Draw the night for the correct time
  1199. @light.bitmap.fill_rect(@light.bitmap.rect, Color.new(@current_color[0], @current_color[1], @current_color[2], @current_color[3]))
  1200. end
  1201. # Display the light when the light switch is off
  1202. if $game_system.activate_light
  1203. # Update the light of the event
  1204. update_light_event
  1205. # Update the light of the player
  1206. update_light_player
  1207. end
  1208. else
  1209. # Draw an empty night when the switch is on
  1210. @light.bitmap.fill_rect(@light.bitmap.rect, Color.new(0,0,0,0))
  1211. end
  1212. # Increase the frame count for the animation
  1213. @frame += 1
  1214. end
  1215. #--------------------------------------------------------------------------
  1216. # * Frame Update (Night)
  1217. #--------------------------------------------------------------------------
  1218. def update_night
  1219. # Get the current time in minute
  1220. current_time = $game_system.time.hour * 60 + $game_system.time.minute
  1221. # Cycle throught
  1222. $game_system.time.night_color.each_index { |i|
  1223. j = (i + 1) % $game_system.time.night_color.size
  1224. time_last = $game_system.time.night_color[i][0] * 60 + $game_system.time.night_color[i][1]
  1225. time_next = $game_system.time.night_color[j][0] * 60 + $game_system.time.night_color[i][1]
  1226. # Check if the next time is smaller then the last time
  1227. if time_next < time_last
  1228. # Add a day because the next time is the first color value
  1229. time_next += 24 * 60
  1230. end
  1231. # Check if the current time is smaller then the last time
  1232. if current_time < time_last
  1233. current_time += 24 * 60
  1234. end
  1235. # Check if the current time is in between the last and the next time
  1236. if current_time >= time_last && current_time <= time_next
  1237. color_last = $game_system.time.night_color[i]
  1238. color_next = $game_system.time.night_color[j]
  1239. ratio_last = (time_next - current_time).to_f / (time_next - time_last)
  1240. ratio_next = (current_time - time_last).to_f / (time_next - time_last)
  1241. (0..3).each{ |c|
  1242. @current_color[c] = color_last[c + 2] * ratio_last + color_next[c + 2] * ratio_next
  1243. }
  1244. end
  1245. }
  1246. end
  1247. #--------------------------------------------------------------------------
  1248. # * Frame Update (Light event)
  1249. #--------------------------------------------------------------------------
  1250. def update_light_event
  1251. # Display the ligth when one or more light were created
  1252. if $game_map.light_event != {}
  1253. # Cycle through the light list
  1254. $game_map.light_event.each { |i, light|
  1255. # Display one light if it's switch is off
  1256. if (light[4] == 0 || (light[4] > 0 && !$game_switches[light[4]])) &&
  1257. (!light[7][0] || (light[7][0] && $game_system.time.night?)) &&
  1258. (!light[7][1] || (light[7][1] && $game_system.time.day?))
  1259. # Get the filename of the light
  1260. filename = light[0]
  1261. if light[1]
  1262. filename += '_D' if $game_map.events[i].direction == 2
  1263. filename += '_L' if $game_map.events[i].direction == 4
  1264. filename += '_R' if $game_map.events[i].direction == 6
  1265. filename += '_U' if $game_map.events[i].direction == 8
  1266. end
  1267. img = RPG::Cache.picture(filename)
  1268. # Get the random zoom effect modifier for the light
  1269. if @frame % light[5][0] == 0
  1270. if light[5][1] > 0
  1271. $game_map.light_event[i][5][2] = (rand(2) - 1) * light[5][1]
  1272. end
  1273. end
  1274. # Get the random opacity effect modifier for the light
  1275. if @frame % light[5][3] == 0
  1276. if light[5][4]
  1277. $game_map.light_event[i][5][5] = (rand(2) - 1) * light[5][5]
  1278. end
  1279. end
  1280. # Get the wave zoom effect modifier for the light
  1281. if @frame % light[6][0] == 0
  1282. if light[6][1] > 0
  1283. $game_map.light_event[i][6][3] += light[6][2]
  1284. if $game_map.light_event[i][6][3] > light[6][1]
  1285. $game_map.light_event[i][6][3] = light[6][1]
  1286. $game_map.light_event[i][6][2] *= -1
  1287. elsif $game_map.light_event[i][6][3] < -1 * light[6][1]
  1288. $game_map.light_event[i][6][3] = -1 * light[6][1]
  1289. $game_map.light_event[i][6][2] *= -1
  1290. end
  1291. end
  1292. end
  1293. # Get the wave opacity effect modifier for the light
  1294. if @frame % light[6][4] == 0
  1295. if light[6][5] > 0
  1296. $game_map.light_event[i][6][7] += light[6][6]
  1297. if $game_map.light_event[i][6][7] > light[6][5]
  1298. $game_map.light_event[i][6][7] = light[6][5]
  1299. $game_map.light_event[i][6][6] *= -1
  1300. elsif $game_map.light_event[i][6][7] < -1 * light[6][5]
  1301. $game_map.light_event[i][6][7] = -1 * light[6][5]
  1302. $game_map.light_event[i][6][6] *= -1
  1303. end
  1304. end
  1305. end
  1306. # Get the width and the height of the modified image
  1307. tx = img.width * (light[2] + $game_map.light_event[i][5][2] + $game_map.light_event[i][6][3])
  1308. ty = img.height * (light[2] + $game_map.light_event[i][5][2] + $game_map.light_event[i][6][3])
  1309. # Get the position of the light base on the position of the event
  1310. x = ($game_map.events[i].real_x - $game_map.display_x) / 4 - tx / 2 + 16
  1311. y = ($game_map.events[i].real_y - $game_map.display_y) / 4 - ty / 2 + 16
  1312. # Get the opacity of the light
  1313. op = [light[3] + $game_map.light_event[i][5][5] + $game_map.light_event[i][6][7], 255].min
  1314. # Draw the light on the light sprite
  1315. @light.bitmap.stretch_blt(Rect.new(x, y, tx, ty), img, img.rect, op)
  1316. end
  1317. }
  1318. end
  1319. end
  1320. #--------------------------------------------------------------------------
  1321. # * Frame Update (Light player)
  1322. #--------------------------------------------------------------------------
  1323. def update_light_player
  1324. # Display player light if it's switch is off
  1325. if $game_map.light_player != [] && ($game_map.light_player[4] == 0 ||
  1326. ($game_map.light_player[4] > 0 &&
  1327. !$game_switches[$game_map.light_player[4]])) &&
  1328. (!$game_map.light_player[7][0] || ($game_map.light_player[7][0] &&
  1329. $game_system.time.night?)) && (!$game_map.light_player[7][1] ||
  1330. ($game_map.light_player[7][1] && $game_system.time.day?))
  1331. # Get the filename of the light
  1332. filename = $game_map.light_player[0]
  1333. if $game_map.light_player[1]
  1334. filename += '_D' if $game_player.direction == 2
  1335. filename += '_L' if $game_player.direction == 4
  1336. filename += '_R' if $game_player.direction == 6
  1337. filename += '_U' if $game_player.direction == 8
  1338. end
  1339. img = RPG::Cache.picture(filename)
  1340. # Get the random zoom effect modifier for the light
  1341. if @frame % $game_map.light_player[5][0] == 0
  1342. if $game_map.light_player[5][1] > 0
  1343. $game_map.light_player[5][2] = (rand(2) - 1) * $game_map.light_player[5][1]
  1344. end
  1345. end
  1346. # Get the random opacity effect modifier for the light
  1347. if @frame % $game_map.light_player[5][3] == 0
  1348. if $game_map.light_player[5][4]
  1349. $game_map.light_player[5][5] = (rand(2) - 1) * $game_map.light_player[5][4]
  1350. end
  1351. end
  1352. # Get the wave zoom effect modifier for the light
  1353. if @frame % $game_map.light_player[6][0] == 0
  1354. if $game_map.light_player[6][1] > 0
  1355. $game_map.light_player[6][3] += $game_map.light_player[6][2]
  1356. if $game_map.light_player[6][3] > $game_map.light_player[6][1]
  1357. $game_map.light_player[6][3] = $game_map.light_player[6][1]
  1358. $game_map.light_player[6][2] *= -1
  1359. elsif $game_map.light_player[6][3] < -1 * $game_map.light_player[6][1]
  1360. $game_map.light_player[6][3] = -1 * $game_map.light_player[6][1]
  1361. $game_map.light_player[6][2] *= -1
  1362. end
  1363. end
  1364. end
  1365. # Get the wave opacity effect modifier for the light
  1366. if @frame % $game_map.light_player[6][4] == 0
  1367. if $game_map.light_player[6][5] > 0
  1368. $game_map.light_player[6][7] += $game_map.light_player[6][6]
  1369. if $game_map.light_player[6][7] > $game_map.light_player[6][5]
  1370. $game_map.light_player[6][7] = $game_map.light_player[6][5]
  1371. $game_map.light_player[6][6] *= -1
  1372. elsif $game_map.light_player[6][7] < -1 * $game_map.light_player[6][5]
  1373. $game_map.light_player[6][7] = -1 * $game_map.light_player[6][5]
  1374. $game_map.light_player[6][6] *= -1
  1375. end
  1376. end
  1377. end
  1378. # Get the width and the height of the modified image
  1379. tx = img.width * ($game_map.light_player[2] + $game_map.light_player[5][2] + $game_map.light_player[6][3])
  1380. ty = img.height * ($game_map.light_player[2] + $game_map.light_player[5][2] + $game_map.light_player[6][3])
  1381. # Get the position of the light base on the position of the event
  1382. x = ($game_player.real_x - $game_map.display_x) / 4 - tx / 2 + 16
  1383. y = ($game_player.real_y - $game_map.display_y) / 4 - ty / 2 + 16
  1384. # Get the opacity of the light
  1385. op = [$game_map.light_player[3] + $game_map.light_player[5][5] + $game_map.light_player[6][7], 255].min
  1386. # Draw the light on the light sprite
  1387. @light.bitmap.stretch_blt(Rect.new(x, y, tx, ty), img, img.rect, op)
  1388. end
  1389. end
  1390. end
  1391.  
  1392. #==============================================================================
  1393. # ** Scene_Map
  1394. #------------------------------------------------------------------------------
  1395. # This class performs map screen processing.
  1396. #==============================================================================
  1397.  
  1398. class Scene_Map
  1399. #--------------------------------------------------------------------------
  1400. # * Main Processing
  1401. #--------------------------------------------------------------------------
  1402. alias dtls_main main
  1403. def main
  1404. #@time_window = Window_Time.new
  1405. #if !$game_system.activate_time_window || !$game_system.activate_time
  1406. #@time_window.visible = false
  1407. #end
  1408. dtls_main
  1409. #@time_window.dispose
  1410. end
  1411. #--------------------------------------------------------------------------
  1412. # * Frame Update
  1413. #--------------------------------------------------------------------------
  1414. alias dtls_update update
  1415. def update
  1416. #$game_system.time.update
  1417. #if $game_system.activate_time_window && $game_system.activate_time
  1418. #@time_window.visible = true
  1419. #@time_window.refresh
  1420. #else
  1421. #@time_window.visible = false
  1422. #end
  1423. dtls_update
  1424. end
  1425. end
Add Comment
Please, Sign In to add comment