Пример #1
0
 private void NotifyWinnedPlayer(Dictionary <int, int> dicPlayerBetStoneCount)
 {
     foreach (var userID in dicPlayerBetStoneCount.Keys)
     {
         string userName = null;
         GambleStonePlayerBetRecord playerBetRecord = null;
         playerBetRecord = this._dicPlayerBetRecord[userID];
         userName        = this._dicPlayerBetRecord[userID].UserName;
         PlayerController.Instance.NotifyChanged(userName);
     }
 }
Пример #2
0
        private GambleStonePlayerBetRecord WinToUpdatePlayer(Dictionary <int, int> dicPlayerBetStoneCount, int winTimes, CustomerMySqlTransaction myTrans)
        {
            int maxWinnedUserID;
            int maxWinnedStone = 0;

            foreach (var kv in dicPlayerBetStoneCount)
            {
                int userID      = kv.Key;
                int winnedStone = kv.Value * winTimes;
                if (winnedStone > maxWinnedStone)
                {
                    maxWinnedStone  = winnedStone;
                    maxWinnedUserID = userID;
                }

                string userName = null;
                GambleStonePlayerBetRecord playerBetRecord = null;
                if (this._dicPlayerBetRecord.ContainsKey(userID))
                {
                    playerBetRecord = this._dicPlayerBetRecord[userID];
                    userName        = this._dicPlayerBetRecord[userID].UserName;
                }
                if (string.IsNullOrEmpty(userName))
                {
                    LogHelper.Instance.AddErrorLog("Gamble NotifyWinnedPlayer Not find PlayerInfo in _dicPlayerBetRecord ", null);
                    var player = PlayerController.Instance.GetPlayerInfoByUserID(userID);
                    userName = player.SimpleInfo.UserName;
                }

                PlayerController.Instance.WinGambleStone(userName, winnedStone, myTrans);
                if (playerBetRecord != null)
                {
                    playerBetRecord.WinnedStone += winnedStone;
                }
            }

            int maxWinnedStoneCount = 0;
            GambleStonePlayerBetRecord maxWinnedBetRecord = null;

            foreach (var item in this._dicPlayerBetRecord.Values)
            {
                if (item.WinnedStone > maxWinnedStoneCount)
                {
                    maxWinnedBetRecord  = item;
                    maxWinnedStoneCount = item.WinnedStone;
                }
                DBProvider.GambleStoneDBProvider.AddGambleStonePlayerBetRecord(item, this._roundInfo.TableName, myTrans);
            }

            return(maxWinnedBetRecord);
        }
Пример #3
0
 private void RecoverPlayerFortune(Dictionary <int, int> dicPlayerBetStoneCount)
 {
     if (dicPlayerBetStoneCount == null)
     {
         return;
     }
     foreach (var userID in dicPlayerBetStoneCount.Keys)
     {
         string userName = null;
         GambleStonePlayerBetRecord playerBetRecord = null;
         playerBetRecord = this._dicPlayerBetRecord[userID];
         userName        = this._dicPlayerBetRecord[userID].UserName;
         PlayerController.Instance.RefreshFortune(userName);
     }
 }
