override public void Tick() { int overload = vehicleCount - upgradeLevel; ResourceCount energyCost = new ResourceCount(0, 0, 0, 0, (overload <= 0 ? 1 : 1 + overload)); GameManager.Instance.Resources -= energyCost; }
public void UpgradeCity(City city) { int cost = city.UpgradeCost; var resourceCost = new ResourceCount(cost, cost, cost, cost, 0); if (GameManager.Instance.Resources < resourceCost) { return; } GameManager.Instance.Resources -= resourceCost; city.UpgradeLevel++; SetLevel(city, "" + city.UpgradeLevel); GameManager.UpdateResourceCounts(city); GameObject cty; Cities.TryGetValue(city, out cty); if (cty != null) { cty.transform.Find("stadtLV1").gameObject.SetActive(false); if (city.UpgradeLevel == 2) { cty.transform.Find("StadtLV2").gameObject.SetActive(true); } else { cty.transform.Find("StadtLV3").gameObject.SetActive(true); cty.transform.Find("StadtLV2").gameObject.SetActive(false); } } }
public static void UpdateResourceCounts(Vector2 tile) { ResourceCount mapResource = Instance.Map.tiles[(int)tile.x, (int)tile.y].resource; int x = (int)tile.x; int y = (int)tile.y; float amount = 0.0f; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { var pos = new Vector2(x + i - Instance.width / 2, y + j - Instance.width / 2); City city = GetCity(pos); if (city != null) { amount += 1.0f; var multiResources = city.production.MultiResources; if ((mapResource.money > 0 && multiResources.money > 0) || (mapResource.beer > 0 && multiResources.beer > 0) || (mapResource.steel > 0 && multiResources.steel > 0) || (mapResource.concrete > 0 && multiResources.concrete > 0) || (mapResource.energy > 0 && multiResources.energy > 0)) { amount += 0.25f; } amount *= city.UpgradeLevel; } } } Instance.SetResourceDisplay(x, y, amount); }
void SpendResources(ResourcePrice[] resPrices) { for (int i = 0; i < resPrices.Length; i++) { ResourceCount resCount = ResourceManager.Instance.resourcesCount.FirstOrDefault(x => x.resourceData == resPrices[i].resourceData); ResourceManager.Instance.ChangeResourceValue(resPrices[i].resourceData, -resPrices[i].price); } }
void Awake() { this.cities = new List <City>(); this.trains = new List <Train>(); this.tickingConnections = new List <Connection>(); this.connections = new Graph(); this.resources = startResources; this.connected = new HashSet <City>(); }
void OnTriggerExit(Collider other) { if (other.tag == _resourceTag) { _animator.SetBool("isGathering", false); resource = null; IsCollectingFood = false; CurrentResource = null; } }
bool IsEnoughResources(ResourcePrice[] resPrices) { for (int i = 0; i < resPrices.Length; i++) { ResourceCount resCount = ResourceManager.Instance.resourcesCount.FirstOrDefault(x => x.resourceData == resPrices[i].resourceData); if (resCount.count - resPrices[i].price < 0) { return(false); } } return(true); }
public void BuildCity(Vector2 position) { var resourceCost = new ResourceCount(0, 1, 2, 4, 0); if (GameManager.Instance.Resources < resourceCost) { return; } GameManager.Instance.Resources -= resourceCost; AddCity(position); }
private void OnMouseDown() { GameObject resourceObj = GameObject.Find("_ResourceCountScript"); ResourceCount resourceScript = resourceObj.GetComponent <ResourceCount>(); if (resourceScript.resourceCounter >= 200) { print("Spawn Zeus"); GameObject zeusPrefab = Instantiate(_turretZeus, _turretPointPos, _turretPivot.transform.rotation) as GameObject; resourceScript.resourceCounter -= 200; _turretPoint.SetActive(false); } }
void OnCollisionEnter2D(Collision2D other) { if (other.gameObject.tag == "Player") { ResourceCount dropResource = new ResourceCount(); dropResource.resourceCount = 1; dropResource.resourceName = myResource; Controls script = (Controls)other.transform.gameObject.GetComponent(typeof(Controls)); script.AddResource(dropResource); Destroy(gameObject); } }
public void ChangeResourceValue(ResourceData resourceData, int operation) { ResourceCount resourceCount = GetResource(resourceData); if (resourceCount.count + operation > 0) { resourceCount.count += operation; } else { resourceCount.count = 0; } UIManager.Instance.UpdateResourcesUIData(resourcesCount); }
public bool BuildEnergyPanel(Vector2 position) { ResourceCount resourceCost = new ResourceCount(0, 3, 2, 0, 0); if (GameManager.Instance.Resources < resourceCost) { return(false); } GameManager.Instance.Resources -= resourceCost; GameManager.Instance.Map.tiles[(int)position.x, (int)position.y].resource = new ResourceCount(0, 0, 0, 0, 1); GameManager.UpdateResourceCounts(position); return(true); }
public bool BuildConnection(Vector2 left, Vector2 right, bool isStammstrecke) { var resourceCost = new ResourceCount(0, 1, 1, 1, 0); if (GameManager.Instance.Resources < resourceCost) { return(false); } if (!AddConnection(left, right, isStammstrecke)) { return(false); } GameManager.Instance.Resources -= resourceCost; SoundManager.Instance.Play(railSound); return(true); }
public void OnTriggerEnter(Collider other) { if (other.tag == _resourceTag) { if (other.name == "Pumpkins") { CurrentResource = other.gameObject.GetComponent <ResourceCount>(); if (CurrentResource.Resources > 0) { resource = "food"; IsCollectingFood = true; _animator.SetBool("isGathering", true); transform.LookAt(other.transform); } } } }
public void AddResource(ResourceCount newResourceCount) { RESOURCE_NAMES name = newResourceCount.resourceName; int add = newResourceCount.resourceCount; int oldValue = 0; if (resourceHash.ContainsKey(name)) { resourceHash[name] = (int)resourceHash[name] + add; oldValue = (int)resourceHash[name]; } else { resourceHash[name] = add; oldValue = add; } }
public List <ResourceCount> getTopPages(RenderContext Context) { var sitedb = Context.WebSite.SiteDb(); List <ResourceCount> pagecountes = new List <ResourceCount>(); List <TempCounter> temp = new List <TempCounter>(); var logs = DashBoardHelper.GetLogs(Context); foreach (var item in logs.GroupBy(o => o.ObjectId)) { TempCounter one = new TempCounter(); one.Item = item.First(); one.Count = item.Count(); one.ObjectId = item.Key; temp.Add(one); } int counter = 0; foreach (var item in temp.OrderByDescending(o => o.Count)) { var page = sitedb.Pages.Get(item.ObjectId, true); if (page != null) { ResourceCount count = new ResourceCount(); var pageurl = ObjectService.GetObjectRelativeUrl(sitedb, item.ObjectId, ConstObjectType.Page); count.Name = pageurl; count.Count = item.Count; count.Size = item.Size; pagecountes.Add(count); counter += 1; if (counter >= 3) { return(pagecountes); } } } return(pagecountes); }
public int CalculateValue(ResourceCount resources) { // Give a negative value to null. It's decidedly less valuable than any existing state. if (resources == null) { return(-1); } // We are assuming that dead states (0 energy) won't show up. If we wanted to support that, we'd have to check specifically for it and give it a negative value too. // (but greater than the value for null) int value = 0; foreach (ConsumableResourceEnum currentResource in Enum.GetValues(typeof(ConsumableResourceEnum))) { value += resources.GetAmount(currentResource) * FixedResourceValues[currentResource]; } return(value); }
private void CalculateProduction(Map map) { production = new ResourceCount(0, 0, 0, 0, 0); int width = GameManager.Instance.width; int height = GameManager.Instance.height; for (int i = -1; i <= 0; i++) { for (int j = -1; j <= 0; j++) { Vector2 vec = position + new Vector2(i, j); if (vec.x < -(width / 2) || vec.x >= (width / 2) || vec.y < -(width / 2) || vec.y >= height / 2) { continue; } production += map.tiles[(int)vec.x + width / 2, (int)vec.y + height / 2].resource; } } }
override public void Tick() { if (myCity.path != null && myCity.path.Count == 1) { modelTrain.Hide(); return; } if (queue.Count == 0) { modelTrain.Hide(); queue = new Queue <Vector2>(myCity.path); if (position == myCity.position) { load = myCity.production; load += 0.25f * myCity.production.MultiResources; load *= myCity.UpgradeLevel; queue = new Queue <Vector2>(queue.Reverse()); modelTrain.PackUp(); } else { GameManager.Instance.Resources += load; load = 0 * load; modelTrain.Unload(); } } if (queue.Count > 0) { Vector2 newPosition = queue.Dequeue(); GameManager.addConnection(GameManager.Instance.Connections.ConnectionAt(position, newPosition)); if (queue.Count > 0) { nextPosition = queue.Peek(); modelTrain.SetTarget(nextPosition); } position = newPosition; } }
public override void GetProperties(ObjectPropertyList list) { base.GetProperties(list); list.Add(1159590, ResourceCount.ToString()); // Essences: ~1_COUNT~ }
public virtual StartConditions CreateStartConditions(SuperMetroidModel model, ItemContainer itemContainer) { if (!model.Rooms.TryGetValue(itemContainer.StartingRoomName, out Room startingRoom)) { throw new Exception($"Starting room '{itemContainer.StartingRoomName}' not found."); } if (!startingRoom.Nodes.TryGetValue(itemContainer.StartingNodeId, out RoomNode startingNode)) { throw new Exception($"Starting node ID {itemContainer.StartingNodeId} not found in room '{startingRoom.Name}'."); } List <GameFlag> startingFlags = new List <GameFlag>(); foreach (string flagName in itemContainer.StartingGameFlagNames) { if (!model.GameFlags.TryGetValue(flagName, out GameFlag flag)) { throw new Exception($"Starting game flag {flagName} not found."); } startingFlags.Add(flag); } List <NodeLock> startingLocks = new List <NodeLock>(); foreach (string lockName in itemContainer.StartingNodeLockNames) { if (!model.Locks.TryGetValue(lockName, out NodeLock nodeLock)) { throw new Exception($"Starting node lock {lockName} not found."); } startingLocks.Add(nodeLock); } ResourceCount startingResources = new ResourceCount(); foreach (ResourceCapacity capacity in itemContainer.StartingResources) { startingResources.ApplyAmount(capacity.Resource, capacity.MaxAmount); } ItemInventory startingInventory = new ItemInventory(startingResources); foreach (string itemName in itemContainer.StartingItemNames) { if (!model.Items.TryGetValue(itemName, out Item item)) { throw new Exception($"Starting item {itemName} not found."); } startingInventory.ApplyAddItem(item); } StartConditions startConditions = new StartConditions { StartingNode = startingNode, StartingGameFlags = startingFlags, StartingOpenLocks = startingLocks, BaseResourceMaximums = startingResources, // Default starting resource counts to the starting maximum StartingResources = startingResources.Clone(), StartingInventory = startingInventory }; return(startConditions); }
private void Start() { _resource = this.gameObject.name; _resourceController = GameObject.FindGameObjectWithTag("ResourceController"); _resourceCount = _resourceController.GetComponent <ResourceCount>(); }
// Use this for initialization void Start() { resourceCountScript = FindObjectOfType <ResourceCount>(); }
public bool HasResource(ResourceCount count) { return(inventory[count.resourceId] >= count.count); }
public ExecutionResult Execute(SuperMetroidModel model, InGameState inGameState, int times = 1, bool usePreviousRoom = false) { var requirementsResult = FarmCycle.RequirementExecution.Execute(model, inGameState, times: times, usePreviousRoom: usePreviousRoom); // Can't even execute one cycle, so return a failure if (requirementsResult == null) { return(null); } // Build a dictionary of resources that are spent while doing the execution of a cycle ResourceCount resourceVariation = requirementsResult.ResultingState.GetResourceVariationWith(inGameState); // Start with all consumable resources IDictionary <ConsumableResourceEnum, int> costingResources = Enum.GetValues(typeof(ConsumableResourceEnum)) .Cast <ConsumableResourceEnum>() // Invert the resource variation to convert it to a resource cost .Select(resource => (resource: resource, cost: resourceVariation.GetAmount(resource) * -1)) // Keep only pairs where some of the resource has been spent .Where(resourceCost => resourceCost.cost > 0) // Finally, build a dictionary from the pairs .ToDictionary(resourceCost => resourceCost.resource, resourceCost => resourceCost.cost); // Identify all resources that can be refilled by this farm cycle IEnumerable <ConsumableResourceEnum> farmableResources = ComputeFarmableResources(model, costingResources); // Calculate the initial effective drop rates, taking into account currently full resources. // However, resources that are full but not farmable here should not be taken into account. IEnumerable <ConsumableResourceEnum> fullResources = inGameState.GetFullConsumableResources().Intersect(farmableResources).ToArray(); EnemyDrops initialEffectiveDropRates = FarmCycle.RoomEnemy.Enemy.GetEffectiveDropRates(model, fullResources); // Build a dictionary containing the variation per cycle for each consmable resource IDictionary <ConsumableResourceEnum, decimal> resourceVariationPerCycle = Enum.GetValues(typeof(ConsumableResourceEnum)) .Cast <ConsumableResourceEnum>() .ToDictionary(resource => resource, resource => CalculateResourceVariationPerCycle(model, resource, initialEffectiveDropRates, costingResources)); // Identify resources that are creeping down as we farm IEnumerable <ConsumableResourceEnum> initiallyUnstableResources = costingResources .Where(pair => resourceVariationPerCycle[pair.Key] < 0) .Select(pair => pair.Key) .ToArray(); // If there's no resources we can farm, just return now if (!farmableResources.Any()) { // If any of the resources initially lose out per farm cycle, we're not even able to farm. Return a failure. if (initiallyUnstableResources.Any()) { return(null); } // Otherwise, we're able to farm but it doesn't do anything according to logical options return(new ExecutionResult(inGameState.Clone())); } // If there's no resource that initially loses out, we're not concerned about losing any resources. // We can refill all farmable resources and report a success if (!initiallyUnstableResources.Any()) { return(ExecuteRefill(model, inGameState, farmableResources)); } // If we have resources that initially lose out, they must eventually turn farmable. // Otherwise, we consider this a failure. if (initiallyUnstableResources.Except(farmableResources).Any()) { return(null); } // Now we know we have at least one resource that currently loses out per cycle, but can eventually recharge. // Execute some farming to see if we can stabilize those resources before we run out. IEnumerable <ConsumableResourceEnum> notFullFarmableResources = farmableResources.Except(fullResources).ToArray(); IDictionary <ConsumableResourceEnum, decimal> resourceCounts = Enum.GetValues(typeof(ConsumableResourceEnum)) .Cast <ConsumableResourceEnum>() .ToDictionary(resource => resource, resource => (decimal)inGameState.GetCurrentAmount(resource)); EnemyDrops effectiveDropRates = initialEffectiveDropRates; // Execute farm cycles until a resource runs out or all costing resources have stabilized while (costingResources .Where(pair => resourceVariationPerCycle[pair.Key] < 0) .Any()) { // Figure out how many cycles we need to execute in order to refill something farmable and stable int cyclesToRefillSomething = notFullFarmableResources.Select(resource => decimal.ToInt32(decimal.Ceiling((inGameState.GetMaxAmount(resource) - resourceCounts[resource]) / resourceVariationPerCycle[resource]))) .Where(cycleCount => cycleCount > 0) .Min(); // Apply to each farmable resource the resource variation from executing that many cycles. // We don't care if it goes over maximum since we won't apply these to the in-game state foreach (ConsumableResourceEnum resource in notFullFarmableResources) { resourceCounts[resource] += resourceVariationPerCycle[resource] * cyclesToRefillSomething; } // If an unstable resource has dipped below the cost per cycle, we can't go on. Return a failure. if (costingResources.Where(costingResource => resourceCounts[costingResource.Key] < costingResource.Value).Any()) { return(null); } // If we haven't run out of anything, prepare the next loop // Update full resources fullResources = resourceCounts .Where(pair => pair.Value >= inGameState.GetMaxAmount(pair.Key)) .Select(pair => pair.Key) .Intersect(farmableResources) .ToArray(); // Update farmable resources by excluding newly-full resources notFullFarmableResources = notFullFarmableResources.Except(fullResources).ToArray(); // Calculate a new effective drop rate using the new list of full resources // If that new effective drop rate stabilizes all unstable resources, we'll make it out of the loop effectiveDropRates = model.Rules.CalculateEffectiveDropRates(FarmCycle.RoomEnemy.Enemy.Drops, model.Rules.GetUnneededDrops(fullResources)); // Use the new effective drop rate to calculate the new resourceVariationPerCycle for resources we still care about resourceVariationPerCycle = notFullFarmableResources .ToDictionary(resource => resource, resource => CalculateResourceVariationPerCycle(model, resource, effectiveDropRates, costingResources)); } // All resources are now stable. We already checked beforehand that all costing resources eventually become farmable, // so we can just apply a refill for all farmable resources and return a success. return(ExecuteRefill(model, inGameState, farmableResources)); }
public Tile(ResourceCount resource) { this.resource = resource; }