Example #1
0
    private void BombPlayer(DLC_StateController controller)
    {
        Debug.Log("bombing Player");

        controller.navMeshAgent.isStopped = true;

        var bombingScript = FindObjectOfType <RandomBomberScript>();

        if (bombingScript != null)
        {
            bombingScript.targetPlayer = true;
        }

        var shield = FindObjectOfType <ForceField>();

        if (shield == null)
        {
            CreateShield(controller);
        }
        else
        {
            shield.transform.position = controller.eyes.transform.position;
        }

        //with random chance you could spawn enemy!!!
    }
    public override bool Decide(DLC_StateController controller)
    {
        float roll   = Random.Range(0f, 1f);
        float chance = .3f;

        return(roll < chance ? true : false);
    }
Example #3
0
    private void Shoot(DLC_StateController controller)
    {
        var gun = controller.gameObject.GetComponent <EnemyGun>();

        if (gun != null)
        {
            if (controller.chaseTarget != null)
            {
                var lookPos     = controller.chaseTarget.position;
                var charControl = controller.chaseTarget.gameObject.GetComponentInParent <CharacterController>();
                if (charControl != null)
                {
                    var playerDir   = charControl.velocity.normalized;
                    var playerVelo  = charControl.velocity.magnitude;
                    var playerRange = Vector3.Distance(controller.chaseTarget.position, controller.gameObject.transform.position);
                    var shotTime    = playerRange / gun.bulletSpeed;
                    var aimMag      = playerVelo * shotTime;
                    lookPos += playerDir * aimMag;
                }//this is to make the AI lead the player when moving;

                lookPos.y = controller.gameObject.transform.position.y;
                controller.gameObject.transform.LookAt(lookPos);
                gun.gunEnabled = true;
            }
            Debug.Log("Target Does not exsist");
        }
        else
        {
            Debug.Log("can't find gun on enemy that needs to shoot");
        }
    }
Example #4
0
    private void CheckTransition(DLC_StateController controller)
    {
        rolex += Time.deltaTime;
        float periods = 0f;

        if (controller.navMeshAgent.speed == controller.enemyStats.walkSpeed)
        {
            periods = controller.enemyStats.patrolUpdateSpeed;
        }
        else
        {
            periods = controller.enemyStats.chaseUpdateSpeed;
        }
        if (rolex >= periods)
        {
            rolex = 0f;

            for (int i = 0; i < transitions.Length; i++)
            {
                bool decisionSucceeded = transitions[i].decision.Decide(controller);

                if (decisionSucceeded)
                {
                    controller.TransitionToState(transitions[i].trueState);
                }
                else
                {
                    controller.TransitionToState(transitions[i].falseState);
                }
            }
        }
    }
Example #5
0
 private void DoActions(DLC_StateController controller) //Decision to complete the action
 {
     for (int i = 0; i < actions.Length; i++)           //For Loop for actions array
     {
         actions[i].Act(controller);
     }
 }
    public bool GetRange(DLC_StateController controller)
    {
        bool finalDecision = false;

        if (controller.chaseTarget != null)
        {
            var target        = controller.chaseTarget.gameObject;
            var pointDistance = Vector3.Distance(target.transform.position, controller.eyes.position);
            var range         = 10f;

            //if the enemy has an enemy gun use the ideal range on it
            var gun = controller.gameObject.GetComponent <EnemyGun>();
            if (gun != null)
            {
                range = gun.GetIdealRange();
            }                                                 //this gets the varied range so they are not all stopping at the same point

            if (pointDistance < range)
            {
                finalDecision = true; //player is in range
            }
        }
        else
        {
            Debug.Log("can't find target in scene");
        }

        return(finalDecision);
    }
    private Transform RallyTroops(DLC_StateController controller)
    {
        var troops = FindObjectsOfType <DLC_StateController>();

        foreach (DLC_StateController troop in troops)
        {
            var parentTrans = troop.chaseTarget;

            if (parentTrans != null)
            {
                while (parentTrans.parent != null)
                {
                    parentTrans = parentTrans.parent;
                }
                var parentObj = parentTrans.gameObject;

                if (parentObj.tag == "Player" || parentObj.tag == "Taunt")
                {
                    var dis = Vector3.Distance(troop.gameObject.transform.position, controller.eyes.position);
                    if (dis < controller.enemyStats.lookDistance / 2)
                    {
                        return(troop.chaseTarget);
                    }
                }
            }
        }
        return(null);
    }
