Exemple #1
0
 //ルームに入室時の処理
 public override void OnJoinedRoom()
 {
     //プレイヤーローカル変数初期化
     LocalVariables.VariableReset();
 }
Exemple #2
0
        /* UNDER THE HOOD - THE CORE OF THE PARSER */

        private decimal Scanner(string _expr)
        {
            // SCANNING THE INPUT STRING AND CONVERT IT INTO TOKENS

            var    _tokens = new List <string>();
            string _vector = "";

            //_expr = _expr.Replace(" ", ""); // remove white space
            _expr = _expr.Replace("+-", "-"); // some basic arithmetical rules
            _expr = _expr.Replace("-+", "-");
            _expr = _expr.Replace("--", "+");

            _expr = LocalVariables.Aggregate(_expr,
                                             (current, item) =>
                                             current.Replace(item.Key, "(" + item.Value.ToString(CULTURE_INFO) + ")"));

            for (int i = 0; i < _expr.Length; i++)
            {
                char ch = _expr[i];

                if (char.IsWhiteSpace(ch))
                {
                } // could also be used to remove white spaces.
                else if (Char.IsLetter(ch))
                {
                    if (i != 0 && (Char.IsDigit(_expr[i - 1]) || Char.IsDigit(_expr[i - 1]) || _expr[i - 1] == ')'))
                    {
                        _tokens.Add("*");
                    }

                    _vector = _vector + ch;
                    while ((i + 1) < _expr.Length && Char.IsLetter(_expr[i + 1]))
                    {
                        i++;
                        _vector = _vector + _expr[i];
                    }
                    if (_vector != null)
                    {
                        _tokens.Add(_vector);
                        _vector = "";
                    }
                }
                else if (Char.IsDigit(ch))
                {
                    _vector = _vector + ch;
                    while ((i + 1) < _expr.Length && (Char.IsDigit(_expr[i + 1]) || _expr[i + 1] == '.'))
                    // removed || _expr[i + 1] == ','
                    {
                        i++;
                        _vector = _vector + _expr[i];
                    }
                    if (_vector != null)
                    {
                        _tokens.Add(_vector);
                        _vector = "";
                    }
                }
                else if ((i + 1) < _expr.Length && (ch == '-' || ch == '+') && Char.IsDigit(_expr[i + 1]) &&
                         (i == 0 || OperatorList.IndexOf(_expr[i - 1].ToString()) != -1 ||
                          ((i - 1) > 0 && _expr[i - 1] == '(')))
                {
                    // if the above is true, then, the token for that negative number will be "-1", not "-","1".
                    // to sum up, the above will be true if the minus sign is in front of the number, but
                    // at the beginning, for example, -1+2, or, when it is inside the brakets (-1).
                    // NOTE: this works for + sign as well!
                    _vector = _vector + ch;
                    while ((i + 1) < _expr.Length && (Char.IsDigit(_expr[i + 1]) || _expr[i + 1] == '.'))
                    // removed || _expr[i + 1] == ','
                    {
                        i++;
                        _vector = _vector + _expr[i];
                    }
                    if (_vector != null)
                    {
                        _tokens.Add(_vector);
                        _vector = "";
                    }
                }
                else if (ch == '(')
                {
                    if (i != 0 && (Char.IsDigit(_expr[i - 1]) || Char.IsDigit(_expr[i - 1]) || _expr[i - 1] == ')'))
                    {
                        _tokens.Add("*");
                        _tokens.Add("(");
                    }
                    else
                    {
                        _tokens.Add("(");
                    }
                }
                else
                {
                    _tokens.Add(ch.ToString());
                }
            }

            return(MathParserLogic(_tokens));
        }
    private void BindFunctions()
    {
        inkStory.BindExternalFunction("getValue", (int a) =>
        {
            GVar var = GlobalVariables.GetVariable(a);

            if (var == null)
            {
                return("no var");
            }

            switch (var.type)
            {
            case VariableType.Boolean:
                return(var.BooleanValue);

            case VariableType.Integer:
                return(var.IntegerValue);

            case VariableType.String:
                return(var.textVal);

            case VariableType.Float:
                return(var.floatVal);
            }
            return("no var");
        });

        inkStory.BindExternalFunction("getLocalValue", (int a) =>
        {
            GVar var = LocalVariables.GetVariable(a);

            if (var == null)
            {
                return("no var");
            }

            switch (var.type)
            {
            case VariableType.Boolean:
                return(var.BooleanValue);

            case VariableType.Integer:
                return(var.IntegerValue);

            case VariableType.String:
                return(var.textVal);

            case VariableType.Float:
                return(var.floatVal);
            }
            return("no var");
        });

        inkStory.BindExternalFunction("inventoryContains", (string item) =>
        {
            foreach (InvItem invItem in KickStarter.runtimeInventory.localItems)
            {
                if (invItem.GetLabel(0).Trim().ToLower() == item.Trim().ToLower())
                {
                    return(true);
                }
            }
            return(false);
        });
    }
Exemple #4
0
 public virtual void UndefineTemps(InstructionList instructions, LocalVariables locals)
 {
     // Empty
 }
        /// <summary>
        /// Enter the math expression in form of a string. You might also add/edit variables using "let" keyword.
        /// For example, "let sampleVariable = 2+2".
        ///
        /// Another way of adding/editing a variable is to type "varName := 20"
        ///
        /// Last way of adding/editing a variable is to type "let varName be 20"
        /// </summary>
        /// <param name="mathExpression"></param>
        /// <param name="correctExpression"></param>
        /// <param name="identifyComments"></param>
        /// <returns></returns>
        public decimal ProgrammaticallyParse(string mathExpression, bool correctExpression = true, bool identifyComments = true)
        {
            if (identifyComments)
            {
                mathExpression = System.Text.RegularExpressions.Regex.Replace(mathExpression, "#\\{.*?\\}#", ""); // Delete Comments #{Comment}#
                mathExpression = System.Text.RegularExpressions.Regex.Replace(mathExpression, "#.*$", "");        // Delete Comments #Comment
            }

            if (correctExpression)
            {
                mathExpression = Correction(mathExpression);
            }
            // this refers to the Correction function which will correct stuff like artn to arctan, etc.

            string  varName;
            decimal varValue;

            if (mathExpression.Contains("let"))
            {
                if (mathExpression.Contains("be"))
                {
                    varName        = mathExpression.Substring(mathExpression.IndexOf("let", StringComparison.Ordinal) + 3, mathExpression.IndexOf("be", StringComparison.Ordinal) - mathExpression.IndexOf("let", StringComparison.Ordinal) - 3);
                    mathExpression = mathExpression.Replace(varName + "be", "");
                }
                else
                {
                    varName        = mathExpression.Substring(mathExpression.IndexOf("let", StringComparison.Ordinal) + 3, mathExpression.IndexOf("=", StringComparison.Ordinal) - mathExpression.IndexOf("let", StringComparison.Ordinal) - 3);
                    mathExpression = mathExpression.Replace(varName + "=", "");
                }

                varName        = varName.Replace(" ", "");
                mathExpression = mathExpression.Replace("let", "");

                varValue = Parse(mathExpression);

                if (LocalVariables.ContainsKey(varName))
                {
                    LocalVariables[varName] = varValue;
                }
                else
                {
                    LocalVariables.Add(varName, varValue);
                }

                return(varValue);
            }

            if (!mathExpression.Contains(":="))
            {
                return(Parse(mathExpression));
            }

            //mathExpression = mathExpression.Replace(" ", ""); // remove white space
            varName        = mathExpression.Substring(0, mathExpression.IndexOf(":=", StringComparison.Ordinal));
            mathExpression = mathExpression.Replace(varName + ":=", "");

            varValue = Parse(mathExpression);
            varName  = varName.Replace(" ", "");

            if (LocalVariables.ContainsKey(varName))
            {
                LocalVariables[varName] = varValue;
            }
            else
            {
                LocalVariables.Add(varName, varValue);
            }

            return(varValue);
        }
Exemple #6
0
        private void MathParserLogic(List <string> tokens)
        {
            // CALCULATING THE EXPRESSIONS INSIDE THE BRACKETS
            // IF NEEDED, EXECUTE A FUNCTION

            // Variables replacement
            for (var i = 0; i < tokens.Count; i++)
            {
                if (LocalVariables.Contains(tokens[i]))
                {
                    tokens[i] = "ldarg." + LocalVariables.IndexOf(tokens[i]);//LocalVariables[tokens[i]].ToString(CultureInfo);
                }
            }
            while (tokens.IndexOf("(") != -1)
            {
                // getting data between "(", ")"
                var open  = tokens.LastIndexOf("(");
                var close = tokens.IndexOf(")", open); // in case open is -1, i.e. no "(" // , open == 0 ? 0 : open - 1

                if (open >= close)
                {
                    // if there is no closing bracket, throw a new exception
                    throw new ArithmeticException("No closing bracket/parenthesis! tkn: " + open.ToString(CultureInfo.InvariantCulture));
                }

                var roughExpr = new List <string>();

                for (var i = open + 1; i < close; i++)
                {
                    roughExpr.Add(tokens[i]);
                }

                string result = ""; // the temporary result is stored here

                var functioName = tokens[open == 0 ? 0 : open - 1];
                var args        = new decimal[0];

                if (LocalFunctions.Keys.Contains(functioName))
                {
                    //if (roughExpr.Contains(","))
                    //{
                    //    // converting all arguments into a decimal array
                    //    for (var i = 0; i < roughExpr.Count; i++)
                    //    {
                    //        var firstCommaOrEndOfExpression = roughExpr.IndexOf(",", i) != -1 ? roughExpr.IndexOf(",", i) : roughExpr.Count;
                    //        var defaultExpr = new List<string>();

                    //        while (i < firstCommaOrEndOfExpression)
                    //        {
                    //            defaultExpr.Add(roughExpr[i]);
                    //            i++;
                    //        }

                    //        // changing the size of the array of arguments
                    //        Array.Resize(ref args, args.Length + 1);

                    //        if (defaultExpr.Count == 0)
                    //        {
                    //            args[args.Length - 1] = 0;
                    //        }
                    //        else
                    //        {
                    //            //args[args.Length - 1] = BasicArithmeticalExpression(defaultExpr);
                    //        }
                    //    }

                    //    // finnaly, passing the arguments to the given function
                    //    result = decimal.Parse(LocalFunctions[functioName](args).ToString(CultureInfo), CultureInfo);
                    //}
                    //else
                    //{
                    //    // but if we only have one argument, then we pass it directly to the function
                    //    //result = decimal.Parse(LocalFunctions[functioName](new[] { BasicArithmeticalExpression(roughExpr) }).ToString(CultureInfo), CultureInfo);
                    //}
                }
                else
                {
                    // if no function is need to execute following expression, pass it
                    // to the "BasicArithmeticalExpression" method.
                    result = BasicArithmeticalExpression(roughExpr);
                }

                // when all the calculations have been done
                // we replace the "opening bracket with the result"
                // and removing the rest.
                tokens[open] = result;
                tokens.RemoveRange(open + 1, close - open);
                if (LocalFunctions.Keys.Contains(functioName))
                {
                    // if we also executed a function, removing
                    // the function name as well.
                    tokens.RemoveAt(open - 1);
                }
            }

            // at this point, we should have replaced all brackets
            // with the appropriate values, so we can simply
            // calculate the expression. it's not so complex
            // any more!
            BasicArithmeticalExpression(tokens);
            //return BasicArithmeticalExpression(tokens);
        }
        public override void ReadBinary(ESPReader reader)
        {
            List <string> readTags = new List <string>();

            while (reader.BaseStream.Position < reader.BaseStream.Length)
            {
                string subTag = reader.PeekTag();

                switch (subTag)
                {
                case "SCHR":
                    if (readTags.Contains("SCHR"))
                    {
                        return;
                    }
                    Data.ReadBinary(reader);
                    break;

                case "SCDA":
                    if (readTags.Contains("SCDA"))
                    {
                        return;
                    }
                    if (CompiledScript == null)
                    {
                        CompiledScript = new SimpleSubrecord <Byte[]>();
                    }

                    CompiledScript.ReadBinary(reader);
                    break;

                case "SCTX":
                    if (readTags.Contains("SCTX"))
                    {
                        return;
                    }
                    if (ScriptSource == null)
                    {
                        ScriptSource = new SimpleSubrecord <Char[]>();
                    }

                    ScriptSource.ReadBinary(reader);
                    break;

                case "SLSD":
                    if (LocalVariables == null)
                    {
                        LocalVariables = new List <LocalVariable>();
                    }

                    LocalVariable tempSLSD = new LocalVariable();
                    tempSLSD.ReadBinary(reader);
                    LocalVariables.Add(tempSLSD);
                    break;

                case "DUMY":
                    ReadReferences(reader);
                    break;

                case "SCRV":
                    ReadLocalReference(reader);
                    break;

                case "SCRO":
                    ReadGlobalReference(reader);
                    break;

                default:
                    return;
                }

                readTags.Add(subTag);
            }
        }
Exemple #8
0
 public virtual Value Execute(ExecutionContext vm, LocalVariables lv) => Value.Empty;
Exemple #9
0
 // システム関数は常に実行可能
 public bool IsExecutable(ExecutionContext vm, LocalVariables lv) => true;
