CONTRACTS: Proposal for Contract Progression System (#2230)

This commit is contained in:
gmcew
2025-07-10 22:25:36 +01:00
committed by GitHub
parent c5799616ce
commit 3fc65a2de4
9 changed files with 21 additions and 16 deletions
+11 -8
View File
@@ -70,17 +70,20 @@ export function tryGeneratingRandomContract(numberOfTries: number): void {
}
export function generateRandomContract(): void {
// First select a random problem type
const problemType = getRandomProblemType();
// Then select a random reward type. 'Money' will always be the last reward type
const reward = getRandomReward();
// Choose random server
const randServer = getRandomServer();
if (randServer === null) {
return;
}
// Then select a random reward type. 'Money' will always be the last reward type
const reward = getRandomReward();
// Finally select a random problem type.
// Difficulty is capped to not overwhelm a new player.
const totalSFs = [...Player.sourceFiles].reduce<number>((total, [__bn, lvl]) => (total += lvl), 0);
const maxDif = 2 * totalSFs + 1;
const problemType = getRandomProblemType(maxDif);
const contractFn = getRandomFilename(randServer, reward);
const contract = new CodingContract(contractFn, problemType, reward);
@@ -179,8 +182,8 @@ function sanitizeRewardType(rewardType: CodingContractRewardType): CodingContrac
return type;
}
function getRandomProblemType(): CodingContractName {
const problemTypes = Object.values(CodingContractName);
function getRandomProblemType(maxDif = 10): CodingContractName {
const problemTypes = Object.values(CodingContractName).filter((x) => CodingContractTypes[x].difficulty <= maxDif);
const randIndex = getRandomIntInclusive(0, problemTypes.length - 1);
return problemTypes[randIndex];