Impl-Nightwave-Standing-Multliplier and Fix syndicateSacrificeController issue that not handle more then one level up in one request #2138
@ -17,81 +17,99 @@ export const syndicateSacrificeController: RequestHandler = async (request, resp
 | 
				
			|||||||
    if (!syndicate) {
 | 
					    if (!syndicate) {
 | 
				
			||||||
        syndicate = inventory.Affiliations[inventory.Affiliations.push({ Tag: data.AffiliationTag, Standing: 0 }) - 1];
 | 
					        syndicate = inventory.Affiliations[inventory.Affiliations.push({ Tag: data.AffiliationTag, Standing: 0 }) - 1];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    const level = data.SacrificeLevel - (syndicate.Title ?? 0);
 | 
					 | 
				
			||||||
    const res: ISyndicateSacrificeResponse = {
 | 
					    const res: ISyndicateSacrificeResponse = {
 | 
				
			||||||
        AffiliationTag: data.AffiliationTag,
 | 
					        AffiliationTag: data.AffiliationTag,
 | 
				
			||||||
        InventoryChanges: {},
 | 
					        InventoryChanges: {},
 | 
				
			||||||
        Level: data.SacrificeLevel,
 | 
					        Level: 0, // the new level after the sacrifice
 | 
				
			||||||
        LevelIncrease: level <= 0 ? 1 : level,
 | 
					        LevelIncrease: 0, // the amount of levels gained from the sacrifice
 | 
				
			||||||
        NewEpisodeReward: false
 | 
					        NewEpisodeReward: false
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					 | 
				
			||||||
    const manifest = ExportSyndicates[data.AffiliationTag];
 | 
					    const manifest = ExportSyndicates[data.AffiliationTag];
 | 
				
			||||||
    let sacrifice: ISyndicateSacrifice | undefined;
 | 
					    const isNightwave = manifest.dailyChallenges !== undefined;
 | 
				
			||||||
    let reward: string | undefined;
 | 
					
 | 
				
			||||||
    if (data.SacrificeLevel == 0) {
 | 
					    const titles = manifest.titles;
 | 
				
			||||||
        sacrifice = manifest.initiationSacrifice;
 | 
					    const oldLevel = syndicate.Title ?? 0;
 | 
				
			||||||
        reward = manifest.initiationReward;
 | 
					    const currentStanding = syndicate.Standing ?? 0;
 | 
				
			||||||
        syndicate.Initiated = true;
 | 
					    let newLevel = oldLevel;
 | 
				
			||||||
    } else {
 | 
					
 | 
				
			||||||
        sacrifice = manifest.titles?.find(x => x.level == data.SacrificeLevel)?.sacrifice;
 | 
					    interface _HandleItem {
 | 
				
			||||||
 | 
					        sacrifice?: ISyndicateSacrifice;
 | 
				
			||||||
 | 
					        reward?: {
 | 
				
			||||||
 | 
					            type: string;
 | 
				
			||||||
 | 
					            count?: number; // default 1
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (sacrifice) {
 | 
					    const needProcess: _HandleItem[] = [];
 | 
				
			||||||
        res.InventoryChanges = { ...updateCurrency(inventory, sacrifice.credits, false) };
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const miscItemChanges = sacrifice.items.map(x => ({
 | 
					    if (!syndicate.Initiated) {
 | 
				
			||||||
 | 
					        needProcess.push({
 | 
				
			||||||
 | 
					            sacrifice: manifest.initiationSacrifice,
 | 
				
			||||||
 | 
					            reward: manifest.initiationReward ? { type: manifest.initiationReward } : undefined,
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					        syndicate.Initiated = true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (titles == undefined) {
 | 
				
			||||||
 | 
					        // ummm then just trust what the client says?
 | 
				
			||||||
 | 
					        newLevel = res.Level = data.SacrificeLevel;
 | 
				
			||||||
 | 
					        res.LevelIncrease = data.SacrificeLevel - oldLevel;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        titles.filter(x => x.level > oldLevel && x.minStanding <= currentStanding).forEach(x => {
 | 
				
			||||||
 | 
					            if (x.level > newLevel) newLevel = x.level;
 | 
				
			||||||
 | 
					            const item: _HandleItem = {};
 | 
				
			||||||
 | 
					            if (x.sacrifice) {
 | 
				
			||||||
 | 
					                item.sacrifice = x.sacrifice;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if (x.storeItemReward) {
 | 
				
			||||||
 | 
					                item.reward = { type: x.storeItemReward, count: 1 };
 | 
				
			||||||
 | 
					            } else if (x.reward) {
 | 
				
			||||||
 | 
					                item.reward = { type: toStoreItem(x.reward.ItemType), count: x.reward.ItemCount };
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if (item.sacrifice || item.reward) {
 | 
				
			||||||
 | 
					                needProcess.push(item);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					        res.Level = newLevel;
 | 
				
			||||||
 | 
					        res.LevelIncrease = newLevel - oldLevel;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (const item of needProcess) {
 | 
				
			||||||
 | 
					        if (item.sacrifice) {
 | 
				
			||||||
 | 
					            const changes = updateCurrency(inventory, item.sacrifice.credits, false);
 | 
				
			||||||
 | 
					            const miscItemChanges = item.sacrifice.items.map(x => ({
 | 
				
			||||||
                ItemType: x.ItemType,
 | 
					                ItemType: x.ItemType,
 | 
				
			||||||
                ItemCount: x.ItemCount * -1
 | 
					                ItemCount: x.ItemCount * -1
 | 
				
			||||||
            }));
 | 
					            }));
 | 
				
			||||||
            addMiscItems(inventory, miscItemChanges);
 | 
					            addMiscItems(inventory, miscItemChanges);
 | 
				
			||||||
        res.InventoryChanges.MiscItems = miscItemChanges;
 | 
					            if (res.InventoryChanges.MiscItems === undefined) {
 | 
				
			||||||
 | 
					                res.InventoryChanges.MiscItems = [];
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            res.InventoryChanges.MiscItems.push(...miscItemChanges);
 | 
				
			||||||
    syndicate.Title ??= 0;
 | 
					            combineInventoryChanges(res.InventoryChanges, changes);
 | 
				
			||||||
    syndicate.Title += 1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (reward) {
 | 
					 | 
				
			||||||
        combineInventoryChanges(
 | 
					 | 
				
			||||||
            res.InventoryChanges,
 | 
					 | 
				
			||||||
            (await handleStoreItemAcquisition(reward, inventory)).InventoryChanges
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        if (item.reward) {
 | 
				
			||||||
    // Quacks like a nightwave syndicate?
 | 
					            const rewardChanges = await handleStoreItemAcquisition(item.reward.type, inventory, item.reward.count ?? 1);
 | 
				
			||||||
    if (manifest.dailyChallenges) {
 | 
					            if (isNightwave && Object.keys(rewardChanges.InventoryChanges).length == 0) {
 | 
				
			||||||
        const title = manifest.titles!.find(x => x.level == syndicate.Title);
 | 
					                logger.debug(`syndicate sacrifice reward did not seem to get added, giving 50 creds instead`);
 | 
				
			||||||
        if (title) {
 | 
					                const syndicateCredsItemType = manifest.titles![0].reward!.ItemType;
 | 
				
			||||||
            res.NewEpisodeReward = true;
 | 
					                rewardChanges.InventoryChanges.MiscItems = [{ ItemType: syndicateCredsItemType, ItemCount: 50 }];
 | 
				
			||||||
            let rewardType: string;
 | 
					                addMiscItems(inventory, rewardChanges.InventoryChanges.MiscItems);
 | 
				
			||||||
            let rewardCount: number;
 | 
					            }
 | 
				
			||||||
            if (title.storeItemReward) {
 | 
					            combineInventoryChanges(res.InventoryChanges, rewardChanges.InventoryChanges);
 | 
				
			||||||
                rewardType = title.storeItemReward;
 | 
					        }
 | 
				
			||||||
                rewardCount = 1;
 | 
					    }
 | 
				
			||||||
 | 
					    if (isNightwave) {
 | 
				
			||||||
 | 
					        res.NewEpisodeReward = needProcess.length > 0;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
                rewardType = toStoreItem(title.reward!.ItemType);
 | 
					        manifest.favours.filter(x => x.rankUpReward && x.requiredLevel <= newLevel).forEach(x => {
 | 
				
			||||||
                rewardCount = title.reward!.ItemCount;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            const rewardInventoryChanges = (await handleStoreItemAcquisition(rewardType, inventory, rewardCount))
 | 
					 | 
				
			||||||
                .InventoryChanges;
 | 
					 | 
				
			||||||
            if (Object.keys(rewardInventoryChanges).length == 0) {
 | 
					 | 
				
			||||||
                logger.debug(`nightwave rank up reward did not seem to get added, giving 50 creds instead`);
 | 
					 | 
				
			||||||
                const nightwaveCredsItemType = manifest.titles![0].reward!.ItemType;
 | 
					 | 
				
			||||||
                rewardInventoryChanges.MiscItems = [{ ItemType: nightwaveCredsItemType, ItemCount: 50 }];
 | 
					 | 
				
			||||||
                addMiscItems(inventory, rewardInventoryChanges.MiscItems);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            combineInventoryChanges(res.InventoryChanges, rewardInventoryChanges);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
        if (syndicate.Title > 0 && manifest.favours.find(x => x.rankUpReward && x.requiredLevel == syndicate.Title)) {
 | 
					 | 
				
			||||||
            syndicate.FreeFavorsEarned ??= [];
 | 
					            syndicate.FreeFavorsEarned ??= [];
 | 
				
			||||||
            if (!syndicate.FreeFavorsEarned.includes(syndicate.Title)) {
 | 
					            if (!syndicate.FreeFavorsEarned.includes(x.requiredLevel)) {
 | 
				
			||||||
                syndicate.FreeFavorsEarned.push(syndicate.Title);
 | 
					                syndicate.FreeFavorsEarned.push(x.requiredLevel);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    }
 | 
					    syndicate.Title = newLevel;
 | 
				
			||||||
 | 
					 | 
				
			||||||
    await inventory.save();
 | 
					    await inventory.save();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    response.json(res);
 | 
					    response.json(res);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user