Exemple #10
0
 /// <summary cref="IEnumerator.Reset"/>
 public void Reset()
 {
     enumerator = LocalVariables.GetEnumerator();
 }
        /*private void CheckTypes()
         * {
         *  foreach (var v in varRPC.variables.references)
         *  {
         *      Variable.DataType varType = (Variable.DataType)v.variable.type;
         *      if (varType == Variable.DataType.Null ||
         *      varType == Variable.DataType.GameObject ||
         *      varType == Variable.DataType.Sprite ||
         *      varType == Variable.DataType.Texture2D)
         *      {
         *          hasForbiddenTypes = true;
         *      }
         *      else
         *      {
         *          hasForbiddenTypes = false;
         *      }
         *  }
         * }*/

        public override void OnInspectorGUI()
        {
            if (serializedObject == null)
            {
                return;
            }

            base.OnInspectorGUI();
            localVars = target as LocalVariables;

            if (localVars.transform.root.gameObject.GetComponent <NetworkItem>())
            {
                return;
            }

            if (this.section == null)
            {
                this.section = new Section("Network Settings", "ActionNetwork.png", this.Repaint);
            }

            if (!initialized)
            {
                network = localVars.transform.root.gameObject.GetComponent <LocalVariablesNetwork>();

                //if(actionsNetwork != null) actionsRPC = ArrayUtility.Find(actionsNetwork.actions, p => p.actions == actions);
                if (network != null)
                {
                    serializedNetwork = new SerializedObject(network);
                    varRPC            = network.localVars.Find(p => p.variables == localVars);
                    index             = network.localVars.IndexOf(varRPC);
                }
                hasComponent = varRPC != null;
                initialized  = true;
                //CheckTypes();
            }

            bool hasChanged = false;

            this.section.PaintSection();
            using (var group = new EditorGUILayout.FadeGroupScope(this.section.state.faded))
            {
                if (group.visible)
                {
                    EditorGUILayout.BeginVertical(CoreGUIStyles.GetBoxExpanded());

                    EditorGUI.BeginChangeCheck();
                    hasComponent = EditorGUILayout.Toggle(GUI_SYNC, hasComponent);
                    hasChanged   = EditorGUI.EndChangeCheck();

                    if (varRPC != null)
                    {
                        /*if (hasChanged)
                         * {
                         *  CheckTypes();
                         * }
                         * if (hasForbiddenTypes)
                         * {*/
                        EditorGUILayout.HelpBox(GUI_FORBID_TYPES, MessageType.Info);
                        //}
                    }
                    EditorGUILayout.EndVertical();
                }
            }

            if (hasChanged)
            {
                if (varRPC != null && network)
                {
                    Debug.Log("Removed LocalVariables");
                    network.localVars.Remove(varRPC);
                    if (network.localVars.Count == 0)
                    {
                        PhotonView pv = network.photonView;

                        DestroyImmediate(network, true);

                        /*if (!pv.GetComponent<CharacterNetwork>() ||
                         *  !pv.GetComponent<StatsNetwork>() ||
                         *  !pv.GetComponent<ActionsNetwork>())
                         * {
                         *  DestroyImmediate(pv, true);
                         * }*/
                    }

                    varRPC  = null;
                    network = null;

                    initialized = false;
                }
                else
                {
                    network = localVars.transform.root.gameObject.GetComponent <LocalVariablesNetwork>() ?? localVars.transform.root.gameObject.AddComponent <LocalVariablesNetwork>();

                    SerializedObject serializedObject = new UnityEditor.SerializedObject(network);

                    varRPC = new LocalVariablesNetwork.VarRPC()
                    {
                        variables = localVars
                    };
                    network.localVars.Add(varRPC);

                    Debug.LogFormat("Added LocalVariables: {0}", varRPC.variables.gameObject.name);

                    serializedObject.ApplyModifiedProperties();
                    serializedObject.Update();

                    hasComponent = true;
                }
                hasChanged = false;
            }
            EditorGUILayout.Space();
        }
Exemple #12
0
 public Variable this[string name]
 {
     get { return(LocalVariables.FirstOrDefault(x => x.Name == name)); }
 }
