Advertisement
Guest User

Class Changing plugin for RPGMaker MV

a guest
Oct 26th, 2015
1,286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. (function() {
  3.  
  4.     var _Window_MenuCommand_makeCommandList = Window_MenuCommand.prototype.makeCommandList;
  5.     Window_MenuCommand.prototype.makeCommandList = function() {
  6.         _Window_MenuCommand_makeCommandList.call(this);
  7.     };
  8.    
  9.     var _Scene_Menu_createCommandWindow = Scene_Menu.prototype.createCommandWindow;
  10.     Scene_Menu.prototype.createCommandWindow = function() {
  11.         _Scene_Menu_createCommandWindow.call(this);
  12.         this._commandWindow.setHandler('job',     this.commandPersonal.bind(this));
  13.     }
  14.    
  15.     Game_Actor.prototype.changeClass = function(classId, keepExp) {
  16.         if (keepExp) {
  17.             this._exp[classId] = this.currentExp();
  18.         }
  19.         this._classId = classId;
  20.         this.changeExp(this._exp[this._classId] || 0, false);
  21.         this.refresh();
  22.     };
  23.  
  24.    
  25.     Window_MenuCommand.prototype.addMainCommands = function() {
  26.         var enabled = this.areMainCommandsEnabled();
  27.         if (this.needsCommand('item')) {
  28.             this.addCommand(TextManager.item, 'item', enabled);
  29.         }
  30.         if (this.needsCommand('skill')) {
  31.             this.addCommand(TextManager.skill, 'skill', enabled);
  32.         }
  33.         this.addCommand('Job','job', enabled);
  34.         if (this.needsCommand('equip')) {
  35.             this.addCommand(TextManager.equip, 'equip', enabled);
  36.         }
  37.         if (this.needsCommand('status')) {
  38.             this.addCommand(TextManager.status, 'status', enabled);
  39.         }
  40.     };
  41.    
  42.     Scene_Menu.prototype.onPersonalOk = function() {
  43.         switch (this._commandWindow.currentSymbol()) {
  44.         case 'skill':
  45.             SceneManager.push(Scene_Skill);
  46.             break;
  47.         case 'equip':
  48.             SceneManager.push(Scene_Equip);
  49.             break;
  50.         case 'job':
  51.             SceneManager.push(Scene_Job);
  52.             break;
  53.         case 'status':
  54.             SceneManager.push(Scene_Status);
  55.             break;
  56.         }
  57.     };
  58.  
  59.     //-----------------------------------------------------------------------------
  60.     // Scene_Job
  61.     //
  62.     // The scene class of the Job screen.
  63.    
  64.     function Scene_Job() {
  65.         this.initialize.apply(this, arguments);
  66.     }
  67.    
  68.     Scene_Job.prototype = Object.create(Scene_ItemBase.prototype);
  69.     Scene_Job.prototype.constructor = Scene_Job;
  70.    
  71.     Scene_Job.prototype.initialize = function() {
  72.         Scene_ItemBase.prototype.initialize.call(this);
  73.     };
  74.    
  75.     Scene_Job.prototype.create = function() {
  76.         Scene_ItemBase.prototype.create.call(this);
  77.         this.createHelpWindow();
  78.         this.createJobTypeWindow();
  79.         this.createStatusWindow();
  80.         this.createJobWindow();
  81.         this.createActorWindow();
  82.         this.refreshActor();
  83.     };
  84.    
  85.     Scene_Job.prototype.createJobTypeWindow = function() {
  86.         var wy = this._helpWindow.height;
  87.         this._jobTypeWindow = new Window_JobType(0, wy);
  88.         this._jobTypeWindow.setHelpWindow(this._helpWindow);
  89.         this._jobTypeWindow.setHandler('job',    this.commandJob.bind(this));
  90.         this._jobTypeWindow.setHandler('cancel',   this.popScene.bind(this));
  91.         this._jobTypeWindow.setHandler('pagedown', this.nextActor.bind(this));
  92.         this._jobTypeWindow.setHandler('pageup',   this.previousActor.bind(this));
  93.         this.addWindow(this._jobTypeWindow);
  94.     };
  95.    
  96.     Scene_Job.prototype.createStatusWindow = function() {
  97.         var wx = this._jobTypeWindow.width;
  98.         var wy = this._helpWindow.height;
  99.         var ww = Graphics.boxWidth - wx;
  100.         var wh = this._jobTypeWindow.height;
  101.         this._statusWindow = new Window_SkillStatus(wx, wy, ww, wh);
  102.         this.addWindow(this._statusWindow);
  103.     };
  104.    
  105.     Scene_Job.prototype.createJobWindow = function() {
  106.         var wx = 0;
  107.         var wy = this._statusWindow.y + this._statusWindow.height;
  108.         var ww = Graphics.boxWidth;
  109.         var wh = Graphics.boxHeight - wy;
  110.         this._jobWindow = new Window_JobList(wx, wy, ww, wh);
  111.         this._jobWindow.setHelpWindow(this._helpWindow);
  112.         this._jobWindow.setHandler('ok',     this.onJobOk.bind(this));
  113.         this._jobWindow.setHandler('cancel', this.onJobCancel.bind(this));
  114.         this._jobTypeWindow.setJobWindow(this._jobWindow);
  115.         this.addWindow(this._jobWindow);
  116.     };
  117.    
  118.     Scene_Job.prototype.refreshActor = function() {
  119.         var actor = this.actor();
  120.         this._jobTypeWindow.setActor(actor);
  121.         this._statusWindow.setActor(actor);
  122.         this._jobWindow.setActor(actor);
  123.         this._jobTypeWindow.refresh();
  124.         this._statusWindow.refresh();
  125.         this._jobWindow.refresh();
  126.     };
  127.    
  128.     Scene_Job.prototype.user = function() {
  129.         return this.actor();
  130.     };
  131.    
  132.     Scene_Job.prototype.commandJob = function() {
  133.         this._jobWindow.activate();
  134.         this._jobWindow.selectLast();
  135.     };
  136.    
  137.     Scene_Job.prototype.onJobOk = function() {
  138.         //this.actor().setLastMenuSkill(this.item());
  139.         //this.determineItem();
  140.         var item = this.item();
  141.         var actor = this.actor();
  142.         actor.changeClass(item.id, true);
  143.         this.refreshActor();
  144.         this._jobWindow.deselect();
  145.         this._jobTypeWindow.activate();
  146.     };
  147.    
  148.     Scene_Job.prototype.item = function() {
  149.         return this._jobWindow.item();
  150.     };
  151.    
  152.     Scene_Job.prototype.onJobCancel = function() {
  153.         this._jobWindow.deselect();
  154.         this._jobTypeWindow.activate();
  155.     };
  156.    
  157.     Scene_Job.prototype.playSeForItem = function() {
  158.         SoundManager.playUseSkill();
  159.     };
  160.    
  161.     Scene_Job.prototype.useItem = function() {
  162.         Scene_ItemBase.prototype.useItem.call(this);
  163.         this._statusWindow.refresh();
  164.         this._jobWindow.refresh();
  165.     };
  166.    
  167.     Scene_Job.prototype.onActorChange = function() {
  168.         this.refreshActor();
  169.         this._jobTypeWindow.activate();
  170.     };
  171.  
  172. //-----------------------------------------------------------------------------
  173. // Window_JobType
  174. //
  175. //
  176.  
  177. function Window_JobType() {
  178.     this.initialize.apply(this, arguments);
  179. }
  180.  
  181. Window_JobType.prototype = Object.create(Window_Command.prototype);
  182. Window_JobType.prototype.constructor = Window_JobType;
  183.  
  184. Window_JobType.prototype.initialize = function(x, y) {
  185.     Window_Command.prototype.initialize.call(this, x, y);
  186.     this._actor = null;
  187. };
  188.  
  189. Window_JobType.prototype.windowWidth = function() {
  190.     return 240;
  191. };
  192.  
  193. Window_JobType.prototype.setActor = function(actor) {
  194.     if (this._actor !== actor) {
  195.         this._actor = actor;
  196.         this.refresh();
  197.         this.selectLast();
  198.     }
  199. };
  200.  
  201. Window_JobType.prototype.numVisibleRows = function() {
  202.     return 4;
  203. };
  204.  
  205. Window_JobType.prototype.makeCommandList = function() {
  206.     this.addCommand("Job", 'job', true );
  207. };
  208.  
  209. Window_JobType.prototype.update = function() {
  210.     Window_Command.prototype.update.call(this);
  211.     if (this._skillWindow) {
  212.         this._skillWindow.setStypeId(this.currentExt());
  213.     }
  214. };
  215.  
  216. Window_JobType.prototype.setJobWindow = function(jobWindow) {
  217.     this._jobWindow = jobWindow;
  218.     this.update();
  219. };
  220.  
  221. Window_JobType.prototype.selectLast = function() {
  222.     this.select(0);
  223. };
  224.  
  225. // **********************
  226. // **********************
  227.  
  228.     //-----------------------------------------------------------------------------
  229.     // Window_JobList
  230.     //
  231.     // The window for selecting a job on the job screen.
  232.    
  233.     function Window_JobList() {
  234.         this.initialize.apply(this, arguments);
  235.     }
  236.    
  237.     Window_JobList.prototype = Object.create(Window_Selectable.prototype);
  238.     Window_JobList.prototype.constructor = Window_JobList;
  239.    
  240.     Window_JobList.prototype.initialize = function(x, y, width, height) {
  241.         Window_Selectable.prototype.initialize.call(this, x, y, width, height);
  242.         this._actor = null;
  243.         this._stypeId = 0;
  244.         this._data = [];
  245.     };
  246.    
  247.  
  248.    
  249.     Window_JobList.prototype.setActor = function(actor) {
  250.         if (this._actor !== actor) {
  251.             this._actor = actor;
  252.             this.refresh();
  253.             this.resetScroll();
  254.         }
  255.     };
  256.    
  257.     Window_JobList.prototype.setStypeId = function(stypeId) {
  258.         if (this._stypeId !== stypeId) {
  259.             this._stypeId = stypeId;
  260.             this.refresh();
  261.             this.resetScroll();
  262.         }
  263.     };
  264.    
  265.     Window_JobList.prototype.maxCols = function() {
  266.         return 2;
  267.     };
  268.    
  269.     Window_JobList.prototype.spacing = function() {
  270.         return 48;
  271.     };
  272.    
  273.     Window_JobList.prototype.maxItems = function() {
  274.         return this._data ? this._data.length : 1;
  275.     };
  276.    
  277.     Window_JobList.prototype.item = function() {
  278.         return this._data && this.index() >= 0 ? this._data[this.index()] : null;
  279.     };
  280.    
  281.     Window_JobList.prototype.isCurrentItemEnabled = function() {
  282.         return this.isEnabled(this._data[this.index()]);
  283.     };
  284.    
  285.     Window_JobList.prototype.includes = function(item) {
  286.         return item && item.stypeId === this._stypeId;
  287.     };
  288.    
  289.     Window_JobList.prototype.isEnabled = function(item) {
  290.         return  this._actor.currentClass() != item;
  291.     };
  292.    
  293.     Window_JobList.prototype.makeJobList = function() {
  294.         if (this._actor) {
  295.             this._data = $dataClasses.filter(function(item) {
  296.                   if (item != null) {
  297.                       return item.name;
  298.                   }
  299.             });
  300.         } else {
  301.             this._data = [];
  302.         }
  303.     };
  304.    
  305.     Window_JobList.prototype.selectLast = function() {
  306.         var skill;
  307.         if ($gameParty.inBattle()) {
  308.             skill = this._actor.lastBattleSkill();
  309.         } else {
  310.             skill = this._actor.lastMenuSkill();
  311.         }
  312.         var index = this._data.indexOf(skill);
  313.         this.select(index >= 0 ? index : 0);
  314.     };
  315.    
  316.     Window_JobList.prototype.drawItem = function(index) {
  317.         var job = this._data[index];
  318.         if (job) {
  319.             var costWidth = this.costWidth();
  320.             var rect = this.itemRect(index);
  321.             rect.width -= this.textPadding();
  322.             this.changePaintOpacity(this.isEnabled(job));
  323.             this.drawItemName(job, rect.x, rect.y, rect.width - costWidth);
  324.             this.drawSkillCost(job, rect.x, rect.y, rect.width);
  325.             this.changePaintOpacity(1);
  326.         }
  327.     };
  328.    
  329.     Window_JobList.prototype.costWidth = function() {
  330.         return this.textWidth('000');
  331.     };
  332.    
  333.     Window_JobList.prototype.drawSkillCost = function(skill, x, y, width) {
  334.         if (this._actor.skillTpCost(skill) > 0) {
  335.             this.changeTextColor(this.tpCostColor());
  336.             this.drawText(this._actor.skillTpCost(skill), x, y, width, 'right');
  337.         } else if (this._actor.skillMpCost(skill) > 0) {
  338.             this.changeTextColor(this.mpCostColor());
  339.             this.drawText(this._actor.skillMpCost(skill), x, y, width, 'right');
  340.         }
  341.     };
  342.    
  343.     Window_JobList.prototype.updateHelp = function() {
  344.         this.setHelpWindowItem(this.item());
  345.     };
  346.    
  347.     Window_JobList.prototype.refresh = function() {
  348.         this.makeJobList();
  349.         this.createContents();
  350.         this.drawAllItems();
  351.     };
  352.  
  353.    
  354.  
  355. // **********************
  356. // **********************
  357.  
  358. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement