// Enemy main nutrient getting absorbed and provide nutrient(child cell) to enemy main cell void Absorb() { Vector2 vectorToTarget = EMHelper.Instance().Position - (Vector2)transform.position; transform.position = Vector2.MoveTowards(transform.position, EMHelper.Instance().Position, (vectorToTarget.magnitude * fAbsorbTime + fAbsorbSpeed) * Time.deltaTime); transform.localScale = Vector3.one * (Vector2.Distance((Vector2)transform.position, EMHelper.Instance().Position)) / EMHelper.Instance().Radius * Random.Range(.5f, 1f); if (Vector2.Distance((Vector2)transform.position, EMHelper.Instance().Position) < .1f || transform.localScale.x < .1f) { if (Level_Manager.LevelID < 4) { EMController.Instance().AddFewNutrient((int)(Random.Range(2, 6) * EMDifficulty.Instance().CurrentDiff)); } else { EMController.Instance().AddFewChildCells((int)(Random.Range(2, 6) * EMDifficulty.Instance().CurrentDiff)); } if (!EMAnimation.Instance().IsExpanding) { EMAnimation.Instance().IsExpanding = true; } Destroy(this.gameObject); } }
// Used to handle everything happens when spawns a child cell public IEnumerator ProduceChild() { if (bCanSpawn) { bCanSpawn = false; // Calling the Animate class for spawn animation Animate mAnimate; mAnimate = new Animate(this.transform); mAnimate.ExpandContract(0.1f, 1, 1.1f); if (Level_Manager.LevelID < 4) { EMController.Instance().ReduceNutrient(); } // Randomize the interval time between spawns of child cells in terms of current difficulty float intervalTime = UnityEngine.Random.Range( 1.25f / EMDifficulty.Instance().CurrentDiff, 1.75f / EMDifficulty.Instance().CurrentDiff ); if (Level_Manager.LevelID > 2) { intervalTime /= 1.2f; } yield return(new WaitForSeconds(intervalTime)); if (m_EMFSM.AvailableChildNum < 100) { bCanSpawn = true; } } }
public override void Enter() { transition = m_EMFSM.emTransition; helper = m_EMFSM.emHelper; // Turn blink animation on EMAnimation.Instance().CanBlink = true; // Reset availability to command mini cell to Landmine state if (!helper.CanAddLandmine) { helper.CanAddLandmine = true; } // Enable expand animation if (!EMAnimation.Instance().IsExpanding) { EMAnimation.Instance().IsExpanding = true; } // Reset transition availability transition.CanTransit = true; // Pause the transition for randomized time float fPauseTime = Random.Range((m_EMFSM.CurrentAggressiveness / 1.5f) / EMDifficulty.Instance().CurrentDiff, (m_EMFSM.CurrentAggressiveness) / EMDifficulty.Instance().CurrentDiff); helper.StartPauseTransition(fPauseTime); }
void Update() { // Force back the enemy main cell when received damage and not forced back if (nDamageNum > 0 && bCanPush && !bPushed && !Stunned && bJustAttacked) { StartCoroutine(ForceBack()); } // Stun the enemy main cell after receiving certain amount of hits within certain period of time if ((float)nDamageNum > fCurrentStunTolerance && !bStunned && bCanStun && !bPushed) { StartCoroutine(Stun()); } // Update speed factor if (fSpeedFactor != EMDifficulty.Instance().CurrentDiff&& EMDifficulty.Instance().CurrentDiff != null) { fSpeedFactor = EMDifficulty.Instance().CurrentDiff; } // Keep updating velocity when stunned if (bStunned && thisRB.velocity != velocity) { ResetVelocity(); } // Check the direction of horizontal movement is correct HorizontalCheck(); // Make sure the horizntal velocity is not lower than its minimum value HorizontalVelocityCheck(); // Update Aggresiveness UpdateAggressiveness(); // Check whether the Enemy main is being attacked by the player IsMainBeingAttacked(); // Check whether the Enemy main is having enough of an advantage to tank player's attack to deal more damage onto the player's main ShouldMainBeTanking(); // Check Whether all idling enemy child cells had entered the enemy main cell HasAllCellsEnterMain(); // Check whether the enemy main cell was just attacked DamageTimer(); }
public override void Enter() { transition = m_EMFSM.emTransition; helper = m_EMFSM.emHelper; transition = m_EMFSM.emTransition; // Reset transition availability transition.CanTransit = true; // Pause the transition for randomized time based on num of available child cells float fPauseTime = Random.Range(Mathf.Sqrt(Mathf.Sqrt(EnemyMainFSM.Instance().AvailableChildNum) * 10f) / EMDifficulty.Instance().CurrentDiff, Mathf.Sqrt(Mathf.Sqrt(EnemyMainFSM.Instance().AvailableChildNum) * 50f) / EMDifficulty.Instance().CurrentDiff); helper.StartPauseTransition(fPauseTime); }
public override void Enter() { // Reset transition availability EMTransition.Instance().CanTransit = true; // Reset spawn availability // Pause the transition for randomized time based on num of available nutrient float fPauseTime = Random.Range(Mathf.Sqrt(Mathf.Sqrt(EMController.Instance().NutrientNum + 1f) * 2f) / EMDifficulty.Instance().CurrentDiff, Mathf.Sqrt(Mathf.Sqrt(EMController.Instance().NutrientNum + 1f) * 10f) / EMDifficulty.Instance().CurrentDiff); helper.StartPauseTransition(fPauseTime); }
public override void Execute() { transition = m_EMFSM.emTransition; controller = m_EMFSM.emController; helper = m_EMFSM.emHelper; #region Attack only when there are more enemy mini cells than player's if (m_EMFSM.AvailableChildNum > PlayerChildFSM.GetActiveChildCount() && helper.CanAddAttack) { float nEnemyChildFactor = (float)m_EMFSM.AvailableChildNum / 10f + 1f; float nPlayerChildFactor = (float)PlayerChildFSM.GetActiveChildCount() / 10f + 1f; if (m_EMFSM.AvailableChildNum > 0 && m_EMFSM.AvailableChildNum <= 15) { for (int nAmount = 0; nAmount < Random.Range(1, 2 + (int)Mathf.Sqrt((nEnemyChildFactor))); nAmount++) { int nIndex = Random.Range(0, m_EMFSM.ECList.Count); if (m_EMFSM.ECList[nIndex].CurrentStateEnum == ECState.Idle || m_EMFSM.ECList[nIndex].CurrentStateEnum == ECState.Defend || m_EMFSM.ECList[nIndex].CurrentStateEnum == ECState.Avoid) { MessageDispatcher.Instance.DispatchMessage(m_EMFSM.gameObject, m_EMFSM.ECList[nIndex].gameObject, MessageType.Attack, 0.0); } } } else if (m_EMFSM.AvailableChildNum > 15 && m_EMFSM.AvailableChildNum <= 30) { for (int nAmount = 0; nAmount < Random.Range(2, 3 + (int)Mathf.Sqrt((nEnemyChildFactor))); nAmount++) { int nIndex = Random.Range(0, m_EMFSM.ECList.Count); if (m_EMFSM.ECList[nIndex].CurrentStateEnum == ECState.Idle || m_EMFSM.ECList[nIndex].CurrentStateEnum == ECState.Defend || m_EMFSM.ECList[nIndex].CurrentStateEnum == ECState.Avoid) { MessageDispatcher.Instance.DispatchMessage(m_EMFSM.gameObject, m_EMFSM.ECList[nIndex].gameObject, MessageType.Attack, 0.0); } } } else if (m_EMFSM.AvailableChildNum > 30) { for (int nAmount = 0; nAmount < Random.Range(3, 4 + (int)Mathf.Sqrt((nEnemyChildFactor))); nAmount++) { int nIndex = Random.Range(0, m_EMFSM.ECList.Count); if (m_EMFSM.ECList[nIndex].CurrentStateEnum == ECState.Idle || m_EMFSM.ECList[nIndex].CurrentStateEnum == ECState.Defend || m_EMFSM.ECList[nIndex].CurrentStateEnum == ECState.Avoid) { MessageDispatcher.Instance.DispatchMessage(m_EMFSM.gameObject, m_EMFSM.ECList[nIndex].gameObject, MessageType.Attack, 0.0); } } } // Pause commanding enemy mini cells to Attack state float fPauseTime = 2f / EMDifficulty.Instance().CurrentDiff; if (fPauseTime > 0f) { helper.StartPauseAddAttack(fPauseTime); } } #endregion #region Transition if (transition.CanTransit && controller.NutrientNum > 0) { m_EMFSM.ChangeState(EMState.Production); } else if (transition.CanTransit && controller.NutrientNum == 0) { m_EMFSM.ChangeState(EMState.Maintain); } #endregion }
public override void Enter() { transition = m_EMFSM.emTransition; helper = m_EMFSM.emHelper; // Turn blink animation on EMAnimation.Instance().CanBlink = true; // Reset availability to command mini cell to Attack state if (!helper.CanAddAttack) { helper.CanAddAttack = true; } // Reset transition availability transition.CanTransit = true; // Pause the transition for randomized time float fPauseTime = Random.Range(Mathf.Sqrt(m_EMFSM.CurrentAggressiveness) * 1.5f / EMDifficulty.Instance().CurrentDiff, Mathf.Sqrt(m_EMFSM.CurrentAggressiveness) * 2.5f / EMDifficulty.Instance().CurrentDiff); helper.StartPauseTransition(fPauseTime); }