diff --git a/src/Go/effects/netscriptGoImplementation.ts b/src/Go/effects/netscriptGoImplementation.ts index f11953824..f4bf6503d 100644 --- a/src/Go/effects/netscriptGoImplementation.ts +++ b/src/Go/effects/netscriptGoImplementation.ts @@ -11,7 +11,7 @@ import { getPreviousMove, simpleBoardFromBoard, } from "../boardAnalysis/boardAnalysis"; -import { getOpponentStats, getScore, resetWinstreak } from "../boardAnalysis/scoring"; +import { endGoGame, getOpponentStats, getScore, resetWinstreak } from "../boardAnalysis/scoring"; import { WHRNG } from "../../Casino/RNG"; import { getRecordKeys } from "../../Types/Record"; import { CalculateEffect, getEffectTypeForFaction } from "./effect"; @@ -337,30 +337,27 @@ export async function determineCheatSuccess( ): Promise { const state = Go.currentGame; const rng = new WHRNG(Player.totalPlaytime); + state.passCount = 0; + // If cheat is successful, run callback if ((successRngOverride ?? rng.random()) <= cheatSuccessChance(state.cheatCount)) { callback(); - state.cheatCount++; GoEvents.emit(); - return makeAIMove(state); } // If there have been prior cheat attempts, and the cheat fails, there is a 10% chance of instantly losing else if (state.cheatCount && (ejectRngOverride ?? rng.random()) < 0.1) { logger(`Cheat failed! You have been ejected from the subnet.`); - resetBoardState(logger, logger, state.ai, state.board[0].length); - return { - type: GoPlayType.gameOver, - x: null, - y: null, - }; + endGoGame(state); + return Go.nextTurn; } // If the cheat fails, your turn is skipped else { logger(`Cheat failed. Your turn has been skipped.`); passTurn(state, GoColor.black, false); - state.cheatCount++; - return makeAIMove(state); } + + state.cheatCount++; + return makeAIMove(state); } /** @@ -395,7 +392,7 @@ export function cheatRemoveRouter( y: number, successRngOverride?: number, ejectRngOverride?: number, -) { +): Promise { const point = Go.currentGame.board[x][y]!; return determineCheatSuccess( logger, @@ -421,7 +418,7 @@ export function cheatPlayTwoMoves( y2: number, successRngOverride?: number, ejectRngOverride?: number, -) { +): Promise { const point1 = Go.currentGame.board[x1][y1]!; const point2 = Go.currentGame.board[x2][y2]!; @@ -446,7 +443,7 @@ export function cheatRepairOfflineNode( y: number, successRngOverride?: number, ejectRngOverride?: number, -) { +): Promise { return determineCheatSuccess( logger, () => { @@ -472,7 +469,7 @@ export function cheatDestroyNode( y: number, successRngOverride?: number, ejectRngOverride?: number, -) { +): Promise { return determineCheatSuccess( logger, () => { diff --git a/src/NetscriptFunctions/Go.ts b/src/NetscriptFunctions/Go.ts index 9a76c7e17..91f379c5f 100644 --- a/src/NetscriptFunctions/Go.ts +++ b/src/NetscriptFunctions/Go.ts @@ -47,11 +47,11 @@ export function NetscriptGo(): InternalAPI { validateMove(error(ctx), x, y, "makeMove"); return makePlayerMove(logger(ctx), error(ctx), x, y); }, - passTurn: (ctx: NetscriptContext) => (): Promise => { + passTurn: (ctx: NetscriptContext) => async (): Promise => { validateTurn(error(ctx), "passTurn()"); return handlePassTurn(logger(ctx)); }, - opponentNextTurn: (ctx: NetscriptContext) => (_logOpponentMove) => { + opponentNextTurn: (ctx: NetscriptContext) => async (_logOpponentMove) => { const logOpponentMove = typeof _logOpponentMove === "boolean" ? _logOpponentMove : true; return getOpponentNextMove(logOpponentMove, logger(ctx)); },