//decides what the attack the boss will do next private void WhatDoNext() { _currAttackTime = (Time.time - _startAttackTime) / _realTimeBetweenAttacks; //Debug.Log("thinking"); if (_currAttackTime >= 1) { float _nextAttack = Random.Range(0, _totalPercentage); if (_nextAttack > 0 && _nextAttack <= _realFollowPercentage) { //Debug.Log("follow Chosen"); _startAttackTime = Time.time; _myAttack = ColorStrats.FOLLOW; } else if (_nextAttack > _realFollowPercentage && _nextAttack <= (_realFollowPercentage + _realBouncePercentage)) { //Debug.Log("Bounce Chosen"); c0 = transform.position; c2 = _playerRef.transform.position; c1 = ((c0 + c2) / 2) + (Vector3.up * _bounceHeight); _enemyAgent.enabled = false; _startAttackTime = Time.time; _myAttack = ColorStrats.BOUNCE; } } }
//called once the boss is done being stunned and will suck up any remaining glhosts private void WaitingForFood() { if (_myRoom.GetCurrEnemyList.Count == 0) { _myAttack = ColorStrats.DOWNTIME; _startAttackTime = Time.time; } }
//once the boss is done with their attack //will do nothing for an amount of time private void Stunned() { _currAttackTime = (Time.time - _startAttackTime) / _realStunnedDuration; //Debug.Log("stunned"); if (_currAttackTime >= 1) { _myColor = _basicColor; _myMaterial.color = _myColor; _myRenderer.materials[1] = _myMaterial; for (int i = 0; i < _myRoom.GetCurrEnemyList.Count; i++) { _myRoom.GetCurrEnemyList[i].GetComponent <MiniColorMinion>().StartBackToBoss(); } _myAttack = ColorStrats.EATGLHOSTS; } }
//Reset function public override void MyReset() { if (_init) { gameObject.SetActive(true); _myRenderer.enabled = true; _basicColor.a = 1; _myMaterial.color = _basicColor; _myRenderer.materials[1] = _myMaterial; _enemyAgent.enabled = false; //Debug.Log("Boss Reset"); transform.position = _startPos; transform.rotation = _startRot; _colorIntroGlhosts.SetActive(true); for (int i = 0; i < _introGlhostList.Count; i++) { _introGlhostList[i].ResetCutscene(); } _currBossHealth = _actualMaxHealth; _laggedBossHealthBar.fillAmount = 1; _actualBossHealthBar.fillAmount = 1; _bossBar.SetActive(false); _cameraInPosition = false; _glhostsDone = false; _eatingFinished = false; _jumpingFinished = false; _endingPlaying = false; _laggingHealth = false; _updatingHealth = false; _dead = false; _amHit = false; _invincible = false; _myAI = BossAI.NONE; _myAttack = ColorStrats.FOLLOW; _init = false; } }
//Attack //Enemy just follows the player for a certain amount of time private void FollowPlayer() { _enemyAgent.SetDestination(_playerRef.transform.position); _currAttackTime = (Time.time - _startAttackTime) / _realFollowDuration; //Debug.Log("following"); if (_currAttackTime >= 1) { _enemyAgent.SetDestination(transform.position); _myAttack = ColorStrats.DOWNTIME; _startAttackTime = Time.time; } for (int i = 0; i <= _numOfCasts; i++) { float Xpos = Mathf.Cos(_calcAngle * Mathf.Deg2Rad) * _bossCollisionDetectDistance; float Zpos = Mathf.Sin(_calcAngle * Mathf.Deg2Rad) * _bossCollisionDetectDistance; Vector3 RayDir = (transform.forward * Zpos) + (transform.right * Xpos); if (_debug) { Debug.DrawRay(transform.position + (Vector3.up * _vertDetectOffset), RayDir * _bossCollisionDetectDistance, Color.red); } _calcAngle += _detectionAngle / _numOfCasts; if (Physics.Raycast(transform.position + (Vector3.up * _vertDetectOffset), RayDir, out hit, _bossCollisionDetectDistance)) { if (hit.collider.GetComponent <PlayerController>()) { hit.collider.GetComponent <PlayerController>().TakeDamage(_bossDamage); } } } _calcAngle = _startAngle; }
//Attack //Boss will jump into the air and slam down onto the players position //will do it any number of times private void BounceAttack() { _currAttackTime = (Time.time - _startAttackTime) / _realBouncingAirtime; //Debug.Log("spinning"); Vector3 c01, c12, c012; c01 = (1 - _currAttackTime) * c0 + _currAttackTime * c1; c12 = (1 - _currAttackTime) * c1 + _currAttackTime * c2; c012 = (1 - _currAttackTime) * c01 + _currAttackTime * c12; transform.position = c012; if (_currAttackTime >= 1) { //Debug.Log("spinning Done"); if (_currBounces >= _realNumOfBounces) { int _randomColor = Random.Range(0, _ColorsLeft.Count); _myColor = _ColorsLeft[_randomColor]; _myMaterial.color = _myColor; _myRenderer.materials[1] = _myMaterial; SpawnGlhosts(_bounceSpawnAngle, _bounceSpawnAngleOffset); _enemyAgent.enabled = true; _currBounces = 0; _myAttack = ColorStrats.STUNNED; _startAttackTime = Time.time; } else { _calcAngle = _startAngle; _currBounces++; c0 = transform.position; c2 = _playerRef.transform.position; c1 = ((c0 + c2) / 2) + (Vector3.up * _bounceHeight); _startAttackTime = Time.time; } } else { for (int i = 0; i <= _numOfCasts; i++) { float Xpos = Mathf.Cos(_calcAngle * Mathf.Deg2Rad) * _bossCollisionDetectDistance; float Zpos = Mathf.Sin(_calcAngle * Mathf.Deg2Rad) * _bossCollisionDetectDistance; Vector3 RayDir = (transform.forward * Zpos) + (transform.right * Xpos); if (_debug) { Debug.DrawRay(transform.position + (Vector3.up * _vertDetectOffset), RayDir * _bossCollisionDetectDistance, Color.red); } _calcAngle += _detectionAngle / _numOfCasts; if (Physics.Raycast(transform.position + (Vector3.up * _vertDetectOffset), RayDir, out hit, _bossCollisionDetectDistance)) { if (hit.collider.GetComponent <PlayerController>()) { hit.collider.GetComponent <PlayerController>().TakeDamage(_bossDamage); } } } } }
//Attack //Boss will rev up by moving backwards //boss will then charge at the player and stop once it hits something private void ChargePlayer() { if (_tellCharging) { _currAttackTime = (Time.time - _startAttackTime) / _realChargeUpDuration; if (_currAttackTime >= 1) { _currAttackTime = 1; _tellCharging = false; _moveDir = (_playerRef.transform.position - transform.position).normalized; _moveDir.y = 0; _calcAngle = _startAngle; _startAttackTime = Time.time; } transform.LookAt(_playerRef.transform.position); if (!Physics.Raycast(transform.position + (Vector3.up * _vertDetectOffset), -transform.forward, _bossCollisionDetectDistance)) { transform.position -= transform.forward * _realChargeUpBackwardsSpeed * Time.deltaTime; } } else { //Debug.Log("charging"); for (int i = 0; i <= _chargeNumOfCasts; i++) { float Xpos = Mathf.Cos(_calcAngle * Mathf.Deg2Rad) * _bossCollisionDetectDistance; float Zpos = Mathf.Sin(_calcAngle * Mathf.Deg2Rad) * _bossCollisionDetectDistance; Vector3 RayDir = (transform.forward * Zpos) + (transform.right * Xpos); if (_debug) { Debug.DrawRay(transform.position + (Vector3.up * _vertDetectOffset), RayDir * _bossCollisionDetectDistance, Color.red); } _calcAngle += _detectionAngle / _chargeNumOfCasts; if (Physics.Raycast(transform.position + (Vector3.up * _vertDetectOffset), RayDir, out hit, _bossCollisionDetectDistance)) { if (hit.collider.GetComponent <PlayerController>()) { hit.collider.GetComponent <PlayerController>().TakeDamage(_bossDamage); } else if (!hit.collider.GetComponent <PlayerController>()) { int _randomColor = Random.Range(0, _ColorsLeft.Count); _myColor = _ColorsLeft[_randomColor]; _myMaterial.color = _myColor; _myRenderer.materials[1] = _myMaterial; SpawnGlhosts(_chargeSpawnAngle, _chargeSpawnAngleOffset); _enemyAgent.enabled = true; _myAttack = ColorStrats.STUNNED; _startAttackTime = Time.time; return; } } } if (_debug) { Debug.DrawRay(transform.position + (Vector3.up * _vertDetectOffset), _moveDir * _bossCollisionDetectDistance, Color.blue); } _calcAngle = _startAngle; transform.position += _moveDir * _realChargeSpeed * Time.deltaTime; } }