refactor: don't pass undefined to getRandomMissionRewards (#913)
Reviewed-on: OpenWF/SpaceNinjaServer#913 Co-authored-by: Ordis <134585663+OrdisPrime@users.noreply.github.com> Co-committed-by: Ordis <134585663+OrdisPrime@users.noreply.github.com>
This commit is contained in:
parent
1fd801403f
commit
0fbf300d3e
@ -2,11 +2,7 @@ import { RequestHandler } from "express";
|
|||||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||||
import { IMissionInventoryUpdateRequest } from "@/src/types/requestTypes";
|
import { IMissionInventoryUpdateRequest } from "@/src/types/requestTypes";
|
||||||
import {
|
import { addMissionInventoryUpdates, addMissionRewards } from "@/src/services/missionInventoryUpdateService";
|
||||||
addMissionInventoryUpdates,
|
|
||||||
addMissionRewards,
|
|
||||||
calculateFinalCredits
|
|
||||||
} from "@/src/services/missionInventoryUpdateService";
|
|
||||||
import { getInventory } from "@/src/services/inventoryService";
|
import { getInventory } from "@/src/services/inventoryService";
|
||||||
import { getInventoryResponse } from "./inventoryController";
|
import { getInventoryResponse } from "./inventoryController";
|
||||||
|
|
||||||
@ -49,7 +45,7 @@ import { getInventoryResponse } from "./inventoryController";
|
|||||||
- [ ] FpsMax
|
- [ ] FpsMax
|
||||||
- [ ] FpsSamples
|
- [ ] FpsSamples
|
||||||
*/
|
*/
|
||||||
|
//move credit calc in here, return MissionRewards: [] if no reward info
|
||||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
export const missionInventoryUpdateController: RequestHandler = async (req, res): Promise<void> => {
|
export const missionInventoryUpdateController: RequestHandler = async (req, res): Promise<void> => {
|
||||||
const accountId = await getAccountIdForRequest(req);
|
const accountId = await getAccountIdForRequest(req);
|
||||||
@ -67,18 +63,8 @@ export const missionInventoryUpdateController: RequestHandler = async (req, res)
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const missionRewardsResults = await addMissionRewards(inventory, missionReport);
|
|
||||||
if (!missionRewardsResults) {
|
|
||||||
throw new Error("Failed to add mission rewards, should not happen");
|
|
||||||
}
|
|
||||||
const { MissionRewards, inventoryChanges, missionCompletionCredits } = missionRewardsResults;
|
|
||||||
|
|
||||||
//creditBonus is not correct for mirage mission 3
|
const { MissionRewards, inventoryChanges, credits } = await addMissionRewards(inventory, missionReport);
|
||||||
const credits = calculateFinalCredits(inventory, {
|
|
||||||
missionCompletionCredits,
|
|
||||||
missionDropCredits: missionReport.RegularCredits ?? 0,
|
|
||||||
rngRewardCredits: inventoryChanges.RegularCredits as number
|
|
||||||
});
|
|
||||||
|
|
||||||
await inventory.save();
|
await inventory.save();
|
||||||
const inventoryResponse = await getInventoryResponse(inventory, true);
|
const inventoryResponse = await getInventoryResponse(inventory, true);
|
||||||
@ -90,7 +76,7 @@ export const missionInventoryUpdateController: RequestHandler = async (req, res)
|
|||||||
MissionRewards,
|
MissionRewards,
|
||||||
...credits,
|
...credits,
|
||||||
...inventoryUpdates,
|
...inventoryUpdates,
|
||||||
FusionPoints: inventoryChanges.FusionPoints
|
FusionPoints: inventoryChanges?.FusionPoints
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -200,10 +200,17 @@ export const addMissionInventoryUpdates = (
|
|||||||
//TODO: return type of partial missioninventoryupdate response
|
//TODO: return type of partial missioninventoryupdate response
|
||||||
export const addMissionRewards = async (
|
export const addMissionRewards = async (
|
||||||
inventory: TInventoryDatabaseDocument,
|
inventory: TInventoryDatabaseDocument,
|
||||||
{ RewardInfo: rewardInfo, LevelKeyName: levelKeyName, Missions: missions }: IMissionInventoryUpdateRequest
|
{
|
||||||
|
RewardInfo: rewardInfo,
|
||||||
|
LevelKeyName: levelKeyName,
|
||||||
|
Missions: missions,
|
||||||
|
RegularCredits: creditDrops
|
||||||
|
}: IMissionInventoryUpdateRequest
|
||||||
) => {
|
) => {
|
||||||
if (!rewardInfo) {
|
if (!rewardInfo) {
|
||||||
logger.warn("no reward info provided");
|
//TODO: if there is a case where you can have credits collected during a mission but no rewardInfo, add credits needs to be handled earlier
|
||||||
|
logger.debug(`Mission ${missions!.Tag} did not have Reward Info `);
|
||||||
|
return { MissionRewards: [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: check double reward merging
|
//TODO: check double reward merging
|
||||||
@ -214,11 +221,12 @@ export const addMissionRewards = async (
|
|||||||
const inventoryChanges: IInventoryChanges = {};
|
const inventoryChanges: IInventoryChanges = {};
|
||||||
|
|
||||||
let missionCompletionCredits = 0;
|
let missionCompletionCredits = 0;
|
||||||
//inventory change is what the client has not rewarded itself, credit updates seem to be taken from totalCredits
|
//inventory change is what the client has not rewarded itself, also the client needs to know the credit changes for display
|
||||||
if (levelKeyName) {
|
if (levelKeyName) {
|
||||||
const fixedLevelRewards = getLevelKeyRewards(levelKeyName);
|
const fixedLevelRewards = getLevelKeyRewards(levelKeyName);
|
||||||
//logger.debug(`fixedLevelRewards ${fixedLevelRewards}`);
|
//logger.debug(`fixedLevelRewards ${fixedLevelRewards}`);
|
||||||
for (const reward of fixedLevelRewards) {
|
for (const reward of fixedLevelRewards) {
|
||||||
|
//quest stage completion credit rewards
|
||||||
if (reward.rewardType == "RT_CREDITS") {
|
if (reward.rewardType == "RT_CREDITS") {
|
||||||
inventory.RegularCredits += reward.amount;
|
inventory.RegularCredits += reward.amount;
|
||||||
missionCompletionCredits += reward.amount;
|
missionCompletionCredits += reward.amount;
|
||||||
@ -231,6 +239,16 @@ export const addMissionRewards = async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const reward of MissionRewards) {
|
||||||
|
//TODO: additem should take in storeItems
|
||||||
|
const inventoryChange = await addItem(inventory, reward.StoreItem.replace("StoreItems/", ""), reward.ItemCount);
|
||||||
|
//TODO: combineInventoryChanges improve type safety, merging 2 of the same item?
|
||||||
|
//TODO: check for the case when two of the same item are added, combineInventoryChanges should merge them, but the client also merges them
|
||||||
|
//TODO: some conditional types to rule out binchanges?
|
||||||
|
combineInventoryChanges(inventoryChanges, inventoryChange.InventoryChanges);
|
||||||
|
}
|
||||||
|
|
||||||
|
//node based credit rewards for mission completion
|
||||||
if (missions) {
|
if (missions) {
|
||||||
const node = getNode(missions.Tag);
|
const node = getNode(missions.Tag);
|
||||||
|
|
||||||
@ -242,27 +260,24 @@ export const addMissionRewards = async (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: resolve issue with creditbundles
|
//creditBonus is not correct for mirage mission 3
|
||||||
for (const reward of MissionRewards) {
|
const credits = addCredits(inventory, {
|
||||||
//TODO: additem should take in storeItems
|
missionCompletionCredits,
|
||||||
const inventoryChange = await addItem(inventory, reward.StoreItem.replace("StoreItems/", ""), reward.ItemCount);
|
missionDropCredits: creditDrops ?? 0,
|
||||||
//TODO: combineInventoryChanges improve type safety, merging 2 of the same item?
|
rngRewardCredits: inventoryChanges.RegularCredits ?? 0
|
||||||
//TODO: check for the case when two of the same item are added, combineInventoryChanges should merge them
|
});
|
||||||
//TODO: some conditional types to rule out binchanges?
|
|
||||||
combineInventoryChanges(inventoryChanges, inventoryChange.InventoryChanges);
|
|
||||||
}
|
|
||||||
|
|
||||||
return { inventoryChanges, MissionRewards, missionCompletionCredits };
|
return { inventoryChanges, MissionRewards, credits };
|
||||||
};
|
};
|
||||||
|
|
||||||
//might not be faithful to original
|
//slightly inaccurate compared to official
|
||||||
//TODO: consider ActiveBoosters
|
//TODO: consider ActiveBoosters
|
||||||
export const calculateFinalCredits = (
|
export const addCredits = (
|
||||||
inventory: HydratedDocument<IInventoryDatabase>,
|
inventory: HydratedDocument<IInventoryDatabase>,
|
||||||
{
|
{
|
||||||
missionDropCredits,
|
missionDropCredits,
|
||||||
missionCompletionCredits,
|
missionCompletionCredits,
|
||||||
rngRewardCredits = 0
|
rngRewardCredits
|
||||||
}: { missionDropCredits: number; missionCompletionCredits: number; rngRewardCredits: number }
|
}: { missionDropCredits: number; missionCompletionCredits: number; rngRewardCredits: number }
|
||||||
) => {
|
) => {
|
||||||
const hasDailyCreditBonus = true;
|
const hasDailyCreditBonus = true;
|
||||||
@ -275,7 +290,7 @@ export const calculateFinalCredits = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (hasDailyCreditBonus) {
|
if (hasDailyCreditBonus) {
|
||||||
inventory.RegularCredits += totalCredits;
|
inventory.RegularCredits += missionCompletionCredits;
|
||||||
finalCredits.CreditBonus[1] *= 2;
|
finalCredits.CreditBonus[1] *= 2;
|
||||||
finalCredits.MissionCredits[1] *= 2;
|
finalCredits.MissionCredits[1] *= 2;
|
||||||
finalCredits.TotalCredits[1] *= 2;
|
finalCredits.TotalCredits[1] *= 2;
|
||||||
@ -295,9 +310,9 @@ function getLevelCreditRewards(nodeName: string): number {
|
|||||||
//TODO: get dark sektor fixed credit rewards and railjack bonus
|
//TODO: get dark sektor fixed credit rewards and railjack bonus
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRandomMissionDrops(RewardInfo: IRewardInfo | undefined): IRngResult[] {
|
function getRandomMissionDrops(RewardInfo: IRewardInfo): IRngResult[] {
|
||||||
const drops: IRngResult[] = [];
|
const drops: IRngResult[] = [];
|
||||||
if (RewardInfo && RewardInfo.node in ExportRegions) {
|
if (RewardInfo.node in ExportRegions) {
|
||||||
const region = ExportRegions[RewardInfo.node];
|
const region = ExportRegions[RewardInfo.node];
|
||||||
const rewardManifests = region.rewardManifests ?? [];
|
const rewardManifests = region.rewardManifests ?? [];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user