コード例 #1
0
        void RandomNPC()
        {
            NPCAction randomAction = new NPCAction();

            var            numSteps = Random.Range(5, 25);
            List <NPCStep> steps    = new List <NPCStep>();

            // Initial Wait Step
            WaitStep initialWait = new WaitStep();

            initialWait.seconds = Random.Range(1, 2);

            steps.Add(initialWait);

            for (int i = 0; i < numSteps; i++)
            {
                // Move Step
                if (Random.Range(0, 2) == 0 || i == 0)
                {
                    // TODO: System for somewhat prioritizing another point in the same cluster for the next move or two

                    MoveStep moveStep = new MoveStep();
                    moveStep.pointName = npcPointNames[Random.Range(0, npcPointNames.Count)];

                    steps.Add(moveStep);
                }

                // Wait Step
                else
                {
                    WaitStep waitStep = new WaitStep();
                    waitStep.seconds = Random.Range(1, 300);

                    steps.Add(waitStep);
                }
            }

            WaitStep finalWait = new WaitStep();

            finalWait.seconds = Random.Range(1, 301);
            steps.Add(finalWait);
            randomAction.steps = steps;
            randomAction.reqs  = new Dictionary <int, string>();

            SpawnNPC(randomAction, true, finalWait.seconds % 2 == 0 ? true : false);
        }
コード例 #2
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;
        }
コード例 #3
0
ファイル: XMLParser.cs プロジェクト: dinguses/squirrel
        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);
            }
        }