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; }
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); } }