コード例 #1
0
        private BooleanVariableComparison GetBooleanVariableComparison()
        {
            var comp = new BooleanVariableComparison();

            if (cmbBooleanComparator.SelectedIndex < 0)
            {
                cmbBooleanComparator.SelectedIndex = 0;
            }

            comp.ComparingEqual = !Convert.ToBoolean(cmbBooleanComparator.SelectedIndex);

            comp.Value = optBooleanTrue.Checked;

            if (optBooleanGlobalVariable.Checked)
            {
                comp.CompareVariableType = VariableTypes.ServerVariable;
                comp.CompareVariableId   = ServerVariableBase.IdFromList(cmbBooleanGlobalVariable.SelectedIndex);
            }
            else if (optBooleanPlayerVariable.Checked)
            {
                comp.CompareVariableType = VariableTypes.PlayerVariable;
                comp.CompareVariableId   = PlayerVariableBase.IdFromList(cmbBooleanPlayerVariable.SelectedIndex);
            }

            return(comp);
        }
コード例 #2
0
        //OLD
        //public class ServerSwitchCondition : Condition
        //{
        //    public override ConditionTypes Type { get; } = ConditionTypes.ServerSwitch;
        //    public Guid SwitchId { get; set; }
        //    public bool Value { get; set; }
        //}

        private static JObject ConvertGlobalSwitchCondition(JObject obj)
        {
            var cmd = new VariableIsCondition();

            if (obj.ContainsKey("SwitchId"))
            {
                cmd.VariableId = Guid.Parse(obj["SwitchId"].ToString());
            }

            cmd.VariableType = VariableTypes.ServerVariable;

            var comp = new BooleanVariableComparison();

            cmd.Comparison = comp;

            comp.ComparingEqual = true;

            if (obj.ContainsKey("Value"))
            {
                comp.Value = bool.Parse(obj["Value"].ToString());
            }

            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));
        }
コード例 #3
0
        public static bool CheckVariableComparison(
            VariableValue currentValue,
            BooleanVariableComparison comparison,
            Player player,
            Event instance
            )
        {
            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.Boolean = comparison.Value;
            }

            if (compValue == null)
            {
                compValue = new VariableValue();
            }

            if (currentValue.Type == 0)
            {
                currentValue.Boolean = false;
            }

            if (compValue.Type != currentValue.Type)
            {
                return(false);
            }

            if (comparison.ComparingEqual)
            {
                return(currentValue.Boolean == compValue.Boolean);
            }
            else
            {
                return(currentValue.Boolean != compValue.Boolean);
            }
        }