public static void If(Pseudocode Pseudocode, string funcName, Action <object> callback, object[] parameters)
        {
            bool             isTrue     = (bool)parameters[0];
            PseudocodeAction TrueDoSth  = (PseudocodeAction)parameters[1];
            PseudocodeAction FalseDoSth = (PseudocodeAction)parameters[2];

            if (isTrue)
            {
                if (TrueDoSth != null)
                {
                    Pseudocode.RunQueue(Pseudocode.GetFuncParamFuncsQueue(TrueDoSth.funcs),
                                        () => { callback?.Invoke(null); });
                }
                else
                {
                    callback?.Invoke(null);
                }
            }
            else
            {
                if (FalseDoSth != null)
                {
                    Pseudocode.RunQueue(Pseudocode.GetFuncParamFuncsQueue(FalseDoSth.funcs),
                                        () => { callback?.Invoke(null); });
                }
                else
                {
                    callback?.Invoke(null);
                }
            }
        }
        public static void IsLessOrEqualsTo(Pseudocode Pseudocode, string funcName, Action <object> callback, object[] parameters, object[] commonParameters)
        {
            float a = GetFloat(parameters[0]);
            float b = GetFloat(parameters[1]);

            callback?.Invoke(a <= b);
        }
        /// <summary>
        /// 指定循环次数连续做几次某事
        /// </summary>
        public static void Foreach(Pseudocode Pseudocode, string funcName, Action <object> callback, object[] parameters, object[] commonParameters)
        {
            IList <object>   list   = parameters[0].GetList();
            var              mList  = list.ToList();
            PseudocodeAction act    = (PseudocodeAction)parameters[1];
            string           loopId = parameters.GetItem(2).GetStr();

            if (mList.Count > 0)
            {
                if (act != null)
                {
                    var one = mList[0];
                    if (loopId != null)
                    {
                        Pseudocode.vars[loopId] = one;
                    }
                    mList.RemoveAt(0);
                    parameters[0] = mList;
                    Pseudocode.RunQueue(Pseudocode.GetFuncParamFuncsQueue(act.funcs),
                                        () => { Foreach(Pseudocode, funcName, callback, parameters, commonParameters); }, commonParameters);
                }
                else
                {
                    callback?.Invoke(null);
                }
            }
            else
            {
                callback?.Invoke(null);
            }
        }
