Exemplo n.º 1
0
        public void PlayerBuyItemGameShop(GPlayer player, Packet packet)
        {
            ShopItemRequest ShopItem;
            uint            DeletePang,
                            DeleteCookie,
                            RentalPrice;

            if (!packet.ReadByte(out byte BuyType))
            {
                return;
            }

            if (!packet.ReadUInt16(out ushort BuyTotal))
            {
                return;
            }

            switch ((TGAME_SHOP_ACTION)BuyType)
            {
            case TGAME_SHOP_ACTION.Normal:
            {
                for (int Count = 0; Count <= BuyTotal - 1; Count++)
                {
                    ShopItem = (ShopItemRequest)packet.Read(new ShopItemRequest());

                    Console.WriteLine($"[BUY_ITEM_RESULT]: TypeID =>{ShopItem.IffTypeId}, Name =>{IffEntry.GetItemName(ShopItem.IffTypeId)} IsPang =>{ShopItem.PangPrice > 0}, IsCookie =>{ShopItem.CookiePrice > 0}");

                    if (!IffEntry.IsExist(ShopItem.IffTypeId))
                    {
                        player.SendResponse(ShowBuyItemSucceed(TGAME_SHOP.PASSWORD_WRONG));
                        return;
                    }
                    if (!IffEntry.IsBuyable(ShopItem.IffTypeId))
                    {
                        player.SendResponse(ShowBuyItemSucceed(TGAME_SHOP.CANNOT_BUY_ITEM));
                        return;
                    }
                    if (!player.Inventory.Available(ShopItem.IffTypeId, ShopItem.IffQty))
                    {
                        player.SendResponse(ShowBuyItemSucceed(TGAME_SHOP.BUY_FAIL));
                        return;
                    }
                    if (IffEntry.GetPrice(ShopItem.IffTypeId, ShopItem.IffDay) <= 0)
                    {
                        player.SendResponse(ShowBuyItemSucceed(TGAME_SHOP.BUY_FAIL));
                        return;
                    }
                    switch (IffEntry.GetShopPriceType(ShopItem.IffTypeId))
                    {
                    case 0:
                    case 2:
                    case 6:
                    case 32:
                    case 96:            //Pang
                    {
                        DeletePang = IffEntry.GetPrice(ShopItem.IffTypeId, ShopItem.IffDay) * ShopItem.IffQty;
                        if (!player.RemovePang(DeletePang))
                        {
                            player.SendResponse(ShowBuyItemSucceed(TGAME_SHOP.PANG_NOTENOUGHT));
                            WriteConsole.WriteLine("HandlePlayerBuyItemGameShop: Cannot Delete Player_{0} {1} pang's", new object[] { player.GetLogin, DeletePang });
                            return;
                        }
                    }
                    break;

                    case 1:
                    case 33:
                    case 97:            //Cookie
                    {
                        DeleteCookie = IffEntry.GetPrice(ShopItem.IffTypeId, ShopItem.IffDay);
                        if (!player.RemoveCookie(DeleteCookie))
                        {
                            player.SendResponse(ShowBuyItemSucceed(TGAME_SHOP.COOKIE_NOTENOUGHT));
                            WriteConsole.WriteLine("HandlePlayerBuyItemGameShop: Cannot Delete Player_{0} {1} cookie's", new object[] { player.GetLogin, DeleteCookie });
                            return;
                        }
                    }
                    break;

                    default:
                    {
                        if (ShopItem.CookiePrice > 0)
                        {
                            player.SendResponse(ShowBuyItemSucceed(TGAME_SHOP.BUY_FAIL));
                            Utils.Log("GameShopCore", $"CookiePriceType: {IffEntry.GetShopPriceType(ShopItem.IffTypeId)}", "GameShopCoreSystem");
                            return;
                        }
                        if (ShopItem.PangPrice > 0)
                        {
                            player.SendResponse(ShowBuyItemSucceed(TGAME_SHOP.BUY_FAIL));
                            Utils.Log("GameShopCore", $"PangPriceType: {IffEntry.GetShopPriceType(ShopItem.IffTypeId)}", "GameShopCoreSystem");
                            return;
                        }
                    }
                    break;
                    }
                    AddShopItem(player, ShopItem);
                }
            }
            break;

            case TGAME_SHOP_ACTION.Rental:
            {
                for (int Count = 0; Count <= BuyTotal - 1; Count++)
                {
                    ShopItem = (ShopItemRequest)packet.Read(new ShopItemRequest());

                    if (!(GetItemGroup(ShopItem.IffTypeId) == 2))
                    {
                        player.SendResponse(ShowBuyItemSucceed(TGAME_SHOP.ITEM_CANNOT_PURCHASE));
                        return;
                    }

                    if (!IffEntry.IsExist(ShopItem.IffTypeId))
                    {
                        player.SendResponse(ShowBuyItemSucceed(TGAME_SHOP.PASSWORD_WRONG));
                        return;
                    }
                    if (!IffEntry.IsBuyable(ShopItem.IffTypeId))
                    {
                        player.SendResponse(ShowBuyItemSucceed(TGAME_SHOP.CANNOT_BUY_ITEM));
                        return;
                    }
                    if (player.Inventory.IsExist(ShopItem.IffTypeId))
                    {
                        player.SendResponse(ShowBuyItemSucceed(TGAME_SHOP.ITEM_CANNOT_PURCHASE));
                        return;
                    }
                    RentalPrice = IffEntry.GetRentalPrice(ShopItem.IffTypeId);

                    if (RentalPrice <= 0)
                    {
                        player.SendResponse(ShowBuyItemSucceed(TGAME_SHOP.ITEM_CANNOT_PURCHASE));
                        return;
                    }
                    if (!player.RemovePang(RentalPrice))
                    {
                        player.SendResponse(ShowBuyItemSucceed(TGAME_SHOP.PANG_NOTENOUGHT));
                        WriteConsole.WriteLine("PlayerPlayerBuyItemGameShop: Cannot delete Player_{0} {1} pang(s)", new object[] { player.GetNickname, RentalPrice });
                    }
                    AddShopRentItem(player, ShopItem);
                }
            }
            break;
            }
            player.SendResponse(ShowBuyItemSucceed(TGAME_SHOP.BUY_SUCCESS, player.GetPang, player.GetCookie));
        }
