SHARE
TWEET

Untitled

a guest Jan 1st, 2016 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // SilvStamina.js
  3. // Version: 1.03
  4. //=============================================================================
  5. /*:
  6.  * @plugindesc v1.03 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 Prefix Text--
  95.  *
  96.  * @param Window Text
  97.  * @desc Use :none to disable this
  98.  * @default :none
  99.  *
  100.  * @param Window Text Offset Y
  101.  * @desc y-coordinate for the text
  102.  * @default 19
  103.  *
  104.  * @param Window Text Spacing X
  105.  * @desc amount of room in coordinates between text and gauge
  106.  * @default 4
  107.  *
  108.  * @param -- Window --
  109.  *
  110.  * @param Hide Stamina Window Delay
  111.  * @desc After how many updates the stamina window should hide itself (if it remains at max stamina)
  112.  * @default 160
  113.  *
  114.  * @param Stamina Window Opacity
  115.  * @desc Stamina window opacity. Set to 0 to hide the window (will still show the bar)
  116.  * @default 255
  117.  *
  118.  * @param Window Slideout Direction
  119.  * @desc What direction to slide the stamina window out to. NoSlide/Left/Top/Right/Bottom
  120.  * @default Left
  121.  *
  122.  * @param Window Slideout Speed
  123.  * @desc How fast the window slides in&out
  124.  * @default 2
  125.  *
  126.  * @param -- Advanced --
  127.  *
  128.  * @param Disable Stamina Consumption GameSwitch
  129.  * @desc The gameswitch to use to disable stamina consumption (or -1 to use none). ON = disabled
  130.  * @default -1
  131.  *
  132.  * @param Window Z-Index
  133.  * @desc Window Z-Index. Value must be > 0.
  134.  * @default 1
  135.  *
  136.  * @param Plugin Command Identifier
  137.  * @desc Do not change if you do not know what this is!
  138.  * @default stamina
  139.  *
  140.  * @help
  141.  * -------------------------------------
  142.  * Plugin Commands (not case sensitive):
  143.  * -------------------------------------
  144.  *
  145.  * Stamina Refill
  146.  * Instantly refills all of your stamina.
  147.  *
  148.  * Stamina Set <value>
  149.  * Instantly sets your stamina to the specified percentage (0-100).
  150.  * Example to set your stamina bar to 64: Stamina Set 64
  151.  *
  152.  * Stamina Deplete
  153.  * Instantly sets your stamina to 0.
  154.  *
  155.  * Stamina ShowWindow
  156.  * Shows the stamina window. Does not work if you disabled the stamina window.
  157.  *
  158.  * Stamina HideWindow
  159.  * Hides the stamina window. Does not work if you disabled the stamina window.
  160.  * Also does not work if the stamina is currently regenerating.
  161.  *
  162.  * Stamina RefillHide
  163.  * Instantly refills all of your stamina and also hides the stamina window.
  164.  *
  165.  * Stamina SetMax <value>
  166.  * Sets a new max-stamina value.
  167.  *
  168.  * Stamina IncreaseMax <value>
  169.  * Increases max stamina by the specified value. You can also use negative values.
  170.  *
  171.  * Stamina EnableDashing <true/false>
  172.  * Allows or prohibits dashing on the map.
  173.  * -------------------------------------
  174.  * Map Notetags
  175.  * -------------------------------------
  176.  * <dstam_disable>
  177.  * Prevents stamina consumption on this map. Not that if the "Disable Stamina Consumption GameSwitch"
  178.  * is turned ON then you consume no stamina anyway.
  179.  *
  180.  * <disable_dashing>
  181.  * Prevents dashing on the map (with or without stamina).
  182.  *
  183.  * -------------------------------------
  184.  * Item Notetags (not case sensitive)
  185.  * -------------------------------------
  186.  * <dash_stamina:command (value)>
  187.  * Available commands:
  188.  *  - Add (may have a negative value)
  189.  *  - Refill
  190.  *  - Deplete
  191.  *  - IncreaseMax (may have a negative value)
  192.  * Examples:
  193.  * <dash_stamina:Add 10>
  194.  * <dash_stamina:Add -10>
  195.  * <dash_stamina:Refill>
  196.  * <dash_stamina:Deplete>
  197.  * <dash_stamina:IncreaseMax 1500>
  198.  * Note that those only work from the menu, not from battle
  199.  *
  200.  *--------------------------------------
  201.  * Version History:
  202.  *--------------------------------------
  203.  * v1.03 (01 January 2016)
  204.  * - Used my new coding standards & refactored.
  205.  * - Switched to the Imported variable.
  206.  * - Fixed an accidental duplicate alias.
  207.  * - Fixed a bug in Scene_Map.prototype.updateMain() (which just so happened to cause no side-effects).
  208.  *
  209.  * v1.02 (12 December 2015)
  210.  * - Dashing for the current map can now be entirely disabled with a map-notetag and switched with a plugin command at any time.
  211.  * - Created a simple plugin addon to store the player-stamina in a global game-variable.
  212.  * - Enabled custom text to be drawn in front of the Stamina Window.
  213.  * - New feature: items can replenish, lower, refill and deplete stamina (only in the menu, not in battle).
  214.  *
  215.  * v1.01 (1 December 2015)
  216.  * - Removed strict-mode because... Possible bug in RPG Maker...
  217.  * - Refactored and fixed semicolons and missing var-keywords.
  218.  *
  219.  * v1.00 (26 November 2015)
  220.  * - First release.
  221.  * Alpha (November 2015)
  222.  * - First alpha release.
  223.  *
  224.  */
  225. // Imported
  226. var Imported = Imported || {};
  227. Imported.Silv_DashStamina = 1.03;
  228.  
  229. // #Parameters
  230. var Silv = Silv || {};
  231. Silv.Parameters = $plugins.filter(function(p) { return p.description.contains('<SilverStamina>'); })[0].parameters;
  232. Silv.DashStamina = Silv.DashStamina || {};
  233. // Non-parameters
  234. Silv.DashStamina.Window = null;
  235. Silv.DashStamina.ScreenIsFading = false;
  236. Silv.DashStamina.DashingDisabled = false;
  237. // General
  238. Silv.DashStamina.ShowWindow = Silv.Parameters['Show Stamina Window'].toLowerCase() === 'true';
  239. // Positioning & Size
  240. Silv.DashStamina.Window_X = parseInt(Silv.Parameters['Window X']);
  241. Silv.DashStamina.Window_Y = parseInt(Silv.Parameters['Window Y']);
  242. Silv.DashStamina.WindowWidth = parseInt(Silv.Parameters['Window Width']);
  243. Silv.DashStamina.WindowHeight = parseInt(Silv.Parameters['Window Height']);
  244. Silv.DashStamina.WindowHorizontalAlignment = (Silv.Parameters['Window Horizontal Alignment']).toLowerCase();
  245. Silv.DashStamina.WindowVerticalAlignment = (Silv.Parameters['Window Vertical Alignment']).toLowerCase();
  246. 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])};
  247. // Stamina Pool
  248. Silv.DashStamina.StaminaDecrease = parseInt(Silv.Parameters['Stamina Decrease']);
  249. Silv.DashStamina.StaminaMax = parseInt(Silv.Parameters['Stamina Max']);
  250. Silv.DashStamina.StaminaRecoveryDelay = parseInt(Silv.Parameters['Stamina Recovery Delay']);
  251. Silv.DashStamina.StaminaRecoveryRate = parseInt(Silv.Parameters['Stamina Recovery Rate']);
  252. Silv.DashStamina.StaminaAutoDashThreshold = parseInt(Silv.Parameters['Stamina AutoDash Threshold']);
  253. Silv.DashStamina.RegenFormula = Silv.Parameters['Stamina Regen Formula'];
  254. // Visuals
  255. Silv.DashStamina.StaminaGaugeColor1 = (Silv.Parameters['Stamina Gauge Color 1']).toUpperCase();
  256. Silv.DashStamina.StaminaGaugeColor2 = (Silv.Parameters['Stamina Gauge Color 2']).toUpperCase();
  257. Silv.DashStamina.DrawStaminaValue = Silv.Parameters['Draw Stamina Value'].toLowerCase();
  258. Silv.DashStamina.FontSize = parseInt(Silv.Parameters['Font Size']);
  259. // Window Prefix Text
  260. Silv.DashStamina.WindowText = Silv.Parameters['Window Text'];
  261. Silv.DashStamina.WindowTextOffsetY = parseInt(Silv.Parameters['Window Text Offset Y']);
  262. Silv.DashStamina.WindowTextGaugeSpacingX = parseInt(Silv.Parameters['Window Text Spacing X']);
  263. // Window
  264. Silv.DashStamina.AutoHideStaminaWindow = Silv.Parameters['Auto Hide Stamina Window'].toLowerCase() === 'true';
  265. Silv.DashStamina.HideStaminaWindowDelay = parseInt(Silv.Parameters['Hide Stamina Window Delay']);
  266. Silv.DashStamina.WindowOpacity = parseInt(Silv.Parameters['Stamina Window Opacity']);
  267. Silv.DashStamina.WindowSlideOutDir = Silv.Parameters['Window Slideout Direction'].toLowerCase();
  268. Silv.DashStamina.WindowSlideOutSpeed = parseFloat(Silv.Parameters['Window Slideout Speed']);
  269. // Advanced
  270. Silv.DashStamina.DisableGameSwitch = parseInt(Silv.Parameters['Disable Stamina Consumption GameSwitch']);
  271. Silv.DashStamina.Window_Z = parseInt(Silv.Parameters['Window Z-Index']);
  272. Silv.DashStamina.PluginCmdId = Silv.Parameters['Plugin Command Identifier'];
  273.  
  274. // Alias
  275. Silv.Alias = Silv.Alias || {};
  276. if (!Silv.AddAlias)
  277. {
  278.     Silv.AddAlias = function(alias, original_method)
  279.     {
  280.         if (Silv.Alias[alias]) { throw new Error('Alias already exists: ' + alias); }
  281.         Silv.Alias[alias] = original_method;
  282.     };
  283. }
  284. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  285. (function()
  286. {
  287. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  288. // Utilities
  289. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  290.  
  291. // Usage: alert( hexToRgb("#0033ff").g ); // "51";
  292. function hexToRgb(hex)
  293. {
  294.     var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  295.     return result ? {
  296.         r: parseInt(result[1], 16),
  297.         g: parseInt(result[2], 16),
  298.         b: parseInt(result[3], 16)
  299.     } : null;
  300. }
  301.  
  302. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  303. // Game Player
  304. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  305. Game_Player.prototype.hasStaminaConsumption = function()
  306. {
  307.     if ($gameSwitches.value(Silv.DashStamina.DisableGameSwitch)) { return false; }
  308.     if (!this.mapConsumeStamina) { return false; }
  309.     return true;
  310. };
  311.  
  312. // #Update stamina amount
  313. Game_Player.prototype.updateStamina = function()
  314. {
  315.     this.isConsumingStamina = (this.isDashing() && this.isMoving() && this.hasStaminaConsumption());
  316.     if (this.isConsumingStamina)
  317.     {
  318.         this.dashStamina -= Silv.DashStamina.StaminaDecrease;
  319.         if (this.dashStamina < 0) { this.dashStamina = 0; }
  320.         this.isRecoveringStamina = false;
  321.         if (Silv.DashStamina.ShowWindow && !Silv.DashStamina.ScreenIsFading) { Silv.DashStamina.Window.showMe(); }
  322.     }
  323.     else // not currently consuming stamina
  324.     {      
  325.         if (this.isRecoveringStamina)
  326.         {
  327.             this.staminaRecoveryTimeCnt++;
  328.             if (this.dashStamina < this.dashStaminaMax) // Recover the stamina
  329.             {
  330.                 // Recover stamina
  331.                 this.dashStamina += this.calculateStaminaRegen(Silv.DashStamina.StaminaRecoveryRate);
  332.                 if (this.dashStamina > this.dashStaminaMax) { this.dashStamina = this.dashStaminaMax; }
  333.                
  334.                 if (Silv.DashStamina.ShowWindow && !Silv.DashStamina.ScreenIsFading) { Silv.DashStamina.Window.showMe(); }
  335.             }
  336.             else // Already at max stamina, find out when to hide the window if applicable and do so if possible
  337.             {
  338.                 // If the stamina window is used, attempt to autohide it if applicable
  339.                 if (Silv.DashStamina.ShowWindow && Silv.DashStamina.AutoHideStaminaWindow)
  340.                 {
  341.                     this.hideStaminaWindowDelayCnt += 1;
  342.                     if (this.hideStaminaWindowDelayCnt >= Silv.DashStamina.HideStaminaWindowDelay)
  343.                     {
  344.                         Silv.DashStamina.Window.hideMe();
  345.                         this.hideStaminaWindowDelayCnt = 0;
  346.                     }
  347.                 }
  348.                    
  349.             }
  350.         }
  351.         else // not currently recovering stamina, so find out when to start recovering it and do so if required
  352.         {
  353.             this.staminaRecoveryTimeCnt = 0;
  354.             this.staminaRecoveryDelayCnt += 1;
  355.             if (this.staminaRecoveryDelayCnt >= Silv.DashStamina.StaminaRecoveryDelay)
  356.             {
  357.                 this.staminaRecoveryDelayCnt = 0;
  358.                 this.isRecoveringStamina = true;
  359.             }
  360.         }
  361.     }
  362.  
  363.     // Stamina Percentage
  364.     this.dashStaminaPerc = this.dashStamina / parseFloat(this.dashStaminaMax);
  365.  
  366.     // Threshold
  367.     if (!this.isConsumingStamina)
  368.     {
  369.         this.requiresThresholdAmount = this.dashStaminaPerc * 100 < Silv.DashStamina.StaminaAutoDashThreshold;
  370.     }
  371. };
  372.  
  373. Game_Player.prototype.calculateStaminaRegen = function()
  374. {
  375.     var base = Silv.DashStamina.StaminaRecoveryRate;
  376.     var x = this.staminaRecoveryTimeCnt;
  377.     return eval(Silv.DashStamina.RegenFormula);
  378. };
  379.  
  380. // #Initialize
  381. Silv.AddAlias('dashStamina_Game_Player_initialize', Game_Player.prototype.initialize);
  382. Game_Player.prototype.initialize = function()
  383. {
  384.     Silv.Alias.dashStamina_Game_Player_initialize.apply(this, arguments);
  385.  
  386.     this.dashStamina = this.dashStaminaMax = Silv.DashStamina.StaminaMax;
  387.     this.staminaRecoveryDelayCnt = 0; // counter for when to start recovering stamina
  388.     this.staminaRecoveryTimeCnt = 0; // counter for how long the player has been recovering stamina (in frames)
  389.     this.isRecoveringStamina = false;
  390.     this.dashStaminaPerc = 1.0;
  391.     this.hideStaminaWindowDelayCnt = 0;
  392.     this.isConsumingStamina = false;
  393.     this.requiresThresholdAmount = false;
  394.     this.wasDashing = false;
  395. };
  396.  
  397. Game_Player.prototype.dashingAllowed = function()
  398. {
  399.     if (this.dashStamina === 0 ||
  400.        (!this.wasDashing && this.requiresThresholdAmount)) // Do not allow to dash if the player was not dashing the previous frame AND if the threshold was passed.
  401.     {
  402.         return false;
  403.     }
  404.    
  405.     return true;
  406. };
  407.  
  408. Silv.AddAlias('dashStamina_Game_Player_updateDashing', Game_Player.prototype.updateDashing);
  409. Game_Player.prototype.updateDashing = function()
  410. {
  411.     Silv.Alias.dashStamina_Game_Player_updateDashing.apply(this, arguments);
  412.    
  413.     if (Silv.DashStamina.DashingDisabled)
  414.     {
  415.         this._dashing = false;
  416.         return;
  417.     }
  418.    
  419.     if (!this.dashingAllowed()) { this._dashing = false; }
  420.     this.wasDashing = this._dashing;
  421. };
  422.  
  423. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  424. // Game Screen
  425. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  426. // Do not just show the minimap on top of a faded-out screen.
  427. Silv.AddAlias('dashStamina_Game_Screen_updateFadeOut', Game_Screen.prototype.updateFadeOut);
  428. Game_Screen.prototype.updateFadeOut = function()
  429. {
  430.     Silv.Alias.dashStamina_Game_Screen_updateFadeOut.apply(this, arguments);
  431.    
  432.     if (this._brightness < 255) // (this._fadeOutDuration > 0)
  433.     {
  434.         Silv.DashStamina.Window.visible = false;
  435.         Silv.DashStamina.ScreenIsFading = true;
  436.     }
  437.     else
  438.     {
  439.         Silv.DashStamina.ScreenIsFading = false;
  440.     }
  441. };
  442.  
  443. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  444. // Scene Base
  445. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  446. Silv.AddAlias('dashStamina_Scene_Base_startFadeIn', Scene_Base.prototype.startFadeIn);
  447. Scene_Base.prototype.startFadeIn = function()
  448. {
  449.     Silv.Alias.dashStamina_Scene_Base_startFadeIn.apply(this, arguments);
  450.     if (Silv.DashStamina.Window !== null) { Silv.DashStamina.Window.visible = false; }
  451. };
  452.  
  453. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  454. // Scene Map
  455. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  456. // Hook into the main loop
  457. Silv.AddAlias('dashStamina_Scene_Map_updateMain', Scene_Map.prototype.updateMain);
  458. Scene_Map.prototype.updateMain = function()
  459. {
  460.     Silv.Alias.dashStamina_Scene_Map_updateMain.apply(this, arguments);
  461.     $gamePlayer.updateStamina();
  462.     if (Silv.DashStamina.ShowWindow) { Silv.DashStamina.Window.update(); }
  463. };
  464.  
  465. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  466. // Game Map
  467. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  468. // Disable Dashing?
  469. Silv.AddAlias('dashStamina_Game_Map_setup', Game_Map.prototype.setup);
  470. Game_Map.prototype.setup = function(mapId)
  471. {
  472.     Silv.Alias.dashStamina_Game_Map_setup.apply(this, arguments);
  473.     Silv.DashStamina.DashingDisabled = ('disable_dashing' in $dataMap.meta);
  474. };
  475.  
  476. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  477. // Stamina Regen/Deplete #Items
  478. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  479. Silv.AddAlias('dashStamina_Scene_ItemBase_useItem', Scene_ItemBase.prototype.useItem);
  480. Scene_ItemBase.prototype.useItem = function()
  481. {
  482.     var item = this.item();
  483.     if ('dash_stamina' in item.meta)
  484.     {
  485.         var args = item.meta.dash_stamina.split(' ');
  486.         switch(args[0].toLowerCase())
  487.         {
  488.             case 'add':
  489.                 if (args.length < 2) { throw 'Item-add-command is missing the value-argument.'; }
  490.                 $gamePlayer.dashStamina += parseInt(args[1]);
  491.                 if ($gamePlayer.dashStamina > $gamePlayer.dashStaminaMax) { $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax; }
  492.                 else if ($gamePlayer.dashStamina < 0) { $gamePlayer.dashStamina = 0; }
  493.                 break;
  494.             case 'refill':
  495.                 $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax;
  496.                 break;
  497.             case 'deplete':
  498.                 $gamePlayer.dashStamina = 0;
  499.                 break;
  500.             case 'increasemax':
  501.                 if (args.length < 2) { throw 'Item-increasemax-command is missing the value-argument.'; }
  502.                 $gamePlayer.dashStaminaMax += parseInt(args[1]);
  503.                 if ($gamePlayer.dashStaminaMax < 1 ) { $gamePlayer.dashStaminaMax = 1; }
  504.                 break;
  505.             default:
  506.                 throw 'Unknown dash_stamina itemnotetag: ' + item.meta;
  507.         }
  508.        
  509.     }
  510.    
  511.     Silv.Alias.dashStamina_Scene_ItemBase_useItem.apply(this, arguments);
  512. };
  513.  
  514. Silv.AddAlias('dashStamina_Game_Action_testApply', Game_Action.prototype.testApply);
  515. Game_Action.prototype.testApply = function(target)
  516. {
  517.     if ('dash_stamina' in this.item().meta)
  518.     {
  519.         return true;
  520.     }
  521.     else
  522.     {
  523.         return Silv.Alias.dashStamina_Game_Action_testApply.apply(this, arguments);
  524.     }
  525. };
  526. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  527. // DashStamina #Window
  528. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  529. function Window_DashStamina() { this.initialize.apply(this, arguments); }
  530. Window_DashStamina.prototype = Object.create(Window_Base.prototype);
  531. Window_DashStamina.prototype.constructor = Window_DashStamina;
  532. // Font Size
  533. Window_DashStamina.prototype.standardFontSize = function() { return Silv.DashStamina.FontSize; };
  534.  
  535. // #Initialize
  536. Window_DashStamina.prototype.initialize = function(x, y, width, height)
  537. {
  538.     Window_Base.prototype.initialize.call(this, x, y, width, height);
  539.     this._helpWindow = null;
  540.     this._handlers = {};
  541.     this._touching = false;
  542.     this.deactivate();
  543.    
  544.     this.opacity = Silv.DashStamina.WindowOpacity;
  545.     this.slideDirection = {x: 0, y: 0 };
  546.     this.originalWinLoc = {x: 0, y: 0 };
  547.     this.sliding = 'none';
  548.     this.isFullySlidedOut = false;
  549.     this.isFullySlidedIn = true;
  550.     this.originalWinLoc.x = x; // for some reason "this." is not allowed here
  551.     this.originalWinLoc.y = y; // for some reason "this." is not allowed here
  552.    
  553.     if (Silv.DashStamina.WindowText != ':none')
  554.     {
  555.         this.windowText = Silv.DashStamina.WindowText;
  556.         this.windowTextWidth = this.contents.measureTextWidth(this.windowText);
  557.         this.windowTextGaugeSpacingX = Silv.DashStamina.WindowTextGaugeSpacingX;
  558.     }
  559.     else
  560.     {
  561.         this.windowText = null;
  562.         this.windowTextWidth = 0;
  563.         this.windowTextGaugeSpacingX = Silv.DashStamina.WindowTextGaugeSpacingX;
  564.     }
  565.    
  566.     this.update();
  567. };
  568.  
  569. // Update
  570. Window_DashStamina.prototype.update = function()
  571. {
  572.     if (Silv.DashStamina.ScreenIsFading)
  573.     {
  574.         this.visible = false;
  575.     }
  576.     else
  577.     {
  578.         Window_Base.prototype.update.call(this);
  579.         this.drawStaminaWindow(0, 0, Silv.DashStamina.StaminaGaugeRectangle.width);
  580.         this.updateSliding();
  581.     }
  582. };
  583.  
  584. //----------------------------------------------------------------------------------------------------
  585. // #Drawing
  586. //----------------------------------------------------------------------------------------------------
  587. Window_DashStamina.prototype.drawStaminaGauge = function(x, y, width, height, rate)
  588. {
  589.     var fillW = Math.floor(width * rate);
  590.     var gaugeY = y + this.lineHeight() - 8;
  591.     this.contents.fillRect(x, gaugeY, width, height, this.gaugeBackColor());
  592.     this.contents.fillRect(x, gaugeY, fillW, height, this.CalculateBarColour());
  593. };
  594.  
  595. Window_DashStamina.prototype.drawStaminaWindow = function(x, y, width)
  596. {
  597.     this.contents.clear();
  598.    
  599.     // Draw text before the gauge
  600.     if (this.windowText !== null)
  601.     {
  602.         this.contents.drawText(this.windowText, 0, Silv.DashStamina.WindowTextOffsetY, this.windowTextWidth, 0);
  603.     }
  604.  
  605.     // Draw gauge
  606.     this.drawStaminaGauge(Silv.DashStamina.StaminaGaugeRectangle.x + this.windowTextWidth + this.windowTextGaugeSpacingX, Silv.DashStamina.StaminaGaugeRectangle.y, Silv.DashStamina.StaminaGaugeRectangle.width, Silv.DashStamina.StaminaGaugeRectangle.height, $gamePlayer.dashStaminaPerc);
  607.     // Draw text on top of the gauge
  608.     var text;
  609.     switch(Silv.DashStamina.DrawStaminaValue) // allowed values: absolute/percentage/both/none
  610.     {
  611.         case 'absolute':
  612.             text = parseInt($gamePlayer.dashStamina) + '/' + parseInt($gamePlayer.dashStaminaMax);
  613.             break;
  614.         case 'percentage':
  615.             text = Math.round($gamePlayer.dashStaminaPerc * 100) + '%';
  616.             break;
  617.         case 'both':
  618.             text = parseInt($gamePlayer.dashStamina) + '/' + parseInt($gamePlayer.dashStaminaMax) + ' (' + Math.round($gamePlayer.dashStaminaPerc * 100) + '%)';
  619.             break;
  620.         case 'none':
  621.             return;
  622.         default:
  623.             throw 'ERROR: drawStaminaWindow missing case-statement or incorrect Silv.DashStamina.DrawStaminaValue value. Value: ' + Silv.DashStamina.DrawStaminaValue;
  624.     }
  625.    
  626.     this.resetTextColor();
  627.     this.drawText(text, x + this.windowTextWidth + this.windowTextGaugeSpacingX, y + 1, width, 'center');
  628. };
  629.  
  630. // Calculate what colour the gauge should be between the two colors depending on the percentage value of the current-stamina value.
  631. Window_DashStamina.prototype.CalculateBarColour = function()
  632. {
  633.     var c1 = hexToRgb(Silv.DashStamina.StaminaGaugeColor1);
  634.     var c2 = hexToRgb(Silv.DashStamina.StaminaGaugeColor2);
  635.        
  636.     var ratio = $gamePlayer.dashStaminaPerc;
  637.     var hex = function(x) {
  638.         x = x.toString(16);
  639.         return (x.length === 1) ? '0' + x : x;
  640.     };
  641.  
  642.     var r = Math.ceil(c1.r * ratio + c2.r * (1-ratio));
  643.     var g = Math.ceil(c1.g * ratio + c2.g * (1-ratio));
  644.     var b = Math.ceil(c1.b * ratio + c2.b * (1-ratio));
  645.  
  646.     var middle = '#' + hex(r) + hex(g) + hex(b);
  647.     return middle;
  648. };
  649.  
  650. //----------------------------------------------------------------------------------------------------
  651. // #Show & #Hide
  652. //----------------------------------------------------------------------------------------------------
  653. Window_DashStamina.prototype.showMe = function()
  654. {
  655.     //if (this.visible) { return; };
  656.     if (this.isFullySlidedIn)
  657.     {
  658.         this.visible = true;
  659.         return;
  660.     }
  661.    
  662.     if (Silv.DashStamina.WindowSlideOutDir === 'noslide' || this.visible === false) { this.visible = true; }
  663.     else
  664.     {
  665.         this.sliding = 'in';
  666.         switch (Silv.DashStamina.WindowSlideOutDir)
  667.         {
  668.             case 'top':
  669.                 this.slideDirection.x = 0;
  670.                 this.slideDirection.y = 1;
  671.                 break;
  672.             case 'left':
  673.                 this.slideDirection.x = 1;
  674.                 this.slideDirection.y = 0;
  675.                 break;
  676.             case 'right':
  677.                 this.slideDirection.x = -1;
  678.                 this.slideDirection.y = 0;
  679.                 break;
  680.             case 'bottom':
  681.                 this.slideDirection.x = 0;
  682.                 this.slideDirection.y = -1;
  683.                 break;
  684.             default:
  685.                 throw 'Window_DashStamina.prototype.HideMe: Unknown switch value: ' + Silv.DashStamina.WindowSlideOutDir;
  686.         }
  687.     }
  688. };
  689.  
  690. Window_DashStamina.prototype.hideMe = function()
  691. {
  692.     if (!this.visible || this.isFullySlidedOut) { return; }
  693.    
  694.     if (Silv.DashStamina.WindowSlideOutDir === 'noslide') { this.visible = false; }
  695.     else
  696.     {
  697.         this.sliding = 'out';
  698.         switch (Silv.DashStamina.WindowSlideOutDir)
  699.         {
  700.             case 'top':
  701.                 this.slideDirection.x = 0;
  702.                 this.slideDirection.y = -1;
  703.                 break;
  704.             case 'left':
  705.                 this.slideDirection.x = -1;
  706.                 this.slideDirection.y = 0;
  707.                 break;
  708.             case 'right':
  709.                 this.slideDirection.x = 1;
  710.                 this.slideDirection.y = 0;
  711.                 break;
  712.             case 'bottom':
  713.                 this.slideDirection.x = 0;
  714.                 this.slideDirection.y = 1;
  715.                 break;
  716.             default:
  717.                 throw 'Window_DashStamina.prototype.HideMe: Unknown switch value: ' + Silv.DashStamina.WindowSlideOutDir;
  718.         }
  719.     }
  720. };
  721.  
  722. //----------------------------------------------------------------------------------------------------
  723. // #Sliding of the Window
  724. //----------------------------------------------------------------------------------------------------
  725. Window_DashStamina.prototype.handleSlidingEnd = function()
  726. {
  727.     if (this.sliding === 'in')
  728.     {
  729.         // Stop sliding in
  730.         if (this.slideDirection.x  === 1 && this.x > this.originalWinLoc.x ||
  731.             this.slideDirection.x  === -1 && this.x < this.originalWinLoc.x ||
  732.             this.slideDirection.y  === 1 && this.y > this.originalWinLoc.y ||
  733.             this.slideDirection.y  === -1 && this.y < this.originalWinLoc.y)
  734.         {
  735.             this.sliding = 'none';
  736.             this.isFullySlidedIn = true;
  737.         }
  738.     }
  739.     else
  740.     {
  741.         // Stop sliding out
  742.         if (this.x < -this.width || this.x > Graphics._width + this.width ||
  743.             this.y < -this.height || this.x > Graphics._height + this.height)
  744.         {
  745.             this.sliding = 'none';
  746.             this.isFullySlidedOut = true;
  747.         }
  748.     }
  749. };
  750.  
  751. Window_DashStamina.prototype.updateSliding = function()
  752. {
  753.     if (this.sliding === 'none') { return; }
  754.     this.x += this.slideDirection.x * Silv.DashStamina.WindowSlideOutSpeed;
  755.     this.y += this.slideDirection.y * Silv.DashStamina.WindowSlideOutSpeed;
  756.    
  757.     this.isFullySlidedOut = false;
  758.     this.isFullySlidedIn = false;
  759.    
  760.     this.handleSlidingEnd();
  761. };
  762.  
  763. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  764. // #Create Stamina Window
  765. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  766. Scene_Map.prototype.createDashWindow = function()
  767. {
  768.     // Dispose the old window, if any
  769.     if (Silv.DashStamina.Window !== null) { this.removeWindow(Silv.DashStamina.Window); }
  770.    
  771.     // Does the map consume stamina?
  772.     $gamePlayer.mapConsumeStamina = !('dstam_disable' in $dataMap.meta);
  773.     if(Silv.DashStamina.ShowWindow)
  774.     {
  775.         var x = 0;
  776.         if (Silv.DashStamina.WindowHorizontalAlignment === 'right') { x = Graphics.width - Silv.DashStamina.WindowWidth; }
  777.         var y = 0;
  778.         if (Silv.DashStamina.WindowVerticalAlignment === 'bottom') { y = Graphics.height - Silv.DashStamina.WindowHeight; }
  779.        
  780.         Silv.DashStamina.Window = new Window_DashStamina(x + Silv.DashStamina.Window_X, y + Silv.DashStamina.Window_Y, Silv.DashStamina.WindowWidth, Silv.DashStamina.WindowHeight);
  781.        
  782.         this.addChild(Silv.DashStamina.Window, Silv.DashStamina.Window_Z);
  783.         if (Silv.DashStamina.AutoHideStaminaWindow) { Silv.DashStamina.Window.visible = false; }
  784.     }
  785. };
  786.  
  787. // Omg why does RPG Maker not have this method by default...
  788. Scene_Base.prototype.removeWindow = function(window)
  789. {
  790.     var index = this.children.indexOf(window);
  791.     if (index > -1) { this.children.splice(index, 1); }
  792. };
  793.  
  794. Silv.AddAlias('dashStamina_Scene_Map_createDisplayObjects', Scene_Map.prototype.createDisplayObjects);
  795. Scene_Map.prototype.createDisplayObjects = function()
  796. {
  797.     Silv.Alias.dashStamina_Scene_Map_createDisplayObjects.apply(this, arguments);
  798.     this.createDashWindow();
  799. };
  800.  
  801. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  802. // Saving & Loading
  803. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  804. Silv.AddAlias('dashStamina_DataManager_makeSaveContents', DataManager.makeSaveContents);
  805. DataManager.makeSaveContents = function()
  806. {
  807.     contents = Silv.Alias.dashStamina_DataManager_makeSaveContents.apply(this, arguments);
  808.     contents.dashStamina = $gamePlayer.dashStamina;
  809.     contents.dashStaminaMax = $gamePlayer.dashStaminaMax;
  810.     return contents;
  811. };
  812.  
  813. Silv.AddAlias('dashStamina_DataManager_extractSaveContents', DataManager.extractSaveContents);
  814. DataManager.extractSaveContents = function(contents)
  815. {
  816.     Silv.Alias.dashStamina_DataManager_extractSaveContents.apply(this, arguments);
  817.     $gamePlayer.dashStamina = contents.dashStamina;
  818.     $gamePlayer.dashStaminaMax = contents.dashStaminaMax;
  819. };
  820.  
  821. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  822. // Plugin Command
  823. // Note: The items are separated by spaces. The command is the first word and any following words are args. args is an array.
  824. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  825. Silv.AddAlias('dashStamina_Game_Interpreter_pluginCommand', Game_Interpreter.prototype.pluginCommand);
  826. Game_Interpreter.prototype.pluginCommand = function(command, args)
  827. {
  828.     Silv.Alias.dashStamina_Game_Interpreter_pluginCommand.apply(this, arguments);
  829.     if (command.toLowerCase() === Silv.DashStamina.PluginCmdId) { Silv.DashStamina.PluginCommand(command, args); }
  830. };
  831.  
  832. Silv.DashStamina.PluginCommand = function(cmd, args)
  833. {
  834.     switch(args[0].toLowerCase())
  835.     {
  836.         case 'refill':
  837.             $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax;
  838.             break;
  839.         case 'deplete':
  840.             $gamePlayer.dashStamina = 0;
  841.             break;
  842.         case 'set':
  843.             var perc = parseInt(args[1]);
  844.             perc = Math.max(0, Math.min(100, perc)); // clamp value between 0-100
  845.             $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax * (perc / 100.0);
  846.         break;
  847.         case 'showwindow':
  848.             if (Silv.DashStamina.Window !== null)
  849.             {
  850.                 $gamePlayer.hideStaminaWindowDelayCnt = 0;
  851.                 Silv.DashStamina.Window.visible = true;
  852.             }
  853.             break;
  854.         case 'refillhide':
  855.             $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax;
  856.             // NO break-statement here! We want to hide the window as well!
  857.         case 'hidewindow':
  858.             if (Silv.DashStamina.Window !== null)
  859.             {
  860.                 $gamePlayer.hideStaminaWindowDelayCnt = Silv.DashStamina.HideStaminaWindowDelay;
  861.                 Silv.DashStamina.Window.visible = false;
  862.             }
  863.             break;
  864.         case 'setmax':
  865.             $gamePlayer.dashStaminaMax = Math.max(1, parseInt(args[1]));
  866.             if ($gamePlayer.dashStamina > $gamePlayer.dashStaminaMax) { $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax; }
  867.             break;
  868.         case 'increasemax':
  869.             $gamePlayer.dashStaminaMax += parseInt(args[1]);
  870.             if ($gamePlayer.dashStaminaMax < 1) { $gamePlayer.dashStaminaMax = 1; }
  871.             if ($gamePlayer.dashStamina > $gamePlayer.dashStaminaMax) { $gamePlayer.dashStamina = $gamePlayer.dashStaminaMax; }
  872.             break;
  873.         case 'enabledashing':
  874.             Silv.DashStamina.DashingDisabled = (args[1].toLowerCase() === 'true');
  875.             break;
  876.         default:
  877.             throw 'Stamina PluginCommand invalid command: ' + args[0];
  878.     }
  879. };
  880.  
  881. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  882. })();
  883. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  884. // This is the end of this awesome script!
  885. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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