Пример #4
0
        public bool AddGambleStonePlayerBetRecord(GambleStonePlayerBetRecord playerBetRecord, string tableNameSuffix, CustomerMySqlTransaction myTrans)
        {
            MySqlCommand mycmd = null;

            try
            {
                string tableName = GambleStonePlayerBetRecordTableNamePrefix + tableNameSuffix;
                mycmd = myTrans.CreateCommand();
                string sqlSelectTableText = "show tables where Tables_in_" + MyDBHelper.DataBaseServerName + " = @tableName ";
                mycmd.CommandText = sqlSelectTableText;
                mycmd.Parameters.AddWithValue("@tableName", tableName);
                DataTable        table   = new DataTable();
                MySqlDataAdapter adapter = new MySqlDataAdapter(mycmd);
                adapter.Fill(table);
                adapter.Dispose();
                if (table.Rows.Count == 0)
                {
                    //表不存在,则创建
                    mycmd.CommandText = string.Format(this.sqlCreateGambleStonePlayerBetRecordTable, tableNameSuffix);
                    mycmd.ExecuteNonQuery();
                }

                string sqlText = "insert into " + tableName + " (`UserID`,`Time`,`RoundID`,`InningID`,`InningIndex`,`BetRedStone`,`BetGreenStone`,`BetBlueStone`,`BetPurpleStone`,`WinnedStone`) " +
                                 " values (@UserID,@Time,@RoundID,@InningID,@InningIndex,@BetRedStone,@BetGreenStone,@BetBlueStone,@BetPurpleStone,@WinnedStone ) ";
                mycmd.CommandText = sqlText;
                mycmd.Parameters.AddWithValue("@UserID", playerBetRecord.UserID);
                mycmd.Parameters.AddWithValue("@Time", playerBetRecord.Time.ToDateTime());
                mycmd.Parameters.AddWithValue("@RoundID", playerBetRecord.RoundID);
                mycmd.Parameters.AddWithValue("@InningID", playerBetRecord.InningID);
                mycmd.Parameters.AddWithValue("@InningIndex", playerBetRecord.InningIndex);
                mycmd.Parameters.AddWithValue("@BetRedStone", playerBetRecord.BetRedStone);
                mycmd.Parameters.AddWithValue("@BetGreenStone", playerBetRecord.BetGreenStone);
                mycmd.Parameters.AddWithValue("@BetBlueStone", playerBetRecord.BetBlueStone);
                mycmd.Parameters.AddWithValue("@BetPurpleStone", playerBetRecord.BetPurpleStone);
                mycmd.Parameters.AddWithValue("@WinnedStone", playerBetRecord.WinnedStone);
                mycmd.ExecuteNonQuery();

                return(true);
            }
            finally
            {
                mycmd.Dispose();
            }
        }
Пример #5
0
 public GambleStonePlayerBetRecordUIModel(GambleStonePlayerBetRecord parent)
 {
     this.ParentObject = parent;
 }
Пример #6
0
        void Client_OnGambleStoneWinNotify(GambleStoneRoundInfo roundInfo, GambleStoneInningInfo inningInfo, GambleStonePlayerBetRecord maxWinner)
        {
            try
            {
                //this.CurrentRoundInfo.ParentObject = roundInfo;
                this.CurrentInningInfo.ParentObject = inningInfo;
                this.CurrentRoundInfo.SetWinnedInningColor(inningInfo.InningIndex - 1, inningInfo.WinnedColor);

                if (GambleStoneInningFinished != null)
                {
                    GambleStoneInningFinished(inningInfo, maxWinner);
                }

                //if (!string.IsNullOrEmpty(this.CurrentInningPlayerBetRecord.InningID))
                {
                    this.CurrentInningPlayerBetRecord.Clear();
                    App.UserVMObject.AsyncGetPlayerInfo();
                }

                //if (maxWinner != null && !string.IsNullOrEmpty(maxWinner.UserName))
                //{
                //    MyMessageBox.ShowInfo(maxWinner.UserName + " 赢得 " + maxWinner.WinnedStone + " 矿石");
                //}
            }
            catch (Exception exc)
            {
                MyMessageBox.ShowInfo("疯狂猜石开奖失败。");
                LogHelper.Instance.AddErrorLog("疯狂猜石开奖失败。", exc);
            }
        }
        void GambleStoneVMObject_GambleStoneInningFinished(GambleStoneInningInfo inningInfo, GambleStonePlayerBetRecord maxWinner)
        {
            _syn.Post(o =>
            {
                if (maxWinner == null || string.IsNullOrEmpty(maxWinner.UserName) || maxWinner.WinnedStone == 0)
                {
                    this.txtWinnerNotice.Text = "";
                }
                else
                {
                    this.txtWinnerNotice.Text = maxWinner.UserName + " 赢得 " + maxWinner.WinnedStone + " 矿石";
                }

                if (inningInfo != null && inningInfo.InningIndex > 0 && inningInfo.InningIndex <= 64)
                {
                    BitmapImage bmp = null;
                    switch (inningInfo.WinnedColor)
                    {
                    case GambleStoneItemColor.Red:
                        //bmp = new BitmapImage(new Uri(@"../../Resources/gamblered.png", UriKind.Relative));
                        bmp = bmpRed;
                        break;

                    case GambleStoneItemColor.Green:
                        //bmp = new BitmapImage(new Uri(@"../../Resources/gamblegreen.png", UriKind.Relative));
                        bmp = bmpGreen;
                        break;

                    case GambleStoneItemColor.Blue:
                        //bmp = new BitmapImage(new Uri(@"../../Resources/gambleblue.png", UriKind.Relative));
                        bmp = bmpBlue;
                        break;

                    case GambleStoneItemColor.Purple:
                        //bmp = new BitmapImage(new Uri(@"../../Resources/gambleyellow.png", UriKind.Relative));
                        bmp = bmpPurple;
                        break;

                    default:
                        break;
                    }

                    //this.imgCurrentWinnedColor.Source = bmp;
                    this.imgSplitStone1.Visibility = System.Windows.Visibility.Visible;
                    this.imgSplitStone2.Visibility = System.Windows.Visibility.Visible;
                    this.imgSplitStone3.Visibility = System.Windows.Visibility.Visible;
                    this.imgSplitStone4.Visibility = System.Windows.Visibility.Visible;

                    SetNewValueToStoryboard(inningInfo.InningIndex - 1, bmp);
                    Storyboard StoryboardOpenGamble = this.FindResource("StoryboardOpenGamble") as Storyboard;
                    if (StoryboardOpenGamble != null)
                    {
                        StoryboardOpenGamble.Begin();
                    }
                }
            }, null);
        }
        public void RaiseOnGambleStoneWinNotify(GambleStoneRoundInfo roundInfo, GambleStoneInningInfo inningInfo, GambleStonePlayerBetRecord maxWinner)
        {
            Action <GambleStoneRoundInfo, GambleStoneInningInfo, GambleStonePlayerBetRecord> handler = this.OnGambleStoneWinNotify;

            if (null != handler)
            {
                handler(roundInfo, inningInfo, maxWinner);
            }
        }
