SHARE
TWEET

Untitled

a guest Dec 1st, 2015 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // SilvStamina.js
  3. // Version: 1.01
  4. //=============================================================================
  5. /*:
  6.  * @plugindesc v1.01 Basic dashing stamina script.
  7.    <SilverStamina>
  8.  * @author Silver
  9.  *
  10.  * @param -- General --
  11.  *
  12.  * @param Show Stamina Window
  13.  * @desc true/false
  14.  * @default true
  15.  *
  16.  * @param -- Positioning & Size --
  17.  *
  18.  * @param Window X
  19.  * @desc X-location of stamina window. If window-alignment is set to Right, this will act as an offset value instead
  20.  * @default 10
  21.  *
  22.  * @param Window Y
  23.  * @desc Y-location of stamina window. If window-alignment is set to Top, this will act as an offset value instead
  24.  * @default 10
  25.  *
  26.  * @param Window Width
  27.  * @desc width of the stamina window
  28.  * @default 170
  29.  *
  30.  * @param Window Height
  31.  * @desc height of the stamina window
  32.  * @default 72
  33.  *
  34.  * @param Window Horizontal Alignment
  35.  * @desc Left/Right
  36.  * @default Left
  37.  *
  38.  * @param Window Vertical Alignment
  39.  * @desc Top/Bottom
  40.  * @default Top
  41.  *
  42.  * @param Stamina Gauge Rectangle
  43.  * @desc The gauge rectangle. Format: x y width height
  44.  * @default 0 -20 132 24
  45.  *
  46.  * @param -- Stamina Pool --
  47.  *
  48.  * @param Stamina Decrease
  49.  * @desc Amount of stamina subtracted per update (use a positive number)
  50.  * @default 1
  51.  *
  52.  * @param Stamina Max
  53.  * @desc Maximum amount of stamina
  54.  * @default 300
  55.  *
  56.  * @param Stamina Recovery Delay
  57.  * @desc delay in update-calls before recovering stamina when not dashing
  58.  * @default 180
  59.  *
  60.  * @param Stamina Recovery Rate
  61.  * @desc How fast stamina is recovered (only when recovering)
  62.  * @default 0.3
  63.  *
  64.  * @param Stamina AutoDash Threshold
  65.  * @desc Do not automatically dash again before stamina is above this threshold (%) when recovering stamina. (0-100)
  66.  * @default 40
  67.  *
  68.  * @param Stamina Regen Formula
  69.  * @desc The formula for how fast to regenerate stamina over longer period of time. "Base" is the recovery rate. Case sensitive!
  70.  * @default base + Math.sqrt(x/50);
  71.  *
  72.  * @param -- Visuals --
  73.  *
  74.  * @param Stamina Gauge Color 1
  75.  * @desc Bar gradient color1 (start of bar) in hex
  76.  * @default #009900
  77.  *
  78.  * @param Stamina Gauge Color 2
  79.  * @desc Bar gradient color2 (end of bar) in hex
  80.  * @default #CC0000
  81.  *
  82.  * @param Draw Stamina Value
  83.  * @desc Draw text in stamina bar? Accepted values: absolute/percentage/both/none
  84.  * @default percentage
  85.  *
  86.  * @param Font Size
  87.  * @desc Size for stamina value
  88.  * @default 20
  89.  *
  90.  * @param Auto Hide Stamina Window
  91.  * @desc Automatically hide the stamina window if it's at max stamina for a specific period of time? true/false
  92.  * @default true
  93.  *
  94.  * @param -- Window --
  95.  *
  96.  * @param Hide Stamina Window Delay
  97.  * @desc After how many updates the stamina window should hide itself (if it remains at max stamina)
  98.  * @default 160
  99.  *
  100.  * @param Stamina Window Opacity
  101.  * @desc Stamina window opacity. Set to 0 to hide the window (will still show the bar).
  102.  * @default 255
  103.  *
  104.  * @param Window Slideout Direction
  105.  * @desc What direction to slide the stamina window out to. NoSlide/Left/Top/Right/Bottom
  106.  * @default Left
  107.  *
  108.  * @param Window Slideout Speed
  109.  * @desc How fast the window slides in&out
  110.  * @default 2
  111.  *
  112.  * @param -- Advanced --
  113.  *
  114.  * @param Disable Stamina Consumption GameSwitch
  115.  * @desc The gameswitch to use to disable stamina consumption (or -1 to use none). ON = disabled.
  116.  * @default -1
  117.  *
  118.  * @param Window Z-Index
  119.  * @desc Window Z-Index. Value must be > 0.
  120.  * @default 1
  121.  *
  122.  * @param Plugin Command Identifier
  123.  * @desc Do not change if you do not know what this is!
  124.  * @default stamina
  125.  *
  126.  * @help
  127.  * -------------------------------------
  128.  * Plugin Commands (not case sensitive):
  129.  * -------------------------------------
  130.  *
  131.  * Stamina Refill
  132.  * Instantly refills all of your stamina.
  133.  *
  134.  * Stamina Set <value>
  135.  * Instantly sets your stamina to the specified percentage (0-100).
  136.  * Example to set your stamina bar to 64: Stamina Set 64
  137.  *
  138.  * Stamina Deplete
  139.  * Instantly sets your stamina to 0.
  140.  *
  141.  * Stamina ShowWindow
  142.  * Shows the stamina window. Does not work if you disabled the stamina window.
  143.  *
  144.  * Stamina HideWindow
  145.  * Hides the stamina window. Does not work if you disabled the stamina window.
  146.  * Also does not work if the stamina is currently regenerating.
  147.  *
  148.  * Stamina RefillHide
  149.  * Instantly refills all of your stamina and also hides the stamina window.
  150.  *
  151.  * Stamina SetMax <value>
  152.  * Sets a new max-stamina value.
  153.  *
  154.  * Stamina IncreaseMax <value>
  155.  * Increases max stamina by the specified value. You can also use negative values.
  156.  * -------------------------------------
  157.  * Map notetags
  158.  * -------------------------------------
  159.  *
  160.  * <dstam_disable>
  161.  * Prevents stamina consumption on this map. Not that if the "Disable Stamina Consumption GameSwitch"
  162.  * is turned ON then you consume no stamina anyway.
  163.  *
  164.  *
  165.  *--------------------------------------
  166.  * Version History:
  167.  *--------------------------------------
  168.  *
  169.  * v1.01 (1 December 2015)
  170.  *   - Removed strict-mode because... Possible bug in RPG Maker...
  171.  *   - Refactored and fixed semicolons and missing var-keywords.
  172.  * v1.00 (26 November 2015)
  173.  *   - First release.
  174.  * Alpha (November 2015)
  175.  *   - First alpha release.
  176.  *
  177.  */
  178.  // Enable strict mode
  179. //"use strict";
  180.  
  181. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  182. // #Parameters
  183. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  184. var Silv = Silv || {};
  185. Silv.Plugins = Silv.Plugins || {};
  186. Silv.Plugins.DashStamina = 1.01;
  187. Silv.Parameters = $plugins.filter(function(p) { return p.description.contains('<SilverStamina>'); })[0].parameters;
  188. Silv.DashStamina = Silv.DashStamina || {};
  189. // Non-parameters
  190. Silv.DashStamina.Window = null;
  191. Silv.DashStamina.ScreenIsFading = false;
  192. // General
  193. Silv.DashStamina.ShowWindow = Silv.Parameters['Show Stamina Window'].toLowerCase() == 'true';
  194. // Positioning & Size
  195. Silv.DashStamina.Window_X = parseInt(Silv.Parameters['Window X']);
  196. Silv.DashStamina.Window_Y = parseInt(Silv.Parameters['Window Y']);
  197. Silv.DashStamina.WindowWidth = parseInt(Silv.Parameters['Window Width']);
  198. Silv.DashStamina.WindowHeight = parseInt(Silv.Parameters['Window Height']);
  199. Silv.DashStamina.WindowHorizontalAlignment = (Silv.Parameters['Window Horizontal Alignment']).toLowerCase();
  200. Silv.DashStamina.WindowVerticalAlignment = (Silv.Parameters['Window Vertical Alignment']).toLowerCase();
  201. Silv.DashStamina.StaminaGaugeRectangle = {x: parseInt(Silv.Parameters['Stamina Gauge Rectangle'].split(' ')[0]), y: parseInt(Silv.Parameters['Stamina Gauge Rectangle'].split(' ')[1]), width: parseInt(Silv.Parameters['Stamina Gauge Rectangle'].split(' ')[2]), height: parseInt(Silv.Parameters['Stamina Gauge Rectangle'].split(' ')[3])};
  202. // Stamina Pool
  203. Silv.DashStamina.StaminaDecrease = parseInt(Silv.Parameters['Stamina Decrease']);
  204. Silv.DashStamina.StaminaMax = parseInt(Silv.Parameters['Stamina Max']);
  205. Silv.DashStamina.StaminaRecoveryDelay = parseInt(Silv.Parameters['Stamina Recovery Delay']);
  206. Silv.DashStamina.StaminaRecoveryRate = parseInt(Silv.Parameters['Stamina Recovery Rate']);
  207. Silv.DashStamina.StaminaAutoDashThreshold = parseInt(Silv.Parameters['Stamina AutoDash Threshold']);
  208. Silv.DashStamina.RegenFormula = Silv.Parameters['Stamina Regen Formula'];
  209. // Visuals
  210. Silv.DashStamina.StaminaGaugeColor1 = (Silv.Parameters['Stamina Gauge Color 1']).toUpperCase();
  211. Silv.DashStamina.StaminaGaugeColor2 = (Silv.Parameters['Stamina Gauge Color 2']).toUpperCase();
  212. Silv.DashStamina.DrawStaminaValue = Silv.Parameters['Draw Stamina Value'].toLowerCase();
  213. Silv.DashStamina.FontSize = parseInt(Silv.Parameters['Font Size']);
  214. // Window
  215. Silv.DashStamina.AutoHideStaminaWindow = Silv.Parameters['Auto Hide Stamina Window'].toLowerCase() == 'true';
  216. Silv.DashStamina.HideStaminaWindowDelay = parseInt(Silv.Parameters['Hide Stamina Window Delay']);
  217. Silv.DashStamina.WindowOpacity = parseInt(Silv.Parameters['Stamina Window Opacity']);
  218. Silv.DashStamina.WindowSlideOutDir = Silv.Parameters['Window Slideout Direction'].toLowerCase();
  219. Silv.DashStamina.WindowSlideOutSpeed = parseFloat(Silv.Parameters['Window Slideout Speed']);
  220. // Advanced
  221. Silv.DashStamina.DisableGameSwitch = parseInt(Silv.Parameters['Disable Stamina Consumption GameSwitch']);
  222. Silv.DashStamina.Window_Z = parseInt(Silv.Parameters['Window Z-Index']);
  223. Silv.DashStamina.PluginCmdId = Silv.Parameters['Plugin Command Identifier'];
  224.  
  225. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  226. // Utility Functions
  227. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  228. (function()
  229. {
  230.  
  231. // Usage: alert( hexToRgb("#0033ff").g ); // "51";
  232. function hexToRgb(hex)
  233. {
  234.         var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  235.         return result ? {
  236.                 r: parseInt(result[1], 16),
  237.                 g: parseInt(result[2], 16),
  238.                 b: parseInt(result[3], 16)
  239.         } : null;
  240. }
  241.  
  242. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  243. // Stamina
  244. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  245. // Hook into the main loop
  246. var alias_updateMain = Scene_Map.prototype.updateMain;
  247. Scene_Map.prototype.updateMain = function()
  248. {
  249.         alias_updateMain.apply(this, arguments);
  250.         Game_Player.prototype.updateStamina();
  251.         if (Silv.DashStamina.ShowWindow) { Silv.DashStamina.Window.update(); }
  252. };
  253.  
  254. Game_Player.prototype.hasStaminaConsumption = function()
  255. {
  256.         if ($gameSwitches.value(Silv.DashStamina.DisableGameSwitch)) { return false; }
  257.         if (!$gamePlayer.mapConsumeStamina) { return false; }
  258.         return true;
  259. };
  260.  
  261. // #Update stamina amount
  262. Game_Player.prototype.updateStamina = function()
  263. {      
  264.         this.isConsumingStamina = ($gamePlayer.isDashing() && $gamePlayer.isMoving() && $gamePlayer.hasStaminaConsumption());
  265.         if (this.isConsumingStamina)
  266.         {
  267.                 $gamePlayer.dashStamina -= Silv.DashStamina.StaminaDecrease;
  268.                 if ($gamePlayer.dashStamina < 0) { $gamePlayer.dashStamina = 0; }
  269.                 $gamePlayer.isRecoveringStamina = false;
  270.                 if (Silv.DashStamina.ShowWindow && !Silv.DashStamina.ScreenIsFading) { Silv.DashStamina.Window.showMe(); }
  271.         }
  272.         else // not currently consuming stamina
  273.         {              
  274.                 if ($gamePlayer.isRecoveringStamina)
  275.                 {
  276.                         $gamePlayer.staminaRecoveryTimeCnt++;
  277.                         if ($gamePlayer.dashStamina < $gamePlayer.dashStaminaMax) // Recover the stamina
  278.                         {
  279.                                 // Recover stamina
  280.                                 $gamePlayer.dashStamina += $gamePlayer.calculateStaminaRegen(Silv.DashStamina.StaminaRecoveryRate);
  281.                                 if ($gamePlayer.dashStamina > $gamePlayer.dashStaminaMax) { $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax; }    
  282.                                
  283.                                 if (Silv.DashStamina.ShowWindow && !Silv.DashStamina.ScreenIsFading) { Silv.DashStamina.Window.showMe(); }
  284.                         }
  285.                         else // Already at max stamina, find out when to hide the window if applicable and do so if possible
  286.                         {
  287.                                 // If the stamina window is used, attempt to autohide it if applicable
  288.                                 if (Silv.DashStamina.ShowWindow && Silv.DashStamina.AutoHideStaminaWindow)
  289.                                 {
  290.                                         $gamePlayer.hideStaminaWindowDelayCnt += 1;
  291.                                         if ($gamePlayer.hideStaminaWindowDelayCnt >= Silv.DashStamina.HideStaminaWindowDelay)
  292.                                         {
  293.                                                 Silv.DashStamina.Window.hideMe();
  294.                                                 $gamePlayer.hideStaminaWindowDelayCnt = 0;
  295.                                         }
  296.                                 }
  297.                                        
  298.                         }
  299.                 }
  300.                 else // not currently recovering stamina, so find out when to start recovering it and do so if required
  301.                 {
  302.                         $gamePlayer.staminaRecoveryTimeCnt = 0;
  303.                         $gamePlayer.staminaRecoveryDelayCnt += 1;
  304.                         if ($gamePlayer.staminaRecoveryDelayCnt >= Silv.DashStamina.StaminaRecoveryDelay)
  305.                         {
  306.                                 $gamePlayer.staminaRecoveryDelayCnt = 0;
  307.                                 $gamePlayer.isRecoveringStamina = true;
  308.                         }
  309.                 }
  310.         }
  311.  
  312.     // Stamina Percentage
  313.         $gamePlayer.dashStaminaPerc = $gamePlayer.dashStamina / parseFloat($gamePlayer.dashStaminaMax);
  314.  
  315.         // Threshold
  316.         if (!this.isConsumingStamina)
  317.         {
  318.                 $gamePlayer.requiresThresholdAmount = $gamePlayer.dashStaminaPerc * 100 < Silv.DashStamina.StaminaAutoDashThreshold;
  319.         }
  320. };
  321.  
  322. Game_Player.prototype.calculateStaminaRegen = function()
  323. {
  324.         var base = Silv.DashStamina.StaminaRecoveryRate;
  325.         var x = $gamePlayer.staminaRecoveryTimeCnt;
  326.         return eval(Silv.DashStamina.RegenFormula);
  327. };
  328.  
  329. // #Initialize variables in $gamePlayer
  330. var alias_Game_PlayerInitialize = Game_Player.prototype.initialize;
  331. Game_Player.prototype.initialize = function()
  332. {
  333.         alias_Game_PlayerInitialize.apply(this, arguments);
  334.  
  335.         this.dashStamina = this.dashStaminaMax = Silv.DashStamina.StaminaMax;
  336.         this.staminaRecoveryDelayCnt = 0; // counter for when to start recovering stamina
  337.         this.staminaRecoveryTimeCnt = 0; // counter for how long the player has been recovering stamina (in frames)
  338.         this.isRecoveringStamina = false;
  339.         this.dashStaminaPerc = 1.0;
  340.         this.hideStaminaWindowDelayCnt = 0;
  341.         this.isConsumingStamina = false;
  342.         this.requiresThresholdAmount = false;
  343.         this.wasDashing = false;
  344. };
  345.  
  346. // Disable dashing when no stamina.
  347. var alias_updateDashing = Game_Player.prototype.updateDashing;
  348. Game_Player.prototype.updateDashing = function()
  349. {
  350.         alias_updateDashing.apply(this, arguments);
  351.         if (!this.dashingAllowed()) { this._dashing = false; }
  352.         this.wasDashing = this._dashing;
  353. };
  354.  
  355. Game_Player.prototype.dashingAllowed = function()
  356. {
  357.         if ($gamePlayer.dashStamina == 0 ||
  358.            (!this.wasDashing && this.requiresThresholdAmount)) // Do not allow to dash if the player was not dashing the previous frame AND if the threshold was passed.
  359.         {
  360.                 return false;
  361.         }
  362.        
  363.         return true;
  364. };
  365.  
  366. // Do not just show the minimap on top of a faded-out screen.
  367. var alias_silv_stamina_updateFadeOut = Game_Screen.prototype.updateFadeOut;
  368. Game_Screen.prototype.updateFadeOut = function() {
  369.         alias_silv_stamina_updateFadeOut.call(this);
  370.    
  371.         if (this._brightness < 255) // (this._fadeOutDuration > 0)
  372.         {
  373.                 Silv.DashStamina.Window.visible = false;
  374.                 Silv.DashStamina.ScreenIsFading = true;
  375.         }
  376.         else
  377.         {
  378.                 Silv.DashStamina.ScreenIsFading = false;
  379.         }
  380. };
  381.  
  382. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  383. // DashStamina #Window
  384. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  385. function Window_DashStamina() { this.initialize.apply(this, arguments); }
  386. // Inherit from Window_Base
  387. Window_DashStamina.prototype = Object.create(Window_Base.prototype);
  388. // Set Constructor
  389. Window_DashStamina.prototype.constructor = Window_DashStamina;
  390.  
  391. Window_DashStamina.prototype.standardFontSize = function() { return Silv.DashStamina.FontSize; };
  392.  
  393. // Constructor #initialize
  394. Window_DashStamina.prototype.initialize = function(x, y, width, height)
  395. {
  396.     Window_Base.prototype.initialize.call(this, x, y, width, height);
  397.     this._helpWindow = null;
  398.     this._handlers = {};
  399.     this._touching = false;
  400.     this.deactivate();
  401.        
  402.     this.opacity = Silv.DashStamina.WindowOpacity;
  403.         this.slideDirection = {x: 0, y: 0 };
  404.         this.originalWinLoc = {x: 0, y: 0 };
  405.         this.sliding = 'none';
  406.         this.isFullySlidedOut = false;
  407.         this.isFullySlidedIn = true;
  408.         this.originalWinLoc.x = x; // for some reason "this." is not allowed here
  409.         this.originalWinLoc.y = y; // for some reason "this." is not allowed here
  410.        
  411.     this.update();
  412. };
  413.  
  414. // Update
  415. Window_DashStamina.prototype.update = function()
  416. {
  417.         if (Silv.DashStamina.ScreenIsFading)
  418.         {
  419.                 this.visible = false;
  420.         }
  421.         else
  422.         {
  423.                 Window_Base.prototype.update.call(this);
  424.                 this.drawStaminaWindow(0, 0, Silv.DashStamina.StaminaGaugeRectangle.width);
  425.                 this.updateSliding();
  426.         }
  427. };
  428.  
  429. var alias_Stamina_SceneBase_StartFadeIn = Scene_Base.prototype.startFadeIn;
  430. Scene_Base.prototype.startFadeIn = function()
  431. {
  432.         alias_Stamina_SceneBase_StartFadeIn.apply(this, arguments);
  433.         if (Silv.DashStamina.Window !== null) { Silv.DashStamina.Window.visible = false; }
  434. };
  435.  
  436. //----------------------------------------------------------------------------------------------------
  437. // #Drawing
  438. //----------------------------------------------------------------------------------------------------
  439. Window_DashStamina.prototype.drawStaminaGauge = function(x, y, width, height, rate)
  440. {
  441.     var fillW = Math.floor(width * rate);
  442.     var gaugeY = y + this.lineHeight() - 8;
  443.     this.contents.fillRect(x, gaugeY, width, height, this.gaugeBackColor());
  444.         this.contents.fillRect(x, gaugeY, fillW, height, this.CalculateBarColour());
  445. };
  446.  
  447. Window_DashStamina.prototype.drawStaminaWindow = function(x, y, width)
  448. {
  449.         this.contents.clear();
  450.         this.drawStaminaGauge(Silv.DashStamina.StaminaGaugeRectangle.x, Silv.DashStamina.StaminaGaugeRectangle.y, Silv.DashStamina.StaminaGaugeRectangle.width, Silv.DashStamina.StaminaGaugeRectangle.height, $gamePlayer.dashStaminaPerc);
  451.         var text;
  452.         switch(Silv.DashStamina.DrawStaminaValue) // allowed values: absolute/percentage/both/none
  453.         {
  454.                 case 'absolute':
  455.                         text = parseInt($gamePlayer.dashStamina) + '/' + parseInt($gamePlayer.dashStaminaMax);
  456.                         break;
  457.                 case 'percentage':
  458.                         text = Math.round($gamePlayer.dashStaminaPerc * 100) + '%';
  459.                         break;
  460.                 case 'both':
  461.                         text = parseInt($gamePlayer.dashStamina) + '/' + parseInt($gamePlayer.dashStaminaMax) + ' (' + Math.round($gamePlayer.dashStaminaPerc * 100) + '%)';
  462.                         break;
  463.                 case 'none':
  464.                         return;
  465.                 default:
  466.                         throw 'ERROR: drawStaminaWindow missing case-statement or incorrect Silv.DashStamina.DrawStaminaValue value. Value: ' + Silv.DashStamina.DrawStaminaValue;
  467.         }
  468.        
  469.         this.resetTextColor();
  470.         this.drawText(text, x, y + 1, width, 'center');
  471. };
  472.  
  473. // Calculate what colour the bar should be between the two colors depending on the percentage value of the current-stamina value.
  474. Window_DashStamina.prototype.CalculateBarColour = function()
  475. {
  476.         var c1 = hexToRgb(Silv.DashStamina.StaminaGaugeColor1);
  477.         var c2 = hexToRgb(Silv.DashStamina.StaminaGaugeColor2);
  478.                
  479.         var ratio = $gamePlayer.dashStaminaPerc;
  480.         var hex = function(x) {
  481.                 x = x.toString(16);
  482.                 return (x.length == 1) ? '0' + x : x;
  483.         };
  484.  
  485.         var r = Math.ceil(c1.r * ratio + c2.r * (1-ratio));
  486.         var g = Math.ceil(c1.g * ratio + c2.g * (1-ratio));
  487.         var b = Math.ceil(c1.b * ratio + c2.b * (1-ratio));
  488.  
  489.         var middle = '#' + hex(r) + hex(g) + hex(b);
  490.         return middle;
  491. };
  492.  
  493. //----------------------------------------------------------------------------------------------------
  494. // #Show & #Hide
  495. //----------------------------------------------------------------------------------------------------
  496. Window_DashStamina.prototype.showMe = function()
  497. {
  498.         //if (this.visible) { return; };
  499.         if (this.isFullySlidedIn)
  500.         {
  501.                 this.visible = true;
  502.                 return;
  503.         }
  504.        
  505.         if (Silv.DashStamina.WindowSlideOutDir == 'noslide' || this.visible === false) { this.visible = true; }
  506.         else
  507.         {
  508.                 this.sliding = 'in';
  509.                 switch (Silv.DashStamina.WindowSlideOutDir)
  510.                 {
  511.                         case 'top':
  512.                                 this.slideDirection.x = 0;
  513.                                 this.slideDirection.y = 1;
  514.                                 break;
  515.                         case 'left':
  516.                                 this.slideDirection.x = 1;
  517.                                 this.slideDirection.y = 0;
  518.                                 break;
  519.                         case 'right':
  520.                                 this.slideDirection.x = -1;
  521.                                 this.slideDirection.y = 0;
  522.                                 break;
  523.                         case 'bottom':
  524.                                 this.slideDirection.x = 0;
  525.                                 this.slideDirection.y = -1;
  526.                                 break;
  527.                         default:
  528.                                 throw 'Window_DashStamina.prototype.HideMe: Unknown switch value: ' + Silv.DashStamina.WindowSlideOutDir;
  529.                 }
  530.         }
  531. };
  532.  
  533. Window_DashStamina.prototype.hideMe = function()
  534. {
  535.         if (!this.visible || this.isFullySlidedOut) { return; }
  536.        
  537.         if (Silv.DashStamina.WindowSlideOutDir == 'noslide') { this.visible = false; }
  538.         else
  539.         {
  540.                 this.sliding = 'out';
  541.                 switch (Silv.DashStamina.WindowSlideOutDir)
  542.                 {
  543.                         case 'top':
  544.                                 this.slideDirection.x = 0;
  545.                                 this.slideDirection.y = -1;
  546.                                 break;
  547.                         case 'left':
  548.                                 this.slideDirection.x = -1;
  549.                                 this.slideDirection.y = 0;
  550.                                 break;
  551.                         case 'right':
  552.                                 this.slideDirection.x = 1;
  553.                                 this.slideDirection.y = 0;
  554.                                 break;
  555.                         case 'bottom':
  556.                                 this.slideDirection.x = 0;
  557.                                 this.slideDirection.y = 1;
  558.                                 break;
  559.                         default:
  560.                                 throw 'Window_DashStamina.prototype.HideMe: Unknown switch value: ' + Silv.DashStamina.WindowSlideOutDir;
  561.                 }
  562.         }
  563. };
  564.  
  565. //----------------------------------------------------------------------------------------------------
  566. // #Sliding of the Window
  567. //----------------------------------------------------------------------------------------------------
  568. Window_DashStamina.prototype.handleSlidingEnd = function()
  569. {
  570.         if(this.sliding == 'in')
  571.         {
  572.                 // Stop sliding in
  573.                 if (this.slideDirection.x  == 1 && this.x > this.originalWinLoc.x ||
  574.                         this.slideDirection.x  == -1 && this.x < this.originalWinLoc.x ||
  575.                         this.slideDirection.y  == 1 && this.y > this.originalWinLoc.y ||
  576.                         this.slideDirection.y  == -1 && this.y < this.originalWinLoc.y)
  577.                 {
  578.                         this.sliding = 'none';
  579.                         this.isFullySlidedIn = true;
  580.                 }
  581.         }
  582.         else
  583.         {
  584.                 // Stop sliding out
  585.                 if (this.x < -this.width || this.x > Graphics._width + this.width ||
  586.                         this.y < -this.height || this.x > Graphics._height + this.height)
  587.                 {
  588.                         this.sliding = 'none';
  589.                         this.isFullySlidedOut = true;
  590.                 }
  591.         }
  592. };
  593.  
  594. Window_DashStamina.prototype.updateSliding = function()
  595. {
  596.         if (this.sliding == 'none') { return; }
  597.         this.x += this.slideDirection.x * Silv.DashStamina.WindowSlideOutSpeed;
  598.         this.y += this.slideDirection.y * Silv.DashStamina.WindowSlideOutSpeed;
  599.        
  600.         this.isFullySlidedOut = false;
  601.         this.isFullySlidedIn = false;
  602.        
  603.         this.handleSlidingEnd();
  604. };
  605.  
  606. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  607. // Create Stamina Window
  608. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  609. Scene_Map.prototype.createDashWindow = function()
  610. {
  611.         // Dispose the old window, if any
  612.         if (Silv.DashStamina.Window !== null) { this.removeWindow(Silv.DashStamina.Window); }
  613.        
  614.         // Does the map consume stamina?
  615.         $gamePlayer.mapConsumeStamina = !('dstam_disable' in $dataMap.meta);
  616.         if(Silv.DashStamina.ShowWindow)
  617.         {
  618.                 var x = 0;
  619.                 if (Silv.DashStamina.WindowHorizontalAlignment == 'right') { x = Graphics.width - Silv.DashStamina.WindowWidth; }
  620.                 var y = 0;
  621.                 if (Silv.DashStamina.WindowVerticalAlignment == 'bottom') { y = Graphics.height - Silv.DashStamina.WindowHeight; }
  622.                
  623.                 Silv.DashStamina.Window = new Window_DashStamina(x + Silv.DashStamina.Window_X, y + Silv.DashStamina.Window_Y, Silv.DashStamina.WindowWidth, Silv.DashStamina.WindowHeight);
  624.                
  625.                 this.addChild(Silv.DashStamina.Window, Silv.DashStamina.Window_Z);
  626.                 if (Silv.DashStamina.AutoHideStaminaWindow) { Silv.DashStamina.Window.visible = false; }
  627.         }
  628. };
  629.  
  630. // Omg why does RPG Maker not have this method by default...
  631. Scene_Base.prototype.removeWindow = function(window)
  632. {
  633.         var index = this.children.indexOf(window);
  634.         if (index > -1) { this.children.splice(index, 1); }
  635. };
  636.  
  637. var alias_createStaminaDisplayObjects = Scene_Map.prototype.createDisplayObjects;
  638. Scene_Map.prototype.createDisplayObjects = function()
  639. {
  640.         alias_createStaminaDisplayObjects.call(this);
  641.         this.createDashWindow();
  642. };
  643.  
  644. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  645. // Saving & Loading
  646. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  647. var alias_silv_stamina_makeSaveContents = DataManager.makeSaveContents;
  648. DataManager.makeSaveContents = function()
  649. {
  650.         contents = alias_silv_stamina_makeSaveContents.call(this);
  651.         contents.dashStamina = $gamePlayer.dashStamina;
  652.         contents.dashStaminaMax = $gamePlayer.dashStaminaMax;
  653.         return contents;
  654. };
  655.  
  656. var alias_silv_stamina_extractSaveContents = DataManager.extractSaveContents;
  657. DataManager.extractSaveContents = function(contents)
  658. {
  659.         alias_silv_stamina_extractSaveContents.call(this, contents);
  660.         $gamePlayer.dashStamina = contents.dashStamina;
  661.         $gamePlayer.dashStaminaMax = contents.dashStaminaMax;
  662. };
  663.  
  664. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  665. // Plugin Command
  666. // Note: The items are separated by spaces. The command is the first word and any following words are args. args is an array.
  667. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  668. var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  669. Game_Interpreter.prototype.pluginCommand = function(command, args)
  670. {
  671.         _Game_Interpreter_pluginCommand.call(this, command, args);
  672.         if (command.toLowerCase() == Silv.DashStamina.PluginCmdId) { PluginCommand(command, args); }
  673. };
  674.  
  675. function PluginCommand(cmd, args)
  676. {
  677.         switch(args[0].toLowerCase())
  678.         {
  679.                 case 'refill':
  680.                         $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax;
  681.                         break;
  682.                 case 'deplete':
  683.                         $gamePlayer.dashStamina = 0;
  684.                         break;
  685.                 case 'set':
  686.                         var perc = parseInt(args[1]);
  687.                         perc = Math.max(0, Math.min(100, perc)); // clamp value between 0-100
  688.                         $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax * (perc / 100.0);
  689.                 break;
  690.                 case 'showwindow':
  691.                         if (Silv.DashStamina.Window !== null)
  692.                         {
  693.                                 $gamePlayer.hideStaminaWindowDelayCnt = 0;
  694.                                 Silv.DashStamina.Window.visible = true;
  695.                         }
  696.                         break;
  697.                 case 'refillhide':
  698.                         $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax;
  699.                         // NO break-statement here! We want to hide the window as well!
  700.                 case 'hidewindow':
  701.                         if (Silv.DashStamina.Window !== null)
  702.                         {
  703.                                 $gamePlayer.hideStaminaWindowDelayCnt = Silv.DashStamina.HideStaminaWindowDelay;
  704.                                 Silv.DashStamina.Window.visible = false;
  705.                         }
  706.                         break;
  707.                 case 'setmax':
  708.                         $gamePlayer.dashStaminaMax = Math.max(1, parseInt(args[1]));
  709.                         if ($gamePlayer.dashStamina > $gamePlayer.dashStaminaMax) { $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax; }
  710.                         break;
  711.                 case 'increasemax':
  712.                         $gamePlayer.dashStaminaMax += parseInt(args[1]);
  713.                         if ($gamePlayer.dashStaminaMax < 1) { $gamePlayer.dashStaminaMax = 1; }
  714.                         if ($gamePlayer.dashStamina > $gamePlayer.dashStaminaMax) { $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax; }
  715.                         break;
  716.                 default:
  717.                         throw 'Stamina PluginCommand invalid command: ' + args[0];
  718.         }
  719. }
  720.  
  721. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  722. })();
  723. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  724. // End of script
  725. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top