Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================================================================
- // ICF-Soft Plugins - Time Utility
- // ICFSoft_TimeUtil.js
- //=============================================================================
- var Imported = Imported || {};
- Imported.ICFSoft_TimeUtil = true;
- var ICF = ICF || {};
- ICF.TimeUtil = ICF.TimeUtil || {};
- ICF.TimeUtil.Version = 103; // 1.03
- //=============================================================================
- /*:
- * @plugindesc v1.03 This plugin stores date and time in game variables
- * for diverse pourposes.
- * @author ICF-Soft [http://icfsoft.blogspot.com.es/]
- *
- * @param Year Var
- * @desc A variable where store year.
- * @default 0
- *
- * @param Month Var
- * @desc A variable where store month from 1 to 12.
- * @default 0
- *
- * @param Day Var
- * @desc A variable where store day from 1 to 31.
- * @default 0
- *
- * @param Hour Var
- * @desc A variable where store hour.
- * @default 0
- *
- * @param Minute Var
- * @desc A variable where store minute.
- * @default 0
- *
- * @param Week Var
- * @desc A variable where store the day of the week.
- * Week starts with Sunday as 0.
- * @default 0
- *
- * @param Month and day
- * @desc A variable where store a month and day combination.
- * @default 0
- *
- * @param Hour and minutes
- * @desc A variable where store a hour and minutes combination.
- * @default 0
- *
- * @param Time travel
- * @desc A variable where store a time offset.
- * @default 0
- *
- * @param Fixed Month and day
- * @desc All days you want to check separated with spaces.
- * Must be month and day combination (see help).
- * @default 101 102
- *
- * @param Fixed Integer checks
- * @desc Respective integers to store if there is dates are.
- * @default 0 0
- *
- * @param Variable Month and day
- * @desc All variables where days you want to check are stored separated
- * with spaces. Must be stored as month and day combination (see help).
- * @default
- *
- * @param Variable Integer checks
- * @desc Respective integers to store if there is dates are.
- * @default 0
- *
- * @help
- * ============================================================================
- * Introduction
- * ============================================================================
- *
- * There are games where special things happen on specific day of the week,
- * specific hour, specific day, and so on.
- * There are games where time continues even when off.
- *
- * With this plugin you can do both.
- *
- * Time is stored in game variables and can be used inside events. Also uses
- * switches to check specified days. Automatically updates on map changes, but
- * can also be updated manually.
- *
- * Also you can store time and check how many real time has passed.
- * Time is stored as minutes.
- *
- * ============================================================================
- * Parameters
- * ============================================================================
- *
- * There are six basic params to store current year, day, hour, etc.
- * These params indicate what variables will be used to store that info.
- * To skip a param put 0.
- *
- * Month and day comes in a special format because events can use only one
- * variable per page. So it needs a combined one. Is Month*100 + Day.
- * Some Month-Day Examples:
- * - 101: January 1st
- * - 102: January 2nd
- * - 201: February 1st
- * - 211: February 11th
- * - 1001: October 1st
- * - 1010: October 10th
- *
- * Hours and minutes works as month and day does. Is Hour*100 + minute.
- *
- * Fixed Month and day: To check specified days sepparated by spaces.
- * It's combined with next parameter.
- *
- * Fixed Integer checks: Switchs sepparated by spaces. There is a switch
- * for every fixed date. When day is met it's switch becomes on, when not
- * it's switch becomes off.
- *
- * Variable Month and day: To check inside specified variable a day.
- * It can be used to store a day ingame and check when is met. Example: B-Day
- * Variables are sepparated by spaces.
- *
- * Variable Integer checks: Switchs sepparated by spaces. There is a switch
- * for every variable. When stored day is met it's switch becomes on, when
- * not it's switch becomes off.
- *
- * ============================================================================
- * Plugin commands
- * ============================================================================
- *
- * GetTime x
- *
- * - To store a time into variable number 'x'.
- *
- * GetTimeSince x y
- * GetHoursSince x y
- * GetDaysSince x y
- *
- * - To compare how much time passed since 'x' in minutes, hours or days
- * and store result in variable 'y'.
- *
- * UpdateTime
- *
- * - To update time variables manually.
- *
- * GoPresent [true]
- * - To reset time. Returning to present.
- * - Optional: placing 'true' will update map automatically.
- *
- * AdvanceTime x [true]
- * AdvanceDays x [true]
- * AdvanceYears x [true]
- * - To advance x minutes, days or years in time (can be negative).
- * - Optional: placing 'true' will update map automatically.
- *
- * ============================================================================
- * Scripting functions
- * ============================================================================
- *
- * For those who prefer scripting over plugin commands there are the
- * alternate versions.
- *
- * ICF.TimeUtil.GetTime(x)
- * ICF.TimeUtil.GetTimeSince(x, y)
- * ICF.TimeUtil.GetHoursSince(x, y)
- * ICF.TimeUtil.GetDaysSince(x, y)
- * ICF.TimeUtil.GetDate()
- * ICF.TimeUtil.GoPresent(x)
- * ICF.TimeUtil.AdvanceTime(x, true)
- * ICF.TimeUtil.AdvanceDays(x, true)
- * ICF.TimeUtil.AdvanceYears(x, true)
- *
- * ============================================================================
- * Incompatibilities
- * ============================================================================
- *
- * There's no known incompatible plugins yet.
- *
- * ============================================================================
- * Known isues
- * ============================================================================
- *
- * There's no known isues yet.
- *
- * ============================================================================
- * Changelog
- * ============================================================================
- *
- * Version 1.03:
- * - Use of ICF-Soft Main Utility.
- * - Added hour and minutes combination.
- *
- * Version 1.02:
- * - Added day check with switchs.
- *
- * Version 1.01:
- * - Added time travel utility.
- *
- * Version 1.00:
- * - Finished plugin!
- *
- * ============================================================================
- *
- * For commercial and non-commercial games.
- * Credit to ICF-Soft.
- * This entire header must be included with plugin.
- *
- * ============================================================================
- */
- //=============================================================================
- /*:es
- * @plugindesc v1.03 Este complemento almacena la fecha y hora en las variables
- * del juego para diversos propósitos.
- * @author ICF-Soft [http://icfsoft.blogspot.com.es/]
- *
- * @param Year Var
- * @desc La variable donde almacenas el año.
- * @default 0
- *
- * @param Month Var
- * @desc La variable donde almacenas el mes (de 1 a 12).
- * @default 0
- *
- * @param Day Var
- * @desc La variable donde almacenas el día (de 1 a 31).
- * @default 0
- *
- * @param Hour Var
- * @desc La variable donde almacenas la hora.
- * @default 0
- *
- * @param Minute Var
- * @desc La variable donde almacenas los minutos.
- * @default 0
- *
- * @param Week Var
- * @desc La variable donde almacenas el día de la semana.
- * La semana empieza con el domingo como 0.
- * @default 0
- *
- * @param Month and day
- * @desc Una variable especial donde se almacena una combinación de mes y día.
- * @default 0
- *
- * @param Hour and minutes
- * @desc Una variable especial donde se almacena una combinación de horas
- * y minutos.
- * @default 0
- *
- * @param Time travel
- * @desc Una variable en donde almacenar el salto en el tiempo.
- * @default 0
- *
- * @param Fixed Month and day
- * @desc Los días que quieres comprobar separados por espacios.
- * Debe ser combinación mes-día (ver ayuda).
- * @default 101 102
- *
- * @param Fixed Integer checks
- * @desc Interruptores respectivos para ver si se cumple la fecha.
- * @default 0 0
- *
- * @param Variable Month and day
- * @desc Las variables en donde se almacenan los días que quieres comprobar
- * separados por espacios. Se almacenan en combinación mes-día (ver ayuda).
- * @default
- *
- * @param Variable Integer checks
- * @desc Interruptores respectivos para ver si se cumple la fecha.
- * @default 0
- *
- * @help
- * ============================================================================
- * Introducción
- * ============================================================================
- *
- * Hay juegos en donde ciertos eventos solo pasan en un día, día de la semana,
- * hora o incluso minuto específico.
- * También los hay en los que el tiempo pasa aunque no estés jugando.
- *
- * Con este complemento puedes hacer ambas cosas.
- *
- * El tiempo se almacena en variables a las que se puede acceder en los eventos.
- * También se puede usar interruptores para comprobar fechas.
- * Se actualiza en cada cambio de mapa, pero también con comando.
- *
- * Además puedes guardar una fecha y comparar cuanto tiempo real ha pasado.
- * El tiempo se almacena en minutos.
- *
- * ============================================================================
- * Parámetros
- * ============================================================================
- *
- * Hay seis parámetros básicos donde almacenar el año, mes, día, hora, etc.
- * Indican qué variables se van a utilizar para almacenar esa info.
- * Para saltar un parámetro dejar en 0.
- *
- * Month and day comes usa un formato especial porque los eventos solo pueden
- * usar una variable por página. Así que necesita una combinada.
- * Viene en Mes*100 + Día.
- * Algunos ejemplos:
- * - 101: 1 de Enero
- * - 102: 2 de Enero
- * - 201: 1 de Febrero
- * - 211: 11 de Febrero
- * - 1001: 1 de Octubre
- * - 1010: 10 de Octubre
- *
- * Hours and minutes funciona como el anterior. Is Hora*100 + minutos.
- *
- * Fixed Month and day: Para comprobar días separados por espacios.
- * Está en combinación con el siguiente parámetro.
- *
- * Fixed Integer checks: Interruptores separados por espacios. Un interruptor
- * para cada fecha. En ese día su interruptor está activado, cuando no,
- * está desactivado.
- *
- * Variable Month and day: Para comprobar la fecha almacenada en variables.
- * Se utiliza para guardar un día y comprobar si es ese día. Se puede usar
- * por ejemplo para guardar una fecha de cumpleaños. Las variables se
- * separan por espacios.
- *
- * Variable Integer checks: Interruptores separados por espacios. Un
- * interruptor para cada variable. Si el día almacenado se cumple su interruptor
- * estará activado, cuando no, estará desactivado.
- *
- * ============================================================================
- * Comandos de complemento
- * ============================================================================
- *
- * GetTime x
- *
- * - Para almacenar el tiempo en la variable número 'x'.
- *
- * GetTimeSince x y
- * GetHoursSince x y
- * GetDaysSince x y
- *
- * - Para comparar cuanto tiempo ha pasado desde 'x' en minutos, horas or días
- * y almacenar el resultado en la variable 'y'.
- *
- * UpdateTime
- *
- * - Para actualizar manualmente las variables.
- *
- * GoPresent [true]
- * - Para reiniciar el tiempo. Volver al presente.
- * - Opcional: poniendo 'true' las variables se actualizarán.
- *
- * AdvanceTime x [true]
- * AdvanceDays x [true]
- * AdvanceYears x [true]
- * - Para avanzar x minutos, días o años en el tiempo (puede ser negativo).
- * - Opcional: poniendo 'true' las variables se actualizarán.
- *
- * ============================================================================
- * Funciones de script
- * ============================================================================
- *
- * Para aquellos que usar javascript en lugar de usar los comandos de
- * complementos éstas son las versiones alternativas.
- *
- * ICF.TimeUtil.GetTime(x)
- * ICF.TimeUtil.GetTimeSince(x, y)
- * ICF.TimeUtil.GetHoursSince(x, y)
- * ICF.TimeUtil.GetDaysSince(x, y)
- * ICF.TimeUtil.GetDate()
- * ICF.TimeUtil.GoPresent(x)
- * ICF.TimeUtil.AdvanceTime(x, true)
- * ICF.TimeUtil.AdvanceDays(x, true)
- * ICF.TimeUtil.AdvanceYears(x, true)
- *
- * ============================================================================
- * Incompatibilidades
- * ============================================================================
- *
- * No se conocen complementos que sean incompatibles hasta la fecha.
- *
- * ============================================================================
- * Problemas conocidos
- * ============================================================================
- *
- * No hay problemas hasta la fecha.
- *
- * ============================================================================
- * Historial de versiones
- * ============================================================================
- *
- * Version 1.03:
- * - Se epieza a utilizar el ICF-Soft Main Utility.
- * - Se ha añadido una combinación de hora y minutos.
- *
- * Version 1.02:
- * - Se ha añadido una función de fechas con interruptores.
- *
- * Version 1.01:
- * - Se ha añadido la utilidad de viaje en el tiempo.
- *
- * Version 1.00:
- * - Complemento terminado.
- *
- * ============================================================================
- *
- * Para juegos comerciales y no comerciales.
- * Se debe incluir a ICF-Soft en los créditos.
- * Esta cabecera debe incluirse íntegramente con el plugin.
- *
- * ============================================================================
- */
- //=============================================================================
- //=============================================================================
- // Parameter Variables
- //=============================================================================
- ICF.Parameters = PluginManager.parameters('ICFSoft_TimeUtil');
- ICF.Param = ICF.Param || {};
- ICF.Param.TimeVars = [];
- ICF.Param.TimeVars[0] = Number(ICF.Parameters['Year Var']);
- ICF.Param.TimeVars[1] = Number(ICF.Parameters['Month Var']);
- ICF.Param.TimeVars[2] = Number(ICF.Parameters['Day Var']);
- ICF.Param.TimeVars[3] = Number(ICF.Parameters['Hour Var']);
- ICF.Param.TimeVars[4] = Number(ICF.Parameters['Minute Var']);
- ICF.Param.TimeVars[5] = Number(ICF.Parameters['Week Var']);
- ICF.Param.TimeVars[6] = Number(ICF.Parameters['Month and day']);
- ICF.Param.TimeVars[7] = Number(ICF.Parameters['Hour and minutes']);
- ICF.Param.TimeTravel = Number(ICF.Parameters['Time travel']);
- ICF.Param.TimeFixedData = ICF.Parameters['Fixed Month and day'].split(/\s+/).leaveNumbers();
- ICF.Param.TimeFixedInt = ICF.Parameters['Fixed Integer checks'].split(/\s+/).leaveNumbers().reduceToFit(ICF.Param.TimeFixedData);
- ICF.Param.TimeVarsData = ICF.Parameters['Variable Month and day'].split(/\s+/).leaveNumbers();
- ICF.Param.TimeVarsInt = ICF.Parameters['Variable Integer checks'].split(/\s+/).leaveNumbers().reduceToFit(ICF.Param.TimeVarsData);
- if (!Imported.ICFSoft_MainUtility) {throw new Error('This plugin requires ICF-Soft Main Utility plugin to work.\nYou can download it at icfsoft.blogspot.com inside plugins section.');}
- //=============================================================================
- // Time Utilities
- //=============================================================================
- ICF.TimeUtil.GetTime = function(varid) {
- var Today = new Date();
- Today.increaseMinutes($gameVariables.value(ICF.Param.TimeTravel));
- $gameVariables.setValue(varid, parseInt(Today.getTime()/60000));
- }
- ICF.TimeUtil.GetTimeSince = function(varid, resid) {
- var Today = new Date();
- Today.increaseMinutes($gameVariables.value(ICF.Param.TimeTravel));
- if (resid == undefined) {return (parseInt(Today.getTime()/60000) - $gameVariables.value(varid));}
- $gameVariables.setValue(resid, parseInt(Today.getTime()/60000) - $gameVariables.value(varid));
- }
- ICF.TimeUtil.GetHoursSince = function(varid, resid) {
- if (resid == undefined) {return (ICF.TimeUtil.GetTimeSince(varid)/60)};
- var Today = new Date();
- Today.increaseMinutes($gameVariables.value(ICF.Param.TimeTravel));
- $gameVariables.setValue(resid, parseInt((Today.getTime()/60000) - $gameVariables.value(varid))/60);
- }
- ICF.TimeUtil.GetDaysSince = function(varid, resid) {
- if (resid == undefined) {return (ICF.TimeUtil.GetTimeSince(varid)/1440)};
- var Today = new Date();
- Today.increaseMinutes($gameVariables.value(ICF.Param.TimeTravel));
- $gameVariables.setValue(resid, parseInt((Today.getTime()/60000) - $gameVariables.value(varid))/1440);
- }
- ICF.TimeUtil.GetDate = function() {
- var Today = new Date();
- ICF.TimeUtil.Today = Today.getMonthAndDay();
- Today.increaseMinutes($gameVariables.value(ICF.Param.TimeTravel));
- ICF.TimeUtil.Day = Today.getMonthAndDay();
- if (ICF.Param.TimeVars[0] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[0], Today.getFullYear());}
- if (ICF.Param.TimeVars[1] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[1], Today.getMonth() + 1);}
- if (ICF.Param.TimeVars[2] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[2], Today.getDate());}
- if (ICF.Param.TimeVars[3] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[3], Today.getHours());}
- if (ICF.Param.TimeVars[4] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[4], Today.getMinutes());}
- if (ICF.Param.TimeVars[5] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[5], Today.getDay());}
- if (ICF.Param.TimeVars[6] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[6], ICF.TimeUtil.Day);}
- if (ICF.Param.TimeVars[7] > 0) {$gameVariables.setValue(ICF.Param.TimeVars[7], Today.getHourAndMinute());}
- }
- ICF.TimeUtil.GoPresent = function(updating) {
- $gameVariables.setValue(ICF.Param.TimeTravel, 0);
- if (updating) {ICF.TimeUtil.GetDate();}
- }
- ICF.TimeUtil.AdvanceTime = function(minutes, updating) {
- if (minutes == undefined) {minutes = 1}
- $gameVariables.setValue(ICF.Param.TimeTravel, $gameVariables.value(ICF.Param.TimeTravel) + minutes);
- if (updating) {ICF.TimeUtil.GetDate();}
- }
- ICF.TimeUtil.AdvanceDays = function(days, updating) {
- if (days == undefined) {days = 1}
- $gameVariables.setValue(ICF.Param.TimeTravel, $gameVariables.value(ICF.Param.TimeTravel) + days * 1440);
- if (updating) {ICF.TimeUtil.GetDate();}
- }
- ICF.TimeUtil.AdvanceYears = function(years, updating) {
- if (years == undefined) {years = 1}
- $gameVariables.setValue(ICF.Param.TimeTravel, $gameVariables.value(ICF.Param.TimeTravel) + years * 525960);
- if (updating) {ICF.TimeUtil.GetDate();}
- }
- //=============================================================================
- // Game_Interpreter
- //=============================================================================
- ICF.TimeUtil.pluginCommand = Game_Interpreter.prototype.pluginCommand;
- Game_Interpreter.prototype.pluginCommand = function(command, args) {
- ICF.TimeUtil.pluginCommand.call(this, command, args);
- if (command.toLowerCase() === 'gettime') {
- ICF.TimeUtil.GetTime(args[0]);
- } else if (command.toLowerCase() == 'gettimesince') {
- ICF.TimeUtil.GetTimeSince(args[0], args[1]);
- } else if (command.toLowerCase() == 'gethourssince') {
- ICF.TimeUtil.GetHoursSince(args[0], args[1]);
- } else if (command.toLowerCase() == 'getdayssince') {
- ICF.TimeUtil.GetDaysSince(args[0], args[1]);
- } else if (command.toLowerCase() == 'updatetime') {
- ICF.TimeUtil.GetDate();
- } else if (command.toLowerCase() == 'gopresent') {
- ICF.TimeUtil.GoPresent(args[0]);
- } else if (command.toLowerCase() == 'advancetime') {
- ICF.TimeUtil.AdvanceTime(args[0], args[1]);
- } else if (command.toLowerCase() == 'advancedays') {
- ICF.TimeUtil.AdvanceDays(args[0], args[1]);
- } else if (command.toLowerCase() == 'advanceyears') {
- ICF.TimeUtil.AdvanceYears(args[0], args[1]);
- }
- };
- //=============================================================================
- // Game_Map
- //=============================================================================
- ICF.TimeUtil.mapsetup = Game_Map.prototype.setup;
- Game_Map.prototype.setup = function(mapId) {
- ICF.TimeUtil.GetDate();
- ICF.TimeUtil.mapsetup.call(this, mapId);
- };
- //=============================================================================
- // Game_Switches
- //=============================================================================
- ICF.TimeUtil.Game_Switches_value = Game_Switches.prototype.value;
- Game_Switches.prototype.value = function(switchId) {
- if (ICF.Param.TimeFixedInt.indexOf(switchId) > -1) {
- return (ICF.TimeUtil.Day == ICF.Param.TimeFixedData[ICF.Param.TimeFixedInt.indexOf(switchId)]);
- } else if (ICF.Param.TimeVarsInt.indexOf(switchId) > -1) {
- return (ICF.TimeUtil.Day == $gameVariables.value(ICF.Param.TimeVarsData[ICF.Param.TimeVarsInt.indexOf(switchId)]));
- } else {
- return ICF.TimeUtil.Game_Switches_value.call(this, switchId);
- }
- };
- //=============================================================================
- // End of File
- //=============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement