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,5 +1,6 @@
import {dialogBoxCreate} from "../utils/DialogBox"; import {dialogBoxCreate} from "../utils/DialogBox";
import {gameOptionsBoxOpen, gameOptionsBoxClose} from "../utils/GameOptions"; import {gameOptionsBoxOpen, gameOptionsBoxClose} from "../utils/GameOptions";
import { getRandomInt } from "../utils/helpers/getRandomInt";
import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement"; import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement";
import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners"; import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners";
import {createElement} from "../utils/uiHelpers/createElement"; import {createElement} from "../utils/uiHelpers/createElement";
@ -23,6 +24,8 @@ import {BitNodes, initBitNodes,
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 {CodingContract, CodingContractRewardType,
CodingContractTypes} from "./CodingContracts";
import {CompanyPositions, initCompanies} from "./Company"; import {CompanyPositions, initCompanies} from "./Company";
import {Corporation} from "./CompanyManagement"; import {Corporation} from "./CompanyManagement";
import {CONSTANTS} from "./Constants"; import {CONSTANTS} from "./Constants";
@ -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 */