protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            if (Degree == null)
            {
                return(Completion.Void);
            }
            double degree = 0;

            try
            {
                var c = Degree.Execute(enviroment);
                if (c.Type != CompletionType.Value)
                {
                    return(c);
                }
                degree = TypeConverters.GetValue <double>(c.ReturnValue);
            }
            catch
            {
                return(Completion.Exception("Wrong number format", Degree));
            }

            Sprite sp = enviroment.GetValue("$$INSTANCE$$") as Sprite;

            if (sp.Direction != (int)degree)
            {
                sp.Direction = (int)degree;
                App.Current.Dispatcher.InvokeAsync(new Action(() =>
                {
                    (enviroment.GetValue("$$Player") as ScriptPlayer).DrawScript();
                }));
            }
            return(Completion.Void);
        }
        Completion ExecuteLogical(ExecutionEnvironment enviroment, object left, object right)
        {
            if (!(left is bool))
            {
                return(Completion.Exception(Properties.Language.NotBoolean, Left));
            }
            if (!(right is bool))
            {
                return(Completion.Exception(Properties.Language.NotBoolean, Right));
            }
            try
            {
                var l = TypeConverters.GetValue <bool>(left);
                var r = TypeConverters.GetValue <bool>(right);
                switch (Operator)
                {
                case Operator.And:
                    return(new Completion(l && r));

                case Operator.Or:
                    return(new Completion(l || r));
                }
                return(Completion.Exception(Properties.Language.UnknowException, this));
            }
            catch (Exception e)
            {
                return(Completion.Exception(e.Message, this));
            }
        }
示例#3
0
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            if (X == null || Y == null)
            {
                return(Completion.Exception(Properties.Language.NullException, this));
            }
            var c = X.Execute(enviroment);

            if (!c.IsValue)
            {
                return(c);
            }
            if (!TypeConverters.IsNumber(c.ReturnValue))
            {
                return(Completion.Exception(Properties.Language.ValueNotNumberException, X));
            }
            double d = TypeConverters.GetValue <double>(c.ReturnValue);

            var e = X.Execute(enviroment);

            if (!e.IsValue)
            {
                return(e);
            }
            if (!TypeConverters.IsNumber(e.ReturnValue))
            {
                return(Completion.Exception(Properties.Language.ValueNotNumberException, Y));
            }
            double f = TypeConverters.GetValue <double>(e.ReturnValue);

            DrawWindow wnd = CanvasEnvironment.GetCanvas(enviroment);

            wnd.LineTo(d, f);
            return(Completion.Void);
        }
        public Completion Execute(ExecutionEnvironment enviroment)
        {
            if (Y == null)
            {
                return(Completion.Void);
            }
            double y = 0;

            try
            {
                var c = Y.Execute(enviroment);
                if (c.Type != CompletionType.Value)
                {
                    return(c);
                }
                y = TypeConverters.GetValue <double>(c.ReturnValue);
            }
            catch
            {
                return(Completion.Exception("Wrong number format", Y));
            }
            Sprite sp = enviroment.GetValue("$$INSTANCE$$") as Sprite;

            sp.Y = (int)y;
            App.Current.Dispatcher.InvokeAsync(new Action(() =>
            {
                (enviroment.GetValue("$$Player") as ScriptPlayer).DrawScript();
            }));
            return(Completion.Void);
        }
示例#5
0
        public Completion Execute(ExecutionEnvironment enviroment)
        {
            if (Size == null)
            {
                return(Completion.Void);
            }
            var c = Size.Execute(enviroment);

            if (c.Type != CompletionType.Value)
            {
                return(c);
            }
            int s = 0;

            try
            {
                s = TypeConverters.GetValue <int>(c.ReturnValue);
            }catch (Exception e)
            {
                return(Completion.Exception("Wrong number format", Size));
            }
            Sprite sp = enviroment.GetValue("$$INSTANCE$$") as Sprite;

            sp.Size = s;
            App.Current.Dispatcher.InvokeAsync(new Action(() =>
            {
                (enviroment.GetValue("$$Player") as ScriptPlayer).DrawScript();
            }));
            return(Completion.Void);
        }
示例#6
0
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            if (Step == null || Angle == null || XRadius == null || YRadius == null)
            {
                return(Completion.Exception(Properties.Language.NullException, this));
            }

            var c = Step.Execute(enviroment);

            if (!c.IsValue)
            {
                return(c);
            }
            if (!TypeConverters.IsNumber(c.ReturnValue))
            {
                return(Completion.Exception(Properties.Language.ValueNotNumberException, Step));
            }
            double step = TypeConverters.GetValue <double>(c.ReturnValue);

            var d = Angle.Execute(enviroment);

            if (!d.IsValue)
            {
                return(d);
            }
            if (!TypeConverters.IsNumber(d.ReturnValue))
            {
                return(Completion.Exception(Properties.Language.ValueNotNumberException, Angle));
            }
            double angle = TypeConverters.GetValue <double>(d.ReturnValue);

            var e = XRadius.Execute(enviroment);

            if (!e.IsValue)
            {
                return(e);
            }
            if (!TypeConverters.IsNumber(e.ReturnValue))
            {
                return(Completion.Exception(Properties.Language.ValueNotNumberException, XRadius));
            }
            double x = TypeConverters.GetValue <double>(e.ReturnValue);

            var f = YRadius.Execute(enviroment);

            if (!f.IsValue)
            {
                return(f);
            }
            if (!TypeConverters.IsNumber(f.ReturnValue))
            {
                return(Completion.Exception(Properties.Language.ValueNotNumberException, YRadius));
            }
            double     y   = TypeConverters.GetValue <double>(f.ReturnValue);
            DrawWindow wnd = CanvasEnvironment.GetCanvas(enviroment);

            wnd.Arc(step, angle, x, y);
            return(Completion.Void);
        }
示例#7
0
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            if (R == null || G == null || B == null)
            {
                return(Completion.Exception(Properties.Language.NullException, this));
            }
            var r = R.Execute(enviroment);

            if (!r.IsValue)
            {
                return(r);
            }
            if (!TypeConverters.IsNumber(r.ReturnValue))
            {
                return(Completion.Exception(Properties.Language.ValueNotNumberException, R));
            }
            int ri = TypeConverters.GetValue <int>(r.ReturnValue);

            if (ri < 0 || ri > 255)
            {
                return(Completion.Exception(Properties.Language.ColorValueOutRangeException, R));
            }
            var g = R.Execute(enviroment);

            if (!g.IsValue)
            {
                return(g);
            }
            if (!TypeConverters.IsNumber(g.ReturnValue))
            {
                return(Completion.Exception(Properties.Language.ValueNotNumberException, G));
            }
            int gi = TypeConverters.GetValue <int>(g.ReturnValue);

            if (gi < 0 || gi > 255)
            {
                return(Completion.Exception(Properties.Language.ColorValueOutRangeException, G));
            }
            var b = R.Execute(enviroment);

            if (!b.IsValue)
            {
                return(b);
            }
            if (!TypeConverters.IsNumber(b.ReturnValue))
            {
                return(Completion.Exception(Properties.Language.ValueNotNumberException, B));
            }
            int bi = TypeConverters.GetValue <int>(b.ReturnValue);

            if (bi < 0 || bi > 255)
            {
                return(Completion.Exception(Properties.Language.ColorValueOutRangeException, B));
            }
            return(new Completion(Color.FromRgb((byte)ri, (byte)gi, (byte)bi)));
        }
        public T GetValue <T>(string variable)
        {
            object value = GetValue(variable);

            if (value == null)
            {
                return(default(T));
            }
            return(TypeConverters.GetValue <T>(value));
        }
示例#9
0
        public Completion Execute(ExecutionEnvironment enviroment)
        {
            if (ImageIndex == null)
            {
                return(Completion.Void);
            }
            var c = ImageIndex.Execute(enviroment);

            if (c.Type != CompletionType.Value)
            {
                return(c);
            }
            int    currentIndex = 0;
            Sprite sp           = enviroment.GetValue("$$INSTANCE$$") as Sprite;

            if (TypeConverters.IsNumber(c.ReturnValue))
            {
                try
                {
                    currentIndex = TypeConverters.GetValue <int>(c.ReturnValue);
                }
                catch
                {
                    return(Completion.Exception("Wrong number format", ImageIndex));
                }
            }
            else
            {
                string name = c.ReturnValue + "";
                int    i    = 0;
                foreach (Resource r in sp.Images)
                {
                    if (r.DisplayName == name)
                    {
                        currentIndex = i;
                    }
                    i++;
                }
            }
            if (currentIndex < 0)
            {
                currentIndex = 0;
            }
            if (currentIndex >= sp.Images.Count)
            {
                currentIndex = 0;
            }
            sp.CurrentImage = currentIndex;
            App.Current.Dispatcher.InvokeAsync(new Action(() =>
            {
                (enviroment.GetValue("$$Player") as ScriptPlayer).DrawScript();
            }));
            return(Completion.Void);
        }
示例#10
0
        public Completion Assign(ExecutionEnvironment environment, object value)
        {
            if (!TypeConverters.IsNumber(value))
            {
                return(Completion.Exception(Properties.Language.ValueNotNumberException, this));
            }
            DrawWindow wnd = CanvasEnvironment.GetCanvas(environment);

            wnd.Thickness = TypeConverters.GetValue <double>(value);
            return(new Completion(value));
        }
示例#11
0
        public Completion Execute(ExecutionEnvironment enviroment)
        {
            if (Min == null)
            {
                return(Completion.Exception("parameter of random can not be null", Min));
            }
            if (Max == null)
            {
                return(Completion.Exception("parameter of random can not be null", Max));
            }
            var left = Min.Execute(enviroment);

            if (left.Type != CompletionType.Value)
            {
                return(left);
            }
            var right = Max.Execute(enviroment);

            if (right.Type != CompletionType.Value)
            {
                return(right);
            }
            if (right.Type != CompletionType.Value)
            {
                return(right);
            }
            if (!TypeConverters.IsNumber(left.ReturnValue))
            {
                return(Completion.Exception("value is not a number", Min));
            }
            if (!TypeConverters.IsNumber(right.ReturnValue))
            {
                return(Completion.Exception("value is not a number", Max));
            }
            Type T = TypeConverters.GetNumberTypes(left.ReturnValue, right.ReturnValue);

            if (T == null)
            {
                return(Completion.Exception("Only nuber can accepted", this));
            }

            try
            {
                var l = TypeConverters.GetValue <int>(left.ReturnValue);
                var r = TypeConverters.GetValue <int>(right.ReturnValue);
                return(new Completion(new Random(1437).Next(l, r)));
            }
            catch (Exception e)
            {
                return(Completion.Exception(e.Message, this));
            }
        }
示例#12
0
        public T GetValue <T>(string variable)
        {
            if (IsAborting)
            {
                throw new ExecutionAbortException(Properties.Language.ExecutionAborted);
            }
            object value = GetValue(variable);

            if (value == null)
            {
                return(default(T));
            }
            return(TypeConverters.GetValue <T>(value));
        }
示例#13
0
 Completion CallMathFunc <T>(List <object> values)
 {
     try
     {
         var ps = new List <T>();
         foreach (var v in values)
         {
             ps.Add(TypeConverters.GetValue <T>(v));
         }
         var methods = typeof(Math).GetMethods();
         foreach (var m in methods)
         {
             if (m.Name.Equals(MathFunction))
             {
                 var pa = m.GetParameters();
                 if (ps.Count != pa.Length)
                 {
                     continue;
                 }
                 bool isFunc = true;
                 foreach (var p in pa)
                 {
                     if (!p.ParameterType.Equals(typeof(T)))
                     {
                         isFunc = false;
                     }
                     break;
                 }
                 if (isFunc)
                 {
                     object[] mps = new object[ps.Count];
                     for (int i = 0; i < ps.Count; i++)
                     {
                         mps[i] = ps[i];
                     }
                     return(new Completion(m.Invoke(null, mps)));
                 }
             }
         }
     }catch (Exception e)
     {
         Console.WriteLine(e.Message);
         Console.WriteLine(e.StackTrace);
         return(Completion.Exception(e.Message, this));
     }
     return(Completion.Exception("no function " + MathFunction + " was not found", this));
 }
示例#14
0
        public Completion Execute(ExecutionEnvironment enviroment)
        {
            if (Left == null || Right == null)
            {
                return(new Completion("Null Exception", CompletionType.Exception));
            }
            var left = Left.Execute(enviroment);

            if (left.Type != CompletionType.Value)
            {
                return(left);
            }
            if (!(left.ReturnValue is bool))
            {
                return(Completion.Exception("left value is not a boolean", Left));
            }
            var right = Right.Execute(enviroment);

            if (right.Type != CompletionType.Value)
            {
                return(right);
            }
            if (!(right.ReturnValue is bool))
            {
                return(Completion.Exception("right value is not a boolean", Right));
            }
            try
            {
                var l = TypeConverters.GetValue <bool>(left.ReturnValue);
                var r = TypeConverters.GetValue <bool>(right.ReturnValue);
                switch (Operator)
                {
                case Operator.And:
                    return(new Completion(l && r));

                case Operator.Or:
                    return(new Completion(l || r));
                }
                return(Completion.Exception("Unknow Exception", this));
            }
            catch (Exception e)
            {
                return(new Completion(e.Message, CompletionType.Exception));
            }
        }
示例#15
0
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            var c = Duration.Execute(enviroment);

            if (c.Type != CompletionType.Value)
            {
                return(c);
            }
            try
            {
                float t = TypeConverters.GetValue <float>(c.ReturnValue);
                Thread.Sleep((int)(t * 1000));
            }catch (Exception e)
            {
                return(new Completion(e.Message, CompletionType.Exception));
            }
            return(Completion.Void);
        }
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            if (Value == null)
            {
                return(Completion.Exception(Language.NullException, this));
            }
            var c = Value.Execute(enviroment);

            if (!c.IsValue)
            {
                return(c);
            }
            if (!TypeConverters.IsNumber(c.ReturnValue))
            {
                return(Completion.Exception(Language.NotNumberException, Value));
            }
            double d = TypeConverters.GetValue <double>(c.ReturnValue);

            return(new Completion(Math.Atan(1 / d) * 180 / Math.PI));
        }
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            if (Degree == null)
            {
                return(Completion.Exception(Language.NullException, this));
            }
            var c = Degree.Execute(enviroment);

            if (!c.IsValue)
            {
                return(c);
            }
            if (!TypeConverters.IsNumber(c.ReturnValue))
            {
                return(Completion.Exception(Language.NotNumberException, Degree));
            }
            double d = TypeConverters.GetValue <double>(c.ReturnValue) * Math.PI / 180;

            return(new Completion(Math.Cos(d)));
        }
示例#18
0
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            if (Loop == null || Body == null || Body.Body.Count == 0)
            {
                return(Completion.Void);
            }
            var c = Loop.Execute(enviroment);

            if (c.Type == CompletionType.Value)
            {
                int cycle = 0;
                try
                {
                    cycle = TypeConverters.GetValue <int>(c.ReturnValue);
                }
                catch
                {
                    return(Completion.Exception(Properties.Language.NotNumber, Loop));
                }
                for (int i = 0; i < cycle; i++)
                {
                    ExecutionEnvironment current = new ExecutionEnvironment(enviroment);
                    var cx = Body.Execute(current);
                    if (cx.Type == CompletionType.Exception)
                    {
                        return(cx);
                    }
                    if (cx.Type == CompletionType.Break)
                    {
                        return(Completion.Void);
                    }
                    if (cx.Type == CompletionType.Return)
                    {
                        return(cx);
                    }
                }
            }
            return(c);
        }
示例#19
0
        public Completion Execute(ExecutionEnvironment enviroment)
        {
            if (Loop == null || Body == null || Body.Body.Count == 0)
            {
                return(Completion.Void);
            }
            var c = Loop.Execute(enviroment);

            if (c.Type == CompletionType.Value)
            {
                int cycle = 0;
                try
                {
                    cycle = TypeConverters.GetValue <int>(c.ReturnValue);
                }
                catch
                {
                    return(Completion.Exception("loop parameter is not a number", Loop));
                }
                for (int i = 0; i < cycle; i++)
                {
                    ExecutionEnvironment current = new ExecutionEnvironment(enviroment);
                    var cx = Body.Execute(current);
                    if (cx.Type == CompletionType.Exception)
                    {
                        return(cx);
                    }
                    if (cx.Type == CompletionType.Break)
                    {
                        return(Completion.Void);
                    }
                    if (cx.Type == CompletionType.Return)
                    {
                        return(cx);
                    }
                }
            }
            return(c);
        }
示例#20
0
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            if (Step == null)
            {
                return(Completion.Exception(Properties.Language.NullException, this));
            }
            var c = Step.Execute(enviroment);

            if (!c.IsValue)
            {
                return(c);
            }
            if (!TypeConverters.IsNumber(c.ReturnValue))
            {
                return(Completion.Exception(Properties.Language.ValueNotNumberException, Step));
            }
            double     d   = TypeConverters.GetValue <double>(c.ReturnValue);
            DrawWindow wnd = CanvasEnvironment.GetCanvas(enviroment);

            wnd.Turn(d);
            return(Completion.Void);
        }
示例#21
0
        public Completion Execute(ExecutionEnvironment enviroment)
        {
            if (Degree == null)
            {
                return(Completion.Void);
            }
            double degree = 0;

            try
            {
                var c = Degree.Execute(enviroment);
                if (c.Type != CompletionType.Value)
                {
                    return(c);
                }
                degree = TypeConverters.GetValue <double>(c.ReturnValue);
            }
            catch
            {
                return(Completion.Exception("Wrong number format", Degree));
            }
            Sprite sp = enviroment.GetValue("$$INSTANCE$$") as Sprite;

            if (Direction == RotationDirection.Clockwise)
            {
                sp.Direction += (int)degree;
            }
            else
            {
                sp.Direction -= (int)degree;
            }
            App.Current.Dispatcher.InvokeAsync(new Action(() =>
            {
                (enviroment.GetValue("$$Player") as ScriptPlayer).DrawScript();
            }));
            double result = sp.Direction;

            return(new Completion(result));
        }
示例#22
0
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            if (String == null)
            {
                return(Completion.Exception(Language.NullException, this));
            }
            var c = String.Execute(enviroment);

            if (!c.IsValue)
            {
                return(c);
            }
            if (!(c.ReturnValue is string || TypeConverters.IsNumber(c.ReturnValue)))
            {
                return(Completion.Exception(Language.NotStringNumberException, String));
            }
            if (c.ReturnValue is string)
            {
                try
                {
                    return(new Completion(long.Parse(c.ReturnValue as string)));
                }
                catch (Exception e)
                {
                    return(Completion.Exception(e.Message, String));
                }
            }
            try
            {
                return(new Completion(TypeConverters.GetValue <long>(c.ReturnValue)));
            }
            catch (Exception e)
            {
                return(Completion.Exception(string.Format(Language.NotConvertToLongException, c.ReturnValue), String));
            }
        }
示例#23
0
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            if (Left == null)
            {
                return(Completion.Exception(Properties.Language.NullException, this));
            }
            if (Right == null)
            {
                return(Completion.Exception(Properties.Language.NullException, this));
            }
            var left = Left.Execute(enviroment);

            if (left.Type != CompletionType.Value)
            {
                return(left);
            }
            var right = Right.Execute(enviroment);

            if (right.Type != CompletionType.Value)
            {
                return(right);
            }
            if (IsLogicalOperator(Operator))
            {
                return(ExecuteLogical(enviroment, left.ReturnValue, right.ReturnValue));
            }
            if (Operator == Operator.Add)
            {
                if ((left.ReturnValue is string) || right.ReturnValue is string)
                {
                    return(ExecuteStringAdd(enviroment, left.ReturnValue, right.ReturnValue));
                }
            }
            if (Operator == Operator.Equal)
            {
                if (left.ReturnValue is string)
                {
                    return(new Completion(left.ReturnValue is string && (left.ReturnValue as string).Equals(right.ReturnValue)));
                }
                if (right.ReturnValue is string)
                {
                    return(new Completion(right.ReturnValue is string && (right.ReturnValue as string).Equals(left.ReturnValue)));
                }
                if (left.ReturnValue is bool)
                {
                    return(new Completion(right.ReturnValue is bool && (bool)right.ReturnValue == (bool)left.ReturnValue));
                }
                if (right.ReturnValue is bool)
                {
                    return(new Completion(left.ReturnValue is bool && (bool)left.ReturnValue == (bool)right.ReturnValue));
                }
                if (left.ReturnValue == null)
                {
                    if (right.ReturnValue == null)
                    {
                        return(new Completion(true));
                    }
                    else
                    {
                        return(new Completion(false));
                    }
                }
                if (right.ReturnValue == null)
                {
                    if (left.ReturnValue == null)
                    {
                        return(new Completion(true));
                    }
                    return(new Completion(false));
                }
            }
            if (Operator == Operator.NotEqual)
            {
                if (left.ReturnValue is string)
                {
                    return(new Completion(!(left.ReturnValue as string).Equals(right.ReturnValue)));
                }
                if (right.ReturnValue is string)
                {
                    return(new Completion(!(right.ReturnValue as string).Equals(left.ReturnValue)));
                }
                if (left.ReturnValue is bool)
                {
                    return(new Completion(!(right.ReturnValue is bool) || (bool)right.ReturnValue != (bool)left.ReturnValue));
                }
                if (right.ReturnValue is bool)
                {
                    return(new Completion(!(left.ReturnValue is bool) || (bool)left.ReturnValue != (bool)right.ReturnValue));
                }
                if (left.ReturnValue == null)
                {
                    if (right.ReturnValue != null)
                    {
                        return(new Completion(true));
                    }
                    else
                    {
                        return(new Completion(false));
                    }
                }
                if (right.ReturnValue == null)
                {
                    if (left.ReturnValue != null)
                    {
                        return(new Completion(true));
                    }
                    return(new Completion(false));
                }
            }
            if (Operator == Operator.Add)
            {
                if ((left.ReturnValue is DateTime) && right.ReturnValue is DateTime)
                {
                    return(ExecuteStringAdd(enviroment, left.ReturnValue, right.ReturnValue));
                }
            }
            Type T = TypeConverters.GetMaxTypes(left.ReturnValue, right.ReturnValue);

            if (T == null)
            {
                return(Completion.Exception(Properties.Language.NotNumber, this));
            }
            if (Operator == Operator.Mod || Operator == Operator.BitAnd || Operator == Operator.BitOr ||
                Operator == Operator.BitLeftShift || Operator == Operator.BitRightShift || Operator == Operator.BitExclusiveOr)
            {
                T = typeof(int);
            }
            if (T.Equals(typeof(char)))
            {
                try
                {
                    var l = TypeConverters.GetValue <char>(left.ReturnValue);
                    var r = TypeConverters.GetValue <char>(right.ReturnValue);
                    switch (Operator)
                    {
                    case Operator.Add:
                        return(new Completion(l + r));

                    case Operator.Minus:
                        return(new Completion(l - r));

                    case Operator.Mulitiply:
                        return(new Completion(l * r));

                    case Operator.Divide:
                        return(new Completion(l / r));

                    case Operator.Mod:
                        return(new Completion(l % r));

                    case Operator.Great:
                        return(new Completion(l > r));

                    case Operator.GreatOrEqual:
                        return(new Completion(l >= r));

                    case Operator.Less:
                        return(new Completion(l < r));

                    case Operator.LessOrEqual:
                        return(new Completion(l <= r));

                    case Operator.Equal:
                        return(new Completion(l == r));

                    case Operator.NotEqual:
                        return(new Completion(l != r));

                    case Operator.BitAnd:
                        return(new Completion(l & r));

                    case Operator.BitOr:
                        return(new Completion(l | r));

                    case Operator.BitLeftShift:
                        return(new Completion(l << r));

                    case Operator.BitRightShift:
                        return(new Completion(l >> r));

                    case Operator.BitExclusiveOr:
                        return(new Completion(l ^ r));
                    }
                    return(Completion.Exception(Properties.Language.UnknowException, this));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                    return(Completion.Exception(e.Message, this));
                }
            }
            if (T.Equals(typeof(int)))
            {
                try
                {
                    var l = TypeConverters.GetValue <int>(left.ReturnValue);
                    var r = TypeConverters.GetValue <int>(right.ReturnValue);
                    switch (Operator)
                    {
                    case Operator.Add:
                        return(new Completion(l + r));

                    case Operator.Minus:
                        return(new Completion(l - r));

                    case Operator.Mulitiply:
                        return(new Completion(l * r));

                    case Operator.Divide:
                        return(new Completion(l / r));

                    case Operator.Mod:
                        return(new Completion(l % r));

                    case Operator.Great:
                        return(new Completion(l > r));

                    case Operator.GreatOrEqual:
                        return(new Completion(l >= r));

                    case Operator.Less:
                        return(new Completion(l < r));

                    case Operator.LessOrEqual:
                        return(new Completion(l <= r));

                    case Operator.Equal:
                        return(new Completion(l == r));

                    case Operator.NotEqual:
                        return(new Completion(l != r));

                    case Operator.BitAnd:
                        return(new Completion(l & r));

                    case Operator.BitOr:
                        return(new Completion(l | r));

                    case Operator.BitLeftShift:
                        return(new Completion(l << r));

                    case Operator.BitRightShift:
                        return(new Completion(l >> r));

                    case Operator.BitExclusiveOr:
                        return(new Completion(l ^ r));
                    }
                    return(Completion.Exception(Properties.Language.UnknowException, this));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                    return(Completion.Exception(e.Message, this));
                }
            }
            if (T.Equals(typeof(float)))
            {
                try
                {
                    var l = TypeConverters.GetValue <float>(left.ReturnValue);
                    var r = TypeConverters.GetValue <float>(right.ReturnValue);
                    switch (Operator)
                    {
                    case Operator.Add:
                        return(new Completion(l + r));

                    case Operator.Minus:
                        return(new Completion(l - r));

                    case Operator.Mulitiply:
                        return(new Completion(l * r));

                    case Operator.Divide:
                        return(new Completion(l / r));

                    case Operator.Great:
                        return(new Completion(l > r));

                    case Operator.GreatOrEqual:
                        return(new Completion(l >= r));

                    case Operator.Less:
                        return(new Completion(l < r));

                    case Operator.LessOrEqual:
                        return(new Completion(l <= r));

                    case Operator.Equal:
                        return(new Completion(l == r));

                    case Operator.NotEqual:
                        return(new Completion(l != r));
                    }
                    return(Completion.Exception(Properties.Language.UnknowException, this));
                }
                catch (Exception e)
                {
                    return(Completion.Exception(e.Message, this));
                }
            }
            if (T.Equals(typeof(long)))
            {
                try
                {
                    var l = TypeConverters.GetValue <long>(left.ReturnValue);
                    var r = TypeConverters.GetValue <long>(right.ReturnValue);
                    switch (Operator)
                    {
                    case Operator.Add:
                        return(new Completion(l + r));

                    case Operator.Minus:
                        return(new Completion(l - r));

                    case Operator.Mulitiply:
                        return(new Completion(l * r));

                    case Operator.Divide:
                        return(new Completion(l / r));

                    case Operator.Great:
                        return(new Completion(l > r));

                    case Operator.GreatOrEqual:
                        return(new Completion(l >= r));

                    case Operator.Less:
                        return(new Completion(l < r));

                    case Operator.LessOrEqual:
                        return(new Completion(l <= r));

                    case Operator.Equal:
                        return(new Completion(l == r));

                    case Operator.NotEqual:
                        return(new Completion(l != r));
                    }
                    return(Completion.Exception(Properties.Language.UnknowException, this));
                }
                catch (Exception e)
                {
                    return(Completion.Exception(e.Message, this));
                }
            }
            {
                try
                {
                    double l = TypeConverters.GetValue <double>(left.ReturnValue);
                    double r = TypeConverters.GetValue <double>(right.ReturnValue);
                    switch (Operator)
                    {
                    case Operator.Add:
                        return(new Completion(l + r));

                    case Operator.Minus:
                        return(new Completion(l - r));

                    case Operator.Mulitiply:
                        return(new Completion(l * r));

                    case Operator.Divide:
                        return(new Completion(l / r));

                    case Operator.Great:
                        return(new Completion(l > r));

                    case Operator.GreatOrEqual:
                        return(new Completion(l >= r));

                    case Operator.Less:
                        return(new Completion(l < r));

                    case Operator.LessOrEqual:
                        return(new Completion(l <= r));

                    case Operator.Equal:
                        return(new Completion(l == r));

                    case Operator.NotEqual:
                        return(new Completion(l != r));
                    }
                    return(Completion.Exception(Properties.Language.UnknowException, this));
                }
                catch (Exception e)
                {
                    return(Completion.Exception(e.Message, this));
                }
            }
        }
