Beispiel #1
0
        /// <summary>
        /// 给指定用户产生随机初始卡
        /// 返回实际生成的卡牌数量
        /// </summary>
        public static Card[] GenerateRandomCards(User user, int num)
        {
            Card[] cards           = new Card[num];
            int    numCardsAlready = 0;

            if (user.cards != null && user.cards.Length > 0)
            {
                numCardsAlready = user.cards.Length;
            }

            byte[] dHeight = Op.BigInt2Bytes(Blockchain.GetHeight());
            byte[] salt    = Rand();
            for (int i = 0; i < num; i++)
            {
                Card   cardResult = new Card();
                byte[] dEmail     = Op.String2Bytes(user.email);
                byte[] dNum       = Op.BigInt2Bytes(i + numCardsAlready);

                cardResult.cardID = Random(Op.JoinByteArray(dEmail, dNum, dHeight), 10);

                cardResult.type = Op.Bytes2BigInt(Hash160(cardResult.cardID)) % TypeArmy.TypeCount;
                cardResult.lvls = Random(salt, Const.numCellsOfCard);

                cardResult.ownerEmail = user.email;
                cardResult.warPos     = 0;
                cards[i] = cardResult;
                RW.SaveCard(cardResult);
            }

            return(cards);
        }