diff --git a/src/lib/data/cox.ts b/src/lib/data/cox.ts index 88c98d274b..8e5a76595a 100644 --- a/src/lib/data/cox.ts +++ b/src/lib/data/cox.ts @@ -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); @@ -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; } } @@ -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; } } diff --git a/src/mahoji/lib/abstracted_commands/coxCommand.ts b/src/mahoji/lib/abstracted_commands/coxCommand.ts index 85f5ba450b..93d24031f5 100644 --- a/src/mahoji/lib/abstracted_commands/coxCommand.ts +++ b/src/mahoji/lib/abstracted_commands/coxCommand.ts @@ -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]; @@ -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; diff --git a/tests/integration/pvm/cox.test.ts b/tests/integration/pvm/cox.test.ts new file mode 100644 index 0000000000..cc9ceed076 --- /dev/null +++ b/tests/integration/pvm/cox.test.ts @@ -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); +});