fix: parse WhenLevel correctly
This commit is contained in:
parent
2924d52c61
commit
1420d44630
@ -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<Scalar>();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user