forked from OpenWF/SpaceNinjaServer
		
	fix: handle standing limits in fishmongerController (#795)
This commit is contained in:
		
							parent
							
								
									0ace5eb446
								
							
						
					
					
						commit
						79f1937483
					
				@ -1,9 +1,10 @@
 | 
				
			|||||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
					import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
				
			||||||
import { addMiscItems, getInventory } from "@/src/services/inventoryService";
 | 
					import { getMaxStanding } from "@/src/helpers/syndicateStandingHelper";
 | 
				
			||||||
 | 
					import { addMiscItems, getInventory, getStandingLimit, updateStandingLimit } from "@/src/services/inventoryService";
 | 
				
			||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
					import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
				
			||||||
import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
					import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
				
			||||||
import { RequestHandler } from "express";
 | 
					import { RequestHandler } from "express";
 | 
				
			||||||
import { ExportResources } from "warframe-public-export-plus";
 | 
					import { ExportResources, ExportSyndicates } from "warframe-public-export-plus";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const fishmongerController: RequestHandler = async (req, res) => {
 | 
					export const fishmongerController: RequestHandler = async (req, res) => {
 | 
				
			||||||
    const accountId = await getAccountIdForRequest(req);
 | 
					    const accountId = await getAccountIdForRequest(req);
 | 
				
			||||||
@ -11,7 +12,7 @@ export const fishmongerController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
    const body = getJSONfromString(String(req.body)) as IFishmongerRequest;
 | 
					    const body = getJSONfromString(String(req.body)) as IFishmongerRequest;
 | 
				
			||||||
    const miscItemChanges: IMiscItem[] = [];
 | 
					    const miscItemChanges: IMiscItem[] = [];
 | 
				
			||||||
    let syndicateTag: string | undefined;
 | 
					    let syndicateTag: string | undefined;
 | 
				
			||||||
    let standingChange = 0;
 | 
					    let gainedStanding = 0;
 | 
				
			||||||
    for (const fish of body.Fish) {
 | 
					    for (const fish of body.Fish) {
 | 
				
			||||||
        const fishData = ExportResources[fish.ItemType];
 | 
					        const fishData = ExportResources[fish.ItemType];
 | 
				
			||||||
        if (req.query.dissect == "1") {
 | 
					        if (req.query.dissect == "1") {
 | 
				
			||||||
@ -25,21 +26,29 @@ export const fishmongerController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            syndicateTag = fishData.syndicateTag!;
 | 
					            syndicateTag = fishData.syndicateTag!;
 | 
				
			||||||
            standingChange += fishData.standingBonus! * fish.ItemCount;
 | 
					            gainedStanding += fishData.standingBonus! * fish.ItemCount;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        miscItemChanges.push({ ItemType: fish.ItemType, ItemCount: fish.ItemCount * -1 });
 | 
					        miscItemChanges.push({ ItemType: fish.ItemType, ItemCount: fish.ItemCount * -1 });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    addMiscItems(inventory, miscItemChanges);
 | 
					    addMiscItems(inventory, miscItemChanges);
 | 
				
			||||||
    if (standingChange && syndicateTag) {
 | 
					    if (gainedStanding && syndicateTag) {
 | 
				
			||||||
        const syndicate = inventory.Affiliations.find(x => x.Tag == syndicateTag);
 | 
					        let syndicate = inventory.Affiliations.find(x => x.Tag == syndicateTag);
 | 
				
			||||||
        if (syndicate !== undefined) {
 | 
					        if (!syndicate) {
 | 
				
			||||||
            syndicate.Standing += standingChange;
 | 
					            syndicate = inventory.Affiliations[inventory.Affiliations.push({ Tag: syndicateTag, Standing: 0 }) - 1];
 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            inventory.Affiliations.push({
 | 
					 | 
				
			||||||
                Tag: syndicateTag,
 | 
					 | 
				
			||||||
                Standing: standingChange
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        const syndicateMeta = ExportSyndicates[syndicateTag];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const max = getMaxStanding(syndicateMeta, syndicate.Title ?? 0);
 | 
				
			||||||
 | 
					        if (syndicate.Standing + gainedStanding > max) {
 | 
				
			||||||
 | 
					            gainedStanding = max - syndicate.Standing;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (gainedStanding > getStandingLimit(inventory, syndicateMeta.dailyLimitBin)) {
 | 
				
			||||||
 | 
					            gainedStanding = getStandingLimit(inventory, syndicateMeta.dailyLimitBin);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        syndicate.Standing += gainedStanding;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        updateStandingLimit(inventory, syndicateMeta.dailyLimitBin, gainedStanding);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    await inventory.save();
 | 
					    await inventory.save();
 | 
				
			||||||
    res.json({
 | 
					    res.json({
 | 
				
			||||||
@ -47,7 +56,7 @@ export const fishmongerController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
            MiscItems: miscItemChanges
 | 
					            MiscItems: miscItemChanges
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        SyndicateTag: syndicateTag,
 | 
					        SyndicateTag: syndicateTag,
 | 
				
			||||||
        StandingChange: standingChange
 | 
					        StandingChange: gainedStanding
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -3,7 +3,8 @@ import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
				
			|||||||
import { addMiscItems, getInventory, getStandingLimit, updateStandingLimit } from "@/src/services/inventoryService";
 | 
					import { addMiscItems, getInventory, getStandingLimit, updateStandingLimit } from "@/src/services/inventoryService";
 | 
				
			||||||
import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
					import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
				
			||||||
import { IOid } from "@/src/types/commonTypes";
 | 
					import { IOid } from "@/src/types/commonTypes";
 | 
				
			||||||
import { ExportSyndicates, ISyndicate } from "warframe-public-export-plus";
 | 
					import { ExportSyndicates } from "warframe-public-export-plus";
 | 
				
			||||||
 | 
					import { getMaxStanding } from "@/src/helpers/syndicateStandingHelper";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const syndicateStandingBonusController: RequestHandler = async (req, res) => {
 | 
					export const syndicateStandingBonusController: RequestHandler = async (req, res) => {
 | 
				
			||||||
    const accountId = await getAccountIdForRequest(req);
 | 
					    const accountId = await getAccountIdForRequest(req);
 | 
				
			||||||
@ -67,14 +68,3 @@ interface ISyndicateStandingBonusRequest {
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
    ModularWeaponId: IOid; // Seems to just be "000000000000000000000000", also note there's a "Category" query field
 | 
					    ModularWeaponId: IOid; // Seems to just be "000000000000000000000000", also note there's a "Category" query field
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
const getMaxStanding = (syndicate: ISyndicate, title: number): number => {
 | 
					 | 
				
			||||||
    if (!syndicate.titles) {
 | 
					 | 
				
			||||||
        // LibrarySyndicate
 | 
					 | 
				
			||||||
        return 125000;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (title == 0) {
 | 
					 | 
				
			||||||
        return syndicate.titles.find(x => x.level == 1)!.minStanding;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    return syndicate.titles.find(x => x.level == title)!.maxStanding;
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										12
									
								
								src/helpers/syndicateStandingHelper.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/helpers/syndicateStandingHelper.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					import { ISyndicate } from "warframe-public-export-plus";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const getMaxStanding = (syndicate: ISyndicate, title: number): number => {
 | 
				
			||||||
 | 
					    if (!syndicate.titles) {
 | 
				
			||||||
 | 
					        // LibrarySyndicate
 | 
				
			||||||
 | 
					        return 125000;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (title == 0) {
 | 
				
			||||||
 | 
					        return syndicate.titles.find(x => x.level == 1)!.minStanding;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return syndicate.titles.find(x => x.level == title)!.maxStanding;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user