Ejemplo n.º 1
0
        static int WonJackpot(CasinoPlayer jackpotPlayer)
        {
            int price = jackpotPlayer.Points;

            if (price <= 0)
            {
                return(0);
            }
            else
            {
                if (!DbInterface.AlterPoints(jackpotPlayer, -price)) //Take money
                {                                                    //Can't change points for some reason
                    throw new Exception("Alter Points failed in CommandSpin.cs");
                }

                return(price);
            }
        }
Ejemplo n.º 2
0
        internal override bool Execute(List <string> args, TextMessage message, PersonDb db)
        {
            if (args.Count < 1)             //Not enough parameters => Show Usage
            {
                CommandManager.AnswerCall(message, "\nUsage:\n" + CommandManager.CmdIndicator + this.Label + " " + this.Usage);
                return(false);
            }

            String arg0 = args[0].ToLower();

            if (arg0 != "buy" && arg0 != "list")
            {
                CommandManager.AnswerCall(message, "\nUsage:\n" + CommandManager.CmdIndicator + this.Label + " " + this.Usage);
                return(false);
            }

            StringBuilder outMessage = new StringBuilder();

            outMessage.Append("\n");

            if (arg0 == "buy")                                   //buy item
            {
                if (args.Count == 2 && GetItem(args[1]) != null) //if we have no item to buy -> show list
                {
                    //Get Invoker
                    CasinoPlayer invoker = DbInterface.GetPlayer(message.InvokerUid, db);

                    Item item = GetItem(args[1]);
                    if (invoker.Points < item.Price)                     //Not enough points
                    {
                        CommandManager.AnswerCall(message, Responses.NotEnoughPoints);
                        return(false);
                    }
                    //Change the points nauw
                    if (!DbInterface.AlterPoints(invoker, -item.Price))                     //Can't change points for some reason
                    {
                        CommandManager.AnswerCall(message, "An Unknown Error Occured! \nGive this to your Admin: 'Alter Points failed in CommandStore.cs'");
                        throw new Exception("Alter Points failed in CommandStore.cs");
                    }
                    DbInterface.GiveItem(invoker, item.ID);
                    DbInterface.SaveChanges(db);

                    //Tell the peepz about their item
                    CommandManager.AnswerCall(message, $"{Utils.Utils.ApplyColor(Color.DarkGreen)}\nYou've bought {item.Name} for {item.Price} Points![/COLOR]\nYou now have {invoker.Points} Points");
                    return(true);
                }
                else
                {
                    ListItems(args, message, ref outMessage);
                    CommandManager.AnswerCall(message, outMessage.ToString());
                    return(true);
                }
            }

            if (arg0 == "list")                                  //List items
            {
                if (args.Count == 2 && GetItem(args[1]) != null) //if we have a item show more information about it else list items
                {
                    Item item = GetItem(args[1]);
                    if (item != null)
                    {
                        outMessage.Append($"{item.Name} | {item.Description} | {item.Price} Points");
                    }
                }
                else
                {
                    //List
                    ListItems(args, message, ref outMessage);
                }
                CommandManager.AnswerCall(message, outMessage.ToString());
                return(true);
            }

            return(true);
        }
