initial work on syndicates

This commit is contained in:
Jānis 2024-06-02 18:10:25 +03:00
parent 3e4eeb601d
commit 304529c56d
7 changed files with 150 additions and 12 deletions

View File

@ -0,0 +1,14 @@
import { updateSyndicate } from "@/src/services/inventoryService";
import { RequestHandler } from "express";
// eslint-disable-next-line @typescript-eslint/no-misused-promises
const setSupportedSyndicateController: RequestHandler = async (request, response) => {
const accountId = request.query.accountId as string;
const syndicate = request.query.syndicate as string;
await updateSyndicate(syndicate, accountId);
response.json({});
};
export { setSupportedSyndicateController };

View File

@ -0,0 +1,26 @@
import { getJSONfromString } from "@/src/helpers/stringHelpers";
import { syndicateSacrifice } from "@/src/services/inventoryService";
import { ISyndicateSacrifice } from "@/src/types/syndicateTypes";
import { RequestHandler } from "express";
// eslint-disable-next-line @typescript-eslint/no-misused-promises
const syndicateSacrificeController: RequestHandler = async (request, response) => {
const accountId = request.query.accountId as string;
const body = getJSONfromString(request.body);
let reply = {};
try {
const update = JSON.parse(body) as ISyndicateSacrifice;
if (typeof update !== "object") {
throw new Error("Invalid data format");
}
reply = await syndicateSacrifice(update, accountId);
} catch (err) {
console.error("Error parsing JSON data:", err);
}
response.json(reply);
};
export { syndicateSacrificeController };

View File

@ -1,19 +1,15 @@
import { RequestHandler } from "express";
import { IChallengeProgress } from "@/src/types/inventoryTypes/inventoryTypes";
import { getJSONfromString } from "@/src/helpers/stringHelpers";
import { getAccountIdForRequest } from "@/src/services/loginService";
import { getInventory, addChallenges } from "@/src/services/inventoryService";
interface IUpdateChallengeProgessRequest {
ChallengeProgress: IChallengeProgress[];
}
import { updateChallengeProgress } from "@/src/services/inventoryService";
import { IUpdateChallengeProgressRequest } from "@/src/types/requestTypes";
const updateChallengeProgressController: RequestHandler = async (req, res) => {
const payload: IUpdateChallengeProgessRequest = getJSONfromString(req.body.toString());
const payload: IUpdateChallengeProgressRequest = getJSONfromString(req.body.toString());
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId);
addChallenges(inventory, payload.ChallengeProgress);
await inventory.save();
await updateChallengeProgress(payload, accountId);
res.status(200).end();
};

View File

