public void Enter()
 {
     //Stops the AI from firing and sends them to their default positon
     _agent.GetComponent <AIWeapons>().SetTarget(null);
     _agent.GetComponent <AIWeapons>().SetFiring(false);
     _agent.GetComponent <NavMeshAgent>().SetDestination(_defaultPosition);
 }
Example #2
0
 public AIMeleeState(AIAgent agent)
 {
     _agent          = agent;
     _animController = _agent.GetComponent <Animator>();
     _navAgent       = _agent.GetComponent <NavMeshAgent>();
     _stabCheck      = _agent.GetComponent <WeaponStabCheck>();
 }
 public void Initialize(AIAgent agent)
 {
     _aiWeapon          = agent.GetComponent <AIWeapons>();
     _navAgent          = agent.GetComponent <NavMeshAgent>();
     _aiHealth          = agent.GetComponent <AIHealth>();
     _fov               = agent.GetComponent <FieldOfView>();
     _lastKnownLocation = GameObject.FindObjectOfType <LastKnownLocation>();
     _agent             = agent;
 }
Example #4
0
    // Update is called once per frame
    void Update()
    {
        //Player Movement control
        if (Input.GetKey(KeyCode.W))
        {
            rb.transform.Translate(Vector3.forward * Time.deltaTime * speed);
        }

        if (Input.GetKey(KeyCode.S))
        {
            rb.transform.Translate(Vector3.back * Time.deltaTime * speed);
        }

        if (Input.GetKey(KeyCode.A))
        {
            rb.transform.Translate(Vector3.left * Time.deltaTime * speed);
        }

        if (Input.GetKey(KeyCode.D))
        {
            rb.transform.Translate(Vector3.right * Time.deltaTime * speed);
        }

        if (Input.GetKeyDown(KeyCode.Space) && ultimate_spell > 0)
        {
            //Find closest enemy
            GameObject[] enemies        = GameObject.FindGameObjectsWithTag("Enemy");
            float        enemy_distance = Vector3.Distance(transform.position, enemies[0].GetComponent <Enemy>().transform.position);
            float        ai_distance    = Vector3.Distance(transform.position, ai.transform.position);
            int          closest_enemy  = 0;
            for (int i = 0; i < enemies.Length; i++)
            {
                float distance = Vector3.Distance(transform.position, enemies[i].GetComponent <Enemy>().transform.position);
                if (distance <= enemy_distance)
                {
                    enemy_distance = distance;
                    closest_enemy  = i;
                }
            }
            if (ai_distance > enemy_distance)
            {
                //despawn and respawn this enemy
                Instantiate(enemy, new Vector3(0f, 0f, enemies[closest_enemy].transform.position.z), new Quaternion(0, 0, 0, 0));
                Destroy(enemies[closest_enemy]);
            }
            else
            {
                //teleport AI to a random alcove
                int ai_location = new System.Random(System.Guid.NewGuid().GetHashCode()).Next(0, 10);
                ai.GetComponent <CapsuleCollider>().enabled = false;
                ai.transform.position = new Vector3(alcoves[ai_location].x, alcoves[ai_location].y, alcoves[ai_location].z > 0 ? 8f : -8f);
                ai.GetComponent <CapsuleCollider>().enabled = true;
            }
            ultimate_spell--;
        }
    }
Example #5
0
    public void Initialize(AIAgent agent)
    {
        _navAgent     = agent.GetComponent <NavMeshAgent>();
        _aiHealth     = agent.GetComponent <AIHealth>();
        _aiWeapon     = agent.GetComponent <AIWeapons>();
        _coversInZone = agent.GetComponentInParent <CombatZone>().CoversInZone.ToArray();

        _anim  = agent.GetComponent <Animator>();
        _agent = agent;
    }
    public PatrolState(AIAgent agent, PatrolRoute route, float movementSpeed, float waitDuration)
    {
        _agent           = agent;
        _route           = route;
        _navAgent        = _agent.GetComponent <NavMeshAgent>();
        _fov             = _agent.GetComponent <FieldOfView>();
        _soundPerception = _agent.GetComponentInChildren <SoundPerception>();

        _waitDuration   = waitDuration;
        _navAgent.speed = movementSpeed;
    }
