コード例 #1
0
ファイル: GameAction.cs プロジェクト: imengyu/Ballance2
 /// <summary>
 /// 创建操作调用结果
 /// </summary>
 /// <param name="success">是否成功</param>
 /// <param name="returnParams">返回的数据</param>
 public GameActionCallResult(bool success, object[] returnParams)
 {
     Success      = success;
     ReturnParams = LuaUtils.LuaTableArrayToObjectArray(returnParams);
 }
コード例 #2
0
        /// <summary>
        /// 调用操作
        /// </summary>
        /// <param name="action">目标操作实例</param>
        /// <param name="param">调用参数</param>
        /// <returns>返回操作调用结果,如果未找到操作,则返回 GameActionCallResult.FailResult </returns>
        public GameActionCallResult CallAction(GameAction action, params object[] param)
        {
            GameErrorManager.LastError = GameError.None;
            GameActionCallResult result = GameActionCallResult.FailResult;

            if (action == null)
            {
                GameErrorManager.SetLastErrorAndLog(GameError.ParamNotProvide, TAG, "CallAction action 参数为空");
                return(result);
            }
            if (action.Name == GameAction.Empty.Name)
            {
                GameErrorManager.SetLastErrorAndLog(GameError.Empty, TAG, "CallAction action 为空");
                return(result);
            }
            if (action.CallTypeCheck != null && action.CallTypeCheck.Length > 0)
            {
                //参数类型检查
                int argCount = action.CallTypeCheck.Length;
                if (argCount > param.Length)
                {
                    GameLogger.Warning(TAG, "操作 {0} 至少需要 {1} 个参数", action.Name, argCount);
                    return(result);
                }
                string allowType, typeName;
                for (int i = 0; i < argCount; i++)
                {
                    allowType = action.CallTypeCheck[i];
                    if (param[i] == null)
                    {
                        if (allowType != "null" &&
                            (!allowType.Contains("/") && !allowType.Contains("null")))
                        {
                            GameLogger.Warning(TAG, "操作 {0} 参数 {1} 不能为null", action.Name, i);
                            return(result);
                        }
                    }
                    else
                    {
                        typeName = param[i].GetType().Name;
                        if (allowType != typeName &&
                            (!allowType.Contains("/") && !allowType.Contains(typeName)))
                        {
                            GameLogger.Warning(TAG, "操作 {0} 参数 {1} 类型必须是 {2}", action.Name, i, action.CallTypeCheck[i]);
                            return(result);
                        }
                    }
                }
            }

            param = LuaUtils.LuaTableArrayToObjectArray(param);

            //GameLogger.Log(TAG, "CallAction {0} -> {1}", action.Name, StringUtils.ValueArrayToString(param));

            result = action.GameHandler.CallActionHandler(param);
            if (!result.Success)
            {
                GameLogger.Warning(TAG, "操作 {0} 执行失败 {1}", action.Name, GameErrorManager.LastError);
            }

            return(result);
        }