Example #8
0
    private void CreateShield(DLC_StateController controller)
    {
        Debug.Log("created Shield");
        var shield = Instantiate(controller.enemyStats.ForceField, controller.eyes.transform.position, controller.eyes.transform.rotation);
        var field  = shield.GetComponent <ForceField>();

        field.owner = controller.eyes.gameObject;
    }
    public override bool Decide(DLC_StateController controller)
    {
        bool returnValue = CheckForShield(controller);

        if (returnValue == false)
        {
            TurnOffBombTargeting();
        }
        return(returnValue);
    }
    public override bool Decide(DLC_StateController controller)
    {
        bool chaseTargetIsActive = false;

        if (controller.chaseTarget != null)
        {
            chaseTargetIsActive = controller.chaseTarget.gameObject.activeSelf;
        }
        return(chaseTargetIsActive);
    }
    private void Patrol(DLC_StateController controller)
    {
        controller.navMeshAgent.destination = controller.wayPointList[controller.nextWayPoint].position; //sets to zero
        controller.navMeshAgent.isStopped   = false;                                                     //controller.navMeshAgent.Resume(); is obsolete


        if (controller.navMeshAgent.remainingDistance <= controller.navMeshAgent.stoppingDistance && !controller.navMeshAgent.pathPending) //checking the distance from the next way point //Path Pending is a bool.
        {
            controller.nextWayPoint = (controller.nextWayPoint + 1) % controller.wayPointList.Count;                                       //make sure not to exceed lenth of waypoint list; makes it loop back the waypoint
        }
    }
Example #12
0
    private void Chase(DLC_StateController controller)
    {
        // controller.navMeshAgent.destination = controller.runAway.position;
        controller.navMeshAgent.speed = controller.enemyStats.runSpeed;
        Debug.Log("Run away little girl, Run away");
        controller.navMeshAgent.isStopped = false;

        var pos = controller.navMeshAgent.pathEndPosition;

        pos.y = controller.transform.position.y;
        controller.gameObject.transform.LookAt(pos);
    }
    private void Attack(DLC_StateController controller)
    {
        RaycastHit hit;

        Debug.DrawRay(controller.eyes.position, controller.eyes.forward.normalized * controller.enemyStats.attackRange, Color.red);

        if (Physics.SphereCast(controller.eyes.position, controller.enemyStats.lookSphereCastRadius, controller.eyes.forward, out hit, controller.enemyStats.attackRange) &&
            hit.collider.CompareTag("Player"))
        {
            if (controller.CheckIfCountDownElapsed(controller.enemyStats.attackSpeed))
            {
                //controller.[enter attack script here].Fire(controller.enemyStats.attackforce, controller.enemyStats.attackspeed);
            }
        }
    }
        public void SetupAI(List <Transform> wayPointList)
        {
            e_StateController = e_Instance.GetComponent <DLC_StateController>();
            e_StateController.SetupAI(true, wayPointList);

            //shooting

            //Get all the renders of the enemy.
            MeshRenderer[] renderers = e_Instance.GetComponentsInChildren <MeshRenderer>();

            for (int i = 0; i < renderers.Length; i++)
            {
                //renderers[i].material.color = e_EnemyColor;
            }
        }
    private bool CheckForShield(DLC_StateController controller)
    {
        var shield = FindObjectOfType <ForceField>();

        if (shield != null)
        {
            if (shield.HP > 0)
            {
                return(true);
            }
            else
            {
                Destroy(shield.gameObject);
            }
        }
        return(false);
    }
    private bool CheckPath(DLC_StateController controller)
    {
        var baseHealth = GameObject.FindObjectOfType <BaseHealth>();

        if (baseHealth != null)
        {
            var         baseTrans = baseHealth.gameObject.transform;
            NavMeshPath checkPath = new NavMeshPath();

            //this offsets the goal so that it falls outside the cylinder
            Vector3 direction = controller.transform.position - baseTrans.position;
            direction.y = 0f;
            direction   = direction.normalized;
            direction  *= 4.5f; //this is the radius of the cylinder as set by the code in the cylinder
            direction.y = -1f;  // to move the final results a little closer to the nav mesh so it registers
            var goal = baseTrans.position + direction;

            Debug.DrawLine(controller.transform.position, goal);

            if (controller.navMeshAgent.CalculatePath(goal, checkPath))
            {
                if (checkPath.status == NavMeshPathStatus.PathPartial)
                {
                    //Debug.Log("path not complete");
                    return(false);
                }
                else
                {
                    //Debug.Log("path is complete");
                    return(true);
                }
            }
            else
            {
                //Debug.Log("couldn't find a path there");
                return(false);
            }
        }
        else
        {
            Debug.Log("there doesn't seem to be a base in this level!!");
            return(false);  //obviously can't path to base
        }
    }//homes in on player base if it exists
