Esempio n. 1
0
    public void Init()
    {
        _enemy  = GetComponent <Enemy>();
        _player = FindObjectOfType <Player>();

        _chasing = gameObject.AddComponent <Chasing>();
        if (_enemy._enemyType != EnemyType.Melee)
        {
            IState shoot = gameObject.AddComponent <EnemyShoot>();

            if (_enemy._enemyType != EnemyType.Melee)
            {
                shoot.Init();
            }
            _actionDic.Add(EnemyState.Shoot, shoot);
        }

        IState meleeAttack = gameObject.AddComponent <MeleeAttack>();
        IState idle        = gameObject.AddComponent <Idle>();

        _chasing.Init();
        meleeAttack.Init();
        idle.Init();

        _actionDic.Add(EnemyState.Attack, meleeAttack);
        _actionDic.Add(EnemyState.Idle, idle);
        _actionDic.Add(EnemyState.Chasing, _chasing);

        SetState(EnemyState.Idle);
        StartCoroutine(IEStateCheker());
        //StartCoroutine(ActionType());
    }
Esempio n. 2
0
    /// <summary>
    /// Send enemy at player, called when enemy is caught in light
    /// </summary>
    /// <returns>The coroutine.</returns>
    IEnumerator ATtaC()
    {
        // Deer in headlights, stare at player for a second or so
        if (chasing != Chasing.PLAYER)
        {
            animationController.Idle();
            myRigidbody.constraints = RigidbodyConstraints.FreezeAll;
            agent.velocity          = new Vector3(0, 0, 0);
            agent.destination       = transform.position;
            chasing = Chasing.PLAYER;
        }
        float time = 0f;

        while (time < Random.value + .5f)
        {
            transform.LookAt(FirstPersonController.instance.gameObject.transform);
            time += Time.deltaTime;
            yield return(null);
        }

        // Chase player, track position while light is on
        animationController.Run();
        agent.isStopped         = false;
        myRigidbody.constraints = RigidbodyConstraints.None;
        agent.destination       = FirstPersonController.instance.transform.position;
        chasing = Chasing.PLAYER;
        while (LightOn())
        {
            agent.destination = FirstPersonController.instance.transform.position;
            yield return(null);
        }
    }
 void Start()
 {
     animator      = GetComponent <Animator>();
     audioSource   = GetComponent <AudioSource>();
     chasing       = GetComponent <Chasing>();
     healthManager = GetComponent <HealthManager>();
 }
Esempio n. 4
0
 public void EnemiesStatesInitializer()
 {
     if (patrolling == null && chasing == null && asleep == null)
     {
         patrolling = new Patrolling();
         chasing    = new Chasing();
         asleep     = new Asleep();
         inDialog   = new PlayerInDialog();
     }
 }
Esempio n. 5
0
    void Awake()
    {
        animator      = GetComponent <Animator>();
        healthManager = GetComponent <HealthManager>();
        chasing       = GetComponent <Chasing>();
        audioSource   = GetComponent <AudioSource>();

        syncPos = transform.position;
        syncRot = transform.rotation;
    }
Esempio n. 6
0
 /// <summary>
 /// If enemy reaches a goal, stop chasing and start idling
 /// </summary>
 void StopAtGoal()
 {
     // Through trial and error, 1.1m seems a good threshold for a goal state if multiple agents are crowding around
     if ((!LightOn() && Vector3.Distance(transform.position, agent.destination) < 1.1f))
     {
         agent.isStopped         = true;
         myRigidbody.constraints = RigidbodyConstraints.FreezeAll;
         animationController.Idle();
         chasing = Chasing.NOTHING;
     }
 }
