diff --git a/src/NetscriptFunctions/CodingContract.ts b/src/NetscriptFunctions/CodingContract.ts index 11dff9eed..ef908e83a 100644 --- a/src/NetscriptFunctions/CodingContract.ts +++ b/src/NetscriptFunctions/CodingContract.ts @@ -4,14 +4,14 @@ import { IPlayer } from "../PersonObjects/IPlayer"; import { getRamCost } from "../Netscript/RamCostGenerator"; import { is2DArray } from "../utils/helpers/is2DArray"; import { CodingContract } from "../CodingContracts"; -import { CodingContract as ICodingContract } from "../ScriptEditor/NetscriptDefinitions"; +import { CodingAttemptOptions, CodingContract as ICodingContract } from "../ScriptEditor/NetscriptDefinitions"; export function NetscriptCodingContract( player: IPlayer, workerScript: WorkerScript, helper: INetscriptHelper, ): ICodingContract { - const getCodingContract = function (func: any, hostname: any, filename: any): CodingContract { + const getCodingContract = function (func: string, hostname: string, filename: string): CodingContract { const server = helper.getServer(hostname, func); const contract = server.getContract(filename); if (contract == null) { @@ -27,10 +27,12 @@ export function NetscriptCodingContract( return { attempt: function ( answer: any, - filename: any, - hostname: any = workerScript.hostname, - { returnReward }: any = {}, + _filename: unknown, + _hostname: unknown = workerScript.hostname, + { returnReward }: CodingAttemptOptions = { returnReward: false }, ): boolean | string { + const filename = helper.string("attempt", "filename", _filename); + const hostname = helper.string("attempt", "hostname", _hostname); helper.updateDynamicRam("attempt", getRamCost(player, "codingcontract", "attempt")); const contract = getCodingContract("attempt", hostname, filename); @@ -53,7 +55,10 @@ export function NetscriptCodingContract( const serv = helper.getServer(hostname, "codingcontract.attempt"); if (contract.isSolution(answer)) { const reward = player.gainCodingContractReward(creward, contract.getDifficulty()); - workerScript.log("codingcontract.attempt", () => `Successfully completed Coding Contract '${filename}'. Reward: ${reward}`); + workerScript.log( + "codingcontract.attempt", + () => `Successfully completed Coding Contract '${filename}'. Reward: ${reward}`, + ); serv.removeContract(filename); return returnReward ? reward : true; } else { @@ -68,7 +73,8 @@ export function NetscriptCodingContract( workerScript.log( "codingcontract.attempt", () => - `Coding Contract attempt '${filename}' failed. ${contract.getMaxNumTries() - contract.tries + `Coding Contract attempt '${filename}' failed. ${ + contract.getMaxNumTries() - contract.tries } attempts remaining.`, ); } @@ -76,12 +82,16 @@ export function NetscriptCodingContract( return returnReward ? "" : false; } }, - getContractType: function (filename: any, hostname: any = workerScript.hostname): string { + getContractType: function (_filename: unknown, _hostname: unknown = workerScript.hostname): string { + const filename = helper.string("getContractType", "filename", _filename); + const hostname = helper.string("getContractType", "hostname", _hostname); helper.updateDynamicRam("getContractType", getRamCost(player, "codingcontract", "getContractType")); const contract = getCodingContract("getContractType", hostname, filename); return contract.getType(); }, - getData: function (filename: any, hostname: any = workerScript.hostname): any { + getData: function (_filename: unknown, _hostname: unknown = workerScript.hostname): any { + const filename = helper.string("getContractType", "filename", _filename); + const hostname = helper.string("getContractType", "hostname", _hostname); helper.updateDynamicRam("getData", getRamCost(player, "codingcontract", "getData")); const contract = getCodingContract("getData", hostname, filename); const data = contract.getData(); @@ -101,12 +111,16 @@ export function NetscriptCodingContract( return data; } }, - getDescription: function (filename: any, hostname: any = workerScript.hostname): string { + getDescription: function (_filename: unknown, _hostname: unknown = workerScript.hostname): string { + const filename = helper.string("getDescription", "filename", _filename); + const hostname = helper.string("getDescription", "hostname", _hostname); helper.updateDynamicRam("getDescription", getRamCost(player, "codingcontract", "getDescription")); const contract = getCodingContract("getDescription", hostname, filename); return contract.getDescription(); }, - getNumTriesRemaining: function (filename: any, hostname: any = workerScript.hostname): number { + getNumTriesRemaining: function (_filename: unknown, _hostname: unknown = workerScript.hostname): number { + const filename = helper.string("getNumTriesRemaining", "filename", _filename); + const hostname = helper.string("getNumTriesRemaining", "hostname", _hostname); helper.updateDynamicRam("getNumTriesRemaining", getRamCost(player, "codingcontract", "getNumTriesRemaining")); const contract = getCodingContract("getNumTriesRemaining", hostname, filename); return contract.getMaxNumTries() - contract.tries; diff --git a/src/Server/BaseServer.ts b/src/Server/BaseServer.ts index af7a80628..faa0d3c35 100644 --- a/src/Server/BaseServer.ts +++ b/src/Server/BaseServer.ts @@ -163,7 +163,7 @@ export class BaseServer { return false; } - removeContract(contract: CodingContract): void { + removeContract(contract: CodingContract | string): void { if (contract instanceof CodingContract) { this.contracts = this.contracts.filter((c) => { return c.fn !== contract.fn;