Advertisement
Unconnected42

RMMV Plug-in _ Unco_ChangeEquipOnBattle_v0_1_0

Dec 2nd, 2015
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Change Equip On Battle, ver0.1.0
  3. //   by Unconnected42
  4. // Based on ChangeWeaponOnBattle, by Kannazuki Sasuke
  5. //
  6. // UNCO_ChangeEquipOnBattle.js
  7. // Last Updated : 2015/11/19
  8. //=============================================================================
  9.  
  10. var Imported = Imported || {};
  11. Imported.UNCO_ChangeEquip = true;
  12.  
  13. var Unco = Unco || {};
  14. Unco.CEB = Unco.CEB || {};
  15.  
  16.  
  17. //=============================================================================
  18.  /*:
  19.  * @plugindesc  Allows player to change certain slots of equipment during battle.
  20.  * <Unco Equip>
  21.  * @author Unconnected42
  22.  *
  23.  * @param Equip Command Name
  24.  * @desc  Name of the equip command in actor battle menu.
  25.  * @default Equip
  26.  *
  27.  * @param Equip Command Icon
  28.  * @desc  Id of the icon to be displayed in front of Equip command when Bobstah's
  29.  * Battle Command List is present.
  30.  * @default 76
  31.  *
  32.  * @param Equip Skip Turn
  33.  * @desc  'full'=turn skipped as soon as one equip changed. 'half'=turn skipped when leaving equip menu. 'none'=no skip.
  34.  * @default full
  35.  *
  36.  * @param Equip Skill Id
  37.  * @desc  The Id of the dummy skill that the actor will use after changing equipment, when turn is consumed.
  38.  * @default 7
  39.  *
  40.  * @help
  41.  * ============================================
  42.  * Introduction
  43.  * ============================================
  44.  *
  45.  * This plug-in is based on the official plug-in ChangeWeaponOnBattle,
  46.  * with the following differences:
  47.  * - allow maker to decide each equipments may be changed, for each class.
  48.  * - guarantees a minimum level of compatibility with Bobstah's Battle
  49.  *   Command List plug-in (equip command can have an icon, but cannot
  50.  *   currently be moved freely at any place in the command list).
  51.  * - guarantee compatibility with Ammunition System.
  52.  * - also provide some compatibility with EquipCore.
  53.  * - changing equipment can consume actor's turn.
  54.  *
  55.  * ============================================
  56.  * Known Compatibility Issues
  57.  * ============================================
  58.  *
  59.  * This plug-in should be placed below any other plug-in that it
  60.  * interacts with, namely: Battle Command List, EquipCore,
  61.  * Ammunition System.
  62.  *
  63.  * ============================================
  64.  * Use
  65.  * ============================================
  66.  *
  67.  * Lines to put in class notebox :
  68.  * <Battle Change Equip: s1,s2,...>
  69.  * ...where 's1,s2,...' are the equip slots that the actor will be
  70.  * able to change during battle.
  71.  * For ex. : <Battle Change Equip: 1,2,5> will allow any actor having
  72.  * the class whete the tag is put to change the three listed equip slots
  73.  * (in that case, probably weapon, shield and some accessory).
  74.  * Please note that if no 'Battle Change Equip' tag is given for a class,
  75.  * the equip command will not appear for the concerned actors.
  76.  *
  77.  */
  78. //=============================================================================
  79.  
  80. //=============================================================================
  81. // Parameter Variables
  82. //=============================================================================
  83.  
  84.  
  85. (function() {
  86.    Unco.Parameters = $plugins.filter(function(p) {
  87.           return p.description.contains('<Unco Equip>');
  88.       })[0].parameters; //Copied from Ellye, who thanks Iavra
  89.    Unco.Param = Unco.Param || {};
  90.  
  91.    Unco.Param.equipCommandName = String(Unco.Parameters['Equip Command Name']) || 'Equip';
  92.    Unco.Param.equipConsumeTurn = String(Unco.Parameters['Equip Skip Turn']).toLowerCase() || 'full';
  93.    Unco.Param.equipIconId = parseInt(Unco.Parameters['Equip Command Icon']) || 76;
  94.    Unco.Param.equipSkillId = parseInt(Unco.Parameters['Equip Skill Id']) || 7;
  95.  
  96.   //=============================================================================
  97.   // DataManager
  98.   //  * Tags Processing
  99.   //=============================================================================
  100.  
  101.    Unco.CEB.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
  102.    DataManager.isDatabaseLoaded = function() {
  103.       if (!Unco.CEB.DataManager_isDatabaseLoaded.call(this)) return false;
  104.       this.processUncoEquipChangeNotetags($dataClasses);
  105.       return true;
  106.    };
  107.  
  108.    DataManager.processUncoEquipChangeNotetags = function(group) {
  109.       for (var n = 1; n < group.length; n++) {
  110.          var obj = group[n];
  111.          var notedata = obj.note.split(/[\r\n]+/);
  112.          obj.equipChangeSlots = [];
  113.          for (var i = 0; i < notedata.length; i++) {
  114.             var line = notedata[i];
  115.             if (line.match(/<(?:BATTLE)[ ](?:CHANGE)[ ](?:EQUIP):[ ](.*)>/i)) {
  116.                var slotList = String(RegExp.$1).split(',');
  117.                for (var i in slotList) {
  118.                   var slot = parseInt(slotList[i])
  119.                   if (!isNaN(slot) && (slot > 0)) obj.equipChangeSlots.push(slot);
  120.                }
  121.             }
  122.          }
  123.       }
  124.    };
  125.  
  126.  
  127.    //=============================================================================
  128.    // Window_BattleEquipStatus
  129.   //  * Display Equip Bonuses
  130.    //=============================================================================
  131.    function Window_BattleEquipStatus() {
  132.       this.initialize.apply(this, arguments);
  133.    }
  134.  
  135.    Window_BattleEquipStatus.prototype =
  136.       Object.create(Window_EquipStatus.prototype);
  137.    Window_BattleEquipStatus.prototype.constructor = Window_BattleEquipStatus;
  138.  
  139.    Window_BattleEquipStatus.prototype.initialize = function(x, y) {
  140.       Window_EquipStatus.prototype.initialize.call(this, x, y);
  141.    };
  142.  
  143.    Window_BattleEquipStatus.prototype.numVisibleRows = function() {
  144.       return 7;
  145.    };
  146.    
  147.    //=============================================================================
  148.    // Window_BattleEquipItem
  149.   //  * One-column Equip Item Window
  150.    //=============================================================================
  151.    function Window_BattleEquipItem() {
  152.       this.initialize.apply(this, arguments);
  153.    }
  154.  
  155.    Window_BattleEquipItem.prototype = Object.create(Window_EquipItem.prototype);
  156.    Window_BattleEquipItem.prototype.constructor = Window_BattleEquipItem;
  157.  
  158.    Window_BattleEquipItem.prototype.initialize  = function(x, y, width, height) {
  159.       Window_EquipItem.prototype.initialize.call(this, x, y, width, height);
  160.    };
  161.  
  162.    Window_BattleEquipItem.prototype.maxCols = function() {
  163.       return 1;
  164.    };
  165.  
  166.    //=============================================================================
  167.    // Window_BattleEquipSlot
  168.   //  * Tiny Equip Slot, with slot list based on the contents of Battle Change Equip Tag.
  169.    //=============================================================================
  170.    function Window_BattleEquipSlot() {
  171.       this.initialize.apply(this, arguments);
  172.    }
  173.  
  174.    Window_BattleEquipSlot.prototype = Object.create(Window_EquipSlot.prototype);
  175.    Window_BattleEquipSlot.prototype.constructor = Window_BattleEquipSlot;
  176.  
  177.    Window_BattleEquipSlot.prototype.initialize  = function(x, y, width, height) {
  178.       Window_EquipSlot.prototype.initialize.call(this, x, y, width, height);
  179.    };
  180.  
  181.    Window_BattleEquipSlot.prototype.maxItems = function() {
  182.       return this._actor ? ($dataClasses[$dataActors[this._actor._actorId].classId].equipChangeSlots.length) : 0;
  183.    };
  184.  
  185.    Window_BattleEquipSlot.prototype.update = function() {
  186.       Window_Selectable.prototype.update.call(this);
  187.       if (this._itemWindow) {
  188.          if ( this._actor) {
  189.             if (Imported.YEP_EquipCore === true) {
  190.                Yanfly.Equip.Window_EquipItem_setSlotId.call(this._itemWindow , $dataClasses[$dataActors[this._actor._actorId].classId].equipChangeSlots[this.index()]-1);
  191.             } else {
  192.                this._itemWindow.setSlotId( $dataClasses[$dataActors[this._actor._actorId].classId].equipChangeSlots[this.index()]-1 );
  193.             }
  194.          } else this._itemWindow.setSlotId( this.index() );
  195.       }
  196.    };
  197.  
  198.    Window_BattleEquipSlot.prototype.item = function() {
  199.       return this._actor ? this._actor.equips()[ $dataClasses[$dataActors[this._actor._actorId].classId].equipChangeSlots[this.index()]-1 ] : null;
  200.    };
  201.  
  202.    Window_BattleEquipSlot.prototype.drawItem = function(index) {
  203.       if (this._actor) {
  204.          var realIndex = $dataClasses[$dataActors[this._actor._actorId].classId].equipChangeSlots[index]-1;
  205.          var rect = this.itemRectForText(index);
  206.          this.changeTextColor(this.systemColor());
  207.          this.changePaintOpacity(this.isEnabled(realIndex));
  208.          this.drawText(this.slotName(index), rect.x, rect.y, 138, this.lineHeight());
  209.          var item = this._actor.equips()[realIndex];
  210.          if ((item === null) && (Window_EquipSlot.prototype.drawEmptySlot)) {
  211.             this.drawEmptySlot(rect.x + 138, rect.y, rect.width - 138);
  212.          } else {
  213.             this.drawItemName(item, rect.x + 138, rect.y);
  214.          }
  215.          this.changePaintOpacity(true);
  216.       }
  217.    };
  218.  
  219.    Window_BattleEquipSlot.prototype.slotName = function(index) {
  220.       var slots = this._actor.equipSlots();
  221.       return this._actor ? $dataSystem.equipTypes[slots[ $dataClasses[$dataActors[this._actor._actorId].classId].equipChangeSlots[index]-1 ]] : '';
  222.    };
  223.  
  224.    Window_BattleEquipSlot.prototype.show = function() {
  225.       Window_EquipSlot.prototype.show.call(this);
  226.       this.showHelpWindow();
  227.    };
  228.  
  229.    Window_BattleEquipSlot.prototype.hide = function() {
  230.       Window_EquipSlot.prototype.hide.call(this);
  231.       this.hideHelpWindow();
  232.    };
  233.  
  234.    
  235.    //=============================================================================
  236.    // Scene_Battle
  237.    //  * Adding the new windows to Scene_Battle, and managing turn skipping.
  238.    //=============================================================================
  239.    var _Scene_Battle_isAnyInputWindowActive = Scene_Battle.prototype.isAnyInputWindowActive;
  240.    Scene_Battle.prototype.isAnyInputWindowActive = function() {
  241.       if (_Scene_Battle_isAnyInputWindowActive.call(this)) {
  242.          return true;
  243.       }
  244.       return (this._equipSlotWindow.active || this._equipItemWindow.active);
  245.    };
  246.    
  247.    var _Scene_Battle_createAllWindows = Scene_Battle.prototype.createAllWindows;
  248.    Scene_Battle.prototype.createAllWindows = function() {
  249.       _Scene_Battle_createAllWindows.call(this);
  250.       this.createEquipStatusWindow();
  251.       this.createEquipSlotWindow();
  252.       this.createEquipItemWindow();
  253.    };
  254.  
  255.    Scene_Battle.prototype.createEquipStatusWindow = function() {
  256.       this._equipStatusWindow = new Window_BattleEquipStatus(0, this._helpWindow.height);
  257.       this._equipStatusWindow.hide();
  258.       this.addWindow(this._equipStatusWindow);
  259.    };
  260.  
  261.    Scene_Battle.prototype.createEquipSlotWindow = function() {
  262.       var wx = this._equipStatusWindow.width;
  263.       var wy = this._helpWindow.height;
  264.       var ww = Graphics.boxWidth - this._equipStatusWindow.width;
  265.       var wh = Window_Base.prototype.lineHeight()*3;
  266.       this._equipSlotWindow = new Window_BattleEquipSlot(wx, wy, ww, wh);
  267.       this._equipSlotWindow.setHelpWindow(this._helpWindow);
  268.       this._equipSlotWindow.setStatusWindow(this._equipStatusWindow);
  269.       this._equipSlotWindow.setHandler('ok', this.onEquipSlotOk.bind(this));
  270.       this._equipSlotWindow.setHandler('cancel', this.onEquipSlotCancel.bind(this));
  271.       this._equipSlotWindow.hide();
  272.       this.addWindow(this._equipSlotWindow);
  273.    };
  274.  
  275.    Scene_Battle.prototype.createEquipItemWindow = function() {
  276.       var wx = this._equipStatusWindow.width;
  277.       var wy = this._equipStatusWindow.y + Window_Base.prototype.lineHeight()*3;
  278.       var ww = Graphics.boxWidth - wx;
  279.       var wh = Graphics.boxHeight - wy - this._statusWindow.height;
  280.       this._equipItemWindow = new Window_BattleEquipItem(wx, wy, ww, wh);
  281.       this._equipItemWindow.setHelpWindow(this._helpWindow);
  282.       this._equipItemWindow.setStatusWindow(this._equipStatusWindow);
  283.       this._equipItemWindow.setHandler('ok',     this.onEquipItemOk.bind(this));
  284.       this._equipItemWindow.setHandler('cancel', this.onEquipItemCancel.bind(this));
  285.       this._equipSlotWindow.setItemWindow(this._equipItemWindow);
  286.       this._equipItemWindow.hide();
  287.       this.addWindow(this._equipItemWindow);
  288.    };
  289.  
  290.    var _Scene_Battle_createActorCommandWindow = Scene_Battle.prototype.createActorCommandWindow;
  291.    Scene_Battle.prototype.createActorCommandWindow = function() {
  292.       _Scene_Battle_createActorCommandWindow.call(this);
  293.       this._actorCommandWindow.setHandler('equip', this.commandEquip.bind(this));
  294.    };
  295.  
  296.    var _Window_ActorCommand_makeCommandList = Window_ActorCommand.prototype.makeCommandList;
  297.    Window_ActorCommand.prototype.makeCommandList = function() {
  298.       _Window_ActorCommand_makeCommandList.call(this);
  299.       if (this._actor && ($dataClasses[$dataActors[this._actor._actorId].classId].equipChangeSlots.length > 0) ) {
  300.          this.addEquipCommand();
  301.       }
  302.    };
  303.  
  304.    Window_ActorCommand.prototype.addEquipCommand = function() {
  305.       if (Imported.BOB_BattleCommandList === true) {
  306.          this.addCommand(Unco.Param.equipCommandName, 'equip', true, null, Unco.Param.equipIconId);
  307.        } else {
  308.          this.addCommand(Unco.Param.equipCommandName, 'equip');
  309.        }
  310.    };
  311.  
  312.    Scene_Battle.prototype.refreshActor = function() {
  313.       var actor = BattleManager.actor();
  314.       this._equipStatusWindow.setActor(actor);
  315.       this._equipSlotWindow.setActor(actor);
  316.       this._equipItemWindow.setActor(actor);
  317.    };
  318.  
  319.    Scene_Battle.prototype.commandEquip = function() {
  320.       this.refreshActor();
  321.       if (Imported.UNCO_AmmunitionSystem === true) {
  322.          this._ammoWindow.hide();
  323.       }
  324.       this._equipStatusWindow.show();
  325.       this._equipItemWindow.refresh();
  326.       this._equipItemWindow.show();
  327.       this._equipSlotWindow.refresh();
  328.       this._equipSlotWindow.show();
  329.       this._equipSlotWindow.activate();
  330.       this._equipSlotWindow.select(0);
  331.       if (this._equipsChanged) delete this._equipsChanged;
  332.    };
  333.  
  334.    Scene_Battle.prototype.onEquipSlotOk = function() {
  335.       this._equipItemWindow.activate();
  336.       this._equipItemWindow.select(0);
  337.    };
  338.  
  339.    Scene_Battle.prototype.onEquipSlotCancel = function() {
  340.       this._equipStatusWindow.hide();
  341.       this._equipItemWindow.hide();
  342.       this._equipSlotWindow.hide();
  343.       if (Unco.Param.equipConsumeTurn === 'half' && this._equipsChanged) {
  344.          var skill = $dataSkills[Unco.Param.equipSkillId];
  345.          var action = BattleManager.inputtingAction();
  346.          action.setSkill(skill.id);
  347.          BattleManager.actor().setLastBattleSkill(skill);
  348.          this.onSelectAction();
  349.       } else {
  350.          if (Imported.UNCO_AmmunitionSystem === true) {
  351.             this.showAmmoWindow();
  352.          }
  353.          this._actorCommandWindow.activate();
  354.          this._actorCommandWindow.select(0);
  355.       }
  356.    };
  357.  
  358.    Scene_Battle.prototype.onEquipItemOk = function() {
  359.       SoundManager.playEquip();
  360.       this._equipsChanged = true;
  361.       BattleManager.actor().changeEquip(  $dataClasses[$dataActors[this._equipSlotWindow._actor._actorId].classId].equipChangeSlots[this._equipSlotWindow.index()]-1 , this._equipItemWindow.item());
  362.       if (Unco.Param.equipConsumeTurn === 'full') {
  363.          this._equipItemWindow.deselect();
  364.          this._equipStatusWindow.hide();
  365.          this._equipItemWindow.hide();
  366.          this._equipSlotWindow.hide();
  367.          var skill = $dataSkills[Unco.Param.equipSkillId];
  368.          var action = BattleManager.inputtingAction();
  369.          action.setSkill(skill.id);
  370.          BattleManager.actor().setLastBattleSkill(skill);
  371.          this.onSelectAction();
  372.       } else {
  373.          this._equipSlotWindow.activate();
  374.          this._equipSlotWindow.refresh();
  375.          this._equipItemWindow.deselect();
  376.          this._equipItemWindow.refresh();
  377.          this._equipStatusWindow.refresh();
  378.       }
  379.    };
  380.  
  381.    Scene_Battle.prototype.onEquipItemCancel = function() {
  382.       this._equipSlotWindow.activate();
  383.       this._equipItemWindow.deselect();
  384.    };
  385.  
  386. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement