Skip to content

Commit f0bd91a

Browse files
committed
fix(2356): only display x-to-y ranges as a range, treat x-to-x as a flat stat
- Remove ItemBase.StatRanges (which was not in the correct order and was part of the reason it was broken before) - change duplicate accessors to local variable
1 parent fa7ab8d commit f0bd91a

File tree

2 files changed

+47
-35
lines changed

2 files changed

+47
-35
lines changed

Intersect (Core)/GameObjects/ItemBase.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.ComponentModel.DataAnnotations.Schema;
2-
2+
using System.Diagnostics.CodeAnalysis;
33
using Intersect.Enums;
44
using Intersect.GameObjects.Conditions;
55
using Intersect.GameObjects.Events;
@@ -335,9 +335,6 @@ public string EffectsJson
335335

336336
public EquipmentProperties? EquipmentProperties { get; set; }
337337

338-
[NotMapped, JsonIgnore]
339-
public ItemRange[] StatRanges => EquipmentProperties?.StatRanges?.Values.ToArray();
340-
341338
[Column(nameof(EventTriggers))]
342339
public string EventTriggersJson
343340
{
@@ -358,11 +355,10 @@ public string EventTriggersJson
358355
[NotMapped, JsonIgnore]
359356
public Dictionary<ItemEventTriggers, Guid> EventTriggers { get; set; } = new Dictionary<ItemEventTriggers, Guid>();
360357

361-
public bool TryGetRangeFor(Stat stat, out ItemRange range)
358+
public bool TryGetRangeFor(Stat stat, [NotNullWhen(true)] out ItemRange? range)
362359
{
363-
range = null;
360+
range = default;
364361
_ = EquipmentProperties?.StatRanges?.TryGetValue(stat, out range);
365-
366362
return range != default;
367363
}
368364

@@ -398,12 +394,13 @@ public void ModifyStatRangeLow(Stat stat, int val)
398394

399395
public void ValidateStatRanges()
400396
{
401-
if (StatRanges == default)
397+
var ranges = EquipmentProperties?.StatRanges?.Values;
398+
if (ranges == default)
402399
{
403400
return;
404401
}
405402

406-
foreach (var range in StatRanges)
403+
foreach (var range in ranges)
407404
{
408405
range.Validate();
409406
}

Intersect.Client.Core/Interface/Game/DescriptionWindows/ItemDescriptionWindow.cs

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Intersect.GameObjects;
33
using Intersect.Client.General;
44
using Intersect.Client.Localization;
5+
using Intersect.GameObjects.Ranges;
56
using Intersect.Logging;
67
using Intersect.Network.Packets.Server;
78
using 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

Comments
 (0)