public Stacks.OnGainOre GetGainOreDelegate(Ore ore) { for (int i = 0; i < oreStacks.Count; i++) { if (ore == oreStacks[i].ore) { return(oreStacks[i].gainOre); } } return(null); }
private void StopMining() { if (rock) { rock.SetMining(false); } player.StopMoving(); miningAnim.SetBool("Mining", false); currentOre = null; rock = null; miningUICanvas.SetActive(false); }
public bool AtCapacity(Ore ore) { bool full = false; for (int i = 0; i < oreStacks.Count; i++) { if (ore == oreStacks[i].ore) { if (oreStacks[i].amount >= maxPerStack) { full = true; } break; } } return(full); }
public void AddToInventory(Ore ore) { // check the array for ore type for (int i = 0; i < oreStacks.Count; i++) { // if found if (oreStacks[i].ore == ore) { // if not full if (oreStacks[i].amount < maxPerStack) { oreStacks[i].AddOre(); // add } else { Debug.Log("Cannot hold anymore " + ore.oreName); Chatbox.Instance.UpdateChatbox("<color=red>Cannot hold anymore " + ore.oreName + "</color>"); } break; } } }
private void CheckInteraction() { // raycast from the camera Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { // look for rock tag if (hit.transform.CompareTag("Rock")) { // if you are already mining if (rock) { // if hit rock, that you are not mining, move to rock if (hit.transform != rock.transform) { // clear current rock StopMining(); // get ore and set rock rock = hit.transform.GetComponent <Rock>(); currentOre = rock.GetOre(); if (currentOre.levelReq > miningLevel.lvl) { Debug.Log("Not highest lvl to mine " + currentOre.oreName); Chatbox.Instance.UpdateChatbox("<color=red>Not highest lvl to mine " + currentOre.oreName + " </color>"); return; } // check if inventory is full if (inventory.AtCapacity(currentOre)) { Debug.Log("Cannot hold anymore " + currentOre.oreName); Chatbox.Instance.UpdateChatbox("<color=red>Cannot hold anymore " + currentOre.oreName + "</color>"); return; } // move player into position player.SetDestination(rock.GetPosition(), rock.transform); // listen to the destination reached event player.ReachTargetEvent.AddListener(StartMining); // restore stamina UpdateStamina(1.0f); } // if hit rock, that you are mining, restore stamina else { UpdateStamina(1.0f); } } // if you are not mining, move to rock and mine else { // get rock and ore rock = hit.transform.GetComponent <Rock>(); currentOre = rock.GetOre(); if (currentOre.levelReq > miningLevel.lvl) { Debug.Log("Not highest lvl to mine " + currentOre.oreName); Chatbox.Instance.UpdateChatbox("<color=red>Not highest lvl to mine " + currentOre.oreName + " </color>"); return; } // check if inventory is full if (inventory.AtCapacity(currentOre)) { Debug.Log("Cannot hold anymore " + currentOre.oreName); Chatbox.Instance.UpdateChatbox("<color=red>Cannot hold anymore " + currentOre.oreName + "</color>"); return; } // move player into position player.SetDestination(rock.GetPosition(), rock.transform); // listen to the destination reached event player.ReachTargetEvent.AddListener(StartMining); } } else { StopMining(); } } }