Skip to content

Commit

Permalink
Merge branch 'master' into challengepack-ammonia
Browse files Browse the repository at this point in the history
  • Loading branch information
suanjiansalt authored Aug 26, 2024
2 parents 3ea1e8a + 166a613 commit ad21aad
Show file tree
Hide file tree
Showing 49 changed files with 12,270 additions and 679 deletions.
1 change: 1 addition & 0 deletions components/2016/legacyMenuData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ legacyMenuDataRouter.get(
req.query.locationId,
req.gameVersion,
req.jwt.unique_name,
req.query.difficulty,
)

const location = getParentLocationByName(
Expand Down
15 changes: 3 additions & 12 deletions components/2016/legacyProfileRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { Router } from "express"
import { controller } from "../controller"
import { json as jsonMiddleware } from "body-parser"
import { uuidRegex } from "../utils"
import { compileRuntimeChallenge } from "../candle/challengeHelpers"
import { compileRuntimeChallengeOnly } from "../candle/challengeHelpers"
import { GetChallengeProgressionBody } from "../types/gameSchemas"

const legacyProfileRouter = Router()
Expand Down Expand Up @@ -74,16 +74,8 @@ legacyProfileRouter.post(
),
)
.flat()
.map(
(challengeData) =>
compileRuntimeChallenge(
challengeData,
controller.challengeService.getPersistentChallengeProgression(
req.jwt.unique_name,
challengeData.Id,
req.gameVersion,
),
).Challenge,
.map((challengeData) =>
compileRuntimeChallengeOnly(challengeData),
),
)

Expand Down Expand Up @@ -155,7 +147,6 @@ legacyProfileRouter.post(
MustBeSaved: progression.MustBeSaved,
})
}
// TODO: HELP! Please DM rdil if you see this

