document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //=============================================================================
  2. // WeaponProficiency.js
  3. //=============================================================================
  4.  
  5. /*:
  6.  * @plugindesc Allows per-Actor or per-Class weapon or armor bonuses or penalties.
  7.  * @author whitesphere
  8.  *
  9.  * @param Default Type
  10.  * @desc Specifies the type of item (weapon or armor) if none specified
  11.  * @default weapon
  12.  *
  13.  * @param Default Attribute
  14.  * @desc Specifies the attribute modified if none specified
  15.  * @default ATK
  16.  *
  17.  * @param Default Operation
  18.  * @desc How are multiple proficiencies stacked?  Set to MULT or ADD.
  19.  * @default MULT
  20.  *
  21.  * @help This modifies parameters such as ATK, MAT, DEF, MDF, AGI or LUK based on
  22.  * the weapon or armor equipped.  This allows you to have, say, an Archer who is
  23.  * more skilled with a Bow than a Knight.  Or to have, say, a Wrestler who can use
  24.  * a Club but poorly.
  25.  *
  26.  * If the notetag is set for an Actor and a Class, the values both apply.  Multiple
  27.  * percentage values will stack by multiplication (for MULT) or by addition (for ADD)
  28.  *
  29.  * ============================================================================
  30.  * Notetags
  31.  * ============================================================================
  32.  *
  33.  * This note-tag will work in Actor, Class or in a State:
  34.  *  <proficiency: type=(weapon or armor), operation=(mult or add), modify=(ATK, MAT, etc), id=percent, ...>
  35.  *  Example:
  36.  *  <proficiency: type=weapon, operation=mult, modify=atk, 1=150, 2=80, 3=110>
  37.  *  This example modifies WEAPON abilities.  In particular, it modifies the ATK skill
  38.  *  Weapon Type #1 does 150% normal, 2 does 80% normal and so on.
  39.  *
  40.  *  <proficiency: type=weapon, operation=add, modify=atk, 1=3, 2=-1, 3=7>
  41.  *  This example modifies WEAPON abilities.  In particular, it modifies the ATK skill
  42.  *  Weapon Type #1 has +3 to ATK, 2 does -1 to ATK and so on.
  43.  *
  44.  *  Valid types are: weapon, armor
  45.  *
  46.  *  Valid modify values are: ATK, MAT, DEF, MDF, AGI, LUK
  47.  */
  48. (function() {
  49.  
  50. WS_WeaponProficiency = {};
  51.  
  52. WS_WeaponProficiency.Parameters = PluginManager.parameters(\'WeaponProficiency\');
  53. WS_WeaponProficiency.Param = {};
  54.  
  55. //=============================================================================
  56. // The plug-in parameters
  57. //=============================================================================
  58. WS_WeaponProficiency.Param.defaultType = WS_WeaponProficiency.Parameters[\'Default Type\'].toLowerCase().trim();
  59. WS_WeaponProficiency.Param.defaultAttribute = WS_WeaponProficiency.Parameters[\'Default Attribute\'].toLowerCase().trim();
  60. WS_WeaponProficiency.Param.defaultOperation = WS_WeaponProficiency.Parameters[\'Default Operation\'].toLowerCase().trim();
  61.  
  62. //=============================================================================
  63. // Class which manages a single weapon skill entry
  64. // entry = the string from the meta-data:
  65. // type=weapon, modify=atk, operation=mult, 1=150, 2=80, 3=110
  66. //=============================================================================
  67. Weapon_skill = function(entry) {
  68.     valueSet=entry.split(",");
  69.    
  70.     // Set the defaults
  71.     this.type = WS_WeaponProficiency.Param.defaultType;
  72.     this.attribute = WS_WeaponProficiency.Param.defaultAttribute;
  73.     this.operation=WS_WeaponProficiency.Param.defaultOperation;
  74.    
  75.     for (weapon_index=0; weapon_index<valueSet.length; weapon_index++) {
  76.         current_entry=valueSet[weapon_index];
  77.         nv_pair=current_entry.split("=");
  78.         if (nv_pair.length != 2)
  79.             continue;
  80.         current_name=nv_pair[0];
  81.         current_value=nv_pair[1];
  82.         current_name=current_name.toLowerCase().trim();
  83.         current_value=current_value.toLowerCase().trim();
  84.         if (current_name == "type") {
  85.             if (current_value == "weapon" || current_value == "armor")
  86.                 this.type=current_value;
  87.             continue;
  88.         }
  89.         if (current_name == "modify") {
  90.             if (this.findParam(current_value) != -1)
  91.                 this.attribute=current_value;
  92.             continue;
  93.         }
  94.         if (current_name == "operation") {
  95.             if (current_value == "mult" || current_value == "add")
  96.                 this.operation=current_value;
  97.             continue;
  98.         }
  99.         current_name_int = parseInt(current_name);
  100.         current_value_as_number = parseInt(current_value);
  101.         if (this.operation == "mult")
  102.             current_value_as_number /= 100.0;
  103.         // Don\'t store NaN (which results if current_value isn\'t a number)
  104.         if (current_value_as_number !== current_value_as_number)
  105.             continue;
  106.         this[current_name_int]=current_value_as_number;
  107.        
  108.     }
  109.     this.param_id=this.findParam(this.attribute);
  110. }
  111.  
  112. //=============================================================================
  113. // Returns an int representing the parameter, -1 if not found
  114. //=============================================================================
  115. Weapon_skill.prototype.findParam = function(param_name) {
  116.     if (!Weapon_skill.prototype._attributes) {
  117.         /* The order comes from Game_BattlerBase, so the array offset is the .param() */
  118.         Weapon_skill.prototype._attributes=["mhp", "mmp", "atk", "def", "mat", "mdf", "agi", "luk"];
  119.     }
  120.     for (weap_search=0; weap_search<Weapon_skill.prototype._attributes.length; weap_search++) {
  121.         if (Weapon_skill.prototype._attributes[weap_search] == param_name) {
  122.             return weap_search;
  123.         }
  124.     }
  125.     return -1;
  126. }
  127.  
  128. //=============================================================================
  129. // Returns true if this skill would affect the passed in param_id, false if not
  130. //=============================================================================
  131. Weapon_skill.prototype.affectsParam = function(param_id) {
  132.     if (this.param_id == param_id)
  133.         return true;
  134.     return false;
  135. }
  136.  
  137. //=============================================================================
  138. // Returns a modifier if this skill would affect the passed in weapon, undefined if not
  139. //=============================================================================
  140. Weapon_skill.prototype.getWeaponModifier = function(weapon) {
  141.     if (this.type != "weapon")
  142.         return undefined;
  143.     return this[weapon.wtypeId];
  144. }
  145.  
  146. //=============================================================================
  147. // Returns a modifier if this skill would affect the passed in armor, undefined if not
  148. //=============================================================================
  149. Weapon_skill.prototype.getArmorModifier = function(armor) {
  150.     if (this.type != "armor")
  151.         return undefined;
  152.     return this[armor.etypeId];
  153. }
  154.  
  155. //=============================================================================
  156. // Game_Actor
  157. //=============================================================================
  158.  
  159.  
  160. //=============================================================================
  161. // Returns the modifier percent being used from 0.0 and up if active, or
  162. // undefined if this skill does not affect the passed-in item
  163. //=============================================================================
  164. Game_Actor.prototype.getItemModifier = function(skill_to_check, item) {
  165.     if (DataManager.isWeapon(item)) {
  166.         result=skill_to_check.getWeaponModifier(current);
  167.         return result;
  168.     }
  169.     if (DataManager.isArmor(item)) {
  170.         result=skill_to_check.getArmorModifier(current);
  171.         return result;
  172.     }
  173.     return undefined;
  174. }
  175.  
  176. //=============================================================================
  177. // Function that returns a modifier for the current parameter or 1.0 if there
  178. // are no modifiers (for multiplication) or 0 for addition
  179. //=============================================================================
  180. Game_Actor.prototype.getOverallSkillsModifier = function(param_id, operation) {
  181.     var ws_result=1.0;
  182.     var ws_active=[];
  183.     if (operation == "add")
  184.         ws_result=0;
  185.    
  186.     /* Check for the actor\'s skills modifier */
  187.     var actor_id=this.actorId();
  188.     var actors_meta=$dataActors[actor_id].meta;
  189.     var current_skill_mod=null;
  190.     if (actors_meta && actors_meta.proficiency) {
  191.         $gameTemp.actorWSCache = $gameTemp.actorWSCache || [];
  192.         if (!$gameTemp.actorWSCache[actor_id]) {
  193.             $gameTemp.actorWSCache[actor_id]=new Weapon_skill(actors_meta.proficiency);
  194.         }
  195.          current_skill_mod=$gameTemp.actorWSCache[actor_id];
  196.          if (current_skill_mod.operation == operation) {
  197.             if ($gameTemp.actorWSCache[actor_id].affectsParam(param_id)) {
  198.                 ws_active.push($gameTemp.actorWSCache[actor_id]);
  199.             }
  200.          }
  201.     }
  202.    
  203.     /* Check for the class skills modifier */
  204.     if (this._classId)
  205.     {
  206.         actors_meta=$dataClasses[this._classId].meta;
  207.         if (actors_meta && actors_meta.proficiency) {
  208.             $gameTemp.actorCCache = $gameTemp.actorCCache || [];
  209.             if (!$gameTemp.actorCCache[actor_id]) {
  210.                 $gameTemp.actorCCache[actor_id]=new Weapon_skill(actors_meta.proficiency);
  211.             }
  212.             current_skill_mod=$gameTemp.actorCCache[actor_id];
  213.             if (current_skill_mod.operation == operation) {
  214.                 if ($gameTemp.actorCCache[actor_id].affectsParam(param_id))
  215.                 {
  216.                     ws_active.push($gameTemp.actorCCache[this._classId]);
  217.                 }
  218.             }
  219.         }
  220.     }
  221.    
  222.     /* And check for the states modifiers */
  223.     var states=this.states();
  224.     for (mod=0; mod<states.length; mod++)
  225.     {
  226.         current=states[mod];
  227.         if (current === null)
  228.             continue;
  229.         if ($dataStates[current.id].meta.proficiency) {
  230.             $gameTemp.actorCCache = $gameTemp.stateCache || [];
  231.             if (!$gameTemp.stateCache[current.id]) {
  232.                 $gameTemp.stateCache[current.id]=new Weapon_skill($dataStates[current.id].meta.proficiency);
  233.             }
  234.             current_skill_mod=$gameTemp.stateCache[actor_id];
  235.             if (current_skill_mod.operation == operation) {
  236.                 if ($gameTemp.stateCache[current.id].affectsParam(param_id))
  237.                 {
  238.                     ws_active.push($gameTemp.stateCache[current.id]);
  239.                 }
  240.             }
  241.         }
  242.     }
  243.    
  244.     /* Now, get the weapon and equipment modifiers which are relevant */
  245.     for (var mod=0; mod<ws_active.length; mod++) {
  246.         var current_skill_mod=ws_active[mod];
  247.        
  248.         /* Check the weapons */
  249.         weapons=this.weapons();
  250.         for (index=0; index<weapons.length; index++) {
  251.             current_weapon=weapons[index];
  252.             new_modifier=this.getItemModifier(current_skill_mod, current_weapon);
  253.             if (new_modifier !== undefined) {
  254.                 if (operation == "add") {
  255.                     ws_result += new_modifier;
  256.                 }
  257.                 else
  258.                 {
  259.                     ws_result *= new_modifier;
  260.                 }
  261.             }
  262.         }
  263.        
  264.         /* And check the equipment */
  265.         items=this.equips();
  266.         for (mod=0; mod<items.length; mod++)
  267.         {
  268.             current_equip=items[mod];
  269.             if (current_equip === null || DataManager.isWeapon(current_equip))
  270.                 continue;
  271.             meta={};
  272.             if (DataManager.isArmor(current_equip))
  273.             {
  274.                 new_modifier=this.getItemModifier(current_skill_mod, current_equip);
  275.                 if (new_modifier !== undefined) {
  276.                     if (operation == "add") {
  277.                         ws_result += new_modifier;
  278.                     }
  279.                     else
  280.                     {
  281.                         ws_result *= new_modifier;
  282.                     }
  283.                 }
  284.             }
  285.         }
  286.     }
  287.     return ws_result;
  288. }
  289.  
  290. var WS_WP_Game_Actor_paramPlus=Game_Actor.prototype.paramPlus;
  291.  
  292. //=============================================================================
  293. // Enhance or penalize any relevant stats here
  294. //=============================================================================
  295. Game_Actor.prototype.paramPlus = function(paramId) {
  296.     var param_result=WS_WP_Game_Actor_paramPlus.call(this,paramId);
  297.     var ws_mult_result=this.getOverallSkillsModifier(paramId, "mult");
  298.     var ws_add_result=this.getOverallSkillsModifier(paramId, "add");
  299.     if (ws_mult_result == 1.0 && ws_add_result == 0)
  300.         return param_result;
  301.     return (param_result + ws_add_result) * ws_mult_result;
  302. }
  303.  
  304.  
  305. })();
  306. //=============================================================================
  307. // End of File
  308. //=============================================================================
');