Exemple #13
0
    public void StartSetting()
    {
        if (photonView.isMine)//thisオブジェクトが自分自身が生成したものだったら
        {
            //初動で選択されたキャラのIDによってパラメータを変える必要あり
            playerLocalVariables = this.gameObject.GetComponent <LocalVariables>();
            runSE                 = this.gameObject.transform.GetComponentInChildren <CriAtomSource>();
            BGM                   = GameObject.Find("Ray01(CriAtomSource)").GetComponent <CriAtomSource>();
            rigidbody             = this.gameObject.GetComponent <Rigidbody>();
            rigidbody.constraints = RigidbodyConstraints.FreezeAll;
            usePosition           = ImageSkillParent.transform.localPosition;
            standbyPosition       = ImageItemParent.transform.localPosition;
            useScale.x            = 1;
            useScale.y            = 1;
            standbyScale.x        = 0.6f;
            standbyScale.y        = 0.6f;

            runSpeed = 1;
#if UNITY_ANDROID
            senci = 5;
#endif

            IP = this.gameObject.GetComponent <Chara>();
            //gameState = GameState.idle;
            Cursor.visible       = false;
            Cursor.lockState     = CursorLockMode.Locked;
            canvasUI.enabled     = true;
            Hip.enabled          = true;
            audioListner.enabled = true;
            //fpc = FPSController.GetComponent<FirstPersonController>();
            //fpc.m_RunSpeed = 10;
            force         = 5000;
            fireRate      = 0.3f;
            coolDownSkill = new float[] { 1.0f, 1.5f, 2.0f, 3.0f };
            coolDownItem  = new float[] { 0, 0, 0, 0, 0 };
            skillIsActive = new bool[] { false, false, false, false };
            itemIsActive  = new bool[] { false, false, false, false, false };
            for (int index = 0; index < item.Length; index++)
            {
                item[index].GetComponent <Image>().enabled  = false;
                items[index].GetComponent <Image>().enabled = false;
            }
            equipmentRefferrence = new string[] { "Weapon1" };
            selectStateCount     = 0;
            cameraState          = CameraState.Hip;
            skillTime            = new float[] { 0, 0, 0, 0 };
            itemTime             = new float[] { 0, 0, 0, 0, 0 };
            skillUseCount        = new int[4] {
                0, 0, 0, 0
            };
            skillUseCountToLevelUp = new int[4] {
                5, 3, 2, 1
            };
            skillLevel = new int[4] {
                1, 1, 1, 1
            };
            //firstBullet = false;
            isShooted    = false;
            cameraCenter = new Vector3(Screen.width / 2, Screen.height / 2);

            //--------------------------ここからHpとMana初期化------------------------------//

            initHpMax   = 100;
            initManaMax = 100;
            playerLocalVariables.MaxHp   = initHpMax;
            playerLocalVariables.ManaMax = initManaMax;
            playerLocalVariables.Hp      = (int)initHpMax;
            playerLocalVariables.Mana    = (int)initManaMax;

            //-------------------------ここまでHpとMana初期化-------------------------------//

            championID   = 0;
            havingItemID = new int[4] {
                0, 0, 0, 0
            };
            //havingItemCount = new int[4] { 0, 0, 0, 0 };
            manaToUseSkill = new float[4] {
                20, 15, 30, 80
            };
            //playerLocalVariables.Hp = hpMax;
            //mana = manaMax;
            manaRecoverCount = 0;
            //money = 100;
            startCount = 3;
            skillMode  = true;

            for (int a = 0; a < 7; a++)
            {
                //装備のIDを格納
                equipmentId[a] = 0;
            }
            //Listに変換
            //equipmentList.AddRange(equipmentId);
            explainerBoard.SetActive(false);
            isPoson             = false;
            isStun              = false;
            isSlow              = false;
            isHealig            = false;
            isShooting          = false;
            timePoison          = 10f;
            isPoisonDamagedTime = 1f;
            timeSlow            = 10f;
            timeStun            = 10f;
            recoil              = 10;
            networkManager      = GameObject.Find("NetworkManager").GetComponent <NetworkManager>();
            BGM.Play();
            isShooted   = false;
            shopManager = GameObject.Find("ShopManager").GetComponent <ShopManager>();
            shopManager.p_localVariables = this.gameObject.GetComponent <LocalVariables>();
            shopManager.chara            = this;
            //StartCoroutine(Shot(fireRate));

            //--------------------------ここからキャラステ初期化--------------------------//

            playerLocalVariables.Level                 = 1;
            playerLocalVariables.PhysicalOffence       = 5;
            playerLocalVariables.MagicalOffence        = 1;
            playerLocalVariables.PhysicalDefence       = 1;
            playerLocalVariables.MagicalDefence        = 1;
            playerLocalVariables.AutomaticManaRecovery = 3;
            playerLocalVariables.AutomaticHpRecovery   = 3;
            initMoveSpeed = 10;
            playerLocalVariables.MoveSpeed    = initMoveSpeed;
            Status_PhysicalAttack.fillAmount  = playerLocalVariables.PhysicalOffence * 0.1f;
            Status_SpecialAttack.fillAmount   = playerLocalVariables.MagicalOffence * 0.1f;
            Status_PhysicalDefence.fillAmount = playerLocalVariables.PhysicalDefence * 0.1f;
            Status_SpecialDefence.fillAmount  = playerLocalVariables.MagicalDefence * 0.1f;
            Status_Speed.fillAmount           = playerLocalVariables.MoveSpeed * 0.01f;
            LevelText.text           = "Lv." + playerLocalVariables.Level;
            manaAutoRecoveryinterval = 5;
            hpAutoRecoveryinterval   = 5;

            //---------------------------キャラステ初期化ここまで----------------------------//

            photonView.RPC("LevelUp", PhotonTargets.MasterClient, playerLocalVariables.Level, this.gameObject.GetPhotonView().ownerId,
                           playerLocalVariables.MaxHp, playerLocalVariables.PhysicalOffence, playerLocalVariables.PhysicalDefence,
                           playerLocalVariables.MagicalOffence, playerLocalVariables.MagicalDefence, playerLocalVariables.MoveSpeed);
            networkManager.photonView.RPC("RecieveChangedHP", PhotonTargets.MasterClient, this.gameObject.GetPhotonView().ownerId, playerLocalVariables.Hp);
        }
    }
Exemple #14
0
 public AMember this[string name]
 => Properties.FirstOrDefault(x => x.Key == name).Value ??
 Fields.FirstOrDefault(x => x.Key == name).Value ??
 Methods.FirstOrDefault(x => x.Key == name).Value ??
 LocalVariables.FirstOrDefault(x => x.Key == name).Value as AMember;
