SHARE
TWEET

Untitled

a guest Apr 1st, 2016 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // SilvStamina.js
  3. // Version: 1.07
  4. //=============================================================================
  5. /*:
  6.  * @plugindesc v1.07 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 Mode
  49.  * @desc Use "Default" to decrease while moving. Use "Tile" to decrease stamina whenever the player enters a new tile.
  50.  * @default Default
  51.  *
  52.  * @param Stamina Decrease
  53.  * @desc Amount of stamina subtracted per update (use a positive number)
  54.  * @default 1
  55.  *
  56.  * @param Stamina Max
  57.  * @desc Maximum amount of stamina
  58.  * @default 300
  59.  *
  60.  * @param Stamina Recovery Delay
  61.  * @desc delay in update-calls before recovering stamina when not dashing
  62.  * @default 180
  63.  *
  64.  * @param Stamina Recovery Rate
  65.  * @desc How fast stamina is recovered (only when recovering)
  66.  * @default 0.3
  67.  *
  68.  * @param Stamina AutoDash Threshold
  69.  * @desc Do not automatically dash again before stamina is above this threshold (%) when recovering stamina. (0-100)
  70.  * @default 40
  71.  *
  72.  * @param Use Custom Stamina Regen Formula?
  73.  * @desc Use a custom stamina regeneration formula? If true, then the parameter "Stamina Regen Formula" is used as the formula. When false the default formula is used (which executes slightly faster).
  74.  * @default false
  75.  *
  76.  * @param Stamina Regen Formula
  77.  * @desc The formula for how fast to regenerate stamina over longer period of time. "Base" is the recovery rate. Case sensitive!
  78.  * @default base + Math.sqrt(x/50);
  79.  *
  80.  * @param -- Visuals --
  81.  *
  82.  * @param Stamina Gauge Color 1
  83.  * @desc Bar gradient color1 (start of bar) in hex
  84.  * @default #009900
  85.  *
  86.  * @param Stamina Gauge Color 2
  87.  * @desc Bar gradient color2 (end of bar) in hex
  88.  * @default #CC0000
  89.  *
  90.  * @param Draw Stamina Value
  91.  * @desc Draw text in stamina bar? Accepted values: absolute/percentage/both/none
  92.  * @default percentage
  93.  *
  94.  * @param Font Size
  95.  * @desc Size for stamina value
  96.  * @default 20
  97.  *
  98.  * @param Auto Hide Stamina Window
  99.  * @desc Automatically hide the stamina window if it's at max stamina for a specific period of time? true/false
  100.  * @default true
  101.  *
  102.  * @param -- Window Prefix Text--
  103.  *
  104.  * @param Window Text
  105.  * @desc Use :none to disable this
  106.  * @default :none
  107.  *
  108.  * @param Window Text Offset Y
  109.  * @desc y-coordinate for the text
  110.  * @default 19
  111.  *
  112.  * @param Window Text Spacing X
  113.  * @desc amount of room in coordinates between text and gauge
  114.  * @default 4
  115.  *
  116.  * @param -- Window --
  117.  *
  118.  * @param Hide Stamina Window Delay
  119.  * @desc After how many updates the stamina window should hide itself (if it remains at max stamina)
  120.  * @default 160
  121.  *
  122.  * @param Stamina Window Opacity
  123.  * @desc Stamina window opacity. Set to 0 to hide the window (will still show the bar)
  124.  * @default 255
  125.  *
  126.  * @param Window Slideout Direction
  127.  * @desc What direction to slide the stamina window out to. NoSlide/Left/Top/Right/Bottom
  128.  * @default Left
  129.  *
  130.  * @param Window Slideout Speed
  131.  * @desc How fast the window slides in&out
  132.  * @default 2
  133.  *
  134.  * @param -- Advanced --
  135.  *
  136.  * @param Common Events At Stamina Values
  137.  * @desc Example to run common event 15 at 0 stamina and common event 17 at 100% stamina: 0 15 100% 17. Note that the common events will be called for EVERY FRAME for which it matches the stamina value/percentage.
  138.  *
  139.  * @param Disable Stamina Consumption GameSwitch
  140.  * @desc The gameswitch to use to disable stamina consumption (or -1 to use none). ON = disabled
  141.  * @default -1
  142.  *
  143.  * @param Window Z-Index
  144.  * @desc Window Z-Index. Value must be > 0.
  145.  * @default 1
  146.  *
  147.  * @param Plugin Command Identifier
  148.  * @desc Do not change if you do not know what this is!
  149.  * @default stamina
  150.  *
  151.  * @help
  152.  * -------------------------------------
  153.  * Plugin Commands (not case sensitive):
  154.  * -------------------------------------
  155.  *
  156.  * Stamina Refill
  157.  * Instantly refills all of your stamina.
  158.  *
  159.  * Stamina Set <value>
  160.  * Instantly sets your stamina to the specified percentage (0-100).
  161.  * Example to set your stamina bar to 64: Stamina Set 64
  162.  *
  163.  * Stamina SetVar <variableIndex>
  164.  * Instantly sets your stamina to the specified percentage (0-100).
  165.  * Example to set the stamina using game-variable #10: Stamina SetVar 10
  166.  *
  167.  * Stamina SetEval <eval>
  168.  * Instantly sets your stamina to the specified percentage (0-100).
  169.  * Example: Example Stamina SetEval ($gameVariables.value(10) + 1) / 2
  170.  *
  171.  * Stamina Deplete
  172.  * Instantly sets your stamina to 0.
  173.  *
  174.  * Stamina ShowWindow
  175.  * Shows the stamina window. Does not work if you disabled the stamina window.
  176.  *
  177.  * Stamina HideWindow
  178.  * Hides the stamina window. Does not work if you disabled the stamina window.
  179.  * Also does not work if the stamina is currently regenerating.
  180.  *
  181.  * Stamina RefillHide
  182.  * Instantly refills all of your stamina and also hides the stamina window.
  183.  *
  184.  * Stamina SetMax <value>
  185.  * Sets a new max-stamina value.
  186.  *
  187.  * Stamina SetMaxVar <variableIndex>
  188.  * Sets a new max-stamina value.
  189.  * Example to set the max-stamina using game-variable #10: Stamina SetMaxVar 10
  190.  *
  191.  * Stamina SetMaxEval <eval>
  192.  * Sets a new max-stamina value. But this time it evaluates the code you enter as <eva>.
  193.  * Example: Stamina SetMaxEval ($gameVariables.value(10) + 1) / 2
  194.  * The above example assigns a new max-stamina using the game-variable 10 and then adding a 1 and then dividing it all by 2.
  195.  *
  196.  * Stamina IncreaseMax <value>
  197.  * Increases max stamina by the specified value. You can also use negative values.
  198.  *
  199.  * Stamina EnableDashing <true/false/toggle>
  200.  * Allows or prohibits dashing on the map.
  201.  * Examples:
  202.  * Stamina EnableDashing true
  203.  * Stamina EnableDashing false
  204.  * Stamina EnableDashing toggle
  205.  * -------------------------------------
  206.  * Map Notetags
  207.  * -------------------------------------
  208.  * <dstam_disable>
  209.  * Prevents stamina consumption on this map. Not that if the "Disable Stamina Consumption GameSwitch"
  210.  * is turned ON then you consume no stamina anyway.
  211.  *
  212.  * <disable_dashing>
  213.  * Prevents dashing on the map (with or without stamina).
  214.  *
  215.  * -------------------------------------
  216.  * Item Notetags (not case sensitive)
  217.  * -------------------------------------
  218.  * <dash_stamina:command (value)>
  219.  * Available commands:
  220.  *  - Add (may have a negative value)
  221.  *  - Refill
  222.  *  - Deplete
  223.  *  - IncreaseMax (may have a negative value)
  224.  * Examples:
  225.  * <dash_stamina:Add 10>
  226.  * <dash_stamina:Add -10>
  227.  * <dash_stamina:Refill>
  228.  * <dash_stamina:Deplete>
  229.  * <dash_stamina:IncreaseMax 1500>
  230.  * Note that those only work from the menu, not from battle
  231.  *
  232.  *--------------------------------------
  233.  * Version History:
  234.  *--------------------------------------
  235.  * v1.07 (1 April 2016) [Parameters Changed]
  236.  * - Added a new parameter to run common events at certain stamina values/percentages. Note that the common events will be called for EVERY FRAME for which it matches the stamina value/percentage.
  237.  * - Added a new parameter "Use Custom Stamina Regen Formula?" for those who need more optimization. By default it does NOT use the custom formula (faster).
  238.  * - Added more comments to the code.
  239.  *
  240.  * v1.06 (26 March 2016)
  241.  * - Added new plugin commands: SetVar, SetEval, SetMaxEval & SetMaxVar.
  242.  * - The plugin command "Stamina EnableDashing" now accepts a third value: toggle.
  243.  *
  244.  * v1.05 (21 March 2016)
  245.  * - Added a new parameter "Stamina Decrease Mode". Now stamina can also be decreased on a per-tile-basis instead of only on a per-update-cycle-basis.
  246.  * - Added new functions and a new alias to accomodate the above new feature.
  247.  *
  248.  * v1.04 (03 February 2016)
  249.  * - Fixed a crash when transferring between maps using an autorun event with manual fading in or out (autorun stops execution of other events and some scripts like this one, which caused the crash).
  250.  *
  251.  * v1.03 (01 January 2016)
  252.  * - Used my new coding standards & refactored.
  253.  * - Switched to the Imported variable.
  254.  * - Fixed an accidental duplicate alias.
  255.  * - Fixed a bug in Scene_Map.prototype.updateMain() (which just so happened to cause no side-effects).
  256.  *
  257.  * v1.02 (12 December 2015)
  258.  * - Dashing for the current map can now be entirely disabled with a map-notetag and switched with a plugin command at any time.
  259.  * - Created a simple plugin addon to store the player-stamina in a global game-variable.
  260.  * - Enabled custom text to be drawn in front of the Stamina Window.
  261.  * - New feature: items can replenish, lower, refill and deplete stamina (only in the menu, not in battle).
  262.  *
  263.  * v1.01 (1 December 2015)
  264.  * - Removed strict-mode because... Possible bug in RPG Maker...
  265.  * - Refactored and fixed semicolons and missing var-keywords.
  266.  *
  267.  * v1.00 (26 November 2015)
  268.  * - First release.
  269.  * Alpha (November 2015)
  270.  * - First alpha release.
  271.  *
  272.  */
  273. // Imported
  274. var Imported = Imported || {};
  275. Imported.Silv_DashStamina = 1.07;
  276.  
  277. // #Parameters
  278. var Silv = Silv || {};
  279. Silv.Parameters = $plugins.filter(function(p) { return p.description.contains('<SilverStamina>'); })[0].parameters;
  280. Silv.DashStamina = Silv.DashStamina || {};
  281. // Non-parameters
  282. Silv.DashStamina.Window = null;
  283. Silv.DashStamina.ScreenIsFading = false;
  284. Silv.DashStamina.DashingDisabled = false;
  285. Silv.DashStamina.CommonEvents = [];
  286. Silv.DashStamina.HasCommonEvents = false;
  287. // General
  288. Silv.DashStamina.ShowWindow = Silv.Parameters['Show Stamina Window'].toLowerCase() === 'true';
  289. // Positioning & Size
  290. Silv.DashStamina.Window_X = parseInt(Silv.Parameters['Window X']);
  291. Silv.DashStamina.Window_Y = parseInt(Silv.Parameters['Window Y']);
  292. Silv.DashStamina.WindowWidth = parseInt(Silv.Parameters['Window Width']);
  293. Silv.DashStamina.WindowHeight = parseInt(Silv.Parameters['Window Height']);
  294. Silv.DashStamina.WindowHorizontalAlignment = (Silv.Parameters['Window Horizontal Alignment']).toLowerCase();
  295. Silv.DashStamina.WindowVerticalAlignment = (Silv.Parameters['Window Vertical Alignment']).toLowerCase();
  296. 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])};
  297. // Stamina Pool
  298. Silv.DashStamina.DecreaseMode = Silv.Parameters['Stamina Decrease Mode'].toLowerCase();
  299. Silv.DashStamina.StaminaDecrease = parseInt(Silv.Parameters['Stamina Decrease']);
  300. Silv.DashStamina.StaminaMax = parseInt(Silv.Parameters['Stamina Max']);
  301. Silv.DashStamina.StaminaRecoveryDelay = parseInt(Silv.Parameters['Stamina Recovery Delay']);
  302. Silv.DashStamina.StaminaRecoveryRate = parseInt(Silv.Parameters['Stamina Recovery Rate']);
  303. Silv.DashStamina.StaminaAutoDashThreshold = parseInt(Silv.Parameters['Stamina AutoDash Threshold']);
  304. Silv.DashStamina.UseCustomRegenFormula = Silv.Parameters['Use Custom Stamina Regen Formula?'].toLowerCase() === 'true';
  305. Silv.DashStamina.RegenFormula = Silv.Parameters['Stamina Regen Formula'];
  306. // Visuals
  307. Silv.DashStamina.StaminaGaugeColor1 = (Silv.Parameters['Stamina Gauge Color 1']).toUpperCase();
  308. Silv.DashStamina.StaminaGaugeColor2 = (Silv.Parameters['Stamina Gauge Color 2']).toUpperCase();
  309. Silv.DashStamina.DrawStaminaValue = Silv.Parameters['Draw Stamina Value'].toLowerCase();
  310. Silv.DashStamina.FontSize = parseInt(Silv.Parameters['Font Size']);
  311. // Window Prefix Text
  312. Silv.DashStamina.WindowText = Silv.Parameters['Window Text'];
  313. Silv.DashStamina.WindowTextOffsetY = parseInt(Silv.Parameters['Window Text Offset Y']);
  314. Silv.DashStamina.WindowTextGaugeSpacingX = parseInt(Silv.Parameters['Window Text Spacing X']);
  315. // Window
  316. Silv.DashStamina.AutoHideStaminaWindow = Silv.Parameters['Auto Hide Stamina Window'].toLowerCase() === 'true';
  317. Silv.DashStamina.HideStaminaWindowDelay = parseInt(Silv.Parameters['Hide Stamina Window Delay']);
  318. Silv.DashStamina.WindowOpacity = parseInt(Silv.Parameters['Stamina Window Opacity']);
  319. Silv.DashStamina.WindowSlideOutDir = Silv.Parameters['Window Slideout Direction'].toLowerCase();
  320. Silv.DashStamina.WindowSlideOutSpeed = parseFloat(Silv.Parameters['Window Slideout Speed']);
  321. // Advanced
  322. Silv.DashStamina.DisableGameSwitch = parseInt(Silv.Parameters['Disable Stamina Consumption GameSwitch']);
  323. Silv.DashStamina.Window_Z = parseInt(Silv.Parameters['Window Z-Index']);
  324. Silv.DashStamina.PluginCmdId = Silv.Parameters['Plugin Command Identifier'];
  325.  
  326. // Alias
  327. Silv.Alias = Silv.Alias || {};
  328. if (!Silv.AddAlias)
  329. {
  330.     Silv.AddAlias = function(alias, original_method)
  331.     {
  332.         if (Silv.Alias[alias]) { throw new Error('Alias already exists: ' + alias); }
  333.         Silv.Alias[alias] = original_method;
  334.     };
  335. }
  336.  
  337.  
  338. // Convert&store data for running common events at certain stamina percentages
  339. (function()
  340. {
  341.     var splitted = Silv.Parameters['Common Events At Stamina Values'].split(' ');
  342.     for (var ceIdx=0; ceIdx<splitted.length; ceIdx+=2)
  343.     {
  344.         var threshold = splitted[ceIdx];
  345.         var thresholdIsPerc = false;
  346.         if (~threshold.indexOf('%'))
  347.         {
  348.             thresholdIsPerc = true;
  349.             threshold = parseInt(threshold.slice(0, -1)); // Remove % character
  350.         }
  351.         else
  352.         {
  353.             threshold = parseInt(threshold);
  354.         }
  355.         var commonEventID = parseInt(splitted[ceIdx + 1]);
  356.        
  357.         Silv.DashStamina.CommonEvents[ceIdx / 2] = { threshold:threshold, thresholdIsPerc:thresholdIsPerc, commonEventID:commonEventID };
  358.     }
  359.     Silv.DashStamina.HasCommonEvents = (Silv.DashStamina.CommonEvents.length > 0);
  360. })();
  361.  
  362. // Sanity checks
  363. (function()
  364. {
  365.     if ((Silv.DashStamina.DecreaseMode !== 'default') && (Silv.DashStamina.DecreaseMode !== 'tile')) { throw new Error('Invalid parameter-value for "Decrease Mode": ' + Silv.DashStamina.DecreaseMode + '.'); }
  366. })();
  367. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  368. (function()
  369. {
  370. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  371. // Utilities
  372. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  373.  
  374. // Usage: alert( hexToRgb("#0033ff").g ); // "51";
  375. function hexToRgb(hex)
  376. {
  377.     var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  378.     return result ? {
  379.         r: parseInt(result[1], 16),
  380.         g: parseInt(result[2], 16),
  381.         b: parseInt(result[3], 16)
  382.     } : null;
  383. }
  384.  
  385. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  386. // Game Player
  387. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  388. //------------------------------------------------------------------------------------------------------------------------------------
  389. // Can the player possibly consume stamina?
  390. //------------------------------------------------------------------------------------------------------------------------------------
  391. Game_Player.prototype.hasStaminaConsumption = function()
  392. {
  393.     if ($gameSwitches.value(Silv.DashStamina.DisableGameSwitch)) { return false; }
  394.     if (!this.mapConsumeStamina) { return false; }
  395.     return true;
  396. };
  397.  
  398. //------------------------------------------------------------------------------------------------------------------------------------
  399. // Alias for whenever the player entered a new tile
  400. //------------------------------------------------------------------------------------------------------------------------------------
  401. Silv.AddAlias('dashStamina_Game_Player_updateMove', Game_Player.prototype.updateMove);
  402. Game_Player.prototype.updateMove = function()
  403. {
  404.     Silv.Alias.dashStamina_Game_Player_updateMove.apply(this, arguments);
  405.     if ((Silv.DashStamina.DecreaseMode === 'tile') && !this.isMoving() && this.isDashing() && this.hasStaminaConsumption())
  406.     {
  407.         // Consume stamina for the tile-decrease-mode
  408.         this.dashStamina -= Silv.DashStamina.StaminaDecrease;
  409.         this.postDecreaseStaminaHandling();
  410.     }
  411. };
  412.  
  413. //------------------------------------------------------------------------------------------------------------------------------------
  414. // Is&can the player consume stamina?
  415. //------------------------------------------------------------------------------------------------------------------------------------
  416. Game_Player.prototype.isConsumingStamina = function()
  417. {
  418.     return (this.isDashing() && this.isMoving() && this.hasStaminaConsumption());
  419. };
  420.  
  421. //------------------------------------------------------------------------------------------------------------------------------------
  422. // Call this method after decreasing the stamina
  423. //------------------------------------------------------------------------------------------------------------------------------------
  424. Game_Player.prototype.postDecreaseStaminaHandling = function()
  425. {
  426.     if (this.dashStamina < 0) { this.dashStamina = 0; }
  427.     this.isRecoveringStamina = false;
  428.     if (Silv.DashStamina.ShowWindow && !Silv.DashStamina.ScreenIsFading) { Silv.DashStamina.Window.showMe(); }
  429. };
  430.  
  431. //------------------------------------------------------------------------------------------------------------------------------------
  432. // Check if common events need running
  433. //------------------------------------------------------------------------------------------------------------------------------------
  434. Game_Player.prototype.staminaEventChecks = function()
  435. {
  436.     if (Silv.DashStamina.HasCommonEvents)
  437.     {
  438.         var staminaPercRounded = Math.round(this.dashStaminaPerc * 100);
  439.        
  440.         for (var ceIdx=0; ceIdx<Silv.DashStamina.CommonEvents.length; ceIdx++)
  441.         {
  442.             if (Silv.DashStamina.CommonEvents[ceIdx].thresholdIsPerc)
  443.             {
  444.                 if (staminaPercRounded === Silv.DashStamina.CommonEvents[ceIdx].threshold) { $gameTemp.reserveCommonEvent(Silv.DashStamina.CommonEvents[ceIdx].commonEventID); }
  445.             }
  446.             else
  447.             {
  448.                 if (this.dashStamina === Silv.DashStamina.CommonEvents[ceIdx].threshold) { $gameTemp.reserveCommonEvent(Silv.DashStamina.CommonEvents[ceIdx].commonEventID); }
  449.             }
  450.         }
  451.     }
  452. };
  453.  
  454. //------------------------------------------------------------------------------------------------------------------------------------
  455. // #Update Stamina
  456. //------------------------------------------------------------------------------------------------------------------------------------
  457. Game_Player.prototype.updateStamina = function()
  458. {
  459.     var isConsumingStamina = this.isConsumingStamina();
  460.     if (isConsumingStamina)
  461.     {
  462.         if (Silv.DashStamina.DecreaseMode === 'default') { this.dashStamina -= Silv.DashStamina.StaminaDecrease; } // Only consume stamina here if the decrease-mode is set to default
  463.         this.postDecreaseStaminaHandling();
  464.     }
  465.     else // not currently consuming stamina
  466.     {      
  467.         if (this.isRecoveringStamina)
  468.         {
  469.             this.staminaRecoveryTimeCnt++;
  470.             if (this.dashStamina < this.dashStaminaMax) // Recover the stamina
  471.             {
  472.                 // Recover stamina
  473.                 this.dashStamina += this.calculateStaminaRegen(Silv.DashStamina.StaminaRecoveryRate);
  474.                 Silv.DashStamina.clampMaxStamina();
  475.                
  476.                 if (Silv.DashStamina.ShowWindow && !Silv.DashStamina.ScreenIsFading) { Silv.DashStamina.Window.showMe(); }
  477.             }
  478.             else // Already at max stamina, find out when to hide the window if applicable and do so if possible
  479.             {
  480.                 // If the stamina window is used, attempt to autohide it if applicable
  481.                 if (Silv.DashStamina.ShowWindow && Silv.DashStamina.AutoHideStaminaWindow)
  482.                 {
  483.                     this.hideStaminaWindowDelayCnt += 1;
  484.                     if (this.hideStaminaWindowDelayCnt >= Silv.DashStamina.HideStaminaWindowDelay)
  485.                     {
  486.                         Silv.DashStamina.Window.hideMe();
  487.                         this.hideStaminaWindowDelayCnt = 0;
  488.                     }
  489.                 }
  490.                    
  491.             }
  492.         }
  493.         else // not currently recovering stamina, so find out when to start recovering it and do so if required
  494.         {
  495.             this.staminaRecoveryTimeCnt = 0;
  496.             this.staminaRecoveryDelayCnt += 1;
  497.             if (this.staminaRecoveryDelayCnt >= Silv.DashStamina.StaminaRecoveryDelay)
  498.             {
  499.                 this.staminaRecoveryDelayCnt = 0;
  500.                 this.isRecoveringStamina = true;
  501.             }
  502.         }
  503.     }
  504.  
  505.     // Stamina Percentage
  506.     this.dashStaminaPerc = this.dashStamina / parseFloat(this.dashStaminaMax);
  507.  
  508.     // Threshold
  509.     if (!isConsumingStamina)
  510.     {
  511.         this.requiresThresholdAmount = this.dashStaminaPerc * 100 < Silv.DashStamina.StaminaAutoDashThreshold;
  512.     }
  513.    
  514.     this.staminaEventChecks();
  515. };
  516.  
  517. //------------------------------------------------------------------------------------------------------------------------------------
  518. // Regeneration Formula
  519. //------------------------------------------------------------------------------------------------------------------------------------
  520. Game_Player.prototype.calculateStaminaRegen = function()
  521. {
  522.     if (!Silv.DashStamina.UseCustomRegenFormula) { return this.calculateStaminaRegenEval(); }
  523.     else { return this.calculateStaminaRegenNoEval();}
  524. };
  525.    
  526. Game_Player.prototype.calculateStaminaRegenEval = function()
  527. {
  528.     var base = Silv.DashStamina.StaminaRecoveryRate;
  529.     var x = this.staminaRecoveryTimeCnt;
  530.     return eval(Silv.DashStamina.RegenFormula);
  531. };
  532.  
  533. Game_Player.prototype.calculateStaminaRegenNoEval = function()
  534. {
  535.     return Silv.DashStamina.StaminaRecoveryRate + Math.sqrt(this.staminaRecoveryTimeCnt / 50);
  536. };
  537.  
  538. //------------------------------------------------------------------------------------------------------------------------------------
  539. // #Initialize
  540. //------------------------------------------------------------------------------------------------------------------------------------
  541. Silv.AddAlias('dashStamina_Game_Player_initialize', Game_Player.prototype.initialize);
  542. Game_Player.prototype.initialize = function()
  543. {
  544.     Silv.Alias.dashStamina_Game_Player_initialize.apply(this, arguments);
  545.  
  546.     this.dashStamina = this.dashStaminaMax = Silv.DashStamina.StaminaMax;
  547.     this.staminaRecoveryDelayCnt = 0; // counter for when to start recovering stamina
  548.     this.staminaRecoveryTimeCnt = 0; // counter for how long the player has been recovering stamina (in frames)
  549.     this.isRecoveringStamina = false;
  550.     this.dashStaminaPerc = 1.0;
  551.     this.hideStaminaWindowDelayCnt = 0;
  552.     this.requiresThresholdAmount = false;
  553.     this.wasDashing = false;
  554. };
  555.  
  556. //------------------------------------------------------------------------------------------------------------------------------------
  557. // Is the player currently allowed to dash?
  558. //------------------------------------------------------------------------------------------------------------------------------------
  559. Game_Player.prototype.dashingAllowed = function()
  560. {
  561.     if (this.dashStamina === 0 ||
  562.        (!this.wasDashing && this.requiresThresholdAmount)) // Do not allow to dash if the player was not dashing the previous frame AND if the threshold was passed.
  563.     {
  564.         return false;
  565.     }
  566.    
  567.     return true;
  568. };
  569.  
  570. //------------------------------------------------------------------------------------------------------------------------------------
  571. // Alias for disallowing dashing
  572. //------------------------------------------------------------------------------------------------------------------------------------
  573. Silv.AddAlias('dashStamina_Game_Player_updateDashing', Game_Player.prototype.updateDashing);
  574. Game_Player.prototype.updateDashing = function()
  575. {
  576.     Silv.Alias.dashStamina_Game_Player_updateDashing.apply(this, arguments);
  577.    
  578.     if (Silv.DashStamina.DashingDisabled)
  579.     {
  580.         this._dashing = false;
  581.         return;
  582.     }
  583.    
  584.     if (!this.dashingAllowed()) { this._dashing = false; }
  585.     this.wasDashing = this._dashing;
  586. };
  587.  
  588. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  589. // Game Screen
  590. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  591. // Do not just show the minimap on top of a faded-out screen.
  592. Silv.AddAlias('dashStamina_Game_Screen_updateFadeOut', Game_Screen.prototype.updateFadeOut);
  593. Game_Screen.prototype.updateFadeOut = function()
  594. {
  595.     Silv.Alias.dashStamina_Game_Screen_updateFadeOut.apply(this, arguments);
  596.    
  597.     if (this._brightness < 255) // (this._fadeOutDuration > 0)
  598.     {
  599.         if (Silv.DashStamina.Window !== null) { Silv.DashStamina.Window.visible = false; }
  600.         Silv.DashStamina.ScreenIsFading = true;
  601.     }
  602.     else
  603.     {
  604.         Silv.DashStamina.ScreenIsFading = false;
  605.     }
  606. };
  607.  
  608. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  609. // Scene Base
  610. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  611. Silv.AddAlias('dashStamina_Scene_Base_startFadeIn', Scene_Base.prototype.startFadeIn);
  612. Scene_Base.prototype.startFadeIn = function()
  613. {
  614.     Silv.Alias.dashStamina_Scene_Base_startFadeIn.apply(this, arguments);
  615.     if (Silv.DashStamina.Window !== null) { Silv.DashStamina.Window.visible = false; }
  616. };
  617.  
  618. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  619. // Scene Map
  620. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  621. // Hook into the main loop
  622. Silv.AddAlias('dashStamina_Scene_Map_updateMain', Scene_Map.prototype.updateMain);
  623. Scene_Map.prototype.updateMain = function()
  624. {
  625.     Silv.Alias.dashStamina_Scene_Map_updateMain.apply(this, arguments);
  626.     $gamePlayer.updateStamina();
  627.     if (Silv.DashStamina.ShowWindow) { Silv.DashStamina.Window.update(); }
  628. };
  629.  
  630. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  631. // Game Map
  632. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  633. // Disable Dashing?
  634. Silv.AddAlias('dashStamina_Game_Map_setup', Game_Map.prototype.setup);
  635. Game_Map.prototype.setup = function(mapId)
  636. {
  637.     Silv.Alias.dashStamina_Game_Map_setup.apply(this, arguments);
  638.     Silv.DashStamina.DashingDisabled = ('disable_dashing' in $dataMap.meta);
  639. };
  640.  
  641. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  642. // Stamina Regen/Deplete #Items
  643. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  644. Silv.AddAlias('dashStamina_Scene_ItemBase_useItem', Scene_ItemBase.prototype.useItem);
  645. Scene_ItemBase.prototype.useItem = function()
  646. {
  647.     var item = this.item();
  648.     if ('dash_stamina' in item.meta)
  649.     {
  650.         var args = item.meta.dash_stamina.split(' ');
  651.         switch(args[0].toLowerCase())
  652.         {
  653.             case 'add':
  654.                 if (args.length < 2) { throw 'Item-add-command is missing the value-argument.'; }
  655.                 $gamePlayer.dashStamina += parseInt(args[1]);
  656.                 if ($gamePlayer.dashStamina > $gamePlayer.dashStaminaMax) { $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax; }
  657.                 else if ($gamePlayer.dashStamina < 0) { $gamePlayer.dashStamina = 0; }
  658.                 break;
  659.             case 'refill':
  660.                 $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax;
  661.                 break;
  662.             case 'deplete':
  663.                 $gamePlayer.dashStamina = 0;
  664.                 break;
  665.             case 'increasemax':
  666.                 if (args.length < 2) { throw 'Item-increasemax-command is missing the value-argument.'; }
  667.                 $gamePlayer.dashStaminaMax += parseInt(args[1]);
  668.                 if ($gamePlayer.dashStaminaMax < 1 ) { $gamePlayer.dashStaminaMax = 1; }
  669.                 break;
  670.             default:
  671.                 throw 'Unknown dash_stamina itemnotetag: ' + item.meta;
  672.         }
  673.        
  674.     }
  675.    
  676.     Silv.Alias.dashStamina_Scene_ItemBase_useItem.apply(this, arguments);
  677. };
  678.  
  679. Silv.AddAlias('dashStamina_Game_Action_testApply', Game_Action.prototype.testApply);
  680. Game_Action.prototype.testApply = function(target)
  681. {
  682.     if ('dash_stamina' in this.item().meta)
  683.     {
  684.         return true;
  685.     }
  686.     else
  687.     {
  688.         return Silv.Alias.dashStamina_Game_Action_testApply.apply(this, arguments);
  689.     }
  690. };
  691. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  692. // Stamina #Window
  693. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  694. function Window_DashStamina() { this.initialize.apply(this, arguments); }
  695. Window_DashStamina.prototype = Object.create(Window_Base.prototype);
  696. Window_DashStamina.prototype.constructor = Window_DashStamina;
  697. // Font Size
  698. Window_DashStamina.prototype.standardFontSize = function() { return Silv.DashStamina.FontSize; };
  699.  
  700. // #Initialize
  701. Window_DashStamina.prototype.initialize = function(x, y, width, height)
  702. {
  703.     Window_Base.prototype.initialize.call(this, x, y, width, height);
  704.     this._helpWindow = null;
  705.     this._handlers = {};
  706.     this._touching = false;
  707.     this.deactivate();
  708.    
  709.     this.opacity = Silv.DashStamina.WindowOpacity;
  710.     this.slideDirection = {x: 0, y: 0 };
  711.     this.originalWinLoc = {x: 0, y: 0 };
  712.     this.sliding = 'none';
  713.     this.isFullySlidedOut = false;
  714.     this.isFullySlidedIn = true;
  715.     this.originalWinLoc.x = x; // for some reason "this." is not allowed here
  716.     this.originalWinLoc.y = y; // for some reason "this." is not allowed here
  717.    
  718.     if (Silv.DashStamina.WindowText != ':none')
  719.     {
  720.         this.windowText = Silv.DashStamina.WindowText;
  721.         this.windowTextWidth = this.contents.measureTextWidth(this.windowText);
  722.         this.windowTextGaugeSpacingX = Silv.DashStamina.WindowTextGaugeSpacingX;
  723.     }
  724.     else
  725.     {
  726.         this.windowText = null;
  727.         this.windowTextWidth = 0;
  728.         this.windowTextGaugeSpacingX = Silv.DashStamina.WindowTextGaugeSpacingX;
  729.     }
  730.    
  731.     this.update();
  732. };
  733.  
  734. //------------------------------------------------------------------------------------------------------------------------------------
  735. // Stamina Window Update
  736. //------------------------------------------------------------------------------------------------------------------------------------
  737. Window_DashStamina.prototype.update = function()
  738. {
  739.     if (Silv.DashStamina.ScreenIsFading)
  740.     {
  741.         this.visible = false;
  742.     }
  743.     else
  744.     {
  745.         Window_Base.prototype.update.call(this);
  746.         this.drawStaminaWindow(0, 0, Silv.DashStamina.StaminaGaugeRectangle.width);
  747.         this.updateSliding();
  748.     }
  749. };
  750.  
  751. //------------------------------------------------------------------------------------------------------------------------------------
  752. // Stamina Window #Drawing
  753. //------------------------------------------------------------------------------------------------------------------------------------
  754. Window_DashStamina.prototype.drawStaminaGauge = function(x, y, width, height, rate)
  755. {
  756.     var fillW = Math.floor(width * rate);
  757.     var gaugeY = y + this.lineHeight() - 8;
  758.     this.contents.fillRect(x, gaugeY, width, height, this.gaugeBackColor());
  759.     this.contents.fillRect(x, gaugeY, fillW, height, this.CalculateBarColour());
  760. };
  761.  
  762. Window_DashStamina.prototype.drawStaminaWindow = function(x, y, width)
  763. {
  764.     this.contents.clear();
  765.    
  766.     // Draw text before the gauge
  767.     if (this.windowText !== null)
  768.     {
  769.         this.contents.drawText(this.windowText, 0, Silv.DashStamina.WindowTextOffsetY, this.windowTextWidth, 0);
  770.     }
  771.  
  772.     // Draw gauge
  773.     this.drawStaminaGauge(Silv.DashStamina.StaminaGaugeRectangle.x + this.windowTextWidth + this.windowTextGaugeSpacingX, Silv.DashStamina.StaminaGaugeRectangle.y, Silv.DashStamina.StaminaGaugeRectangle.width, Silv.DashStamina.StaminaGaugeRectangle.height, $gamePlayer.dashStaminaPerc);
  774.     // Draw text on top of the gauge
  775.     var text;
  776.     switch(Silv.DashStamina.DrawStaminaValue) // allowed values: absolute/percentage/both/none
  777.     {
  778.         case 'absolute':
  779.             text = parseInt($gamePlayer.dashStamina) + '/' + parseInt($gamePlayer.dashStaminaMax);
  780.             break;
  781.         case 'percentage':
  782.             text = Math.round($gamePlayer.dashStaminaPerc * 100) + '%';
  783.             break;
  784.         case 'both':
  785.             text = parseInt($gamePlayer.dashStamina) + '/' + parseInt($gamePlayer.dashStaminaMax) + ' (' + Math.round($gamePlayer.dashStaminaPerc * 100) + '%)';
  786.             break;
  787.         case 'none':
  788.             return;
  789.         default:
  790.             throw 'ERROR: drawStaminaWindow missing case-statement or incorrect Silv.DashStamina.DrawStaminaValue value. Value: ' + Silv.DashStamina.DrawStaminaValue;
  791.     }
  792.    
  793.     this.resetTextColor();
  794.     this.drawText(text, x + this.windowTextWidth + this.windowTextGaugeSpacingX, y + 1, width, 'center');
  795. };
  796.  
  797. // Calculate what colour the gauge should be between the two colors depending on the percentage value of the current-stamina value.
  798. Window_DashStamina.prototype.CalculateBarColour = function()
  799. {
  800.     var c1 = hexToRgb(Silv.DashStamina.StaminaGaugeColor1);
  801.     var c2 = hexToRgb(Silv.DashStamina.StaminaGaugeColor2);
  802.        
  803.     var ratio = $gamePlayer.dashStaminaPerc;
  804.     var hex = function(x) {
  805.         x = x.toString(16);
  806.         return (x.length === 1) ? '0' + x : x;
  807.     };
  808.  
  809.     var r = Math.ceil(c1.r * ratio + c2.r * (1-ratio));
  810.     var g = Math.ceil(c1.g * ratio + c2.g * (1-ratio));
  811.     var b = Math.ceil(c1.b * ratio + c2.b * (1-ratio));
  812.  
  813.     var middle = '#' + hex(r) + hex(g) + hex(b);
  814.     return middle;
  815. };
  816.  
  817. //------------------------------------------------------------------------------------------------------------------------------------
  818. // Stamina Window #Show & #Hide
  819. //------------------------------------------------------------------------------------------------------------------------------------
  820. Window_DashStamina.prototype.showMe = function()
  821. {
  822.     //if (this.visible) { return; };
  823.     if (this.isFullySlidedIn)
  824.     {
  825.         this.visible = true;
  826.         return;
  827.     }
  828.    
  829.     if (Silv.DashStamina.WindowSlideOutDir === 'noslide' || this.visible === false) { this.visible = true; }
  830.     else
  831.     {
  832.         this.sliding = 'in';
  833.         switch (Silv.DashStamina.WindowSlideOutDir)
  834.         {
  835.             case 'top':
  836.                 this.slideDirection.x = 0;
  837.                 this.slideDirection.y = 1;
  838.                 break;
  839.             case 'left':
  840.                 this.slideDirection.x = 1;
  841.                 this.slideDirection.y = 0;
  842.                 break;
  843.             case 'right':
  844.                 this.slideDirection.x = -1;
  845.                 this.slideDirection.y = 0;
  846.                 break;
  847.             case 'bottom':
  848.                 this.slideDirection.x = 0;
  849.                 this.slideDirection.y = -1;
  850.                 break;
  851.             default:
  852.                 throw 'Window_DashStamina.prototype.HideMe: Unknown switch value: ' + Silv.DashStamina.WindowSlideOutDir;
  853.         }
  854.     }
  855. };
  856.  
  857. Window_DashStamina.prototype.hideMe = function()
  858. {
  859.     if (!this.visible || this.isFullySlidedOut) { return; }
  860.    
  861.     if (Silv.DashStamina.WindowSlideOutDir === 'noslide') { this.visible = false; }
  862.     else
  863.     {
  864.         this.sliding = 'out';
  865.         switch (Silv.DashStamina.WindowSlideOutDir)
  866.         {
  867.             case 'top':
  868.                 this.slideDirection.x = 0;
  869.                 this.slideDirection.y = -1;
  870.                 break;
  871.             case 'left':
  872.                 this.slideDirection.x = -1;
  873.                 this.slideDirection.y = 0;
  874.                 break;
  875.             case 'right':
  876.                 this.slideDirection.x = 1;
  877.                 this.slideDirection.y = 0;
  878.                 break;
  879.             case 'bottom':
  880.                 this.slideDirection.x = 0;
  881.                 this.slideDirection.y = 1;
  882.                 break;
  883.             default:
  884.                 throw 'Window_DashStamina.prototype.HideMe: Unknown switch value: ' + Silv.DashStamina.WindowSlideOutDir;
  885.         }
  886.     }
  887. };
  888.  
  889. //------------------------------------------------------------------------------------------------------------------------------------
  890. // Stamina Window #Sliding of the Window
  891. //------------------------------------------------------------------------------------------------------------------------------------
  892. Window_DashStamina.prototype.handleSlidingEnd = function()
  893. {
  894.     if (this.sliding === 'in')
  895.     {
  896.         // Stop sliding in
  897.         if (this.slideDirection.x  === 1 && this.x > this.originalWinLoc.x ||
  898.             this.slideDirection.x  === -1 && this.x < this.originalWinLoc.x ||
  899.             this.slideDirection.y  === 1 && this.y > this.originalWinLoc.y ||
  900.             this.slideDirection.y  === -1 && this.y < this.originalWinLoc.y)
  901.         {
  902.             this.sliding = 'none';
  903.             this.isFullySlidedIn = true;
  904.         }
  905.     }
  906.     else
  907.     {
  908.         // Stop sliding out
  909.         if (this.x < -this.width || this.x > Graphics._width + this.width ||
  910.             this.y < -this.height || this.x > Graphics._height + this.height)
  911.         {
  912.             this.sliding = 'none';
  913.             this.isFullySlidedOut = true;
  914.         }
  915.     }
  916. };
  917.  
  918. Window_DashStamina.prototype.updateSliding = function()
  919. {
  920.     if (this.sliding === 'none') { return; }
  921.     this.x += this.slideDirection.x * Silv.DashStamina.WindowSlideOutSpeed;
  922.     this.y += this.slideDirection.y * Silv.DashStamina.WindowSlideOutSpeed;
  923.    
  924.     this.isFullySlidedOut = false;
  925.     this.isFullySlidedIn = false;
  926.    
  927.     this.handleSlidingEnd();
  928. };
  929.  
  930. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  931. // #Create Stamina Window
  932. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  933. Scene_Map.prototype.createDashWindow = function()
  934. {
  935.     // Dispose the old window, if any
  936.     if (Silv.DashStamina.Window !== null) { this.removeWindow(Silv.DashStamina.Window); }
  937.    
  938.     // Does the map consume stamina?
  939.     $gamePlayer.mapConsumeStamina = !('dstam_disable' in $dataMap.meta);
  940.     if(Silv.DashStamina.ShowWindow)
  941.     {
  942.         var x = 0;
  943.         if (Silv.DashStamina.WindowHorizontalAlignment === 'right') { x = Graphics.width - Silv.DashStamina.WindowWidth; }
  944.         var y = 0;
  945.         if (Silv.DashStamina.WindowVerticalAlignment === 'bottom') { y = Graphics.height - Silv.DashStamina.WindowHeight; }
  946.        
  947.         Silv.DashStamina.Window = new Window_DashStamina(x + Silv.DashStamina.Window_X, y + Silv.DashStamina.Window_Y, Silv.DashStamina.WindowWidth, Silv.DashStamina.WindowHeight);
  948.        
  949.         this.addChild(Silv.DashStamina.Window, Silv.DashStamina.Window_Z);
  950.         if (Silv.DashStamina.AutoHideStaminaWindow) { Silv.DashStamina.Window.visible = false; }
  951.     }
  952. };
  953.  
  954. // Omg why does RPG Maker not have this method by default...
  955. Scene_Base.prototype.removeWindow = function(window)
  956. {
  957.     var index = this.children.indexOf(window);
  958.     if (index > -1) { this.children.splice(index, 1); }
  959. };
  960.  
  961. Silv.AddAlias('dashStamina_Scene_Map_createDisplayObjects', Scene_Map.prototype.createDisplayObjects);
  962. Scene_Map.prototype.createDisplayObjects = function()
  963. {
  964.     Silv.Alias.dashStamina_Scene_Map_createDisplayObjects.apply(this, arguments);
  965.     this.createDashWindow();
  966. };
  967.  
  968. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  969. // Saving & Loading
  970. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  971. Silv.AddAlias('dashStamina_DataManager_makeSaveContents', DataManager.makeSaveContents);
  972. DataManager.makeSaveContents = function()
  973. {
  974.     contents = Silv.Alias.dashStamina_DataManager_makeSaveContents.apply(this, arguments);
  975.     contents.dashStamina = $gamePlayer.dashStamina;
  976.     contents.dashStaminaMax = $gamePlayer.dashStaminaMax;
  977.     return contents;
  978. };
  979.  
  980. Silv.AddAlias('dashStamina_DataManager_extractSaveContents', DataManager.extractSaveContents);
  981. DataManager.extractSaveContents = function(contents)
  982. {
  983.     Silv.Alias.dashStamina_DataManager_extractSaveContents.apply(this, arguments);
  984.     $gamePlayer.dashStamina = contents.dashStamina;
  985.     $gamePlayer.dashStaminaMax = contents.dashStaminaMax;
  986. };
  987.  
  988. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  989. // Plugin Command
  990. // Note: The items are separated by spaces. The command is the first word and any following words are args. args is an array.
  991. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  992. Silv.AddAlias('dashStamina_Game_Interpreter_pluginCommand', Game_Interpreter.prototype.pluginCommand);
  993. Game_Interpreter.prototype.pluginCommand = function(command, args)
  994. {
  995.     Silv.Alias.dashStamina_Game_Interpreter_pluginCommand.apply(this, arguments);
  996.     if (command.toLowerCase() === Silv.DashStamina.PluginCmdId) { Silv.DashStamina.PluginCommand(command, args); }
  997. };
  998.  
  999. // Concatenate the 'arguments' starting at a specific index because they are all part of an eval.
  1000. Silv.DashStamina.concatArgs = function(args, startIdx)
  1001. {
  1002.     var evalstr = '';
  1003.     for (var argIdx = startIdx; argIdx < args.length; argIdx++)
  1004.     {
  1005.         evalstr += args[argIdx] + ' ';
  1006.     }
  1007.     return evalstr;
  1008. };
  1009.  
  1010. // newValue must be between 0 - 100.
  1011. Silv.DashStamina.assignNewStaminaValue = function(newValue)
  1012. {
  1013.     var perc = Math.max(0, Math.min(100, newValue)); // clamp value between 0-100
  1014.     $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax * (perc / 100.0);
  1015. };
  1016.  
  1017. Silv.DashStamina.clampMaxStamina = function()
  1018. {
  1019.     if ($gamePlayer.dashStamina > $gamePlayer.dashStaminaMax) { $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax; }
  1020. };
  1021.  
  1022. Silv.DashStamina.PluginCommand = function(cmd, args)
  1023. {
  1024.     switch(args[0].toLowerCase())
  1025.     {
  1026.         case 'refill':
  1027.             $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax;
  1028.             break;
  1029.         case 'deplete':
  1030.             $gamePlayer.dashStamina = 0;
  1031.             break;
  1032.         case 'set':
  1033.             Silv.DashStamina.assignNewStaminaValue(parseInt(args[1]));
  1034.         break;
  1035.         case 'setvar':
  1036.             Silv.DashStamina.assignNewStaminaValue(parseInt($gameVariables.value(args[1])));
  1037.         break;
  1038.         case 'seteval':
  1039.             var perc = parseInt(eval(Silv.DashStamina.concatArgs(args, 1)));
  1040.             if (isNaN(perc)) { throw new Error('Plugin command: "Stamina SetEval" evaled to a NaN value: ' + perc + '.'); }
  1041.             Silv.DashStamina.assignNewStaminaValue(perc);
  1042.         break;
  1043.         case 'showwindow':
  1044.             if (Silv.DashStamina.Window !== null)
  1045.             {
  1046.                 $gamePlayer.hideStaminaWindowDelayCnt = 0;
  1047.                 Silv.DashStamina.Window.visible = true;
  1048.             }
  1049.             break;
  1050.         case 'refillhide':
  1051.             $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax;
  1052.             // NO break-statement here! We want to hide the window as well!
  1053.         case 'hidewindow':
  1054.             if (Silv.DashStamina.Window !== null)
  1055.             {
  1056.                 $gamePlayer.hideStaminaWindowDelayCnt = Silv.DashStamina.HideStaminaWindowDelay;
  1057.                 Silv.DashStamina.Window.visible = false;
  1058.             }
  1059.             break;
  1060.         case 'setmax':
  1061.             $gamePlayer.dashStaminaMax = Math.max(1, parseInt(args[1]));
  1062.             Silv.DashStamina.clampMaxStamina();
  1063.             break;
  1064.         case 'setmaxeval':
  1065.             $gamePlayer.dashStaminaMax = Math.max(1, parseInt(eval(Silv.DashStamina.concatArgs(args, 1))));
  1066.             Silv.DashStamina.clampMaxStamina();
  1067.             break;
  1068.         case 'setmaxvar':
  1069.             $gamePlayer.dashStaminaMax = Math.max(1, parseInt($gameVariables.value(args[1])));
  1070.             Silv.DashStamina.clampMaxStamina();
  1071.             break;
  1072.         case 'increasemax':
  1073.             $gamePlayer.dashStaminaMax += parseInt(args[1]);
  1074.             if ($gamePlayer.dashStaminaMax < 1) { $gamePlayer.dashStaminaMax = 1; }
  1075.             if ($gamePlayer.dashStamina > $gamePlayer.dashStaminaMax) { $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax; }
  1076.             break;
  1077.         case 'enabledashing':
  1078.             switch(args[1].toLowerCase())
  1079.             {
  1080.                 case 'true':
  1081.                     Silv.DashStamina.DashingDisabled = false;
  1082.                     break;
  1083.                 case 'false':
  1084.                     Silv.DashStamina.DashingDisabled = true;
  1085.                     break;
  1086.                 case 'toggle':
  1087.                     Silv.DashStamina.DashingDisabled = !Silv.DashStamina.DashingDisabled;
  1088.                     break;
  1089.                 default:
  1090.                     throw new Error('"Stamina EnableDashing" received an unknown argument: ' + args[1] + '. Expected: True, False or Toggle.');
  1091.             }
  1092.             break;
  1093.         default:
  1094.             throw 'Stamina PluginCommand invalid command: ' + args[0];
  1095.     }
  1096. };
  1097.  
  1098. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1099. })();
  1100. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1101. // This is the end of this awesome script!
  1102. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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