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);
        }
Esempio n. 2
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 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);
        }
        //查询亲友创建者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));
        }
Esempio n. 5
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);
            }
        }
        //玩家上线事件
        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);
        }
Esempio n. 8
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);
        }