Exemple #15
0
            /// <summary>
            /// This constructor will add some basic operators, functions, and variables
            /// to the parser. Please note that you are able to change that using
            /// boolean flags
            /// </summary>
            /// <param name="loadPreDefinedFunctions">This will load "abs", "cos", "cosh", "arccos", "sin", "sinh", "arcsin", "tan", "tanh", "arctan", "sqrt", "rem", "round"</param>
            /// <param name="loadPreDefinedOperators">This will load "%", "*", ":", "/", "+", "-", ">", "&lt;", "="</param>
            /// <param name="loadPreDefinedVariables">This will load "pi"</param>
            public MathParser(bool loadPreDefinedFunctions = true, bool loadPreDefinedOperators = true, bool loadPreDefinedVariables = true)
            {
                if (loadPreDefinedOperators)
                {
                    // by default, we will load basic arithmetic operators.
                    // please note, its possible to do it either inside the constructor,
                    // or outside the class. the lowest value will be executed first!
                    OperatorList.Add("%"); // modulo
                    OperatorList.Add("^"); // to the power of
                    OperatorList.Add(":"); // division 1
                    OperatorList.Add("/"); // division 2
                    OperatorList.Add("*"); // multiplication
                    OperatorList.Add("-"); // subtraction
                    OperatorList.Add("+"); // addition

                    OperatorList.Add(">"); // greater than
                    OperatorList.Add("<"); // less than
                    OperatorList.Add("="); // are equal


                    // when an operator is executed, the parser needs to know how.
                    // this is how you can add your own operators. note, the order
                    // in this list does not matter.
                    _operatorAction.Add("%", (numberA, numberB) => numberA % numberB);
                    _operatorAction.Add("^", (numberA, numberB) => (decimal)Math.Pow((double)numberA, (double)numberB));
                    _operatorAction.Add(":", (numberA, numberB) => numberA / numberB);
                    _operatorAction.Add("/", (numberA, numberB) => numberA / numberB);
                    _operatorAction.Add("*", (numberA, numberB) => numberA * numberB);
                    _operatorAction.Add("+", (numberA, numberB) => numberA + numberB);
                    _operatorAction.Add("-", (numberA, numberB) => numberA - numberB);

                    _operatorAction.Add(">", (numberA, numberB) => numberA > numberB ? 1 : 0);
                    _operatorAction.Add("<", (numberA, numberB) => numberA < numberB ? 1 : 0);
                    _operatorAction.Add("=", (numberA, numberB) => numberA == numberB ? 1 : 0);
                }


                if (loadPreDefinedFunctions)
                {
                    // these are the basic functions you might be able to use.
                    // as with operators, localFunctions might be adjusted, i.e.
                    // you can add or remove a function.
                    // please open the "MathosTest" project, and find MathParser.cs
                    // in "CustomFunction" you will see three ways of adding
                    // a new function to this variable!
                    // EACH FUNCTION MAY ONLY TAKE ONE PARAMETER, AND RETURN ONE
                    // VALUE. THESE VALUES SHOULD BE IN "DECIMAL FORMAT"!
                    LocalFunctions.Add("abs", x => (decimal)Math.Abs((double)x[0]));

                    LocalFunctions.Add("cos", x => (decimal)Math.Cos((double)x[0]));
                    LocalFunctions.Add("cosh", x => (decimal)Math.Cosh((double)x[0]));
                    LocalFunctions.Add("arccos", x => (decimal)Math.Acos((double)x[0]));

                    LocalFunctions.Add("sin", x => (decimal)Math.Sin((double)x[0]));
                    LocalFunctions.Add("sinh", x => (decimal)Math.Sinh((double)x[0]));
                    LocalFunctions.Add("arcsin", x => (decimal)Math.Asin((double)x[0]));

                    LocalFunctions.Add("tan", x => (decimal)Math.Tan((double)x[0]));
                    LocalFunctions.Add("tanh", x => (decimal)Math.Tanh((double)x[0]));
                    LocalFunctions.Add("arctan", x => (decimal)Math.Atan((double)x[0]));

                    LocalFunctions.Add("sqrt", x => (decimal)Math.Sqrt((double)x[0]));
                    LocalFunctions.Add("rem", x => (decimal)Math.IEEERemainder((double)x[0], (double)x[1]));
                    LocalFunctions.Add("round", x => (decimal)Math.Round((double)x[0]));
                    LocalFunctions.Add("pow", x => (decimal)Math.Pow((double)x[0], (double)x[1]));
                }

                if (loadPreDefinedVariables)
                {
                    // local variables such as pi can also be added into the parser.
                    LocalVariables.Add("pi", (decimal)Math.PI); // the simplest variable!
                }
            }
Exemple #16
0
 public override Value Execute(ExecutionContext vm, LocalVariables lv)
 {
     return(base.Execute(vm, lv));
 }
 public override void UndefineTemps(InstructionList instructions, LocalVariables locals)
 {
     locals.UndefineLocal(_array, instructions.Count);
     locals.UndefineLocal(_index, instructions.Count);
 }
Exemple #18
0
 public override Value Execute(ExecutionContext vm, LocalVariables lv)
 {
     // 変数のシリアライズ
     vm.Variables.Serialize(Path.Combine(vm.RootDirectory, "imouto_vars.txt"));
     return(Value.Empty);
 }
Exemple #19
0
 public void ZapiszLokalnaZmienna(object o, int indeks)
 {
     LocalVariables.Ustaw(indeks, o);
 }
Exemple #20
0
    public override Value Execute(ExecutionContext vm, LocalVariables lv)
    {
        var argv = lv.GetVariable("argv");

        return(new Value(argv[0].Count));
    }
