diff --git a/src/App/CreateGoal.tsx b/src/App/CreateGoal.tsx index 4dbc205..b5cc1fe 100644 --- a/src/App/CreateGoal.tsx +++ b/src/App/CreateGoal.tsx @@ -45,8 +45,8 @@ export function CreateGoal({ onClose }: { onClose: () => void }) { const repeats = useStateObservable(repeats$); const rewards = useMemo( - () => getRewardForGoal(divisions, repeats.value), - [divisions, repeats.value] + () => getRewardForGoal(season, divisions, repeats.value), + [season, divisions, repeats.value] ); const pips = useMemo( () => (season ? calculateCost(season, divisions, repeats.value) : 0), diff --git a/src/App/PlayerDetails.tsx b/src/App/PlayerDetails.tsx index 9a4197d..3140e9b 100644 --- a/src/App/PlayerDetails.tsx +++ b/src/App/PlayerDetails.tsx @@ -51,6 +51,8 @@ function RefreshingTimeAgo({ date }: { date?: Date }) { const token = setInterval(() => { setFormattedTime(date ? timeAgo.format(date) : "N/A"); }, 60_000); + setFormattedTime(date ? timeAgo.format(date) : "N/A"); + return () => { clearInterval(token); }; diff --git a/src/service/gw2Api.ts b/src/service/gw2Api.ts index 51ae65c..0499d8e 100644 --- a/src/service/gw2Api.ts +++ b/src/service/gw2Api.ts @@ -8,6 +8,7 @@ export function getCurrentSeason$() { return fetch(`https://api.guildwars2.com/v2/pvp/seasons`); }).pipe( map((result) => result.data as any), + // tap((result) => console.log(result)), map((result): string => result[result.length - 1]), switchMap((seasonId) => fetch(`https://api.guildwars2.com/v2/pvp/seasons/${seasonId}`) @@ -51,8 +52,8 @@ export function getSeasonCurrentPips$(apiKey: string, season_id: string) { filter((result) => Array.isArray(result)), map( (result): number => - result.find((line: any) => line.season_id === season_id).current - .total_points + result.find((line: any) => line.season_id === season_id)?.current + .total_points ?? 1 ) ); } diff --git a/src/service/rewards.ts b/src/service/rewards.ts index 3cd1c44..7c988ef 100644 --- a/src/service/rewards.ts +++ b/src/service/rewards.ts @@ -1,3 +1,5 @@ +import { SeasonData } from "./localData"; + interface Rewards { shardOfGlory: number; unidentifiedDye: number; @@ -185,14 +187,200 @@ const regularRewards: Array = [ ), ]; -export function getRewardForGoal(divisions: number, repeats: number) { +const mini2v2Rewards: Array = [ + // Cerulean + calculateReward( + 3, + { + shardOfGlory: 5, + unidentifiedDye: 1, + gold: 30_00, + transmutationCharge: 1, + }, + { + shardOfGlory: 10, + unidentifiedDye: 2, + warlordArmorBox: 1, + pvpLeagueTicket: 10, + gold: 5_00_00, + transmutationCharge: 1, + ascendedShardOfGlory: 25, + } + ), + // Jasper + calculateReward( + 4, + { + shardOfGlory: 10, + unidentifiedDye: 1, + gold: 45_00, + transmutationCharge: 1, + }, + { + shardOfGlory: 15, + unidentifiedDye: 2, + warlordArmorBox: 1, + pvpLeagueTicket: 10, + gold: 5_00_00, + transmutationCharge: 3, + ascendedShardOfGlory: 50, + } + ), + // Saffron + calculateReward( + 5, + { + shardOfGlory: 15, + unidentifiedDye: 1, + gold: 60_00, + transmutationCharge: 1, + }, + { + shardOfGlory: 20, + unidentifiedDye: 2, + warlordArmorBox: 1, + pvpLeagueTicket: 15, + gold: 10_00_00, + transmutationCharge: 3, + ascendedShardOfGlory: 75, + } + ), + // Persimmon + calculateReward( + 5, + { + shardOfGlory: 20, + unidentifiedDye: 1, + gold: 75_00, + transmutationCharge: 1, + }, + { + shardOfGlory: 25, + unidentifiedDye: 2, + boxOfGrandmasterMarks: 1, + warlordArmorBox: 1, + pvpLeagueTicket: 15, + gold: 10_00_00, + transmutationCharge: 5, + ascendedShardOfGlory: 75, + } + ), + // Persimmon (Repeatable) + calculateReward( + 5, + { + shardOfGlory: 20, + unidentifiedDye: 1, + gold: 75_00, + transmutationCharge: 1, + }, + { + shardOfGlory: 25, + unidentifiedDye: 1, + gold: 5_00_00, + transmutationCharge: 1, + ascendedShardOfGlory: 25, + } + ), +]; + +const mini3v3Rewards: Array = [ + // Cerulean + calculateReward( + 3, + { + shardOfGlory: 5, + unidentifiedDye: 1, + gold: 30_00, + transmutationCharge: 1, + }, + { + shardOfGlory: 10, + unidentifiedDye: 2, + warlordArmorBox: 1, + pvpLeagueTicket: 10, + gold: 5_00_00, + transmutationCharge: 1, + ascendedShardOfGlory: 25, + } + ), + // Jasper + calculateReward( + 4, + { + shardOfGlory: 10, + unidentifiedDye: 1, + gold: 45_00, + transmutationCharge: 1, + }, + { + shardOfGlory: 15, + unidentifiedDye: 2, + warlordArmorBox: 1, + pvpLeagueTicket: 10, + gold: 5_00_00, + transmutationCharge: 3, + ascendedShardOfGlory: 50, + } + ), + // Saffron + calculateReward( + 5, + { + shardOfGlory: 15, + unidentifiedDye: 1, + gold: 60_00, + transmutationCharge: 1, + }, + { + shardOfGlory: 25, + unidentifiedDye: 2, + warlordArmorBox: 1, + pvpLeagueTicket: 15, + gold: 10_00_00, + transmutationCharge: 5, + ascendedShardOfGlory: 75, + boxOfGrandmasterMarks: 1, + } + ), + // Saffron (Repeatable) + calculateReward( + 5, + { + shardOfGlory: 15, + unidentifiedDye: 1, + gold: 60_00, + transmutationCharge: 1, + }, + { + shardOfGlory: 25, + unidentifiedDye: 1, + gold: 4_00_00, + transmutationCharge: 1, + ascendedShardOfGlory: 20, + } + ), +]; + +export function getRewardForGoal( + season: SeasonData | null, + divisions: number, + repeats: number +) { + if (!season) return emptyReward; + + const rewards = season.name.includes("3v3 Season") + ? mini3v3Rewards + : season.name.includes("2v2 Season") + ? mini2v2Rewards + : regularRewards; const result = { ...emptyReward }; for (let i = 0; i < divisions; i++) { - addReward(result, regularRewards[i]); + addReward(result, rewards[i]); } for (let i = 0; i < repeats; i++) { - addReward(result, regularRewards[regularRewards.length - 1]); + addReward(result, rewards[rewards.length - 1]); } return result;