コード例 #1
0
        /** User starts a war against a city. If the city is empty now, it's gonna occupy it directly.
         * 参战某城市,
         * Return: An object of War. If failed to create, return null
         */
        /** User starts a war against a city. If the city is empty now, it's gonna occupy it directly.
         * 参战某城市,
         * Return: An object of War. If failed to create, return null
         */
        public static byte[] StartSiege(Credential credential, BigInteger serverId, BigInteger cityId, byte[] cardIds)
        {
            if (Global.VerifyUser(credential))
            {
                if (cityId >= Const.numCities)
                {
                    return(NuTP.RespDataWithCode(ErrCate.City, ErrType.NotExist));
                }
                else
                {   //City does exist
                    City       city   = RW.FindCity(serverId, cityId);
                    BigInteger status = RW.GetStatusCity(city);
                    if (status == StatusCity.Sieging)
                    {
                        return(NuTP.RespDataWithCode(ErrCate.City, ErrType.Duplicated));
                    }
                    else
                    {
                        User user = RW.FindUser(credential.email);
                        if (user.warID != Op.Void())
                        {  //User does not allow to participate into multiple wars at the same time
                            return(NuTP.RespDataWithCode(ErrCate.War, ErrType.Duplicated));
                        }
                        else
                        {
                            CarryBattleSC.Card[] cards = RW.Table2Cards(cardIds);
                            if (cards.Length != Const.numCardsSiege)
                            {  //Format of card array must be wrong
                                return(NuTP.RespDataWithCode(NuTP.SysDom, NuTP.Code.BadRequest));
                            }

                            for (int i = 0; i < Const.numCardsSiege; i++)
                            {
                                if (cards[i].ownerEmail != user.email)
                                {
                                    return(NuTP.RespDataWithCode(ErrCate.Card, ErrType.NotExist));
                                }
                            }

                            Siege siege = RW.CreateSiege(serverId, city, user, cards, Blockchain.GetHeight());

                            return(NuTP.RespDataSucWithBody(RW.Seige2Bytes(siege)));
                        }
                    }
                }
            }
            else
            {
                return(NuTP.RespDataWithCode(ErrCate.Account, ErrType.AuthFail));
            }
        }