Skip to content

Commit

Permalink
Merge branch 'master' into tempor-rope
Browse files Browse the repository at this point in the history
  • Loading branch information
TastyPumPum authored Oct 11, 2023
2 parents 4f9bf76 + 7297e2f commit e4e7540
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/lib/MUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ GROUP BY data->>'clueID';`);
const { bank } = this;
const items = resolveItems(_items);
for (const baseID of items) {
const similarItems = [...getSimilarItems(baseID), baseID];
const similarItems = getSimilarItems(baseID);
const hasOneEquipped = similarItems.some(id => this.hasEquipped(id, true));
const hasOneInBank = similarItems.some(id => bank.has(id));
// If only one needs to be equipped, return true now if it is equipped.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/combat_achievements/grandmaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ export const grandmasterCombatAchievements: CombatAchievement[] = [
monster: 'Theatre of Blood',
rng: {
chancePerKill: 50,
hasChance: data => data.type === 'TheatreOfBlood' && (data as TheatreOfBloodTaskOptions).hardMode
hasChance: 'TheatreOfBlood'
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/lib/data/similarItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,5 +369,5 @@ for (const [baseItem, similarItems] of source) {

export function getSimilarItems(itemID: number): number[] {
const similars = similarItems.get(itemID);
return similars ? [itemID, ...similars] : [];
return similars ? [itemID, ...similars] : [itemID];
}
6 changes: 4 additions & 2 deletions src/lib/rolesTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,10 @@ SELECT id, (cardinality(u.cl_keys) - u.inverse_length) as qty
let topSacrificers: string[] = [];
const mostValue = await q<any[]>('SELECT id FROM users ORDER BY "sacrificedValue" DESC LIMIT 3;');
for (let i = 0; i < 3; i++) {
topSacrificers.push(mostValue[i].id);
addToUserMap(userMap, mostValue[i].id, `Rank ${i + 1} Sacrifice Value`);
if (mostValue[i] !== undefined) {
topSacrificers.push(mostValue[i].id);
addToUserMap(userMap, mostValue[i].id, `Rank ${i + 1} Sacrifice Value`);
}
}
const mostValueIronman = await q<any[]>(
'SELECT id FROM users WHERE "minion.ironman" = true ORDER BY "sacrificedValue" DESC LIMIT 1;'
Expand Down
10 changes: 3 additions & 7 deletions src/lib/structures/Gear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,7 @@ export class Gear {
if (inverse) {
values.push(...inverse.values());
}
const similarItems = getSimilarItems(item);
if (similarItems) {
values.push(...similarItems);
}
values.push(...getSimilarItems(item));
}
}

Expand Down Expand Up @@ -471,16 +468,15 @@ export class Gear {
let currentCount = 0;
for (const i of [...items]) {
const similarItems = getSimilarItems(i);
if (similarItems.length > 0) {
if (similarItems.some(si => allItems.includes(si))) currentCount++;
if (similarItems.some(si => allItems.includes(si))) {
currentCount++;
} else if (allItems.includes(i)) currentCount++;
}
return currentCount === targetCount;
}
// similar = true, every = false
for (const i of [...items]) {
const similarItems = getSimilarItems(i);
similarItems.push(i);
if (similarItems.some(si => allItems.includes(si))) return true;
}
return false;
Expand Down
8 changes: 7 additions & 1 deletion src/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { ADMIN_IDS, OWNER_IDS, SupportServer } from '../config';
import { ClueTiers } from './clues/clueTiers';
import { badgesCache, BitField, projectiles, usernameCache } from './constants';
import { UserStatsDataNeededForCL } from './data/Collections';
import { getSimilarItems } from './data/similarItems';
import { DefenceGearStat, GearSetupType, GearSetupTypes, GearStat, OffenceGearStat } from './gear/types';
import type { Consumable } from './minions/types';
import { MUserClass } from './MUser';
Expand Down Expand Up @@ -515,7 +516,12 @@ export function checkRangeGearWeapon(gear: Gear) {
const { ammo } = gear;
if (!ammo) return 'You have no ammo equipped.';

const projectileCategory = objectEntries(projectiles).find(i => i[1].weapons.includes(weapon.id));
const projectileCategory = objectEntries(projectiles).find(i =>
i[1].weapons
.map(w => getSimilarItems(w))
.flat()
.includes(weapon.id)
);
if (!projectileCategory) return 'You have an invalid range weapon.';
if (!projectileCategory[1].items.includes(ammo.item)) {
return `You have invalid ammo for your equipped weapon. For ${
Expand Down
10 changes: 3 additions & 7 deletions src/mahoji/lib/abstracted_commands/infernoCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ async function infernoRun({
const weapon = setup.equippedWeapon();
const validWeapons = Object.keys(weapons)
.map(itemID)
.map(id => [...getSimilarItems(id), id])
.map(id => getSimilarItems(id))
.flat();
if (!weapon || !validWeapons.includes(weapon.id)) {
return `You need one of these weapons in your ${name} setup: ${Object.keys(weapons).join(', ')}.`;
Expand All @@ -282,15 +282,11 @@ async function infernoRun({
duration.add(getSimilarItems(itemID('Armadyl crossbow')).includes(rangeGear.equippedWeapon()!.id), 4.5, 'ACB');

zukDeathChance.add(
[...getSimilarItems(itemID('Twisted bow')), itemID('Twisted bow')].includes(rangeGear.equippedWeapon()!.id),
getSimilarItems(itemID('Twisted bow')).includes(rangeGear.equippedWeapon()!.id),
1.5,
'Zuk with TBow'
);
duration.add(
[...getSimilarItems(itemID('Twisted bow')), itemID('Twisted bow')].includes(rangeGear.equippedWeapon()!.id),
-7.5,
'TBow'
);
duration.add(getSimilarItems(itemID('Twisted bow')).includes(rangeGear.equippedWeapon()!.id), -7.5, 'TBow');

/**
*
Expand Down
15 changes: 14 additions & 1 deletion tests/integration/rolesTask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Bank } from 'oldschooljs';
import { describe, expect, test } from 'vitest';

import { runRolesTask } from '../../src/lib/rolesTask';
import { MinigameName, Minigames } from '../../src/lib/settings/minigames';
import { prisma } from '../../src/lib/settings/prisma';
import { cryptoRand } from '../../src/lib/util';
import { userStatsBankUpdate } from '../../src/mahoji/mahojiSettings';
Expand All @@ -14,9 +15,21 @@ describe('Roles Task', async () => {
const user = await createTestUser();
await userStatsBankUpdate(user.id, 'sacrificed_bank', new Bank().add('Coal', 10_000));
const ironUser = await createTestUser();
await ironUser.update({ minion_ironman: true });
await ironUser.update({ minion_ironman: true, sacrificedValue: 1_000_000 });
await userStatsBankUpdate(ironUser.id, 'sacrificed_bank', new Bank().add('Coal', 10_000));

// Create minigame scores:
const minigames = Minigames.map(game => game.column).filter(i => i !== 'tithe_farm');
const minigameUpdate: { [K in MinigameName]?: number } = {};
for (const minigame of minigames) {
minigameUpdate[minigame] = 1000;
}
await prisma.minigame.upsert({
where: { user_id: ironUser.id },
update: minigameUpdate,
create: { user_id: ironUser.id, ...minigameUpdate }
});

await prisma.giveaway.create({
data: {
user_id: user.id,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/similarItems.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describe('Gear', () => {
}
}

expect(getSimilarItems(itemID('Infernal max cape'))).toEqual([]);
expect(getSimilarItems(itemID('Infernal max cape'))).toEqual([itemID('Infernal max cape')]);

test('toa', () => {
let testGear = new Gear({ cape: 'Masori assembler max cape' });
Expand Down

0 comments on commit e4e7540

Please sign in to comment.