Example #1
0
        public bool IsMath(string s)
        {
            switch (s)
            {
            case "==":
                mathType = BurikoMathType.Equals;
                return(true);

            case "!=":
                mathType = BurikoMathType.NotEquals;
                return(true);

            case "<=":
                mathType = BurikoMathType.LessThanOrEquals;
                return(true);

            case ">=":
                mathType = BurikoMathType.GreaterThanOrEquals;
                return(true);

            case ">":
                mathType = BurikoMathType.GreaterThan;
                return(true);

            case "<":
                mathType = BurikoMathType.LessThan;
                return(true);

            case "+":
                mathType = BurikoMathType.Add;
                return(true);

            case "-":
                mathType = BurikoMathType.Subtract;
                return(true);

            case "*":
                mathType = BurikoMathType.Multiply;
                return(true);

            case "/":
                mathType = BurikoMathType.Divide;
                return(true);

            case "%":
                mathType = BurikoMathType.Modulus;
                return(true);

            default:
                return(false);
            }
        }
        private static int PerformMath(BurikoMathType type, BurikoVariable a, BurikoVariable b)
        {
            int num  = a.IntValue();
            int num2 = b.IntValue();

            switch (type)
            {
            case BurikoMathType.Equals:
                return((num == num2) ? 1 : 0);

            case BurikoMathType.Add:
                return(num + num2);

            case BurikoMathType.Divide:
                return(num / num2);

            case BurikoMathType.Multiply:
                return(num * num2);

            case BurikoMathType.Subtract:
                return(num - num2);

            case BurikoMathType.GreaterThan:
                return((num > num2) ? 1 : 0);

            case BurikoMathType.GreaterThanOrEquals:
                return((num >= num2) ? 1 : 0);

            case BurikoMathType.LessThan:
                return((num < num2) ? 1 : 0);

            case BurikoMathType.LessThanOrEquals:
                return((num <= num2) ? 1 : 0);

            case BurikoMathType.Modulus:
                return(num % num2);

            case BurikoMathType.NotEquals:
                return((num != num2) ? 1 : 0);

            case BurikoMathType.And:
                return((num != 0 && num2 != 0) ? 1 : 0);

            case BurikoMathType.Or:
                return((num != 0 || num2 != 0) ? 1 : 0);

            default:
                throw new Exception("Cannot find a handler for math type " + type);
            }
        }
        public BurikoVariable(BinaryReader stream)
        {
            Type = (BurikoValueType)stream.ReadInt16();
            switch (Type)
            {
            case BurikoValueType.Null:
                valueInt = -1;
                break;

            case BurikoValueType.Bool:
                valueInt = stream.ReadByte();
                break;

            case BurikoValueType.Int:
                valueInt = stream.ReadInt32();
                break;

            case BurikoValueType.String:
                valueString = stream.ReadString();
                break;

            case BurikoValueType.Variable:
                stream.BaseStream.Seek(-2L, SeekOrigin.Current);
                valueReference = ReadReference(stream);
                break;

            case BurikoValueType.Math:
            {
                BurikoMathType type = (BurikoMathType)stream.ReadInt16();
                BurikoVariable a    = new BurikoVariable(stream);
                BurikoVariable b    = new BurikoVariable(stream);
                Type     = BurikoValueType.Int;
                valueInt = PerformMath(type, a, b);
                break;
            }

            case BurikoValueType.Operation:
                valueVariable = BurikoScriptSystem.Instance.GetCurrentScript().ExecuteOperation((BurikoOperations)stream.ReadInt16());
                break;

            default:
                throw new NotImplementedException("BurikoVariable: Unhandled BurikoValueType " + Type);
            }
        }