Advertisement
ICF-Soft

ICF-Soft Enemy Troops Extension RPG Maker MV

Oct 18th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // ICF-Soft Plugins - Enemy Troops Extension
  3. // ICFSoft_EnemyTroopExt.js
  4. //=============================================================================
  5.  
  6. var Imported = Imported || {};
  7. Imported.ICFSoft_ETroopEx = true;
  8.  
  9. var ICF = ICF || {};
  10. ICF.ETroopEx = ICF.ETroopEx || {};
  11.  
  12. ICF.ETroopEx.Version = 100; // 1.00
  13.  
  14. //=============================================================================
  15.  /*:
  16.  * @plugindesc v1.00 This plugin allows more conditions to battle events
  17.  * and to concatenate troops.
  18.  * @author ICF-Soft [http://icfsoft.blogspot.com.es/]
  19.  *
  20.  * @param Developer HaltJS
  21.  * @desc When true it throws an error if an custom page condition
  22.  * javascript doesn't work.   NO - false     YES - true
  23.  * @default false
  24.  *
  25.  * @help
  26.  * ============================================================================
  27.  * Introduction
  28.  *
  29.  * This is a plugin similar to ICF-Soft Event Extension, made to work with
  30.  * troops. I've decided to separate this because of the diferences between
  31.  * these so I can give different features each one.
  32.  * It uses switches and variables that can be needed inside a battle, like
  33.  * game ones, actor and party ones, battle ones, and enemy and troop ones.
  34.  *
  35.  * Plus you can add enemies from other troopIds.
  36.  *
  37.  * ============================================================================
  38.  * How to use
  39.  * ============================================================================
  40.  *
  41.  * To enable a page you must give it a condition, then add every extra
  42.  * condition to a page with a comment or note, same format as plugin commands:
  43.  *
  44.  * switch x x x x x x
  45.  * battleswitch x x x x x
  46.  * troopswitch x x
  47.  * partyswitch x x x
  48.  * partybattleswitch x x x
  49.  *
  50.  *  - Add specified game, battle, troop or party switch to conditions.
  51.  *    You can place all same-type switchs you need in same line.
  52.  *
  53.  * [prefix]variable x value
  54.  * [prefix]variablehigh x value
  55.  * [prefix]variableless x value
  56.  * [prefix]variablemax x value
  57.  * [prefix]variableequal x value
  58.  * [prefix]variabledif x value
  59.  *
  60.  *  - Add a variable condition. There are six types: min value, higher than,
  61.  *    lower than, max value, equal and not equal.
  62.  *    Optionaly you can add a prefix to use battle, troop, party and
  63.  *    partybattle variables this way:
  64.  *
  65.  * battlevariable x value
  66.  * troopvariable x value [min/max/avg]
  67.  * partybattlevariable x value [min/max/avg]
  68.  *
  69.  *  - Party and troop variables can have an extra parameter. If omited
  70.  *    it will check sum of members specified variables.
  71.  *    -min: check minimun of members specified variables.
  72.  *    -max: check maximun of members specified variables.
  73.  *    -avg: check average value of members specified variables.
  74.  *
  75.  * Also you can add enemies from another troop id by adding a comment
  76.  * no mather wich page.
  77.  *
  78.  * concatenate x x x x
  79.  * concatenate x to y
  80.  *
  81.  * ============================================================================
  82.  * Parameters
  83.  * ============================================================================
  84.  *
  85.  * Developer HaltJS: This is a development variable usefull to check if there is
  86.  * a wrong javascript event condition.
  87.  * When true will throw an error when it found a wrong javascript in lunatic
  88.  * mode.
  89.  * When false it will be ignored and game continues.
  90.  *
  91.  * ============================================================================
  92.  * Incompatibilities
  93.  * ============================================================================
  94.  *
  95.  * It's incompatible with plugins that fully override troop setup.
  96.  *
  97.  * ============================================================================
  98.  * Known isues
  99.  * ============================================================================
  100.  *
  101.  * For non-full override troop setup plugins it must be placed before them
  102.  * or otherwise their setup will be ignored.
  103.  *
  104.  * ============================================================================
  105.  *
  106.  * For commercial and non-commercial games.
  107.  * Credit to ICF-Soft.
  108.  * This entire header must be included with plugin.
  109.  *
  110.  * ============================================================================
  111. */
  112. //=============================================================================
  113.  /*:es
  114.  * @plugindesc v1.00 Este complemento permite más condiciones en los eventos
  115.  * de batalla y concatenar tropas.
  116.  * @author ICF-Soft [http://icfsoft.blogspot.com.es/]
  117.  *
  118.  * @param Developer HaltJS
  119.  * @desc Si está activado salta cuando una función personalizada
  120.  * da error.   No - false   Si - true
  121.  * @default false
  122.  *
  123.  * @help
  124.  * ============================================================================
  125.  * Introducción
  126.  * ============================================================================
  127.  *
  128.  * Este plugin es similar a ICF-Soft Event Extension, pero para funcionar
  129.  * con tropas. Los hice separados debido a las diferencias existentes y
  130.  * así puedo poner diferentes características en cada uno.
  131.  * Usa interruptores y variables que puedan usarse en batalla, como los
  132.  * del juego, de personajes y enemigos y sus grupos, y de batalla.
  133.  *
  134.  * Además puedes agregar enemigos de otros grupos.
  135.  *
  136.  * ============================================================================
  137.  * Uso
  138.  * ============================================================================
  139.  *
  140.  * Para habilitar una página basta con darle una condición, y entonces añadir
  141.  * las condiciones mediante comentarios, el mismo formato que los comandos
  142.  * de complemento:
  143.  *
  144.  * switch x x x x x x
  145.  * battleswitch x x x x x
  146.  * troopswitch x x
  147.  * partyswitch x x x
  148.  * partybattleswitch x x x
  149.  *
  150.  *  - Añade interruptores del juego, batalla, troopa o del grupo.
  151.  *    Puedes poner todos los necesarios en la misma linea.
  152.  *
  153.  * [prefix]variable x value
  154.  * [prefix]variablehigh x value
  155.  * [prefix]variableless x value
  156.  * [prefix]variablemax x value
  157.  * [prefix]variableequal x value
  158.  * [prefix]variabledif x value
  159.  *
  160.  *  - Añade condición de variable variable condition. Hay seis tipos: mínimo,
  161.  *    mayor que, menor que, máximo, igual y diferente.
  162.  *    Opcionalmente puedes añadir un prefijo como battle (de batalla),
  163.  *    troop (de tropa), party (del grupo) y partybattle (de batalla del grupo):
  164.  *
  165.  * battlevariable x value
  166.  * troopvariable x value [min/max/avg]
  167.  * partybattlevariable x value [min/max/avg]
  168.  *
  169.  *  - Los de grupos pueden llevar un parámetro extra. Si se omite se usará
  170.  *    la suma de dicha variable por cada miembro.
  171.  *    -min: el mínimo del grupo.
  172.  *    -max: el máximo del grupo.
  173.  *    -avg: la media del grupo.
  174.  *
  175.  * Además puedes añadir enemigos de otro troopid mediante un comentario
  176.  * sin importar en qué página.
  177.  *
  178.  * concatenate x x x x
  179.  * concatenate x hasta y
  180.  *
  181.  * ============================================================================
  182.  * Parámetros
  183.  * ============================================================================
  184.  *
  185.  * Developer HaltJS: Esta es una variable de uso durante el desarrollo del juego
  186.  * útil cuando quieres comprobar si hay alguna función personalizada incorrecta.
  187.  * Cuando está activado al encontrar un error el juego se para.
  188.  * Cuando está desactivado ignora el error y el juego continúa.
  189.  *
  190.  * ============================================================================
  191.  * Incompatibilidades
  192.  * ============================================================================
  193.  *
  194.  * No es compatible con plugins que reemplacen por completo el troop setup.
  195.  *
  196.  * ============================================================================
  197.  * Problemas conocidos
  198.  * ============================================================================
  199.  *
  200.  * Para los plugins que no reemplazan por completo el troop setup, éste debe
  201.  * estar antes o les eliminará sus características.
  202.  *
  203.  * ============================================================================
  204.  *
  205.  * Para juegos comerciales y no comerciales.
  206.  * Se debe incluir a ICF-Soft en los créditos.
  207.  * Esta cabecera debe incluirse íntegramente con el plugin.
  208.  *
  209.  * ============================================================================
  210. */
  211. //=============================================================================
  212.  
  213. //=============================================================================
  214. // Parameter Variables
  215. //=============================================================================
  216.  
  217. ICF.Parameters = PluginManager.parameters('ICFSoft_EnemyTroopExt');
  218. ICF.Param = ICF.Param || {};
  219.  
  220. ICF.Param.ETroopExHalt = ICF.Parameters['Developer HaltJS'].toLowerCase() === "true";
  221.  
  222. if (!Imported.ICFSoft_MainUtility) {throw new Error('This plugin requires ICF-Soft Main Utility plugin version 1.01 to work.\nYou can download it at icfsoft.blogspot.com inside plugins section.');}
  223. if (ICF.MainUtility.Version < 101) {throw new Error('This plugin requires ICF-Soft Main Utility plugin version 1.01 to work.\nYou can download it at icfsoft.blogspot.com inside plugins section.');}
  224.  
  225. //=============================================================================
  226. // DataManager
  227. //=============================================================================
  228.  
  229. ICF.ETroopEx.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
  230. DataManager.isDatabaseLoaded = function() {
  231.     if (!ICF.ETroopEx.DataManager_isDatabaseLoaded.call(this)) return false;
  232.     if (!ICF.ETroopEx.Procesed) {
  233.     this.processTroopExTags($dataTroops);
  234.     ICF.ETroopEx.Procesed = true;
  235.     }
  236.     return true;
  237. };
  238.  
  239. DataManager.processTroopExTags = function(group) {
  240.     for (var n = 1; n < group.length; n++) {
  241.     var obj = group[n];
  242.     var pages = obj.pages;
  243.  
  244.     obj.concatenation = [];
  245.  
  246.     for (var i = 1; i < pages.length; i++) {
  247.         var page = pages[i];
  248.         page._switchs = [];
  249.         page._battleswitchs = [];
  250.         page._troopswitchs = [];
  251.         page._partyswitchs = [];
  252.         page._partybswitchs = [];
  253.         page._vars = [];
  254.         page._battlevars = [];
  255.         page._troopvars = [];
  256.         page._partyvars = [];
  257.         page._partybvars = [];
  258.         page._customreq = "";
  259.         for (j = 0; j < page.list.length; j += 1) {
  260.             var command = page.list[j];
  261.             if (command.code === 108) {
  262.                 ICF.TroopEx.Checking = false;
  263.                 ICF.TroopEx.ProcessComment(page, obj, command.parameters[0]);
  264.             } else if (command.code === 408) {
  265.                 ICF.TroopEx.ProcessComment(page, obj, command.parameters[0]);
  266.             }
  267.         }
  268.  
  269.     }
  270.  
  271.  
  272.     }
  273. };
  274.  
  275. //=============================================================================
  276. // TroopEx Utilities
  277. //=============================================================================
  278.  
  279. ICF.TroopEx.Checking = false;
  280.  
  281. ICF.TroopEx.CustomSwitch = function(mapid, evid, switchname, value) {
  282.     var _key = [mapid, evid, switchname];
  283.     var _value = (value.toLowerCase() === "true");
  284.     $gameSelfSwitches.setValue(_key, _value);
  285. }
  286.  
  287. ICF.TroopEx.ProcessComment = function(page, obj, content) {
  288.     var args = content.split(" ");
  289.     if (ICF.TroopEx.Checking) {
  290.         page._customreq = page._customreq + content + '\n';
  291.     } else if (args[0] !== null && args[1] !== null) {
  292.         if (args[0].toLowerCase() == "switch") {
  293.             args.splice(0, 1);
  294.             page._switchs = page._switchs.concat(args);
  295.         } else if (args[0].toLowerCase() == "battleswitch") {
  296.             args.splice(0, 1);
  297.             page._battleswitchss = page._battleswitchs.concat(args);
  298.         } else if (args[0].toLowerCase() == "troopswitch") {
  299.             args.splice(0, 1);
  300.             page._troopswitchs = page._troopswitchs.concat(args);
  301.         } else if (args[0].toLowerCase() == "partyswitch") {
  302.             args.splice(0, 1);
  303.             page._partyswitchs = page._partyswitchs.concat(args);
  304.         } else if (args[0].toLowerCase() == "partybattleswitch") {
  305.             args.splice(0, 1);
  306.             page._partybswitchs = page._partybswitchs.concat(args);
  307.         } else if (args[0].toLowerCase().match(/((?:battle)|(?:troop)|(?:party)|(?:partybattle))?(variable)((?:high)|(?:less)|(?:min)|(?:max)|(?:equal)|(?:dif))?/i)&&(RegExp.$1.length + RegExp.$2.length + RegExp.$3.length == args[0].length)) {
  308.             var code = (RegExp.$3 == "high")? 2 : (RegExp.$3 == "less")? 4 : (RegExp.$3 == "max")? 5 : (RegExp.$3 == "equal")? 0 : (RegExp.$3 == "dif")? 1 : 3;
  309.             if (RegExp.$1 == "battle") page._battlevars.push([code, args[1], args[2]]);
  310.             else if (RegExp.$1 == "troop") page._troopvars.push([code, args[1], args[2], args[3]]);
  311.             else if (RegExp.$1 == "party") page._partyvars.push([code, args[1], args[2], args[3]]);
  312.             else if (RegExp.$1 == "partybattle") page._partybvars.push([code, args[1], args[2], args[3]]);
  313.             else page._vars.push([code, args[1], args[2]]);
  314.         } else if (args[0].toLowerCase() == "customreq:") {
  315.             page._customreq = page._customreq + content.substring(10) + '\n';
  316.             ICF.Events.Checking = true;
  317.         } else if (args[0].toLowerCase() == "concatenate") {
  318.             args.splice(0, 1);
  319.             args.extend().leaveNumbers();
  320.             obj.concatenation = obj.concatenation.concat(args);
  321.         }
  322.     }
  323. }
  324.  
  325. ICF.TroopEx.CheckVar = function(code, value1, value2) {
  326.     switch (code) {
  327.         case 0:
  328.             return (value1 == value2); break;
  329.         case 1:
  330.             return (value1 !== value2); break;
  331.         case 2:
  332.             return (value1 > value2); break;
  333.         case 3:
  334.             return (value1 >= value2); break;
  335.         case 4:
  336.             return (value1 < value2); break;
  337.         case 5:
  338.             return (value1 <= value2); break;
  339.         default:
  340.             return false;
  341.     }
  342. }
  343.  
  344. //=============================================================================
  345. // Game_Troop
  346. //=============================================================================
  347.  
  348. Game_Troop.prototype.fulltroop = function() {
  349.     var fulltroop $dataTroops[this._troopId].members;
  350.     var a = $dataTroops[this._troopId].concatenation;
  351.     for (i = 0; i < a.length; i += 1) {
  352.     fulltroop.concat($dataTroops[a[i]].members);
  353.     }
  354.     return fulltroop;
  355. };
  356.  
  357. Game_Troop.prototype.setup = function(troopId) {
  358.     this.clear();
  359.     this._troopId = troopId;
  360.     this._enemies = [];
  361.     this.fulltroop().forEach(function(member) {
  362.         if ($dataEnemies[member.enemyId]) {
  363.             var enemyId = member.enemyId;
  364.             var x = member.x;
  365.             var y = member.y;
  366.             var enemy = new Game_Enemy(enemyId, x, y);
  367.             if (member.hidden) {
  368.                 enemy.hide();
  369.             }
  370.             this._enemies.push(enemy);
  371.         }
  372.     }, this);
  373.     this.makeUniqueNames();
  374. };
  375.  
  376. ICF.ETroopEx.meetsConditions = Game_Troop.prototype.meetsConditions{
  377. Game_Troop.prototype.meetsConditions = function(page) {
  378.     if (!ICF.ETroopEx.meetsConditions.call(this, page)) return false;
  379.     for (i = 0; i < page._switchs.length; i += 1) {
  380.         if (!$gameSwitches.value(page._switchs[i])) {
  381.             return false;
  382.         }
  383.     }
  384.     for (i = 0; i < page._battleswitchs.length; i += 1) {
  385.         if (!$gameBattleSwitches.value([0, 0, page._battleswitchs[i]])) {
  386.             return false;
  387.         }
  388.     }
  389.     for (i = 0; i < page._troopswitchs.length; i += 1) {
  390.         if ($gameTroop.battleswitch(page._troopswitchs[i])) !== true) {
  391.             return false;
  392.         }
  393.     }
  394.     for (i = 0; i < page._partyswitchs.length; i += 1) {
  395.         if ($gameParty.selfswitch(page._partyswitchs[i]) !== true) {
  396.             return false;
  397.         }
  398.     }
  399.     for (i = 0; i < page._partybswitchs.length; i += 1) {
  400.         if ($gameParty.battleswitch(page._partybswitchs[i]) !== true) {
  401.             return false;
  402.         }
  403.     }
  404.     for (i = 0; i < page._vars.length; i += 1) {
  405.         if (!ICF.TroopEx.CheckVar(page._vars[i][0], $gameVariables.value(page._vars[i][1]), page._vars[i][2])) {
  406.             return false;
  407.         }
  408.     }
  409.     for (i = 0; i < page._battlevars.length; i += 1) {
  410.         var key = [0, 0, page._battlevars[i][1]];
  411.         if (!ICF.TroopEx.CheckVar(page._battlevars[i][0], $gameBattleVariables.value(key), page._battlevars[i][2])) {
  412.             return false;
  413.         }
  414.     }
  415.     for (i = 0; i < page._partyvars.length; i += 1) {
  416.         var code = -1;
  417.         if (!!page._partyvars[i][3]) {code = ["min", "max", "avg"].indexOf(page._partyvars[i][3].toLowerCase());}
  418.         if (code == 0) {if (!ICF.TroopEx.CheckVar(page._partyvars[i][0], $gameParty.minselfvariable(page._partyvars[i][1]), page._partyvars[i][2])) {
  419.             return false;}
  420.         } else if (code == 1) {if (!ICF.TroopEx.CheckVar(page._partyvars[i][0], $gameParty.maxselfvariable(page._partyvars[i][1]), page._partyvars[i][2])) {
  421.             return false;}
  422.         } else if (code == 2) {if (!ICF.TroopEx.CheckVar(page._partyvars[i][0], $gameParty.avgselfvariable(page._partyvars[i][1]), page._partyvars[i][2])) {
  423.             return false;}
  424.         } else {if (!ICF.TroopEx.CheckVar(page._partyvars[i][0], $gameParty.selfvariable(page._partyvars[i][1]), page._partyvars[i][2])) {
  425.             return false;}
  426.         }
  427.     }
  428.     for (i = 0; i < page._partybvars.length; i += 1) {
  429.         var code = -1;
  430.         if (!!page._partybvars[i][3]) {code = ["min", "max", "avg"].indexOf(page._partybvars[i][3].toLowerCase());}
  431.         if (code == 0) {if (!ICF.TroopEx.CheckVar(page._partybvars[i][0], $gameParty.minbattlevariable(page._partybvars[i][1]), page._partybvars[i][2])) {
  432.             return false;}
  433.         } else if (code == 1) {if (!ICF.TroopEx.CheckVar(page._partybvars[i][0], $gameParty.maxbattlevariable(page._partybvars[i][1]), page._partybvars[i][2])) {
  434.             return false;}
  435.         } else if (code == 2) {if (!ICF.TroopEx.CheckVar(page._partybvars[i][0], $gameParty.avgbattlevariable(page._partybvars[i][1]), page._partybvars[i][2])) {
  436.             return false;}
  437.         } else {if (!ICF.TroopEx.CheckVar(page._partybvars[i][0], $gameParty.battlevariable(page._partybvars[i][1]), page._partybvars[i][2])) {
  438.             return false;}
  439.         }
  440.     }
  441.     for (i = 0; i < page._troopvars.length; i += 1) {
  442.         var code = -1;
  443.         if (!!page._troopvars[i][3]) {code = ["min", "max", "avg"].indexOf(page._troopvars[i][3].toLowerCase());}
  444.         if (code == 0) {if (!ICF.TroopEx.CheckVar(page._troopvars[i][0], $gameTroop.minbattlevariable(page._troopvars[i][1]), page._troopvars[i][2])) {
  445.             return false;}
  446.         } else if (code == 1) {if (!ICF.TroopEx.CheckVar(page._troopvars[i][0], $gameTroop.maxbattlevariable(page._troopvars[i][1]), page._troopvars[i][2])) {
  447.             return false;}
  448.         } else if (code == 2) {if (!ICF.TroopEx.CheckVar(page._troopvars[i][0], $gameTroop.avgbattlevariable(page._troopvars[i][1]), page._troopvars[i][2])) {
  449.             return false;}
  450.         } else {if (!ICF.TroopEx.CheckVar(page._troopvars[i][0], $gameTroop.battlevariable(page._troopvars[i][1]), page._troopvars[i][2])) {
  451.             return false;}
  452.         }
  453.     }
  454.  
  455.     if (page._customreq.length != "") {
  456.         var result = false;
  457.         try {eval(page._customreq);}
  458.         catch (e) {if(ICF.Param.ETroopExHalt){throw new Error('Error in custom page condition for troop');}}
  459.         return result;
  460.     }
  461.  
  462.     return true;
  463. }
  464.  
  465. //=============================================================================
  466. // End of File
  467. //=============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement