Exemple #1
0
        /**
         *      Remove all gumps from a player
         */
        private void RemoveGumps(MobileDiceStstatus mds)
        {
            try{
                while (mds.getMobile().HasGump(typeof(NewDiceGameGump)))
                {
                    mds.getMobile().CloseGump(typeof(NewDiceGameGump));
                }
                while (mds.getMobile().HasGump(typeof(ExitDiceGump)))
                {
                    mds.getMobile().CloseGump(typeof(ExitDiceGump));
                }

                while (mds.getMobile().HasGump(typeof(StatusDiceGump)))
                {
                    mds.getMobile().CloseGump(typeof(StatusDiceGump));
                }
                while (mds.getMobile().HasGump(typeof(GameDiceGump)))
                {
                    mds.getMobile().CloseGump(typeof(GameDiceGump));
                }
                while (mds.getMobile().HasGump(typeof(CallBluffGump)))
                {
                    mds.getMobile().CloseGump(typeof(CallBluffGump));
                }
            }catch {
                SendMessageAllPlayers("Player " + mds.getMobile().Name + " was disconnected");
                RemovePlayer(mds.getMobile(), true);
            }
        }
Exemple #2
0
 /**
  *      Game timer limit on a player, warn/kick if necessary in the callbacks
  */
 public void SetTimerAction(MobileDiceStstatus prevPlayer, MobileDiceStstatus currPlayer)
 {
     prevPlayer.SetTimeStamp(DateTime.Now);
     currPlayer.SetTimeStamp(DateTime.Now);
     //setup the "warning" timer
     Timer timer = Timer.DelayCall(TimeSpan.FromSeconds(this.playerToActSeconds - 5), new TimerCallback(delegate() {
         TimeSpan timeDiff = (DateTime.Now - currPlayer.GetTimeStamp());
         //check time in miliseconds
         if (timeDiff.TotalMilliseconds > ((this.playerToActSeconds - 5) * 1000))
         {
             if (this.playerCnt > 1)
             {
                 SendMessageAllPlayers(currPlayer.getMobile().Name + " has 5 seconds to act before being kicked!");
             }
         }
     }));
     //setup timer to kick player if applicable
     Timer timer2 = Timer.DelayCall(TimeSpan.FromSeconds(this.playerToActSeconds), new TimerCallback(delegate() {
         TimeSpan timeDiff = (DateTime.Now - currPlayer.GetTimeStamp());
         //check time in miliseconds
         if (timeDiff.TotalMilliseconds > (this.playerToActSeconds * 1000))
         {
             if (this.playerCnt > 1)
             {
                 SendMessageAllPlayers(currPlayer.getMobile().Name + " ran out of time, and has been kicked from the game.");
                 RemovePlayer(currPlayer.getMobile(), true);
             }
         }
     }));
 }
Exemple #3
0
 /**
  *      Remove just the status gump from a player
  */
 public void RemoveStatusGump(MobileDiceStstatus mds)
 {
     try{
         while (mds.getMobile().HasGump(typeof(StatusDiceGump)))
         {
             mds.getMobile().CloseGump(typeof(StatusDiceGump));
         }
     }catch {
         SendMessageAllPlayers("Player " + mds.getMobile().Name + " was disconnected");
         RemovePlayer(mds.getMobile(), true);
     }
 }
Exemple #4
0
        /**
         *      Adds player to the dice game, by adding them to the dicePlayers array, and starting game loop
         *      if enough players.
         */
        public MobileDiceStstatus AddPlayer(Mobile m, int tableBalance)
        {
            //create our data storage structure
            MobileDiceStstatus mds = new MobileDiceStstatus(m, tableBalance);

            if (m.HasGump(typeof(GameDiceGump)))
            {
                m.CloseGump(typeof(GameDiceGump));
            }
            //is the mobile already in game?
            for (int i = 0; i < this.playerCnt; i++)
            {
                if (m == dicePlayers[i].getMobile())
                {
                    m.SendMessage("You are already playing!");
                    return(null);
                }
            }
            //to many players already?
            if (this.playerCnt >= this.maxNumberOfPlayers)
            {
                m.SendMessage("Liars Dice is currently at it maximum capacity of " + this.maxNumberOfPlayers + " players, try again later.");
                mds.getMobile().Frozen = false;
                return(mds);
            }
            //add to our main dice players list
            dicePlayers.Add(mds);
            //increment player count
            this.playerCnt += 1;
            //Wait for 2nd player before starting
            if (dicePlayers.Count == 1)
            {
                AddPlayerWaiting(0);
                m.SendMessage("Must have at least 2 players to play! Waiting..");
            }
            //Don't start with more than 2 ppl, otherwise we get missing gumps
            else if (dicePlayers.Count == 2)
            {
                //start game at index 0 of player list
                updatedMobileIdx = 0;
                prevPlayerIdx    = GetNextDicePlayerIdx(updatedMobileIdx);
                nextPlayerIdx    = GetNextDicePlayerIdx(updatedMobileIdx);
                PlayerTurn(dicePlayers[updatedMobileIdx], DICE_RESET);
                AddPlayerWaiting(updatedMobileIdx);
                SetTimerAction(dicePlayers[prevPlayerIdx], dicePlayers[updatedMobileIdx]);
            }
            else if (dicePlayers.Count > 2)
            {
                AddPlayerWaiting(updatedMobileIdx);
            }
            return(mds);
        }
Exemple #5
0
        /**
         *      Player turn, with a dice level they must beat
         */
        public void PlayerTurn(MobileDiceStstatus mds, int diceToBeat)
        {
            RemoveGumps(mds);
            //rolls and sets to previous
            int currRoll = mds.Roll();

            gdg = new GameDiceGump(this, currRoll, diceToBeat);
            try{
                mds.getMobile().SendGump(gdg);
            }catch {
                SendMessageAllPlayers("Player " + mds.getMobile().Name + " was disconnected");
                RemovePlayer(mds.getMobile(), true);
            }
        }
Exemple #6
0
        /**
         *      Send the bluff decision gump to the next player, and send a callBluff gump to the user
         */
        public void PlayBluffDecisionTurn(MobileDiceStstatus prevPlayer, MobileDiceStstatus currPlayer)
        {
            RemoveGumps(prevPlayer);
            int prevRollOrBluff = prevPlayer.GetPrevRollOrBluff();

            cbg = new CallBluffGump(this, prevRollOrBluff);
            try{
                currPlayer.getMobile().SendGump(cbg);
            }catch {
                SendMessageAllPlayers("Player " + currPlayer.getMobile().Name + " was disconnected");
                RemovePlayer(currPlayer.getMobile(), true);
            }
            //do timer checking, since timer is a thread, when the callback occurs we just look at the "previous" player
            SetTimerAction(prevPlayer, currPlayer);
        }
Exemple #7
0
        /********************************** START OF PRIVATE FUNCTIONS *****************************/

        /**
         *      Sends a plyer waiting gump, create gumps with 3 status arrays
         */
        public void PlayerWaiting(MobileDiceStstatus mds, int currentPlayerIdx)
        {
            if (mds.getMobile().HasGump(typeof(StatusDiceGump)))
            {
                mds.getMobile().CloseGump(typeof(StatusDiceGump));
            }
            string[] playerNames     = this.GetPlayerNames();
            int[]    playerBalances  = this.GetPlayerBalances();
            int[]    playPrevRollIdx = this.GetPlayerPrevRollOrBluff();
            sdg = new StatusDiceGump(this, playerNames, playerBalances, playPrevRollIdx, currentPlayerIdx);
            try{
                bool success = mds.getMobile().SendGump(sdg);
                //check to make sure the status gump was actually sent, and use THIS as our dissconnect protection
                if (success == false)
                {
                    SendMessageAllPlayers("Player " + mds.getMobile().Name + " was disconnected");
                    RemovePlayer(mds.getMobile(), true);
                }
            }catch {
                SendMessageAllPlayers("Player " + mds.getMobile().Name + " was disconnected");
                RemovePlayer(mds.getMobile(), true);
            }
        }
Exemple #8
0
        /**
         *      Way more complex code than it should actually be.. Removes a player, changes turn, updates bank balance
         */
        public void RemovePlayer(Mobile m, bool exchangeBalance)
        {
            int exitMobileIdx     = GetCurrentDicePlayerIdx(m);
            int prevExitPlayerIdx = GetPrevDicePlayerIdx(exitMobileIdx);
            //make the next updated mobile idx
            MobileDiceStstatus mds = dicePlayers[exitMobileIdx];

            RemoveGumps(mds);             //remove all gumps from user exiting
            int exitPlayerBal     = mds.GetTableBalance();
            int exitPrevPlayerBal = dicePlayers[prevExitPlayerIdx].GetTableBalance();

            //only subtract balances, if exchangeBalance is true, and therefore player left the table, and not kicked out by
            //a too low of balance
            if (this.playerCnt > 1 && exchangeBalance == true)
            {
                if (exitMobileIdx == updatedMobileIdx)
                {
                    //give previous player the balance
                    //give next player a fresh roll
                    mds.SetTableBalance(exitPlayerBal - this.goldPerGame);
                    dicePlayers[prevExitPlayerIdx].SetTableBalance(exitPrevPlayerBal + this.goldPerGame);
                    SendMessageAllPlayers("Player " + mds.getMobile().Name + " Left on his turn, so " + dicePlayers[prevPlayerIdx].getMobile().Name + " wins " + this.goldPerGame + " gp. from " + mds.getMobile().Name);
                }
                else if (exitMobileIdx == prevPlayerIdx)
                {
                    //give next player the balance.
                    //give current player a fresh roll
                    mds.SetTableBalance(exitPlayerBal - this.goldPerGame);
                    dicePlayers[updatedMobileIdx].SetTableBalance(exitPrevPlayerBal + this.goldPerGame);
                    SendMessageAllPlayers("Player " + mds.getMobile().Name + " Left the game before " + dicePlayers[updatedMobileIdx].getMobile().Name + " could make his decision, and so " + dicePlayers[updatedMobileIdx].getMobile().Name + " wins " + this.goldPerGame + " gp. from " + mds.getMobile().Name);
                }
            }
            //deposite old money
            Banker.Deposit(mds.getMobile(), mds.GetTableBalance());
            //update indexes of game
            if (updatedMobileIdx >= exitMobileIdx && this.playerCnt > 1)
            {
                updatedMobileIdx -= 1;
                if (dicePlayers.Contains(mds))
                {
                    dicePlayers.Remove(mds);
                }
                this.playerCnt -= 1;
                //unfreeze character, used so they can't enter more than 1 game at time
                mds.getMobile().Frozen = false;
                prevPlayerIdx = GetPrevDicePlayerIdx(updatedMobileIdx);
                nextPlayerIdx = GetNextDicePlayerIdx(updatedMobileIdx);
                if (this.playerCnt < 2)
                {
                    return;
                }
                PlayerTurn(dicePlayers[updatedMobileIdx], DICE_RESET);
                AddPlayerWaiting(updatedMobileIdx);
                SetTimerAction(dicePlayers[prevPlayerIdx], dicePlayers[updatedMobileIdx]);
            }
            else if (this.playerCnt > 1)
            {
                if (dicePlayers.Contains(mds))
                {
                    dicePlayers.Remove(mds);
                }
                this.playerCnt -= 1;
                //unfreeze character, used so they can't enter more than 1 game at time
                mds.getMobile().Frozen = false;
                prevPlayerIdx = GetPrevDicePlayerIdx(updatedMobileIdx);
                nextPlayerIdx = GetNextDicePlayerIdx(updatedMobileIdx);
                if (this.playerCnt < 2)
                {
                    AddPlayerWaiting(0);
                    return;
                }
                PlayerTurn(dicePlayers[updatedMobileIdx], DICE_RESET);
                AddPlayerWaiting(updatedMobileIdx);
                SetTimerAction(dicePlayers[prevPlayerIdx], dicePlayers[updatedMobileIdx]);
            }
            else if (this.playerCnt == 1)
            {
                if (dicePlayers.Contains(mds))
                {
                    dicePlayers.Remove(mds);
                }
                this.playerCnt = 0;
                //unfreeze character, used so they can't enter more than 1 game at time
                mds.getMobile().Frozen = false;
            }
        }