Skip to content

Commit

Permalink
Gnarly stashpoint refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Reece Dunham <[email protected]>
  • Loading branch information
RDIL committed Dec 17, 2023
1 parent 3b869d8 commit c08d0f5
Show file tree
Hide file tree
Showing 8 changed files with 490 additions and 468 deletions.
213 changes: 1 addition & 212 deletions components/2016/legacyMenuData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,223 +19,13 @@
import { Router } from "express"
import { RequestWithJwt } from "../types/types"
import { getConfig } from "../configSwizzleManager"
import { getDefaultSuitFor, uuidRegex } from "../utils"
import { json as jsonMiddleware } from "body-parser"
import { controller } from "../controller"
import {
generateUserCentric,
getParentLocationByName,
getSubLocationByName,
} from "../contracts/dataGen"
import { getUserData } from "../databaseHandler"
import { log, LogLevel } from "../loggingInterop"
import { createInventory, getUnlockableById } from "../inventory"
import { getFlag } from "../flags"
import { loadouts } from "../loadouts"
import { StashpointQueryH2016, StashpointSlotName } from "../types/gameSchemas"
import { getParentLocationByName } from "../contracts/dataGen"

const legacyMenuDataRouter = Router()

legacyMenuDataRouter.get(
"/stashpoint",
(req: RequestWithJwt<StashpointQueryH2016>, res) => {
if (!uuidRegex.test(req.query.contractid)) {
res.status(400).send("contract id was not a uuid")
return
}

if (typeof req.query.slotname !== "string") {
res.status(400).send("invalid slot data")
return
}

const contractData = controller.resolveContract(req.query.contractid)

if (!contractData) {
res.status(404).send("contract not found")
return
}

const loadoutSlots: StashpointSlotName[] = [
"carriedweapon",
"carrieditem",
"concealedweapon",
"disguise",
"gear",
"gear",
"stashpoint",
]

if (loadoutSlots.includes(req.query.slotname.slice(0, -1))) {
req.query.slotid = req.query.slotname.slice(0, -1)
} else {
log(
LogLevel.ERROR,
`Unknown slotname in legacy stashpoint: ${req.query.slotname}`,
)
return
}

const userProfile = getUserData(req.jwt.unique_name, req.gameVersion)

const sublocation = getSubLocationByName(
contractData.Metadata.Location,
req.gameVersion,
)

const inventory = createInventory(
req.jwt.unique_name,
req.gameVersion,
sublocation,
)

const userCentricContract = generateUserCentric(
contractData,
req.jwt.unique_name,
"h1",
)

const defaultLoadout = {
2: "FIREARMS_HERO_PISTOL_TACTICAL_001_SU_SKIN01",
3: getDefaultSuitFor(sublocation),
4: "TOKEN_FIBERWIRE",
5: "PROP_TOOL_COIN",
}

const getLoadoutItem = (id: number) => {
if (getFlag("loadoutSaving") === "LEGACY") {
const dl = userProfile.Extensions.defaultloadout

if (!dl) {
return defaultLoadout[id]
}

const forLocation = (userProfile.Extensions.defaultloadout ||
{})[sublocation?.Properties?.ParentLocation]

if (!forLocation) {
return defaultLoadout[id]
}

return forLocation[id]
} else {
let dl = loadouts.getLoadoutFor("h1")

if (!dl) {
dl = loadouts.createDefault("h1")
}

const forLocation =
dl.data[sublocation?.Properties?.ParentLocation]

if (!forLocation) {
return defaultLoadout[id]
}

return forLocation[id]
}
}

res.json({
template: getConfig("LegacyStashpointTemplate", false),
data: {
ContractId: req.query.contractid,
// the game actually only needs the loadoutdata from the requested slotid, but this is what IOI servers do
LoadoutData: [...loadoutSlots.entries()].map(
([slotid, slotname]) => ({
SlotName: slotname,
SlotId: slotid.toString(),
Items: inventory
.filter((item) => {
return (
item.Unlockable.Properties.LoadoutSlot && // only display items
(item.Unlockable.Properties.LoadoutSlot ===
slotname || // display items for requested slot
(slotname === "stashpoint" && // else: if stashpoint
item.Unlockable.Properties
.LoadoutSlot !== "disguise")) && // => display all non-disguise items
(req.query.allowlargeitems === "true" ||
item.Unlockable.Properties
.LoadoutSlot !== "carriedweapon") &&
item.Unlockable.Type !==
"challengemultipler" &&
!item.Unlockable.Properties.InclusionData
) // not sure about this one
})
.map((item) => ({
Item: item,
ItemDetails: {
Capabilities: [],
StatList: item.Unlockable.Properties
.Gameplay
? Object.entries(
item.Unlockable.Properties
.Gameplay,
).map(([key, value]) => ({
Name: key,
Ratio: value,
}))
: [],
PropertyTexts: [],
},
SlotId: slotid.toString(),
SlotName: slotname,
})),
Page: 0,
Recommended: getLoadoutItem(slotid)
? {
item: getUnlockableById(
getLoadoutItem(slotid),
req.gameVersion,
),
type: loadoutSlots[slotid],
owned: true,
}
: null,
HasMore: false,
HasMoreLeft: false,
HasMoreRight: false,
OptionalData:
slotid === 6
? {
stashpoint: req.query.stashpoint,
AllowLargeItems:
req.query.allowlargeitems ||
!req.query.stashpoint,
}
: {},
}),
),
Contract: userCentricContract.Contract,
ShowSlotName: req.query.slotname,
UserCentric: userCentricContract,
},
})
},
)

