/// <summary> /// i.e. won't detect negative edge or holds /// </summary> /// <param name="inputHistory"></param> /// <param name="motionInput"></param> /// <returns></returns> public static bool InterpretNormalAttackInput(InputHistory inputHistory, AttackMotionInput motionInput) { InputHistoryEntry entry = inputHistory.GetEntry(0); IList <ButtonStatus> buttons = entry.buttons; ButtonStatus[] reference = motionInput.buttons; for (int i = 0; i < buttons.Count; i++) { ButtonStatus currStatus = buttons[i]; if (reference[i] == ButtonStatus.Down && currStatus == ButtonStatus.Down) { // Down match } else if (reference[i] == ButtonStatus.Up) { // Up ignored } else { // mismatch! // TODO: might lead to strange behavior currently. i.e. 632AB might not give nothing instead of A DP return(false); } } return(InterpretMotionInput(inputHistory, motionInput)); }
/** * Warning, not called every frame * Only called when new input is detected from scanner */ public void ParseNewInput(InputHistory inputHistory) { bool matched = false; matched = InterpretAttack(inputHistory); if (!matched) { matched = InterpretMovement(inputHistory); } }
/// <summary> /// Attack input priority is determined here too! /// </summary> /// <param name="inputHistory"></param> /// <returns>true if interpreted to something</returns> private bool InterpretAttack(InputHistory inputHistory) { // // invul moves // // button combos // if (InterpretUtil.InterpretTapButtonCombo(inputHistory, RC)) { // DebugMessage(RC.ToString()); // inputActions.RC(RC.frameLimit); // return true; // } // if (InterpretUtil.InterpretTapButtonCombo(inputHistory, ForwardThrow)) { // DebugMessage(ForwardThrow.ToString()); // inputActions.InputBufferCancel(ForwardThrow.frameLimit); // inputActions.Throw(true); // return true; // } // if (InterpretUtil.InterpretTapButtonCombo(inputHistory, BackwardThrow)) { // DebugMessage(BackwardThrow.ToString()); // inputActions.InputBufferCancel(BackwardThrow.frameLimit); // inputActions.Throw(false); // return true; // } // // specials // if (InterpretUtil.InterpretSpecialAttackInput (inputHistory, S236B)) { // DebugMessage(S236B.ToString()); // inputActions.S236 (Button.B); // return true; // } // command normals // normals // if (InterpretUtil.InterpretNormalAttackInput(inputHistory, N5A)) { // DebugMessage(N5A.ToString()); // inputActions.N5(Button.A); // return true; // } // if (InterpretUtil.InterpretNormalAttackInput(inputHistory, N5B)) { // DebugMessage(N5B.ToString()); // inputActions.N5(Button.B); // return true; // } // if (InterpretUtil.InterpretNormalAttackInput(inputHistory, N5C)) { // DebugMessage(N5C.ToString()); // inputActions.N5(Button.C); // return true; // } return(false); }
private bool InterpretMovement(InputHistory inputHistory) { // inputActions.StopWalk(); // if (InterpretUtil.InterpretMotionInput(inputHistory, M66)) // { // DebugMessage(M66.ToString()); // inputActions.Dash(); // return true; // } else { // inputActions.StopRun(); // } // if (InterpretUtil.InterpretMotionInput(inputHistory, M44)) // { // DebugMessage(M44.ToString()); // inputActions.BackDash(); // return true; // } // if (InterpretUtil.InterpretMotionInput(inputHistory, MJump)) // { // DebugMessage(MJump.ToString()); // inputActions.Jump(inputHistory.GetEntry(0).direction); // return true; // } else { // inputActions.ReleaseJump(); // } inputActions.Walk(Numpad.N5); if (InterpretUtil.InterpretMotionInput(inputHistory, M6)) { DebugMessage(M6.ToString()); inputActions.Walk(Numpad.N6); return(true); } if (InterpretUtil.InterpretMotionInput(inputHistory, M4)) { DebugMessage(M4.ToString()); inputActions.Walk(Numpad.N4); return(true); } return(false); }
public BattleInputScanner() { runningFrames = 0; // Frame 1 will be first update frame // parser = new BattleInputParser(); // ChangeDirectionEventSource = GetComponent<IStateManager>(); // ChangeDirectionEventSource.ChangeDirectionEvent += ChangeDirectionEventHandler; nextDirection = Numpad.N5; nextButtons = new List <ButtonStatus> (); for (int j = 0; j < ButtonCount; j++) { nextButtons.Add(ButtonStatus.Up); } newInputs = false; // initialize input history inputHistory = new InputHistory(InputHistorySize, ButtonCount); }
/// <summary> /// i.e. won't detect negative edge /// Great for detecting FD, not so great for detecting throw /// </summary> /// <param name="inputHistory"></param> /// <param name="motionInput"></param> /// <returns></returns> public static bool InterpretHoldButtonCombo(InputHistory inputHistory, AttackMotionInput motionInput) { int index = 0; int totalFrames = 0; InputHistoryEntry entry = null; IList <ButtonStatus> buttons = null; ButtonStatus[] reference = motionInput.buttons; bool noMatchesFound = true; // has the input history matched a button combo yet? while (noMatchesFound) { if (index >= inputHistory.GetSize()) { return(false); } entry = inputHistory.GetEntry(index); buttons = entry.buttons; bool noMismatch = true; for (int i = 0; i < buttons.Count; i++) { ButtonStatus currStatus = buttons[i]; if (reference[i] == ButtonStatus.Down && (currStatus == ButtonStatus.Down || currStatus == ButtonStatus.Hold)) { // held[i] = true; } else if (reference[i] == ButtonStatus.Up) { // Up ignored } else { // mismatch! // TODO: might lead to strange behavior currently. i.e. 632AB might not give nothing instead of A DP noMismatch = false; } } if (index > 0) { // i.e. first input has running frames since last input. // Only factor in if motion input is longer than 1 input (ie. 46A) totalFrames += inputHistory.GetEntry(index - 1).runningFrames; if (totalFrames > motionInput.frameLimit) { return(false); } } if (noMismatch) { return(InterpretMotionInput(inputHistory, motionInput)); } index++; } return(false); }
/// <summary> /// i.e. won't detect negative edge /// Great for detecting FD, not so great for detecting throw /// </summary> /// <param name="inputHistory"></param> /// <param name="motionInput"></param> /// <returns></returns> public static bool InterpretTapButtonCombo(InputHistory inputHistory, AttackMotionInput motionInput) { int index = 0; int totalFrames = 0; InputHistoryEntry entry = null; IList <ButtonStatus> buttons = null; ButtonStatus[] reference = motionInput.buttons; int[] frameLimits = new int[reference.Length]; bool noMatchesFound = true; // has the input history matched a button combo yet? while (noMatchesFound) { if (index >= inputHistory.GetSize()) { return(false); } entry = inputHistory.GetEntry(index); buttons = entry.buttons; for (int i = 0; i < buttons.Count; i++) { ButtonStatus currStatus = buttons[i]; if (reference[i] == ButtonStatus.Down) { if (currStatus == ButtonStatus.Down) { frameLimits[i] = motionInput.frameLimit + 1; } else { // ignore everything else } } else { // reference up doesn't affect button combo frameLimits[i] = 100; // indicate safe state } } if (index > 0) { // i.e. first input has running frames since last input. // Only factor in if motion input is longer than 1 input (ie. 46A) totalFrames += inputHistory.GetEntry(index - 1).runningFrames; if (totalFrames > motionInput.frameLimit) { return(false); } } bool buttonComboDetected = true; for (int i = 0; i < frameLimits.Length; i++) { if (frameLimits[i] <= 0) { buttonComboDetected = false; } frameLimits[i] = frameLimits[i] - 1; } if (buttonComboDetected) { return(InterpretMotionInput(inputHistory, motionInput)); } index++; } return(false); }
/// <summary> /// Return true if input history matches the numpad inputs given /// /// TODO: Make sure this function isn't too slow /// </summary> /// <param name="inputHistory">The player's most recent inputs</param> /// <param name="motionInput">All possible forms of the given motion input</param> /// <returns>true if the player inputs match this motion input</returns> public static bool InterpretMotionInput(InputHistory inputHistory, MotionInput motionInput) { int historyIndex = -1; // which index in the input history to look at? Numpad prevInput = Numpad.N0; // most recently interpreted numpad direction int curIndex = 0; // which index in the motion inputs to look at? int totalFrames = 0; // total frames the input took to input bool noMatchesFound = false; // has the input history matched a motion input yet? // assume watching all at first bool[] notWatching = new bool[motionInput.motionInputs.Count]; while (!noMatchesFound) { // find next input in inputHistory to consider historyIndex++; if (historyIndex >= inputHistory.GetSize()) { return(false); } InputHistoryEntry currEntry = inputHistory.GetEntry(historyIndex); // add to total frames if (currEntry.direction != prevInput) { // new numpad input to investigate! // update prev input for next iteration prevInput = currEntry.direction; for (int i = 0; i < notWatching.Length; i++) { if (notWatching[i] == false) { // still watching this motion input list IList <Numpad> curMotionInput = motionInput.motionInputs[i]; if (curIndex == curMotionInput.Count - 1 && curMotionInput[curIndex] == currEntry.direction) { // curMotionInput was on watch list and is not exhausted // means a match was detected! if (totalFrames <= motionInput.frameLimit) { // TODO: You can put this check earlier probably! return(true); } notWatching[i] = true; } else if (curMotionInput[curIndex] != currEntry.direction) { // motion input did not match up, don't watch it anymore notWatching[i] = true; } } } // looking for next index on next new direction found curIndex++; } // are we watching any other motion inputs? noMatchesFound = true; foreach (bool notWatch in notWatching) { noMatchesFound = noMatchesFound && notWatch; } if (historyIndex > 0) { // i.e. first input has running frames since last input. // Only factor in if motion input is longer than 1 input (ie. 46A) totalFrames += inputHistory.GetEntry(historyIndex - 1).runningFrames; } } return(false); }