Added a check to prevent doubling coding contract rewards

This commit is contained in:
Undeemiss 2022-05-11 15:51:54 -05:00
parent f5f5879fc3
commit a23c55c760

@ -330,8 +330,7 @@ export class Terminal implements ITerminal {
this.print("Time to hack: " + (!isHacknet ? convertTimeMsToTimeElapsedString(hackingTime, true) : "N/A")); this.print("Time to hack: " + (!isHacknet ? convertTimeMsToTimeElapsedString(hackingTime, true) : "N/A"));
} }
this.print( this.print(
`Total money available on server: ${ `Total money available on server: ${currServ instanceof Server ? numeralWrapper.formatMoney(currServ.moneyAvailable) : "N/A"
currServ instanceof Server ? numeralWrapper.formatMoney(currServ.moneyAvailable) : "N/A"
}`, }`,
); );
if (currServ instanceof Server) { if (currServ instanceof Server) {
@ -463,6 +462,12 @@ export class Terminal implements ITerminal {
this.contractOpen = true; this.contractOpen = true;
const res = await contract.prompt(); const res = await contract.prompt();
//Check if the contract still exists by the time the promise is fullfilled
if (serv.getContract(contractName) == null) {
this.contractOpen = false;
return this.error("Contract no longer exists (Was it solved by a script?)");
}
switch (res) { switch (res) {
case CodingContractResult.Success: case CodingContractResult.Success:
if (contract.reward !== null) { if (contract.reward !== null) {