Advertisement
ICF-Soft

ICF-Soft Enemy Selector 1.03 RPG Maker MV

Aug 27th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // ICF-Soft Plugins - Enemy Selector
  3. // ICFSoft_EnemySelector.js
  4. //=============================================================================
  5.  
  6. var Imported = Imported || {};
  7. Imported.ICFSoft_EnemySelector = true;
  8.  
  9. var ICF = ICF || {};
  10. ICF.EnemySelect = ICF.EnemySelect || {};
  11.  
  12. ICF.EnemySelect.Version = 103; // 1.03
  13.  
  14. //=============================================================================
  15.  /*:
  16.  * @plugindesc v1.03 This plugin allows you to change enemies before
  17.  * start battle.
  18.  * @author ICF-Soft [http://icfsoft.blogspot.com.es/]
  19.  *
  20.  * @param Absolute
  21.  * @desc If true, enemy chage if var is equal to selector instead
  22.  * of equal or higher.   NO - false     YES - true
  23.  * @default false
  24.  *
  25.  * @param Enemy Var
  26.  * @desc The game variable where the selector is stored.
  27.  * @default 40
  28.  *
  29.  * @param Developer HaltJS
  30.  * @desc When true it throws an error if an custom enemy selection
  31.  * javascript doesn't work.   NO - false     YES - true
  32.  * @default false
  33.  *
  34.  * @help
  35.  * ============================================================================
  36.  * Introduction
  37.  *
  38.  * In database we have a 2000 item cap per tab. So we have up to 2000 different
  39.  * enemies and up to 2000 enemy groups.
  40.  * It's usual to use some groups for a different number of same enemy
  41.  * (ex: 2 and 3 bats) and different enemy combinations, so a less number of enemy
  42.  * types are used.
  43.  *
  44.  * This plugin allow to increase the number of used enemies and, at same time,
  45.  * use a lower number of enemy groups.
  46.  *
  47.  * Main utility is to implement an ingame difficult increase system with different
  48.  * enemies.
  49.  *
  50.  * ============================================================================
  51.  * Parameters
  52.  * ============================================================================
  53.  *
  54.  * Absolute: Tell if value must be exact to swap enemy.
  55.  * When off enemy will change if value is equal or higher, making an ingame
  56.  * difficult increase system.
  57.  *
  58.  * Enemy Var: Tell wich variable vill be used as selector.
  59.  *
  60.  * Developer HaltJS: This is a development variable usefull to check if there is
  61.  * a wrong javascript enemy selection.
  62.  * When true will throw an error when it found a wrong javascript in lunatic
  63.  * mode and tell specified enemiId.
  64.  * When false it will be ignored and game continues.
  65.  *
  66.  * ============================================================================
  67.  * Config enemies
  68.  * ============================================================================
  69.  *
  70.  * Enemies are configured via notetags.
  71.  *
  72.  * Starts with "<ENEMY SELECTOR>", then the selectors come in succesive lines.
  73.  * Minimun 2 numbers separated, first by ":" and others by "," or spaces.
  74.  * The first is the value for the selector and others are enemy ids to alter.
  75.  * You can use ranges.
  76.  * Selectors must be in ascending order.
  77.  * And finish with "</ENEMY SELECTOR>".
  78.  *
  79.  * Example:
  80.  *
  81.  * <ENEMY SELECTOR>
  82.  * 1:2
  83.  * 2:10,11
  84.  * 3:5 to 10,3
  85.  * </ENEMY SELECTOR>
  86.  *
  87.  * This enemy will change to database enemy 2 when selected variable become 1.
  88.  * If selected variable become 2, enemy will be 10 or 11.
  89.  * If selected variable become 3, enemy will be 3 or a number from 5 to 10.
  90.  *
  91.  * ============================================================================
  92.  * Lunatic Mode
  93.  * ============================================================================
  94.  *
  95.  * For those who want another way to select enemies I've added a lunatic mode.
  96.  *
  97.  * It also work in notetags:
  98.  *
  99.  * <CUSTOM ENEMY SELECTOR>
  100.  * converted = 2;
  101.  * converted += 25;
  102.  * </CUSTOM ENEMY SELECTOR>
  103.  *
  104.  * It runs after normal selection if you want to use both for an enemy.
  105.  * You can use javascript between these tags to alter the final result.
  106.  *
  107.  * converted - This is the enemyId that you are changing, by your own formula
  108.  *             for especified enemy.
  109.  *
  110.  * ============================================================================
  111.  * Plugin commands
  112.  * ============================================================================
  113.  *
  114.  * ChangeEnemySelector x
  115.  *
  116.  *  - Change the variable where selector is stored.
  117.  *
  118.  * ResetEnemySelector
  119.  *
  120.  *  - Reset the variable where selector is stored to it's initial value.
  121.  *
  122.  * ============================================================================
  123.  * Scripting functions
  124.  * ============================================================================
  125.  *
  126.  * $gameVariables.enemySelector()
  127.  *
  128.  *  - Get the value stored in current selector.
  129.  *
  130.  * $gameVariables.initialEnemySelector()
  131.  *
  132.  *  - Get the value stored in initial selector.
  133.  *
  134.  * Game_Enemy.initialEnemyID()
  135.  *
  136.  *  - Get the initial enemyID before change.
  137.  *
  138.  * ICF.EnemySelect.changeSelector(x)
  139.  * ICF.EnemySelect.initSelector()
  140.  *
  141.  *  - Scripting alternatives in javascript for plugin commands.
  142.  *
  143.  * ============================================================================
  144.  * Incompatibilities
  145.  * ============================================================================
  146.  *
  147.  * There's no known incompatible plugins yet.
  148.  *
  149.  * ============================================================================
  150.  * Known isues
  151.  * ============================================================================
  152.  *
  153.  * Different enemy sizes can look weird.
  154.  * Pointer position is on bottom left corner.
  155.  *
  156.  * ============================================================================
  157.  * Changelog
  158.  * ============================================================================
  159.  *
  160.  * Version 1.03:
  161.  * - Use of ICF-Soft Main Utility.
  162.  * - Use of ranges.
  163.  * - Added plugin commands.
  164.  * - Added scripting functions.
  165.  *
  166.  * Version 1.02:
  167.  * - Improved lunatic mode.
  168.  *
  169.  * Version 1.01:
  170.  * - Added randomizing to standard procedure.
  171.  * - Added lunatic mode.
  172.  *
  173.  * Version 1.00:
  174.  * - Finished plugin!
  175.  *
  176.  * ============================================================================
  177.  *
  178.  * For commercial and non-commercial games.
  179.  * Credit to ICF-Soft.
  180.  * This entire header must be included with plugin.
  181.  *
  182.  * ============================================================================
  183. */
  184. //=============================================================================
  185.  /*:es
  186.  * @plugindesc v1.03 Este complemento permite cambiar los enemigos antes
  187.  * de que la batalla comience.
  188.  * @author ICF-Soft [http://icfsoft.blogspot.com.es/]
  189.  *
  190.  * @param Absolute
  191.  * @desc Si se activa, el enemigo cambiará solo si coincide el
  192.  * selector, si no, cuando sea mayor o igual.  No - false   Si - true
  193.  * @default false
  194.  *
  195.  * @param Enemy Var
  196.  * @desc La variable donde se almacena el selector.
  197.  * @default 40
  198.  *
  199.  * @param Developer HaltJS
  200.  * @desc Si está activado salta cuando una función personalizada
  201.  * da error.   No - false   Si - true
  202.  * @default false
  203.  *
  204.  * @help
  205.  * ============================================================================
  206.  * Introducción
  207.  * ============================================================================
  208.  *
  209.  * En la base de datos hay un tope de 2000 elementos por pestaña. Por un lado
  210.  * tenemos hasta 2000 enemigos distintos y por otro hasta 2000 grupos de enemigos
  211.  * a los que se puede enfrentar en el juego.
  212.  * Normalmente no se utiliza un grupo para cada enemigo, sino varios grupos con dos
  213.  * o tres enemigos del mismo tipo y diversas combinaciones de enemigos, por lo que
  214.  * en realidad se utilizan bastantes tipos de enemigos menos.
  215.  *
  216.  * Este script permite aprovechar el máximo de enemigos posible reduciendo,
  217.  * a su vez, el número de grupos de enemigos.
  218.  *
  219.  * La utilidad principal reside en que se puede hacer un sistema de dificultad
  220.  * creciente y/o aprovechar mejor el número de enemigos de la base de datos.
  221.  *
  222.  * ============================================================================
  223.  * Parámetros
  224.  * ============================================================================
  225.  *
  226.  * Absolute: Indica si el valor debe ser exacto para que el enemigo cambie.
  227.  * Cuando está desactivado el enemigo cambiará cuando el valor sea mayor o igual,
  228.  * haciendo un sistema de dificultad creciente.
  229.  *
  230.  * Enemy Var: Indica qué variable vas a utilizar para almacenar el selector.
  231.  *
  232.  * Developer HaltJS: Esta es una variable de uso durante el desarrollo del juego
  233.  * útil cuando quieres comprobar si hay alguna función personalizada incorrecta.
  234.  * Cuando está activado al encontrar un error el juego se para y muestra
  235.  * en qué enemigo se encuentra el error.
  236.  * Cuando está desactivado ignora el error y el juego continúa.
  237.  *
  238.  * ============================================================================
  239.  * Configurar los enemigos
  240.  * ============================================================================
  241.  *
  242.  * Los enemigos se configuran en la base de datos en el apartado de las notas.
  243.  *
  244.  * Se empieza una línea con "<ENEMY SELECTOR>", se ponen en cada línea sucesiva
  245.  * al menos dos números, el primero separado por ":" y el resto por ',' o
  246.  * espacios. El primero es el valor que debe tomar el selector y el resto
  247.  * los enemigos que pueden ocupar su lugar. Se pueden usar rangos.
  248.  * Los selectores deben ir en orden ascendente.
  249.  * Finalmente se termina con la línea "</ENEMY SELECTOR>".
  250.  *
  251.  * Ejemplo:
  252.  *
  253.  * <ENEMY SELECTOR>
  254.  * 1:2
  255.  * 2:10,11
  256.  * 3:5 a 10,3
  257.  * </ENEMY SELECTOR>
  258.  *
  259.  * Este enemigo cuando la variable escogida valga 1 será sustituido por el enemigo
  260.  * número 2 de la base de datos.
  261.  * En cambio, si la variable vale 2 será sustituido por el enemigo número 10 o el 11
  262.  * de la base de datos.
  263.  * Si vale 3, se sustituirá por el 3 o cualquiera entre el 5 y el 10.
  264.  *
  265.  * ============================================================================
  266.  * Lunatic Mode
  267.  * ============================================================================
  268.  *
  269.  * Para aquellos que quieren otro modo de seleccionar los enemigos he añadido el
  270.  * modo lunático.
  271.  * El modo lunático permite utilizar código javascript diréctamente.
  272.  *
  273.  * Usa las siguientes etiquetas:
  274.  *
  275.  * <CUSTOM ENEMY SELECTOR>
  276.  * converted = 2;
  277.  * converted += 25;
  278.  * </CUSTOM ENEMY SELECTOR>
  279.  *
  280.  * En el caso de que se quiera combinar con el modo anterior, este código se
  281.  * ejecuta después.
  282.  *
  283.  * converted - Este es el resultado, contiene el enemyId inicial que puedes
  284.  *             alterar bajo tu criterio.
  285.  *
  286.  * ============================================================================
  287.  * Comandos de complemento
  288.  * ============================================================================
  289.  *
  290.  * ChangeEnemySelector x
  291.  *
  292.  *  - Cambia la variable en donde se guarda el selector.
  293.  *
  294.  * ResetEnemySelector
  295.  *
  296.  *  - Reinicia la variable en donde se guarda el selector a su valor
  297.  *    inicial.
  298.  *
  299.  * ============================================================================
  300.  * Funciones de script
  301.  * ============================================================================
  302.  *
  303.  * $gameVariables.enemySelector()
  304.  *
  305.  *  - Obtiene el valor del selector actual.
  306.  *
  307.  * $gameVariables.initialEnemySelector()
  308.  *
  309.  *  - Obtiene el valor del selector inicial.
  310.  *
  311.  * Game_Enemy.initialEnemyID()
  312.  *
  313.  *  - Permite comprobar el enemigo que fue sustituido.
  314.  *
  315.  * ICF.EnemySelect.changeSelector(x)
  316.  * ICF.EnemySelect.initSelector()
  317.  *
  318.  *  - Alternativas en javascript para los comandos de complemento.
  319.  *
  320.  * ============================================================================
  321.  * Incompatibilidades
  322.  * ============================================================================
  323.  *
  324.  * No se conocen complementos que sean incompatibles hasta la fecha.
  325.  *
  326.  * ============================================================================
  327.  * Problemas conocidos
  328.  * ============================================================================
  329.  *
  330.  * Si los enemigos que se intercambian son de distintos tamaños pueden quedar
  331.  * vistosamente mal colocados.
  332.  * La posición viene definida por la esquina inferior izquierda.
  333.  *
  334.  * ============================================================================
  335.  * Historial de versiones
  336.  * ============================================================================
  337.  *
  338.  * Version 1.03:
  339.  * - Se epieza a utilizar el ICF-Soft Main Utility.
  340.  * - Se pueden usar rangos de enemigos.
  341.  * - Se han añadido los comandos de complemento.
  342.  * - Se han añadido funciones de script.
  343.  *
  344.  * Versión 1.02:
  345.  * - Modo lunático mejorado.
  346.  *
  347.  * Versión 1.01:
  348.  * - Se ha añadido una función para aleatorizar.
  349.  * - Se ha añadido el modo lunático.
  350.  *
  351.  * Versión 1.00:
  352.  * - Complemento terminado.
  353.  *
  354.  * ============================================================================
  355.  *
  356.  * Para juegos comerciales y no comerciales.
  357.  * Se debe incluir a ICF-Soft en los créditos.
  358.  * Esta cabecera debe incluirse íntegramente con el plugin.
  359.  *
  360.  * ============================================================================
  361. */
  362. //=============================================================================
  363.  
  364. //=============================================================================
  365. // Parameter Variables
  366. //=============================================================================
  367.  
  368. ICF.Parameters = PluginManager.parameters('ICFSoft_EnemySelector');
  369. ICF.Param = ICF.Param || {};
  370.  
  371. ICF.Param.EnemyVarAbsolute = ICF.Parameters['Absolute'].toLowerCase() === "true";
  372. ICF.Param.EnemyVar = Number(ICF.Parameters['Enemy Var']);
  373. ICF.Param.EnemyVarInitial = ICF.Param.EnemyVar;
  374.  
  375. ICF.Param.EnemySelHalt = ICF.Parameters['Developer HaltJS'].toLowerCase() === "true";
  376.  
  377. 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.');}
  378.  
  379. //=============================================================================
  380. // DataManager
  381. //=============================================================================
  382.  
  383. ICF.EnemySelect.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
  384. DataManager.isDatabaseLoaded = function() {
  385.     if (!ICF.EnemySelect.DataManager_isDatabaseLoaded.call(this)) return false;
  386.     if (!ICF.EnemySelect.Procesed) {
  387.     this.processEnemySelectNotetags($dataEnemies);
  388.     ICF.EnemySelect.Procesed = true;
  389.     }
  390.     return true;
  391. };
  392.  
  393. DataManager.processEnemySelectNotetags = function(group) {
  394.   var note1 = /<(?:ENEMY SELECTOR)>/i;
  395.   var note2 = /<\/(?:ENEMY SELECTOR)>/i;
  396.   var note3 = /<(?:CUSTOM ENEMY SELECTOR)>/i;
  397.   var note4 = /<\/(?:CUSTOM ENEMY SELECTOR)>/i;
  398.   ICF.EnemySelect.Enemies = [];
  399.   ICF.EnemySelect.CustEnemies = [];
  400.   for (var n = 1; n < group.length; n++) {
  401.     var obj = group[n];
  402.     var notedata = obj.note.split(/[\r\n]+/);
  403.  
  404.     ICF.EnemySelect.Enemies[n] = [];
  405.     ICF.EnemySelect.CustEnemies[n] = '';
  406.  
  407.     obj.enemySelect = [];
  408.     obj.customEnemySelect = '';
  409.  
  410.     var esFlag = false;
  411.     var esFlag2 = false;
  412.  
  413.       for (var i = 0; i < notedata.length; i++) {
  414.         var line = notedata[i];
  415.         if (line.match(note1)) {
  416.             esFlag = true;
  417.         } else if (line.match(note2)) {
  418.             esFlag = false;
  419.         } else if (line.match(note3)) {
  420.             esFlag2 = true;
  421.         } else if (line.match(note4)) {
  422.             esFlag2 = false;
  423.         } else if (esFlag) {
  424.             line = line.split(/:|,|\s+/);
  425.             if ((line.length > 1)&&(line[0] != NaN)&&(line[1] != NaN)) {
  426.                 line.extend().leaveNumbers();
  427.                 ICF.EnemySelect.Enemies[n].push(line);
  428.                 obj.enemySelect.push(line);
  429.             }
  430.         } else if (esFlag2) {
  431.             ICF.EnemySelect.CustEnemies[n] = ICF.EnemySelect.CustEnemies[n] + line + '\n';
  432.             obj.customEnemySelect = obj.customEnemySelect + line + '\n';
  433.         }
  434.  
  435.       }
  436.   }
  437. };
  438.  
  439. //=============================================================================
  440. // Game_Enemy
  441. //=============================================================================
  442.  
  443. ICF.EnemySelect.setupEnemy = Game_Enemy.prototype.initialize;
  444. Game_Enemy.prototype.initialize = function(enemyId, x, y) {
  445.     this._originalEnemyId = enemyId;
  446.     var converted = enemyId;
  447.     var ary = $dataEnemies[enemyId].enemySelect;
  448.  
  449.     if (ary.length == 0) {
  450.         converted = enemyId;
  451.     } else if (ICF.Param.EnemyVarAbsolute) {
  452.         for (i = 0; i < ary.length; i++) {
  453.             if (ary[i][0] == $gameVariables.value(ICF.Param.EnemyVar)) {
  454.                 converted = ary[i][Math.floor((Math.random() * (ary[i].length - 1)) + 1)];
  455.                 break;
  456.             }
  457.         }
  458.     } else {
  459.         for (i = ary.length - 1; i >= 0; i--) {
  460.             if (ary[i][0] <= $gameVariables.value(ICF.Param.EnemyVar)) {
  461.                 converted = ary[i][Math.floor((Math.random() * (ary[i].length - 1)) + 1)];
  462.                 break;
  463.             }
  464.         }
  465.     }
  466.     if ($dataEnemies[enemyId].customEnemySelect != '') {
  467.         try {eval($dataEnemies[enemyId].customEnemySelect);}
  468.         catch (e) {if(ICF.Param.EnemySelHalt){throw new Error('Error in custom enemy selection in enemy #' + enemyId);}}
  469.     }
  470.  
  471.     ICF.EnemySelect.setupEnemy.call(this, converted, x, y);
  472. };
  473.  
  474. Game_Enemy.prototype.initialEnemyID = function() {
  475.     return this._originalEnemyId;
  476. }
  477.  
  478. //=============================================================================
  479. // Game_Variables
  480. //=============================================================================
  481.  
  482. Game_Variables.prototype.enemySelector = function() {
  483.     return this._data[ICF.Param.EnemyVar] || 0;
  484. };
  485.  
  486. Game_Variables.prototype.initialEnemySelector = function() {
  487.     return this._data[ICF.Param.EnemyVarInitial] || 0;
  488. };
  489.  
  490. //=============================================================================
  491. // Game_Interpreter
  492. //=============================================================================
  493.  
  494. ICF.EnemySelect.pluginCommand = Game_Interpreter.prototype.pluginCommand;
  495. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  496.         ICF.EnemySelect.pluginCommand.call(this, command, args);
  497.     if (command.toLowerCase() === 'changeenemyselector') {
  498.         ICF.EnemySelect.changeSelector(args[0]);
  499.     } else if (command.toLowerCase() == 'resetenemyselector') {
  500.         ICF.EnemySelect.initSelector();
  501.     }
  502. };
  503.  
  504. //=============================================================================
  505. // Some Utilities
  506. //=============================================================================
  507.  
  508. ICF.EnemySelect.changeSelector = function(newselector) {
  509.     ICF.Param.EnemyVar = newselector;
  510. }
  511.  
  512. ICF.EnemySelect.initSelector = function() {
  513.     ICF.Param.EnemyVar = ICF.Param.EnemyVarInitial;
  514. }
  515.  
  516. //=============================================================================
  517. // End of File
  518. //=============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement