Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test #6195

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/lib/data/cox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,9 +629,12 @@ export async function calcCoxDuration(

// Track degradeable items (fakemass works properly with this code, it wont remove 5x charges):
const degradeableItems: { item: Item; user: MUser; chargesToDegrade: number }[] = [];
const uniqueUsers = new Map();

for (const u of team) {
let userPercentChange = 0;
const isUserReal = !uniqueUsers.has(u.id);
uniqueUsers.set(u.id, true);

// Reduce time for gear
const { total } = calculateUserGearPercents(u);
Expand All @@ -656,7 +659,7 @@ export async function calcCoxDuration(
const canDegrade = checkUserCanUseDegradeableItem(testItem);
if (canDegrade.hasEnough) {
userPercentChange += item.boost;
degradeableItems.push(testItem);
if (isUserReal) degradeableItems.push(testItem);
break;
}
}
Expand All @@ -670,7 +673,7 @@ export async function calcCoxDuration(
const canDegrade = checkUserCanUseDegradeableItem(testItem);
if (canDegrade.hasEnough) {
userPercentChange += item.boost;
degradeableItems.push(testItem);
if (isUserReal) degradeableItems.push(testItem);
break;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/mahoji/lib/abstracted_commands/coxCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,16 @@ export async function coxCommand(
}
};
const channel = globalClient.channels.cache.get(channelID.toString());
if (!channelIsSendable(channel)) return 'No channel found.';

let users: MUser[] = [];
let isFakeMass = false;

const fakeUsers = Math.min(maxSizeInput ?? 5, maxSize);
if (type === 'fakemass') {
users = new Array(fakeUsers).fill(user);
isFakeMass = true;
} else if (type === 'mass') {
if (!channelIsSendable(channel)) return 'No channel found.';
users = (await setupParty(channel, user, partyOptions)).filter(u => !u.minionIsBusy);
} else {
users = [user];
Expand Down Expand Up @@ -240,7 +243,6 @@ export async function coxCommand(

let debugStr = '';
const isSolo = users.length === 1;
const isFakeMass = users.length > 1 && new Set(users).size === 1;

for (const d of degradeables) {
d.chargesToDegrade *= quantity;
Expand Down
59 changes: 59 additions & 0 deletions tests/integration/pvm/cox.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { expect, test } from 'vitest';

import { COXMaxMageGear, COXMaxMeleeGear, COXMaxRangeGear } from '../../../src/lib/data/cox';
import { Bank, itemID, resolveItems } from '../../../src/lib/util';
import { raidCommand } from '../../../src/mahoji/commands/raid';
import { mockClient, mockUser } from '../util';

test('CoX ', async () => {
const client = await mockClient();

const user = await mockUser({
rangeGear: resolveItems(['Venator bow']),
rangeLevel: 70,
venatorBowCharges: 1000,
slayerLevel: 70
});
await user.max();

await user.update({
tum_shadow_charges: 10000,
scythe_of_vitur_charges: 100,
gear_mage: COXMaxMageGear.raw() as any,
gear_melee: COXMaxMeleeGear.raw() as any,
gear_range: {
...(COXMaxRangeGear.raw() as any),
ammo: {
item: itemID('Dragon arrow'),
quantity: 10000
}
},
bank: new Bank()
.add('Shark', 10000)
.add('Stamina potion(4)', 10000)
.add('Super restore(4)', 10000)
.add('Saradomin brew(4)', 10000)
.toJSON()
});
await user.equip('melee', resolveItems(['Scythe of vitur']));
const res = await user.runCommand(
raidCommand,
{
cox: {
start: {
type: 'fakemass',
max_team_size: 5
}
}
},
true
);
expect(res).toContain('the total trip will take');
await user.processActivities(client);
await user.sync();
expect(user.bank.amount('Scythe of vitur (uncharged)')).toBe(1);
expect(user.bank.amount('Scythe of vitur')).toBe(0);
expect(user.gear.melee.weapon?.item).toBeUndefined();
expect(user.allItemsOwned.amount('Scythe of vitur (uncharged)')).toBe(1);
expect(user.allItemsOwned.amount('Scythe of vitur')).toBe(0);
});