public bool RemoveShopItem(ItemDefinition.ItemType type, int quantity, ref int remainingQuantity) { if (stock.TryGetValue(type, out ShopItem item)) { remainingQuantity = item.RemoveQuantity(quantity); if (remainingQuantity == 0) { stock.Remove(item.Definition.Type); onShopItemRemoved?.Invoke(item); } else { onShopItemUpdated?.Invoke(item); } return true; } else { Debug.LogWarning("[ShopManager] Tried to remove stock that didn't exist: " + type.ToString()); return false; } }
public ItemDefinition GetItemDefinition(ItemDefinition.ItemType itemType) { for (int i = itemDefinitions.Count; i-- > 0;) { if (itemDefinitions[i].Type == itemType) { return(itemDefinitions[i]); } } return(null); }
protected void OnActorPlaced(Vector3 cellPosition, bool multiple = false) { pickedActor.transform.position = cellPosition; pickedActor.Mesh.transform.position = cellPosition; pickedActor.SetLayerForHighlight(false); if (pickedActor is Plant) { PlantDefinition def = pickedActor.Definition as PlantDefinition; ItemDefinition.ItemType itemType = def.Seed; if (StorageManager.Instance.Stock.TryGetValue(itemType, out StorageItem storageItem)) { if (storageItem.Quantity > 0) { Accounts.Instance.BuyItem(storageItem.Definition.Cost); int remainingQuantity = 0; StorageManager.Instance.RemoveStorageItem(itemType, 1, ref remainingQuantity); } else { Debug.Log("No storage stock of " + storageItem.Definition.DescriptiveName); } } else { Debug.Log("No storage key stock of " + itemType.ToString()); } } else { Accounts.Instance.BuyItem(pickedActor.Definition.Cost); // TODO: Need to add in a solution for if the player can't afford to buy } pickedActor.OnPlaced(); pickedActor.Picked = false; if (multiple) { SpawnDuplicateActor(pickedActor); } else { pickedActor = null; previousActorRotation = 0f; actorRotation = 0f; appliedRotationY = 0f; } }
public int GetItemDefinitionQuantity(ItemDefinition.ItemType itemType) { for (int i = stockedItems.Count; i-- > 0;) { if (stockedItems[i].Item.Type == itemType) { return(stockedItems[i].Quantity); } } Debug.LogError("[ShopManifest] Unable to find item of type: " + itemType); return(0); }
public void GetItemDefinitionAndQuantity(ItemDefinition.ItemType itemType, out ItemDefinition item, out int quantity) { for (int i = stockedItems.Count; i-- > 0;) { if (stockedItems[i].Item.Type == itemType) { item = stockedItems[i].Item; quantity = stockedItems[i].Quantity; return; } } Debug.LogError("[ShopManifest] Unable to find item of type: " + itemType); item = null; quantity = 0; }
public bool AddShopItem(ItemDefinition.ItemType type) { bool success = false; ConstructionEditor.Instance.ShopManifest.GetItemDefinitionAndQuantity(type, out ItemDefinition itemDef, out int quantity); if (itemDef == null) return false; ShopItem item = new ShopItem(itemDef, quantity); // Debug.Log("Adding: " + itemDef.DescriptiveName); stock.Add(type, item); onShopItemAdded?.Invoke(item); success = true; return success; }
public bool AddShopItem(ItemDefinition.ItemType type, int quantity) { bool success = false; if (stock.TryGetValue(type, out ShopItem item)) { success = item.AddQuantity(quantity); onShopItemUpdated?.Invoke(item); } else { item = new ShopItem(ConstructionEditor.Instance.ShopManifest.GetItemDefinition(type), quantity); stock.Add(type, item); onShopItemAdded?.Invoke(item); success = true; } return success; }
public ItemDefinition GetItemDefinition(ItemDefinition.ItemType itemType, bool supressError = false) { if (stockedItems.Count == 0) { return(null); } for (int i = stockedItems.Count; i-- > 0;) { if (stockedItems[i].Item.Type == itemType) { return(stockedItems[i].Item); } } if (!supressError) { Debug.LogError("[ShopManifest] Unable to find item of type: " + itemType); } return(null); }