Advertisement
jerry2810

WeaponClassChange

Oct 9th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // WeaponClassChange.js
  3. //=============================================================================
  4.  
  5. /*:
  6.  * @plugindesc Changes class when actor equips a different weapon type.
  7.  * @author Jeremy Cannady
  8.  *
  9.  * @param Weapon Types
  10.  * @desc List the weapon types.
  11.  * @default 1,2,3,4,5,6,7,8,9,10
  12.  *
  13.  * @param Classes
  14.  * @desc List the classes.
  15.  * @default 1,2,3,4,5,6,7,8,9,10
  16.  *
  17.  * @param Unequipped Class
  18.  * @desc The is the class you want to be when you dont have a weapon equipped.
  19.  * @default 1
  20.  
  21.  * Example one:
  22.  * Weapon Type :1,2,3,4,5,6,7,8,9,10
  23.  *              | | | | | | | | | |
  24.  * Class:       1,2,3,4,5,6,7,8,9,10
  25.  * When you equip weapon type one your class changes to class #1 in your database.
  26.  *  When you equip weapon type 5 your class changes to class #5 in your database.
  27.  *
  28.  * Example two:
  29.  * Weapon Type: 1,2,3,4,5,6,7,8,9,10
  30.  *              | | | | | | | | | |
  31.  * Class:       1,2,8,4,5,6,7,8,9,10
  32.  *  When you equip weapon type three or eight your class changes to class #8 in your database.
  33.  *
  34.  * @help The parameter order determines the class change.
  35.     Classes 1,2,3,4,5,6,7,8,9,10
  36.  *For example when you equip weapon type 1 then your class changes to class 1.
  37.     Classes 2,2,3,4,5,6,7,8,9,10
  38.  *In this example when you equip weapon type 1 then your class changes to class 2.
  39.  *Please see script text for a simple graphic.
  40.  *
  41.  *
  42.  *
  43. */
  44.  
  45. var COLD = COLD || {};
  46. COLD.WeaponClassChange = {
  47.     Game_Actor_Setup : Game_Actor.prototype.setup,
  48.     Game_Actor_changeEquip : Game_Actor.prototype.changeEquip,
  49.     Parameters : PluginManager.parameters('WeaponClassChange'),
  50. };
  51.  
  52. COLD.WeaponClassChange.weaponType = COLD.WeaponClassChange.Parameters['Weapon Types'].split(',');
  53. COLD.WeaponClassChange.classes = COLD.WeaponClassChange.Parameters['Classes'].split(',');;
  54. COLD.WeaponClassChange.defaultClass = Number(COLD.WeaponClassChange.Parameters['Unequipped Class']);
  55.  
  56. //Convert the parameters into number array
  57. for(var i = 0; i < COLD.WeaponClassChange.weaponType.length; i++) { COLD.WeaponClassChange.weaponType[i] = parseInt(COLD.WeaponClassChange.weaponType[i], 10); }
  58. for(var i = 0; i < COLD.WeaponClassChange.classes.length; i++) { COLD.WeaponClassChange.classes[i] = parseInt(COLD.WeaponClassChange.classes[i], 10); }
  59.  
  60.  
  61. (function() {
  62.  
  63.     Game_Actor.prototype.setup = function(actorId) {
  64.         COLD.WeaponClassChange.Game_Actor_Setup.call(this,actorId);
  65.         this._classExp = [];
  66.         var length = $dataClasses.length
  67.         for(var i = 0; i<length; i++){
  68.             //Sets the default value for each class starting exp to 0
  69.             this._classExp.push(0);
  70.         };
  71.     };
  72.  
  73.     //This function compares which weapon type you have equipped and gives you the class that corresponds to it.
  74.     Game_Actor.prototype.getNewClassId = function(){
  75.         var wtypeId = this.weapons()[0] ? this.weapons()[0].wtypeId : 0;
  76.         //Takes the position of the weapon parameter and makes newClassId equal to the the parameter that is in the same position as the weapon type.
  77.         var newClassId = COLD.WeaponClassChange.classes[COLD.WeaponClassChange.weaponType.indexOf(wtypeId)];
  78.         //If the actor has unequipped a weapon then make the newClassId into the 'Unequipped Class' in the parameters.
  79.         if($gameActors.actor(this.actor().id).hasNoWeapons()){
  80.             newClassId = COLD.WeaponClassChange.defaultClass;
  81.         };
  82.         //When we call this function then return what our class should be based upon which wepaon we have equipped
  83.         return newClassId;
  84.     };
  85.  
  86.     //Overide Game_Actor.prototype.changeEquip
  87.     Game_Actor.prototype.changeEquip = function(slotId, item) {
  88.         //When we change our equipment then do what we used to do in the origial Game_Actor.prototype.changeEquip
  89.         COLD.WeaponClassChange.Game_Actor_changeEquip.call(this,slotId,item);
  90.  
  91.         //but also do this
  92.         COLD.WeaponClassChange.changeToNewClass(this.actor().id);
  93.     };
  94.  
  95.     COLD.WeaponClassChange.changeToNewClass = function(currentActor){
  96.         //When we call the function changeToNewClass then do these things.
  97.         //Current Actor ID
  98.          
  99.         var actor = $gameActors.actor(currentActor);
  100.          
  101.         //Current Class Id
  102.         var currentClassId = actor.currentClass().id;
  103.         var newClassId = actor.getNewClassId();
  104.          
  105.         //Current Exp
  106.         var currentExp = actor.currentExp();
  107.          
  108.         //Put the curent exp back in to the array
  109.         actor._classExp[currentClassId] = currentExp;
  110.          
  111.         //Change the class
  112.         actor.changeClass(newClassId, false);
  113.          
  114.         //Change the exp to the correct value
  115.         var newExp = actor._classExp[newClassId];
  116.         actor.changeExp(newExp,false)
  117.          
  118.         //Forget old skills
  119.         actor._skills.forEach(function(forget){
  120.             var index = actor._skills.indexOf(forget);
  121.             if (index >= 0) {
  122.                 actor._skills.splice(index, 1);
  123.             };
  124.         }, actor);
  125.          
  126.         //Learn new skills
  127.         actor.currentClass().learnings.forEach(function(learning) {
  128.               if (learning.level <= actor._level) {
  129.                   actor.learnSkill(learning.skillId);
  130.               }
  131.         }, actor);
  132.        
  133.     };
  134.  
  135. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement