void PlaceRDP() { if (m_MyLerp.targetReached) { if (!m_RDPPlaced && m_MyRDP == null) { Debug.Log("Placed RDP"); m_WangObject.CreateRDP(m_RDPTile); m_MyRDP = m_WangObject.FindRDP(m_RDPTile.position); m_RDPMan = m_MyRDP.GetComponent <RDPManager>(); m_RDPPlaced = true; m_MyLerp.StopAllCoroutines(); m_MyLerp.enabled = false; m_Moving = false; ChangeState(CurrentState.SHOULD_MAKE_DECISION); } } }
// Stone Priorities: Cube6 -> Cube8&14 -> Cube2&5, -> Cube16 // Iron Priorities: Cube6 -> Cube2&5 -> Cube1 void SearchForRes() { bool _foundTile = false; while (!_foundTile) { int[] _matsToFind = new int[] { }; if (m_MyChoice == Choice.STONE) { _matsToFind = new int[] { 6, 8, 14 } } ; else if (m_MyChoice == Choice.IRON) { _matsToFind = new int[] { 6, 2, 5 } } ; GameObject[] _found = m_WangObject.FindCollection(transform.position, _matsToFind, 15); if (_found != null) { for (int i = 0; i < _found.Length; i++) { _found[i].SetActive(true); if (!_found[i].GetComponent <TileResources>().m_NWoodDepleted) { m_MyState = CurrentState.MOVINGTOTILE; m_Seeker.StartPath(transform.position, _found[i].transform.position, OnPathComplete); _foundTile = true; m_CurrentTile = _found[i]; m_ShouldSearch = false; break; } else { _found[i].SetActive(false); continue; } } break; } } } void DepositResources() { if (m_CurrentStone > 0) { m_MyRDP.GetComponent <RDPManager>().m_StoneAmount += m_CurrentStone; m_CurrentStone = 0; } else if (m_CurrentIron > 0) { m_MyRDP.GetComponent <RDPManager>().m_IronAmount += m_CurrentIron; m_CurrentIron = 0; } } IEnumerator IMine(GameObject _currentTile, Choice _type) { var _tileRes = _currentTile.GetComponent <TileResources>(); if (_type == Choice.STONE) { m_MyState = CurrentState.MININGRESOURCES; while (m_CurrentStone < m_InventorySize || !_tileRes.m_StoneDepleted) { m_CurrentStone++; _currentTile.GetComponent <TileResources>().m_Stone--; yield return(new WaitForSeconds(m_MineSpeed)); if (m_CurrentStone == m_InventorySize) { break; } } } else if (_type == Choice.IRON) { m_MyState = CurrentState.MININGRESOURCES; while (m_CurrentIron <= m_InventorySize || !_tileRes.m_IronDepleted) { m_CurrentIron++; _tileRes.m_Iron--; yield return(new WaitForSeconds(m_MineSpeed * 3f)); if (m_CurrentIron == m_InventorySize) { break; } } } else { yield break; } if (m_CurrentStone == m_InventorySize || m_CurrentIron == m_InventorySize || _tileRes.m_StoneDepleted || _tileRes.m_IronDepleted) { _currentTile.SetActive(false); SetRDP(); ReturnToRDP(); m_IsMining = false; yield return(null); } } bool SetRDP() { if (m_MyRDP == null) { m_MyRDP = m_WangObject.FindRDP(transform.position); if (m_MyRDP != null) { m_MyRDP.GetComponent <RDPManager>().m_Miners.Add(gameObject); } return(true); } return(false); } void ReturnToRDP() { if (m_MyRDP != null) { m_MyLerp.enabled = true; m_Seeker.StartPath(transform.position, m_MyRDP.transform.position, Deposit); } } void OnPathComplete(Path p) { if (!p.error) { m_Path = p; } } void Deposit(Path p) { if (!p.error) { m_Path = p; m_MyState = CurrentState.MOVINGTORDP; } } }
// NWood Priorities: Cube11 -> Cube12&15 -> Cube3&9 -> Cube16 -> Cube1 -> Cube8&14 -> Cube2&5 -> Cube6 // Pine Priorities: Cube1 -> Cube3&9 -> Cube11 ->Cube2&5 -> Cube12&15 void SearchForTrees() { bool _foundTile = false; while (!_foundTile) { int[] _matsToFind = new int[] { }; if (m_MyChoice == Choice.NWOOD) { _matsToFind = new int[] { 11, 12, 15 } } ; else if (m_MyChoice == Choice.PINE) { _matsToFind = new int[] { 1, 3, 9 } } ; GameObject[] _found = m_WangObject.FindCollection(transform.position, _matsToFind, 15); if (_found != null) { for (int i = 0; i < _found.Length; i++) { _found[i].SetActive(true); if (!_found[i].GetComponent <TileResources>().m_NWoodDepleted) { m_MyState = CurrentState.MOVINGTOTILE; m_Seeker.StartPath(transform.position, _found[i].transform.position, OnPathComplete); _foundTile = true; m_CurrentTile = _found[i]; m_ShouldSearch = false; break; } else { _found[i].SetActive(false); continue; } } break; } } } void DepositResources() { if (m_CurrentNWood > 0) { m_MyRDP.GetComponent <RDPManager>().m_WoodAmount += m_CurrentNWood; m_CurrentNWood = 0; } else if (m_CurrentPine > 0) { m_MyRDP.GetComponent <RDPManager>().m_PineAmount += m_CurrentPine; m_CurrentPine = 0; } } IEnumerator IChop(GameObject _currentTile, Choice _type) { var _tileRes = _currentTile.GetComponent <TileResources>(); if (_type == Choice.NWOOD) { m_MyState = CurrentState.CHOPPINGWOOD; while (m_CurrentNWood < m_InventorySize || !_tileRes.m_NWoodDepleted) { m_CurrentNWood++; _tileRes.m_NWood--; yield return(new WaitForSeconds(m_ChopSpeed)); if (m_CurrentNWood == m_InventorySize) { break; } } } else if (_type == Choice.PINE) { m_MyState = CurrentState.CHOPPINGWOOD; while (m_CurrentPine <= m_InventorySize || !_tileRes.m_PineDepleted) { m_CurrentPine++; _tileRes.m_Pine--; yield return(new WaitForSeconds(m_ChopSpeed * 3f)); if (m_CurrentPine == m_InventorySize) { break; } } } else { yield break; } if (m_CurrentPine == m_InventorySize || m_CurrentNWood == m_InventorySize || _tileRes.m_NWoodDepleted || _tileRes.m_PineDepleted) { _currentTile.SetActive(false); while (!SetRDP()) { yield return(new WaitForSeconds(3)); } ReturnToRDP(); m_IsChopping = false; yield return(null); } } bool SetRDP() { if (m_MyRDP == null) { m_MyRDP = m_WangObject.FindRDP(transform.position); if (m_MyRDP != null) { m_MyRDP.GetComponent <RDPManager>().m_Lumberjacks.Add(gameObject); } return(true); } return(false); } void ReturnToRDP() { if (m_MyRDP != null) { m_MyLerp.enabled = true; m_Seeker.StartPath(transform.position, m_MyRDP.transform.position, Deposit); } } void OnPathComplete(Path p) { if (!p.error) { m_Path = p; } } void Deposit(Path p) { if (!p.error) { m_Path = p; m_MyState = CurrentState.MOVINGTORDP; } } }