legacyMenuDataRouter.get("/Safehouse", (req: RequestWithJwt, res, next) => {
const template = getConfig("LegacySafehouseTemplate", false)

// call /SafehouseCategory but rewrite the result a bit
req.url = `/SafehouseCategory?page=0&type=${req.query.type}&subtype=`
const originalJsonFunc = res.json

res.json = function json(originalData) {
return originalJsonFunc.call(this, {
template,
data: {
SafehouseData: originalData.data,
},
})
}

next()
})

legacyMenuDataRouter.get(
"/debriefingchallenges",
jsonMiddleware(),
(
req: RequestWithJwt<{ contractSessionId: string; contractId: string }>,
res,
Expand Down Expand Up @@ -265,7 +55,6 @@ legacyMenuDataRouter.get(

legacyMenuDataRouter.get(
"/MasteryLocation",
jsonMiddleware(),
(req: RequestWithJwt<{ locationId: string; difficulty: string }>, res) => {
const masteryData =
controller.masteryService.getMasteryDataForDestination(
Expand Down
11 changes: 0 additions & 11 deletions components/2016/legacyMenuSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import serveStatic from "serve-static"
import { Router } from "express"
import { join } from "path"
import md5File from "md5-file"
import { readFile } from "atomically"
import { imageFetchingMiddleware } from "../menus/imageHandler"
import { MenuSystemDatabase } from "../menus/menuSystem"

const legacyMenuSystemRouter = Router()

Expand All @@ -46,12 +43,4 @@ legacyMenuSystemRouter.get(
},
)

legacyMenuSystemRouter.use(MenuSystemDatabase.configMiddleware)

legacyMenuSystemRouter.use(
"/images/",
serveStatic("images", { fallthrough: true }),
imageFetchingMiddleware,
)

export { legacyMenuSystemRouter }
66 changes: 0 additions & 66 deletions components/candle/challengeRouting.ts

This file was deleted.

10 changes: 5 additions & 5 deletions components/generatedPeacockRequireTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import * as legacyMenuData from "./2016/legacyMenuData"
import * as legacyMenuSystem from "./2016/legacyMenuSystem"
import * as legacyProfileRouter from "./2016/legacyProfileRouter"
import * as challengeHelpers from "./candle/challengeHelpers"
import * as challengeRouting from "./candle/challengeRouting"
import * as challengeService from "./candle/challengeService"
import * as masteryService from "./candle/masteryService"
import * as progressionService from "./candle/progressionService"
Expand All @@ -71,6 +70,7 @@ import * as menuSystem from "./menus/menuSystem"
import * as planning from "./menus/planning"
import * as playnext from "./menus/playnext"
import * as sniper from "./menus/sniper"
import * as stashpoints from "./menus/stashpoints"
import * as multiplayerMenuData from "./multiplayer/multiplayerMenuData"
import * as multiplayerService from "./multiplayer/multiplayerService"
import * as multiplayerUtils from "./multiplayer/multiplayerUtils"
Expand Down Expand Up @@ -151,10 +151,6 @@ export default {
__esModule: true,
...challengeHelpers,
},
"@peacockproject/core/candle/challengeRouting": {
__esModule: true,
...challengeRouting,
},
"@peacockproject/core/candle/challengeService": {
__esModule: true,
...challengeService,
Expand Down Expand Up @@ -230,6 +226,10 @@ export default {
"@peacockproject/core/menus/planning": { __esModule: true, ...planning },
"@peacockproject/core/menus/playnext": { __esModule: true, ...playnext },
"@peacockproject/core/menus/sniper": { __esModule: true, ...sniper },
"@peacockproject/core/menus/stashpoints": {
__esModule: true,
...stashpoints,
},
"@peacockproject/core/multiplayer/multiplayerMenuData": {
__esModule: true,
...multiplayerMenuData,
Expand Down
Loading

0 comments on commit c08d0f5

Please sign in to comment.