public bool AssignJob(MeasureType typeToInstall) { _target = FindBestBuilding(typeToInstall); if (_target == null) { UIController.instance.AddNews(name, " wants to install a " + typeToInstall.ToString() + ", but there is no room left."); return(false); } if (GameController.instance.money < RainproofMeasures.GetCost(typeToInstall)) { UIController.instance.AddNews(name, " tried to buy a " + typeToInstall.ToString() + ", but there is currently not enough money."); return(false); } _measureToInstall = typeToInstall; _path = AStar.FindPath(_lastReachedWaypoint, _target); _target.GetComponent <RainproofMeasures>().PlanMeasure(_measureToInstall); Vector2 screenSize = new Vector2(Screen.width, Screen.height); Vector2 canvasLocation = Camera.main.WorldToViewportPoint(new Vector2(_target.transform.position.x * screenSize.x, _target.transform.position.y * screenSize.y)); UIController.instance.AddMoneyDecreaseFeedback(canvasLocation, RainproofMeasures.GetCost(typeToInstall)); UIController.instance.AddNews(name, " bought a " + typeToInstall.ToString() + " and is now going to install it."); CreateMeasureIcon(); ApplyEasterEgg(); return(true); }
public int CalculateProfit() { int amount = 0; foreach (MeasureType type in appliedMeasures) { amount += (int)(RainproofMeasures.GetCost(type) * SettingsController.instance.costPercentageProfitPerMonth); } return(amount); }
void Awake() { RainproofMeasures.AddCostValue(MeasureType.DrainPipe, SettingsController.instance.drainPipeCost); RainproofMeasures.AddCostValue(MeasureType.GreenGarden, SettingsController.instance.greenGardenCost); RainproofMeasures.AddCostValue(MeasureType.GreenRoof, SettingsController.instance.greenRoofCost); RainproofMeasures.AddCostValue(MeasureType.RainBarrel, SettingsController.instance.rainBarrelCost); RainproofMeasures.AddCostValue(MeasureType.TemporalDams, SettingsController.instance.temporalDamsCost); RainproofMeasures.AddCostValue(MeasureType.Threshold, SettingsController.instance.thresholdCost); RainproofMeasures.AddCostValue(MeasureType.VerticalGarden, SettingsController.instance.verticalGardenCost); UIController.instance.UpdateProductLabels(); UIController.instance.UpdateRainwaterMeter(); TimeController.OnMonthPassed += TimeController_OnMonthPassed; RequestController.instance.ClearOnlineQueue(); }
int GatherAvailableRainwater(int amount) { int foundRainwater = 0; Waypoint[] allBuildings = GameController.instance.GetAllBuildingWaypoints(); foreach (Waypoint building in allBuildings) { RainproofMeasures measures = building.GetComponent <RainproofMeasures>(); if (measures.appliedMeasures.Contains(MeasureType.RainBarrel)) { foundRainwater += measures.TakeRainwater(amount - foundRainwater); } } return(foundRainwater); }
public Waypoint FindBestBuilding(MeasureType typeToInstall) { Waypoint[] allBuildings = GameController.instance.GetAllBuildingWaypoints(); Waypoint target = null; int lowestCount = int.MaxValue; foreach (Waypoint building in allBuildings) { RainproofMeasures measures = building.GetComponent <RainproofMeasures>(); int count = measures.appliedMeasures.Count + measures.plannedMeasures.Count; if (count < lowestCount && measures.CanApply(typeToInstall)) { target = building; lowestCount = count; } } return(target); }
void ProcessRaining() { float radius = 5f * transform.localScale.x; RaycastHit2D[] hits = Physics2D.CircleCastAll(transform.position, radius, Vector2.zero); foreach (RaycastHit2D hit in hits) { if (hit.collider.tag == "Building Waypoint") { RainproofMeasures measures = hit.collider.GetComponent <RainproofMeasures>(); measures.RainUpon(_mmPerDay); GameController.instance.totalDamage += (int)(_mmPerDay / 10f); UIController.instance.UpdateDamageCounter(); } else if (hit.collider.tag == "Sewage Drain") { SewageDrain drain = hit.collider.GetComponent <SewageDrain>(); if (!drain.isFlooding) { drain.RainUpon(_mmPerDay); } } else if (hit.collider.name == "Rain Cloud Deleter") { DestroyNow(); } } //if (count == 0) // return; //int maxCount = (buildingMeasures.Count * System.Enum.GetValues(typeof(MeasureType)).Length); //float maxReduction = SettingsController.instance.maximumDamageReduction; //float factor = (1f - (count / maxCount)) * maxReduction; //int mmPerDay = Mathf.FloorToInt(_mmPerDay * factor); ////Debug.Log(factor); //foreach (RainproofMeasures measure in buildingMeasures) //{ // measure.RainUpon(mmPerDay); //} //UIController.instance.UpdateDamageCounter(); //int calculatedMMPerFrame = _mmPerDay; //int count = 0; //foreach (Waypoint building in _buildings.Values) // count += building.GetComponent<RainproofMeasures>().appliedMeasures.Count; //foreach (SewageDrain drain in _drains.Values) //{ // if (!drain.isFlooding) // count++; //} //if (count > 1) //{ // float factor = 1f - (SettingsController.instance.maximumDamageReduction / 35f) * count; // calculatedMMPerFrame = Mathf.FloorToInt(_mmPerDay * factor); //} //calculatedMMPerFrame = (calculatedMMPerFrame < 1) ? 1 : calculatedMMPerFrame; //foreach (Waypoint building in _buildings.Values) // building.GetComponent<RainproofMeasures>().RainUpon(calculatedMMPerFrame); //foreach (SewageDrain drain in _drains.Values) // drain.GetComponent<SewageDrain>().RainUpon(calculatedMMPerFrame); }
void DiscountReward(WebData data) { Waypoint chosenBuilding = null; MeasureType?chosenType = null; Waypoint[] buildingsCopy = (Waypoint[])GameController.instance.GetAllBuildingWaypoints().Clone(); MeasureType[] measureTypesCopy = (MeasureType[])Enum.GetValues(typeof(MeasureType)); int totalMeasureCount = Enum.GetValues(typeof(MeasureType)).Length; MiscUtils.ShuffleArray(buildingsCopy); for (int i = 0; i < buildingsCopy.Length; i++) { RainproofMeasures measures = buildingsCopy[i].GetComponent <RainproofMeasures>(); if (measures.appliedMeasures.Count == totalMeasureCount) { continue; } chosenBuilding = buildingsCopy[i]; MiscUtils.ShuffleArray(measureTypesCopy); for (int j = 0; j < measureTypesCopy.Length; j++) { MeasureType type = measureTypesCopy[j]; if (!measures.CanApply(type)) { continue; } if (GameController.instance.money < (int)(RainproofMeasures.GetCost((MeasureType)type) * 0.5f)) { continue; } chosenType = type; break; } if (chosenType != null) { break; } } if (chosenBuilding == null || chosenType == null) { UIController.instance.AddNews(data.sender, " got a a 50% discount on a random rainproofing measure, but there was no room or money."); return; } GameObject builderObj = SpawnController.instance.SpawnBuilder(data); builderObj.transform.SetParent(GameObject.Find("Character Holder").transform, false); Builder builder = builderObj.GetComponent <Builder>(); builder.SpawnAt(GameController.instance.GetRandomStartingWaypoint()); builder.AssignJob((MeasureType)chosenType, chosenBuilding); builderObj.SetActive(true); UIController.instance.AddNews(data.sender, " got a 50% discount on a " + chosenType.ToString() + " and is going to install it."); UIController.instance.AddMoneyDecreaseFeedback(Vector2.zero, (int)(RainproofMeasures.GetCost((MeasureType)chosenType) * 0.5f)); }