예제 #1
0
 //==============================
 // Add item to the item list
 //==============================
 public static void AddItem(OverworldItem item)
 {
     if (!items.Contains(item))
     {
         items.Add(item);
     }
 }
예제 #2
0
 //==============================
 // Remove item from the item list
 //==============================
 public static void RemoveItem(OverworldItem item)
 {
     if (!items.Contains(item))
     {
         items.Remove(item);
     }
 }
예제 #3
0
        //==============================
        // Dropping an item from the inventory into the overworld
        //==============================
        public static void DropItem(Client player, params object[] arguments)
        {
            //[0] = id
            //[1] = type
            //[2] = coords
            //[3] = quantity

            if (arguments.Length <= 0)
            {
                return;
            }

            int       id       = (int)arguments[0];
            ItemTypes type     = (ItemTypes)Enum.Parse(typeof(ItemTypes), arguments[1].ToString());
            Vector3   coords   = (Vector3)arguments[2];
            int       quantity = Convert.ToInt32(arguments[3]);

            //Must drop it nearby
            if (coords.DistanceTo(player.position) > 6)
            {
                API.shared.sendChatMessageToPlayer(player, "~r~You're attempting to drop an item too far away. Try aiming down.");
                return;
            }

            //Check if player owns item to drop
            Player    instance  = player.getData("Instance");
            Inventory inventory = instance.PlayerInventory;

            foreach (KeyValuePair <int, Item> entry in inventory.CurrentItems)
            {
                Item i = entry.Value;

                if (i.Id == id && i.Type == type && i.Quantity >= quantity) //Owns item & same Type & Enough to drop
                {
                    OverworldItem newOverworldItem;

                    if (i.Data.Length <= 0) //Item is stackable, remove from stack and create new Item for overworld item
                    {
                        i.Quantity -= quantity;
                        if (i.Quantity <= 0)
                        {
                            inventory.CurrentItems.Remove(entry.Key);
                        }

                        Item item = new Item(type, quantity);
                        newOverworldItem = new OverworldItem(player, item, coords);
                        items.Add(newOverworldItem);
                        return;
                    }
                    else //Item isn't stackable, remove item from inventory and attach to new overworld item
                    {
                        inventory.CurrentItems.Remove(entry.Key);
                        newOverworldItem = new OverworldItem(player, i, coords);
                        items.Add(newOverworldItem);
                        return;
                    }
                }
            }
        }