diff --git a/Barotrauma/BarotraumaShared/Source/StatusEffects/PropertyConditional.cs b/Barotrauma/BarotraumaShared/Source/StatusEffects/PropertyConditional.cs index 678dc030c..e910950f9 100644 --- a/Barotrauma/BarotraumaShared/Source/StatusEffects/PropertyConditional.cs +++ b/Barotrauma/BarotraumaShared/Source/StatusEffects/PropertyConditional.cs @@ -15,9 +15,19 @@ namespace Barotrauma HasStatusTag } + public enum OperatorType + { + Equals, + NotEquals, + LessThan, + LessThanEquals, + GreaterThan, + GreaterThanEquals + } + public readonly ConditionType Type; public readonly string PropertyName; - public readonly string Operator; + public readonly OperatorType Operator; public readonly string Value; public PropertyConditional(XAttribute attribute) @@ -25,7 +35,6 @@ namespace Barotrauma string attributeString = attribute.Value.ToString(); string atStr = attributeString; string[] splitString = atStr.Split(' '); - string op = splitString[0]; if (splitString.Length > 0) { for (int i = 1; i < splitString.Length; i++) @@ -34,12 +43,13 @@ namespace Barotrauma } } //thanks xml for not letting me use < or > in attributes :( + string op = splitString[0]; switch (op) { case "e": case "eq": case "equals": - op = "=="; + Operator = OperatorType.Equals; break; case "ne": case "neq": @@ -48,31 +58,31 @@ namespace Barotrauma case "!e": case "!eq": case "!equals": - op = "!="; + Operator = OperatorType.NotEquals; break; case "gt": case "greaterthan": - op = ">"; + Operator = OperatorType.GreaterThan; break; case "lt": case "lessthan": - op = "<"; + Operator = OperatorType.LessThan; break; case "gte": case "gteq": case "greaterthanequals": - op = ">="; + Operator = OperatorType.GreaterThanEquals; break; case "lte": case "lteq": case "lessthanequals": - op = "<="; + Operator = OperatorType.LessThanEquals; break; default: if (op != "==" && op != "!=" && op != ">" && op != "<" && op != ">=" && op != "<=") //Didn't use escape strings or anything { - atStr = attributeString; //We probably don't even have an operator - op = "=="; + atStr = attributeString; //We probably don't even have an operator + DebugConsole.ThrowError("Error in property conditional - \"" + op + "\" is not a valid operator."); } break; } @@ -82,8 +92,7 @@ namespace Barotrauma PropertyName = attribute.Name.ToString(); Type = ConditionType.PropertyValue; } - - Operator = op; + Value = atStr; } @@ -111,7 +120,7 @@ namespace Barotrauma switch (Operator) { - case "==": + case OperatorType.Equals: if (floatValue == null) { return property.GetValue().Equals(floatValue); @@ -120,7 +129,7 @@ namespace Barotrauma { return property.GetValue().Equals(Value); } - case "!=": + case OperatorType.NotEquals: if (floatValue == null) { return !property.GetValue().Equals(floatValue); @@ -129,7 +138,7 @@ namespace Barotrauma { return !property.GetValue().Equals(Value); } - case ">": + case OperatorType.GreaterThan: if (floatValue == null) { DebugConsole.ThrowError("Couldn't compare " + Value.ToString() + " (" + Value.GetType() + ") to property \"" + property.Name + "\" (" + type + ")! " @@ -138,7 +147,7 @@ namespace Barotrauma else if (floatProperty > floatValue) return true; break; - case "<": + case OperatorType.LessThan: if (floatValue == null) { DebugConsole.ThrowError("Couldn't compare " + Value.ToString() + " (" + Value.GetType() + ") to property \"" + property.Name + "\" (" + type + ")! " @@ -147,7 +156,7 @@ namespace Barotrauma else if (floatProperty < floatValue) return true; break; - case ">=": + case OperatorType.GreaterThanEquals: if (floatValue == null) { DebugConsole.ThrowError("Couldn't compare " + Value.ToString() + " (" + Value.GetType() + ") to property \"" + property.Name + "\" (" + type + ")! " @@ -156,7 +165,7 @@ namespace Barotrauma else if (floatProperty >= floatValue) return true; break; - case "<=": + case OperatorType.LessThanEquals: if (floatValue == null) { DebugConsole.ThrowError("Couldn't compare " + Value.ToString() + " (" + Value.GetType() + ") to property \"" + property.Name + "\" (" + type + ")! " diff --git a/Barotrauma/BarotraumaShared/Source/StatusEffects/StatusEffect.cs b/Barotrauma/BarotraumaShared/Source/StatusEffects/StatusEffect.cs index 28c523af8..291d343d3 100644 --- a/Barotrauma/BarotraumaShared/Source/StatusEffects/StatusEffect.cs +++ b/Barotrauma/BarotraumaShared/Source/StatusEffects/StatusEffect.cs @@ -285,7 +285,7 @@ namespace Barotrauma } return false; case PropertyConditional.ConditionType.Name: - return pc.Operator == "==" ? target.Name == valStr : target.Name != valStr; + return (pc.Operator == PropertyConditional.OperatorType.Equals) == (target.Name == valStr); case PropertyConditional.ConditionType.HasTag: { string[] readTags = valStr.Split(','); @@ -294,7 +294,7 @@ namespace Barotrauma if (((Item)target).HasTag(tag)) matches++; //If operator is == then it needs to match everything, otherwise if its != there must be zero matches. - return pc.Operator == "==" ? matches >= readTags.Length : matches <= 0; + return pc.Operator == PropertyConditional.OperatorType.Equals ? matches >= readTags.Length : matches <= 0; } case PropertyConditional.ConditionType.HasStatusTag: List durations = DurationList.FindAll(d => d.Targets.Contains(target)); @@ -310,7 +310,7 @@ namespace Barotrauma foreach (string tag in readTags) if (duration.Parent.HasTag(tag)) matches++; - success = pc.Operator == "==" ? matches >= readTags.Length : matches <= 0; + success = pc.Operator == PropertyConditional.OperatorType.Equals ? matches >= readTags.Length : matches <= 0; if (cancelStatusEffect > 0 && success) DurationList.Remove(duration); if (cancelStatusEffect != 2) //cancelStatusEffect 1 = only cancel once, cancelStatusEffect 2 = cancel all of matching tags @@ -322,7 +322,7 @@ namespace Barotrauma foreach (string tag in readTags) if (delay.Parent.HasTag(tag)) matches++; - success = pc.Operator == "==" ? matches >= readTags.Length : matches <= 0; + success = pc.Operator == PropertyConditional.OperatorType.Equals ? matches >= readTags.Length : matches <= 0; if (cancelStatusEffect > 0 && success) DelayedEffect.DelayList.Remove(delay); if (cancelStatusEffect != 2) //ditto @@ -331,7 +331,7 @@ namespace Barotrauma } return success; case PropertyConditional.ConditionType.SpeciesName: - return pc.Operator == "==" ? ((Character)target).SpeciesName == valStr : ((Character)target).SpeciesName != valStr; + return (pc.Operator == PropertyConditional.OperatorType.Equals) == (((Character)target).SpeciesName == valStr); } } }