示例#1
0
 public override void AddItemToShop(Character pCharacter, PlayerShopItem Item)
 {
     if (Items.Count == 0)
     {
         Items.Add(0, Item);
         Item.ShopSlot = 0;
     }
     else
     {
         Items.Add((byte)Items.Count, Item);
         Item.ShopSlot = (byte)Items.Count;
     }
     PlayerShopPackets.PersonalShopRefresh(pCharacter, this);
     base.AddItemToShop(pCharacter, Item);
 }
示例#2
0
 public void HandleMoveItemBack(Character pCharacter, byte slot)
 {
     if (Items.TryGetValue(slot, out PlayerShopItem pst))
     {
         pCharacter.Inventory.AddItem2(pst.sItem);
         ItemTransfer.PersonalShopGetBackItem(pCharacter.ID, pst.sItem.ItemID, pst.sItem.Amount, _transaction, pst.sItem);
         var x = pst.sItem.Amount;
         if (x == 1)
         {
             PlayerShopPackets.MoveItemToInventory(pCharacter, 0, slot);
             // Remove? but that would reorder it!!!
         }
         else
         {
             byte left = (byte)(x - 1); //amount left
             PlayerShopPackets.MoveItemToInventory(pCharacter, left, slot);
         }
     }
     InventoryPacket.NoChange(pCharacter);
 }
示例#3
0
        public void RemovePlayerFromShop(Character pCharacter)
        {
            MiniRoomBase mrb = pCharacter.Room;

            if (pCharacter == Users[0])
            {
                // Kick all players
                for (int i = 0; i < EnteredUsers; i++)
                {
                    if (pCharacter != Users[i])
                    {
                        PlayerShopPackets.CloseShop(Users[i], 2);
                        EnteredUsers--;
                        Users[i].Room       = null;
                        Users[i].RoomSlotId = 0;
                    }
                }

                PlayerShop ps = PlayerShops[mrb.ID];
                ps.RevertItems(pCharacter);
                MiniGamePacket.RemoveAnnounceBox(pCharacter);
                PlayerShops.Remove(mrb.ID);
                pCharacter.Field.PlayerShops.Remove(mrb.ID);
                pCharacter.Room       = null;
                pCharacter.RoomSlotId = 0;
            }

            else
            {
                PlayerShopPackets.RemovePlayer(pCharacter, mrb);
                EnteredUsers--;
                Users[pCharacter.RoomSlotId] = null;
                pCharacter.Room       = null;
                pCharacter.RoomSlotId = 0;
            }
        }
示例#4
0
        private static void EnterMiniRoom(Character chr, Packet packet)
        {
            if (chr.Room != null)
            {
                miniroomLog.Info($"{chr.Name} cannot enter miniroom: already in one.");
                return; // Already in a Mini Room
            }


            //MessagePacket.SendNotice("PACKET: " + packet.ToString(), chr);
            int roomId = packet.ReadInt();

            if (!MiniRoomBase.MiniRooms.TryGetValue(roomId, out var mrb))
            {
                ReportManager.FileNewReport("Tried entering a trade room without a proper ID.", chr.ID, 0);
                return; // Invalid Room ID
            }

            if (mrb.EnteredUsers == 0)
            {
                return;
            }

            if (mrb.IsFull())
            {
                miniroomLog.Info($"{chr.Name} cannot enter miniroom: already full.");
                return; // Error msg if full?
            }

            if (mrb.Users.ToList().Exists(u => u != null && u.MapID != chr.MapID))
            {
                InviteResult(chr, 1); // must be on same map. Show "not found" msg
                return;
            }

            chr.Room = mrb;
            byte nType = (byte)chr.Room.Type;

            switch (nType)
            {
            case 1:     // Omok
            {
                bool usePassword = packet.ReadBool();
                Omok omok        = MiniRoomBase.Omoks[chr.Room.ID];

                if (usePassword)
                {
                    string password = packet.ReadString();
                    if (password != omok.Password)
                    {
                        miniroomLog.Info($"{chr.Name} cannot enter omok: invalid password");
                        MiniGamePacket.ErrorMessage(chr, MiniGamePacket.MiniGameError.IncorrectPassword);
                        chr.Room = null;
                        break;
                    }
                }
                if (chr.Inventory.Mesos >= 100)
                {
                    omok.AddPlayer(chr);
                    MiniGamePacket.AddVisitor(chr, mrb);
                    MiniGamePacket.ShowWindow(chr, mrb, omok.OmokType);
                    chr.AddMesos(-100);
                    miniroomLog.Info($"{chr.Name} entered omok");
                }
                else
                {
                    miniroomLog.Info($"{chr.Name} cannot enter omok: not enough mesos");
                    MiniGamePacket.ErrorMessage(chr, MiniGamePacket.MiniGameError.NotEnoughMesos);
                }
                break;
            }

            case 3:     // Trade
            {
                miniroomLog.Info($"{chr.Name} entered trade");
                mrb.AddPlayer(chr);
                MiniRoomPacket.ShowJoin(mrb, chr);
                MiniRoomPacket.ShowWindow(mrb, chr);
                break;
            }

            case 4:     // Player Shop
            {
                miniroomLog.Info($"{chr.Name} entered playershop");
                PlayerShop shop = MiniRoomBase.PlayerShops[roomId];
                for (int i = 0; i < shop.EnteredUsers; i++)
                {
                    Character shopUser = mrb.Users[i];
                    if (shopUser != null && shopUser != chr)
                    {
                        shop.AddPlayer(chr);
                        PlayerShopPackets.AddPlayer(chr, shopUser);
                        PlayerShopPackets.OpenPlayerShop(chr, mrb);
                        PlayerShopPackets.PersonalShopRefresh(chr, shop);         //Show items
                    }
                }
                break;
            }
            }
        }
