SHARE
TWEET

Untitled

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