예제 #1
0
        public static MapleItem CreateItem(int itemId, string source, short quantity = 1, bool randomStats = false)
        {
            MapleInventoryType type = ItemConstants.GetInventoryType(itemId);

            if (type == MapleInventoryType.Equip)
            {
                WzEquip wzInfo = DataBuffer.GetEquipById(itemId);
                if (wzInfo != null)
                {
                    MapleEquip equip = new MapleEquip(itemId, source);
                    equip.SetDefaultStats(wzInfo, randomStats);
                    return(equip);
                }
            }
            else if (type != MapleInventoryType.Undefined)
            {
                WzItem wzInfo = DataBuffer.GetItemById(itemId);
                if (wzInfo != null)
                {
                    if (wzInfo.SlotMax > 0 && quantity > wzInfo.SlotMax)
                    {
                        quantity = (short)wzInfo.SlotMax;
                    }
                    MapleItem item = new MapleItem(itemId, source, quantity);
                    return(item);
                }
            }
            return(null);
        }
예제 #2
0
        //todo
        //response to join trade room if the owner disconnected or closed it
        //response packet if character is busy
        //"enabled actions" needs worked on, such as after adding an item to the trade the client expects its actions enabled.
        private static void HandleAddItem(PacketReader pr, MapleCharacter chr)
        {
            MapleInventoryType inventoryType = (MapleInventoryType)pr.ReadByte();

            short fromSlot  = pr.ReadShort();
            short quantity  = pr.ReadShort();
            byte  tradeSlot = pr.ReadByte();



            MapleItem item = chr.Inventory.GetItemSlotFromInventory(inventoryType, fromSlot);

            if (item != null)
            {
                if (chr.Trade.AddItem(item, tradeSlot, quantity, chr))
                {
                    if (item.Quantity == quantity)
                    {
                        chr.Client.SendPacket(MapleInventory.Packets.RemoveItem(inventoryType, fromSlot));
                    }
                    else
                    {
                        short newVal = (short)(item.Quantity - quantity);
                        chr.Client.SendPacket(MapleInventory.Packets.UpdateItemQuantity(inventoryType, fromSlot, newVal));
                    }
                }
            }
        }
예제 #3
0
        private static bool GetAndCheckItemsFromInventory(MapleInventory inventory, short equipSlot, short scrollSlot, out MapleEquip equip, out MapleItem scroll)
        {
            MapleInventoryType equipInventory = equipSlot < 0 ? MapleInventoryType.Equipped : MapleInventoryType.Equip;

            equip  = inventory.GetItemSlotFromInventory(equipInventory, equipSlot) as MapleEquip;
            scroll = inventory.GetItemSlotFromInventory(MapleInventoryType.Use, scrollSlot);
            return(equip != null && scroll != null);
        }
예제 #4
0
            public static PacketWriter ItemSortResponse(MapleInventoryType inventoryType)
            {
                PacketWriter pw = new PacketWriter(SendHeader.ItemSortComplete);

                pw.WriteBool(true);
                pw.WriteByte((byte)inventoryType);

                return(pw);
            }
예제 #5
0
        public static void Handle(MapleClient c, PacketReader pw)
        {
            MapleCharacter chr = c.Account.Character;

            if (!chr.DisableActions())
            {
                return;
            }
            int tickCount           = pw.ReadInt();
            MapleInventoryType type = (MapleInventoryType)pw.ReadByte();
            short oldPosition       = pw.ReadShort();
            short newPosition       = pw.ReadShort();
            short quantity          = pw.ReadShort();
            bool  success           = false;

            if (oldPosition == newPosition)
            {
                return;
            }
            try
            {
                MapleInventory inventory = chr.Inventory;

                if (newPosition < 0 && oldPosition > 0) //equip item
                {
                    success = inventory.EquipItem(oldPosition, newPosition);
                }
                else if (oldPosition < 0 && newPosition > 0) //unequip item
                {
                    success = inventory.UnEquip(oldPosition, newPosition);
                }
                else if (newPosition == 0) //drop item
                {
                    if (!chr.Map.DropItemLimit)
                    {
                        success = inventory.DropItem(type, oldPosition, quantity);
                    }
                }
                else //item moved within inventory
                {
                    success = inventory.MoveItem(type, oldPosition, newPosition);
                }
            }
            finally
            {
                chr.EnableActions(!success);
            }
        }
