Exemple #1
0
        public ReturnMessage removeUser(int userId)
        {
            for (int i = 0; i < players.Length; i++)
            {
                if (players[i] != null && players[i].systemUserID == userId)
                {
                    // Buy in handle
                    int buyIn = 50;
                    BuyInPolicyDecPref buyInPref = (BuyInPolicyDecPref)gamePreferences.getOptionalPref(new BuyInPolicyDecPref(0, null));
                    if (buyInPref != null)
                    {
                        buyIn = buyInPref.buyInPolicy;
                    }

                    // Starting chips amount policy
                    int moneyToAdd    = 0;
                    int startingChips = 1000;
                    StartingAmountChipsCedPref startingChipsPref = (StartingAmountChipsCedPref)gamePreferences.getOptionalPref(new StartingAmountChipsCedPref(0, null));
                    if (startingChipsPref != null)
                    {
                        int policy = startingChipsPref.startingChipsPolicy;
                        if (policy == 0)
                        {
                            startingChips = buyIn;
                            moneyToAdd   += players[i].Tokens;
                        }
                        else
                        {
                            startingChips = policy;
                        }
                    }

                    // updates the rank and money of the user.
                    rankMoneyUpdateCallback(new int[] { userId, players[i].Tokens - startingChips, moneyToAdd });

                    GameLog.logLine(gameId, GameLog.Actions.Player_Left, players[i].name, i.ToString());

                    players[i] = null;

                    gameStatesObserver.Update(this);
                    spectateObserver.Update(this);
                    return(new ReturnMessage(true, ""));
                }
            }
            foreach (SystemUser u in spectators)
            {
                if (u.id == userId)
                {
                    spectators.Remove(u);
                    u.spectatingGame.Remove(this);
                    return(new ReturnMessage(true, ""));
                }
            }
            return(new ReturnMessage(true, ""));
        }
Exemple #2
0
        public ReturnMessage joinGame(SystemUser user, int seatIndex)
        {
            ReturnMessage m = gamePreferences.canPerformUserActions(this, user, "join");

            if (!m.success)
            {
                return(m);
            }

            if (seatIndex > players.Length)
            {
                return(new ReturnMessage(false, "cannot seat here"));
            }
            if (players[seatIndex] != null)
            {
                return(new ReturnMessage(false, "seat is taken"));
            }

            // Buy in handle
            int buyIn = 50;
            BuyInPolicyDecPref buyInPref = (BuyInPolicyDecPref)gamePreferences.getOptionalPref(new BuyInPolicyDecPref(0, null));

            if (buyInPref != null)
            {
                buyIn = buyInPref.buyInPolicy;
            }

            // Starting chips amount policy
            int startingChips = 1000;
            StartingAmountChipsCedPref startingChipsPref = (StartingAmountChipsCedPref)gamePreferences.getOptionalPref(new StartingAmountChipsCedPref(0, null));

            if (startingChipsPref != null)
            {
                int policy = startingChipsPref.startingChipsPolicy;
                if (policy == 0)
                {
                    startingChips = buyIn;
                }
                else
                {
                    startingChips = policy;
                }
            }

            // The user pay to enter the game.
            //user.money -= buyIn;
            rankMoneyUpdateCallback(new int[] { user.id, 0, -buyIn });

            Player p = new Player(user.id, user.name, startingChips, user.rank, user.userImageByteArray);

            players[seatIndex] = p;

            playersStats[seatIndex] = new LeaderboardsStats();

            if (firstJoin)
            {
                currentDealer = seatIndex;
                firstJoin     = false;
            }

            GameLog.logLine(gameId, GameLog.Actions.Player_Join, user.name, seatIndex.ToString(), startingChips.ToString());

            spectateObserver.Update(this);
            gameStatesObserver.Update(this);
            moneyInGame += buyIn;
            return(new ReturnMessage(true, ""));
        }