示例#1
0
        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);
            }
        }
示例#2
0
        private void PrepareDestination(AgentNPC pacient)
        {
            Transform pacientTransform = pacient.transform;

            _meetingPosition = pacientTransform.position + pacientTransform.forward * 2;
            _npc.Agent.SetDestination(_meetingPosition);
        }
示例#3
0
 public void AddDoctor(AgentNPC doctor)
 {
     if (_doctorList.Contains(doctor) == false)
     {
         _doctorList.Add(doctor);
     }
 }
示例#4
0
 public void AddAgent(AgentNPC agentNPC)
 {
     if (!agentNPCList.Contains(agentNPC))
     {
         agentNPCList.Add(agentNPC);
     }
 }
示例#5
0
        public void Enable()
        {
            _npc = GetComponent <AgentNPC>();
            _npc.Agent.isStopped = true;
            _audioSource         = GetComponent <AudioSource>();

            Player.Player.Instance.OnFirstCough += SayHeyToPlayer;
            Infirmery.Instance.AddDoctor(_npc);
        }
示例#6
0
        public IEnumerator OnUpdate()
        {
            while (_pacientsStack.Count > 0)
            {
                AgentNPC pacient = _pacientsStack.Peek();
                _pacientsStack.Pop();
                yield return(StartCoroutine(HealPacient(pacient)));
            }

            _npc.RemoveBehaviour(this);
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }
示例#9
0
 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);
 }
示例#10
0
        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;
        }
示例#11
0
        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);
            }
        }
示例#12
0
        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);
        }
示例#13
0
 public void IgnoreAgent(AgentNPC agent, int duration)
 {
     _ignoredAgents.Add(new Tuple <AgentNPC, int, float>(agent, duration, Time.time));
 }
示例#14
0
 public MeetSystem(AgentNPC ownerOwnerNPC)
 {
     _npc       = ownerOwnerNPC;
     _transform = _npc.transform;
 }
示例#15
0
 public void AddPacient(AgentNPC npc)
 {
     _pacientsStack.Push(npc);
 }
示例#16
0
 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);
 }
示例#17
0
 public void Enable()
 {
     _npc = GetComponent <AgentNPC>();
     _npc.Agent.isStopped = false;
     Debug.Log($"enabling heal behaviour at position {_meetingPosition}");
 }