Skip to content

Commit

Permalink
Grant mastery drops on mission end
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyFuller committed Aug 18, 2024
1 parent 7f0f54e commit 53302ed
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions components/scoreHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
sniperLevelForXp,
xpRequiredForLevel,
} from "./utils"
import { contractSessions, getCurrentState } from "./eventHandler"
import { contractSessions, enqueueEvent, getCurrentState } from "./eventHandler"
import { getConfig } from "./configSwizzleManager"
import { controller } from "./controller"
import type {
Expand Down Expand Up @@ -72,7 +72,12 @@ import {
MissionEndResult,
} from "./types/score"
import { MasteryData } from "./types/mastery"
import { createInventory, getUnlockablesById, InventoryItem } from "./inventory"
import {
createInventory,
getUnlockablesById,
grantDrops,
InventoryItem,
} from "./inventory"
import { calculatePlaystyle } from "./playStyles"
import assert from "assert"

Expand Down Expand Up @@ -1016,11 +1021,7 @@ export async function getMissionEndData(
}

if (contractData.Metadata.Type === "sniper") {
const userInventory = createInventory(
jwt.unique_name,
gameVersion,
undefined,
)
const userInventory = createInventory(jwt.unique_name, gameVersion)

const [sniperScore, headlines] = calculateSniperScore(
sessionDetails,
Expand Down Expand Up @@ -1113,6 +1114,41 @@ export async function getMissionEndData(
Unlockable: e.Unlockable,
}))
}

// If this isn't a dry run, tell the user that their level has changed,
// so we can pop the achievement.
if (!isDryRun) {
enqueueEvent(jwt.unique_name, {
Name: "Progression_LevelGain",
Value: {
Location: levelData.Metadata.Location,
NewLevel: newLocationLevel,
},
Version: {
_Major: 8,
_Minor: 15,
_Build: 0,
_Revision: 0,
},
})
}
}

// If this isn't a dry run (and mastery progression is enabled), grant drops
// if the user's inventory doesn't already have it.
if (!isDryRun && getFlag("enableMasteryProgression")) {
const userInventory = createInventory(jwt.unique_name, gameVersion)

const toGrant = masteryDrops
.filter(
(drop) =>
!userInventory.some(
(e) => e.Unlockable.Id === drop.Unlockable.Id,
),
)
.map((e) => e.Unlockable)

grantDrops(jwt.unique_name, toGrant)
}

// Challenge Drops
Expand Down

0 comments on commit 53302ed

Please sign in to comment.