/// <summary> /// Called when the craft button is clicked. /// </summary> public void callback_craftButtonClick() { Recipe r = this.selectedRecipe.getRecipe(); ContainerContents <IItemBase> inventory = this.getPlayer().inventory; // Remove the items from the players inventory. foreach (ItemData item in r.getIngredients()) { int i; inventory.containsItem(item, out i); if (i != -1) { ItemManager.destroyItem(this.getPlayer(), i); } } // Add the new item to the players inventory. if (r.getResult() != null) { IItemBase item = ItemManager.create <IItemBase>(r.getResult()); item.setInWorld(false, Vector3.zero, Quaternion.identity); inventory.addItem(item); } // Set the selected recipe to be null. this.selectedRecipe.setOutlined(false); this.setSelectedRecipe(null); }
public bool hasRequiredIngredients(ContainerContents <IItemBase> containerContents) { IItemBase[] items = containerContents.getRawItemArray(); List <int> indicies = new List <int>(); foreach (ItemData item in this.ingredients) { if (item != null) { for (int i = 0; i < items.Length; i++) { if (items[i] != null && items[i].getData() == item) { if (indicies.Contains(i)) { continue; } else { indicies.Add(i); break; // Found the item, go to the next ingredient } } } } } return(indicies.Count == this.ingredients.Length); }
public static T create <T>(ItemData itemData, ContainerContents <IItemBase> container) where T : IItemBase { T item = ItemManager.create <T>(itemData); item.setInWorld(false, Vector3.zero, Quaternion.identity); // TODO where should they be stored? container.addItem(item); return(item); }
/// <summary> /// Called when the container is opened by a Player. /// </summary> public virtual Container onOpen(ContainerContents <IItemBase> data, Player player) { this.contents = data; this.player = player; this.gameObject.SetActive(true); return(this); }
private void Start() { this.health.subscribeToDamageEvent(onDamageCallback); Vector2Int inventorySize = this.getContainerSize(); this.inventory = new ContainerContents <IItemBase>(inventorySize.x, inventorySize.y); this.init(); }
public void drawHotbarItems(ContainerContents <IItemBase> container) { for (int i = 0; i < 4; i++) { IItemBase item = container.getItem(i); if (item != null) { Transform t = this.hotbarSquares[i].transform; RenderHelper.renderItemMesh(item, t.position, t.rotation, t.localScale, this.orthoCamera); } } }
public void fillContainer(ContainerContents <IItemBase> container) { foreach (ItemData itemData in this.items) { if (container.isFull()) { break; } if (itemData == null) { continue; } ItemManager.create <IItemBase>(itemData, container); } }
public void Init(ContainerContents containerCont) { items = new ItemDictionary(); var contents = containerCont.GetContents(); List <ContainerItem> itemCounts = new List <ContainerItem>(); foreach (ItemBaseCount baseCount in contents) { Item item = Game.Instance.Factories.ItemFactory.CreateItem(baseCount.itemBase); itemCounts.Add(new ContainerItem() { item = item, count = baseCount.count }); } Add(itemCounts); }