Beispiel #4
0
        private static void onCallFunc(Pseudocode pseudocode, string funName, Action <object> callback, object[] parameters, object[] commonParams)
        {
            var func = GetMethod(funName);

            if (func != null)
            {
                try
                {
                    func.Invoke(null, new object[] { pseudocode, funName, callback, parameters, commonParams });
                }
                catch (TargetParameterCountException ex)
                {
                    Debug.LogErrorFormat("PseudocodeHelper 调用 {0} 时, 参数异常!", funName);
                }
                catch (Exception ex)
                {
                    Debug.LogErrorFormat("PseudocodeHelper 调用 {0} 时出错: {1}", funName, ex);
                }
            }
            else
            {
                Debug.LogError($"未找到“伪”方法 {funName} 对应的“真”方法!");
                callback(null);
            }
        }
        public static void Print(Pseudocode Pseudocode, string funcName, Action <object> callback, object[] parameters)
        {
            string s = parameters[0].ToString();

            Debug.Log(s);
            callback?.Invoke(null);
        }
        /// <summary>
        /// 指定循环次数连续做几次某事
        /// </summary>
        public static void For(Pseudocode Pseudocode, string funcName, Action <object> callback, object[] parameters, object[] commonParameters)
        {
            int loopCount = parameters[0].GetInt();
            PseudocodeAction LoopDoSth = (PseudocodeAction)parameters[1];
            string           loopId    = parameters.GetItem(2).GetStr();

            if (loopCount > 0)
            {
                loopCount--;
                parameters[0] = loopCount;

                if (loopId != null)
                {
                    Pseudocode.vars[loopId] = loopCount;
                }

                if (LoopDoSth != null)
                {
                    Pseudocode.RunQueue(Pseudocode.GetFuncParamFuncsQueue(LoopDoSth.funcs),
                                        () => { For(Pseudocode, funcName, callback, parameters, commonParameters); }, commonParameters);
                }
                else
                {
                    callback?.Invoke(null);
                }
            }
            else
            {
                callback?.Invoke(null);
            }
        }
        public static void Or(Pseudocode Pseudocode, string funcName, Action <object> callback, object[] parameters)
        {
            bool a = (bool)parameters[0];
            bool b = (bool)parameters[1];

            callback?.Invoke(a || b);
        }
        public static void IsEqualsTo(Pseudocode Pseudocode, string funcName, Action <object> callback, object[] parameters, object[] commonParameters)
        {
            float a = GetFloat(parameters[0]);
            float b = GetFloat(parameters[1]);

            callback?.Invoke(Math.Abs(a - b) < 0.0000001f);
        }
        public static void IsEqualsTo(Pseudocode Pseudocode, string funcName, Action <object> callback, object[] parameters)
        {
            float a = (float)parameters[0];
            float b = (float)parameters[1];

            callback?.Invoke(Math.Abs(a - b) < 0.0000001f);
        }
        public static void IsLessTo(Pseudocode Pseudocode, string funcName, Action <object> callback, object[] parameters)
        {
            float a = (float)parameters[0];
            float b = (float)parameters[1];

            callback?.Invoke(a < b);
        }
        public static void Remaind(Pseudocode Pseudocode, string funcName, Action <object> callback, object[] parameters, object[] commonParameters)
        {
            float a = GetFloat(parameters[0]);
            float b = GetFloat(parameters[1]);

            callback?.Invoke(a % b);
        }
        public static void While(Pseudocode Pseudocode, string funcName, Action <object> callback, object[] parameters)
        {
            if (parameters[0] is bool)
            {
                throw new Exception("定义While方法的条件参数,需要使用方法: NewFunc(表达式)");
            }
            PseudocodeFunc   isTruePseudocodeFunc = (PseudocodeFunc)parameters[0];
            PseudocodeAction LoopDoSth            = (PseudocodeAction)parameters[1];

            Pseudocode.Run(isTruePseudocodeFunc, () =>
            {
                if ((bool)isTruePseudocodeFunc.result)
                {
                    if (LoopDoSth != null)
                    {
                        Pseudocode.RunQueue(Pseudocode.GetFuncParamFuncsQueue(LoopDoSth.funcs),
                                            () => { While(Pseudocode, funcName, callback, parameters); });
                    }
                    else
                    {
                        callback?.Invoke(null);
                    }
                }
                else
                {
                    callback?.Invoke(null);
                }
            });
        }
        /// <summary>
        /// 并行处理多个动作,非多线程
        /// </summary>
        public static void Parallel(Pseudocode Pseudocode, string funcName, Action <object> callback,
                                    object[] parameters, object[] commonParameters)
        {
            var count = parameters.Length;
            var cur   = 0;

            for (int i = 0; i < parameters.Length; i++)
            {
                PseudocodeAction act = (PseudocodeAction)parameters[i];
                if (!act)
                {
                    Debug.LogError("Parallel 方法只接受NewAction方法返回的参数!");
                    cur++;
                    if (cur == count)
                    {
                        // 全部并行处理完,再返回
                        callback?.Invoke(null);
                    }
                    continue;
                }
                Pseudocode.RunQueue(Pseudocode.GetFuncParamFuncsQueue(act.funcs), () =>
                {
                    // 单线程处理,不用担心
                    cur++;
                    if (cur == count)
                    {
                        // 全部并行处理完,再返回
                        callback?.Invoke(null);
                    }
                }, commonParameters);
            }
        }
        public static void SetVar(Pseudocode Pseudocode, string funcName, Action <object> callback, object[] parameters)
        {
            string varName  = (string)parameters[0];
            object varValue = parameters[1];

            Pseudocode.vars[varName] = varValue;
            callback?.Invoke(varValue);
        }
 public static void MurdererToKill(Pseudocode Pseudocode, string funcName, Action <object> callback,
                                   object[] parameters, object[] commonParams)
 {
     Debug.Log($"MurdererToKill: {2}");
     CoroutineHelper.Instance.Delay(2, () =>
     {
         callback?.Invoke(null);
     });
 }
        public static void RemoveVar(Pseudocode Pseudocode, string funcName, Action <object> callback, object[] parameters)
        {
            string varName = (string)parameters[0];

            var res = Pseudocode.vars[varName];

            Pseudocode.vars.Remove(varName);
            callback?.Invoke(res);
        }
        public static void StringConnect(Pseudocode Pseudocode, string funcName, Action <object> callback, object[] parameters, object[] commonParameters)
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < parameters.Length; i++)
            {
                sb.Append(parameters[i]);
            }
            callback?.Invoke(sb.ToString());
        }
        private static IEnumerator DelayCor(Pseudocode Pseudocode, string funcName, Action <object> callback,
                                            float duration, PseudocodeAction act, object[] commonParameters)
        {
            yield return(new WaitForSeconds(duration));

            Pseudocode.RunQueue(Pseudocode.GetFuncParamFuncsQueue(act.funcs), () =>
            {
                callback?.Invoke(null);
            }, commonParameters);
        }
        public static void SelectDoor(Pseudocode Pseudocode, string funcName, Action <object> callback,
                                      object[] parameters, object[] commonParams)
        {
            var isOpened = (bool)parameters[0];

            Debug.Log($"SelectDoor: {isOpened}");
            CoroutineHelper.Instance.Delay(2, () =>
            {
                callback?.Invoke(2.5f);
            });
        }
        public static void AbnormalKillHuman(Pseudocode Pseudocode, string funcName, Action <object> callback,
                                             object[] parameters, object[] commonParams)
        {
            var human = (string)parameters[0];

            Debug.Log($"AbnormalKillHuman: {human} Be Killed!");
            CoroutineHelper.Instance.Delay(2, () =>
            {
                callback?.Invoke(null);
            });
        }
        public static void OpenLuDeng(Pseudocode Pseudocode, string funcName, Action <object> callback,
                                      object[] parameters, object[] commonParams)
        {
            var wait = (int)parameters[0];

            Debug.Log($"OpenLuDeng: {wait}");
            CoroutineHelper.Instance.Delay(wait, () =>
            {
                callback?.Invoke(null);
            });
        }
        public static void OpenDoor(Pseudocode Pseudocode, string funcName, Action <object> callback,
                                    object[] parameters, object[] commonParams)
        {
            var wait = DefaultFuncs.GetFloat(parameters[0]);

            Debug.Log($"OpenDoor: {wait}");
            CoroutineHelper.Instance.Delay(wait, () =>
            {
                callback?.Invoke(null);
            });
        }
        public static void GetVar(Pseudocode Pseudocode, string funcName, Action <object> callback, object[] parameters, object[] commonParameters)
        {
            string varName = (string)parameters[0];

            if (Pseudocode.vars.ContainsKey(varName))
            {
                callback?.Invoke(Pseudocode.vars[varName]);
            }
            else
            {
                Debug.LogError($"不存在变量:{varName} ---- {funcName}");
            }
        }
        public static void RandomHuman(Pseudocode Pseudocode, string funcName, Action <object> callback,
                                       object[] parameters, object[] commonParams)
        {
            var set1 = (HashSet <string>)parameters[0];
            var res  = set1.ToList()[Random.Range(0, set1.Count)];

            Debug.Log($"RandomHuman: {res}");

            CoroutineHelper.Instance.Delay(2, () =>
            {
                callback?.Invoke(res);
            });
        }
        public static void Delay(Pseudocode Pseudocode, string funcName, Action <object> callback, object[] parameters, object[] commonParameters)
        {
            float            duration  = parameters[0].GetFloat();
            PseudocodeAction LoopDoSth = (PseudocodeAction)parameters[1];

            if (!LoopDoSth)
            {
                Debug.LogError("Loop 方法第3个参数只接受NewAction方法返回的参数!");
            }

            CoroutineHelper.Instance.StartCoroutine(DelayCor(Pseudocode, funcName, callback,
                                                             duration, LoopDoSth, commonParameters));
        }