示例#24
0
 protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
 {
     try
     {
         List <object> values = new List <object>();
         for (int i = 0; i < Args.Count; i++)
         {
             if (Args[i] == null)
             {
                 return(Completion.Exception(Language.NullException, this));
             }
             var c = Args[i].Execute(enviroment);
             if (!c.IsValue)
             {
                 return(c);
             }
             if (!TypeConverters.IsNumber(c.ReturnValue))
             {
                 return(Completion.Exception(Language.NotNumberException, Args[i]));
             }
             values.Add(c.ReturnValue);
         }
         int        methodCount  = 0;
         var        ms           = typeof(Math).GetMethods();
         MethodInfo doubleMethod = null;
         foreach (var m in ms)
         {
             if (m.Name.Equals(MathFunction) && m.GetParameters().Length == Args.Count)
             {
                 methodCount++;
                 bool isDouble = true;
                 foreach (var p in m.GetParameters())
                 {
                     if (!p.ParameterType.Equals(typeof(double)))
                     {
                         isDouble = false;
                         break;
                     }
                 }
                 if (isDouble)
                 {
                     doubleMethod = m;
                 }
             }
         }
         if (methodCount < 0)
         {
             return(Completion.Exception("no function found", this));
         }
         else if (methodCount == 1)
         {
             if (doubleMethod != null)
             {
                 var           ps     = doubleMethod.GetParameters();
                 List <object> fparam = new List <object>();
                 for (int i = 0; i < Args.Count; i++)
                 {
                     fparam.Add(TypeConverters.GetValue(values[i], ps[i].ParameterType));
                 }
                 return(new Completion(doubleMethod.Invoke(null, fparam.ToArray())));
             }
             else
             {
                 MethodInfo    method = typeof(Math).GetMethod(MathFunction);
                 var           ps     = method.GetParameters();
                 List <object> fparam = new List <object>();
                 for (int i = 0; i < Args.Count; i++)
                 {
                     fparam.Add(TypeConverters.GetValue(values[i], ps[i].ParameterType));
                 }
                 return(new Completion(method.Invoke(null, fparam.ToArray())));
             }
         }
         else if (methodCount == 2)
         {
             if (doubleMethod != null)
             {
                 var           ps     = doubleMethod.GetParameters();
                 List <object> fparam = new List <object>();
                 for (int i = 0; i < Args.Count; i++)
                 {
                     fparam.Add(TypeConverters.GetValue(values[i], ps[i].ParameterType));
                 }
                 return(new Completion(doubleMethod.Invoke(null, fparam.ToArray())));
             }
             return(Completion.Exception(Language.UnknowException, this));
         }
         else
         {
             var T = TypeConverters.GetMaxTypes(values.ToArray());
             if (T.Equals(typeof(char)))
             {
                 return(CallMathFunc <int>(values));
             }
             else if (T.Equals(typeof(int)))
             {
                 return(CallMathFunc <int>(values));
             }
             else if (T.Equals(typeof(float)))
             {
                 return(CallMathFunc <float>(values));
             }
             else
             {
                 return(CallMathFunc <double>(values));
             }
         }
     }catch (Exception e)
     {
         Console.WriteLine(e.Message);
         Console.WriteLine(e.StackTrace);
         return(Completion.Exception(e.Message, this));
     }
 }
示例#25
0
        public Completion Execute(ExecutionEnvironment enviroment)
        {
            if (Left == null || Right == null)
            {
                return(new Completion("Null Exception", CompletionType.Exception));
            }
            var left = Left.Execute(enviroment);

            if (left.Type != CompletionType.Value)
            {
                return(left);
            }
            var right = Right.Execute(enviroment);

            if (right.Type != CompletionType.Value)
            {
                return(right);
            }

            Type T = TypeConverters.GetNumberTypes(left.ReturnValue, right.ReturnValue);

            if (T == null)
            {
                return(Completion.Exception("Only nuber can accepted", this));
            }
            if (T.Equals(typeof(int)))
            {
                try
                {
                    var l = TypeConverters.GetValue <int>(left.ReturnValue);
                    var r = TypeConverters.GetValue <int>(right.ReturnValue);
                    switch (Operator)
                    {
                    case Operator.Great:
                        return(new Completion(l > r));

                    case Operator.GreatOrEqual:
                        return(new Completion(l >= r));

                    case Operator.Less:
                        return(new Completion(l < r));

                    case Operator.LessOrEqual:
                        return(new Completion(l <= r));

                    case Operator.Equal:
                        return(new Completion(l == r));
                    }
                    return(new Completion(l + r));
                }
                catch (Exception e)
                {
                    return(new Completion(e.Message, CompletionType.Exception));
                }
            }
            if (T.Equals(typeof(float)))
            {
                try
                {
                    var l = TypeConverters.GetValue <float>(left.ReturnValue);
                    var r = TypeConverters.GetValue <float>(right.ReturnValue);
                    switch (Operator)
                    {
                    case Operator.Great:
                        return(new Completion(l > r));

                    case Operator.GreatOrEqual:
                        return(new Completion(l >= r));

                    case Operator.Less:
                        return(new Completion(l < r));

                    case Operator.LessOrEqual:
                        return(new Completion(l <= r));

                    case Operator.Equal:
                        return(new Completion(l == r));
                    }
                    return(new Completion(l + r));
                }
                catch (Exception e)
                {
                    return(new Completion(e.Message, CompletionType.Exception));
                }
            }
            if (T.Equals(typeof(long)))
            {
                try
                {
                    var l = TypeConverters.GetValue <long>(left.ReturnValue);
                    var r = TypeConverters.GetValue <long>(right.ReturnValue);
                    switch (Operator)
                    {
                    case Operator.Great:
                        return(new Completion(l > r));

                    case Operator.GreatOrEqual:
                        return(new Completion(l >= r));

                    case Operator.Less:
                        return(new Completion(l < r));

                    case Operator.LessOrEqual:
                        return(new Completion(l <= r));

                    case Operator.Equal:
                        return(new Completion(l == r));
                    }
                    return(new Completion(l + r));
                }
                catch (Exception e)
                {
                    return(new Completion(e.Message, CompletionType.Exception));
                }
            }
            {
                try
                {
                    var l = TypeConverters.GetValue <double>(left.ReturnValue);
                    var r = TypeConverters.GetValue <double>(right.ReturnValue);
                    switch (Operator)
                    {
                    case Operator.Great:
                        return(new Completion(l > r));

                    case Operator.GreatOrEqual:
                        return(new Completion(l >= r));

                    case Operator.Less:
                        return(new Completion(l < r));

                    case Operator.LessOrEqual:
                        return(new Completion(l <= r));

                    case Operator.Equal:
                        return(new Completion(l == r));
                    }
                    return(new Completion(l + r));
                }
                catch (Exception e)
                {
                    return(new Completion(e.Message, CompletionType.Exception));
                }
            }
        }
示例#26
0
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            if (Expression == null)
            {
                return(Completion.Exception(Properties.Language.NullException, this));
            }
            var c = Expression.Execute(enviroment);

            if (c.Type != CompletionType.Value)
            {
                return(c);
            }
            if (!TypeConverters.IsNumber(c.ReturnValue))
            {
                return(Completion.Exception(Properties.Language.NotNumber, Expression));
            }
            Type t = c.ReturnValue.GetType();

            if (t.Equals(typeof(int)))
            {
                int v   = TypeConverters.GetValue <int>(c.ReturnValue);
                int old = v;
                if (Operator == UpdateOperator.Add)
                {
                    v += 1;
                }
                else
                {
                    v = v - 1;
                }
                if (Expression is Identifier)
                {
                    enviroment.SetValue(((Identifier)Expression).Variable, v);
                }
                return(new Completion(IsPrefix ? v : old));
            }
            else if (t.Equals(typeof(float)))
            {
                float v   = TypeConverters.GetValue <float>(c.ReturnValue);
                float old = v;
                if (Operator == UpdateOperator.Add)
                {
                    v += 1;
                }
                else
                {
                    v = v - 1;
                }
                if (Expression is Identifier)
                {
                    enviroment.SetValue(((Identifier)Expression).Variable, v);
                }
                return(new Completion(IsPrefix ? v : old));
            }
            else
            {
                double v   = TypeConverters.GetValue <double>(c.ReturnValue);
                double old = v;
                if (Operator == UpdateOperator.Add)
                {
                    v += 1;
                }
                else
                {
                    v = v - 1;
                }
                if (Expression is Identifier)
                {
                    enviroment.SetValue(((Identifier)Expression).Variable, v);
                }
                return(new Completion(IsPrefix ? v : old));
            }
        }
示例#27
0
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            if (Step == null)
            {
                return(Completion.Void);
            }
            double degree = 0;

            try
            {
                var c = Step.Execute(enviroment);
                if (c.Type != CompletionType.Value)
                {
                    return(c);
                }
                degree = TypeConverters.GetValue <double>(c.ReturnValue);
            }
            catch
            {
                return(Completion.Exception("Wrong number format", Step));
            }
            bool reflection = false;

            if (enviroment.HasValue("$$ReflectionOnTouchSide&&") && enviroment.GetValue <bool>("$$ReflectionOnTouchSide&&"))
            {
                reflection = true;
            }
            Sprite sp        = enviroment.GetValue("$$INSTANCE$$") as Sprite;
            int    x         = sp.X + (int)(Math.Cos(sp.Direction * Math.PI / 180) * degree);
            int    y         = sp.Y + (int)(Math.Sin(sp.Direction * Math.PI / 180) * degree);
            int    direction = sp.Direction;

            if (reflection)
            {
                while (x < 0)
                {
                    x         = -x;
                    direction = 180 - direction;
                }
                while (x > CurrentEnviroment.ScreenWidth)
                {
                    x         = CurrentEnviroment.ScreenWidth * 2 - x;
                    direction = 180 - direction;
                }
                while (y < 0)
                {
                    y         = -y;
                    direction = -direction;
                }
                while (y > CurrentEnviroment.ScreenHeight)
                {
                    y         = CurrentEnviroment.ScreenHeight * 2 - y;
                    direction = -direction;
                }
            }
            sp.X         = x;
            sp.Y         = y;
            sp.Direction = direction;
            App.Current.Dispatcher.InvokeAsync(new Action(() =>
            {
                (enviroment.GetValue("$$Player") as ScriptPlayer).DrawScript();
            }));
            return(Completion.Void);
        }
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            if (Right == null)
            {
                return(Completion.Exception(Properties.Language.NoValueAssigned, this));
            }
            var right = Right.Execute(enviroment);

            if (right.Type != CompletionType.Value)
            {
                return(right);
            }
            if (Left == null)
            {
                return(right);
            }
            if (Left is IAssignment)
            {
                try
                {
                    if (Operator == AssignmentOperator.Equal)
                    {
                        return((Left as IAssignment).Assign(enviroment, right.ReturnValue));
                    }
                    var l = Left.Execute(enviroment);
                    if (!l.IsValue)
                    {
                        return(l);
                    }
                    if (l.ReturnValue == null)
                    {
                        return(Completion.Exception(Properties.Language.VariableNullException, Left));
                    }
                    Type lt = l.ReturnValue.GetType();

                    if (l.ReturnValue is string || right.ReturnValue is string)
                    {
                        if (Operator != AssignmentOperator.AddEqual)
                        {
                            return(Completion.Exception(Properties.Language.StringOnlySupport, this));
                        }
                        return((Left as IAssignment).Assign(enviroment, l.ReturnValue + "" + right.ReturnValue));
                    }
                    if (!TypeConverters.IsNumber(l.ReturnValue))
                    {
                        return(Completion.Exception(Properties.Language.NotNumber, Left));
                    }
                    if (!TypeConverters.IsNumber(right.ReturnValue))
                    {
                        return(Completion.Exception(Properties.Language.NotNumber, Right));
                    }
                    Type maxType = TypeConverters.GetMaxTypes(l.ReturnValue, right.ReturnValue);
                    Console.Write(maxType);
                    if (maxType.Equals(typeof(char)))
                    {
                        var lint = TypeConverters.GetValue <char>(l.ReturnValue);
                        var rint = TypeConverters.GetValue <char>(right.ReturnValue);
                        if (Operator == AssignmentOperator.AddEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint + rint));
                        }
                        if (Operator == AssignmentOperator.MinusEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint - rint));
                        }
                        if (Operator == AssignmentOperator.MulitiplyEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint * rint));
                        }
                        if (Operator == AssignmentOperator.DivideEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint / rint));
                        }
                        if (Operator == AssignmentOperator.ModEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint % rint));
                        }
                        if (Operator == AssignmentOperator.BitAndEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint & rint));
                        }
                        if (Operator == AssignmentOperator.BitExclusiveOrEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint ^ rint));
                        }
                        if (Operator == AssignmentOperator.BitLeftShiftEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint << rint));
                        }
                        if (Operator == AssignmentOperator.BitOrEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint | rint));
                        }
                        if (Operator == AssignmentOperator.BitRightShiftEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint >> rint));
                        }
                        return(Completion.Exception(Properties.Language.UnknowException, this));
                    }
                    if (Operator == AssignmentOperator.BitAndEqual || Operator == AssignmentOperator.BitExclusiveOrEqual || Operator == AssignmentOperator.BitLeftShiftEqual ||
                        Operator == AssignmentOperator.BitOrEqual || Operator == AssignmentOperator.BitRightShiftEqual)
                    {
                        int lint = TypeConverters.GetValue <int>(l.ReturnValue);
                        int rint = TypeConverters.GetValue <int>(right.ReturnValue);
                        if (Operator == AssignmentOperator.BitAndEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint & rint));
                        }
                        if (Operator == AssignmentOperator.BitExclusiveOrEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint ^ rint));
                        }
                        if (Operator == AssignmentOperator.BitLeftShiftEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint << rint));
                        }
                        if (Operator == AssignmentOperator.BitOrEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint | rint));
                        }
                        if (Operator == AssignmentOperator.BitRightShiftEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint >> rint));
                        }
                        return(Completion.Exception(Properties.Language.UnknowException, this));
                    }
                    if (maxType.Equals(typeof(int)))
                    {
                        int lint = TypeConverters.GetValue <int>(l.ReturnValue);
                        int rint = TypeConverters.GetValue <int>(right.ReturnValue);
                        if (Operator == AssignmentOperator.AddEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint + rint));
                        }
                        if (Operator == AssignmentOperator.MinusEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint - rint));
                        }
                        if (Operator == AssignmentOperator.MulitiplyEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint * rint));
                        }
                        if (Operator == AssignmentOperator.DivideEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint / rint));
                        }
                        if (Operator == AssignmentOperator.ModEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint % rint));
                        }
                        return(Completion.Exception(Properties.Language.UnknowException, this));
                    }
                    else if (maxType.Equals(typeof(float)))
                    {
                        float lint = TypeConverters.GetValue <float>(l.ReturnValue);
                        float rint = TypeConverters.GetValue <int>(right.ReturnValue);
                        if (Operator == AssignmentOperator.AddEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint + rint));
                        }
                        if (Operator == AssignmentOperator.MinusEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint - rint));
                        }
                        if (Operator == AssignmentOperator.MulitiplyEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint * rint));
                        }
                        if (Operator == AssignmentOperator.DivideEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint / rint));
                        }
                        if (Operator == AssignmentOperator.ModEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint % rint));
                        }
                        return(Completion.Exception(Properties.Language.UnknowException, this));
                    }
                    else
                    {
                        double lint = TypeConverters.GetValue <double>(l.ReturnValue);
                        double rint = TypeConverters.GetValue <double>(right.ReturnValue);
                        if (Operator == AssignmentOperator.AddEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint + rint));
                        }
                        if (Operator == AssignmentOperator.MinusEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint - rint));
                        }
                        if (Operator == AssignmentOperator.MulitiplyEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint * rint));
                        }
                        if (Operator == AssignmentOperator.DivideEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint / rint));
                        }
                        if (Operator == AssignmentOperator.ModEqual)
                        {
                            return((Left as IAssignment).Assign(enviroment, lint % rint));
                        }
                        return(Completion.Exception(Properties.Language.UnknowException, this));
                    }
                }catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    return(Completion.Exception(e.Message, this));
                }
            }
            else
            {
                return(Completion.Exception(Properties.Language.InvalidBeforeEqual, Left));
            }
        }
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            DateTime startTime;
            DateTime finishTime;
            double   orgin_x;
            double   orgin_y;
            double   totalTime;

            if (X == null)
            {
                return(Completion.Void);
            }
            double x = 0;

            try
            {
                var c = X.Execute(enviroment);
                if (c.Type != CompletionType.Value)
                {
                    return(c);
                }
                x = TypeConverters.GetValue <double>(c.ReturnValue);
            }
            catch
            {
                return(Completion.Exception("Wrong number format", X));
            }
            if (Y == null)
            {
                return(Completion.Void);
            }
            double y = 0;

            try
            {
                var c = Y.Execute(enviroment);
                if (c.Type != CompletionType.Value)
                {
                    return(c);
                }
                y = TypeConverters.GetValue <double>(c.ReturnValue);
            }
            catch
            {
                return(Completion.Exception("Wrong number format", Y));
            }
            if (Time == null)
            {
                return(Completion.Void);
            }
            double time = 0;

            try
            {
                var c = Time.Execute(enviroment);
                if (c.Type != CompletionType.Value)
                {
                    return(c);
                }
                time = TypeConverters.GetValue <double>(c.ReturnValue);
            }
            catch
            {
                return(Completion.Exception("Wrong number format", Time));
            }

            Sprite sp = enviroment.GetValue("$$INSTANCE$$") as Sprite;

            if (x < 0)
            {
                x = 0;
            }
            if (x > CurrentEnviroment.ScreenWidth)
            {
                x = CurrentEnviroment.ScreenWidth;
            }
            if (y < 0)
            {
                y = 0;
            }
            if (y > CurrentEnviroment.ScreenHeight)
            {
                y = CurrentEnviroment.ScreenHeight;
            }
            orgin_x    = sp.X;
            orgin_y    = sp.Y;
            startTime  = DateTime.Now;
            finishTime = DateTime.Now.AddSeconds(time);
            totalTime  = (finishTime - startTime).TotalMilliseconds;

            while (true)
            {
                if (DateTime.Now > finishTime)
                {
                    break;
                }
                double duration = (DateTime.Now - startTime).TotalMilliseconds;

                sp.X = (int)(orgin_x + (x - orgin_x) * duration / totalTime);
                sp.Y = (int)(orgin_y + (y - orgin_y) * duration / totalTime);
                App.Current.Dispatcher.InvokeAsync(new Action(() =>
                {
                    (enviroment.GetValue("$$Player") as ScriptPlayer).DrawScript();
                }));
                Thread.Sleep(100);
            }

            sp.X = (int)x;
            sp.Y = (int)y;
            App.Current.Dispatcher.InvokeAsync(new Action(() =>
            {
                (enviroment.GetValue("$$Player") as ScriptPlayer).DrawScript();
            }));
            return(Completion.Void);
        }