Advertisement
Astfgl

QTEWindow R2

Nov 14th, 2016 (edited)
10,479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // QTEWindow
  3. // by Astfgl
  4. // Date: 03/11/2016
  5. // Build: 26/11/2016
  6. // Release build 02
  7. // Bug fixes + New parameters.
  8. // TERMS OF USE:
  9. // Free to use both commercially and non commercially.
  10. // For commercial games, you must provide me with a free copy of the game.
  11. // For non commercial games, tell me about it! I'd love to see what you were able
  12. // to do with my plugin.
  13. // Credits required, in a visible place:
  14. // any of Astfgl/ Pierre MATEO/ Pierre MATEO (Astfgl)
  15. // Edits allowed, with the caveat that you must keep the edited product under the
  16. // same license and you must clearly indicate it is an edit, and what part you
  17. // did edit.
  18. // You must keep this header intact.
  19. //
  20. // For information, time spent developping this + addons: 30hours.
  21. // 08/07/2023 added paramater for sound bites
  22. //=============================================================================
  23.  
  24. /*:
  25.  * @plugindesc v1.0; Basic QTE setup
  26.  * @author Astfgl
  27.  *
  28.  * @param BaseDuration
  29.  * @desc The base duration of the QTE Window, in frames.
  30.  * @default 60
  31.  *
  32.  * @param EndingDuration
  33.  * @desc The duration when the sequence is completed before closing the window for free QTEs, in frames.
  34.  * @default 30
  35.  *
  36.  * @param IconArray
  37.  * @desc The index of each icon to use for the display. [up,down,left,right,ok,cancel]
  38.  * @default [12,13,14,15,28,29]
  39.  *
  40.  * @param Width
  41.  * @desc Number of icons to show in the QTE Window
  42.  * @default 6
  43.  *
  44.  * @param Height
  45.  * @desc The height in pixels of the QTE Window
  46.  * @default 100
  47.  *
  48.  * @param PlaySound
  49.  * @desc Whether to play any sound or not
  50.  * @default true
  51.  *
  52.  * @param SuccessSoundName
  53.  * @desc The name of the SE to be played on succesfull input. If 0, no sound will be played.
  54.  * @default Cursor2
  55.  *
  56.  * @param SuccessSoundParam
  57.  * @desc The parameters for playing the success sound [volume,pitch,pan]
  58.  * @default [90,100,0]
  59.  *
  60.  * @param ResultSuccessSound
  61.  * @desc The name of the SE to be played when the QTE is completed succesfully. 0 = no sound.
  62.  * @default Decision1
  63.  *
  64.  * @param ResultSuccessSoundParam
  65.  * @desc The parameters for playing the success sound [volume,pitch,pan]
  66.  * @default [90,100,0]
  67.  *
  68.  * @param ResultFailureSound
  69.  * @desc The name of the SE to be played when the QTE fails. 0 = no sound.
  70.  * @default Buzzer1
  71.  *
  72.  * @param ResultFailureSoundParam
  73.  * @desc The parameters for playing the success sound [volume,pitch,pan]
  74.  * @default [90,100,0]
  75.  *
  76.  * @param CanFail
  77.  * @desc Whether or not the player can make wrong inputs. If false, a wrong input will end the QTE as a failure.
  78.  * @default false
  79.  *
  80.  * @param ShowTime
  81.  * @desc Show The remaining time or not, can be: gauge, number, both or no
  82.  * @default gauge
  83.  *
  84.  * @param TextAlign
  85.  * @desc Where to put the countdown number: can be left right or center
  86.  * @default right
  87.  *
  88.  * @param GaugeFilling
  89.  * @desc The color of the gauge gradient 1 in [r,g,b] format
  90.  * @default [255,255,255]
  91.  *
  92.  * @param GaugeBack
  93.  * @desc The color of the gauge gradient 2, in [r,g,b] format
  94.  * @default [0,0,0]
  95.  *
  96.  * @param DisplayFailText
  97.  * @desc true = display a message in the log window upon QTE failure, false = don't
  98.  * @default true
  99.  *
  100.  * @param FailText
  101.  * @desc The message shown when a QTE fails.
  102.  * @default Wrong input ot time ran out.
  103.  *
  104.  * @param DisplayNoMatchText
  105.  * @desc true = display a message in the log window when no match is found, false = don't
  106.  * @default true
  107.  *
  108.  * @param NoMatchText
  109.  * @desc The message shown when no match is found for a free QTE.
  110.  * @default No skill found matching that sequence.
  111.  *
  112.  * @param OcarinaSounds
  113.  * @desc The array of each sound name, in that order [up,down,left,right,ok,cancel]
  114.  * @default ["OcarinaRé2","OcarinaFa","OcarinaSi","OcarinaLa","OcarinaRé","Ocarina",]
  115.  *
  116.  * @param OcarinaNotePosition
  117.  * @desc The position of each note on the music sheet [up,down,left,right,ok,cancel]
  118.  * @default [36*1+18+3,4*36+3,3*36+3,2*36+18+3,5*36+3,0]
  119.  *
  120.  * @help
  121.  * ===================================================================
  122.  * PLUGIN SETUP:
  123.  * Set the parameters before use, notably the icon indexes or the
  124.  * inputs won't show.
  125.  * If you want to use the ocarina mode, you'll have to specify
  126.  * the file names in the ocarina sounds parameter.
  127.  * If you want accurate note display you'll have to modify the note
  128.  * position array too, 36 is one full space, 18 a half space, 3 is
  129.  * just for correct spacing.
  130.  *
  131.  * ===================================================================
  132.  * SUGGESTED PLUGINS FOR BATTLE USE:
  133.  * Yanfly Core Engine, Battle Engine Core, Action sequence 1
  134.  * This is for battle use through action sequences. You can call the QTE
  135.  * using common events or another plugin providing action sequences if you want.
  136.  * I just haven't tried it. I make almost no battle modifications though
  137.  * so another plugin should work too.
  138.  *
  139.  * Look at the examples in the thread for ideas on how to use them in action
  140.  * sequences.
  141.  *
  142.  * ==================================================================
  143.  * How to call a QTE:
  144.  * $gameMap.QTE(mode,duration,sequence,visible,x*,y*,opacity*,
  145.  * width*,height*,wrongInput*,showTime*)
  146.  *
  147.  * =================
  148.  * NORMAL QTE
  149.  * mode = ["normal"]
  150.  * duration = duration wanted in frames
  151.  * sequence = sequence (see at the end of the help file how to provide sequences)
  152.  * visible = whether you want to show the qte window or not, true or false
  153.  *
  154.  * All the following parameters marked with an * are not required, but the window
  155.  * will use them instead of the plugin parameters if they are present.
  156.  * x = x position of the qte window
  157.  * y = y position of the qte window
  158.  * opacity = opacity of the back of the qte window, not the icons
  159.  * or time remaining gauge
  160.  * width = the width as in number of icons you want to show at once
  161.  * height = the height in pixels
  162.  * wrongInput = whether a wrong input will end the QTE as a failure or not,
  163.  * can be true or false
  164.  * showTime = the mode to show time, "number", "gauge", "both" or "no"
  165.  *
  166.  * ex: $gameMap.QTE(["normal"],300,["ok","up","left"],true)
  167.  *
  168.  *==================
  169.  * To set one QTE window option in particular:
  170.  *
  171.  * $gameMap.setQTEpos(x,y) = sets the x and y position of the QTE window.
  172.  * $gameMap.setQTEdim(width,height) = sets the width and height of the QTE window
  173.  * $gameMap.setQTEfail(boolean) = either true or false, whether a wrong
  174.  * Input makes the QTE stops as a failure.
  175.  * $gameMap.setQTEopacity(number) from 0 transparent to 255 opaque,
  176.  * the opacity of the QTE window, not the contents.
  177.  * $gameMap.setQTEtime(mode) sets which mode to display time, same options
  178.  * as the parameter.
  179.  * $gameMap.setQTEsound(bool) true or false, whether to play sounds or not.
  180.  * Note that this will only stop the system sounds from playing, the ocarina
  181.  * sounds will be played if applicable.
  182.  * $gameMap.setOcarina(bool,bool2) if bool = true each input will play the sound
  183.  * defined in the parameters, if bool2 = true it will switch the display mode
  184.  * of the sequence to look like a music sheet.
  185.  * ================
  186.  *
  187.  * Every QTE window option is reset at the end of each action in battle.
  188.  * On the map, the QTE window is reset each time the map is entered,
  189.  * like going in the menuand then back.
  190.  * This goes for all QTE modes.
  191.  * Reset all QTE options: $gameMap.clearQTE();
  192.  *
  193.  * ===============
  194.  * FREE QTE a QTE that registers player input
  195.  * The script call is the same as above, however the mode argument differs
  196.  * mode = ["free",maxInput,cancelButton]
  197.  * maxInput = the maximum numberof recorded keys
  198.  * cancelButton = a button to end the input.
  199.  * If you have several skills with different sequence length
  200.  * set the maxInput to the maximum sequence length. Ie fire is up up down,
  201.  * spark up up up up, set max Input to 4.
  202.  * If you want to cast spark just press up 4 times, because maxInput is reached
  203.  * the qte will end automatically. But if you want to cast Fire you'll gave to
  204.  * press up up down and then cancelButton.
  205.  * It will ignore the sequence argument, so just put [].
  206.  *
  207.  * ex: $gameMap.QTE(["free",4,"cancel"],300,[],true). This will produce a
  208.  * QTE window asking for 4 inputs, ending when running out of time or
  209.  * on the first "cancel" button press.
  210.  *================
  211.  *
  212.  * RYTHMIC QTE: ie a qte progressing by itself and you need to press each
  213.  * button in its timeframe
  214.  * The sequence is setup like this:
  215.  * [[button,duration],[button2,duration2],...,[buttonN,durationN]]
  216.  * In addition to the inputs below you can use "no", and it will wait and
  217.  * return a failure if any button is pressed during the wait.
  218.  * The mode argument is also changed mode = ["rythm",increment*]
  219.  * Increment is not mandatory, it is by how much at each frame the duration
  220.  * will diminish.
  221.  * If not set it will use 1.
  222.  * Ex: duration = 300 frame, increment 1 -> actual duration 300 frame
  223.  * duration = 300 frames, increment 5 -> actual duration 60 frames. It will make
  224.  * the qte move faster.
  225.  * Call example:
  226.  * var seq = [["ok",100],["no",50],["up",100],["down",100]]
  227.  * $gameMap.QTE(["rythm",5],300,seq,true);
  228.  *
  229.  *
  230.  * ========================================================
  231.  * How to get a QTE result: $gameMap.getQTEResult()
  232.  *
  233.  * =================
  234.  * Important:
  235.  * Please note that due to the way this works you have to use the
  236.  * getQTEResult() script call in another script event command, not in
  237.  * the same as the one where you launch the qte or it won't work.
  238.  *
  239.  * =================
  240.  * The result function has 4 possibilities:
  241.  * pending: qte not started
  242.  * start: qte currently running
  243.  * success: qte ended succesfully
  244.  * failure: qte ended in failure
  245.  *
  246.  * ex: $gameMap.getQTEResult() === "success" in a condition script will return true
  247.  * if the QTE was a success, and false for any other option.
  248.  *
  249.  * ================
  250.  * In case of a free QTE the result function will return the sequence.
  251.  * To get the skills that match the sequence entered, use the call:
  252.  * $gameMap.getSkillMatch(actorId)
  253.  * This will look through all skills of the actor, and if any of the
  254.  * sequences in their note <qteSeq:> matches that of the skill, will return
  255.  * their id.
  256.  *
  257.  * ex: $gameMap.getSkillMatch(1) will look through actor 1 skills.
  258.  *
  259.  * If you want to return the name of a skill from a match, use
  260.  * $gameMap.getSkillNameFromMatch(skillId)
  261.  *
  262.  * ex: $gameMap.getSkillNameFromMatch($getSkillMatch(1))
  263.  * That call will try to match the qte result to a skill id, and return their
  264.  * name. Assign it to a variable and you can display it.
  265.  *
  266.  * ============================================================
  267.  * DEFINING SEQUENCES:
  268.  * ============================================================
  269.  *
  270.  * Normal mode :
  271.  * Provide sequences as an array
  272.  * ["button1", button2",...,"buttonN"].
  273.  *
  274.  *
  275.  * Free mode:
  276.  * The defined sequence doesn't matter just use [].
  277.  *
  278.  *
  279.  * Rythm mode:
  280.  * Provide sequences as an array:
  281.  * [[button,duration],[button2,duration2],...[buttonN,durationN]]
  282.  * You can use "no" instead of a button if you want to make a pause
  283.  * in the QTE.
  284.  *
  285.  * ============================================================
  286.  * Use a free input QTE to cast a spell for each input:
  287.  * $gameMap.castSequence(user,target,actionAr)
  288.  * IMPORTANT This command won't work without yanfly's battle engine
  289.  * core and will crash your game if used without.
  290.  * The user and target must be the objects themselves, not the ID
  291.  * or index.
  292.  * ActionAr is the array of action to match the input in that order:
  293.  * [up,down,left,right,ok,cancel]
  294.  *
  295.  * ex: eval: $gameMap.castSequence(user,target,[30,31,32,33,34,35])
  296.  * For an input: up down left right ok
  297.  * This will make the user cast skills 30,31,32,33,34 in succession
  298.  *
  299.  * You can use v(id) inside the action array, to refer to the value
  300.  * of variable id, so you are able to modify the combos in game.
  301.  *
  302.  * ============================================================
  303.  * Use a free input QTE to cast a skill that matches its sequence.
  304.  * $gameMap.castSkillMatch(user,target,failActionId)
  305.  * This will make the user cast the matching action on target,
  306.  * if there was no match it will instead make it cast failActionId.
  307.  * If failActionId is 0, it won't do anything instead.
  308.  *
  309.  * ============================================================
  310.  * Cast both the sequence and the skill match:
  311.  * $gameMap.castSandSM(user,target,actionAr,failActionId)
  312.  * This will first go through the actions via the cast sequence
  313.  * command and then attempt to cast a match from that sequence.
  314.  * The arguments are the same as the functions described above.
  315.  *
  316.  * =============================================================
  317.  * Cast every skill match found within the sequence:
  318.  * $gameMap.trySequence(user,target,minInputs*,maxInputs*)
  319.  * Okay, this one is a bit complicated, let's take an example:
  320.  * the free QTE result is ["ok","ok","down","down"]
  321.  * Let's say min and max Inputs aren't given as instructions.
  322.  * It will cast the skills the actor know with the notetags
  323.  * <qteSeq:["ok"]> and <qteSeq:["down"]> in that order:
  324.  * ok, ok, down, down.
  325.  * Then it will move to look for matches in 2 length.
  326.  * So it will cast the spells okok, okdown and downdown
  327.  * Then do it for 3:
  328.  * okokdown, okdowndown
  329.  * Then do it for 4:
  330.  * okokdowndown
  331.  * If the actor doesn't have any skills that match those notetags
  332.  * it simply will ignore them.
  333.  * What do min Input and max Input do: they will start or end
  334.  * the process at those number.
  335.  * So if min inputs was 2 , it wouldn't have cast the skills
  336.  * that matched only 1 input. And if max Inputs was 3 it wouldn't
  337.  * have cast the final sequence of 4.
  338.  *
  339.  * =============================================================
  340.  * MAKE A RANDOM SEQUENCE
  341.  * ONLY FOR NORMAL MODE
  342.  * Use $gameMap.randomSequence(length)
  343.  * It will generate a random QTE sequence of that length, using
  344.  * all inputs available, except those you put after length
  345.  * example: $gameMap.randomSequence(5,"up") will return a 5
  346.  * input long sequence that doesn't contain the up key.
  347.  * $gameMap.randomSequence(5,"up","down") will do the same
  348.  * but without the down key too.
  349.  * example:
  350.  * $gameMap.QTE(["normal",0],500,$gameMap.randomSequence(5),true)
  351.  *
  352.  *
  353.  *
  354.  *
  355.  *
  356.  * ===========================================================
  357.  * KEY LIST
  358.  * ===========================================================
  359.  * You can find the list of keys here:
  360.  *   0: 'ok',        // A
  361.  *   1: 'cancel',    // B Used as cancel key in examples.
  362.  *   2: 'shift',     // X Not supported
  363.  *   3: 'menu',      // Y Not supported
  364.  *   4: 'pageup',    // LB Not suppoted
  365.  *   5: 'pagedown',  // RB Not supported
  366.  *   12: 'up',       // D-pad up
  367.  *   13: 'down',     // D-pad down
  368.  *   14: 'left',     // D-pad left
  369.  *   15: 'right',    // D-pad right
  370.  *
  371.  */
  372.  
  373.  
  374. //Creating the QTE window object prototype
  375. function Window_QTE() {
  376.     this.initialize.apply(this, arguments);
  377. }
  378.  
  379. Window_QTE.prototype = Object.create(Window_Selectable.prototype);
  380. Window_QTE.prototype.constructor = Window_QTE;
  381.  
  382. Window_QTE.prototype.initialize = function(duration) {
  383.     var parameters = PluginManager.parameters('QTEWindow');
  384.     this._duration = duration || Number(parameters.BaseDuration);
  385.     var width = Number(parameters.Width) * 48 + 20;
  386.     var height = Number(parameters.Height);
  387.     var x = Graphics.boxWidth/2 - width/2;
  388.     var y = Graphics.boxHeight/2 - height/2;
  389.     Window_Selectable.prototype.initialize.call(this, x, y, 1000, 1000);
  390.     this.width = width;
  391.     this.height = height;
  392.     var a = eval(PluginManager.parameters('QTEWindow').GaugeBack);
  393.     var b = eval(PluginManager.parameters('QTEWindow').GaugeFilling);
  394.     this._gaugeBack = Utils.rgbToCssColor(a[0],a[1],a[2])
  395.     this._gaugeFilling = Utils.rgbToCssColor(b[0],b[1],b[2])
  396.     this._result = "pending";
  397.     this._sequence = [];
  398.     this._seqIndex = 0;
  399.     this._currentB = 0;
  400.     this._frozen = true;
  401.     this._maxDuration = 0;
  402.     this._mode = ["normal",0];
  403.     this._currInputs = 0;
  404.     this._wrongInput = eval(parameters.CanFail)
  405.     this._itemNumber = Number(parameters.Width);
  406.     this._increment = 1;
  407.     this._inputs = [];
  408.     this._sound = eval(parameters.PlaySound);
  409.     this._ocarina = [false,false];
  410.     this._notePos = eval(parameters.OcarinaNotePosition)
  411.     this._endDur = eval(parameters.EndingDuration)
  412.     this._ending = false;
  413.     this.update();
  414. }
  415.  
  416. Window_QTE.prototype.update = function() {
  417.     if (!this._frozen) {
  418.         var wrongInput = this._wrongInput;
  419.         this.contents.clear();
  420.         var showTime = PluginManager.parameters('QTEWindow').ShowTime;
  421.         if (this._ending === true) { //Show the sequence when the QTE has ended
  422.             this.contents.clear();
  423.             if (this._mode[0] === "normal" || this._mode[0] === "rythm") {
  424.                 this._endDur = 0;
  425.             }
  426.             if (this._mode[0] === "free") {
  427.                 if (!this._ocarina[1]) {
  428.                     this.drawSequence();
  429.                 } else {
  430.                     this.drawOcarina();
  431.                 }
  432.                 this.drawTime(showTime);
  433.                 this._endDur -= 1;
  434.             }
  435.             if (this._endDur <= 0) {
  436.                 //this._ending = false;
  437.                 this._frozen = true;
  438.                 this.hide();
  439.                 this.end();
  440.             }
  441.         }
  442.         if (this._mode[0] === "normal" && !this._ending) { //update normal QTE mode
  443.             if (!this._ocarina[1]) {
  444.                 this.drawSequence();
  445.             } else {
  446.                 this.drawOcarina();
  447.             }
  448.             this.setCurrentB();
  449.             this.setDuration(-1);
  450.             this.drawTime(showTime);
  451.             var check = true;
  452.             if (Input.isTriggered(this._currentB)) {
  453.                 if (this._currentB === "cancel") {check = false}
  454.                 this._seqIndex += 1;
  455.                 this.playInput();
  456.                 if (this._ocarina[0]) {
  457.                     this.playOcarina();
  458.                 }
  459.             }
  460.             if (this.getSeqIndex() >= this._sequence.length) {
  461.                 this.setResult("success");
  462.                 this.playSuccessSound();
  463.                 this._ending = true;
  464.             };
  465.             if (this.getResult() === "start" && !this.checkFailure() && !wrongInput && check) {
  466.                 this.setResult("failure");
  467.             }
  468.             if (this._duration <= 0 && this.getResult() === "start") {
  469.                 this.setResult("failure");
  470.             }
  471.             if (this.getResult() === "failure") {
  472.                 this.playFailureSound();
  473.                 this.displayFailure();
  474.                 /*this.hide();
  475.                 this._frozen = true;*/
  476.                 this._ending = true;
  477.             }
  478.             if (this.getResult() === "success") {
  479.                 /*this.hide();
  480.                 this._frozen = true;*/
  481.                 this.playSuccessSound();
  482.                 this._ending = true;
  483.             }
  484.         }
  485.        
  486.         if (this._mode[0] === "free" && !this._ending) {// update free input QTE mode
  487.             if (!this._ocarina[1]) {
  488.                 this.drawSequence();
  489.             } else {
  490.                 this.drawOcarina();
  491.             }
  492.             this.setCurrentB();
  493.             this._seqIndex = 0;
  494.             this.setDuration(-1);
  495.             this.drawTime(showTime);
  496.             var maxInputs = this._mode[1];
  497.             var endButton = this._mode[2];
  498.             if (this._currInputs >= maxInputs) {
  499.                 //finished inputting, > max inputs
  500.                 this.playSuccessSound();
  501.                 this.endFreeQTE();
  502.             }
  503.             if (Input.isTriggered(endButton)) {
  504.                 //player presses the finish button
  505.                 this.playSuccessSound();
  506.                 this.endFreeQTE();
  507.             }
  508.             if (this.checkInput(endButton) !== 0 && !this._ending) {
  509.                 //register inputs
  510.                 this._sequence.push(this.checkInput(endButton));
  511.                 this._currInputs += 1;
  512.                 this.playInput();
  513.                 if (this._ocarina[0]) {
  514.                     this.playOcarina();
  515.                 }
  516.             }
  517.             if (this._duration <= 0 && this.getResult() === "start") {
  518.                 this.setResult("failure");
  519.             }
  520.             if (this.getResult() === "failure") {
  521.                 this.playFailureSound();
  522.                 this.displayFailure();
  523.                 //this.hide();
  524.                 //this._frozen = true;
  525.                 this._ending = true;
  526.             }
  527.         }
  528.    
  529.         if (this._mode[0] === "rythm" && !this._ending) {//update rythm mode
  530.             var increment = this._increment || 1;
  531.             this.setDuration(-increment);
  532.             if (!this._ocarina[1]) {
  533.                 this.drawRythm();
  534.             } else {
  535.                 this.drawRythmOcarina();
  536.             }
  537.             this.drawTime(showTime);
  538.             this._currentB = this.getRythmCurrInput();
  539.             var index = this.getRythmIndex()
  540.             if (!this._inputs[index] && this._sequence[index][0] === "no") { //for a waiting period
  541.                 this._inputs[index] = true;
  542.                 this._seqIndex +=1;
  543.             }
  544.             if (this._inputs[index]) {
  545.                 this._currentB = ""
  546.             }
  547.             if (Input.isTriggered(this._currentB) && !this._inputs[index]) {
  548.                 this._inputs[index] = true;
  549.                 this._seqIndex += 1;
  550.                 this.playInput();
  551.                 if (this._ocarina[0]) {
  552.                     this.playOcarina();
  553.                 }
  554.             }
  555.             if (this.getResult() === "start" && !this.checkFailure() && !wrongInput) {
  556.                 this.setResult("failure");
  557.             }
  558.             if (index > this.getSeqIndex()) { //If player missed a note, the sequence index will be < to the expected index
  559.                 this.setResult("failure");
  560.             }
  561.             if (this.getSeqIndex() >= this._sequence.length) { //If end music reached
  562.                 this.setResult("success")
  563.             }
  564.             if (this._duration <= 0) {
  565.                 this.setResult("failure");
  566.             }
  567.             if (this.getResult() === "failure") {
  568.                 this.playFailureSound();
  569.                 this.displayFailure();
  570.                 /*this.hide();
  571.                 this._frozen = true;*/
  572.                 this._ending = true;;
  573.             }
  574.             if (this.getResult() === "success") {
  575.                 /*this.hide();
  576.                 this._frozen = true;*/
  577.                 this.playSuccessSound();
  578.                 this._ending = true
  579.             }
  580.            
  581.         }
  582.     }
  583. }
  584.  
  585. Window_QTE.prototype.setDuration = function(duration) {
  586.     if (duration === undefined) {return this._duration}
  587.     this._duration += duration;
  588. }
  589.  
  590. Window_QTE.prototype.getResult = function() {
  591.     return this._result
  592. }
  593.  
  594. Window_QTE.prototype.setResult = function(result) {
  595.     this._result = result
  596. }
  597.  
  598. Window_QTE.prototype.setSequence = function(seq) {
  599.     this._sequence = seq;
  600. }
  601.  
  602. Window_QTE.prototype.getSeqIndex = function() {
  603.     return this._seqIndex
  604. }
  605.  
  606. Window_QTE.prototype.setCurrentB = function(index) {
  607.     this._currentB = this._sequence[this.getSeqIndex()]
  608. }
  609.  
  610. Window_QTE.prototype.playInput = function() {
  611.     var filename = PluginManager.parameters('QTEWindow').SuccessSoundName
  612.     var ar = eval(PluginManager.parameters('QTEWindow').SuccessSoundParam);
  613.     var sound = {
  614.         name: filename,
  615.         volume: ar[0],
  616.         pitch: ar[1],
  617.         pan: ar[2] }
  618.     if (filename !== "0" && this._sound) {
  619.         AudioManager.playSe(sound);
  620.     }
  621. }
  622.  
  623. Window_QTE.prototype.playSuccessSound = function() {
  624.     var filename = PluginManager.parameters('QTEWindow').ResultSuccessSound
  625.     var ar = eval(PluginManager.parameters('QTEWindow').ResultSuccessSoundParam);
  626.     var sound = {
  627.         name: filename,
  628.         volume: ar[0],
  629.         pitch: ar[1],
  630.         pan: ar[2] }
  631.     if (filename !== "0" && this._sound) {
  632.         AudioManager.playSe(sound);
  633.     }
  634. }
  635.  
  636. Window_QTE.prototype.playFailureSound = function() {
  637.     var filename = PluginManager.parameters('QTEWindow').ResultFailureSound
  638.     var ar = eval(PluginManager.parameters('QTEWindow').ResultFailureSoundParam);
  639.     var sound = {
  640.         name: filename,
  641.         volume: ar[0],
  642.         pitch: ar[1],
  643.         pan: ar[2] }
  644.     if (filename !== "0" && this._sound) {
  645.         AudioManager.playSe(sound);
  646.     }
  647. }
  648.  
  649. Window_QTE.prototype.drawSequence = function() {
  650.     var max = Math.min(this._itemNumber,this._sequence.length - this.getSeqIndex());
  651.     for (var i = 0; i < max; i++) {
  652.         this.drawIcon(this.getIconIndex(this._sequence[i + this.getSeqIndex()]) ,48 * i, 0)
  653.     }
  654. }
  655.  
  656. Window_QTE.prototype.startSequence = function(mode) {
  657.     this._frozen = false;
  658.     this._seqIndex = 0;
  659.     this.setResult("start")
  660.     this._mode = mode
  661. }
  662.  
  663. Window_QTE.prototype.getIconIndex = function(string) {
  664.     var iconar = eval(PluginManager.parameters('QTEWindow').IconArray);
  665.     switch (string) {
  666.         case "ok":
  667.             return iconar[4];
  668.             break;
  669.         case "cancel":
  670.             return iconar[5];
  671.             break;
  672.         case "up":
  673.             return iconar[0];
  674.             break;
  675.         case "down":
  676.             return iconar[1];
  677.             break;
  678.         case "left":
  679.             return iconar[2];
  680.             break;
  681.         case "right":
  682.             return iconar[3];
  683.             break;
  684.         default:
  685.             return 0;
  686.             break;
  687.     }
  688. }
  689.  
  690. Window_QTE.prototype.checkFailure = function() {
  691.     if (Input.isTriggered("up") && this._currentB !== "up") {
  692.         return false
  693.     } else if (Input.isTriggered("down") && this._currentB !== "down") {
  694.         return false
  695.     } else if (Input.isTriggered("left") && this._currentB !== "left") {
  696.         return false
  697.     } else if (Input.isTriggered("right") && this._currentB !== "right") {
  698.         return false
  699.     } else if (Input.isTriggered("ok") && this._currentB !== "ok") {
  700.         return false
  701.     } else if ((Input.isTriggered("cancel") || Input.isTriggered("escape")) && this._currentB !== "cancel") {
  702.         return false
  703.     } else if (Input.isTriggered("shift") && this._currentB !== "shift") {
  704.         return false
  705.     } else if (Input.isTriggered("menu") && this._currentB !== "menu") {
  706.         return false
  707.     } else if (Input.isTriggered("pageup") && this._currentB !== "pageup") {
  708.         return false
  709.     } else if (Input.isTriggered("pagedown") && this._currentB !== "pagedown") {
  710.         return false
  711.     } else {
  712.         return true
  713.     }
  714. }
  715.  
  716. Window_QTE.prototype.end = function() {
  717.     this.deactivate();
  718. }
  719.  
  720. Window_QTE.prototype.clear = function() {
  721.     this._result = "pending"
  722.     this._sequence = [];
  723.     this._seqIndex = 0;
  724.     this._currentB = 0;
  725.     this._frozen = true;
  726.     this.opacity = 255;
  727.     var parameters = PluginManager.parameters('QTEWindow')
  728.     var width = Number(parameters.Width) * 48 + 20;
  729.     var height = Number(parameters.Height);
  730.     this.width = width;
  731.     this.height = height;
  732.     var x = Graphics.boxWidth/2 - width/2;
  733.     var y = Graphics.boxHeight/2 - height/2;
  734.     this.x = x;
  735.     this.y = y;
  736.     this._wrongInput = eval(parameters.CanFail);
  737.     this._itemNumber = Number(parameters.Width);
  738.     this._mode = ["normal",0];
  739.     this._currInputs = 0;
  740.     this._inputs = [];
  741.     this._increment = 1;
  742.     this._sound = eval(parameters.PlaySound);
  743.     this._ocarina = [false,false];
  744.     this._ending= false;
  745.     this._endDur = eval(parameters.EndingDuration)
  746. }
  747.  
  748. Window_QTE.prototype.drawTime = function(mode) {
  749.     var align = PluginManager.parameters('QTEWindow').TextAlign
  750.     var x;
  751.     var y;
  752.     var width = this.width - 40
  753.     //var height = this.height - 58;
  754.     var rate = this._duration/this._maxDuration;
  755.     if (mode === "gauge") {
  756.         x = 0;
  757.         y = 20;
  758.         if (this._ocarina[1]) {
  759.             y = this.height - 54 - 30
  760.         }
  761.         this.drawGauge(x,y,width,rate,this._gaugeBack,this._gaugeFilling);
  762.     }
  763.     if (mode === "number") {
  764.         x = 0;
  765.         y = 34;
  766.         if (this._ocarina[1]) {
  767.             y = this.height - 34 - 30
  768.         }
  769.         var txt = ""
  770.         txt += Math.floor(this._duration/60)
  771.         txt += "/"
  772.         txt += Math.floor(this._maxDuration/60)
  773.         this.drawText(txt,x,y,width,align)
  774.     }
  775.     if (mode === "both") {
  776.         x = 0;
  777.         y = 20;
  778.         if (this._ocarina[1]) {
  779.             y = this.height - 54 - 30
  780.         }
  781.         this.drawGauge(x,y,width,rate,this._gaugeBack,this._gaugeFilling);
  782.         x = 0;
  783.         y = 34;
  784.         if (this._ocarina[1]) {
  785.             y = this.height - 34 - 30
  786.         }
  787.         var txt = ""
  788.         txt += Math.floor(this._duration/60)
  789.         txt += "/"
  790.         txt += Math.floor(this._maxDuration/60)
  791.         this.drawText(txt,x,y,width,align)
  792.     }
  793.     if (mode === "no") {};
  794. }
  795.  
  796. Window_QTE.prototype.checkInput = function(endButton) {
  797.     if (Input.isTriggered("up") && (endButton !== "up")) {
  798.         return "up"
  799.     } else if (Input.isTriggered("down") && (endButton !== "down")) {
  800.         return "down"
  801.     } else if (Input.isTriggered("left") && (endButton !== "left")) {
  802.         return "left"
  803.     } else if (Input.isTriggered("right") && (endButton !== "right")) {
  804.         return "right"
  805.     } else if (Input.isTriggered("ok") && (endButton !== "ok")) {
  806.         return "ok"
  807.     } else if (Input.isTriggered("cancel") && (endButton !== "cancel")) {
  808.         return "cancel"
  809.     } else if (Input.isTriggered("shift") && (endButton !== "shift")) {
  810.         return "shift"
  811.     } else if (Input.isTriggered("menu") && (endButton !== "menu")) {
  812.         return "menu"
  813.     } else if (Input.isTriggered("pageup") && (endButton !== "pageup")) {
  814.         return "pageup"
  815.     } else if (Input.isTriggered("pagedown") && (endButton !== "pagedown")) {
  816.         return "pagedown"
  817.     } else {
  818.         return 0
  819.     }
  820. }
  821.  
  822. Window_QTE.prototype.endFreeQTE = function() {
  823.     if (this._sequence[0] === undefined) {
  824.         this.setResult("failure");
  825.     } else {
  826.         this.setResult(this._sequence);
  827.     };
  828.     this._ending = true;
  829.     /*this.hide();
  830.     this._frozen = true;
  831.     this.end();*/
  832. }
  833.  
  834. Window_QTE.prototype.getRythmCurrInput = function() {
  835.     return this._sequence[this.getRythmIndex()][0]
  836. }
  837.  
  838. Window_QTE.prototype.getRythmIndex = function() {
  839.     var curTime = this._maxDuration - this._duration;
  840.     var sum1 = 0;
  841.     var sum2 = this._sequence[0][1]
  842.     var index = 0;
  843.  
  844.     for (var i = 0; i < this._sequence.length; i++) {
  845.         if (curTime >= sum1 && curTime <= sum2) {
  846.             index = i
  847.         }
  848.         if (i === (this._sequence.length-1)) {break}
  849.         sum1 += this._sequence[i][1];
  850.         sum2 += this._sequence[i+1][1];
  851.     }
  852.     return index
  853. }
  854.  
  855. Window_QTE.prototype.drawRythm = function() {
  856.     var width = this.width;
  857.     var height = 36
  858.     var color1 = Utils.rgbToCssColor(188,64,64);
  859.     var color1Bis = Utils.rgbToCssColor(255,0,0);
  860.     var color2 = Utils.rgbToCssColor(64,64,188);
  861.     var color2Bis = Utils.rgbToCssColor(0,0,255);
  862.     var color, colorBis
  863.     var sum = 0;
  864.     var sum2 = this._sequence[0][1];
  865.     var currTime = this._maxDuration - this._duration
  866.     for (var i = 0; i < this._sequence.length; i++) {
  867.         var x = sum - currTime;
  868.         if (x < currTime + width) {
  869.             if (i%2 === 0) {
  870.                 color = color1;
  871.                 colorBis = color1Bis
  872.             } else {
  873.                 color = color2
  874.                 colorBis = color2Bis
  875.             };
  876.             if (this._sequence[i][0] !== "no") {
  877.                 this.contents.gradientFillRect(x,0,this._sequence[i][1],height,color,colorBis, false);
  878.                 this.contents.clearRect (x + 5 , 5 , this._sequence[i][1] - 10 , height - 10 )
  879.                 this.drawText(this._sequence[i][0], x, 0, this._sequence[i][1], "center")
  880.             }
  881.         }
  882.         if (i === (this._sequence.length -1)) {
  883.             break;
  884.         }
  885.         sum += this._sequence[i][1]
  886.         sum2 += this._sequence[i+1][1]
  887.     }
  888.    
  889. }
  890.  
  891. Window_QTE.prototype.displayFailure = function() {
  892.     if (SceneManager._scene instanceof Scene_Battle) {
  893.         SceneManager._scene._logWindow.displayQTEFailure();
  894.     }
  895. }
  896.  
  897. Window_QTE.prototype.playOcarina = function(endButton) {
  898.     var input = this.checkInput(endButton);
  899.     var ocarina = eval(PluginManager.parameters("QTEWindow").OcarinaSounds);
  900.     var filename = "0";
  901.     if (input === "up") {
  902.         var filename = ocarina[0];
  903.     } else if (input === "down") {
  904.         var filename = ocarina[1];
  905.     } else if (input === "left") {
  906.         var filename = ocarina[2];
  907.     } else if (input === "right") {
  908.         var filename = ocarina[3];
  909.     } else if (input === "ok") {
  910.         var filename = ocarina[4];
  911.     } else if (input === "cancel") {
  912.         var filename = ocarina[5];
  913.     }
  914.     var sound = {
  915.         name: filename,
  916.         volume: 90,
  917.         pitch: 100,
  918.         pan: 0
  919.     };
  920.     if (filename !== "0") {
  921.         AudioManager.playSe(sound);
  922.     }
  923. }
  924.  
  925. Window_QTE.prototype.drawOcarina = function() {
  926.     var max = Math.min(this._itemNumber,this._sequence.length - this.getSeqIndex());
  927.     for (var i = 0; i < 5; i++) {
  928.         this.drawHorzLine(36 + 36 * i);
  929.     }
  930.     for (var i = 0; i < max; i++) {
  931.         if (this._sequence[i+this.getSeqIndex()] === "ok") {
  932.             var y = this._notePos[4];
  933.         } else  if (this._sequence[i+this.getSeqIndex()] === "up") {
  934.             var y = this._notePos[0];
  935.         } else  if (this._sequence[i+this.getSeqIndex()] === "down") {
  936.             var y = this._notePos[1];
  937.         } else  if (this._sequence[i+this.getSeqIndex()] === "right") {
  938.             var y = this._notePos[3];
  939.         } else if (this._sequence[i+this.getSeqIndex()] === "left") {
  940.             var y = this._notePos[2];
  941.         } else {
  942.             var y = 0;
  943.         }
  944.         this.drawIcon(this.getIconIndex(this._sequence[i + this.getSeqIndex()]) ,48 * i, y)
  945.     }
  946. }
  947.  
  948. Window_QTE.prototype.drawHorzLine = function(y) {
  949.     var lineY = y;
  950.     this.contents.paintOpacity = 120;
  951.     this.contents.fillRect(0, lineY, this.contentsWidth(), 2, this.lineColor());
  952.     this.contents.paintOpacity = 255;
  953. };
  954.  
  955. Window_QTE.prototype.lineColor = function() {
  956.     return this.normalColor();
  957. };
  958.  
  959. Window_QTE.prototype.drawRythmOcarina = function() {
  960.     var width = this.width;
  961.     var height = 33
  962.     var color1 = Utils.rgbToCssColor(188,64,64);
  963.     var color1Bis = Utils.rgbToCssColor(255,0,0);
  964.     var color2 = Utils.rgbToCssColor(64,64,188);
  965.     var color2Bis = Utils.rgbToCssColor(0,0,255);
  966.     var color, colorBis
  967.     var sum = 0;
  968.     var sum2 = this._sequence[0][1];
  969.     var currTime = this._maxDuration - this._duration
  970.     for (var i = 0; i < 5; i++) {
  971.         this.drawHorzLine(36 + 36 * i);
  972.     }
  973.     for (var i = 0; i < this._sequence.length; i++) {
  974.         var x = sum - currTime;
  975.         if (x < currTime + width) {
  976.             if (i%2 === 0) {
  977.                 color = color1;
  978.                 colorBis = color1Bis
  979.             } else {
  980.                 color = color2
  981.                 colorBis = color2Bis
  982.             };
  983.             if (this._sequence[i][0] !== "no") {
  984.                 if (this._sequence[i][0] === "ok") {
  985.                     var y = this._notePos[4];
  986.                 } else  if (this._sequence[i][0] === "up") {
  987.                     var y = this._notePos[0];
  988.                 } else  if (this._sequence[i][0] === "down") {
  989.                     var y = this._notePos[1];
  990.                 } else  if (this._sequence[i][0] === "right") {
  991.                     var y = this._notePos[3];
  992.                 } else if (this._sequence[i][0] === "left") {
  993.                     var y = this._notePos[2];
  994.                 } else {
  995.                     var y = 0;
  996.                 }
  997.                 this.contents.gradientFillRect(x, y, this._sequence[i][1], height, color, colorBis, false);
  998.                 this.contents.clearRect (x + 5 , y + 5 , this._sequence[i][1] - 10 , height - 10 )
  999.                 this.drawText(this._sequence[i][0], x, y, this._sequence[i][1], "center")
  1000.             }
  1001.         }
  1002.         if (i === (this._sequence.length -1)) {
  1003.             break;
  1004.         }
  1005.         sum += this._sequence[i][1]
  1006.         sum2 += this._sequence[i+1][1]
  1007.     }
  1008.    
  1009. }
  1010.  
  1011.  
  1012. //Scene Battle Modifications to handle QTE input
  1013. var _Astfgl_newSBCAW = Scene_Battle.prototype.createAllWindows
  1014. Scene_Battle.prototype.createAllWindows = function() {
  1015.     _Astfgl_newSBCAW.call(this)
  1016.     this.createQTEWindow()
  1017. };
  1018.  
  1019. Scene_Battle.prototype.createQTEWindow = function() {
  1020.     this._QTEWindow = new Window_QTE;
  1021.     this._QTEWindow.visible = false;
  1022.     this.addWindow(this._QTEWindow);
  1023. }
  1024.  
  1025. var _Astfgl_newSBIAIWA = Scene_Battle.prototype.isAnyInputWindowActive
  1026. Scene_Battle.prototype.isAnyInputWindowActive = function() {
  1027.     return _Astfgl_newSBIAIWA.call(this) || this._QTEWindow.active
  1028. };
  1029.  
  1030. //BattleManager modifications
  1031. var _Astfgl_newBMIB = BattleManager.isBusy
  1032. BattleManager.isBusy = function() {
  1033.     return _Astfgl_newBMIB.call(this) || (SceneManager._scene._QTEWindow.getResult() === "start")
  1034. };
  1035.  
  1036. var _Astfgl_newBMEA = BattleManager.endAction
  1037. BattleManager.endAction = function() {
  1038.     _Astfgl_newBMEA.call(this);
  1039.     $gameMap.clearQTE();
  1040. };
  1041.  
  1042. //Scene_Map modifications
  1043. var _Astfgl_newSMCAW = Scene_Map.prototype.createAllWindows
  1044. Scene_Map.prototype.createAllWindows = function() {
  1045.     _Astfgl_newSMCAW.call(this);
  1046.     this.createQTEWindow();
  1047. };
  1048.  
  1049. Scene_Map.prototype.createQTEWindow = function() {
  1050.     this._QTEWindow = new Window_QTE;
  1051.     this.addChild(this._QTEWindow);
  1052.     //this._QTEWindowIndex = this.children.length - 1;
  1053.     this._QTEWindow.visible = false;
  1054. }
  1055.  
  1056. var _Astfgl_newSMIB = Scene_Map.prototype.isBusy
  1057. Scene_Map.prototype.isBusy = function() {
  1058.     return _Astfgl_newSMIB.call(this) || this._QTEWindow.getResult() === "start"
  1059. };
  1060.  
  1061. //GameMap call to start QTE
  1062. Game_Map.prototype.QTE = function(mode,duration,sequence,visible,x,y,opacity,width,height,wrongInput,showTime) {
  1063.     var qte = SceneManager._scene._QTEWindow
  1064.     if (mode[0] === "free") {
  1065.         sequence = [];
  1066.         qte._currInputs = 0;
  1067.         width = mode[1];
  1068.         qte._itemNumber = width;
  1069.     }
  1070.     if (mode[0] === "rythm") {
  1071.         var b = 0;
  1072.         qte._inputs=[]
  1073.         for (var i = 0; i < sequence.length; i++) {
  1074.             b += sequence [i][1]
  1075.             qte._inputs.push(false)
  1076.         }
  1077.         duration = b;
  1078.         qte._increment = mode[1];
  1079.     }
  1080.     qte.setSequence(sequence);
  1081.     qte._duration = duration;
  1082.     qte._maxDuration = duration;
  1083.     qte._endDur = eval(PluginManager.parameters("QTEWindow").EndingDuration);
  1084.     qte._ending = false;
  1085.     if (visible) {
  1086.         qte.show()
  1087.     };
  1088.     qte.startSequence(mode);
  1089.     if (SceneManager._scene instanceof Scene_Battle) {
  1090.         qte.activate();
  1091.     }
  1092.     if (x !== undefined) {qte.x = x};
  1093.     if (y !== undefined) {qte.y = y};
  1094.     if (width !== undefined) {qte.width = width * 48 + 20; qte._itemNumber = width};
  1095.     if (height !== undefined) {qte.height = height}
  1096.     if (wrongInput !== undefined) {qte._wrongInput = wrongInput}
  1097.     if (showTime !== undefined) {qte._showTime = showTime}
  1098.     if (opacity !== undefined) {qte.opacity = opacity};
  1099.     //if (SceneManager._scene instanceof Scene_Map) {}
  1100. }
  1101.  
  1102. Game_Map.prototype.clearQTE = function() {
  1103.     var qte = SceneManager._scene._QTEWindow
  1104.     qte.clear();
  1105. }
  1106.  
  1107. Game_Map.prototype.getQTEResult = function() {
  1108.     var qte = SceneManager._scene._QTEWindow
  1109.     return qte.getResult()
  1110. }
  1111.  
  1112. //GameMap calls to set options
  1113. Game_Map.prototype.setQTEpos = function(x,y) {
  1114.     var qte = SceneManager._scene._QTEWindow;
  1115.     qte.x = x;
  1116.     qte.y = y;
  1117. }
  1118.  
  1119. Game_Map.prototype.setQTEopacity = function(x) {
  1120.     var qte = SceneManager._scene._QTEWindow;
  1121.     qte.opacity = x;
  1122. }
  1123.  
  1124. Game_Map.prototype.setQTEdim = function(width,height) {
  1125.     var qte = SceneManager._scene._QTEWindow;
  1126.     qte.width = width;
  1127.     qte.height = height;
  1128. }
  1129.  
  1130. Game_Map.prototype.setQTEfail = function(bool) {
  1131.     var qte = SceneManager._scene._QTEWindow;
  1132.     qte._wrongInput = bool;
  1133. }
  1134.  
  1135. Game_Map.prototype.setQTEtime = function(mode) {
  1136.     var qte = SceneManager._scene._QTEWindow;
  1137.     qte._showTime = mode;
  1138. }
  1139.  
  1140. Game_Map.prototype.setQTEsound = function(bool) {
  1141.     var qte = SceneManager._scene._QTEWindow;
  1142.     qte._sound = bool
  1143. }
  1144.  
  1145. Game_Map.prototype.setOcarina = function(bool,bool2) {
  1146.     var qte = SceneManager._scene._QTEWindow;
  1147.     qte._ocarina = [bool,bool2];
  1148.     if (bool2) {
  1149.         qte.height = 8 * 36;
  1150.     }
  1151. }
  1152.  
  1153. //GameMap call to match qte input to skill sequence meta
  1154. Game_Map.prototype.getSkillMatch = function(actorId,seq) {
  1155.     var actor = $gameActors.actor(actorId);
  1156.     var sequence = seq || $gameMap.getQTEResult();
  1157.     var skills = actor.skills()
  1158.     var qteSkills = [[]];
  1159.     var meta;
  1160.     for (var i = 0; i < skills.length; i ++) {
  1161.         if (skills[i].meta.qteSeq) {
  1162.             qteSkills[0].push(skills[i])
  1163.         }
  1164.     }
  1165.  
  1166.     for (var ii = 0; ii < sequence.length; ii++) { //for the length of the sequence
  1167.         qteSkills.push([])
  1168.         for (i = 0; i < qteSkills[ii].length; i++) {
  1169.             if (eval(qteSkills[ii][i].meta.qteSeq)[ii] === sequence[ii]) {
  1170.             qteSkills[ii+1].push(qteSkills[ii][i]);
  1171.             }
  1172.         }
  1173.     }
  1174.     var result = []
  1175.     for (i = 0; i < qteSkills[qteSkills.length-1].length; i++) {
  1176.         if (eval(qteSkills[qteSkills.length-1][i].meta.qteSeq).length === sequence.length) {
  1177.         result.push(qteSkills[qteSkills.length-1][i])
  1178.         }
  1179.     }
  1180.     if (result[0]) {
  1181.         return result[0].id
  1182.     } else {
  1183.         if (SceneManager._scene instanceof Scene_Battle) {
  1184.             SceneManager._scene._logWindow.displayNoMatch()
  1185.         }
  1186.         return "no match found"
  1187.     }
  1188.  
  1189. }
  1190.  
  1191. Game_Map.prototype.getSkillNameFromMatch = function(id) {
  1192.     if (id !== "no match found") {
  1193.         return $dataSkills[id].name
  1194.     } else {
  1195.         return " "
  1196.     }
  1197. }
  1198.  
  1199. Game_Map.prototype.castSkillMatch = function(user,target,id) {
  1200.     var targetIndex
  1201.     if (target instanceof Game_Actor) {
  1202.         targetIndex = $gameParty.battleMembers().indexOf(target)
  1203.     } else if (target instanceof Game_Enemy) {
  1204.         targetIndex = $gameTroop.members().indexOf(target)
  1205.     }
  1206.     var match = $gameMap.getSkillMatch(user._actorId)
  1207.     if (match !== "no match found") {
  1208.         user.forceAction(match, targetIndex);
  1209.     } else if (id !== 0) {
  1210.         user.forceAction(id, targetIndex);
  1211.     }
  1212. }
  1213.  
  1214. Game_Map.prototype.castSandSM = function(user,target,actionAr,actionId) { //This command Requires YEP Battle Engine Core
  1215.     var seq = $gameMap.getQTEResult();
  1216.     $gameMap.castSequence(user,target,actionAr);
  1217.     SceneManager._scene._QTEWindow._result = seq
  1218.     var targetIndex
  1219.     if (target instanceof Game_Actor) {
  1220.         targetIndex = $gameParty.battleMembers().indexOf(target)
  1221.     } else if (target instanceof Game_Enemy) {
  1222.         targetIndex = $gameTroop.members().indexOf(target)
  1223.     }
  1224.     var match = $gameMap.getSkillMatch(user._actorId)
  1225.     if (match !== "no match found") {
  1226.         BattleManager.queueForceAction(user, match, target);
  1227.     } else if (actionId !== 0) {
  1228.         BattleManager.queueForceAction(user, actionId, target);
  1229.     }
  1230. }
  1231.  
  1232. Game_Map.prototype.trySequence = function(user,target,minInputs,maxInputs) { //This command Requires YEP Battle Engine Core
  1233.     var seq = $gameMap.getQTEResult();
  1234.     var maxIndex = seq.length - 1;
  1235.     minInputs = minInputs || 1;
  1236.     maxInputs = maxInputs || seq.length;
  1237.     var start = minInputs;
  1238.     var length = seq.length
  1239.     var start = minInputs;
  1240.     var matches = [];
  1241.     var match = 0
  1242.     for (start; start <= maxInputs; start ++) {
  1243.         for (var i = 0; i < length; i++) {
  1244.             var curSeq = [];
  1245.             for (var ii = 0; ii < start; ii++) {
  1246.                 if (ii + i <= maxIndex) {
  1247.                     curSeq.push(seq[ii + i]);
  1248.                 } else {
  1249.                     break;
  1250.                 }
  1251.             }
  1252.             if (curSeq.length === start) {
  1253.                 matches.push(curSeq);
  1254.             }
  1255.         }
  1256.     }
  1257.     for (i = 0; i < matches.length; i++) {
  1258.         match = $gameMap.getSkillMatch(user._actorId,matches[i])
  1259.         if (match !== "no match found") {
  1260.             BattleManager.queueForceAction(user, match, target);
  1261.         }
  1262.     }
  1263. }
  1264.  
  1265. //Game Map call to make a random sequence
  1266. Game_Map.prototype.randomSequence = function(length) {
  1267.     var inputs = ["up","down","left","right","ok","cancel"]
  1268.     for (var i = 1; i < arguments.length; i++) {
  1269.         for (var ii = 0; ii < inputs.length; ii++) {
  1270.             if (inputs[ii] === arguments[i]) {
  1271.                 inputs.splice(ii,1)
  1272.             }
  1273.         }
  1274.     }
  1275.     var seq = []
  1276.     for (i = 0; i < length; i++) {
  1277.         var rand = Math.floor(Math.random()*(inputs.length));
  1278.         seq.push(inputs[rand]);
  1279.     }
  1280.     return seq
  1281. }
  1282.  
  1283.  
  1284. //Game Map call to cast a sequence by input
  1285. Game_Map.prototype.castSequence = function(user,target,actionAr) { //This command Requires YEP Battle Engine Core
  1286.     var v = function(id) {
  1287.         return $gameVariables.value(id);
  1288.     }
  1289.     var actionUp = eval(actionAr[0]);
  1290.     var actionDw = eval(actionAr[1]);
  1291.     var actionLe = eval(actionAr[2]);
  1292.     var actionRi = eval(actionAr[3]);
  1293.     var actionOk = eval(actionAr[4]);
  1294.     var actionCa = eval(actionAr[5]);
  1295.     var seq = $gameMap.getQTEResult();
  1296.     var actionId = 0;
  1297.     var targetIndex = 0;
  1298.     var actions = [];
  1299.     for (var i = 0; i < seq.length; i ++) {
  1300.         if (seq[i] === "up") {
  1301.             actionId = actionUp
  1302.         } else if (seq[i] === "down") {
  1303.             actionId = actionDw;
  1304.         } else if (seq[i] === "left") {
  1305.             actionId = actionLe
  1306.         } else if (seq[i] === "right") {
  1307.             actionId = actionRi
  1308.         } else if (seq[i] === "ok") {
  1309.             actionId = actionOk
  1310.         } else if (seq[i] === "cancel") {
  1311.             actionId = actionCa
  1312.         }
  1313.         if (target instanceof Game_Actor) {
  1314.             targetIndex = $gameParty.battleMembers().indexOf(target)
  1315.         } else if (target instanceof Game_Enemy) {
  1316.             targetIndex = $gameTroop.members().indexOf(target)
  1317.         }
  1318.         BattleManager.queueForceAction(user, actionId, target); //this doesn't exist outside the battle core
  1319.     }
  1320. }
  1321.  
  1322. //Game Interpreter Modifications to wait for the QTE to finish
  1323. var _Astfgl_newGIUWM = Game_Interpreter.prototype.updateWaitMode
  1324. Game_Interpreter.prototype.updateWaitMode = function() {
  1325.     return _Astfgl_newGIUWM.call(this) || (SceneManager._scene._QTEWindow.getResult() === "start")
  1326.     //start = qte window running, we don't want game interpreter to progress until qte is finished
  1327. }
  1328.  
  1329. //Battle Log window modification to show no match found and wrong Input.
  1330. Window_BattleLog.prototype.displayQTEFailure = function(target) {
  1331.     if (eval(PluginManager.parameters("QTEWindow").DisplayFailText)) {
  1332.         var failText = PluginManager.parameters("QTEWindow").FailText
  1333.         this.push('addText', failText);
  1334.     }
  1335. }
  1336.  
  1337. Window_BattleLog.prototype.displayNoMatch = function(target) {
  1338.     if (eval(PluginManager.parameters("QTEWindow").DisplayNoMatchText)) {
  1339.         var failText = PluginManager.parameters("QTEWindow").NoMatchText
  1340.         this.push('addText', failText);
  1341.     }
  1342. }
  1343.  
  1344. //End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement