feat: handle purchasing of archwing, archgun, & archmelee (#326)

This commit is contained in:
Sainan 2024-06-19 17:46:12 +02:00 committed by GitHub
parent f1237d562d
commit 1fe8351dca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 88 additions and 65 deletions

View File

@ -197,29 +197,32 @@ ArchonCrystalUpgradeSchema.set("toJSON", {
} }
}); });
const EquipmentSchema = new Schema<IEquipmentDatabase>({ const EquipmentSchema = new Schema<IEquipmentDatabase>(
ItemType: String, {
Configs: [ItemConfigSchema], ItemType: String,
UpgradeVer: Number, Configs: [ItemConfigSchema],
XP: Number, UpgradeVer: Number,
Features: Number, XP: Number,
Polarized: Number, Features: Number,
Polarity: [polaritySchema], Polarized: Number,
FocusLens: String, Polarity: [polaritySchema],
ModSlotPurchases: Number, FocusLens: String,
CustomizationSlotPurchases: Number, ModSlotPurchases: Number,
UpgradeType: String, CustomizationSlotPurchases: Number,
UpgradeFingerprint: String, UpgradeType: String,
ItemName: String, UpgradeFingerprint: String,
InfestationDate: Date, ItemName: String,
InfestationDays: Number, InfestationDate: Date,
InfestationType: String, InfestationDays: Number,
ModularParts: [String], InfestationType: String,
UnlockLevel: Number, ModularParts: { type: [String], default: undefined },
Expiry: Date, UnlockLevel: Number,
SkillTree: String, Expiry: Date,
ArchonCrystalUpgrades: { type: [ArchonCrystalUpgradeSchema], default: undefined } SkillTree: String,
}); ArchonCrystalUpgrades: { type: [ArchonCrystalUpgradeSchema], default: undefined }
},
{ id: false }
);
EquipmentSchema.virtual("ItemId").get(function () { EquipmentSchema.virtual("ItemId").get(function () {
return { $oid: this._id.toString() } satisfies IOid; return { $oid: this._id.toString() } satisfies IOid;
@ -955,6 +958,10 @@ type InventoryDocumentProps = {
Sentinels: Types.DocumentArray<IEquipmentDatabase>; Sentinels: Types.DocumentArray<IEquipmentDatabase>;
Horses: Types.DocumentArray<IEquipmentDatabase>; Horses: Types.DocumentArray<IEquipmentDatabase>;
PendingRecipes: Types.DocumentArray<IPendingRecipeDatabase>; PendingRecipes: Types.DocumentArray<IPendingRecipeDatabase>;
SpaceSuits: Types.DocumentArray<IEquipmentDatabase>;
SpaceGuns: Types.DocumentArray<IEquipmentDatabase>;
SpaceMelee: Types.DocumentArray<IEquipmentDatabase>;
SentinelWeapons: Types.DocumentArray<IEquipmentDatabase>;
}; };
// eslint-disable-next-line @typescript-eslint/ban-types // eslint-disable-next-line @typescript-eslint/ban-types

View File

@ -92,33 +92,51 @@ export const addItem = async (
// Path-based duck typing // Path-based duck typing
switch (typeName.substr(1).split("/")[1]) { switch (typeName.substr(1).split("/")[1]) {
case "Powersuits": case "Powersuits":
if (typeName.includes("EntratiMech")) { switch (typeName.substr(1).split("/")[2]) {
const mechSuit = await addMechSuit(typeName, accountId); default: {
await updateSlots(accountId, InventorySlot.MECHSUITS, 0, 1); const suit = await addPowerSuit(typeName, accountId);
logger.debug("mech suit", mechSuit); await updateSlots(accountId, InventorySlot.SUITS, 0, 1);
return { return {
InventoryChanges: { InventoryChanges: {
MechBin: { SuitBin: {
count: 1, count: 1,
platinum: 0, platinum: 0,
Slots: -1 Slots: -1
}, },
MechSuits: [mechSuit] Suits: [suit]
} }
}; };
}
const suit = await addPowerSuit(typeName, accountId);
await updateSlots(accountId, InventorySlot.SUITS, 0, 1);
return {
InventoryChanges: {
SuitBin: {
count: 1,
platinum: 0,
Slots: -1
},
Suits: [suit]
} }
}; case "Archwing": {
const spaceSuit = await addSpaceSuit(typeName, accountId);
await updateSlots(accountId, InventorySlot.SPACESUITS, 0, 1);
return {
InventoryChanges: {
SpaceSuitBin: {
count: 1,
platinum: 0,
Slots: -1
},
SpaceSuits: [spaceSuit]
}
};
}
case "EntratiMech": {
const mechSuit = await addMechSuit(typeName, accountId);
await updateSlots(accountId, InventorySlot.MECHSUITS, 0, 1);
return {
InventoryChanges: {
MechBin: {
count: 1,
platinum: 0,
Slots: -1
},
MechSuits: [mechSuit]
}
};
}
}
break;
case "Weapons": case "Weapons":
const weaponType = getWeaponType(typeName); const weaponType = getWeaponType(typeName);
const weapon = await addWeapon(weaponType, typeName, accountId); const weapon = await addWeapon(weaponType, typeName, accountId);
@ -277,6 +295,13 @@ export const addSpecialItem = async (itemName: string, accountId: string) => {
return changedInventory.SpecialItems[specialItemIndex - 1].toJSON(); return changedInventory.SpecialItems[specialItemIndex - 1].toJSON();
}; };
export const addSpaceSuit = async (spacesuitName: string, accountId: string) => {
const inventory = await getInventory(accountId);
const suitIndex = inventory.SpaceSuits.push({ ItemType: spacesuitName, Configs: [], UpgradeVer: 101, XP: 0 });
const changedInventory = await inventory.save();
return changedInventory.SpaceSuits[suitIndex - 1].toJSON();
};
export const updateSlots = async (accountId: string, slotName: SlotNames, slotAmount: number, extraAmount: number) => { export const updateSlots = async (accountId: string, slotName: SlotNames, slotAmount: number, extraAmount: number) => {
const inventory = await getInventory(accountId); const inventory = await getInventory(accountId);
@ -391,22 +416,12 @@ export const addWeapon = async (
): Promise<IEquipmentClient> => { ): Promise<IEquipmentClient> => {
const inventory = await getInventory(accountId); const inventory = await getInventory(accountId);
let weaponIndex; const weaponIndex = inventory[weaponType].push({
switch (weaponType) { ItemType: weaponName,
case "LongGuns": Configs: [],
case "Pistols": XP: 0,
case "Melee": ModularParts: modularParts
case "OperatorAmps": });
weaponIndex = inventory[weaponType].push({
ItemType: weaponName,
Configs: [],
XP: 0,
ModularParts: modularParts
});
break;
default:
throw new Error("unknown weapon type: " + weaponType);
}
const changedInventory = await inventory.save(); const changedInventory = await inventory.save();
return changedInventory[weaponType][weaponIndex - 1].toJSON(); return changedInventory[weaponType][weaponIndex - 1].toJSON();

View File

@ -358,6 +358,7 @@ export interface ICombat {
export enum InventorySlot { export enum InventorySlot {
SUITS = "SuitBin", SUITS = "SuitBin",
WEAPONS = "WeaponBin", WEAPONS = "WeaponBin",
SPACESUITS = "SpaceSuitBin",
MECHSUITS = "MechBin", MECHSUITS = "MechBin",
PVE_LOADOUTS = "PveBonusLoadoutBin", PVE_LOADOUTS = "PveBonusLoadoutBin",
SENTINELS = "SentinelBin" SENTINELS = "SentinelBin"