Пример #1
0
        private void Swap(IMapleItem source, IMapleItem target)
        {
            Inventory.Remove(source.Position);
            Inventory.Remove(target.Position);

            var swapPos = source.Position;

            source.Position = target.Position;
            target.Position = swapPos;

            if (Inventory.ContainsKey(source.Position))
            {
                Inventory[source.Position] = source;
            }
            else
            {
                Inventory.Add(source.Position, source);
            }

            if (Inventory.ContainsKey(target.Position))
            {
                Inventory[target.Position] = target;
            }
            else
            {
                Inventory.Add(target.Position, target);
            }
        }
Пример #2
0
 public MapleMapItem(IMapleItem item, Point position, IMapleMapObject dropper, MapleCharacter owner)
 {
     Position = position;
     Item     = item;
     Dropper  = dropper;
     Owner    = owner;
     Meso     = 0;
 }
Пример #3
0
 public int CompareTo(IMapleItem other)
 {
     if (Math.Abs(Position) < Math.Abs(other.Position))
     {
         return(-1);
     }
     return(Math.Abs(Position) == Math.Abs(other.Position) ? 0 : 1);
 }
Пример #4
0
        public void AddFromDb(IMapleItem item)
        {
            if (item.Position > 127 && Type != MapleInventoryType.Equipped)
            {
                Console.WriteLine($"Item with negative position in non-equipped IV wtf? ID:{item.ItemId}");
            }

            if (Inventory.ContainsKey(item.Position))
            {
                Inventory[item.Position] = item;
            }
            else
            {
                Inventory.Add(item.Position, item);
            }
        }
Пример #5
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));
            }
        }
Пример #6
0
        public byte AddItem(IMapleItem item)
        {
            var slotId = GetNextFreeSlot();

            if (slotId == 0xFF)
            {
                return(0xFF);
            }

            if (Inventory.ContainsKey(slotId))
            {
                Inventory[slotId] = item;
            }
            else
            {
                Inventory.Add(slotId, item);
            }
            item.Position = slotId;
            return(slotId);
        }
Пример #7
0
        public static void Drop(MapleClient c, MapleInventoryType type, byte srcSlot, short quantity)
        {
            MapleItemInformationProvider ii = MapleItemInformationProvider.Instance;

            if (srcSlot > 127)
            {
                type = MapleInventoryType.Equipped;
            }
            IMapleItem source = c.Player.Inventorys[type.Value].Inventory[srcSlot];

            if (quantity > ii.GetSlotMax(c, source.ItemId))
            {
                //try
                //{
                //    c.getChannelServer().getWorldInterface().broadcastGMMessage(c.Player.getName(), PacketCreator.serverNotice(0, c.Player.getName() + " is dropping more than slotMax.").getBytes());
                //}
                //catch (Throwable u)
                //{
                //}
            }
            if (quantity < 0 || quantity == 0 && !ii.IsThrowingStar(source.ItemId) && !ii.IsBullet(source.ItemId))
            {
                //String message = "Dropping " + quantity + " " + (source == null ? "?" : source.ItemId) + " (" +type.name() + "/" + srcSlot + ")";
                //log.info(MapleClient.getLogMessage(c, message));
                c.Close(); // disconnect the client as is inventory is inconsistent with the serverside inventory
                return;
            }
            Point dropPos = c.Player.Position;

            if (quantity < source.Quantity && !ii.IsThrowingStar(source.ItemId) && !ii.IsBullet(source.ItemId))
            {
                IMapleItem target = source.Copy();
                target.Quantity  = quantity;
                source.Quantity -= quantity;
                c.Send(PacketCreator.DropInventoryItemUpdate(type, source));
                bool weddingRing = source.ItemId == 1112804;
                bool liRing      = source.ItemId == 1112405;
                if (weddingRing)
                {
                    c.Player.Map.disappearingItemDrop(c.Player, c.Player, target, dropPos);
                }
                else if (liRing)
                {
                    c.Player.Map.disappearingItemDrop(c.Player, c.Player, target, dropPos);
                }
                else if (c.Player.Map.Everlast)
                {
                    if (ii.IsDropRestricted(target.ItemId))
                    {
                        c.Player.Map.disappearingItemDrop(c.Player, c.Player, target, dropPos);
                    }
                    else
                    {
                        c.Player.Map.spawnItemDrop(c.Player, c.Player, target, dropPos, true, false);
                    }
                }
                else
                {
                    if (ii.IsDropRestricted(target.ItemId))
                    {
                        c.Player.Map.disappearingItemDrop(c.Player, c.Player, target, dropPos);
                    }
                    else
                    {
                        c.Player.Map.spawnItemDrop(c.Player, c.Player, target, dropPos, true, false);
                    }
                }
            }
            else
            {
                c.Player.Inventorys[type.Value].RemoveSlot(srcSlot);
                c.Send(PacketCreator.DropInventoryItem(srcSlot > 127 ? MapleInventoryType.Equip : type, srcSlot));
                bool liRing = source.ItemId == 1112405;
                if (srcSlot > 127)
                {
                    c.Player.EquipChanged();
                }
                if (c.Player.Map.Everlast)
                {
                    if (ii.IsDropRestricted(source.ItemId))
                    {
                        c.Player.Map.disappearingItemDrop(c.Player, c.Player, source, dropPos);
                    }
                    else
                    {
                        c.Player.Map.spawnItemDrop(c.Player, c.Player, source, dropPos, true, false);
                        if (liRing)
                        {
                            c.Player.Map.disappearingItemDrop(c.Player, c.Player, source, dropPos);
                        }
                        else
                        {
                            c.Player.Map.spawnItemDrop(c.Player, c.Player, source, dropPos, true, true);
                        }
                    }
                }
                else
                {
                    if (ii.IsDropRestricted(source.ItemId))
                    {
                        c.Player.Map.disappearingItemDrop(c.Player, c.Player, source, dropPos);
                    }
                    else
                    {
                        if (liRing)
                        {
                            c.Player.Map.disappearingItemDrop(c.Player, c.Player, source, dropPos);
                        }
                        else
                        {
                            c.Player.Map.spawnItemDrop(c.Player, c.Player, source, dropPos, true, true);
                        }
                    }
                }
            }
        }
Пример #8
0
        public static void Equip(MapleClient c, short src, short dst)
        {
            MapleItemInformationProvider ii = MapleItemInformationProvider.Instance;

            byte srcSlot = (byte)src;
            byte dstSlot = (byte)dst;

            Equip source = c.Player.Inventorys[MapleInventoryType.Equip.Value].Inventory.FirstOrDefault(x => x.Key == srcSlot).Value as Equip;
            Equip target = c.Player.Inventorys[MapleInventoryType.Equipped.Value].Inventory.FirstOrDefault(x => x.Key == dstSlot).Value as Equip;

            if (source == null)
            {
                return;
            }
            if (!c.Player.IsGm)
            {
                switch (source.ItemId)
                {
                case 1002140:     // Wizet Invincible Hat
                case 1042003:     // Wizet Plain Suit
                case 1062007:     // Wizet Plain Suit Pants
                case 1322013:     // Wizet Secret Agent Suitcase
                    RemoveAllById(c, source.ItemId, false);
                    c.Player.DropMessage(PacketCreator.ServerMessageType.Popup, "无法佩带此物品");
                    return;
                }
            }
            int  reqLevel = ii.GetReqLevel(source.ItemId);
            int  reqStr   = ii.GetReqStr(source.ItemId);
            int  reqDex   = ii.GetReqDex(source.ItemId);
            int  reqInt   = ii.GetReqInt(source.ItemId);
            int  reqLuk   = ii.GetReqLuk(source.ItemId);
            bool cashSlot = false;

            if (source.ItemId == 1812006)
            {
                RemoveAllById(c, source.ItemId, false);
                c.Player.DropMessage(PacketCreator.ServerMessageType.Popup, "物品已被封印");
                return;
            }
            if (dstSlot < 0x9D)
            {
                cashSlot = true;
            }
            if (!ii.IsCash(source.ItemId))
            {
                string type = ii.GetType(source.ItemId);
                if ((type.Equals("Cp", StringComparison.CurrentCultureIgnoreCase) && dstSlot != 0xFF) ||
                    (type.Equals("Af", StringComparison.CurrentCultureIgnoreCase) && dstSlot != 0xFE) ||
                    (type.Equals("Ay", StringComparison.CurrentCultureIgnoreCase) && dstSlot != 0xFD) ||
                    (type.Equals("Ae", StringComparison.CurrentCultureIgnoreCase) && dstSlot != 0xFC) ||
                    ((type.Equals("Ma", StringComparison.CurrentCultureIgnoreCase) || type.Equals("MaPn", StringComparison.CurrentCultureIgnoreCase)) && dstSlot != 0xFB) ||
                    (type.Equals("Pn", StringComparison.CurrentCultureIgnoreCase) && dstSlot != 0xFA) ||
                    (type.Equals("So", StringComparison.CurrentCultureIgnoreCase) && dstSlot != 0xF9) ||
                    (type.Equals("Gv", StringComparison.CurrentCultureIgnoreCase) && dstSlot != 0xF8) ||
                    (type.Equals("Sr", StringComparison.CurrentCultureIgnoreCase) && dstSlot != 0xF7) ||
                    (type.Equals("Si", StringComparison.CurrentCultureIgnoreCase) && dstSlot != 0xF6) ||
                    ((type.Equals("Wp", StringComparison.CurrentCultureIgnoreCase) || type.Equals("WpSi", StringComparison.CurrentCultureIgnoreCase)) && dstSlot != 0xF5) ||
                    (type.Equals("Pe", StringComparison.CurrentCultureIgnoreCase) && dstSlot != 0xEF))
                {
                    c.Send(PacketCreator.EnableActions());
                    return;
                }
            }
            if ((ii.GetName(source.ItemId).Contains("(Male)") && !c.Player.Gender) ||
                (ii.GetName(source.ItemId).Contains("(Female)") && c.Player.Gender) ||
                reqLevel > c.Player.Level ||
                reqStr > c.Player.Localstr ||
                reqDex > c.Player.Localdex ||
                reqInt > c.Player.Localint ||
                reqLuk > c.Player.Localluk ||
                (cashSlot && !ii.IsCash(source.ItemId)))
            {
                c.Send(PacketCreator.EnableActions());
                return;
            }

            switch (dstSlot)
            {
            case 0xFA:
            {
                // unequip the overall
                IMapleItem top;
                if (c.Player.Inventorys[MapleInventoryType.Equipped.Value].Inventory.TryGetValue(0xFB, out top) && ii.IsOverall(top.ItemId))
                {
                    if (c.Player.Inventorys[MapleInventoryType.Equip.Value].IsFull())
                    {
                        c.Send(PacketCreator.GetInventoryFull());
                        c.Send(PacketCreator.GetShowInventoryFull());
                        return;
                    }
                    UnEquip(c, -5, c.Player.Inventorys[MapleInventoryType.Equip.Value].GetNextFreeSlot());
                }
            }
            break;

            case 0xFB:
            {        // unequip the bottom and top
                IMapleItem top    = c.Player.Inventorys[MapleInventoryType.Equipped.Value].Inventory.FirstOrDefault(x => x.Key == 0xFB).Value;
                IMapleItem bottom = c.Player.Inventorys[MapleInventoryType.Equipped.Value].Inventory.FirstOrDefault(x => x.Key == 0xFA).Value;
                if (top != null && ii.IsOverall(source.ItemId))
                {
                    if (c.Player.Inventorys[MapleInventoryType.Equip.Value].IsFull(bottom != null && ii.IsOverall(source.ItemId) ? 1 : 0))
                    {
                        c.Send(PacketCreator.GetInventoryFull());
                        c.Send(PacketCreator.GetShowInventoryFull());
                        return;
                    }
                    UnEquip(c, -5, c.Player.Inventorys[MapleInventoryType.Equip.Value].GetNextFreeSlot());
                }
                if (bottom != null && ii.IsOverall(source.ItemId))
                {
                    if (c.Player.Inventorys[MapleInventoryType.Equip.Value].IsFull())
                    {
                        c.Send(PacketCreator.GetInventoryFull());
                        c.Send(PacketCreator.GetShowInventoryFull());
                        return;
                    }
                    UnEquip(c, -6, c.Player.Inventorys[MapleInventoryType.Equip.Value].GetNextFreeSlot());
                }
            }
            break;

            case 0xF6:
                // check if weapon is two-handed
                IMapleItem weapon;
                if (c.Player.Inventorys[MapleInventoryType.Equipped.Value].Inventory.TryGetValue(0xF5, out weapon) && ii.IsTwoHanded(weapon.ItemId))
                {
                    if (c.Player.Inventorys[MapleInventoryType.Equip.Value].IsFull())
                    {
                        c.Send(PacketCreator.GetInventoryFull());
                        c.Send(PacketCreator.GetShowInventoryFull());
                        return;
                    }
                    UnEquip(c, -11, c.Player.Inventorys[MapleInventoryType.Equip.Value].GetNextFreeSlot());
                }
                break;

            case 0xF5:
                IMapleItem shield;
                if (c.Player.Inventorys[MapleInventoryType.Equipped.Value].Inventory.TryGetValue(0xF6, out shield) && ii.IsTwoHanded(source.ItemId))
                {
                    if (c.Player.Inventorys[MapleInventoryType.Equip.Value].IsFull())
                    {
                        c.Send(PacketCreator.GetInventoryFull());
                        c.Send(PacketCreator.GetShowInventoryFull());
                        return;
                    }
                    UnEquip(c, -10, c.Player.Inventorys[MapleInventoryType.Equip.Value].GetNextFreeSlot());
                }
                break;

            case 0xEE:
                //if (c.Player.Mount != null)
                //{
                //    c.Player.getMount().setItemId(source.ItemId);
                //}
                break;
            }

            source = c.Player.Inventorys[MapleInventoryType.Equip.Value].Inventory.FirstOrDefault(x => x.Key == srcSlot).Value as Equip;
            target = c.Player.Inventorys[MapleInventoryType.Equipped.Value].Inventory.FirstOrDefault(x => x.Key == dstSlot).Value as Equip;

            c.Player.Inventorys[MapleInventoryType.Equip.Value].RemoveSlot(srcSlot);

            if (target != null)
            {
                c.Player.Inventorys[MapleInventoryType.Equipped.Value].RemoveSlot(dstSlot);
            }

            source.Position = dstSlot;

            c.Player.Inventorys[MapleInventoryType.Equipped.Value].AddFromDb(source);

            if (target != null)
            {
                target.Position = srcSlot;
                c.Player.Inventorys[MapleInventoryType.Equip.Value].AddFromDb(target);
            }

            if (c.Player.GetBuffedValue(MapleBuffStat.Booster) != null && ii.IsWeapon(source.ItemId))
            {
                c.Player.CancelBuffStats(MapleBuffStat.Booster);
            }

            c.Send(PacketCreator.MoveInventoryItem(MapleInventoryType.Equip, src, dst, 2));
            c.Player.EquipChanged();
        }
