예제 #1
0
    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;
    }
예제 #2
0
 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);
 }
예제 #3
0
    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);
    }
예제 #4
0
    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);
    }
예제 #5
0
 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);
 }
예제 #6
0
 public static GameObject CreateView(StoragableType type)
 {
     return(Object.Instantiate(views[type]) as GameObject);
 }