Exemple #21
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "StageObject")
        {
            Destroy(this.gameObject);
        }

        if (!IsMine)
        {
            return;
        }

        if (other.gameObject.tag == "Player")
        {
            if (other.gameObject.GetPhotonView().ownerId % 2 == 1 && teamColor == TeamColor.White)
            {
                return;
            }
            if (other.gameObject.GetPhotonView().ownerId % 2 == 0 && teamColor == TeamColor.Black)
            {
                return;
            }

            int otherPlayerID     = other.gameObject.GetPhotonView().ownerId;
            int otherPhotonViewID = other.gameObject.GetPhotonView().viewID;

            networkManager.photonView.RPC("SendDamage", PhotonTargets.MasterClient, originPlayer.GetPhotonView().ownerId, otherPlayerID, otherPhotonViewID);

            Destroy(this.gameObject);
        }
        else if (other.gameObject.tag == "MinionBodyCollider")
        {
            if (other.transform.parent.GetComponent <LocalVariables>().team == teamColor)
            {
                return;
            }

            targetLocalVariables = other.transform.root.GetComponent <LocalVariables>();
            targetLocalVariables.DamageMinion(attack, (int)teamColor);

            targetLocalVariables.photonView.RPC("DestroyMinionObject", PhotonTargets.MasterClient, other.transform.root.gameObject.GetPhotonView().viewID, ownerID);

            Destroy(this.gameObject);
        }
        else if (other.gameObject.tag == "Tower")
        {
            targetLocalVariables = other.gameObject.GetComponent <LocalVariables>();
            if (targetLocalVariables.team == teamColor)
            {
                Destroy(this.gameObject);
                return;
            }

            targetLocalVariables.photonView.RPC("Damage", PhotonTargets.MasterClient, attack);
            targetLocalVariables.photonView.RPC("DestroyTowerObject", PhotonTargets.MasterClient, other.gameObject.GetPhotonView().viewID, ownerID);

            Destroy(this.gameObject);
        }
        else if (other.gameObject.tag == "Projector")
        {
            targetLocalVariables = other.gameObject.GetComponent <LocalVariables>();
            if (targetLocalVariables.team == teamColor)
            {
                return;
            }

            targetLocalVariables.photonView.RPC("Damage", PhotonTargets.MasterClient, attack);
            Destroy(this.gameObject);
        }
    }
Exemple #22
0
    public override Value Execute(ExecutionContext vm, LocalVariables lv)
    {
        var argv = lv.GetVariable("argv");

        return(new Value(Path.GetFileName(argv[0].ToString())));
    }
Exemple #23
0
 public virtual Value Evaluate(ExecutionContext vm, LocalVariables lv) => null;
Exemple #24
0
    public override Value Execute(ExecutionContext vm, LocalVariables lv)
    {
        var argv = lv.GetVariable("argv");

        return(new Value(argv[1].ToString().LastIndexOf(argv[0].ToString())));
    }
