Skip to content

Commit

Permalink
feat!: add game version to resolveContract
Browse files Browse the repository at this point in the history
Signed-off-by: Reece Dunham <[email protected]>
  • Loading branch information
RDIL committed Sep 2, 2024
1 parent 50b25d5 commit 49d59db
Show file tree
Hide file tree
Showing 28 changed files with 283 additions and 118 deletions.
16 changes: 9 additions & 7 deletions components/2016/legacyContractHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Router } from "express"
import { gameDifficulty, nilUuid, ServerVer, uuidRegex } from "../utils"
import { json as jsonMiddleware } from "body-parser"
import { enqueueEvent, newSession } from "../eventHandler"
import { _legacyBull, controller } from "../controller"
import { controller } from "../controller"
import { log, LogLevel } from "../loggingInterop"
import { getConfig } from "../configSwizzleManager"
import type { GameChanger, RequestWithJwt } from "../types/types"
Expand Down Expand Up @@ -88,11 +88,10 @@ legacyContractRouter.post(
return
}

const contractData =
req.gameVersion === "h1" &&
req.body.id === "42bac555-bbb9-429d-a8ce-f1ffdf94211c"
? _legacyBull
: controller.resolveContract(req.body.id)
const contractData = controller.resolveContract(
req.body.id,
req.gameVersion,
)

