public void tryEnqueueShip(ShipCost ship) { // check resource costs ResourceTank[] tanks = GetComponents<ResourceTank>(); float availableResource = 0; foreach (ResourceTank tank in tanks) { if (tank.Type == ship.Type) { availableResource += tank.Stored; } } if (availableResource < ship.Cost) { return; } // consume resources int remainingCost = ship.Cost; foreach (ResourceTank tank in tanks) { if (tank.Type == ship.Type) { remainingCost -= tank.tryExtract(remainingCost); } } // set up start time based on what's in queue float startTime = Time.time; if (_constructionQueue.Count > 0) { startTime = _queueCompletionTime; } // actually enqueue ConstructionOrder toEnqueue = new ConstructionOrder() { Ship = ship, StartTime = startTime }; _constructionQueue.Enqueue(toEnqueue); _queueCompletionTime = toEnqueue.EndTime; toEnqueue.OnConstructionCompleted += () => CompleteShip(ship); toEnqueue.OnConstructionCompleted += () => { if (orderDequeued != null) orderDequeued(toEnqueue); }; // notify views if (orderEnqueued != null) { orderEnqueued(toEnqueue); } }
public bool CreateShipCost(ShipCost shipCost) { outpostwarsEntities entities = new outpostwarsEntities(); try { // Add tew New Player into the player Collection entities.ShipCosts.Add(shipCost); // Save changes return(entities.SaveChanges() == 1); } catch (DbEntityValidationException ex) { LogCriticalError(ex); } return(false); }
/// <summary> /// Generates a number of ships that is within a range /// </summary> public void GenerateShips() { RandomizerHelper randomDictionary = new RandomizerHelper(); DictionaryStorage listOfShips = new DictionaryStorage(); UniqueList uniqueList = new UniqueList(); Dictionary <string, int> dict = new Dictionary <string, int>(); Ships = new Dictionary <string, string>(); numbers = arrayOfNumbers.ToList(); if (CurrentFaction == "Scum") { dict = listOfShips.ScumShips; } if (CurrentFaction == "Imperial") { dict = listOfShips.ImperialShips; } int shipAudit = 0; int pointsSpent = 0; Random r = new Random(); if (pointsSpent < ShipBudget) { ShipCost = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First(); pointsSpent = pointsSpent + ShipCost; } foreach (var fetchedShipName in randomDictionary.RandomValues(dict, ShipCost).Take(1)) { Ship1Name = fetchedShipName; Ships.Add("Ship 1: " + fetchedShipName, Ship1Name); if (uniqueList.UniqueVar.Contains(fetchedShipName)) { dict.Remove(fetchedShipName); if (!dict.Values.Contains(ShipCost)) { numbers.Remove(ShipCost); } } } if (pointsSpent < ShipBudget) { Ship2Cost = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First(); pointsSpent = pointsSpent + Ship2Cost; } foreach (var fetchedShipName in randomDictionary.RandomValues(dict, Ship2Cost).Take(1)) { Ship2Name = fetchedShipName.ToString(); Ships.Add("Ship 2: " + fetchedShipName, Ship2Name); if (uniqueList.UniqueVar.Contains(fetchedShipName)) { dict.Remove(fetchedShipName); if (uniqueList.UniqueVar.Contains(fetchedShipName)) { dict.Remove(fetchedShipName); if (!dict.Values.Contains(ShipCost)) { numbers.Remove(ShipCost); } } } } if (pointsSpent < ShipBudget) { if (pointsSpent < ShipBudget - 5) { shipAudit = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First(); while (shipAudit + pointsSpent > ShipBudget + 5) { shipAudit = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First(); } Ship3Cost = shipAudit; pointsSpent = pointsSpent + Ship3Cost; } } if (Ship3Cost > 0) { foreach (var fetchedShipName in randomDictionary.RandomValues(dict, Ship3Cost).Take(1)) { Ship3Name = fetchedShipName.ToString(); Ships.Add("Ship 3: " + fetchedShipName, Ship3Name); if (uniqueList.UniqueVar.Contains(fetchedShipName)) { dict.Remove(fetchedShipName); if (!dict.Values.Contains(ShipCost)) { numbers.Remove(ShipCost); } } } } if (pointsSpent < ShipBudget) { if (pointsSpent < ShipBudget - 12) { shipAudit = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First(); while (shipAudit + pointsSpent > ShipBudget + 5) { shipAudit = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First(); } Ship4Cost = shipAudit; pointsSpent = pointsSpent + Ship4Cost; } } if (Ship4Cost > 0) { foreach (var fetchedShipName in randomDictionary.RandomValues(dict, Ship4Cost).Take(1)) { Ship4Name = fetchedShipName.ToString(); Ships.Add("Ship 4: " + fetchedShipName, Ship4Name); if (uniqueList.UniqueVar.Contains(fetchedShipName)) { dict.Remove(fetchedShipName); if (!dict.Values.Contains(ShipCost)) { numbers.Remove(ShipCost); } } } } if (pointsSpent < ShipBudget) { if (pointsSpent < ShipBudget - 12) { shipAudit = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First(); while (shipAudit + pointsSpent > ShipBudget + 5) { shipAudit = numbers.OrderBy(n => Guid.NewGuid()).ToArray().First(); } Ship5Cost = shipAudit; pointsSpent = pointsSpent + Ship5Cost; } } if (Ship5Cost > 0) { foreach (var fetchedShipName in randomDictionary.RandomValues(dict, Ship5Cost).Take(1)) { Ship5Name = fetchedShipName.ToString(); Ships.Add("Ship 5: " + fetchedShipName, Ship4Name); if (uniqueList.UniqueVar.Contains(fetchedShipName)) { dict.Remove(fetchedShipName); if (!dict.Values.Contains(ShipCost)) { numbers.Remove(ShipCost); } } } } Console.WriteLine(""); Console.Write(string.Format("We finished building your ships. We will be spending {0} on Ship 1, {1} on ship 2", ShipCost.ToString(), Ship2Cost.ToString())); if (Ship3Cost > 0) { Console.Write(string.Format(", {0} on ship 3", Ship3Cost.ToString())); } if (Ship4Cost > 0) { Console.Write(string.Format(", {0} on ship 4", Ship4Cost.ToString())); } if (Ship5Cost > 0) { Console.Write(string.Format(", {0} on ship 5", Ship5Cost.ToString())); } Console.Write("."); Console.WriteLine(""); SpentSoFar = SpentSoFar + pointsSpent; SpentOnShips = pointsSpent; }
void CompleteShip(ShipCost completed) { Instantiate(completed.Prefab, SpawnLocation.position, SpawnLocation.rotation); }