Advertisement
Guest User

Untitled

a guest
Jul 21st, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.17 KB | None | 0 0
  1. #===============================================================================
  2. # Sistema de día y noche
  3. #===============================================================================
  4. def pbGetTimeNow
  5. return Time.now
  6. end
  7.  
  8.  
  9.  
  10. module PBDayNight
  11. HourlyTones=[
  12. Tone.new(-142.5,-142.5,-22.5,68), # Medianoche
  13. Tone.new(-135.5,-135.5,-24, 68),
  14. Tone.new(-127.5,-127.5,-25.5,68),
  15. Tone.new(-127.5,-127.5,-25.5,68),
  16. Tone.new(-119, -96.3, -45.3,45.3),
  17. Tone.new(-51, -73.7, -73.7,22.7),
  18. Tone.new(17, -51, -102, 0), # 6AM
  19. Tone.new(14.2, -42.5, -85, 0),
  20. Tone.new(11.3, -34, -68, 0),
  21. Tone.new(8.5, -25.5, -51, 0),
  22. Tone.new(5.7, -17, -34, 0),
  23. Tone.new(2.8, -8.5, -17, 0),
  24. Tone.new(0, 0, 0, 0), # Mediodía
  25. Tone.new(0, 0, 0, 0),
  26. Tone.new(0, 0, 0, 0),
  27. Tone.new(0, 0, 0, 0),
  28. Tone.new(-3, -7, -2, 0),
  29. Tone.new(-10, -18, -5, 0),
  30. Tone.new(-36, -75, -13, 0), # 6PM
  31. Tone.new(-72, -136, -34, 3),
  32. Tone.new(-88.5, -133, -31, 34),
  33. Tone.new(-108.5,-129, -28, 68),
  34. Tone.new(-127.5,-127.5,-25.5,68),
  35. Tone.new(-142.5,-142.5,-22.5,68)
  36. ]
  37. @cachedTone=nil
  38. @dayNightToneLastUpdate=nil
  39. @oneOverSixty=1/60.0
  40.  
  41. # Devuelve verdadero si es de día.
  42. def self.isDay?(time=nil)
  43. time=pbGetTimeNow if !time
  44. return (time.hour>=6 && time.hour<20)
  45. end
  46.  
  47. # Devuelve verdadero si es de noche.
  48. def self.isNight?(time=nil)
  49. time=pbGetTimeNow if !time
  50. return (time.hour>=20 || time.hour<6)
  51. end
  52.  
  53. # Devuelve verdadero si es de mañana.
  54. def self.isMorning?(time=nil)
  55. time=pbGetTimeNow if !time
  56. return (time.hour>=6 && time.hour<12)
  57. end
  58.  
  59. # Devuelve verdadero si es de tarde.
  60. def self.isAfternoon?(time=nil)
  61. time=pbGetTimeNow if !time
  62. return (time.hour>=12 && time.hour<20)
  63. end
  64.  
  65. # Devuelve verdadero si está anocheciendo.
  66. def self.isEvening?(time=nil)
  67. time=pbGetTimeNow if !time
  68. return (time.hour>=17 && time.hour<20)
  69. end
  70.  
  71. # Devuelve un número representando la cantidad de luz de día.
  72. # 0=completamente de noche, 255=completamente de día
  73. def self.getShade
  74. time=pbGetDayNightMinutes
  75. time=(24*60)-time if time>(12*60)
  76. shade=255*time/(12*60)
  77. end
  78.  
  79. # Devuelve un objeto Tone (es decir, Tono) representando el tono de sombra sugerido
  80. # para la hora actual del día.
  81. def self.getTone()
  82. @cachedTone=Tone.new(0,0,0) if !@cachedTone
  83. return @cachedTone if !ENABLESHADING
  84. if !@dayNightToneLastUpdate || @dayNightToneLastUpdate!=Graphics.frame_count
  85. getToneInternal()
  86. @dayNightToneLastUpdate=Graphics.frame_count
  87. end
  88. return @cachedTone
  89. end
  90.  
  91. def self.pbGetDayNightMinutes
  92. now=pbGetTimeNow # Get the current in-game time
  93. return (now.hour*60)+now.min
  94. end
  95.  
  96. private
  97.  
  98. # Función interna
  99.  
  100. def self.getToneInternal()
  101. # Calculates the tone for the current frame, used for day/night effects
  102. realMinutes=pbGetDayNightMinutes
  103. hour=realMinutes/60
  104. minute=realMinutes%60
  105. tone=PBDayNight::HourlyTones[hour]
  106. nexthourtone=PBDayNight::HourlyTones[(hour+1)%24]
  107. # Calculate current tint according to current and next hour's tint and
  108. # depending on current minute
  109. @cachedTone.red=((nexthourtone.red-tone.red)*minute*@oneOverSixty)+tone.red
  110. @cachedTone.green=((nexthourtone.green-tone.green)*minute*@oneOverSixty)+tone.green
  111. @cachedTone.blue=((nexthourtone.blue-tone.blue)*minute*@oneOverSixty)+tone.blue
  112. @cachedTone.gray=((nexthourtone.gray-tone.gray)*minute*@oneOverSixty)+tone.gray
  113. end
  114. end
  115.  
  116.  
  117.  
  118. def pbDayNightTint(object)
  119. if !$scene.is_a?(Scene_Map)
  120. return
  121. else
  122. if ENABLESHADING && $game_map && pbGetMetadata($game_map.map_id,MetadataOutdoor)
  123. tone=PBDayNight.getTone()
  124. object.tone.set(tone.red,tone.green,tone.blue,tone.gray)
  125. else
  126. object.tone.set(0,0,0,0)
  127. end
  128. end
  129. end
  130.  
  131.  
  132.  
  133. #===============================================================================
  134. # Fases de la Luna y Zodíaco
  135. #===============================================================================
  136. # Determina la fase de la luna.
  137. # 0 - New Moon - Luna Nueva
  138. # 1 - Waxing Crescent - Luna Nueva Visible
  139. # 2 - First Quarter - Cuarto Creciente
  140. # 3 - Waxing Gibbous - Luna Gibosa Creciente
  141. # 4 - Full Moon - Luna Llena
  142. # 5 - Waning Gibbous - Luna Gibosa Menguante
  143. # 6 - Last Quarter - Cuarto Menguante
  144. # 7 - Waning Crescent - Luna Menguante
  145. def moonphase(time=nil) # en UTC
  146. time=pbGetTimeNow if !time
  147. transitions=[
  148. 1.8456618033125,
  149. 5.5369854099375,
  150. 9.2283090165625,
  151. 12.9196326231875,
  152. 16.6109562298125,
  153. 20.3022798364375,
  154. 23.9936034430625,
  155. 27.6849270496875]
  156. yy=time.year-((12-time.mon)/10.0).floor
  157. j=(365.25*(4712+yy)).floor + (((time.mon+9)%12)*30.6+0.5).floor + time.day+59
  158. j-=(((yy/100.0)+49).floor*0.75).floor-38 if j>2299160
  159. j+=(((time.hour*60)+time.min*60)+time.sec)/86400.0
  160. v=(j-2451550.1)/29.530588853
  161. v=((v-v.floor)+(v<0 ? 1 : 0))
  162. ag=v*29.53
  163. for i in 0...transitions.length
  164. return i if ag<=transitions[i]
  165. end
  166. return 0
  167. end
  168.  
  169. # Calculates the zodiac sign based on the given month and day:
  170. # 0 is Aries, 11 is Pisces. Month is 1 if January, and so on.
  171. def zodiac(month,day)
  172. time=[
  173. 3,21,4,19, # Aries - Aries
  174. 4,20,5,20, # Taurus - Tauro
  175. 5,21,6,20, # Gemini - Géminis
  176. 6,21,7,20, # Cancer - Cáncer
  177. 7,23,8,22, # Leo - Leo
  178. 8,23,9,22, # Virgo - Virgo
  179. 9,23,10,22, # Libra - Libra
  180. 10,23,11,21, # Scorpio - Escorpio
  181. 11,22,12,21, # Sagittarius - Sagitario
  182. 12,22,1,19, # Capricorn - Capricornio
  183. 1,20,2,18, # Aquarius - Acuario
  184. 2,19,3,20 # Pisces - Piscis
  185. ]
  186. for i in 0...12
  187. return i if month==time[i*4] && day>=time[i*4+1]
  188. return i if month==time[i*4+2] && day<=time[i*4+2]
  189. end
  190. return 0
  191. end
  192.  
  193. # Returns the opposite of the given zodiac sign.
  194. # 0 is Aries, 11 is Pisces.
  195. def zodiacOpposite(sign)
  196. return (sign+6)%12
  197. end
  198.  
  199. # 0 is Aries, 11 is Pisces.
  200. def zodiacPartners(sign)
  201. return [(sign+4)%12,(sign+8)%12]
  202. end
  203.  
  204. # 0 is Aries, 11 is Pisces.
  205. def zodiacComplements(sign)
  206. return [(sign+1)%12,(sign+11)%12]
  207. end
  208.  
  209. #===============================================================================
  210. # Días de la semana
  211. #===============================================================================
  212. def pbIsWeekday(wdayVariable,*arg)
  213. timenow=pbGetTimeNow
  214. wday=timenow.wday
  215. ret=false
  216. for wd in arg
  217. ret=true if wd==wday
  218. end
  219. if wdayVariable>0
  220. $game_variables[wdayVariable]=[
  221. _INTL("Domingo"),
  222. _INTL("Lunes"),
  223. _INTL("Martes"),
  224. _INTL("Miércoles"),
  225. _INTL("Jueves"),
  226. _INTL("Viernes"),
  227. _INTL("Sábado")][wday]
  228. $game_map.need_refresh = true if $game_map
  229. end
  230. return ret
  231. end
  232.  
  233. #===============================================================================
  234. # Meses
  235. #===============================================================================
  236. def pbIsMonth(monVariable,*arg)
  237. timenow=pbGetTimeNow
  238. thismon=timenow.mon
  239. ret=false
  240. for wd in arg
  241. ret=true if wd==thismon
  242. end
  243. if monVariable>0
  244. $game_variables[monVariable]=[
  245. _INTL("Enero"),
  246. _INTL("Febrero"),
  247. _INTL("Marzo"),
  248. _INTL("Abril"),
  249. _INTL("Mayo"),
  250. _INTL("Junio"),
  251. _INTL("Julio"),
  252. _INTL("Agosto"),
  253. _INTL("Septiembre"),
  254. _INTL("Octubre"),
  255. _INTL("Noviembre"),
  256. _INTL("Diciembre")][thismon-1]
  257. $game_map.need_refresh = true if $game_map
  258. end
  259. return ret
  260. end
  261.  
  262. def pbGetAbbrevMonthName(month)
  263. return ["",
  264. _INTL("Ene."),
  265. _INTL("Feb."),
  266. _INTL("Mar."),
  267. _INTL("Abr."),
  268. _INTL("May"),
  269. _INTL("Jun."),
  270. _INTL("Jul."),
  271. _INTL("Ago."),
  272. _INTL("Sep."),
  273. _INTL("Oct."),
  274. _INTL("Nov."),
  275. _INTL("Dic.")][month]
  276. end
  277.  
  278. #===============================================================================
  279. # Estaciones
  280. #===============================================================================
  281. def pbGetSeason
  282. return (pbGetTimeNow.mon-1)%4
  283. end
  284.  
  285. def pbIsSeason(seasonVariable,*arg)
  286. thisseason=pbGetSeason
  287. ret=false
  288. for wd in arg
  289. ret=true if wd==thisseason
  290. end
  291. if seasonVariable>0
  292. $game_variables[seasonVariable]=[
  293. _INTL("Primavera"),
  294. _INTL("Verano"),
  295. _INTL("Otoño"),
  296. _INTL("Invierno")][thisseason]
  297. $game_map.need_refresh = true if $game_map
  298. end
  299. return ret
  300. end
  301.  
  302. def pbIsSpring; return pbIsSeason(0,0); end # Ene, May, Sep
  303. def pbIsSummer; return pbIsSeason(0,1); end # Feb, Jun, Oct
  304. def pbIsAutumn; return pbIsSeason(0,2); end # Mar, Jul, Nov
  305. def pbIsFall; return pbIsAutumn; end
  306. def pbIsWinter; return pbIsSeason(0,3); end # Abr, Ago, Dic
  307.  
  308. def pbGetSeasonName(season)
  309. return [_INTL("Primavera"),
  310. _INTL("Verano"),
  311. _INTL("Otoño"),
  312. _INTL("Invierno")][season]
  313. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement