Advertisement
Maliki79

MalPermadeath

Feb 7th, 2019
1,674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Maliki's Permadeath
  3. // MalPermadeath.js
  4. // version 1.2
  5. //=============================================================================
  6. /*:  
  7.  * @plugindesc Version 1.2 Allows you to render save files unusable upon
  8.  * Game Over.
  9.  * @author Maliki79
  10.  * @help
  11.  * After installing this plugin, use the script call
  12.  * $gameSystem.enablePermadeath();
  13.  * to activate.  After making the call, saves will be treated
  14.  * as permadeath or ironman saves.
  15.  * What this means is that basically only one "current" save can be used for a
  16.  * game's playthrough.
  17.  * If the player attempts to make a subsequent save on a different slot, the
  18.  * original save with no loger load.
  19.  * Also, quitting a game mid-battle or on a Game Over will also not allow
  20.  * that current session's saves to be used.
  21.  *
  22.  * If a new game is started with saves from an old playthrough still present,
  23.  * those saves WILL still be active and usable.
  24.  *
  25.  * As of version 1.2 of this plugin, script calls were added to enable and
  26.  * disable this plugin.
  27.  *
  28.  * $gameSystem.enablePermadeath();
  29.  * Turns on funtionality of this plugin.
  30.  *
  31.  * $gameSystem.disablePermadeath();
  32.  * Turns off functionality of this plugin.
  33.  */
  34.  
  35. var Mal_Config_PDMakeData = ConfigManager.makeData;
  36. ConfigManager.makeData = function() {
  37.     var config = Mal_Config_PDMakeData.call(this);
  38.     config.saveCheck = this.saveCheck || [];   
  39.     return config;
  40. };
  41.  
  42. var Mal_PDConfig_applyData = ConfigManager.applyData;
  43. ConfigManager.applyData = function(config) {
  44.     Mal_PDConfig_applyData.call(this, config);
  45.     this.saveCheck = this.readSaveCheck(config, 'saveCheck');
  46. };
  47.  
  48. ConfigManager.readSaveCheck = function(config, name) {
  49.     var value = config[name];
  50.     if (value !== undefined) {
  51.         return value;
  52.     } else {
  53.         return 0;
  54.     }
  55. }; 
  56.  
  57. ConfigManager.makeSaveCheck = function(saveCheck) {
  58.     var saveNum = saveCheck;
  59.     if (!this.saveCheck) this.saveCheck = [];
  60.     for(i = 0; i < this.saveCheck.length; i++) {
  61.         var save = this.saveCheck[i];
  62.         if(save[0] == $gameSystem._saveId) {
  63.             save[1] = saveNum;
  64.             ConfigManager.save();
  65.             return;
  66.         }
  67.     }
  68.     this.saveCheck.push([$gameSystem._saveId, saveNum])
  69.     ConfigManager.save();
  70. };
  71.  
  72. var Mal_DBSNG = DataManager.setupNewGame;
  73. DataManager.setupNewGame = function() {
  74.     Mal_DBSNG.call(this);
  75.     $gameSystem._saveId = (Math.randomInt(10000000) + 1);
  76.     $gameSystem._bonuszZ = 0;
  77.     ConfigManager.save();
  78. };
  79.  
  80. Game_System.prototype.enablePermadeath = function() {
  81.     $gameSystem._bonuszZ = 1;
  82. };
  83.  
  84. Game_System.prototype.disablePermadeath = function(file) {
  85.     if(!file) {
  86.         $gameSystem._bonuszZ = 0;
  87.     } else if(file > 0) {
  88.         var globalInfo = DataManager.loadGlobalInfo();
  89.         globalInfo[file].saveCheck[2] = 0;
  90.     };
  91. };
  92.  
  93. var Mal_PDonBeforeSave = Game_System.prototype.onBeforeSave;
  94. Game_System.prototype.onBeforeSave = function() {
  95.     Mal_PDonBeforeSave.call(this);
  96.     if (!BattleManager.isBattleTest()) {
  97.         this._saveCheck = (Math.randomInt(10000000) + 1);
  98.         ConfigManager.makeSaveCheck(this._saveCheck);
  99.     };
  100. };
  101.  
  102. var Mal_PDonBattleStart = Game_System.prototype.onBattleStart;
  103. Game_System.prototype.onBattleStart = function() {
  104.     Mal_PDonBattleStart.call(this);
  105.     ConfigManager.makeSaveCheck(0);
  106. };
  107.  
  108. var Mal_PDupdateBE = BattleManager.updateBattleEnd;
  109. BattleManager.updateBattleEnd = function() {
  110.     Mal_PDupdateBE.call(this);
  111.     if (!this._escaped && $gameParty.isAllDead()) {
  112.         if (this._canLose) {
  113.             ConfigManager.makeSaveCheck($gameSystem._saveCheck);
  114.         };
  115.     };
  116. };
  117.  
  118. var Mal_PDBM_processVictory = BattleManager.processVictory;
  119. BattleManager.processVictory = function() {
  120.     Mal_PDBM_processVictory.call(this);
  121.     ConfigManager.makeSaveCheck($gameSystem._saveCheck);
  122. };
  123.  
  124. var Mal_PDBM_processAbort = BattleManager.processAbort;
  125. BattleManager.processAbort = function() {
  126.     ConfigManager.makeSaveCheck($gameSystem._saveCheck);
  127.     Mal_PDBM_processAbort.call(this);
  128. };
  129.  
  130. var MalDataManager_makeSavefileInfo = DataManager.makeSavefileInfo;
  131.   DataManager.makeSavefileInfo = function() {
  132.     var info = MalDataManager_makeSavefileInfo.call(this);
  133.     if(!info.saveCheck)info.saveCheck = [];
  134.     info.saveCheck = [$gameSystem._saveId, $gameSystem._saveCheck, $gameSystem._bonuszZ];
  135.    
  136.     var fs = require('fs');
  137.     var pathCon = StorageManager.localFileDirectoryPath() + 'config.rpgsave';
  138.     var timeCon = fs.statSync(pathCon);
  139.     if (!info.saveKey) info.saveKey = timeCon.atimeMs;
  140.    
  141.     return info
  142.   };
  143.  
  144. DataManager.isThisGameFile = function(savefileId) {
  145.     var globalInfo = this.loadGlobalInfo();
  146.     var fs = require('fs');
  147.     var pathCon = StorageManager.localFileDirectoryPath() + 'config.rpgsave';
  148.     var timeCon = fs.statSync(pathCon);
  149.     if (globalInfo[savefileId] && globalInfo[savefileId].saveKey) {
  150.         if(timeCon.atimeMs != globalInfo[savefileId].saveKey && globalInfo[savefileId].saveCheck[2] != 1) return false;
  151.     };
  152.     if (globalInfo && globalInfo[savefileId]) {
  153.         if (StorageManager.isLocalMode()) {
  154.         if(globalInfo[savefileId].saveCheck && this.globalMatch(globalInfo[savefileId].saveCheck, globalInfo[savefileId].saveCheck[2])) return true;
  155.         } else {
  156.             var savefile = globalInfo[savefileId];
  157.             return (savefile.globalId === this._globalId &&
  158.                     savefile.title === $dataSystem.gameTitle);
  159.         }
  160.     } else {
  161.         return false;
  162.     }
  163. };
  164.  
  165. DataManager.globalMatch = function(gSaveCheck, bypass) {
  166. if(!gSaveCheck) return false;
  167. if (bypass == 0) return true;
  168.     for(i = 0; i < ConfigManager.saveCheck.length; i++) {
  169.         var save = ConfigManager.saveCheck[i];
  170.         if(save[0] == gSaveCheck[0]) {
  171.             if (save[1] == gSaveCheck[1]) {
  172.                 return true;
  173.             } else {
  174.                 return false;
  175.             }
  176.             ConfigManager.save();
  177.             return false;
  178.         }
  179.     }
  180. return true;
  181. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement