示例#1
0
        public override XElement ToXML()
        {
            var conditionXml = new XElement("Condition");

            if (IsComparison)
            {
                if (IsComparisonToConstant)
                {
                    conditionXml.Add(new XElement("Type", "ComparisonToConstant"));
                }
                else if (IsComparisonToVariable)
                {
                    conditionXml.Add(new XElement("Type", "ComparisonToVariable"));
                }

                if (this.SelectedVariable != null && this.SelectedVariable.LinkedVariable != null)
                {
                    conditionXml.Add(new XElement("Left", this.SelectedVariable.LinkedVarId));
                }


                if (this.IsEquals)
                {
                    conditionXml.Add(new XElement("Comparison", "EQ"));
                }
                else if (this.IsNotEquals)
                {
                    conditionXml.Add(new XElement("Comparison", "NEQ"));
                }
                else if (this.IsLessThan)
                {
                    conditionXml.Add(new XElement("Comparison", "LT"));
                }
                else if (this.IsLessThanOrEqualTo)
                {
                    conditionXml.Add(new XElement("Comparison", "LTE"));
                }
                else if (this.IsGreaterThan)
                {
                    conditionXml.Add(new XElement("Comparison", "GT"));
                }
                else if (this.IsGreaterThanOrEqualTo)
                {
                    conditionXml.Add(new XElement("Comparison", "GTE"));
                }

                if (this.IsComparisonToVariable && this.VariableToCompare != null && this.VariableToCompare.LinkedVariable != null)
                {
                    conditionXml.Add(new XElement("Right", this.VariableToCompare.LinkedVarId));
                    if (this.IsDateTime)
                    {
                        conditionXml.Add(new XElement("VarType", "DateTime"));
                    }
                    else if (this.IsNumber)
                    {
                        conditionXml.Add(new XElement("VarType", "Number"));
                    }
                    else if (this.IsString)
                    {
                        conditionXml.Add(new XElement("VarType", "String"));
                    }
                }
                if (this.IsComparisonToConstant)
                {
                    if (this.IsDateTime)
                    {
                        conditionXml.Add(new XElement("Right", this.DateTimeToCompareTo.ToString()));
                        conditionXml.Add(new XElement("VarType", "DateTime"));
                    }
                    else if (this.IsNumber)
                    {
                        conditionXml.Add(new XElement("Right", this.NumberToCompareTo.ToString()));
                        conditionXml.Add(new XElement("VarType", "Number"));
                    }
                    else if (this.IsString)
                    {
                        conditionXml.Add(new XElement("Right", this.StringToCompareTo));
                        conditionXml.Add(new XElement("VarType", "String"));
                    }
                }
            }
            if (ItemIsNotNull)
            {
                conditionXml.Add(new XElement("Type", "ItemIsNotNull"));
                conditionXml.Add(new XElement("VarRef", this.SelectedVariable.LinkedVarId));
            }
            if (ItemIsClass)
            {
                conditionXml.Add(new XElement("Type", "ItemIsClass"));
                conditionXml.Add(new XElement("VarRef", this.SelectedVariable.LinkedVarId));
                conditionXml.Add(new XElement("ClassName", this.SelectedClassName));
            }
            if (PlayerHasItem)
            {
                conditionXml.Add(new XElement("Type", "PlayerHasItem"));
                conditionXml.Add(new XElement("ItemRef", this.SelectedItem.LinkedItemId));
            }
            return(new XElement("If", conditionXml,
                                new XElement("Then", ThenStatement.ToXML()),
                                new XElement("Else", ElseStatement.ToXML())));
        }