Esempio n. 1
0
        void NextStep()
        {
            currStep = steps[currStepNum];

            navMeshAgent.isStopped = true;

            if (currStep is MoveStep)
            {
                MoveStep ms = (MoveStep)currStep;

                Vector3 destinationPoint = spawnerManager.npcPoints[ms.pointName];

                // TODO
                ziggyPoints = GenZiggyPoints(npcTransform.position, destinationPoint);
                //ziggyPoints[0] = destinationPoint;

                navMeshAgent.SetDestination(ziggyPoints[0]);
                navMeshAgent.isStopped = false;

                destination = ziggyPoints[0];


                if (Random.Range(0, 101) <= runLikelihood)
                {
                    anim.CrossFade(hashes.npc_run, 0.02f);
                    navMeshAgent.speed = 9.0f;
                }
                else
                {
                    anim.CrossFade(hashes.npc_walk, 0.02f);
                    navMeshAgent.speed = 3.5f;
                }

                //anim.CrossFade(hashes.npc_run, 0.02f);
                //rotateTowards = true;

                //StartCoroutine(MoveTurn(1.5f));
            }
            else if (currStep is WaitStep)
            {
                WaitStep ws = (WaitStep)currStep;

                if (!currentlyUsing)
                {
                    anim.CrossFade(hashes.npc_idle, 0.02f);
                }

                StartCoroutine(Wait(ws.seconds));
            }
            else if (currStep is MsgStep)
            {
                MsgStep ms = (MsgStep)currStep;

                if (!currentlyUsing)
                {
                    anim.CrossFade(hashes.npc_idle, 0.02f);
                }

                if (ms.waitForPals.Count > 0)
                {
                    waitingForPals = true;
                }
                else
                {
                    msg.text = ms.msg;
                    StartCoroutine(Wait(5));
                }
            }
            else if (currStep is UseStep)
            {
                UseStep us = (UseStep)currStep;

                // If NPC is stopping whatever they're doing
                if (us.objToUse == "stop")
                {
                    currentlyUsing = false;

                    // TODO: move NPC back off of the object
                    MoveForUse(us.objToUse);
                }

                else
                {
                    anim.CrossFade(hashes.npc_sit_idle, 0.02f);

                    currentlyUsing = true;

                    MoveForUse(us.objToUse);
                }

                return;
            }

            loopStep = true;
        }
Esempio n. 2
0
        void LoopStep()
        {
            if (currStep is MoveStep)
            {
                MoveStep ms = (MoveStep)currStep;

                //var distToDest = Vector3.Distance(npcTransform.position, ziggyPoints[0]);
                //float distTest = navMeshAgent.remainingDistance;

                //Debug.Log(navMeshAgent.remainingDistance);

                // TODO
                // if (distToDest <= 1.0f)
                //if (navMeshAgent.remainingDistance <= navMeshAgent.stoppingDistance)
                //if (navMeshAgent.pathStatus == NavMeshPathStatus.PathComplete)
                if (navMeshAgent.remainingDistance <= 1.75f && navMeshAgent.remainingDistance != 0)
                {
                    ziggyPoints.RemoveAt(0);

                    if (ziggyPoints.Count > 0)
                    {
                        //rotateTowards = true;
                        //navMeshAgent.isStopped = true;
                        //anim.CrossFade(hashes.npc_idle, 0.02f);
                        navMeshAgent.SetDestination(ziggyPoints[0]);
                    }
                    else
                    {
                        navMeshAgent.isStopped = true;
                        navMeshAgent.speed     = 0;
                        navMeshAgent.velocity  = Vector3.zero;
                        //navMeshAgent.GetComponent<Rigidbody>().drag = 100000;

                        StepOver();
                    }
                }
            }

            else if (currStep is MsgStep)
            {
                if (waitingForPals)
                {
                    MsgStep ms = (MsgStep)currStep;

                    bool allPalsHere = false;

                    foreach (int pal in ms.waitForPals)
                    {
                        GameObject bbb = GameObject.Find("NPC_" + pal);

                        if (bbb != null)
                        {
                            var distToPals = Vector3.Distance(bbb.transform.position, npcTransform.position);

                            if (distToPals <= 5.0f)
                            {
                                allPalsHere = true;
                            }
                            else
                            {
                                allPalsHere = false;
                            }
                        }
                        else
                        {
                            allPalsHere = false;
                        }
                    }

                    if (allPalsHere)
                    {
                        waitingForPals = false;
                        msg.text       = ms.msg;
                        StartCoroutine(Wait(5));
                    }
                }
            }
        }
Esempio n. 3
0
        private void ReadActions()
        {
            foreach (XmlElement node in actionsDoc.SelectNodes("actions/action"))
            {
                NPCAction                newAction = new NPCAction(int.Parse(node.GetAttribute("id")));
                List <NPCStep>           steps     = new List <NPCStep>();
                Dictionary <int, string> reqs      = new Dictionary <int, string>();
                List <int>               pals      = new List <int>();

                foreach (XmlElement reqsNode in node.SelectNodes("reqs/req"))
                {
                    reqs.Add(int.Parse(reqsNode.GetAttribute("id")), reqsNode.GetAttribute("value"));
                }

                foreach (XmlElement palsNode in node.SelectNodes("pals/pal"))
                {
                    pals.Add(int.Parse(palsNode.GetAttribute("id")));
                }

                foreach (XmlElement stepsNode in node.SelectNodes("steps/step"))
                {
                    switch (stepsNode.GetAttribute("type"))
                    {
                    case "move":
                        MoveStep moveStep = new MoveStep();
                        moveStep.pointName = stepsNode.GetAttribute("point");
                        steps.Add(moveStep);
                        break;

                    case "wait":
                        WaitStep waitStep = new WaitStep();
                        waitStep.seconds = float.Parse(stepsNode.GetAttribute("time"));
                        steps.Add(waitStep);
                        break;

                    case "msg":
                        MsgStep msgStep = new MsgStep();
                        msgStep.msg = stepsNode.GetAttribute("words");
                        string waitForString = stepsNode.GetAttribute("waitFor");

                        List <int> palsList = new List <int>();

                        if (!waitForString.Equals(""))
                        {
                            palsList = new List <int>(Array.ConvertAll(waitForString.Split(','), int.Parse));
                        }

                        msgStep.waitForPals = palsList;

                        //msgStep.waitForPals = (stepsNode.GetAttribute("waitForPals") == "t" ? true : false);

                        steps.Add(msgStep);
                        break;

                    case "use":
                        UseStep useStep = new UseStep();
                        useStep.objToUse = stepsNode.GetAttribute("obj");
                        steps.Add(useStep);
                        break;

                    default:
                        break;
                    }
                }

                newAction.steps = steps;
                newAction.reqs  = reqs;
                newAction.pals  = pals;
                npcActions.Add(newAction);
            }
        }