res.json(challenges)
},
Expand Down
113 changes: 95 additions & 18 deletions components/candle/challengeHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import {
ChallengeProgressionData,
CompiledChallengeIngameData,
CompiledChallengeRuntimeData,
InclusionData,
MissionManifest,
Expand All @@ -27,43 +28,85 @@ import { SavedChallengeGroup } from "../types/challenges"
import { controller } from "../controller"
import { gameDifficulty, isSniperLocation } from "../utils"

/**
* Change a registry challenge to the runtime format (for GetActiveChallenges).
* @param challenge The challenge.
* @returns The runtime challenge.
* @see {@link compileRuntimeChallenge} for the modern variant with progression data.
*/
export function compileRuntimeChallengeOnly(
challenge: RegistryChallenge,
): CompiledChallengeIngameData {
return {
Id: challenge.Id,
GroupId: challenge.inGroup,
Name: challenge.Name,
Type: challenge.RuntimeType || "contract",
Description: challenge.Description,
ImageName: challenge.ImageName,
InclusionData: challenge.InclusionData || undefined,
Definition: challenge.Definition,
Tags: challenge.Tags,
Drops: challenge.Drops,
LastModified: "2021-01-06T23:00:32.0117635", // this is a lie 👍
PlayableSince: null,
PlayableUntil: null,
Xp: challenge.Rewards.MasteryXP || 0,
XpModifier: challenge.XpModifier || {},
}
}

/**
* Change a registry challenge to the runtime format (for GetActiveChallengesAndProgression).
* @param challenge The challenge.
* @param progression The progression data.
* @returns The runtime challenge (including progression data).
* @see {@link compileRuntimeChallengeOnly} for when you only need the challenge data.
*/
export function compileRuntimeChallenge(
challenge: RegistryChallenge,
progression: ChallengeProgressionData,
): CompiledChallengeRuntimeData {
return {
// GetActiveChallengesAndProgression
Challenge: {
Id: challenge.Id,
GroupId: challenge.inGroup,
Name: challenge.Name,
Type: challenge.RuntimeType || "contract",
Description: challenge.Description,
ImageName: challenge.ImageName,
InclusionData: challenge.InclusionData || undefined,
Definition: challenge.Definition,
Tags: challenge.Tags,
Drops: challenge.Drops,
LastModified: "2021-01-06T23:00:32.0117635", // this is a lie 👍
PlayableSince: null,
PlayableUntil: null,
Xp: challenge.Rewards.MasteryXP || 0,
XpModifier: challenge.XpModifier || {},
},
Challenge: compileRuntimeChallengeOnly(challenge),
Progression: progression,
}
}

/**
* How to handle filtering of challenges.
*/
export enum ChallengeFilterType {
/** Note that this option will include global elusive and escalations challenges. */
None = "None",
/** A single contract's challenges. */
Contract = "Contract",
/** Only used for the CAREER -> CHALLENGES page */
Contracts = "Contracts",
/** Only used for the location page, and when calculating location completion */
ParentLocation = "ParentLocation",
}

/**
* How to handle filtering of pro1 challenges.
* Works in conjunction with {@link ChallengeFilterType}, but only if the
* challenge is tagged as pro1 and the challenge filter is met.
*/
export enum Pro1FilterType {
/**
* Only include pro1 challenges.
*/
Only = "Only",
/**
* Include both pro1 and non-pro1 challenges.
*/
Ignore = "Ignore",
/**
* Exclude pro1 challenges.
*/
Exclude = "Exclude",
}

export type ChallengeFilterOptions =
| {
type: ChallengeFilterType.None
Expand All @@ -74,15 +117,18 @@ export type ChallengeFilterOptions =
locationId: string
isFeatured?: boolean
difficulty: number
pro1Filter: Pro1FilterType
}
| {
type: ChallengeFilterType.Contracts
contractIds: string[]
locationId: string
pro1Filter: Pro1FilterType
}
| {
type: ChallengeFilterType.ParentLocation
parent: string
pro1Filter: Pro1FilterType
}

/**
Expand Down Expand Up @@ -127,6 +173,7 @@ export function isChallengeForDifficulty(
* @param locationId The sublocation ID of the challenge.
* @param difficulty The upper bound on the difficulty of the challenges to return.
* @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.
* @returns A boolean value, denoting the result.
*/
Expand All @@ -135,6 +182,7 @@ function isChallengeInContract(
locationId: string,
difficulty: number,
challenge: RegistryChallenge,
pro1Filter: Pro1FilterType,
forCareer = false,
): boolean {
if (!contractId || !locationId) {
Expand Down Expand Up @@ -168,6 +216,13 @@ function isChallengeInContract(
)
}

if (
challenge.Tags.includes("elusive") &&
contract?.Metadata.Type !== "elusive"
) {
return false
}

// Is this for the current contract or group contract?
const isForContract = (challenge.InclusionData?.ContractIds || []).includes(
contract?.Metadata.Id || "",
Expand All @@ -193,6 +248,14 @@ function isChallengeInContract(
challenge.LocationId === locationId ||
challenge.LocationId === challenge.ParentLocationId

const isPro1 = challenge.Tags.includes("pro1")

if (isPro1 && pro1Filter === Pro1FilterType.Exclude) {
return false
} else if (!isPro1 && pro1Filter === Pro1FilterType.Only) {
return false
}

return (
isForContract ||
isForContractType ||
Expand All @@ -213,6 +276,7 @@ export function filterChallenge(
options.locationId,
options.difficulty,
challenge,
options.pro1Filter,
)
}
case ChallengeFilterType.Contracts: {
Expand All @@ -223,6 +287,7 @@ export function filterChallenge(
options.locationId,
gameDifficulty.master, // Get challenges of all difficulties
challenge,
options.pro1Filter,
true,
),
)
Expand Down Expand Up @@ -255,12 +320,24 @@ export function filterChallenge(
}

if (challenge.Tags.includes("escalation")) {
if (options.pro1Filter === Pro1FilterType.Only) {
return false
}

return (
!isSniperLocation(options.parent) &&
"LOCATION_PARENT_SNUG" !== options.parent
)
}

const isPro1 = challenge.Tags.includes("pro1")

if (isPro1 && options.pro1Filter === Pro1FilterType.Exclude) {
return false
} else if (!isPro1 && options.pro1Filter === Pro1FilterType.Only) {
return false
}

return true
}
}
Expand Down
Loading

0 comments on commit ad21aad

Please sign in to comment.