Skip to content

Commit 8e4b774

Browse files
committed
Debug EffectFactory.CreateMany when there is no separator
1 parent f0a1d33 commit 8e4b774

File tree

5 files changed

+30
-23
lines changed

5 files changed

+30
-23
lines changed

Cyberia.Api/Factories/CriterionFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,13 @@ public static ICriterion Create(ReadOnlySpan<char> compressedCriterion)
166166
return Create(id, @operator);
167167
}
168168

169-
var parametersCount = compressedCriterion.Count(separator) + 1;
170-
if (parametersCount == 1)
169+
var parameterCount = compressedCriterion.Count(separator) + 1;
170+
if (parameterCount == 1)
171171
{
172172
return Create(id, @operator, compressedCriterion.ToString());
173173
}
174174

175-
Span<string> parameters = new string[parametersCount];
175+
Span<string> parameters = new string[parameterCount];
176176
var index = 0;
177177
foreach (var range in compressedCriterion.Split(separator))
178178
{

Cyberia.Api/Factories/EffectFactory.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ public static IEffect Create(ReadOnlySpan<char> compressedEffect)
478478

479479
if (compressedEffect.IsEmpty)
480480
{
481-
Log.Error("Failed to create Effect from an empty string");
481+
Log.Error("Failed to create Effect from empty string");
482482

483483
return new ErroredEffect(string.Empty);
484484
}
@@ -509,28 +509,28 @@ public static List<IEffect> CreateMany(ReadOnlySpan<char> compressedEffects)
509509

510510
if (compressedEffects.IsEmpty)
511511
{
512+
Log.Error("Failed to create Effects from empty string");
513+
512514
return [];
513515
}
514516

515-
var effectCount = compressedEffects.Count(separator) + 1;
516-
List<IEffect> effects = new(effectCount);
517+
var separatorCount = compressedEffects.Count(separator) + 1;
518+
Span<Range> ranges = stackalloc Range[separatorCount];
517519

518-
var indexOfSeparator = compressedEffects.IndexOf(separator);
519-
while (indexOfSeparator != -1)
520+
var effectCount = compressedEffects.Split(ranges, separator, StringSplitOptions.RemoveEmptyEntries);
521+
if (effectCount == 0)
520522
{
521-
if (indexOfSeparator == 0)
522-
{
523-
compressedEffects = compressedEffects[1..];
524-
indexOfSeparator = compressedEffects.IndexOf(separator);
523+
Log.Error("Failed to create Effects from {CompressedEffects}", compressedEffects.ToString());
525524

526-
continue;
527-
}
525+
return [];
526+
}
528527

529-
var effect = Create(compressedEffects[..indexOfSeparator]);
530-
effects.Add(effect);
528+
List<IEffect> effects = new(effectCount);
531529

532-
compressedEffects = compressedEffects[(indexOfSeparator + 1)..];
533-
indexOfSeparator = compressedEffects.IndexOf(separator);
530+
for (var i = 0; i < effectCount; i++)
531+
{
532+
var compressedEffect = compressedEffects[ranges[i]];
533+
effects.Add(Create(compressedEffect));
534534
}
535535

536536
return effects;

Cyberia.Api/JsonConverters/EffectReadOnlyListConverter.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Cyberia.Api.Factories;
22
using Cyberia.Api.Factories.Effects;
33

4+
using System.Collections.ObjectModel;
45
using System.Text.Json;
56
using System.Text.Json.Serialization;
67

@@ -23,7 +24,13 @@ public override IReadOnlyList<IEffect> Read(ref Utf8JsonReader reader, Type type
2324
throw new JsonException($"Expected {JsonTokenType.String} but got {reader.TokenType}.");
2425
}
2526

26-
return EffectFactory.CreateMany(reader.GetString() ?? string.Empty).AsReadOnly();
27+
var compressedEffects = reader.GetString();
28+
if (string.IsNullOrEmpty(compressedEffects))
29+
{
30+
return ReadOnlyCollection<IEffect>.Empty;
31+
}
32+
33+
return EffectFactory.CreateMany(compressedEffects).AsReadOnly();
2734
}
2835

2936
public override void Write(Utf8JsonWriter writer, IReadOnlyList<IEffect> values, JsonSerializerOptions options)

Cyberia.Api/Utils/RuneCalculator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ public static double GetPercentChanceToObtainRune(RuneData runeData, RuneType ty
8989
public static RuneBundle GetRuneBundleFromStat(RuneData runeData, int itemLevel, int statAmount, double? multiplicator = null)
9090
{
9191
RuneBundle bundle = new(runeData, 0, 0, 0, 0);
92-
var actualMultiplier = multiplicator ?? GetRandomMultiplicator();
93-
var amountExtractable = statAmount * GetPercentStatExtractable(runeData, itemLevel, statAmount) * actualMultiplier / 100;
92+
var actualMultiplicator = multiplicator ?? GetRandomMultiplicator();
93+
var amountExtractable = statAmount * GetPercentStatExtractable(runeData, itemLevel, statAmount) * actualMultiplicator / 100;
9494

9595
if (runeData.RaRuneItemId is not null)
9696
{

Cyberia.Salamandra/EventHandlers/InteractionsEventHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ private static bool TryParsePacket(
153153

154154
if (!packet.IsEmpty)
155155
{
156-
var parameterSize = packet.Count(PacketFormatter.Separator) + 1;
157-
parameters = new string[parameterSize];
156+
var parameterCount = packet.Count(PacketFormatter.Separator) + 1;
157+
parameters = new string[parameterCount];
158158

159159
var index = 0;
160160
foreach (var range in packet.Split(PacketFormatter.Separator))

0 commit comments

Comments
 (0)