1
mirror of https://github.com/thepeacockproject/Peacock synced 2025-02-23 03:35:25 +01:00

Fix mission end screens for challenges ()

* Fix mission end screens for challenges

Signed-off-by: Anthony Fuller <24512050+AnthonyFuller@users.noreply.github.com>
Co-authored-by: Anthony Fuller <24512050+AnthonyFuller@users.noreply.github.com>
This commit is contained in:
moonysolari 2023-01-28 23:29:53 -05:00 committed by GitHub
parent 485fa3dc45
commit 323419c497
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 17 deletions

@ -122,6 +122,8 @@ legacyProfileRouter.post(
ChallengeId: challenge.Id,
ProfileId: req.jwt.unique_name,
Completed: false,
// Here we don't care about "Ticked" and the client will ignore it
Ticked: false,
State: {},
ETag: `W/"datetime'${encodeURIComponent(
new Date().toISOString(),

@ -189,6 +189,24 @@ export class ChallengeService extends ChallengeRegistry {
)
}
/**
* Same concept as {@link fastGetIsCompleted},
* but for if a challenge is unticked.
*
* @param userData The user's data object. Will not be modified.
* @param challengeId The ID of the challenge.
* @returns Whether the challenge is completed and unticked.
* @see fastGetIsCompleted
*/
fastGetIsUnticked(
userData: Readonly<UserProfile>,
challengeId: string,
): boolean {
const progression =
userData.Extensions.ChallengeProgression[challengeId]
return (progression?.Completed && !progression.Ticked) || false
}
getPersistentChallengeProgression(
userId: string,
challengeId: string,
@ -217,6 +235,7 @@ export class ChallengeService extends ChallengeRegistry {
// apply default context if no progression exists
data[challengeId] ??= {
Ticked: false,
Completed: false,
State: initialContext,
}
@ -231,6 +250,7 @@ export class ChallengeService extends ChallengeRegistry {
return {
Completed: data[challengeId].Completed,
Ticked: data[challengeId].Ticked,
State: data[challengeId].State,
ChallengeId: challengeId,
ProfileId: userId,
@ -902,6 +922,7 @@ export class ChallengeService extends ChallengeRegistry {
userData.Extensions.ChallengeProgression[challenge.Id] ??= {
State: {},
Completed: false,
Ticked: false,
}
userData.Extensions.ChallengeProgression[challenge.Id].Completed = true

@ -563,11 +563,13 @@ profileRouter.post(
}
for (const challenge of challenges) {
// TODO: Add actual support for shortcut challenges
if (challenge.Challenge.Tags?.includes("shortcut")) {
challenge.Progression = {
ChallengeId: challenge.Challenge.Id,
ProfileId: req.jwt.unique_name,
Completed: true,
Ticked: true,
State: {
CurrentState: "Success",
},

@ -316,25 +316,32 @@ export async function missionEnd(
},
Challenges: Object.values(contractChallenges)
.flat()
// FIXME: This behaviour may not be accurate to original server
.filter((challengeData) =>
controller.challengeService.fastGetIsCompleted(
.filter((challengeData) => {
return controller.challengeService.fastGetIsUnticked(
userData,
challengeData.Id,
),
)
.map((challengeData) =>
controller.challengeService.compileRegistryChallengeTreeData(
challengeData,
controller.challengeService.getPersistentChallengeProgression(
req.jwt.unique_name,
challengeData.Id,
req.gameVersion,
),
req.gameVersion,
req.jwt.unique_name,
),
),
)
})
.map((challengeData) => {
const userId = req.jwt.unique_name
const gameVersion = req.gameVersion
userData.Extensions.ChallengeProgression[
challengeData.Id
].Ticked = true
writeUserData(userId, gameVersion)
return {
ChallengeId: challengeData.Id,
ChallengeTags: challengeData.Tags,
ChallengeName: challengeData.Name,
ChallengeImageUrl: challengeData.ImageName,
ChallengeDescription: challengeData.Description,
XPGain: challengeData.Rewards.MasteryXP,
IsGlobal: challengeData.Name.includes("GLOBAL"),
IsActionReward:
challengeData.Tags.includes("actionreward"),
Drops: challengeData.Drops,
}
}),
Drops: [],
OpportunityRewards: [], // ?
CompletionData: generateCompletionData(

@ -70,6 +70,7 @@ export interface ChallengePackage {
}
export type ProfileChallengeData = {
Ticked: boolean
Completed: boolean
// eslint-disable-next-line @typescript-eslint/no-explicit-any
State: any

@ -1105,6 +1105,7 @@ export interface ChallengeProgressionData {
ChallengeId: string
ProfileId: string
Completed: boolean
Ticked: boolean
State: Record<string, unknown>
CompletedAt: Date | string | null
MustBeSaved: boolean