Esempio n. 7
0
    void SpawnEnemy()
    {
        if (spawnTimer < respawnDuration)
        {
            return;
        }

        int playerCount   = GetPlayerCount();
        int spawnCount    = 0;
        int maxSpawnCount = 5 + ((playerCount - 1) * 1);        // 1P: 5, 2P: 6, 3P: 7, 4P: 8
        int zombiesCount  = GameObject.FindGameObjectsWithTag("Enemy").Length;

        foreach (GameObject spawnPoint in spawnPoints)
        {
            // If zombies were spawned too many, just stop.
            if (zombiesCount >= maxZombies)
            {
                break;
            }

            // Check how many zombies are spawning once by player numbers
            else if (spawnCount >= maxSpawnCount)
            {
                break;
            }

            GameObject zombie = PhotonNetwork.Instantiate("Zombie", spawnPoint.transform.position, spawnPoint.transform.rotation, 0);

            float zombieHealth = currentHealth;
            float addtionalHP  = currentHealth * 0.5f;

            zombieHealth = zombieHealth + (addtionalHP * (playerCount - 1));
            zombie.GetComponent <HealthManager>().SetHealth(currentHealth);

            KillReward killReward = zombie.GetComponent <KillReward>();
            killReward.SetReward(currentEXP, currentFund);

            // Boost rotating speed
            float rotateSpeed = 120f + currentMoveSpeed;
            rotateSpeed = Mathf.Max(rotateSpeed, 200f);                 // Max 200f

            Chasing chasing = zombie.GetComponent <Chasing>();
            chasing.SetDamage(currentDamage);
            chasing.SetSpeed(currentMoveSpeed, rotateSpeed);

            spawnCount++;
            zombiesCount++;
        }

        spawnTimer = 0f;
    }
Esempio n. 8
0
 /// <summary>
 /// FPC uses this to alert enemies that they're hit by its raycasts
 /// </summary>
 public void HitByLight()
 {
     if (!LocationManager.instance.PlayerIsSafe())
     {
         StartCoroutine(ATtaC());
     }
     else
     {
         // Stop and stare. One Republic.
         agent.isStopped         = true;
         myRigidbody.constraints = RigidbodyConstraints.FreezeAll;
         animationController.Idle();
         chasing = Chasing.NOTHING;
     }
 }
Esempio n. 9
0
    void Start()
    {
        GameObject  songObject = this.transform.Find("SongObject").gameObject;
        AudioSource player     = songObject.GetComponent <AudioSource> ();

        player.Play();
        player.loop             = true;
        agent                   = GetComponent <NavMeshAgent> ();
        myRigidbody             = GetComponent <Rigidbody> ();
        animationController     = GetComponentInChildren <EnemyAnimationController> ();
        chasing                 = Chasing.NOTHING;
        flickerCoroutineRunning = false;
        m_AudioSource           = GetComponent <AudioSource>();
//		StartCoroutine (DebugCoroutine ());
    }
Esempio n. 10
0
    void SpawnEnemy()
    {
        if (spawnTimer < respawnDuration)
        {
            return;
        }

        int spawnCount    = 0;
        int maxSpawnCount = 5;
        int zombiesCount  = GameObject.FindGameObjectsWithTag("Enemy").Length;

        foreach (GameObject spawnPoint in spawnPoints)
        {
            // If zombies were spawned too many, just stop.
            //თუ ძალიან ბევრი ზომბია გაჩენილი უბრალოდ გაჩერდეს
            if (zombiesCount >= maxZombies)
            {
                break;
            }

            //შემოწმება თუ რამდენი ზომბი ხდება ერთდროულად მოთამაშის მიხედვით
            else if (spawnCount >= maxSpawnCount)
            {
                break;
            }

            GameObject zombie = Instantiate(zombiePrefab, spawnPoint.transform.position, spawnPoint.transform.rotation);

            zombie.GetComponent <HealthManager>().SetHealth(currentHealth);

            KillReward killReward = zombie.GetComponent <KillReward>();
            killReward.SetReward(currentEXP, currentFund);

            // Boost rotating speed
            float rotateSpeed = 120f + currentMoveSpeed;
            rotateSpeed = Mathf.Max(rotateSpeed, 200f);                 // Max 200f

            Chasing chasing = zombie.GetComponent <Chasing>();
            chasing.SetDamage(currentDamage);
            chasing.SetSpeed(currentMoveSpeed, rotateSpeed);

            spawnCount++;
            zombiesCount++;
        }

        spawnTimer = 0f;
    }
    void SpawnEnemy()
    {
        if (spawnTimer < respawnDuration)
        {
            return;
        }

        int spawnCount    = 0;
        int maxSpawnCount = 5;
        int zombiesCount  = GameObject.FindGameObjectsWithTag("Enemy").Length;

        foreach (GameObject spawnPoint in spawnPoints)
        {
            // If zombies were spawned too many, just stop.
            if (zombiesCount >= maxZombies)
            {
                break;
            }

            // Check how many zombies are spawning once by player numbers
            else if (spawnCount >= maxSpawnCount)
            {
                break;
            }

            GameObject zombie = Instantiate(zombiePrefab, spawnPoint.transform.position, spawnPoint.transform.rotation);

            zombie.GetComponent <HealthManager>().SetHealth(currentHealth);

            KillReward killReward = zombie.GetComponent <KillReward>();
            killReward.SetReward(currentEXP, currentFund);

            // Boost rotating speed
            float rotateSpeed = 120f + currentMoveSpeed;
            rotateSpeed = Mathf.Max(rotateSpeed, 200f);                 // Max 200f

            Chasing chasing = zombie.GetComponent <Chasing>();
            chasing.SetDamage(currentDamage);
            chasing.SetSpeed(currentMoveSpeed, rotateSpeed);

            spawnCount++;
            zombiesCount++;
        }

        spawnTimer = 0f;
    }
