Skip to content

Commit

Permalink
Add mini seasons
Browse files Browse the repository at this point in the history
  • Loading branch information
voliva committed Sep 15, 2022
1 parent 74f2eca commit e2828e6
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/App/CreateGoal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions src/App/PlayerDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
5 changes: 3 additions & 2 deletions src/service/gw2Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down Expand Up @@ -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
)
);
}
194 changes: 191 additions & 3 deletions src/service/rewards.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { SeasonData } from "./localData";

interface Rewards {
shardOfGlory: number;
unidentifiedDye: number;
Expand Down Expand Up @@ -185,14 +187,200 @@ const regularRewards: Array<Rewards> = [
),
];

export function getRewardForGoal(divisions: number, repeats: number) {
const mini2v2Rewards: Array<Rewards> = [
// 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<Rewards> = [
// 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;
Expand Down

0 comments on commit e2828e6

Please sign in to comment.