Example #7
0
    public AISearchForPlayerState(AIAgent agent)
    {
        _agent = agent;
        _playersKnownLocation = GameObject.FindObjectOfType <LastKnownLocation>();

        if (_playersKnownLocation == null)
        {
            Debug.LogError("Last Player Location prefab not placed in scene.");
        }

        _navAgent = agent.GetComponent <NavMeshAgent>();

        _fov = agent.GetComponent <FieldOfView>();
    }
    public void Update()
    {
        //See if we have arrived at the point
        if (!_arrivedAtPoint && _navAgent.remainingDistance < 1.5f)
        {
            _arrivedAtPoint = true;
        }

        //Look at the last known location
        _agent.LookAtLastKnownLocation();

        //Gets the agents in the nearby area
        List <AIAgent> agents = _lastKnownLocation.GetEnemiesInRange(7.5f);

        if (_arrivedAtPoint)
        {
            //if there is no selected AI to investigate
            if (_selectedAI == null)
            {
                _investigateTimer += Time.deltaTime;

                //Timer check, basically waits for more "allies" to show up before choosing someone to go see the player
                if (_investigateTimer > _investigateDuration)
                {
                    _selectedAI = _agent;
                }

                //if there are enough allies in the area, then forget the timer and go straight in
                if (agents.Count > 3)
                {
                    if (_selectedAI == null)
                    {
                        _selectedAI = agents[(int)Random.Range(0, agents.Count)];
                    }
                }
            }
            else
            {
                //if this ai is the selected ai
                if (_selectedAI == _agent)
                {
                    //Set the destination
                    _navAgent.SetDestination(_lastKnownLocation.transform.position);

                    //When we are close enough set searched to true and change to the search state
                    if (_navAgent.remainingDistance < 2.0f)
                    {
                        _selectedAI = null;
                        agents.ForEach(ally => ally.stateMachine.ChangeState(AiStateId.SearchForPlayer));
                    }
                }
            }
        }

        //Sees if the player is in the agents FOV, if so then switch all allies to combat state
        if (_agent.GetComponent <FieldOfView>().IsEnemyInFOV)
        {
            agents.ForEach(ally => ally.Aggrevate());
        }
    }
 public AIIdleState(AIAgent agent)
 {
     _agent           = agent;
     _FOV             = agent.GetComponent <FieldOfView>();
     _soundPerception = agent.GetComponentInChildren <SoundPerception>();
     _defaultPosition = agent.transform.position;
 }
Example #10
0
    private void PlaceAIAgent()
    {
        Rigidbody rigidbody = aiAgent.GetComponent <Rigidbody>();

        rigidbody.velocity         = Vector3.zero;
        rigidbody.angularVelocity  = Vector3.zero;
        aiAgent.transform.position = new Vector3(13f, 0.5f, 8f);
        aiAgent.transform.rotation = Quaternion.Euler(0f, 180f, 0f);
    }
    public void Enter()
    {
        //Debug.Log("Entered Combat State");

        //Decide the best course of action upon entering this state
        EvaluateSnippets();

        _agent.GetComponent <NavMeshAgent>().isStopped = false;
    }
Example #12
0
    //Used for telling the player when they are in range for assassination attack
    void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            if (_owner.GetComponent <Health>().IsDead)
            {
                return;
            }

            //Debug.Log("Player in range");
            _player.GetComponent <PlayerController>().AgentInRange = _owner;
        }
    }
Example #13
0
    public AIContext(AIAgent agent, AISenses senses, Transform head, Animator animator, NavMeshAgent navAgent)
    {
        Agent              = agent;
        Senses             = senses;
        Head               = head;
        Animator           = animator;
        NavAgent           = navAgent;
        NavAgent.isStopped = true;
        Mobile             = agent.GetComponent <Mobile>();
        Mobile.Init(this);
        CanSense = true;

        base.Init();
    }
Example #14
0
    internal void FindComponents(AIAgent agent)
    {
        if (agentFields == null)
        {
            agentFields = GetType().GetFields().Where(IsValidField).ToArray();
        }

        foreach (var field in agentFields)
        {
            if (field.GetValue(this) == default)
            {
                field.SetValue(this, agent.GetComponent(field.FieldType));
            }
        }
    }
