Esempio n. 1
0
    public void MergeCards()
    {
        Debug.Log("Merge Begin");

        // Create Card1
        Card card1 = CreateCard("card1", "CrazyKnight");
        // Create Card2
        Card card2 = CreateCard("card2", "FloppyInfantry");

        object[] paras = new object[3];
        paras[0] = card1.id;
        paras[1] = card2.id;
        paras[2] = "SharpArchery";

        NuTP.Response response = NuContract.InvokeWithResp("", "cardMerge", paras);

        if (response.header.code == NuTP.Code.Success)
        {
            Card cardNew = Contract.Bytes2Card(response.body);
            Debug.Log("New card's ID:\t" + cardNew.id);
            Debug.Log("New card's name:\t" + cardNew.name);
            Debug.Log("New card's birthBlock:\t" + cardNew.birthBlock);
        }
        else
        {
            Debug.Log("failed to merge card");
        }
    }
Esempio n. 2
0
        /** Get basic information of a list of users
         *
         *  获取一系列玩家信息, 内容包括所在服务器、所占城池、
         * 返回:该用户所有卡牌具体信息。
         *
         * For each user, the information includes:
         *     -  User email and address,
         *     -  User current server and city
         *     -  User score and unclaimed score
         *     -  User's cards (full cards data)
         *
         * Return: Array of the User objects and cards
         *
         *
         */

        /* * NuTP:
         * <emails> = S[S<email>*]
         *
         * <getUsers> =  [S<header>,
         *             S[([S<user>,
         *                  S[S<card>*10]]
         *             )*]
         */

        private static byte[] GetUsers(Credential credential, byte[] emails)
        {
            // This method does not require credential

            int numEmails = emails.SizeTable();

            byte[] retBody = Op.Void();

            for (int i = 0; i < numEmails; i++)
            {
                string email = emails.SplitTblStr(i);
                User   user  = RW.FindUser(email);
                if (user != null)
                {
                    byte[] body = NuSD.Seg(RW.User2Bytes(user)).AddSeg(RW.UserCards2Table(user));
                    retBody.AddSeg(body);
                }
                else
                {
                    return(NuTP.RespDataWithDetail(ErrCate.User, ErrType.NotExist, email, Op.Void()));
                }
            }

            NuTP.Response response = new NuTP.Response
            {
                header = new NuTP.Header
                {
                    domain = NuTP.SysDom,
                    code   = NuTP.Code.Success
                },

                body = retBody
            };
            return(NuTP.Response2Bytes(response));
        }
Esempio n. 3
0
    private Card CreateCard(string id, string cardName)
    {
        object[] paras = new object[3];
        paras[0] = myID;
        paras[1] = Op.String2Bytes(id);
        paras[2] = cardName;

        NuTP.Response response = NuContract.InvokeWithResp("", "randomCard", paras);
        if (response.header.code == NuTP.Code.Success)
        {
            return(Contract.Bytes2Card(response.body));
        }
        else
        {
            Debug.LogError(response.header.code + ":" + response.header.description);
            paras    = new object[1];
            paras[0] = Op.String2Bytes(id);
            NuTP.Response respGetCard = NuContract.InvokeWithResp("", "getCard", paras);
            if (respGetCard.header.code == NuTP.Code.Success)
            {
                return(Contract.Bytes2Card(respGetCard.body));
            }
            else
            {
                return(null);
            }
        }
    }