示例#5
0
        private static void CreateMiniRoomBase(Character chr, Packet packet)
        {
            if (chr.Room != null)
            {
                return;
            }

            byte nType = packet.ReadByte();

            switch (nType)
            {
            case 0:     // What is this case?
            {
                break;
            }

            case 1:     // Omok
            {
                miniroomLog.Info($"{chr.Name} creates an omok miniroom");
                MiniRoomBase omok = MiniRoomBase.CreateRoom(chr, 1, packet, false, 0);
                chr.Room = omok;

                MiniGamePacket.ShowWindow(chr, omok, MiniRoomBase.Omoks[chr.Room.ID].OmokType);
                MiniGamePacket.AddAnnounceBox(chr, (byte)MiniRoomBase.RoomType.Omok, omok.ID, omok.Title, omok.Private, omok.PieceType, false);
                break;
            }

            case 2:     // Match Cards TODO!
            {
                return;

                miniroomLog.Info($"{chr.Name} creates a match cards");
                string title       = packet.ReadString();
                bool   usePassword = packet.ReadBool();
                string password    = "";
                if (usePassword)
                {
                    password = packet.ReadString();
                }
                packet.Skip(7);
                byte cardType = packet.ReadByte();
                break;
            }

            case 3:     // Trade
            {
                miniroomLog.Info($"{chr.Name} creates a trade miniroom");
                MiniRoomBase mrb = MiniRoomBase.CreateRoom(chr, nType, packet, false, 0);
                chr.Room = mrb;
                MiniRoomPacket.ShowWindow(mrb, chr);
                break;
            }

            case 4:     // Player Shops
            {
                return;

                miniroomLog.Info($"{chr.Name} creates a player shop miniroom");
                MiniRoomBase mrb = MiniRoomBase.CreateRoom(chr, nType, packet, false, 0);
                chr.Room = mrb;
                PlayerShopPackets.OpenPlayerShop(chr, mrb);
                break;
            }
            }
        }
示例#6
0
        public void BuyItem(Character pCharacter, byte slot, short quantity)
        {
            //This may seem confusing, but the client calculates the amount left itself.
            //The formula is bundles * bundleamount, so if you have 2 bundles with 25 in each, it will obviously show 50. If you have 100 items in 1 bundle, it will show you 100
            PlayerShopItem pst = Items[slot];
            PlayerShop     ps  = MiniRoomBase.PlayerShops[pCharacter.Room.ID];

            if (pst == null)
            {
                return;
            }

            if (pCharacter.AssertForHack(
                    quantity < 0,
                    $"PlayerShop hack: trying to buy negative amount. Requested {quantity}"
                    ))
            {
                return;
            }

            if (pst.sItem.Amount <= 0)
            {
                // TODO: Get packet?
                return;
            }


            var cost       = quantity * pst.Price;
            var realAmount = (short)(quantity * pst.BundleAmount);

            if (cost > pCharacter.Inventory.Mesos)
            {
                // TODO: Get packet?
                return;
            }

            if (pCharacter.AssertForHack(
                    pst.Bundles < quantity,
                    $"PlayerShop hack: buying more than there's in store. Bundle: {pst.Bundles}, requested {quantity}"
                    ))
            {
                return;
            }

            if (pCharacter.AssertForHack(
                    pst.sItem.Amount < realAmount,
                    $"PlayerShop hack: buying more than there's in store. Item amount: {pst.sItem.Amount}, requested {realAmount}"
                    ))
            {
                return;
            }


            pCharacter.Inventory.AddNewItem(pst.sItem.ItemID, realAmount);
            pCharacter.AddMesos(-cost);
            Owner.AddMesos(cost);

            MesosTransfer.PlayerBuysFromPersonalShop(pCharacter.ID, Owner.ID, cost, _transaction);
            ItemTransfer.PersonalShopBoughtItem(Owner.ID, pCharacter.ID, pst.sItem.ItemID, realAmount, TransactionID, pst.sItem);



            pst.Bundles      -= quantity;
            pst.sItem.Amount -= realAmount;

            PlayerShopPackets.PersonalShopRefresh(pCharacter, ps);
            PlayerShopPackets.SoldItemResult(Owner, pCharacter, slot, quantity);
        }