예제 #1
0
        public override void Enter(SimpleBallManFSM agent)
        {
            NavMeshAgent nav_agent = agent.GetComponent <NavMeshAgent>();

            if (nav_agent)
            {
                Collider[] entities = Physics.OverlapSphere(agent.transform.position, agent.SearchRadius, agent.InteractableLayers);

                nav_agent.ResetPath();

                foreach (Collider entity in entities)
                {
                    Transform food = entity.transform;

                    while (food != null && food.tag != "Food")
                    {
                        food = food.parent;
                    }

                    if (food != null)
                    {
                        nav_agent.SetDestination(food.position);
                        Debug.Log(agent.transform.name + " sees food (" + food.name + ") and is heading toward it!");

                        return;
                    }
                }

                Debug.Log(agent.transform.name + " doesn't see any food...");
            }
            else
            {
                Debug.LogError(agent.transform.name + " [FindFoodState]: No NavMeshAgent found!");
            }
        }
예제 #2
0
        public override void Enter(SimpleBallManFSM agent)
        {
            NavMeshAgent nav_agent = agent.GetComponent <NavMeshAgent>();

            if (nav_agent)
            {
                Collider[] entities = Physics.OverlapSphere(agent.transform.position, agent.SearchRadius, agent.InteractableLayers);

                nav_agent.ResetPath();

                foreach (Collider entity in entities)
                {
                    NestScaler nest = entity.GetComponentInParent <NestScaler>();

                    if (nest != null)
                    {
                        nav_agent.SetDestination(nest.transform.position);
                        Debug.Log(agent.transform.name + " sees its nest (" + nest.transform.name + ") and is heading toward it!");

                        return;
                    }
                }

                Debug.Log(agent.transform.name + " doesn't see his home. :'(");
            }
            else
            {
                Debug.LogError(agent.transform.name + " [ReturnToNestState]: No NavMeshAgent found!");
            }
        }
예제 #3
0
        public override void Enter(SimpleBallManFSM agent)
        {
            NavMeshAgent nav_agent = agent.GetComponent <NavMeshAgent>();

            if (nav_agent)
            {
                nav_agent.ResetPath();
            }

            Debug.Log(agent.transform.name + " is looking for crystals!");
        }
예제 #4
0
        public override void Leave(SimpleBallManFSM agent)
        {
            NavMeshAgent nav_agent = agent.GetComponent <NavMeshAgent>();

            if (nav_agent)
            {
                nav_agent.ResetPath();
            }

            Debug.Log(agent.transform.name + " has stopped looking for food.");
        }
예제 #5
0
        public override void Leave(SimpleBallManFSM agent)
        {
            NavMeshAgent nav_agent = agent.GetComponent <NavMeshAgent>();

            if (nav_agent)
            {
                nav_agent.ResetPath();
            }

            Debug.Log(agent.transform.name + " is done going to his nest.");
        }
예제 #6
0
        public override void Run(SimpleBallManFSM agent)
        {
            Collider[] entities = Physics.OverlapSphere(agent.transform.position, agent.InteractionRadius, agent.InteractableLayers);

            foreach (Collider entity in entities)
            {
                Transform crystal = entity.transform;

                while (crystal != null && crystal.tag != "Crystal")
                {
                    crystal = crystal.parent;
                }

                if (crystal != null)
                {
                    if (Random.value <= agent.Determination)
                    {
                        agent.CrystalsHeld  += 20;
                        agent.Determination += 0.02f;

                        if (agent.DeterminationEffect != null)
                        {
                            agent.DeterminationEffect.Play();
                        }

                        Debug.Log(agent.transform.name + " is filled with DETERMINATION and gathered 20 crystals!");
                    }
                    else
                    {
                        agent.Hunger       -= 1 + (int)Mathf.Floor(Random.Range(0, 2));
                        agent.Exhaustion   -= 3 + (int)Mathf.Floor(Random.Range(0, 2));
                        agent.CrystalsHeld += 1 + (int)Mathf.Floor(Random.Range(0, 1));

                        Debug.Log(agent.transform.name + " gathered a crystal!");
                    }

                    if (agent.CrystalsHeld >= 25 || agent.Exhaustion < 5)
                    {
                        agent.ChangeState(ReturnToNestState.Instance);
                    }
                    else if (agent.Hunger < 3)
                    {
                        agent.ChangeState(EatFoodState.Instance);
                    }

                    return;
                }
            }

            agent.ChangeState(FindCrystalState.Instance);

            Debug.Log(agent.transform.name + " couldn't find a crystal.");
        }
예제 #7
0
        public override void Run(SimpleBallManFSM agent)
        {
            NavMeshAgent nav_agent = agent.GetComponent <NavMeshAgent>();

            Collider[] entities = Physics.OverlapSphere(agent.transform.position, agent.InteractionRadius, agent.InteractableLayers);

            foreach (Collider entity in entities)
            {
                NestScaler nest = entity.GetComponentInParent <NestScaler>();

                if (nest != null)
                {
                    nest.Resources    += agent.CrystalsHeld;
                    agent.CrystalsHeld = 0;

                    Debug.Log(agent.transform.name + " deposited his crystals in his nest.");

                    if (agent.Exhaustion < 5)
                    {
                        agent.ChangeState(SleepState.Instance);
                    }
                    else if (agent.Hunger >= 8)
                    {
                        agent.ChangeState(FindCrystalState.Instance);
                    }
                    else
                    {
                        agent.ChangeState(FindFoodState.Instance);
                    }

                    return;
                }
            }

            if (nav_agent && nav_agent.hasPath)
            {
                Debug.Log(agent.transform.name + " is heading towards his nest!");
            }
            else
            {
                Debug.Log(agent.transform.name + " is lost...");
            }
        }