Пример #9
0
        public int SaveInningInfoToDB()
        {
            Dictionary <int, int> dicWinnedPlayerBetStoneCount = null;
            int winnedTimes = 0;

            GambleStonePlayerBetRecord maxWinner = null;
            int result = MyDBHelper.Instance.TransactionDataBaseOper(myTrans =>
            {
                DBProvider.GambleStoneDBProvider.AddGambleStoneInningInfo(this._roundInfo, this._inningInfo, myTrans);
                switch (this._inningInfo.WinnedColor)
                {
                case GambleStoneItemColor.Red:
                    dicWinnedPlayerBetStoneCount = this._dicPlayerBetRedStone;
                    winnedTimes = GlobalConfig.GameConfig.GambleStoneRedColorWinTimes;
                    break;

                case GambleStoneItemColor.Green:
                    dicWinnedPlayerBetStoneCount = this._dicPlayerBetGreenStone;
                    winnedTimes = GlobalConfig.GameConfig.GambleStoneGreenColorWinTimes;
                    break;

                case GambleStoneItemColor.Blue:
                    dicWinnedPlayerBetStoneCount = this._dicPlayerBetBlueStone;
                    winnedTimes = GlobalConfig.GameConfig.GambleStoneBlueWinTimes;
                    break;

                case GambleStoneItemColor.Purple:
                    dicWinnedPlayerBetStoneCount = this._dicPlayerBetPurpleStone;
                    winnedTimes = GlobalConfig.GameConfig.GambleStonePurpleWinTimes;
                    break;

                default:
                    break;
                }

                maxWinner = WinToUpdatePlayer(dicWinnedPlayerBetStoneCount, winnedTimes, myTrans);
                if (this._roundInfo.FinishedInningCount >= GlobalConfig.GameConfig.GambleStone_Round_InningCount)
                {
                    this._roundInfo.EndTime = new MyDateTime(DateTime.Now);
                }
                DBProvider.GambleStoneDBProvider.UpdateGambleStoneRoundInfo(this._roundInfo, myTrans);
                return(OperResult.RESULTCODE_TRUE);
            },
                                                                     exc =>
            {
                if (exc != null)
                {
                    LogHelper.Instance.AddErrorLog("赌石游戏,保存异常。局信息:" + this.InningInfo.ToString(), exc);
                }
                if (dicWinnedPlayerBetStoneCount != null)
                {
                    foreach (var userID in dicWinnedPlayerBetStoneCount.Keys)
                    {
                        PlayerController.Instance.RefreshFortune(this._dicPlayerBetRecord[userID].UserName);
                    }
                }
            });

            if (result == OperResult.RESULTCODE_TRUE)
            {
                LogHelper.Instance.AddInfoLog("赌石游戏,保存成功。局信息:" + this.InningInfo.ToString());

                if (maxWinner == null)
                {
                    maxWinner = new GambleStonePlayerBetRecord();
                }

                if (!string.IsNullOrEmpty(maxWinner.UserName))
                {
                    PlayerActionController.Instance.AddLog(maxWinner.UserName, MetaData.ActionLog.ActionType.GambleStoneMaxWinner, maxWinner.WinnedStone);
                }
                if (this.GambleStoneInningWinnedNotifyAllClient != null)
                {
                    this.GambleStoneInningWinnedNotifyAllClient(this._roundInfo, this.InningInfo, maxWinner);
                }
                //NotifyWinnedPlayer(dicWinnedPlayerBetStoneCount);
            }
            else
            {
                RecoverPlayerFortune(dicWinnedPlayerBetStoneCount);
            }

            return(result);
        }
Пример #10
0
        public GambleStonePlayerBetInResult BetIn(int roundID, GambleStoneItemColor color, int stoneCount, int userID, string userName)
        {
            lock (_lockBetIn)
            {
                GambleStonePlayerBetInResult result = new GambleStonePlayerBetInResult();

                //客户端倒计时5秒内,不再允许下游。以防止计算错误
                if (this._inningInfo.State != GambleStoneInningStatusType.BetInWaiting)
                {
                    LogHelper.Instance.AddInfoLog("State: " + this._inningInfo.State.ToString());
                    result.ResultCode = OperResult.RESULTCODE_GAME_GAMBLE_INNINGFINISHED;
                    return(result);
                }

                GambleStonePlayerBetRecord betrecord = null;
                if (this._dicPlayerBetRecord.ContainsKey(userID))
                {
                    betrecord = this._dicPlayerBetRecord[userID];
                }
                else
                {
                    betrecord = new GambleStonePlayerBetRecord()
                    {
                        UserID      = userID,
                        UserName    = userName,
                        InningID    = this._inningInfo.ID,
                        InningIndex = this._inningInfo.InningIndex,
                        RoundID     = roundID,
                        Time        = new MyDateTime(DateTime.Now)
                    };
                    this._dicPlayerBetRecord.Add(userID, betrecord);
                }

                switch (color)
                {
                case GambleStoneItemColor.Red:
                    betrecord.BetRedStone        += stoneCount;
                    this._inningInfo.BetRedStone += stoneCount;
                    if (this._dicPlayerBetRedStone.ContainsKey(userID))
                    {
                        this._dicPlayerBetRedStone[userID] += stoneCount;
                    }
                    else
                    {
                        this._dicPlayerBetRedStone.Add(userID, stoneCount);
                    }
                    break;

                case GambleStoneItemColor.Green:
                    betrecord.BetGreenStone        += stoneCount;
                    this._inningInfo.BetGreenStone += stoneCount;
                    if (this._dicPlayerBetGreenStone.ContainsKey(userID))
                    {
                        this._dicPlayerBetGreenStone[userID] += stoneCount;
                    }
                    else
                    {
                        this._dicPlayerBetGreenStone.Add(userID, stoneCount);
                    }
                    break;

                case GambleStoneItemColor.Blue:
                    betrecord.BetBlueStone        += stoneCount;
                    this._inningInfo.BetBlueStone += stoneCount;
                    if (this._dicPlayerBetBlueStone.ContainsKey(userID))
                    {
                        this._dicPlayerBetBlueStone[userID] += stoneCount;
                    }
                    else
                    {
                        this._dicPlayerBetBlueStone.Add(userID, stoneCount);
                    }
                    break;

                case GambleStoneItemColor.Purple:
                    betrecord.BetPurpleStone        += stoneCount;
                    this._inningInfo.BetPurpleStone += stoneCount;
                    if (this._dicPlayerBetPurpleStone.ContainsKey(userID))
                    {
                        this._dicPlayerBetPurpleStone[userID] += stoneCount;
                    }
                    else
                    {
                        this._dicPlayerBetPurpleStone.Add(userID, stoneCount);
                    }
                    break;

                default:
                    break;
                }

                result.PlayerBetRecord = betrecord;
                result.ResultCode      = OperResult.RESULTCODE_TRUE;
                return(result);
            }
        }
Пример #11
0
 void CurrentInningRunner_GambleStoneInningWinnedNotifyAllClient(GambleStoneRoundInfo roundInfo, GambleStoneInningInfo inningInfo, GambleStonePlayerBetRecord maxWinner)
 {
     if (this.GambleStoneInningWinnedNotifyAllClient != null)
     {
         GambleStoneInningWinnedNotifyAllClient(roundInfo, inningInfo, maxWinner);
     }
 }