Example #1
0
        public override ActionStatus Execute(IGameAction gameAction, IScenarioContent content, out string error)
        {
            if (content.length != 1)
            {
                error = GetLengthErrorString(1);
                return(ActionStatus.Error);
            }

            error = null;
            return(ActionStatus.BackAction);
        }
Example #2
0
        protected override ActionStatus Run(IGameAction gameAction, IScenarioContent content, GotoArgs args, out string error)
        {
            ScenarioAction action;

            if (!ParseAction <ScenarioAction>(gameAction, out action, out error))
            {
                return(ActionStatus.Error);
            }

            return(action.GotoCommand(args.flag, out error));
        }
Example #3
0
        public override ActionStatus Execute(IGameAction gameAction, IScenarioContent content, out string error)
        {
            if (content.length > 1)
            {
                error = GetLengthErrorString(1);
                return(ActionStatus.Error);
            }

            error = null;
            GameDirector.instance.GameActionRunOver();
            GameMain.instance.LoadScene(GameMain.instance.startScene, LoadSceneMode.Single);
            return(ActionStatus.NextFrame);
        }
Example #4
0
        public override bool ParseArgs(IScenarioContent content, ref GotoArgs args, out string error)
        {
            // goto #flag;
            if (content.length != 2)
            {
                error = GetLengthErrorString(2);
                return(false);
            }

            args.flag = content[1];
            error     = null;
            return(true);
        }
Example #5
0
        protected virtual bool CheckArgsCorrect(IScenarioContent content, ref LoadArgs args, out string error)
        {
            switch (args.type)
            {
            case "scene":
                if (string.IsNullOrEmpty(args.arg0))
                {
                    error = string.Format(
                        "{0} ParseArgs error: scene name can not be null or empty.",
                        typeName);
                    return(false);
                }

                break;

            case "profile":
                if (string.IsNullOrEmpty(args.arg0))
                {
                    error = string.Format(
                        "{0} ParseArgs error: profile position is null or empty.",
                        typeName);
                    return(false);
                }

                args.arg0 = args.arg0.ToLower();
                if (args.arg0 != "top" || args.arg0 != "bottom")
                {
                    error = string.Format(
                        "{0} ParseArgs error: profile position can only be one of [top, bottom].",
                        typeName);
                    return(false);
                }

                if (string.IsNullOrEmpty(args.arg1))
                {
                    error = string.Format(
                        "{0} ParseArgs error: profile name is null or empty.",
                        typeName);
                    return(false);
                }

                break;

            // TODO other
            default:
                break;
            }

            error = null;
            return(true);
        }
        protected override ActionStatus Run(IGameAction gameAction, IScenarioContent content, BattleArgs args, out string error)
        {
            error = null;
            ScenarioBlackboard.battleMapScene = args.sceneName;
            ScenarioBlackboard.mapScript      = args.scriptName;
            if (!GameDirector.instance.LoadMap(args.sceneName))
            {
                return(ActionStatus.Error);
            }

            ScenarioBlackboard.Set(args.sceneName, 0);
            error = null;
            return(ActionStatus.WaitMapDone);
        }
Example #7
0
        public override bool ParseArgs(IScenarioContent content, ref SetFlagArgs args, out string error)
        {
            // #flag0
            // 剧情标识符只能有一个参数
            if (content.length != 1)
            {
                error = GetLengthErrorString(1);
                return(false);
            }

            args.flag = content.code;
            error     = null;
            return(true);
        }
        public override bool ParseArgs(IScenarioContent content, ref BattleArgs args, out string error)
        {
            // map Stage0Scene stage0script;
            if (content.length != 3)
            {
                error = GetLengthErrorString(3);
                return(false);
            }

            args.sceneName  = content[1];
            args.scriptName = content[2];

            error = null;
            return(true);
        }
Example #9
0
        protected override ActionStatus Run(IGameAction gameAction, IScenarioContent content, ClearArgs args, out string error)
        {
            switch (args.type)
            {
            case "text":
                return(ClearTextCmd(gameAction, args, out error));

            // TODO other
            default:
                error = string.Format(
                    "{0} Run -> UNESPECTED ERROR! the type `{1}` is not supported.",
                    typeName,
                    args.type);
                return(ActionStatus.Error);
            }
        }
Example #10
0
        public override bool ParseArgs(IScenarioContent content, ref CalcArgs args, out string error)
        {
            // calc var += 10;
            // calc var = var + 10;
            if (content.length != 4 && content.length != 6)
            {
                error = GetLengthErrorString(4, 6);
                return(false);
            }

            // 在计算之前,变量必须存在
            if (!IsMatchVar(content[1], true, ref args.name, out error))
            {
                return(false);
            }

            if (!IsMatchEqualOperator(content[2], ref args.equalOp, out error))
            {
                return(false);
            }

            if (!ParseOrGetVarValue(content[3], ref args.value1, out error))
            {
                return(false);
            }

            if (content.length == 4)
            {
                args.binaryOp = "+";
                args.value2   = 0;
            }
            else
            {
                if (!IsMatchBinaryOperator(content[4], ref args.binaryOp, out error))
                {
                    return(false);
                }

                if (!ParseOrGetVarValue(content[5], ref args.value2, out error))
                {
                    return(false);
                }
            }

            error = null;
            return(true);
        }
Example #11
0
        protected override ActionStatus Run(IGameAction gameAction, IScenarioContent content, IfGotoArgs args, out string error)
        {
            ScenarioAction action;

            if (!ParseAction <ScenarioAction>(gameAction, out action, out error))
            {
                return(ActionStatus.Error);
            }

            if (CompareResult(args.condition, args.left, args.right))
            {
                return(action.GotoCommand(args.flag, out error));
            }

            error = null;
            return(ActionStatus.Continue);
        }
Example #12
0
        /// <summary>
        /// 执行每一条命令
        /// </summary>
        /// <returns></returns>
        private ActionStatus Step()
        {
            if (token >= scenario.contentCount)
            {
                error = string.Format(
                    "{0} -> Step: scenario running end.",
                    GetType().Name);
                return(ActionStatus.Error);
            }

            // 获取命令
            IScenarioContent content = scenario.GetContent(token);

            DebugLogFormat(LogType.Log,
                           "Step {0}: {1}",
                           token,
                           content.ToString());

            IScenarioContentExecutor executor;

            // 如果是标识符,设置标识符
            if (content.type == ScenarioContentType.Flag)
            {
                executor = setFlagExecutor;
            }
            // 如果是动作,执行动作
            else
            {
                executor = GetExecutor(content.code);
                if (executor == null)
                {
                    error = string.Format(
                        "{0} -> Step: executor `{1}` was not found.",
                        GetType().Name,
                        content.code);
                    return(ActionStatus.Error);
                }
            }

            token++;
            ActionStatus result = executor.Execute(this, content, out m_Error);

            return(result);
        }
Example #13
0
        public override bool ParseArgs(IScenarioContent content, ref VarArgs args, out string error)
        {
            // var a;
            // var b = 10;
            // var c = b;
            if (content.length != 2 && content.length != 4)
            {
                error = GetLengthErrorString(2, 4);
                return(false);
            }

            // 变量名只能包含数字,字母(中文),下划线,且不能以数字开头
            if (!RegexUtility.IsMatchVariable(content[1]))
            {
                error = GetMatchVariableErrorString(content[1]);
                return(false);
            }
            args.name = content[1];

            //// 你也可以使用这个方法,这里确保了变量必须不存在
            //if (!IsMatchVar(content[1], false, ref args.name, out error))
            //{
            //    return false;
            //}

            args.value = 0;

            if (content.length == 4)
            {
                if (content[2] != "=")
                {
                    error = GetMatchOperatorErrorString(content[2], "=");
                    return(false);
                }

                if (!ParseOrGetVarValue(content[3], ref args.value, out error))
                {
                    return(false);
                }
            }

            error = null;
            return(true);
        }
Example #14
0
        public override bool ParseArgs(IScenarioContent content, ref DebugArgs args, out string error)
        {
#if UNITY_EDITOR
            // debug log "message";
            // debug warning "var = " var;
            // debug error "str0" var0 "str1" var1 var2 var3 "str2"...;
            if (content.length < 3)
            {
                error = GetLengthErrorString();
                return(false);
            }

            if (!s_EditorLowerLogTypeStrings.Contains(content[1].ToLower()))
            {
                error = string.Format(
                    "{0} ParseArgs error: LogType `{1}` is not defined.",
                    typeName,
                    content[1]);
                return(false);
            }
            args.logType = (LogType)Enum.Parse(typeof(LogType), content[1], true);

            List <string> messages   = new List <string>();
            int           startIndex = 2;
            int           endIndex   = 2;
            string        str;
            while (startIndex < content.length)
            {
                if (GetNextString(content, startIndex, ref endIndex, out str, out error))
                {
                    messages.Add(str);
                    startIndex = endIndex + 1;
                }
                else
                {
                    return(false);
                }
            }
            args.message = string.Join(" ", messages.ToArray());
#endif
            error = null;
            return(true);
        }
Example #15
0
        public override bool ParseArgs(IScenarioContent content, ref ClearArgs args, out string error)
        {
            if (content.length < 2)
            {
                error = GetLengthErrorString();
                return(false);
            }

            args.type = content[1].ToLower();
            if (!GetSupportedTypes().Contains(args.type))
            {
                error = string.Format(
                    "{0} ParseArgs -> the type `{1}` is not supported.",
                    typeName,
                    args.type);
                return(false);
            }

            int length = content.length;
            int index  = 2;

            if (index < length)
            {
                args.arg0 = content[index++];
            }

            if (index < length)
            {
                args.arg1 = content[index++];
            }

            if (index < length)
            {
                args.arg2 = content[index++];
            }

            if (index < length)
            {
                args.arg3 = content[index++];
            }

            return(CheckArgsCorrect(content, ref args, out error));
        }
