public Order(int id, float price, float time, LiquidMix drink) { this.id = id; this.price = price; this.time = time; this.drink = drink; }
///<summary> ///Adds the newLiquid to the LiquidsDict with regards to the remainingSpace. ///If remainingSpace = -1, this condition is ignored. ///</summary> public void AddLiquidToMix(Liquid newLiquid, double remainingSpace) { LiquidMix newLiquidMix = new LiquidMix(newLiquid); Combine(newLiquidMix, remainingSpace); // Update stats according to the new levels UpdateInfo(); }
//Single public Order GenerateOrder() { bool mix = Random.value < mixChance; LiquidMix drink = new LiquidMix(new List <Material>(), new List <float>()); if (mix) { int amountOfLiquids = Random.Range(2, 4); //2 or 3 bool finished = false; int amount = LiquidList.Instance.amount; while (!finished) { Material l = LiquidList.Instance.liquids[Random.Range(0, amount)]; if (!drink.liquids.Contains(l)) { drink.liquids.Add(l); if (drink.liquids.Count >= amountOfLiquids) { finished = true; } } } List <float> ratios = new List <float>(); float total = 0f; for (int r = 0; r < amountOfLiquids; r++) { if (r == amountOfLiquids - 1) //Last ratio { ratios.Add(1 - total); } else if (r > 0) //Middle ratio { ratios.Add(Random.Range(0, ratios[r - 1] * 0.75f)); total += ratios[r]; } else //First { ratios.Add(Random.Range(0.33f, 0.5f)); total += ratios[r]; } } drink.ratios = ratios; } else { Material l = LiquidList.Instance.liquids[Random.Range(0, LiquidList.Instance.amount)]; drink.liquids.Add(l); drink.ratios.Add(1f); } return(new Order(Statistics.Instance.ordersReceived, 3f, Random.Range(30, 60), drink));; }
public void Combine(LiquidMix newLiquidMix, double remainingSpace) { // If there's no space, don't do anything if (remainingSpace == 0) { return; } // Ignore volume requirements else if (remainingSpace == -1) { } // If the incoming volume is greater than remaining space, change incoming volume amount else if (newLiquidMix.TotalVolume > remainingSpace) { newLiquidMix.TotalVolume = remainingSpace; } // Using the total volume and the proportions of each liquidType, get the volume for each liquidType Dictionary <LiquidType, double> LiquidVolumes = new Dictionary <LiquidType, double>(); foreach (KeyValuePair <LiquidType, double> entry in LiquidProportions) { LiquidVolumes.Add(entry.Key, entry.Value * TotalVolume); } // Create new dictionary, loop through new list, add to current stuff Dictionary <LiquidType, double> newLiquidProportions = newLiquidMix.LiquidProportions; foreach (KeyValuePair <LiquidType, double> entry in newLiquidProportions) { double entryVolume = entry.Value * newLiquidMix.TotalVolume; if (LiquidVolumes.ContainsKey(entry.Key)) { LiquidVolumes[entry.Key] += entryVolume; } else { LiquidVolumes.Add(entry.Key, entryVolume); } } UpdateProportionsGivenVolumes(LiquidVolumes); UpdateInfo(); }
public bool SameLiquidMix(LiquidMix newLiquidMix) { bool same = true; // Check if new mix has all types from original mix foreach (LiquidType type in LiquidProportions.Keys) { if (!(newLiquidMix.LiquidProportions.ContainsKey(type))) { same = false; } } // Check if original mix has all types from new mix foreach (LiquidType type in newLiquidMix.LiquidProportions.Keys) { if (!(LiquidProportions.ContainsKey(type))) { same = false; } } return(same); }
//public void MixAll() //{ // if (LiquidsCollList.Count > 1) // { // double remainingVolume = maxVolume - currentVolume; // currentVolume = 0; // foreach (LiquidsCollection liquidsCollection in LiquidsCollList) // { // if (liquidsCollection != LiquidsCollList[1]) // LiquidsCollList[1].Combine(liquidsCollection, remainingVolume); // currentVolume += liquidsCollection.CombinedVolume; // } // LiquidsCollList.RemoveRange(1, LiquidsCollList.Count - 1); // } //} public void AddLiquid(LiquidType liquidType, double volumeAdded) { double remainingVolume = maxVolume - currentVolume; if (currentVolume >= maxVolume) { return; } else if (currentVolume + volumeAdded > maxVolume) { volumeAdded = remainingVolume; } currentVolume += volumeAdded; LiquidMix newLiquidMix = new LiquidMix(new Liquid(liquidType, volumeAdded)); // If the top mix is the same recipe as the incoming, just update the proportions & volume if (LiquidMixList.Count > 0) { if (LiquidMixList[LiquidMixList.Count - 1].SameLiquidMix(newLiquidMix)) { LiquidMixList[LiquidMixList.Count - 1].Combine(newLiquidMix, remainingVolume); } else { LiquidMixList.Add(newLiquidMix); } } // Else add a new layer to the thing else { LiquidMixList.Add(newLiquidMix); //LiquidLayerReferences.Add(Instantiate(LiquidLayerPrefab , new Vector3(0, 0, 0), Quaternion.identity)); } }