SHARE
TWEET

Squirting Elephant's Dash Stamina V2.00

a guest Oct 18th, 2019 19 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. "use strict";
  2. // Note: Use CTRL+K CTRL+L to collapse region in Visual Studio Code.
  3. //#region Header
  4. /*:
  5. ╔════════╗
  6. ║ #Index ║
  7. ╚════════╝
  8. #Index
  9. @help
  10. #Version History
  11. Plugin #Initialization
  12. #Parameters & Variables
  13. #Utilities
  14. Game #Player
  15.     #Stamina adjusting
  16.     #Update Stamina Stuff
  17. Game #Screen
  18. Scene #Base
  19. Scene #Map
  20. #Game Map
  21. #Stamina Regen/Deplete Items
  22. #Stamina Window #Definition
  23.     #Drawing
  24.     #Show, #Hide & #Slide
  25. #Create Stamina Window
  26. Play #SFX
  27. #Saving & #Loading
  28. Plugin #Command
  29.  
  30. ╔════════════════╗
  31. ║ Plugin Manager ║
  32. ╚════════════════╝
  33.  * @plugindesc v2.00 Basic dashing stamina script.
  34.  * @author Squirting Elephant
  35.  *
  36.  * @param General
  37.  *
  38.  * @param ShowStaminaWindow
  39.  * @text Show Stamina Window
  40.  * @desc Show the stamina window?
  41.  * @parent General
  42.  * @type boolean
  43.  * @on Show
  44.  * @off Hide
  45.  * @default true
  46.  *
  47.  * @param SFXDefaultVolume
  48.  * @text Default SFX Volume
  49.  * @desc The default volume level for all ItemLog SFX. Use the value -1 to use the "live AudioManager.seVolume" instead.
  50.  * @parent General
  51.  * @type number
  52.  * @min -1
  53.  * @default -1
  54.  *
  55.  * @param SFXStaminaDecreaseTiled
  56.  * @text Stamina Decrease Tiled SFX
  57.  * @desc The SFX to play whenever stamina is decreased (only works when "Stamina Decrease Mode" is set to "Tile". Use "None" w/o quotes to disable this.
  58.  * @parent General
  59.  * @default Switch1
  60.  *
  61.  * @param PauseStaminaDuringDialog
  62.  * @text Freeze Stamina During GameMessage
  63.  * @desc Stops stamina regeneration and such when a GameMessage (=dialog) is active.
  64.  * @parent General
  65.  * @type boolean
  66.  * @on Freeze
  67.  * @off Don't freeze
  68.  * @default true
  69.  *
  70.  *
  71.  * @param Positioning & Size
  72.  *
  73.  * @param Window_X
  74.  * @text Window X
  75.  * @desc X-location of stamina window. If window-alignment is set to Right, this will act as an offset value instead
  76.  * @parent Positioning & Size
  77.  * @type number
  78.  * @default 10
  79.  *
  80.  * @param Window_Y
  81.  * @text Window Y
  82.  * @desc Y-location of stamina window. If window-alignment is set to Top, this will act as an offset value instead
  83.  * @parent Positioning & Size
  84.  * @type number
  85.  * @default 10
  86.  *
  87.  * @param WindowWidth
  88.  * @text Window Width
  89.  * @desc width of the stamina window
  90.  * @parent Positioning & Size
  91.  * @type number
  92.  * @min 0
  93.  * @default 170
  94.  *
  95.  * @param WindowHeight
  96.  * @text Window Height
  97.  * @desc height of the stamina window
  98.  * @parent Positioning & Size
  99.  * @type number
  100.  * @min 0
  101.  * @default 72
  102.  *
  103.  * @param WindowAlignment_Horizontal
  104.  * @text Window Horizontal Alignment
  105.  * @parent Positioning & Size
  106.  * @type select
  107.  * @option Left
  108.  * @option Right
  109.  * @default Left
  110.  *
  111.  * @param WindowAlignment_Vertical
  112.  * @text Window Vertical Alignment
  113.  * @parent Positioning & Size
  114.  * @type select
  115.  * @option Top
  116.  * @option Bottom
  117.  * @default Top
  118.  *
  119.  * @param StaminaGaugeRect
  120.  * @text Stamina Gauge Rectangle
  121.  * @desc The gauge rectangle.
  122.  * @parent Positioning & Size
  123.  * @type struct<SEGaugeRect>
  124.  * @default {"x":"0","y":"-20","width":"132","height":"24"}
  125.  *
  126.  * @param Stamina Pool
  127.  *
  128.  * @param StaminaDecreaseMode
  129.  * @text Stamina Decrease Mode
  130.  * @desc Use "Default" to decrease while moving. Use "Tile" to decrease stamina whenever the player enters a new tile.
  131.  * @parent Stamina Pool
  132.  * @type select
  133.  * @option Default
  134.  * @option Tile
  135.  * @default Default
  136.  *
  137.  * @param StaminaDecreaseAmountDefault
  138.  * @text Stamina Decrease Amount Default
  139.  * @desc Amount of stamina subtracted per update (use a positive number) while in default mode.
  140.  * @parent Stamina Pool
  141.  * @type number
  142.  * @min 0
  143.  * @default 1
  144.  *
  145.  * @param StaminaDecreaseAmountTiled
  146.  * @text Stamina Decrease Amount Tiled
  147.  * @desc Amount of stamina subtracted per update (use a positive number) while in tiled mode.
  148.  * @parent Stamina Pool
  149.  * @type number
  150.  * @min 0
  151.  * @default 10
  152.  *
  153.  * @param StaminaMax
  154.  * @text Max Stamina
  155.  * @desc The maximum amount of stamina.
  156.  * @parent Stamina Pool
  157.  * @type number
  158.  * @min 1
  159.  * @default 300
  160.  *
  161.  * @param StaminaRecoveryDelay
  162.  * @text Stamina Recovery Delay
  163.  * @desc delay in update-calls before recovering stamina when not dashing.
  164.  * @parent Stamina Pool
  165.  * @type number
  166.  * @min 0
  167.  * @default 180
  168.  *
  169.  * @param StaminaRecoveryRate
  170.  * @text Stamina Recovery Rate
  171.  * @desc How fast stamina is recovered (only when recovering).
  172.  * @parent Stamina Pool
  173.  * @type number
  174.  * @min 0
  175.  * @decimals 2
  176.  * @default 0.30
  177.  *
  178.  * @param StaminaAutoDashThreshold
  179.  * @text Stamina AutoDash Threshold
  180.  * @desc Do not automatically dash again before stamina is above this threshold (in %, 0-100) when recovering stamina.
  181.  * @parent Stamina Pool
  182.  * @type number
  183.  * @min 0
  184.  * @max 100
  185.  * @default 15
  186.  *
  187.  * @param UsesCustomStaminaRegenFormula
  188.  * @text Use Custom Stamina Regen Formula?
  189.  * @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).
  190.  * @parent Stamina Pool
  191.  * @type boolean
  192.  * @on Yes
  193.  * @off No
  194.  * @default false
  195.  *
  196.  * @param StaminaRegenFormula
  197.  * @text Stamina Regen Formula
  198.  * @desc The formula for how fast to regenerate stamina over longer period of time. "Base" is the recovery rate. Case sensitive!
  199.  * @parent Stamina Pool
  200.  * @default base + Math.sqrt(x/50);
  201.  *
  202.  * @param Visuals
  203.  *
  204.  * @param StaminaGaugeColor_1
  205.  * @text Stamina Gauge Color 1
  206.  * @desc Bar gradient color1 (start of bar) in hex.
  207.  * @parent Visuals
  208.  * @default #009900
  209.  *
  210.  * @param StaminaGaugeColor_2
  211.  * @text Stamina Gauge Color 2
  212.  * @desc Bar gradient color2 (end of bar) in hex.
  213.  * @parent Visuals
  214.  * @default #CC0000
  215.  *
  216.  * @param StaminaValueRenderType
  217.  * @text Draw Stamina Value
  218.  * @desc Draw text in stamina bar? Accepted values: absolute/percentage/both/none
  219.  * @parent Visuals
  220.  * @type select
  221.  * @option none
  222.  * @option absolute
  223.  * @option percentage
  224.  * @option both
  225.  * @default percentage
  226.  *
  227.  * @param FontSize
  228.  * @text Font Size
  229.  * @desc Font size for stamina value.
  230.  * @parent Visuals
  231.  * @type number
  232.  * @min 1
  233.  * @default 20
  234.  *
  235.  * @param Window Prefix Text
  236.  *
  237.  * @param WindowText
  238.  * @text Window Text
  239.  * @desc Use :none to disable this.
  240.  * @parent Window Prefix Text
  241.  * @default :none
  242.  *
  243.  * @param WindowTextOffset_Y
  244.  * @text Window Text Offset Y
  245.  * @desc y-coordinate for the text.
  246.  * @parent Window Prefix Text
  247.  * @type number
  248.  * @default 19
  249.  *
  250.  * @param WindowTextSpacing_X
  251.  * @text Window Text Spacing X
  252.  * @desc The amount of room in coordinates between text and gauge.
  253.  * @parent Window Prefix Text
  254.  * @type number
  255.  * @min 0
  256.  * @default 4
  257.  *
  258.  * @param Hiding
  259.  *
  260.  * @param AutoHideStaminaWindow
  261.  * @text Auto Hide Stamina Window
  262.  * @desc Automatically hide the stamina window if it's at max stamina for a specific period of time?
  263.  * @parent Hiding
  264.  * @type boolean
  265.  * @on Yes
  266.  * @off No
  267.  * @default true
  268.  *
  269.  * @param HideStaminaWindowDelay
  270.  * @text Hide Stamina Window Delay
  271.  * @desc After how many updates the stamina window should hide itself (if it remains at max stamina).
  272.  * @parent Hiding
  273.  * @type number
  274.  * @min 0
  275.  * @default 180
  276.  *
  277.  * @param IsHiddenDuringGameMessage
  278.  * @text Hide During Game Message
  279.  * @desc Hide the stamina window when a GameMessage (=dialog, choice, etc.) is active?
  280.  * @parent Hiding
  281.  * @type boolean
  282.  * @on Yes
  283.  * @off No
  284.  * @default true
  285.  *
  286.  * @param Window
  287.  *
  288.  * @param StaminaWindowOpacity
  289.  * @text Stamina Window Opacity
  290.  * @desc Stamina window opacity between 0-255. Set to 0 to hide the window (will still show the bar).
  291.  * @parent Window
  292.  * @type number
  293.  * @min 0
  294.  * @max 255
  295.  * @default 255
  296.  *
  297.  * @param WindowSlideoutDirection
  298.  * @text Window Slide-out Direction
  299.  * @desc What direction to slide the stamina window out to.
  300.  * @parent Window
  301.  * @type select
  302.  * @option Disabled
  303.  * @option Up
  304.  * @option Right
  305.  * @option Down
  306.  * @option Left
  307.  * @default Left
  308.  *
  309.  * @param WindowSlideSpeed
  310.  * @text Window Slide Speed
  311.  * @desc How fast the window slides in & out.
  312.  * @parent Window
  313.  * @type number
  314.  * @min 0
  315.  * @decimals 1
  316.  * @default 2.0
  317.  *
  318.  * @param Advanced
  319.  *
  320.  * @param CommonEvent_StaminaValue_ActivationDelta
  321.  * @text Common Event Stamina Value Activation Delta
  322.  * @desc How big the difference in stamina value must be between now and the last time a common event was ran. A value of 0 will run the Common Event every frame (if it matches the stamina value).
  323.  * @parent Advanced
  324.  * @type number
  325.  * @min 0
  326.  * @default 5
  327.  *
  328.  * @param GameVariableNumberStamina
  329.  * @text Game Variable Number
  330.  * @desc Use a value of 0 to disable this. The GameVariable # to store the current stamina value into.
  331.  * @parent Advanced
  332.  * @type number
  333.  * @min 0
  334.  * @default 0
  335.  *
  336.  * @param DisableStaminaConsumptionGameSwitch
  337.  * @text Disable Stamina Consumption GameSwitch
  338.  * @desc The gameswitch to use to disable stamina consumption (or -1 to use none). A switch status of "ON" means: disabled.
  339.  * @parent Advanced
  340.  * @type number
  341.  * @min -1
  342.  * @default -1
  343.  *
  344.  * @param Window_Z_Index
  345.  * @text Window Z-Index
  346.  * @desc Window Z-Index.
  347.  * @parent Advanced
  348.  * @type number
  349.  * @min 1
  350.  * @default 1
  351.  *
  352.  * @param PluginCommandIdentifier
  353.  * @text Plugin Command Identifier
  354.  * @desc Do not change if you do not know what this is!
  355.  * @parent Advanced
  356.  * @default stamina
  357.  *
  358.  * @param CommonEventsAtStaminaValues
  359.  * @text Common Events At Stamina Values
  360.  * @desc Example to run common event 15 at 0 stamina and common event 17 at 100% stamina: 0 15 100% 17.
  361.  * @parent Advanced
  362.  *
  363.  * @param DebugEnabled
  364.  * @desc Enables/Disables debugging. Note that this may cost extra performance when enabled.
  365.  * @parent Advanced
  366.  * @type boolean
  367.  * @on Enabled
  368.  * @off Disabled
  369.  * @default false
  370.  * @text Debugging Enabled
  371.  *
  372.    ╔══════╗
  373.    ║ Help ║
  374.    ╚══════╝
  375.  * @help
  376.  * -------------------------------------
  377.  * Plugin Commands (not case sensitive):
  378.  * -------------------------------------
  379.  *
  380.  * Stamina Refill
  381.  * Instantly refills all of your stamina.
  382.  *
  383.  * Stamina Set <value>
  384.  * Instantly sets your stamina to the specified percentage (0-100).
  385.  * Example to set your stamina bar to 64: Stamina Set 64
  386.  *
  387.  * Stamina SetVar <variableIndex>
  388.  * Instantly sets your stamina to the specified percentage (0-100).
  389.  * Example to set the stamina using game-variable #10: Stamina SetVar 10
  390.  *
  391.  * Stamina SetEval <eval>
  392.  * Instantly sets your stamina to the specified percentage (0-100).
  393.  * Example: Example Stamina SetEval ($gameVariables.value(10) + 1) / 2
  394.  *
  395.  * Stamina Deplete
  396.  * Instantly sets your stamina to 0.
  397.  *
  398.  * Stamina ShowWindow
  399.  * Shows the stamina window. Does not work if you disabled the stamina window.
  400.  *
  401.  * Stamina HideWindow
  402.  * Hides the stamina window. Does not work if you disabled the stamina window.
  403.  * Also does not work if the stamina is currently regenerating.
  404.  *
  405.  * Stamina RefillHide
  406.  * Instantly refills all of your stamina and also hides the stamina window.
  407.  *
  408.  * Stamina SetMax <value>
  409.  * Sets a new max-stamina value.
  410.  *
  411.  * Stamina SetMaxVar <variableIndex>
  412.  * Sets a new max-stamina value.
  413.  * Example to set the max-stamina using game-variable #10: Stamina SetMaxVar 10
  414.  *
  415.  * Stamina SetMaxEval <eval>
  416.  * Sets a new max-stamina value. But this time it evaluates the code you enter as <eva>.
  417.  * Example: Stamina SetMaxEval ($gameVariables.value(10) + 1) / 2
  418.  * 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.
  419.  *
  420.  * Stamina IncreaseMax <value>
  421.  * Increases max stamina by the specified value. You can also use negative values.
  422.  *
  423.  * Stamina EnableDashing <true/false/toggle>
  424.  * Allows or prohibits dashing on the map.
  425.  * Examples:
  426.  * Stamina EnableDashing true
  427.  * Stamina EnableDashing false
  428.  * Stamina EnableDashing toggle
  429.  *
  430.  * Stamina ForceHide <true/false>
  431.  * Example:
  432.  * Stamina ForceHide true
  433.  *
  434.  * Stamina SetDecreaseMode <Default/Tile>
  435.  * Examples:
  436.  * Stamina SetDecreaseMode Default
  437.  * Stamina SetDecreaseMode Tile
  438.  *
  439.  * Stamina ToggleDecreaseMode
  440.  * Toggles the DecreaseMode between Default and Tile.
  441.  *
  442.  * -------------------------------------
  443.  * Map Notetags
  444.  * -------------------------------------
  445.  * <dstam_disable>
  446.  * Prevents stamina consumption on this map. Not that if the "Disable Stamina Consumption GameSwitch"
  447.  * is turned ON then you consume no stamina anyway.
  448.  *
  449.  * <disable_dashing>
  450.  * Prevents dashing on the map (with or without stamina).
  451.  *
  452.  * -------------------------------------
  453.  * Item Notetags (not case sensitive)
  454.  * -------------------------------------
  455.  * <dash_stamina:command (value)>
  456.  * Available commands:
  457.  *  - Add (may have a negative value)
  458.  *  - Refill
  459.  *  - Deplete
  460.  *  - IncreaseMax (may have a negative value)
  461.  * Examples:
  462.  * <dash_stamina:Add 10>
  463.  * <dash_stamina:Add -10>
  464.  * <dash_stamina:Refill>
  465.  * <dash_stamina:Deplete>
  466.  * <dash_stamina:IncreaseMax 1500>
  467.  * Note that those only work from the menu, not from battle
  468.  *
  469.  *--------------------------------------
  470.  * Aliases created for:
  471.  *--------------------------------------
  472.  * * DataManager.extractSaveContents()
  473.  * * DataManager.makeSaveContents()
  474.  * * Game_Action.prototype.testApply()
  475.  * * Game_Interpreter.prototype.pluginCommand()
  476.  * * Game_Map.prototype.setup()
  477.  * * Game_Message.prototype.add()
  478.  * * Game_Player.prototype.initialize()
  479.  * * Game_Player.prototype.updateDashing()
  480.  * * Game_Player.prototype.updateMove()
  481.  * * Game_Screen.prototype.updateFadeOut()
  482.  * * Scene_Base.prototype.startFadeIn()
  483.  * * Scene_ItemBase.prototype.useItem()
  484.  * * Scene_Map.prototype.createDisplayObjects()
  485.  * * Scene_Map.prototype.updateMain()
  486.  *
  487.  *--------------------------------------
  488.  * #Version History:
  489.  *--------------------------------------
  490.  * v2.00 (17 October 2019) [Parameters Changed]
  491.  * - The stamina window can now automatically hide itself during dialogs (with a new parameter).
  492.  * - Added another new parameter: "Freeze Stamina During GameMessage".
  493.  * - Added an index for developers.
  494.  * - A lot of refactoring and 'upgrade' to Javascript ECMA 6 which is now supported by RMMV.
  495.  * - Merged the "GameVariable Addon" into this script.
  496.  * - Added a new plugin command: Stamina SetDecreaseMode <default/tile>.
  497.  * - Added a new plugin command: Stamina ToggleDecreaseMode.
  498.  * - Changed the default "Stamina AutoDash Threshold" value from 40 --> 15 and "Hide Stamina Window Delay" from 160 --> 180.
  499.  * - Renamed Parameter "Stamina Decrease Amount" --> "Stamina Decrease Amount Default" and added a new parameter "Stamina Decrease Amount Tiled".
  500.  * - Fixed a console-warning from the visibility check when the window was fully slided out.
  501.  *
  502.  * v1.21 (29 September 2019)
  503.  * - This time I upgraded the correct version of the script... Please don't use v1.20.
  504.  *  
  505.  * v1.20 (28 September 2019)
  506.  * - Updated this plugin for the latest version of RMMV.
  507.  *
  508.  * v1.10 (05 June 2016)
  509.  * - Added a new plugin command to enforce to hide the stamina-bar (for cut-scenes and such): Stamina ForceHide true/false.
  510.  * - Fixed a bug that wouldn't correctly render the stamina window when setting "Autohide" to false. Consuming stamina at least once also used to fix this.
  511.  *
  512.  * v1.09 (11 April 2016)
  513.  * - Refactoring & minor performance optimizations.
  514.  *
  515.  * v1.08 (03 April 2016) [Parameters Changed]
  516.  * - Added an optional SFX to the tile-mode.
  517.  * - Added two new parameters: "Default SFX Volume" and "Stamina Decrease Tiled SFX".
  518.  *
  519.  * v1.07a (01 April 2016) [Parameters Changed]
  520.  * - Added a new parameter to run common events at certain stamina values/percentages.
  521.  * - 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).
  522.  * - Added more comments to the code.
  523.  *
  524.  * v1.06 (26 March 2016)
  525.  * - Added new plugin commands: SetVar, SetEval, SetMaxEval & SetMaxVar.
  526.  * - The plugin command "Stamina EnableDashing" now accepts a third value: toggle.
  527.  *
  528.  * v1.05 (21 March 2016)
  529.  * - 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.
  530.  * - Added new functions and a new alias to accomodate the above new feature.
  531.  *
  532.  * v1.04 (03 February 2016)
  533.  * - 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).
  534.  *
  535.  * v1.03 (01 January 2016)
  536.  * - Used my new coding standards & refactored.
  537.  * - Switched to the Imported variable.
  538.  * - Fixed an accidental duplicate alias.
  539.  * - Fixed a bug in Scene_Map.prototype.updateMain() (which just so happened to cause no side-effects).
  540.  *
  541.  * v1.02 (12 December 2015)
  542.  * - Dashing for the current map can now be entirely disabled with a map-notetag and switched with a plugin command at any time.
  543.  * - Created a simple plugin addon to store the player-stamina in a global game-variable.
  544.  * - Enabled custom text to be drawn in front of the Stamina Window.
  545.  * - New feature: items can replenish, lower, refill and deplete stamina (only in the menu, not in battle).
  546.  *
  547.  * v1.01 (1 December 2015)
  548.  * - Removed strict-mode because... Possible bug in RPG Maker...
  549.  * - Refactored and fixed semicolons and missing var-keywords.
  550.  *
  551.  * v1.00 (26 November 2015)
  552.  * - First release.
  553.  * Alpha (November 2015)
  554.  * - First alpha release.
  555.  *
  556.  */
  557.  
  558. /*~struct~SEGaugeRect:
  559.  * @param x
  560.  * @type number
  561.  * @default 0
  562.  *
  563.  * @param y
  564.  * @type number
  565.  * @default -20
  566.  *
  567.  * @param width
  568.  * @type number
  569.  * @min 0
  570.  * @default 132
  571.  *
  572.  * @param height
  573.  * @type number
  574.  * @min 0
  575.  * @default 24
  576.  */
  577. //#endregion
  578. /*╔════════════════════════╗
  579.   ║ Plugin #Initialization ║
  580.   ╚════════════════════════╝*/
  581. var Imported = Imported || {};
  582. Imported.SE_DashStamina = { name: 'SE_DashStamina', version: 2.00, author: 'Squirting Elephant', date:'2019-10-17'};
  583. var SE = SE || {};
  584. SE.Alias = SE.Alias || {};
  585.  
  586. (function()
  587. {
  588. /*╔═════════════════════════╗
  589.   ║ #Parameters & Variables ║
  590.   ╚═════════════════════════╝*/
  591. //#region Parameters & Variables
  592.  
  593.     const NO_SFX = 'none';
  594.  
  595.     // Enums
  596.     var ESlideState = Object.freeze({
  597.         'none' : 0, // Means that the window is currently not sliding, but it can slide if the conditions are right.
  598.         'in'   : 1,        // Means that it is currently sliding in.
  599.         'out'  : 2         // Means that it is currently sliding out.
  600.     });
  601.     var ESlideDir = Object.freeze({
  602.         'up'       : 1,
  603.         'right'    : 2,
  604.         'down'     : 3,
  605.         'left'     : 4
  606.     });
  607.     var EDirectionValue = Object.freeze({
  608.         'none'   : Object.freeze({x:  0, y:  0 }), // Shallow cloning: https://stackoverflow.com/questions/39736397/is-this-a-good-way-to-clone-an-object-in-es6
  609.         'up'     : Object.freeze({x:  0, y: -1 }),
  610.         'right'  : Object.freeze({x:  1, y:  0 }),
  611.         'down' : Object.freeze({x:  0, y:  1 }),
  612.         'left'   : Object.freeze({x: -1, y:  0 })
  613.     });
  614.     var EAlign = Object.freeze({
  615.         'top'    : 0,
  616.         'right'  : 1,
  617.         'bottom' : 2,
  618.         'left'   : 3
  619.     });
  620.     var EDrawStaminaValue = Object.freeze({
  621.         'none'       : 0,
  622.         'absolute'   : 1,
  623.         'percentage' : 2,
  624.         'both'       : 3
  625.        
  626.     });
  627.     var EStaminaDecreaseMode = Object.freeze({
  628.         'default' : 0,
  629.         'tile'    : 1
  630.     });
  631.  
  632.     function parseParameters(string)
  633.     {
  634.         try
  635.         {
  636.             return JSON.parse(string, (key, value) => {
  637.                 try { return parseParameters(value); }
  638.                 catch (e) { return value; }
  639.             });
  640.         } catch (e) { return string; }
  641.     };
  642.  
  643.     SE.Params.DashStamina = PluginManager.parameters('SE_DashStamina');
  644.     for (var key in SE.Params.DashStamina) { SE.Params.DashStamina[key] = SE.Params.DashStamina[key].replace('\r', ''); } // Because: fix stupid RMMV bug (https://forums.rpgmakerweb.com/index.php?threads/parameter-string-does-not-equal-string.113697/)
  645.     SE.Params.DashStamina = parseParameters(JSON.stringify(SE.Params.DashStamina));
  646.     SE.DashStamina = {};
  647.  
  648.     // Make a shorter params alias for ease of use.
  649.     var params = SE.Params.DashStamina;
  650.  
  651.     // Non-parameters
  652.     SE.DashStamina.Window = null;
  653.     SE.DashStamina.ScreenIsFading = false;
  654.     SE.DashStamina.DashingDisabled = false;
  655.     SE.DashStamina.CommonEvents = [];
  656.     SE.DashStamina.HasCommonEvents = false;
  657.     // General
  658.     SE.DashStamina.ShowWindow                = params.ShowStaminaWindow;
  659.     SE.DashStamina.DefaultVolume             = params.SFXDefaultVolume
  660.     SE.DashStamina.TiledStaminaDecreaseSFX   = params.SFXStaminaDecreaseTiled;
  661.     SE.DashStamina.PauseStaminaDuringDialog  = params.PauseStaminaDuringDialog;
  662.     // Positioning & Size
  663.     SE.DashStamina.Window_X                  = params.Window_X;
  664.     SE.DashStamina.Window_Y                  = params.Window_Y;
  665.     SE.DashStamina.WindowWidth               = params.WindowWidth;
  666.     SE.DashStamina.WindowHeight              = params.WindowHeight;
  667.     SE.DashStamina.WindowHorizontalAlignment = EAlign[params.WindowAlignment_Horizontal.toLowerCase()];
  668.     SE.DashStamina.WindowVerticalAlignment   = EAlign[params.WindowAlignment_Vertical.toLowerCase()];
  669.  
  670.     var gaugeStruct = params.StaminaGaugeRect;
  671.     SE.DashStamina.StaminaGaugeRectangle     = { x: gaugeStruct.x, y: gaugeStruct.y, width: gaugeStruct.width, height: gaugeStruct.height }; // 'clone' the object by creating a new one with the same values.
  672.     // Stamina Pool
  673.     SE.DashStamina.DecreaseMode              = EStaminaDecreaseMode[params.StaminaDecreaseMode.toLowerCase()];
  674.     SE.DashStamina.StaminaDecreaseDefault    = params.StaminaDecreaseAmountDefault;
  675.     SE.DashStamina.StaminaDecreaseTiled      = params.StaminaDecreaseAmountTiled;
  676.     SE.DashStamina.StaminaMax                = params.StaminaMax;
  677.     SE.DashStamina.StaminaRecoveryDelay      = params.StaminaRecoveryDelay;
  678.     SE.DashStamina.StaminaRecoveryRate       = params.StaminaRecoveryRate;
  679.     SE.DashStamina.StaminaAutoDashThreshold  = params.StaminaAutoDashThreshold;
  680.     SE.DashStamina.UseCustomRegenFormula     = params.UsesCustomStaminaRegenFormula;
  681.     SE.DashStamina.RegenFormula              = params.StaminaRegenFormula
  682.     // Visuals
  683.     SE.DashStamina.StaminaGaugeColor1        = params.StaminaGaugeColor_1.toUpperCase();
  684.     SE.DashStamina.StaminaGaugeColor2        = params.StaminaGaugeColor_2.toUpperCase();
  685.     SE.DashStamina.DrawStaminaValue          = EDrawStaminaValue[params.StaminaValueRenderType.toLowerCase()];
  686.     SE.DashStamina.FontSize                  = params.FontSize;
  687.     // Window Prefix Text
  688.     SE.DashStamina.WindowText                = params.WindowText;
  689.     SE.DashStamina.WindowTextOffsetY         = params.WindowTextOffset_Y;
  690.     SE.DashStamina.WindowTextGaugeSpacingX   = params.WindowTextSpacing_X;
  691.     // Hiding
  692.     SE.DashStamina.IsHiddenDuringGameMessage = params.IsHiddenDuringGameMessage;
  693.     // Window
  694.     SE.DashStamina.AutoHideStaminaWindow     = params.AutoHideStaminaWindow;
  695.     SE.DashStamina.HideStaminaWindowDelay    = params.HideStaminaWindowDelay;
  696.     SE.DashStamina.WindowOpacity             = params.StaminaWindowOpacity;
  697.     SE.DashStamina.SlidingEnabled            = (params.WindowSlideoutDirection.toLowerCase() !== 'disabled'); // Note that this is not actually a parameter.
  698.     SE.DashStamina.WindowSlideOutDir         = SE.DashStamina.SlidingEnabled ? ESlideDir[params.WindowSlideoutDirection.toLowerCase()] : ESlideDir.left;
  699.     if (SE.DashStamina.WindowSlideOutDir === undefined) { console.log('Something went wrong assigning to  SE.DashStamina.WindowSlideOutDir. Got raw parameter: ' + params.WindowSlideoutDirection.toLowerCase()); }
  700.     SE.DashStamina.WindowSlideSpeed          = params.WindowSlideSpeed;
  701.     // Advanced
  702.     SE.DashStamina.CE_Delta                  = params.CommonEvent_StaminaValue_ActivationDelta;
  703.     SE.DashStamina.GameVariableNumberStamina = params.GameVariableNumberStamina;
  704.     SE.DashStamina.DisableGameSwitch         = params.DisableStaminaConsumptionGameSwitch;
  705.     SE.DashStamina.Window_Z                  = params.Window_Z_Index;
  706.     SE.DashStamina.PluginCmdId               = params.PluginCommandIdentifier;
  707.     SE.DashStamina.IsDebug                   = params.DebugEnabled;
  708.     // Non-parameters
  709.     SE.DashStamina.ForcedHidden              = false;
  710.     SE.DashStamina.PutStaminaIntoGameVar     = SE.DashStamina.GameVariableNumberStamina > 0;
  711.  
  712. // Convert&store data for running common events at certain stamina percentages
  713.     var splitted = params.CommonEventsAtStaminaValues.split(' ');
  714.     for (var ceIdx=0; ceIdx<splitted.length; ceIdx+=2)
  715.     {
  716.         var threshold = splitted[ceIdx];
  717.         var thresholdIsPerc = false;
  718.         if (~threshold.indexOf('%'))
  719.         {
  720.             thresholdIsPerc = true;
  721.             threshold = parseInt(threshold.slice(0, -1)); // Remove % character
  722.         }
  723.         else
  724.         {
  725.             threshold = parseInt(threshold);
  726.         }
  727.         var commonEventID = parseInt(splitted[ceIdx + 1]);
  728.        
  729.         SE.DashStamina.CommonEvents[ceIdx / 2] = { threshold:threshold, thresholdIsPerc:thresholdIsPerc, commonEventID:commonEventID, lastRunStaminaAmount:null };
  730.     }
  731.     SE.DashStamina.HasCommonEvents = (SE.DashStamina.CommonEvents.length > 0);
  732. //#endregion
  733.  
  734. /*╔═══════════════╗
  735.   ║ Sanity Checks ║
  736.   ╚═══════════════╝*/
  737.     if ((SE.DashStamina.DecreaseMode !== EStaminaDecreaseMode.default) && (SE.DashStamina.DecreaseMode !== EStaminaDecreaseMode.tile)) { throw new Error('Invalid parameter-value for "Decrease Mode": ' + SE.DashStamina.DecreaseMode + '.'); }
  738.  
  739. /*╔════════════╗
  740.   ║ #Utilities ║
  741.   ╚════════════╝*/
  742. //#region Utilities
  743.     function debugLog(msg)
  744.     {
  745.         if (SE.DashStamina.IsDebug === true) { console.log(msg); }
  746.     };
  747.  
  748.     // Usage: alert( hexToRgb("#0033ff").g ); // "51";
  749.     function hexToRgb(hex)
  750.     {
  751.         var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  752.         return result ? {
  753.             r: parseInt(result[1], 16),
  754.             g: parseInt(result[2], 16),
  755.             b: parseInt(result[3], 16)
  756.         } : null;
  757.     };
  758.  
  759.     function clamp(value, min, max)
  760.     {      
  761.         return Math.min(Math.max(value, min), max);
  762.     };
  763. //#endregion
  764.  
  765. /*╔══════════════╗
  766.   ║ Game #Player ║
  767.   ╚══════════════╝*/
  768.     //------------------------------------------------------------------------------------------------------------------------------------
  769.     // Can the player possibly consume stamina?
  770.     //------------------------------------------------------------------------------------------------------------------------------------
  771.     Game_Player.prototype.hasStaminaConsumption = function()
  772.     {
  773.         if ($gameSwitches.value(SE.DashStamina.DisableGameSwitch)) { return false; }
  774.         if (!this.mapConsumeStamina) { return false; }
  775.         return true;
  776.     };
  777.  
  778.     // Alias for whenever the player entered a new tile
  779.     SE.Alias.DashStamina_Game_Player_prototype_updateMove = Game_Player.prototype.updateMove;
  780.     Game_Player.prototype.updateMove = function()
  781.     {
  782.         SE.Alias.DashStamina_Game_Player_prototype_updateMove.apply(this, arguments);
  783.         if ((SE.DashStamina.DecreaseMode === EStaminaDecreaseMode.tile) && !this.isMoving() && this.isDashing() && this.hasStaminaConsumption())
  784.         {
  785.             debugLog('Player entered new tile.');
  786.             // Consume stamina for the tile-decrease-mode
  787.             this.decreaseStamina(SE.DashStamina.StaminaDecreaseTiled);
  788.             SE.DashStamina.Window.forceRedraw = true;
  789.             if (SE.DashStamina.TiledStaminaDecreaseSFX.toLowerCase() !== NO_SFX) { Play_SE(SE.DashStamina.TiledStaminaDecreaseSFX); }
  790.         }
  791.     };
  792.  
  793.     // Is & can the player consume stamina?
  794.     Game_Player.prototype.isConsumingStamina = function()
  795.     {
  796.         return (this.isDashing() && this.isMoving() && this.hasStaminaConsumption());
  797.     };
  798.  
  799.   /*╔════════════════════╗
  800.     ║ #Stamina adjusting ║
  801.     ╚════════════════════╝*/
  802. //#region Stamina Adjusting
  803.  
  804.     // newPercValue must be between 0 - 100.
  805.     Game_Player.prototype.setStaminaByPerc = function(newPercValue)
  806.     {
  807.         var perc = Math.max(0, Math.min(100, newPercValue)); // clamp value between 0-100
  808.         this.setStamina(this.dashStaminaMax * (perc / 100.0));
  809.     }
  810.  
  811.     Game_Player.prototype.setStamina = function(newValue)
  812.     {
  813.         var oldStamina = this.dashStamina;
  814.         this.dashStamina = clamp(newValue, 0, this.dashStaminaMax);
  815.         if (this.dashStamina < oldStamina)
  816.         {
  817.             this.postDecreaseStaminaHandling();
  818.         } else if (this.dashStamina > oldStamina)
  819.         {
  820.             this.postIncreaseStaminaHandling();
  821.         }
  822.  
  823.         if (oldStamina !== this.dashStamina) { this.onStaminaValueChanged(oldStamina, this.dashStamina); }
  824.     };
  825.  
  826.     // Changes the MAXIMUM stamina (not the current stamina).
  827.     Game_Player.prototype.setMaxStamina = function(newMaxValue)
  828.     {
  829.         this.dashStaminaMax = newMaxValue;
  830.         if (this.dashStaminaMax < 1) { this.dashStaminaMax = 1; }
  831.         this.setStamina(this.dashStamina); // For clamping and calling stuff in case the this.dashStamina changes.
  832.         this.calcStaminaPerc(); // This one might be called twice if the stamina value also changes but we have to call it in case it didn't change.
  833.     }
  834.  
  835.     // Call this when the stamina value changes (NOT when only the percentage changes, like for example by changing the this.dashStaminaMax).
  836.     Game_Player.prototype.onStaminaValueChanged = function(oldVal, newVal)
  837.     {
  838.         this.updateGameVarStaminaIfRequired();
  839.         this.calcStaminaPerc();
  840.     }
  841.  
  842.     Game_Player.prototype.updateGameVarStaminaIfRequired = function()
  843.     {
  844.         if (SE.DashStamina.PutStaminaIntoGameVar === true)
  845.         {
  846.             $gameVariables.setValue(SE.DashStamina.GameVariableNumberStamina, $gamePlayer.dashStamina);
  847.         }
  848.     }
  849.  
  850.     Game_Player.prototype.increaseStamina = function(amount)
  851.     {
  852.         if (amount === 0) { return; } // Do nothing.
  853.  
  854.         this.setStamina(this.dashStamina + amount);
  855.     }
  856.  
  857.     Game_Player.prototype.decreaseStamina = function(amount)
  858.     {
  859.         if (amount === 0) { return; } // Do nothing.
  860.        
  861.         this.setStamina(this.dashStamina - amount);
  862.     };
  863.  
  864.     Game_Player.prototype.fillStamina = function()
  865.     {
  866.         this.setStamina(this.dashStaminaMax);
  867.     }
  868.  
  869.     Game_Player.prototype.depleteStamina = function()
  870.     {
  871.         this.setStamina(0);
  872.     };
  873.  
  874.     //------------------------------------------------------------------------------------------------------------------------------------
  875.     // Call this method after increasing the stamina (and only call this if the stamina-value actually changed).
  876.     //------------------------------------------------------------------------------------------------------------------------------------
  877.     Game_Player.prototype.postIncreaseStaminaHandling = function()
  878.     {
  879.         if (this.staminaIsFull())
  880.         {
  881.             this.isRecoveringStamina = false;
  882.         }
  883.         else
  884.         {
  885.             SE.DashStamina.Window.attemptToSlideIn();
  886.         }
  887.     }
  888.  
  889.     //------------------------------------------------------------------------------------------------------------------------------------
  890.     // Call this method after decreasing the stamina (and only call this if the stamina-value actually changed).
  891.     //------------------------------------------------------------------------------------------------------------------------------------
  892.     Game_Player.prototype.postDecreaseStaminaHandling = function()
  893.     {
  894.         this.isRecoveringStamina = false;
  895.         SE.DashStamina.Window.attemptToSlideIn();
  896.     };
  897. //#endregion
  898.  
  899.     //------------------------------------------------------------------------------------------------------------------------------------
  900.     // Check if #Common Events (CE) need running and do so if applicable
  901.     //------------------------------------------------------------------------------------------------------------------------------------
  902.     Game_Player.prototype.staminaEventChecks = function()
  903.     {
  904.         if (SE.DashStamina.HasCommonEvents)
  905.         {
  906.             var staminaPercRounded = Math.round(this.dashStaminaPerc * 100);
  907.             for (var ceIdx=0; ceIdx<SE.DashStamina.CommonEvents.length; ceIdx++)
  908.             {
  909.                 if (SE.DashStamina.CommonEvents[ceIdx].lastRunStaminaAmount === null)
  910.                 {
  911.                     if (SE.DashStamina.CommonEvents[ceIdx].thresholdIsPerc)
  912.                     {
  913.                         if (staminaPercRounded === SE.DashStamina.CommonEvents[ceIdx].threshold) { this.staminaRunCE(ceIdx); }
  914.                     }
  915.                     else
  916.                     {
  917.                         if (this.dashStamina === SE.DashStamina.CommonEvents[ceIdx].threshold) { this.staminaRunCE(ceIdx); }
  918.                     }
  919.                 }
  920.                 else
  921.                 {
  922.                     if (Math.abs(SE.DashStamina.CommonEvents[ceIdx].lastRunStaminaAmount - this.dashStamina) >= (SE.DashStamina.CE_Delta - 1))
  923.                     {
  924.                         SE.DashStamina.CommonEvents[ceIdx].lastRunStaminaAmount = null; // Allow this CE to be run again next time
  925.                     }
  926.                 }
  927.             }
  928.         }
  929.     };
  930.  
  931.     Game_Player.prototype.staminaRunCE = function(ceIdx)
  932.     {
  933.         $gameTemp.reserveCommonEvent(SE.DashStamina.CommonEvents[ceIdx].commonEventID);
  934.         SE.DashStamina.CommonEvents[ceIdx].lastRunStaminaAmount = this.dashStamina;
  935.     };
  936.  
  937.     //------------------------------------------------------------------------------------------------------------------------------------
  938.     // #Update Stamina Stuff
  939.     //------------------------------------------------------------------------------------------------------------------------------------
  940.     Game_Player.prototype.updateStamina = function()
  941.     {
  942.         // If a dialog is active and the stamina should be paused during that, then do nothing.
  943.         if (SE.DashStamina.PauseStaminaDuringDialog && ($gameMessage.isBusy() === true)) { return; }
  944.  
  945.         this.oldDashStamina = this.dashStamina;
  946.  
  947.         var isConsumingStamina = this.isConsumingStamina();
  948.         if (isConsumingStamina)
  949.         {
  950.             this.hideStaminaWindowDelayCnt = 0;
  951.  
  952.             // Only consume stamina here if the decrease-mode is set to default
  953.             if (SE.DashStamina.DecreaseMode === EStaminaDecreaseMode.default)
  954.             {
  955.                 this.decreaseStamina(SE.DashStamina.StaminaDecreaseDefault);
  956.             }
  957.         }
  958.         else // Not currently consuming stamina.
  959.         {      
  960.             if (this.isRecoveringStamina === true)
  961.             {
  962.                 this.hideStaminaWindowDelayCnt = 0;
  963.                 this.staminaRegenerationTimeCnt++;
  964.                 this.RegenerateStamina();
  965.             }
  966.             else
  967.             {
  968.                 this.attemptToStartStaminaRegeneration();
  969.             }
  970.  
  971.             // If still not recovering stamina, increase the counter for sliding the window out and slide it out if needed (if not already sliding out).
  972.             if ((this.isRecoveringStamina === false) &&
  973.                 (SE.DashStamina.Window.wSliding.state !== ESlideState.out) &&
  974.                 (SE.DashStamina.ShowWindow === true) &&
  975.                 (SE.DashStamina.AutoHideStaminaWindow === true))
  976.             {
  977.                 this.hideStaminaWindowDelayCnt += 1;
  978.                 if (this.hideStaminaWindowDelayCnt >= SE.DashStamina.HideStaminaWindowDelay)
  979.                 {
  980.                     this.hideStaminaWindowDelayCnt = 0;
  981.                     SE.DashStamina.Window.attemptToSlideOut();
  982.                 }
  983.             }
  984.         }
  985.    
  986.         // Threshold
  987.         if (!isConsumingStamina)
  988.         {
  989.             this.requiresThresholdAmount = this.dashStaminaPerc * 100 < SE.DashStamina.StaminaAutoDashThreshold;
  990.         }
  991.        
  992.         var staminaChanged = this.oldDashStamina !== this.dashStamina;
  993.         if ((staminaChanged === true) || SE.DashStamina.Window.forceRedraw)
  994.         {
  995.             SE.DashStamina.Window.forceRedraw = false;
  996.             if (SE.DashStamina.Window) { SE.DashStamina.Window.onAfterStaminaChanged(); }
  997.         }
  998.  
  999.         this.staminaEventChecks();
  1000.     };
  1001.  
  1002.     Game_Player.prototype.calcStaminaPerc = function()
  1003.     {
  1004.         this.dashStaminaPerc = this.dashStamina / parseFloat(this.dashStaminaMax);
  1005.     }
  1006.  
  1007.     Game_Player.prototype.RegenerateStamina = function()
  1008.     {
  1009.         this.increaseStamina(this.calculateStaminaRegen(SE.DashStamina.StaminaRecoveryRate));
  1010.     };
  1011.  
  1012.     Game_Player.prototype.staminaIsFull = function()
  1013.     {
  1014.         return this.dashStamina >= this.dashStaminaMax;
  1015.     }
  1016.  
  1017.     // When not already recovering stamina, find out when to start recovering it and do so if required.
  1018.     Game_Player.prototype.attemptToStartStaminaRegeneration = function()
  1019.     {
  1020.         if ((this.isRecoveringStamina === true) || this.staminaIsFull()) { return; } // Safety check.
  1021.  
  1022.         this.staminaRecoveryDelayCnt += 1;
  1023.         if (this.staminaRecoveryDelayCnt >= SE.DashStamina.StaminaRecoveryDelay)
  1024.         {
  1025.             //this.hideStaminaWindowDelayCnt = 0;
  1026.             this.staminaRecoveryDelayCnt = 0;
  1027.             this.staminaRegenerationTimeCnt = 0;
  1028.             this.isRecoveringStamina = true;
  1029.         }
  1030.     };
  1031.  
  1032.     //------------------------------------------------------------------------------------------------------------------------------------
  1033.     // Regeneration Formula
  1034.     //------------------------------------------------------------------------------------------------------------------------------------
  1035.     Game_Player.prototype.calculateStaminaRegen = function()
  1036.     {
  1037.         if (!SE.DashStamina.UseCustomRegenFormula) { return this.calculateStaminaRegenEval();   }
  1038.         else { return this.calculateStaminaRegenNoEval();}
  1039.     };
  1040.        
  1041.     Game_Player.prototype.calculateStaminaRegenEval = function()
  1042.     {
  1043.         var base = SE.DashStamina.StaminaRecoveryRate;
  1044.         var x = this.staminaRegenerationTimeCnt;
  1045.         return eval(SE.DashStamina.RegenFormula);
  1046.     };
  1047.  
  1048.     Game_Player.prototype.calculateStaminaRegenNoEval = function()
  1049.     {
  1050.         return SE.DashStamina.StaminaRecoveryRate + Math.sqrt(this.staminaRegenerationTimeCnt / 50);
  1051.     };
  1052.  
  1053.     //------------------------------------------------------------------------------------------------------------------------------------
  1054.     // Initialize
  1055.     //------------------------------------------------------------------------------------------------------------------------------------
  1056.     SE.Alias.DashStamina_Game_Player_prototype_initialize = Game_Player.prototype.initialize;
  1057.     Game_Player.prototype.initialize = function()
  1058.     {
  1059.         SE.Alias.DashStamina_Game_Player_prototype_initialize.apply(this, arguments);
  1060.  
  1061.         this.dashStaminaMax = SE.DashStamina.StaminaMax; // do this before calling fillStamina()
  1062.         this.fillStamina();
  1063.         this.staminaRecoveryDelayCnt = 0; // counter for when to start recovering stamina
  1064.         this.staminaRegenerationTimeCnt = 0; // counter for how long the player has been recovering stamina (in frames)
  1065.         this.isRecoveringStamina = false;
  1066.         this.dashStaminaPerc = 1.0;
  1067.         this.hideStaminaWindowDelayCnt = 0;
  1068.         this.requiresThresholdAmount = false;
  1069.         this.wasDashing = false;
  1070.     };
  1071.  
  1072.     //------------------------------------------------------------------------------------------------------------------------------------
  1073.     // Is the player currently allowed to dash?
  1074.     //------------------------------------------------------------------------------------------------------------------------------------
  1075.     Game_Player.prototype.dashingAllowed = function()
  1076.     {
  1077.         if (this.dashStamina === 0 ||
  1078.         (!this.wasDashing && this.requiresThresholdAmount)) // Do not allow to dash if the player was not dashing the previous frame AND if the threshold was passed.
  1079.         {
  1080.             return false;
  1081.         }
  1082.        
  1083.         return true;
  1084.     };
  1085.  
  1086.     //------------------------------------------------------------------------------------------------------------------------------------
  1087.     // Alias for disallowing dashing
  1088.     //------------------------------------------------------------------------------------------------------------------------------------
  1089.     SE.Alias.DashStamina_Game_Player_prototype_updateDashing = Game_Player.prototype.updateDashing;
  1090.     Game_Player.prototype.updateDashing = function()
  1091.     {
  1092.         SE.Alias.DashStamina_Game_Player_prototype_updateDashing.apply(this, arguments);
  1093.        
  1094.         if (SE.DashStamina.DashingDisabled)
  1095.         {
  1096.             this._dashing = false;
  1097.             return;
  1098.         }
  1099.        
  1100.         if (!this.dashingAllowed()) { this._dashing = false; }
  1101.         this.wasDashing = this._dashing;
  1102.     };
  1103.  
  1104. /*╔══════════════╗
  1105.   ║ Game #Screen ║
  1106.   ╚══════════════╝*/
  1107.     // Do not just show the minimap on top of a faded-out screen.
  1108.     SE.Alias.DashStamina_Game_Screen_prototype_updateFadeOut = Game_Screen.prototype.updateFadeOut;
  1109.     Game_Screen.prototype.updateFadeOut = function()
  1110.     {
  1111.         SE.Alias.DashStamina_Game_Screen_prototype_updateFadeOut.apply(this, arguments);
  1112.        
  1113.         if (this._brightness < 255) // (this._fadeOutDuration > 0)
  1114.         {
  1115.             if (SE.DashStamina.Window !== null) { SE.DashStamina.Window.visible = false; }
  1116.             SE.DashStamina.ScreenIsFading = true;
  1117.         }
  1118.         else
  1119.         {
  1120.             SE.DashStamina.ScreenIsFading = false;
  1121.         }
  1122.     };
  1123.  
  1124. /*╔═════════════╗
  1125.   ║ Scene #Base ║
  1126.   ╚═════════════╝*/
  1127.     SE.Alias.DashStamina_Scene_Base_prototype_startFadeIn = Scene_Base.prototype.startFadeIn;
  1128.     Scene_Base.prototype.startFadeIn = function()
  1129.     {
  1130.         SE.Alias.DashStamina_Scene_Base_prototype_startFadeIn.apply(this, arguments);
  1131.         if (SE.DashStamina.Window !== null) { SE.DashStamina.Window.visible = false; }
  1132.     };
  1133.  
  1134. /*╔════════════╗
  1135.   ║ Scene #Map ║
  1136.   ╚════════════╝*/
  1137.     // Hook into the main loop
  1138.     SE.Alias.DashStamina_Scene_Map_prototype_updateMain = Scene_Map.prototype.updateMain;
  1139.     Scene_Map.prototype.updateMain = function()
  1140.     {
  1141.         SE.Alias.DashStamina_Scene_Map_prototype_updateMain.apply(this, arguments);
  1142.         $gamePlayer.updateStamina();
  1143.         if (SE.DashStamina.ShowWindow) { SE.DashStamina.Window.update(); }
  1144.     };
  1145.  
  1146. /*╔═══════════╗
  1147.   ║ #Game Map ║
  1148.   ╚═══════════╝*/
  1149.     // Disable Dashing?
  1150.     SE.Alias.DashStamina_Game_Map_prototype_setup = Game_Map.prototype.setup;
  1151.     Game_Map.prototype.setup = function(mapId)
  1152.     {
  1153.         SE.Alias.DashStamina_Game_Map_prototype_setup.apply(this, arguments);
  1154.         SE.DashStamina.DashingDisabled = ('disable_dashing' in $dataMap.meta);
  1155.     };
  1156.  
  1157. /*╔══════════════════════════════╗
  1158.   ║ #Stamina Regen/Deplete Items ║
  1159.   ╚══════════════════════════════╝*/
  1160.     SE.Alias.DashStamina_Scene_ItemBase_prototype_useItem = Scene_ItemBase.prototype.useItem;
  1161.     Scene_ItemBase.prototype.useItem = function()
  1162.     {
  1163.         var item = this.item();
  1164.         if ('dash_stamina' in item.meta)
  1165.         {
  1166.             var args = item.meta.dash_stamina.split(' ');
  1167.             switch(args[0].toLowerCase())
  1168.             {
  1169.                 case 'add':
  1170.                     if (args.length < 2) { throw 'Item-add-command is missing the value-argument.'; }
  1171.                     $gamePlayer.increaseStamina(parseInt(args[1]));
  1172.                     break;
  1173.                 case 'refill':
  1174.                     $gamePlayer.fillStamina();
  1175.                     break;
  1176.                 case 'deplete':
  1177.                     $gamePlayer.depleteStamina();
  1178.                     break;
  1179.                 case 'increasemax':
  1180.                     if (args.length < 2) { throw 'Item-increasemax-command is missing the value-argument.'; }
  1181.                     $gamePlayer.setMaxStamina(parseInt(args[1]));
  1182.                     break;
  1183.                 default:
  1184.                     throw 'Unknown dash_stamina itemnotetag: ' + item.meta;
  1185.             }
  1186.            
  1187.         }
  1188.        
  1189.         SE.Alias.DashStamina_Scene_ItemBase_prototype_useItem.apply(this, arguments);
  1190.     };
  1191.  
  1192.     SE.Alias.DashStamina_Game_Action_prototype_testApply = Game_Action.prototype.testApply;
  1193.     Game_Action.prototype.testApply = function(target)
  1194.     {
  1195.         if ('dash_stamina' in this.item().meta)
  1196.         {
  1197.             return true;
  1198.         }
  1199.         else
  1200.         {
  1201.             return SE.Alias.DashStamina_Game_Action_prototype_testApply.apply(this, arguments);
  1202.         }
  1203.     };
  1204.  
  1205. /*╔═════════════════════════════╗
  1206.   ║ #Stamina Window #Definition ║
  1207.   ╚═════════════════════════════╝*/
  1208.     function Window_DashStamina() { this.initialize.apply(this, arguments); }
  1209.     Window_DashStamina.prototype = Object.create(Window_Base.prototype);
  1210.     Window_DashStamina.prototype.constructor = Window_DashStamina;
  1211.     // Font Size
  1212.     Window_DashStamina.prototype.standardFontSize = function() { return SE.DashStamina.FontSize; };
  1213.  
  1214.     // #Initialize
  1215.     Window_DashStamina.prototype.initialize = function(x, y, width, height)
  1216.     {
  1217.         Window_Base.prototype.initialize.call(this, x, y, width, height);
  1218.         this._helpWindow = null;
  1219.         this._handlers = {};
  1220.         this._touching = false;
  1221.         this.deactivate();
  1222.         this.opacity = SE.DashStamina.WindowOpacity;
  1223.         this.gaugeText = '';
  1224.         this.forceRedraw = false;
  1225.  
  1226.         // Window Sliding
  1227.         this.wSliding =
  1228.         {
  1229.             enabled: SE.DashStamina.SlidingEnabled,
  1230.             state: ESlideState.none,
  1231.             slideDirValue: EDirectionValue.none, // Holds the x and y direction values (-1, 0 or 1).
  1232.             originalWinLoc: {x: x, y: y},
  1233.             state: ESlideState.none,
  1234.             isFullySlidedOut: false,
  1235.             isFullySlidedIn: true,
  1236.             isSliding: function() { return (this.state === ESlideState.in) || (this.state === ESlideState.out); }
  1237.         };
  1238.        
  1239.         if (SE.DashStamina.WindowText != ':none')
  1240.         {
  1241.             this.windowText = SE.DashStamina.WindowText;
  1242.             this.windowTextWidth = this.contents.measureTextWidth(this.windowText);
  1243.             this.windowTextGaugeSpacingX = SE.DashStamina.WindowTextGaugeSpacingX;
  1244.         }
  1245.         else
  1246.         {
  1247.             this.windowText = null;
  1248.             this.windowTextWidth = 0;
  1249.             this.windowTextGaugeSpacingX = SE.DashStamina.WindowTextGaugeSpacingX;
  1250.         }
  1251.        
  1252.         this.calculateGaugeFillColour();
  1253.         this.update();
  1254.         this.onAfterStaminaChanged();
  1255.     };
  1256.  
  1257.     //------------------------------------------------------------------------------------------------------------------------------------
  1258.     // Stamina Window Update
  1259.     //------------------------------------------------------------------------------------------------------------------------------------
  1260.     Window_DashStamina.prototype.update = function()
  1261.     {
  1262.         if (SE.DashStamina.ScreenIsFading)
  1263.         {
  1264.             this.visible = false;
  1265.         }
  1266.         else
  1267.         {
  1268.             Window_Base.prototype.update.call(this);
  1269.             this.drawStaminaWindow(0, 0);
  1270.             this.updateSliding();
  1271.         }
  1272.     };
  1273.  
  1274.     //------------------------------------------------------------------------------------------------------------------------------------
  1275.     // Stamina Window Drawing Optimizations (are not called every frame, unless the stamina is changing every frame of course)
  1276.     //------------------------------------------------------------------------------------------------------------------------------------
  1277.     Window_DashStamina.prototype.setGaugeFillWidth = function(rate)
  1278.     {
  1279.         this.gaugeFillWidth = Math.floor(SE.DashStamina.StaminaGaugeRectangle.width * rate);
  1280.     };
  1281.  
  1282.     // Set the desired gauge-text variable
  1283.     Window_DashStamina.prototype.setGaugeText = function()
  1284.     {
  1285.         switch(SE.DashStamina.DrawStaminaValue)
  1286.         {
  1287.             case EDrawStaminaValue.absolute:
  1288.                 this.gaugeText = parseInt($gamePlayer.dashStamina) + '/' + parseInt($gamePlayer.dashStaminaMax);
  1289.                 break;
  1290.             case EDrawStaminaValue.percentage:
  1291.                 this.gaugeText = Math.round($gamePlayer.dashStaminaPerc * 100) + '%';
  1292.                 break;
  1293.             case EDrawStaminaValue.both:
  1294.                 this.gaugeText = parseInt($gamePlayer.dashStamina) + '/' + parseInt($gamePlayer.dashStaminaMax) + ' (' + Math.round($gamePlayer.dashStaminaPerc * 100) + '%)';
  1295.                 break;
  1296.             case EDrawStaminaValue.none:
  1297.                 this.gaugeText = '';
  1298.                 return;
  1299.             default:
  1300.                 throw 'ERROR: drawStaminaWindow missing case-statement or incorrect SE.DashStamina.DrawStaminaValue value. Value: ' + SE.DashStamina.DrawStaminaValue;
  1301.         }
  1302.     };
  1303.  
  1304.     Window_DashStamina.prototype.onAfterStaminaChanged = function()
  1305.     {
  1306.         this.calculateGaugeFillColour();
  1307.         this.setGaugeFillWidth($gamePlayer.dashStaminaPerc);
  1308.         this.setGaugeText();
  1309.     };
  1310.  
  1311.     //------------------------------------------------------------------------------------------------------------------------------------
  1312.     // Stamina Window #Drawing
  1313.     //------------------------------------------------------------------------------------------------------------------------------------
  1314.     Window_DashStamina.prototype.drawStaminaGauge = function(x, y)
  1315.     {
  1316.         var gaugeY = y + this.lineHeight() - 8;
  1317.         this.contents.fillRect(x, gaugeY, SE.DashStamina.StaminaGaugeRectangle.width, SE.DashStamina.StaminaGaugeRectangle.height, this.gaugeBackColor());
  1318.         this.contents.fillRect(x, gaugeY, this.gaugeFillWidth, SE.DashStamina.StaminaGaugeRectangle.height, this.gaugeFillColour);
  1319.     };
  1320.  
  1321.     Window_DashStamina.prototype.drawStaminaWindow = function(x, y)
  1322.     {
  1323.         this.contents.clear();
  1324.         // Draw the prefix text (if applicable)
  1325.         if (this.windowText !== null)
  1326.         {
  1327.             this.contents.drawText(this.windowText, 0, SE.DashStamina.WindowTextOffsetY, this.windowTextWidth, 0);
  1328.         }
  1329.  
  1330.         // Draw gauge
  1331.         this.drawStaminaGauge(SE.DashStamina.StaminaGaugeRectangle.x + this.windowTextWidth + this.windowTextGaugeSpacingX, SE.DashStamina.StaminaGaugeRectangle.y);
  1332.        
  1333.         this.resetTextColor();
  1334.         this.drawText(this.gaugeText, x + this.windowTextWidth + this.windowTextGaugeSpacingX, y + 1, SE.DashStamina.StaminaGaugeRectangle.width, 'center');
  1335.     };
  1336.  
  1337.     // Calculate what colour the gauge should be between the two colours depending on the percentage value of the current-stamina value.
  1338.     Window_DashStamina.prototype.calculateGaugeFillColour = function()
  1339.     {
  1340.         var c1 = hexToRgb(SE.DashStamina.StaminaGaugeColor1);
  1341.         var c2 = hexToRgb(SE.DashStamina.StaminaGaugeColor2);
  1342.            
  1343.         var ratio = $gamePlayer.dashStaminaPerc;
  1344.         var hex = function(x) {
  1345.             x = x.toString(16);
  1346.             return (x.length === 1) ? '0' + x : x;
  1347.         };
  1348.  
  1349.         var r = Math.ceil(c1.r * ratio + c2.r * (1-ratio));
  1350.         var g = Math.ceil(c1.g * ratio + c2.g * (1-ratio));
  1351.         var b = Math.ceil(c1.b * ratio + c2.b * (1-ratio));
  1352.  
  1353.         var middle = '#' + hex(r) + hex(g) + hex(b);
  1354.         this.gaugeFillColour = middle;
  1355.     };
  1356.  
  1357.     //------------------------------------------------------------------------------------------------------------------------------------
  1358.     // Stamina Window #Show, #Hide & #Slide
  1359.     //------------------------------------------------------------------------------------------------------------------------------------
  1360.     // Calculates and sets the visibility of this window.
  1361.     Window_DashStamina.prototype.updateVisibility = function()
  1362.     {
  1363.         this.visible = this.shouldThisBeVisible();
  1364.     }
  1365.    
  1366.     // Alias for re-checking the stamina window visibility when a dialog is active (because we may want to hide it during a dialog).
  1367.     SE.Alias.DashStamina_Game_Message_prototype_add = Game_Message.prototype.add;
  1368.     Game_Message.prototype.add = function(text)
  1369.     {
  1370.         SE.Alias.DashStamina_Game_Message_prototype_add.apply(this, arguments);
  1371.         if (SE.DashStamina.Window) { SE.DashStamina.Window.updateVisibility(); }
  1372.     }
  1373.  
  1374.     // Calculates whether this window should be visible or not.
  1375.     Window_DashStamina.prototype.shouldThisBeVisible = function()
  1376.     {
  1377.         // Hide if...
  1378.         if (
  1379.             // The stamina window should never be visible anyway.
  1380.             ((SE.DashStamina.ShowWindow === false)) ||
  1381.  
  1382.             // The user forced it to be hidden.
  1383.             (SE.DashStamina.ForcedHidden === true) ||
  1384.            
  1385.             // It should be hidden during an active GameMessage and if the parameter is set to do so.
  1386.             ((SE.DashStamina.IsHiddenDuringGameMessage === true) && ($gameMessage.isBusy() === true)) ||
  1387.  
  1388.             // The screen is currently fading out.
  1389.             (SE.DashStamina.ScreenIsFading === true) ||
  1390.  
  1391.             // The window is fully slided-out and is currently not sliding, therefor there is no point in rendering it.
  1392.             ((this.wSliding.isFullySlidedOut === true) && (this.wSliding.isSliding() === false))
  1393.             )
  1394.         {
  1395.             return false
  1396.         };
  1397.  
  1398.         // Show if...
  1399.         if (
  1400.             // Fully slided-in OR if it does not slide OR if it is currently sliding.
  1401.             (this.wSliding.isFullySlidedIn === true) || (this.wSliding.isSliding() === true) ||
  1402.  
  1403.             // The stamina window does not slide.
  1404.             (SE.DashStamina.SlidingEnabled === false) ||
  1405.  
  1406.             // The player is recovering stamina.
  1407.             ($gamePlayer.isRecoveringStamina === true)
  1408.             )
  1409.         {
  1410.             return true;
  1411.         }
  1412.        
  1413.         // We probably missed some conditional-check so just return true.
  1414.         console.log('Warning: "Window_DashStamina.prototype.shouldThisBeVisible" defaulted to true.')
  1415.         return true;
  1416.     }
  1417.    
  1418.     /* Regarding sliding:
  1419.      * ONLY slide if:
  1420.      * 1. Sliding is enabled in the parameters.
  1421.      * 2. The stamina window is visible.
  1422.      * 3. The screen is not fading.
  1423.      *
  1424.      * ONLY start sliding-in if the above points 1-3 plus:
  1425.      * A. The window is not already sliding-in.
  1426.      *
  1427.      * ONLY start sliding-out if the above points 1-3 plus:
  1428.      * B. The window is not already sliding-out.
  1429.      *
  1430.      * Sliding is started by calling either attemptToSlideIn() or attemptToSlideOut()
  1431.      *
  1432.      * attemptToSlideIn() should be called when:
  1433.      * - Stamina is increasing or decreasing.
  1434.      *
  1435.      * attemptToSlideOut() should be called when:
  1436.      * - Stamina hasn't changed for at least SE.DashStamina.HideStaminaWindowDelay (not in seconds but in updates) time.
  1437.      * - SE.DashStamina.AutoHideStaminaWindow is true.
  1438.      */
  1439.     Window_DashStamina.prototype.canSlidingStart = function()
  1440.     {
  1441.         // Do nothing if...
  1442.         if (
  1443.             // There is no sliding desired.
  1444.             (SE.DashStamina.SlidingEnabled === false) ||
  1445.  
  1446.             // The window is not visible.
  1447.             (SE.DashStamina.ShowWindow === false) ||
  1448.  
  1449.             // The screen is fading.
  1450.             (SE.DashStamina.ScreenIsFading === true)
  1451.             )
  1452.         {
  1453.             return false;
  1454.         }
  1455.  
  1456.         return true;
  1457.     }
  1458.  
  1459.     Window_DashStamina.prototype.canSlidingInStart = function()
  1460.     {
  1461.         return ((this.wSliding.state !== ESlideState.in) && this.canSlidingStart());
  1462.     }
  1463.  
  1464.     Window_DashStamina.prototype.canSlidingOutStart = function()
  1465.     {
  1466.         return ((this.wSliding.state !== ESlideState.out) && this.canSlidingStart());
  1467.     }
  1468.  
  1469.     // Attempt to slide the window further in.
  1470.     Window_DashStamina.prototype.attemptToSlideIn = function()
  1471.     {
  1472.         if (this.canSlidingInStart() === false) { return; }
  1473.        
  1474.         debugLog('Starting to slide-in.');
  1475.         switch (SE.DashStamina.WindowSlideOutDir)
  1476.         {
  1477.             // We'll use inverted values compared to the Switch from attemptToSlideOut().
  1478.             case ESlideDir.up:
  1479.                 this.wSliding.slideDirValue = EDirectionValue.down;
  1480.                 break;
  1481.             case ESlideDir.left:
  1482.                 this.wSliding.slideDirValue = EDirectionValue.right;
  1483.                 break;
  1484.             case ESlideDir.right:
  1485.                 this.wSliding.slideDirValue = EDirectionValue.left;
  1486.                 break;
  1487.             case ESlideDir.down:
  1488.                 this.wSliding.slideDirValue = EDirectionValue.up;
  1489.                 break;
  1490.             default:
  1491.                 throw 'Window_DashStamina.prototype.attemptToSlideIn: Unknown switch value: ' + SE.DashStamina.WindowSlideOutDir;
  1492.         }
  1493.         this.wSliding.state = ESlideState.in;
  1494.         this.updateVisibility();
  1495.     };
  1496.  
  1497.     // Attempt to slide the window further out.
  1498.     Window_DashStamina.prototype.attemptToSlideOut = function()
  1499.     {
  1500.         if (this.canSlidingOutStart() === false) { return; }
  1501.        
  1502.         debugLog('Starting to slide-out.');
  1503.         switch (SE.DashStamina.WindowSlideOutDir)
  1504.         {
  1505.             case ESlideDir.up:
  1506.                 this.wSliding.slideDirValue = EDirectionValue.up;
  1507.                 break;
  1508.             case ESlideDir.left:
  1509.                 this.wSliding.slideDirValue = EDirectionValue.left;
  1510.                 break;
  1511.             case ESlideDir.right:
  1512.                 this.wSliding.slideDirValue = EDirectionValue.right;
  1513.                 break;
  1514.             case ESlideDir.down:
  1515.                 this.wSliding.slideDirValue = EDirectionValue.down;
  1516.                 break;
  1517.             default:
  1518.                 throw 'Window_DashStamina.prototype.attemptToSlideOut: Unknown switch value: ' + SE.DashStamina.WindowSlideOutDir;
  1519.         }
  1520.         this.wSliding.state = ESlideState.out;
  1521.         this.updateVisibility();
  1522.     };
  1523.  
  1524.     Window_DashStamina.prototype.handleSlidingEnd = function()
  1525.     {
  1526.         if (this.wSliding.state === ESlideState.in)
  1527.         {
  1528.             // Stop sliding in
  1529.             if ((this.wSliding.slideDirValue.x  ===  1) && (this.x >= this.wSliding.originalWinLoc.x) ||
  1530.                 (this.wSliding.slideDirValue.x  === -1) && (this.x <= this.wSliding.originalWinLoc.x) ||
  1531.                 (this.wSliding.slideDirValue.y  ===  1) && (this.y >= this.wSliding.originalWinLoc.y) ||
  1532.                 (this.wSliding.slideDirValue.y  === -1) && (this.y <= this.wSliding.originalWinLoc.y))
  1533.             {
  1534.                 debugLog('The window fully slided-in.');
  1535.                 this.wSliding.state = ESlideState.none;
  1536.                 this.restoreOriginalWindowLocation();
  1537.                 this.wSliding.isFullySlidedIn = true;
  1538.                 this.updateVisibility();
  1539.             }
  1540.         }
  1541.         else
  1542.         {
  1543.             // Stop sliding out
  1544.             if ((this.x < -this.width)  || (this.x > Graphics._width + this.width) ||
  1545.                 (this.y < -this.height) || (this.x > Graphics._height + this.height))
  1546.             {
  1547.                 debugLog('The window fully slided-out.');
  1548.                 this.wSliding.state = ESlideState.none;
  1549.                 this.wSliding.isFullySlidedOut = true;
  1550.                 this.updateVisibility();
  1551.             }
  1552.         }
  1553.     };
  1554.  
  1555.     Window_DashStamina.prototype.restoreOriginalWindowLocation = function()
  1556.     {
  1557.         this.x = this.wSliding.originalWinLoc.x;
  1558.         this.y = this.wSliding.originalWinLoc.y;
  1559.     }
  1560.  
  1561.     Window_DashStamina.prototype.updateSliding = function()
  1562.     {
  1563.         if ((this.wSliding.state === ESlideState.disabled) || (this.wSliding.state === ESlideState.none)) { return; }
  1564.  
  1565.         this.x += this.wSliding.slideDirValue.x * SE.DashStamina.WindowSlideSpeed;
  1566.         this.y += this.wSliding.slideDirValue.y * SE.DashStamina.WindowSlideSpeed;
  1567.        
  1568.         this.wSliding.isFullySlidedOut = false;
  1569.         this.wSliding.isFullySlidedIn = false;
  1570.        
  1571.         this.handleSlidingEnd();
  1572.     };
  1573.  
  1574. /*╔════════════════════════╗
  1575.   ║ #Create Stamina Window ║
  1576.   ╚════════════════════════╝*/
  1577.     Scene_Map.prototype.createDashWindow = function()
  1578.     {
  1579.         // Dispose the old window, if any
  1580.         if (SE.DashStamina.Window !== null) { this.removeWindow(SE.DashStamina.Window); }
  1581.        
  1582.         // Does the map consume stamina?
  1583.         $gamePlayer.mapConsumeStamina = !('dstam_disable' in $dataMap.meta);
  1584.         if(SE.DashStamina.ShowWindow)
  1585.         {
  1586.             var x = 0;
  1587.             if (SE.DashStamina.WindowHorizontalAlignment === EAlign.right) { x = Graphics.width - SE.DashStamina.WindowWidth; }
  1588.             var y = 0;
  1589.             if (SE.DashStamina.WindowVerticalAlignment === EAlign.bottom) { y = Graphics.height - SE.DashStamina.WindowHeight; }
  1590.            
  1591.             SE.DashStamina.Window = new Window_DashStamina(x + SE.DashStamina.Window_X, y + SE.DashStamina.Window_Y, SE.DashStamina.WindowWidth, SE.DashStamina.WindowHeight);
  1592.             this.addChildAt(SE.DashStamina.Window, Math.min(SE.DashStamina.Window_Z, this.children.length));
  1593.             if (SE.DashStamina.AutoHideStaminaWindow) { SE.DashStamina.Window.visible = false; }
  1594.         }
  1595.     };
  1596.  
  1597.     // Omg why does RPG Maker not have this method by default...
  1598.     Scene_Base.prototype.removeWindow = function(window)
  1599.     {
  1600.         var index = this.children.indexOf(window);
  1601.         if (index > -1) { this.children.splice(index, 1); }
  1602.     };
  1603.  
  1604.     SE.Alias.DashStamina_Scene_Map_prototype_createDisplayObjects = Scene_Map.prototype.createDisplayObjects;
  1605.     Scene_Map.prototype.createDisplayObjects = function()
  1606.     {
  1607.         SE.Alias.DashStamina_Scene_Map_prototype_createDisplayObjects.apply(this, arguments);
  1608.         this.createDashWindow();
  1609.     };
  1610. /*╔═══════════╗
  1611.   ║ Play #SFX ║
  1612.   ╚═══════════╝*/
  1613.     function Play_SE(filename)
  1614.     {
  1615.         var volume = (SE.DashStamina.DefaultVolume > -1) ? SE.DashStamina.DefaultVolume : AudioManager.seVolume;
  1616.         AudioManager.playSe({name: filename, volume: volume, pitch: 100, pan: 0});
  1617.     }
  1618.  
  1619. /*╔════════════════════╗
  1620.   ║ #Saving & #Loading ║
  1621.   ╚════════════════════╝*/
  1622.     SE.Alias.DashStamina_DataManager_makeSaveContents = DataManager.makeSaveContents;
  1623.     DataManager.makeSaveContents = function()
  1624.     {
  1625.         contents = SE.Alias.DashStamina_DataManager_makeSaveContents.apply(this, arguments);
  1626.         contents.dashStamina = $gamePlayer.dashStamina;
  1627.         contents.dashStaminaMax = $gamePlayer.dashStaminaMax;
  1628.         return contents;
  1629.     };
  1630.  
  1631.     SE.Alias.DashStamina_DataManager_extractSaveContents = DataManager.extractSaveContents;
  1632.     DataManager.extractSaveContents = function(contents)
  1633.     {
  1634.         SE.Alias.DashStamina_DataManager_extractSaveContents.apply(this, arguments);
  1635.         $gamePlayer.dashStamina = contents.dashStamina;
  1636.         $gamePlayer.dashStaminaMax = contents.dashStaminaMax;
  1637.     };
  1638.  
  1639. /*╔═════════════════╗
  1640.   ║ Plugin #Command ║
  1641.   ║                 ╚═══════════════════════════════════════════════════════════════════════════════════════════════════════════╗
  1642.   ║ Note: The items are separated by spaces. The command is the first word and any following words are args. args is an array.  ║
  1643.   ╚═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝*/
  1644.     SE.Alias.DashStamina_Game_Interpreter_prototype_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  1645.     Game_Interpreter.prototype.pluginCommand = function(command, args)
  1646.     {
  1647.         SE.Alias.DashStamina_Game_Interpreter_prototype_pluginCommand.apply(this, arguments);
  1648.         if (command.toLowerCase() === SE.DashStamina.PluginCmdId) { SE.DashStamina.PluginCommand(command, args); }
  1649.     };
  1650.  
  1651.     // Concatenate the 'arguments' starting at a specific index because they are all part of an eval.
  1652.     SE.DashStamina.concatArgs = function(args, startIdx)
  1653.     {
  1654.         var evalstr = '';
  1655.         for (var argIdx = startIdx; argIdx < args.length; argIdx++)
  1656.         {
  1657.             evalstr += args[argIdx] + ' ';
  1658.         }
  1659.         return evalstr;
  1660.     };
  1661.  
  1662.     SE.DashStamina.PluginCommand = function(cmd, args)
  1663.     {
  1664.         switch(args[0].toLowerCase())
  1665.         {
  1666.             case 'refill':
  1667.                 $gamePlayer.fillStamina();
  1668.                 SE.DashStamina.Window.forceRedraw = true;
  1669.                 break;
  1670.             case 'deplete':
  1671.                 $gamePlayer.depleteStamina();
  1672.                 SE.DashStamina.Window.forceRedraw = true;
  1673.                 break;
  1674.             case 'set':
  1675.                 $gamePlayer.setStaminaByPerc(parseInt(args[1]));
  1676.                 SE.DashStamina.Window.forceRedraw = true;
  1677.             break;
  1678.             case 'setvar':
  1679.                 $gamePlayer.setStaminaByPerc(parseInt($gameVariables.value(args[1])));
  1680.                 SE.DashStamina.Window.forceRedraw = true;
  1681.             break;
  1682.             case 'seteval':
  1683.                 var perc = parseInt(eval(SE.DashStamina.concatArgs(args, 1)));
  1684.                 if (isNaN(perc)) { throw new Error('Plugin command: "Stamina SetEval" evaled to a NaN value: ' + perc + '.'); }
  1685.                 $gamePlayer.setStaminaByPerc(perc);
  1686.                 SE.DashStamina.Window.forceRedraw = true;
  1687.             break;
  1688.             case 'showwindow':
  1689.                 if (SE.DashStamina.Window !== null)
  1690.                 {
  1691.                     $gamePlayer.hideStaminaWindowDelayCnt = 0;
  1692.                     SE.DashStamina.Window.visible = (!SE.DashStamina.ForcedHidden);
  1693.                 }
  1694.                 break;
  1695.             case 'refillhide':
  1696.                 $gamePlayer.setStamina($gamePlayer.dashStaminaMax);
  1697.                 // NO break-statement here! We want to hide the window as well!
  1698.             case 'hidewindow':
  1699.                 if (SE.DashStamina.Window !== null)
  1700.                 {
  1701.                     $gamePlayer.hideStaminaWindowDelayCnt = SE.DashStamina.HideStaminaWindowDelay;
  1702.                     SE.DashStamina.Window.visible = false;
  1703.                 }
  1704.                 break;
  1705.             case 'setmax':
  1706.                 $gamePlayer.setMaxStamina(parseInt(args[1]));
  1707.                 SE.DashStamina.Window.forceRedraw = true;
  1708.                 break;
  1709.             case 'setmaxeval':
  1710.                 $gamePlayer.setMaxStamina(parseInt(eval(SE.DashStamina.concatArgs(args, 1))));
  1711.                 SE.DashStamina.Window.forceRedraw = true;
  1712.                 break;
  1713.             case 'setmaxvar':
  1714.                 $gamePlayer.setMaxStamina(parseInt($gameVariables.value(args[1])));
  1715.                 SE.DashStamina.Window.forceRedraw = true;
  1716.                 break;
  1717.             case 'increasemax':
  1718.                 $gamePlayer.setMaxStamina($gamePlayer.dashStaminaMax + parseInt(args[1]));
  1719.                 SE.DashStamina.Window.forceRedraw = true;
  1720.                 break;
  1721.             case 'enabledashing':
  1722.                 switch(args[1].toLowerCase())
  1723.                 {
  1724.                     case 'true':
  1725.                         SE.DashStamina.DashingDisabled = false;
  1726.                         break;
  1727.                     case 'false':
  1728.                         SE.DashStamina.DashingDisabled = true;
  1729.                         break;
  1730.                     case 'toggle':
  1731.                         SE.DashStamina.DashingDisabled = !SE.DashStamina.DashingDisabled;
  1732.                         break;
  1733.                     default:
  1734.                         throw new Error('"Stamina EnableDashing" received an unknown argument: ' + args[1] + '. Expected: True, False or Toggle.');
  1735.                 }
  1736.                 break;
  1737.             case 'forcehide':
  1738.                 SE.DashStamina.ForcedHidden = (args[1].toLowerCase() === 'true');
  1739.                 if (SE.DashStamina.Window !== null)
  1740.                 {
  1741.                     SE.DashStamina.Window.visible = !SE.DashStamina.ForcedHidden;
  1742.                 }
  1743.                 break;
  1744.             case 'setdecreasemode':
  1745.                 SE.DashStamina.DecreaseMode = (args[1].toLowerCase() === 'default') ?  EStaminaDecreaseMode.default : EStaminaDecreaseMode.tile;
  1746.                 break;
  1747.             case 'toggledecreasemode':
  1748.                 SE.DashStamina.DecreaseMode = (SE.DashStamina.DecreaseMode === EStaminaDecreaseMode.default) ? EStaminaDecreaseMode.tile : EStaminaDecreaseMode.default;
  1749.                 break;
  1750.             default:
  1751.                 throw 'Stamina PluginCommand invalid command: ' + args[0];
  1752.         }
  1753.     };
  1754.  
  1755. })();
  1756. /*╔═════════════╗
  1757.   ║ End of File ║
  1758.   ╚═════════════╝*/
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top