Ejemplo 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));
        }
Ejemplo n.º 2
0
        public void PlayerGMCommand(GPlayer player, Packet packet)
        {
            GameBase   Game;
            MailSender AddMail;
            Channel    PLobby;
            uint       ItemTypeID, Quantity, PlayerConnectionID;
            string     Nick;
            byte       Arg1;

            if (!(player.GetCapability == 4))
            {
                WriteConsole.WriteLine("HandleGMCommands: Player has requested gm command but he is not an admin");
                return;
            }

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

            PLobby = player.Lobby;

            if (PLobby == null)
            {
                return;
            }
            switch ((GM_COMMAND)CommandId)
            {
            case GM_COMMAND.GM_Visibility:     //command /visible [on/off] (Ficar Visivel Ou Invisivel)
            {
                packet.ReadByte(out Arg1);
                switch ((TVISIBLE_ACTION)Arg1)
                {
                case TVISIBLE_ACTION.Enable:             //visibilidade: on
                {
                    player.Visible = 4;
                }
                break;

                case TVISIBLE_ACTION.Disable:            //visibilidade: off
                {
                    player.Visible = 0;
                }
                break;
                }
                PLobby.UpdatePlayerLobbyInfo(player);
                break;
            }

            case GM_COMMAND.Player_Whisper:     //command /whisper  [on/off]
            {
                packet.ReadByte(out Arg1);
                switch ((TWHISPER_ACTION)Arg1)
                {
                case TWHISPER_ACTION.Disable:             //whisper: off
                {
                }
                break;

                case TWHISPER_ACTION.Enable:            //whiper: on
                {
                }
                break;
                }
                player.SendResponse(new byte[] { 0x0F, 0x00 });
            }
            break;

            case GM_COMMAND.Player_Lobby:     //command /TLobby  [on/off]
            {
                packet.ReadByte(out Arg1);
                switch (Arg1)
                {
                case 0:             //lobby: off
                {
                }
                break;

                case 2:            //lobby: on
                {
                }
                break;
                }
                player.SendResponse(new byte[] { 0x0F, 0x00 });
            }
            break;

            case GM_COMMAND.Player_Open:     //command /open [nick]
            {
                packet.ReadPStr(out Nick);
                WriteConsole.WriteLine("test =>" + Nick);
            }
            break;

            case GM_COMMAND.Player_Close:     //command /close [nick]
            {
                packet.ReadPStr(out Nick);
                WriteConsole.WriteLine("test =>" + Nick);
            }
            break;

            case GM_COMMAND.Player_Kick:     //command /kick [nick] [op]
            {
                if (!packet.ReadUInt32(out PlayerConnectionID))
                {
                    return;
                }

                var client = PLobby.GetPlayerByConnectionId(PlayerConnectionID);

                if (client == null)
                {
                    return;
                }

                player.SendResponse(new byte[] { 0x0F, 0x00 });

                client.Close();
            }
            break;

            case GM_COMMAND.Player_Disconnect_By_UID:     //command /discon_uid [uid]
            {
                if (!packet.ReadUInt32(out PlayerConnectionID))
                {
                    return;
                }

                var client = PLobby.GetPlayerByConnectionId(PlayerConnectionID);

                if (client == null)
                {
                    return;
                }

                client.SendResponse(new byte[] { 0x76, 0x02, 0xFA, 0x00, 0x00, 0x00 });

                client.Close();
            }
            break;

            case GM_COMMAND.Player_Change_GameWind:     //Command /wind [spd] [dir]
            {
                packet.ReadByte(out byte WP);

                packet.ReadByte(out byte WD);

                Game = PLobby.GetGameHandle(player);

                if (Game == null)
                {
                    return;
                }

                if (Game != null && Game.GameType != GAME_TYPE.CHAT_ROOM)
                {
                    Game.Send(ShowWind(WP, WD));
                }
            }
            break;

            case GM_COMMAND.Player_Change_GameWeather:     //Command /weather [type] 'fine', 'rain', 'snow', 'cloud' (Chuva, Neve ...)
            {
                packet.ReadByte(out Arg1);

                Game = PLobby.GetGameHandle(player);

                if (Game == null)
                {
                    return;
                }

                Game.Send(ShowWeather(Arg1));
            }
            break;

            case GM_COMMAND.Player_GiveItem:               //giveitem: /giveitem [nick][typeid][num]
            {
                packet.ReadUInt32(out PlayerConnectionID); //meu id de conexão ou do client
                packet.ReadUInt32(out ItemTypeID);         //id do item enviado
                packet.ReadUInt32(out Quantity);           //quantidade de itens enviado

                if (!IffEntry.IsExist(ItemTypeID))
                {
                    return;
                }

                var Client = (GPlayer)(player.Server).GetClientByConnectionId(PlayerConnectionID);

                if (null == Client)
                {
                    return;
                }
                AddMail = new MailSender();

                try
                {
                    AddMail.Sender = "@GM";
                    AddMail.AddText("GM presents you");
                    AddMail.AddItem(ItemTypeID, Quantity, true);
                    // Add to db
                    AddMail.Send(Client.GetUID);
                    Client.SendMailPopup();

                    player.SendResponse(new byte[] { 0x0F, 0x00 });
                }
                finally
                {
                    AddMail.Dispose();
                }
            }
            break;

            case GM_COMMAND.Player_GoldenBell:     //Command goldenbell ID (enviar item para todos da sala)
            {
                //id do item enviado
                if (!packet.ReadUInt32(out ItemTypeID))
                {
                    return;
                }
                //quantidade de itens enviado
                if (!packet.ReadUInt32(out Quantity))
                {
                    return;
                }
                //Checagem do item
                if (!IffEntry.IsExist(ItemTypeID))
                {
                    return;
                }

                Game = PLobby.GetGameHandle(player);

                if (Game == null)
                {
                    return;
                }
                AddMail = new MailSender();

                try
                {
                    foreach (var Client in Game.Players)
                    {
                        AddMail.Sender = "@GM";
                        AddMail.AddText("GM presents you");
                        AddMail.AddItem(ItemTypeID, Quantity, true);
                        // Add to db
                        AddMail.Send(Client.GetUID);
                        Client.SendMailPopup();
                    }
                }
                finally
                {
                    AddMail.Dispose();
                }
            }
            break;

            case GM_COMMAND.HioHoleCupScale:
            {
            }
            break;

            case GM_COMMAND.SetMission:     //Command /setmission [MISSION_NUM]
            {
                packet.ReadByte(out byte MissionID);

                WriteConsole.WriteLine("SetMission => " + MissionID);
            }
            break;

            case GM_COMMAND.MatchMap:    //Command /matchmap [mapcount]
            {
                packet.ReadUInt32(out uint MapCount);

                WriteConsole.WriteLine("MatchMap => " + MapCount);
            }
            break;

            case GM_COMMAND.Notice_Prize:
            {
                //List<TNoticePrize> itens;
                if (!packet.ReadByte(out Arg1))
                {
                    return;
                }
                switch (Arg1)
                {
                case 0:             //lobby: off
                {
                    if (!packet.ReadUInt32(out uint Count))
                    {
                        return;
                    }
                    for (int i = 0; i < Count; i++)
                    {
                        var item = (TNoticePrize)packet.Read(new TNoticePrize());
                    }
                }
                break;

                case 2:            //lobby: on
                {
                }
                break;
                }
                player.SendResponse(new byte[] { 0x0F, 0x00 });
            }
            break;

            default:
            {
                WriteConsole.WriteLine("Command ID UNK => " + CommandId);
                packet.Save();
            }
            break;
            }
        }