Example #16
0
        /// <summary>
        /// 将剧本跳转到Flag
        /// </summary>
        /// <param name="flag"></param>
        /// <returns></returns>
        public ActionStatus GotoCommand(string flag, out string cmdError)
        {
            int index;

            if (!m_FlagDict.TryGetValue(flag, out index))
            {
                // 向后查找flag
                while (token < scenario.contentCount)
                {
                    IScenarioContent content = scenario.GetContent(token);
                    token++;
                    if (content.type != ScenarioContentType.Flag)
                    {
                        continue;
                    }

                    // 向后查找时,将新的剧情标识符加入到字典中
                    if (setFlagExecutor.Execute(this, content, out cmdError) == ActionStatus.Error)
                    {
                        return(ActionStatus.Error);
                    }

                    // 是我们需要的剧情标识符
                    if (flag == content.code)
                    {
                        return(ActionStatus.Continue);
                    }
                }

                // 没有搜索到
                cmdError = string.Format(
                    "{0} GotoCommand error: flag `{1}` was not found.",
                    GetType().Name,
                    flag);
                return(ActionStatus.Error);
            }

            token    = index;
            cmdError = null;
            return(ActionStatus.Continue);
        }
        /// <summary>
        /// Get strings with `"`.
        /// </summary>
        /// <param name="content"></param>
        /// <param name="startIndex"></param>
        /// <param name="result"></param>
        /// <param name="error"></param>
        /// <returns></returns>
        public static bool ParseContenStrings(IScenarioContent content, ref int startIndex, out List <string> result, out string error)
        {
            if (content == null)
            {
                result = null;
                error  = "ParseArgs error: `content` is null.";
                return(false);
            }

            if (startIndex >= content.length)
            {
                result = null;
                error  = "ParseArgs error: index is out of range.";
                return(false);
            }

            result = new List <string>();
            string str;

            while (startIndex < content.length)
            {
                if (content[startIndex].StartsWith("\""))
                {
                    if (!ParseContentString(content, ref startIndex, out str, out error))
                    {
                        result = null;
                        return(false);
                    }

                    result.Add(str);
                }
                else
                {
                    break;
                }
            }

            error = null;
            return(true);
        }
Example #18
0
        protected override ActionStatus Run(IGameAction gameAction, IScenarioContent content, MenuArgs args, out string error)
        {
            ScenarioAction action;

            if (!ParseAction <ScenarioAction>(gameAction, out action, out error))
            {
                return(ActionStatus.Error);
            }

            // 重置变量为-1
            ScenarioBlackboard.Set(args.menuName, -1);

            // 打开UI
            UIMenuPanel panel = UIManager.views.OpenView <UIMenuPanel>(UINames.k_UIMenuPanel, false);

            // 设置选项并传入选择后的处理方法
            if (!panel.SetOptions(args.options, selected =>
            {
                // 选择完成后的处理

                // 关闭菜单UI
                UIManager.views.CloseView(UINames.k_UIMenuPanel);
                // 设置选择的按钮
                ScenarioBlackboard.Set(args.menuName, selected);
                // 继续剧本
                action.MenuDone();
            }))
            {
                error = string.Format(
                    "{0} ParseArgs error: set menu options error.",
                    typeName);
                return(ActionStatus.Error);
            }

            error = null;
            return(ActionStatus.WaitMenuOption);
        }
Example #19
0
        protected override ActionStatus Run(IGameAction gameAction, IScenarioContent content, DebugArgs args, out string error)
        {
#if UNITY_EDITOR
            string message = args.message;

            switch (args.logType)
            {
            case LogType.Error:
                Debug.LogError(message);
                break;

            case LogType.Assert:
                Debug.LogAssertion(message);
                break;

            case LogType.Warning:
                Debug.LogWarning(message);
                break;

            case LogType.Log:
                Debug.Log(message);
                break;

            case LogType.Exception:
                DebugException e = new DebugException(message);
                error = e.ToString();
                Debug.LogException(e);
                return(ActionStatus.Error);

            default:
                break;
            }
#endif
            error = null;
            return(ActionStatus.Continue);
        }
Example #20
0
        public override bool ParseArgs(IScenarioContent content, ref IfGotoArgs args, out string error)
        {
            // if var goto #flag;
            // if !var goto #flag;
            // if var >= num goto #flag;
            if (content.length != 4 && content.length != 6)
            {
                error = GetLengthErrorString(4, 6);
                return(false);
            }

            string gotoStr;

            if (content.length == 4)
            {
                string varName;
                if (content[1][0] == '!')
                {
                    varName        = content[1].Remove(0, 1);
                    args.condition = "==";
                }
                else
                {
                    varName        = content[1];
                    args.condition = "!=";
                }

                if (!ParseOrGetVarValue(varName, ref args.left, out error))
                {
                    return(false);
                }
                args.right = 0;

                gotoStr   = content[2];
                args.flag = content[3];
            }
            else
            {
                if (!ParseOrGetVarValue(content[1], ref args.left, out error))
                {
                    return(false);
                }

                if (!IsMatchConditionOperator(content[2], ref args.condition, out error))
                {
                    return(false);
                }

                if (!ParseOrGetVarValue(content[3], ref args.right, out error))
                {
                    return(false);
                }

                gotoStr   = content[4];
                args.flag = content[5];
            }

            if (gotoStr != "goto")
            {
                error = string.Format(
                    "{0} ParseArgs error: keycode `{1}` is not equal to `goto`.",
                    GetType().Name,
                    gotoStr);
                return(false);
            }

            error = null;
            return(true);
        }
Example #21
0
        public override bool ParseArgs(IScenarioContent content, ref TextArgs args, out string error)
        {
            // text position text0 text1 ...;
            if (content.length < 3)
            {
                error = GetLengthErrorString();
                return(false);
            }

            string position = content[1].ToLower();

            if (position != "top" && position != "bottom" && position != "global")
            {
                error = string.Format(
                    "{0} ParseArgs error: position must be one of [top, bottom, global].",
                    typeName,
                    content[1]);
                return(false);
            }
            args.position = position;

            TextInfoConfig config  = TextInfoConfig.Get <TextInfoConfig>();
            StringBuilder  builder = new StringBuilder();

            int index = 2;

            while (index < content.length)
            {
                string line;
                if (content[index].StartsWith("\""))
                {
                    if (!ScenarioUtility.ParseContentString(content, ref index, out line, out error))
                    {
                        return(false);
                    }
                }
                else
                {
                    // 可能是个变量
                    int id = -1;
                    if (!ParseOrGetVarValue(content[index], ref id, out error))
                    {
                        return(false);
                    }

                    TextInfo info = config[id];
                    if (info == null)
                    {
                        error = string.Format(
                            "{0} ParseArgs error: text id `{1}` was not found.",
                            typeName,
                            content[index]);
                        return(false);
                    }

                    line = info.text;
                    index++;
                }
                builder.AppendLine(line);
            }

            args.text = builder.ToString();

            /// 从游戏设置中读取
            /// 最常见的形式是类似J-AVG快进的形式
            args.async = true;

            error = null;
            return(true);
        }
Example #22
0
 protected override ActionStatus Run(IGameAction gameAction, IScenarioContent content, VarArgs args, out string error)
 {
     ScenarioBlackboard.Set(args.name, args.value);
     error = null;
     return(ActionStatus.Continue);
 }
 public abstract ActionStatus Execute(IGameAction gameAction, IScenarioContent content, out string error);
Example #24
0
 protected override ActionStatus Run(IGameAction gameAction, IScenarioContent content, SleepArgs args, out string error)
 {
     GameDirector.instance.StartTimer(-1, args.sec, gameAction.TimerTimeout);
     error = null;
     return(ActionStatus.WaitTimerTimeout);
 }
Example #25
0
        public override bool ParseArgs(IScenarioContent content, ref MenuArgs args, out string error)
        {
            /// menu option
            ///     option0
            ///     option1
            ///     ...;
            if (content.length < 3)
            {
                error = GetLengthErrorString();
                return(false);
            }

            // 获取使用的变量
            if (!RegexUtility.IsMatchVariable(content[1]))
            {
                error = GetMatchVariableErrorString(content[1]);
                return(false);
            }
            args.menuName = content[1];

            TextInfoConfig config  = TextInfoConfig.Get <TextInfoConfig>();
            List <string>  options = new List <string>();
            int            index   = 2;

            while (index < content.length)
            {
                string line;
                if (content[index].StartsWith("\""))
                {
                    if (!ScenarioUtility.ParseContentString(content, ref index, out line, out error))
                    {
                        return(false);
                    }
                }
                else
                {
                    // 可能是个变量
                    int id = -1;
                    if (!ParseOrGetVarValue(content[index], ref id, out error))
                    {
                        return(false);
                    }

                    TextInfo info = config[id];
                    if (info == null)
                    {
                        error = string.Format(
                            "{0} ParseArgs error: text id `{1}` was not found.",
                            typeName,
                            content[index]);
                        return(false);
                    }

                    line = info.text;
                    index++;
                }
                options.Add(line);
            }
            args.options = options.ToArray();

            error = null;
            return(true);
        }