daily pastebin goal
55%
SHARE
TWEET

SubSkills

ludovicodes Dec 12th, 2017 (edited) 321 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. //TODO
  20. //
  21. //Scene_Battle.prototype.onActorOk
  22. //Scene_Battle.prototype.stop
  23.  
  24. //-----------------------------------------------------------------------------
  25. // Window_SubActorCommand
  26. //
  27. // The window for selecting an actor's subactions on the battle screen.
  28.  
  29. function Window_SubActorCommand() {
  30.     this.initialize.apply(this, arguments);
  31. }
  32.  
  33. Window_SubActorCommand.prototype = Object.create(Window_ActorCommand.prototype);
  34. Window_SubActorCommand.prototype.constructor = Window_SubActorCommand;
  35.  
  36. Window_SubActorCommand.prototype.initialize = function() {
  37.     var y = Graphics.boxHeight - this.windowHeight();
  38.     Window_Command.prototype.initialize.call(this, 192, y);
  39.     this._stypeId = 0;
  40.     this.openness = 0;
  41.     this.deactivate();
  42.     this._actor = null;
  43. };
  44.  
  45. Window_SubActorCommand.prototype.makeCommandList = function() {
  46.     if (this._actor) {
  47.         this.addElementsCommands();
  48.     }
  49. };
  50.  
  51.  
  52. Window_SubActorCommand.prototype.setStypeId = function(stypeId) {
  53.     if (this._stypeId !== stypeId) {
  54.         this._stypeId = stypeId;
  55.         this.refresh();
  56.         this.resetScroll();
  57.     }
  58. };
  59.  
  60. Window_SubActorCommand.prototype.addElementsCommands = function() {
  61.     var subTypes =  $subTypes[$dataSystem.skillTypes[this._stypeId]];
  62.     if(subTypes){
  63.         subTypes.sort(function(a, b) {
  64.             return a - b;
  65.         });
  66.         subTypes.forEach(function(element) {
  67.             if(this.checkSubSkill(element)){
  68.             var name = element;
  69.             this.addCommand(name, 'subskill', true, element);
  70.             }
  71.         }, this);
  72.     }
  73. };
  74.  
  75. Window_SubActorCommand.prototype.checkSubSkill = function(element) {
  76.     for(i of this._actor._skills){
  77.         skill = $dataSkills[i].meta.subType;
  78.         if(skill == element){
  79.             return true;
  80.         }
  81.     }
  82.    
  83.     return false
  84. }
  85.  
  86. Window_SubActorCommand.prototype.setup = function(actor) {
  87.     this._actor = actor;
  88.     this.clearCommandList();
  89.     this.makeCommandList();
  90.     this.refresh();
  91.     this.selectLast();
  92.     this.activate();
  93.     this.open();
  94. };
  95.  
  96. Window_ActorCommand.prototype.addSkillCommands = function() {
  97.     var skillTypes = this._actor.addedSkillTypes();
  98.     skillTypes.sort(function(a, b) {
  99.         return a - b;
  100.     });
  101.     skillTypes.forEach(function(stypeId) {
  102.         if(this.checkSubSkill(stypeId)){
  103.         var name = $dataSystem.skillTypes[stypeId];
  104.         this.addCommand(name, 'skill', true, stypeId);
  105.         }
  106.     }, this);
  107. };
  108.  
  109. Window_ActorCommand.prototype.checkSubSkill = function(element) {
  110.     for(i of this._actor._skills){
  111.         skill = $dataSkills[i];
  112.         if(skill.stypeId == element && skill.meta.subType){
  113.             return true;
  114.         }
  115.        
  116.     }
  117.     return false
  118. }
  119. //-----------------------------------------------------------------------------
  120. // Window_SubBattleSkill
  121. //
  122. // The window for selecting a subskill to use on the battle screen.
  123.  
  124. function Window_SubBattleSkill() {
  125.     this.initialize.apply(this, arguments);
  126. }
  127.  
  128. Window_SubBattleSkill.prototype = Object.create(Window_BattleSkill.prototype);
  129. Window_SubBattleSkill.prototype.constructor = Window_SubBattleSkill;
  130.  
  131. Window_SubBattleSkill.prototype.initialize = function(x, y, width, height) {
  132.     Window_SkillList.prototype.initialize.call(this, x, y, width, height);
  133.     this._subType = "";
  134.     this.hide();
  135. };
  136.  
  137. Window_SubBattleSkill.prototype.setSubType = function(subtype) {
  138.     if (this._subType !== subtype) {
  139.         this._subType = subtype;
  140.         this.refresh();
  141.         this.resetScroll();
  142.     }
  143. };
  144.  
  145. Window_SubBattleSkill.prototype.includes = function(item) {
  146.     var subType = item.meta.subType;
  147.     return (item && item.stypeId === this._stypeId && subType && subType === this._subType);
  148. };
  149.  
  150. //-----------------------------------------------------------------------------
  151. // Scene_Battle Optimization to accomodate for the subTypes
  152. //
  153. //
  154.  
  155.     Scene_Battle.prototype.createAllWindows = function() {
  156.         this.createLogWindow();
  157.         this.createStatusWindow();
  158.         this.createPartyCommandWindow();
  159.         this.createActorCommandWindow();
  160.  
  161.         this.createSubActorCommandWindow();
  162.        
  163.         this.createHelpWindow();
  164.         this.createSkillWindow();
  165.        
  166.         this.createSubSkillWindow();
  167.    
  168.         this.createItemWindow();
  169.         this.createActorWindow();
  170.         this.createEnemyWindow();
  171.         this.createMessageWindow();
  172.         this.createScrollTextWindow();  
  173.     };
  174.    
  175.  
  176.     Scene_Battle.prototype.createSubActorCommandWindow = function() {
  177.         this._subactorCommandWindow = new Window_SubActorCommand();
  178.         this._subactorCommandWindow.setHandler('subskill',  this.commandSubSkill.bind(this));
  179.         this._subactorCommandWindow.setHandler('cancel', this.onSubCancel.bind(this));
  180.         this.addWindow(this._subactorCommandWindow);
  181.     }
  182.    
  183.     Scene_Battle.prototype.createSubSkillWindow = function() {
  184.         var wy = this._helpWindow.y + this._helpWindow.height;
  185.         var wh = this._statusWindow.y - wy;
  186.         this._subskillWindow = new Window_SubBattleSkill(0, wy, Graphics.boxWidth, wh);
  187.         this._subskillWindow.setHelpWindow(this._helpWindow);
  188.         this._subskillWindow.setHandler('ok',     this.onSubSkillOk.bind(this));
  189.         this._subskillWindow.setHandler('cancel', this.onSubSkillCancel.bind(this));
  190.         this.addWindow(this._subskillWindow);
  191.     };
  192.    
  193.     Scene_Battle.prototype.commandSubSkill = function() {
  194.         this._subskillWindow.setActor(BattleManager.actor());
  195.         this._subskillWindow.setStypeId(this._actorCommandWindow.currentExt());
  196.         this._subskillWindow.setSubType(this._subactorCommandWindow.currentExt());
  197.         this._subskillWindow.refresh();
  198.         this._subskillWindow.show();
  199.         this._subskillWindow.activate();
  200.     };
  201.    
  202.     Scene_Battle.prototype.onSubSkillCancel = function() {
  203.         this._subskillWindow.hide();
  204.         this._subactorCommandWindow.activate();
  205.     };
  206.  
  207.     Scene_Battle.prototype.endCommandSelection = function() {
  208.         this._partyCommandWindow.close();
  209.         this._actorCommandWindow.close();
  210.         this._subactorCommandWindow.close();
  211.         this._statusWindow.deselect();
  212.     };
  213.    
  214.     Scene_Battle.prototype.onSubCancel = function() {
  215.         this._subactorCommandWindow.close();
  216.         this._skillWindow.deactivate();
  217.         this._actorCommandWindow.activate();
  218.     };
  219.    
  220.     Scene_Battle.prototype.onSubSkillOk = function() {
  221.         var skill = this._subskillWindow.item();
  222.         var action = BattleManager.inputtingAction();
  223.         action.setSkill(skill.id);
  224.         BattleManager.actor().setLastBattleSkill(skill);
  225.         this._skillWindow.deactivate();
  226.         this.onSelectAction();
  227.     };
  228.    
  229.     Scene_Battle.prototype.isAnyInputWindowActive = function() {
  230.         console.log(this._actorCommandWindow.active, this._subactorCommandWindow.active, this._skillWindow.active)
  231.         return (this._partyCommandWindow.active ||
  232.                 this._actorCommandWindow.active ||
  233.                 this._subactorCommandWindow.active ||
  234.                 this._skillWindow.active ||
  235.                 this._itemWindow.active ||
  236.                 this._actorWindow.active ||
  237.                 this._enemyWindow.active);
  238.     };
  239.  
  240.     Scene_Battle.prototype.startPartyCommandSelection = function() {
  241.         this.refreshStatus();
  242.         this._statusWindow.deselect();
  243.         this._statusWindow.open();
  244.         this._actorCommandWindow.close();
  245.         this._subactorCommandWindow.close();    
  246.         this._partyCommandWindow.setup();
  247.     };
  248.    
  249.     Scene_Battle.prototype.startActorCommandSelection = function() {
  250.         this._statusWindow.select(BattleManager.actor().index());
  251.         this._partyCommandWindow.close();
  252.         this._subactorCommandWindow.close();
  253.         this._actorCommandWindow.setup(BattleManager.actor());
  254.     };
  255.  
  256.     Scene_Battle.prototype.onSelectAction = function() {
  257.         var action = BattleManager.inputtingAction();
  258.         this._skillWindow.hide();
  259.         this._subskillWindow.hide();
  260.         this._itemWindow.hide();
  261.         if (!action.needsSelection()) {
  262.             this.selectNextCommand();
  263.         } else if (action.isForOpponent()) {
  264.             this.selectEnemySelection();
  265.         } else {
  266.             this.selectActorSelection();
  267.         }
  268.     };
  269.    
  270.     Scene_Battle.prototype.stop = function() {
  271.         Scene_Base.prototype.stop.call(this);
  272.         if (this.needsSlowFadeOut()) {
  273.             this.startFadeOut(this.slowFadeSpeed(), false);
  274.         } else {
  275.             this.startFadeOut(this.fadeSpeed(), false);
  276.         }
  277.         this._statusWindow.close();
  278.         this._partyCommandWindow.close();
  279.         this._actorCommandWindow.close();
  280.         this._subactorCommandWindow.close();
  281.     };
  282.        
  283.     Scene_Battle.prototype.endCommandSelection = function() {
  284.         this._partyCommandWindow.close();
  285.         this._actorCommandWindow.close();
  286.         this._subactorCommandWindow.close();
  287.         this._statusWindow.deselect();
  288.     };
  289.  
  290.     Scene_Battle.prototype.commandSkill = function() {
  291.         this._subactorCommandWindow.setStypeId(this._actorCommandWindow.currentExt());
  292.         this._subactorCommandWindow.setup(BattleManager.actor());
  293.         this._skillWindow.activate();    
  294.     };
  295.  
  296.     Scene_Battle.prototype.createSkillWindow = function() {
  297.         var wy = this._helpWindow.y + this._helpWindow.height;
  298.         var wh = this._statusWindow.y - wy;
  299.         this._skillWindow = new Window_BattleSkill(0, wy, Graphics.boxWidth, wh);
  300.         this._skillWindow.setHelpWindow(this._helpWindow);
  301.         this.addWindow(this._skillWindow);
  302.     };
  303.  
  304.     Scene_Battle.prototype.onEnemyOk = function() {
  305.         var action = BattleManager.inputtingAction();
  306.         action.setTarget(this._enemyWindow.enemyIndex());
  307.         this._enemyWindow.hide();
  308.         this._skillWindow.hide();
  309.         this._subskillWindow.hide();
  310.         this._itemWindow.hide();
  311.         this.selectNextCommand();
  312.     };
  313.  
  314.     Scene_Battle.prototype.onActorOk = function() {
  315.         var action = BattleManager.inputtingAction();
  316.         action.setTarget(this._actorWindow.index());
  317.         this._actorWindow.hide();
  318.         this._skillWindow.hide();
  319.         this._subskillWindow.hide();
  320.         this._itemWindow.hide();
  321.         this.selectNextCommand();
  322.     };
  323.    
  324.     Scene_Battle.prototype.onActorCancel = function() {
  325.         this._actorWindow.hide();
  326.         switch (this._actorCommandWindow.currentSymbol()) {
  327.         case 'skill':
  328.             this._skillWindow.show();
  329.             this._skillWindow.activate();
  330.             break;
  331.         case 'item':
  332.             this._itemWindow.show();
  333.             this._itemWindow.activate();
  334.             break;
  335.         }
  336.     };
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
 
Top