mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-10 01:33:54 +01:00
IPVGO: Fix non-async promise-returning methods to be more consistent (#1327)
This commit is contained in:
parent
7321d64383
commit
5f6a5c8785
@ -11,7 +11,7 @@ import {
|
|||||||
getPreviousMove,
|
getPreviousMove,
|
||||||
simpleBoardFromBoard,
|
simpleBoardFromBoard,
|
||||||
} from "../boardAnalysis/boardAnalysis";
|
} from "../boardAnalysis/boardAnalysis";
|
||||||
import { getOpponentStats, getScore, resetWinstreak } from "../boardAnalysis/scoring";
|
import { endGoGame, getOpponentStats, getScore, resetWinstreak } from "../boardAnalysis/scoring";
|
||||||
import { WHRNG } from "../../Casino/RNG";
|
import { WHRNG } from "../../Casino/RNG";
|
||||||
import { getRecordKeys } from "../../Types/Record";
|
import { getRecordKeys } from "../../Types/Record";
|
||||||
import { CalculateEffect, getEffectTypeForFaction } from "./effect";
|
import { CalculateEffect, getEffectTypeForFaction } from "./effect";
|
||||||
@ -337,30 +337,27 @@ export async function determineCheatSuccess(
|
|||||||
): Promise<Play> {
|
): Promise<Play> {
|
||||||
const state = Go.currentGame;
|
const state = Go.currentGame;
|
||||||
const rng = new WHRNG(Player.totalPlaytime);
|
const rng = new WHRNG(Player.totalPlaytime);
|
||||||
|
state.passCount = 0;
|
||||||
|
|
||||||
// If cheat is successful, run callback
|
// If cheat is successful, run callback
|
||||||
if ((successRngOverride ?? rng.random()) <= cheatSuccessChance(state.cheatCount)) {
|
if ((successRngOverride ?? rng.random()) <= cheatSuccessChance(state.cheatCount)) {
|
||||||
callback();
|
callback();
|
||||||
state.cheatCount++;
|
|
||||||
GoEvents.emit();
|
GoEvents.emit();
|
||||||
return makeAIMove(state);
|
|
||||||
}
|
}
|
||||||
// If there have been prior cheat attempts, and the cheat fails, there is a 10% chance of instantly losing
|
// 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) {
|
else if (state.cheatCount && (ejectRngOverride ?? rng.random()) < 0.1) {
|
||||||
logger(`Cheat failed! You have been ejected from the subnet.`);
|
logger(`Cheat failed! You have been ejected from the subnet.`);
|
||||||
resetBoardState(logger, logger, state.ai, state.board[0].length);
|
endGoGame(state);
|
||||||
return {
|
return Go.nextTurn;
|
||||||
type: GoPlayType.gameOver,
|
|
||||||
x: null,
|
|
||||||
y: null,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
// If the cheat fails, your turn is skipped
|
// If the cheat fails, your turn is skipped
|
||||||
else {
|
else {
|
||||||
logger(`Cheat failed. Your turn has been skipped.`);
|
logger(`Cheat failed. Your turn has been skipped.`);
|
||||||
passTurn(state, GoColor.black, false);
|
passTurn(state, GoColor.black, false);
|
||||||
state.cheatCount++;
|
|
||||||
return makeAIMove(state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
state.cheatCount++;
|
||||||
|
return makeAIMove(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -395,7 +392,7 @@ export function cheatRemoveRouter(
|
|||||||
y: number,
|
y: number,
|
||||||
successRngOverride?: number,
|
successRngOverride?: number,
|
||||||
ejectRngOverride?: number,
|
ejectRngOverride?: number,
|
||||||
) {
|
): Promise<Play> {
|
||||||
const point = Go.currentGame.board[x][y]!;
|
const point = Go.currentGame.board[x][y]!;
|
||||||
return determineCheatSuccess(
|
return determineCheatSuccess(
|
||||||
logger,
|
logger,
|
||||||
@ -421,7 +418,7 @@ export function cheatPlayTwoMoves(
|
|||||||
y2: number,
|
y2: number,
|
||||||
successRngOverride?: number,
|
successRngOverride?: number,
|
||||||
ejectRngOverride?: number,
|
ejectRngOverride?: number,
|
||||||
) {
|
): Promise<Play> {
|
||||||
const point1 = Go.currentGame.board[x1][y1]!;
|
const point1 = Go.currentGame.board[x1][y1]!;
|
||||||
const point2 = Go.currentGame.board[x2][y2]!;
|
const point2 = Go.currentGame.board[x2][y2]!;
|
||||||
|
|
||||||
@ -446,7 +443,7 @@ export function cheatRepairOfflineNode(
|
|||||||
y: number,
|
y: number,
|
||||||
successRngOverride?: number,
|
successRngOverride?: number,
|
||||||
ejectRngOverride?: number,
|
ejectRngOverride?: number,
|
||||||
) {
|
): Promise<Play> {
|
||||||
return determineCheatSuccess(
|
return determineCheatSuccess(
|
||||||
logger,
|
logger,
|
||||||
() => {
|
() => {
|
||||||
@ -472,7 +469,7 @@ export function cheatDestroyNode(
|
|||||||
y: number,
|
y: number,
|
||||||
successRngOverride?: number,
|
successRngOverride?: number,
|
||||||
ejectRngOverride?: number,
|
ejectRngOverride?: number,
|
||||||
) {
|
): Promise<Play> {
|
||||||
return determineCheatSuccess(
|
return determineCheatSuccess(
|
||||||
logger,
|
logger,
|
||||||
() => {
|
() => {
|
||||||
|
@ -47,11 +47,11 @@ export function NetscriptGo(): InternalAPI<NSGo> {
|
|||||||
validateMove(error(ctx), x, y, "makeMove");
|
validateMove(error(ctx), x, y, "makeMove");
|
||||||
return makePlayerMove(logger(ctx), error(ctx), x, y);
|
return makePlayerMove(logger(ctx), error(ctx), x, y);
|
||||||
},
|
},
|
||||||
passTurn: (ctx: NetscriptContext) => (): Promise<Play> => {
|
passTurn: (ctx: NetscriptContext) => async (): Promise<Play> => {
|
||||||
validateTurn(error(ctx), "passTurn()");
|
validateTurn(error(ctx), "passTurn()");
|
||||||
return handlePassTurn(logger(ctx));
|
return handlePassTurn(logger(ctx));
|
||||||
},
|
},
|
||||||
opponentNextTurn: (ctx: NetscriptContext) => (_logOpponentMove) => {
|
opponentNextTurn: (ctx: NetscriptContext) => async (_logOpponentMove) => {
|
||||||
const logOpponentMove = typeof _logOpponentMove === "boolean" ? _logOpponentMove : true;
|
const logOpponentMove = typeof _logOpponentMove === "boolean" ? _logOpponentMove : true;
|
||||||
return getOpponentNextMove(logOpponentMove, logger(ctx));
|
return getOpponentNextMove(logOpponentMove, logger(ctx));
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user