Ejemplo n.º 3
0
        internal override bool Execute(List <string> args, TextMessage msg, PersonDb db)
        {
            if (args.Count < 1)
            {
                CommandManager.AnswerCall(msg, $"\nUsage:\n{CommandManager.CmdIndicator}{this.Label} {this.Usage}");
                return(false);
            }

            String bet = args[0].ToLower();

            if (bet != "heads" && bet != "tails")
            {
                CommandManager.AnswerCall(msg, $"\nUsage:\n{CommandManager.CmdIndicator}{this.Label} {this.Usage}");
                return(false);
            }

            int wager = 5;

            if (args.Count > 1)
            {
                if (!Int32.TryParse(args[1], out wager))
                {
                    CommandManager.AnswerCall(msg, $"{Utils.Utils.ApplyColor(Color.Red)}\n{args[1]} is not a number![/COLOR]");
                    return(false);
                }
                if (wager <= 0)                 //Number not positive => frick off
                {
                    CommandManager.AnswerCall(msg, Responses.NegativeNumber);
                    return(false);
                }
            }

            CasinoPlayer myPlayer = DbInterface.GetPlayer(msg.InvokerUid, db);

            if (myPlayer.Points < wager)             //Not enough points
            {
                CommandManager.AnswerCall(msg, Responses.NotEnoughPoints);
                return(false);
            }

            StringBuilder outMessage = new StringBuilder();

            outMessage.Append("\n");

            //Generate Numbers
            Random run  = new Random();
            int    edge = run.Next(0, 6000);
            int    flip = 0;

            int price = 0;

            if (edge != 1)              //1 in 6k
            {
                flip = run.Next(0, 1);
                if (flip == 0)
                {
                    outMessage.Append("The Coin shows Heads!\n");
                    if (bet.Equals("heads"))
                    {
                        price = wager * 2;
                    }
                }
                else
                {
                    outMessage.Append("The Coin shows Tails!\n");
                    if (bet.Equals("tails"))
                    {
                        price = wager * 2;
                    }
                }
            }
            else
            {
                outMessage.Append("The Coin landed on its edge! What a crooked game!\n");
            }

            int add = price - wager;

            if (!DbInterface.AlterPoints(myPlayer, add)) //Give/Take money
            {                                            //Can't change points for some reason
                CommandManager.AnswerCall(msg, "An Unknown Error Occured! \nGive this to your Admin: 'Alter Points failed in CommandCoin.cs'");
                throw new Exception("Alter Points failed in CommandCoin.cs");
            }
            DbInterface.SaveChanges(db);

            outMessage.Append(add >= 0 ? $"You have won {add}" : $"You have lost {-add}");
            outMessage.Append($" Points. You now have {myPlayer.Points} Points!");

            CommandManager.AnswerCall(msg, outMessage.ToString());
            return(true);
        }
Ejemplo n.º 4
0
        internal override bool Execute(List <string> args, TextMessage msg, PersonDb db)
        {
            CasinoPlayer myPlayer = DbInterface.GetPlayer(msg.InvokerUid, db);

            /*
             * The user Exp has pulled the SLOTMACHINE!
             #############
             # 5 | 6 | 5 #
             #############
             #############And they won a meh Price...
             */

            if (myPlayer.Points < this.Cost)             //Not enough points
            {
                CommandManager.AnswerCall(msg, Responses.NotEnoughPoints);
                return(false);
            }

            //GetJackPot player
            CasinoPlayer jackpotPlayer = DbInterface.GetPlayer(this.JackpotID, db);

            if (jackpotPlayer == null)
            {
                CommandManager.AnswerCall(msg, $"{Utils.Utils.ApplyColor(Color.Red)}\nNo Jackpot found! Please contact your admin![/COLOR]");
                return(false);
            }

            //Generate Numbers
            Random run       = new Random();
            int    firstNum  = run.Next(1, 9);
            int    secondNum = run.Next(1, 9);
            int    thirdNum  = run.Next(1, 9);

            int price = 0;

            //Create Message
            StringBuilder outMessage = new StringBuilder();

            outMessage.Append("\n");
            outMessage.Append($"{CommandManager.ClientUrl(myPlayer.Id, myPlayer.Name)} has paid {this.Cost} to spin the Slot Machine!\n");
            outMessage.Append("########\n");
            outMessage.Append($"# {firstNum} |  {secondNum}  |  {thirdNum} #\n");
            outMessage.Append("########\n");

            //Did you win something? prolly not
            if (firstNum == MagicNumber && secondNum == MagicNumber && thirdNum == MagicNumber)
            {            //lucky bastard
                outMessage.Append("\nYou've won the Jackpot!\n");
                price = WonJackpot(jackpotPlayer);
            }
            else if ((firstNum == MagicNumber && secondNum == MagicNumber) ||
                     (firstNum == MagicNumber && thirdNum == MagicNumber) ||
                     (secondNum == MagicNumber && thirdNum == MagicNumber))                     //medium
            {
                outMessage.Append("\nYou've won a neato price!\n");
                price = Cost * 2;
            }
            else if (firstNum == MagicNumber || secondNum == MagicNumber || thirdNum == MagicNumber)
            {            //better than nothing amirite
                outMessage.Append("\nYou've won a meh price!\n");
                price = Cost;
            }
            else if (firstNum == 4 && secondNum == 0 && thirdNum == 4)
            {
                outMessage.Append("\nPrice not found!\n");
                price = Cost;
            }
            else             //Nothing
            {
                outMessage.Append("\nYou've won [S]a price[/S] [B]nothing[/B]!\n");
                price = 0;
            }

            int add = price - this.Cost;

            if (add < 0)             //if the player loses money give it to the jackpot
            {
                DbInterface.AlterPoints(jackpotPlayer, -add);
            }
            if (!DbInterface.AlterPoints(myPlayer, add)) //Give/Take money
            {                                            //Can't change points for some reason
                CommandManager.AnswerCall(msg, "An Unknown Error Occured! \nGive this to your Admin: 'Alter Points failed in CommandSpin.cs'");
                throw new Exception("Alter Points failed in CommandSpin.cs");
            }
            DbInterface.SaveChanges(db);

            outMessage.Append(add >= 0 ? $"You have won {add}" : $"You have lost {-add}");
            outMessage.Append($" Points. You now have {myPlayer.Points} Points!");

            CommandManager.AnswerCall(msg, outMessage.ToString());
            return(true);
        }
