Advertisement
jerry2810

WeaponClassChange

Nov 1st, 2015
309
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 4.93 KB | None
  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. (function() {
  45. //Retrieve the parameters
  46. var parameters = PluginManager.parameters('WeaponClassChange');
  47. var weaponType = parameters['Weapon Types'];
  48.   var classes = parameters['Classes'];
  49. var defaultClass = Number(parameters['Unequipped Class']);
  50.  
  51. //Store the parameters into an string array and get rid of the commas
  52. var weaponTypeArray = weaponType.split(',');
  53. var classesArray = classes.split(',');
  54.  
  55. //Convert the parameters into number array
  56. for(var i=0; i<weaponTypeArray.length; i++) { weaponTypeArray[i] = parseInt(weaponTypeArray[i], 10); }
  57. for(var i=0; i<classesArray.length; i++) { classesArray[i] = parseInt(classesArray[i], 10); }
  58.  
  59. //Lets make a copy of Game_Actor.prototype.setup so we can add to it
  60.  
  61. var Game_Actor_setup = Game_Actor.prototype.setup;
  62.  
  63. Game_Actor.prototype.setup = function(actorId) {
  64. 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 = classesArray[weaponTypeArray.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 = 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. //Make a copy of changeEquip so we can edit it
  87. var copyOfChangeEquip = Game_Actor.prototype.changeEquip;
  88.  
  89. //Overide Game_Actor.prototype.changeEquip
  90. Game_Actor.prototype.changeEquip = function(slotId, item) {
  91. //When we change our equipment then do what we used to do in the origial Game_Actor.prototype.changeEquip
  92. copyOfChangeEquip.call(this,slotId,item);
  93.  
  94. //but also do this
  95. this.changeToNewClass(this.actor().id);
  96. };
  97.  
  98. Game_Actor.prototype.changeToNewClass = function(currentActor){
  99. //When we call the function changeToNewClass then do these things.
  100. //Current Actor ID
  101.  
  102. var actor = $gameActors.actor(currentActor);
  103.  
  104. //Current Class Id
  105. var currentClassId = actor.currentClass().id;
  106. var newClassId = actor.getNewClassId();
  107.  
  108. //Current Exp
  109. var currentExp = actor.currentExp();
  110.  
  111. //Put the curent exp back in to the array
  112. actor._classExp[currentClassId] = currentExp;
  113.  
  114. //Change the class
  115. actor.changeClass(newClassId, false);
  116.  
  117. //Change the exp to the correct value
  118. var newExp = actor._classExp[newClassId];
  119. actor.changeExp(newExp,false)
  120.  
  121. //Forget old skills
  122. actor._skills.forEach(function(skill){
  123.         var index = actor._skills.indexOf(skill);
  124.         if (index >= 0) {
  125.             actor._skills.splice(index, 1);
  126. };
  127. }, actor);
  128.  
  129. //Learn new skills
  130. actor.currentClass().learnings.forEach(function(learning) {
  131.           if (learning.level <= actor._level) {
  132.               actor.learnSkill(learning.skillId);
  133.           }
  134.       }, actor);
  135. };
  136. })();
  137. /*:Credits
  138. ArcherBanish ---> http://forums.rpgmakerweb.com/index.php?/topic/47747-custom-class-change-v100/?hl=classchange
  139. //I used his code for forgetting and learning new skills
  140.  
  141. Yoji Ojima
  142. //I used the plugin TitleCommand Position to learn how to operate the parameters
  143. */
Advertisement
RAW Paste Data Copied
Advertisement