Beispiel #26
0
        private static void onCallFunc(Pseudocode pseudocode, string funName, Action <object> callback, object[] parameters)
        {
            var func = GetMethod(funName);

            if (func != null)
            {
                func.Invoke(null, new object[] { pseudocode, funName, callback, parameters });
            }
            else
            {
                Debug.LogError($"未找到“伪”方法 “{funName}” 对应的“真”方法!");
                callback(null);
            }
        }
        public static void RandomRange(Pseudocode Pseudocode, string funcName, Action <object> callback, object[] parameters, object[] commonParameters)
        {
            float a     = parameters[0].GetFloat();
            float b     = parameters[1].GetFloat();
            bool  isInt = parameters[2].GetBool();

            if (isInt)
            {
                callback?.Invoke(Random.Range(Mathf.RoundToInt(a), Mathf.RoundToInt(b)));
            }
            else
            {
                callback?.Invoke(Random.Range(a, b));
            }
        }
        public static void GetAllHumans(Pseudocode Pseudocode, string funcName, Action <object> callback,
                                        object[] parameters, object[] commonParams)
        {
            var count = (int)parameters[0];

            Debug.Log($"GetAllHumans: {count}");

            var res = new HashSet <string>()
            {
                "100001", "100002", "100008", "100010"
            };

            CoroutineHelper.Instance.Delay(2, () =>
            {
                callback?.Invoke(res);
            });
        }
        public static void NewSet(Pseudocode Pseudocode, string funcName, Action <object> callback,
                                  object[] parameters, object[] commonParams)
        {
            var str  = (string)parameters[0];
            var item = str.Replace("{", "").Replace("}", "");

            Debug.Log($"NewSet: {item}");
            var res = new HashSet <string>()
            {
                item
            };

            CoroutineHelper.Instance.Delay(2, () =>
            {
                callback?.Invoke(res);
            });
        }
        public static void SubtractSet(Pseudocode Pseudocode, string funcName, Action <object> callback,
                                       object[] parameters, object[] commonParams)
        {
            var set1 = (HashSet <string>)parameters[0];
            var set2 = (HashSet <string>)parameters[1];

            Debug.Log($"SubtractSet: {2}");

            var res = new HashSet <string>(set1);

            res.ExceptWith(set2);

            CoroutineHelper.Instance.Delay(2, () =>
            {
                callback?.Invoke(res);
            });
        }