Exemple #25
0
        /// <summary>
        /// This constructor will add some basic operators, functions, and variables
        /// to the parser. Please note that you are able to change that using
        /// boolean flags
        /// </summary>
        /// <param name="loadPreDefinedFunctions">This will load "abs", "cos", "cosh", "arccos", "sin", "sinh", "arcsin", "tan", "tanh", "arctan", "sqrt", "rem", "round"</param>
        /// <param name="loadPreDefinedOperators">This will load "%", "*", ":", "/", "+", "-", ">", "&lt;", "="</param>
        /// <param name="loadPreDefinedVariables">This will load "pi" and "e"</param>
        public MathParser(bool loadPreDefinedFunctions = true, bool loadPreDefinedOperators = true, bool loadPreDefinedVariables = true)
        {
            if (loadPreDefinedOperators)
            {
                // by default, we will load basic arithmetic operators.
                // please note, its possible to do it either inside the constructor,
                // or outside the class. the lowest value will be executed first!
                OperatorList.Add("%");     // modulo
                OperatorList.Add("^");     // to the power of
                OperatorList.Add(":");     // division 1
                OperatorList.Add("/");     // division 2
                OperatorList.Add("*");     // multiplication
                OperatorList.Add("-");     // subtraction
                OperatorList.Add("+");     // addition

                OperatorList.Add(">");     // greater than
                OperatorList.Add("<");     // less than
                OperatorList.Add("=");     // are equal


                // when an operator is executed, the parser needs to know how.
                // this is how you can add your own operators. note, the order
                // in this list does not matter.
                _operatorAction.Add("%", (numberA, numberB) => numberA % numberB);
                _operatorAction.Add("^", (numberA, numberB) => (decimal)Math.Pow((double)numberA, (double)numberB));
                _operatorAction.Add(":", (numberA, numberB) => numberA / numberB);
                _operatorAction.Add("/", (numberA, numberB) => numberA / numberB);
                _operatorAction.Add("*", (numberA, numberB) => numberA * numberB);
                _operatorAction.Add("+", (numberA, numberB) => numberA + numberB);
                _operatorAction.Add("-", (numberA, numberB) => numberA - numberB);

                _operatorAction.Add(">", (numberA, numberB) => numberA > numberB ? 1 : 0);
                _operatorAction.Add("<", (numberA, numberB) => numberA < numberB ? 1 : 0);
                _operatorAction.Add("=", (numberA, numberB) => numberA == numberB ? 1 : 0);
            }


            if (loadPreDefinedFunctions)
            {
                // these are the basic functions you might be able to use.
                // as with operators, localFunctions might be adjusted, i.e.
                // you can add or remove a function.
                // please open the "MathosTest" project, and find MathParser.cs
                // in "CustomFunction" you will see three ways of adding
                // a new function to this variable!
                // EACH FUNCTION MAY ONLY TAKE ONE PARAMETER, AND RETURN ONE
                // VALUE. THESE VALUES SHOULD BE IN "DECIMAL FORMAT"!
                LocalFunctions.Add("abs", x => (decimal)Math.Abs((double)x[0]));

                LocalFunctions.Add("cos", x => (decimal)Math.Cos((double)x[0]));
                LocalFunctions.Add("cosh", x => (decimal)Math.Cosh((double)x[0]));
                LocalFunctions.Add("arccos", x => (decimal)Math.Acos((double)x[0]));

                LocalFunctions.Add("sin", x => (decimal)Math.Sin((double)x[0]));
                LocalFunctions.Add("sinh", x => (decimal)Math.Sinh((double)x[0]));
                LocalFunctions.Add("arcsin", x => (decimal)Math.Asin((double)x[0]));

                LocalFunctions.Add("tan", x => (decimal)Math.Tan((double)x[0]));
                LocalFunctions.Add("tanh", x => (decimal)Math.Tanh((double)x[0]));
                LocalFunctions.Add("arctan", x => (decimal)Math.Atan((double)x[0]));
                //LocalFunctions.Add("arctan2", x => (decimal)Math.Atan2((double)x[0], (double)x[1]));

                LocalFunctions.Add("sqrt", x => (decimal)Math.Sqrt((double)x[0]));
                LocalFunctions.Add("rem", x => (decimal)Math.IEEERemainder((double)x[0], (double)x[1]));
                LocalFunctions.Add("root", x => (decimal)Math.Pow((double)x[0], 1.0 / (double)x[1]));
                LocalFunctions.Add("ln", x => (decimal)Math.Log((double)x[0], Math.E));
                LocalFunctions.Add("pow", x => (decimal)Math.Pow((double)x[0], (double)x[1]));
                LocalFunctions.Add("e", x => (decimal)Math.Pow(Math.E, (double)x[0]));

                LocalFunctions.Add("exp", x => (decimal)Math.Exp((double)x[0]));
                //LocalFunctions.Add("log", x => (decimal)Math.Log((double)x[0]));
                //LocalFunctions.Add("log10", x => (decimal)Math.Log10((double)x[0]));
                LocalFunctions.Add("log", delegate(decimal[] input)
                {
                    // input[0] is the number
                    // input[1] is the base

                    switch (input.Length)
                    {
                    case 1:
                        return((decimal)Math.Log((double)input[0]));

                    case 2:
                        return((decimal)Math.Log((double)input[0], (double)input[1]));

                    default:
                        return(0);        // false
                    }
                });

                LocalFunctions.Add("round", x => (decimal)Math.Round((double)x[0]));
                LocalFunctions.Add("truncate", x => (decimal)(x[0] < 0.0m ? -Math.Floor(-(double)x[0]) : Math.Floor((double)x[0])));
                LocalFunctions.Add("floor", x => (decimal)Math.Floor((double)x[0]));
                LocalFunctions.Add("ceiling", x => (decimal)Math.Ceiling((double)x[0]));
                LocalFunctions.Add("sign", x => (decimal)Math.Sign((double)x[0]));
            }

            if (loadPreDefinedVariables)
            {
                // local variables such as pi can also be added into the parser.
                LocalVariables.Add("pi", (decimal)3.14159265358979323846264338327950288);     // the simplest variable!
                LocalVariables.Add("pi2", (decimal)6.28318530717958647692528676655900576);
                LocalVariables.Add("pi05", (decimal)1.57079632679489661923132169163975144);
                LocalVariables.Add("pi025", (decimal)0.78539816339744830961566084581987572);
                LocalVariables.Add("pi0125", (decimal)0.39269908169872415480783042290993786);
                LocalVariables.Add("pitograd", (decimal)57.2957795130823208767981548141051704);
                LocalVariables.Add("piofgrad", (decimal)0.01745329251994329576923690768488612);

                LocalVariables.Add("e", (decimal)2.71828182845904523536028747135266249);
                LocalVariables.Add("phi", (decimal)1.61803398874989484820458683436563811);
                LocalVariables.Add("major", (decimal)0.61803398874989484820458683436563811);
                LocalVariables.Add("minor", (decimal)0.38196601125010515179541316563436189);
            }
        }
Exemple #26
0
 /// <summary>
 /// Tests if a variable name is declared locally or globally
 /// </summary>
 /// <param name="variableName">The name of the variable</param>
 /// <returns>True if the variable is declared, otherwise false</returns>
 public bool IsVariable(string variableName)
 {
     return(LocalVariables.ContainsKey(variableName) ||
            _referencedGlobalVariables.Any(f => f.Key.Name == variableName) ||
            typeof(Installation).GetProperty(variableName) != null);
 }