private IntegerVariableComparison GetNumericVariableComparison() { var comp = new IntegerVariableComparison(); if (cmbNumericComparitor.SelectedIndex < 0) { cmbNumericComparitor.SelectedIndex = 0; } comp.Comparator = (VariableComparators)cmbNumericComparitor.SelectedIndex; comp.CompareVariableId = Guid.Empty; if (rdoVarCompareStaticValue.Checked) { comp.Value = (long)nudVariableValue.Value; } else if (rdoVarCompareGlobalVar.Checked) { comp.CompareVariableType = VariableTypes.ServerVariable; comp.CompareVariableId = ServerVariableBase.IdFromList(cmbCompareGlobalVar.SelectedIndex); } else if (rdoVarComparePlayerVar.Checked) { comp.CompareVariableType = VariableTypes.PlayerVariable; comp.CompareVariableId = PlayerVariableBase.IdFromList(cmbComparePlayerVar.SelectedIndex); } return(comp); }
//OLD //public class ServerVariableCondition : Condition //{ // public override ConditionTypes Type { get; } = ConditionTypes.ServerVariable; // public Guid VariableId { get; set; } // public VariableComparators Comparator { get; set; } = VariableComparators.Equal; // public VariableCompareTypes CompareType { get; set; } = VariableCompareTypes.StaticValue; // public long Value { get; set; } // public Guid CompareVariableId { get; set; } //} private static JObject ConvertGlobalVariableCondition(JObject obj) { var cmd = new VariableIsCondition(); if (obj.ContainsKey("VariableId")) { cmd.VariableId = Guid.Parse(obj["VariableId"].ToString()); } cmd.VariableType = VariableTypes.ServerVariable; var comp = new IntegerVariableComparison(); cmd.Comparison = comp; if (obj.ContainsKey("Value")) { comp.Value = long.Parse(obj["Value"].ToString()); } if (obj.ContainsKey("CompareVariableId")) { comp.CompareVariableId = Guid.Parse(obj["CompareVariableId"].ToString()); } if (obj.ContainsKey("Comparator")) { comp.Comparator = (VariableComparators)int.Parse(obj["Comparator"].ToString()); } if (!obj.ContainsKey("CompareType")) { comp.CompareVariableId = Guid.Empty; } else { if (int.Parse(obj["CompareType"].ToString()) == 1) { comp.CompareVariableType = VariableTypes.PlayerVariable; } else { comp.CompareVariableType = VariableTypes.ServerVariable; } } var newJson = JsonConvert.SerializeObject( cmd, typeof(Condition), new JsonSerializerSettings() { Formatting = Formatting.None, TypeNameHandling = TypeNameHandling.Auto, DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate, ObjectCreationHandling = ObjectCreationHandling.Replace } ); return(JObject.Parse(newJson)); }
public static bool CheckVariableComparison( VariableValue currentValue, IntegerVariableComparison comparison, Player player, Event instance ) { long compareAgainst = 0; VariableValue compValue = null; if (comparison.CompareVariableId != Guid.Empty) { if (comparison.CompareVariableType == VariableTypes.PlayerVariable) { compValue = player.GetVariableValue(comparison.CompareVariableId); } else if (comparison.CompareVariableType == VariableTypes.ServerVariable) { compValue = ServerVariableBase.Get(comparison.CompareVariableId)?.Value; } } else { compValue = new VariableValue(); compValue.Integer = comparison.Value; } if (compValue == null) { compValue = new VariableValue(); } if (currentValue.Type == 0) { currentValue.Integer = 0; } if (compValue.Type != currentValue.Type) { return(false); } var varVal = currentValue.Integer; compareAgainst = compValue.Integer; switch (comparison.Comparator) //Comparator { case VariableComparators.Equal: if (varVal == compareAgainst) { return(true); } break; case VariableComparators.GreaterOrEqual: if (varVal >= compareAgainst) { return(true); } break; case VariableComparators.LesserOrEqual: if (varVal <= compareAgainst) { return(true); } break; case VariableComparators.Greater: if (varVal > compareAgainst) { return(true); } break; case VariableComparators.Less: if (varVal < compareAgainst) { return(true); } break; case VariableComparators.NotEqual: if (varVal != compareAgainst) { return(true); } break; } return(false); }