Exemple #1
0
        public static async Task <User> Create(int minBeansNum)
        {
            if (_AiMatchUsers == null)
            {
                await InitAIUsers();
            }
            if (++_AIUserUseIndex >= _AIUsers.Count)
            {
                _AIUserUseIndex = 0;
            }
            User userAi = _AIUsers[_AIUserUseIndex];

            _IconNameUseIndex++;
            if (_IconNameUseIndex >= _AINames.Count || _IconNameUseIndex >= _AIIcons.Count)
            {
                _IconNameUseIndex = 0;
            }
            userAi.Icon = _AIIcons[_IconNameUseIndex];
            userAi.Name = _AINames[_IconNameUseIndex];
            int oughtBeansNum = minBeansNum + RandomTool.Random(1, 10) * (minBeansNum / 10);
            int aiAddBeansNum = (int)(oughtBeansNum - userAi.Beans);

            userAi.Beans = oughtBeansNum;
            for (int i = 0; i < _AiMatchUsers.Count; i++)
            {
                if (_AiMatchUsers[i].UserId == userAi.UserId)
                {
                    _AiMatchUsers[i].BeansTotalResult += aiAddBeansNum;
                    await Game.Scene.GetComponent <DBProxyComponent>().Save(_AiMatchUsers[i]);

                    break;
                }
            }
            return(UserFactory.AIUserCopy(userAi));
        }
        //获取超时时间
        public static long GetOverTime(this FiveStarRoom fiveStarRoom, int playerSeatIndex, int overTimeType)
        {
            if (fiveStarRoom.FiveStarPlayerDic[playerSeatIndex].IsLiangDao && overTimeType == FiveStarOverTimeType.PlayCardType)
            {
                return(FiveStarRoomComponent.CurrTime + 1);//如果亮倒了 出牌 就一秒时间
            }
            if (!fiveStarRoom.RoomConfig.IsHaveOverTime)
            {
                return(0);//配置没有超时 直接返回0
            }
            if (fiveStarRoom.FiveStarPlayerDic[playerSeatIndex].IsAI)
            {
                return(FiveStarRoomComponent.CurrTime + RandomTool.Random(1, 4));//如果是AI加个随机值
            }
            if (overTimeType == FiveStarOverTimeType.DaPiaoType)
            {
                return(FiveStarRoomComponent.CurrTime + FiveStarOverTime.CanDaPiaoOverTime);
            }
            if (fiveStarRoom.FiveStarPlayerDic[playerSeatIndex].IsCollocation)
            {
                return(FiveStarRoomComponent.CurrTime + 1);
            }

            if (overTimeType == FiveStarOverTimeType.PlayCardType)
            {
                return(FiveStarRoomComponent.CurrTime + FiveStarOverTime.CanPlayCardOverTime);
            }
            else if (overTimeType == FiveStarOverTimeType.OperateType)
            {
                return(FiveStarRoomComponent.CurrTime + FiveStarOverTime.CanOperateOverTime);
            }
            return(0);
        }
Exemple #3
0
        //开始游戏
        public static void StartGame(this FiveStarRoom fiveStarRoom)
        {
            Actor_FiveStar_StartGame actorFiveStarStart = new Actor_FiveStar_StartGame();

            actorFiveStarStart.RoomConfigs = fiveStarRoom.RoomConfig.Configs;
            actorFiveStarStart.RoomId      = fiveStarRoom.RoomId;
            if (fiveStarRoom.RoomType == RoomType.Match)
            {
                actorFiveStarStart.RoomId = fiveStarRoom.MathRoomId;
            }

            foreach (var player in fiveStarRoom.FiveStarPlayerDic.Values)
            {
                //因为有些对象不能进行序列化 就必须重新复制一份
                actorFiveStarStart.PlayerInfos.Add(FiveStarPlayerFactory.CopySerialize(player));
            }
            foreach (var player in fiveStarRoom.FiveStarPlayerDic)
            {
                player.Value.StartGame(actorFiveStarStart);
            }
            //第一局随机出一个休息的玩家
            fiveStarRoom.NextRestSeatIndex = RandomTool.Random(1, fiveStarRoom.RoomConfig.RoomNumber); //不能为0 因为0要第一个摸牌
            fiveStarRoom.SmallStartGame();                                                             //小局开始游戏
            //用来发送消息的序列化对象 放入简易对象池 不能直接销毁 因为会改变一些东西
            foreach (var player in actorFiveStarStart.PlayerInfos)
            {
                FiveStarPlayerFactory.DisposeSerializePlayer(player);
            }
        }
        //延迟打漂AI打漂
        public static async void AIDelayDaPiao(this FiveStarPlayer fiveStarPlayer)
        {
            if (!fiveStarPlayer.IsAI)//不是AI直接 返回
            {
                return;
            }
            await Game.Scene.GetComponent <TimerComponent>().WaitAsync(RandomTool.Random(1, 4) * 1000);

            fiveStarPlayer.CollocationAIOperate();
        }
        //随机一个房间号 不与之前的重复
        public static int RandomRoomId(this MatchRoomComponent matchRoomComponent)
        {
            int roomId = RandomTool.Random(10000, 99999);

            while (matchRoomComponent.MatchRoomDic.ContainsKey(roomId))
            {
                roomId = RandomTool.Random(10000, 99999);
                Log.Info("随机生成房间号:" + roomId);
            }
            return(roomId);
        }
Exemple #6
0
 public long GetShowUserId()
 {
     if (UserId >= 1000)
     {
         return(UserId);
     }
     if (_showUserId == 0)
     {
         _showUserId = RandomTool.Random(1235, 9999);
     }
     return(_showUserId);
 }
Exemple #7
0
        //如果是匹配模式 并且有AI参与
        public static RepeatedField <RepeatedField <int> > AIDealCards(int number)
        {
            RepeatedField <RepeatedField <int> > distrbuteCards = new RepeatedField <RepeatedField <int> >();
            RepeatedField <int> initCards = new RepeatedField <int>()
            {
                mInitCards
            };

            //获取必赢的牌
            RepeatedField <int> sureWinCards = new RepeatedField <int>();

            for (int i = 0; i < 4; i++)
            {
                int shunZiStart = RandomTool.Random(1, 17);
                while (shunZiStart == 8 || shunZiStart == 9)
                {
                    shunZiStart = RandomTool.Random(1, 17);
                }
                for (int j = 0; j < 3; j++)
                {
                    sureWinCards.Add(shunZiStart + j);
                    initCards.Remove(shunZiStart + j);
                }
            }
            int jiangNum = RandomTool.Random(1, 22);

            while (sureWinCards.Contains(jiangNum))
            {
                jiangNum = RandomTool.Random(1, 22);
            }
            sureWinCards.Add(jiangNum);
            sureWinCards.Add(jiangNum);
            initCards.Remove(jiangNum);
            initCards.Remove(jiangNum);
            int winCardIndex = RandomTool.Random(0, sureWinCards.Count);
            int winCard      = sureWinCards[winCardIndex];

            sureWinCards.Remove(winCard);
            sureWinCards.Add(winCard);
            //将牌打乱获取正常玩家的牌
            initCards.RandomBrakRank();
            for (int i = 0; i < number; i++)
            {
                distrbuteCards.Add(initCards.TakeOutCards(DealCardCount));
            }
            initCards.AddRange(sureWinCards);
            distrbuteCards.Add(initCards);
            return(distrbuteCards);
        }
Exemple #8
0
        public async void PlayAnim()
        {
            if (isAnimIn)
            {
                return;
            }

            isAnimIn = true;
            while (gameObject.activeInHierarchy)
            {
                _LanternVector.z = (float)RandomTool.Random(LanternRange / 2, LanternRange) * RangePlus;
                _AigletVector.z  = (float)RandomTool.Random(AigletRange / 2, AigletRange) * RangePlus;
                gameObject.transform.DOLocalRotate(_LanternVector, 3f);
                _AigletGo.transform.DOLocalRotate(_AigletVector, 3f);
                RangePlus = RangePlus * -1;
                await ETModel.Game.Scene.GetComponent <TimerComponent>().WaitAsync(2000);
            }
            isAnimIn = false;
        }
        //直接随机出现一个抽奖物品
        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);
        }
Exemple #10
0
        public static async Task <AccountInfo> EditRegisterCreatUser(string account)
        {
            User user = ComponentFactory.Create <User>();

            user.Icon   = string.Empty;
            user.Name   = "小明" + RandomTool.Random(0, 1000);
            user.Beans  = UserConfigComponent.Ins.InitUserBeans.Value;
            user.Jewel  = UserConfigComponent.Ins.InitUserJewel.Value;
            user.UserId = ++UserConfigComponent.Ins.MaximumUserId;
            user.Sex    = SexType.WoMan;//游客或者编辑登陆 性别默认是女
            await Game.Scene.GetComponent <DBProxyComponent>().Save(user);

            AccountInfo accountInfo = ComponentFactory.Create <AccountInfo>();

            accountInfo.UserId     = user.UserId;
            accountInfo.Account    = account;
            accountInfo.Password   = string.Empty;
            accountInfo.IsStopSeal = false;
            await Game.Scene.GetComponent <DBProxyComponent>().Save(accountInfo);

            return(accountInfo);
        }
        //托管的默认操作
        public static void CollocationAIOperate(this FiveStarPlayer fiveStarPlayer)
        {
            if (fiveStarPlayer.FiveStarRoom.CurrRoomStateType == RoomStateType.GameIn)
            {
                fiveStarPlayer.boolData = true;
                if (fiveStarPlayer.FiveStarRoom.IsDaPiaoBeing && (!fiveStarPlayer.IsAlreadyDaPiao)) //如果在打漂中 并且自己没有打漂就打漂
                {
                    if (fiveStarPlayer.IsAI)                                                        //如果是AI就随便漂
                    {
                        fiveStarPlayer.DaPiao(
                            RandomTool.Random(0, fiveStarPlayer.FiveStarRoom.RoomConfig.MaxPiaoNum + 1)); //随机打漂
                    }
                    else
                    {
                        fiveStarPlayer.DaPiao(0); //默认是不漂
                    }
                }
                else if (fiveStarPlayer.IsCanPlayCard)                                                   //如果可以出牌 直接出 最后摸到的牌
                {
                    if (fiveStarPlayer.IsAI)                                                             //如果是AI出牌 保留手牌中有多张相同的
                    {
                        fiveStarPlayer.Hands.Sort();                                                     //手牌排序
                        fiveStarPlayer.intData = fiveStarPlayer.Hands.IndexOf(fiveStarPlayer.MoEndHand); //获取摸到的牌 首次出现的位置

                        if (fiveStarPlayer.intData < fiveStarPlayer.Hands.Count - 2 && fiveStarPlayer.Hands[fiveStarPlayer.intData + 1] == fiveStarPlayer.MoEndHand)
                        {
                            fiveStarPlayer.AICollcationPlayCard(fiveStarPlayer.Hands[fiveStarPlayer.Hands.Count - 1]); //摸到的牌有相同的 出牌组里最后一张牌
                        }
                        else
                        {
                            fiveStarPlayer.AICollcationPlayCard(fiveStarPlayer.MoEndHand); //没有相同的出摸到的牌
                        }
                    }
                    else
                    {
                        fiveStarPlayer.AICollcationPlayCard(fiveStarPlayer.MoEndHand); //不是AI出牌直接出 最后摸到的牌
                    }
                }
                else if (fiveStarPlayer.FiveStarRoom.CanOperatePlayerIndex.Contains(fiveStarPlayer.SeatIndex)
                         ) //如果玩家可操作索引列表里面有自己 则直接操作
                {
                    FiveStarOperateInfo fiveStarOperateInfo;
                    if (fiveStarPlayer.canOperateLists.Contains(FiveStarOperateType.FangChongHu)) //如果可以胡 就胡
                    {
                        fiveStarOperateInfo = FiveStarOperateInfoFactory.Create(0, FiveStarOperateType.FangChongHu, 0);
                    }
                    else
                    {
                        fiveStarOperateInfo =
                            FiveStarOperateInfoFactory.Create(0, FiveStarOperateType.None, 0); //不能胡就放弃
                    }
                    if (fiveStarPlayer.IsAI)                                                   //如果是AI 就是能碰就碰 能杠就杠 因为发的牌会做特殊手脚
                    {
                        if (fiveStarPlayer.canOperateLists.Contains(FiveStarOperateType.Peng)) //如果可以胡 就胡
                        {
                            fiveStarOperateInfo.OperateType = FiveStarOperateType.Peng;
                        }
                        else if (fiveStarPlayer.canOperateLists.Contains(FiveStarOperateType.MingGang))
                        {
                            //杠牌 不仅需要传递 操作类型 还是传杠那张牌 之前记录亮了
                            foreach (var canGang in fiveStarPlayer.canGangCards)
                            {
                                fiveStarOperateInfo.Card        = canGang.Key;
                                fiveStarOperateInfo.OperateType = canGang.Value;
                            }
                        }
                    }
                    fiveStarPlayer.OperatePengGangHu(fiveStarOperateInfo); //执行操作
                    //不能销毁 fiveStarPlayer 因为多人操作会保留一段时间
                }
                else
                {
                    fiveStarPlayer.boolData = false;
                }
                if (fiveStarPlayer.boolData)
                {
                    fiveStarPlayer.SetCollocation(true); //如果进行了 托管操作 就进入托管
                }
            }
        }
 public async ETTask RandomPlaySifterNum()
 {
     await PlaySifterAnim(RandomTool.Random(1, 7), RandomTool.Random(1, 7));
 }