Example #15
0
    public void UseCard()
    {
        switch (turn)
        {
        case WhoTurn.Player:
            player.GetComponent <CardSelection>().UseCard();
            break;

        case WhoTurn.AI:
            ai.GetComponent <CardSelection>().UseCard();
            break;

        default:
            break;
        }
        ChangeTurn();
    }
        private void InteractWithAssassination()
        {
            if (Input.GetKeyDown(KeyCode.F))
            {
                //If we are standing then return
                if (_isStanding)
                {
                    return;
                }

                //if there is an agent in range and we have not been detected
                if (_agentInRange != null && !_detected)
                {
                    //if the agent is dead then return
                    if (_agentInRange.Health.IsDead)
                    {
                        return;
                    }

                    //Calculate the offset
                    Vector3 offSetPos = _agentInRange.transform.position - _agentInRange.transform.forward * 1.0f;
                    //Set our position to that offset
                    transform.position = offSetPos;
                    //Call the assassinate animation
                    _animator.SetTrigger("stealthAssassinate");
                    //Set the agent to being killed
                    _agentInRange.BeingKilled = true;
                    //Set us in the kill animation, stops us from moving
                    _inKillAnimation = true;
                    //Set the animation for the AI
                    _agentInRange.GetComponent <Animator>().SetTrigger("stealthAssassinate");
                    //Clears the agent
                    _agentInRange = null;
                    //Stops the UI from displaying the prompt
                    gameObject.SendMessage("DisplayAssassinationPrompt", false);
                }
            }
        }
Example #17
0
 public void Initialize(AIAgent agent)
 {
     _aiWeapon = agent.GetComponent <AIWeapons>();
     _agent    = agent;
 }
 public AICheckPlayerState(AIAgent agent)
 {
     _agent    = agent;
     _navAgent = agent.GetComponent <NavMeshAgent>();
 }
Example #19
0
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag("Enemy"))
        {
            // When colliding with an enemy we want the player to knock them back unless they're moving slower.

            //  first check who's going faster
            AIAgent AI = collision.gameObject.GetComponent <AIAgent>();

            if (velocity.magnitude > AI.Velocity.magnitude)
            {
                // player going faster means we knock the AI back instead of us
                AI.AddStun();

                // calculate force vector
                var force = collision.transform.position - transform.position;

                // normalize force vector to get direction only and trim magnitude
                force.Normalize();
                AI.GetComponent <Rigidbody>().AddForce(force * shipKnockBack);
            }
            else
            {
                // Stun stops the player controller from moving forward and allows us to add forces to the player
                controller.AddStun(stunDuration);

                // calculate force vector
                var force = transform.position - collision.transform.position;

                // normalize force vector to get direction only and trim magnitude
                force.Normalize();
                gameObject.GetComponent <Rigidbody>().AddForce(force * shipKnockBack);
            }
        }

        if (collision.contacts[0].thisCollider.CompareTag("Ram"))
        {
            float hitDamage = collision.relativeVelocity.magnitude;

            // Debug.Log("Hit with Ram with a force of " + hitDamage);

            if (collision.collider.gameObject.GetComponent <AttachmentBase>())
            {
                collision.collider.gameObject.GetComponent <AttachmentBase>().TakeDamage(ramDamage);
            }

            if (collision.collider.gameObject.GetComponent <AIAgent>())
            {
                collision.collider.gameObject.GetComponent <AIAgent>().TakeDamage(ramDamage);
            }
        }

        if (collision.gameObject.layer == 8)
        {
            // Stun stops the player controller from moving forward and allows us to add forces to the player
            controller.AddStun(islandStunDuration);

            // calculate force vector
            var force = transform.position - collision.transform.position;
            // normalize force vector to get direction only and trim magnitude
            force.Normalize();
            gameObject.GetComponent <Rigidbody>().AddForce(force * islandKnockBack);
        }
    }
Example #20
0
 protected override void AgentEndInteraction(AIAgent agent, int agentIndex)
 {
     agent.IsInteracting = false;
     OnAiInteract.Invoke();
     agent.GetComponent <HitAnimation>().PlayHitAnimation(gameObject);
 }
 public AIDeathState(AIAgent agent)
 {
     _ragdoll  = agent.GetComponent <Ragdoll>();
     _aiWeapon = agent.GetComponent <AIWeapons>();
     _navAgent = agent.GetComponent <NavMeshAgent>();
 }