SHARE
TWEET

Stamina

a guest Nov 26th, 2015 115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // SilvStamina.js
  3. // Version: 1.0
  4. //=============================================================================
  5. /*:
  6.  * @plugindesc v1.00 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.00 (26 November 2015)
  170.  *   - First release.
  171.  *
  172.  * Alpha (November 2015)
  173.  *   - First alpha release.
  174.  *
  175.  */
  176.  // Enable strict mode
  177. "use strict";
  178.  
  179. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  180. // #Parameters
  181. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  182. var Silv = Silv || {};
  183. Silv.Parameters = $plugins.filter(function(p) { return p.description.contains('<SilverStamina>'); })[0].parameters;
  184. Silv.DashStamina = Silv.DashStamina || {};
  185. // Non-parameters
  186. Silv.DashStamina.Window = null;
  187. Silv.DashStamina.ScreenIsFading = false;
  188. // General
  189. Silv.DashStamina.ShowWindow = Silv.Parameters['Show Stamina Window'].toLowerCase() == 'true';
  190. // Positioning & Size
  191. Silv.DashStamina.Window_X = parseInt(Silv.Parameters['Window X']);
  192. Silv.DashStamina.Window_Y = parseInt(Silv.Parameters['Window Y']);
  193. Silv.DashStamina.WindowWidth = parseInt(Silv.Parameters['Window Width']);
  194. Silv.DashStamina.WindowHeight = parseInt(Silv.Parameters['Window Height']);
  195. Silv.DashStamina.WindowHorizontalAlignment = (Silv.Parameters['Window Horizontal Alignment']).toLowerCase();
  196. Silv.DashStamina.WindowVerticalAlignment = (Silv.Parameters['Window Vertical Alignment']).toLowerCase();
  197. 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])};
  198. // Stamina Pool
  199. Silv.DashStamina.StaminaDecrease = parseInt(Silv.Parameters['Stamina Decrease']);
  200. Silv.DashStamina.StaminaMax = parseInt(Silv.Parameters['Stamina Max']);
  201. Silv.DashStamina.StaminaRecoveryDelay = parseInt(Silv.Parameters['Stamina Recovery Delay']);
  202. Silv.DashStamina.StaminaRecoveryRate = parseInt(Silv.Parameters['Stamina Recovery Rate']);
  203. Silv.DashStamina.StaminaAutoDashThreshold = parseInt(Silv.Parameters['Stamina AutoDash Threshold']);
  204. Silv.DashStamina.RegenFormula = Silv.Parameters['Stamina Regen Formula'];
  205. // Visuals
  206. Silv.DashStamina.StaminaGaugeColor1 = (Silv.Parameters['Stamina Gauge Color 1']).toUpperCase();
  207. Silv.DashStamina.StaminaGaugeColor2 = (Silv.Parameters['Stamina Gauge Color 2']).toUpperCase();
  208. Silv.DashStamina.DrawStaminaValue = Silv.Parameters['Draw Stamina Value'].toLowerCase();
  209. Silv.DashStamina.FontSize = parseInt(Silv.Parameters['Font Size']);
  210. // Window
  211. Silv.DashStamina.AutoHideStaminaWindow = Silv.Parameters['Auto Hide Stamina Window'].toLowerCase() == 'true';
  212. Silv.DashStamina.HideStaminaWindowDelay = parseInt(Silv.Parameters['Hide Stamina Window Delay']);
  213. Silv.DashStamina.WindowOpacity = parseInt(Silv.Parameters['Stamina Window Opacity']);
  214. Silv.DashStamina.WindowSlideOutDir = Silv.Parameters['Window Slideout Direction'].toLowerCase();
  215. Silv.DashStamina.WindowSlideOutSpeed = parseFloat(Silv.Parameters['Window Slideout Speed']);
  216. // Advanced
  217. Silv.DashStamina.DisableGameSwitch = parseInt(Silv.Parameters['Disable Stamina Consumption GameSwitch']);
  218. Silv.DashStamina.Window_Z = parseInt(Silv.Parameters['Window Z-Index']);
  219. Silv.DashStamina.PluginCmdId = Silv.Parameters['Plugin Command Identifier'];
  220.  
  221. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  222. // Utility Functions
  223. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  224. (function()
  225. {
  226. // Usage: alert(rgbToHex(0, 51, 255)); // #0033ff
  227. function componentToHex(c)
  228. {
  229.         var hex = c.toString(16);
  230.         return hex.length == 1 ? "0" + hex : hex;
  231. }
  232.  
  233. function rgbToHex(r, g, b) { return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b); }
  234.  
  235. // Usage: alert( hexToRgb("#0033ff").g ); // "51";
  236. function hexToRgb(hex)
  237. {
  238.         var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  239.         return result ? {
  240.                 r: parseInt(result[1], 16),
  241.                 g: parseInt(result[2], 16),
  242.                 b: parseInt(result[3], 16)
  243.         } : null;
  244. }
  245.  
  246. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  247. // Stamina
  248. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  249. // Hook into the main loop
  250. var alias_updateMain = Scene_Map.prototype.updateMain;
  251. Scene_Map.prototype.updateMain = function()
  252. {
  253.         alias_updateMain.apply(this, arguments);
  254.         Game_Player.prototype.updateStamina();
  255.         if (Silv.DashStamina.ShowWindow) { Silv.DashStamina.Window.update(); }
  256. };
  257.  
  258. Game_Player.prototype.hasStaminaConsumption = function()
  259. {
  260.         if ($gameSwitches.value(Silv.DashStamina.DisableGameSwitch)) { return false; }
  261.         if (!$gamePlayer.mapConsumeStamina) { return false; }
  262.         return true;
  263. };
  264.  
  265. // #Update stamina amount
  266. Game_Player.prototype.updateStamina = function()
  267. {      
  268.         this.isConsumingStamina = ($gamePlayer.isDashing() && $gamePlayer.isMoving() && $gamePlayer.hasStaminaConsumption());
  269.         if (this.isConsumingStamina)
  270.         {
  271.                 $gamePlayer.dashStamina -= Silv.DashStamina.StaminaDecrease;
  272.                 if ($gamePlayer.dashStamina < 0) { $gamePlayer.dashStamina = 0; }
  273.                 $gamePlayer.isRecoveringStamina = false;
  274.                 if (Silv.DashStamina.ShowWindow && !Silv.DashStamina.ScreenIsFading) { Silv.DashStamina.Window.showMe(); }
  275.         }
  276.         else // not currently consuming stamina
  277.         {              
  278.                 if ($gamePlayer.isRecoveringStamina)
  279.                 {
  280.                         $gamePlayer.staminaRecoveryTimeCnt++;
  281.                         if ($gamePlayer.dashStamina < $gamePlayer.dashStaminaMax) // Recover the stamina
  282.                         {
  283.                                 // Recover stamina
  284.                                 $gamePlayer.dashStamina += $gamePlayer.calculateStaminaRegen(Silv.DashStamina.StaminaRecoveryRate);
  285.                                 if ($gamePlayer.dashStamina > $gamePlayer.dashStaminaMax) { $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax; }    
  286.                                
  287.                                 if (Silv.DashStamina.ShowWindow && !Silv.DashStamina.ScreenIsFading) { Silv.DashStamina.Window.showMe(); }
  288.                         }
  289.                         else // Already at max stamina, find out when to hide the window if applicable and do so if possible
  290.                         {
  291.                                 // If the stamina window is used, attempt to autohide it if applicable
  292.                                 if (Silv.DashStamina.ShowWindow && Silv.DashStamina.AutoHideStaminaWindow)
  293.                                 {
  294.                                         $gamePlayer.hideStaminaWindowDelayCnt += 1;
  295.                                         if ($gamePlayer.hideStaminaWindowDelayCnt >= Silv.DashStamina.HideStaminaWindowDelay)
  296.                                         {
  297.                                                 Silv.DashStamina.Window.hideMe();
  298.                                                 $gamePlayer.hideStaminaWindowDelayCnt = 0;
  299.                                         }
  300.                                 }
  301.                                        
  302.                         }
  303.                 }
  304.                 else // not currently recovering stamina, so find out when to start recovering it and do so if required
  305.                 {
  306.                         $gamePlayer.staminaRecoveryTimeCnt = 0;
  307.                         $gamePlayer.staminaRecoveryDelayCnt += 1;
  308.                         if ($gamePlayer.staminaRecoveryDelayCnt >= Silv.DashStamina.StaminaRecoveryDelay)
  309.                         {
  310.                                 $gamePlayer.staminaRecoveryDelayCnt = 0;
  311.                                 $gamePlayer.isRecoveringStamina = true;
  312.                         }
  313.                 }
  314.         }
  315.  
  316.     // Stamina Percentage
  317.         $gamePlayer.dashStaminaPerc = $gamePlayer.dashStamina / parseFloat($gamePlayer.dashStaminaMax);
  318.  
  319.         // Threshold
  320.         if (!this.isConsumingStamina)
  321.         {
  322.                 $gamePlayer.requiresThresholdAmount = $gamePlayer.dashStaminaPerc * 100 < Silv.DashStamina.StaminaAutoDashThreshold;
  323.         }
  324. };
  325.  
  326. Game_Player.prototype.calculateStaminaRegen = function()
  327. {
  328.         var base = Silv.DashStamina.StaminaRecoveryRate;
  329.         var x = $gamePlayer.staminaRecoveryTimeCnt;
  330.         return eval(Silv.DashStamina.RegenFormula);
  331. };
  332.  
  333. // #Initialize variables in $gamePlayer
  334. var alias_Game_PlayerInitialize = Game_Player.prototype.initialize;
  335. Game_Player.prototype.initialize = function()
  336. {
  337.         alias_Game_PlayerInitialize.apply(this, arguments);
  338.  
  339.         this.dashStamina = this.dashStaminaMax = Silv.DashStamina.StaminaMax;
  340.         this.staminaRecoveryDelayCnt = 0; // counter for when to start recovering stamina
  341.         this.staminaRecoveryTimeCnt = 0; // counter for how long the player has been recovering stamina (in frames)
  342.         this.isRecoveringStamina = false;
  343.         this.dashStaminaPerc = 1.0;
  344.         this.hideStaminaWindowDelayCnt = 0;
  345.         this.isConsumingStamina = false;
  346.         this.requiresThresholdAmount = false;
  347.         this.wasDashing = false;
  348. };
  349.  
  350. // Disable dashing when no stamina.
  351. var alias_updateDashing = Game_Player.prototype.updateDashing;
  352. Game_Player.prototype.updateDashing = function()
  353. {
  354.         alias_updateDashing.apply(this, arguments);
  355.         if ($gamePlayer.dashStamina == 0) { this._dashing = false; };
  356.         if (!this.wasDashing && this.requiresThresholdAmount) { this._dashing = false; }; // Do not allow to dash if the player was not dashing the previous frame AND if the threshold was passed.
  357.         this.wasDashing = this._dashing;
  358. };
  359.  
  360. // Do not just show the minimap on top of a faded-out screen.
  361. var alias_silv_stamina_updateFadeOut = Game_Screen.prototype.updateFadeOut;
  362. Game_Screen.prototype.updateFadeOut = function() {
  363.         alias_silv_stamina_updateFadeOut.call(this);
  364.    
  365.         if (this._brightness < 255) // (this._fadeOutDuration > 0)
  366.         {
  367.                 Silv.DashStamina.Window.visible = false;
  368.                 Silv.DashStamina.ScreenIsFading = true;
  369.         }
  370.         else
  371.         {
  372.                 Silv.DashStamina.ScreenIsFading = false;
  373.         }
  374. };
  375.  
  376. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  377. // DashStamina Window
  378. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  379. function Window_DashStamina() { this.initialize.apply(this, arguments); }
  380. // Inherit from Window_Base
  381. Window_DashStamina.prototype = Object.create(Window_Base.prototype);
  382. // Set Constructor
  383. Window_DashStamina.prototype.constructor = Window_DashStamina;
  384.  
  385. Window_DashStamina.prototype.standardFontSize = function() { return Silv.DashStamina.FontSize; }
  386.  
  387. var sliding;
  388. var isFullySlidedOut;
  389. var isFullySlidedIn;
  390. var slideDirection = {x: 0, y: 0 };
  391. var originalWinLoc = {x: 0, y: 0 };
  392.  
  393. // Constructor
  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.     this.opacity = Silv.DashStamina.WindowOpacity;
  402.         this.sliding = 'none';
  403.         this.isFullySlidedOut = false;
  404.         this.isFullySlidedIn = true;
  405.         originalWinLoc.x = x; // for some reason "this." is not allowed here
  406.         originalWinLoc.y = y; // for some reason "this." is not allowed here
  407.        
  408.     this.update();
  409. };
  410.  
  411. // Update
  412. Window_DashStamina.prototype.update = function()
  413. {
  414.         if (Silv.DashStamina.ScreenIsFading)
  415.         {
  416.                 this.visible = false;
  417.         }
  418.         else
  419.         {
  420.                 Window_Base.prototype.update.call(this);
  421.                 this.drawStaminaWindow(0, 0, Silv.DashStamina.StaminaGaugeRectangle.width);
  422.                 this.updateSliding();
  423.         }
  424. };
  425.  
  426. var alias_Stamina_SceneBase_StartFadeIn = Scene_Base.prototype.startFadeIn;
  427. Scene_Base.prototype.startFadeIn = function()
  428. {
  429.         alias_Stamina_SceneBase_StartFadeIn.apply(this, arguments)  
  430.         if (Silv.DashStamina.Window != null) { Silv.DashStamina.Window.visible = false; }
  431. };
  432.  
  433. //----------------------------------------------------------------------------------------------------
  434. // #Drawing
  435. //----------------------------------------------------------------------------------------------------
  436. Window_DashStamina.prototype.drawStaminaGauge = function(x, y, width, height, rate)
  437. {
  438.     var fillW = Math.floor(width * rate);
  439.     var gaugeY = y + this.lineHeight() - 8;
  440.     this.contents.fillRect(x, gaugeY, width, height, this.gaugeBackColor());
  441.         this.contents.fillRect (x, gaugeY, fillW, height, this.CalculateBarColour())
  442. };
  443.  
  444. Window_DashStamina.prototype.drawStaminaWindow = function(x, y, width)
  445. {
  446.         this.contents.clear();
  447.         this.drawStaminaGauge(Silv.DashStamina.StaminaGaugeRectangle.x, Silv.DashStamina.StaminaGaugeRectangle.y, Silv.DashStamina.StaminaGaugeRectangle.width, Silv.DashStamina.StaminaGaugeRectangle.height, $gamePlayer.dashStaminaPerc);
  448.         var text;
  449.         switch(Silv.DashStamina.DrawStaminaValue) // allowed values: absolute/percentage/both/none
  450.         {
  451.                 case 'absolute':
  452.                         text = parseInt($gamePlayer.dashStamina) + '/' + parseInt($gamePlayer.dashStaminaMax)
  453.                         break;
  454.                 case 'percentage':
  455.                         text = Math.round($gamePlayer.dashStaminaPerc * 100) + '%';
  456.                         break;
  457.                 case 'both':
  458.                         text = parseInt($gamePlayer.dashStamina) + '/' + parseInt($gamePlayer.dashStaminaMax) + ' (' + Math.round($gamePlayer.dashStaminaPerc * 100) + '%)';
  459.                         break;
  460.                 case 'none':
  461.                         return;
  462.                         break;
  463.                 default:
  464.                         throw 'ERROR: drawStaminaWindow missing case-statement or incorrect Silv.DashStamina.DrawStaminaValue value. Value: ' + Silv.DashStamina.DrawStaminaValue;
  465.                 break;
  466.         }
  467.        
  468.         this.resetTextColor();
  469.         this.drawText(text, x, y + 1, width, 'center');
  470. };
  471.  
  472. // Calculate what colour the bar should be between the two colors depending on the percentage value of the current-stamina value.
  473. Window_DashStamina.prototype.CalculateBarColour = function()
  474. {
  475.         var c1 = hexToRgb(Silv.DashStamina.StaminaGaugeColor1);
  476.         var c2 = hexToRgb(Silv.DashStamina.StaminaGaugeColor2);
  477.                
  478.         var ratio = $gamePlayer.dashStaminaPerc;
  479.         var hex = function(x) {
  480.                 x = x.toString(16);
  481.                 return (x.length == 1) ? '0' + x : x;
  482.         };
  483.  
  484.         var r = Math.ceil(c1.r * ratio + c2.r * (1-ratio));
  485.         var g = Math.ceil(c1.g * ratio + c2.g * (1-ratio));
  486.         var b = Math.ceil(c1.b * ratio + c2.b * (1-ratio));
  487.  
  488.         var middle = '#' + hex(r) + hex(g) + hex(b);
  489.         return middle;
  490. };
  491.  
  492. //----------------------------------------------------------------------------------------------------
  493. // #Show & #Hide
  494. //----------------------------------------------------------------------------------------------------
  495. Window_DashStamina.prototype.showMe = function()
  496. {
  497.         //if (this.visible) { return; };
  498.         if (this.isFullySlidedIn)
  499.         {
  500.                 this.visible = true;
  501.                 return;
  502.         }
  503.        
  504.         if (Silv.DashStamina.WindowSlideOutDir == 'noslide' || this.visible == false) { this.visible = true; }
  505.         else
  506.         {
  507.                 this.sliding = 'in';
  508.                 switch (Silv.DashStamina.WindowSlideOutDir)
  509.                 {
  510.                         case 'top':
  511.                                 slideDirection.x = 0;
  512.                                 slideDirection.y = 1;
  513.                                 break;
  514.                         case 'left':
  515.                                 slideDirection.x = 1;
  516.                                 slideDirection.y = 0;
  517.                                 break;
  518.                         case 'right':
  519.                                 slideDirection.x = -1;
  520.                                 slideDirection.y = 0;
  521.                                 break;
  522.                         case 'bottom':
  523.                                 slideDirection.x = 0;
  524.                                 slideDirection.y = -1;
  525.                                 break;
  526.                         default:
  527.                                 throw 'Window_DashStamina.prototype.HideMe: Unknown switch value: ' + Silv.DashStamina.WindowSlideOutDir;
  528.                 }
  529.         }
  530. };
  531.  
  532. Window_DashStamina.prototype.hideMe = function()
  533. {
  534.         if (!this.visible || this.isFullySlidedOut) { return; };
  535.        
  536.         if (Silv.DashStamina.WindowSlideOutDir == 'noslide') { this.visible = false; }
  537.         else
  538.         {
  539.                 this.sliding = 'out';
  540.                 switch (Silv.DashStamina.WindowSlideOutDir)
  541.                 {
  542.                         case 'top':
  543.                                 slideDirection.x = 0;
  544.                                 slideDirection.y = -1;
  545.                                 break;
  546.                         case 'left':
  547.                                 slideDirection.x = -1;
  548.                                 slideDirection.y = 0;
  549.                                 break;
  550.                         case 'right':
  551.                                 slideDirection.x = 1;
  552.                                 slideDirection.y = 0;
  553.                                 break;
  554.                         case 'bottom':
  555.                                 slideDirection.x = 0;
  556.                                 slideDirection.y = 1;
  557.                                 break;
  558.                         default:
  559.                                 throw 'Window_DashStamina.prototype.HideMe: Unknown switch value: ' + Silv.DashStamina.WindowSlideOutDir;
  560.                 }
  561.         }
  562. };
  563.  
  564. //----------------------------------------------------------------------------------------------------
  565. // #Sliding of the Window
  566. //----------------------------------------------------------------------------------------------------
  567. Window_DashStamina.prototype.handleSlidingEnd = function()
  568. {
  569.         if(this.sliding == 'in')
  570.         {
  571.                 // Stop sliding in
  572.                 if (slideDirection.x  == 1 && this.x > originalWinLoc.x ||
  573.                         slideDirection.x  == -1 && this.x < originalWinLoc.x ||
  574.                         slideDirection.y  == 1 && this.y > originalWinLoc.y ||
  575.                         slideDirection.y  == -1 && this.y < originalWinLoc.y)
  576.                 {
  577.                         this.sliding = 'none';
  578.                         this.isFullySlidedIn = true;
  579.                 }
  580.         }
  581.         else
  582.         {
  583.                 // Stop sliding out
  584.                 if (this.x < -this.width || x > Graphics._width + this.width ||
  585.                         this.y < -this.height || x > Graphics._height + this.height)
  586.                 {
  587.                         this.sliding = 'none';
  588.                         this.isFullySlidedOut = true;
  589.                 }
  590.         }
  591. };
  592.  
  593. Window_DashStamina.prototype.updateSliding = function()
  594. {
  595.         if (this.sliding == 'none') { return; }
  596.         this.x += slideDirection.x * Silv.DashStamina.WindowSlideOutSpeed;
  597.         this.y += slideDirection.y * Silv.DashStamina.WindowSlideOutSpeed;
  598.        
  599.         this.isFullySlidedOut = false;
  600.         this.isFullySlidedIn = false;
  601.        
  602.         this.handleSlidingEnd();
  603. };
  604.  
  605. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  606. // Create Stamina Window
  607. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  608. Scene_Map.prototype.createDashWindow = function()
  609. {
  610.         // Dispose the old window, if any
  611.         if (Silv.DashStamina.Window != null) { this.removeWindow(Silv.DashStamina.Window); }
  612.        
  613.         // Does the map consume stamina?
  614.         $gamePlayer.mapConsumeStamina = !('dstam_disable' in $dataMap.meta);
  615.         if(Silv.DashStamina.ShowWindow)
  616.         {
  617.                 x = 0;
  618.                 if (Silv.DashStamina.WindowHorizontalAlignment == 'right') { x = Graphics.width - Silv.DashStamina.WindowWidth; }
  619.                 y = 0;
  620.                 if (Silv.DashStamina.WindowVerticalAlignment == 'bottom') { y = Graphics.height - Silv.DashStamina.WindowHeight; }
  621.                
  622.                 Silv.DashStamina.Window = new Window_DashStamina(x + Silv.DashStamina.Window_X, y + Silv.DashStamina.Window_Y, Silv.DashStamina.WindowWidth, Silv.DashStamina.WindowHeight);
  623.                
  624.                 this.addChild(Silv.DashStamina.Window, Silv.DashStamina.Window_Z);
  625.                 if (Silv.DashStamina.AutoHideStaminaWindow) { Silv.DashStamina.Window.visible = false; }
  626.         }
  627. };
  628.  
  629. // Omg why does RPG Maker not have this method by default...
  630. Scene_Base.prototype.removeWindow = function(window)
  631. {
  632.         var index = this.children.indexOf(window);
  633.         if (index > -1) { this.children.splice(index, 1); }
  634. };
  635.  
  636. var alias_createStaminaDisplayObjects = Scene_Map.prototype.createDisplayObjects;
  637. Scene_Map.prototype.createDisplayObjects = function()
  638. {
  639.         alias_createStaminaDisplayObjects.call(this);
  640.         this.createDashWindow();
  641. };
  642.  
  643. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  644. // Saving & Loading
  645. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  646. var alias_silv_stamina_makeSaveContents = DataManager.makeSaveContents;
  647. DataManager.makeSaveContents = function()
  648. {
  649.         contents = alias_silv_stamina_makeSaveContents.call(this);
  650.         contents.dashStamina = $gamePlayer.dashStamina;
  651.         contents.dashStaminaMax = $gamePlayer.dashStaminaMax;
  652.         return contents;
  653. };
  654.  
  655. var alias_silv_stamina_extractSaveContents = DataManager.extractSaveContents;
  656. DataManager.extractSaveContents = function(contents)
  657. {
  658.         alias_silv_stamina_extractSaveContents.call(this, contents);
  659.         $gamePlayer.dashStamina = contents.dashStamina;
  660.         $gamePlayer.dashStaminaMax = contents.dashStaminaMax;
  661. };
  662.  
  663. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  664. // Plugin Command
  665. // Note: The items are separated by spaces. The command is the first word and any following words are args. args is an array.
  666. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  667. var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  668. Game_Interpreter.prototype.pluginCommand = function(command, args)
  669. {
  670.         _Game_Interpreter_pluginCommand.call(this, command, args);
  671.         if (command.toLowerCase() == Silv.DashStamina.PluginCmdId) { PluginCommand(command, args); }
  672. };
  673.  
  674. function PluginCommand(cmd, args)
  675. {
  676.         switch(args[0].toLowerCase())
  677.         {
  678.                 case 'refill':
  679.                         $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax;
  680.                         break;
  681.                 case 'deplete':
  682.                         $gamePlayer.dashStamina = 0;
  683.                         break;
  684.                 case 'set':
  685.                         var perc = parseInt(args[1]);
  686.                         perc = Math.max(0, Math.min(100, perc)); // clamp value between 0-100
  687.                         $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax * (perc / 100.0);
  688.                 break;
  689.                 case 'showwindow':
  690.                         if (Silv.DashStamina.Window != null)
  691.                         {
  692.                                 $gamePlayer.hideStaminaWindowDelayCnt = 0;
  693.                                 Silv.DashStamina.Window.visible = true;
  694.                         }
  695.                         break;
  696.                 case 'refillhide':
  697.                         $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax;
  698.                 case 'hidewindow':
  699.                         if (Silv.DashStamina.Window != null)
  700.                         {
  701.                                 $gamePlayer.hideStaminaWindowDelayCnt = Silv.DashStamina.HideStaminaWindowDelay;
  702.                                 Silv.DashStamina.Window.visible = false;
  703.                         }
  704.                         break;
  705.                 case 'setmax':
  706.                         $gamePlayer.dashStaminaMax = Math.max(1, parseInt(args[1]));
  707.                         if ($gamePlayer.dashStamina > $gamePlayer.dashStaminaMax) { $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax; }
  708.                         break;
  709.                 case 'increasemax':
  710.                         $gamePlayer.dashStaminaMax += parseInt(args[1]);
  711.                         if ($gamePlayer.dashStaminaMax < 1) { $gamePlayer.dashStaminaMax = 1; }
  712.                         if ($gamePlayer.dashStamina > $gamePlayer.dashStaminaMax) { $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax; }
  713.                         break;
  714.                 default:
  715.                         throw 'Stamina PluginCommand invalid command: ' + args[0];
  716.                         break;
  717.         }
  718. };
  719.  
  720. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  721. })();
  722. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  723. // End of script
  724. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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