Example #1
0
        public static void UnequipItem(Item item, short destinationSlot = 0)
        {
            //check for item type
            if (item.ItemType != ItemConstants.ItemType.Equipment)
            {
                throw new InvalidOperationException("Can only unequip equipment items.");
            }

            // slot to move item from
            short sourceSlot = item.Slot;

            // if no destination given then find first free slot for equip type
            if (destinationSlot == 0)
            {
                destinationSlot = item.Parent.GetNextFreeSlot(ItemConstants.ItemType.Equipment);
            }

            // change slot of item being unequipped to free equip slot
            item.Slot = destinationSlot;

            // send packet to carry out the un-equip item action
            item.Character.Client.Send(ItemPackets.EquipOrUnequipItems(item, sourceSlot, destinationSlot));

            // update char appearance
            CharacterAppearance.UpdateApperance(item.Character);
        }
Example #2
0
 public void sendTo3x3AreaRemoveItem(Area area, int uID)
 {
     for (int i = 0; i < 3; i++)
     {
         for (int u = 0; u < 3; u++)
         {
             Area nearCentral = getArea(new int[] { area.getAreaPosition()[0] - 1 + i, area.getAreaPosition()[1] - 1 + u });
             if (nearCentral == null)
             {
                 continue;
             }
             foreach (Character characterAround in nearCentral.getCharacters())
             {
                 try
                 {
                     characterAround.getAccount().mClient.WriteRawPacket(ItemPackets.removeDroppedItemForCharacter(characterAround, uID));
                 }
                 catch (Exception e)
                 {
                     Console.WriteLine(e);
                 }
             }
         }
     }
 }
Example #3
0
        public static void DropItem(Item item, short dropQuantity)
        {
            // cannot drop blocked items
            if (item.IsBlocked)
            {
                // TODO: notify character
                return;
            }

            // no multiplication of rechargeable items
            if (item.IsRechargeable)
            {
                dropQuantity = item.Quantity;
            }

            // cannot drop more then i have
            if (dropQuantity > item.Quantity)
            {
                // TODO: notify character
                return;
            }

            if (dropQuantity == item.Quantity)
            {
                // send packet to carry out the remove item action
                item.Character.Client.Send(ItemPackets.RemoveItem(item));

                // update item ownership properties
                item.Dropper = item.Character;
                item.Owner   = null;

                // create drop on map
                item.Character.Map.Drops.Add(item);

                // remove item from dropper's inventory
                item.Parent.RemoveItemFromInventory(item, false);
            }
            else if (dropQuantity < item.Quantity)
            {
                // subtract the quantity to drop
                item.Quantity -= dropQuantity;

                // send packet to carry out the item quantity update action
                item.Character.Client.Send(ItemPackets.ModifyItemsQuantity(item));

                // create new drop item with droppers properties
                Item dropped = new Item(item.MapleID, quantity)
                {
                    Dropper = item.Character,
                    Owner   = null
                };

                // add dropped item to map
                item.Character.Map.Drops.Add(dropped);
            }
        }
Example #4
0
        public static void MoveItem(Item item, short destinationSlot)
        {
            // slot to move item from
            short sourceSlot = item.Slot;

            // item in slot to move item to
            Item itemAtDestinationSlot = item.Parent[item.ItemType, destinationSlot];

            // case of moving non-rechargeable non-equip stackable items
            // TODO: proper treatment
            if (IsStackableNotRechargeable(item) && CanStackItems(item, itemAtDestinationSlot))
            {
                int totalQuantity = item.Quantity + itemAtDestinationSlot.Quantity;

                // Sub-case 1: stack at destination will overflow on addition
                if (totalQuantity > itemAtDestinationSlot.MaxPerStack)
                {
                    // subtract whats left at destination slot
                    item.Quantity -= (short)(itemAtDestinationSlot.MaxPerStack - itemAtDestinationSlot.Quantity);

                    // send packet to do stacking action when stack at destination is full
                    item.Character.Client.Send(ItemPackets.StackItemsFullStack(item, itemAtDestinationSlot));
                }
                // Sub-case 2: stack at destination wont overflow on addition
                else
                {
                    // add quantity of itemFirst to itemSecond
                    itemAtDestinationSlot.Quantity += item.Quantity;

                    // send packet to do stacking action
                    item.Character.Client.Send(ItemPackets.StackItems(item, itemAtDestinationSlot));
                }
            }
            // other cases
            else
            {
                // if there is an item at destination slot move it to source slot
                if (itemAtDestinationSlot != null)
                {
                    itemAtDestinationSlot.Slot = sourceSlot;
                }

                // move item to destination slot
                item.Slot = destinationSlot;

                // send packet to do item move action
                item.Character.Client.Send(ItemPackets.MoveItem(item, sourceSlot, destinationSlot));
            }
        }
Example #5
0
        public static void ItemCreate(MartialClient c, InCommand cmd)
        {
            if (cmd.commandArgs == null)
            {
                StaticPackets.sendSystemMessageToClient(c, 1, "/item [itemid] [*amount]");
                return;
            }

            if (c.getAccount().activeCharacter == null)
            {
                Logger.LogCheat(Logger.HackTypes.NullActive, c, "Null activity in command handler");
                c.Close();
                return;
            }
            Character chr = c.getAccount().activeCharacter;

            int itemID = 0;

            Int32.TryParse(cmd.commandArgs[0], out itemID);
            if (itemID < 200000000 || itemID > 299999999)
            {
                StaticPackets.sendSystemMessageToClient(c, 1, "Item ID range goes from 200.000.000 - 299.999.999.");
                return;
            }
            if (ItemDataCache.Instance.getItemData(itemID).getID() == 0)
            {
                StaticPackets.sendSystemMessageToClient(c, 1, "Selected item wasn't found.");
                return;
            }

            short itemQuantity = 1;

            Int16.TryParse(cmd.commandArgs[1], out itemQuantity);
            if (itemQuantity > short.MaxValue)
            {
                StaticPackets.sendSystemMessageToClient(c, 1, "Items amount, can't be bigger than 100!");
                return;
            }

            c.WriteRawPacket(ItemPackets.createDroppedItem(WMap.Instance.items.Count, chr.getPosition()[0], chr.getPosition()[1], itemID, itemQuantity));
            StaticPackets.sendSystemMessageToClient(c, 1, "Item of ID: " + itemID + "|" + WMap.Instance.items.Count + "|" + itemQuantity + ", has been created at coords: ");
            StaticPackets.sendSystemMessageToClient(c, 1, chr.getPosition()[0] + ":" + chr.getPosition()[1] + ":" + chr.getMap() + "!");
            WMap.Instance.items.Add(WMap.Instance.items.Count, new Item(itemID, itemQuantity));
            return;
        }
Example #6
0
        public static void EquipItem(Item item)
        {
            // Check ItemType
            if (item.ItemType != ItemConstants.ItemType.Equipment)
            {
                throw new InvalidOperationException("Can only equip equipment items.");
            }

            // If were not VIP user then check for requirements
            if (!item.Character.IsMaster)
            {
                if (item.Character.Stats.Strength < item.RequiredStrength || item.Character.Stats.Dexterity < item.RequiredDexterity ||
                    item.Character.Stats.Intelligence < item.RequiredIntelligence || item.Character.Stats.Luck < item.RequiredLuck ||
                    item.Character.Stats.Fame < item.RequiredFame)
                {
                    return;
                }
            }

            // slot to move item from
            short sourceSlot = item.Slot;

            // slot to move item into
            ItemConstants.EquipmentSlot destinationSlot = item.GetEquippedSlot();

            // get char's items
            Item top    = item.Parent[ItemConstants.EquipmentSlot.Top];
            Item bottom = item.Parent[ItemConstants.EquipmentSlot.Bottom];
            Item weapon = item.Parent[ItemConstants.EquipmentSlot.Weapon];
            Item shield = item.Parent[ItemConstants.EquipmentSlot.Shield];

            // get item at char's destination slot
            Item destination = item.Parent[destinationSlot];

            // if there is an item
            if (destination != null)
            {
                // put it into slot of item to be replaced with
                destination.Slot = sourceSlot;
            }

            // item to replace acquires destination slot
            item.Slot = (short)destinationSlot;

            // unequipped blocking items
            switch (destinationSlot)
            {
            case ItemConstants.EquipmentSlot.Bottom:
            {
                if (top?.IsOverall == true)
                {
                    UnequipItem(top);
                }
            }
            break;

            case ItemConstants.EquipmentSlot.Top:
            {
                if (item.IsOverall && bottom != null)
                {
                    UnequipItem(bottom);
                }
            }
            break;

            case ItemConstants.EquipmentSlot.Shield:
            {
                if (weapon?.IsTwoHanded == true)
                {
                    UnequipItem(weapon);
                }
            }
            break;

            case ItemConstants.EquipmentSlot.Weapon:
            {
                if (item.IsTwoHanded && shield != null)
                {
                    UnequipItem(shield);
                }
            }
            break;
            }

            // send packet to carry out the equipped action
            item.Character.Client.Send(ItemPackets.EquipOrUnequipItems(item, sourceSlot, (short)destinationSlot));

            // update char appearance
            CharacterAppearance.UpdateApperance(item.Character);
        }
Example #7
0
 public static void UpdateItem(Item item)
 {
     item.Character.Client.Send(ItemPackets.UpdateItems(item));
 }