예제 #1
0
        private void OnTriggerEnter2D(Collider2D _other)
        {
            if (_other.gameObject != null)
            {
                PlayerManager _player = _other.gameObject.GetComponentInParent <PlayerManager>();

                if (_player != null)
                {
                    ShieldController shield = GetComponentInParent <ShieldController>();
                    //i
                    if (_player.team == Team.Virus)
                    {
                        GeneralAI _aiPlayer = _other.GetComponentInParent <GeneralAI>();
                        if (_aiPlayer != null)
                        {
                            _aiPlayer.isInsideShield = true;
                            _aiPlayer.exitVector     = transform.parent.GetChild(0);
                        }
                        if (!shield.isActivated)
                        {
                            GetComponentInParent <ShieldController>().photonView.RPC("ActivateShield", Photon.Pun.RpcTarget.AllBuffered);
                        }
                    }

                    return;
                }
            }
        }
예제 #2
0
        private void UpdatePath()
        {
            ExecuteStateBehaviour();

            if (seeker.IsDone() && !aiPlayerManager.isDead)
            {
                if (stateMachine == AIState.OnDuty)
                {
                    ShieldController _targetShield = target.gameObject.GetComponent <ShieldController>();
                    if (_targetShield.isActivated && team == Team.Virus)
                    {
                        FindRedShieldTarget();
                    }
                    seeker.StartPath(this.transform.position, target.position, OnPathComplete);
                }
                else
                {
                    seeker.StartPath(this.transform.position, secondaryTarget.position, OnPathComplete);
                }
            }
        }
예제 #3
0
        private void FindRedShieldTarget()
        {
            if (!GameManager.isGameover)
            {
                int _randomShieldNumber = 0;
                if (target != null)
                {
                    ShieldController _targetShield = target.gameObject.GetComponent <ShieldController>();
                    if (!_targetShield.isActivated && team == Team.Virus)
                    {
                        return;
                    }

                    _randomShieldNumber = GetRandomExcept(target.GetSiblingIndex());
                }
                else
                {
                    _randomShieldNumber = GetRandomExcept(-1);
                }

                target = ShieldsManager.instance.transform.GetChild(_randomShieldNumber);
            }
        }
예제 #4
0
        public void AnalyseEnvironement()
        {
            fleeVector   = Vector2.zero;
            stateMachine = AIState.OnDuty;
            if (radar == null)
            {
                return;
            }

            int _index = 0;

            foreach (Collider2D _detectedEntity in radar.detectedEntities)
            {
                if (_detectedEntity == null)
                {
                    continue;
                }

                PlayerManager    _player   = _detectedEntity.GetComponentInParent <PlayerManager>();
                Pickable         _pickable = _detectedEntity.GetComponent <Pickable>();
                ShieldController _shield   = _detectedEntity.GetComponent <ShieldController>();

                if (_pickable != null)
                {
                    bool _takePickable = true;
                    foundPickable = _pickable.transform;
                    if (stateMachine != AIState.Threatened && aiPlayerManager.abilities.Count < 2)
                    {
                        if (team == Team.Virus)
                        {
                            if (_pickable.pickableType == PickableType.Magnesium)
                            {
                                _takePickable = false;
                            }
                        }
                        else if (team == Team.White)
                        {
                            if (_pickable.pickableType == PickableType.Vitamin || _pickable.pickableType == PickableType.Proteine)
                            {
                                _takePickable = false;
                            }
                        }

                        if (_takePickable)
                        {
                            stateMachine = AIState.Curious;
                        }
                    }
                }
                if (_player != null)
                {
                    if (this.team != _player.team && this.team == Team.Virus)
                    {
                        fleeVector  += this.transform.position - _player.transform.position;
                        stateMachine = AIState.Threatened;

                        if (Vector2.Distance(this.transform.position, _player.transform.position) <= minAttackDistance)
                        {
                            try
                            {
                                Pickable _ability0 = aiPlayerManager.abilities[0];
                                Pickable _ability1 = aiPlayerManager.abilities[1];
                                aiPlayerManager.UseAbbility(_ability0);
                                aiPlayerManager.UseAbbility(_ability1);
                            }catch {}
                        }
                    }
                    else if (this.team != _player.team && this.team == Team.White)
                    {
                        enemyPosition = _player.transform;
                        stateMachine  = AIState.Chasing;
                    }
                }
                if (_shield != null)
                {
                    closeShieldPosition = _shield.transform;
                    if (this.team == Team.White && (target == closeShieldPosition))
                    {
                        FindRedShieldTarget();
                        //Debug.Log("too close to shield changing target !");
                    }
                    else if (this.team == Team.Virus && stateMachine == AIState.Threatened)
                    {
                        if (stateMachine == AIState.Threatened)
                        {
                            stateMachine = AIState.SeekingRefuge;
                            refugeShield = closeShieldPosition;
                            //Debug.Log("Virus is seeking refuge");
                        }
                        else
                        {
                            stateMachine = AIState.OnDuty;
                        }
                    }
                }

                radar.detectedEntities[_index] = null;
                _index++;
            }

            fleeTarget.position = this.transform.position + fleeVector.normalized * fleeDistance;
        }