Advertisement
Maliki79

MalConfusionControl

Oct 25th, 2020 (edited)
2,598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Maliki's Confusion Control MZ
  3. // MalConfusionControl.js
  4. // version 1.2
  5. //=============================================================================
  6. /*:
  7.  * @target MZ
  8.  *  
  9.  * @plugindesc ver1.2 - Allows devs to specify skills other than basic attack
  10.  * for confused battlers to use.
  11.  * @author Maliki79
  12.  *
  13.  * @help To use this plugin, simply add the following tag to enemy, actor or class notes:
  14.  *
  15.  * <conAttacks: x, y, z...>
  16.  *
  17.  * with x, y, or z being the id number of the desired skill(s) in your database.
  18.  * (All actor skills will be added as well, so seal skills you do not wish to be used while confused)
  19.  * Note that while the battler does not need to have normal access to that skill to use it,
  20.  * the battler will need sufficent MP/TP to do so.
  21.  * Also note that actors will need to be able to use the skills normally.  
  22.  * (If a sword skill is on the list but the actor does not have a sword equipped,
  23.  * the skill will not be useable.)
  24.  *
  25.  * When creating Confusion states, you can use the tag
  26.  *
  27.  * <charm>
  28.  *
  29.  * When used, friendly and offensive skills will be totally reversed.
  30.  * In other words, a "charmed" enemy will NEVER use a heal spell on another enemy.
  31.  * Note that charmed states will take presidance over regular confusion states.
  32.  * Also, direct user skills will still target ONLY the user.
  33.  */
  34.  
  35.  var MalCControlDatabaseLoad = DataManager.isDatabaseLoaded;
  36. DataManager.isDatabaseLoaded = function() {
  37.   if (!MalCControlDatabaseLoad.call(this)) return false;
  38.   if (!DataManager._malCControl_DatabaseLoaded) {
  39.     this.processCControlNotetags($dataActors);
  40.     this.processCControlNotetags($dataEnemies);
  41.     this.processCControlNotetags($dataClasses);
  42.     DataManager._malCControl_DatabaseLoaded = true;
  43.   }
  44.   return true;
  45. };
  46.  
  47. DataManager.processCControlNotetags = function(group) {
  48.     for (var n = 1; n < group.length; n++) {
  49.         var obj = group[n];
  50.         if(!obj) continue;
  51.         obj.conAttacks = [];
  52.         var noteread = obj.note;
  53.         while(noteread.indexOf("conAttacks") > -1) {
  54.             var match = noteread.split("<conAttacks: ");
  55.             var match2 = match[1].split(">");
  56.             var match3 = match2[0].split(",");
  57.             for(var cc = 0; cc < match3.length; cc++) {
  58.                 obj.conAttacks.push(parseInt(match3[cc]));
  59.             }
  60.             noteread = noteread.replace("<conAttacks:", " ");
  61.         };
  62.     };
  63. };
  64.  
  65.  
  66. Game_Action.prototype.setConfusion = function() {
  67.     this.setConfAttack();
  68. };
  69.  
  70. Game_Action.prototype.setConfAttack = function() {
  71.     var skills = [];
  72.     var skill = 0;
  73.     if(this.subject().isActor()) {
  74.         skills = this.subject().currentClass().conAttacks;
  75.         skills = skills.concat($dataActors[this.subject()._actorId].conAttacks);
  76.         var skillset = this.subject().usableSkills();
  77.         for (var ii = 0; ii < skillset.length; ii++){
  78.             if(this.subject().addedSkillTypes().includes(skillset[ii].stypeId)) skills.push(skillset[ii].id);
  79.         };
  80.     } else {
  81.         skills = skills.concat($dataEnemies[this.subject()._enemyId].conAttacks);
  82.     }
  83.     skill = skills[Math.randomInt(skills.length)];
  84.     if (skills.length > 0) {
  85.         this.setSkill(skill);
  86.     } else {
  87.         this.setSkill(this.subject().attackSkillId());
  88.     }
  89. };
  90.  
  91. Game_Action.prototype.makeTargets = function() {
  92.     const targets = [];
  93.     if (!this._forcing && this.subject().isConfused() && !this.subject().isCharmed()) {
  94.         targets.push(this.confusionTarget());
  95.     } else if (this.isForEveryone()) {
  96.         targets.push(...this.targetsForEveryone());
  97.     } else if (this.isForOpponent()) {
  98.         targets.push(...this.targetsForOpponents());
  99.     } else if (this.isForFriend()) {
  100.         targets.push(...this.targetsForFriends());
  101.     }
  102.     return this.repeatTargets(targets);
  103. };
  104.  
  105. Game_Action.prototype.confusionTarget = function() {
  106.     if (this.isForUser()) return this.subject();
  107.     switch (this.subject().confusionLevel()) {
  108.         case 1:
  109.             return this.opponentsUnit().randomTarget();
  110.         case 2:
  111.             if (Math.randomInt(2) === 0) {
  112.                 return this.opponentsUnit().randomTarget();
  113.             }
  114.             return this.friendsUnit().randomTarget();
  115.         default:
  116.             return this.friendsUnit().randomTarget();
  117.     }
  118. };
  119.  
  120. Game_Actor.prototype.friendsUnit = function() {
  121.     if (this.isCharmed()) return $gameTroop;
  122.     return $gameParty;
  123. };
  124. Game_Actor.prototype.opponentsUnit = function() {
  125.     if (this.isCharmed()) return $gameParty;
  126.     return $gameTroop;
  127. };
  128. Game_Enemy.prototype.friendsUnit = function() {
  129.     if (this.isCharmed()) return $gameParty;
  130.     return $gameTroop;
  131. };
  132. Game_Enemy.prototype.opponentsUnit = function() {
  133.     if (this.isCharmed()) return $gameTroop;
  134.     return $gameParty;
  135. };
  136.  
  137. Game_BattlerBase.prototype.isCharmed = function() {
  138.     var states = this.states();
  139.     for (i = 0; i < states.length; i++) {
  140.         if(states[i].meta.charm) return true;
  141.     };
  142.     return false;
  143. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement