-
Notifications
You must be signed in to change notification settings - Fork 6
/
PokerGame.cs
921 lines (739 loc) · 27.5 KB
/
PokerGame.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
#region References
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Server.Items;
using Server.Mobiles;
using Server.Network;
#endregion
namespace Server.Engines.TexasHoldem
{
public class PokerGame
{
#region Fields
public Deck Deck { get; set; }
public PokerGameState State { get; set; }
public PokerExport Exporter { get; set; }
public PokerDealer Dealer { get; set; }
public PokerGameTimer PokerTimer { get; set; }
public PokerPlayer DealerButton { get; private set; }
public PokerPlayer SmallBlind { get; private set; }
public PokerPlayer BigBlind { get; private set; }
public int MinimumRaise { get; set; }
public int MinimumBet { get; set; }
public PokerPlayer CurrentTurn { get; set; }
public List<Card> CommunityCards { get; set; }
public List<PokerPlayer> Players { get; set; }
public List<PokerPlayer> ActivePlayers { get; set; }
public List<PlayerMobile> Viewers { get; set; }
public List<PokerPot> PokerPots { get; set; }
public List<PlayerAction> RoundActions { get; set; }
public DateTime StartTime { get; set; }
public Type TypeOfCurrency
{
get { return Dealer != null && Dealer.IsDonation ? typeof(DonationCoin) : typeof(Gold); }
}
public TimeSpan TurnLength { get { return TimeSpan.FromSeconds(60); } }
public TimeSpan CooldownPeriod { get { return TimeSpan.FromSeconds(20); } }
public TimeSpan HandCoolDown { get; set; }
#endregion
public PokerGame(PokerDealer dealer)
{
Dealer = dealer;
State = PokerGameState.Inactive;
Deck = new Deck();
PokerTimer = new PokerGameTimer(this);
Exporter = new PokerExport();
CommunityCards = new List<Card>();
Players = new List<PokerPlayer>();
ActivePlayers = new List<PokerPlayer>();
RoundActions = new List<PlayerAction>();
PokerPots = new List<PokerPot>();
Viewers = new List<PlayerMobile>();
}
#region Core Functionality
/// <summary>
/// Process a tick of the poker game timer. Refresh the gumps of all players, try to increment the round and check for
/// afk players
/// </summary>
public void ProcessTick()
{
if (IsIntermission() && HandCoolDown <= TimeSpan.FromSeconds(0))
{
ResetGame();
}
else if (State == PokerGameState.Showdown)
{
DoShowdown();
}
else if (State > PokerGameState.Inactive && State < PokerGameState.Showdown)
{
DoRoundAction();
//if it is someones turn and they haven't done an action
if (IsBettingRound && CurrentTurn != null)
{
CurrentTurn.TurnEnd -= TimeSpan.FromSeconds(1);
if (CurrentTurn.TurnEnd == TimeSpan.FromSeconds(30) ||
CurrentTurn.TurnEnd == TimeSpan.FromSeconds(15) ||
CurrentTurn.TurnEnd == TimeSpan.FromSeconds(5))
{
CurrentTurn.SendMessage("Your turn will end in " + CurrentTurn.TurnEnd.Seconds +
" seconds. If you do not make a move before your time runs out, you will fold your hand.");
}
//thye've used up their turn grace time, force them to fold from the hand
if (CurrentTurn.TurnEnd <= TimeSpan.FromSeconds(0))
{
DoAction(CurrentTurn, PlayerAction.Fold);
}
}
}
else if (IsIntermission())
{
var seconds = HandCoolDown.Seconds;
if (seconds == 20 || seconds == 10 || seconds == 5)
{
PokerMessage(Dealer, "The next hand will begin in " + HandCoolDown.Seconds +
" seconds.");
}
HandCoolDown -= TimeSpan.FromSeconds(1);
}
}
/// <summary>
/// Check if the user is already at the table
/// </summary>
public bool IsBlind(PokerPlayer player)
{
return player == BigBlind || player == DealerButton || player == SmallBlind;
}
/// <summary>
/// Check if the user is already at the table
/// </summary>
public bool IsViewer(PlayerMobile pm)
{
return Viewers.Contains(pm);
}
/// <summary>
/// Check if the user is already at the table
/// </summary>
public bool IsPlayer(PlayerMobile pm)
{
PokerPlayer player;
return IsPlayer(pm, out player);
}
/// <summary>
/// Check if the user is part of the current hand
/// </summary>
public bool IsActivePlayer(PlayerMobile pm)
{
PokerPlayer player;
return IsPlayer(pm, out player);
}
public bool IsActivePlayer(PlayerMobile pm, out PokerPlayer player)
{
player = ActivePlayers.FirstOrDefault(x => x.Owner == pm);
return player != null;
}
public bool IsPlayer(PlayerMobile pm, out PokerPlayer player)
{
player = Players.FirstOrDefault(x => x.Owner == pm);
return player != null;
}
public bool IsDonationGame()
{
return TypeOfCurrency == typeof(DonationCoin);
}
/// <summary>
/// Send a message to all poker players of the last persons move. For increase visibility, also display it over their
/// head.
/// </summary>
public void PokerMessage(Mobile from, string message)
{
foreach (var player in Players.ToArray())
{
from.PrivateOverheadMessage(MessageType.Regular, 0x9A, true, message, player.Owner.NetState);
if (player.Owner != null)
{
player.Owner.SendMessage(0x9A, "[{0}]: {1}", from.Name, message);
}
}
}
/// <summary>
/// Get a count of all active players in a game
/// </summary>
public int GetAllActivePlayers()
{
return ActivePlayers.Count;
}
/// <summary>
/// Get a count of all players in a game that can still act in rounds
/// </summary>
public int GetActiveElliblePlayersCount()
{
return ActivePlayers.Count(x => x.Currency > 0 && !x.HasFolded);
}
public bool IsIntermission()
{
return State == PokerGameState.Intermission;
}
/// <summary>
/// Refresh all gumps for playermobiles
/// </summary>
public void RefreshGumps()
{
foreach (var player in Players.ToArray())
{
new PokerTableGump(player.Owner, this).Send();
}
foreach (var viewer in Viewers.ToArray())
{
if (viewer.HasGump(typeof(PokerTableGump)))
new PokerTableGump(viewer, this).Send();
else
Viewers.Remove(viewer);
}
}
/// <summary>
/// Closes all poker gumps for playermobiles
/// </summary>
public void CloseGumps()
{
foreach (var player in Players.ToArray())
{
player.CloseAllGumps();
}
foreach (var viewer in Viewers.ToArray())
{
if (viewer.HasGump(typeof(PokerTableGump)))
viewer.CloseGump(typeof(PokerTableGump));
else
Viewers.Remove(viewer);
}
}
/// <summary>
/// Creates a list of active players and grabs the next active player that can act. If play doesn't exist, grab the
/// first player in the list
/// <returns>next active player</returns>
/// </summary>
public PokerPlayer GetNextActivePlayer(PokerPlayer current)
{
var index = ActivePlayers.IndexOf(current);
PokerPlayer activeplayer;
do
{
activeplayer = ActivePlayers[index == -1 ? 0 : (index + 1 >= ActivePlayers.Count ? 0 : (index + 1))];
index = ActivePlayers.IndexOf(activeplayer);
}
while (activeplayer.Currency == 0 || activeplayer.HasFolded);
return activeplayer == current ? null : activeplayer;
}
/// <summary>
/// Gets the amount a player needs to bet in order to meet the current minimum bet to stay in the game
/// <returns>amount needed to meet call</returns>
/// </summary>
public int GetCallAmount(PokerPlayer player)
{
return MinimumBet - player.TotalBetInRound;
}
/// <summary>
/// Raises can only be made if a bet has already been posted
/// <returns>amount needed to meet call</returns>
/// </summary>
public bool CanRaise()
{
return RoundActions.Exists(x => x == PlayerAction.Bet);
}
public bool HasRaised()
{
return RoundActions.Exists(x => x == PlayerAction.Raise);
}
/// <summary>
/// In poker, every second round is a betting round. This is useful in making code to determine state changes more
/// compact.
/// </summary>
public bool IsBettingRound { get { return State > PokerGameState.Inactive && State < PokerGameState.Intermission && (int)State % 2 == 0; } }
public bool CanEndBettingRound()
{
return !ActivePlayers.Exists(x => x.Currency > 0 && !x.HasFolded && (!x.HasActed || GetCallAmount(x) > 0));
}
#endregion
#region Initialize Game
/// <summary>
/// Determines the blinds for a new hand of poker. The dealer button and blinds always move to the left.
/// </summary>
public void DetermineBlinds()
{
if (!Players.Contains(DealerButton))
DealerButton = null;
if (!Players.Contains(SmallBlind))
SmallBlind = null;
if (!Players.Contains(BigBlind))
BigBlind = null;
if (GetActiveElliblePlayersCount() >= 2)
{
if (DealerButton == null)
{
if (SmallBlind != null)
{
DealerButton = SmallBlind;
SmallBlind = GetNextActivePlayer(DealerButton);
}
else
{
DealerButton = GetNextActivePlayer(null);
SmallBlind = GetNextActivePlayer(DealerButton);
}
}
else
{
DealerButton = GetNextActivePlayer(DealerButton);
SmallBlind = GetNextActivePlayer(DealerButton);
}
if (GetActiveElliblePlayersCount() >= 3)
BigBlind = GetNextActivePlayer(SmallBlind);
}
}
/// <summary>
/// Attempt to disburse any pending credit to players
/// </summary>
public void ProcessCredit()
{
foreach (var player in Players.ToArray())
{
player.ProcessCredit(Dealer.MinBuyIn, Dealer.MaxBuyIn, TypeOfCurrency);
}
}
#endregion
#region Start/Stop Game/Reset Game
public void BeginGame()
{
StartTime = DateTime.Now;
DetermineBlinds();
PokerPots.Add(new PokerPot());
State = PokerGameState.DealHoleCards;
}
/// <summary>
/// End the poker game and clear players of any relevant variables to that specific game
/// </summary>
public void EndGame()
{
State = PokerGameState.Inactive;
CurrentTurn = null;
//process credit first so that players that have queued in with a rebuy won't be kicked for having low currency
ProcessCredit();
ProcessLeaves();
StartIntermission();
RefreshGumps();
}
public void ResetGame()
{
CloseGumps();
State = PokerGameState.Inactive;
RoundActions = new List<PlayerAction>();
CommunityCards.Clear();
//create and shuffle a new deck
Deck = new Deck();
PokerPots.Clear();
ActivePlayers.Clear();
foreach (var player in Players.ToArray())
{
player.ClearGame();
}
ActivePlayers.AddRange(Players.Where(x => x.Currency > 0));
if (GetActiveElliblePlayersCount() > 1)
{
BeginGame();
}
else
{
StopIntermission();
ActivePlayers.Clear();
}
}
public void StopIntermission()
{
PokerMessage(Dealer, "There were not enough players to start a new hand.");
if (PokerTimer != null && PokerTimer.Running)
PokerTimer.Stop();
State = PokerGameState.Inactive;
}
public void StartIntermission()
{
State = PokerGameState.Intermission;
if (PokerTimer == null || !PokerTimer.Running)
{
PokerTimer = new PokerGameTimer(this);
PokerTimer.Start();
}
HandCoolDown = CooldownPeriod;
}
#endregion
#region Round Functionality
public void MakeBet(PokerPlayer player, int bet)
{
player.MakeBet(bet);
var pot = PokerPots.FirstOrDefault();
if (pot != null)
pot.AddtoPot(bet, player);
}
public void CreateSidePots()
{
PokerPot newPot;
do
{
var pot = PokerPots.Last();
newPot = pot.TrySplitPot();
if (newPot != null)
PokerPots.Add(newPot);
}
while (newPot != null);
}
public void DoRoundAction() //Happens once State is changed (once per state)
{
if (IsBettingRound && CanEndBettingRound())
{
//if all players have acted and have either gone all-in, folded or have equal amounts in community currency
State++;
}
else if (!IsBettingRound)
{
//if this is one of the 3 card draw stages
if (State == PokerGameState.Flop || State == PokerGameState.Turn || State == PokerGameState.River)
{
var round = State.ToString().ToLower();
var numberOfCards = State == PokerGameState.Flop ? 3 : 1;
PopCards(numberOfCards, round);
}
//prepare next betting round
if (State == PokerGameState.DealHoleCards)
{
SetUpHole();
}
else if (GetActiveElliblePlayersCount() > 1)
{
SetUpBettingRound();
}
RankHands();
State++;
}
RefreshGumps();
}
public void PopCards(int amount, string message)
{
if (amount > 0) //Pop the appropriate number of cards from the top of the deck
{
var sb = new StringBuilder();
sb.Append("The " + message + " shows: ");
for (int i = 0; i < amount; ++i)
{
Card popped = Deck.Pop();
if (i == 2 || amount == 1)
{
sb.Append(popped.Name + ".");
}
else
{
sb.Append(popped.Name + ", ");
}
CommunityCards.Add(popped);
}
PokerMessage(Dealer, sb.ToString());
}
}
/// <summary>
/// Deal initial cards to players
/// </summary>
public void SetUpHole()
{
for (var i = 0; i < 2; ++i)
//Simulate passing one card out at a time, going around the circle of players 2 times
{
foreach (var player in ActivePlayers.ToArray())
{
Card card = Deck.Pop();
player.AddCard(card);
}
}
//if >3 players, smallblind posts smallblind else dealerbutton does
DoAction(BigBlind != null ? SmallBlind : DealerButton, PlayerAction.Bet, Dealer.SmallBlind, true, false);
//if >3 players, bigblind posts bigblind else smallblind does
DoAction(BigBlind ?? SmallBlind, PlayerAction.Bet, Dealer.BigBlind, true, false);
CurrentTurn = BigBlind ?? SmallBlind;
AssignNextTurn();
}
/// <summary>
/// Start a betting round of the game. Creates valid players and sets the first player's turn
/// </summary>
public void SetUpBettingRound()
{
//reset these variables because they need to be 0 for a new round
MinimumBet = 0;
MinimumRaise = 0;
foreach (var player in ActivePlayers)
{
player.ClearRound();
}
CurrentTurn = DealerButton;
RoundActions = new List<PlayerAction>();
//start betting again
AssignNextTurn();
}
public void RankHands()
{
foreach (var player in ActivePlayers.Where(x => !x.HasFolded))
{
player.RankHand(CommunityCards);
}
}
public void DoAction(PokerPlayer player, PlayerAction action, int bet = 0, bool isforced = false,
bool verbose = true)
{
if (!isforced && CurrentTurn != player)
return;
var pm = player.Owner;
string message = string.Empty;
Exporter.AddAction(pm, action, State, action == PlayerAction.AllIn ? player.Currency : bet);
switch (action)
{
case PlayerAction.Bet:
message = String.Format("I {0} {1}.", "bet", bet);
MakeBet(player, bet);
MinimumBet = bet;
//raise after a bet is always 2*bet according to poker rules
MinimumRaise = bet * 2;
break;
case PlayerAction.Raise:
message = String.Format("I {0} {1}.",
RoundActions.Exists(x => x == PlayerAction.Raise) ? "reraise" : "raise", bet);
MakeBet(player, GetCallAmount(player) + bet);
MinimumBet += bet;
MinimumRaise = bet;
break;
case PlayerAction.Call:
message = "I call.";
//match what is on the table from the last player. This takes into account how much you already have on the table in that round
bet = GetCallAmount(player);
MakeBet(player, bet);
break;
case PlayerAction.Check:
message = "Check.";
break;
case PlayerAction.Fold:
message = "I fold.";
player.HasFolded = true;
if (ActivePlayers.Count(x => !x.HasFolded) == 1)
{
DoShowdown();
return;
}
break;
case PlayerAction.AllIn:
if (player.Currency > 0)
{
message = MinimumBet > player.Currency ? "I call: all-in." : "All in.";
int difference = player.Currency + player.TotalBetInRound;
if (difference > MinimumBet)
{
MinimumBet = difference;
}
MakeBet(player, player.Currency);
}
break;
}
RefreshGumps();
if (verbose)
{
PokerMessage(pm, message);
}
if (!isforced)
{
player.HasActed = true;
}
RoundActions.Add(action);
if (!isforced && !CanEndBettingRound())
{
AssignNextTurn();
}
}
public void AssignNextTurn()
{
CurrentTurn = GetNextActivePlayer(CurrentTurn);
RefreshGumps();
if (CurrentTurn != null)
{
CurrentTurn.TurnEnd = TurnLength;
if (CurrentTurn.RequestLeave)
{
DoAction(CurrentTurn, PlayerAction.Fold);
return;
}
if (GetActiveElliblePlayersCount() == 1 && CanEndBettingRound())
{
DoAction(CurrentTurn, PlayerAction.Check);
return;
}
new PokerBetGump(CurrentTurn.Owner, this, CurrentTurn).Send();
}
}
/// <summary>
/// Determines the winner, ends the game and then tries to start a new one
/// </summary>
public void DoShowdown()
{
State = PokerGameState.DetermineWinners;
RefreshGumps();
CreateSidePots();
DetermineWinners();
Exporter.ProcessHand(this);
EndGame();
}
public void DetermineWinners()
{
foreach (var player in ActivePlayers)
{
player.RankHand(CommunityCards);
}
foreach (var pot in PokerPots)
{
pot.AwardPot(ActivePlayers);
}
foreach (var player in ActivePlayers)
{
player.DistributeCredit(this);
}
}
#endregion
#region Add/Remove Players
/// <summary>
/// Add a player to the poker game
/// </summary>
public void AddPlayer(PlayerMobile player, int buyin)
{
if (!CanJoinTable(player, buyin))
{
return;
}
var seat = Dealer.Seats.FirstOrDefault(x => !Dealer.SeatTaken(x));
if (seat != Point3D.Zero)
{
var pokerplayer = new PokerPlayer(player, buyin, seat, this);
Players.Add(pokerplayer);
}
if (Players.Count > 1 && !IsIntermission() && HandCoolDown <= TimeSpan.FromSeconds(0))
{
StartIntermission();
}
}
public bool CanJoinTable(PlayerMobile player, int buyin)
{
if (!ShardInfo.IsTestCenter && player.AccessLevel == AccessLevel.Player && Players.Any(p => p.Owner.NetState != null && player.NetState != null &&
p.Owner.NetState.Address.Equals(player.NetState.Address)))
{
return false;
}
if (player.PokerJoinTimer > DateTime.UtcNow)
{
TimeSpan nextuse = player.PokerJoinTimer - DateTime.UtcNow;
player.SendMessage("You cannot join another poker game for " + nextuse.Seconds + " seconds.");
return false;
}
if (player.Aggressed.Any(info => (DateTime.UtcNow - info.LastCombatTime) < TimeSpan.FromSeconds(60)))
{
player.SendMessage("You cannot join poker while you are in combat!");
return false;
}
if (player.Aggressors.Any(info => (DateTime.UtcNow - info.LastCombatTime) < TimeSpan.FromSeconds(60)))
{
player.SendMessage("You cannot join poker while you are in combat!");
return false;
}
if (player.Party != null)
{
player.SendMessage("You cannot join a poker game while in a party.");
return false;
}
if (!Dealer.InRange(player.Location, 8))
{
player.PrivateOverheadMessage(MessageType.Regular, 0x22, true, "I am too far away to do that",
player.NetState);
return false;
}
if (IsPlayer(player))
{
player.SendMessage(0x22, "You are already seated at this table");
return false;
}
if (Players.Count >= Dealer.MaxPlayers)
{
player.SendMessage(0x22, "Sorry, that table is full");
return false;
}
if (!Dealer.Seats.Exists(x => !Dealer.SeatTaken(x)))
{
player.SendMessage(0x22, "Sorry, that table is full");
return false;
}
if (!Banker.WithdrawPackAndBank(player, TypeOfCurrency, buyin))
{
player.SendMessage(0x22, "Your bank box lacks the funds to join this poker table.");
return false;
}
return true;
}
/// <summary>
/// Remove player from the game
/// </summary>
public void RemovePlayer(PokerPlayer player)
{
if (player != null)
{
//null these here so we know that one of the key players for the next game has left
if (DealerButton == player)
{
DealerButton = null;
}
if (SmallBlind == player)
{
SmallBlind = null;
}
if (BigBlind == player)
{
BigBlind = null;
}
//Move to view list so that they can continue viewing the game
if (ActivePlayers.Contains(player))
Viewers.Add(player.Owner);
Players.Remove(player);
player.LeaveGame(this);
}
}
/// <summary>
/// Removes players from the game that meet leave criteria
/// </summary>
public void ProcessLeaves()
{
foreach (
var player in
Players.ToArray()
.Where(player => !player.IsOnline() || player.Currency < Dealer.BigBlind || player.RequestLeave)
)
{
RemovePlayer(player);
}
}
#endregion
}
public class PokerGameTimer : Timer
{
private readonly PokerGame _Game;
public PokerGameTimer(PokerGame game)
: base(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0))
{
_Game = game;
}
protected override void OnTick()
{
_Game.ProcessTick();
}
}
}