Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
nwjgit committed Jul 14, 2024
1 parent dd95812 commit ebd3cb5
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 89 deletions.
2 changes: 1 addition & 1 deletion src/lib/data/Collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ export const allCollectionLogs: ICollection = {
...Monsters.Vardorvis.allItems,
...Monsters.DukeSucellus.allItems
],
items: [...theLeviathanCL, ...theWhispererCL, ...vardorvisCL, ...dukeSucellusCL]
items: [...theLeviathanCL, ...theWhispererCL, ...vardorvisCL, ...dukeSucellusCL]
},
Creatables: {
counts: false,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/data/creatables/dt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const dtCreatables: Createable[] = [
.add("Executioner's axe head")
.add('Eye of the duke')
.add('Blood rune', 2000),
outputItems: new Bank().add(25484) //use id to prevent beta id usage
outputItems: new Bank().add(25484) //use id to prevent beta id usage
//TODO: 28338 is the proper id but OSJS is missing this item??
}
];
35 changes: 20 additions & 15 deletions src/lib/util/parseStringBank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { itemNameMap } from 'oldschooljs/dist/structures/Items';

import { ONE_TRILLION } from '../constants';
import { filterableTypes } from '../data/filterables';
import { setItemAlias } from '../data/itemAliases';
import { cleanString, getItem, stringMatches } from '../util';
import itemIsTradeable from './itemIsTradeable';
import { setItemAlias } from '../data/itemAliases';

const { floor, max, min } = Math;

Expand Down Expand Up @@ -57,7 +57,12 @@ export function parseQuantityAndItem(str = '', inputBank?: Bank): [Item[], numbe
return [osItems, quantity];
}

export function parseStringBank(str = '', inputBank?: Bank, noDuplicateItems?: true, itemAliases?: true): [Item, number | undefined][] {
export function parseStringBank(
str = '',
inputBank?: Bank,
noDuplicateItems?: true,
itemAliases?: true
): [Item, number | undefined][] {
const split = str
.trim()
.replace(/\s\s+/g, ' ')
Expand All @@ -71,19 +76,19 @@ export function parseStringBank(str = '', inputBank?: Bank, noDuplicateItems?: t
if (resItems !== undefined) {
for (const item of noDuplicateItems ? resItems.slice(0, 1) : resItems) {
if (currentIDs.has(item.id)) continue;
let resolvedItem: Item | null = item;
if (itemAliases) {
resolvedItem = getItem(item.name);
}
if (resolvedItem) {
items.push([resolvedItem, quantity]);
currentIDs.add(resolvedItem.id);
}
}
}
}
return items;
let resolvedItem: Item | null = item;
if (itemAliases) {
resolvedItem = getItem(item.name);
}
if (resolvedItem) {
items.push([resolvedItem, quantity]);
currentIDs.add(resolvedItem.id);
}
}
}
}

return items;
}

