예제 #1
0
        public static void CloseDevice()
        {
            var player = GetLastClosedBy();

            if (!GetIsPC(player) || GetIsDM(player))
            {
                return;
            }

            var device = OBJECT_SELF;

            for (var item = GetFirstItemInInventory(device); GetIsObjectValid(item); item = GetNextItemInInventory(device))
            {
                var resref = GetResRef(item);

                if (CommandResrefs.Contains(resref))
                {
                    DestroyObject(item);
                }
                else
                {
                    Item.ReturnItem(player, item);
                }
            }

            // If player is quitting crafting, clear out their state.
            var state = Craft.GetPlayerCraftingState(player);

            if (!state.IsOpeningMenu)
            {
                Craft.ClearPlayerCraftingState(player);
            }
        }
예제 #2
0
        /// <summary>
        /// Sends a message to a player informing them of the current number of items in the container and the maximum allowed.
        /// If incrementByOne is true, the current count will be increased by one. This is to account for the fact that
        /// the OnAddItem event fires before the item is actually added to the inventory (therefore it would have an off-by-one error)
        /// </summary>
        /// <param name="player">The player receiving the message</param>
        /// <param name="incrementByOne">Increments current item count by one if true, else does nothing.</param>
        protected static void SendItemLimitMessage(uint player, bool incrementByOne)
        {
            var container = OBJECT_SELF;
            var limit     = GetItemLimit();
            var count     = Item.GetInventoryItemCount(container);

            // The Add event fires before the item exists in the container. Need to increment by one in this scenario.
            if (incrementByOne)
            {
                count++;
            }

            SendMessageToPC(player, ColorToken.White("Item Limit: " + (count > limit ? limit : count) + " / ") + ColorToken.Red("" + limit));
        }
예제 #3
0
        /// <summary>
        /// Searches a player's inventory for components matching this recipe's requirements.
        /// </summary>
        /// <param name="player">The player to search.</param>
        private static void LoadComponents(uint player)
        {
            var device = OBJECT_SELF;
            var state  = Craft.GetPlayerCraftingState(player);
            var recipe = Craft.GetRecipe(state.SelectedRecipe);

            for (var item = GetFirstItemInInventory(player); GetIsObjectValid(item); item = GetNextItemInInventory(player))
            {
                var resref = GetResRef(item);

                if (recipe.Components.ContainsKey(resref))
                {
                    Item.ReturnItem(device, item);
                }
            }
        }
예제 #4
0
        public static void TakeItem()
        {
            var disturbType = GetInventoryDisturbType();

            if (disturbType != DisturbType.Removed)
            {
                return;
            }

            var player = GetLastDisturbed();
            var item   = GetInventoryDisturbItem();
            var resref = GetResRef(item);
            var device = OBJECT_SELF;
            var state  = Craft.GetPlayerCraftingState(player);

            if (state.IsAutoCrafting)
            {
                SendMessageToPC(player, ColorToken.Red("You are auto-crafting."));
                return;
            }

            // Auto-craft item
            if (resref == AutoCraftItemResref)
            {
                Item.ReturnItem(device, item);
                AutoCraftItem(player);
            }
            // Manually craft the item
            else if (resref == CraftItemResref)
            {
                Item.ReturnItem(device, item);
                CraftItem(player);
            }
            // Load components into container
            else if (resref == LoadComponentsResref)
            {
                Item.ReturnItem(device, item);
                LoadComponents(player);
            }
            // Select a different recipe
            else if (resref == SelectRecipeResref)
            {
                Item.ReturnItem(device, item);
                SelectRecipe(player);
            }
        }