mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-18 20:25:45 +01:00
Fixed various Coding Contract bugs. Added getContractType() to coding contract API
This commit is contained in:
parent
f86d87fa03
commit
62b58cd766
@ -31,6 +31,20 @@ attempt
|
|||||||
|
|
||||||
:returns: Boolean indicating whether the solution was correct
|
:returns: Boolean indicating whether the solution was correct
|
||||||
|
|
||||||
|
getContractType
|
||||||
|
---------------
|
||||||
|
|
||||||
|
.. js:function:: getContractType(fn[, hostname/ip=current ip])
|
||||||
|
|
||||||
|
:param string fn: Filename of the contract
|
||||||
|
:param string hostname/ip: Hostname or IP of the server containing the contract.
|
||||||
|
Optional. Defaults to current server if not provided
|
||||||
|
|
||||||
|
Returns a name describing the type of problem posed by the Coding Contract.
|
||||||
|
(e.g. Find Largest Prime Factor, Total Ways to Sum, etc.)
|
||||||
|
|
||||||
|
:returns: A string with the contract's problem type
|
||||||
|
|
||||||
getDescription
|
getDescription
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
|
@ -112,7 +112,8 @@ let NetscriptFunctions =
|
|||||||
"getCityChaos|switchCity|getStamina|joinBladeburnerFaction|getBonusTime|" +
|
"getCityChaos|switchCity|getStamina|joinBladeburnerFaction|getBonusTime|" +
|
||||||
|
|
||||||
// Coding Contract API
|
// Coding Contract API
|
||||||
"codingcontract|attempt|getData|getDescription|getNumTriesRemaining";
|
"codingcontract|attempt|getContractType|getData|getDescription|" +
|
||||||
|
"getNumTriesRemaining";
|
||||||
|
|
||||||
var NetscriptHighlightRules = function(options) {
|
var NetscriptHighlightRules = function(options) {
|
||||||
var keywordMapper = this.createKeywordMapper({
|
var keywordMapper = this.createKeywordMapper({
|
||||||
|
@ -154,6 +154,10 @@ export class CodingContract {
|
|||||||
return CodingContractTypes[this.type].numTries;
|
return CodingContractTypes[this.type].numTries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getType(): string {
|
||||||
|
return CodingContractTypes[this.type].name;
|
||||||
|
}
|
||||||
|
|
||||||
isSolution(solution: string): boolean {
|
isSolution(solution: string): boolean {
|
||||||
return CodingContractTypes[this.type].solver(this.data, solution);
|
return CodingContractTypes[this.type].solver(this.data, solution);
|
||||||
}
|
}
|
||||||
|
@ -506,18 +506,11 @@ let CONSTANTS = {
|
|||||||
|
|
||||||
LatestUpdate:
|
LatestUpdate:
|
||||||
`
|
`
|
||||||
v0.40.4
|
v0.40.5
|
||||||
* Added new Coding Contracts mechanic. Solve programming problems to earn rewards
|
* Added codingcontract.getContractType() Netscript function
|
||||||
* The write() and read() Netscript functions now work on scripts
|
* Bug Fix: codingcontract.getData() Netscript function now returns arrays by value rather than reference
|
||||||
* Added getStockSymbols() Netscript function to the TIX API (by InfraK)
|
* Bug Fix: Decreased highest possible data value for 'Find Largest Prime Factor' Coding Contract (to avoid hangs when solving it)
|
||||||
* Added wget() Netscript function
|
* Bug Fix: Fixed a bug that caused game to freeze during Coding Contract generation
|
||||||
* Added bladeburner.getActionRepGain() function to the Netscript Bladeburner API
|
|
||||||
* The getLevelUpgradeCost(), getRamUpgradeCost(), and getCoreUpgradeCost() functions in the Hacknet API now return Infinity if the node is at max level. See documentation
|
|
||||||
* It is now possible to use freely use angled bracket (<, >) and create DOM elements using tprint()
|
|
||||||
* The game's theme colors can now be set through the Terminal configuration (.fconf).
|
|
||||||
* You can now switch to the old left-hand main menu bar through the Terminal configuration (.fconf)
|
|
||||||
* Bug Fix: grow() percentage is no longer reported as Infinity when a server's money is grown from 0 to X
|
|
||||||
* Bug Fix: Infiltration popup now displays the correct amount of exp gained
|
|
||||||
`
|
`
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4085,17 +4085,35 @@ function NetscriptFunctions(workerScript) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
getContractType : function(fn, ip=workerScript.serverIp) {
|
||||||
|
if (workerScript.checkingRam) {
|
||||||
|
return updateStaticRam("getContractType", CONSTANTS.ScriptCodingContractBaseRamCost / 2);
|
||||||
|
}
|
||||||
|
updateDynamicRam("getContractType", CONSTANTS.ScriptCodingContractBaseRamCost / 2);
|
||||||
|
let contract = getCodingContract(fn, ip);
|
||||||
|
if (contract == null) {
|
||||||
|
workerScript.log(`ERROR: codingcontract.getData() failed because it could find the specified contract ${fn} on server ${ip}`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return contract.getType();
|
||||||
|
},
|
||||||
getData : function(fn, ip=workerScript.serverIp) {
|
getData : function(fn, ip=workerScript.serverIp) {
|
||||||
if (workerScript.checkingRam) {
|
if (workerScript.checkingRam) {
|
||||||
return updateStaticRam("getData", CONSTANTS.ScriptCodingContractBaseRamCost / 2);
|
return updateStaticRam("getData", CONSTANTS.ScriptCodingContractBaseRamCost / 2);
|
||||||
}
|
}
|
||||||
updateDynamicRam("getData", CONSTANTS.ScriptCodingContractBaseRamCost / 2);
|
updateDynamicRam("getData", CONSTANTS.ScriptCodingContractBaseRamCost / 2);
|
||||||
var contract = getCodingContract(fn, ip);
|
let contract = getCodingContract(fn, ip);
|
||||||
if (contract == null) {
|
if (contract == null) {
|
||||||
workerScript.log(`ERROR: codingcontract.getData() failed because it could find the specified contract ${fn} on server ${ip}`);
|
workerScript.log(`ERROR: codingcontract.getData() failed because it could find the specified contract ${fn} on server ${ip}`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return contract.getData();
|
let data = contract.getData();
|
||||||
|
if (typeof data === "object") {
|
||||||
|
// Pass a copy
|
||||||
|
return data.slice();
|
||||||
|
} else {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
getDescription : function(fn, ip=workerScript.serverIp) {
|
getDescription : function(fn, ip=workerScript.serverIp) {
|
||||||
if (workerScript.checkingRam) {
|
if (workerScript.checkingRam) {
|
||||||
|
@ -50,7 +50,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
|
|||||||
},
|
},
|
||||||
difficulty: 1,
|
difficulty: 1,
|
||||||
gen: () => {
|
gen: () => {
|
||||||
return getRandomInt(500, 9e9);
|
return getRandomInt(500, 1e9);
|
||||||
},
|
},
|
||||||
name: "Find Largest Prime Factor",
|
name: "Find Largest Prime Factor",
|
||||||
numTries: 10,
|
numTries: 10,
|
||||||
|
@ -1169,10 +1169,18 @@ const Engine = {
|
|||||||
reward.type = getRandomInt(0, CodingContractRewardType.Money);
|
reward.type = getRandomInt(0, CodingContractRewardType.Money);
|
||||||
|
|
||||||
// Change type based on certain conditions
|
// Change type based on certain conditions
|
||||||
if (reward.type === CodingContractRewardType.FactionReputation && Player.factions.length === 0) {
|
var factionsThatAllowHacking = Player.factions.filter((fac) => {
|
||||||
|
try {
|
||||||
|
return Factions[fac].getInfo().offerHackingWork;
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`Error when trying to filter Hacking Factions for Coding Contract Generation: ${e}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (reward.type === CodingContractRewardType.FactionReputation && factionsThatAllowHacking.length === 0) {
|
||||||
reward.type = CodingContractRewardType.CompanyReputation;
|
reward.type = CodingContractRewardType.CompanyReputation;
|
||||||
}
|
}
|
||||||
if (reward.type === CodingContractRewardType.FactionReputationAll && Player.factions.length === 0) {
|
if (reward.type === CodingContractRewardType.FactionReputationAll && factionsThatAllowHacking.length === 0) {
|
||||||
reward.type = CodingContractRewardType.CompanyReputation;
|
reward.type = CodingContractRewardType.CompanyReputation;
|
||||||
}
|
}
|
||||||
if (reward.type === CodingContractRewardType.CompanyReputation && Player.companyName === "") {
|
if (reward.type === CodingContractRewardType.CompanyReputation && Player.companyName === "") {
|
||||||
@ -1183,18 +1191,9 @@ const Engine = {
|
|||||||
switch (reward.type) {
|
switch (reward.type) {
|
||||||
case CodingContractRewardType.FactionReputation:
|
case CodingContractRewardType.FactionReputation:
|
||||||
// Get a random faction that player is a part of. That
|
// Get a random faction that player is a part of. That
|
||||||
//faction must allow hacking contracts
|
// faction must allow hacking contracts
|
||||||
var numFactions = Player.factions.length;
|
var numFactions = factionsThatAllowHacking.length;
|
||||||
var randFaction = Player.factions[getRandomInt(0, numFactions - 1)];
|
var randFaction = factionsThatAllowHacking[getRandomInt(0, numFactions - 1)];
|
||||||
try {
|
|
||||||
while(Factions[randFaction].getInfo().offerHackingWork !== true) {
|
|
||||||
randFaction = Player.factions[getRandomInt(0, numFactions - 1)];
|
|
||||||
}
|
|
||||||
reward.name = randFaction;
|
|
||||||
} catch (e) {
|
|
||||||
exceptionAlert("Failed to find a faction for Coding Contract Generation: " + e);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case CodingContractRewardType.CompanyReputation:
|
case CodingContractRewardType.CompanyReputation:
|
||||||
if (Player.companyName !== "") {
|
if (Player.companyName !== "") {
|
||||||
|
Loading…
Reference in New Issue
Block a user