Skip to content

Commit

Permalink
Merge pull request #35 from gw2efficiency/update-limited-recipes
Browse files Browse the repository at this point in the history
Added new items, changed file/variable namings so they make more sense.
  • Loading branch information
queicherius authored Dec 7, 2024
2 parents 40d7b5e + cc3e0f2 commit fb81030
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 19 deletions.
24 changes: 12 additions & 12 deletions src/helpers/dailyCooldowns.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { DAILY_COOLDOWNS } from '../static/dailyCooldowns'
import { DAILY_LIMITED_ITEMS, DailyLimitedItem } from '../static/dailyLimitedItems'
import { LIMITED_RECIPES, LimitedRecipe } from '../static/limitedRecipes'
import { RecipeTreeWithCraftFlags } from '../types'

const dailyCooldownIds = DAILY_COOLDOWNS.filter((x) => x.craftInterval === 'daily').map((x) => x.id)
const dailyLimitedItems = DAILY_LIMITED_ITEMS
const limitedRecipes = LIMITED_RECIPES

export type DailyCooldownsBreakdown = Record<string, number>
export type MatchingItemWithoutLimit = Omit<DailyLimitedItem, 'dailyLimit'>
export type MatchingRecipeWithoutLimit = Omit<LimitedRecipe, 'limit'>

// Get a list of daily cooldowns used in the recipe
export function dailyCooldowns(
Expand All @@ -21,12 +21,12 @@ export function dailyCooldowns(
breakdown[tree.id] = (breakdown[tree.id] || 0) + tree.usedQuantity
}

const matchingItem = dailyLimitedItems.find((item) => item.id === tree.id)
const matchingRecipe = limitedRecipes.find((recipe) => recipe.id === tree.id)
if (
matchingItem &&
matchesItemProperties(
matchingRecipe &&
matchesRecipeProperties(
tree,
(({ dailyLimit, ...matchingItemWithoutLimit }) => matchingItemWithoutLimit)(matchingItem)
(({ limit, ...matchingRecipeWithoutLimit }) => matchingRecipeWithoutLimit)(matchingRecipe)

Check warning on line 29 in src/helpers/dailyCooldowns.ts

View workflow job for this annotation

GitHub Actions / Test & build

'limit' is defined but never used
)
) {
breakdown[tree.id] = (breakdown[tree.id] || 0) + tree.usedQuantity
Expand All @@ -36,27 +36,27 @@ export function dailyCooldowns(
return breakdown
}

export function matchesItemProperties(
export function matchesRecipeProperties(
tree: RecipeTreeWithCraftFlags,
matchingItemWithoutLimit: MatchingItemWithoutLimit
matchingRecipeWithoutLimit: MatchingRecipeWithoutLimit
): boolean {
return Object.entries(matchingItemWithoutLimit).every(([key, value]) => {
return Object.entries(matchingRecipeWithoutLimit).every(([key, value]) => {
if (!(key in tree)) {
return false
}

const treeValue = tree[key as keyof RecipeTreeWithCraftFlags] as unknown

if (typeof value === 'object' && !Array.isArray(value) && typeof treeValue === 'object') {
return matchesItemProperties(treeValue as RecipeTreeWithCraftFlags, value)
return matchesRecipeProperties(treeValue as RecipeTreeWithCraftFlags, value)
}

if (Array.isArray(value)) {
if (!Array.isArray(treeValue)) {
return false
}
return value.every((nestedObject, index) =>
matchesItemProperties(treeValue[index], nestedObject as MatchingItemWithoutLimit)
matchesRecipeProperties(treeValue[index], nestedObject as MatchingRecipeWithoutLimit)
)
}

Expand Down
7 changes: 0 additions & 7 deletions src/static/dailyLimitedItems.ts

This file was deleted.

78 changes: 78 additions & 0 deletions src/static/limitedRecipes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
export type LimitedRecipe = {
id: number
limit: { type: string; quantity: number }
} & Partial<{
components: { id: number; type: string; quantity: number }[]
}>

export const LIMITED_RECIPES: LimitedRecipe[] = [
{
id: 92272,
components: [{ id: 2, type: 'Currency', quantity: 2668 }],
limit: { type: 'daily', quantity: 10 },
}, // Eternal Ice Shard
{
id: 103846,
components: [
{ id: 68063, type: 'Item', quantity: 1 },
{ id: 102494, type: 'Item', quantity: 1 },
{ id: 2, type: 'Currency', quantity: 1050 },
],
limit: { type: 'weekly', quantity: 21 },
}, // Discounted Shard of Janthir Syntri
{
id: 103316,
components: [
{ id: 68063, type: 'Item', quantity: 3 },
{ id: 102494, type: 'Item', quantity: 3 },
{ id: 2, type: 'Currency', quantity: 1750 },
],
limit: { type: 'weekly', quantity: 21 },
}, // Shard of Janthir Syntri
{
id: 103991,
components: [
{ id: 68063, type: 'Item', quantity: 1 },
{ id: 103038, type: 'Item', quantity: 1 },
{ id: 2, type: 'Currency', quantity: 1050 },
],
limit: { type: 'weekly', quantity: 21 },
}, // Discounted Shard of Lowland Shore
{
id: 103991,
components: [
{ id: 68063, type: 'Item', quantity: 3 },
{ id: 103038, type: 'Item', quantity: 3 },
{ id: 2, type: 'Currency', quantity: 1750 },
],
limit: { type: 'weekly', quantity: 21 },
}, // Shard of Lowland Shore
{
id: 102494,
components: [
{ id: 103038, type: 'Item', quantity: 1 },
{ id: 102558, type: 'Item', quantity: 3 },
{ id: 102503, type: 'Item', quantity: 3 },
],
limit: { type: 'daily', quantity: 3 },
}, // Curious Mursaat Currency
{
id: 102494,
components: [{ id: 2, type: 'Currency', quantity: 1050 }],
limit: { type: 'daily', quantity: 3 },
}, // Curious Mursaat Currency (Karma)
{
id: 103038,
components: [
{ id: 102494, type: 'Item', quantity: 1 },
{ id: 103279, type: 'Item', quantity: 3 },
{ id: 102255, type: 'Item', quantity: 3 },
],
limit: { type: 'daily', quantity: 3 },
}, // Curious Lowland Honeycomb
{
id: 103038,
components: [{ id: 2, type: 'Currency', quantity: 1050 }],
limit: { type: 'daily', quantity: 3 },
}, // Curious Lowland Honeycomb (Karma)
]

0 comments on commit fb81030

Please sign in to comment.