private IEnumerator HealPacient(AgentNPC pacient) { PrepareDestination(pacient); while (true) { if (_npc.Agent.pathPending) { yield return(null); } Debug.Log(Vector3.Distance(transform.position, _meetingPosition) + " " + _npc.Agent.remainingDistance); if (_npc.Agent.remainingDistance < 0.5f) { Debug.Log($"doctor reached at {pacient.name}"); _npc.Agent.isStopped = true; yield return(StartCoroutine(RotateCoroutine(1f, pacient))); // TODO: add heal animation yield return(new WaitForSeconds(2f)); Debug.Log($"{pacient.name} is healed"); pacient.InfectionSystem.Cured = true; _npc.Agent.isStopped = false; break; } yield return(null); } }
private void PrepareDestination(AgentNPC pacient) { Transform pacientTransform = pacient.transform; _meetingPosition = pacientTransform.position + pacientTransform.forward * 2; _npc.Agent.SetDestination(_meetingPosition); }
public void AddDoctor(AgentNPC doctor) { if (_doctorList.Contains(doctor) == false) { _doctorList.Add(doctor); } }
public void AddAgent(AgentNPC agentNPC) { if (!agentNPCList.Contains(agentNPC)) { agentNPCList.Add(agentNPC); } }
public void Enable() { _npc = GetComponent <AgentNPC>(); _npc.Agent.isStopped = true; _audioSource = GetComponent <AudioSource>(); Player.Player.Instance.OnFirstCough += SayHeyToPlayer; Infirmery.Instance.AddDoctor(_npc); }
public IEnumerator OnUpdate() { while (_pacientsStack.Count > 0) { AgentNPC pacient = _pacientsStack.Peek(); _pacientsStack.Pop(); yield return(StartCoroutine(HealPacient(pacient))); } _npc.RemoveBehaviour(this); }
private Vector3 GetMeetingPosition(AgentNPC npc) { Vector3 position = _transform.position; Vector3 direction = npc.transform.position - position; direction /= 2; var meetingDistance = AgentManager.Instance.generalConfiguration.meetingDistance / 2; Vector3 meetingPosition = position + direction - meetingDistance * direction.normalized; return(meetingPosition); }
public void Meet(AgentNPC partnerNPC, float talkDuration) { // set up every thing in order to meet the agent partnerNPC Vector3 meetingPosition = GetMeetingPosition(partnerNPC); var meetBehaviour = _npc.gameObject.AddComponent <MeetBehaviour>(); meetBehaviour.MeetPosition = meetingPosition; meetBehaviour.partnerNPC = partnerNPC; meetBehaviour.talkDuration = talkDuration; _npc.SetBehaviour(meetBehaviour); }
public Transform GetBedPosition(AgentNPC pacientNpc) { for (int i = 0; i < _ocuppiedBeds.Count; i++) { if (_ocuppiedBeds[i] == false) { _npcBedIndex.Add(pacientNpc, i); _ocuppiedBeds[i] = true; return(beds[i]); } } return(null); }
private IEnumerator RotateCoroutine(float duration, AgentNPC pacient) { Quaternion initialRotation = transform.rotation; Quaternion desiredRotation = pacient.transform.rotation * Quaternion.Euler(0, 180, 0); var initialTime = Time.time; while (Time.time - initialTime < duration) { transform.rotation = Quaternion.Lerp(initialRotation, desiredRotation, (Time.time - initialTime) / duration); yield return(null); } transform.rotation = desiredRotation; }
public void CallDoctor(AgentNPC pacient) { AgentNPC doctor = _doctorList[0]; if (doctor.GetComponent <HealAgentBehaviour>() == null) { var healBehaviour = doctor.gameObject.AddComponent <HealAgentBehaviour>(); healBehaviour.AddPacient(pacient); doctor.SetBehaviour(healBehaviour); } else { var healBehaviour = doctor.gameObject.GetComponent <HealAgentBehaviour>(); healBehaviour.AddPacient(pacient); } }
private bool AcceptsMeeting(AgentNPC agentNPC) { if (agentNPC.GetComponent <MeetBehaviour>() || agentNPC.GetComponent <PatrolBehaviour>() == null) { return(false); // if it is already in meeting then return false } // check to prevent two agents meeting without having time to turn around and walk away if (LastMeetingTime != 0 && !(Time.time - LastMeetingTime > _npc.agentConfiguration.cooldownMeeting)) { return(false); } var found = _ignoredAgents.Find(tuple => tuple.Item1 == agentNPC); // if we found an agent ignored and if (found != null) { // if the duration has passed seconds had not still passed, then we simply cancel the meeting var ignoreDuration = found.Item2; var initialIgnoreTIme = found.Item3; if (Time.time - initialIgnoreTIme < ignoreDuration) { Debug.Log($"Meeting Failed because {_npc.name} ignored {agentNPC.name}"); return(false); } // if the duration in seconds passed(e.g 10 seconds) than remove the bot because is no longer ignored _ignoredAgents.Remove(found); } if (AIUtils.CanSeeObject(_transform, agentNPC.transform, AgentManager.Instance.generalConfiguration.viewDistance, AgentManager.Instance.generalConfiguration.viewAngle)) { return(true); } return(false); }
public void IgnoreAgent(AgentNPC agent, int duration) { _ignoredAgents.Add(new Tuple <AgentNPC, int, float>(agent, duration, Time.time)); }
public MeetSystem(AgentNPC ownerOwnerNPC) { _npc = ownerOwnerNPC; _transform = _npc.transform; }
public void AddPacient(AgentNPC npc) { _pacientsStack.Push(npc); }
public void FreeBed(AgentNPC pacient) { Debug.Assert(_npcBedIndex.ContainsKey(pacient), "The pacient want to leave a bed and had not registred in the hospital"); _ocuppiedBeds[_npcBedIndex[pacient]] = false; _npcBedIndex.Remove(pacient); }
public void Enable() { _npc = GetComponent <AgentNPC>(); _npc.Agent.isStopped = false; Debug.Log($"enabling heal behaviour at position {_meetingPosition}"); }