Exemple #1
0
        public override void Handle(virtualUser User)
        {
            int num1 = int.Parse(this.getBlock(0));

            HANDLE_GUN_SMITH.Type type = (HANDLE_GUN_SMITH.Type) int.Parse(this.getBlock(1));
            if (type == HANDLE_GUN_SMITH.Type.Ticket && !User.hasItem("CZ75"))
            {
                return;
            }
            string[] GunSmithArray = DB.runReadRow("SELECT gameid, item, rare, required_items, lose_items, required_materials, cost FROM gunsmith WHERE gameid='" + num1 + "'");
            if (GunSmithArray.Length <= 0)
            {
                return;
            }
            string ItemCode = GunSmithArray[1];
            int    num2     = int.Parse(GunSmithArray[6]);
            string str      = GunSmithArray[2];
            int    eaItems1 = User.getEAItems("CZ83");
            int    eaItems2 = User.getEAItems("CZ84");
            int    eaItems3 = User.getEAItems("CZ85");

            string[] strArray2 = (GunSmithArray[5]).ToString().Split(',');
            if (type == HANDLE_GUN_SMITH.Type.Ticket)
            {
                num2 = 0;
            }
            if (num2 == -1)
            {
                return;
            }
            int[] numArray = new int[strArray2.Length];
            for (int index = 0; index < numArray.Length; ++index)
            {
                int.TryParse(strArray2[index], out numArray[index]);
            }
            if (numArray[0] > eaItems3 || numArray[1] > eaItems2 || numArray[2] > eaItems1)
            {
                return;
            }
            string[] strArray3 = (GunSmithArray[3]).ToString().Split(',');
            if (!User.hasItem(strArray3[0]) || !User.hasItem(strArray3[1]) || !User.hasItem(strArray3[2]))
            {
                return;
            }
            User.DeleteItem(strArray3[0], 0);
            User.DeleteItem(strArray3[1], 0);
            User.DeleteItem(strArray3[2], 0);
            string[] strArray4 = (GunSmithArray[4]).ToString().Split(',');
            int      num3      = new Random().Next(0, 50);

            if (type == HANDLE_GUN_SMITH.Type.Ticket)
            {
                num3 += 10;
            }
            int index1 = new Random().Next(0, strArray4.Length);
            int Days   = 30;

            if (type == HANDLE_GUN_SMITH.Type.Dinar)
            {
                User.Dinar -= num2;
            }
            else
            {
                User.DeleteItem("CZ75", 1);
            }
            User.DeleteItem("CZ83", numArray[0]);
            User.DeleteItem("CZ84", numArray[1]);
            User.DeleteItem("CZ85", numArray[2]);
            int calcPerc = (type == Type.Dinar ? 10 : 25);

            if (num3 == 17)
            {
                ItemCode = str;
                User.send((Packet) new PACKET_GUN_SMITH(User, ItemCode, PACKET_GUN_SMITH.WonType.Rare));
            }
            else if (num3 > calcPerc)
            {
                User.send((Packet) new PACKET_GUN_SMITH(User, ItemCode, PACKET_GUN_SMITH.WonType.Normal));
            }
            else
            {
                ItemCode = strArray4[index1];
                Days     = new Random().Next(1, 15);
                User.send((Packet) new PACKET_GUN_SMITH(User, ItemCode, PACKET_GUN_SMITH.WonType.Lose));
            }
            User.AddOutBoxItem(ItemCode, Days, 1);
        }
Exemple #2
0
        public override void Handle(virtualUser User)
        {
            bool   Found      = false;
            string CouponCode = getBlock(0);

            int[]    array       = DB.runReadColumn("SELECT id FROM coupons", 0, null);
            string[] CouponArray = DB.runReadRow(string.Concat("SELECT id, coupon, code, days, amount, active, item, usedby, public, expiredate FROM coupons"));
            if ((int)CouponArray.Length <= 0)
            {
                User.send(new PACKET_SHOP_COUPON(PACKET_SHOP_COUPON.Subtype.WrongCoupon));
                return;
            }
            for (int I = 0; I < array.Length; I++)
            {
                string[] Coupon = DB.runReadRow("SELECT coupon FROM coupons WHERE id=" + array[I].ToString());
                if (Coupon[0] == CouponCode)
                {
                    Found = true;
                }
            }
            if (Found == false)
            {
                User.send(new PACKET_SHOP_COUPON(PACKET_SHOP_COUPON.Subtype.WrongCoupon));
                return;
            }
            int Actived = Convert.ToInt32(CouponArray[5]);

            string[] UsedBy = CouponArray[7].Split(',');
            int      Public = Convert.ToInt32(CouponArray[8]);

            DateTime dateTime = DateTime.ParseExact(CouponArray[9], "dd-MM-yyyy", null);
            string   str      = dateTime.ToString("yyMMdd");
            DateTime now      = DateTime.Now;
            int      num      = Convert.ToInt32(string.Format("{0:yyMMdd}", now));

            if (UsedBy.Length > 1 && Actived == '1' && Public == '0')
            {
                User.send(new PACKET_SHOP_COUPON(PACKET_SHOP_COUPON.Subtype.AlreadyUsedCouponByOther));
                return;
            }
            virtualUser user   = User;
            int         UserID = user.UserID;

            for (int N = 0; N < UsedBy.Length; N++)
            {
                if (UsedBy[N] == User.UserID.ToString())
                {
                    User.send(new PACKET_SHOP_COUPON(PACKET_SHOP_COUPON.Subtype.AlreadyUsedCouponByHimself));
                    return;
                }
            }
            if (num >= Convert.ToInt32(str))
            {
                User.send(new PACKET_SHOP_COUPON(PACKET_SHOP_COUPON.Subtype.CouponIsExpired));
                return;
            }

            int InventorySlot = User.InventorySlots;

            if (InventorySlot == 0)
            {
                User.send(new PACKET_SHOP_COUPON(PACKET_SHOP_COUPON.Subtype.InventoryFull));
                return;
            }
            string str1 = CouponArray[2];

            User.AddOutBoxItem(str1, Convert.ToInt32(CouponArray[3]), Convert.ToInt32(CouponArray[4]));
            if (Public == 1)
            {
                Actived = 1;
            }
            DB.runQuery("UPDATE coupons SET active = " + Actived + " ',' usedby = " + user.UserID + "" + "," + " WHERE id = " + CouponArray[9] + "");
            Log.AppendText(User.Nickname + " enter ingamepromocode: " + CouponArray[2]);
        }