2022-10-20 03:18:35 +02:00
|
|
|
/*
|
|
|
|
* The Peacock Project - a HITMAN server replacement.
|
2023-01-23 19:37:33 +01:00
|
|
|
* Copyright (C) 2021-2023 The Peacock Project Team
|
2022-10-20 03:18:35 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import type { Response } from "express"
|
|
|
|
import {
|
2023-03-21 01:12:54 +01:00
|
|
|
contractTypes,
|
2023-07-25 00:47:28 +02:00
|
|
|
DEFAULT_MASTERY_MAXLEVEL,
|
2022-10-20 03:18:35 +02:00
|
|
|
difficultyToString,
|
2023-03-18 18:35:26 +01:00
|
|
|
EVERGREEN_LEVEL_INFO,
|
2023-07-25 00:47:28 +02:00
|
|
|
evergreenLevelForXp,
|
2022-10-20 03:18:35 +02:00
|
|
|
handleAxiosError,
|
|
|
|
isObjectiveActive,
|
2023-03-18 18:35:26 +01:00
|
|
|
levelForXp,
|
2022-10-20 03:18:35 +02:00
|
|
|
PEACOCKVERSTRING,
|
2023-03-19 03:04:23 +01:00
|
|
|
SNIPER_LEVEL_INFO,
|
2023-07-25 00:47:28 +02:00
|
|
|
sniperLevelForXp,
|
2022-10-20 03:18:35 +02:00
|
|
|
xpRequiredForLevel,
|
|
|
|
} from "./utils"
|
|
|
|
import { contractSessions, getCurrentState } from "./eventHandler"
|
2023-03-18 18:35:26 +01:00
|
|
|
import { getConfig } from "./configSwizzleManager"
|
2022-10-20 03:18:35 +02:00
|
|
|
import { _theLastYardbirdScpc, controller } from "./controller"
|
|
|
|
import type {
|
2023-04-14 04:13:16 +02:00
|
|
|
ContractHistory,
|
2022-10-20 03:18:35 +02:00
|
|
|
ContractSession,
|
2023-03-18 22:53:14 +01:00
|
|
|
GameChanger,
|
2023-03-18 18:35:26 +01:00
|
|
|
GameVersion,
|
|
|
|
MissionManifest,
|
2022-10-20 03:18:35 +02:00
|
|
|
MissionManifestObjective,
|
|
|
|
RequestWithJwt,
|
|
|
|
Seconds,
|
|
|
|
} from "./types/types"
|
|
|
|
import {
|
2023-04-21 19:48:56 +02:00
|
|
|
escalationTypes,
|
2022-10-20 03:18:35 +02:00
|
|
|
getLevelCount,
|
|
|
|
} from "./contracts/escalations/escalationService"
|
|
|
|
import { getUserData, writeUserData } from "./databaseHandler"
|
|
|
|
import axios from "axios"
|
|
|
|
import { getFlag } from "./flags"
|
2023-03-19 04:25:52 +01:00
|
|
|
import { log, LogLevel } from "./loggingInterop"
|
2023-03-18 18:35:26 +01:00
|
|
|
import {
|
|
|
|
generateCompletionData,
|
|
|
|
getSubLocationByName,
|
|
|
|
} from "./contracts/dataGen"
|
2022-10-20 03:18:35 +02:00
|
|
|
import { liveSplitManager } from "./livesplit/liveSplitManager"
|
2023-04-29 04:37:46 +02:00
|
|
|
import { ScoringHeadline } from "./types/scoring"
|
2022-10-20 03:18:35 +02:00
|
|
|
import { MissionEndRequestQuery } from "./types/gameSchemas"
|
2023-01-12 16:35:27 +01:00
|
|
|
import { ChallengeFilterType } from "./candle/challengeHelpers"
|
|
|
|
import { getCompletionPercent } from "./menus/destinations"
|
2023-03-18 18:35:26 +01:00
|
|
|
import {
|
|
|
|
CalculateScoreResult,
|
2023-07-25 00:47:28 +02:00
|
|
|
CalculateSniperScoreResult,
|
|
|
|
CalculateXpResult,
|
|
|
|
MissionEndChallenge,
|
2023-03-18 18:35:26 +01:00
|
|
|
MissionEndDrop,
|
|
|
|
MissionEndEvergreen,
|
2023-07-25 00:47:28 +02:00
|
|
|
MissionEndResponse,
|
2023-03-18 18:35:26 +01:00
|
|
|
} from "./types/score"
|
|
|
|
import { MasteryData } from "./types/mastery"
|
2023-07-25 00:47:28 +02:00
|
|
|
import { createInventory, InventoryItem, getUnlockablesById } from "./inventory"
|
2023-04-29 04:37:46 +02:00
|
|
|
import { calculatePlaystyle } from "./playStyles"
|
2022-10-20 03:18:35 +02:00
|
|
|
|
2023-04-22 19:59:47 +02:00
|
|
|
export function calculateGlobalXp(
|
2023-03-18 18:35:26 +01:00
|
|
|
contractSession: ContractSession,
|
2023-04-05 21:02:25 +02:00
|
|
|
gameVersion: GameVersion,
|
2023-03-18 18:35:26 +01:00
|
|
|
): CalculateXpResult {
|
|
|
|
const completedChallenges: MissionEndChallenge[] = []
|
|
|
|
let totalXp = 0
|
2022-10-20 03:18:35 +02:00
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// TODO: Merge with the non-global challenges?
|
2023-03-18 18:35:26 +01:00
|
|
|
for (const challengeId of Object.keys(contractSession.challengeContexts)) {
|
|
|
|
const data = contractSession.challengeContexts[challengeId]
|
2022-10-20 03:18:35 +02:00
|
|
|
|
2023-03-18 18:35:26 +01:00
|
|
|
if (data.timesCompleted <= 0) {
|
|
|
|
continue
|
2022-10-20 03:18:35 +02:00
|
|
|
}
|
|
|
|
|
2023-04-05 21:02:25 +02:00
|
|
|
const challenge = controller.challengeService.getChallengeById(
|
|
|
|
challengeId,
|
|
|
|
gameVersion,
|
|
|
|
)
|
2023-03-18 18:35:26 +01:00
|
|
|
|
|
|
|
if (!challenge || !challenge.Xp || !challenge.Tags.includes("global")) {
|
|
|
|
continue
|
2022-10-20 03:18:35 +02:00
|
|
|
}
|
|
|
|
|
2023-03-18 18:35:26 +01:00
|
|
|
const challengeXp = challenge.Xp * data.timesCompleted
|
|
|
|
totalXp += challengeXp
|
|
|
|
|
|
|
|
const challengeData = {
|
|
|
|
ChallengeId: challenge.Id,
|
|
|
|
ChallengeTags: challenge.Tags,
|
|
|
|
ChallengeName: challenge.Name,
|
|
|
|
ChallengeImageUrl: challenge.ImageName,
|
|
|
|
ChallengeDescription: challenge.Description,
|
2023-04-29 05:39:57 +02:00
|
|
|
// TODO: We probably have to use Repeatable here somehow to determine when to "repeat" a challenge.
|
2023-03-18 18:35:26 +01:00
|
|
|
XPGain: challengeXp,
|
|
|
|
IsGlobal: true,
|
|
|
|
IsActionReward: challenge.Tags.includes("actionreward"),
|
|
|
|
Drops: challenge.Drops,
|
2022-10-20 03:18:35 +02:00
|
|
|
}
|
|
|
|
|
2023-03-18 18:35:26 +01:00
|
|
|
completedChallenges.push(challengeData)
|
2022-10-20 03:18:35 +02:00
|
|
|
}
|
|
|
|
|
2023-03-18 18:35:26 +01:00
|
|
|
return {
|
|
|
|
completedChallenges: completedChallenges,
|
|
|
|
xp: totalXp,
|
2022-10-20 03:18:35 +02:00
|
|
|
}
|
2023-03-18 18:35:26 +01:00
|
|
|
}
|
2022-10-20 03:18:35 +02:00
|
|
|
|
2023-03-18 18:35:26 +01:00
|
|
|
export function calculateScore(
|
|
|
|
gameVersion: GameVersion,
|
|
|
|
contractSession: ContractSession,
|
|
|
|
contractData: MissionManifest,
|
|
|
|
timeTotal: Seconds,
|
|
|
|
): CalculateScoreResult {
|
2023-04-29 05:39:57 +02:00
|
|
|
// Bonuses
|
2022-10-20 03:18:35 +02:00
|
|
|
const bonuses = [
|
|
|
|
{
|
|
|
|
headline: "UI_SCORING_SUMMARY_OBJECTIVES",
|
|
|
|
bonusId: "AllObjectivesCompletedBonus",
|
|
|
|
condition:
|
2023-03-18 18:35:26 +01:00
|
|
|
gameVersion === "h1" ||
|
2022-10-20 03:18:35 +02:00
|
|
|
contractData.Metadata.Id ===
|
|
|
|
"2d1bada4-aa46-4954-8cf5-684989f1668a" ||
|
|
|
|
contractData.Data.Objectives?.every(
|
|
|
|
(obj: MissionManifestObjective) =>
|
|
|
|
obj.ExcludeFromScoring ||
|
2023-03-18 18:35:26 +01:00
|
|
|
contractSession.completedObjectives.has(obj.Id) ||
|
2022-10-20 03:18:35 +02:00
|
|
|
(obj.IgnoreIfInactive &&
|
|
|
|
!isObjectiveActive(
|
|
|
|
obj,
|
2023-03-18 18:35:26 +01:00
|
|
|
contractSession.completedObjectives,
|
2022-10-20 03:18:35 +02:00
|
|
|
)) ||
|
|
|
|
"Success" ===
|
2023-04-21 19:48:56 +02:00
|
|
|
getCurrentState(contractSession.Id, obj.Id),
|
2022-10-20 03:18:35 +02:00
|
|
|
),
|
2023-03-18 18:35:26 +01:00
|
|
|
fractionNumerator: 2,
|
|
|
|
fractionDenominator: 3,
|
2022-10-20 03:18:35 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
headline: "UI_SCORING_SUMMARY_NOT_SPOTTED",
|
|
|
|
bonusId: "Unspotted",
|
|
|
|
condition: [
|
2023-03-18 18:35:26 +01:00
|
|
|
...contractSession.witnesses,
|
|
|
|
...contractSession.spottedBy,
|
2022-10-20 03:18:35 +02:00
|
|
|
].every(
|
|
|
|
(witness) =>
|
2023-03-18 18:35:26 +01:00
|
|
|
(gameVersion === "h1"
|
2022-10-20 03:18:35 +02:00
|
|
|
? false
|
2023-03-18 18:35:26 +01:00
|
|
|
: contractSession.targetKills.has(witness)) ||
|
|
|
|
contractSession.npcKills.has(witness),
|
2022-10-20 03:18:35 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
headline: "UI_SCORING_SUMMARY_NO_NOTICED_KILLS",
|
|
|
|
bonusId: "NoWitnessedKillsBonus",
|
2023-03-18 18:35:26 +01:00
|
|
|
condition: [...contractSession.killsNoticedBy].every(
|
2022-10-20 03:18:35 +02:00
|
|
|
(witness) =>
|
2023-03-18 18:35:26 +01:00
|
|
|
(gameVersion === "h1"
|
2022-10-20 03:18:35 +02:00
|
|
|
? true
|
2023-03-18 18:35:26 +01:00
|
|
|
: contractSession.targetKills.has(witness)) ||
|
|
|
|
contractSession.npcKills.has(witness),
|
2022-10-20 03:18:35 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
headline: "UI_SCORING_SUMMARY_NO_BODIES_FOUND",
|
|
|
|
bonusId: "NoBodiesFound",
|
|
|
|
condition:
|
2023-03-18 18:35:26 +01:00
|
|
|
contractSession.legacyHasBodyBeenFound === false &&
|
|
|
|
[...contractSession.bodiesFoundBy].every(
|
2022-10-20 03:18:35 +02:00
|
|
|
(witness) =>
|
2023-03-18 18:35:26 +01:00
|
|
|
(gameVersion === "h1"
|
2022-10-20 03:18:35 +02:00
|
|
|
? false
|
2023-03-18 18:35:26 +01:00
|
|
|
: contractSession.targetKills.has(witness)) ||
|
|
|
|
contractSession.npcKills.has(witness),
|
2022-10-20 03:18:35 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
headline: "UI_SCORING_SUMMARY_NO_RECORDINGS",
|
|
|
|
bonusId: "SecurityErased",
|
|
|
|
condition:
|
2023-03-18 18:35:26 +01:00
|
|
|
contractSession.recording === "NOT_SPOTTED" ||
|
|
|
|
contractSession.recording === "ERASED",
|
2022-10-20 03:18:35 +02:00
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Non-target kills
|
2023-03-18 18:35:26 +01:00
|
|
|
const nonTargetKills =
|
|
|
|
contractData?.Metadata.AllowNonTargetKills === true
|
|
|
|
? 0
|
|
|
|
: contractSession.npcKills.size + contractSession.crowdNpcKills
|
2022-10-20 03:18:35 +02:00
|
|
|
|
2023-03-18 18:35:26 +01:00
|
|
|
let totalScore = -5000 * nonTargetKills
|
2022-10-20 03:18:35 +02:00
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Headlines and bonuses
|
2023-03-18 18:35:26 +01:00
|
|
|
const scoringHeadlines = []
|
|
|
|
const awardedBonuses = []
|
|
|
|
const failedBonuses = []
|
2022-10-20 03:18:35 +02:00
|
|
|
|
|
|
|
const headlineObjTemplate: Partial<ScoringHeadline> = {
|
|
|
|
type: "summary",
|
|
|
|
count: "",
|
|
|
|
scoreIsFloatingType: false,
|
|
|
|
fractionNumerator: 0,
|
|
|
|
fractionDenominator: 0,
|
|
|
|
scoreTotal: 20000,
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const bonus of bonuses) {
|
|
|
|
const bonusObj = {
|
|
|
|
Score: 20000,
|
|
|
|
Id: bonus.bonusId,
|
2023-03-18 18:35:26 +01:00
|
|
|
FractionNumerator: bonus.fractionNumerator || 0,
|
|
|
|
FractionDenominator: bonus.fractionDenominator || 0,
|
2022-10-20 03:18:35 +02:00
|
|
|
}
|
2023-03-18 18:35:26 +01:00
|
|
|
|
2022-10-20 03:18:35 +02:00
|
|
|
const headlineObj = Object.assign(
|
|
|
|
{},
|
|
|
|
headlineObjTemplate,
|
|
|
|
) as ScoringHeadline
|
|
|
|
headlineObj.headline = bonus.headline
|
2023-03-18 18:35:26 +01:00
|
|
|
headlineObj.fractionNumerator = bonus.fractionNumerator || 0
|
|
|
|
headlineObj.fractionDenominator = bonus.fractionDenominator || 0
|
2022-10-20 03:18:35 +02:00
|
|
|
|
|
|
|
if (bonus.condition) {
|
2023-03-18 18:35:26 +01:00
|
|
|
totalScore += 20000
|
|
|
|
scoringHeadlines.push(headlineObj)
|
|
|
|
awardedBonuses.push(bonusObj)
|
2022-10-20 03:18:35 +02:00
|
|
|
} else {
|
|
|
|
bonusObj.Score = 0
|
|
|
|
headlineObj.scoreTotal = 0
|
2023-03-18 18:35:26 +01:00
|
|
|
scoringHeadlines.push(headlineObj)
|
|
|
|
failedBonuses.push(bonusObj)
|
2022-10-20 03:18:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-18 18:35:26 +01:00
|
|
|
totalScore = Math.max(0, totalScore)
|
2022-10-20 03:18:35 +02:00
|
|
|
|
2023-03-18 18:35:26 +01:00
|
|
|
scoringHeadlines.push(
|
2022-10-20 03:18:35 +02:00
|
|
|
Object.assign(Object.assign({}, headlineObjTemplate), {
|
|
|
|
headline: "UI_SCORING_SUMMARY_KILL_PENALTY",
|
|
|
|
count: nonTargetKills > 0 ? `${nonTargetKills}x-5000` : "",
|
|
|
|
scoreTotal: -5000 * nonTargetKills,
|
|
|
|
}) as ScoringHeadline,
|
|
|
|
)
|
|
|
|
|
|
|
|
const timeHours = Math.floor(timeTotal / 3600)
|
|
|
|
const timeMinutes = Math.floor((timeTotal - timeHours * 3600) / 60)
|
|
|
|
const timeSeconds = Math.floor(
|
|
|
|
timeTotal - timeHours * 3600 - timeMinutes * 60,
|
|
|
|
)
|
|
|
|
let timebonus = 0
|
|
|
|
|
|
|
|
// formula from https://hitmanforumarchive.notex.app/#/t/how-the-time-bonus-is-calculated/17438 (https://archive.ph/pRjzI)
|
|
|
|
const scorePoints = [
|
|
|
|
[0, 1.1], // 1.1 bonus multiplier at 0 secs (0 min)
|
|
|
|
[300, 0.7], // 0.7 bonus multiplier at 300 secs (5 min)
|
|
|
|
[900, 0.6], // 0.6 bonus multiplier at 900 secs (15 min)
|
|
|
|
[17100, 0.0], // 0 bonus multiplier at 17100 secs (285 min)
|
|
|
|
]
|
|
|
|
|
|
|
|
let prevsecs: number, prevmultiplier: number
|
|
|
|
|
|
|
|
for (const [secs, multiplier] of scorePoints) {
|
|
|
|
if (timeTotal > secs) {
|
|
|
|
prevsecs = secs
|
|
|
|
prevmultiplier = multiplier
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// linear interpolation between current and previous scorePoints
|
|
|
|
const bonusMultiplier =
|
|
|
|
prevmultiplier! -
|
|
|
|
((prevmultiplier! - multiplier) * (timeTotal - prevsecs!)) /
|
|
|
|
(secs - prevsecs!)
|
2023-03-18 18:35:26 +01:00
|
|
|
|
|
|
|
timebonus = totalScore * bonusMultiplier
|
2022-10-20 03:18:35 +02:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
timebonus = Math.round(timebonus)
|
|
|
|
|
2023-03-18 18:35:26 +01:00
|
|
|
const totalScoreWithBonus = totalScore + timebonus
|
2022-10-20 03:18:35 +02:00
|
|
|
|
2023-03-18 18:35:26 +01:00
|
|
|
awardedBonuses.push({
|
2022-10-20 03:18:35 +02:00
|
|
|
Score: timebonus,
|
|
|
|
Id: "SwiftExecution",
|
|
|
|
FractionNumerator: 0,
|
|
|
|
FractionDenominator: 0,
|
|
|
|
})
|
|
|
|
|
2023-03-18 18:35:26 +01:00
|
|
|
scoringHeadlines.push(
|
2022-10-20 03:18:35 +02:00
|
|
|
Object.assign(Object.assign({}, headlineObjTemplate), {
|
|
|
|
headline: "UI_SCORING_SUMMARY_TIME",
|
|
|
|
count: `${`0${timeHours}`.slice(-2)}:${`0${timeMinutes}`.slice(
|
|
|
|
-2,
|
|
|
|
)}:${`0${timeSeconds}`.slice(-2)}`,
|
|
|
|
scoreTotal: timebonus,
|
|
|
|
}) as ScoringHeadline,
|
|
|
|
)
|
|
|
|
|
|
|
|
for (const type of ["total", "subtotal"]) {
|
2023-03-18 18:35:26 +01:00
|
|
|
scoringHeadlines.push(
|
2022-10-20 03:18:35 +02:00
|
|
|
Object.assign(Object.assign({}, headlineObjTemplate), {
|
|
|
|
type,
|
|
|
|
headline: `UI_SCORING_SUMMARY_${type.toUpperCase()}`,
|
2023-03-18 18:35:26 +01:00
|
|
|
scoreTotal: totalScoreWithBonus,
|
2022-10-20 03:18:35 +02:00
|
|
|
}) as ScoringHeadline,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Stars
|
2023-03-18 18:35:26 +01:00
|
|
|
let stars =
|
|
|
|
5 -
|
|
|
|
[...bonuses, { condition: nonTargetKills === 0 }].filter(
|
|
|
|
(x) => !x!.condition,
|
|
|
|
).length // one star less for each bonus missed
|
2022-10-20 03:18:35 +02:00
|
|
|
|
2023-03-18 18:35:26 +01:00
|
|
|
stars = stars < 0 ? 0 : stars // clamp to 0
|
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Achieved masteries
|
2023-03-18 18:35:26 +01:00
|
|
|
const achievedMasteries = [
|
|
|
|
{
|
|
|
|
score: -5000 * nonTargetKills,
|
|
|
|
RatioParts: nonTargetKills,
|
|
|
|
RatioTotal: nonTargetKills,
|
|
|
|
Id: "KillPenaltyMastery",
|
|
|
|
BaseScore: -5000,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// NOTE: need to have all bonuses except objectives for SA
|
2023-03-18 18:35:26 +01:00
|
|
|
const silentAssassin = [
|
|
|
|
...bonuses.slice(1),
|
|
|
|
{ condition: nonTargetKills === 0 },
|
|
|
|
].every((x) => x.condition)
|
|
|
|
|
|
|
|
return {
|
|
|
|
stars: stars,
|
|
|
|
scoringHeadlines: scoringHeadlines,
|
|
|
|
achievedMasteries: achievedMasteries,
|
|
|
|
awardedBonuses: awardedBonuses,
|
|
|
|
failedBonuses: failedBonuses,
|
|
|
|
silentAssassin: silentAssassin,
|
|
|
|
score: totalScore,
|
|
|
|
scoreWithBonus: totalScoreWithBonus,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-25 00:47:28 +02:00
|
|
|
export function calculateSniperScore(
|
|
|
|
contractSession: ContractSession,
|
|
|
|
timeTotal: Seconds,
|
|
|
|
inventory: InventoryItem[],
|
|
|
|
): [CalculateSniperScoreResult, ScoringHeadline[]] {
|
|
|
|
const timeMinutes = Math.floor(timeTotal / 60)
|
|
|
|
const timeSeconds = Math.floor(timeTotal % 60)
|
|
|
|
const timeMiliseconds = Math.floor(((timeTotal % 60) - timeSeconds) * 1000)
|
|
|
|
|
|
|
|
const bonusTimeStart =
|
|
|
|
contractSession.firstKillTimestamp ?? contractSession.timerStart
|
|
|
|
const bonusTimeEnd = contractSession.timerEnd
|
|
|
|
const bonusTimeTotal: Seconds =
|
|
|
|
(bonusTimeEnd as number) - (bonusTimeStart as number)
|
|
|
|
|
|
|
|
let timeBonus = 0
|
|
|
|
|
|
|
|
// TODO? generate this curve from contractSession.scoring.Settings["timebonus"] somehow
|
|
|
|
const scorePoints = [
|
|
|
|
[0, 50000], // 50000 bonus score at 0 secs (0 min)
|
|
|
|
[240, 40000], // 40000 bonus score at 240 secs (4 min)
|
|
|
|
[480, 35000], // 35000 bonus score at 480 secs (8 min)
|
|
|
|
[900, 0], // 0 bonus score at 900 secs (15 min)
|
|
|
|
]
|
|
|
|
let prevsecs: number, prevscore: number
|
|
|
|
|
|
|
|
for (const [secs, score] of scorePoints) {
|
|
|
|
if (bonusTimeTotal > secs) {
|
|
|
|
prevsecs = secs
|
|
|
|
prevscore = score
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// linear interpolation between current and previous scorePoints
|
|
|
|
timeBonus =
|
|
|
|
prevscore -
|
|
|
|
((prevscore - score) * (bonusTimeTotal - prevsecs)) /
|
|
|
|
(secs - prevsecs)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
timeBonus = Math.floor(timeBonus)
|
|
|
|
|
|
|
|
const defaultHeadline: Partial<ScoringHeadline> = {
|
|
|
|
type: "summary",
|
|
|
|
count: "",
|
|
|
|
scoreIsFloatingType: false,
|
|
|
|
fractionNumerator: 0,
|
|
|
|
fractionDenominator: 0,
|
|
|
|
scoreTotal: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
const baseScore = contractSession.scoring.Context["TotalScore"]
|
|
|
|
const challengeMultiplier = contractSession.scoring.Settings["challenges"][
|
|
|
|
"Unlockables"
|
|
|
|
].reduce((acc, unlockable) => {
|
|
|
|
const item = inventory.find((item) => item.Unlockable.Id === unlockable)
|
|
|
|
|
|
|
|
if (item) {
|
|
|
|
return acc + item.Unlockable.Properties["Multiplier"]
|
|
|
|
}
|
|
|
|
|
|
|
|
return acc
|
|
|
|
}, 1.0)
|
|
|
|
const bulletsMissed = 0 // TODO? not sure if neccessary, the penalty is always 0 for inbuilt contracts
|
|
|
|
const bulletsMissedPenalty =
|
|
|
|
bulletsMissed *
|
|
|
|
contractSession.scoring.Settings["bulletsused"]["penalty"]
|
|
|
|
// Get SA status from global SA challenge for contracttype sniper
|
|
|
|
const silentAssassin =
|
|
|
|
contractSession.challengeContexts[
|
|
|
|
"029c4971-0ddd-47ab-a568-17b007eec04e"
|
|
|
|
].state !== "Failure"
|
|
|
|
const saBonus = silentAssassin
|
|
|
|
? contractSession.scoring.Settings["silentassassin"]["score"]
|
|
|
|
: 0
|
|
|
|
const saMultiplier = silentAssassin
|
|
|
|
? contractSession.scoring.Settings["silentassassin"]["multiplier"]
|
|
|
|
: 1.0
|
|
|
|
|
|
|
|
const subTotalScore = baseScore + timeBonus + saBonus - bulletsMissedPenalty
|
|
|
|
const totalScore = Math.round(
|
|
|
|
subTotalScore * challengeMultiplier * saMultiplier,
|
|
|
|
)
|
|
|
|
|
|
|
|
const headlines = [
|
|
|
|
{
|
|
|
|
headline: "UI_SNIPERSCORING_SUMMARY_BASESCORE",
|
|
|
|
scoreTotal: baseScore,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
headline: "UI_SNIPERSCORING_SUMMARY_BULLETS_MISSED_PENALTY",
|
|
|
|
scoreTotal: bulletsMissedPenalty,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
headline: "UI_SNIPERSCORING_SUMMARY_TIME_BONUS",
|
|
|
|
count: `${String(timeMinutes).padStart(2, "0")}:${String(
|
|
|
|
timeSeconds,
|
|
|
|
).padStart(2, "0")}.${String(timeMiliseconds).padStart(3, "0")}`,
|
|
|
|
scoreTotal: timeBonus,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
headline: "UI_SNIPERSCORING_SUMMARY_SILENT_ASSASIN_BONUS",
|
|
|
|
scoreTotal: saBonus,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
headline: "UI_SNIPERSCORING_SUMMARY_SUBTOTAL",
|
|
|
|
scoreTotal: subTotalScore,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
headline: "UI_SNIPERSCORING_SUMMARY_CHALLENGE_MULTIPLIER",
|
|
|
|
scoreIsFloatingType: true,
|
|
|
|
scoreTotal: challengeMultiplier,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
headline: "UI_SNIPERSCORING_SUMMARY_SILENT_ASSASIN_MULTIPLIER",
|
|
|
|
scoreIsFloatingType: true,
|
|
|
|
scoreTotal: saMultiplier,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "total",
|
|
|
|
headline: "UI_SNIPERSCORING_SUMMARY_TOTAL",
|
|
|
|
scoreTotal: totalScore,
|
|
|
|
},
|
|
|
|
].map((e) => {
|
|
|
|
return Object.assign(
|
|
|
|
Object.assign({}, defaultHeadline),
|
|
|
|
e,
|
|
|
|
) as ScoringHeadline
|
|
|
|
})
|
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
FinalScore: totalScore,
|
|
|
|
BaseScore: baseScore,
|
|
|
|
TotalChallengeMultiplier: challengeMultiplier,
|
|
|
|
BulletsMissed: bulletsMissed,
|
|
|
|
BulletsMissedPenalty: bulletsMissedPenalty,
|
|
|
|
TimeTaken: timeTotal,
|
|
|
|
TimeBonus: timeBonus,
|
|
|
|
SilentAssassin: silentAssassin,
|
|
|
|
SilentAssassinBonus: saBonus,
|
|
|
|
SilentAssassinMultiplier: saMultiplier,
|
|
|
|
},
|
|
|
|
headlines,
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2023-03-18 18:35:26 +01:00
|
|
|
export async function missionEnd(
|
|
|
|
req: RequestWithJwt<MissionEndRequestQuery>,
|
|
|
|
res: Response,
|
|
|
|
): Promise<void> {
|
2023-07-25 00:47:28 +02:00
|
|
|
// TODO: For this entire function, add support for 2016 difficulties
|
2023-04-29 05:39:57 +02:00
|
|
|
// Resolve the contract session
|
2023-03-18 18:35:26 +01:00
|
|
|
if (!req.query.contractSessionId) {
|
|
|
|
res.status(400).end()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const sessionDetails = contractSessions.get(req.query.contractSessionId)
|
|
|
|
|
|
|
|
if (!sessionDetails) {
|
|
|
|
res.status(404).send("contract session not found")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sessionDetails.userId !== req.jwt.unique_name) {
|
|
|
|
res.status(401).send("requested score for other user's session")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Resolve userdata
|
2023-03-18 18:35:26 +01:00
|
|
|
const userData = getUserData(req.jwt.unique_name, req.gameVersion)
|
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Resolve contract data
|
2023-03-18 18:35:26 +01:00
|
|
|
const contractData =
|
|
|
|
req.gameVersion === "scpc" &&
|
|
|
|
sessionDetails.contractId === "ff9f46cf-00bd-4c12-b887-eac491c3a96d"
|
|
|
|
? _theLastYardbirdScpc
|
2023-04-14 04:13:16 +02:00
|
|
|
: controller.resolveContract(sessionDetails.contractId, true)
|
2023-03-18 18:35:26 +01:00
|
|
|
|
|
|
|
if (!contractData) {
|
|
|
|
res.status(404).send("contract not found")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Handle escalation groups
|
2023-04-21 19:48:56 +02:00
|
|
|
if (escalationTypes.includes(contractData.Metadata.Type)) {
|
|
|
|
const eGroupId =
|
|
|
|
contractData.Metadata.InGroup ?? contractData.Metadata.Id
|
2023-03-18 18:35:26 +01:00
|
|
|
|
|
|
|
if (!eGroupId) {
|
|
|
|
log(
|
|
|
|
LogLevel.ERROR,
|
|
|
|
`Unregistered escalation group ${sessionDetails.contractId}`,
|
|
|
|
)
|
|
|
|
res.status(500).end()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!userData.Extensions.PeacockEscalations[eGroupId]) {
|
|
|
|
userData.Extensions.PeacockEscalations[eGroupId] = 1
|
|
|
|
}
|
|
|
|
|
2023-04-14 04:13:16 +02:00
|
|
|
const history: ContractHistory = {
|
|
|
|
LastPlayedAt: new Date().getTime(),
|
|
|
|
IsEscalation: true,
|
|
|
|
}
|
|
|
|
|
2023-03-18 18:35:26 +01:00
|
|
|
if (
|
|
|
|
userData.Extensions.PeacockEscalations[eGroupId] ===
|
2023-04-14 04:13:16 +02:00
|
|
|
getLevelCount(controller.resolveContract(eGroupId))
|
2023-03-18 18:35:26 +01:00
|
|
|
) {
|
|
|
|
// we are on the final level, and the user completed this level
|
|
|
|
if (
|
|
|
|
!userData.Extensions.PeacockCompletedEscalations?.includes(
|
|
|
|
eGroupId,
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
// the user never finished this escalation before
|
|
|
|
userData.Extensions.PeacockCompletedEscalations.push(eGroupId)
|
|
|
|
}
|
2023-04-14 04:13:16 +02:00
|
|
|
|
|
|
|
history.Completed = true
|
2023-03-18 18:35:26 +01:00
|
|
|
} else {
|
|
|
|
// not the final level
|
|
|
|
userData.Extensions.PeacockEscalations[eGroupId] += 1
|
|
|
|
}
|
|
|
|
|
2023-04-14 04:13:16 +02:00
|
|
|
if (!userData.Extensions.PeacockPlayedContracts[eGroupId]) {
|
|
|
|
userData.Extensions.PeacockPlayedContracts[eGroupId] = {}
|
|
|
|
}
|
|
|
|
|
|
|
|
userData.Extensions.PeacockPlayedContracts[eGroupId] = history
|
|
|
|
|
2023-03-21 01:12:54 +01:00
|
|
|
writeUserData(req.jwt.unique_name, req.gameVersion)
|
|
|
|
} else if (contractTypes.includes(contractData.Metadata.Type)) {
|
|
|
|
// Update the contract in the played list
|
|
|
|
const id = contractData.Metadata.Id
|
|
|
|
|
|
|
|
if (!userData.Extensions.PeacockPlayedContracts[id]) {
|
|
|
|
userData.Extensions.PeacockPlayedContracts[id] = {}
|
|
|
|
}
|
|
|
|
|
2023-04-14 04:13:16 +02:00
|
|
|
userData.Extensions.PeacockPlayedContracts[id] = {
|
|
|
|
LastPlayedAt: new Date().getTime(),
|
|
|
|
Completed: true,
|
|
|
|
}
|
|
|
|
|
2023-03-18 18:35:26 +01:00
|
|
|
writeUserData(req.jwt.unique_name, req.gameVersion)
|
|
|
|
}
|
|
|
|
|
2023-04-21 19:48:56 +02:00
|
|
|
const levelData = controller.resolveContract(
|
|
|
|
sessionDetails.contractId,
|
|
|
|
false,
|
|
|
|
)
|
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Resolve the id of the parent location
|
2023-03-18 18:35:26 +01:00
|
|
|
const subLocation = getSubLocationByName(
|
2023-04-21 19:48:56 +02:00
|
|
|
levelData.Metadata.Location,
|
2023-03-18 18:35:26 +01:00
|
|
|
req.gameVersion,
|
|
|
|
)
|
|
|
|
|
|
|
|
const locationParentId = subLocation
|
|
|
|
? subLocation.Properties?.ParentLocation
|
2023-04-21 19:48:56 +02:00
|
|
|
: levelData.Metadata.Location
|
2023-03-18 18:35:26 +01:00
|
|
|
|
|
|
|
if (!locationParentId) {
|
|
|
|
res.status(404).send("location parentid not found")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Resolve all opportunities for the location
|
2023-03-18 18:35:26 +01:00
|
|
|
const opportunities = contractData.Metadata.Opportunities
|
|
|
|
const opportunityCount = opportunities ? opportunities.length : 0
|
|
|
|
const opportunityCompleted = opportunities
|
|
|
|
? opportunities.filter(
|
|
|
|
(ms) => ms in userData.Extensions.opportunityprogression,
|
|
|
|
).length
|
|
|
|
: 0
|
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Resolve all challenges for the location
|
2023-03-18 18:35:26 +01:00
|
|
|
const locationChallenges =
|
|
|
|
controller.challengeService.getGroupedChallengeLists(
|
|
|
|
{
|
2023-04-15 00:41:43 +02:00
|
|
|
type: ChallengeFilterType.ParentLocation,
|
2023-04-21 19:48:56 +02:00
|
|
|
parent: locationParentId,
|
2023-03-18 18:35:26 +01:00
|
|
|
},
|
|
|
|
locationParentId,
|
2023-04-05 21:02:25 +02:00
|
|
|
req.gameVersion,
|
2023-03-18 18:35:26 +01:00
|
|
|
)
|
|
|
|
const contractChallenges =
|
|
|
|
controller.challengeService.getChallengesForContract(
|
|
|
|
sessionDetails.contractId,
|
|
|
|
req.gameVersion,
|
2023-04-21 19:48:56 +02:00
|
|
|
req.jwt.unique_name,
|
2023-04-05 21:02:25 +02:00
|
|
|
sessionDetails.difficulty,
|
2023-03-18 18:35:26 +01:00
|
|
|
)
|
|
|
|
const locationChallengeCompletion =
|
|
|
|
controller.challengeService.countTotalNCompletedChallenges(
|
|
|
|
locationChallenges,
|
|
|
|
userData.Id,
|
|
|
|
req.gameVersion,
|
|
|
|
)
|
|
|
|
|
|
|
|
const contractChallengeCompletion =
|
|
|
|
controller.challengeService.countTotalNCompletedChallenges(
|
|
|
|
contractChallenges,
|
|
|
|
userData.Id,
|
|
|
|
req.gameVersion,
|
|
|
|
)
|
|
|
|
|
|
|
|
const locationPercentageComplete = getCompletionPercent(
|
|
|
|
locationChallengeCompletion.CompletedChallengesCount,
|
|
|
|
locationChallengeCompletion.ChallengesCount,
|
|
|
|
opportunityCompleted,
|
|
|
|
opportunityCount,
|
|
|
|
)
|
|
|
|
|
|
|
|
const playerProgressionData =
|
|
|
|
userData.Extensions.progression.PlayerProfileXP
|
|
|
|
|
2023-04-22 19:59:47 +02:00
|
|
|
// Calculate XP based on global challenges.
|
|
|
|
const calculateXpResult: CalculateXpResult = calculateGlobalXp(
|
2023-04-05 21:02:25 +02:00
|
|
|
sessionDetails,
|
|
|
|
req.gameVersion,
|
|
|
|
)
|
2023-03-18 18:35:26 +01:00
|
|
|
let justTickedChallenges = 0
|
2023-04-22 19:59:47 +02:00
|
|
|
let totalXpGain = calculateXpResult.xp
|
2023-03-18 18:35:26 +01:00
|
|
|
|
2023-04-27 08:12:55 +02:00
|
|
|
// Calculate XP based on non-global challenges. Remember to add elusive challenges of the contract
|
|
|
|
Object.values({
|
|
|
|
...locationChallenges,
|
|
|
|
...(Object.keys(contractChallenges).includes("elusive") && {
|
|
|
|
elusive: contractChallenges.elusive,
|
|
|
|
}),
|
|
|
|
})
|
2023-03-18 18:35:26 +01:00
|
|
|
.flat()
|
|
|
|
.filter((challengeData) => {
|
|
|
|
return (
|
|
|
|
!challengeData.Tags.includes("global") &&
|
|
|
|
controller.challengeService.fastGetIsUnticked(
|
|
|
|
userData,
|
|
|
|
challengeData.Id,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.forEach((challengeData) => {
|
|
|
|
const userId = req.jwt.unique_name
|
|
|
|
const gameVersion = req.gameVersion
|
|
|
|
|
|
|
|
userData.Extensions.ChallengeProgression[challengeData.Id].Ticked =
|
|
|
|
true
|
|
|
|
writeUserData(userId, gameVersion)
|
|
|
|
|
|
|
|
justTickedChallenges++
|
|
|
|
|
2023-04-22 19:59:47 +02:00
|
|
|
totalXpGain += challengeData.Rewards.MasteryXP
|
2023-03-18 18:35:26 +01:00
|
|
|
|
|
|
|
calculateXpResult.completedChallenges.push({
|
|
|
|
ChallengeId: challengeData.Id,
|
|
|
|
ChallengeTags: challengeData.Tags,
|
|
|
|
ChallengeName: challengeData.Name,
|
|
|
|
ChallengeImageUrl: challengeData.ImageName,
|
|
|
|
ChallengeDescription: challengeData.Description,
|
|
|
|
XPGain: challengeData.Rewards.MasteryXP,
|
|
|
|
IsGlobal: false,
|
|
|
|
IsActionReward: challengeData.Tags.includes("actionreward"),
|
|
|
|
Drops: challengeData.Drops,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2023-07-25 00:47:28 +02:00
|
|
|
let completionData = generateCompletionData(
|
2023-04-21 19:48:56 +02:00
|
|
|
levelData.Metadata.Location,
|
2023-03-24 14:19:01 +01:00
|
|
|
req.jwt.unique_name,
|
|
|
|
req.gameVersion,
|
|
|
|
contractData.Metadata.Type,
|
2023-07-25 00:47:28 +02:00
|
|
|
req.query.masteryUnlockableId,
|
2023-03-24 14:19:01 +01:00
|
|
|
)
|
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Calculate the old location progression based on the current one and process it
|
2023-04-22 19:59:47 +02:00
|
|
|
const oldLocationXp = completionData.PreviouslySeenXp
|
|
|
|
? completionData.PreviouslySeenXp
|
|
|
|
: completionData.XP - totalXpGain
|
2023-03-18 18:35:26 +01:00
|
|
|
let oldLocationLevel = levelForXp(oldLocationXp)
|
2023-04-22 19:59:47 +02:00
|
|
|
|
2023-03-24 14:19:01 +01:00
|
|
|
const newLocationXp = completionData.XP
|
2023-03-18 18:35:26 +01:00
|
|
|
let newLocationLevel = levelForXp(newLocationXp)
|
2023-07-25 00:47:28 +02:00
|
|
|
|
|
|
|
if (!req.query.masteryUnlockableId) {
|
|
|
|
userData.Extensions.progression.Locations[
|
|
|
|
locationParentId
|
|
|
|
].PreviouslySeenXp = newLocationXp
|
|
|
|
}
|
|
|
|
|
2023-04-22 19:59:47 +02:00
|
|
|
writeUserData(req.jwt.unique_name, req.gameVersion)
|
2023-03-18 18:35:26 +01:00
|
|
|
|
2023-07-25 00:47:28 +02:00
|
|
|
const masteryData = controller.masteryService.getMasteryPackage(
|
|
|
|
locationParentId,
|
|
|
|
req.gameVersion,
|
|
|
|
)
|
2023-03-18 18:35:26 +01:00
|
|
|
|
2023-03-19 03:04:23 +01:00
|
|
|
let maxLevel = 1
|
|
|
|
let locationLevelInfo = [0]
|
2023-03-18 18:35:26 +01:00
|
|
|
|
2023-03-19 03:04:23 +01:00
|
|
|
if (masteryData) {
|
2023-07-25 00:47:28 +02:00
|
|
|
maxLevel =
|
|
|
|
(req.query.masteryUnlockableId
|
|
|
|
? masteryData.SubPackages.find(
|
|
|
|
(subPkg) => subPkg.Id === req.query.masteryUnlockableId,
|
|
|
|
).MaxLevel
|
|
|
|
: masteryData.MaxLevel) || DEFAULT_MASTERY_MAXLEVEL
|
2023-03-19 03:04:23 +01:00
|
|
|
|
2023-03-19 20:20:31 +01:00
|
|
|
locationLevelInfo = Array.from({ length: maxLevel }, (_, i) => {
|
2023-03-19 03:04:23 +01:00
|
|
|
return xpRequiredForLevel(i + 1)
|
|
|
|
})
|
|
|
|
}
|
2023-03-18 18:35:26 +01:00
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Calculate the old playerprofile progression based on the current one and process it
|
2023-03-18 18:35:26 +01:00
|
|
|
const oldPlayerProfileXp = playerProgressionData.Total - totalXpGain
|
|
|
|
const oldPlayerProfileLevel = levelForXp(oldPlayerProfileXp)
|
|
|
|
const newPlayerProfileXp = playerProgressionData.Total
|
|
|
|
const newPlayerProfileLevel = levelForXp(newPlayerProfileXp)
|
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// NOTE: We assume the ProfileLevel is currently already up-to-date
|
2023-03-18 18:35:26 +01:00
|
|
|
const profileLevelInfo = []
|
|
|
|
|
|
|
|
for (
|
|
|
|
let level = oldPlayerProfileLevel;
|
|
|
|
level <= newPlayerProfileLevel + 1;
|
|
|
|
level++
|
|
|
|
) {
|
|
|
|
profileLevelInfo.push(xpRequiredForLevel(level))
|
|
|
|
}
|
|
|
|
|
|
|
|
const profileLevelInfoOffset = oldPlayerProfileLevel - 1
|
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Time
|
2023-03-18 22:53:14 +01:00
|
|
|
const timeTotal: Seconds =
|
|
|
|
(sessionDetails.timerEnd as number) -
|
|
|
|
(sessionDetails.timerStart as number)
|
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Playstyle
|
2023-03-18 22:53:14 +01:00
|
|
|
const calculatedPlaystyles = calculatePlaystyle(sessionDetails)
|
|
|
|
|
|
|
|
let playstyle =
|
|
|
|
calculatedPlaystyles[0].Score !== 0
|
|
|
|
? calculatedPlaystyles[0]
|
|
|
|
: undefined
|
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Calculate score and summary
|
2023-03-18 22:53:14 +01:00
|
|
|
const calculateScoreResult = calculateScore(
|
|
|
|
req.gameVersion,
|
|
|
|
sessionDetails,
|
|
|
|
contractData,
|
|
|
|
timeTotal,
|
|
|
|
)
|
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Evergreen
|
2023-03-18 22:53:14 +01:00
|
|
|
const evergreenData: MissionEndEvergreen = <MissionEndEvergreen>{
|
|
|
|
PayoutsCompleted: [],
|
|
|
|
PayoutsFailed: [],
|
|
|
|
}
|
2023-03-18 18:35:26 +01:00
|
|
|
|
|
|
|
if (contractData.Metadata.Type === "evergreen") {
|
2023-03-18 22:53:14 +01:00
|
|
|
const gameChangerProperties = getConfig<Record<string, GameChanger>>(
|
|
|
|
"EvergreenGameChangerProperties",
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
|
|
|
|
let totalPayout = 0
|
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// ASSUMPTION: All payout objectives have a "condition"-category objective
|
|
|
|
// and a "secondary"-category objective with a "MyPayout" in the context.
|
2023-03-18 22:53:14 +01:00
|
|
|
Object.keys(gameChangerProperties).forEach((e) => {
|
|
|
|
const gameChanger = gameChangerProperties[e]
|
|
|
|
|
|
|
|
const conditionObjective = gameChanger.Objectives.find(
|
|
|
|
(e) => e.Category === "condition",
|
|
|
|
)
|
|
|
|
|
|
|
|
const secondaryObjective = gameChanger.Objectives.find(
|
|
|
|
(e) =>
|
|
|
|
e.Category === "secondary" &&
|
|
|
|
e.Definition.Context["MyPayout"],
|
|
|
|
)
|
|
|
|
|
|
|
|
if (
|
|
|
|
conditionObjective &&
|
|
|
|
secondaryObjective &&
|
|
|
|
sessionDetails.objectiveStates.get(conditionObjective.Id) ===
|
|
|
|
"Success"
|
|
|
|
) {
|
|
|
|
const payoutObjective = {
|
|
|
|
Name: gameChanger.Name,
|
|
|
|
Payout: parseInt(
|
|
|
|
sessionDetails.objectiveContexts.get(
|
|
|
|
secondaryObjective.Id,
|
|
|
|
)["MyPayout"] || 0,
|
|
|
|
),
|
|
|
|
IsPrestige: gameChanger.IsPrestigeObjective || false,
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
2023-03-19 04:25:52 +01:00
|
|
|
!sessionDetails.evergreen.failed &&
|
2023-03-18 22:53:14 +01:00
|
|
|
sessionDetails.objectiveStates.get(
|
|
|
|
secondaryObjective.Id,
|
|
|
|
) === "Success"
|
|
|
|
) {
|
|
|
|
totalPayout += payoutObjective.Payout
|
|
|
|
evergreenData.PayoutsCompleted.push(payoutObjective)
|
|
|
|
} else {
|
|
|
|
evergreenData.PayoutsFailed.push(payoutObjective)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
evergreenData.Payout = totalPayout
|
2023-03-18 18:35:26 +01:00
|
|
|
evergreenData.EndStateEventName =
|
|
|
|
sessionDetails.evergreen.scoringScreenEndState
|
|
|
|
|
|
|
|
locationLevelInfo = EVERGREEN_LEVEL_INFO
|
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Override the location levels to trigger potential drops
|
2023-04-22 19:59:47 +02:00
|
|
|
oldLocationLevel = evergreenLevelForXp(oldLocationXp)
|
2023-03-24 14:19:01 +01:00
|
|
|
newLocationLevel = completionData.Level
|
2023-03-18 18:35:26 +01:00
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Override the silent assassin rank
|
2023-03-18 22:53:14 +01:00
|
|
|
if (calculateScoreResult.silentAssassin) {
|
|
|
|
playstyle = {
|
|
|
|
Id: "595f6ff1-85bf-4e4f-a9ee-76038a455648",
|
|
|
|
Name: "UI_PLAYSTYLE_ICA_STEALTH_ASSASSIN",
|
|
|
|
Type: "STEALTH_ASSASSIN",
|
|
|
|
Score: 0,
|
|
|
|
}
|
|
|
|
}
|
2023-03-18 18:35:26 +01:00
|
|
|
|
2023-03-18 22:53:14 +01:00
|
|
|
calculateScoreResult.silentAssassin = false
|
2023-03-19 03:04:23 +01:00
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Overide the calculated score
|
2023-03-19 03:04:23 +01:00
|
|
|
calculateScoreResult.stars = undefined
|
|
|
|
}
|
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Sniper
|
2023-03-19 03:04:23 +01:00
|
|
|
let unlockableProgression = undefined
|
|
|
|
let sniperChallengeScore = undefined
|
|
|
|
|
2023-03-26 23:20:55 +02:00
|
|
|
let contractScore = {
|
|
|
|
Total: calculateScoreResult.scoreWithBonus,
|
|
|
|
AchievedMasteries: calculateScoreResult.achievedMasteries,
|
|
|
|
AwardedBonuses: calculateScoreResult.awardedBonuses,
|
|
|
|
TotalNoMultipliers: calculateScoreResult.score,
|
|
|
|
TimeUsedSecs: timeTotal,
|
|
|
|
StarCount: calculateScoreResult.stars,
|
|
|
|
FailedBonuses: calculateScoreResult.failedBonuses,
|
|
|
|
SilentAssassin: calculateScoreResult.silentAssassin,
|
|
|
|
}
|
|
|
|
|
2023-03-19 03:04:23 +01:00
|
|
|
if (contractData.Metadata.Type === "sniper") {
|
2023-07-25 00:47:28 +02:00
|
|
|
const userInventory = createInventory(
|
|
|
|
req.jwt.unique_name,
|
|
|
|
req.gameVersion,
|
|
|
|
undefined,
|
|
|
|
)
|
2023-03-19 03:04:23 +01:00
|
|
|
|
2023-07-25 00:47:28 +02:00
|
|
|
const [sniperScore, headlines] = calculateSniperScore(
|
|
|
|
sessionDetails,
|
|
|
|
timeTotal,
|
|
|
|
userInventory,
|
|
|
|
)
|
|
|
|
sniperChallengeScore = sniperScore
|
|
|
|
|
|
|
|
// Grant sniper mastery
|
|
|
|
controller.progressionService.grantProfileProgression(
|
|
|
|
0,
|
|
|
|
sniperScore.FinalScore,
|
|
|
|
[],
|
|
|
|
sessionDetails,
|
|
|
|
userData,
|
|
|
|
locationParentId,
|
|
|
|
req.query.masteryUnlockableId,
|
|
|
|
)
|
|
|
|
|
|
|
|
// Update completion data with latest mastery
|
|
|
|
locationLevelInfo = SNIPER_LEVEL_INFO
|
|
|
|
oldLocationLevel = sniperLevelForXp(oldLocationXp)
|
2023-03-19 03:04:23 +01:00
|
|
|
|
2023-07-25 00:47:28 +02:00
|
|
|
// Temporarily get completion data for the unlockable
|
|
|
|
completionData = generateCompletionData(
|
|
|
|
levelData.Metadata.Location,
|
|
|
|
req.jwt.unique_name,
|
|
|
|
req.gameVersion,
|
|
|
|
"sniper", // We know the type will be sniper.
|
|
|
|
req.query.masteryUnlockableId,
|
|
|
|
)
|
|
|
|
newLocationLevel = completionData.Level
|
2023-03-19 03:04:23 +01:00
|
|
|
unlockableProgression = {
|
2023-07-25 00:47:28 +02:00
|
|
|
Id: completionData.Id,
|
|
|
|
Level: completionData.Level,
|
|
|
|
LevelInfo: locationLevelInfo,
|
|
|
|
Name: completionData.Name,
|
|
|
|
XP: completionData.XP,
|
|
|
|
XPGain:
|
|
|
|
completionData.Level === completionData.MaxLevel
|
|
|
|
? 0
|
|
|
|
: sniperScore.FinalScore,
|
2023-03-19 03:04:23 +01:00
|
|
|
}
|
|
|
|
|
2023-07-25 00:47:28 +02:00
|
|
|
userData.Extensions.progression.Locations[locationParentId][
|
|
|
|
req.query.masteryUnlockableId
|
|
|
|
].PreviouslySeenXp = completionData.XP
|
|
|
|
|
|
|
|
writeUserData(req.jwt.unique_name, req.gameVersion)
|
|
|
|
|
|
|
|
// Set the completion data to the location so the end screen formats properly.
|
|
|
|
completionData = generateCompletionData(
|
|
|
|
levelData.Metadata.Location,
|
|
|
|
req.jwt.unique_name,
|
|
|
|
req.gameVersion,
|
|
|
|
)
|
2023-03-19 03:04:23 +01:00
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Override the contract score
|
2023-03-19 03:04:23 +01:00
|
|
|
contractScore = undefined
|
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Override the playstyle
|
2023-03-19 03:04:23 +01:00
|
|
|
playstyle = undefined
|
|
|
|
|
|
|
|
calculateScoreResult.stars = undefined
|
2023-07-25 00:47:28 +02:00
|
|
|
calculateScoreResult.scoringHeadlines = headlines
|
2023-03-18 18:35:26 +01:00
|
|
|
}
|
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Mastery Drops
|
2023-04-05 21:19:28 +02:00
|
|
|
let masteryDrops: MissionEndDrop[] = []
|
2023-03-18 18:35:26 +01:00
|
|
|
|
|
|
|
if (newLocationLevel - oldLocationLevel > 0) {
|
2023-07-25 00:47:28 +02:00
|
|
|
// We get the subpackage as it functions like getMasteryDataForDestination
|
|
|
|
// but allows us to get the specific unlockable if required.
|
2023-03-18 18:35:26 +01:00
|
|
|
const masteryData =
|
2023-07-25 00:47:28 +02:00
|
|
|
controller.masteryService.getMasteryDataForSubPackage(
|
2023-03-18 18:35:26 +01:00
|
|
|
locationParentId,
|
2023-07-25 00:47:28 +02:00
|
|
|
req.query.masteryUnlockableId ?? undefined,
|
2023-03-18 18:35:26 +01:00
|
|
|
req.gameVersion,
|
|
|
|
req.jwt.unique_name,
|
2023-07-25 00:47:28 +02:00
|
|
|
) as MasteryData
|
2023-03-18 18:35:26 +01:00
|
|
|
|
2023-07-25 00:47:28 +02:00
|
|
|
if (masteryData) {
|
|
|
|
masteryDrops = masteryData.Drops.filter(
|
2023-03-19 03:04:23 +01:00
|
|
|
(e) =>
|
|
|
|
e.Level > oldLocationLevel && e.Level <= newLocationLevel,
|
|
|
|
).map((e) => {
|
|
|
|
return {
|
|
|
|
Unlockable: e.Unlockable,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2023-03-18 18:35:26 +01:00
|
|
|
}
|
|
|
|
|
2023-04-05 21:19:28 +02:00
|
|
|
// Challenge Drops
|
|
|
|
const challengeDrops: MissionEndDrop[] =
|
|
|
|
calculateXpResult.completedChallenges.reduce((acc, challenge) => {
|
|
|
|
if (challenge?.Drops?.length) {
|
2023-06-14 17:36:07 +02:00
|
|
|
const drops = getUnlockablesById(
|
2023-04-05 21:19:28 +02:00
|
|
|
challenge.Drops,
|
2023-06-14 17:36:07 +02:00
|
|
|
req.gameVersion,
|
2023-04-05 21:19:28 +02:00
|
|
|
)
|
|
|
|
delete challenge.Drops
|
|
|
|
|
|
|
|
for (const drop of drops) {
|
|
|
|
acc.push({
|
|
|
|
Unlockable: drop,
|
|
|
|
SourceChallenge: challenge,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-04-29 05:39:57 +02:00
|
|
|
|
2023-04-05 21:19:28 +02:00
|
|
|
return acc
|
|
|
|
}, [])
|
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Setup the result
|
2023-03-18 18:35:26 +01:00
|
|
|
const result: MissionEndResponse = {
|
|
|
|
MissionReward: {
|
|
|
|
LocationProgression: {
|
|
|
|
LevelInfo: locationLevelInfo,
|
|
|
|
XP: completionData.XP,
|
|
|
|
Level: completionData.Level,
|
|
|
|
Completion: completionData.Completion,
|
2023-04-29 05:39:57 +02:00
|
|
|
// NOTE: Official makes this 0 if maximum Mastery is reached
|
2023-03-18 18:35:26 +01:00
|
|
|
XPGain: completionData.Level === maxLevel ? 0 : totalXpGain,
|
2023-03-19 03:04:23 +01:00
|
|
|
HideProgression: masteryData?.HideProgression || false,
|
2023-03-18 18:35:26 +01:00
|
|
|
},
|
|
|
|
ProfileProgression: {
|
|
|
|
LevelInfo: profileLevelInfo,
|
|
|
|
LevelInfoOffset: profileLevelInfoOffset,
|
|
|
|
XP: newPlayerProfileXp,
|
|
|
|
Level: newPlayerProfileLevel,
|
|
|
|
XPGain: totalXpGain,
|
|
|
|
},
|
|
|
|
Challenges: calculateXpResult.completedChallenges,
|
2023-04-05 21:19:28 +02:00
|
|
|
Drops: [...masteryDrops, ...challengeDrops],
|
2023-04-29 05:39:57 +02:00
|
|
|
// TODO: Do these exist? Appears to be optional.
|
2023-03-18 18:35:26 +01:00
|
|
|
OpportunityRewards: [],
|
2023-03-19 03:04:23 +01:00
|
|
|
UnlockableProgression: unlockableProgression,
|
2023-03-18 18:35:26 +01:00
|
|
|
CompletionData: completionData,
|
|
|
|
ChallengeCompletion: locationChallengeCompletion,
|
|
|
|
ContractChallengeCompletion: contractChallengeCompletion,
|
|
|
|
OpportunityStatistics: {
|
|
|
|
Count: opportunityCount,
|
|
|
|
Completed: opportunityCompleted,
|
|
|
|
},
|
|
|
|
LocationCompletionPercent: locationPercentageComplete,
|
|
|
|
},
|
|
|
|
ScoreOverview: {
|
|
|
|
XP: completionData.XP,
|
|
|
|
Level: completionData.Level,
|
|
|
|
Completion: completionData.Completion,
|
2023-04-29 05:39:57 +02:00
|
|
|
// NOTE: Official appears to always make this 0
|
2023-03-18 18:35:26 +01:00
|
|
|
XPGain: 0,
|
|
|
|
ChallengesCompleted: justTickedChallenges,
|
2023-03-19 03:04:23 +01:00
|
|
|
LocationHideProgression: masteryData?.HideProgression || false,
|
2023-03-18 18:35:26 +01:00
|
|
|
ProdileId1: req.jwt.unique_name,
|
|
|
|
stars: calculateScoreResult.stars,
|
|
|
|
ScoreDetails: {
|
|
|
|
Headlines: calculateScoreResult.scoringHeadlines,
|
|
|
|
},
|
2023-03-19 03:04:23 +01:00
|
|
|
ContractScore: contractScore,
|
|
|
|
SniperChallengeScore: sniperChallengeScore,
|
|
|
|
SilentAssassin:
|
|
|
|
contractScore?.SilentAssassin ||
|
|
|
|
sniperChallengeScore?.silentAssassin ||
|
|
|
|
false,
|
2023-04-29 05:39:57 +02:00
|
|
|
// TODO: Use data from the leaderboard?
|
2023-03-18 18:35:26 +01:00
|
|
|
NewRank: 1,
|
|
|
|
RankCount: 1,
|
|
|
|
Rank: 1,
|
|
|
|
FriendsRankCount: 1,
|
|
|
|
FriendsRank: 1,
|
|
|
|
IsPartOfTopScores: false,
|
|
|
|
PlayStyle: playstyle,
|
|
|
|
IsNewBestScore: false,
|
|
|
|
IsNewBestTime: false,
|
|
|
|
IsNewBestStars: false,
|
|
|
|
Evergreen: evergreenData,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-04-29 05:39:57 +02:00
|
|
|
// Finalize the response
|
2022-10-20 03:18:35 +02:00
|
|
|
if ((getFlag("autoSplitterForceSilentAssassin") as boolean) === true) {
|
|
|
|
if (result.ScoreOverview.SilentAssassin) {
|
|
|
|
await liveSplitManager.completeMission(timeTotal)
|
|
|
|
} else {
|
|
|
|
await liveSplitManager.failMission(timeTotal)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
await liveSplitManager.completeMission(timeTotal)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
getFlag("leaderboards") === true &&
|
|
|
|
sessionDetails.compat === true &&
|
2023-07-25 00:47:28 +02:00
|
|
|
contractData.Metadata.Type !== "vsrace" &&
|
|
|
|
contractData.Metadata.Type !== "evergreen" &&
|
|
|
|
// Disable sending sniper scores for now
|
|
|
|
contractData.Metadata.Type !== "sniper"
|
2022-10-20 03:18:35 +02:00
|
|
|
) {
|
|
|
|
try {
|
|
|
|
// update leaderboards
|
|
|
|
await axios.post(
|
|
|
|
`${getFlag("leaderboardsHost")}/leaderboards/commit`,
|
|
|
|
{
|
|
|
|
contractId: sessionDetails.contractId,
|
|
|
|
gameDifficulty: difficultyToString(
|
|
|
|
sessionDetails.difficulty,
|
|
|
|
),
|
|
|
|
gameVersion: req.gameVersion,
|
|
|
|
platform: req.jwt.platform,
|
|
|
|
username: userData.Gamertag,
|
|
|
|
platformId:
|
|
|
|
req.jwt.platform === "epic"
|
|
|
|
? userData.EpicId
|
|
|
|
: userData.SteamId,
|
2023-03-18 18:35:26 +01:00
|
|
|
score: calculateScoreResult.scoreWithBonus,
|
2022-10-20 03:18:35 +02:00
|
|
|
data: {
|
|
|
|
Score: {
|
2023-03-18 18:35:26 +01:00
|
|
|
Total: calculateScoreResult.scoreWithBonus,
|
2022-10-20 03:18:35 +02:00
|
|
|
AchievedMasteries:
|
|
|
|
result.ScoreOverview.ContractScore
|
|
|
|
.AchievedMasteries,
|
|
|
|
AwardedBonuses:
|
|
|
|
result.ScoreOverview.ContractScore
|
|
|
|
.AwardedBonuses,
|
|
|
|
TotalNoMultipliers:
|
|
|
|
result.ScoreOverview.ContractScore
|
|
|
|
.TotalNoMultipliers,
|
|
|
|
TimeUsedSecs:
|
|
|
|
result.ScoreOverview.ContractScore.TimeUsedSecs,
|
|
|
|
FailedBonuses: null,
|
|
|
|
IsVR: false,
|
|
|
|
SilentAssassin: result.ScoreOverview.SilentAssassin,
|
2023-03-18 18:35:26 +01:00
|
|
|
StarCount: calculateScoreResult.stars,
|
2022-10-20 03:18:35 +02:00
|
|
|
},
|
|
|
|
GroupIndex: 0,
|
2023-07-25 00:47:28 +02:00
|
|
|
SniperChallengeScore: sniperChallengeScore,
|
2022-10-20 03:18:35 +02:00
|
|
|
PlayStyle: result.ScoreOverview.PlayStyle || null,
|
|
|
|
Description: "UI_MENU_SCORE_CONTRACT_COMPLETED",
|
|
|
|
ContractSessionId: req.query.contractSessionId,
|
|
|
|
Percentile: {
|
|
|
|
Spread: Array(10).fill(0),
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
peacockHeadlines:
|
|
|
|
result.ScoreOverview.ScoreDetails.Headlines,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
headers: {
|
|
|
|
"Peacock-Version": PEACOCKVERSTRING,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
} catch (e) {
|
|
|
|
handleAxiosError(e)
|
|
|
|
log(
|
|
|
|
LogLevel.WARN,
|
|
|
|
"Failed to commit leaderboards data! Either you or the server may be offline.",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
res.json({
|
|
|
|
template:
|
|
|
|
req.gameVersion === "scpc"
|
|
|
|
? getConfig("FrankensteinScoreOverviewTemplate", false)
|
|
|
|
: null,
|
|
|
|
data: result,
|
|
|
|
})
|
|
|
|
}
|