예제 #8
0
        public override void Run(SimpleBallManFSM agent)
        {
            NavMeshAgent nav_agent = agent.GetComponent <NavMeshAgent>();

            Collider[] entities = Physics.OverlapSphere(agent.transform.position, agent.InteractionRadius, agent.InteractableLayers);
            Transform  food     = null;

            foreach (Collider entity in entities)
            {
                food = entity.transform;

                while (food != null && food.tag != "Food")
                {
                    food = food.parent;
                }

                if (food != null)
                {
                    break;
                }
            }

            if (food != null)
            {
                Debug.Log(agent.transform.name + " found food!");

                if (nav_agent && nav_agent.hasPath)
                {
                    nav_agent.Stop();
                }

                agent.ChangeState(EatFoodState.Instance);
            }
            else if (nav_agent != null && nav_agent.hasPath)
            {
                Debug.Log(agent.transform.name + " is heading towards food!");
            }
            else
            {
                Debug.LogError(agent.transform.name + " [FindFoodState]: No NavMeshAgent found!");
            }
        }
예제 #9
0
        public override void Run(SimpleBallManFSM agent)
        {
            Collider[] entities = Physics.OverlapSphere(agent.transform.position, agent.InteractionRadius, agent.InteractableLayers);

            foreach (Collider entity in entities)
            {
                NestScaler nest = entity.GetComponentInParent <NestScaler>();

                if (nest != null)
                {
                    if (agent.Exhaustion < 50)
                    {
                        if (agent.Hunger > 0)
                        {
                            --agent.Hunger;
                        }

                        agent.Exhaustion += 5;

                        Debug.Log(agent.transform.name + " zzzzzzzz ...");
                    }
                    else if (agent.Hunger < 8)
                    {
                        agent.ChangeState(FindFoodState.Instance);
                    }
                    else
                    {
                        agent.ChangeState(FindCrystalState.Instance);
                    }

                    return;
                }
            }

            agent.ChangeState(ReturnToNestState.Instance);
        }
예제 #10
0
        public override void Run(SimpleBallManFSM agent)
        {
            Collider[] entities = Physics.OverlapSphere(agent.transform.position, agent.InteractionRadius, agent.InteractableLayers);

            foreach (Collider entity in entities)
            {
                Transform food = entity.transform;

                while (food != null && food.tag != "Food")
                {
                    food = food.parent;
                }

                if (food != null)
                {
                    ++agent.Hunger;
                    ++agent.Exhaustion;

                    if (agent.Determination > 0.2f)
                    {
                        agent.Determination -= 0.05f;
                    }

                    Debug.Log(agent.transform.name + " ate some food!");

                    if (agent.Hunger >= 10)
                    {
                        agent.ChangeState(FindCrystalState.Instance);
                    }

                    return;
                }
            }

            agent.ChangeState(FindFoodState.Instance);
        }
예제 #11
0
 public override void Leave(SimpleBallManFSM agent)
 {
     Debug.Log(agent.transform.name + " stopped gathering crystals.");
 }
예제 #12
0
 public abstract void Leave(SimpleBallManFSM agent);
예제 #13
0
 public abstract void Run(SimpleBallManFSM agent);
예제 #14
0
 public abstract void Enter(SimpleBallManFSM agent);
예제 #15
0
 public override void Leave(SimpleBallManFSM agent)
 {
     agent.Determination = 0.02f;
     Debug.Log(agent.transform.name + " has stopped sleeping.");
 }
예제 #16
0
 public override void Enter(SimpleBallManFSM agent)
 {
     Debug.Log(agent.transform.name + " is going to sleep.");
 }
예제 #17
0
        public override void Run(SimpleBallManFSM agent)
        {
            NavMeshAgent nav_agent = agent.GetComponent <NavMeshAgent>();

            Collider[] entities = Physics.OverlapSphere(agent.transform.position, agent.InteractionRadius, agent.InteractableLayers);
            Transform  crystal  = null;

            foreach (Collider entity in entities)
            {
                crystal = entity.transform;

                while (crystal != null && crystal.tag != "Crystal")
                {
                    crystal = crystal.parent;
                }

                if (crystal != null)
                {
                    break;
                }
            }

            if (crystal != null)
            {
                Debug.Log(agent.transform.name + " found a crystal!");

                agent.ChangeState(GatherCrystalsState.Instance);

                return;
            }

            if (nav_agent)
            {
                if (!nav_agent.hasPath)
                {
                    entities = Physics.OverlapSphere(agent.transform.position, agent.SearchRadius, agent.InteractableLayers);

                    foreach (Collider entity in entities)
                    {
                        crystal = entity.transform;

                        while (crystal != null && crystal.tag != "Crystal")
                        {
                            crystal = crystal.parent;
                        }

                        if (crystal != null)
                        {
                            break;
                        }
                    }

                    if (crystal != null)
                    {
                        Debug.Log(agent.transform.name + " sees a crystal (" + crystal.name + ") and is heading toward it!");

                        nav_agent.SetDestination(crystal.position);
                    }
                }
                else
                {
                    Debug.Log(agent.transform.name + " is heading towards a crystal!");
                }
            }
            else
            {
                Debug.LogError(agent.transform.name + " [FindCrystalState]: No NavMeshAgent found!");
            }
        }
예제 #18
0
 public override void Enter(SimpleBallManFSM agent)
 {
     Debug.Log(agent.transform.name + " is going to gather crystals!");
 }
예제 #19
0
 public override void Leave(SimpleBallManFSM agent)
 {
     Debug.Log(agent.transform.name + " has stopped eating food.");
 }