/// <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); }
public ErrorCode OnCs2DbBuyChampion(NetSessionBase session, Google.Protobuf.IMessage message) { Protos.CS2DB_BuyChampion request = (Protos.CS2DB_BuyChampion)message; Protos.DB2CS_BuyChampionRet resp = ProtoCreator.R_CS2DB_BuyChampion(request.Opts.Pid); string cids = string.Join('|', request.Cids); string str = $"UPDATE account_user SET money={request.Money},diamoned={request.Diamoned},champions={cids} where id={request.Ukey}"; ErrorCode errorCode = DB.instance.accountDB.SqlExecNonQuery(str, out _, out uint _); switch (errorCode) { case ErrorCode.Success: request.Result = Protos.Global.Types.ECommon.Success; break; default: request.Result = Protos.Global.Types.ECommon.Failed; break; } session.Send(resp); return(ErrorCode.Success); }