daily pastebin goal
91%
SHARE
TWEET

LudoSubSkill

ludovicodes Dec 12th, 2017 (edited) 480 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //==
  2. //LudoSubWindow.js
  3. //==
  4.  
  5. //Manually change this for now
  6. $subTypes = {
  7.     "Magic" : ["Fire", "Water", "Earth", "Wind", "Support"],
  8.     "Special" : ["Axe", "Sword"],
  9. };
  10.  
  11. /*:
  12.  * @plugindesc Plugin that adds sub-options to the skills and magic battle commands to better separate larger amounts of options.
  13.  * @author Alessio De Santis
  14.  *
  15.  * @help Use metatags in the form of <subType:Fire> where Fire is a string of your choice, then in LudoSubWindow.js (this plugin), change the subTypes object to include all Skill Types and their associated sub-Types, also make sure all skills have a subtype and associate skill type or they will not appear.
  16.  *
  17.  */
  18.  
  19. //-----------------------------------------------------------------------------
  20. // Window_SubActorCommand
  21. //
  22. // The window for selecting an actor's subactions on the battle screen.
  23.  
  24. function Window_SubActorCommand() {
  25.     this.initialize.apply(this, arguments);
  26. }
  27.  
  28. Window_SubActorCommand.prototype = Object.create(Window_ActorCommand.prototype);
  29. Window_SubActorCommand.prototype.constructor = Window_SubActorCommand;
  30.  
  31. Window_SubActorCommand.prototype.initialize = function() {
  32.     var y = Graphics.boxHeight - this.windowHeight();
  33.     Window_Command.prototype.initialize.call(this, 192, y);
  34.     this._stypeId = 0;
  35.     this.openness = 0;
  36.     this.deactivate();
  37.     this._actor = null;
  38. };
  39.  
  40. Window_SubActorCommand.prototype.makeCommandList = function() {
  41.     if (this._actor) {
  42.         this.addElementsCommands();
  43.     }
  44. };
  45.  
  46. Window_SubActorCommand.prototype.setStypeId = function(stypeId) {
  47.     if (this._stypeId !== stypeId) {
  48.         this._stypeId = stypeId;
  49.         this.refresh();
  50.         this.resetScroll();
  51.     }
  52. };
  53.  
  54. Window_SubActorCommand.prototype.addElementsCommands = function() {
  55.     var subTypes =  $subTypes[$dataSystem.skillTypes[this._stypeId]];
  56.     if(subTypes){
  57.         subTypes.sort(function(a, b) {
  58.             return a - b;
  59.         });
  60.         subTypes.forEach(function(element) {
  61.             if(this.checkSubSkill(element)){
  62.             var name = element;
  63.             this.addCommand(name, 'subskill', true, element);
  64.             }
  65.         }, this);
  66.     }
  67. };
  68.  
  69. Window_SubActorCommand.prototype.checkSubSkill = function(element) {
  70.     for(i of this._actor._skills){
  71.         skill = $dataSkills[i].meta.subType;
  72.         if(skill == element){
  73.             return true;
  74.         }
  75.     }
  76.    
  77.     return false
  78. };
  79.  
  80. Window_SubActorCommand.prototype.setup = function(actor) {
  81.     this._actor = actor;
  82.     this.clearCommandList();
  83.     this.makeCommandList();
  84.     this.refresh();
  85.     this.selectLast();
  86.     this.activate();
  87.     this.open();
  88. };
  89.  
  90. Window_ActorCommand.prototype.addSkillCommands = function() {
  91.     var skillTypes = this._actor.addedSkillTypes();
  92.     skillTypes.sort(function(a, b) {
  93.         return a - b;
  94.     });
  95.     skillTypes.forEach(function(stypeId) {
  96.         if(this.checkSubSkill(stypeId)){
  97.         var name = $dataSystem.skillTypes[stypeId];
  98.         this.addCommand(name, 'skill', true, stypeId);
  99.         }
  100.     }, this);
  101. };
  102.  
  103. Window_ActorCommand.prototype.checkSubSkill = function(element) {
  104.     for(i of this._actor._skills){
  105.         skill = $dataSkills[i];
  106.         if(skill.stypeId == element && skill.meta.subType){
  107.             return true;
  108.         }
  109.        
  110.     }
  111.     return false
  112. }
  113. //-----------------------------------------------------------------------------
  114. // Window_SubBattleSkill
  115. //
  116. // The window for selecting a subskill to use on the battle screen.
  117.  
  118. function Window_SubBattleSkill() {
  119.     this.initialize.apply(this, arguments);
  120. }
  121.  
  122. Window_SubBattleSkill.prototype = Object.create(Window_BattleSkill.prototype);
  123. Window_SubBattleSkill.prototype.constructor = Window_SubBattleSkill;
  124.  
  125. Window_SubBattleSkill.prototype.initialize = function(x, y, width, height) {
  126.     Window_SkillList.prototype.initialize.call(this, x, y, width, height);
  127.     this._subType = "";
  128.     this.hide();
  129. };
  130.  
  131. Window_SubBattleSkill.prototype.setSubType = function(subtype) {
  132.     if (this._subType !== subtype) {
  133.         this._subType = subtype;
  134.         this.refresh();
  135.         this.resetScroll();
  136.     }
  137. };
  138.  
  139. Window_SubBattleSkill.prototype.includes = function(item) {
  140.     var subType = item.meta.subType;
  141.     return (item && item.stypeId === this._stypeId && subType && subType === this._subType);
  142. };
  143.  
  144. //-----------------------------------------------------------------------------
  145. // Scene_Battle Optimization to accomodate for the subTypes
  146. //
  147.  
  148. Scene_Battle.prototype.createAllWindows = function() {
  149.     this.createLogWindow();
  150.     this.createStatusWindow();
  151.     this.createPartyCommandWindow();
  152.     this.createActorCommandWindow();
  153.  
  154.     this.createSubActorCommandWindow();
  155.    
  156.     this.createHelpWindow();
  157.     this.createSkillWindow();
  158.    
  159.     this.createSubSkillWindow();
  160.  
  161.     this.createItemWindow();
  162.     this.createActorWindow();
  163.     this.createEnemyWindow();
  164.     this.createMessageWindow();
  165.     this.createScrollTextWindow();  
  166. };
  167.  
  168. Scene_Battle.prototype.createSubActorCommandWindow = function() {
  169.     this._subactorCommandWindow = new Window_SubActorCommand();
  170.     this._subactorCommandWindow.setHandler('subskill',  this.commandSubSkill.bind(this));
  171.     this._subactorCommandWindow.setHandler('cancel', this.onSubCancel.bind(this));
  172.     this.addWindow(this._subactorCommandWindow);
  173. };
  174.  
  175. Scene_Battle.prototype.createSubSkillWindow = function() {
  176.     var wy = this._helpWindow.y + this._helpWindow.height;
  177.     var wh = this._statusWindow.y - wy;
  178.     this._subskillWindow = new Window_SubBattleSkill(0, wy, Graphics.boxWidth, wh);
  179.     this._subskillWindow.setHelpWindow(this._helpWindow);
  180.     this._subskillWindow.setHandler('ok',     this.onSubSkillOk.bind(this));
  181.     this._subskillWindow.setHandler('cancel', this.onSubSkillCancel.bind(this));
  182.     this.addWindow(this._subskillWindow);
  183. };
  184.  
  185. Scene_Battle.prototype.commandSubSkill = function() {
  186.     this._subskillWindow.setActor(BattleManager.actor());
  187.     this._subskillWindow.setStypeId(this._actorCommandWindow.currentExt());
  188.     this._subskillWindow.setSubType(this._subactorCommandWindow.currentExt());
  189.     this._subskillWindow.refresh();
  190.     this._subskillWindow.show();
  191.     this._subskillWindow.activate();
  192. };
  193.  
  194. Scene_Battle.prototype.onSubSkillCancel = function() {
  195.     this._subskillWindow.hide();
  196.     this._subactorCommandWindow.activate();
  197. };
  198.  
  199. Scene_Battle.prototype.endCommandSelection = function() {
  200.     this._partyCommandWindow.close();
  201.     this._actorCommandWindow.close();
  202.     this._subactorCommandWindow.close();
  203.     this._statusWindow.deselect();
  204. };
  205.  
  206. Scene_Battle.prototype.onSubCancel = function() {
  207.     this._subactorCommandWindow.close();
  208.     this._skillWindow.deactivate();
  209.     this._actorCommandWindow.activate();
  210. };
  211.  
  212. Scene_Battle.prototype.onSubSkillOk = function() {
  213.     var skill = this._subskillWindow.item();
  214.     var action = BattleManager.inputtingAction();
  215.     action.setSkill(skill.id);
  216.     BattleManager.actor().setLastBattleSkill(skill);
  217.     this._skillWindow.deactivate();
  218.     this.onSelectAction();
  219. };
  220.  
  221. Scene_Battle.prototype.isAnyInputWindowActive = function() {
  222.     return (this._partyCommandWindow.active ||
  223.             this._actorCommandWindow.active ||
  224.             this._subactorCommandWindow.active ||
  225.             this._skillWindow.active ||
  226.             this._itemWindow.active ||
  227.             this._actorWindow.active ||
  228.             this._enemyWindow.active);
  229. };
  230.  
  231. Scene_Battle.prototype.startPartyCommandSelection = function() {
  232.     this.refreshStatus();
  233.     this._statusWindow.deselect();
  234.     this._statusWindow.open();
  235.     this._actorCommandWindow.close();
  236.     this._subactorCommandWindow.close();    
  237.     this._partyCommandWindow.setup();
  238. };
  239.  
  240. Scene_Battle.prototype.startActorCommandSelection = function() {
  241.     this._statusWindow.select(BattleManager.actor().index());
  242.     this._partyCommandWindow.close();
  243.     this._subactorCommandWindow.close();
  244.     this._actorCommandWindow.setup(BattleManager.actor());
  245. };
  246.  
  247. Scene_Battle.prototype.onSelectAction = function() {
  248.     var action = BattleManager.inputtingAction();
  249.     this._skillWindow.hide();
  250.     this._subskillWindow.hide();
  251.     this._itemWindow.hide();
  252.     if (!action.needsSelection()) {
  253.         this.selectNextCommand();
  254.     } else if (action.isForOpponent()) {
  255.         this.selectEnemySelection();
  256.     } else {
  257.         this.selectActorSelection();
  258.     }
  259. };
  260.  
  261. Scene_Battle.prototype.stop = function() {
  262.     Scene_Base.prototype.stop.call(this);
  263.     if (this.needsSlowFadeOut()) {
  264.         this.startFadeOut(this.slowFadeSpeed(), false);
  265.     } else {
  266.         this.startFadeOut(this.fadeSpeed(), false);
  267.     }
  268.     this._statusWindow.close();
  269.     this._partyCommandWindow.close();
  270.     this._actorCommandWindow.close();
  271.     this._subactorCommandWindow.close();
  272. };
  273.    
  274. Scene_Battle.prototype.endCommandSelection = function() {
  275.     this._partyCommandWindow.close();
  276.     this._actorCommandWindow.close();
  277.     this._subactorCommandWindow.close();
  278.     this._statusWindow.deselect();
  279. };
  280.  
  281. Scene_Battle.prototype.commandSkill = function() {
  282.     this._subactorCommandWindow.setStypeId(this._actorCommandWindow.currentExt());
  283.     this._subactorCommandWindow.setup(BattleManager.actor());
  284.     this._skillWindow.activate();    
  285. };
  286.  
  287. Scene_Battle.prototype.createSkillWindow = function() {
  288.     var wy = this._helpWindow.y + this._helpWindow.height;
  289.     var wh = this._statusWindow.y - wy;
  290.     this._skillWindow = new Window_BattleSkill(0, wy, Graphics.boxWidth, wh);
  291.     this._skillWindow.setHelpWindow(this._helpWindow);
  292.     // this.addWindow(this._skillWindow);
  293. };
  294.  
  295. Scene_Battle.prototype.onEnemyOk = function() {
  296.     var action = BattleManager.inputtingAction();
  297.     action.setTarget(this._enemyWindow.enemyIndex());
  298.     this._enemyWindow.hide();
  299.     this._skillWindow.hide();
  300.     this._subskillWindow.hide();
  301.     this._itemWindow.hide();
  302.     this.selectNextCommand();
  303. };
  304.  
  305. Scene_Battle.prototype.onEnemyCancel = function() {
  306.     this._enemyWindow.hide();
  307.    
  308.     switch (this._actorCommandWindow.currentSymbol()) {
  309.     case 'attack':
  310.         this._actorCommandWindow.activate();
  311.         break;
  312.     case 'skill':
  313.         this._skillWindow.activate();
  314.         this._subskillWindow.show();
  315.         this._subskillWindow.selectLast();
  316.         this._subskillWindow.activate();    
  317.         break;
  318.     case 'item':
  319.         this._itemWindow.show();
  320.         this._itemWindow.activate();
  321.         break;
  322.     }
  323. };
  324.  
  325. Scene_Battle.prototype.onActorCancel = function() {
  326.     this._actorWindow.hide();
  327.     console.log("Cancel!");
  328.     switch (this._actorCommandWindow.currentSymbol()) {
  329.     case 'skill':
  330.         this._skillWindow.activate();
  331.         this._subskillWindow.show();
  332.         this._subskillWindow.selectLast();
  333.         this._subskillWindow.activate();  
  334.         break;
  335.     case 'item':
  336.         this._itemWindow.show();
  337.         this._itemWindow.activate();
  338.         break;
  339.     }
  340. };
  341.  
  342. Scene_Battle.prototype.onActorOk = function() {
  343.     var action = BattleManager.inputtingAction();
  344.     action.setTarget(this._actorWindow.index());
  345.     this._actorWindow.hide();
  346.     this._skillWindow.hide();
  347.     this._subskillWindow.hide();
  348.     this._itemWindow.hide();
  349.     this.selectNextCommand();
  350. };
  351.  
  352. /*
  353. Scene_Battle.prototype.commandSkill = function() {
  354.     this._skillWindow.setActor(BattleManager.actor());
  355.     this._skillWindow.setStypeId(this._actorCommandWindow.currentExt());
  356.     this._skillWindow.refresh();
  357.     this._skillWindow.show();
  358.     this._skillWindow.activate();
  359. };
  360.  
  361. Scene_Battle.prototype.onSkillOk = function() {
  362.     var skill = this._skillWindow.item();
  363.     var action = BattleManager.inputtingAction();
  364.     action.setSkill(skill.id);
  365.     BattleManager.actor().setLastBattleSkill(skill);
  366.     this.onSelectAction();
  367. };
  368.  
  369. Scene_Battle.prototype.onSkillCancel = function() {
  370.     this._skillWindow.hide();
  371.     this._actorCommandWindow.activate();
  372. };
  373. */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand