Exemple #1
0
        /// <summary>
        /// 客户端请求购买英雄
        /// </summary>
        public ErrorCode OnGc2CsBuyChampion(NetSessionBase session, IMessage message)
        {
            Protos.GC2CS_BuyChampion    request  = (Protos.GC2CS_BuyChampion)message;
            Protos.CS2GC_BuyChampionRet response = ProtoCreator.R_GC2CS_BuyChampion(request.Opts.Pid);
            int    id    = request.Cid;
            ulong  gcNID = request.Opts.Transid;
            CSUser user  = CS.instance.userMgr.GetUser(gcNID);

            if (user == null)
            {
                return(ErrorCode.Success);
            }

            if (user.champions.Contains(id))                //已存在该英雄
            {
                response.Result = Protos.CS2GC_BuyChampionRet.Types.Result.Failed;
                user.Send(response);
                return(ErrorCode.Success);
            }
            Hashtable defs        = GoodsDefs.GetChampion(id);
            int       priceNeeded = ( int )(defs.GetInt("price") * (1 + defs.GetFloat("p_discount")));

            if (user.money < priceNeeded)              //没有足够金钱
            {
                response.Result = Protos.CS2GC_BuyChampionRet.Types.Result.NotEnoughMoney;
                user.Send(response);
                return(ErrorCode.Success);
            }
            int diamonedNeeded = ( int )(defs.GetInt("diamoned") * (1 + defs.GetFloat("d_discount")));

            if (user.diamoned < diamonedNeeded)
            {
                response.Result = Protos.CS2GC_BuyChampionRet.Types.Result.NotEnoughDiamoned;
                user.Send(response);
                return(ErrorCode.Success);
            }
            int expNeeded = defs.GetInt("exp");

            if (user.exp < expNeeded)
            {
                response.Result = Protos.CS2GC_BuyChampionRet.Types.Result.NotEnoughExp;
                user.Send(response);
                return(ErrorCode.Success);
            }

            int moneyResult    = user.money - priceNeeded;
            int diamonedResult = user.diamoned - diamonedNeeded;

            Protos.CS2DB_BuyChampion request2 = ProtoCreator.Q_CS2DB_BuyChampion();
            request2.Ukey     = user.ukey;
            request2.Money    = moneyResult;
            request2.Diamoned = diamonedResult;
            request2.Cids.Add(request.Cid);
            CS.instance.netSessionMgr.Send(SessionType.ServerC2DB, request2, RPCEntry.Pop(OnBuyChampion, user, moneyResult, diamonedResult, request.Cid, response));

            return(ErrorCode.Success);
        }
Exemple #2
0
 public void LoadGoods() => GoodsDefs.Load(File.ReadAllText(this.config.goodsPath));