XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

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

1fe8351d
Sainan <sainan@calamity.gg>
提交于

代码差异

3 个文件 +88 -65
Modified src/models/inventoryModels/inventoryModel.ts +30 -23
@@ -197,29 +197,32 @@ ArchonCrystalUpgradeSchema.set("toJSON", {
197 197 }
198 198 });
199 199
200 const EquipmentSchema = new Schema<IEquipmentDatabase>({
201 ItemType: String,
202 Configs: [ItemConfigSchema],
203 UpgradeVer: Number,
204 XP: Number,
205 Features: Number,
206 Polarized: Number,
207 Polarity: [polaritySchema],
208 FocusLens: String,
209 ModSlotPurchases: Number,
210 CustomizationSlotPurchases: Number,
211 UpgradeType: String,
212 UpgradeFingerprint: String,
213 ItemName: String,
214 InfestationDate: Date,
215 InfestationDays: Number,
216 InfestationType: String,
217 ModularParts: [String],
218 UnlockLevel: Number,
219 Expiry: Date,
220 SkillTree: String,
221 ArchonCrystalUpgrades: { type: [ArchonCrystalUpgradeSchema], default: undefined }
222 });
200 const EquipmentSchema = new Schema<IEquipmentDatabase>(
201 {
202 ItemType: String,
203 Configs: [ItemConfigSchema],
204 UpgradeVer: Number,
205 XP: Number,
206 Features: Number,
207 Polarized: Number,
208 Polarity: [polaritySchema],
209 FocusLens: String,
210 ModSlotPurchases: Number,
211 CustomizationSlotPurchases: Number,
212 UpgradeType: String,
213 UpgradeFingerprint: String,
214 ItemName: String,
215 InfestationDate: Date,
216 InfestationDays: Number,
217 InfestationType: String,
218 ModularParts: { type: [String], default: undefined },
219 UnlockLevel: Number,
220 Expiry: Date,
221 SkillTree: String,
222 ArchonCrystalUpgrades: { type: [ArchonCrystalUpgradeSchema], default: undefined }
223 },
224 { id: false }
225 );
223 226
224 227 EquipmentSchema.virtual("ItemId").get(function () {
225 228 return { $oid: this._id.toString() } satisfies IOid;
@@ -955,6 +958,10 @@ type InventoryDocumentProps = {
955 958 Sentinels: Types.DocumentArray<IEquipmentDatabase>;
956 959 Horses: Types.DocumentArray<IEquipmentDatabase>;
957 960 PendingRecipes: Types.DocumentArray<IPendingRecipeDatabase>;
961 SpaceSuits: Types.DocumentArray<IEquipmentDatabase>;
962 SpaceGuns: Types.DocumentArray<IEquipmentDatabase>;
963 SpaceMelee: Types.DocumentArray<IEquipmentDatabase>;
964 SentinelWeapons: Types.DocumentArray<IEquipmentDatabase>;
958 965 };
959 966
960 967 // eslint-disable-next-line @typescript-eslint/ban-types
Modified src/services/inventoryService.ts +57 -42
@@ -92,33 +92,51 @@ export const addItem = async (
92 92 // Path-based duck typing
93 93 switch (typeName.substr(1).split("/")[1]) {
94 94 case "Powersuits":
95 if (typeName.includes("EntratiMech")) {
96 const mechSuit = await addMechSuit(typeName, accountId);
97 await updateSlots(accountId, InventorySlot.MECHSUITS, 0, 1);
98 logger.debug("mech suit", mechSuit);
99 return {
100 InventoryChanges: {
101 MechBin: {
102 count: 1,
103 platinum: 0,
104 Slots: -1
105 },
106 MechSuits: [mechSuit]
107 }
108 };
109 }
110 const suit = await addPowerSuit(typeName, accountId);
111 await updateSlots(accountId, InventorySlot.SUITS, 0, 1);
112 return {
113 InventoryChanges: {
114 SuitBin: {
115 count: 1,
116 platinum: 0,
117 Slots: -1
118 },
119 Suits: [suit]
95 switch (typeName.substr(1).split("/")[2]) {
96 default: {
97 const suit = await addPowerSuit(typeName, accountId);
98 await updateSlots(accountId, InventorySlot.SUITS, 0, 1);
99 return {
100 InventoryChanges: {
101 SuitBin: {
102 count: 1,
103 platinum: 0,
104 Slots: -1
105 },
106 Suits: [suit]
107 }
108 };
120 109 }
121 };
110 case "Archwing": {
111 const spaceSuit = await addSpaceSuit(typeName, accountId);
112 await updateSlots(accountId, InventorySlot.SPACESUITS, 0, 1);
113 return {
114 InventoryChanges: {
115 SpaceSuitBin: {
116 count: 1,
117 platinum: 0,
118 Slots: -1
119 },
120 SpaceSuits: [spaceSuit]
121 }
122 };
123 }
124 case "EntratiMech": {
125 const mechSuit = await addMechSuit(typeName, accountId);
126 await updateSlots(accountId, InventorySlot.MECHSUITS, 0, 1);
127 return {
128 InventoryChanges: {
129 MechBin: {
130 count: 1,
131 platinum: 0,
132 Slots: -1
133 },
134 MechSuits: [mechSuit]
135 }
136 };
137 }
138 }
139 break;
122 140 case "Weapons":
123 141 const weaponType = getWeaponType(typeName);
124 142 const weapon = await addWeapon(weaponType, typeName, accountId);
@@ -277,6 +295,13 @@ export const addSpecialItem = async (itemName: string, accountId: string) => {
277 295 return changedInventory.SpecialItems[specialItemIndex - 1].toJSON();
278 296 };
279 297
298 export const addSpaceSuit = async (spacesuitName: string, accountId: string) => {
299 const inventory = await getInventory(accountId);
300 const suitIndex = inventory.SpaceSuits.push({ ItemType: spacesuitName, Configs: [], UpgradeVer: 101, XP: 0 });
301 const changedInventory = await inventory.save();
302 return changedInventory.SpaceSuits[suitIndex - 1].toJSON();
303 };
304
280 305 export const updateSlots = async (accountId: string, slotName: SlotNames, slotAmount: number, extraAmount: number) => {
281 306 const inventory = await getInventory(accountId);
282 307
@@ -391,22 +416,12 @@ export const addWeapon = async (
391 416 ): Promise<IEquipmentClient> => {
392 417 const inventory = await getInventory(accountId);
393 418
394 let weaponIndex;
395 switch (weaponType) {
396 case "LongGuns":
397 case "Pistols":
398 case "Melee":
399 case "OperatorAmps":
400 weaponIndex = inventory[weaponType].push({
401 ItemType: weaponName,
402 Configs: [],
403 XP: 0,
404 ModularParts: modularParts
405 });
406 break;
407 default:
408 throw new Error("unknown weapon type: " + weaponType);
409 }
419 const weaponIndex = inventory[weaponType].push({
420 ItemType: weaponName,
421 Configs: [],
422 XP: 0,
423 ModularParts: modularParts
424 });
410 425
411 426 const changedInventory = await inventory.save();
412 427 return changedInventory[weaponType][weaponIndex - 1].toJSON();
Modified src/types/inventoryTypes/inventoryTypes.ts +1 -0
@@ -358,6 +358,7 @@ export interface ICombat {
358 358 export enum InventorySlot {
359 359 SUITS = "SuitBin",
360 360 WEAPONS = "WeaponBin",
361 SPACESUITS = "SpaceSuitBin",
361 362 MECHSUITS = "MechBin",
362 363 PVE_LOADOUTS = "PveBonusLoadoutBin",
363 364 SENTINELS = "SentinelBin"