private void TrySwapForMostFuel(Container otherContainer) { Containable item = Peek(); if (item == null) { return; } Fuel fuel = item.GetComponent <Fuel>(); Containable best = null; float mostFuel = fuel == null ? 0f : fuel.quantity; float maxFuel = 1f; int bestIndex = -1; for (int index = 0, numContents = otherContainer.contents.Length; index < numContents; ++index) { Containable otherItem = otherContainer.contents[index]; if (mostFuel >= maxFuel) { break; } if (otherItem == null) { continue; } Fuel otherFuel = otherItem.GetComponent <Fuel>(); if (otherFuel == null) { continue; } if (otherFuel.quantity > mostFuel) { mostFuel = otherFuel.quantity; best = otherItem; bestIndex = index; } } if (best == null) { return; } item = Pop(); if (!TryReceive(best)) { return; } otherContainer.Replace(item, bestIndex); }
private void ChangeFuel(Container container, float deltaFuel) { Containable item = container.Peek(); if (item == null) { return; } Fuel fuel = item.GetComponent <Fuel>(); if (fuel == null) { return; } if (fuel.Add(deltaFuel)) { return; } container.Pop(); Destroy(fuel.gameObject); }