2023-06-01 17:08:05 -07:00
import { RequestHandler } from "express" ;
2023-09-10 00:10:21 +04:00
import { getJSONfromString } from "@/src/helpers/stringHelpers" ;
2024-05-28 13:45:06 +02:00
import { getAccountIdForRequest } from "@/src/services/loginService" ;
2023-09-10 00:10:21 +04:00
import { IMissionInventoryUpdateRequest } from "@/src/types/requestTypes" ;
2025-02-06 07:11:31 -08:00
import { addMissionInventoryUpdates , addMissionRewards } from "@/src/services/missionInventoryUpdateService" ;
2025-01-24 14:13:21 +01:00
import { getInventory } from "@/src/services/inventoryService" ;
2025-01-25 13:12:49 +01:00
import { getInventoryResponse } from "./inventoryController" ;
2025-02-18 05:24:28 -08:00
import { logger } from "@/src/utils/logger" ;
2025-01-24 16:17:59 +01:00
2023-08-31 14:29:09 +04:00
/ *
2023-09-06 14:02:54 +04:00
* * * * INPUT * * * *
2023-08-31 14:29:09 +04:00
- [ ] crossPlaySetting
- [ ] rewardsMultiplier
- [ ] ActiveBoosters
- [ x ] LongGuns
- [ x ] Pistols
- [ x ] Suits
- [ x ] Melee
- [ x ] RawUpgrades
- [ x ] MiscItems
- [ x ] RegularCredits
- [ ] RandomUpgradesIdentified
- [ ] MissionFailed
- [ ] MissionStatus
- [ ] CurrentLoadOutIds
- [ ] AliveTime
- [ ] MissionTime
2023-09-10 00:10:21 +04:00
- [ x ] Missions
2023-08-31 14:29:09 +04:00
- [ ] CompletedAlerts
- [ ] LastRegionPlayed
- [ ] GameModeId
- [ ] hosts
- [ x ] ChallengeProgress
- [ ] SeasonChallengeHistory
2025-01-24 14:13:21 +01:00
- [ ] PS ( anticheat data )
2023-08-31 14:29:09 +04:00
- [ ] ActiveDojoColorResearch
2023-09-06 14:02:54 +04:00
- [ x ] RewardInfo
2023-08-31 14:29:09 +04:00
- [ ] ReceivedCeremonyMsg
- [ ] LastCeremonyResetDate
2023-09-05 07:37:30 -05:00
- [ ] MissionPTS ( Used to validate the mission / alive time above . )
2025-01-24 14:13:21 +01:00
- [ ] RepHash
2023-08-31 14:29:09 +04:00
- [ ] EndOfMatchUpload
- [ ] ObjectiveReached
- [ ] FpsAvg
- [ ] FpsMin
- [ ] FpsMax
- [ ] FpsSamples
* /
2025-02-06 07:11:31 -08:00
//move credit calc in here, return MissionRewards: [] if no reward info
2025-01-24 14:13:21 +01:00
export const missionInventoryUpdateController : RequestHandler = async ( req , res ) : Promise < void > = > {
2024-05-28 13:45:06 +02:00
const accountId = await getAccountIdForRequest ( req ) ;
2025-01-24 14:27:10 +01:00
const missionReport = getJSONfromString < IMissionInventoryUpdateRequest > ( ( req . body as string ) . toString ( ) ) ;
2025-02-18 05:24:28 -08:00
logger . debug ( "mission report:" , missionReport ) ;
2023-09-06 14:02:54 +04:00
2025-01-24 16:17:59 +01:00
const inventory = await getInventory ( accountId ) ;
2025-03-07 00:41:18 -08:00
const inventoryUpdates = await addMissionInventoryUpdates ( inventory , missionReport ) ;
2025-01-24 16:17:59 +01:00
2025-04-10 22:09:55 +02:00
// skip mission rewards if not GS_SUCCESS and not a bounty (by presence of jobId, as there's a reward every stage but only the last stage has GS_SUCCESS)
if ( missionReport . MissionStatus !== "GS_SUCCESS" && ! missionReport . RewardInfo ? . jobId ) {
2025-01-24 21:09:34 +01:00
await inventory . save ( ) ;
2025-01-25 13:12:49 +01:00
const inventoryResponse = await getInventoryResponse ( inventory , true ) ;
2025-01-24 21:09:34 +01:00
res . json ( {
InventoryJson : JSON.stringify ( inventoryResponse ) ,
MissionRewards : [ ]
} ) ;
2025-01-24 15:13:55 +01:00
return ;
2025-01-24 14:13:21 +01:00
}
2025-02-06 07:11:31 -08:00
const { MissionRewards , inventoryChanges , credits } = await addMissionRewards ( inventory , missionReport ) ;
2025-01-24 14:13:21 +01:00
2025-01-24 21:09:34 +01:00
await inventory . save ( ) ;
2025-01-25 13:12:49 +01:00
const inventoryResponse = await getInventoryResponse ( inventory , true ) ;
2025-01-24 14:13:21 +01:00
//TODO: figure out when to send inventory. it is needed for many cases.
res . json ( {
2025-01-24 21:09:34 +01:00
InventoryJson : JSON.stringify ( inventoryResponse ) ,
2025-01-24 14:13:21 +01:00
InventoryChanges : inventoryChanges ,
MissionRewards ,
. . . credits ,
. . . inventoryUpdates ,
2025-02-06 07:11:31 -08:00
FusionPoints : inventoryChanges?.FusionPoints
2025-01-24 14:13:21 +01:00
} ) ;
2023-06-01 17:08:05 -07:00
} ;
2023-09-06 14:02:54 +04:00
/ *
* * * * OUTPUT * * * *
- [ x ] InventoryJson
- [ x ] MissionRewards
- [ x ] TotalCredits
- [ x ] CreditsBonus
- [ x ] MissionCredits
- [ x ] InventoryChanges
- [ x ] FusionPoints
* /