mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-22 15:43:49 +01:00
build part pr
This commit is contained in:
parent
7b3369223d
commit
f035457efc
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -11,11 +11,14 @@ export function NetscriptCodingContract(
|
||||
workerScript: WorkerScript,
|
||||
helper: INetscriptHelper,
|
||||
): ICodingContract {
|
||||
const getCodingContract = function (func: any, ip: any, fn: any): CodingContract {
|
||||
const server = helper.getServer(ip, func);
|
||||
const contract = server.getContract(fn);
|
||||
const getCodingContract = function (func: any, hostname: any, filename: any): CodingContract {
|
||||
const server = helper.getServer(hostname, func);
|
||||
const contract = server.getContract(filename);
|
||||
if (contract == null) {
|
||||
throw helper.makeRuntimeErrorMsg(`codingcontract.${func}`, `Cannot find contract '${fn}' on server '${ip}'`);
|
||||
throw helper.makeRuntimeErrorMsg(
|
||||
`codingcontract.${func}`,
|
||||
`Cannot find contract '${filename}' on server '${hostname}'`,
|
||||
);
|
||||
}
|
||||
|
||||
return contract;
|
||||
@ -24,12 +27,12 @@ export function NetscriptCodingContract(
|
||||
return {
|
||||
attempt: function (
|
||||
answer: any,
|
||||
fn: any,
|
||||
ip: any = workerScript.hostname,
|
||||
filename: any,
|
||||
hostname: any = workerScript.hostname,
|
||||
{ returnReward }: any = {},
|
||||
): boolean | string {
|
||||
helper.updateDynamicRam("attempt", getRamCost("codingcontract", "attempt"));
|
||||
const contract = getCodingContract("attempt", ip, fn);
|
||||
const contract = getCodingContract("attempt", hostname, filename);
|
||||
|
||||
// Convert answer to string. If the answer is a 2D array, then we have to
|
||||
// manually add brackets for the inner arrays
|
||||
@ -47,35 +50,37 @@ export function NetscriptCodingContract(
|
||||
const creward = contract.reward;
|
||||
if (creward === null) throw new Error("Somehow solved a contract that didn't have a reward");
|
||||
|
||||
const serv = helper.getServer(ip, "codingcontract.attempt");
|
||||
const serv = helper.getServer(hostname, "codingcontract.attempt");
|
||||
if (contract.isSolution(answer)) {
|
||||
const reward = player.gainCodingContractReward(creward, contract.getDifficulty());
|
||||
workerScript.log("attempt", `Successfully completed Coding Contract '${fn}'. Reward: ${reward}`);
|
||||
serv.removeContract(fn);
|
||||
workerScript.log("attempt", `Successfully completed Coding Contract '${filename}'. Reward: ${reward}`);
|
||||
serv.removeContract(filename);
|
||||
return returnReward ? reward : true;
|
||||
} else {
|
||||
++contract.tries;
|
||||
if (contract.tries >= contract.getMaxNumTries()) {
|
||||
workerScript.log("attempt", `Coding Contract attempt '${fn}' failed. Contract is now self-destructing`);
|
||||
serv.removeContract(fn);
|
||||
workerScript.log("attempt", `Coding Contract attempt '${filename}' failed. Contract is now self-destructing`);
|
||||
serv.removeContract(filename);
|
||||
} else {
|
||||
workerScript.log(
|
||||
"attempt",
|
||||
`Coding Contract attempt '${fn}' failed. ${contract.getMaxNumTries() - contract.tries} attempts remaining.`,
|
||||
`Coding Contract attempt '${filename}' failed. ${
|
||||
contract.getMaxNumTries() - contract.tries
|
||||
} attempts remaining.`,
|
||||
);
|
||||
}
|
||||
|
||||
return returnReward ? "" : false;
|
||||
}
|
||||
},
|
||||
getContractType: function (fn: any, ip: any = workerScript.hostname): string {
|
||||
getContractType: function (filename: any, hostname: any = workerScript.hostname): string {
|
||||
helper.updateDynamicRam("getContractType", getRamCost("codingcontract", "getContractType"));
|
||||
const contract = getCodingContract("getContractType", ip, fn);
|
||||
const contract = getCodingContract("getContractType", hostname, filename);
|
||||
return contract.getType();
|
||||
},
|
||||
getData: function (fn: any, ip: any = workerScript.hostname): any {
|
||||
getData: function (filename: any, hostname: any = workerScript.hostname): any {
|
||||
helper.updateDynamicRam("getData", getRamCost("codingcontract", "getData"));
|
||||
const contract = getCodingContract("getData", ip, fn);
|
||||
const contract = getCodingContract("getData", hostname, filename);
|
||||
const data = contract.getData();
|
||||
if (data.constructor === Array) {
|
||||
// For two dimensional arrays, we have to copy the internal arrays using
|
||||
@ -93,14 +98,14 @@ export function NetscriptCodingContract(
|
||||
return data;
|
||||
}
|
||||
},
|
||||
getDescription: function (fn: any, ip: any = workerScript.hostname): string {
|
||||
getDescription: function (filename: any, hostname: any = workerScript.hostname): string {
|
||||
helper.updateDynamicRam("getDescription", getRamCost("codingcontract", "getDescription"));
|
||||
const contract = getCodingContract("getDescription", ip, fn);
|
||||
const contract = getCodingContract("getDescription", hostname, filename);
|
||||
return contract.getDescription();
|
||||
},
|
||||
getNumTriesRemaining: function (fn: any, ip: any = workerScript.hostname): number {
|
||||
getNumTriesRemaining: function (filename: any, hostname: any = workerScript.hostname): number {
|
||||
helper.updateDynamicRam("getNumTriesRemaining", getRamCost("codingcontract", "getNumTriesRemaining"));
|
||||
const contract = getCodingContract("getNumTriesRemaining", ip, fn);
|
||||
const contract = getCodingContract("getNumTriesRemaining", hostname, filename);
|
||||
return contract.getMaxNumTries() - contract.tries;
|
||||
},
|
||||
};
|
||||
|
14
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
14
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -2799,7 +2799,7 @@ export interface CodingContract {
|
||||
* @param opts - Optional parameters for configuring function behavior.
|
||||
* @returns True if the solution was correct, false otherwise. If the returnReward option is configured, then the function will instead return a string. If the contract is successfully solved, the string will contain a description of the contract’s reward. Otherwise, it will be an empty string.
|
||||
*/
|
||||
attempt(answer: string[] | number, fn: string, host?: string, opts?: CodingAttemptOptions): boolean | string;
|
||||
attempt(answer: string[] | number, filename: string, host?: string, opts?: CodingAttemptOptions): boolean | string;
|
||||
|
||||
/**
|
||||
* Get the type of a coding contract.
|
||||
@ -2813,7 +2813,7 @@ export interface CodingContract {
|
||||
* @param host - Host of the server containing the contract. Optional. Defaults to current server if not provided.
|
||||
* @returns Name describing the type of problem posed by the Coding Contract.
|
||||
*/
|
||||
getContractType(fn: string, host?: string): string;
|
||||
getContractType(filename: string, host?: string): string;
|
||||
|
||||
/**
|
||||
* Get the description.
|
||||
@ -2826,7 +2826,7 @@ export interface CodingContract {
|
||||
* @param host - Host of the server containing the contract. Optional. Defaults to current server if not provided.
|
||||
* @returns Contract’s text description.
|
||||
*/
|
||||
getDescription(fn: string, host?: string): string;
|
||||
getDescription(filename: string, host?: string): string;
|
||||
|
||||
/**
|
||||
* Get the input data.
|
||||
@ -2837,11 +2837,11 @@ export interface CodingContract {
|
||||
* Note that this is not the same as the contract’s description.
|
||||
* This is just the data that the contract wants you to act on in order to solve
|
||||
*
|
||||
* @param fn - Filename of the contract.
|
||||
* @param filename - Filename of the contract.
|
||||
* @param host - Host of the server containing the contract. Optional. Defaults to current server if not provided.
|
||||
* @returns The specified contract’s data;
|
||||
*/
|
||||
getData(fn: string, host?: string): string;
|
||||
getData(filename: string, host?: string): string;
|
||||
|
||||
/**
|
||||
* Get the number of attempt remaining.
|
||||
@ -2854,7 +2854,7 @@ export interface CodingContract {
|
||||
* @param host - Host of the server containing the contract. Optional. Defaults to current server if not provided.
|
||||
* @returns How many attempts are remaining for the contract;
|
||||
*/
|
||||
getNumTriesRemaining(fn: string, host?: string): number;
|
||||
getNumTriesRemaining(filename: string, host?: string): number;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -4416,7 +4416,7 @@ export interface NS extends Singularity {
|
||||
* RAM cost: 0.3 GB
|
||||
* @returns info about a running script
|
||||
*/
|
||||
getRunningScript(fn: string | number, hostname: string, ...args: (string | number)[]): RunningScript;
|
||||
getRunningScript(filename: string | number, hostname: string, ...args: (string | number)[]): RunningScript;
|
||||
|
||||
/**
|
||||
* Get cost of purchasing a server.
|
||||
|
Loading…
Reference in New Issue
Block a user