public RaiderPlayerBetInfo FindWinner()
        {
            int ranCount = _ran.Next(2, 10);

            int winnerNumber = 0;

            for (int i = 0; i < ranCount; i++)
            {
                winnerNumber = _ran.Next(this._currentRoundInfo.AwardPoolSumStones);
            }

            RaiderPlayerBetInfo winnerBetInfo = null;

            int sum = 0;

            for (int i = 0; i < this.listPlayerBetInfos.Count; i++)
            {
                if (winnerNumber <= sum + this.listPlayerBetInfos[i].BetStones)
                {
                    winnerBetInfo = this.listPlayerBetInfos[i];
                    break;
                }
                sum += this.listPlayerBetInfos[i].BetStones;
            }

            if (winnerBetInfo == null)
            {
                winnerBetInfo = this.listPlayerBetInfos[this.listPlayerBetInfos.Count - 1];
            }

            return(winnerBetInfo);
        }
        public int Join(int userID, string userName, int roundID, int stonesCount)
        {
            lock (_lockJoin)
            {
                if (roundID != this._currentRoundInfo.ID)
                {
                    return(OperResult.RESULTCODE_FALSE);
                }
                if (this._currentRoundInfo.State == RaiderRoundState.Finished)
                {
                    return(OperResult.RESULTCODE_GAME_RAIDER_ROUNDFINISHED);
                }

                if (!this.listPlayerUserName.Contains(userName))
                {
                    this.listPlayerUserName.Add(userName);
                    this._currentRoundInfo.JoinedPlayerCount++;
                }

                this._currentRoundInfo.AwardPoolSumStones += stonesCount;

                if (this._currentRoundInfo.State == RaiderRoundState.Waiting && this._currentRoundInfo.JoinedPlayerCount >= 2)
                {
                    StartRound();
                }
            }

            var betInfo = new RaiderPlayerBetInfo()
            {
                UserID        = userID,
                UserName      = userName,
                RaiderRoundID = _currentRoundInfo.ID,
                BetStones     = stonesCount,
                Time          = MyDateTime.FromDateTime(DateTime.Now)
            };

            //如果保存数据库不成功,将异常抛到外层
            DBProvider.GameRaiderofLostArkDBProvider.SavePlayerBetInfo(betInfo);
            listPlayerBetInfos.Add(betInfo);

            if (this._currentRoundInfo.JoinedPlayerCount >= 2)
            {
                return(OperResult.RESULTCODE_TRUE);
            }
            else
            {
                return(OperResult.RESULTCODE_GAME_RAIDER_WAITINGSECONDPLAYERJOIN_TOSTART);
            }
        }
示例#3
0
        public bool SavePlayerBetInfo(RaiderPlayerBetInfo betInfo)
        {
            MySqlConnection myconn = null;
            MySqlCommand    mycmd  = null;

            try
            {
                myconn = MyDBHelper.Instance.CreateConnection();
                myconn.Open();
                //1. Save to DB

                string sqlTextA = "";

#if V1
                sqlTextA = "insert into  raiderplayerbetinfo (`RaiderRoundID`,`UserID`,`UserName`,`BetStones`,`Time`) values ( @RaiderRoundID,@UserID,@UserName,@BetStones,@Time) ;";
#else
                sqlTextA = "insert into  raiderplayerbetinfo (`RaiderRoundID`,`UserID`,`BetStones`,`Time`) values ( @RaiderRoundID,@UserID,@BetStones,@Time) ;";
#endif

                mycmd             = myconn.CreateCommand();
                mycmd.CommandText = sqlTextA;
                mycmd.Parameters.AddWithValue("@RaiderRoundID", betInfo.RaiderRoundID);
                mycmd.Parameters.AddWithValue("@UserID", betInfo.UserID);
#if V1
                mycmd.Parameters.AddWithValue("@UserName", DESEncrypt.EncryptDES(betInfo.UserName));
#endif
                mycmd.Parameters.AddWithValue("@BetStones", betInfo.BetStones);
                mycmd.Parameters.AddWithValue("@Time", betInfo.Time.ToDateTime());
                mycmd.ExecuteNonQuery();
                return(true);
            }
            finally
            {
                if (mycmd != null)
                {
                    mycmd.Dispose();
                }
                MyDBHelper.Instance.DisposeConnection(myconn);
            }
        }
        void FinishRound(object sender, ElapsedEventArgs e)
        {
            this._timer.Stop();

            try
            {
                lock (_lockJoin)
                {
                    if (this._currentRoundInfo.State == MetaData.Game.RaideroftheLostArk.RaiderRoundState.Finished)
                    {
                        return;
                    }
                    this._currentRoundInfo.State = RaiderRoundState.Finished;
                    if (this.listPlayerBetInfos.Count == 0)
                    {
                        return;
                    }

                    RaiderPlayerBetInfo winnerBetInfo = FindWinner();
                    var winnerPersonAllBetCount       = this.listPlayerBetInfos.Where(b => b.UserID == winnerBetInfo.UserID).Sum(b => b.BetStones);
                    int expense            = (int)Math.Ceiling(this._currentRoundInfo.AwardPoolSumStones * GlobalConfig.GameConfig.RaiderExpense);
                    int winnerGainBetCount = this._currentRoundInfo.AwardPoolSumStones - expense;
                    if (winnerGainBetCount < winnerPersonAllBetCount)
                    {
                        winnerGainBetCount = winnerPersonAllBetCount;
                    }

                    this._currentRoundInfo.EndTime        = new MyDateTime(DateTime.Now);
                    this._currentRoundInfo.WinnerUserName = winnerBetInfo.UserName;
                    this._currentRoundInfo.WinStones      = winnerGainBetCount;

                    bool isOK = false;
                    CustomerMySqlTransaction myTrans = null;
                    try
                    {
                        myTrans = MyDBHelper.Instance.CreateTrans();
                        DBProvider.GameRaiderofLostArkDBProvider.UpdateRaiderRoundMetaDataInfo(this._currentRoundInfo, myTrans);
                        int result = PlayerController.Instance.WinRaiderGetAward(winnerBetInfo.UserName, winnerGainBetCount, myTrans);
                        if (result != OperResult.RESULTCODE_TRUE)
                        {
                            LogHelper.Instance.AddErrorLog("夺宝奇兵给玩家返奖失败。" + this._currentRoundInfo.ToString(), null);
                        }
                        myTrans.Commit();
                        isOK = true;
                    }
                    catch (Exception exc)
                    {
                        myTrans.Rollback();
                        isOK = false;
                        LogHelper.Instance.AddErrorLog("RaiderofLostArk Finish Round SaveTo DB Exception. Round Info: " + this._currentRoundInfo.ToString(), exc);
                    }
                    finally
                    {
                        if (myTrans != null)
                        {
                            myTrans.Dispose();
                        }
                    }

                    if (isOK)
                    {
                        if (NotifyAllPlayerRaiderWinnerEvent != null)
                        {
                            NotifyAllPlayerRaiderWinnerEvent(this._currentRoundInfo);
                        }

                        //10秒后再开始下一轮。
                        System.Threading.Thread.Sleep(10 * 1000);

                        CreateNewRound();
                    }
                }
            }
            catch (Exception exc)
            {
                LogHelper.Instance.AddErrorLog("RaiderofLostArk Finish Round Exception. Round Info: " + this._currentRoundInfo.ToString(), exc);
            }
        }
示例#5
0
 public RaiderPlayerBetInfoUIModel(RaiderPlayerBetInfo parent)
 {
     this.ParentObject = parent;
 }