From d7bfd17fc80e46e4e3bb126e4eca9f4e3a6aafb6 Mon Sep 17 00:00:00 2001 From: TastyPumPum Date: Fri, 9 Feb 2024 17:17:42 +0000 Subject: [PATCH] Changes --- src/lib/slayer/tasks/index.ts | 2 + src/mahoji/commands/testpotato.ts | 84 ++++++++++++------- .../lib/abstracted_commands/minionKill.ts | 2 +- 3 files changed, 55 insertions(+), 33 deletions(-) diff --git a/src/lib/slayer/tasks/index.ts b/src/lib/slayer/tasks/index.ts index a514c6c844..b33c3dccc0 100644 --- a/src/lib/slayer/tasks/index.ts +++ b/src/lib/slayer/tasks/index.ts @@ -18,3 +18,5 @@ export const allSlayerTasks: AssignableSlayerTask[] = [ ...vannakaTasks, ...duradelTasks ]; + +export const allSlayerMonsters = allSlayerTasks.map(m => m.monster); diff --git a/src/mahoji/commands/testpotato.ts b/src/mahoji/commands/testpotato.ts index ee39f6e46c..eff1da8f92 100644 --- a/src/mahoji/commands/testpotato.ts +++ b/src/mahoji/commands/testpotato.ts @@ -21,12 +21,13 @@ import { allOpenables } from '../../lib/openables'; import { tiers } from '../../lib/patreon'; import { Minigames } from '../../lib/settings/minigames'; import { prisma } from '../../lib/settings/prisma'; -import { getNewUser } from '../../lib/settings/settings'; import { getFarmingInfo } from '../../lib/skilling/functions/getFarmingInfo'; import Skills from '../../lib/skilling/skills'; import Farming from '../../lib/skilling/skills/farming'; import { slayerMasterChoices } from '../../lib/slayer/constants'; import { slayerMasters } from '../../lib/slayer/slayerMasters'; +import { getUsersCurrentSlayerInfo } from '../../lib/slayer/slayerUtil'; +import { allSlayerMonsters } from '../../lib/slayer/tasks'; import { stringMatches } from '../../lib/util'; import { calcDropRatesFromBankWithoutUniques } from '../../lib/util/calcDropRatesFromBank'; import { @@ -454,16 +455,16 @@ export const testPotatoCommand: OSBMahojiCommand | null = production description: 'The monster you want to set your task as.', required: true, autocomplete: async value => { - return effectiveMonsters - .filter(i => { + return allSlayerMonsters + .filter(monster => { if (!value) return true; - return [i.name.toLowerCase(), i.aliases].some(i => - i.includes(value.toLowerCase()) + return [monster.name.toLowerCase(), monster.aliases].some(aliases => + aliases.includes(value.toLowerCase()) ); }) - .map(i => ({ - name: i.name, - value: i.name + .map(monster => ({ + name: monster.name, + value: monster.name })); } }, @@ -863,40 +864,59 @@ ${droprates.join('\n')}`), if (options.setslayertask) { const user = await mUserFetch(userID); - await prisma.slayerTask.deleteMany({ where: { user_id: user.id } }); + const usersTask = await getUsersCurrentSlayerInfo(user.id); - const monsterName = options.setslayertask?.monster ?? ''; - const masterName = options.setslayertask?.master; - const quantity = options.setslayertask?.quantity ?? 50; + const { monster, master } = options.setslayertask; - const monster = effectiveMonsters.find(m => stringMatches(m.name, monsterName)); - const master = slayerMasters.find( - sm => - stringMatches(masterName, sm.name) || - sm.aliases.some(alias => stringMatches(masterName, alias)) + const selectedMonster = allSlayerMonsters.find(m => stringMatches(m.name, monster)); + const selectedMaster = slayerMasters.find( + sm => stringMatches(master, sm.name) || sm.aliases.some(alias => stringMatches(master, alias)) ); - if (!monster) return 'Invalid monster.'; - if (!master) return 'Invalid slayer master.'; + const quantity = options.setslayertask?.quantity ?? 50; + + const assignedTask = selectedMaster!.tasks.find(m => m.monster.id === selectedMonster?.id)!; - const newUser = await getNewUser(user.id); + if (!selectedMonster || !selectedMaster || !assignedTask) { + return !selectedMonster + ? 'Invalid monster.' + : !selectedMaster + ? 'Invalid slayer master.' + : `${selectedMaster.name} does not assign ${selectedMonster.name}.`; + } // Create a new slayer task for the user - await prisma.slayerTask.create({ - data: { - user_id: newUser.id, - quantity, - quantity_remaining: quantity, - slayer_master_id: master.id, - monster_id: monster.id, - skipped: false - } - }); + if (usersTask.currentTask?.id) { + await prisma.slayerTask.update({ + where: { + id: usersTask.currentTask?.id + }, + data: { + quantity, + quantity_remaining: quantity, + slayer_master_id: selectedMaster.id, + monster_id: selectedMonster.id, + skipped: false + } + }); + } else { + await prisma.slayerTask.create({ + data: { + user_id: user.id, + quantity, + quantity_remaining: quantity, + slayer_master_id: selectedMaster.id, + monster_id: selectedMonster.id, + skipped: false + } + }); + } + await user.update({ - slayer_last_task: monster.id + slayer_last_task: selectedMonster.id }); - return `You set your slayer task to ${monster.name} using ${master.name}.`; + return `You set your slayer task to ${selectedMonster.name} using ${selectedMaster.name}.`; } if (options.forcegrow) { diff --git a/src/mahoji/lib/abstracted_commands/minionKill.ts b/src/mahoji/lib/abstracted_commands/minionKill.ts index 9b16e6d86f..d252ed6756 100644 --- a/src/mahoji/lib/abstracted_commands/minionKill.ts +++ b/src/mahoji/lib/abstracted_commands/minionKill.ts @@ -178,7 +178,7 @@ export async function minionKillCommand( return `You can't kill ${monster.name}, because you're not on a slayer task.`; } - if (monster.canBePked && wilderness !== undefined && !wilderness) { + if (monster.canBePked && wilderness === false) { return `You can't kill ${monster.name} outside the wilderness.`; }