Exemplo n.º 2
0
        public void PlayerRenewRent(GPlayer player, Packet packet)
        {
            uint PartCharge;


            if (!packet.ReadUInt32(out uint PartIndex))
            {
                return;
            }

            var PPart = player.Inventory.ItemWarehouse.GetItem(PartIndex);

            if (PPart == null)
            {
                player.SendResponse(new byte[] { 0x8F, 0x01, 0x05 });

                WriteConsole.WriteLine("PlayerPlayerRenewRent: variable ppart is null");
                return;
            }

            if (!(GetItemGroup(PPart.ItemTypeID) == 2) || (!(PPart.ItemFlag == 0x62)))
            {
                player.SendResponse(new byte[] { 0x8F, 0x01, 0x03 });

                WriteConsole.WriteLine("PlayerPlayerRenewRent: Error 01");
                return;
            }
            PartCharge = IffEntry.GetRentalPrice(PPart.ItemTypeID);

            if (PartCharge <= 0)
            {
                player.SendResponse(new byte[] { 0x8F, 0x01, 0x05 });

                WriteConsole.WriteLine("PlayerPlayerRenewRent: Error RentalPrice");
                return;
            }

            if (!player.RemovePang(PartCharge))
            {
                player.SendResponse(new byte[] { 0x8F, 0x01, 0x04 });

                WriteConsole.WriteLine("PlayerPlayerRenewRent: Error RemovePang");
                return;
            }

            player.SendPang();

            PPart.Renew();


            try
            {
                packet.Write(new byte[] { 0x8F, 0x01, 0x00 });
                packet.WriteUInt32(PPart.ItemTypeID);
                packet.WriteUInt32(PPart.ItemIndex);
                player.SendResponse(packet.GetBytes());
            }
            finally
            {
                packet.Dispose();
            }
        }