Guest User

Jay_OneOrAllTargets.js

a guest
Feb 28th, 2016
599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Single/Multiple targeting switch
  3. // Jay_OneOrAllTargets.js
  4. // Version 0.6
  5. //=============================================================================
  6.  
  7. var Imported = Imported || {};
  8. Imported.Jay_OneOrAllTargets = true;
  9.  
  10. var Jay = Jay || {};
  11. Jay.OneOrAllTargets = Jay.OneOrAllTargets || {};
  12.  
  13. //=============================================================================
  14.  /*:
  15.  * @plugindesc Allows tagged skills to affect either one or all targets.
  16.  *
  17.  * @author Jason R. Godding
  18.  *
  19.  * @param Set Enemy to All Key
  20.  * @desc Which key to press to set targeting from one enemy to all.
  21.  * You can define more than one key, separated by spaces.
  22.  * @default shift
  23.  *
  24.  * @param Set Enemy to One Key
  25.  * @desc Which key to press to set targeting from all enemies to one.
  26.  * You can define more than one key, separated by spaces.
  27.  * @default shift
  28.  *
  29.  * @param Set Ally to All Key
  30.  * @desc Which key to press to set targeting from one ally to all.
  31.  * You can define more than one key, separated by spaces.
  32.  * @default shift
  33.  *
  34.  * @param Set Ally to One Key
  35.  * @desc Which key to press to set targeting from all allies to one.
  36.  * You can define more than one key, separated by spaces.
  37.  * @default shift
  38.  *
  39.  * @help To set a skill/item to be able to hit one or all targets, put the tag
  40.  * <OneOrAll> in its Note box. It will default to targeting however it is set
  41.  * in the database, but you can switch it by pressing the correct key. It is,
  42.  * however, recommended that you use "1 enemy" or "1 ally" targeting in the
  43.  * database.
  44.  *
  45.  * This plugin currently requires Yanfly's Battle Core to work at all. It is
  46.  * recommended that you use Visual Enemy Select; it works without, but not
  47.  * perfectly. In this build, all Target Core tags override the <OneOrAll>
  48.  * tag (except <Repeat: x>), but the two plugins otherwise do not conflict.
  49.  *
  50.  * For damage/healing skills, you can use the tag <SplitMulti> to divide the
  51.  * damage by the number of targets or <DivideMulti: x> to always divide the
  52.  * damage for multiple targets by x. These can be placed on any skill, not just
  53.  * ones  marked <OneOrAll>! (Though they won't DO anything for skills that only
  54.  * hit a single target.) Using both tags on a single skill is allowed but not
  55.  * recommended (it will split the damage twice.)
  56.  *
  57.  * This plugin is free for non-commercial and commercial use, but please credit
  58.  * Jason R. Godding if you use it. Thank you.
  59.  *
  60.  */
  61.  
  62. Jay.Parameters = Jay.Parameters || {};
  63. Jay.Parameters.OneOrAllTargets = PluginManager.parameters('Jay_OneOrAllTargets');
  64.  
  65. Jay.Param = Jay.Param || {};
  66. Jay.Param.EnemyToAllKey = Jay.Parameters.OneOrAllTargets['Set Enemy to All Key'].split(' ');
  67. Jay.Param.EnemyToOneKey = Jay.Parameters.OneOrAllTargets['Set Enemy to One Key'].split(' ');
  68. Jay.Param.AllyToAllKey = Jay.Parameters.OneOrAllTargets['Set Ally to All Key'].split(' ');
  69. Jay.Param.AllyToOneKey = Jay.Parameters.OneOrAllTargets['Set Ally to One Key'].split(' ');
  70.  
  71. Jay.OneOrAllTargets.actionInit = Game_Action.prototype.initialize;
  72. Game_Action.prototype.initialize = function(subject, forcing) {
  73.     this._switchToOne = false;
  74.     this._switchToAll = false;
  75.     Jay.OneOrAllTargets.actionInit.call(this, subject, forcing);
  76. };
  77.  
  78.  
  79. Jay.OneOrAllTargets.isForOne = Game_Action.prototype.isForOne;
  80. Game_Action.prototype.isForOne = function() {
  81.     if (this._switchToOne) {
  82.         return true;
  83.     }
  84.     else if (this._switchToAll) {
  85.         return false;
  86.     }
  87.     return Jay.OneOrAllTargets.isForOne.call(this);
  88. };
  89.  
  90. Jay.OneOrAllTargets.isForAll = Game_Action.prototype.isForAll;
  91. Game_Action.prototype.isForAll = function() {
  92.     if (this._switchToAll) {
  93.         return true;
  94.     }
  95.     else if (this._switchToOne) {
  96.         return false;
  97.     }
  98.     return Jay.OneOrAllTargets.isForAll.call(this);
  99. };
  100.  
  101. Game_Action.prototype.allowsOneOrAll = function() {
  102.     if (this.item() && this.item().meta.OneOrAll) {
  103.         return true;
  104.     }
  105.     return false;
  106. };
  107.  
  108. Game_Action.prototype.switchToAll = function() {
  109.     if (this.allowsOneOrAll()) {
  110.         this._switchToOne = false;
  111.         this._switchToAll = true;
  112.     }
  113. };
  114.  
  115. Game_Action.prototype.switchToOne = function() {
  116.     if (this.allowsOneOrAll()) {
  117.         this._switchToOne = true;
  118.         this._switchToAll = false;
  119.     }
  120. };
  121.  
  122. Jay.OneOrAllTargets.makeDamageValue = Game_Action.prototype.makeDamageValue;
  123. Game_Action.prototype.makeDamageValue = function(target, critical) {
  124.     var baseDamage = Jay.OneOrAllTargets.makeDamageValue.call(this, target, critical);
  125.     var numTargets = this.makeTargets().length;
  126.     if(this.item().meta.SplitMulti && numTargets > 0) {
  127.         baseDamage = baseDamage / numTargets;
  128.     }
  129.     if(this.item().meta.DivideMulti && numTargets > 1) {
  130.         baseDamage = baseDamage / this.item().meta.DivideMulti;
  131.     }
  132.     baseDamage = Math.round(baseDamage);
  133.     return baseDamage;
  134. }
  135.  
  136. Jay.OneOrAllTargets.updateScene = Scene_Battle.prototype.update
  137. Scene_Battle.prototype.update = function() {
  138.     Jay.OneOrAllTargets.updateScene.call(this);
  139.     this.updateOneOrAll();
  140. };
  141.  
  142. Scene_Battle.prototype.updateOneOrAll = function() {
  143.     var input = BattleManager.inputtingAction();
  144.     var triggered = function(key) {
  145.                 return Input.isTriggered(key);
  146.             };
  147.  
  148.     if (!this._actorWindow.active && !this._enemyWindow.active) {
  149.         return;
  150.     }
  151.  
  152.     if (!input) {
  153.         return;
  154.     }
  155.  
  156.     if (!input.item()) {
  157.         return;
  158.     }
  159.  
  160.     if(!input.allowsOneOrAll()) {
  161.         return;
  162.     }
  163.  
  164.     if (Jay.Param.EnemyToAllKey.some(triggered) && input.isForOne() && this._enemyWindow.active) {
  165.         input.switchToAll();
  166.         BattleManager.startAllSelection();
  167.         this._helpWindow.clear();
  168.         this._helpWindow.drawSpecialSelectionText(input);
  169.     }
  170.     else if (Jay.Param.EnemyToOneKey.some(triggered) && input.isForAll() && this._enemyWindow.active) {
  171.         input.switchToOne();
  172.         BattleManager.stopAllSelection();
  173.         this._helpWindow.clear();
  174.         this._helpWindow.setBattler(this._enemyWindow.enemy());
  175.     }
  176.     else if (Jay.Param.AllyToAllKey.some(triggered) && input.isForOne() && this._actorWindow.active) {
  177.         input.switchToAll();
  178.         BattleManager.startAllSelection();
  179.         this._helpWindow.clear();
  180.         this._helpWindow.drawSpecialSelectionText(input);
  181.     }
  182.     else if (Jay.Param.AllyToOneKey.some(triggered) && input.isForAll() && this._actorWindow.active) {
  183.         input.switchToOne();
  184.         BattleManager.stopAllSelection();
  185.         this._helpWindow.clear();
  186.         this._helpWindow.setBattler(this._actorWindow.actor());
  187.     }
  188. };
  189.  
  190. Jay.OneOrAllTargets.specialSelectionText = Window_Help.prototype.specialSelectionText;
  191. Window_Help.prototype.specialSelectionText = function(action) {
  192.     if (action && action.isForAll()) {
  193.         return true;
  194.     }
  195.     return Jay.OneOrAllTargets.specialSelectionText.call(this, action);
  196. };
Advertisement
Add Comment
Please, Sign In to add comment