/// <summary> /// Add physical gameObject /// item to scene inventory. /// </summary> /// <param name="item">GameObject - item gameObject physical reference.</param> /// <param name="type">ItemData.Type - to which inventory this item will be stored</param> public void AddItem(GameObject item, ItemData.Type type) { if (!CheckIfItemExists(item, type)) { Transform newParent; switch (type) { case ItemData.Type.basic: newParent = basicInventory.transform; break; case ItemData.Type.crafting: newParent = craftingInventory.transform; break; case ItemData.Type.important: newParent = importantInventory.transform; break; default: newParent = null; break; } if (newParent != null) { item.transform.parent = newParent; item.transform.position = newParent.position; item.transform.localPosition = newParent.localPosition; } } }
private Item GetItem(ItemData itemData) { string name = itemData.name; ItemData.Type type = itemData.type; switch (type) { case ItemData.Type.Active: foreach (ActiveItem item in activeItemsList) { if (name.Equals(item.name)) { return(item); } } Debug.LogError("Item not found"); return(null); case ItemData.Type.Passive: foreach (PassiveItem item in passiveItemsList) { if (name.Equals(item.name)) { return(item); } } Debug.LogError("Item not found"); return(null); default: Debug.LogError("No items of type " + type.ToString()); return(null); } }
/// <summary> /// Check if item exist in /// one of the scene inventories. /// </summary> /// <param name="item">GameObject - item gameObject physical reference.</param> /// <param name="type">ItemData.Type - to which inventory this item will be stored</param> /// <returns>bool</returns> public bool CheckIfItemExists(GameObject item, ItemData.Type type) { bool result = false; GameObject inventoryToLooK = null; switch (type) { case ItemData.Type.basic: inventoryToLooK = basicInventory; break; case ItemData.Type.crafting: inventoryToLooK = craftingInventory; break; case ItemData.Type.important: inventoryToLooK = importantInventory; break; default: inventoryToLooK = null; break; } if (inventoryToLooK != null) { result = inventoryToLooK.transform.Find(item.name); } return(result); }
/// <summary> /// Remove item from /// scene inventory. /// </summary> /// <param name="item">GameObject - item gameObject physical reference.</param> /// <param name="type">ItemData.Type - to which inventory this item will be stored</param> public void RemoveItem(GameObject item, ItemData.Type type) { if (CheckIfItemExists(item, type)) { GameObject inventoryToLook = null; switch (type) { case ItemData.Type.basic: inventoryToLook = basicInventory; break; case ItemData.Type.crafting: inventoryToLook = craftingInventory; break; case ItemData.Type.important: inventoryToLook = importantInventory; break; default: inventoryToLook = null; break; } if (inventoryToLook != null) { Destroy(inventoryToLook.transform.Find(item.name).gameObject); } } }
/// <summary> /// Get item as gameObject /// instance. /// </summary> /// <param name="itemName">string - item gameObject name.</param> /// <param name="type">ItemData.Type - to which inventory this item will be stored</param> /// <returns>GameObject</returns> public GameObject GetItem(string itemName, ItemData.Type type) { GameObject item = null; GameObject inventoryToLook = null; switch (type) { case ItemData.Type.basic: inventoryToLook = basicInventory; break; case ItemData.Type.crafting: inventoryToLook = craftingInventory; break; case ItemData.Type.important: inventoryToLook = importantInventory; break; default: inventoryToLook = null; break; } if (inventoryToLook != null) { item = inventoryToLook.transform.Find(itemName).gameObject; } return(item); }
public bool HasItemForSale(ItemData.Type itemType) { return(_sellSlots.Any(s => { if (s.Content == null) { return false; } return s.Content.Type == itemType; })); }
public Sprite GetSpriteFor(ItemData.Type itemType) { var itemMap = _itemMapping.FirstOrDefault(m => m.type == itemType); if (itemMap == null) { return(null); } return(itemMap.data.sprite); }
public Item Create(ItemData.Type itemType) { var itemData = _itemMapping.FirstOrDefault(m => m.type == itemType).data; if (itemData == null) { throw new ArgumentOutOfRangeException("Item of type " + itemType + " is not mapped in ItemFactory"); } return(CreateFromData(itemData)); }
public bool SellItem(ItemData.Type itemType) { var slotContainingItem = _sellSlots.FirstOrDefault(s => { if (s.Content == null) { return(false); } return(s.Content.Type == itemType); }); if (slotContainingItem == null) { Debug.LogWarningFormat("Cannot sell item of type '{0}' because it is not in the sell slots.", itemType.ToString()); return(false); } slotContainingItem.Clear(); return(true); }
protected void Awake() { item = this.GetComponent <Item>(); module = item.data.GetModule <ItemModuleFetch>(); holder = item.GetComponentInChildren <Holder>(); holder.UnSnapped += new Holder.HolderDelegate(this.OnWeaponItemRemoved); //Trim list of ItemData IDs by sub-type. Each ItemData has its own type, defined by these enum indicies: //Misc = 0 //Weapon = 1 //Quiver = 2 //Potion = 3 //Prop = 4 //Body = 5 //Shield = 6 //Get all ItemData IDs from the chosen category. If no valid itemCategory is set, then no trimming is done and all types are valid for return if (module.itemCategory >= 0 && module.itemCategory <= 6) { var categoryEnums = Enum.GetValues(typeof(ItemData.Type)); ItemData.Type chosenCategory = (ItemData.Type)categoryEnums.GetValue(module.itemCategory); itemsList = Catalog.GetAllID <ItemData>().FindAll(i => Catalog.GetData <ItemData>(i, true).type.Equals(chosenCategory)); //Only include ItemData IDs which are purchasable itemsList = itemsList.FindAll(i => Catalog.GetData <ItemData>(i, true).purchasable.Equals(true)); } //Otherwise, populate the list with everything as long as it is purchasable else { itemsList = Catalog.GetAllID <ItemData>().FindAll(i => Catalog.GetData <ItemData>(i, true).purchasable.Equals(true)); } // If the plugin is in `overrideMode`, first fetch items from the given category (if supplied) and then add any additionally given items to the parsed list if (module.overrideMode) { parsedItemsList = new List <string>(); if (!String.IsNullOrEmpty(module.overrideCategory)) { parsedItemsList = itemsList.FindAll(i => Catalog.GetData <ItemData>(i, true).categoryPath.Any(j => j.Contains(module.overrideCategory))); } foreach (string itemName in module.overrideItems) { if (!parsedItemsList.Contains(itemName) && itemsList.Contains(itemName)) { parsedItemsList.Add(itemName); } } } // Otherwise if not in override mode, then load all items from all categories (from the given BS master list), optionally exluding specific categories and items else { parsedItemsList = new List <string>(itemsList); foreach (string categoryName in module.excludedCategories) { parsedItemsList = parsedItemsList.FindAll(i => !Catalog.GetData <ItemData>(i, true).categoryPath.Any(j => j.Contains(categoryName))); } foreach (string itemName in module.excludedItems) { parsedItemsList = parsedItemsList.FindAll(i => !i.Contains(itemName)); } } // If no capacity is defined, default to infinite usages. Otherwise, set up a tracker for remaining uses if (module.capacity <= 0) { infiniteUses = true; } else { usesRemaining = module.capacity - 1; } waitingForSpawn = false; Debug.Log("[Fisher-HoldingBags] AWAKE HOLDING BAG: " + Time.time); return; }
private void ShowHoldingItem(ItemData.Type itemType, float delay = 0f) { var itemData = ItemFactory.Instance.GetDataFor(itemType); ShowHoldingItem(itemData, delay); }
private void Start() { _type = itemSlotGroup.type; itemSlotGroup.equipPanel = this; UpdateStash(); }