UNPKG

slp-enforcer

Version:

Finds violations of the Melee Controller Ruleset by inspecting SLP files

255 lines (254 loc) 12.8 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const get_1 = __importDefault(require("lodash/get")); const isEqual_1 = __importDefault(require("lodash/isEqual")); const keyBy_1 = __importDefault(require("lodash/keyBy")); const last_1 = __importDefault(require("lodash/last")); const set_1 = __importDefault(require("lodash/set")); const size_1 = __importDefault(require("lodash/size")); const common_1 = require("./common"); // Frame pattern that indicates a dash dance turn was executed const dashDanceAnimations = [common_1.State.DASH, common_1.State.TURN, common_1.State.DASH]; class ActionsComputer { constructor() { this.playerPermutations = new Array(); this.state = new Map(); } setup(settings) { this.state = new Map(); this.playerPermutations = common_1.getSinglesPlayerPermutationsFromSettings(settings); this.playerPermutations.forEach((indices) => { const playerCounts = { playerIndex: indices.playerIndex, wavedashCount: 0, wavelandCount: 0, airDodgeCount: 0, dashDanceCount: 0, spotDodgeCount: 0, ledgegrabCount: 0, rollCount: 0, lCancelCount: { success: 0, fail: 0, }, attackCount: { jab1: 0, jab2: 0, jab3: 0, jabm: 0, dash: 0, ftilt: 0, utilt: 0, dtilt: 0, fsmash: 0, usmash: 0, dsmash: 0, nair: 0, fair: 0, bair: 0, uair: 0, dair: 0, }, grabCount: { success: 0, fail: 0, }, throwCount: { up: 0, forward: 0, back: 0, down: 0, }, groundTechCount: { // tech away/in are in reference to the opponents position and not the stage away: 0, in: 0, neutral: 0, fail: 0, }, wallTechCount: { success: 0, fail: 0, }, }; const playerState = { playerCounts: playerCounts, animations: [], actionFrameCounters: [], }; this.state.set(indices, playerState); }); } processFrame(frame) { this.playerPermutations.forEach((indices) => { const state = this.state.get(indices); if (state) { handleActionCompute(state, indices, frame); } }); } fetch() { return Array.from(this.state.values()).map((val) => val.playerCounts); } } exports.ActionsComputer = ActionsComputer; function isMissGroundTech(animation) { return animation === common_1.State.TECH_MISS_DOWN || animation === common_1.State.TECH_MISS_UP; } function isRolling(animation) { return animation === common_1.State.ROLL_BACKWARD || animation === common_1.State.ROLL_FORWARD; } function isGrabAction(animation) { // Includes Grab pull, wait, pummel, and throws return animation > common_1.State.GRAB && animation <= common_1.State.THROW_DOWN && animation !== common_1.State.DASH_GRAB; } function isGrabbing(animation) { return animation === common_1.State.GRAB || animation === common_1.State.DASH_GRAB; } function isAerialAttack(animation) { return animation >= common_1.State.AERIAL_ATTACK_START && animation <= common_1.State.AERIAL_ATTACK_END; } function isForwardTilt(animation) { return animation >= common_1.State.ATTACK_FTILT_START && animation <= common_1.State.ATTACK_FTILT_END; } function isForwardSmash(animation) { return animation >= common_1.State.ATTACK_FSMASH_START && animation <= common_1.State.ATTACK_FSMASH_END; } function handleActionCompute(state, indices, frame) { const playerFrame = frame.players[indices.playerIndex].post; const opponentFrame = frame.players[indices.opponentIndex].post; const incrementCount = (field, condition) => { if (!condition) { return; } const current = get_1.default(state.playerCounts, field, 0); set_1.default(state.playerCounts, field, current + 1); }; // Manage animation state const currentAnimation = playerFrame.actionStateId; state.animations.push(currentAnimation); const currentFrameCounter = playerFrame.actionStateCounter; state.actionFrameCounters.push(currentFrameCounter); // Grab last 3 frames const last3Frames = state.animations.slice(-3); const prevAnimation = last3Frames[last3Frames.length - 2]; const prevFrameCounter = state.actionFrameCounters[state.actionFrameCounters.length - 2]; // New action if new animation or frame counter goes back down (repeated action) const isNewAction = currentAnimation !== prevAnimation || prevFrameCounter > currentFrameCounter; if (!isNewAction) { return; } // Increment counts based on conditions const didDashDance = isEqual_1.default(last3Frames, dashDanceAnimations); incrementCount("dashDanceCount", didDashDance); incrementCount("rollCount", isRolling(currentAnimation)); incrementCount("spotDodgeCount", currentAnimation === common_1.State.SPOT_DODGE); incrementCount("airDodgeCount", currentAnimation === common_1.State.AIR_DODGE); incrementCount("ledgegrabCount", currentAnimation === common_1.State.CLIFF_CATCH); // Grabs incrementCount("grabCount.success", isGrabbing(prevAnimation) && isGrabAction(currentAnimation)); incrementCount("grabCount.fail", isGrabbing(prevAnimation) && !isGrabAction(currentAnimation)); if (currentAnimation === common_1.State.DASH_GRAB && prevAnimation === common_1.State.ATTACK_DASH) { state.playerCounts.attackCount.dash -= 1; // subtract from dash attack if boost grab } // Basic attacks incrementCount("attackCount.jab1", currentAnimation === common_1.State.ATTACK_JAB1); incrementCount("attackCount.jab2", currentAnimation === common_1.State.ATTACK_JAB2); incrementCount("attackCount.jab3", currentAnimation === common_1.State.ATTACK_JAB3); incrementCount("attackCount.jabm", currentAnimation === common_1.State.ATTACK_JABM); incrementCount("attackCount.dash", currentAnimation === common_1.State.ATTACK_DASH); incrementCount("attackCount.ftilt", isForwardTilt(currentAnimation)); incrementCount("attackCount.utilt", currentAnimation === common_1.State.ATTACK_UTILT); incrementCount("attackCount.dtilt", currentAnimation === common_1.State.ATTACK_DTILT); incrementCount("attackCount.fsmash", isForwardSmash(currentAnimation)); incrementCount("attackCount.usmash", currentAnimation === common_1.State.ATTACK_USMASH); incrementCount("attackCount.dsmash", currentAnimation === common_1.State.ATTACK_DSMASH); incrementCount("attackCount.nair", currentAnimation === common_1.State.AERIAL_NAIR); incrementCount("attackCount.fair", currentAnimation === common_1.State.AERIAL_FAIR); incrementCount("attackCount.bair", currentAnimation === common_1.State.AERIAL_BAIR); incrementCount("attackCount.uair", currentAnimation === common_1.State.AERIAL_UAIR); incrementCount("attackCount.dair", currentAnimation === common_1.State.AERIAL_DAIR); // GnW is weird and has unique IDs for some moves if (playerFrame.internalCharacterId === 0x18) { incrementCount("attackCount.jab1", currentAnimation === common_1.State.GNW_JAB1); incrementCount("attackCount.jabm", currentAnimation === common_1.State.GNW_JABM); incrementCount("attackCount.dtilt", currentAnimation === common_1.State.GNW_DTILT); incrementCount("attackCount.fsmash", currentAnimation === common_1.State.GNW_FSMASH); incrementCount("attackCount.nair", currentAnimation === common_1.State.GNW_NAIR); incrementCount("attackCount.bair", currentAnimation === common_1.State.GNW_BAIR); incrementCount("attackCount.uair", currentAnimation === common_1.State.GNW_UAIR); } // Peach is also weird and has a unique ID for her fsmash // FSMASH1 = Golf Club, FSMASH2 = Frying Pan, FSMASH3 = Tennis Racket if (playerFrame.internalCharacterId === 0x09) { incrementCount("attackCount.fsmash", currentAnimation === common_1.State.PEACH_FSMASH1); incrementCount("attackCount.fsmash", currentAnimation === common_1.State.PEACH_FSMASH2); incrementCount("attackCount.fsmash", currentAnimation === common_1.State.PEACH_FSMASH3); } // Throws incrementCount("throwCount.up", currentAnimation === common_1.State.THROW_UP); incrementCount("throwCount.forward", currentAnimation === common_1.State.THROW_FORWARD); incrementCount("throwCount.down", currentAnimation === common_1.State.THROW_DOWN); incrementCount("throwCount.back", currentAnimation === common_1.State.THROW_BACK); // Techs const opponentDir = playerFrame.positionX > opponentFrame.positionX ? -1 : 1; const facingOpponent = playerFrame.facingDirection === opponentDir; incrementCount("groundTechCount.fail", isMissGroundTech(currentAnimation)); incrementCount("groundTechCount.in", currentAnimation === common_1.State.FORWARD_TECH && facingOpponent); incrementCount("groundTechCount.in", currentAnimation === common_1.State.BACKWARD_TECH && !facingOpponent); incrementCount("groundTechCount.neutral", currentAnimation === common_1.State.NEUTRAL_TECH); incrementCount("groundTechCount.away", currentAnimation === common_1.State.BACKWARD_TECH && facingOpponent); incrementCount("groundTechCount.away", currentAnimation === common_1.State.FORWARD_TECH && !facingOpponent); incrementCount("wallTechCount.success", currentAnimation === common_1.State.WALL_TECH); incrementCount("wallTechCount.fail", currentAnimation === common_1.State.MISSED_WALL_TECH); if (isAerialAttack(currentAnimation)) { incrementCount("lCancelCount.success", playerFrame.lCancelStatus === 1); incrementCount("lCancelCount.fail", playerFrame.lCancelStatus === 2); } // Handles wavedash detection (and waveland) handleActionWavedash(state.playerCounts, state.animations); } function handleActionWavedash(counts, animations) { const currentAnimation = last_1.default(animations); const prevAnimation = animations[animations.length - 2]; const isSpecialLanding = currentAnimation === common_1.State.LANDING_FALL_SPECIAL; const isAcceptablePrevious = isWavedashInitiationAnimation(prevAnimation); const isPossibleWavedash = isSpecialLanding && isAcceptablePrevious; if (!isPossibleWavedash) { return; } // Here we special landed, it might be a wavedash, let's check // We grab the last 8 frames here because that should be enough time to execute a // wavedash. This number could be tweaked if we find false negatives const recentFrames = animations.slice(-8); const recentAnimations = keyBy_1.default(recentFrames, (animation) => animation); if (size_1.default(recentAnimations) === 2 && recentAnimations[common_1.State.AIR_DODGE]) { // If the only other animation is air dodge, this might be really late to the point // where it was actually an air dodge. Air dodge animation is really long return; } if (recentAnimations[common_1.State.AIR_DODGE]) { // If one of the recent animations was an air dodge, let's remove that from the // air dodge counter, we don't want to count air dodges used to wavedash/land counts.airDodgeCount -= 1; } if (recentAnimations[common_1.State.ACTION_KNEE_BEND]) { // If a jump was started recently, we will consider this a wavedash counts.wavedashCount += 1; } else { // If there was no jump recently, this is a waveland counts.wavelandCount += 1; } } function isWavedashInitiationAnimation(animation) { if (animation === common_1.State.AIR_DODGE) { return true; } const isAboveMin = animation >= common_1.State.CONTROLLED_JUMP_START; const isBelowMax = animation <= common_1.State.CONTROLLED_JUMP_END; return isAboveMin && isBelowMax; }