예제 #6
0
        public void Sell(MapleClient c, MapleInventoryType type, byte slot, short quantity)
        {
            if (quantity == short.MinValue || quantity == 0)
            {
                quantity = 1;
            }

            MapleItemInformationProvider ii = MapleItemInformationProvider.Instance;
            IMapleItem item = c.Player.Inventorys[type.Value].Inventory[slot];

            if (ii.IsThrowingStar(item.ItemId))
            {
                quantity = item.Quantity;
            }
            if (quantity < 0)
            {
                AutobanManager.Instance.AddPoints(c, 1000, 0, "Selling " + quantity + " " + item.ItemId + " (" + type + "/" + slot + ")");
                return;
            }
            short iQuant = item.Quantity;

            if (iQuant == short.MinValue)
            {
                iQuant = 1;
            }

            if (quantity <= iQuant && iQuant > 0)
            {
                MapleInventoryManipulator.RemoveFromSlot(c, type, slot, quantity, false);
                double price;
                if (ii.IsThrowingStar(item.ItemId))
                {
                    price = ii.GetWholePrice(item.ItemId) / (double)ii.GetSlotMax(c, item.ItemId);
                }
                else
                {
                    price = ii.GetPrice(item.ItemId);
                }
                int recvMesos = (int)Math.Max(Math.Ceiling(price * quantity), 0);
                if (Math.Abs(price + 1) > 0.000001 && recvMesos > 0)
                {
                    c.Player.GainMeso(recvMesos, true);
                }

                c.Send(PacketCreator.ConfirmShopTransaction(0x8));
            }
        }
예제 #7
0
        public static void HandleItemSort(MapleClient c, PacketReader pr)
        {
            MapleCharacter chr = c.Account.Character;

            if (!chr.DisableActions())
            {
                return;
            }
            int  tickCount = pr.ReadInt();
            byte inventory = pr.ReadByte();

            if (inventory < 1 || inventory > 5)
            {
                return;
            }
            MapleInventoryType type = (MapleInventoryType)inventory;

            chr.Inventory.SortItems(type, c);
            chr.EnableActions(false);
            c.SendPacket(Packets.ItemSortResponse(type));
        }
예제 #8
0
 public bool Equals(MapleInventoryType other) => Value == other.Value;
        public static void Handle(MapleClient c, PacketReader pr)
        {
            try
            {
                if (c.NpcEngine != null && c.NpcEngine.IsShop)
                {
                    byte mode  = pr.ReadByte();
                    int  NpcId = c.NpcEngine.NpcId;
                    switch (mode)
                    {
                    case 0:
                    {
                        short shopIndex = pr.ReadShort();
                        int   itemId    = pr.ReadInt();
                        short amount    = pr.ReadShort();
                        c.NpcEngine.BuyItem(itemId, shopIndex, amount);
                        break;
                    }

                    case 1:     //sell
                    {
                        short inventoryIndex = pr.ReadShort();
                        int   itemId         = pr.ReadInt();
                        short qty            = pr.ReadShort();

                        MapleInventoryType invType = ItemConstants.GetInventoryType(itemId);
                        switch (invType)
                        {
                        case MapleInventoryType.Equip:
                        case MapleInventoryType.Etc:
                        case MapleInventoryType.Setup:
                        case MapleInventoryType.Use:
                            break;

                        default:
                            return;         // Not a valid item
                        }
                        WzItem wzitem = DataBuffer.GetItemById(itemId);
                        if (wzitem == null)
                        {
                            wzitem = DataBuffer.GetEquipById(itemId);
                        }
                        if (wzitem == null)     // Item doesnt exist (anymore?)
                        {
                            return;
                        }
                        if (wzitem.NotSale || wzitem.IsCashItem || wzitem.IsQuestItem)
                        {
                            return;
                        }
                        byte response = 0;
                        if (!wzitem.IsQuestItem)
                        {
                            MapleInventory inventory = c.Account.Character.Inventory;
                            MapleItem      item      = inventory.GetItemSlotFromInventory(invType, inventoryIndex);
                            if (item?.ItemId == itemId && item.Quantity >= qty)
                            {
                                if (inventory.Mesos + wzitem.Price > GameConstants.MAX_MESOS)
                                {
                                    response = 2;     // You do not have enough mesos
                                }
                                else
                                {
                                    inventory.RemoveItemsFromSlot(item.InventoryType, item.Position, qty, true);
                                    inventory.GainMesos(wzitem.Price * qty, false, false);
                                }
                                // TODO: buyback
                            }
                        }
                        PacketWriter pw = new PacketWriter();
                        pw.WriteHeader(SendHeader.NpcTransaction);
                        pw.WriteByte(response);
                        pw.WriteByte(0);
                        pw.WriteByte(0);
                        c.SendPacket(pw);
                        break;
                    }

                    case 3:
                    {
                        c.NpcEngine.Dispose();
                        break;
                    }

                    default:
                    {
                        c.NpcEngine.ScriptInstance = null;
                        ServerConsole.Warning("Unkown NpcShopActionHandler mode:" + mode);
                        ServerConsole.Info(Functions.ByteArrayToStr(pr.ToArray()));
                        break;
                    }
                    }
                }
            }
            catch (Exception ex)
            {
                ServerConsole.Error("NpcShopActionHandler Failure");
                ServerConsole.Error(ex.Message);
                if (c.NpcEngine != null)
                {
                    c.NpcEngine.Dispose();
                }
            }
        }