Esempio n. 1
0
        // rpc signature: 'kogsobjectinfo objectid'
        // returns parsed info about game object in baseInfo
        // the caller needs to query baseInfo.objectId param and cast to the corresponding type, like:
        // if (baseInfo.objectId == "G")
        //     KogsGameStatus gameStatus = (KogsGameStatus)baseInfo;
        public static int kogsobjectinfo(string objectid, out KogsBaseInfo baseInfo, out string errorStr)
        {
            Int64 jresultPtr;

            errorStr = "";
            baseInfo = null;
            StringBuilder sbErrorStr = new StringBuilder(NSPV_MAXERRORLEN);

            RpcRequest <string[]> request = new RpcRequest <string[]>("kogsobjectinfo");

            request.@params = new string[] { objectid };
            string requestStr = JsonUtility.ToJson(request);

            Debug.Log("rpc request=" + requestStr);

            int rc = uplugin_CallRpcWithJson(requestStr, out jresultPtr, sbErrorStr);

            if (rc == 0)
            {
                string jresult = NSPVPtr2String(jresultPtr, out errorStr);
                Debug.Log("jresult=" + jresult);

                KogsBaseInfo baseInit = JsonUtility.FromJson <KogsBaseInfo>(jresult);
                if (baseInit != null && baseInit.objectType != null)
                {
                    switch (baseInit.objectType)
                    {
                    case "G":
                        KogsGameStatus gameStatus = JsonUtility.FromJson <KogsGameStatus>(jresult);
                        baseInfo = gameStatus;
                        break;

                    case "W":
                        KogsPlayerInfo playerInfo = JsonUtility.FromJson <KogsPlayerInfo>(jresult);
                        baseInfo = playerInfo;
                        break;

                    case "P":
                        KogsPackInfo packInfo = JsonUtility.FromJson <KogsPackInfo>(jresult);
                        baseInfo = packInfo;
                        break;

                    case "C":
                        KogsContainerInfo containerInfo = JsonUtility.FromJson <KogsContainerInfo>(jresult);
                        baseInfo = containerInfo;
                        break;

                    case "K":
                    case "S":
                        KogsMatchObjectInfo matchobjectInfo = JsonUtility.FromJson <KogsMatchObjectInfo>(jresult);
                        baseInfo = matchobjectInfo;
                        break;
                    }
                    return(0);
                }
                else
                {
                    errorStr = "could not parse the returned result object";
                    return(-1);
                }
            }
            else
            {
                errorStr = sbErrorStr.ToString();
            }
            return(rc);
        }