function parseBankFromFlags({
Expand Down
140 changes: 69 additions & 71 deletions src/lib/util/repairBrokenItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,44 @@ import { notEmpty } from 'e';
import { Items } from 'oldschooljs';

import { userStatsUpdate } from '../../mahoji/mahojiSettings';
import type { ItemBank } from '../types';
import { type GearSetup, GearSetupTypes } from '../gear/types';
import type { ItemBank } from '../types';

interface ItemSwaps {
item: string;
wrongID: number;
correctID: number;
item: string;
wrongID: number;
correctID: number;
}

const itemswaps: ItemSwaps[] = [
{
item: 'Bellator ring',
wrongID: 25488,
correctID: 28316
},
{
item: 'Ultor ring',
wrongID: 25485,
correctID: 28307
},
{
item: 'Magus ring',
wrongID: 25486,
correctID: 28313
},
{
item: 'Venator ring',
wrongID: 25487,
correctID: 28310
}
/* TODO: id 28338 is missing from OSJS in item_data.json
{
item: 'Bellator ring',
wrongID: 25488,
correctID: 28316
},
{
item: 'Ultor ring',
wrongID: 25485,
correctID: 28307
},
{
item: 'Magus ring',
wrongID: 25486,
correctID: 28313
},
{
item: 'Venator ring',
wrongID: 25487,
correctID: 28310
}
/* TODO: id 28338 is missing from OSJS in item_data.json
{
item: 'Soulreaper axe',
wrongID: 25484,
correctID: 28338
}
*/
]
];

export async function repairBrokenItemsFromUser(mUser: MUser): Promise<[string] | [string, any[]]> {
const { user } = mUser;
Expand Down Expand Up @@ -74,61 +74,61 @@ export async function repairBrokenItemsFromUser(mUser: MUser): Promise<[string]
['gear', allGearItemIDs]
];

for (const [, ids] of allItemsToCheck) {
for (const id of ids.map(i => Number(i))) {
const item = Items.get(id);
if (!item) {
brokenBank.push(id);
} else {
const swap = itemswaps.find(s => s.wrongID === id);
if (swap) {
brokenBank.push(id);
}
}
}
}
for (const [, ids] of allItemsToCheck) {
for (const id of ids.map(i => Number(i))) {
const item = Items.get(id);
if (!item) {
brokenBank.push(id);
} else {
const swap = itemswaps.find(s => s.wrongID === id);
if (swap) {
brokenBank.push(id);
}
}
}
}

const newFavs = favorites.filter(i => !brokenBank.includes(i));
const newBank = { ...rawBank };
const newCL = { ...rawCL };
const newTempCL = { ...rawTempCL };
const newSacLog = { ...rawSacLog };

for (const id of brokenBank) {
const swap = itemswaps.find(s => s.wrongID === id);
if (swap) {
if (newBank[id]) {
newBank[swap.correctID] = (newBank[swap.correctID] || 0) + newBank[id];
}
if (newCL[id]) {
newCL[swap.correctID] = (newCL[swap.correctID] || 0) + newCL[id];
}
if (newTempCL[id]) {
newTempCL[swap.correctID] = (newTempCL[swap.correctID] || 0) + newTempCL[id];
}
if (newSacLog[id]) {
newSacLog[swap.correctID] = (newSacLog[swap.correctID] || 0) + newSacLog[id];
}
}
delete newBank[id];
delete newCL[id];
delete newTempCL[id];
delete newSacLog[id];
}
for (const id of brokenBank) {
const swap = itemswaps.find(s => s.wrongID === id);
if (swap) {
if (newBank[id]) {
newBank[swap.correctID] = (newBank[swap.correctID] || 0) + newBank[id];
}
if (newCL[id]) {
newCL[swap.correctID] = (newCL[swap.correctID] || 0) + newCL[id];
}
if (newTempCL[id]) {
newTempCL[swap.correctID] = (newTempCL[swap.correctID] || 0) + newTempCL[id];
}
if (newSacLog[id]) {
newSacLog[swap.correctID] = (newSacLog[swap.correctID] || 0) + newSacLog[id];
}
}
delete newBank[id];
delete newCL[id];
delete newTempCL[id];
delete newSacLog[id];
}

for (const setupType of GearSetupTypes) {
const _gear = user[`gear_${setupType}`] as GearSetup | null;
if (_gear === null) continue;
const gear = { ..._gear };
for (const [key, value] of Object.entries(gear)) {
if (value === null) continue;
const swap = itemswaps.find(s => s.wrongID === value.item);
if (brokenBank.includes(value.item)) {
delete gear[key as keyof GearSetup];
}
if (swap) {
gear[key as keyof GearSetup] = { ...value, item: swap.correctID };
}
const swap = itemswaps.find(s => s.wrongID === value.item);
if (brokenBank.includes(value.item)) {
delete gear[key as keyof GearSetup];
}
if (swap) {
gear[key as keyof GearSetup] = { ...value, item: swap.correctID };
}
}
// @ts-ignore ???
changes[`gear_${setupType}`] = gear;
Expand Down Expand Up @@ -156,9 +156,7 @@ export async function repairBrokenItemsFromUser(mUser: MUser): Promise<[string]
return [
`You had ${
brokenBank.length
} broken items in your bank/collection log/favorites/gear, they were removed. ${
brokenBank
.slice(0, 500)}`,
} broken items in your bank/collection log/favorites/gear, they were removed. ${brokenBank.slice(0, 500)}`,
Object.keys(brokenBank)
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/mahoji/commands/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { getItem } from '../../lib/util/getOSItem';
import { handleMahojiConfirmation } from '../../lib/util/handleMahojiConfirmation';
import { deferInteraction } from '../../lib/util/interactionReply';
import { makeBankImage } from '../../lib/util/makeBankImage';
import { repairBrokenItemsFromUser } from '../../lib/util/repairBrokenItems';
import {
getParsedStashUnits,
stashUnitBuildAllCommand,
Expand All @@ -51,7 +52,6 @@ import {
import { itemOption, monsterOption, skillOption } from '../lib/mahojiCommandOptions';
import type { OSBMahojiCommand } from '../lib/util';
import { patronMsg } from '../mahojiSettings';
import { repairBrokenItemsFromUser } from '../../lib/util/repairBrokenItems';

const INTERVAL_DAY = 'day';
const INTERVAL_WEEK = 'week';
Expand Down

0 comments on commit ebd3cb5

Please sign in to comment.