Advertisement
ICF-Soft

ICF-Soft Actors Core for RPG Maker

Jan 23rd, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // ICF-Soft Plugins - Actors Core
  3. // ICFSoft_ActorsCore.js
  4. //=============================================================================
  5.  
  6. var Imported = Imported || {};
  7. Imported.ICFSoft_ActorsCore = true;
  8.  
  9. var ICF = ICF || {};
  10. ICF.ActorsCore = ICF.ActorsCore || {};
  11.  
  12. ICF.ActorsCore.Version = 100; // 1.00
  13.  
  14. //=============================================================================
  15.  /*:
  16.  * @plugindesc v1.00 This plugin gives level up actions and subtraits
  17.  * to actors.
  18.  * @author ICF-Soft [http://icfsoft.blogspot.com.es/]
  19.  *
  20.  * @param Javascript on level down
  21.  * @desc Javascript code will run also when an actor level down.
  22.  * NO - false     YES - true
  23.  * @default false
  24.  *
  25.  * @param Developer HaltJS
  26.  * @desc When true it throws an error if an custom enemy selection
  27.  * javascript doesn't work.   NO - false     YES - true
  28.  * @default false
  29.  *
  30.  * @help
  31.  * ============================================================================
  32.  * Introduction
  33.  *
  34.  * This is a plugin designed to have all actor related funtions.
  35.  *
  36.  * Actually you can give special subtraits based on level or
  37.  * custom javascript conditions. And use level up common events and
  38.  * javascript code.
  39.  *
  40.  * ============================================================================
  41.  * How to use
  42.  * ============================================================================
  43.  *
  44.  * It works with notetags, these can be applied to actors or classes:
  45.  *
  46.  * <LEVEL SUBTRAITS: lv n>
  47.  * <LEVEL SUBTRAITS: lv n, lv n, lv n>
  48.  *
  49.  *  - Allow to use a subtrait setup from main utility plugin when an
  50.  *    actor has reached specified level. Only highest level is applied.
  51.  *    You can use all you will need in a line, must be in ascending order.
  52.  *
  53.  * <CONDITIONAL SUBTRAIT: n javascript>
  54.  *
  55.  *  - Allow to use a subtrait setup for an actor if a condition is
  56.  *    met. More than one setup can be applied.
  57.  *
  58.  * <LEVEL UP EVENT: x>
  59.  *
  60.  *  - Allow to call a common event when an actor level up.
  61.  *
  62.  * To make subtrait setups you use main utility plugin notation.
  63.  * (See main utility plugin readme file).
  64.  *
  65.  * Example:
  66.  *
  67.  * <SUBTRAITS MASTER>
  68.  * debuffrate 3 0.95
  69.  * <SUBTRAITS MASTER>
  70.  * debuffrate 3 0.92
  71.  * xparamplus 0 0.1
  72.  * </SUBTRAITS MASTER>
  73.  *
  74.  *
  75.  * Here's an example of an actor setup:
  76.  *
  77.  * <LEVEL SUBTRAITS: 5 0, 10 1, 15 2>
  78.  * <CONDITIONAL SUBTRAIT: 3 $gameSwitches.value(20)>
  79.  * <CONDITIONAL SUBTRAIT: 4 this.hp / this.mhp < 0.3)>
  80.  * <LEVEL UP EVENT: 1>
  81.  *
  82.  * <SUBTRAITS MASTER>
  83.  * debuffrate 3 0.95
  84.  * <SUBTRAITS MASTER>
  85.  * debuffrate 3 0.92
  86.  * xparamplus 0 0.1
  87.  * <SUBTRAITS MASTER>
  88.  * debuffrate 3 0.90
  89.  * xparamplus 0 0.15
  90.  * <SUBTRAITS MASTER>
  91.  * paramxflat 1 200
  92.  * <SUBTRAITS MASTER>
  93.  * attack_state 2 1
  94.  * </SUBTRAITS MASTER>
  95.  *
  96.  * ============================================================================
  97.  * Lunatic Mode
  98.  * ============================================================================
  99.  *
  100.  * If you want to use special javascript code when an actor level up you can
  101.  * use this notetag.
  102.  *
  103.  * <CUSTOM LEVEL UP>
  104.  * lastLevel
  105.  * level
  106.  * levels
  107.  * </CUSTOM LEVEL UP>
  108.  *
  109.  *  - You can use lastlevel, level and levels variables. They're
  110.  *    selfexplanatory
  111.  *
  112.  * ============================================================================
  113.  * Parameters
  114.  * ============================================================================
  115.  *
  116.  * Javascript on level down: By default, javascript code only runs when level
  117.  * up. If enabled javascript code will be runned either on level up or level
  118.  * down.
  119.  *
  120.  * Developer HaltJS: This is a development variable usefull to check if there
  121.  * is a wrong javascript code.
  122.  * When true will throw an error when it found a wrong javascript in lunatic
  123.  * mode and tell specified actor or class id.
  124.  * When false it will be ignored and game continues.
  125.  *
  126.  * ============================================================================
  127.  * Incompatibilities
  128.  * ============================================================================
  129.  *
  130.  * There's no known incompatible plugins yet.
  131.  *
  132.  * ============================================================================
  133.  * Known isues
  134.  * ============================================================================
  135.  *
  136.  * Not yet.
  137.  *
  138.  * ============================================================================
  139.  *
  140.  * For commercial and non-commercial games.
  141.  * Credit to ICF-Soft.
  142.  * This entire header must be included with plugin.
  143.  *
  144.  * ============================================================================
  145. */
  146. //=============================================================================
  147.  /*:es
  148.  * @plugindesc v1.00 Este complemento añade acciones al subir de nivel
  149.  * y subrasgos a los personajes.
  150.  * @author ICF-Soft [http://icfsoft.blogspot.com.es/]
  151.  *
  152.  * @param Javascript on level down
  153.  * @desc El código javascript se ejecutará también cuando el personaje
  154.  * baje de nivel.   No - false   Si - true
  155.  * @default false
  156.  *
  157.  * @param Developer HaltJS
  158.  * @desc Si está activado salta cuando una función personalizada
  159.  * da error.   No - false   Si - true
  160.  * @default false
  161.  *
  162.  * @help
  163.  * ============================================================================
  164.  * Introducción
  165.  * ============================================================================
  166.  *
  167.  * Este plugin está hecho para englobar todas las funciones relativas a
  168.  * los personajes.
  169.  *
  170.  * Actualmente puedes añadir conjuntos de subrasgos en función del nivel
  171.  * o condiciones javascript personalizadas. Además puedes hacer que se
  172.  * ejecuten eventos comunes y/o código javascript al subir de nivel.
  173.  *
  174.  * ============================================================================
  175.  * Uso
  176.  * ============================================================================
  177.  *
  178.  * Funciona mediante etiquetas en las notas, pueden usarse tanto en
  179.  * actores como en clases:
  180.  *
  181.  * <LEVEL SUBTRAITS: lv n>
  182.  * <LEVEL SUBTRAITS: lv n, lv n, lv n>
  183.  *
  184.  *  - Permite usar subrasgos creados mediante el main utility en función
  185.  *    del nivel del personaje. Solo se aplica el nivel más alto.
  186.  *    Puedes usar todos los que necesites en la misma lines, tienen que
  187.  *    estar en orden ascendente.
  188.  *
  189.  * <CONDITIONAL SUBTRAIT: n javascript>
  190.  *
  191.  *  - Permite usar subrasgos si se cumple una condición en javascript.
  192.  *    Pueden aplicarse más de una.
  193.  *
  194.  * <LEVEL UP EVENT: x>
  195.  *
  196.  *  - Permite llamar un evento común al subir de nivel.
  197.  *
  198.  * Para crear un conjunto de subrasgos se utiliza la notación del
  199.  * plugin main utility (Ver archivo léeme del main utility).
  200.  *
  201.  * Ejemplo:
  202.  *
  203.  * <SUBTRAITS MASTER>
  204.  * debuffrate 3 0.95
  205.  * <SUBTRAITS MASTER>
  206.  * debuffrate 3 0.92
  207.  * xparamplus 0 0.1
  208.  * </SUBTRAITS MASTER>
  209.  *
  210.  *
  211.  * Aquí tienes un ejemplo de configuración de personaje:
  212.  *
  213.  * <LEVEL SUBTRAITS: 5 0, 10 1, 15 2>
  214.  * <CONDITIONAL SUBTRAIT: 3 $gameSwitches.value(20)>
  215.  * <CONDITIONAL SUBTRAIT: 4 this.hp / this.mhp < 0.3)>
  216.  * <LEVEL UP EVENT: 1>
  217.  *
  218.  * <SUBTRAITS MASTER>
  219.  * debuffrate 3 0.95
  220.  * <SUBTRAITS MASTER>
  221.  * debuffrate 3 0.92
  222.  * xparamplus 0 0.1
  223.  * <SUBTRAITS MASTER>
  224.  * debuffrate 3 0.90
  225.  * xparamplus 0 0.15
  226.  * <SUBTRAITS MASTER>
  227.  * paramxflat 1 200
  228.  * <SUBTRAITS MASTER>
  229.  * attack_state 2 1
  230.  * </SUBTRAITS MASTER>
  231.  *
  232.  * ============================================================================
  233.  * Modo Lunático
  234.  * ============================================================================
  235.  *
  236.  * Si quieres usar código javascript cuando el personaje suba de nivel
  237.  * utiliza las siguientes etiquetas.
  238.  *
  239.  * <CUSTOM LEVEL UP>
  240.  * lastLevel
  241.  * level
  242.  * levels
  243.  * </CUSTOM LEVEL UP>
  244.  *
  245.  *  - Puedes usar las variables lastlevel para el nivel que tenía antes,
  246.  *    level para el nivel actual y levels para cuantos niveles ha subido.
  247.  *
  248.  * ============================================================================
  249.  * Parámetros
  250.  * ============================================================================
  251.  *
  252.  * Javascript on level down: De modo predeterminado, las funciones en
  253.  * javascript sólo se ejecutan al subir de nivel. Si lo activas, el código
  254.  * También se ejecutará al bajar de nivel.
  255.  *
  256.  * Developer HaltJS: Esta es una variable de uso durante el desarrollo del juego
  257.  * útil cuando quieres comprobar si hay alguna función personalizada incorrecta.
  258.  * Cuando está activado al encontrar un error el juego se para y muestra
  259.  * en qué personaje o clase se encuentra el error.
  260.  * Cuando está desactivado ignora el error y el juego continúa.
  261.  *
  262.  * ============================================================================
  263.  * Incompatibilidades
  264.  * ============================================================================
  265.  *
  266.  * No se conocen complementos que sean incompatibles hasta la fecha.
  267.  *
  268.  * ============================================================================
  269.  * Problemas conocidos
  270.  * ============================================================================
  271.  *
  272.  * Por el momento ninguno.
  273.  *
  274.  * ============================================================================
  275.  *
  276.  * Para juegos comerciales y no comerciales.
  277.  * Se debe incluir a ICF-Soft en los créditos.
  278.  * Esta cabecera debe incluirse íntegramente con el plugin.
  279.  *
  280.  * ============================================================================
  281. */
  282. //=============================================================================
  283.  
  284. //=============================================================================
  285. // Parameter Variables
  286. //=============================================================================
  287.  
  288. ICF.Parameters = PluginManager.parameters('ICFSoft_ActorsCore');
  289. ICF.Param = ICF.Param || {};
  290.  
  291. ICF.Param.IncludeLevelDown = ICF.Parameters['Javascript on level down'].toLowerCase() === "true";
  292. ICF.Param.ActorCoreHalt = ICF.Parameters['Developer HaltJS'].toLowerCase() === "true";
  293.  
  294. 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.');}
  295.  
  296. //=============================================================================
  297. // DataManager
  298. //=============================================================================
  299.  
  300. ICF.ActorsCore.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
  301. DataManager.isDatabaseLoaded = function() {
  302.     if (!ICF.ActorsCore.DataManager_isDatabaseLoaded.call(this)) return false;
  303.     if (!ICF.ActorsCore.Procesed) {
  304.     DataManager.processActorsCoreNotetags($dataActors);
  305.     DataManager.processActorsCoreNotetags($dataClasses);
  306.     ICF.ActorsCore.Procesed = true;
  307.     }
  308.     return true;
  309. };
  310.  
  311. DataManager.processActorsCoreNotetags = function(group) {
  312.     var note1 = /<(?:LEVEL SUBTRAITS):[ ]*(\d+\s+\d+(?:\s*,\s*\d+\s+\d+)*\s*)>/i;
  313.     var note2 = /<(?:CONDITIONAL SUBTRAIT):[ ]*(\d+) (.*)\s*>/i;
  314.     var note3 = /<(?:LEVEL[-_ ]UP[-_ ]EVENT):[ ]*(\d+)>/i;
  315.     var note4a = /<(?:CUSTOM LEVEL UP)>/i;
  316.     var note4b = /<\/(?:CUSTOM LEVEL UP)>/i;
  317.  
  318.     for (var n = 1; n < group.length; n++) {
  319.     var obj = group[n];
  320.     var notedata = obj.note.split(/[\r\n]+/);
  321.  
  322.     obj.levelSubtraits = [];
  323.     obj.condSubtraits = [];
  324.  
  325.     obj.levelUpEvent = 0;
  326.     obj.customLevelUp = '';
  327.  
  328.     var flag = false;
  329.  
  330.     for (var i = 0; i < notedata.length; i++) {
  331.         var line = notedata[i];
  332.         if (line.match(note1)) {
  333.             var array = JSON.parse('[' + RegExp.$1.match(/\d+/g) + ']');
  334.             for (var il = 0; il < array.length; il += 2) {
  335.                 obj.levelSubtraits.push([array[il], array[il + 1]]);
  336.             }
  337.         } else if (line.match(note2)) {
  338.             obj.condSubtraits.push([RegExp.$2, RegExp.$1]);
  339.         } else if (line.match(note3)) {
  340.             obj.levelUpEvent = RegExp.$1;
  341.         } else if (line.match(note4a)) {
  342.             flag = true;
  343.         } else if (line.match(note4b)) {
  344.             flag = false;
  345.         } else if (flag) {
  346.             obj.customLevelUp = obj.customLevelUp + line + '\n';
  347.         }
  348.     }
  349.     }
  350. };
  351.  
  352. //=============================================================================
  353. // Game_Actor
  354. //=============================================================================
  355.  
  356. ICF.ActorsCore.traitObjects = Game_Actor.prototype.traitObjects;
  357. Game_Actor.prototype.traitObjects = function() {
  358.     var objects = ICF.ActorsCore.traitObjects.call(this);
  359.     if (!this._lvTrait) this.getLevelTrait();
  360.     if (!this._lvCTrait) this.getLevelCTrait();
  361.  
  362.     if (this._lvTrait > -1) objects.push(this.actor().subtraits[this._lvTrait]);
  363.     if (this._lvCTrait > -1) objects.push(this.currentClass().subtraits[this._lvCTrait]);
  364.  
  365.     var array = this.actor().condSubtraits;
  366.     for (var i = 0; i < array.length; i++) {
  367.     if (eval(array[i][0])) {
  368.         objects.push(this.actor().subtraits[array[i][1]]);
  369.     }
  370.     }
  371.     array = this.currentClass().condSubtraits;
  372.     for (var i = 0; i < array.length; i++) {
  373.     if (eval(array[i][0])) {
  374.         objects.push(this.currentClass().subtraits[array[i][1]]);
  375.     }
  376.     }
  377.     return objects;
  378. };
  379.  
  380. Game_Actor.prototype.getLevelTrait = function() {
  381.     this._lvTrait = -1;
  382.     var array = this.actor().levelSubtraits;
  383.     for (var i = 0; i < array.length; i++) {
  384.     if (this._level >= array[i][0]) {
  385.         this._lvTrait = array[i][1];
  386.     }
  387.     }
  388. };
  389.  
  390. Game_Actor.prototype.getLevelCTrait = function() {
  391.     this._lvCTrait = -1;
  392.     var array = this.currentClass().levelSubtraits;
  393.     for (var i = 0; i < array.length; i++) {
  394.     if (this._level >= array[i][0]) {
  395.         this._lvCTrait = array[i][1];
  396.     }
  397.     }
  398. };
  399.  
  400. ICF.ActorsCore.changeExp = Game_Actor.prototype.changeExp;
  401. Game_Actor.prototype.changeExp = function(exp, show) {
  402.     var lastLevel = this._level;
  403.     ICF.ActorsCore.changeExp.call(this, exp, show);
  404.     var level = this._level;
  405.     var levels = level - lastLevel;
  406.     if (levels != 0) {
  407.     this.getLevelTrait();
  408.     this.getLevelCTrait();
  409.     }
  410.     if (levels < 0 && ICF.Param.IncludeLevelDown) {
  411.     if (this.actor().customLevelUp != '') {
  412.         try {eval(this.actor().customLevelUp);}
  413.         catch (e) {if(ICF.Param.ActorCoreHalt){throw new Error('Error in custom level up for actor #' + this._actorId);}}
  414.     }
  415.     if (this.currentClass().customLevelUp != '') {
  416.         try {eval(this.currentClass().customLevelUp);}
  417.         catch (e) {if(ICF.Param.ActorCoreHalt){throw new Error('Error in custom level up for class #' + this._classId);}}
  418.     }
  419.     }
  420.     if (levels > 0) {
  421.     if (this.actor().customLevelUp != '') {
  422.         try {eval(this.actor().customLevelUp);}
  423.         catch (e) {if(ICF.Param.ActorCoreHalt){throw new Error('Error in custom level up for actor #' + this._actorId);}}
  424.     }
  425.     if (this.currentClass().customLevelUp != '') {
  426.         try {eval(this.currentClass().customLevelUp);}
  427.         catch (e) {if(ICF.Param.ActorCoreHalt){throw new Error('Error in custom level up for class #' + this._classId);}}
  428.     }
  429.     if (!DataManager.isBattleTest()) {
  430.         if (this.actor().levelUpEvent > 0) {
  431.             for (var i = 0; i < levels; i++) {$gameTemp.reserveCommonEvent(this.actor().levelUpEvent);}
  432.         }
  433.         if (this.currentClass().levelUpEvent > 0) {
  434.             for (var i = 0; i < levels; i++) {$gameTemp.reserveCommonEvent(this.currentClass().levelUpEvent);}
  435.         }
  436.     }
  437.     }
  438.     this.refresh();
  439. };
  440.  
  441. //=============================================================================
  442. // Game_Temp
  443. //=============================================================================
  444.  
  445. if (!Imported.ICFSoft_MainCore) {
  446.     Game_Temp.prototype.reserveCommonEvent = function(commonEventId) {
  447.     if (!this._commontEventArray) this._commontEventArray = [];
  448.     this._commontEventArray.push(commonEventId);
  449.     };
  450.  
  451.     Game_Temp.prototype.clearCommonEvent = function() {
  452.     if (!this._commontEventArray) this._commontEventArray = [];
  453.     this._commontEventArray.splice(0, 1);
  454.     };
  455.  
  456.     Game_Temp.prototype.isCommonEventReserved = function() {
  457.     if (!this._commontEventArray) this._commontEventArray = [];
  458.     return this._commontEventArray.length > 0;
  459.     };
  460.  
  461.     Game_Temp.prototype.reservedCommonEvent = function() {
  462.     if (!this._commontEventArray) this._commontEventArray = [];
  463.     return $dataCommonEvents[this._commontEventArray[0]];
  464.     };
  465. }
  466.  
  467. //=============================================================================
  468. // End of File
  469. //=============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement