From 6bc66da196c07cf8913246dd7d25e290c07ad29a Mon Sep 17 00:00:00 2001 From: gc <30398469+gc@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:35:45 +1100 Subject: [PATCH] Add moon key drops --- src/lib/util/minionUtils.ts | 14 ++++++++++++-- src/tasks/minions/miningActivity.ts | 21 ++++++++++++++++++--- src/tasks/minions/woodcuttingActivity.ts | 7 ++++++- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/lib/util/minionUtils.ts b/src/lib/util/minionUtils.ts index 620baf4095..47ec592ceb 100644 --- a/src/lib/util/minionUtils.ts +++ b/src/lib/util/minionUtils.ts @@ -1,11 +1,13 @@ -import { toTitleCase } from '@oldschoolgg/toolkit/util'; +import { perTimeUnitChance, toTitleCase } from '@oldschoolgg/toolkit/util'; import type { BaseMessageOptions } from 'discord.js'; import { escapeMarkdown, time } from 'discord.js'; import { Time } from 'e'; -import { convertXPtoLVL } from 'oldschooljs/dist/util/util'; +import { type Bank, convertXPtoLVL } from 'oldschooljs/dist/util/util'; import { resolveItems } from 'oldschooljs/dist/util/util'; +import { MUserClass } from '../MUser'; import { Emoji } from '../constants'; +import { QuestID } from '../minions/data/quests'; import type { SkillsEnum } from '../skilling/types'; import type { Peak } from './../tickers'; @@ -103,3 +105,11 @@ export function checkPeakTimes(): BaseMessageOptions { content: str }; } + +export function rollForMoonKeyHalf({ user, duration, loot }: { user: MUser | boolean; duration: number; loot: Bank }) { + if (user instanceof MUserClass && !user.user.finished_quest_ids.includes(QuestID.ChildrenOfTheSun)) return; + if (!user) return; + perTimeUnitChance(duration, 1, Time.Minute * 30, () => { + loot.add('Loop half of key (moon key)'); + }); +} diff --git a/src/tasks/minions/miningActivity.ts b/src/tasks/minions/miningActivity.ts index d02947f691..7bfb025f0d 100644 --- a/src/tasks/minions/miningActivity.ts +++ b/src/tasks/minions/miningActivity.ts @@ -1,6 +1,7 @@ import { Time, increaseNumByPercent, randInt, roll, sumArr } from 'e'; import { Emoji, Events } from '../../lib/constants'; +import { QuestID } from '../../lib/minions/data/quests'; import addSkillingClueToLoot from '../../lib/minions/functions/addSkillingClueToLoot'; import Mining, { prospectorItemsArr } from '../../lib/skilling/skills/mining'; import { type Ore, SkillsEnum } from '../../lib/skilling/types'; @@ -9,14 +10,23 @@ import { UpdateBank } from '../../lib/structures/UpdateBank'; import type { MiningActivityTaskOptions } from '../../lib/types/minions'; import { skillingPetDropRate, toKMB } from '../../lib/util'; import { handleTripFinish } from '../../lib/util/handleTripFinish'; +import { rollForMoonKeyHalf } from '../../lib/util/minionUtils'; export function determineMiningResult({ ore, quantity, gearBank, duration, - isPowermining -}: { ore: Ore; quantity: number; gearBank: GearBank; duration: number; isPowermining: boolean }) { + isPowermining, + hasFinishedCOTS +}: { + ore: Ore; + quantity: number; + gearBank: GearBank; + duration: number; + isPowermining: boolean; + hasFinishedCOTS: boolean; +}) { const miningLvl = gearBank.skillsAsLevels.mining; const messages: string[] = []; let xpToReceive = quantity * ore.xp; @@ -108,6 +118,10 @@ export function determineMiningResult({ } } + if (ore.name === 'Runite ore') { + rollForMoonKeyHalf({ user: hasFinishedCOTS, duration, loot: updateBank.itemLootBank }); + } + return { updateBank, messages, @@ -128,7 +142,8 @@ export const miningTask: MinionTask = { quantity, gearBank: user.gearBank, duration, - isPowermining: powermine + isPowermining: powermine, + hasFinishedCOTS: user.user.finished_quest_ids.includes(QuestID.ChildrenOfTheSun) }); const updateResult = await updateBank.transact(user); diff --git a/src/tasks/minions/woodcuttingActivity.ts b/src/tasks/minions/woodcuttingActivity.ts index 8b0fdbab99..15a2796401 100644 --- a/src/tasks/minions/woodcuttingActivity.ts +++ b/src/tasks/minions/woodcuttingActivity.ts @@ -1,6 +1,6 @@ import { perTimeUnitChance } from '@oldschoolgg/toolkit/util'; import { Time, objectEntries, percentChance, randInt } from 'e'; -import { Bank } from 'oldschooljs'; +import { Bank, EItem } from 'oldschooljs'; import type { TwitcherGloves } from '../../lib/constants'; import { Emoji, Events } from '../../lib/constants'; @@ -14,6 +14,7 @@ import { SkillsEnum } from '../../lib/skilling/types'; import type { WoodcuttingActivityTaskOptions } from '../../lib/types/minions'; import { resolveItems, roll, skillingPetDropRate } from '../../lib/util'; import { handleTripFinish } from '../../lib/util/handleTripFinish'; +import { rollForMoonKeyHalf } from '../../lib/util/minionUtils'; import { userStatsBankUpdate } from '../../mahoji/mahojiSettings'; async function handleForestry({ user, duration, loot }: { user: MUser; duration: number; loot: Bank }) { @@ -334,6 +335,10 @@ export const woodcuttingTask: MinionTask = { } } + if ([EItem.MAGIC_LOGS, EItem.YEW_LOGS, EItem.TEAK_LOGS, EItem.MAPLE_LOGS].includes(log.id)) { + rollForMoonKeyHalf({ user, duration, loot }); + } + // Loot received, items used, and logs/loot rolls lost message str += `\nYou received ${loot}. `; str += `${itemsToRemove.length > 0 ? `You used ${itemsToRemove}. ` : ''}`;