Ejemplo n.º 5
0
        internal override CCR Execute(List <string> args, PersonDb db)
        {
            #region argCompute
            if (args.Count == 0 || args.Count == 2 || args.Count > 3)
            {
                return(CCR.WRONGPARAM);
            }
            CasinoPlayer player = DbInterface.GetPlayer(args[0], db);
            if (player == null)
            {
                return(CCR.PLAYERNOTFOUND);
            }
            #endregion
            // show case
            if (args.Count == 1)
            {
                Console.WriteLine($"Name: {player.Name}\nPoints: {player.Points}\nSteam: {player.SteamID64}");
                return(CCR.OK);
            }
            // change case
            if (args[1].ToLower() == "change")
            {
                if (!Int32.TryParse(args[2], out int amount))
                {
                    return(CCR.NOTANUMBER);
                }
                if (!DbInterface.AlterPoints(player, amount))
                {
                    return(CCR.NOTENOUGHPOINTS);
                }

                switch (DbInterface.SaveChanges(db))
                {
                case Error.OK:
                    Console.WriteLine($"Points altered from {(player.Points - amount)} to {player.Points}");
                    return(CCR.OK);

                //	break;
                case Error.SAVEERROR:
                    DbInterface.AlterPoints(player, -amount);
                    return(CCR.DBWRITEFAILED);

                //	break;

                case Error.UNKNOWN:
                default:
                    return(CCR.UNKNOWN);
                    //	break;
                }
            }
            // set case
            if (args[1].ToLower() == "set")
            {
                if (!Int32.TryParse(args[2], out int amount))
                {
                    return(CCR.NOTANUMBER);
                }
                if (amount < 0)
                {
                    return(CCR.BELOWZERO);
                }
                int oldAmount = player.Points;

                db.Players.Find(player.Id).Points = amount;                 // Setting the amount of Points

                switch (DbInterface.SaveChanges(db))
                {
                case Error.OK:
                    Console.WriteLine($"{player.Name}'s Points were altered from {oldAmount} to {player.Points}");
                    return(CCR.OK);

                //	break;
                case Error.SAVEERROR:
                    db.Players.Find(player.Id).Points = oldAmount;                            // Resetting the amount of Points to the Old value
                    return(CCR.DBWRITEFAILED);

                //	break;

                case Error.UNKNOWN:
                default:
                    return(CCR.UNKNOWN);
                    //	break;
                }
            }
            return(CCR.UNKNOWN);
        }