Booster purchase fix
This commit is contained in:
parent
5facad179c
commit
bd79fee02f
@ -186,30 +186,23 @@ export const missionInventoryUpdate = async (data: MissionInventoryUpdate, accou
|
|||||||
await inventory.save();
|
await inventory.save();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addBooster = async (boosterName: string, accountId: string): Promise<void> => {
|
export const addBooster = async (ItemType: string, time: number, accountId: string): Promise<void> => {
|
||||||
const match = boosterName.match(/(\d+)Day/);
|
const currentTime = Math.floor(Date.now() / 1000) - 129600; // booster time getting more without 129600, probably defence logic, idk
|
||||||
if (!match) return;
|
|
||||||
|
|
||||||
const extractedDigit = Number(match[1]);
|
|
||||||
const ItemType = boosterName.replace(`${extractedDigit}Day`, "");
|
|
||||||
const plusTime = 86400 * extractedDigit;
|
|
||||||
const currentTime = Math.floor(Date.now() / 1000);
|
|
||||||
|
|
||||||
const inventory = await getInventory(accountId);
|
const inventory = await getInventory(accountId);
|
||||||
const { Boosters } = inventory;
|
const { Boosters } = inventory;
|
||||||
|
|
||||||
let itemIndex = Boosters.findIndex(i => i.ItemType === ItemType);
|
const itemIndex = Boosters.findIndex(i => i.ItemType === ItemType);
|
||||||
|
|
||||||
if (itemIndex !== -1) {
|
if (itemIndex !== -1) {
|
||||||
const existingBooster = Boosters[itemIndex];
|
const existingBooster = Boosters[itemIndex];
|
||||||
existingBooster.ExpiryDate = Math.max(existingBooster.ExpiryDate, currentTime) + plusTime;
|
existingBooster.ExpiryDate = Math.max(existingBooster.ExpiryDate, currentTime) + time;
|
||||||
inventory.markModified(`Boosters.${itemIndex}.ExpiryDate`);
|
inventory.markModified(`Boosters.${itemIndex}.ExpiryDate`);
|
||||||
} else {
|
} else {
|
||||||
itemIndex = Boosters.push({ ItemType, ExpiryDate: currentTime + plusTime }) - 1;
|
Boosters.push({ ItemType, ExpiryDate: currentTime + time }) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const changedInventory = await inventory.save();
|
await inventory.save();
|
||||||
return changedInventory.Boosters[itemIndex].toJSON();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export { createInventory, addPowerSuit };
|
export { createInventory, addPowerSuit };
|
||||||
|
@ -112,12 +112,28 @@ const handleSuitCustomizationsPurchase = async (customizationName: string, accou
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleBoostersPurchase = async (boosterName: string, accountId: string) => {
|
const boosterCollection = [
|
||||||
const addedBooster = await addBooster(boosterName, accountId);
|
"/Lotus/Types/Boosters/ResourceAmountBooster",
|
||||||
|
"/Lotus/Types/Boosters/AffinityBooster",
|
||||||
|
"/Lotus/Types/Boosters/ResourceDropChanceBooster",
|
||||||
|
"/Lotus/Types/Boosters/CreditBooster"
|
||||||
|
];
|
||||||
|
|
||||||
|
const handleBoostersPurchase = async (boosterStoreName: string, accountId: string) => {
|
||||||
|
const match = boosterStoreName.match(/(\d+)Day/);
|
||||||
|
if (!match) return;
|
||||||
|
|
||||||
|
const extractedDigit = Number(match[1]);
|
||||||
|
const ItemType = boosterCollection.find(i =>
|
||||||
|
boosterStoreName.includes(i.split("/").pop()!.replace("Booster", ""))
|
||||||
|
)!;
|
||||||
|
const ExpiryDate = extractedDigit * 86400;
|
||||||
|
|
||||||
|
await addBooster(ItemType, ExpiryDate, accountId);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
InventoryChanges: {
|
InventoryChanges: {
|
||||||
Boosters: [addedBooster]
|
Boosters: [{ ItemType, ExpiryDate }]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user