Esempio n. 12
0
 /// <summary>
 /// If the light is on, chase the light
 /// </summary>
 void ChaseIfLightOn()
 {
     if (LightOn() && chasing != Chasing.PLAYER)
     {
         chasing                 = Chasing.LIGHT;
         agent.isStopped         = false;
         myRigidbody.constraints = RigidbodyConstraints.None;
         animationController.Run();
         Vector3 newGoal = FirstPersonController.instance.GetLightLocation();
         if (newGoal != new Vector3(0, 0, 0))
         {
             NavMeshHit hit;
             NavMesh.SamplePosition(newGoal, out hit, 10, 1);
             agent.destination = hit.position;
         }
     }
 }
Esempio n. 13
0
 void Update()
 {
     velocity = agent.velocity.magnitude;
     if (LocationManager.instance && LocationManager.instance.PlayerIsSafe())
     {
         agent.isStopped         = true;
         myRigidbody.constraints = RigidbodyConstraints.FreezeAll;
         animationController.Idle();
         chasing = Chasing.NOTHING;
         return;
     }
     AdjustSpeed();
     PlayFootsteps();
     ChaseIfLightOn();
     StopAtGoal();
     KeepUpWithPlayer();
     ChaseIfLookingDownAndClose();
 }
Esempio n. 14
0
 public override string ToString()
 {
     return(base.ToString() + " " + Ability.GetType().Name + " -> " + Chasing.GetType().Name);
 }
Esempio n. 15
0
        public void EnemyControllerUpdate(float deltaTime)
        {
            if (alive)
            {
                if (conditions.HasActiveConditions)
                {
                    CheckHealth.Invoke();
                    conditions.ConditionsUpdateStart(CharacterModel, ref spec, deltaTime);
                }

                ///<summary>
                ///Проверка состояния деятельности врага
                /// </summary>
                if (inChase)
                {
                    enemyView.enabled = false;
                    Chasing.Chase(player, deltaTime);
                    //Debug.Log("Chasing");
                }
                else if (comingHome)
                {
                    //Debug.Log("ComingHome");
                    timer += deltaTime;
                    ComingHome.ComingHome();
                    if (timer > 3f && !enemyView.enabled)
                    {
                        enemyView.enabled = true;
                    }
                }
                else if (onPatrol)
                {
                    Patroling.Patrol(route);
                }
                else if (onIdle)
                {
                    Idle.Idle();
                }
                else if (inFight)
                {
                    Fight.Fight(player, deltaTime);
                }
                else
                {
                    var choseAct = Random.Range(-patrolChance, idleChance);
                    if (choseAct < 0)
                    {
                        onPatrol = true;
                        route    = RouteGenerator.Compile(homePoint, spec.PatrolDistance);
                        patrolChance--;
                        idleChance = 5;
                    }
                    else
                    {
                        onIdle = true;
                        idleChance--;
                        patrolChance = 5;
                    }
                }
            }
            else
            {
                Move.Stop();
                headMesh.enabled    = false;
                gun.enabled         = false;
                knife.enabled       = false;
                enemyBorder.enabled = false;                          //выключаем коллайдер
                rb.constraints      = RigidbodyConstraints.FreezeAll; //замораживаем перемещения и повороты
                Dying.Die(mesh, deltaTime);                           //запускаем событие смерти
            }
        }