Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/oldschoolgg/oldschoolbot
Browse files Browse the repository at this point in the history
…into wildy-slayer
  • Loading branch information
TastyPumPum committed Oct 12, 2023
2 parents d365d29 + 2e44aeb commit 63d8f74
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 7 deletions.
40 changes: 40 additions & 0 deletions src/lib/combat_achievements/caUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,46 @@
import { CAViewType } from '../../mahoji/commands/ca';
import type { ActivityTaskData, MonsterActivityTaskOptions } from '../types/minions';
import { CombatAchievement } from './combatAchievements';

export function isCertainMonsterTrip(monsterID: number) {
return (data: ActivityTaskData) =>
data.type === 'MonsterKilling' && (data as MonsterActivityTaskOptions).monsterID === monsterID;
}

interface CombatAchievementGroup {
name: string;
tasks: CombatAchievement[];
}

export const buildCombatAchievementsResult = (
completedTaskIDs: Set<number>,
combatAchievements: CombatAchievementGroup,
type: CAViewType,
maxContentLength: number
) => {
const { name, tasks } = combatAchievements;
let result = `Combat Achievement tasks for ${name}:\n\n`;

const completedTasks = tasks.filter(task => completedTaskIDs.has(task.id));
const allTasksCompleted = completedTasks.length === tasks.length;

if (type === 'complete' && completedTasks.length === 0) {
return `No tasks completed for ${name}.`;
}

if (type === 'incomplete' && allTasksCompleted) {
return `All tasks completed for ${name}.`;
}

for (const task of tasks) {
if (type === 'complete' && !completedTaskIDs.has(task.id)) continue;
if (type === 'incomplete' && completedTaskIDs.has(task.id)) continue;
const completionStatus = completedTaskIDs.has(task.id) ? 'Completed' : 'Incomplete';
result += `Name: ${task.name}\nDescription: ${task.desc}\nStatus: ${completionStatus}\n\n`;
}

return {
content: result.length <= maxContentLength ? result : 'Result too large. Check the attached file for details.',
files: result.length > maxContentLength ? [{ attachment: Buffer.from(result), name: 'caBoss.txt' }] : undefined
};
};
19 changes: 19 additions & 0 deletions src/lib/combat_achievements/combatAchievements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@ import { hardCombatAchievements } from './hard';
import { masterCombatAchievements } from './master';
import { mediumCombatAchievements } from './medium';

const collectMonsterNames = (...achievements: CombatAchievement[][]) => {
const allMonsterNamesSet = new Set<string>();
for (const achievementGroup of achievements) {
for (const achievement of achievementGroup) {
allMonsterNamesSet.add(achievement.monster);
}
}
return Array.from(allMonsterNamesSet);
};

export const allCAMonsterNames = collectMonsterNames(
easyCombatAchievements,
mediumCombatAchievements,
hardCombatAchievements,
eliteCombatAchievements,
masterCombatAchievements,
grandmasterCombatAchievements
);

type CAType = 'kill_count' | 'mechanical' | 'perfection' | 'restriction' | 'speed' | 'stamina';

