Advertisement
jeneeus

CommandEquip

Nov 4th, 2015
2,111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //==============================================================================
  2. // ** Equip Battle Command
  3. // by: Jeneeus Guruman
  4. //------------------------------------------------------------------------------
  5.  
  6. var Imported = Imported || {};
  7. var Jene = Jene || {};
  8.  
  9. /*:
  10.  * @plugindesc Equip Battle Command v1.1.1
  11.  * @author Jeneeus Guruman
  12.  *
  13.  * @param Unchangeable Types
  14.  * @desc The equipment types that cannot be changed in battle.
  15.  * Separate the IDs by spaces.
  16.  * @default
  17.  *
  18.  * @help
  19.  *
  20.  *     This plugin allows to access equip window to change equipment.
  21.  *  
  22.  *       Notes:
  23.  *       * Place this below scripts that alter the Equip layout but
  24.  *       above other scripts.
  25.  *
  26.  *   Changelog:
  27.  *
  28.  *     * v1.1.1 Fixed a bug while using Yanfly's Equip Core that will
  29.  *     clear equipment even the unremovable ones and optimized them
  30.  *     even when set to not be optimized (special thanks to snorlord
  31.  *     for the help).
  32.  *     * v1.1.0: Now added "Unchangeable Types" parameter to exclude
  33.  *     some slots to enable equip changes in battle.
  34.  *     * v1.0.2: Fixed a bug that won't refresh the equip item list
  35.  *     when the quantity of any equip altered outside of the equip
  36.  *     command.
  37.  *     * v1.0.1: Now compatible with Yanfly's Equip Core.
  38.  */
  39.  
  40. parameters = PluginManager.parameters('CommandEquip');
  41.  
  42. Jene.unchangeableTypes = String(parameters['Unchangeable Types']);
  43.  
  44. Jene.windowEquipSlotIsCurrentItemEnabled = Window_EquipSlot.prototype.isCurrentItemEnabled;
  45.  
  46. Window_EquipSlot.prototype.isCurrentItemEnabled = function() {
  47.     var disabledSlots = [];
  48.     for (i=0; i < Jene.unchangeableTypes.split(" ").length; i++) {
  49.         disabledSlots.push(Number(Jene.unchangeableTypes.split(" ")[i]));
  50.     }
  51.     var etypeId = this._actor.equipSlots()[this.index()];
  52.     console.log(disabledSlots.contains(etypeId));
  53.     if ($gameParty.inBattle() && disabledSlots.contains(etypeId)) {
  54.         return false;
  55.     }
  56.     return this.isEnabled(this.index());
  57. };
  58.  
  59. if (Imported.YEP_EquipCore) {
  60.  
  61. Window_ActorCommand.prototype.addEquipCommand = function() {
  62.     this.addCommand(TextManager.equip, 'equip');
  63. };
  64.  
  65. Jene.windowActorCommandMakeCommandListYEP = Window_ActorCommand.prototype.makeCommandList;
  66.  
  67. Window_ActorCommand.prototype.makeCommandList = function() {
  68.     Jene.windowActorCommandMakeCommandListYEP.call(this);
  69.     if (this._actor) {
  70.         this.addEquipCommand();
  71.     }
  72. };
  73.  
  74. Jene.sceneBattleIsAnyInputWindowActiveYEP = Scene_Battle.prototype.isAnyInputWindowActive;
  75.  
  76. Scene_Battle.prototype.isAnyInputWindowActive = function() {
  77.     return (Jene.sceneBattleIsAnyInputWindowActiveYEP.call(this) || this._equipCommandWindow.active || this._slotWindow.active || this._equipItemWindow.active);
  78. };
  79.  
  80. Jene.sceneBattleCreateAllWindowsYEP = Scene_Battle.prototype.createAllWindows;
  81.  
  82. Scene_Battle.prototype.createAllWindows = function() {
  83.     Jene.sceneBattleCreateAllWindowsYEP.call(this);
  84.     this.createEquipCommandWindow();
  85.     this.createEquipStatusWindow();
  86.     this.createSlotWindow();
  87.     this.createEquipItemWindow();
  88.     this.createCompareWindow();
  89. }
  90.  
  91. Jene.sceneBattleCreateActorCommandWindowYEP = Scene_Battle.prototype.createActorCommandWindow;
  92.  
  93. Scene_Battle.prototype.createActorCommandWindow = function() {
  94.     Jene.sceneBattleCreateActorCommandWindowYEP.call(this);
  95.     this._actorCommandWindow.setHandler('equip',  this.commandEquipment.bind(this));
  96.     this.addWindow(this._actorCommandWindow);
  97. };
  98.  
  99. Scene_Battle.prototype.createEquipStatusWindow = function() {
  100.     var wx = this._equipCommandWindow.width;
  101.     var wy = this._helpWindow.height;
  102.     var ww = Graphics.boxWidth - wx;
  103.     var wh = this._equipCommandWindow.height;
  104.     this._equipStatusWindow = new Window_SkillStatus(wx, wy, ww, wh);
  105.     $gameParty.members().forEach(function(actor) {
  106.         ImageManager.loadFace(actor.faceName());
  107.     }, this._equipStatusWindow);
  108.     this._equipStatusWindow.hide();
  109.     this.addWindow(this._equipStatusWindow);
  110. };
  111.  
  112. Scene_Battle.prototype.createEquipCommandWindow = function() {
  113.     var wy = this._helpWindow.height;
  114.     this._equipCommandWindow = new Window_EquipCommand(0, wy, 240);
  115.     this._equipCommandWindow.setHelpWindow(this._helpWindow);
  116.     this._equipCommandWindow.setHandler('equip',    this.commandEquip.bind(this));
  117.     this._equipCommandWindow.setHandler('optimize', this.commandOptimize.bind(this));
  118.     this._equipCommandWindow.setHandler('clear',    this.commandClear.bind(this));
  119.     this._equipCommandWindow.setHandler('cancel',   this.commandEquipmentCancel.bind(this));
  120.     this._equipCommandWindow.deactivate();
  121.     this._equipCommandWindow.hide();
  122.     this.addWindow(this._equipCommandWindow);
  123. };
  124.  
  125. Scene_Battle.prototype.createSlotWindow = function() {
  126.     var wy = this._equipCommandWindow.y + this._equipCommandWindow.height;
  127.     var ww = Graphics.boxWidth / 2;
  128.     var wh = Graphics.boxHeight - wy;
  129.     this._slotWindow = new Window_EquipSlot(0, wy, ww, wh);
  130.     this._slotWindow.setHelpWindow(this._helpWindow);
  131.     this._slotWindow.setStatusWindow(this._equipStatusWindow);
  132.     this._slotWindow.setHandler('ok',       this.onSlotOk.bind(this));
  133.     this._slotWindow.setHandler('cancel',   this.onSlotCancel.bind(this));
  134.     this._slotWindow.hide();
  135.     this.addWindow(this._slotWindow);
  136. };
  137.  
  138. Scene_Battle.prototype.createEquipItemWindow = function() {
  139.     var wy = this._slotWindow.y;
  140.     var ww = Graphics.boxWidth / 2;
  141.     var wh = Graphics.boxHeight - wy;
  142.     this._equipItemWindow = new Window_EquipItem(0, wy, ww, wh);
  143.     this._equipItemWindow.setHelpWindow(this._helpWindow);
  144.     this._equipItemWindow.setStatusWindow(this._equipStatusWindow);
  145.     this._equipItemWindow.setHandler('ok',     this.onEquipItemOk.bind(this));
  146.     this._equipItemWindow.setHandler('cancel', this.onEquipItemCancel.bind(this));
  147.     this._slotWindow.setItemWindow(this._equipItemWindow);
  148.     this._equipItemWindow.hide();
  149.     this.addWindow(this._equipItemWindow);
  150. };
  151.  
  152. Scene_Battle.prototype.createCompareWindow = function() {
  153.     var wx = this._equipItemWindow.width;
  154.     var wy = this._equipItemWindow.y;
  155.     var ww = Graphics.boxWidth - wx;
  156.     var wh = Graphics.boxHeight - wy;
  157.     this._compareWindow = new Window_StatCompare(wx, wy, ww, wh);
  158.     this._slotWindow.setStatusWindow(this._compareWindow);
  159.     this._equipItemWindow.setStatusWindow(this._compareWindow);
  160.     this._compareWindow.hide();
  161.     this.addWindow(this._compareWindow);
  162. };
  163.  
  164. Scene_Battle.prototype.refreshActor = function() {
  165.     var actor = BattleManager.actor();
  166.     this._equipStatusWindow.setActor(actor);
  167.     this._slotWindow.setActor(actor);
  168.     this._equipItemWindow.setActor(actor);
  169.     this._compareWindow.setActor(actor);
  170. };
  171.  
  172. Scene_Battle.prototype.commandEquipment = function() {
  173.     this.refreshActor();
  174.     this._helpWindow.show();
  175.     this._equipCommandWindow.refresh();
  176.     this._equipCommandWindow.show();
  177.     this._equipCommandWindow.activate();
  178.     this._equipStatusWindow.refresh();
  179.     this._equipStatusWindow.show();
  180.     this._slotWindow.refresh();
  181.     this._slotWindow.show();
  182.     this._compareWindow.refresh();
  183.     this._compareWindow.show();
  184.     this._equipItemWindow.refresh();
  185.     this._equipCommandWindow.select(0);
  186. };
  187.  
  188. Scene_Battle.prototype.commandEquip = function() {
  189.     this._slotWindow.refresh();
  190.     this._slotWindow.activate();
  191.     this._slotWindow.select(0);
  192. };
  193.  
  194. Scene_Battle.prototype.commandOptimize = function() {
  195.     $gameTemp._optimizeEquipments = true;
  196.     var hpRate = BattleManager.actor().hp / Math.max(1, BattleManager.actor().mhp);
  197.     var mpRate = BattleManager.actor().mp / Math.max(1, BattleManager.actor().mmp);
  198.     SoundManager.playEquip();
  199.     BattleManager.actor().optimizeEquipments();
  200.     this._equipStatusWindow.refresh();
  201.     this._slotWindow.refresh();
  202.     this._equipCommandWindow.activate();
  203.     $gameTemp._optimizeEquipments = false;
  204.     BattleManager.actor().setHp(parseInt(BattleManager.actor().mhp * hpRate));
  205.         BattleManager.actor().setMp(parseInt(BattleManager.actor().mmp * mpRate));
  206.     this._compareWindow.refresh();
  207.     this._statusWindow.refresh();
  208. };
  209.  
  210. Scene_Battle.prototype.commandClear = function() {
  211.     $gameTemp._clearEquipments = true;
  212.     var hpRate = BattleManager.actor().hp / Math.max(1, BattleManager.actor().mhp);
  213.     var mpRate = BattleManager.actor().mp / Math.max(1, BattleManager.actor().mmp);
  214.     SoundManager.playEquip();
  215.     BattleManager.actor().clearEquipments();
  216.     this._equipStatusWindow.refresh();
  217.     this._slotWindow.refresh();
  218.     this._equipCommandWindow.activate();
  219.     $gameTemp._clearEquipments = false;
  220.     BattleManager.actor().setHp(parseInt(BattleManager.actor().mhp * hpRate));
  221.         BattleManager.actor().setMp(parseInt(BattleManager.actor().mmp * mpRate));
  222.     this._compareWindow.refresh();
  223.     this._statusWindow.refresh();
  224. };
  225.  
  226. Scene_Battle.prototype.onSlotOk = function() {
  227.     var slotId = this._slotWindow.index();
  228.     Yanfly.Equip.Window_EquipItem_setSlotId.call(this._equipItemWindow, slotId);
  229.     this._equipItemWindow.show();
  230.     this._equipItemWindow.activate();
  231.     this._equipItemWindow.select(0);
  232. };
  233.  
  234. Scene_Battle.prototype.onSlotCancel = function() {
  235.     this._slotWindow.deselect();
  236.     this._equipCommandWindow.activate();
  237. };
  238.  
  239. Scene_Battle.prototype.commandEquipmentCancel = function() {
  240.     this._helpWindow.hide();
  241.     this._equipCommandWindow.hide();
  242.     this._equipStatusWindow.hide();
  243.     this._equipItemWindow.hide();
  244.     this._slotWindow.hide();
  245.     this._compareWindow.hide();
  246.     this._actorCommandWindow.activate();
  247.     //this.selectPreviousCommand.bind(this);
  248. };
  249.  
  250. Scene_Battle.prototype.onEquipItemOk = function() {
  251.     SoundManager.playEquip();
  252.     BattleManager.actor().changeEquip(this._slotWindow.index(), this._equipItemWindow.item());
  253.     this._slotWindow.activate();
  254.     this._slotWindow.refresh();
  255.     this._equipItemWindow.deselect();
  256.     this._equipItemWindow.refresh();
  257.     this._equipItemWindow.hide();
  258.     this._equipStatusWindow.refresh();
  259. };
  260.  
  261. Scene_Battle.prototype.onEquipItemCancel = function() {
  262.     this._slotWindow.activate();
  263.     this._equipItemWindow.hide();
  264. };
  265.  
  266. }
  267.  
  268. else {
  269.  
  270. Window_ActorCommand.prototype.addEquipCommand = function() {
  271.     this.addCommand(TextManager.equip, 'equip');
  272. };
  273.  
  274. Jene.windowActorCommandMakeCommandList = Window_ActorCommand.prototype.makeCommandList;
  275.  
  276. Window_ActorCommand.prototype.makeCommandList = function() {
  277.     Jene.windowActorCommandMakeCommandList.call(this);
  278.     if (this._actor) {
  279.         this.addEquipCommand();
  280.     }
  281. };
  282.  
  283. Jene.sceneBattleIsAnyInputWindowActive = Scene_Battle.prototype.isAnyInputWindowActive;
  284.  
  285. Scene_Battle.prototype.isAnyInputWindowActive = function() {
  286.     return (Jene.sceneBattleIsAnyInputWindowActive.call(this) || this._equipCommandWindow.active || this._slotWindow.active || this._equipItemWindow.active);
  287. };
  288.  
  289. Jene.sceneBattleCreateAllWindows = Scene_Battle.prototype.createAllWindows;
  290.  
  291. Scene_Battle.prototype.createAllWindows = function() {
  292.     Jene.sceneBattleCreateAllWindows.call(this);
  293.     this.createEquipStatusWindow();
  294.     this.createEquipCommandWindow();
  295.     this.createSlotWindow();
  296.     this.createEquipItemWindow();
  297. }
  298.  
  299. Jene.sceneBattleCreateActorCommandWindow = Scene_Battle.prototype.createActorCommandWindow;
  300.  
  301. Scene_Battle.prototype.createActorCommandWindow = function() {
  302.     Jene.sceneBattleCreateActorCommandWindow.call(this);
  303.     this._actorCommandWindow.setHandler('equip',  this.commandEquipment.bind(this));
  304.     this.addWindow(this._actorCommandWindow);
  305. };
  306.  
  307. Scene_Battle.prototype.createEquipStatusWindow = function() {
  308.     this._equipStatusWindow = new Window_EquipStatus(0, this._helpWindow.height);
  309.     $gameParty.members().forEach(function(actor) {
  310.         ImageManager.loadFace(actor.faceName());
  311.     }, this._equipStatusWindow);
  312.     this._equipStatusWindow.hide();
  313.     this.addWindow(this._equipStatusWindow);
  314. };
  315.  
  316. Scene_Battle.prototype.createEquipCommandWindow = function() {
  317.     var wx = this._equipStatusWindow.width;
  318.     var wy = this._helpWindow.height;
  319.     var ww = Graphics.boxWidth - this._equipStatusWindow.width;
  320.     this._equipCommandWindow = new Window_EquipCommand(wx, wy, ww);
  321.     this._equipCommandWindow.setHandler('equip',    this.commandEquip.bind(this));
  322.     this._equipCommandWindow.setHandler('optimize', this.commandOptimize.bind(this));
  323.     this._equipCommandWindow.setHandler('clear',    this.commandClear.bind(this));
  324.     this._equipCommandWindow.setHandler('cancel',   this.commandEquipmentCancel.bind(this));
  325.     this._equipCommandWindow.deactivate();
  326.     this._equipCommandWindow.hide();
  327.     this.addWindow(this._equipCommandWindow);
  328. };
  329.  
  330. Scene_Battle.prototype.createSlotWindow = function() {
  331.     var wx = this._equipStatusWindow.width;
  332.     var wy = this._equipCommandWindow.y + this._equipCommandWindow.height;
  333.     var ww = Graphics.boxWidth - this._equipStatusWindow.width;
  334.     var wh = this._equipStatusWindow.height - this._equipCommandWindow.height;
  335.     this._slotWindow = new Window_EquipSlot(wx, wy, ww, wh);
  336.     this._slotWindow.setHelpWindow(this._helpWindow);
  337.     this._slotWindow.setStatusWindow(this._equipStatusWindow);
  338.     this._slotWindow.setHandler('ok',       this.onSlotOk.bind(this));
  339.     this._slotWindow.setHandler('cancel',   this.onSlotCancel.bind(this));
  340.     this._slotWindow.hide();
  341.     this.addWindow(this._slotWindow);
  342. };
  343.  
  344. Scene_Battle.prototype.createEquipItemWindow = function() {
  345.     var wx = 0;
  346.     var wy = this._equipStatusWindow.y + this._equipStatusWindow.height;
  347.     var ww = Graphics.boxWidth;
  348.     var wh = Graphics.boxHeight - wy;
  349.     this._equipItemWindow = new Window_EquipItem(wx, wy, ww, wh);
  350.     this._equipItemWindow.setHelpWindow(this._helpWindow);
  351.     this._equipItemWindow.setStatusWindow(this._equipStatusWindow);
  352.     this._equipItemWindow.setHandler('ok',     this.onEquipItemOk.bind(this));
  353.     this._equipItemWindow.setHandler('cancel', this.onEquipItemCancel.bind(this));
  354.     this._slotWindow.setItemWindow(this._equipItemWindow);
  355.     this._equipItemWindow.hide();
  356.     this.addWindow(this._equipItemWindow);
  357. };
  358.  
  359. Scene_Battle.prototype.refreshActor = function() {
  360.     var actor = BattleManager.actor();
  361.     this._equipStatusWindow.setActor(actor);
  362.     this._slotWindow.setActor(actor);
  363.     this._equipItemWindow.setActor(actor);
  364. };
  365.  
  366. Scene_Battle.prototype.commandEquipment = function() {
  367.     this.refreshActor();
  368.     this._helpWindow.show();
  369.     this._equipCommandWindow.refresh();
  370.     this._equipCommandWindow.show();
  371.     this._equipCommandWindow.activate();
  372.     this._equipStatusWindow.refresh();
  373.     this._equipStatusWindow.show();
  374.     this._slotWindow.refresh();
  375.     this._slotWindow.show();
  376.     this._equipItemWindow.show();
  377.     this._equipItemWindow.refresh();
  378.     this._equipCommandWindow.select(0);
  379. };
  380.  
  381. Scene_Battle.prototype.commandEquip = function() {
  382.     this._slotWindow.refresh();
  383.     this._slotWindow.activate();
  384. };
  385.  
  386. Scene_Battle.prototype.commandOptimize = function() {
  387.     SoundManager.playEquip();
  388.     BattleManager.actor().optimizeEquipments();
  389.     this._equipStatusWindow.refresh();
  390.     this._slotWindow.refresh();
  391.     this._equipCommandWindow.activate();
  392. };
  393.  
  394. Scene_Battle.prototype.commandClear = function() {
  395.     SoundManager.playEquip();
  396.     BattleManager.actor().clearEquipments();
  397.     this._equipStatusWindow.refresh();
  398.     this._slotWindow.refresh();
  399.     this._equipCommandWindow.activate();
  400. };
  401.  
  402. Scene_Battle.prototype.onSlotOk = function() {
  403.     this._equipItemWindow.activate();
  404.     this._equipItemWindow.select(0);
  405. };
  406.  
  407. Scene_Battle.prototype.onSlotCancel = function() {
  408.     this._slotWindow.deselect();
  409.     this._equipCommandWindow.activate();
  410. };
  411.  
  412. Scene_Battle.prototype.commandEquipmentCancel = function() {
  413.     this._helpWindow.hide();
  414.     this._equipCommandWindow.hide();
  415.     this._equipStatusWindow.hide();
  416.     this._equipItemWindow.hide();
  417.     this._slotWindow.hide();
  418.     this._actorCommandWindow.activate();
  419.     //this.selectPreviousCommand.bind(this);
  420. };
  421.  
  422. Scene_Battle.prototype.onEquipItemOk = function() {
  423.     SoundManager.playEquip();
  424.     BattleManager.actor().changeEquip(this._slotWindow.index(), this._equipItemWindow.item());
  425.     this._slotWindow.activate();
  426.     this._slotWindow.refresh();
  427.     this._equipItemWindow.deselect();
  428.     this._equipItemWindow.refresh();
  429.     this._equipStatusWindow.refresh();
  430. };
  431.  
  432. Scene_Battle.prototype.onEquipItemCancel = function() {
  433.     this._slotWindow.activate();
  434. };
  435.  
  436. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement