Advertisement
ICF-Soft

ICF-Soft Element Core RPG Maker MV

May 5th, 2016
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // ICF-Soft Plugins - Element Core
  3. // ICFSoft_ElementCore.js
  4. //=============================================================================
  5.  
  6. var Imported = Imported || {};
  7. Imported.ICFSoft_ElementCore = true;
  8.  
  9. var ICF = ICF || {};
  10. ICF.ElementCore = ICF.ElementCore || {};
  11.  
  12. //=============================================================================
  13.  /*:
  14.  * @plugindesc v1.00 This plugin adds an advanced element system.
  15.  * @author ICF-Soft [http://icfsoft.blogspot.com.es/]
  16.  *
  17.  * @param Elements Blend
  18.  * @desc How to apply when there are more than one element.
  19.  * 0 - Average  1 - Normal  2 - Absorb first
  20.  * @default 2
  21.  *
  22.  * @param Absorbtion Mode
  23.  * @desc How to treat element absorbtion.
  24.  * 0 - Absolute  1 - Relative
  25.  * @default 1
  26.  *
  27.  * @help
  28.  * ============================================================================
  29.  * Introduction
  30.  * ============================================================================
  31.  *
  32.  * Defalut element system in RPG Maker MV is limited and doesn't allow
  33.  * absorbtion.
  34.  *
  35.  * With this plugin you can use not only elements but skill and weapon types
  36.  * plus element absorbtion.
  37.  *
  38.  * This new formula makes more things important and gives extra depth in
  39.  * tactics.
  40.  *
  41.  * Now you can make magic resistance, bulletproof and so on.
  42.  *
  43.  * ============================================================================
  44.  * How to use
  45.  * ============================================================================
  46.  *
  47.  * It works with notetags. These can be used in actors, classes, enemies,
  48.  * weapons, armors and states.
  49.  *
  50.  * <ELEMENT ABSORB: x>
  51.  * <ELEMENT ABSORB: x, x>
  52.  *
  53.  *  - Add all elements that can be absorbed in one line.
  54.  *
  55.  * <WEAPON ELEMENTS: x>
  56.  * <WEAPON ELEMENTS: x, x>
  57.  *
  58.  *  - Add all weapon elements that are used in one line.
  59.  *    Usefull for enemies and for unarmed actors.
  60.  *    0 is barehands. Used for actors when need a weapontype but hasn't one.
  61.  *
  62.  * <WEAPON RESISTANCES: x rate>
  63.  * <WEAPON RESISTANCES: x rate, x rate>
  64.  *
  65.  *  - Add all weapon resistances needed in one line.
  66.  *    rate: must be an integer where 100 is normal, 50 is half,
  67.  *          200 is double, etc...
  68.  *
  69.  * <SKILL RESISTANCES: x rate>
  70.  * <SKILL RESISTANCES: x rate, x rate>
  71.  *
  72.  *  - Add all skill resistances needed in one line.
  73.  *    rate: must be an integer where 100 is normal, 50 is half,
  74.  *          200 is double, etc...
  75.  *
  76.  * Skill resistance triggers on every skill that came with skilltype.
  77.  *
  78.  * Weapon resistance triggers on physical skills and weapon using skills.
  79.  *
  80.  * ============================================================================
  81.  * Params
  82.  * ============================================================================
  83.  *
  84.  * Elements Blend:
  85.  *
  86.  *  Behavior when more than one element are used.
  87.  *
  88.  *  0 - Average:      Calcs entire element average.
  89.  *  1 - Normal:       Strongest element takes priority.
  90.  *  2 - Absorb first: If there is an absorbing element will take priority.
  91.  *
  92.  * Absorbtion Mode:
  93.  *
  94.  *  How element absorbtion is treated changes the way players must choose
  95.  *  equipment.
  96.  *
  97.  *  0 - Absolute:     Element defense increase absorbtion.
  98.  *  1 - Relative:     Element defense reduces absorbtion same way as damage.
  99.  *
  100.  * ============================================================================
  101.  * Incompatibilities
  102.  * ============================================================================
  103.  *
  104.  * There's no known incompatible plugins yet.
  105.  *
  106.  * ============================================================================
  107.  * Known isues
  108.  * ============================================================================
  109.  *
  110.  * It overrides every other element system that comes after.
  111.  *
  112.  * ============================================================================
  113.  *
  114.  * Commercial use avaiable.
  115.  * Credit to ICF-Soft.
  116.  * This entire header must be included with plugin.
  117.  *
  118.  * ============================================================================
  119. */
  120. //=============================================================================
  121.  /*:es
  122.  * @plugindesc v1.00 Este complemento añade un sistema de elementos
  123.  * avanzado.
  124.  * @author ICF-Soft [http://icfsoft.blogspot.com.es/]
  125.  *
  126.  * @param Elements Blend
  127.  * @desc Qué hacer cuando se usa más de un elemento.
  128.  * 0 - Media  1 - Normal  2 - Absorbción primero
  129.  * @default 2
  130.  *
  131.  * @param Absorbtion Mode
  132.  * @desc El modo en el que se absorben los elementos.
  133.  * 0 - Absoluto  1 - Relativo
  134.  * @default 1
  135.  *
  136.  * @help
  137.  * ============================================================================
  138.  * Introducción
  139.  * ============================================================================
  140.  *
  141.  * El sistema de elementos que viene predeterminado en RPG Maker MV es limitado
  142.  * y no permite la absorbción.
  143.  *
  144.  * Con este complemento puedes usar no sólo elementos sino también tipos de
  145.  * habilidades y armas además de la absorbción de elementos.
  146.  *
  147.  * Esta nueva fórmula da importancia a más opciones y da profundidad extra
  148.  * en las tácticas.
  149.  *
  150.  * Ahora puedes utilizar resistencia a la magia, antibalas y más cosas similares.
  151.  *
  152.  * ============================================================================
  153.  * Uso
  154.  * ============================================================================
  155.  *
  156.  * Funciona con etiquetas en las notas. Pueden usarse en actores, clases,
  157.  * enemigos, armas, armaduras y estados alterados.
  158.  *
  159.  * <ELEMENT ABSORB: x>
  160.  * <ELEMENT ABSORB: x, x>
  161.  *
  162.  *  - Añade todos los elementos que puede absorber en una linea.
  163.  *
  164.  * <WEAPON ELEMENTS: x>
  165.  * <WEAPON ELEMENTS: x, x>
  166.  *
  167.  *  - Añade todos los tipos de arma que se utilizan en una linea.
  168.  *    Útil para enemigos y los actores que no lleven armas.
  169.  *    0 son los puños. Se utiliza cuando un actor necesita un tipo de arma
  170.  *    pero no está disponible ninguno.
  171.  *
  172.  * <WEAPON RESISTANCES: x rate>
  173.  * <WEAPON RESISTANCES: x rate, x rate>
  174.  *
  175.  *  - Añade todas las resistencias a las armas en una linea.
  176.  *    rate: debe ser un número entero, 100 es normal, 50 es la mitad,
  177.  *          200 es doble, etc...
  178.  *
  179.  * <SKILL RESISTANCES: x rate>
  180.  * <SKILL RESISTANCES: x rate, x rate>
  181.  *
  182.  *  - Añade todas las resistencias a las habilidades en una linea.
  183.  *    rate: debe ser un número entero, 100 es normal, 50 es la mitad,
  184.  *          200 es doble, etc...
  185.  *
  186.  * La resistencia a las habilidades se activa en las habilidades que incluyan
  187.  * categoría.
  188.  *
  189.  * La resistencia a las armas se activa en las habilidades físicas y las que
  190.  * utilizan arma.
  191.  *
  192.  * ============================================================================
  193.  * Parámetros
  194.  * ============================================================================
  195.  *
  196.  * Elements Blend:
  197.  *
  198.  *  El comportamiento cuando se usan más de un elemento.
  199.  *
  200.  *  0 - Media:             Calcula la media.
  201.  *  1 - Normal:            El elemento más dañino toma prioridad.
  202.  *  2 - Absorción primero: Si un elemento es absorbible tendrá prioridad.
  203.  *
  204.  * Absorbtion Mode:
  205.  *
  206.  *  El modo en el que los elementos son absorbidos cambia el modo en el que
  207.  *  el jugador debe seleccionar el equipamiento.
  208.  *
  209.  *  0 - Absoluto:     La defensa elemental incrementa la absorbción.
  210.  *  1 - Relativo:     La defensa elemental reduce tanto la absorbción
  211.  *                    como el daño.
  212.  *
  213.  * ============================================================================
  214.  * Incompatibilidades
  215.  * ============================================================================
  216.  *
  217.  * No se conocen complementos que sean incompatibles hasta la fecha.
  218.  *
  219.  * ============================================================================
  220.  * Problemas conocidos
  221.  * ============================================================================
  222.  *
  223.  * Se sobreescribe cualquier sistema de elementos que se haya puesto antes.
  224.  *
  225.  * ============================================================================
  226.  *
  227.  * Se permite el uso comercial.
  228.  * Se debe incluir a ICF-Soft en los créditos.
  229.  * Esta cabecera debe incluirse íntegramente con el plugin.
  230.  *
  231.  * ============================================================================
  232. */
  233. //=============================================================================
  234.  
  235. //=============================================================================
  236. // Parameter Variables
  237. //=============================================================================
  238.  
  239. ICF.Parameters = PluginManager.parameters('ICFSoft_ElementCore');
  240. ICF.Param = ICF.Param || {};
  241.  
  242. ICF.Param.ElementBlend = Number(ICF.Parameters['Elements Blend']);
  243. ICF.Param.ElementAbsorbM = Number(ICF.Parameters['Absorbtion Mode']);
  244.  
  245. //=============================================================================
  246. // Constants
  247. //=============================================================================
  248.  
  249. Game_BattlerBase.TRAIT_SK_ELEMENT_RATE    = 15;
  250. Game_BattlerBase.TRAIT_WP_ELEMENT_RATE    = 16;
  251. Game_BattlerBase.TRAIT_ELEMENT_ABSORB     = 17;
  252. Game_BattlerBase.TRAIT_ATTACK_WP_ELEMENT  = 35;
  253.  
  254. //=============================================================================
  255. // DataManager
  256. //=============================================================================
  257.  
  258. ICF.ElementCore.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
  259. DataManager.isDatabaseLoaded = function() {
  260.     if (!ICF.ElementCore.DataManager_isDatabaseLoaded.call(this)) return false;
  261.     if (!ICF.ElementCore.Procesed) {
  262.     DataManager.processEleCoreNotetags($dataActors);
  263.     DataManager.processEleCoreNotetags($dataClasses);
  264.     DataManager.processEleCoreNotetags($dataEnemies);
  265.     DataManager.processEleCoreNotetags($dataWeapons);
  266.     DataManager.processEleCoreNotetags($dataArmors);
  267.     DataManager.processEleCoreNotetags($dataStates);
  268.     ICF.ElementCore.Procesed = true;
  269.     }
  270.     return true;
  271. };
  272.  
  273. DataManager.processEleCoreNotetags = function(group) {
  274.     var note1 = /<(?:ELEMENT ABSORB):[ ]*(\d+(?:\s*,\s*\d+)*)>/i;
  275.     var note2 = /<(?:WEAPON ELEMENTS):[ ]*(\d+(?:\s*,\s*\d+)*)>/i;
  276.     var note3 = /<(?:SKILL RESISTANCES):[ ]*(\d+\s+\d+(?:\s*,\s*\d+\s+\d+)*)>/i;
  277.     var note4 = /<(?:WEAPON RESISTANCES):[ ]*(\d+\s+\d+(?:\s*,\s*\d+\s+\d+)*)>/i;
  278.  
  279.     for (var n = 1; n < group.length; n++) {
  280.     var obj = group[n];
  281.     var notedata = obj.note.split(/[\r\n]+/);
  282.  
  283.     obj.elementAbsorb = [];
  284.  
  285.     for (var i = 0; i < notedata.length; i++) {
  286.         var line = notedata[i];
  287.         if (line.match(note1)) {
  288.             var array = JSON.parse('[' + RegExp.$1.match(/\d+/g) + ']');
  289.             for (var il = 0; il < array.length; il++) {
  290.                 obj.traits.push({code:17, dataId:array[il], value:0});
  291.             }
  292.         } else if (line.match(note2)) {
  293.             var array = JSON.parse('[' + RegExp.$1.match(/\d+/g) + ']');
  294.             for (var il = 0; il < array.length; il++) {
  295.                 obj.traits.push({code:35, dataId:array[il], value:0});
  296.             }
  297.         } else if (line.match(note3)) {
  298.             var array = JSON.parse('[' + RegExp.$1.match(/\d+/g) + ']');
  299.             for (var il = 0; il < (array.length - 1); il += 2) {
  300.                 obj.traits.push({code:15, dataId:array[il], value:array[il + 1] * 0.01});
  301.             }
  302.         } else if (line.match(note4)) {
  303.             var array = JSON.parse('[' + RegExp.$1.match(/\d+/g) + ']');
  304.             for (var il = 0; il < (array.length - 1); il += 2) {
  305.                 obj.traits.push({code:16, dataId:array[il], value:array[il + 1] * 0.01});
  306.             }
  307.         }
  308.     }
  309.     }
  310. };
  311.  
  312. //=============================================================================
  313. // Game_BattlerBase
  314. //=============================================================================
  315.  
  316. Game_BattlerBase.prototype.elementAbsorb = function(elementId) {
  317.     return (this.traitsWithId(Game_BattlerBase.TRAIT_ELEMENT_ABSORB, elementId).length > 0);
  318. };
  319.  
  320. ICF.ElementCore.Game_BtlrBase_elementRate = Game_BattlerBase.prototype.elementRate;
  321. Game_BattlerBase.prototype.elementRate = function(elementId) {
  322.     var result = ICF.ElementCore.Game_BtlrBase_elementRate.call(this, elementId);
  323.     if (this.elementAbsorb(elementId)) {
  324.     if (ICF.Param.ElementAbsorbM == 0) {result = Math.min(result - 2.0, -0.01);}
  325.     else {result *= -1}
  326.     }
  327.     return result;
  328. };
  329.  
  330. Game_BattlerBase.prototype.elSkillRate = function(stypeId) {
  331.     return this.traitsPi(Game_BattlerBase.TRAIT_SK_ELEMENT_RATE, stypeId);
  332. };
  333.  
  334. Game_BattlerBase.prototype.elWeaponRate = function(wtypeId) {
  335.     return this.traitsPi(Game_BattlerBase.TRAIT_WP_ELEMENT_RATE, wtypeId);
  336. };
  337.  
  338. Game_BattlerBase.prototype.wpAttackElements = function() {
  339.     var wpns = this.traitsSet(Game_BattlerBase.TRAIT_ATTACK_WP_ELEMENT);
  340.     wpns.sort(function(a, b){return a-b});
  341.     for (i = wpns.length - 1; i > 0; i -= 1) {
  342.     if (wpns[i] == wpns[i - 1]) wpns.splice(i,1);
  343.     }
  344.     return wpns;
  345. };
  346.  
  347. //=============================================================================
  348. // Game_Actor
  349. //=============================================================================
  350.  
  351. Game_Actor.prototype.wpAttackElements = function() {
  352.     var wpns;
  353.     if (this.weapons().length > 0) {
  354.     wpns = this.weapons().reduce(function(r, obj) {
  355.         return r.concat([obj.wtypeId]);
  356.     }, []);
  357.     wpns.sort(function(a, b){return a-b});
  358.     for (i = wpns.length - 1; i > 0; i -= 1) {
  359.         if (wpns[i] == wpns[i - 1]) wpns.splice(i,1);
  360.     }
  361.     return wpns;
  362.     }
  363.  
  364.     wpns = Game_BattlerBase.prototype.wpAttackElements.call(this);
  365.     if (wpns.length == 0) wpns[0] = 0;
  366.  
  367.     return wpns;
  368. };
  369.  
  370. //=============================================================================
  371. // Game_Action
  372. //=============================================================================
  373.  
  374. Game_Action.prototype.elementsMinRate = function(target, elements) {
  375.     if (elements.length > 0) {
  376.         return Math.min.apply(null, elements.map(function(elementId) {
  377.             return target.elementRate(elementId);
  378.         }, this));
  379.     } else {
  380.         return 1;
  381.     }
  382. };
  383.  
  384. Game_Action.prototype.elementsAverageRate = function(target, elements) {
  385.     if (elements.length > 0) {
  386.         return elements.reduce(function(r, element) {
  387.             return r + target.elementRate(element);
  388.         }, 0) / elements.length;
  389.     } else {
  390.         return 1;
  391.     }
  392. };
  393.  
  394. Game_Action.prototype.wpElementsMaxRate = function(target, wpelements) {
  395.     if (wpelements.length > 0) {
  396.         return Math.max.apply(null, wpelements.map(function(wpelementId) {
  397.             return target.elWeaponRate(wpelementId);
  398.         }, this));
  399.     } else {
  400.         return 1;
  401.     }
  402. };
  403.  
  404. Game_Action.prototype.wpElementsAverageRate = function(target, wpelements) {
  405.     if (wpelements.length > 0) {
  406.         return wpelements.reduce(function(r, wpelement) {
  407.             return r + target.elWeaponRate(wpelement);
  408.         }, 0) / wpelements.length;
  409.     } else {
  410.         return 1;
  411.     }
  412. };
  413.  
  414. Game_Action.prototype.calcWeaponElementRate = function(target) {
  415.     var rate = 1;
  416.     var wpns = this.subject().wpAttackElements();
  417.     if (wpns > 0) {
  418.     if (ICF.Param.ElementBlend == 0) {
  419.         rate = this.wpElementsAverageRate(target, wpns);
  420.     } else {
  421.         rate = this.wpElementsMaxRate(target, wpns);
  422.     }
  423.     }
  424.     return rate;
  425. };
  426.  
  427. Game_Action.prototype.calcElementRate = function(target) {
  428.     var rate = 1;
  429.     var rate2 = 0;
  430.     if (this.item().damage.elementId < 0) {
  431.     if (ICF.Param.ElementBlend == 0) {
  432.         rate = this.elementsAverageRate(target, this.subject().attackElements());
  433.     } else {
  434.         rate = this.elementsMaxRate(target, this.subject().attackElements());
  435.         rate2 = this.elementsMinRate(target, this.subject().attackElements());
  436.         if (ICF.Param.ElementBlend == 2 && rate2 < 0) rate = rate2;
  437.     }
  438.     } else {
  439.         rate = target.elementRate(this.item().damage.elementId);
  440.     }
  441.     if (this.isSkill()) {
  442.     if (this.item().stypeId > 0) {
  443.         rate2 = target.elSkillRate(this.item().stypeId);
  444.         if ((rate < 0)||(rate2 < 1)) {rate = rate * rate2;}
  445.         else {rate += rate2 - 1;}
  446.     }
  447.     if ((this.isPhysical())||(this.item().damage.elementId < 0)) {
  448.         rate2 = this.calcWeaponElementRate(target) + rate;
  449.         if (rate2 > 2) {rate = rate2 - 1;}
  450.         else {rate = rate2 / 2;}
  451.     }
  452.     }
  453.  
  454.     return rate;
  455. };
  456.  
  457. //=============================================================================
  458. // End of File
  459. //=============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement