Advertisement
Guest User

Untitled

a guest
Apr 30th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2.  /*:
  3.  * @plugindesc v1.00; This plugin provides the ability to catch enemies. See help for more information.
  4.  * @author FlipelyFlip
  5.  *
  6.  * @param Base Catch Rate
  7.  * @desc Base Catch Rate is used, when an enemy has no Catch Rate assigned. Default: 45
  8.  * @default 45
  9.  *
  10.  * @param Caught Text
  11.  * @desc Text, which will be shown, when an enemy is caught. %1 = Enemy Name
  12.  * @default Gotcha! %1 was caught.
  13.  *
  14.  * @param Fail Text
  15.  * @desc Text, which will be shown, when an enemy is not caught. %1 = Enemy Name
  16.  * @default Shoot! It was so close!
  17.  *
  18.  * @param Miss Text
  19.  * @desc Text, which will be shown, when an enemy is missed. %1 = Enemy Name
  20.  * @default Darn! I missed %1.
  21.  *
  22.  * @help
  23.  * With this plugin, you can add the possibility to catch enemies and add them
  24.  * to your party.
  25.  * But to make it work properly, you have to define an actor as a base. This
  26.  * is needed, so that the enemy has a specific class, exp table, skills and
  27.  * so on. This will be changed for future plugins. But currently it's easier
  28.  * for you to work this way.
  29.  *
  30.  * You can catch an enemy via item or skill. You can define custom modifiers
  31.  * for your skills and items. You can also add JavaScript statements to it
  32.  * if you want to. There are several notetags available.
  33.  *
  34.  * I used the catch formula from Pokémon for this plugin, so every value above
  35.  * 765 will result in an instant catch, if every other modification is at least
  36.  * 1.0 or higher and the HP full.
  37.  *
  38.  * When an enemy is caught, the newly gained actor will have the enemy's hp, mp
  39.  * and state changes. If used together with my FFP_BaseStats and my
  40.  * FFP_EnemyLevels, the newly gained actor will also get the enemy's iv and
  41.  * level.
  42.  *
  43.  *=============================================================================
  44.  *   *  Possible Notetags (not case-sensitive)
  45.  *=============================================================================
  46.  * Enemies:
  47.  * ----------------------------------------------------------------------------
  48.  * <catch rate: x>
  49.  * x = defines how hard/easy an enemy is to catch.
  50.  * The higher the number, the easier to catch.
  51.  *
  52.  * <actor fix: x>
  53.  * x = The ID of the actor to which it will be fixed.
  54.  * Catching the same enemy over and over again results in multiple copies of
  55.  * the actor.
  56.  *
  57.  * <catch rate eval>
  58.  * code
  59.  * </catch rate eval>
  60.  * with these 2 notetags you can set the catch rate to be everything you
  61.  * want as long as it's any JavaScript statement. The result will be added to
  62.  * the other catch rate if used.
  63.  *
  64.  * Skills & Items:
  65.  * ----------------------------------------------------------------------------
  66.  * <masterball>
  67.  * defines an item or skill as masterball and makes it so that it's always a
  68.  * successes.
  69.  *
  70.  * <catch modifier: x.f>
  71.  * x.f = the modifier rate. It is a float number.
  72.  *
  73.  * <catch modifier eval>
  74.  * code
  75.  * </catch modifier eval>
  76.  * with these 2 notetags you can set the catch modifier to be everything you
  77.  * want as long as it's any JavaScript statement.The result will be added to
  78.  * the other notetag if used.
  79.  *
  80.  * States:
  81.  * ----------------------------------------------------------------------------
  82.  * <catch modifier: x.f>
  83.  * x.f = the modifier rate. It is a float number.
  84.  *
  85.  * <catch modifier eval>
  86.  * code
  87.  * </catch modifier eval>
  88.  * with these 2 notetags you can set the catch modifier to be everything you
  89.  * want as long as it's any JavaScript statement. The result will be added to
  90.  * the other notetag if used.
  91.  *
  92.  *=============================================================================
  93.  *   *  CatchSuccess Calculation
  94.  *=============================================================================
  95.  * The current formula used for the CatchSuccess Calculation is this one:
  96.  *
  97.  * (3 * maxHP - 2 * curHp) * rate * bonusBall
  98.  * ------------------------------------------ * bonusStatus = valueA
  99.  *             3 * maxHP
  100.  *
  101.  * If the resulted Value is greater than 255, then it's a sure catch. If not,
  102.  * this formula will apply:
  103.  *
  104.  * 0x000FFFF0 / SquareRoot( SquareRoot( 0x00FF0000 / valueA))) = valueB
  105.  *
  106.  * valueB will be checked 4 times with a random generated number between
  107.  * 0 and 65536. If valueB is greater than the randomized number, it means
  108.  * the ball would shake once. If it passes all 4 checks, the enemy will
  109.  * be caught.
  110.  *
  111.  * This is the actual CatchSuccess Calculation as it is used in the Pokémon
  112.  * Games.
  113.  *
  114.  *
  115.  *
  116.  */
  117. //=============================================================================
  118.  
  119. var Imported = Imported || {};
  120. Imported.FFP_CatchEnemies = true;
  121.  
  122. var FFP = FFP || {};
  123. FFP.CatchEnemies = FFP.CatchEnemies || {};
  124. FFP.CatchEnemies.Parameter = PluginManager.parameters('FFP_CatchEnemies');
  125.  
  126. //=============================================================================
  127. // Saves the dataActors data
  128. //=============================================================================
  129. FFP.CatchEnemies.makeSaveContents = DataManager.makeSaveContents;
  130. DataManager.makeSaveContents = function() {
  131.     var contents = FFP.CatchEnemies.makeSaveContents.call(this);
  132.     contents.dataActors   = $dataActors;
  133.     return contents;
  134. };
  135.  
  136. //=============================================================================
  137. // Loads the dataActors data
  138. //=============================================================================
  139. FFP.CatchEnemies.extractSaveContents = DataManager.extractSaveContents;
  140. DataManager.extractSaveContents = function(contents) {
  141.     FFP.CatchEnemies.extractSaveContents.call(this, contents);
  142.     $dataActors        = contents.dataActors;
  143. };
  144.  
  145. //=============================================================================
  146. // Loads the Notetags for Enemies, Skills, Items and States
  147. //=============================================================================
  148. FFP.CatchEnemies.isDatabaseLoaded = DataManager.isDatabaseLoaded;
  149. DataManager.isDatabaseLoaded = function() {
  150.     if (!FFP.CatchEnemies.isDatabaseLoaded.call(this)) return false;
  151.     this.getFfpEnemyNotetags($dataEnemies);
  152.     this.getFfpLunaticNotetags($dataSkills);
  153.     this.getFfpLunaticNotetags($dataItems);
  154.     this.getFfpLunaticStateNotetags($dataStates);
  155.     return true;
  156. };
  157.  
  158. //=============================================================================
  159. // Used for Notetags for Enemies
  160. //=============================================================================
  161. DataManager.getFfpEnemyNotetags = function(group) {
  162.     var noteCatchRate = /<(?:CATCH RATE):[ ](\d+)>/i;
  163.     var noteActorFix = /<(?:ACTOR FIX):[ ](\d+)>/i;
  164.     var noteCatchEval1 = /<(?:CATCH RATE EVAL)>/i;
  165.     var noteCatchEval2 = /<\/(?:CATCH RATE EVAL)>/i;
  166.     for (var n = 1; n < group.length; n++) {
  167.         var obj = group[n];
  168.         var notedata = obj.note.split(/[\r\n]+/);
  169.         obj.catchRate = FFP.CatchEnemies.Parameter['Base Catch Rate'];
  170.         obj.actorFix = -1;
  171.         obj.customRateEval = '';
  172.         var mode = '';
  173.         for (var i = 0; i < notedata.length; i++) {
  174.             var line = notedata[i];
  175.             if (line.match(noteCatchRate)) {
  176.                 obj.catchRate = parseInt(RegExp.$1);
  177.             } else if (line.match(noteActorFix)) {
  178.                 obj.actorFix = parseInt(RegExp.$1);
  179.             } else if (line.match(noteCatchEval1)) {
  180.                 mode = 'in';
  181.             } else if (line.match(noteCatchEval2)) {
  182.                 mode = '';
  183.             } else if (mode === 'in') {
  184.                 obj.customRateEval = obj.customRateEval + line + '\n';
  185.             };
  186.         };
  187.     };
  188. };
  189.  
  190. //=============================================================================
  191. // Used for Notetags from Items and Skills
  192. //=============================================================================
  193. DataManager.getFfpLunaticNotetags = function(group) {
  194.     var noteCatchModEval1 = /<(?:CATCH MODIFIER EVAL)>/i;
  195.     var noteCatchModEval2 = /<\/(?:CATCH MODIFIER EVAL)>/i;
  196.     var noteCatchModifier = /<(?:CATCH MODIFIER):[ ](\d+(\.\d+))>/i;
  197.     var noteMasterball = /<(?:MASTERBALL)>/i;
  198.     for (var n = 1; n < group.length; n++) {
  199.         var obj = group[n];
  200.         var notedata = obj.note.split(/[\r\n]+/);
  201.         var mode = '';
  202.         obj.customCatchMod = '';
  203.         obj.catchMod = 0.0;
  204.         obj.catchItem = false;
  205.         obj.masterball = false;
  206.         for (var i = 0; i < notedata.length; i++) {
  207.             var line = notedata[i];
  208.             if (line.match(noteCatchModifier)) {
  209.                 obj.catchMod = parseFloat(RegExp.$1);
  210.                 obj.catchItem = true;
  211.             } else if (line.match(noteMasterball)) {
  212.                 obj.masterball = true;
  213.                 obj.catchItem = true;
  214.             } else if (line.match(noteCatchModEval1)) {
  215.                 mode = 'in';
  216.                 obj.catchItem = true;
  217.             } else if (line.match(noteCatchModEval2)) {
  218.                 mode = '';
  219.             } else if (mode === 'in') {
  220.                 obj.customCatchMod = obj.customCatchMod + line + '\n';
  221.             };
  222.         };
  223.     };
  224. };
  225.  
  226. //=============================================================================
  227. // Used the Notetags from States
  228. //=============================================================================
  229. DataManager.getFfpLunaticStateNotetags = function(group) {
  230.     var noteCatchModEval1 = /<(?:CATCH MODIFIER EVAL|catch modifier eval)>/i;
  231.     var noteCatchModEval2 = /<\/(?:CATCH MODIFIER EVAL|catch modifier eval)>/i;
  232.     var noteCatchModifier = /<(?:CATCH MODIFIER):[ ](\d+(\.\d+))>/i;
  233.     for (var n = 1; n < group.length; n++) {
  234.         var obj = group[n];
  235.         var notedata = obj.note.split(/[\r\n]+/);
  236.         var mode = '';
  237.         obj.customCatchMod = '';
  238.         obj.catchMod = 0.0;
  239.         for (var i = 0; i < notedata.length; i++) {
  240.             var line = notedata[i];
  241.             if (line.match(noteCatchModifier)) {
  242.                 obj.catchMod = parseFloat(RegExp.$1);
  243.             } else if (line.match(noteCatchModEval1)) {
  244.                 mode = 'in';
  245.             } else if (line.match(noteCatchModEval2)) {
  246.                 mode = '';
  247.             } else if (mode === 'in') {
  248.                 obj.customCatchMod = obj.customCatchMod + line + '\n';
  249.             };
  250.         };
  251.     };
  252. };
  253.  
  254. //=============================================================================
  255. // Checks if the item is an Item for catching
  256. //=============================================================================
  257. Game_Action.prototype.isCatching = function() {
  258.     return this.item().catchItem;
  259. };
  260.  
  261. //=============================================================================
  262. // Used to see, if the action is able to catch an enemy
  263. //=============================================================================
  264. FFP.CatchEnemies.actionApply = Game_Action.prototype.apply;
  265. Game_Action.prototype.apply = function(target) {
  266.     FFP.CatchEnemies.actionApply.call(this, target);
  267.     console.log(this);
  268.     if (this.isCatching() && target.isEnemy() && target.enemy().actorFix > 1) {
  269.         BattleManager.catching(target, this.item());
  270.     };
  271. };
  272.  
  273. //=============================================================================
  274. // Used for the catching sequence
  275. //=============================================================================
  276. BattleManager.catching = function(target, item) {
  277.     this._logWindow.catchingEnemy();
  278.     var shakes = target.catching(item);
  279.     if (shakes === 4) {
  280.         this._logWindow.catchingEnemySuccessfull();
  281.         var names = FFP.CatchEnemies.Parameter['Caught Text'];
  282.         var text = names.format(target.name());
  283.         this._logWindow.push('addText', text);
  284.         $dataActors.push($dataActors[target.enemy().actorFix]);
  285.         $gameParty.addActor($dataActors.length-1);
  286.         target.changeActor($gameParty.allMembers()[$gameParty.allMembers().length-1]);
  287.         target.hide();
  288.     };
  289. };
  290.  
  291. //=============================================================================
  292. // Used to calculate if the enemy is caught
  293. //=============================================================================
  294. Game_Enemy.prototype.catching = function(item) {
  295.     if (item.masterball) {return 4;};
  296.     if (this.enemy().actorFix < 1) { return 0;};
  297.     var hpMax = this.mhp;
  298.     var hpCurr = this.hp
  299.     var value = parseFloat(eval(item.customCatchMod));
  300.     if (isNaN(value)) { value = 0.0; };
  301.     var bonusBall = item.catchMod + value;
  302.     var bonusStatus = 0.0;
  303.     var rate = this.enemy().catchRate;
  304.     var evalRate = eval(this.enemy().customRateEval);
  305.     if (isNaN(evalRate)) { evalRate = 0; };
  306.     rate += evalRate;
  307.     for (var i = 0; i < this._states.length; i++) {
  308.         var mValue = parseFloat($dataStates[this._states[i]].catchMod);
  309.         if (isNaN(mValue)) { mValue = 0.0; };
  310.         bonusStatus += mValue;
  311.         var nValue = parseFloat(eval($dataStates[this._states[i]].customCatchmod));
  312.         if (isNaN(nValue)) { nValue = 0.0; };
  313.         bonusStatus += nValue;
  314.     };
  315.     if (bonusStatus === 0.0) { bonusStatus = 1.0; };
  316.     var valueA = ((((3 * hpMax - 2 * hpCurr) * rate * bonusBall) / (3 * hpMax)) * bonusStatus);
  317.     valueA = Math.floor(valueA);
  318.     var valueB = 0x000FFFF0/(Math.sqrt(Math.sqrt(0x00FF0000/valueA)));
  319.     valueB = Math.floor(valueB);
  320.     var shakes = 4;
  321.     if (valueA < 255) {
  322.         shakes = 0;
  323.         if (valueA === 0) { valueA = 1; };
  324.         for(var i=0; (i < 4) && (shakes === i); i++) {
  325.             var rand = Math.random() * 65536;
  326.             if (rand < valueB) {
  327.                 shakes++;
  328.             };
  329.         };
  330.     };
  331.     return shakes;
  332. };
  333.  
  334. //=============================================================================
  335. // Changes Data from an Actor to the enemy data
  336. //=============================================================================
  337. Game_Enemy.prototype.changeActor = function(actor) {
  338.     if (Imported.FFP_PokemonBaseStats) {
  339.         actor._iv = this._iv;
  340.     };
  341.     if (Imported.FFP_EnemyLevels) {
  342.         actor.changeLevel(this.enemy().level, false);
  343.     };
  344.     actor.setHp(this.hp);
  345.     actor.setMp(this.mp);
  346.     actor.setTp(this.tp);
  347.     actor._states = this._states;
  348.     actor._stateTurns = this._stateTurns;
  349. };
  350.  
  351. //=============================================================================
  352. // sets the Actor HP to the given Value
  353. //=============================================================================
  354. Game_Actor.prototype.setHp = function(value) {
  355.     this._hp = value;
  356. };
  357.  
  358. //=============================================================================
  359. // sets the Actor MP to the given Value
  360. //=============================================================================
  361. Game_Actor.prototype.setMp = function(value) {
  362.     this._mp = value;
  363. };
  364.  
  365. //=============================================================================
  366. // sets the Actor TP to the given Value
  367. //=============================================================================
  368. Game_Actor.prototype.setTp = function(value) {
  369.     this._tp = value;
  370. };
  371.  
  372. //=============================================================================
  373. // Used for the Catch Messages.
  374. //=============================================================================
  375. FFP.CatchEnemies.catchInitialize = Window_BattleLog.prototype.initialize;
  376. Window_BattleLog.prototype.initialize = function() {
  377.     FFP.CatchEnemies.catchInitialize.call(this);
  378.     this._catchAttempt = false;
  379.     this._catchAttemptSuccessfull = false;
  380. };
  381.  
  382. //=============================================================================
  383. // Displays the Miss Message
  384. //=============================================================================
  385. Window_BattleLog.prototype.displayMiss = function(target) {
  386.     if (!this.catchAttempt()) {
  387.         var fmt;
  388.         if (target.result().physical) {
  389.             fmt = target.isActor() ? TextManager.actorNoHit : TextManager.enemyNoHit;
  390.             this.push('performMiss', target);
  391.         } else {
  392.             fmt = TextManager.actionFailure;
  393.         };
  394.     } else {
  395.         fmt = FFP.CatchEnemies.Parameter['Miss Text'];
  396.     };
  397.     this.push('addText', fmt.format(target.name()));
  398.     this._catchAttempt = false;
  399. };
  400.  
  401. //=============================================================================
  402. // displays the Failure Message (used, if no Damage is dealt)
  403. //=============================================================================
  404. Window_BattleLog.prototype.displayFailure = function(target) {
  405.     if (!this.catchAttempt() && !this.catchAttemptSuccessfull()) {
  406.         if (target.result().isHit() && !target.result().success) {
  407.             this.push('addText', TextManager.actionFailure.format(target.name()));
  408.         }
  409.     } else if (this.catchAttempt() && !this.catchAttemptSuccessfull()) {
  410.         var fmt = FFP.CatchEnemies.Parameter['Fail Text'];
  411.         this.push('addText', fmt.format(target.name()));
  412.     };
  413.     this._catchAttempt = false;
  414.     this._catchAttemptSuccessfull = false;
  415. };
  416.  
  417. //=============================================================================
  418. // Returns the value of this._catchAttempt
  419. //=============================================================================
  420. Window_BattleLog.prototype.catchAttempt = function() {
  421.     return this._catchAttempt;
  422. };
  423.  
  424. //=============================================================================
  425. // Sets the value of this._catchAttempt to true
  426. //=============================================================================
  427. Window_BattleLog.prototype.catchingEnemy = function() {
  428.     this._catchAttempt = true;
  429. };
  430.  
  431. //=============================================================================
  432. // Returns the value of this._catchAttemptSuccessfull
  433. //=============================================================================
  434. Window_BattleLog.prototype.catchAttemptSuccessfull = function() {
  435.     return this._catchAttemptSuccessfull;
  436. };
  437.  
  438. //=============================================================================
  439. // Sets the value of this._catchAttemptSuccessfull to true
  440. //=============================================================================
  441. Window_BattleLog.prototype.catchingEnemySuccessfull = function() {
  442.     this._catchAttemptSuccessfull = true;
  443. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement