Advertisement
ICF-Soft

ICF-Soft Main Utility 1.01c RPG Maker MV

Oct 15th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // ICF-Soft Plugins - Main Utility
  3. // ICFSoft_MainUtility.js
  4. //=============================================================================
  5.  
  6. var Imported = Imported || {};
  7. Imported.ICFSoft_MainUtility = true;
  8.  
  9. var ICF = ICF || {};
  10. ICF.MainUtility = ICF.MainUtility || {};
  11.  
  12. ICF.MainUtility.Version = 101; // 1.01
  13.  
  14. //=============================================================================
  15.  /*:
  16.  * @plugindesc v1.01c A sdk plugin with a lot of utilities for game
  17.  * and plugin developers.
  18.  * @author ICF-Soft [http://icfsoft.blogspot.com.es/]
  19.  *
  20.  * @help
  21.  * ============================================================================
  22.  * Introduction
  23.  *
  24.  * This is a sdk plugin with a lot of utilities to script easier.
  25.  * It's needed for the mayority of my plugins to work.
  26.  *
  27.  * It includes:
  28.  *  -Special json feature to edit/add data fields.
  29.  *  -Special trait system allowing to add traits to non-trait data (skills
  30.  *      and items), add actor/enemy traits ingame plus a subtraits system.
  31.  *  -Self and battle switchs/variables system.
  32.  *  -Javascript runing system.
  33.  *  -Extended features for some js built-in objects.
  34.  *
  35.  * ============================================================================
  36.  * How to use
  37.  * ============================================================================
  38.  *
  39.  * It uses notetags to add/alter data.
  40.  * For plugin developers it's recommended to show how to use these tags
  41.  * inside your plugins.
  42.  *
  43.  *
  44.  * Json master tag allow to alter data in a particular way. You
  45.  * can add new fields or edit out of field limits, it works in
  46.  * json notation, better than just meta-tags.
  47.  *
  48.  * Use every line between open and close tags to edit a field, first
  49.  * field name followed by a two dots symbol, then one space and the
  50.  * code in json format.
  51.  *
  52.  * Example:
  53.  *
  54.  * <JSON MASTER>
  55.  * gold: 50000000
  56.  * hands_power: [50,100]
  57.  * grade: 'F'
  58.  * </JSON MASTER>
  59.  *
  60.  *
  61.  * Traits master tag allow to add traits througth notebox.
  62.  * Every line between open and close tags are three numbers separated
  63.  * by spaces. It is recomended to use the three numbers even if specified
  64.  * trait uses only two, next inline place can be used for comments.
  65.  * You can use a name instead of first number (see readme for all names).
  66.  *
  67.  * Example:
  68.  *
  69.  * <TRAITS MASTER>
  70.  * elem_rate 1 1.5
  71.  * 21 1 2
  72.  * 31 2 0 -Attack element
  73.  * </TRAITS MASTER>
  74.  *
  75.  *
  76.  * Subtraits master tag allow to add more trait setups for different
  77.  * uses like subclass traits, random enemy/item/equipment traits,
  78.  * alter states tiers and so on. It works like traits master but you
  79.  * dont't need to close tag every time you open a new subtrait setup.
  80.  *
  81.  * Example:
  82.  *
  83.  * <SUBTRAITS MASTER> -Fire slime
  84.  * elem_rate 1 1.5
  85.  * 11 2 0.5
  86.  * 31 2 0 -Fire attack element
  87.  * <SUBTRAITS MASTER> -Cold slime
  88.  * elem_rate 1 1.5
  89.  * 11 2 2.1
  90.  * 31 3 0 -Cold attack element
  91.  * </SUBTRAITS MASTER>
  92.  *
  93.  * Note: More than one plugin can use subtraits in same data for different
  94.  * purposes so you must provide a way to use specific blocks, something
  95.  * like "<MyAmacingPluginSubtraits first last>" can be usefull.
  96.  *
  97.  * To access a subtrait setup use 'item.subtraits[i].traits' instead of
  98.  * 'item.traits', where 'i' is the index.
  99.  * And for trait items use 'item.subtraits[i]' instead of 'item'.
  100.  *
  101.  *
  102.  * JSEval master tag allow to add javascript code that can be run
  103.  * when a condition is given or diverse pourposes.
  104.  * You can give single key, double key or more, and you dont't need
  105.  * to close tag every time you open a new code.
  106.  *
  107.  * Example:
  108.  *
  109.  * <JSEVAL MASTER A>
  110.  * this.gainTp(15);
  111.  * <JSEVAL MASTER A B>
  112.  * if (this == subject) this.gainMp(-10);
  113.  * v.setValue(10, v.value(10) + 2);
  114.  * </JSEVAL MASTER>
  115.  *
  116.  * Some variables are passed and can be used inside code:
  117.  *   - subject: the subject of the action.
  118.  *   - item: the object used in the action. Can be an item or a skill.
  119.  *   - isSkill: check if is an skill.
  120.  *
  121.  * ============================================================================
  122.  * Battle Switches and Variables
  123.  * ============================================================================
  124.  *
  125.  * These are new reciclable switches an variables that are reset every
  126.  * battle. Are usefull in battle and help making battle steps without
  127.  * touching persistent switches or variables.
  128.  *
  129.  * Can be usefull for plugins that affect battles.
  130.  *
  131.  * See readme file for more info.
  132.  *
  133.  * ============================================================================
  134.  * Plugin Commands
  135.  * ============================================================================
  136.  *
  137.  * selfswitch x true/false
  138.  * mapswitch x true/false
  139.  * actorswitch actorid x true/false
  140.  * battleswitch x true/false
  141.  * enemybattleswitch enemyposition x true/false
  142.  *
  143.  *  - Turns on/off specified selfswitch or mapswitch.
  144.  *    You can also use an actorswitch.
  145.  *
  146.  * remoteswitch mapid eventid x true/false
  147.  *
  148.  *  - Turns on/off specified selfswitch or mapswitch remotely.
  149.  *    Use eventid 0 for a mapswitch.
  150.  *
  151.  * selfvariable x value
  152.  * mapvariable x value
  153.  * actorvariable actorid x value
  154.  * battlevariable x value
  155.  * enemybattlevariable enemyposition x value
  156.  *
  157.  *  - Changes value of specified selfvariable or mapvariable.
  158.  *    You can also use an actorvariable.
  159.  *    You can put increase/multiply/divide/mod prefix.
  160.  *
  161.  * remotevariable mapid eventid x value
  162.  *
  163.  *  - Changes value of specified selfvariable or mapvariable remotely.
  164.  *    Use eventid 0 for a mapvariable.
  165.  *
  166.  * actortraitadd actorid code id value
  167.  * partymembertraitadd actorpos code id value
  168.  * enemytraitadd enemy code id value
  169.  *
  170.  *  - Adds an ingame trait to specified actor, actor in party or
  171.  *    in battle enemy.
  172.  *    Doesn't check for repeated traits (same code and id).
  173.  *
  174.  * actortrait actorid code id value
  175.  * partymembertrait actorpos code id value
  176.  * enemytrait enemy code id value
  177.  *
  178.  *  - Ensures an ingame trait to specified actor, actor in party or
  179.  *    in battle enemy. If there isn't it'll be added, if there is at least
  180.  *    one it'll be replaced and all repeated traits will be removed.
  181.  *
  182.  * actortraitplus actorid code id value
  183.  * partymembertraitplus actorpos code id value
  184.  * enemytraitplus enemy code id value
  185.  *
  186.  *  - Increase existing ingame trait to specified actor, actor in party or
  187.  *    in battle enemy by a value. If there isn't it'll be added, and
  188.  *    every repeated trait will be merged togeder by sum.
  189.  *
  190.  * actortraitrate actorid code id value
  191.  * partymembertraitrate actorpos code id value
  192.  * enemytraitrate enemy code id value
  193.  *
  194.  *  - Multiply existing ingame trait to specified actor, actor in party or
  195.  *    in battle enemy by a value. If there isn't it'll be added, and
  196.  *    every repeated trait will be merged togeder by multiplication.
  197.  *
  198.  * removeactortrait actorid code id
  199.  * removepartymembertrait actorpos code id
  200.  * removeenemytraitenemy code id
  201.  *
  202.  *  - Remove all ingame traits with specified code and id to specified actor,
  203.  *    actor in party or in battle enemy.
  204.  *
  205.  * clearactortraits actorid
  206.  * clearpartymembertraits actorpos
  207.  * clearenemytraits enemy
  208.  *
  209.  *  - Remove all ingame traits to specified actor, actor in party or in
  210.  *    battle enemy.
  211.  *
  212.  * ============================================================================
  213.  * Incompatibilities
  214.  * ============================================================================
  215.  *
  216.  * There's no known incompatible plugins yet.
  217.  *
  218.  * ============================================================================
  219.  * Known isues
  220.  * ============================================================================
  221.  *
  222.  * Not yet.
  223.  *
  224.  * ============================================================================
  225.  * Changelog
  226.  * ============================================================================
  227.  *
  228.  * Version 1.01:
  229.  * - Added battle switches and variables.
  230.  * - Added eval system.
  231.  * - Added more js functions.
  232.  *
  233.  * Version 1.00:
  234.  * - Finished plugin!
  235.  *
  236.  * ============================================================================
  237.  *
  238.  * For commercial and non-commercial games.
  239.  * Credit to ICF-Soft.
  240.  * Any plugin that needs this to work must add a clausule to say that ICF-Soft
  241.  * must be included in credits page.
  242.  * This entire header and plugin readme files must be included with plugin.
  243.  *
  244.  * ============================================================================
  245. */
  246. //=============================================================================
  247.  /*:es
  248.  * @plugindesc v1.01c Librería sdk con muchas utilidades para desarrolladores
  249.  * de juegos y complementos.
  250.  * @author ICF-Soft [http://icfsoft.blogspot.com.es/]
  251.  *
  252.  * @help
  253.  * ============================================================================
  254.  * Introducción
  255.  * ============================================================================
  256.  *
  257.  * Este complemento es una librería sdk con un montón de utilidades para
  258.  * programar más fácil.
  259.  * Es necesario para la mayoría de mis complementos.
  260.  *
  261.  * Incluye:
  262.  *  -Sistema json para editar/añadir campos.
  263.  *  -sistema especial de características que permite añadir características
  264.  *      en datos que normalmente no tienen (habilidades y objetos), añadir
  265.  *      características a los personajes y enemigos durante el juego y un
  266.  *      sistema especial de subcaracterísticas.
  267.  *  -Sistema de interruptores y variables locales y de batalla.
  268.  *  -Sistema de ejecución de código javascript.
  269.  *  -Funciones extra para algunos objetos predefinidos de javascript.
  270.  *
  271.  * ============================================================================
  272.  * Uso
  273.  * ============================================================================
  274.  *
  275.  * Para añadir o editar datos se utilizan las etiquetas en las notas.
  276.  * Para desarrolladores de plugins se recomienda que se muestre cómo usarlas
  277.  * en sus plugins.
  278.  *
  279.  *
  280.  * La etiqueta 'Json master' permite alterar los datos de un modo particular.
  281.  * Puedes añadir nuevos campos o editarlos sin las restricciones predeterminadas,
  282.  * funciona en notación json, mejor que las simples etiquetas meta.
  283.  *
  284.  * Utiliza cada linea entre las etiquetas de abertura y cierre para editar
  285.  * un campo, primero el nombre del campo, luego dos puntos, un espacio y el
  286.  * código en formato json.
  287.  *
  288.  * Ejemplo:
  289.  *
  290.  * <JSON MASTER>
  291.  * gold: 50000000
  292.  * hands_power: [50,100]
  293.  * alias: 'Romistrugio'
  294.  * </JSON MASTER>
  295.  *
  296.  *
  297.  * La etiqueta 'Traits master' permite añadir características o rasgos.
  298.  * En cada linea entre las etiquetas de apertura y cierre van tres números
  299.  * separados por espacios. Se recomienda usar los tres aún cuando el rasgo
  300.  * solo necesite dos, puedes continuar la linea con comentarios.
  301.  * Puedes usar un nombre en lugar del primer número (en el archivo leeme
  302.  * puedes encontrar todos los disponibles).
  303.  *
  304.  * Ejemplo:
  305.  *
  306.  * <TRAITS MASTER>
  307.  * elem_rate 1 1.5
  308.  * 21 1 2
  309.  * 31 2 0 -Elemento de ataque
  310.  * </TRAITS MASTER>
  311.  *
  312.  *
  313.  * La etiqueta 'Subtraits master' permite añadir conjuntos de rasgos para
  314.  * diferentes usos tales como rasgos de subclase, rasgos aleatorios para
  315.  * enemigos/objetos/armas, fases de un estado alterado y más.
  316.  * Funciona como la etiqueta anterior pero no necesitas cerrar antes de abrir
  317.  * un nuevo subconjunto.
  318.  *
  319.  * Ejemplo:
  320.  *
  321.  * <SUBTRAITS MASTER> -Limo de fuego
  322.  * elem_rate 1 1.5
  323.  * 11 2 0.5
  324.  * 31 2 0 -Ataca con fuego
  325.  * <SUBTRAITS MASTER> -Limo de hielo
  326.  * elem_rate 1 1.5
  327.  * 11 2 2.1
  328.  * 31 3 0 -Ataca con hielo
  329.  * </SUBTRAITS MASTER>
  330.  *
  331.  * Nota: Varios complementos pueden usar subconjuntos para las mismas tablas
  332.  * de la base de datos para diferentes propósitos, de modo que debes
  333.  * proveer un modo de usar subconjuntos específicos, por ejemplo algo así
  334.  * como "<MiIncreiblePluginSubtraits primero ultimo>" podría ser útil.
  335.  *
  336.  * Para acceder a un subconjunto se utiliza 'item.subtraits[i].traits' en
  337.  * lugar de 'item.traits', donde 'i' es el índice.
  338.  * Y para el objeto del subconjunto usar 'item.subtraits[i]' en lugar de 'item'.
  339.  *
  340.  *
  341.  * La etiqueta 'JSEval master' permite añadir código javascript que se
  342.  * ejecutará en condiciones específicas o diversos propósitos.
  343.  * Se puede hacer de una clave, dos o las que hagan falta, y no hace falta
  344.  * cerrar la etiqueta cuando se ponen consecutivas.
  345.  *
  346.  * Ejemplo:
  347.  *
  348.  * <JSEVAL MASTER A>
  349.  * this.gainTp(15);
  350.  * <JSEVAL MASTER A B>
  351.  * if (this == subject) this.gainMp(-10);
  352.  * v.setValue(10, v.value(10) + 2);
  353.  * </JSEVAL MASTER>
  354.  *
  355.  * Hay algunas variables a las que se puede acceder dentro del código:
  356.  *   - subject: el sujeto de la acción.
  357.  *   - item: el objeto usado en la acción. Puede ser un objeto o habilidad.
  358.  *   - isSkill: comprueba si se trata de una habilidad.
  359.  *
  360.  * ============================================================================
  361.  * Interruptores y Variables de Batalla
  362.  * ============================================================================
  363.  *
  364.  * Son nuevos interruptores y variables reciclables que se reinician en
  365.  * cada batalla. Útiles para dividir la batalla en fases sin tocar otros
  366.  * interruptores o variables.
  367.  *
  368.  * Muy útiles para plugins que afectan las batallas.
  369.  *
  370.  * Para más información ver el archivo leeme.
  371.  *
  372.  * ============================================================================
  373.  * Comandos de complemento
  374.  * ============================================================================
  375.  *
  376.  * selfswitch x true/false
  377.  * mapswitch x true/false
  378.  * actorswitch actorid x true/false
  379.  * battleswitch x true/false
  380.  * enemybattleswitch enemyposition x true/false
  381.  *
  382.  *  - Activa o desactiva el autointerruptor, interruptor de mapa
  383.  *    o de personaje.
  384.  *
  385.  * remoteswitch mapid eventid x true/false
  386.  *
  387.  *  - Activa o desactiva el autointerruptor o interruptor de mapa específico
  388.  *    de forma remota. Usar eventid 0 para interruptor de mapa.
  389.  *
  390.  * selfvariable x value
  391.  * mapvariable x value
  392.  * actorvariable actorid x value
  393.  * battlevariable x value
  394.  * enemybattlevariable enemyposition x value
  395.  *
  396.  *  - Cambia el valor de la variable de evento, mapa o personaje.
  397.  *    Se pueden añadir los prefijos increase/multiply/divide/mod.
  398.  *
  399.  * remotevariable mapid eventid x value
  400.  *
  401.  *  - Cambia el valor de la variable de evento o mapa específico
  402.  *    de forma remota. Usar eventid 0 para interruptor de mapa.
  403.  *
  404.  * actortraitadd actorid code id value
  405.  * partymembertraitadd actorpos code id value
  406.  * enemytraitadd enemy code id value
  407.  *
  408.  *  - Añade un rasgo dentro del juego para el personaje, personaje del
  409.  *    grupo o enemigo.
  410.  *    No comprueba si existen repetidos (mismos code e id).
  411.  *
  412.  * actortrait actorid code id value
  413.  * partymembertrait actorpos code id value
  414.  * enemytrait enemy code id value
  415.  *
  416.  *  - Asegura un rasgo dentro del juego para el personaje, personaje del
  417.  *    grupo o enemigo. Si no hay se añade, si hay almenos uno se
  418.  *    sobreescribe y el resto se elimina.
  419.  *
  420.  * actortraitplus actorid code id value
  421.  * partymembertraitplus actorpos code id value
  422.  * enemytraitplus enemy code id value
  423.  *
  424.  *  - Incrementa un rasgo dentro del juego para el personaje, personaje del
  425.  *    grupo o enemigo. Si no hay se añade, si hay almenos uno se
  426.  *    todos los que tenga se combinan mediante suma.
  427.  *
  428.  * actortraitrate actorid code id value
  429.  * partymembertraitrate actorpos code id value
  430.  * enemytraitrate enemy code id value
  431.  *
  432.  *  - Multiplica un rasgo dentro del juego para el personaje, personaje del
  433.  *    grupo o enemigo. Si no hay se añade, si hay almenos uno se
  434.  *    todos los que tenga se combinan mediante multiplicación.
  435.  *
  436.  * removeactortrait actorid code id
  437.  * removepartymembertrait actorpos code id
  438.  * removeenemytraitenemy code id
  439.  *
  440.  *  - Elimina todos los rasgos dentro del juego con código e id específicos
  441.  *    del personaje, personaje del grupo o enemigo.
  442.  *
  443.  * clearactortraits actorid
  444.  * clearpartymembertraits actorpos
  445.  * clearenemytraits enemy
  446.  *
  447.  *  - Elimina todos los rasgos dentro del juego del personaje, personaje
  448.  *    del grupo o enemigo.
  449.  *
  450.  * ============================================================================
  451.  * Incompatibilidades
  452.  * ============================================================================
  453.  *
  454.  * No se conocen complementos que sean incompatibles hasta la fecha.
  455.  *
  456.  * ============================================================================
  457.  * Problemas conocidos
  458.  * ============================================================================
  459.  *
  460.  * Por el momento ninguno.
  461.  *
  462.  * ============================================================================
  463.  * Historial de versiones
  464.  * ============================================================================
  465.  *
  466.  * Versión 1.01:
  467.  * - Se han añadido interruptores y variables de batalla.
  468.  * - Se han añadido funciones evaluables.
  469.  * - Se han añadido más funciones extra.
  470.  *
  471.  * Versión 1.00:
  472.  * - Complemento terminado.
  473.  *
  474.  * ============================================================================
  475.  *
  476.  * Para juegos comerciales y no comerciales.
  477.  * Se debe incluir a ICF-Soft en los créditos.
  478.  * Cualquier plugin que necesite este para funcionar debe incluir una cláusula
  479.  * que indique que se debe incluir a ICF-Soft en los créditos.
  480.  * Esta cabecera y los archivos leeme del complemento deben incluirse
  481.  * íntegramente con el plugin.
  482.  *
  483.  * ============================================================================
  484. */
  485. //=============================================================================
  486.  
  487. //=============================================================================
  488. // Parameter Variables
  489. //=============================================================================
  490.  
  491. ICF.Parameters = PluginManager.parameters('ICFSoft_MainUtility');
  492. ICF.Param = ICF.Param || {};
  493.  
  494. //=============================================================================
  495. // Constants
  496. //=============================================================================
  497.  
  498. ICF.MainUtility.traittags = [
  499.     ['elem_rate', 11, 0],
  500.     ['debuffrate', 12, 0],
  501.     ['ndebuffrate', 12, 10],
  502.     ['state_rate', 13, 0],
  503.     ['state_resist', 14, 0],
  504.     ['skill_rate', 15, 0],
  505.     ['itemdamage_rate', 15, 2000],
  506.     ['weapon_rate', 16, 0],
  507.     ['elem_absorb', 17, 0],
  508.     ['elem_curse', 18, 0],
  509.     ['elem_reflect', 19, 0],
  510.     ['paramplus', 21, 10],
  511.     ['paramrate', 21, 0],
  512.     ['paramflat', 21, 20],
  513.     ['paramxrate', 21, 30],
  514.     ['xparamplus', 22, 0],
  515.     ['xparamrate', 22, 10],
  516.     ['xparamflat', 22, 20],
  517.     ['sparamplus', 23, 10],
  518.     ['sparamrate', 23, 0],
  519.     ['sparamflat', 23, 20],
  520.     ['nparamplus', 24, 0],
  521.     ['nparamrate', 24, 10],
  522.     ['nparamflat', 24, 20],
  523.     ['nparamxrate', 24, 30],
  524.     ['pparamplus', 25, 0],
  525.     ['pparamrate', 25, 10],
  526.     ['pparamflat', 25, 20],
  527.     ['attack_elem', 31, 0],
  528.     ['attack_state', 32, 0],
  529.     ['attack_speed', 33, 0],
  530.     ['attack_times', 34, 0],
  531.     ['attack_weapon', 35, 0],
  532.     ['elem_enhace', 36, 0],
  533.     ['skill_enhace', 36, 2000],
  534.     ['weapon_enhace', 36, 4000],
  535.     ['itemdamage_enhace', 36, 6000],
  536.     ['stypeadd', 41, 0],
  537.     ['stypeseal', 42, 0],
  538.     ['skilladd', 43, 0],
  539.     ['skillseal', 44, 0],
  540.     ['equipweapon', 51, 0],
  541.     ['equiparmor', 52, 0],
  542.     ['equiplock', 53, 0],
  543.     ['equipseal', 54, 0],
  544.     ['slot_type', 55, 0],
  545.     ['action_plus', 61, 0],
  546.     ['special_flag', 62, 0],
  547.     ['collapse_type', 63, 0],
  548.     ['party_ability', 64, 0]
  549. ];
  550.  
  551. var $gameSelfvariables    = null;
  552.  
  553. //=============================================================================
  554. // Game_SelfVariables
  555. //=============================================================================
  556.  
  557. function Game_SelfVariables() {
  558.     this.initialize.apply(this, arguments);
  559. }
  560.  
  561. Game_SelfVariables.prototype.initialize = function() {
  562.     this.clear();
  563. };
  564.  
  565. Game_SelfVariables.prototype.clear = function() {
  566.     this._data = {};
  567. };
  568.  
  569. Game_SelfVariables.prototype.value = function(key) {
  570.     return this._data[key] || 0;
  571. };
  572.  
  573. Game_SelfVariables.prototype.strictValue = function(key) {
  574.     var value = Number(this._data[key]);
  575.     return (isNaN(value))? 0 : Number(value);
  576. };
  577.  
  578. Game_SelfVariables.prototype.setValue = function(key, value) {
  579.     if (value) {
  580.         this._data[key] = (isNaN(Number(value))||Array.isArray(value))? value : Number(value);
  581.     } else {
  582.         delete this._data[key];
  583.     }
  584.     this.onChange();
  585. };
  586.  
  587. Game_SelfVariables.prototype.increaseValue = function(key, value) {
  588.     var val = Number(this._data[key] || 0);
  589.     if (isNaN(val)||isNaN(value)) return;
  590.     this._data[key] = Number(this._data[key] || 0) + Number(value);
  591.     this.onChange();
  592. };
  593.  
  594. Game_SelfVariables.prototype.multiplyValue = function(key, value) {
  595.     var val = Number(this._data[key] || 0);
  596.     if (isNaN(val)||isNaN(value)) return;
  597.     this._data[key] = Number(this._data[key] || 0) * Number(value);
  598.     this.onChange();
  599. };
  600.  
  601. Game_SelfVariables.prototype.divideValue = function(key, value) {
  602.     var val = Number(this._data[key] || 0);
  603.     if (isNaN(val)||isNaN(value)||value == 0) return;
  604.     this._data[key] = Number(this._data[key] || 0) / Number(value);
  605.     this.onChange();
  606. };
  607.  
  608. Game_SelfVariables.prototype.modValue = function(key, value) {
  609.     var val = Number(this._data[key] || 0);
  610.     if (isNaN(val)||isNaN(value)||value == 0) return;
  611.     this._data[key] = Number(this._data[key] || 0) % Number(value);
  612.     this.onChange();
  613. };
  614.  
  615. Game_SelfVariables.prototype.onChange = function() {
  616.     $gameMap.requestRefresh();
  617. };
  618.  
  619. //=============================================================================
  620. // Game_BattleSwitches
  621. //=============================================================================
  622.  
  623. function Game_BattleSwitches() {
  624.     this.initialize.apply(this, arguments);
  625. }
  626.  
  627. Game_BattleSwitches.prototype.initialize = function() {
  628.     this.clear();
  629. };
  630.  
  631. Game_BattleSwitches.prototype.clear = function() {
  632.     this._data = {};
  633. };
  634.  
  635. Game_BattleSwitches.prototype.value = function(key) {
  636.     return !!this._data[key];
  637. };
  638.  
  639. Game_BattleSwitches.prototype.setValue = function(key, value) {
  640.     if (value) {
  641.         this._data[key] = true;
  642.     } else {
  643.         delete this._data[key];
  644.     }
  645.     this.onChange();
  646. };
  647.  
  648. Game_BattleSwitches.prototype.onChange = function() {
  649.     //$gameMap.requestRefresh();
  650. };
  651.  
  652. var $gameBattleSwitches = new Game_BattleSwitches();
  653.  
  654. //=============================================================================
  655. // Game_BattleVariables
  656. //=============================================================================
  657.  
  658. function Game_BattleVariables() {
  659.     this.initialize.apply(this, arguments);
  660. }
  661.  
  662. Game_BattleVariables.prototype.initialize = function() {
  663.     this.clear();
  664. };
  665.  
  666. Game_BattleVariables.prototype.clear = function() {
  667.     this._data = {};
  668. };
  669.  
  670. Game_BattleVariables.prototype.value = function(key) {
  671.     return this._data[key] || 0;
  672. };
  673.  
  674. Game_BattleVariables.prototype.strictValue = function(key) {
  675.     var value = Number(this._data[key]);
  676.     return (isNaN(value))? 0 : Number(value);
  677. };
  678.  
  679. Game_BattleVariables.prototype.setValue = function(key, value) {
  680.     if (value) {
  681.         this._data[key] = (isNaN(Number(value))||Array.isArray(value))? value : Number(value);
  682.     } else {
  683.         delete this._data[key];
  684.     }
  685.     this.onChange();
  686. };
  687.  
  688. Game_BattleVariables.prototype.increaseValue = function(key, value) {
  689.     var val = Number(this._data[key] || 0);
  690.     if (isNaN(val)||isNaN(value)) return;
  691.     this._data[key] = Number(this._data[key] || 0) + Number(value);
  692.     this.onChange();
  693. };
  694.  
  695. Game_BattleVariables.prototype.multiplyValue = function(key, value) {
  696.     var val = Number(this._data[key] || 0);
  697.     if (isNaN(val)||isNaN(value)) return;
  698.     this._data[key] = Number(this._data[key] || 0) * Number(value);
  699.     this.onChange();
  700. };
  701.  
  702. Game_BattleVariables.prototype.divideValue = function(key, value) {
  703.     var val = Number(this._data[key] || 0);
  704.     if (isNaN(val)||isNaN(value)||value == 0) return;
  705.     this._data[key] = Number(this._data[key] || 0) / Number(value);
  706.     this.onChange();
  707. };
  708.  
  709. Game_BattleVariables.prototype.modValue = function(key, value) {
  710.     var val = Number(this._data[key] || 0);
  711.     if (isNaN(val)||isNaN(value)||value == 0) return;
  712.     this._data[key] = Number(this._data[key] || 0) % Number(value);
  713.     this.onChange();
  714. };
  715.  
  716. Game_BattleVariables.prototype.onChange = function() {
  717.     //$gameMap.requestRefresh();
  718. };
  719.  
  720. var $gameBattleVariables = new Game_BattleVariables();
  721.  
  722. //=============================================================================
  723. // DataManager
  724. //=============================================================================
  725.  
  726. ICF.MainUtility.extractMetadata = DataManager.extractMetadata;
  727. DataManager.extractMetadata = function(data) {
  728.     ICF.MainUtility.extractMetadata.call(this, data);
  729.     var note1 = /<(?:JSON MASTER)>/i;
  730.     var note2 = /<\/(?:JSON MASTER)>/i;
  731.     var note3 = /<(?:TRAITS MASTER)>/i;
  732.     var note4 = /<\/(?:TRAITS MASTER)>/i;
  733.     var note5 = /<(?:SUBTRAITS MASTER)>/i;
  734.     var note6 = /<\/(?:SUBTRAITS MASTER)>/i;
  735.     var note7 = /<(?:JSEVAL MASTER)[ ]+(\w+(?:\s+\w+)*)[ ]*>/i;
  736.     var note8 = /<\/(?:JSEVAL MASTER)>/i;
  737.  
  738.     var notedata = data.note.split(/[\r\n]+/);
  739.  
  740.     var flag1 = false;
  741.     var flag2 = false;
  742.     var flag3 = false;
  743.     var flag4 = false;
  744.  
  745.     var subindex = -1;
  746.  
  747.     data.jsreactions = data.jsreactions || {};
  748.     var key = '';
  749.  
  750.     for (var i = 0; i < notedata.length; i++) {
  751.     var line = notedata[i].trim().replace(/\s+/g, ' ');
  752.     if (line.match(note1)) {
  753.         flag1 = true;
  754.     } else if (line.match(note2)) {
  755.         flag1 = false;
  756.     } else if (line.match(note3)) {
  757.         flag2 = true;
  758.         data.traits = data.traits || [];
  759.     } else if (line.match(note4)) {
  760.         flag2 = false;
  761.     } else if (line.match(note5)) {
  762.         flag3 = true;
  763.         subindex += 1;
  764.         data.subtraits = data.subtraits || [];
  765.         data.subtraits[subindex] = data.subtraits[subindex] || {};
  766.         data.subtraits[subindex].traits = data.subtraits[subindex].traits || [];
  767.     } else if (line.match(note6)) {
  768.         flag3 = false;
  769.     } else if (line.match(note7)) {
  770.         flag4 = true;
  771.         key = RegExp.$1.split(/\s+/);
  772.         data.jsreactions[key] = data.jsreactions[key] || '';
  773.     } else if (line.match(note8)) {
  774.         flag4 = false;
  775.         key = '';
  776.     } else if (flag1) {
  777.         var field = line.split(":")[0];
  778.         line = line.substring(line.indexOf(':') + 1);
  779.         data[field] = JsonEx.parse(line);
  780.     } else if (flag2) {
  781.         line = line.split(" ").clean();
  782.         if (isNaN(Number(line[0]))) {line = ICF.MainUtility.gettfield(line);};
  783.         if (line[0] > -1) {data.traits.push({code:Number(line[0]), dataId:Number(line[1]), value:Number(line[2])});};
  784.     } else if (flag3) {
  785.         line = line.split(" ").clean();
  786.         if (isNaN(Number(line[0]))) {line = ICF.MainUtility.gettfield(line);};
  787.         if (line[0] > -1) {data.subtraits[subindex].traits.push({code:Number(line[0]), dataId:Number(line[1]), value:Number(line[2])});};
  788.     } else if (flag4) {
  789.         data.jsreactions[key] = data.jsreactions[key] + line + '\n';
  790.     }
  791.  
  792.     }
  793. };
  794.  
  795. if (!Imported.ICFSoft_MainCore) {
  796.     ICF.MainUtility.createGameObjects = DataManager.createGameObjects;
  797.     DataManager.createGameObjects = function() {
  798.     ICF.MainUtility.createGameObjects.call(this);
  799.     $gameSelfVariables = new Game_SelfVariables();
  800.     };
  801.  
  802.     ICF.MainUtility.extractSaveContents = DataManager.extractSaveContents;
  803.     DataManager.extractSaveContents = function(contents) {
  804.     ICF.MainUtility.extractSaveContents.call(this, contents);
  805.     $gameSelfVariables = contents.selfVariables;
  806.     if (!$gameSelfVariables) $gameSelfVariables = new Game_SelfVariables();
  807.     };
  808.  
  809.     ICF.MainUtility.makeSaveContents = DataManager.makeSaveContents;
  810.     DataManager.makeSaveContents = function() {
  811.     var contents = ICF.MainUtility.makeSaveContents.call(this);
  812.     contents.selfvariables = $gameSelfvariables;
  813.     return contents;
  814.     };
  815.  
  816. } else {
  817.     ICF.MainUtility.createGameObjects = DataManager.createGameObjectsPhase1;
  818.     DataManager.createGameObjectsPhase1 = function() {
  819.     ICF.MainUtility.createGameObjects.call(this);
  820.     $gameSelfVariables = new Game_SelfVariables();
  821.     };
  822.  
  823.     ICF.MainUtility.extractSaveContents = DataManager.extractSaveContentsPhase1;
  824.     DataManager.extractSaveContentsPhase1 = function(contents) {
  825.     ICF.MainUtility.extractSaveContents.call(this, contents);
  826.     $gameSelfVariables = contents.selfVariables;
  827.     if (!$gameSelfVariables) $gameSelfVariables = new Game_SelfVariables();
  828.     };
  829.  
  830.     ICF.MainUtility.makeSaveContents = DataManager.makeSaveContentsPhase1;
  831.     DataManager.makeSaveContentsPhase1 = function() {
  832.     var contents = ICF.MainUtility.makeSaveContents.call(this);
  833.     contents.selfvariables = $gameSelfvariables;
  834.     return contents;
  835.     };
  836.  
  837. }
  838.  
  839.  
  840. //=============================================================================
  841. // Game_BattlerBase
  842. //=============================================================================
  843.  
  844. ICF.MainUtility.traitObjects = Game_BattlerBase.prototype.traitObjects;
  845. Game_BattlerBase.prototype.traitObjects = function() {
  846.     if (!this._traitsObject) {
  847.     this._traitsObject = {};
  848.     this._traitsObject.traits = [];
  849.     }
  850.     return ICF.MainUtility.traitObjects.call(this).concat([this._traitsObject]);
  851. };
  852.  
  853. ICF.MainUtility.initMembers = Game_BattlerBase.prototype.initMembers;
  854. Game_BattlerBase.prototype.initMembers = function() {
  855.     ICF.MainUtility.initMembers.call(this);
  856.     this._traitsObject = {};
  857.     this._traitsObject.traits = [];
  858. };
  859.  
  860. Game_BattlerBase.prototype.clearTraits = function() {
  861.     this._traitsObject.traits = [];
  862. };
  863.  
  864. Game_BattlerBase.prototype.selfswitch = function(selfswitch) { return false;};
  865.  
  866. Game_BattlerBase.prototype.setselfswitch = function(selfswitch, value) { };
  867.  
  868. Game_BattlerBase.prototype.battleswitch = function(selfswitch) { return false;};
  869.  
  870. Game_BattlerBase.prototype.setbattleswitch = function(selfswitch, value) { };
  871.  
  872. Game_BattlerBase.prototype.selfvariable = function(selfvariable) { return 0;};
  873.  
  874. Game_BattlerBase.prototype.strictselfvariable = function(selfvariable) { return 0;};
  875.  
  876. Game_BattlerBase.prototype.setselfvariable = function(selfvariable, value) { };
  877.  
  878. Game_BattlerBase.prototype.increaseselfvariable = function(selfvariable, value) { };
  879.  
  880. Game_BattlerBase.prototype.multiplyselfvariable = function(selfvariable, value) { };
  881.  
  882. Game_BattlerBase.prototype.divideselfvariable = function(selfvariable, value) { };
  883.  
  884. Game_BattlerBase.prototype.modselfvariable = function(selfvariable, value) { };
  885.  
  886. Game_BattlerBase.prototype.battlevariable = function(selfvariable) { return 0;};
  887.  
  888. Game_BattlerBase.prototype.strictbattlevariable = function(selfvariable) { return 0;};
  889.  
  890. Game_BattlerBase.prototype.setbattlevariable = function(selfvariable, value) { };
  891.  
  892. Game_BattlerBase.prototype.increasebattlevariable = function(selfvariable, value) { };
  893.  
  894. Game_BattlerBase.prototype.multiplybattlevariable = function(selfvariable, value) { };
  895.  
  896. Game_BattlerBase.prototype.dividebattlevariable = function(selfvariable, value) { };
  897.  
  898. Game_BattlerBase.prototype.modbattlevariable = function(selfvariable, value) { };
  899.  
  900. Game_BattlerBase.prototype.jsevalObjects = function() {
  901.     return this.states().filter(function(obj) {
  902.         return Object.keys(obj.jsreactions).length > 0;
  903.     });
  904. };
  905.  
  906. Game_BattlerBase.prototype.jsevalReactions = function(subject, item, isSkill, reaction) {
  907.     var jsevalobjects = this.jsevalObjects();
  908.     var s = $gameSwitches._data;
  909.     var v = $gameVariables._data;
  910.  
  911.     for (var h = 0; h < jsevalobjects.length; h++) {
  912.     if (jsevalobjects[h].jsreactions[reaction]) eval(jsevalobjects[h].jsreactions[reaction]);
  913.     }
  914. };
  915.  
  916. Game_BattlerBase.prototype.jsevalArrayReactions = function(subject, item, isSkill, reactions) {
  917.     var jsevalobjects = this.jsevalObjects();
  918.     var s = $gameSwitches._data;
  919.     var v = $gameVariables._data;
  920.  
  921.     for (var h = 0; h < jsevalobjects.length; h++) {
  922.     for (var i = 0; i < reactions.length; i++) {
  923.         if (jsevalobjects[h].jsreactions[reactions[i]]) eval(jsevalobjects[h].jsreactions[reactions[i]]);
  924.     }
  925.     }
  926. };
  927.  
  928. Game_BattlerBase.prototype.jsevalBulkReactions = function(subject, item, isSkill, reactions) {
  929.     var jsevalobjects = this.jsevalObjects();
  930.     var s = $gameSwitches._data;
  931.     var v = $gameVariables._data;
  932.  
  933.     for (var h = 0; h < jsevalobjects.length; h++) {
  934.     for (var i = 0; i < reactions.length; i++) {
  935.         for (var j = 0; j < reactions[i][1].length; j++) {
  936.             var key = [reactions[i][0],reactions[i][1][j]];
  937.             if (jsevalobjects[h].jsreactions[key]) eval(jsevalobjects[h].jsreactions[key]);
  938.         }
  939.     }
  940.     }
  941. };
  942.  
  943. //=============================================================================
  944. // Game_Battler
  945. //=============================================================================
  946.  
  947. if (!Imported.ICFSoft_MainCore) {
  948.     Game_Battler.prototype.gainHp = function(value) {
  949.     this._result.hpDamage -= value;
  950.     this._result.hpAffected = true;
  951.     this.setHp(this.hp + value);
  952.     };
  953.  
  954.     Game_Battler.prototype.gainMp = function(value) {
  955.     this._result.mpDamage -= value;
  956.     this.setMp(this.mp + value);
  957.     };
  958.  
  959.     Game_Battler.prototype.gainTp = function(value) {
  960.     this._result.tpDamage -= value;
  961.     this.setTp(this.tp + value);
  962.     };
  963. }
  964.  
  965. //=============================================================================
  966. // Game_Actor
  967. //=============================================================================
  968.  
  969. Game_Actor.prototype.selfswitch = function(selfswitch) {
  970.     var key = [0, this._actorId, selfswitch];
  971.     return $gameSelfSwitches.value(key);
  972. }
  973.  
  974. Game_Actor.prototype.setselfswitch = function(selfswitch, value) {
  975.     ICF.MainUtility.CustomSwitch(0, this._actorId, selfswitch, value);
  976. }
  977.  
  978. Game_Actor.prototype.selfvariable = function(selfvariable) {
  979.     var key = [0, this._actorId, selfvariable];
  980.     return $gameSelfVariables.value(key);
  981. }
  982.  
  983. Game_Actor.prototype.strictselfvariable = function(selfvariable) {
  984.     var key = [0, this._actorId, selfvariable];
  985.     return $gameSelfVariables.strictValue(key);
  986. }
  987.  
  988. Game_Actor.prototype.setselfvariable = function(selfvariable, value) {
  989.     ICF.MainUtility.CustomVariable(0, this._actorId, selfvariable, value);
  990. }
  991.  
  992. Game_Actor.prototype.increaseselfvariable = function(selfvariable, value) {
  993.     ICF.MainUtility.IncreaseCustomVariable(0, this._actorId, selfvariable, value);
  994. }
  995.  
  996. Game_Actor.prototype.multiplyselfvariable = function(selfvariable, value) {
  997.     ICF.MainUtility.MultiplyCustomVariable(0, this._actorId, selfvariable, value);
  998. }
  999.  
  1000. Game_Actor.prototype.divideselfvariable = function(selfvariable, value) {
  1001.     ICF.MainUtility.DivideCustomVariable(0, this._actorId, selfvariable, value);
  1002. }
  1003.  
  1004. Game_Actor.prototype.modselfvariable = function(selfvariable, value) {
  1005.     ICF.MainUtility.ModCustomVariable(0, this._actorId, selfvariable, value);
  1006. }
  1007.  
  1008. Game_Actor.prototype.jsevalObjects = function() {
  1009.     var objects = [this.actor(), this.currentClass()];
  1010.     objects = objects.concat(Game_Battler.prototype.jsevalObjects.call(this));
  1011.     var equips = this.equips();
  1012.     for (var i = 0; i < equips.length; i++) {
  1013.         var item = equips[i];
  1014.         if (item) {
  1015.             objects.push(item);
  1016.         }
  1017.     }
  1018.     return objects.filter(function(obj) {
  1019.         return Object.keys(obj.jsreactions).length > 0;
  1020.     });
  1021. };
  1022.  
  1023. //=============================================================================
  1024. // Game_Enemy
  1025. //=============================================================================
  1026.  
  1027. Game_Enemy.prototype.battleswitch = function(battleswitch) {
  1028.     var key = ["e", this.index(), battleswitch];
  1029.     return $gameBattleSwitches.value(key);
  1030. }
  1031.  
  1032. Game_Enemy.prototype.setbattleswitch = function(battleswitch, value) {
  1033.     var key = ["e", this.index(), battleswitch];
  1034.     value = (value.toString().toLowerCase() === "true");
  1035.     $gameBattleSwitches.setValue(key, value);
  1036. }
  1037.  
  1038. Game_Enemy.prototype.battlevariable = function(battlevariable) {
  1039.     var key = ["e", this.index(), battlevariable];
  1040.     return $gameBattleVariables.value(key);
  1041. }
  1042.  
  1043. Game_Enemy.prototype.strictbattlevariable = function(battlevariable) {
  1044.     var key = ["e", this.index(), battlevariable];
  1045.     return $gameBattleVariables.strictValue(key);
  1046. }
  1047.  
  1048. Game_Enemy.prototype.setbattlevariable = function(battlevariable, value) {
  1049.     var _key = ["e", this.index(), battlevariable];
  1050.     $gameBattleVariables.setValue(_key, value);
  1051. }
  1052.  
  1053. Game_Enemy.prototype.increasebattlevariable = function(battlevariable, value) {
  1054.     var _key = ["e", this.index(), battlevariable];
  1055.     $gameBattleVariables.increaseValue(_key, value);
  1056. }
  1057.  
  1058. Game_Enemy.prototype.multiplybattlevariable = function(battlevariable, value) {
  1059.     var _key = ["e", this.index(), battlevariable];
  1060.     $gameBattleVariables.multiplyValue(_key, value);
  1061. }
  1062.  
  1063. Game_Enemy.prototype.dividebattlevariable = function(battlevariable, value) {
  1064.     var _key = ["e", this.index(), battlevariable];
  1065.     $gameBattleVariables.divideValue(_key, value);
  1066. }
  1067.  
  1068. Game_Enemy.prototype.modbattlevariable = function(battlevariable, value) {
  1069.     var _key = ["e", this.index(), battlevariable];
  1070.     $gameBattleVariables.modValue(_key, value);
  1071. }
  1072.  
  1073. Game_Enemy.prototype.jsevalObjects = function() {
  1074.     var objects = [this.enemy()];
  1075.     objects = objects.concat(Game_Battler.prototype.jsevalObjects.call(this));
  1076.     return objects.filter(function(obj) {
  1077.         return Object.keys(obj.jsreactions).length > 0;
  1078.     });
  1079. };
  1080.  
  1081. //=============================================================================
  1082. // Game_Unit
  1083. //=============================================================================
  1084.  
  1085. Game_Unit.prototype.selfswitch = function(selfswitch) { return false;};
  1086.  
  1087. Game_Unit.prototype.selfvariable = function(selfvariable) { return 0;};
  1088.  
  1089. Game_Unit.prototype.maxselfvariable = function(selfvariable) { return 0;};
  1090.  
  1091. Game_Unit.prototype.minselfvariable = function(selfvariable) { return 0;};
  1092.  
  1093. Game_Unit.prototype.avgselfvariable = function(selfvariable) { return 0;};
  1094.  
  1095. Game_Unit.prototype.battleswitch = function(battleswitch) { return false;};
  1096.  
  1097. Game_Unit.prototype.battlevariable = function(battlevariable) { return 0;};
  1098.  
  1099. Game_Unit.prototype.maxbattlevariable = function(battlevariable) { return 0;};
  1100.  
  1101. Game_Unit.prototype.minbattlevariable = function(battlevariable) { return 0;};
  1102.  
  1103. Game_Unit.prototype.avgbattlevariable = function(battlevariable) { return 0;};
  1104.  
  1105. //=============================================================================
  1106. // Game_Troop
  1107. //=============================================================================
  1108.  
  1109. ICF.MainUtility.clearTroop = Game_Troop.prototype.clear;
  1110. Game_Troop.prototype.clear = function() {
  1111.     ICF.MainUtility.clearTroop.call(this);
  1112.     $gameBattleSwitches.clear();
  1113.     $gameBattleVariables.clear();
  1114. };
  1115.  
  1116. Game_Troop.prototype.battleswitch = function(battleswitch) {
  1117.     this.aliveMembers().forEach(function(enemy) {
  1118.         if (enemy.battleswitch(battleswitch)) {
  1119.             return true;
  1120.         }
  1121.     });
  1122.     return false;
  1123. }
  1124.  
  1125. Game_Troop.prototype.battlevariable = function(battlevariable) {
  1126.     var value = 0;
  1127.     this.aliveMembers().forEach(function(enemy) {
  1128.         value += enemy.strictbattlevariable(battlevariable);
  1129.     });
  1130.     return Math.floor(value);
  1131. }
  1132.  
  1133. Game_Troop.prototype.maxbattlevariable = function(battlevariable) {
  1134.     if (this.aliveMembers().length < 1) return 0;
  1135.     var value = this.aliveMembers()[0].strictbattlevariable(battlevariable);
  1136.     this.aliveMembers().forEach(function(enemy) {
  1137.         value = Math.max(value, enemy.strictbattlevariable(battlevariable));
  1138.     });
  1139.     return Math.floor(value);
  1140. }
  1141.  
  1142. Game_Troop.prototype.minbattlevariable = function(battlevariable) {
  1143.     if (this.aliveMembers().length < 1) return 0;
  1144.     var value = this.aliveMembers()[0].strictbattlevariable(battlevariable);
  1145.     this.aliveMembers().forEach(function(enemy) {
  1146.         value = Math.min(value, enemy.strictbattlevariable(battlevariable));
  1147.     });
  1148.     return Math.floor(value);
  1149. }
  1150.  
  1151. Game_Troop.prototype.avgbattlevariable = function(battlevariable) {
  1152.     if (this.aliveMembers().length < 1) return 0;
  1153.     var value = 0;
  1154.     this.aliveMembers().forEach(function(enemy) {
  1155.         value += enemy.strictbattlevariable(battlevariable);
  1156.     });
  1157.     return Math.floor(value / this.aliveMembers().length);
  1158. }
  1159.  
  1160. //=============================================================================
  1161. // Game_Party
  1162. //=============================================================================
  1163.  
  1164. Game_Party.prototype.selfswitch = function(selfswitch) {
  1165.     this.allMembers().forEach(function(actor) {
  1166.         if (actor.selfswitch(selfswitch)) {
  1167.             return true;
  1168.         }
  1169.     });
  1170.     return false;
  1171. }
  1172.  
  1173. Game_Party.prototype.selfvariable = function(selfvariable) {
  1174.     var value = 0;
  1175.     this.allMembers().forEach(function(actor) {
  1176.         value += actor.strictselfvariable(selfvariable);
  1177.     });
  1178.     return Math.floor(value);
  1179. }
  1180.  
  1181. Game_Party.prototype.maxselfvariable = function(selfvariable) {
  1182.     if (this.allMembers().length < 1) return 0;
  1183.     var value = this.allMembers()[0].strictselfvariable(selfvariable);
  1184.     this.allMembers().forEach(function(actor) {
  1185.         value = Math.max(value, actor.strictselfvariable(selfvariable));
  1186.     });
  1187.     return Math.floor(value);
  1188. }
  1189.  
  1190. Game_Party.prototype.minselfvariable = function(selfvariable) {
  1191.     if (this.allMembers().length < 1) return 0;
  1192.     var value = this.allMembers()[0].strictselfvariable(selfvariable);
  1193.     this.allMembers().forEach(function(actor) {
  1194.         value = Math.min(value, actor.strictselfvariable(selfvariable));
  1195.     });
  1196.     return Math.floor(value);
  1197. }
  1198.  
  1199. Game_Party.prototype.avgselfvariable = function(selfvariable) {
  1200.     if (this.allMembers().length < 1) return 0;
  1201.     var value = 0;
  1202.     this.allMembers().forEach(function(actor) {
  1203.         value += actor.strictselfvariable(selfvariable);
  1204.     });
  1205.     return Math.floor(value / this.allMembers().length);
  1206. }
  1207.  
  1208. //=============================================================================
  1209. // Game_Event
  1210. //=============================================================================
  1211.  
  1212. Game_Event.prototype.selfswitch = function(selfswitch) {
  1213.     var key = [this._mapId, this._eventId, selfswitch];
  1214.     return $gameSelfSwitches.value(key);
  1215. }
  1216.  
  1217. Game_Event.prototype.setselfswitch = function(selfswitch, value) {
  1218.     ICF.MainUtility.CustomSwitch(this._mapId, this._eventId, selfswitch, value);
  1219. }
  1220.  
  1221. Game_Event.prototype.mapswitch = function(mapswitch) {
  1222.     var key = [this._mapId, 0, mapswitch];
  1223.     return $gameSelfSwitches.value(key);
  1224. }
  1225.  
  1226. Game_Event.prototype.setmapswitch = function(mapswitch, value) {
  1227.     ICF.MainUtility.CustomSwitch(this._mapId, 0, mapswitch, value);
  1228. }
  1229.  
  1230. Game_Event.prototype.selfvariable = function(selfvariable) {
  1231.     var key = [this._mapId, this._eventId, selfvariable];
  1232.     return $gameSelfVariables.value(key);
  1233. }
  1234.  
  1235. Game_Event.prototype.strictselfvariable = function(selfvariable) {
  1236.     var key = [this._mapId, this._eventId, selfvariable];
  1237.     return $gameSelfVariables.strictValue(key);
  1238. }
  1239.  
  1240. Game_Event.prototype.setselfvariable = function(selfvariable, value) {
  1241.     ICF.MainUtility.CustomVariable(this._mapId, this._eventId, selfvariable, value);
  1242. }
  1243.  
  1244. Game_Event.prototype.increaseselfvariable = function(selfvariable, value) {
  1245.     ICF.MainUtility.IncreaseCustomVariable(this._mapId, this._eventId, selfvariable, value);
  1246. }
  1247.  
  1248. Game_Event.prototype.multiplyselfvariable = function(selfvariable, value) {
  1249.     ICF.MainUtility.MultiplyCustomVariable(this._mapId, this._eventId, selfvariable, value);
  1250. }
  1251.  
  1252. Game_Event.prototype.divideselfvariable = function(selfvariable, value) {
  1253.     ICF.MainUtility.DivideCustomVariable(this._mapId, this._eventId, selfvariable, value);
  1254. }
  1255.  
  1256. Game_Event.prototype.modselfvariable = function(selfvariable, value) {
  1257.     ICF.MainUtility.ModCustomVariable(this._mapId, this._eventId, selfvariable, value);
  1258. }
  1259.  
  1260. Game_Event.prototype.mapvariable = function(mapvariable) {
  1261.     var key = [this._mapId, 0, mapvariable];
  1262.     return $gameSelfVariables.value(key);
  1263. }
  1264.  
  1265. Game_Event.prototype.strictmapvariable = function(mapvariable) {
  1266.     var key = [this._mapId, 0, mapvariable];
  1267.     return $gameSelfVariables.strictValue(key);
  1268. }
  1269.  
  1270. Game_Event.prototype.setmapvariable = function(mapvariable, value) {
  1271.     ICF.MainUtility.CustomVariable(this._mapId, 0, mapvariable, value);
  1272. }
  1273.  
  1274. Game_Event.prototype.increasemapvariable = function(mapvariable, value) {
  1275.     ICF.MainUtility.IncreaseCustomVariable(this._mapId, 0, mapvariable, value);
  1276. }
  1277.  
  1278. Game_Event.prototype.multiplymapvariable = function(mapvariable, value) {
  1279.     ICF.MainUtility.MultiplyCustomVariable(this._mapId, 0, mapvariable, value);
  1280. }
  1281.  
  1282. Game_Event.prototype.dividemapvariable = function(mapvariable, value) {
  1283.     ICF.MainUtility.DivideCustomVariable(this._mapId, 0, mapvariable, value);
  1284. }
  1285.  
  1286. Game_Event.prototype.modmapvariable = function(mapvariable, value) {
  1287.     ICF.MainUtility.ModCustomVariable(this._mapId, 0, mapvariable, value);
  1288. }
  1289.  
  1290. //=============================================================================
  1291. // Game_Map
  1292. //=============================================================================
  1293.  
  1294. Game_Map.prototype.mapswitch = function(mapswitch) {
  1295.     var key = [this._mapId, 0, mapswitch];
  1296.     return $gameSelfSwitches.value(key);
  1297. }
  1298.  
  1299. Game_Map.prototype.setmapswitch = function(mapswitch, value) {
  1300.     ICF.MainUtility.CustomSwitch(this._mapId, 0, mapswitch, value);
  1301. }
  1302.  
  1303. Game_Map.prototype.mapvariable = function(mapvariable) {
  1304.     var key = [this._mapId, 0, mapvariable];
  1305.     return $gameSelfVariables.value(key);
  1306. }
  1307.  
  1308. Game_Map.prototype.strictmapvariable = function(mapvariable) {
  1309.     var key = [this._mapId, 0, mapvariable];
  1310.     return $gameSelfVariables.strictValue(key);
  1311. }
  1312.  
  1313. Game_Map.prototype.setmapvariable = function(mapvariable, value) {
  1314.     ICF.MainUtility.CustomVariable(this._mapId, 0, mapvariable, value);
  1315. }
  1316.  
  1317. Game_Map.prototype.increasemapvariable = function(mapvariable, value) {
  1318.     ICF.MainUtility.IncreaseCustomVariable(this._mapId, 0, mapvariable, value);
  1319. }
  1320.  
  1321. Game_Map.prototype.multiplymapvariable = function(mapvariable, value) {
  1322.     ICF.MainUtility.MultiplyCustomVariable(this._mapId, 0, mapvariable, value);
  1323. }
  1324.  
  1325. Game_Map.prototype.dividemapvariable = function(mapvariable, value) {
  1326.     ICF.MainUtility.DivideCustomVariable(this._mapId, 0, mapvariable, value);
  1327. }
  1328.  
  1329. Game_Map.prototype.modmapvariable = function(mapvariable, value) {
  1330.     ICF.MainUtility.ModCustomVariable(this._mapId, 0, mapvariable, value);
  1331. }
  1332.  
  1333. //=============================================================================
  1334. // Game_Item
  1335. //=============================================================================
  1336.  
  1337. Game_Item.prototype.traitDataTypes = function(code) {
  1338.     var data = this.object();
  1339.     if ((data == null)||(!data.traits)) return [];
  1340.     data = data.traits;
  1341.     return data.reduce(function(r, obj) {
  1342.         if (obj.code == code) return r.concat([obj.dataId]);
  1343.         return r;
  1344.     }, []).removeRepeated();
  1345. }
  1346.  
  1347. Game_Item.prototype.traitDataTypesOffset = function(code, min, max) {
  1348.     var data = this.object();
  1349.     if ((data == null)||(!data.traits)) return [];
  1350.     data = data.traits;
  1351.     return data.reduce(function(r, obj) {
  1352.         if ((obj.code == code)&&(obj.dataId >= min)&&(obj.dataId <= max)) return r.concat([obj.dataId - min]);
  1353.         return r;
  1354.     }, []).removeRepeated();
  1355. }
  1356.  
  1357. Game_Item.prototype.traitDataTypesMod = function(code, mod) {
  1358.     var data = this.object();
  1359.     if ((data == null)||(!data.traits)) return [];
  1360.     data = data.traits;
  1361.     return data.reduce(function(r, obj) {
  1362.         if (obj.code == code) return r.concat([obj.dataId % mod]);
  1363.         return r;
  1364.     }, []).removeRepeated();
  1365. }
  1366.  
  1367. //=============================================================================
  1368. // Game_Interpreter
  1369. //=============================================================================
  1370.  
  1371. ICF.MainUtility.pluginCommand = Game_Interpreter.prototype.pluginCommand;
  1372. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  1373.         ICF.MainUtility.pluginCommand.call(this, command, args);
  1374.     if (command.toLowerCase() == 'selfswitch') {
  1375.         ICF.MainUtility.CustomSwitch(this._mapId, this._eventId, args[0], args[1]);
  1376.     } else if (command.toLowerCase() == 'mapswitch') {
  1377.         ICF.MainUtility.CustomSwitch(this._mapId, 0, args[0], args[1]);
  1378.     } else if (command.toLowerCase() == 'remoteswitch') {
  1379.         ICF.MainUtility.CustomSwitch(args[0], args[1], args[2], args[3]);
  1380.     } else if (command.toLowerCase() == 'actorswitch') {
  1381.         ICF.MainUtility.CustomSwitch(0, args[0], args[1], args[2]);
  1382.     } else if (command.toLowerCase() == 'battleswitch') {
  1383.         ICF.MainUtility.BattleSwitch(0, 0, args[0], args[1]);
  1384.     } else if (command.toLowerCase() == 'enemybattleswitch') {
  1385.         ICF.MainUtility.BattleSwitch("e", args[0], args[1], args[2]);
  1386.     } else if (command.toLowerCase().match(/((?:self)|(?:map))(variable)/i)&&(RegExp.$1.length + RegExp.$2.length == command.length)) {
  1387.         var event = (RegExp.$1 == "self")? this._eventId : 0;
  1388.         ICF.MainUtility.CustomVariable(this._mapId, event, args[0], args[1]);
  1389.     } else if (command.toLowerCase().match(/(increase)((?:self)|(?:map))(variable)/i)&&(RegExp.$1.length + RegExp.$2.length + RegExp.$3.length == command.length)) {
  1390.         var event = (RegExp.$2 == "self")? this._eventId : 0;
  1391.         ICF.MainUtility.IncreaseCustomVariable(this._mapId, event, args[0], args[1]);
  1392.     } else if (command.toLowerCase().match(/(multiply)((?:self)|(?:map))(variable)/i)&&(RegExp.$1.length + RegExp.$2.length + RegExp.$3.length == command.length)) {
  1393.         var event = (RegExp.$2 == "self")? this._eventId : 0;
  1394.         ICF.MainUtility.MultiplyCustomVariable(this._mapId, event, args[0], args[1]);
  1395.     } else if (command.toLowerCase().match(/(divide)((?:self)|(?:map))(variable)/i)&&(RegExp.$1.length + RegExp.$2.length + RegExp.$3.length == command.length)) {
  1396.         var event = (RegExp.$2 == "self")? this._eventId : 0;
  1397.         ICF.MainUtility.DivideCustomVariable(this._mapId, event, args[0], args[1]);
  1398.     } else if (command.toLowerCase().match(/(mod)((?:self)|(?:map))(variable)/i)&&(RegExp.$1.length + RegExp.$2.length + RegExp.$3.length == command.length)) {
  1399.         var event = (RegExp.$2 == "self")? this._eventId : 0;
  1400.         ICF.MainUtility.ModCustomVariable(this._mapId, event, args[0], args[1]);
  1401.     } else if (command.toLowerCase() == 'remotevariable') {
  1402.         ICF.MainUtility.CustomVariable(args[0], args[1], args[2], args[3]);
  1403.     } else if (command.toLowerCase() == 'actorvariable') {
  1404.         ICF.MainUtility.CustomVariable(0, args[0], args[1], args[2]);
  1405.     } else if (command.toLowerCase() == 'increaseactorvariable') {
  1406.         ICF.MainUtility.IncreaseCustomVariable(0, args[0], args[1], args[2]);
  1407.     } else if (command.toLowerCase() == 'multiplyactorvariable') {
  1408.         ICF.MainUtility.MultiplyCustomVariable(0, args[0], args[1], args[2]);
  1409.     } else if (command.toLowerCase() == 'divideactorvariable') {
  1410.         ICF.MainUtility.DivideCustomVariable(0, args[0], args[1], args[2]);
  1411.     } else if (command.toLowerCase() == 'modactorvariable') {
  1412.         ICF.MainUtility.ModCustomVariable(0, args[0], args[1], args[2]);
  1413.     } else if (command.toLowerCase().match(/(enemy)?(battlevariable)/i)&&(RegExp.$1.length + RegExp.$2.length == command.length)) {
  1414.         if (RegExp.$1 == "enemy") {ICF.MainUtility.BattleVariable("e", args[0], args[1], args[2]);}
  1415.         else {ICF.MainUtility.BattleVariable(0, 0, args[0], args[1]);}
  1416.     } else if (command.toLowerCase().match(/(increase)(enemy)?(battlevariable)/i)&&(RegExp.$1.length + RegExp.$2.length + RegExp.$3.length == command.length)) {
  1417.         if (RegExp.$2 == "enemy") {ICF.MainUtility.IncreaseBattleVariable("e", args[0], args[1], args[2]);}
  1418.         else {ICF.MainUtility.IncreaseBattleVariable(0, 0, args[0], args[1]);}
  1419.     } else if (command.toLowerCase().match(/(multiply)(enemy)?(battlevariable)/i)&&(RegExp.$1.length + RegExp.$2.length + RegExp.$3.length == command.length)) {
  1420.         if (RegExp.$2 == "enemy") {ICF.MainUtility.MultiplyBattleVariable("e", args[0], args[1], args[2]);}
  1421.         else {ICF.MainUtility.MultiplyBattleVariable(0, 0, args[0], args[1]);}
  1422.     } else if (command.toLowerCase().match(/(divide)(enemy)?(battlevariable)/i)&&(RegExp.$1.length + RegExp.$2.length + RegExp.$3.length == command.length)) {
  1423.         if (RegExp.$2 == "enemy") {ICF.MainUtility.DivideBattleVariable("e", args[0], args[1], args[2]);}
  1424.         else {ICF.MainUtility.DivideBattleVariable(0, 0, args[0], args[1]);}
  1425.     } else if (command.toLowerCase().match(/(mod)(enemy)?(battlevariable)/i)&&(RegExp.$1.length + RegExp.$2.length + RegExp.$3.length == command.length)) {
  1426.         if (RegExp.$2 == "enemy") {ICF.MainUtility.ModBattleVariable("e", args[0], args[1], args[2]);}
  1427.         else {ICF.MainUtility.ModBattleVariable(0, 0, args[0], args[1]);}
  1428.     } else if (command.toLowerCase().match(/((?:actor)|(?:enemy)|(?:partymember))(trait)((?:add)|(?:rate)|(?:plus))?/i)&&(RegExp.$1.length + RegExp.$2.length + RegExp.$3.length == command.length)) {
  1429.         var data = (RegExp.$1 == "actor")? $gameActors.actor(args[0])._traitsObject : (RegExp.$1 == "enemy")? $gameTroop.members()[args[0]]._traitsObject : $gameParty.members()[args[0]]._traitsObject;
  1430.         var mode = (RegExp.$3 == "add")? 0 : (RegExp.$3 == "plus")? 2 : (RegExp.$3 == "rate")? 3 : 1;
  1431.         ICF.MainUtility.addTrait(data, mode, args[1], args[2], args[3]);
  1432.     } else if (command.toLowerCase().match(/(remove)((?:actor)|(?:enemy)|(?:partymember))(trait)/i)&&(RegExp.$1.length + RegExp.$2.length + RegExp.$3.length == command.length)) {
  1433.         var data = (RegExp.$2 == "actor")? $gameActors.actor(args[0])._traitsObject : (RegExp.$2 == "enemy")? $gameTroop.members()[args[0]]._traitsObject : $gameParty.members()[args[0]]._traitsObject;
  1434.         ICF.MainUtility.removeTrait(data, args[1], args[2]);
  1435.     } else if (command.toLowerCase().match(/(clear)((?:actor)|(?:enemy)|(?:partymember))(traits)/i)&&(RegExp.$1.length + RegExp.$2.length + RegExp.$3.length == command.length)) {
  1436.         var data = (RegExp.$2 == "actor")? $gameActors.actor(args[0]) : (RegExp.$2 == "enemy")? $gameTroop.members()[args[0]] : $gameParty.members()[args[0]];
  1437.         data.clearTraits();
  1438.         }
  1439. };
  1440.  
  1441. //=============================================================================
  1442. // Utilities
  1443. //=============================================================================
  1444.  
  1445. ICF.MainUtility.gettfield = function(array) {
  1446.     for (var i = 0; i < ICF.MainUtility.traittags.length; i++) {
  1447.         if (array[0].toLowerCase() == ICF.MainUtility.traittags[i][0]) {
  1448.             array[0] = ICF.MainUtility.traittags[i][1];
  1449.             array[1] = Number(array[1]) + ICF.MainUtility.traittags[i][2];
  1450.             break;
  1451.         }
  1452.     }
  1453.     if (isNaN(Number(array[0]))) {return [-1];}
  1454.     return array;
  1455. }
  1456.  
  1457. ICF.MainUtility.addTrait = function(data, mode, code, dataid, value) {
  1458.     if (!data.traits) return;
  1459.     var array = [code, Number(dataid), Number(value)];
  1460.     if (isNaN(Number(array[0]))) {array = ICF.MainUtility.gettfield(array);};
  1461.     if (array[0] < 0) {return;};
  1462.     if (mode == 0) {data.traits.push({code:Number(array[0]), dataId:array[1], value:array[2]}); return;};
  1463.     var ind = -1;
  1464.     for (var i = 0; i < data.traits.length; i++) {
  1465.         if ((data.traits[i].code == array[0])&&(data.traits[i].dataId == array[1])) {
  1466.             ind = i;
  1467.             break;
  1468.         }
  1469.     }
  1470.     if (ind == -1) {data.traits.push({code:Number(array[0]), dataId:array[1], value:array[2]}); return;};
  1471.     if (mode == 1) {
  1472.         data.traits[ind].value = array[2];
  1473.         for (var i = data.traits.length - 1; i > ind; i--) {
  1474.             if ((data.traits[i].code == array[0])&&(data.traits[i].dataId == array[1])) {
  1475.                 data.traits.splice(i, 1);
  1476.             }
  1477.         }
  1478.     } else if (mode == 2){
  1479.         data.traits[ind].value += array[2];
  1480.         for (var i = data.traits.length - 1; i > ind; i--) {
  1481.             if ((data.traits[i].code == array[0])&&(data.traits[i].dataId == array[1])) {
  1482.                 data.traits[ind].value += data.traits[i].value;
  1483.                 data.traits.splice(i, 1);
  1484.             }
  1485.         }
  1486.     } else if (mode == 3){
  1487.         data.traits[ind].value *= array[2];
  1488.         for (var i = data.traits.length - 1; i > ind; i--) {
  1489.             if ((data.traits[i].code == array[0])&&(data.traits[i].dataId == array[1])) {
  1490.                 data.traits[ind].value *= data.traits[i].value;
  1491.                 data.traits.splice(i, 1);
  1492.             }
  1493.         }
  1494.     }
  1495. }
  1496.  
  1497. ICF.MainUtility.removeTrait = function(data, code, dataid) {
  1498.     if (!data.traits) return;
  1499.     var array = [code, Number(dataid), 0];
  1500.     if (isNaN(Number(array[0]))) {array = ICF.MainUtility.gettfield(array);};
  1501.     if (array[0] < 0) {return;};
  1502.     var ind = -1;
  1503.     for (var i = data.traits.length - 1; i >= 0; i--) {
  1504.         if ((data.traits[i].code == array[0])&&(data.traits[i].dataId == array[1])) {
  1505.             data.traits.splice(i, 1);
  1506.         }
  1507.     }
  1508. }
  1509.  
  1510. ICF.MainUtility.CustomSwitch = function(mapid, evid, switchname, value) {
  1511.     var _key = [mapid, evid, switchname];
  1512.     var _value = (value.toString().toLowerCase() === "true");
  1513.     $gameSelfSwitches.setValue(_key, _value);
  1514. }
  1515.  
  1516. ICF.MainUtility.CustomVariable = function(mapid, evid, variablename, value) {
  1517.     var _key = [mapid, evid, variablename];
  1518.     $gameSelfVariables.setValue(_key, value);
  1519. }
  1520.  
  1521. ICF.MainUtility.IncreaseCustomVariable = function(mapid, evid, variablename, value) {
  1522.     var _key = [mapid, evid, variablename];
  1523.     $gameSelfVariables.increaseValue(_key, value);
  1524. }
  1525.  
  1526. ICF.MainUtility.MultiplyCustomVariable = function(mapid, evid, variablename, value) {
  1527.     var _key = [mapid, evid, variablename];
  1528.     $gameSelfVariables.multiplyValue(_key, value);
  1529. }
  1530.  
  1531. ICF.MainUtility.DivideCustomVariable = function(mapid, evid, variablename, value) {
  1532.     var _key = [mapid, evid, variablename];
  1533.     $gameSelfVariables.divideValue(_key, value);
  1534. }
  1535.  
  1536. ICF.MainUtility.ModCustomVariable = function(mapid, evid, variablename, value) {
  1537.     var _key = [mapid, evid, variablename];
  1538.     $gameSelfVariables.modValue(_key, value);
  1539. }
  1540.  
  1541. ICF.MainUtility.BattleSwitch = function(code, evid, switchname, value) {
  1542.     var _key = [code, evid, switchname];
  1543.     var _value = (value.toString().toLowerCase() === "true");
  1544.     $gameBattleSwitches.setValue(_key, _value);
  1545. }
  1546.  
  1547. ICF.MainUtility.BattleVariable = function(code, evid, variablename, value) {
  1548.     var _key = [code, evid, variablename];
  1549.     $gameBattleVariables.setValue(_key, value);
  1550. }
  1551.  
  1552. ICF.MainUtility.IncreaseBattleVariable = function(code, evid, variablename, value) {
  1553.     var _key = [code, evid, variablename];
  1554.     $gameBattleVariables.increaseValue(_key, value);
  1555. }
  1556.  
  1557. ICF.MainUtility.MultiplyBattleVariable = function(code, evid, variablename, value) {
  1558.     var _key = [code, evid, variablename];
  1559.     $gameBattleVariables.multiplyValue(_key, value);
  1560. }
  1561.  
  1562. ICF.MainUtility.DivideBattleVariable = function(code, evid, variablename, value) {
  1563.     var _key = [code, evid, variablename];
  1564.     $gameBattleVariables.divideValue(_key, value);
  1565. }
  1566.  
  1567. ICF.MainUtility.ModBattleVariable = function(code, evid, variablename, value) {
  1568.     var _key = [code, evid, variablename];
  1569.     $gameBattleVariables.modValue(_key, value);
  1570. }
  1571.  
  1572. Array.range = function() {
  1573.     var args = arguments;
  1574.     if (args.length < 1) return [];
  1575.     var x = [];
  1576.     if (args.length == 1) {
  1577.     if (args[0] == 0) return [0];
  1578.     if (args[0] > 0) for (var i = 1; i <= args[0]; i++) {
  1579.         x.push([i]);
  1580.     } else for (var i = -1; i >= args[0]; i--) {
  1581.         x.push([i]);
  1582.     }
  1583.     } else if (args.length == 2) {
  1584.     if (args[0] < args[1]) for (var i = args[0]; i <= args[1]; i++) {
  1585.         x.push([i]);
  1586.     } else for (var i = args[0]; i >= args[1]; i--) {
  1587.         x.push([i]);
  1588.     }
  1589.     } else {
  1590.     if (args[0] < args[1] && args[2] > 0) for (var i = args[0]; i <= args[1]; i += args[2]) {
  1591.         x.push([i]);
  1592.     } else if (args[0] > args[1] && args[2] < 0) for (var i = args[0]; i >= args[1]; i += args[2]) {
  1593.         x.push([i]);
  1594.     }
  1595.     }
  1596.     return x;
  1597. };
  1598.  
  1599. Array.coincidences = function() {
  1600.     var args = arguments;
  1601.     if (args.length < 1) return [];
  1602.     if (args.length == 1) return args[0];
  1603.     var x = [];
  1604.     for (var i = 0; i < args[0].length; i++) {
  1605.     if (args[1].indexOf(args[0][i]) > -1) x.push(args[0][i]);
  1606.     }
  1607.     if (args.length == 2) return x.removeRepeated();
  1608.     for (var i = x.length - 1; i >= 0; i--) {
  1609.     for (var il = 2; il < args.length; il++) {
  1610.         if (args[il].indexOf(x[i]) == -1) {
  1611.             x.splice(i,1);
  1612.             break;
  1613.         }
  1614.     }
  1615.     }
  1616.     return x.removeRepeated();
  1617. };
  1618.  
  1619. Array.prototype.removeRepeated = function() {
  1620.     this.sort(function(a, b) { return a - b;});
  1621.     for (var i = this.length - 1; i > 0; i--) {
  1622.        if (this[i] == this[i - 1]) this.splice(i,1);
  1623.     }
  1624.     return this;
  1625. };
  1626.  
  1627. Array.prototype.clean = function() {
  1628.     for (var i = this.length - 1; i >= 0; i -= 1) {
  1629.     if (this[i] == null) this.splice(i,1);
  1630.     if (String(this[i]).length == 0) this.splice(i,1);
  1631.     }
  1632.     return this;
  1633. };
  1634.  
  1635. Array.prototype.cleanAll = function() {
  1636.     for (var i = this.length - 1; i >= 0; i -= 1) {
  1637.     if (this[i] == null) this.splice(i,1);
  1638.     if (String(this[i]).length == 0) this.splice(i,1);
  1639.     if (Array.isArray(this[i])) this[i].cleanAll();
  1640.     }
  1641.     return this;
  1642. };
  1643.  
  1644. Array.prototype.cleaned = function() {
  1645.     var x = [];
  1646.     for (var i = 0; i < this.length; i++) {
  1647.     if (this[i] != null) x.push(this[i]);
  1648.     }
  1649.     return x;
  1650. };
  1651.  
  1652. Array.prototype.cleanedAll = function() {
  1653.     var x = [];
  1654.     var y = [];
  1655.     for (var i = 0; i < this.length; i++) {
  1656.     if (Array.isArray(this[i])) {
  1657.         y = this[i].cleanedAll();
  1658.         if (y.length > 0) x.push(y);
  1659.     } else if (this[i] != null) x.push(this[i]);
  1660.     }
  1661.     return x;
  1662. };
  1663.  
  1664. Array.prototype.extend = function() {
  1665.     this.clean();
  1666.     for (var i = this.length - 2; i > 0; i -= 1) {
  1667.     if ((String(this[i]).match(/(?:to)|(?:a)|(?:hasta)/))&&(RegExp.$1.length == String(this[i]).length)) {
  1668.         eval("this.splice(i - 1,3," + Array.range(this[i - 1], this[i + 1]).join() + ")");
  1669.         i--;
  1670.     }
  1671.     }
  1672.     return this;
  1673. };
  1674.  
  1675. Array.prototype.fixedBlocks = function(block) {
  1676.     if ((this.length % block)  > 0) {
  1677.     eval("this.splice(this.length,0," + new Array(block - this.length % block).join() + ")");
  1678.     }
  1679. };
  1680.  
  1681. Array.prototype.leaveNumbers = function() {
  1682.     for (var i = this.length - 1; i >= 0; i -= 1) {
  1683.     if (isNaN(Number(this[i]))) this.splice(i,1);
  1684.     else this[i] = Number(this[i]);
  1685.     }
  1686.     return this;
  1687. };
  1688.  
  1689. Array.prototype.numbers = function() {
  1690.     var x = [];
  1691.     for (var i = 0; i < this.length; i++) {
  1692.     if (!isNaN(Number(this[i]))) x.push(Number(this[i]));
  1693.     }
  1694.     return x;
  1695. };
  1696.  
  1697. Array.prototype.reduceToFit = function() {
  1698.     var args = arguments;
  1699.     if (args.length < 1) return this;
  1700.     for (var i = 0; i < args.length; i++) {
  1701.     if ((Array.isArray(args[i]))&&(args[i].length < this.length)) this.splice(args[i].length, this.length - args[i].length);
  1702.     }
  1703.     return this;
  1704. };
  1705.  
  1706. String.prototype.doubleSplit = function() {
  1707.     var x = this.split(",");
  1708.     for (var i = 0; i < x.length; i++) {
  1709.     x[i] = x[i].split(/\s+/);
  1710.     }
  1711.     return x;
  1712. }
  1713.  
  1714. String.prototype.doubleSplitNumbers = function() {
  1715.     var x = this.doubleSplit();
  1716.     for (var i = x.length - 1; i >= 0; i--) {
  1717.     x[i] = x[i].extend().numbers();
  1718.     if (x[i].length < 1) x.splice(i,1);
  1719.     }
  1720.     return x;
  1721. }
  1722.  
  1723. Date.prototype.getMonthAndDay = function() {
  1724.     return this.getMonth() * 100 + this.getDate() + 100;
  1725. };
  1726.  
  1727. Date.prototype.getHourAndMinute = function() {
  1728.     return this.getHours() * 100 + this.getMinutes();
  1729. };
  1730.  
  1731. Date.prototype.getDayMinutes = function() {
  1732.     return this.getHours() * 60 + this.getMinutes();
  1733. };
  1734.  
  1735. Date.prototype.increaseMinutes = function(minutes) {
  1736.     this.setMinutes(this.getMinutes() + minutes);
  1737. };
  1738.  
  1739. //=============================================================================
  1740. // End of File
  1741. //=============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement