22using Intersect . GameObjects ;
33using Intersect . Client . General ;
44using Intersect . Client . Localization ;
5+ using Intersect . GameObjects . Ranges ;
56using Intersect . Logging ;
67using Intersect . Network . Packets . Server ;
78using Intersect . Utilities ;
@@ -14,7 +15,7 @@ public partial class ItemDescriptionWindow : DescriptionWindowBase
1415
1516 protected int mAmount ;
1617
17- protected ItemProperties mItemProperties ;
18+ protected ItemProperties ? mItemProperties ;
1819
1920 protected string mTitleOverride ;
2021
@@ -27,7 +28,7 @@ public ItemDescriptionWindow(
2728 int amount ,
2829 int x ,
2930 int y ,
30- ItemProperties itemProperties ,
31+ ItemProperties ? itemProperties ,
3132 string titleOverride = "" ,
3233 string valueLabel = ""
3334 ) : base ( Interface . GameUi . GameCanvas , "DescriptionWindow" )
@@ -322,50 +323,64 @@ protected void SetupEquipmentInfo()
322323
323324 // Stats
324325 var statModifiers = mItemProperties ? . StatModifiers ;
325- for ( var i = 0 ; i < Enum . GetValues < Stat > ( ) . Length ; i ++ )
326+ for ( var statIndex = 0 ; statIndex < Enum . GetValues < Stat > ( ) . Length ; statIndex ++ )
326327 {
328+ var stat = ( Stat ) statIndex ;
327329 // Do we have item properties, if so this is a finished item. Otherwise does this item not have growing stats?
328- if ( statModifiers != default || mItem . StatRanges ? . Length == 0 || ( mItem . StatRanges != default && mItem . StatRanges [ i ] . LowRange == 0 && mItem . StatRanges [ i ] . HighRange == 0 ) )
330+ var statLabel = Strings . ItemDescription . StatCounts [ statIndex ] ;
331+ ItemRange ? rangeForStat = default ;
332+ var percentageGivenForStat = mItem . PercentageStatsGiven [ statIndex ] ;
333+ if ( statModifiers != default || ! mItem . TryGetRangeFor ( stat , out rangeForStat ) || rangeForStat . LowRange == rangeForStat . HighRange )
329334 {
330- var flatStat = mItem . StatsGiven [ i ] ;
335+ var flatValueGivenForStat = mItem . StatsGiven [ statIndex ] ;
331336 if ( statModifiers != default )
332337 {
333- flatStat += statModifiers [ i ] ;
338+ flatValueGivenForStat += statModifiers [ statIndex ] ;
334339 }
335340
336- if ( flatStat != 0 && mItem . PercentageStatsGiven [ i ] != 0 )
341+ // If the range is something like 1 to 1 then it should just be added into the flat stat
342+ flatValueGivenForStat += rangeForStat ? . LowRange ?? 0 ;
343+
344+ if ( flatValueGivenForStat != 0 && percentageGivenForStat != 0 )
337345 {
338- rows . AddKeyValueRow ( Strings . ItemDescription . StatCounts [ i ] , Strings . ItemDescription . RegularAndPercentage . ToString ( flatStat , mItem . PercentageStatsGiven [ i ] ) ) ;
346+ rows . AddKeyValueRow (
347+ statLabel ,
348+ Strings . ItemDescription . RegularAndPercentage . ToString ( flatValueGivenForStat , percentageGivenForStat )
349+ ) ;
339350 }
340- else if ( flatStat != 0 )
351+ else if ( flatValueGivenForStat != 0 )
341352 {
342- rows . AddKeyValueRow ( Strings . ItemDescription . StatCounts [ i ] , flatStat . ToString ( ) ) ;
353+ rows . AddKeyValueRow ( statLabel , flatValueGivenForStat . ToString ( ) ) ;
343354 }
344- else if ( mItem . PercentageStatsGiven [ i ] != 0 )
355+ else if ( percentageGivenForStat != 0 )
345356 {
346- rows . AddKeyValueRow ( Strings . ItemDescription . StatCounts [ i ] , Strings . ItemDescription . Percentage . ToString ( mItem . PercentageStatsGiven [ i ] ) ) ;
357+ rows . AddKeyValueRow (
358+ statLabel ,
359+ Strings . ItemDescription . Percentage . ToString ( percentageGivenForStat )
360+ ) ;
347361 }
348362 }
349363 // We do not have item properties and have growing stats! So don't display a finished stat but a range instead.
350- else
364+ else if ( mItem . TryGetRangeFor ( stat , out var range ) )
351365 {
352- if ( mItem . TryGetRangeFor ( ( Stat ) i , out var range ) )
353- {
354- var statGiven = mItem . StatsGiven [ i ] ;
355- var percentageStatGiven = mItem . PercentageStatsGiven [ i ] ;
356- var statLow = statGiven + range . LowRange ;
357- var statHigh = statGiven + range . HighRange ;
366+ var statGiven = mItem . StatsGiven [ statIndex ] ;
367+ var percentageStatGiven = percentageGivenForStat ;
368+ var statLow = statGiven + range . LowRange ;
369+ var statHigh = statGiven + range . HighRange ;
358370
359- var statMessage = Strings . ItemDescription . StatGrowthRange . ToString ( statLow , statHigh ) ;
371+ var statMessage = Strings . ItemDescription . StatGrowthRange . ToString ( statLow , statHigh ) ;
360372
361- if ( percentageStatGiven != 0 )
362- {
363- statMessage = Strings . ItemDescription . RegularAndPercentage . ToString ( statMessage , percentageStatGiven ) ;
364- }
365- rows . AddKeyValueRow ( Strings . ItemDescription . StatCounts [ i ] , statMessage ) ;
373+ if ( percentageStatGiven != 0 )
374+ {
375+ statMessage = Strings . ItemDescription . RegularAndPercentage . ToString (
376+ statMessage ,
377+ percentageStatGiven
378+ ) ;
366379 }
380+
381+ rows . AddKeyValueRow ( statLabel , statMessage ) ;
382+ }
367383 }
368- }
369384
370385 // Bonus Effect
371386 foreach ( var effect in mItem . Effects )
0 commit comments