Example #17
0
    private void Hunt(DLC_StateController controller)
    {
        var player = GameObject.FindObjectOfType <KE_MainPlayer_Script>();

        if (player != null)
        {
            controller.chaseTarget = player.transform;
            controller.navMeshAgent.destination = controller.chaseTarget.position;
            controller.navMeshAgent.speed       = controller.enemyStats.walkSpeed;
            // Debug.Log("I am chasing the player");
            controller.navMeshAgent.isStopped = false;

            var pos = controller.navMeshAgent.pathEndPosition;
            pos.y = controller.transform.position.y;
            controller.gameObject.transform.LookAt(pos);
        }
        else
        {
            Debug.Log("there doesn't seem to be a player in this level!!");
        }
    }//homes in on player base if it exists
Example #18
0
    private void Wander(DLC_StateController controller)
    {
        var distance = PathDistanceLeft(controller.navMeshAgent);

        if (distance < 1f) //(Random.Range(0f, 100f) < .1f)
        {
            float   spread = 30f;
            Vector3 pos    = controller.gameObject.transform.position;
            controller.navMeshAgent.speed = controller.enemyStats.walkSpeed;

            var vecOffset = SetVectorFromAngle(Random.Range(0f, 360f), Random.Range(spread / 2, spread));

            var newX = pos.x + vecOffset.x;
            var newY = pos.y;
            var newZ = pos.z + vecOffset.z;



            controller.navMeshAgent.destination = new Vector3(newX, newY, newZ);
            controller.navMeshAgent.isStopped   = false;
        }
    }
Example #19
0
    public override bool Decide(DLC_StateController controller)
    {
        var finalTrans = controller.eyes.gameObject.transform;

        while (finalTrans.parent != null)
        {
            finalTrans = finalTrans.parent;
        }
        var health = finalTrans.gameObject.GetComponentInChildren <AMS_Health_Management>();

        if (health != null)
        {
            if (!controller.enemyStats.usedShield)
            {
                if (health.currentHealth < health.maxHealth / 2f)
                {
                    Debug.Log("should be activating shield!!!!!!!!!!!!!!!!!!");
                    controller.enemyStats.usedShield = true;
                    return(true);
                }
                else
                {
                    Debug.Log("health not below 50perc");
                    return(false);
                }
            }
            else
            {
                Debug.Log("already used shield");
                return(false);
            }
        }
        else
        {
            Debug.Log("can't find health component!!!!!!!!!!!!!");
            return(false);
        }
    }
