private Spawned SpawnObjectInMesh(int index, int trashArrayPos) { Mesh m = spawnArea[index].mesh; Transform t = center[index]; SpawnedList curRow = spawnable_SmallTrash[trashArrayPos]; Spawned current = curRow[curRow.Count - 1]; Vector3 vec = m.GetRandomPointInsideConvex(); vec = t.TransformPoint(vec); RaycastHit info; LayerMask mask = LayerMask.GetMask("Ground"); if (Physics.Raycast(vec, Vector3.down, out info, Mathf.Infinity, mask)) { current.gameObject.transform.position = info.point + Vector3.up * 0.2f; current.gameObject.transform.rotation = Random.rotation; current.gameObject.SetActive(true); curRow.Remove(current); spawned_SmallTrash[trashArrayPos].Add(current); LevelBalancing.SetTrashValue(current.personalTrashValue); return(current); } return(null); }
public override AbstractState UpdateState() { // anchor: ran out of Time in this state if (RemainingTimeInState >= SecondsToStateChange) { // return next AbstractState -> State_MainDecay return(NextState); } else { //Debug.Log("LevelBalancing: " + LevelBalancing.GetBalanceVariance()+"\nLastBalanceInState: "+ LastBalanceInState()); if (!SpawnTrashOverTime() && // If the normal SpawnOverTime logic takes place, skip this step (LastBalanceInState() >= timeBetweenBalancing || lastbaBalanceUpdate < 0f)) // Check if enough time has elapsed since last Balance spawn. Or its the first Balance spawn { Debug.Log("Balancing is triggered"); if (LevelBalancing.GetBalanceVariance() < 0f) // Check if there is need for Balance | Look up description in LevelBalancing Class for more info { GameInfo.TrashSpawner.SpawnOnTimer(); } else if (LevelBalancing.GetBalanceVariance() > Trees.startingNatureValue / 2f) { Debug.Log("Balancing is executing."); GameInfo.PlantDestroyer.DestroyRandomTreeInMiddleState(); } lastbaBalanceUpdate = GameInfo.SpentSecondsIngame; } } return(this); }
// Start is called before the first frame update void Start() { tC = new TreeComparer(); int counter = 0; if (treeParent == null) { Debug.LogError("treeParent is not selected in Editor."); } else { Trees[] temp = treeParent.GetComponentsInChildren <Trees>(); foreach (Trees t in temp) { t.TreeNumber = counter++; t.Controller = this; aliveTrees.Add(t); } float pNatVal = Trees.startingNatureValue; foreach (Trees t in aliveTrees) { t.personalNatureValue = pNatVal; } //Debug.LogWarning(pNatVal + "||" + counter); LevelBalancing.ResetBalanceValue(pNatVal * counter); } counter = 0; if (PoIParent == null) { //Debug.LogError("POIParent is not selected in Editor."); } else { PoI[] temp2 = PoIParent.GetComponentsInChildren <PoI>(); if (temp2 == null) { Debug.LogError($"No POI selected"); } else { foreach (PoI p in temp2) { p.Setup(this, counter++); PoIList.Add(p); } } } }
private void UpdateLevelTimer(float totalSeconds) { int minutes = Mathf.FloorToInt(totalSeconds / 60f); int seconds = Mathf.FloorToInt(totalSeconds % 60f); if (seconds == 60) { seconds = 0; minutes += 1; } debugInfo.text = $"Time: {minutes.ToString("00")}:{seconds.ToString("00")} \nSTATE: {currentState.ToString()} " + $"\nNature: {LevelBalancing.GetCurrentNatureValue()}\nTrash: {LevelBalancing.GetCurrentTrashValue()}\nBalanceValue: {LevelBalancing.GetBalanceVariance()}"; }
public void handleTreeDestroy(Trees t, int index = -1) { int treeIndex; if (index > -1) // is the index of the tree in the aliveTrees already known (index >= 0) or need it be checked now? { treeIndex = index; } else { //Debug.Log($"In DestroyVegetation because of {t}."); treeIndex = aliveTrees.BinarySearch(t, tC); //Debug.Log($"Found {t} at position {treeIndex}."); } if (treeIndex >= 0) { if (!t.lDis.isDissolving) { t.Interact(); } if (t.status == TREE_STAGE.ALIVE2) { float substractionValue = Trees.startingNatureValue / 100f * 30f; // gets reduced by 30% from original value //Debug.Log("StartingNatureVal: " + Trees.startingNatureValue + "Trees.startingNatureValue/100f*30f: " + substractionValue); t.personalNatureValue -= substractionValue; LevelBalancing.SetNatureValue(substractionValue); } if (t.status == TREE_STAGE.BETWEEN1 || t.status == TREE_STAGE.BETWEEN2) { float substractionValue = Trees.startingNatureValue / 100f * 20f; // gets reduced by 20% from original value t.personalNatureValue -= substractionValue; LevelBalancing.SetNatureValue(substractionValue); } else if (t.status == TREE_STAGE.DEAD) { aliveTrees.RemoveAt(treeIndex); deadTrees.Add(t); deadTrees.Sort(tC); LevelBalancing.SetNatureValue(t.personalNatureValue); // gets reduced by remaining 30% from original value t.personalNatureValue = 0f; if (deadTrees.Count == 1) { state.SwitchFirstTreeDestroyed(); } } } }
public Spawned SpawnSpecificTrashArea(int indexForm, int indexSpawnArea) { Spawned ret = null; TA_SHAPES standard = TA_SHAPES.Plane_Small; SpawnedList spawnable_curList = spawnable_TrashAreas[indexForm]; SpawnedList spawned_curList = spawned_TrashAreas[indexForm]; Spawned curPopped; int lastPos; if (spawnable_curList.Count == 0) { lastPos = 0; curPopped = spawned_curList[0]; spawned_curList.RemoveAt(0); spawnable_curList.Add(curPopped); } else { lastPos = spawnable_TrashAreas[indexForm].Count - 1; curPopped = spawnable_curList[lastPos]; } curPopped.gameObject.SetActive(true); //trashAreaHandler.Spawn(current + i, spawnArea[/*Random.Range(0, spawnArea.Length)*/4], curPopped); bool spawnedCorrectly = trashAreaHandler.Spawn(standard + indexForm, spawnArea[indexSpawnArea], curPopped, Random.Range(100, 160)); if (spawnedCorrectly) { StartCoroutine(GrowToSize(curPopped)); spawnable_curList.RemoveAt(lastPos); spawned_curList.Add(curPopped); ret = curPopped; LevelBalancing.SetTrashValue(curPopped.personalTrashValue); } else if (!spawnedCorrectly) { curPopped.gameObject.SetActive(false); } return(ret); }
public override AbstractState UpdateState() { // anchor: ran out of Time in this state if (RemainingTimeInState >= SecondsToStateChange) { return(NextState); } else if ((RemainingTimeInState >= SecondsToStateChange - 10f) && (preStatechangeAction)) { SpawnTrashOverTime(); GameInfo.PlantDestroyer.DestroyTreesInAlive1(); preStatechangeAction = false; } // else spawn small Trash every time spawnTiming is hit; else { SpawnTrashOverTime(); if (LastBalanceInState() >= timeBetweenBalancing || lastbaBalanceUpdate < 0f) // Check if enough time has elapsed since last Balance spawn. Or its the first Balance spawn { Debug.Log("Balancing is triggered"); if (LevelBalancing.GetBalanceVariance() < 0f) // Check if there is need for Balance | Look up description in LevelBalancing Class for more info { GameInfo.TrashSpawner.SpawnOnTimer(); } else if (LevelBalancing.GetBalanceVariance() > (Trees.startingNatureValue / 100f * 30f)) { Debug.Log("Balancing is executing."); GameInfo.PlantDestroyer.DestroyRandomTreeInRisingState(); } lastbaBalanceUpdate = GameInfo.SpentSecondsIngame; } } return(this); }