export type CombatAchievement = {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ const mentionCommands: MentionCommand[] = [
if (items.length === 0) return msg.reply('No results for that item.');

const gettedItem = items[0];
const { sacrificed_bank: sacrificedBank } = await user.fetchStats({ sacrificed_bank: true });

let str = `Found ${items.length} items:\n${items
.slice(0, 5)
Expand All @@ -197,6 +198,7 @@ const mentionCommands: MentionCommand[] = [
if (user.cl.has(item.id)) icons.push(Emoji.CollectionLog);
if (user.bank.has(item.id)) icons.push(Emoji.Bank);
if (((sacrificedBank as ItemBank)[item.id] ?? 0) > 0) icons.push(Emoji.Incinerator);
const price = toKMB(Math.floor(item.price));
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
4 changes: 2 additions & 2 deletions src/lib/util/handleTripFinish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ export async function handleTripFinish(
components.push(..._components);
}

handleTriggerShootingStar(user, data, components);

if (components.length > 0) {
message.components = makeComponents(components);
}

handleTriggerShootingStar(user, data, components);

sendToChannelID(channelID, message);
}
45 changes: 42 additions & 3 deletions src/mahoji/commands/ca.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { calcWhatPercent, objectEntries } from 'e';
import { ApplicationCommandOptionType, CommandRunOptions } from 'mahoji';
import { Bank } from 'oldschooljs';

import { buildCombatAchievementsResult } from '../../lib/combat_achievements/caUtils';
import {
allCAMonsterNames,
allCombatAchievementTasks,
caToPlayerString,
CombatAchievement,
Expand All @@ -14,7 +16,10 @@ import { deferInteraction } from '../../lib/util/interactionReply';
import { OSBMahojiCommand } from '../lib/util';

const viewTypes = ['all', 'incomplete', 'complete'] as const;
type ViewType = (typeof viewTypes)[number];

export type CAViewType = (typeof viewTypes)[number];

type MonsterNames = (typeof allCAMonsterNames)[number];

export const caCommand: OSBMahojiCommand = {
name: 'ca',
Expand All @@ -25,12 +30,23 @@ export const caCommand: OSBMahojiCommand = {
name: 'view',
description: 'View your Combat Achievements progress.',
options: [
{
type: ApplicationCommandOptionType.String,
name: 'name',
description: 'What boss do you want to view?',
autocomplete: async (value: string) => {
return allCAMonsterNames
.filter(i => (!value ? true : i.toLowerCase().includes(value.toLowerCase())))
.map(i => ({ name: i, value: i }));
},
required: false
},
{
type: ApplicationCommandOptionType.String,
name: 'type',
description: 'What do you want to view?',
choices: viewTypes.map(i => ({ name: i, value: i })),
required: true
required: false
}
]
},
Expand All @@ -48,7 +64,8 @@ export const caCommand: OSBMahojiCommand = {
}: CommandRunOptions<{
claim?: {};
view?: {
type: ViewType;
name?: MonsterNames;
type?: CAViewType;
};
}>) => {
await deferInteraction(interaction);
Expand Down Expand Up @@ -118,6 +135,27 @@ export const caCommand: OSBMahojiCommand = {
}

if (options.view) {
let selectedMonster = options.view.name;
let tasksView: CAViewType = options.view.type !== undefined ? options.view.type : 'all';

if (selectedMonster) {
const tasksForSelectedMonster = allCombatAchievementTasks.filter(
task => task.monster === selectedMonster
);

if (tasksForSelectedMonster.length === 0)
return 'No Combat Achievement tasks found for the specified monster.';

const maxContentLength = 750;
const result = buildCombatAchievementsResult(
completedTaskIDs,
{ name: `${selectedMonster}`, tasks: tasksForSelectedMonster },
tasksView,
maxContentLength
);
return result;
}

let result = '';

for (const group of Object.values(CombatAchievements)) {
Expand All @@ -141,6 +179,7 @@ export const caCommand: OSBMahojiCommand = {
files: [{ attachment: Buffer.from(result), name: 'ca.txt' }]
};
}

return 'Invalid command.';
}
};
5 changes: 4 additions & 1 deletion src/mahoji/commands/gear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ export const gearCommand: OSBMahojiCommand = {
name: 'setup',
description: 'The setup you want to view.',
required: true,
choices: ['All', ...GearSetupTypes].map(i => ({ name: toTitleCase(i), value: i }))
choices: ['All', ...GearSetupTypes, 'Lost on wildy death'].map(i => ({
name: toTitleCase(i),
value: i
}))
},
{
type: ApplicationCommandOptionType.Boolean,
Expand Down
51 changes: 51 additions & 0 deletions src/mahoji/lib/abstracted_commands/gearCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { unEquipAllCommand } from '../../../lib/minions/functions/unequipAllComm
import { prisma } from '../../../lib/settings/prisma';
import { defaultGear, Gear, globalPresets } from '../../../lib/structures/Gear';
import { assert, formatSkillRequirements, isValidGearSetup, stringMatches } from '../../../lib/util';
import calculateGearLostOnDeathWilderness from '../../../lib/util/calculateGearLostOnDeathWilderness';
import { gearEquipMultiImpl } from '../../../lib/util/equipMulti';
import { getItem } from '../../../lib/util/getOSItem';
import { handleMahojiConfirmation } from '../../../lib/util/handleMahojiConfirmation';
Expand Down Expand Up @@ -343,6 +344,56 @@ export async function gearViewCommand(user: MUser, input: string, text: boolean)
files: [file]
};
}
if (stringMatches(input, 'lost on wildy death')) {
interface GearLostOptions {
gear: GearSetup;
skulled: boolean;
after20wilderness: boolean;
smited: boolean;
protectItem: boolean;
}

function showGearLost(options: GearLostOptions) {
const results = calculateGearLostOnDeathWilderness(options);
return results; // Return the entire results object
}

function calculateAndGetString(options: GearLostOptions, smited: boolean): string {
const gearLost = showGearLost({ ...options, smited });
return gearLost.lostItems.toString();
}

const userGear = user.gear.wildy;
const scenarios = [
{ skulled: true, after20wilderness: true, smited: false, protectItem: true },
{ skulled: true, after20wilderness: true, smited: true, protectItem: true },
{ skulled: false, after20wilderness: true, smited: true, protectItem: true },
{ skulled: false, after20wilderness: true, smited: false, protectItem: true },
{ skulled: false, after20wilderness: false, smited: true, protectItem: true },
{ skulled: false, after20wilderness: false, smited: false, protectItem: true }
];

const scenarioDescriptions = [
'when skulled',
'when skulled and smited',
'in 20+ Wilderness and smited',
'in 20+ Wilderness',
'in less than 20 Wilderness and smited',
'in less than 20 Wilderness'
];

const content = scenarios
.map((scenario, index) => {
const lostItemsString = calculateAndGetString({ gear: userGear, ...scenario }, scenario.smited);
const description = scenarioDescriptions[index];
return `The gear you would lose ${description}:\n${lostItemsString}`;
})
.join('\n\n');

const updatedContent = `${content}\n\nThese assume you have atleast 25 prayer for the protect item prayer.`;

return { content: updatedContent };
}
if (!isValidGearSetup(input)) return 'Invalid setup.';
const gear = user.gear[input];
if (text) {
Expand Down

0 comments on commit 63d8f74

Please sign in to comment.