Example #20
0
    private void Chase(DLC_StateController controller)
    {
        if (controller.chaseTarget != null)
        {
            controller.navMeshAgent.destination = controller.chaseTarget.position;
            controller.navMeshAgent.speed       = controller.enemyStats.runSpeed;
            // Debug.Log("I am chasing the player");
            controller.isSeen = true;

            var dist = Vector3.Distance(controller.eyes.transform.position, controller.chaseTarget.position);
            if (dist > 1.4)
            {
                controller.navMeshAgent.isStopped = false;
            }
            else
            {
                controller.navMeshAgent.isStopped = true;
            }

            var pos = controller.navMeshAgent.pathEndPosition;
            pos.y = controller.transform.position.y;
            controller.gameObject.transform.LookAt(pos);
        }
    }
 public override void Act(DLC_StateController controller)
 {
 }
Example #22
0
 public abstract void Act(DLC_StateController controller);
Example #23
0
    public override bool Decide(DLC_StateController controller)
    {
        bool targetInRange = GetRange(controller);

        return(targetInRange);
    }
Example #24
0
 public override void Act(DLC_StateController controller)
 {
     controller.navMeshAgent.isStopped = true;
     Shoot(controller);
 }
Example #25
0
    private void Home(DLC_StateController controller)
    {
        var baseHealth = GameObject.FindObjectOfType <BaseHealth>();

        if (controller.enemyStats.tauntWorks)
        {
            var tauntTargets = GameObject.FindObjectsOfType <TauntStatue>();

            if (tauntTargets.Length > 0)
            {
                Transform validTauntTarget = null;
                float     closestDist      = Mathf.Infinity;

                for (var i = 0; i < tauntTargets.Length; i++)
                {
                    var dist = Vector3.Distance(tauntTargets[i].gameObject.transform.position, controller.eyes.position);
                    if (dist < closestDist && dist < tauntTargets[i].effectRange)
                    {
                        validTauntTarget = tauntTargets[i].gameObject.transform;
                    }
                }//go through all taunters and see if any is within range and select the closest

                if (validTauntTarget != null)
                {
                    Vector3 direction = controller.transform.position - validTauntTarget.position;
                    direction.y = 0f;
                    direction   = direction.normalized;
                    direction  *= 1.25f;

                    controller.navMeshAgent.destination = validTauntTarget.position + direction;
                    controller.navMeshAgent.speed       = controller.enemyStats.walkSpeed;
                    //Debug.Log("There is a statue that is mocking me!");
                    controller.navMeshAgent.isStopped = false;

                    var pos = controller.transform.position + controller.navMeshAgent.velocity;
                    controller.gameObject.transform.LookAt(pos);
                    return;
                } //there is a valid taunt target so assign and then kill the rest of the function
            }     //check for valid taunt targets
        }         //only do taunt check if enemy can be effected by taunts

        if (baseHealth != null)
        {
            //this is so the enemy only checks every so often for the base
            //it doesn't move so it shouldn't need pathing every step
            if (Random.Range(0f, 1f) < .1f)
            {
                var baseTrans = baseHealth.gameObject.transform;

                //this offsets the goal so that it falls outside the cylinder
                Vector3 direction = controller.transform.position - baseTrans.position;
                direction.y = 0f;
                direction   = direction.normalized;
                direction  *= 4.5f; //this is the radius of the cylinder as set by the code in the cylinder

                controller.navMeshAgent.destination = baseTrans.position + direction;
                controller.navMeshAgent.speed       = controller.enemyStats.walkSpeed;
                //Debug.Log("I'm homing on the base");
                controller.navMeshAgent.isStopped = false;

                var pos = controller.transform.position + controller.navMeshAgent.velocity;
                pos.y = controller.transform.position.y;
                controller.gameObject.transform.LookAt(pos);
            }
        }//there is a base so target it
        else
        {
            Debug.Log("there doesn't seem to be a base in this level!!");
        }
    }//homes in on taunt target or player base if it exists
Example #26
0
 public override void Act(DLC_StateController controller)
 {
     BombPlayer(controller);
 }
 private void Explode(DLC_StateController controller)
 {
 }
 public override void Act(DLC_StateController controller)
 {
     Explode(controller);
 }
Example #29
0
 public abstract bool Decide(DLC_StateController controller);
Example #30
0
 public override void Act(DLC_StateController controller)
 {
     Wander(controller);
 }