using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

using Plus.HabboHotel.Rooms;
using Plus.HabboHotel.GameClients;
using Plus.Communication.Packets.Outgoing.Rooms.Engine;
using Plus.Communication.Packets.Outgoing.Rooms.Chat;
using Plus.Database.Interfaces;
using Plus.Communication.Packets.Outgoing.Inventory.Purse;


namespace Plus.HabboHotel.Rooms.Chat.Commands.User.Fun
{
    class PariCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_pari"; }
        }

        public string Parameters
        {
            get { return "%montant%"; }
        }

        public string Description
        {
            get { return "Envie de misé tes crédits ?"; }
        }

        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            if (Params.Length == 1)
            {
                Session.SendWhisper("Tu n'as pas entré de pseudonyme.", 34);
                return;
            }
            Random Pari = new Random();
            int randompari = Pari.Next(1, 10);
            int credit = 0;
            credit = Convert.ToInt32(Params[1]);
            int gain = 0;
            gain = credit * 2;
            if (Session.GetHabbo().Credits >= credit)
            {
                if (int.TryParse(Params[1], out credit))
                {
                    if (randompari == 7 || randompari == 2)
                    {

                        RoomUser ThisUser = Room.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);
                        Room.SendMessage(new ChatComposer(ThisUser.VirtualId, "*Mise " + credit + " Crédits*", 0, 1));
                        Room.SendMessage(new ChatComposer(ThisUser.VirtualId, "*Remporte " + gain + " Crédits*", 0, 1));
                        Session.GetHabbo().Credits = Session.GetHabbo().Credits + gain;
                        Session.SendMessage(new CreditBalanceComposer(Session.GetHabbo().Credits));
                        return;
                    }
                    else
                    {
                        RoomUser ThisUser = Room.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);
                        Room.SendMessage(new ChatComposer(ThisUser.VirtualId, "*Mise " + credit + " Crédits*", 0, 1));
                        Room.SendMessage(new ChatComposer(ThisUser.VirtualId, "*Je n'ai rien gagné :(*", 0, 1));
                        Session.GetHabbo().Credits = Session.GetHabbo().Credits - credit;
                        Session.SendMessage(new CreditBalanceComposer(Session.GetHabbo().Credits));
                        return;
                    }
                }
                else
                {
                    Session.SendWhisper("Montant invalide!");
                }
            }
            else
            {
                Session.SendWhisper("Tu n'a pas assez de crédits!");
            }
        }
    }
}