Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 private void StopMining()
 {
     if (rock)
     {
         rock.SetMining(false);
     }
     player.StopMoving();
     miningAnim.SetBool("Mining", false);
     currentOre = null;
     rock       = null;
     miningUICanvas.SetActive(false);
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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;
                }
            }
        }
Ejemplo n.º 5
0
        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();
                }
            }
        }