예제 #1
0
        private async void OnEnterRoom(int i)
        {
            try
            {
                UINetLoadingComponent.showNetLoading();

                RoomConfig roomConfig = ConfigHelp.Get <RoomConfig>(i);
                if (PlayerInfoComponent.Instance.GetPlayerInfo().GoldNum < roomConfig.MinThreshold)
                {
                    ToastScript.createToast("金币不足:" + roomConfig.MinThreshold);
                    UINetLoadingComponent.closeNetLoading();
                    return;
                }
                G2C_EnterRoom enterRoom = (G2C_EnterRoom)await Game.Scene.GetComponent <SessionComponent>().Session.Call(new C2G_EnterRoom()
                {
                    RoomType = i
                });

                PlayerInfoComponent.Instance.RoomType = i;
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
예제 #2
0
        [Get] // url-> /Login?name=11&age=1111
        public async Task <HttpResult> BuyYuanBao(int orderId, long userId, int goodsId, int goodsNum, float price, string account, string password)
        {
            Log.Info($"web请求发元宝,orderId:{orderId},userId:{userId},goodsId:{goodsId},price:{price}");
            try
            {
                if (!"admin".Equals(account) || !"jinyou123".Equals(password))
                {
                    return(Error("账号错误"));
                }

                ShopConfig config = ConfigHelp.Get <ShopConfig>(goodsId);

                if (config == null)
                {
                    return(Error("goodsId错误"));
                }

                if (price != config.Price)
                {
                    return(Error("支付的价格不正确"));
                }

                await DBCommonUtil.UserRecharge(orderId, userId, goodsId, goodsNum, price);

                return(Ok());
            }
            catch (Exception e)
            {
                Log.Error(e);
                return(Error());
            }
        }
예제 #3
0
        /// <summary>
        /// 发货接口
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="userId"></param>
        /// <param name="goodsId"></param>
        /// <param name="goodsNum"></param>
        /// <param name="price"></param>
        public static async Task UserRecharge(int orderId, long userId, int goodsId, int goodsNum, float price)
        {
            try
            {
                string           reward         = "";
                DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                ShopConfig       config         = ConfigHelp.Get <ShopConfig>(goodsId);

                List <Log_Recharge> log_Recharge = await proxyComponent.QueryJson <Log_Recharge>($"{{Uid:{userId}}}");

                if (log_Recharge.Count == 0)
                {
                    reward = "1:120000;105:20;104:1;107:1";
                    await DBCommonUtil.changeWealthWithStr(userId, reward, "首充奖励");
                }

                reward = config.Items;

                await DBCommonUtil.changeWealthWithStr(userId, reward, "购买元宝");

                //向gate服务器发送请求
                StartConfigComponent startConfig    = Game.Scene.GetComponent <StartConfigComponent>();
                IPEndPoint           gateIPEndPoint = startConfig.GateConfigs[0].GetComponent <InnerConfig>().IPEndPoint;
                Session gateSession = Game.Scene.GetComponent <NetInnerComponent>().Get(gateIPEndPoint);

                G2H_GamerCharge g2HGamerCharge = (G2H_GamerCharge)await gateSession.Call(new H2G_GamerCharge()
                {
                    goodsId = goodsId,
                    UId     = userId
                });

//                UserComponent userComponent = Game.Scene.GetComponent<UserComponent>();
//                User user = userComponent.Get(userId);
//                //给玩家发送消息
//                user?.session?.Send(new Actor_GamerBuyYuanBao()
//                {
//                    goodsId = goodsId
//                });

                // 记录日志
                {
                    Log_Recharge log_recharge = ComponentFactory.CreateWithId <Log_Recharge>(IdGenerater.GenerateId());
                    log_recharge.Uid     = userId;
                    log_recharge.GoodsId = config.Id;
                    log_recharge.Price   = config.Price;
                    log_recharge.OrderId = orderId;
                    await proxyComponent.Save(log_recharge);
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
예제 #4
0
        /// <summary>
        /// 更新成就
        /// </summary>
        /// <param name="UId"></param>
        /// <param name="taskId"></param>
        /// <param name="progress"></param>
        public static async Task UpdateChengjiu(long UId, int taskId, int progress)
        {
            DBProxyComponent    proxyComponent   = Game.Scene.GetComponent <DBProxyComponent>();
            List <ChengjiuInfo> chengjiuInfoList =
                await proxyComponent.QueryJson <ChengjiuInfo>($"{{UId:{UId},TaskId:{taskId}}}");

//            Log.Debug("UId:" + UId + " " + "更新成就" + taskId);
//            Log.Debug("用户:" + UId + "成就" + "taskId" + JsonHelper.ToJson(chengjiuInfoList));
            if (chengjiuInfoList.Count <= 0)
            {
//                Log.Debug("成就写入数据库");
                ChengjiuInfo   info   = ComponentFactory.CreateWithId <ChengjiuInfo>(IdGenerater.GenerateId());
                ChengjiuConfig config = ConfigHelp.Get <ChengjiuConfig>(taskId);
                info.IsGet = false;
                info.UId   = UId;
                if (config != null)
                {
                    info.Name        = config.Name;
                    info.TaskId      = (int)config.Id;
                    info.IsComplete  = false;
                    info.Target      = config.Target;
                    info.Reward      = config.Reward;
                    info.Desc        = config.Desc;
                    info.CurProgress = 0;
                }
                else
                {
                    Log.Warning("config:" + taskId + "数据为空");
                }
                await proxyComponent.Save(info);

                chengjiuInfoList =
                    await proxyComponent.QueryJson <ChengjiuInfo>($"{{UId:{UId},TaskId:{taskId}}}");

                //Log.Debug("用户:" + UId + "成就" + "taskId" + JsonHelper.ToJson(chengjiuInfoList));
            }
            if (chengjiuInfoList.Count > 0)
            {
                //Log.Debug("增加成就");
                chengjiuInfoList[0].CurProgress += progress;
                if (chengjiuInfoList[0].CurProgress >= chengjiuInfoList[0].Target)
                {
                    chengjiuInfoList[0].IsComplete = true;
                }
                else
                {
                    chengjiuInfoList[0].IsComplete = false;
                }

                await proxyComponent.Save(chengjiuInfoList[0]);
            }
        }
예제 #5
0
        /// <summary>
        /// 创建Room对象
        /// </summary>
        /// <param name="roomType"></param>
        /// <returns></returns>
        public static Room Create(int roomType)
        {
            try
            {
                Room idleRoom = ComponentFactory.Create <Room>();
                idleRoom.AddComponent <DeskComponent>();
                idleRoom.AddComponent <OrderControllerComponent>();
                idleRoom.IsFriendRoom = false;
                GameControllerComponent controllerComponent = idleRoom.AddComponent <GameControllerComponent>();
                controllerComponent.RoomConfig = ConfigHelp.Get <RoomConfig>(roomType);
                controllerComponent.RoomName   = (RoomName)roomType;

                Log.Debug("创建房间:" + JsonHelper.ToJson(controllerComponent.RoomConfig));
                return(idleRoom);
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
            return(null);
        }
예제 #6
0
        protected override async void Run(ETModel.Session session, Actor_GamerHuPai message)
        {
            try
            {
                Log.Info($"收到胡:");
                UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom);
                if (uiRoom == null)
                {
                    return;
                }

                GamerComponent     gamerComponent     = uiRoom.GetComponent <GamerComponent>();
                UIRoomComponent    uiRoomComponent    = uiRoom.GetComponent <UIRoomComponent>();
                Gamer              gamer              = gamerComponent.Get(message.Uid);
                HandCardsComponent handCardsComponent = gamer.GetComponent <HandCardsComponent>();

                SoundsHelp.Instance.PlayHuSound(gamer.PlayerInfo.PlayerSound);

                if (PlayerInfoComponent.Instance.uid == message.Uid)
                {
                    SoundsHelp.Instance.playSound_Win();
                }
                else
                {
                    SoundsHelp.Instance.playSound_Fail();
                }

                if (message.IsZiMo)
                {
                    handCardsComponent.ShowOperateAnimAsync((int)GamerOpearteType.zimo);
                }
                else
                {
                    handCardsComponent.ShowOperateAnimAsync((int)GamerOpearteType.Hu);
                }

                uiRoomComponent.exitBtn.gameObject.SetActive(false);

                await ETModel.Game.Scene.GetComponent <TimerComponent>().WaitAsync(1500);

                uiRoomComponent.exitBtn.gameObject.SetActive(true);
                if (gamerComponent.GetGamerCount() < 4)
                {
                    return;
                }

                UIGameResultComponent gameResultComponent =
                    Game.Scene.GetComponent <UIComponent>().Create(UIType.UIGameResult).GetComponent <UIGameResultComponent>();

                RoomConfig roomConfig;
                if (uiRoomComponent.RoomType == 3)
                {
                    roomConfig = uiRoomComponent.RoomConfig;
                    gameResultComponent.SetFriendRoom();
                    gameResultComponent.startTimer(5);
                }
                else
                {
                    roomConfig = ConfigHelp.Get <RoomConfig>(uiRoomComponent.RoomType);
                    gameResultComponent.startTimer(20);
                }
                gameResultComponent.setData(message, gamerComponent, roomConfig.Multiples);
                UIRoomComponent.ISGaming = false;
                uiRoomComponent.ClosePropmtBtn();
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
예제 #7
0
        protected override async void Run(Session session, C2G_BuyItem message, Action <G2C_BuyItem> reply)
        {
            G2C_BuyItem response = new G2C_BuyItem();

            try
            {
                DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>();

                ShopConfig config = ConfigHelp.Get <ShopConfig>(message.ShopId);
                int        shopId = CommonUtil.splitStr_Start(config.Items.ToString(), ':');
                int        count  = CommonUtil.splitStr_End(config.Items.ToString(), ':');
                int        cost   = 0;
                if (await DBCommonUtil.IsVIP(message.UId))
                {
                    cost = config.VipPrice;
                }
                else
                {
                    cost = config.Price;
                }

                await DBCommonUtil.ChangeWealth(message.UId, config.CurrencyType, -cost, $"花费{cost}元宝购买商品{config.Name}");

                List <PlayerBaseInfo> playerBaseInfos = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{message.UId}}}");

                switch (config.CurrencyType)
                {
                //金币
                case 1:
                    response.Wealth   = playerBaseInfos[0].GoldNum;
                    response.ShopType = 2;
                    break;

                //元宝
                case 2:
                    response.Wealth   = playerBaseInfos[0].WingNum;
                    response.ShopType = 1;
                    break;
                }
                //购买金币
                if (shopId == 1)
                {
                    await DBCommonUtil.ChangeWealth(message.UId, 1, count, $"商城购买{count}金币");
                }
                else if (shopId == 112)
                {
                    await DBCommonUtil.AddFriendKey(message.UId, count, "-1", $"商城购买{count}个{config.Name}道具");
                }
                else
                {
                    List <UserBag> itemInfos = await proxyComponent.QueryJson <UserBag>($"{{UId:{message.UId},BagId:{shopId}}}");

                    await DBCommonUtil.ChangeWealth(message.UId, shopId, count, $"商城购买{count}个{config.Name}道具");
                }

                response.Count = count;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
예제 #8
0
        /// <summary>
        /// 更新任务
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="taskId"></param>
        /// <param name="progress"></param>
        public static async Task UpdateTask(long uid, int taskId, int progress)
        {
            DBProxyComponent        proxyComponent       = Game.Scene.GetComponent <DBProxyComponent>();
            TaskInfo                taskInfo             = new TaskInfo();
            List <TaskProgressInfo> taskProgressInfoList =
                await proxyComponent.QueryJson <TaskProgressInfo>($"{{UId:{uid},TaskId:{taskId}}}");

            if (taskProgressInfoList.Count <= 0)
            {
                TaskProgressInfo info   = ComponentFactory.CreateWithId <TaskProgressInfo>(IdGenerater.GenerateId());
                TaskConfig       config = ConfigHelp.Get <TaskConfig>(taskId);
//                TaskConfig config = TaskData.getInstance().GetDataByTaskId(taskId);
                info.IsGet       = false;
                info.UId         = uid;
                info.Name        = config.Name;
                info.TaskId      = (int)config.Id;
                info.IsComplete  = false;
                info.Target      = config.Target;
                info.Reward      = config.Reward;
                info.Desc        = config.Desc;
                info.CurProgress = 0;

                await proxyComponent.Save(info);

                taskProgressInfoList =
                    await proxyComponent.QueryJson <TaskProgressInfo>($"{{UId:{uid},TaskId:{taskId}}}");
            }

            if (taskProgressInfoList.Count > 0)
            {
                /*
                 * progress = -1  代表输
                 * progress = 1  代表赢
                 */
                if (taskId == 104)
                {
                    if (!taskProgressInfoList[0].IsComplete)
                    {
                        if (progress == -1)
                        {
                            taskProgressInfoList[0].CurProgress = 0;
                            await proxyComponent.Save(taskProgressInfoList[0]);
                        }
                        else if (progress == 1)
                        {
                            taskProgressInfoList[0].CurProgress += progress;
                            if (taskProgressInfoList[0].CurProgress == taskProgressInfoList[0].Target)
                            {
                                taskProgressInfoList[0].IsComplete = true;
                            }

                            await proxyComponent.Save(taskProgressInfoList[0]);
                        }
                    }
                }
                else
                {
                    taskProgressInfoList[0].CurProgress += progress;
                    if (taskProgressInfoList[0].CurProgress >= taskProgressInfoList[0].Target)
                    {
                        taskProgressInfoList[0].IsComplete = true;
                    }

                    await proxyComponent.Save(taskProgressInfoList[0]);
                }
            }

            // 增加转盘次数
            if (taskId == 101)
            {
                if (taskProgressInfoList[0].CurProgress < 4)
                {
                    PlayerBaseInfo playerBaseInfo = await DBCommonUtil.getPlayerBaseInfo(uid);

                    ++playerBaseInfo.ZhuanPanCount;
                    await proxyComponent.Save(playerBaseInfo);
                }
            }

//            Log.Debug("UpdateTask111111111111");
        }