Advertisement
ICF-Soft

ICF-Soft Time Utility 1.02 RPG Maker MV

Jul 16th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // ICF-Soft Plugins - Time Utility
  3. // ICFSoft_TimeUtil.js
  4. //=============================================================================
  5.  
  6. var Imported = Imported || {};
  7. Imported.ICFSoft_TimeUtil = true;
  8.  
  9. var ICF = ICF || {};
  10. ICF.TimeUtil = ICF.TimeUtil || {};
  11.  
  12. //=============================================================================
  13.  /*:
  14.  * @plugindesc v1.02 This plugin stores date and time in game variables
  15.  * for diverse pourposes.
  16.  * @author ICF-Soft [http://icfsoft.blogspot.com.es/]
  17.  *
  18.  * @param Year Var
  19.  * @desc A variable where store year.
  20.  * @default 0
  21.  *
  22.  * @param Month Var
  23.  * @desc A variable where store month from 1 to 12.
  24.  * @default 0
  25.  *
  26.  * @param Day Var
  27.  * @desc A variable where store day from 1 to 31.
  28.  * @default 0
  29.  *
  30.  * @param Hour Var
  31.  * @desc A variable where store hour.
  32.  * @default 0
  33.  *
  34.  * @param Minute Var
  35.  * @desc A variable where store minute.
  36.  * @default 0
  37.  *
  38.  * @param Week Var
  39.  * @desc A variable where store the day of the week.
  40.  * Week starts with Sunday as 0.
  41.  * @default 0
  42.  *
  43.  * @param Month and day
  44.  * @desc A variable where store a month and day combination.
  45.  * @default 0
  46.  *
  47.  * @param Time travel
  48.  * @desc A variable where store a time offset.
  49.  * @default 0
  50.  *
  51.  * @param Fixed Month and day
  52.  * @desc All days you want to check separated with spaces.
  53.  * Must be month and day combination (see help).
  54.  * @default 101 102
  55.  *
  56.  * @param Fixed Integer checks
  57.  * @desc Respective integers to store if there is dates are.
  58.  * @default 0 0
  59.  *
  60.  * @param Variable Month and day
  61.  * @desc All variables where days you want to check are stored separated
  62.  * with spaces. Must be stored as month and day combination (see help).
  63.  * @default
  64.  *
  65.  * @param Variable Integer checks
  66.  * @desc Respective integers to store if there is dates are.
  67.  * @default 0
  68.  *
  69.  * @help
  70.  * ============================================================================
  71.  * Introduction
  72.  * ============================================================================
  73.  *
  74.  * There are games where special things happen on specific day of the week,
  75.  * specific hour, specific day, and so on.
  76.  * There are games where time continues even when off.
  77.  *
  78.  * With this plugin you can do both.
  79.  *
  80.  * Time is stored in game variables and can be used inside events. Also uses
  81.  * switches to check specified days. Automatically updates on map changes, but
  82.  * can also be updated manually.
  83.  *
  84.  * Also you can store time and check how many real time has passed.
  85.  * Time is stored as minutes.
  86.  *
  87.  * ============================================================================
  88.  * Parameters
  89.  * ============================================================================
  90.  *
  91.  * There are six basic params to store current year, day, hour, etc.
  92.  * These params indicate what variables will be used to store that info.
  93.  * To skip a param put 0.
  94.  *
  95.  * Month and day comes in a special format because events can use only one
  96.  * variable per page. So it needs a combined one. Is Month*100 + Day.
  97.  * Some Month-Day Examples:
  98.  *   -  101: January 1st
  99.  *   -  102: January 2nd
  100.  *   -  201: February 1st
  101.  *   -  211: February 11th
  102.  *   - 1001: October 1st
  103.  *   - 1010: October 10th
  104.  *
  105.  * Fixed Month and day: To check specified days sepparated by spaces.
  106.  * It's combined with next parameter.
  107.  *
  108.  * Fixed Integer checks: Switchs sepparated by spaces. There is a switch
  109.  * for every fixed date. When day is met it's switch becomes on, when not
  110.  * it's switch becomes off.
  111.  *
  112.  * Variable Month and day: To check inside specified variable a day.
  113.  * It can be used to store a day ingame and check when is met. Example: B-Day
  114.  * Variables are sepparated by spaces.
  115.  *
  116.  * Variable Integer checks: Switchs sepparated by spaces. There is a switch
  117.  * for every variable. When stored day is met it's switch becomes on, when
  118.  * not it's switch becomes off.
  119.  *
  120.  * ============================================================================
  121.  * Plugin commands
  122.  * ============================================================================
  123.  *
  124.  * GetTime x
  125.  *
  126.  *  - To store a time into variable number 'x'.
  127.  *
  128.  * GetTimeSince x y
  129.  * GetHoursSince x y
  130.  * GetDaysSince x y
  131.  *
  132.  *  - To compare how much time passed since 'x' in minutes, hours or days
  133.  *    and store result in variable 'y'.
  134.  *
  135.  * UpdateTime
  136.  *
  137.  *  - To update time variables manually.
  138.  *
  139.  * GoPresent [true]
  140.  *  - To reset time. Returning to present.
  141.  *  - Optional: placing 'true' will update map automatically.
  142.  *    
  143.  * AdvanceTime x [true]
  144.  * AdvanceDays x [true]
  145.  * AdvanceYears x [true]
  146.  *  - To advance x minutes, days or years in time (can be negative).
  147.  *  - Optional: placing 'true' will update map automatically.
  148.  *
  149.  * ============================================================================
  150.  * Incompatibilities
  151.  * ============================================================================
  152.  *
  153.  * There's no known incompatible plugins yet.
  154.  *
  155.  * ============================================================================
  156.  * Known isues
  157.  * ============================================================================
  158.  *
  159.  * There's no known isues yet.
  160.  *
  161.  * ============================================================================
  162.  * Changelog
  163.  * ============================================================================
  164.  *
  165.  * Version 1.02:
  166.  * - Added day check with switchs.
  167.  *
  168.  * Version 1.01:
  169.  * - Added time travel utility.
  170.  *
  171.  * Version 1.00:
  172.  * - Finished plugin!
  173.  *
  174.  * ============================================================================
  175.  *
  176.  * For commercial and non-commercial games.
  177.  * Credit to ICF-Soft.
  178.  * This entire header must be included with plugin.
  179.  *
  180.  * ============================================================================
  181. */
  182. //=============================================================================
  183.  /*:es
  184.  * @plugindesc v1.02 Este complemento almacena la fecha y hora en las variables
  185.  * del juego para diversos propósitos.
  186.  * @author ICF-Soft [http://icfsoft.blogspot.com.es/]
  187.  *
  188.  * @param Year Var
  189.  * @desc La variable donde almacenas el año.
  190.  * @default 0
  191.  *
  192.  * @param Month Var
  193.  * @desc La variable donde almacenas el mes (de 1 a 12).
  194.  * @default 0
  195.  *
  196.  * @param Day Var
  197.  * @desc La variable donde almacenas el día (de 1 a 31).
  198.  * @default 0
  199.  *
  200.  * @param Hour Var
  201.  * @desc La variable donde almacenas la hora.
  202.  * @default 0
  203.  *
  204.  * @param Minute Var
  205.  * @desc La variable donde almacenas los minutos.
  206.  * @default 0
  207.  *
  208.  * @param Week Var
  209.  * @desc La variable donde almacenas el día de la semana.
  210.  * La semana empieza con el domingo como 0.
  211.  * @default 0
  212.  *
  213.  * @param Month and day
  214.  * @desc Una variable especial donde se almacena una combinación de mes y día.
  215.  * @default 0
  216.  *
  217.  * @param Time travel
  218.  * @desc Una variable en donde almacenar el salto en el tiempo.
  219.  * @default 0
  220.  *
  221.  * @param Fixed Month and day
  222.  * @desc Los días que quieres comprobar separados por espacios.
  223.  * Debe ser combinación mes-día (ver ayuda).
  224.  * @default 101 102
  225.  *
  226.  * @param Fixed Integer checks
  227.  * @desc Interruptores respectivos para ver si se cumple la fecha.
  228.  * @default 0 0
  229.  *
  230.  * @param Variable Month and day
  231.  * @desc Las variables en donde se almacenan los días que quieres comprobar
  232.  * separados por espacios. Se almacenan en combinación mes-día (ver ayuda).
  233.  * @default
  234.  *
  235.  * @param Variable Integer checks
  236.  * @desc Interruptores respectivos para ver si se cumple la fecha.
  237.  * @default 0
  238.  *
  239.  * @help
  240.  * ============================================================================
  241.  * Introducción
  242.  * ============================================================================
  243.  *
  244.  * Hay juegos en donde ciertos eventos solo pasan en un día, día de la semana,
  245.  * hora o incluso minuto específico.
  246.  * También los hay en los que el tiempo pasa aunque no estés jugando.
  247.  *
  248.  * Con este complemento puedes hacer ambas cosas.
  249.  *
  250.  * El tiempo se almacena en variables a las que se puede acceder en los eventos.
  251.  * También se puede usar interruptores para comprobar fechas.
  252.  * Se actualiza en cada cambio de mapa, pero también con comando.
  253.  *
  254.  * Además puedes guardar una fecha y comparar cuanto tiempo real ha pasado.
  255.  * El tiempo se almacena en minutos.
  256.  *
  257.  * ============================================================================
  258.  * Parámetros
  259.  * ============================================================================
  260.  *
  261.  * Hay seis parámetros básicos donde almacenar el año, mes, día, hora, etc.
  262.  * Indican qué variables se van a utilizar para almacenar esa info.
  263.  * Para saltar un parámetro dejar en 0.
  264.  *
  265.  * Month and day comes usa un formato especial porque los eventos solo pueden
  266.  * usar una variable por página. Así que necesita una combinada.
  267.  * Viene en Mes*100 + Día.
  268.  * Algunos ejemplos:
  269.  *   -  101: 1  de Enero
  270.  *   -  102: 2  de Enero
  271.  *   -  201: 1  de Febrero
  272.  *   -  211: 11 de Febrero
  273.  *   - 1001: 1  de Octubre
  274.  *   - 1010: 10 de Octubre
  275.  *
  276.  * Fixed Month and day: Para comprobar días separados por espacios.
  277.  * Está en combinación con el siguiente parámetro.
  278.  *
  279.  * Fixed Integer checks: Interruptores separados por espacios. Un interruptor
  280.  * para cada fecha. En ese día su interruptor está activado, cuando no,
  281.  * está desactivado.
  282.  *
  283.  * Variable Month and day: Para comprobar la fecha almacenada en variables.
  284.  * Se utiliza para guardar un día y comprobar si es ese día. Se puede usar
  285.  * por ejemplo para guardar una fecha de cumpleaños. Las variables se
  286.  * separan por espacios.
  287.  *
  288.  * Variable Integer checks: Interruptores separados por espacios. Un
  289.  * interruptor para cada variable. Si el día almacenado se cumple su interruptor
  290.  * estará activado, cuando no, estará desactivado.
  291.  *
  292.  * ============================================================================
  293.  * Comandos de complemento
  294.  * ============================================================================
  295.  *
  296.  * GetTime x
  297.  *
  298.  *  - Para almacenar el tiempo en la variable número 'x'.
  299.  *
  300.  * GetTimeSince x y
  301.  * GetHoursSince x y
  302.  * GetDaysSince x y
  303.  *
  304.  *  - Para comparar cuanto tiempo ha pasado desde 'x' en minutos, horas or días
  305.  *    y almacenar el resultado en la variable 'y'.
  306.  *
  307.  * UpdateTime
  308.  *
  309.  *  - Para actualizar manualmente las variables.
  310.  *
  311.  * GoPresent [true]
  312.  *  - Para reiniciar el tiempo. Volver al presente.
  313.  *  - Opcional: poniendo 'true' las variables se actualizarán.
  314.  *    
  315.  * AdvanceTime x [true]
  316.  * AdvanceDays x [true]
  317.  * AdvanceYears x [true]
  318.  *  - Para avanzar x minutos, días o años en el tiempo (puede ser negativo).
  319.  *  - Opcional: poniendo 'true' las variables se actualizarán.
  320.  *
  321.  * ============================================================================
  322.  * Incompatibilidades
  323.  * ============================================================================
  324.  *
  325.  * No se conocen complementos que sean incompatibles hasta la fecha.
  326.  *
  327.  * ============================================================================
  328.  * Problemas conocidos
  329.  * ============================================================================
  330.  *
  331.  * No hay problemas hasta la fecha.
  332.  *
  333.  * ============================================================================
  334.  * Historial de versiones
  335.  * ============================================================================
  336.  *
  337.  * Version 1.02:
  338.  * - Se ha añadido una función de fechas con interruptores.
  339.  *
  340.  * Version 1.01:
  341.  * - Se ha añadido la utilidad de viaje en el tiempo.
  342.  *
  343.  * Version 1.00:
  344.  * - Complemento terminado.
  345.  *
  346.  * ============================================================================
  347.  *
  348.  * Para juegos comerciales y no comerciales.
  349.  * Se debe incluir a ICF-Soft en los créditos.
  350.  * Esta cabecera debe incluirse íntegramente con el plugin.
  351.  *
  352.  * ============================================================================
  353. */
  354. //=============================================================================
  355.  
  356. //=============================================================================
  357. // Parameter Variables
  358. //=============================================================================
  359.  
  360. ICF.Parameters = PluginManager.parameters('ICFSoft_TimeUtil');
  361. ICF.Param = ICF.Param || {};
  362.  
  363. ICF.Param.TimeVars = [];
  364. ICF.Param.TimeVars[0] = Number(ICF.Parameters['Year Var']);
  365. ICF.Param.TimeVars[1] = Number(ICF.Parameters['Month Var']);
  366. ICF.Param.TimeVars[2] = Number(ICF.Parameters['Day Var']);
  367. ICF.Param.TimeVars[3] = Number(ICF.Parameters['Hour Var']);
  368. ICF.Param.TimeVars[4] = Number(ICF.Parameters['Minute Var']);
  369. ICF.Param.TimeVars[5] = Number(ICF.Parameters['Week Var']);
  370. ICF.Param.TimeVars[6] = Number(ICF.Parameters['Month and day']);
  371.  
  372. ICF.Param.TimeTravel = Number(ICF.Parameters['Time travel']);
  373.  
  374. ICF.Param.TimeFixedData = ICF.Parameters['Fixed Month and day'].trim().split(/\s+/);
  375. ICF.Param.TimeFixedInt = ICF.Parameters['Fixed Integer checks'].trim().split(/\s+/);
  376. ICF.Param.TimeVarsData = ICF.Parameters['Variable Month and day'].trim().split(/\s+/);
  377. ICF.Param.TimeVarsInt = ICF.Parameters['Variable Integer checks'].trim().split(/\s+/);
  378.  
  379. if (ICF.Param.TimeFixedInt.length > ICF.Param.TimeFixedData.length) ICF.Param.TimeFixedInt.splice(ICF.Param.TimeFixedData.length, ICF.Param.TimeFixedInt.length - ICF.Param.TimeFixedData.length);
  380. if (ICF.Param.TimeVarsInt.length > ICF.Param.TimeVarsData.length) ICF.Param.TimeVarsInt.splice(ICF.Param.TimeVarsData.length, ICF.Param.TimeVarsInt.length - ICF.Param.TimeVarsData.length);
  381. for (var i = 0; i < ICF.Param.TimeFixedInt.length; i++) {ICF.Param.TimeFixedInt[i] = Number(ICF.Param.TimeFixedInt[i]);};
  382. for (var i = 0; i < ICF.Param.TimeVarsInt.length; i++) {ICF.Param.TimeVarsInt[i] = Number(ICF.Param.TimeVarsInt[i]);};
  383.  
  384. //=============================================================================
  385. // Time Utilities
  386. //=============================================================================
  387.  
  388. ICF.TimeUtil.GetTime = function(varid) {
  389.     var Today = new Date();
  390.     Today.setMinutes(Today.getMinutes() + $gameVariables.value(ICF.Param.TimeTravel));
  391.     $gameVariables.setValue(varid, parseInt(Today.getTime()/60000));
  392. }
  393.  
  394. ICF.TimeUtil.GetTimeSince = function(varid, resid) {
  395.     var Today = new Date();
  396.     Today.setMinutes(Today.getMinutes() + $gameVariables.value(ICF.Param.TimeTravel));
  397.     if (resid == undefined) {return (parseInt(Today.getTime()/60000) - $gameVariables.value(varid));}
  398.     $gameVariables.setValue(resid, parseInt(Today.getTime()/60000) - $gameVariables.value(varid));
  399. }
  400.  
  401. ICF.TimeUtil.GetHoursSince = function(varid, resid) {
  402.     if (resid == undefined) {return (ICF.TimeUtil.GetTimeSince(varid)/60)};
  403.     var Today = new Date();
  404.     Today.setMinutes(Today.getMinutes() + $gameVariables.value(ICF.Param.TimeTravel));
  405.     $gameVariables.setValue(resid, parseInt((Today.getTime()/60000) - $gameVariables.value(varid))/60);
  406. }
  407.  
  408. ICF.TimeUtil.GetDaysSince = function(varid, resid) {
  409.     if (resid == undefined) {return (ICF.TimeUtil.GetTimeSince(varid)/1440)};
  410.     var Today = new Date();
  411.     Today.setMinutes(Today.getMinutes() + $gameVariables.value(ICF.Param.TimeTravel));
  412.     $gameVariables.setValue(resid, parseInt((Today.getTime()/60000) - $gameVariables.value(varid))/1440);
  413. }
  414.  
  415. ICF.TimeUtil.GetDate = function() {
  416.     var Today = new Date();
  417.     ICF.TimeUtil.Today = Today.getMonth() * 100 + Today.getDate() + 100;
  418.     Today.setMinutes(Today.getMinutes() + $gameVariables.value(ICF.Param.TimeTravel));
  419.     ICF.TimeUtil.Day = Today.getMonth() * 100 + Today.getDate() + 100;
  420.     if (ICF.Param.TimeVars[0] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[0], Today.getFullYear());}
  421.     if (ICF.Param.TimeVars[1] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[1], Today.getMonth() + 1);}
  422.     if (ICF.Param.TimeVars[2] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[2], Today.getDate());}
  423.     if (ICF.Param.TimeVars[3] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[3], Today.getHours());}
  424.     if (ICF.Param.TimeVars[4] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[4], Today.getMinutes());}
  425.     if (ICF.Param.TimeVars[5] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[5], Today.getDay());}
  426.     if (ICF.Param.TimeVars[6] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[6], ICF.TimeUtil.Day);}
  427.  
  428. }
  429.  
  430. ICF.TimeUtil.GoPresent = function(updating) {
  431.     $gameVariables.setValue(ICF.Param.TimeTravel, 0);
  432.     if (updating) {ICF.TimeUtil.GetDate();}
  433. }
  434.  
  435. ICF.TimeUtil.AdvanceTime = function(minutes, updating) {
  436.     if (minutes == undefined) {minutes = 1}
  437.     $gameVariables.setValue(ICF.Param.TimeTravel, ICF.Param.TimeTravel + minutes);
  438.     if (updating) {ICF.TimeUtil.GetDate();}
  439. }
  440.  
  441. ICF.TimeUtil.AdvanceDays = function(days, updating) {
  442.     if (days == undefined) {days = 1}
  443.     $gameVariables.setValue(ICF.Param.TimeTravel, ICF.Param.TimeTravel + days * 1440);
  444.     if (updating) {ICF.TimeUtil.GetDate();}
  445. }
  446.  
  447. ICF.TimeUtil.AdvanceYears = function(years, updating) {
  448.     if (years == undefined) {years = 1}
  449.     $gameVariables.setValue(ICF.Param.TimeTravel, ICF.Param.TimeTravel + years * 525960);
  450.     if (updating) {ICF.TimeUtil.GetDate();}
  451. }
  452.  
  453. //=============================================================================
  454. // Game_Interpreter
  455. //=============================================================================
  456.  
  457. ICF.TimeUtil.pluginCommand = Game_Interpreter.prototype.pluginCommand;
  458. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  459.         ICF.TimeUtil.pluginCommand.call(this, command, args);
  460.     if (command === 'GetTime') {
  461.         ICF.TimeUtil.GetTime(args[0]);
  462.     } else if (command === 'GetTimeSince') {
  463.         ICF.TimeUtil.GetTimeSince(args[0], args[1]);
  464.     } else if (command === 'GetHoursSince') {
  465.         ICF.TimeUtil.GetHoursSince(args[0], args[1]);
  466.     } else if (command === 'GetDaysSince') {
  467.         ICF.TimeUtil.GetDaysSince(args[0], args[1]);
  468.         } else if (command === 'UpdateTime') {
  469.         ICF.TimeUtil.GetDate();
  470.         } else if (command === 'GoPresent') {
  471.         ICF.TimeUtil.GoPresent(args[0]);
  472.     } else if (command === 'AdvanceTime') {
  473.         ICF.TimeUtil.AdvanceTime(args[0], args[1]);
  474.     } else if (command === 'AdvanceDays') {
  475.         ICF.TimeUtil.AdvanceDays(args[0], args[1]);
  476.         } else if (command === 'AdvanceYears') {
  477.         ICF.TimeUtil.AdvanceYears(args[0], args[1]);
  478.         }
  479. };
  480.  
  481. //=============================================================================
  482. // Game_Map
  483. //=============================================================================
  484.  
  485. ICF.TimeUtil.mapsetup = Game_Map.prototype.setup;
  486. Game_Map.prototype.setup = function(mapId) {
  487.     ICF.TimeUtil.GetDate();
  488.     ICF.TimeUtil.mapsetup.call(this, mapId);
  489. };
  490.  
  491. //=============================================================================
  492. // Game_Switches
  493. //=============================================================================
  494.  
  495. ICF.TimeUtil.Game_Switches_value = Game_Switches.prototype.value;
  496. Game_Switches.prototype.value = function(switchId) {
  497.   if (ICF.Param.TimeFixedInt.indexOf(switchId) > -1) {
  498.     return (ICF.TimeUtil.Day == ICF.Param.TimeFixedData[ICF.Param.TimeFixedInt.indexOf(switchId)]);
  499.   } else if (ICF.Param.TimeVarsInt.indexOf(switchId) > -1) {
  500.     return (ICF.TimeUtil.Day == $gameVariables.value(ICF.Param.TimeVarsData[ICF.Param.TimeVarsInt.indexOf(switchId)]));
  501.   } else {
  502.     return ICF.TimeUtil.Game_Switches_value.call(this, switchId);
  503.   }
  504. };
  505.  
  506. //=============================================================================
  507. // End of File
  508. //=============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement