diff --git a/Model/WhenLevel.cs b/Model/WhenLevel.cs index 5c9d8e3..3b70233 100644 --- a/Model/WhenLevel.cs +++ b/Model/WhenLevel.cs @@ -16,7 +16,7 @@ public class WhenLevel : IWhen { return false; } - var cmp = player.Level.CompareTo(this.Level); + var cmp = ((uint) player.Level).CompareTo(this.Level); return this.CompareResult switch { 1 when cmp > 0 => true, 0 when cmp == 0 => true, @@ -46,37 +46,31 @@ public class WhenLevelConverter : IYamlTypeConverter { var value = parser.Consume(); + void ParseOperation(int comparer) { + if (comparerResult != null) { + throw new YamlException("duplicate operations in whenlevel"); + } + + comparerResult = comparer; + + if (!uint.TryParse(value.Value, out var lvl)) { + throw new YamlException("invalid whenlevel: level was not numeric"); + } + + level = lvl; + } + switch (key.Value) { case "greaterThan": { - if (comparerResult != null) { - throw new YamlException("duplicate operations in whenlevel"); - } - - comparerResult = 1; + ParseOperation(1); break; } case "equalTo": { - if (comparerResult != null) { - throw new YamlException("duplicate operations in whenlevel"); - } - - comparerResult = 0; + ParseOperation(0); break; } case "lessThan": { - if (comparerResult != null) { - throw new YamlException("duplicate operations in whenlevel"); - } - - comparerResult = -1; - break; - } - case "level": { - if (!uint.TryParse(value.Value, out var lvl)) { - throw new YamlException("invalid whenlevel: level was not numeric"); - } - - level = lvl; + ParseOperation(-1); break; } case "text": { @@ -118,8 +112,7 @@ public class WhenLevelConverter : IYamlTypeConverter { }; } - public void WriteYaml(IEmitter emitter, object? value, Type type) - { + public void WriteYaml(IEmitter emitter, object? value, Type type) { throw new NotImplementedException(); } } diff --git a/replacements.yaml b/replacements.yaml index e22af7b..851a861 100644 --- a/replacements.yaml +++ b/replacements.yaml @@ -26,13 +26,13 @@ replacements: # Original: Don't ever turn your back on a beastie, hear? - id: 280 when: - - level: - greaterThan: 30 - text: |- - Try not to get - swarmed out there. - level: greaterThan: 50 text: |- Bet beasties never give you any trouble. + - level: + greaterThan: 30 + text: |- + Try not to get + swarmed out there.