if (!contractData) {
log(
Expand Down Expand Up @@ -193,7 +192,10 @@ legacyContractRouter.post(
return
}

const c = controller.resolveContract(req.body.contractId)
const c = controller.resolveContract(
req.body.contractId,
req.gameVersion,
)

if (!c) {
res.status(404).end()
Expand Down
2 changes: 2 additions & 0 deletions components/2016/legacyMenuData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ legacyMenuDataRouter.get(
{
type: ChallengeFilterType.ParentLocation,
parent: parentLocation.Id,
gameVersion: req.gameVersion,
pro1Filter: Pro1FilterType.Exclude,
},
parentLocation.Id,
Expand Down Expand Up @@ -198,6 +199,7 @@ legacyMenuDataRouter.get(
{
type: ChallengeFilterType.ParentLocation,
parent: parentLocation.Id,
gameVersion: req.gameVersion,
pro1Filter: Pro1FilterType.Only,
},
parentLocation.Id,
Expand Down
5 changes: 4 additions & 1 deletion components/2016/legacyProfileRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ legacyProfileRouter.post(
false,
)

const json = controller.resolveContract(req.body.contractId)
const json = controller.resolveContract(
req.body.contractId,
req.gameVersion,
)

if (!json) {
log(
Expand Down
14 changes: 12 additions & 2 deletions components/candle/challengeHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
ChallengeProgressionData,
CompiledChallengeIngameData,
CompiledChallengeRuntimeData,
GameVersion,
InclusionData,
MissionManifest,
RegistryChallenge,
Expand Down Expand Up @@ -115,19 +116,22 @@ export type ChallengeFilterOptions =
type: ChallengeFilterType.Contract
contractId: string
locationId: string
gameVersion: GameVersion
isFeatured?: boolean
difficulty: number
pro1Filter: Pro1FilterType
}
| {
type: ChallengeFilterType.Contracts
contractIds: string[]
gameVersion: GameVersion
locationId: string
pro1Filter: Pro1FilterType
}
| {
type: ChallengeFilterType.ParentLocation
parent: string
gameVersion: GameVersion
pro1Filter: Pro1FilterType
}

Expand Down Expand Up @@ -172,6 +176,7 @@ export function isChallengeForDifficulty(
* @param contractId The id of the contract.
* @param locationId The sublocation ID of the challenge.
* @param difficulty The upper bound on the difficulty of the challenges to return.
* @param gameVersion The game version.
* @param challenge The challenge in question.
* @param pro1Filter Settings for handling pro1 challenges.
* @param forCareer Whether the result is used to decide what is shown the CAREER -> CHALLENGES page. Defaulted to false.
Expand All @@ -181,6 +186,7 @@ function isChallengeInContract(
contractId: string,
locationId: string,
difficulty: number,
gameVersion: GameVersion,
challenge: RegistryChallenge,
pro1Filter: Pro1FilterType,
forCareer = false,
Expand All @@ -197,7 +203,7 @@ function isChallengeInContract(
return false
}

const contract = controller.resolveContract(contractId, true)
const contract = controller.resolveContract(contractId, gameVersion, true)

if (challenge.Type === "global") {
return inclusionDataCheck(
Expand Down Expand Up @@ -233,7 +239,9 @@ function isChallengeInContract(
// We have to resolve the non-group contract, `contract` is the group contract
const isForContractType = (
challenge.InclusionData?.ContractTypes || []
).includes(controller.resolveContract(contractId)!.Metadata.Type)
).includes(
controller.resolveContract(contractId, gameVersion)!.Metadata.Type,
)

// Is this a location-wide challenge?
// "location" is more widely used, but "parentlocation" is used in Ambrose and Berlin, as well as some "Discover XX" challenges.
Expand Down Expand Up @@ -275,6 +283,7 @@ export function filterChallenge(
options.contractId,
options.locationId,
options.difficulty,
options.gameVersion,
challenge,
options.pro1Filter,
)
Expand All @@ -286,6 +295,7 @@ export function filterChallenge(
contractId,
options.locationId,
gameDifficulty.master, // Get challenges of all difficulties
options.gameVersion,
challenge,
options.pro1Filter,
true,
Expand Down
46 changes: 39 additions & 7 deletions components/candle/challengeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,11 @@ export class ChallengeService extends ChallengeRegistry {
difficulty = 4,
): GroupIndexedChallengeLists {
const userData = getUserData(userId, gameVersion)
const contractGroup = this.controller.resolveContract(contractId, true)
const contractGroup = this.controller.resolveContract(
contractId,
gameVersion,
true,
)

if (!contractGroup) {
return {}
Expand All @@ -852,9 +856,17 @@ export class ChallengeService extends ChallengeRegistry {

assert.ok(currentLevel, "expected current level ID in escalation")

contract = this.controller.resolveContract(currentLevel, false)
contract = this.controller.resolveContract(
currentLevel,
gameVersion,
false,
)
} else {
contract = this.controller.resolveContract(contractId, false)
contract = this.controller.resolveContract(
contractId,
gameVersion,
false,
)
}

if (!contract) {
Expand All @@ -878,6 +890,7 @@ export class ChallengeService extends ChallengeRegistry {
gameVersion !== "h1"
? "LOCATION_ICA_FACILITY_SHIP"
: contract.Metadata.Location,
gameVersion,
isFeatured: contractGroup.Metadata.Type === "featured",
pro1Filter:
contract.Metadata.Difficulty === "pro1"
Expand Down Expand Up @@ -924,6 +937,7 @@ export class ChallengeService extends ChallengeRegistry {
type: ChallengeFilterType.Contracts,
contractIds: contracts,
locationId: child,
gameVersion,
pro1Filter: Pro1FilterType.Exclude,
},
parent,
Expand All @@ -936,7 +950,11 @@ export class ChallengeService extends ChallengeRegistry {
// brand new.
const { gameVersion, contractId, challengeContexts } = session

const contractJson = this.controller.resolveContract(contractId, true)
const contractJson = this.controller.resolveContract(
contractId,
gameVersion,
true,
)

const challengeGroups = this.getChallengesForContract(
contractId,
Expand Down Expand Up @@ -1139,7 +1157,11 @@ export class ChallengeService extends ChallengeRegistry {
): CompiledChallengeTreeCategory[] {
const userData = getUserData(userId, gameVersion)

const contractData = this.controller.resolveContract(contractId, true)
const contractData = this.controller.resolveContract(
contractId,
gameVersion,
true,
)

if (!contractData) {
return []
Expand All @@ -1164,9 +1186,17 @@ export class ChallengeService extends ChallengeRegistry {
return []
}

levelData = this.controller.resolveContract(order, false)
levelData = this.controller.resolveContract(
order,
gameVersion,
false,
)
} else {
levelData = this.controller.resolveContract(contractId, false)
levelData = this.controller.resolveContract(
contractId,
gameVersion,
false,
)
}

if (!levelData) {
Expand Down Expand Up @@ -1306,6 +1336,7 @@ export class ChallengeService extends ChallengeRegistry {
{
type: ChallengeFilterType.ParentLocation,
parent: locationParentId,
gameVersion,
pro1Filter: isPro1
? Pro1FilterType.Only
: Pro1FilterType.Exclude,
Expand Down Expand Up @@ -1535,6 +1566,7 @@ export class ChallengeService extends ChallengeRegistry {
if (challenge.Type === "contract") {
contract = this.controller.resolveContract(
challenge.InclusionData?.ContractIds?.[0] || "",
gameVersion,
)

// This is so we can remove unused data and make it more like official - AF
Expand Down
5 changes: 4 additions & 1 deletion components/candle/progressionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ export class ProgressionService {
location: string,
sniperUnlockable?: string,
): void {
const contract = controller.resolveContract(contractSession.contractId)
const contract = controller.resolveContract(
contractSession.contractId,
contractSession.gameVersion,
)

if (!contract) {
return
Expand Down
11 changes: 9 additions & 2 deletions components/contracts/contractRouting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ contractRoutingRouter.post(
return // user sent some nasty info
}

const contractData = controller.resolveContract(req.body.id)
const contractData = controller.resolveContract(
req.body.id,
req.gameVersion,
)

if (!contractData) {
log(
Expand Down Expand Up @@ -266,6 +269,7 @@ contractRoutingRouter.post(

const contractData = controller.resolveContract(
sessionDetails.contractId,
sessionDetails.gameVersion,
)

if (!contractData) {
Expand Down Expand Up @@ -347,7 +351,10 @@ contractRoutingRouter.post(
jsonMiddleware(),
// @ts-expect-error Has jwt props.
(req: RequestWithJwt<never, { contractId: string }>, res) => {
const contract = controller.resolveContract(req.body.contractId)
const contract = controller.resolveContract(
req.body.contractId,
req.gameVersion,
)

if (!contract) {
res.status(400).send("contract not found")
Expand Down
1 change: 1 addition & 0 deletions components/contracts/contractsModeRouting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function contractsModeHome(req: RequestWithJwt, res: Response): void {

const contractCreationTutorial = controller.resolveContract(
contractCreationTutorialId,
req.gameVersion,
)

res.json({
Expand Down
2 changes: 1 addition & 1 deletion components/contracts/dataGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export function generateUserCentric(

uc.Data.EscalationCompletedLevels = p - 1
uc.Data.EscalationTotalLevels = getLevelCount(
controller.resolveContract(eGroupId),
controller.resolveContract(eGroupId, gameVersion),
)
uc.Data.EscalationCompleted =
userData.Extensions.PeacockCompletedEscalations.includes(eGroupId)
Expand Down
2 changes: 1 addition & 1 deletion components/contracts/escalations/escalationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export function getPlayEscalationInfo(
}

const totalLevelCount = getLevelCount(
controller.resolveContract(groupContractId),
controller.resolveContract(groupContractId, gameVersion),
)

let nextContractId = "00000000-0000-0000-0000-000000000000"
Expand Down
7 changes: 5 additions & 2 deletions components/contracts/hitsCategoryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class HitsCategoryService {
.for("Elusive_Target_Hits")
.tap(tapName, (contracts, gameVersion) => {
for (const id of orderedETs) {
const contract = controller.resolveContract(id)
const contract = controller.resolveContract(id, gameVersion)

switch (gameVersion) {
case "h1":
Expand Down Expand Up @@ -243,7 +243,10 @@ export class HitsCategoryService {
missionsInLocations.escalations,
)) {
for (const id of escalations) {
const contract = controller.resolveContract(id)
const contract = controller.resolveContract(
id,
gameVersion,
)

if (!contract) continue

Expand Down
2 changes: 1 addition & 1 deletion components/contracts/leaderboards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export async function getLeaderboardEntries(
): Promise<GameFacingLeaderboardData | undefined> {
let difficulty = "unset"

const contract = controller.resolveContract(contractId)
const contract = controller.resolveContract(contractId, gameVersion)

if (!contract) {
return undefined
Expand Down
Loading

1 comment on commit 49d59db

@AnthonyFuller
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Please sign in to comment.