//请求购买商品 如果要微信支付就会返回 如果只是需要钻石就会直接购买
        public static async Task <WeChatOrderInfo> RequestTopUp(this TopUpComponent topUpComponent, long userId, long commodityId, IResponse iResponse)
        {
            Commodity commodity = ShoppingCommodityComponent.Ins.GetCommdity(commodityId);

            if (commodity.MonetaryType == GoodsId.CNY)
            {
                WeChatOrderInfo weChatOrderInfo = WeChatPayComponent.Ins.WeChatPlaceOrder(commodity.Price);
                TopUpRecord     topUpRecord     = TopUpRecordFactory.Create(weChatOrderInfo.outTradeNo, userId, commodity);
                await Game.Scene.GetComponent <DBProxyComponent>().Save(topUpRecord);//存储充值记录

                return(weChatOrderInfo);
            }
            else if (commodity.MonetaryType == GoodsId.Jewel)
            {
                User user = await UserHelp.QueryUserInfo(userId);

                if (user.Jewel >= commodity.Price)
                {
                    await user.GoodsChange(GoodsId.Jewel, commodity.Price * -1, GoodsChangeType.ShopPurchase);       //减少钻石

                    await user.GoodsChange(commodity.CommodityType, commodity.Amount, GoodsChangeType.ShopPurchase); //增加商品数量
                }
                else
                {
                    iResponse.Message = "钻石不足";
                }
            }
            return(null);
        }
示例#2
0
 //游戏结束扣除玩家钻石
 public static async Task DeductJewel(this MatchRoom matchRoom)
 {
     if (matchRoom.RoomType != RoomType.RoomCard)
     {
         return;//不是房卡 不扣除钻石
     }
     //亲友圈房间 亲友圈主人扣除钻石
     if (matchRoom.FriendsCreateUserId > 0)
     {
         await UserHelp.GoodsChange(matchRoom.FriendsCreateUserId, GoodsId.Jewel, matchRoom.NeedJeweNumCount *-1,
                                    GoodsChangeType.RoomCard, false);
     }
     else if (matchRoom.IsAADeductJewel)
     {
         //如果是AA所有人都有扣除钻石
         foreach (var player in matchRoom.PlayerInfoDic)
         {
             await player.Value.User.GoodsChange(GoodsId.Jewel, matchRoom.NeedJeweNumCount * -1,
                                                 GoodsChangeType.RoomCard, false);
         }
     }
     else
     {
         //如果不是亲友圈 也不是AA就房主 索引0扣除钻石
         if (matchRoom.PlayerInfoDic.ContainsKey(0))
         {
             await matchRoom.PlayerInfoDic[0].User.GoodsChange(GoodsId.Jewel, matchRoom.NeedJeweNumCount * -1,
                                                               GoodsChangeType.RoomCard, false);
         }
     }
 }
示例#3
0
        //代理卖钻石
        public static async Task SaleJewel(this AgencyComponent agencyComponent, long sellerUserId, long buyerUserId, int jewelNum, IResponse iResponse)
        {
            if (!agencyComponent.JudgeIsAgency(sellerUserId))
            {
                iResponse.Message = "权限不足";
                return;
            }
            if (sellerUserId == buyerUserId)
            {
                iResponse.Message = "不能卖给自己";
                return;
            }
            User sellerUser = await UserHelp.QueryUserInfo(sellerUserId);

            User buyerUser = await UserHelp.QueryUserInfo(buyerUserId);

            if (buyerUser == null)
            {
                iResponse.Message = "买家不存在";
                return;
            }
            if (sellerUser.Jewel >= jewelNum)
            {
                UserHelp.GoodsChange(sellerUserId, GoodsId.Jewel, jewelNum * -1, GoodsChangeType.AgencyDeal);
                UserHelp.GoodsChange(buyerUserId, GoodsId.Jewel, jewelNum, GoodsChangeType.AgencyDeal);
                agencyComponent.RecordMarketInfo(sellerUserId, buyerUser, jewelNum);
                iResponse.Message = "销售成功";
            }
            else
            {
                iResponse.Message = "钻石不足";
            }
        }
        //完成支付
        public static async void FinishPay(this TopUpComponent topUpComponent, string outTradeNo, bool isRepairOrder = false)
        {
            DBProxyComponent   dbProxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
            List <TopUpRecord> topUpRecords     = await dbProxyComponent.Query <TopUpRecord>(topUpRecord => topUpRecord.OrderId.Equals(outTradeNo));

            if (topUpRecords.Count <= 0)
            {
                Log.Error("没有充值记录 订单id:" + outTradeNo);
            }
            else
            {
                TopUpRecord topUpRecord = topUpRecords[0];
                if (topUpRecord.TopUpState == TopUpStateType.NoPay)
                {
                    await UserHelp.GoodsChange(topUpRecord.TopUpUserId, topUpRecord.GoodsId, topUpRecord.GoodsAmount, GoodsChangeType.ShopPurchase);

                    topUpRecord.TopUpState = TopUpStateType.AlreadyPay;
                    if (isRepairOrder)
                    {
                        topUpRecord.TopUpState = TopUpStateType.RepairOrder;
                    }
                    await dbProxyComponent.Save(topUpRecord);
                }
                else
                {
                    Log.Error("订单id:" + outTradeNo + "订单已经完成 重复收到完成消息");
                }
            }
        }
示例#5
0
        protected override async void Run(Session session, C2L_GetEverydayShareAward message, Action <L2C_GetEverydayShareAward> reply)
        {
            L2C_GetEverydayShareAward response = new L2C_GetEverydayShareAward();

            try
            {
                List <EverydayShareInfo> everydayShareInfos = await GameLobby.Ins.dbProxyComponent.Query <EverydayShareInfo>(every => every.UserId == message.UserId);

                if (everydayShareInfos.Count > 0)
                {
                    if (TimeTool.TimeStampIsToday(everydayShareInfos[0].ShareTime))
                    {
                        response.Message = "今日已经领取过奖励";
                        reply(response);
                        return;
                    }
                    everydayShareInfos[0].ShareTime = TimeTool.GetCurrenTimeStamp();
                }
                else
                {
                    EverydayShareInfo everydayShareInfo = ComponentFactory.Create <EverydayShareInfo>();
                    everydayShareInfo.UserId    = message.UserId;
                    everydayShareInfo.ShareTime = TimeTool.GetCurrenTimeStamp();
                    everydayShareInfos.Add(everydayShareInfo);
                }
                UserHelp.GoodsChange(message.UserId, GoodsId.Jewel, GameLobby._TheFirstShareAwarNum, GoodsChangeType.EverydayShare, true);
                await GameLobby.Ins.dbProxyComponent.Save(everydayShareInfos[0]);

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
        public const int DarwLotteryConsumeJewelNum = 10;//抽奖消耗的钻石数量
        //玩家抽奖
        public static async Task <TurntableGoods> DarwLottery(this TurntableComponent turntableComponent, long userId, IResponse response)
        {
            List <FreeDrawLottery> freeDrawInfo = await turntableComponent.dbProxyComponent.Query <FreeDrawLottery>((free) => free.UserId == userId);

            if (freeDrawInfo.Count > 0 && freeDrawInfo[0].Count > 0)
            {
                freeDrawInfo[0].Count--;
                await turntableComponent.dbProxyComponent.Save(freeDrawInfo[0]);

                return(turntableComponent.RandomDarwLottery(userId));
            }
            else
            {
                User user = await UserHelp.QueryUserInfo(userId);

                if (user.Jewel >= DarwLotteryConsumeJewelNum)
                {
                    UserHelp.GoodsChange(userId, GoodsId.Jewel, DarwLotteryConsumeJewelNum * -1, GoodsChangeType.DrawLottery);//改变物品给用户服
                    return(turntableComponent.RandomDarwLottery(userId));
                }
                else
                {
                    response.Error   = 1;
                    response.Message = "钻石不足";
                }
            }
            return(null);
        }
示例#7
0
        //改变用户物品
        public static async Task GoodsChange(this User user, List <GetGoodsOne> getGoodsOnes, int changeType, bool isShowHint = false)
        {
            User newUser = await UserHelp.GoodsChange(user.UserId, getGoodsOnes, changeType, isShowHint);

            if (newUser != null)
            {
                user.Beans = newUser.Beans;
                user.Beans = newUser.Jewel;
            }
        }
示例#8
0
        //改变用户物品
        public static async Task GoodsChange(this User user, long goodId, int amount, int changeType, bool isShowHint = false, bool isSynchronizationGoods = true)
        {
            User newUser = await UserHelp.GoodsChange(user.UserId, goodId, amount, changeType, isShowHint);

            if (isSynchronizationGoods && newUser != null)
            {
                user.Beans = newUser.Beans;
                user.Beans = newUser.Jewel;
            }
        }
        //查询亲友创建者User
        public static async Task <User> GetFriendsCircleCreateUser(int friendsCircleId, IResponse iResponse)
        {
            List <FriendsCircle> friendsCircles = await Game.Scene.GetComponent <DBProxyComponent>().Query <FriendsCircle>(friends => (friends.FriendsCircleId == friendsCircleId));

            if (friendsCircles.Count <= 0)
            {
                iResponse.Message = "亲友圈不存在";
                return(null);
            }
            return(await UserHelp.QueryUserInfo(friendsCircles[0].CreateUserId));
        }
示例#10
0
        protected override async void Run(Session session, C2L_GetUserInfo message, Action <L2C_GetUserInfo> reply)
        {
            L2C_GetUserInfo response = new L2C_GetUserInfo();

            try
            {
                List <User> users = await UserHelp.QueryUserInfo(message.QueryUserIds);

                response.UserInfos.Add(users.ToArray());
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
 protected override async void Run(Session session, C2U_ChangeUserGoods message, Action<U2C_ChangeUserGoods> reply)
 {
     U2C_ChangeUserGoods response = new U2C_ChangeUserGoods();
     try
     {
         User user = await UserHelp.GoodsChange(message.ChangeUserUserId, message.GoodsId, message.Amount,GoodsChangeType.Administrator);
         if (user == null)
         {
             response.Message = "用户不存在";
         }
         reply(response);
     }
     catch (Exception e)
     {
         ReplyError(response, e, reply);
     }
 }
        //玩家上线事件
        public static async Task <User> UserOnLine(this GateUserComponent gateUserComponent, long userId, long sessionActorId)
        {
            User user = await UserHelp.QueryUserInfo(userId);

            if (user == null)
            {
                return(null);
            }
            user.IsOnLine = true;//改变在线状态
            //给其他服务器广播玩家上线消息
            gateUserComponent.BroadcastOnAndOffLineMessage(new G2S_UserOnline()
            {
                UserId = userId, SessionActorId = sessionActorId
            });
            //记录玩家信息
            gateUserComponent.mUserDic[userId] = user;
            return(user);
        }
        public static async Task GetGreenGift(this GeneralizeComponent generalizeComponent, long getUserId, long initeUserId, IResponse iResponse)
        {
            if (getUserId == initeUserId)
            {
                iResponse.Message = "邀请人不能是自己";
                return;
            }
            if (await generalizeComponent.GreenGiftGetStatu(getUserId))
            {
                iResponse.Message = "已经领取过礼包";
                return;
            }
            User user = await UserHelp.QueryUserInfo(initeUserId);

            if (user == null)
            {
                iResponse.Message = "邀请码不对";
                return;
            }
            //存储个领取新手奖励信息
            GetGreenGiftInfo getGreenGiftInfo = ComponentFactory.Create <GetGreenGiftInfo>();

            getGreenGiftInfo.GetUserId    = getUserId;
            getGreenGiftInfo.InviteUserId = initeUserId;
            getGreenGiftInfo.GetJewelNum  = GeneralizeComponent.AwardJewelNum;
            await generalizeComponent.dbProxyComponent.Save(getGreenGiftInfo);

            //存储推广奖励信息
            GeneralizeAwardInfo generalizeAwardInfo = await generalizeComponent.GetGeneralizeAwardInfo(initeUserId);

            if (generalizeAwardInfo == null)
            {
                generalizeAwardInfo = CreateGeneralizeAwardInfo(initeUserId);
            }
            generalizeAwardInfo.GeneralizeNumber++;
            generalizeAwardInfo.GetJewelTotalNum += GeneralizeComponent.AwardJewelNum;
            await generalizeComponent.dbProxyComponent.Save(generalizeAwardInfo);

            UserHelp.GoodsChange(getUserId, GoodsId.Jewel, GeneralizeComponent.AwardJewelNum, GoodsChangeType.GeneralizeAward, true);
            UserHelp.GoodsChange(initeUserId, GoodsId.Jewel, GeneralizeComponent.AwardJewelNum, GoodsChangeType.GeneralizeAward);
        }
示例#14
0
        //创建亲友圈
        public static async Task <FriendsCircle> CreatorFriendsCircle(this FriendsCircleComponent friendsCircleComponent,
                                                                      long creatorUserId, string name, string announcement, RepeatedField <int> roomConfigs, long toyGameId, IResponse iResponse)
        {
            User creatorUser = await UserHelp.QueryUserInfo(creatorUserId);

            if (creatorUser.Jewel < 200)
            {
                iResponse.Message = "钻石少于200无法创建亲友圈";
                return(null);
            }
            //效验配置 如果配置错误 会使用默认配置
            if (!RoomConfigIntended.IntendedRoomConfigParameter(roomConfigs, toyGameId))
            {
                iResponse.Message = "玩法配置错误 无法创建";
                return(null);
            }
            FriendsCircle friendsCircle = FriendsCircleFactory.Create(name, creatorUserId, roomConfigs, announcement);
            await friendsCircle.SucceedJoinFriendsCircle(creatorUserId); //成功加入到亲友圈 这个方法和保存亲友圈数据到数据库

            return(friendsCircle);
        }
示例#15
0
        protected override async void Run(Session session, C2L_GetReliefPayment message, Action <L2C_GetReliefPayment> reply)
        {
            L2C_GetReliefPayment response = new L2C_GetReliefPayment();

            try
            {
                List <ReliefPaymentInfo> reliefPaymentInfos = await GameLobby.Ins.dbProxyComponent.Query <ReliefPaymentInfo>(info => info.UserId == message.UserId);

                if (reliefPaymentInfos.Count <= 0)
                {
                    ReliefPaymentInfo reliefPaymentInfo = ComponentFactory.Create <ReliefPaymentInfo>();
                    reliefPaymentInfo.UserId = message.UserId;
                    reliefPaymentInfo.Number = 0;
                    reliefPaymentInfos.Add(reliefPaymentInfo);
                }
                if (!TimeTool.TimeStampIsToday(reliefPaymentInfos[0].Time))//如果上次领取的时机 不是今天 次数重置为0
                {
                    reliefPaymentInfos[0].Number = 0;
                }
                if (reliefPaymentInfos[0].Number >= GameLobby.ReliefPaymentNumber)
                {
                    response.Message = "今日领取救济金达到上限";
                    reply(response);
                    return;
                }
                reliefPaymentInfos[0].Time = TimeTool.GetCurrenTimeStamp(); //记录当前领取的时机
                reliefPaymentInfos[0].Number++;                             //领取的次数++
                //给用户加上豆子
                await UserHelp.GoodsChange(message.UserId, GoodsId.Besans, GameLobby.ReliefPaymentBeansNum,
                                           GoodsChangeType.None, false);

                await GameLobby.Ins.dbProxyComponent.Save(reliefPaymentInfos[0]);//存储 领取救济金信息

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
        //直接随机出现一个抽奖物品
        public static TurntableGoods RandomDarwLottery(this TurntableComponent turntableComponent, long userId)
        {
            int randNum         = RandomTool.Random(0, 100);//默认概率是 100 所有物品的概率加起来也是要100
            int currProbability = 0;

            for (int i = 0; i < turntableComponent.mTurntableGoodses.Count; i++)
            {
                currProbability += turntableComponent.mTurntableGoodses[i].Probability;
                if (randNum < currProbability)
                {
                    if (turntableComponent.mTurntableGoodses[i].GoodsId != GoodsId.None)
                    {
                        UserHelp.GoodsChange(userId, turntableComponent.mTurntableGoodses[i].GoodsId
                                             , turntableComponent.mTurntableGoodses[i].Amount, GoodsChangeType.DrawLottery); //改变物品给用户服
                    }
                    turntableComponent.RecordWinPrizeInfo(userId, turntableComponent.mTurntableGoodses[i]);                  //记录中奖信息
                    return(turntableComponent.mTurntableGoodses[i]);
                }
            }
            Log.Error("概率随机出现错误");
            return(null);
        }
 //发送玩家获得物品的信息
 public static async Task SendUserGetGoods(this SingInActivityComponent singInActivityComponent, long userId, int singInDays)
 {
     SignInAward signInAward = singInActivityComponent.mSignInAwardList[singInDays - 1];
     await UserHelp.GoodsChange(userId, signInAward.GoodsId, signInAward.Amount, GoodsChangeType.SignIn, true);
 }