11import { getSeasonPassStatus } from 'app/progress/SeasonalRank' ;
22import { useCurrentSeasonInfo } from 'app/utils/seasons' ;
3- import { DestinyProfileResponse , DestinyProgressionDefinition } from 'bungie-api-ts/destiny2' ;
4- import { clamp } from 'es-toolkit' ;
3+ import { DestinyProfileResponse } from 'bungie-api-ts/destiny2' ;
54import { D2ManifestDefinitions } from '../../destiny2/d2-definitions' ;
65
76/**
@@ -13,8 +12,14 @@ export function useIsWellRested(
1312 defs : D2ManifestDefinitions ,
1413 profileInfo : DestinyProfileResponse ,
1514) : {
15+ /** Is the "well rested" buff active? */
1616 wellRested : boolean ;
17+ /** How much of the well rested XP has been earned so far this week? */
1718 weeklyProgress ?: number ;
19+ /**
20+ * How much XP total needs to be earned in a week before the character is no
21+ * longer "well rested"?
22+ */
1823 requiredXP ?: number ;
1924} {
2025 const { season, seasonPass } = useCurrentSeasonInfo ( defs , profileInfo ) ;
@@ -33,59 +38,18 @@ export function useIsWellRested(
3338 } ;
3439 }
3540
36- const {
37- seasonPassLevel,
38- seasonProgression,
39- prestigeMode,
40- prestigeProgression,
41- prestigeProgressionDef,
42- seasonProgressionDef,
43- weeklyProgress,
44- nextLevelAt,
45- } = getSeasonPassStatus ( defs , profileInfo , seasonPass , season ) ;
46-
47- /**
48- * Calculate the amount of levels we need to fullfill well rested requirements
49- * Ranks 101-110 are equiv to 5 levels each
50- */
51- const baseLevelXPRequirement = seasonProgressionDef ?. steps [ 1 ] ?. progressTotal ?? 100000 ;
52- const wellRestedLevels = ( baseLevelXPRequirement * 5 ) / nextLevelAt ;
53-
54- if ( seasonProgressionDef . steps . length === seasonProgression . levelCap ) {
55- for ( let i = 0 ; i < wellRestedLevels ; i ++ ) {
56- seasonProgressionDef . steps . push ( prestigeProgressionDef . steps [ 0 ] ) ;
57- }
58- }
41+ const { weeklyProgress } = getSeasonPassStatus ( defs , profileInfo , seasonPass , season ) ;
5942
60- const requiredXP =
61- prestigeMode && prestigeProgression . level >= wellRestedLevels
62- ? xpRequiredForLevel ( 0 , prestigeProgressionDef ) * wellRestedLevels
63- : xpTotalRequiredForLevel ( seasonPassLevel , seasonProgressionDef , wellRestedLevels ) ;
43+ // 5 levels worth of XP at 100k each. We used to calculate this dynamically
44+ // but this has been 500k consistently and the calculation is no longer easy
45+ // as the definitions don't agree with the game (Ranks 101-110 are displayed
46+ // in game as 5 segments, each of which is equivalent to one regular levels at
47+ // 100k, but in the defs they are a single 500k level).
48+ const requiredXP = 500_000 ;
6449
65- // Have you gained XP equal to three full levels worth of XP?
6650 return {
6751 wellRested : weeklyProgress < requiredXP ,
6852 weeklyProgress,
6953 requiredXP,
7054 } ;
7155}
72-
73- /**
74- * How much XP was required to achieve the given level?
75- */
76- function xpRequiredForLevel ( level : number , progressDef : DestinyProgressionDefinition ) {
77- const stepIndex = clamp ( level , 0 , progressDef . steps . length - 1 ) ;
78- return progressDef . steps [ stepIndex ] . progressTotal ;
79- }
80-
81- function xpTotalRequiredForLevel (
82- totalLevel : number ,
83- seasonProgressDef : DestinyProgressionDefinition ,
84- WELL_RESTED_LEVELS : number ,
85- ) {
86- let totalXP = 0 ;
87- for ( let i = 0 ; i < WELL_RESTED_LEVELS ; i ++ ) {
88- totalXP += xpRequiredForLevel ( totalLevel - i , seasonProgressDef ) ;
89- }
90- return totalXP ;
91- }
0 commit comments