public void Init(FactoryRoomInfo factoryRoomInfo) { productionRate = factoryRoomInfo.consumptionRate; drugType = factoryRoomInfo.drugType; switch (drugType) { case DrugType.Weed: storagableDrugType = StoragableType.Weed; break; case DrugType.Opiate: storagableDrugType = StoragableType.Opiate; break; case DrugType.Psychodelic: storagableDrugType = StoragableType.Psychodelic; break; case DrugType.Stimulator: storagableDrugType = StoragableType.Stimulator; break; default: throw new System.ArgumentOutOfRangeException(); } consumptionRate = factoryRoomInfo.consumptionRate; currentProductionProgress = 0f; }
public static bool Add(StoragableType type, int count) { foreach (var o in instance.storages) { count = o.TryAddToStorage(type, count); if (count == 0) { return(true); } } return(false); }
public static bool TryGetItem(StoragableType type, int count) { int orig = count; foreach (var o in instance.storages) { count = o.RemoveFromStorage(type, count); if (count == 0) { return(true); } } Add(type, orig - count); return(false); }
public int TryAddToStorage(StoragableType type, int count) { //First pass on foreach (var storageCell in storageConfiguration.storage) { if (storageCell.type == type) { int freeSpace = storageCell.getFreeSpace(); if (freeSpace >= count) { storageCell.count += count; return(0); } else { storageCell.count += freeSpace; count -= freeSpace; } } } //Not found any space in existing, trying to create new foreach (var storageCell in storageConfiguration.storage) { if (storageCell.type == StoragableType.Empty) { storageCell.type = type; int freeSpace = storageCell.getFreeSpace(); if (freeSpace >= count) { storageCell.count += count; return(0); } else { storageCell.count += freeSpace; count -= freeSpace; } } } return(count); }
public int RemoveFromStorage(StoragableType type, int count) { for (int i = storageConfiguration.storage.Count - 1; i > -1; i--) { var storageCell = storageConfiguration.storage[i]; if (storageCell.type == type) { if (storageCell.count > count) { storageCell.count -= count; return(0); } else { count -= storageCell.count; storageCell.type = StoragableType.Empty; storageCell.count = 0; } } } return(count); }
public static GameObject CreateView(StoragableType type) { return(Object.Instantiate(views[type]) as GameObject); }