Rename ContractTypes -> CodingCOntractTypes. Begin Contract Generation code

This commit is contained in:
danielyxie 2018-09-16 03:55:54 -05:00
parent c309c0cdc9
commit a114904fd3
2 changed files with 80 additions and 57 deletions

@ -8,7 +8,7 @@ import { IMap } from "./types";
/* tslint:disable:no-magic-numbers completed-docs max-classes-per-file no-console */ /* tslint:disable:no-magic-numbers completed-docs max-classes-per-file no-console */
/* Represents different types of problems that a Coding Contract can have */ /* Represents different types of problems that a Coding Contract can have */
export class ContractType { export class CodingContractType {
/** /**
* Function that generates a description of the problem * Function that generates a description of the problem
*/ */
@ -56,12 +56,12 @@ export class ContractType {
/* Contract Types */ /* Contract Types */
// tslint:disable-next-line // tslint:disable-next-line
export const ContractTypes: IMap<ContractType> = {}; export const CodingContractTypes: IMap<CodingContractType> = {};
for (const md of codingContractTypesMetadata) { for (const md of codingContractTypesMetadata) {
ContractTypes[md.name] = new ContractType(md.name, md.desc, md.gen, md.solver, md.difficulty, md.numTries); CodingContractTypes[md.name] = new CodingContractType(md.name, md.desc, md.gen, md.solver, md.difficulty, md.numTries);
} }
console.info(`${Object.keys(ContractTypes).length} Coding Contract Types loaded`); console.info(`${Object.keys(CodingContractTypes).length} Coding Contract Types loaded`);
/** /**
* Enum representing the different types of rewards a Coding Contract can give * Enum representing the different types of rewards a Coding Contract can give
@ -70,7 +70,7 @@ export enum CodingContractRewardType {
FactionReputation, FactionReputation,
FactionReputationAll, FactionReputationAll,
CompanyReputation, CompanyReputation,
Money, Money, // This must always be the last reward type
} }
/** /**
@ -128,25 +128,25 @@ export class CodingContract {
} }
// tslint:disable-next-line // tslint:disable-next-line
if (ContractTypes[type] == null) { if (CodingContractTypes[type] == null) {
throw new Error(`Error: invalid contract type: ${type} please contact developer`); throw new Error(`Error: invalid contract type: ${type} please contact developer`);
} }
this.type = type; this.type = type;
this.data = ContractTypes[type].generate(); this.data = CodingContractTypes[type].generate();
this.reward = reward; this.reward = reward;
} }
getDifficulty(): number { getDifficulty(): number {
return ContractTypes[this.type].difficulty; return CodingContractTypes[this.type].difficulty;
} }
getMaxNumTries(): number { getMaxNumTries(): number {
return ContractTypes[this.type].numTries; return CodingContractTypes[this.type].numTries;
} }
isSolution(solution: string): boolean { isSolution(solution: string): boolean {
return ContractTypes[this.type].solver(this.data, solution); return CodingContractTypes[this.type].solver(this.data, solution);
} }
/** /**
@ -155,7 +155,7 @@ export class CodingContract {
async prompt(): Promise<CodingContractResult> { async prompt(): Promise<CodingContractResult> {
// tslint:disable-next-line // tslint:disable-next-line
return new Promise<CodingContractResult>((resolve: Function, reject: Function) => { return new Promise<CodingContractResult>((resolve: Function, reject: Function) => {
const contractType: ContractType = ContractTypes[this.type]; const contractType: ContractType = CodingContractTypes[this.type];
const popupId: string = `coding-contract-prompt-popup-${this.fn}`; const popupId: string = `coding-contract-prompt-popup-${this.fn}`;
const txt: HTMLElement = createElement("p", { const txt: HTMLElement = createElement("p", {
innerText: ["You are attempting to solve a Coding Contract. Note that", innerText: ["You are attempting to solve a Coding Contract. Note that",

@ -1,75 +1,78 @@
import {dialogBoxCreate} from "../utils/DialogBox"; import {dialogBoxCreate} from "../utils/DialogBox";
import {gameOptionsBoxOpen, gameOptionsBoxClose}from "../utils/GameOptions"; import {gameOptionsBoxOpen, gameOptionsBoxClose} from "../utils/GameOptions";
import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement"; import { getRandomInt } from "../utils/helpers/getRandomInt";
import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners"; import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement";
import {createElement} from "../utils/uiHelpers/createElement"; import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners";
import {exceptionAlert} from "../utils/helpers/exceptionAlert"; import {createElement} from "../utils/uiHelpers/createElement";
import {removeLoadingScreen} from "../utils/uiHelpers/removeLoadingScreen"; import {exceptionAlert} from "../utils/helpers/exceptionAlert";
import {removeLoadingScreen} from "../utils/uiHelpers/removeLoadingScreen";
import {numeralWrapper} from "./ui/numeralFormat"; import {numeralWrapper} from "./ui/numeralFormat";
import {formatNumber, import {formatNumber,
convertTimeMsToTimeElapsedString, convertTimeMsToTimeElapsedString,
replaceAt} from "../utils/StringHelperFunctions"; replaceAt} from "../utils/StringHelperFunctions";
import {loxBoxCreate, logBoxUpdateText, import {loxBoxCreate, logBoxUpdateText,
logBoxOpened} from "../utils/LogBox"; logBoxOpened} from "../utils/LogBox";
import {updateActiveScriptsItems} from "./ActiveScriptsUI"; import {updateActiveScriptsItems} from "./ActiveScriptsUI";
import {Augmentations, installAugmentations, import {Augmentations, installAugmentations,
initAugmentations, AugmentationNames, initAugmentations, AugmentationNames,
displayAugmentationsContent, displayAugmentationsContent,
PlayerOwnedAugmentation} from "./Augmentations"; PlayerOwnedAugmentation} from "./Augmentations";
import {BitNodes, initBitNodes, import {BitNodes, initBitNodes,
initBitNodeMultipliers} from "./BitNode"; initBitNodeMultipliers} from "./BitNode";
import {Bladeburner} from "./Bladeburner"; import {Bladeburner} from "./Bladeburner";
import {CharacterOverview} from "./CharacterOverview"; import {CharacterOverview} from "./CharacterOverview";
import {cinematicTextFlag} from "./CinematicText"; import {cinematicTextFlag} from "./CinematicText";
import {CompanyPositions, initCompanies} from "./Company"; import {CodingContract, CodingContractRewardType,
import {Corporation} from "./CompanyManagement"; CodingContractTypes} from "./CodingContracts";
import {CONSTANTS} from "./Constants"; import {CompanyPositions, initCompanies} from "./Company";
import {Corporation} from "./CompanyManagement";
import {CONSTANTS} from "./Constants";
import {displayCreateProgramContent, import {displayCreateProgramContent,
getNumAvailableCreateProgram, getNumAvailableCreateProgram,
initCreateProgramButtons, initCreateProgramButtons,
Programs} from "./CreateProgram"; Programs} from "./CreateProgram";
import {displayFactionContent, joinFaction, import {displayFactionContent, joinFaction,
processPassiveFactionRepGain, Factions, processPassiveFactionRepGain, Factions,
inviteToFaction, initFactions} from "./Faction"; inviteToFaction, initFactions} from "./Faction";
import {FconfSettings} from "./Fconf"; import {FconfSettings} from "./Fconf";
import {displayLocationContent, import {displayLocationContent,
initLocationButtons} from "./Location"; initLocationButtons} from "./Location";
import {Locations} from "./Locations"; import {Locations} from "./Locations";
import {displayGangContent, updateGangContent, import {displayGangContent, updateGangContent,
Gang} from "./Gang"; Gang} from "./Gang";
import {displayHacknetNodesContent, processAllHacknetNodeEarnings, import {displayHacknetNodesContent, processAllHacknetNodeEarnings,
updateHacknetNodesContent} from "./HacknetNode"; updateHacknetNodesContent} from "./HacknetNode";
import {iTutorialStart} from "./InteractiveTutorial"; import {iTutorialStart} from "./InteractiveTutorial";
import {initLiterature} from "./Literature"; import {initLiterature} from "./Literature";
import {checkForMessagesToSend, initMessages} from "./Message"; import {checkForMessagesToSend, initMessages} from "./Message";
import {inMission, currMission} from "./Missions"; import {inMission, currMission} from "./Missions";
import {initSingularitySFFlags, import {initSingularitySFFlags,
hasSingularitySF, hasCorporationSF} from "./NetscriptFunctions"; hasSingularitySF, hasCorporationSF} from "./NetscriptFunctions";
import {updateOnlineScriptTimes, import {updateOnlineScriptTimes,
runScriptsLoop} from "./NetscriptWorker"; runScriptsLoop} from "./NetscriptWorker";
import {Player} from "./Player"; import {Player} from "./Player";
import {prestigeAugmentation, import {prestigeAugmentation,
prestigeSourceFile} from "./Prestige"; prestigeSourceFile} from "./Prestige";
import {redPillFlag, hackWorldDaemon} from "./RedPill"; import {redPillFlag, hackWorldDaemon} from "./RedPill";
import {saveObject, loadGame} from "./SaveObject"; import {saveObject, loadGame} from "./SaveObject";
import {loadAllRunningScripts, scriptEditorInit, import {loadAllRunningScripts, scriptEditorInit,
updateScriptEditorContent} from "./Script"; updateScriptEditorContent} from "./Script";
import {AllServers, Server, initForeignServers} from "./Server"; import {AllServers, Server, initForeignServers} from "./Server";
import {Settings} from "./Settings"; import {Settings} from "./Settings";
import {setSettingsLabels} from "./ui/setSettingsLabels"; import {setSettingsLabels} from "./ui/setSettingsLabels";
import {initSourceFiles, SourceFiles, import {initSourceFiles, SourceFiles,
PlayerOwnedSourceFile} from "./SourceFile"; PlayerOwnedSourceFile} from "./SourceFile";
import {SpecialServerIps, initSpecialServerIps} from "./SpecialServerIps"; import {SpecialServerIps, initSpecialServerIps} from "./SpecialServerIps";
import {StockMarket, StockSymbols, import {StockMarket, StockSymbols,
SymbolToStockMap, initStockSymbols, SymbolToStockMap, initStockSymbols,
initSymbolToStockMap, stockMarketCycle, initSymbolToStockMap, stockMarketCycle,
updateStockPrices, updateStockPrices,
displayStockMarketContent} from "./StockMarket"; displayStockMarketContent} from "./StockMarket";
import {Terminal, postNetburnerText} from "./Terminal"; import {Terminal, postNetburnerText} from "./Terminal";
import {KEY} from "../utils/helpers/keyCodes"; import {KEY} from "../utils/helpers/keyCodes";
import {Page, routing} from "./ui/navigationTracking"; import {Page, routing} from "./ui/navigationTracking";
// These should really be imported with the module that is presenting that UI, but because they very much depend on the // These should really be imported with the module that is presenting that UI, but because they very much depend on the
// cascade order, we'll pull them all in here. // cascade order, we'll pull them all in here.
@ -1004,6 +1007,7 @@ const Engine = {
stockTick: 30, //Update stock prices stockTick: 30, //Update stock prices
sCr: 1500, sCr: 1500,
mechanicProcess: 5, //Processes certain mechanics (Corporation, Bladeburner) mechanicProcess: 5, //Processes certain mechanics (Corporation, Bladeburner)
contractGeneration: 3000 //Generate Coding Contracts
}, },
decrementAllCounters: function(numCycles = 1) { decrementAllCounters: function(numCycles = 1) {
@ -1149,6 +1153,25 @@ const Engine = {
} }
Engine.Counters.mechanicProcess = 5; Engine.Counters.mechanicProcess = 5;
} }
if (Engine.Counters.contractGeneration <= 0) {
// 5% chance of a contract being generated
if (Math.random() <= 0.05) {
// First select a random problem type
let problemTypes = Object.keys(CodingContractTypes);
let randIndex = getRandomInt(0, problemTypes.length - 1);
let problemType = CodingContractTypes[problemTypes[randIndex]];
// Then select a random reward type. 'Money' will always be the last reward type
let rewardType = getRandomInt(1, CodingContractRewardType.Money);
// Add additional information based on the reward type
switch (rewardType) {
case CodingContractRewardType
}
}
Engine.Counters.contractGeneration = 3000;
}
}, },
/* Calculates the hack progress for a manual (non-scripted) hack and updates the progress bar/time accordingly */ /* Calculates the hack progress for a manual (non-scripted) hack and updates the progress bar/time accordingly */