@ -13,12 +13,14 @@ import {
IMiscItem,
IMission,
IRawUpgrade,
ISeasonChallengeHistory,
ITypeCount
} from "@/src/types/inventoryTypes/inventoryTypes";
import { IGenericUpdate } from "../types/genericUpdate";
import { IArtifactsRequest, IMissionInventoryUpdateRequest, IThemeUpdateRequest } from "../types/requestTypes";
import { IArtifactsRequest, IMissionInventoryUpdateRequest, IThemeUpdateRequest, IUpdateChallengeProgressRequest } from "../types/requestTypes";
import { logger } from "@/src/utils/logger";
import { WeaponTypeInternal } from "@/src/services/itemDataService";
import { ISyndicateSacrifice, ISyndicateSacrificeResponse } from "../types/syndicateTypes";
export const createInventory = async (
accountOwnerId: Types.ObjectId,
@ -164,6 +166,32 @@ export const updateTheme = async (data: IThemeUpdateRequest, accountId: string)
await inventory.save();
};
export const syndicateSacrifice = async (data: ISyndicateSacrifice, accountId: string): Promise<ISyndicateSacrificeResponse> => {
const inventory = await getInventory(accountId);
const syndicate = inventory.Affiliations.find(x => x.Tag == data.AffiliationTag);
const level = data.SacrificeLevel - (syndicate?.Title ?? 0);
const res: ISyndicateSacrificeResponse = {
AffiliationTag: data.AffiliationTag,
InventoryChanges: [],
Level: data.SacrificeLevel,
LevelIncrease: level <= 0 ? 1 : level,
NewEpisodeReward: syndicate?.Tag == "RadioLegionIntermission9Syndicate"
}
if (syndicate?.Title !== undefined) syndicate.Title += 1;
await inventory.save();
return res;
};
export const updateSyndicate = async (syndicate: string, accountId: string) => {
const inventory = await getInventory(accountId);
inventory.SupportedSyndicate = syndicate;
await inventory.save();
};
export const addWeapon = async (
weaponType: WeaponTypeInternal,
weaponName: string,
@ -290,6 +318,29 @@ export const addMods = (inventory: IInventoryDatabaseDocument, itemsArray: IRawU
});
};
export const updateChallengeProgress = async (challenges: IUpdateChallengeProgressRequest, accountId: string) => {
const inventory = await getInventory(accountId);
addChallenges(inventory, challenges.ChallengeProgress);
addSeasonalChallengeHistory(inventory, challenges.SeasonChallengeHistory);
await inventory.save();
};
export const addSeasonalChallengeHistory = (inventory: IInventoryDatabaseDocument, itemsArray: ISeasonChallengeHistory[] | undefined) => {
const category = inventory.SeasonChallengeHistory;
itemsArray?.forEach(({ challenge, id }) => {
const itemIndex = category.findIndex(i => i.challenge === challenge);
if (itemIndex !== -1) {
category[itemIndex].id = id;
} else {
category.push({ challenge, id });
}
});
};
export const addChallenges = (inventory: IInventoryDatabaseDocument, itemsArray: IChallengeProgress[] | undefined) => {
const category = inventory.ChallengeProgress;
@ -330,6 +381,23 @@ export const missionInventoryUpdate = async (data: IMissionInventoryUpdateReques
// endo
inventory.FusionPoints += FusionPoints || 0;
// syndicate
data.AffiliationChanges?.forEach(affiliation => {
const syndicate = inventory.Affiliations.find(x => x.Tag == affiliation.Tag);
if (syndicate !== undefined) {
syndicate.Standing = syndicate.Standing === undefined ? affiliation.Standing : syndicate.Standing + affiliation.Standing;
syndicate.Title = syndicate.Title === undefined ? affiliation.Title : syndicate.Title + affiliation.Title;
} else {
inventory.Affiliations.push({
Standing: affiliation.Standing,
Title: affiliation.Title,
Tag: affiliation.Tag,
FreeFavorsEarned: [],
FreeFavorsUsed: []
});
}
})
// Gear XP
gearKeys.forEach(key => addGearExpByCategory(inventory, data[key], key));

View File

@ -1028,6 +1028,11 @@ export interface ISeasonChallengeHistory {
id: string;
}
export interface ISeasonChallengeCompletions {
challenge: string;
id: string;
}
export interface ISentientSpawnChanceBoosters {
numOceanMissionsCompleted: number;
}

View File

@ -7,7 +7,9 @@ import {
ICrewShipSalvagedWeaponSkin,
IMiscItem,
IMission,
IRawUpgrade
IRawUpgrade,
ISeasonChallengeCompletions,
ISeasonChallengeHistory
} from "./inventoryTypes/inventoryTypes";
import { IWeaponClient } from "./inventoryTypes/weaponTypes";
import { ISuitClient } from "./inventoryTypes/SuitTypes";
@ -25,9 +27,23 @@ export interface IThemeUpdateRequest {
Sounds?: string;
}
export interface IAffiliationChange
{
Tag: string,
Standing: number,
Title: number
}
export interface IUpdateChallengeProgressRequest {
ChallengeProgress: IChallengeProgress[];
SeasonChallengeHistory: ISeasonChallengeHistory[];
SeasonChallengeCompletions: ISeasonChallengeCompletions[];
}
export interface IMissionInventoryUpdateRequest {
rewardsMultiplier?: number;
ActiveBoosters?: IBooster[];
AffiliationChanges?: IAffiliationChange[];
LongGuns?: IWeaponClient[];
Pistols?: IWeaponClient[];
Suits?: ISuitClient[];

View File

@ -0,0 +1,13 @@
export interface ISyndicateSacrifice {
AffiliationTag: string;
SacrificeLevel: number;
AllowMultiple: boolean;
}
export interface ISyndicateSacrificeResponse {
AffiliationTag: string;
Level: number;
LevelIncrease: number;
InventoryChanges: any[];
NewEpisodeReward: boolean;
}