Skip to content

Commit c77df51

Browse files
committed
Move projectiles to own file (fixes bso issue)
1 parent 40ff097 commit c77df51

File tree

5 files changed

+65
-104
lines changed

5 files changed

+65
-104
lines changed

src/lib/MUser.ts

Lines changed: 24 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ import { generateAllGearImage, generateGearImage } from '@/lib/canvas/generateGe
2727
import type { IconPackID } from '@/lib/canvas/iconPacks.js';
2828
import { ClueTiers } from '@/lib/clues/clueTiers.js';
2929
import { type CATier, CombatAchievements } from '@/lib/combat_achievements/combatAchievements.js';
30-
import { BitField, MAX_LEVEL, projectiles } from '@/lib/constants.js';
30+
import { BitField, MAX_LEVEL } from '@/lib/constants.js';
3131
import { bossCLItems } from '@/lib/data/Collections.js';
3232
import { allPetIDs, avasDevices } from '@/lib/data/CollectionsExport.js';
3333
import { degradeableItems } from '@/lib/degradeableItems.js';
3434
import { diaries, userhasDiaryTierSync } from '@/lib/diaries.js';
3535
import type { CommandResponseValue } from '@/lib/discord/index.js';
3636
import { mentionCommand } from '@/lib/discord/utils.js';
37+
import { projectiles } from '@/lib/gear/projectiles.js';
3738
import type { GearSetup, UserFullGearSetup } from '@/lib/gear/types.js';
3839
import { handleNewCLItems } from '@/lib/handleNewCLItems.js';
39-
import { marketPriceOfBank } from '@/lib/marketPrices.js';
4040
import backgroundImages from '@/lib/minions/data/bankBackgrounds.js';
4141
import type { CombatOptionsEnum } from '@/lib/minions/data/combatConstants.js';
4242
import { type AddMonsterXpParams, addMonsterXPRaw } from '@/lib/minions/functions/addMonsterXPRaw.js';
@@ -1094,52 +1094,6 @@ Charge your items using ${mentionCommand('minion', 'charge')}.`
10941094
};
10951095
}
10961096

1097-
async calculateNetWorth() {
1098-
const bank = this.allItemsOwned.clone();
1099-
const activeListings = await prisma.gEListing.findMany({
1100-
where: {
1101-
user_id: this.id,
1102-
quantity_remaining: {
1103-
gt: 0
1104-
},
1105-
fulfilled_at: null,
1106-
cancelled_at: null
1107-
},
1108-
include: {
1109-
buyTransactions: true,
1110-
sellTransactions: true
1111-
}
1112-
});
1113-
for (const listing of activeListings) {
1114-
if (listing.type === 'Sell') {
1115-
bank.add(listing.item_id, listing.quantity_remaining);
1116-
} else {
1117-
bank.add('Coins', Number(listing.asking_price_per_item) * listing.quantity_remaining);
1118-
}
1119-
}
1120-
const activeGiveaways = await prisma.giveaway.findMany({
1121-
where: {
1122-
completed: false,
1123-
user_id: this.id
1124-
}
1125-
});
1126-
for (const giveaway of activeGiveaways) {
1127-
bank.add(giveaway.loot as ItemBank);
1128-
}
1129-
const gifts = await prisma.giftBox.findMany({
1130-
where: {
1131-
owner_id: this.id
1132-
}
1133-
});
1134-
for (const gift of gifts) {
1135-
bank.add(gift.items as ItemBank);
1136-
}
1137-
return {
1138-
bank,
1139-
value: marketPriceOfBank(bank)
1140-
};
1141-
}
1142-
11431097
public hasDiary(key: HasDiaryDiaryKey): boolean {
11441098
return this.user.completed_achievement_diaries.includes(key);
11451099
}
@@ -1295,23 +1249,29 @@ declare global {
12951249
var GlobalMUserClass: typeof MUserClass;
12961250
}
12971251

1298-
async function srcMUserFetch(userID: string, updates?: Prisma.UserUpdateInput) {
1299-
const user =
1300-
updates !== undefined
1301-
? await prisma.user.upsert({
1302-
create: {
1303-
id: userID
1304-
},
1305-
update: updates,
1306-
where: {
1307-
id: userID
1308-
}
1309-
})
1310-
: await prisma.user.findUnique({ where: { id: userID } });
1311-
1312-
if (!user) {
1313-
return srcMUserFetch(userID, {});
1252+
async function srcMUserFetch(userID: string) {
1253+
const [user] = await prisma.$queryRaw<User[]>`INSERT INTO users (id)
1254+
VALUES (${userID})
1255+
ON CONFLICT (id) DO UPDATE SET id = EXCLUDED.id
1256+
RETURNING *;
1257+
`;
1258+
for (const [key, val] of Object.entries(user)) {
1259+
if (key.includes('.') || key.includes(' ')) {
1260+
(user as any)[key.replace(/[.\s]/g, '_')] = val;
1261+
// @ts-expect-error
1262+
delete user[key];
1263+
}
13141264
}
1265+
1266+
// const user2 = await prisma.user.upsert({
1267+
// where: { id: userID },
1268+
// update: {},
1269+
// create: { id: userID }
1270+
// });
1271+
1272+
// console.log(deepEqual(user, user2));
1273+
// console.log(omit(user, ['bank', 'collectionLogBank', 'gear.range', 'gear.melee', 'gear.mage', 'gear.wildy']));
1274+
13151275
return new MUserClass(user);
13161276
}
13171277

src/lib/constants.ts

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'node:path';
33
import { isMainThread } from 'node:worker_threads';
44
import { dateFm, Emoji, PerkTier } from '@oldschoolgg/toolkit';
55
import * as dotenv from 'dotenv';
6-
import { convertLVLtoXP, resolveItems } from 'oldschooljs';
6+
import { convertLVLtoXP } from 'oldschooljs';
77
import * as z from 'zod';
88

99
import { activity_type_enum } from '@/prisma/main/enums.js';
@@ -327,42 +327,6 @@ export const SILENT_ERROR = 'SILENT_ERROR';
327327
export const PATRON_ONLY_GEAR_SETUP =
328328
'Sorry - but the `other` gear setup is only available for Tier 3 Patrons (and higher) to use.';
329329

330-
export const projectiles = {
331-
arrow: {
332-
items: resolveItems(['Adamant arrow', 'Rune arrow', 'Amethyst arrow', 'Dragon arrow']),
333-
savedByAvas: true,
334-
weapons: resolveItems(['Twisted bow'])
335-
},
336-
ogreArrow: {
337-
items: resolveItems(['Ogre Arrow']),
338-
savedByAvas: true,
339-
weapons: resolveItems(['Ogre bow'])
340-
},
341-
bolt: {
342-
items: resolveItems([
343-
'Runite bolts',
344-
'Dragon bolts',
345-
'Diamond bolts (e)',
346-
'Diamond dragon bolts (e)',
347-
'Ruby dragon bolts (e)'
348-
]),
349-
savedByAvas: true,
350-
weapons: resolveItems([
351-
'Armadyl crossbow',
352-
'Dragon hunter crossbow',
353-
'Dragon crossbow',
354-
'Zaryte crossbow',
355-
'Rune crossbow'
356-
])
357-
},
358-
javelin: {
359-
items: resolveItems(['Amethyst javelin', 'Rune javelin', 'Dragon javelin']),
360-
savedByAvas: false,
361-
weapons: resolveItems(['Heavy ballista'])
362-
}
363-
} as const;
364-
export type ProjectileType = keyof typeof projectiles;
365-
366330
export const NMZ_STRATEGY = ['experience', 'points'] as const;
367331
export type NMZStrategy = (typeof NMZ_STRATEGY)[number];
368332

src/lib/gear/functions/checkRangeGearWeapon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { objectEntries } from '@oldschoolgg/toolkit';
22
import { EItem, Items } from 'oldschooljs';
33

4-
import { projectiles } from '@/lib/constants.js';
54
import { getSimilarItems } from '@/lib/data/similarItems.js';
5+
import { projectiles } from '@/lib/gear/projectiles.js';
66
import type { Gear } from '@/lib/structures/Gear.js';
77
import { formatList } from '@/lib/util/smallUtils.js';
88

src/lib/gear/projectiles.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { resolveItems } from 'oldschooljs';
2+
3+
export const projectiles = {
4+
arrow: {
5+
items: resolveItems(['Adamant arrow', 'Rune arrow', 'Amethyst arrow', 'Dragon arrow']),
6+
savedByAvas: true,
7+
weapons: resolveItems(['Twisted bow'])
8+
},
9+
ogreArrow: {
10+
items: resolveItems(['Ogre Arrow']),
11+
savedByAvas: true,
12+
weapons: resolveItems(['Ogre bow'])
13+
},
14+
bolt: {
15+
items: resolveItems([
16+
'Runite bolts',
17+
'Dragon bolts',
18+
'Diamond bolts (e)',
19+
'Diamond dragon bolts (e)',
20+
'Ruby dragon bolts (e)'
21+
]),
22+
savedByAvas: true,
23+
weapons: resolveItems([
24+
'Armadyl crossbow',
25+
'Dragon hunter crossbow',
26+
'Dragon crossbow',
27+
'Zaryte crossbow',
28+
'Rune crossbow'
29+
])
30+
},
31+
javelin: {
32+
items: resolveItems(['Amethyst javelin', 'Rune javelin', 'Dragon javelin']),
33+
savedByAvas: false,
34+
weapons: resolveItems(['Heavy ballista'])
35+
}
36+
} as const;
37+
export type ProjectileType = keyof typeof projectiles;

src/mahoji/lib/abstracted_commands/infernoCommand.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { calcPercentOfNum, Emoji, formatDuration, sumArr, Time } from '@oldschoo
33
import { Bank, type ItemBank, Items, itemID, Monsters } from 'oldschooljs';
44

55
import { newChatHeadImage } from '@/lib/canvas/chatHeadImage.js';
6-
import type { ProjectileType } from '@/lib/constants.js';
7-
import { BitField, projectiles } from '@/lib/constants.js';
6+
import { BitField } from '@/lib/constants.js';
87
import { getSimilarItems } from '@/lib/data/similarItems.js';
8+
import { type ProjectileType, projectiles } from '@/lib/gear/projectiles.js';
99
import { blowpipeDarts } from '@/lib/minions/functions/blowpipeCommand.js';
1010
import type { BlowpipeData } from '@/lib/minions/types.js';
1111
import { PercentCounter } from '@/lib/structures/PercentCounter.js';

0 commit comments

Comments
 (0)