Пример #9
0
        public static bool AddFromDrop(MapleClient c, IMapleItem item, bool show, string loginfo = "")
        {
            var ii   = MapleItemInformationProvider.Instance;
            var type = ii.GetInventoryType(item.ItemId);

            if (!c.ChannelServer.AllowMoreThanOne && ii.IsPickupRestricted(item.ItemId) &&
                c.Player.HaveItem(item.ItemId, 1, true, false))
            {
                c.Send(PacketCreator.GetInventoryFull());
                c.Send(PacketCreator.ShowItemUnavailable());
                return(false);
            }
            var quantity = item.Quantity;

            if (quantity >= 4000 || quantity < 0)
            {
                AutobanManager.Instance.Autoban(c, $"XSource| PE Item: {quantity} x {item.ItemId}");
                return(false);
            }
            if (type != MapleInventoryType.Equip)
            {
                var slotMax  = ii.GetSlotMax(c, item.ItemId);
                var existing = c.Player.Inventorys[type.Value].ListById(item.ItemId);
                if (!ii.IsThrowingStar(item.ItemId) && !ii.IsBullet(item.ItemId))
                {
                    if (existing.Any())
                    {
                        var i = existing.GetEnumerator();
                        while (quantity > 0)
                        {
                            if (i.MoveNext())
                            {
                                var eItem = (Item)i.Current;
                                if (eItem != null)
                                {
                                    var oldQ = eItem.Quantity;
                                    if (oldQ < slotMax && item.Owner == eItem.Owner)
                                    {
                                        var newQ = (short)Math.Min(oldQ + quantity, slotMax);
                                        quantity      -= (short)(newQ - oldQ);
                                        eItem.Quantity = newQ;
                                        c.Send(PacketCreator.UpdateInventorySlot(type, eItem, true));
                                    }
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    // add new slots if there is still something left
                    while (quantity > 0 || ii.IsThrowingStar(item.ItemId) || ii.IsBullet(item.ItemId))
                    {
                        var newQ = Math.Min(quantity, slotMax);
                        quantity -= newQ;
                        var nItem = new Item(item.ItemId, 0, newQ)
                        {
                            Owner = item.Owner
                        };
                        var newSlot = c.Player.Inventorys[type.Value].AddItem(nItem);
                        if (newSlot == 0xFF)
                        {
                            c.Send(PacketCreator.GetInventoryFull());
                            c.Send(PacketCreator.GetShowInventoryFull());
                            item.Quantity = (short)(quantity + newQ);
                            return(false);
                        }
                        c.Send(PacketCreator.AddInventorySlot(type, nItem, true));
                    }
                }
                else
                {
                    // Throwing Stars and Bullets - Add all into one slot regardless of quantity.
                    var nItem   = new Item(item.ItemId, 0, quantity);
                    var newSlot = c.Player.Inventorys[type.Value].AddItem(nItem);
                    if (newSlot == 0xFF)
                    {
                        c.Send(PacketCreator.GetInventoryFull());
                        c.Send(PacketCreator.GetShowInventoryFull());
                        return(false);
                    }
                    c.Send(PacketCreator.AddInventorySlot(type, nItem));
                    c.Send(PacketCreator.EnableActions());
                }
            }
            else
            {
                if (quantity == 1)
                {
                    var newSlot = c.Player.Inventorys[type.Value].AddItem(item);

                    if (newSlot == 0xFF)
                    {
                        c.Send(PacketCreator.GetInventoryFull());
                        c.Send(PacketCreator.GetShowInventoryFull());
                        return(false);
                    }
                    c.Send(PacketCreator.AddInventorySlot(type, item, true));
                }
                else
                {
                    throw new Exception("Trying to create equip with non-one quantity");
                }
            }
            if (show)
            {
                c.Send(PacketCreator.GetShowItemGain(item.ItemId, item.Quantity));
            }
            return(true);
        }