// Critic Tells the learning element how well the agent is doing with respect to a fixed performance measure private void Critic() { EMState currentStateEnum = m_EMFSM.CurrentStateIndex; int nCurrentEnemyChild = m_EMFSM.AvailableChildNum; int nCurrentPlayerChild = PlayerChildFSM.GetActiveChildCount(); int nCurrentSquadChild = 0; bool bSquadCaptainIsAlive = false; if (PlayerSquadFSM.Instance != null) { nCurrentSquadChild = PlayerSquadFSM.Instance.AliveChildCount(); bSquadCaptainIsAlive = PlayerSquadFSM.Instance.IsAlive; } int nCurrentEnemyHealth = m_EMFSM.Health; int nCurrentPlayerHealth = 0; if (PlayerMain.Instance != null) { nCurrentPlayerHealth = PlayerMain.Instance.Health; } // Pause calling the function for checking and wait for the result fCheckFreq = Random.Range(0.25f, .5f); StartCoroutine(PauseCheck(fCheckFreq, currentStateEnum, nCurrentEnemyChild, nCurrentPlayerChild, nCurrentSquadChild, bSquadCaptainIsAlive, nCurrentEnemyHealth, nCurrentPlayerHealth)); }
public void ActionSpawn(int _nodeIndex) { Node _selectedNode = (Node)_nodeIndex; if (activeNode != Node.None && !m_bIsHoldingDownSpawnBtn) { return; } if (PlayerChildFSM.GetActiveChildCount() >= Constants.s_nPlayerMaxChildCount) { infoText.text = "Reached\nMaximum\nChild Cell\nCount"; PresentInfoPanel(); Node_Manager.GetNode(_selectedNode).CalculateChildCount(); // Force calcualtion check. return; } if (s_nResources >= Settings.s_nPlayerChildSpawnCost) { // Call a child cell from object pool and set its m_assignedNode to assigned node. PlayerChildFSM currentChild = PlayerChildFSM.Spawn(PlayerMain.Instance.transform.position + (Vector3)Random.insideUnitCircle * 0.25f); currentChild.m_assignedNode = Node_Manager.GetNode(_selectedNode); currentChild.m_bIsDefending = Node_Manager.GetNode(_selectedNode).m_bIsDefending; currentChild.m_assignedNode.AddChildToNode(currentChild.poolIndex); s_nResources -= Settings.s_nPlayerChildSpawnCost; UpdateUI_nutrients(); UpdateUI_nodeChildCountText(); // Animations PlayerMain.Instance.animate.ExpandContract(0.5f, 1, 1.2f, true, 0.2f); switch (_selectedNode) { case Node.LeftNode: leftNodeChildText.transform.localPosition = new Vector3(leftNodeChildText.transform.localPosition.x, childCountTextOriginY + childCountTextPopOffsetY); m_LeftNodeChildTextAnimate.ExpandContract(1.1f, 1, 4.0f, true, 0.4f); break; case Node.RightNode: rightNodeChildText.transform.localPosition = new Vector3(rightNodeChildText.transform.localPosition.x, childCountTextOriginY + childCountTextPopOffsetY); m_RightNodeChildTextAnimate.ExpandContract(1.1f, 1, 4.0f, true, 0.4f); break; } // Update tutorial state if (Tutorial.Instance() != null && Tutorial.Instance().tutorialState == TutorialState.PlayerNodeTapWaiting) { Tutorial.Instance().tutorialState = TutorialState.PlayerNodeTapCompleted; } AudioManager.PlayPMSoundEffect(PlayerMainSFX.SpawnCell); } else { infoText.text = "Not enough\nnutrients\n\nNeeded:\n" + Settings.s_nPlayerChildSpawnCost + " units"; PresentInfoPanel(); } }
public override void Enter() { transition = m_EMFSM.emTransition; controller = m_EMFSM.emController; helper = m_EMFSM.emHelper; // Turn blink animation on EMAnimation.Instance().CanBlink = true; // Reset availability to command mini cell to Defend state if (!helper.CanAddDefend) { helper.CanAddDefend = true; } // Set status to defending controller.bIsDefend = true; // Reset transition availability transition.CanTransit = true; // Pause the transition for randomized time float fPauseTime = Random.Range(Mathf.Sqrt(Mathf.Sqrt((float)PlayerChildFSM.GetActiveChildCount() + 4f)) * 2f, Mathf.Sqrt((float)PlayerChildFSM.GetActiveChildCount() + 4f) * 2f); helper.StartPauseTransition(fPauseTime); }
public override void Execute() { transition = m_EMFSM.emTransition; controller = m_EMFSM.emController; helper = m_EMFSM.emHelper; #region Command child cells to transit to Defend state only when there are more player mini cells than enemy mini cells if (m_EMFSM.AvailableChildNum < PlayerChildFSM.GetActiveChildCount() && helper.CanAddDefend) { float nEnemyChildFactor = (float)m_EMFSM.AvailableChildNum / 10f + 1f; float nPlayerChildFactor = (float)PlayerChildFSM.GetActiveChildCount() / 10f + 1f; // If there are more than 10 and less than 25 available enemy mini cells if (m_EMFSM.AvailableChildNum > 10 && m_EMFSM.AvailableChildNum <= 25 && helper.CanAddDefend) { for (int nAmount = 0; nAmount < Random.Range(5, 11); nAmount++) { int nIndex = Random.Range(0, m_EMFSM.ECList.Count); if (m_EMFSM.ECList[nIndex].CurrentStateEnum == ECState.Idle || m_EMFSM.ECList[nIndex].CurrentStateEnum == ECState.Avoid) { MessageDispatcher.Instance.DispatchMessage(m_EMFSM.EnemyMainObject, m_EMFSM.ECList[nIndex].gameObject, MessageType.Defend, 0.0); helper.CanAddDefend = false; } } if (helper.CanAddDefend) { EMHelper.Instance().StartPauseAddDefend(0.25f); } } else if (m_EMFSM.AvailableChildNum > 25 && m_EMFSM.AvailableChildNum <= 50 && helper.CanAddDefend) { for (int nAmount = 0; nAmount < Random.Range(3, 9); nAmount++) { int nIndex = Random.Range(0, m_EMFSM.ECList.Count); if (m_EMFSM.ECList[nIndex].CurrentStateEnum == ECState.Idle || m_EMFSM.ECList[nIndex].CurrentStateEnum == ECState.Avoid) { MessageDispatcher.Instance.DispatchMessage(m_EMFSM.EnemyMainObject, m_EMFSM.ECList[nIndex].gameObject, MessageType.Defend, 0.0); helper.CanAddDefend = false; } } } // Pause commanding enemy mini cells to defend state helper.StartPauseTransition(2f); } #endregion //Start checking transition only when transition is allowed if (transition.CanTransit) { // Transit to other states only when there are more player mini cells than enemy mini cells if (m_EMFSM.AvailableChildNum >= PlayerChildFSM.GetActiveChildCount()) { m_EMFSM.ChangeState(EMState.Production); } // If not transit to Production state, then transit to Maintain state m_EMFSM.ChangeState(EMState.Maintain); } // Check transition every 0.2 second to save computing power if (transition.CanTransit) { helper.StartPauseTransition(.2f); } }
public override void Execute() { transition = m_EMFSM.emTransition; controller = m_EMFSM.emController; helper = m_EMFSM.emHelper; // Start checking transition only when there are more than 10 available enemy mini cells and transition is allowed if (m_EMFSM.AvailableChildNum > 10 && transition.CanTransit) { // If there are more than 10 and less than 25 available enemy mini cells if (m_EMFSM.AvailableChildNum > 0 && m_EMFSM.AvailableChildNum <= 15) { float nEnemyChildFactor = (float)m_EMFSM.AvailableChildNum / 10f + 1f; float nPlayerChildFactor = (float)PlayerChildFSM.GetActiveChildCount() / 10f + 1f; // Transition to Defend if (EMHelper.Instance().MinToMaxYRatio > 0.5f) { transition.Transition(1000f / (nPlayerChildFactor * 10f + EMLeraningAgent.Instance().RealScore(EMState.Defend)) * (1f + EMHelper.Instance().MinToMaxYRatio), EMState.Defend); } // Transition to EMAggressiveAttack if (nEnemyChildFactor > nPlayerChildFactor * 1.5f) { transition.Transition(1000f / (helper.Pow(nEnemyChildFactor * 1f / nPlayerChildFactor, 2f) * 3f + m_EMFSM.CurrentAggressiveness * 3.5f + EMLeraningAgent.Instance().RealScore(EMState.AggressiveAttack)), EMState.AggressiveAttack); } // Transition to EMCautiousAttack if (nEnemyChildFactor > nPlayerChildFactor) { transition.Transition(1000f / (helper.Pow(nEnemyChildFactor * 1.5f / nPlayerChildFactor, 2f) * 5f + m_EMFSM.CurrentAggressiveness * 2f + EMLeraningAgent.Instance().RealScore(EMState.CautiousAttack)), EMState.CautiousAttack); } // Transition to Landmine if (nPlayerChildFactor > 1.5f) { EMTransition.Instance().Transition(1000f / ((helper.Pow(nPlayerChildFactor, 2f) / helper.Sqrt(nPlayerChildFactor) * 1f) + m_EMFSM.CurrentAggressiveness * 2f + EMLeraningAgent.Instance().RealScore(EMState.Landmine)), EMState.Landmine); } // Transition to Production if (controller.NutrientNum > 0) { transition.Transition(1000f / (helper.Pow(Mathf.Sqrt(controller.NutrientNum), 2f) + EMLeraningAgent.Instance().RealScore(EMState.Production)), EMState.Production); } } else if (m_EMFSM.AvailableChildNum > 15 && m_EMFSM.AvailableChildNum <= 30) { float nEnemyChildFactor = (float)m_EMFSM.AvailableChildNum / 10f + 1f; float nPlayerChildFactor = (float)PlayerChildFSM.GetActiveChildCount() / 10f + 1f; // Transition to Defend if (EMHelper.Instance().MinToMaxYRatio > 0.5f) { transition.Transition(1000f / (nPlayerChildFactor * 10f + EMLeraningAgent.Instance().RealScore(EMState.Defend)) * (1f + EMHelper.Instance().MinToMaxYRatio), EMState.Defend); } // Transition to EMAggressiveAttack if (nEnemyChildFactor > nPlayerChildFactor * 1.5f) { transition.Transition(1000f / ((helper.Pow(nEnemyChildFactor * 1.5f / nPlayerChildFactor, 2f) * 3f + m_EMFSM.CurrentAggressiveness * 3.75f) + EMLeraningAgent.Instance().RealScore(EMState.AggressiveAttack)), EMState.AggressiveAttack); } // Transition to EMCautiousAttack if (nEnemyChildFactor > nPlayerChildFactor) { transition.Transition(1000f / ((helper.Pow(nEnemyChildFactor * 2f / nPlayerChildFactor, 2f) * 5f + m_EMFSM.CurrentAggressiveness * 2.25f) + EMLeraningAgent.Instance().RealScore(EMState.CautiousAttack)), EMState.CautiousAttack); } // Transition to Landmine if (nPlayerChildFactor > 1f) { EMTransition.Instance().Transition(1000f / ((helper.Pow(nPlayerChildFactor, 2f) / helper.Sqrt(nPlayerChildFactor) * 1f) + m_EMFSM.CurrentAggressiveness * 2f + EMLeraningAgent.Instance().RealScore(EMState.Landmine)), EMState.Landmine); } // Transition to Production if (controller.NutrientNum > 0) { transition.Transition(1000f / (helper.Pow(Mathf.Sqrt(controller.NutrientNum), 2f) + EMLeraningAgent.Instance().RealScore(EMState.Production)), EMState.Production); } } else if (m_EMFSM.AvailableChildNum > 30) { float nEnemyChildFactor = (float)m_EMFSM.AvailableChildNum / 10f + 1f; float nPlayerChildFactor = (float)PlayerChildFSM.GetActiveChildCount() / 10f + 1f; // Transition to EMAggressiveAttack if (nEnemyChildFactor > nPlayerChildFactor * 1.5f) { transition.Transition(1000f / ((helper.Pow(nEnemyChildFactor * 1.75f / nPlayerChildFactor, 2f) * 5f + m_EMFSM.CurrentAggressiveness * 4f) + EMLeraningAgent.Instance().RealScore(EMState.AggressiveAttack)), EMState.AggressiveAttack); } // Transition to EMCautiousAttack if (nEnemyChildFactor > nPlayerChildFactor) { transition.Transition(1000f / ((helper.Pow(nEnemyChildFactor * 2f / nPlayerChildFactor, 2f) * 7.5f + m_EMFSM.CurrentAggressiveness * 2.5f) + EMLeraningAgent.Instance().RealScore(EMState.CautiousAttack)), EMState.CautiousAttack); } // Transition to Landmine if (nPlayerChildFactor > 1f) { EMTransition.Instance().Transition(1000f / ((helper.Pow(nPlayerChildFactor, 2f) / helper.Sqrt(nPlayerChildFactor) * 1f) + m_EMFSM.CurrentAggressiveness * 2f + EMLeraningAgent.Instance().RealScore(EMState.Landmine)), EMState.Landmine); } // Transition to Production if (controller.NutrientNum > 0) { transition.Transition(1000f / (helper.Pow(Mathf.Sqrt(controller.NutrientNum), 2f) + EMLeraningAgent.Instance().RealScore(EMState.Production)), EMState.Production); } } // Check transition every 0.1 second to save computing power if (transition.CanTransit) { helper.StartPauseTransition(.1f); } } }
public override void Execute() { controller = m_EMFSM.emController; helper = m_EMFSM.emHelper; // Produce enemy mini cell if has nutrient and can spawn if (controller.NutrientNum > 0 && helper.CanSpawn && Level_Manager.LevelID < 4) { helper.ECPool.SpawnFromPool(EMHelper.Instance().Position, false); } else if (controller.NutrientNum > 0 && helper.CanSpawn && Level_Manager.LevelID > 3) { for (int i = 0; i < 2; i++) { helper.ECPool.SpawnFromPool(EMHelper.Instance().Position, false); } } else if (controller.NutrientNum == 0 && EMTransition.Instance().CanTransit) { m_EMFSM.ChangeState(EMState.Maintain); } // Start checking transition only when there are more than 10 available enemy mini cells, transition is allowed and has nutrient if (m_EMFSM.AvailableChildNum > 10 && EMTransition.Instance().CanTransit&& controller.NutrientNum > 0) { // If there are more than 10 and less than 25 available enemy mini cells if (m_EMFSM.AvailableChildNum > 0 && m_EMFSM.AvailableChildNum <= 15) { float nEnemyChildFactor = (float)m_EMFSM.AvailableChildNum / 10f + 1f; float nPlayerChildFactor = (float)PlayerChildFSM.GetActiveChildCount() / 10f + 1f; // Transition to Defend if (EMHelper.Instance().MinToMaxYRatio > 0.5f) { EMTransition.Instance().Transition(1000f / (nPlayerChildFactor * 10f + EMLeraningAgent.Instance().RealScore(EMState.Defend)) * (1f + EMHelper.Instance().MinToMaxYRatio), EMState.Defend); } // Transition to EMAggressiveAttack if (nEnemyChildFactor > nPlayerChildFactor * 1.5f) { EMTransition.Instance().Transition(1000f / ((helper.Pow(nEnemyChildFactor * 1f / nPlayerChildFactor, 2f) * 3f) + m_EMFSM.CurrentAggressiveness * 3.5f + EMLeraningAgent.Instance().RealScore(EMState.AggressiveAttack)), EMState.AggressiveAttack); } // Transition to EMCautiousAttack if (nEnemyChildFactor > nPlayerChildFactor) { EMTransition.Instance().Transition(1000f / (helper.Pow(nEnemyChildFactor * 1.5f / nPlayerChildFactor, 2f) * 5f + m_EMFSM.CurrentAggressiveness * 2f + EMLeraningAgent.Instance().RealScore(EMState.CautiousAttack)), EMState.CautiousAttack); } // Transition to Landmine if (nPlayerChildFactor > 1.5f) { EMTransition.Instance().Transition(1000f / ((helper.Pow(nPlayerChildFactor, 2f) / helper.Sqrt(nPlayerChildFactor) * 1f) + m_EMFSM.CurrentAggressiveness * 2f + EMLeraningAgent.Instance().RealScore(EMState.Landmine)), EMState.Landmine); } // Transition to Maintain if (nPlayerChildFactor <= 5f && helper.Abs((nEnemyChildFactor - nPlayerChildFactor)) <= 1f) { EMTransition.Instance().Transition(1000f / (helper.Pow(5f - helper.Pow(nEnemyChildFactor - nPlayerChildFactor, 1.5f), 2f) + EMLeraningAgent.Instance().RealScore(EMState.Maintain)), EMState.Maintain); } } else if (m_EMFSM.AvailableChildNum > 15 && m_EMFSM.AvailableChildNum <= 30) { float nEnemyChildFactor = (float)m_EMFSM.AvailableChildNum / 10f + 1f; float nPlayerChildFactor = (float)PlayerChildFSM.GetActiveChildCount() / 10f + 1f; // Transition to Defend if (EMHelper.Instance().MinToMaxYRatio > 0.5f) { EMTransition.Instance().Transition(1000f / (nPlayerChildFactor * 10f + EMLeraningAgent.Instance().RealScore(EMState.Defend)) * (1f + EMHelper.Instance().MinToMaxYRatio), EMState.Defend); } // Transition to EMAggressiveAttack if (nEnemyChildFactor > nPlayerChildFactor * 1.5f) { EMTransition.Instance().Transition(1000f / ((helper.Pow(nEnemyChildFactor * 1.5f / nPlayerChildFactor, 2f) * 3f + m_EMFSM.CurrentAggressiveness * 3.75f) + EMLeraningAgent.Instance().RealScore(EMState.AggressiveAttack)), EMState.AggressiveAttack); } // Transition to EMCautiousAttack if (nEnemyChildFactor > nPlayerChildFactor) { EMTransition.Instance().Transition(1000f / ((helper.Pow(nEnemyChildFactor * 2f / nPlayerChildFactor, 2f) * 5f + m_EMFSM.CurrentAggressiveness * 2.25f) + EMLeraningAgent.Instance().RealScore(EMState.CautiousAttack)), EMState.CautiousAttack); } // Transition to Landmine if (nPlayerChildFactor > 1f) { EMTransition.Instance().Transition(1000f / ((helper.Pow(nPlayerChildFactor, 2f) / helper.Sqrt(nPlayerChildFactor) * 1f) + m_EMFSM.CurrentAggressiveness * 2f + EMLeraningAgent.Instance().RealScore(EMState.Landmine)), EMState.Landmine); } // Transition to Maintain if (nPlayerChildFactor <= 5f && helper.Abs((nEnemyChildFactor - nPlayerChildFactor)) <= 1f) { EMTransition.Instance().Transition(1000f / (helper.Pow(5f - helper.Pow(nEnemyChildFactor - nPlayerChildFactor, 1.25f), 2f) + EMLeraningAgent.Instance().RealScore(EMState.Maintain)), EMState.Maintain); } } else if (m_EMFSM.AvailableChildNum > 30) { float nEnemyChildFactor = (float)m_EMFSM.AvailableChildNum / 10f + 1f; float nPlayerChildFactor = (float)PlayerChildFSM.GetActiveChildCount() / 10f + 1f; // Transition to EMAggressiveAttack if (nEnemyChildFactor > nPlayerChildFactor * 1.5f) { EMTransition.Instance().Transition(1000f / ((helper.Pow(nEnemyChildFactor * 1.75f / nPlayerChildFactor, 2f) * 5f + m_EMFSM.CurrentAggressiveness * 4f) + EMLeraningAgent.Instance().RealScore(EMState.AggressiveAttack)), EMState.AggressiveAttack); } // Transition to EMCautiousAttack if (nEnemyChildFactor > nPlayerChildFactor) { EMTransition.Instance().Transition(1000f / ((helper.Pow(nEnemyChildFactor * 2f / nPlayerChildFactor, 2f) * 7.5f + m_EMFSM.CurrentAggressiveness * 2.5f) + EMLeraningAgent.Instance().RealScore(EMState.CautiousAttack)), EMState.CautiousAttack); } // Transition to Landmine if (nPlayerChildFactor > 1f) { EMTransition.Instance().Transition(1000f / ((helper.Pow(nPlayerChildFactor, 2f) / helper.Sqrt(nPlayerChildFactor) * 1f) + m_EMFSM.CurrentAggressiveness * 2f + EMLeraningAgent.Instance().RealScore(EMState.Landmine)), EMState.Landmine); } // Transition to Maintain if (nPlayerChildFactor <= 5f && helper.Abs((nEnemyChildFactor - nPlayerChildFactor)) <= 1f) { EMTransition.Instance().Transition(1000f / (helper.Pow(5f - helper.Pow(nEnemyChildFactor - nPlayerChildFactor, 1f), 2f) + EMLeraningAgent.Instance().RealScore(EMState.Maintain)), EMState.Maintain); } } // Check transition every 0.2 to 0.4 second to save computing power // With the value given by learning element increases, the transition check will be less frequent // Thus transition probability will decline if (EMTransition.Instance().CanTransit) { helper.StartPauseTransition(.2f * (1f + EnemyMainFSM.Instance().LearningDictionary[EMState.Production] / 100f)); } } }
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 }
// Color blink animation in AggresiveAttack, CautiousAttack, Landmine and defend states private void ColorBlink() { // Reset elapsed time when blink animation is disabled if (!bCanBlink && fBlinkElapsedTime != 0.0f) { fBlinkElapsedTime = 0.0f; } // Update blink animation if (bCanBlink) { fBlinkElapsedTime += Time.deltaTime; if (EnemyMainFSM.Instance().CurrentStateIndex == EMState.AggressiveAttack) { if (fBlinkElapsedTime >= 0.8f / Mathf.Sqrt(Mathf.Sqrt(EnemyMainFSM.Instance().CurrentAggressiveness))) { if (thisRend.material.color != aggressiveColor) { thisRend.material.color = aggressiveColor; } else { thisRend.material.color = defaultColor; } fBlinkElapsedTime = 0.0f; } } else if (EnemyMainFSM.Instance().CurrentStateIndex == EMState.CautiousAttack) { if (fBlinkElapsedTime >= 1.2f / Mathf.Sqrt(Mathf.Sqrt(EnemyMainFSM.Instance().CurrentAggressiveness))) { if (thisRend.material.color != cautiousColor) { thisRend.material.color = cautiousColor; } else { thisRend.material.color = defaultColor; } fBlinkElapsedTime = 0.0f; } } else if (EnemyMainFSM.Instance().CurrentStateIndex == EMState.Landmine) { if (fBlinkElapsedTime >= 1.2f / Mathf.Sqrt(Mathf.Sqrt(EnemyMainFSM.Instance().CurrentAggressiveness))) { if (thisRend.material.color != landmineColor) { thisRend.material.color = landmineColor; } else { thisRend.material.color = defaultColor; } fBlinkElapsedTime = 0.0f; } } else if (EnemyMainFSM.Instance().CurrentStateIndex == EMState.Defend) { if (fBlinkElapsedTime >= 1.2f / (Mathf.Sqrt(Mathf.Sqrt(PlayerChildFSM.GetActiveChildCount() + PlayerSquadFSM.Instance.AliveChildCount() + 4f) / 2.0f))) { if (thisRend.material.color != defendColor) { thisRend.material.color = defendColor; } else { thisRend.material.color = defaultColor; } fBlinkElapsedTime = 0.0f; } } } // Update color in stun state else if (EnemyMainFSM.Instance().CurrentStateIndex == EMState.Stunned) { if (thisRend.material.color != stunColor) { thisRend.material.color = stunColor; } } else { thisRend.material.color = defaultColor; } }
// Check only once within a given perio of time IEnumerator PauseCheck(float checkFreq, EMState pastState, int pastEnemyChild, int pastPlayerChild, int pastSquadChild, bool squadCaptainWasAlive, int pastEnemyHealth, int pastPlayerHealth) { bCanStartCheck = false; // One check at a time yield return(new WaitForSeconds(checkFreq)); // If we are still in the same state then proceed if (EMLeraningAgent.instance != null && PlayerChildFSM.playerChildPool != null && PlayerSquadFSM.Instance != null) { if (pastState == m_EMFSM.CurrentStateIndex) { LearningElement(pastState, pastEnemyChild, m_EMFSM.AvailableChildNum, pastPlayerChild, PlayerChildFSM.GetActiveChildCount(), pastSquadChild, PlayerSquadFSM.Instance.AliveChildCount(), squadCaptainWasAlive, PlayerSquadFSM.Instance.IsAlive, pastEnemyHealth, pastPlayerHealth); } } bCanStartCheck = true; //Reset the checking availability }
public override void Execute() { transition = m_EMFSM.emTransition; controller = m_EMFSM.emController; helper = m_EMFSM.emHelper; int nCommandNum = 0; #region Landmine Behaviour if (helper.CanAddLandmine) { float nEnemyChildFactor = (float)m_EMFSM.AvailableChildNum / 10f + 1f; float nPlayerChildFactor = (float)PlayerChildFSM.GetActiveChildCount() / 10f + 1f; if (m_EMFSM.AvailableChildNum > 0 && m_EMFSM.AvailableChildNum <= 15) { nCommandNum = Random.Range(1, 2 + (int)nPlayerChildFactor); for (int nAmount = 0; nAmount < nCommandNum; 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.EnemyMainObject, m_EMFSM.ECList[nIndex].gameObject, MessageType.Landmine, 0.0); helper.CanAddLandmine = false; } } } else if (m_EMFSM.AvailableChildNum > 15 && m_EMFSM.AvailableChildNum <= 30) { nCommandNum = Random.Range(2, 3 + (int)nPlayerChildFactor); for (int nAmount = 0; nAmount < nCommandNum; 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.EnemyMainObject, m_EMFSM.ECList[nIndex].gameObject, MessageType.Landmine, 0.0); helper.CanAddLandmine = false; } } } else if (m_EMFSM.AvailableChildNum > 30) { nCommandNum = Random.Range(3, 4 + (int)nPlayerChildFactor); for (int nAmount = 0; nAmount < nCommandNum; 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.EnemyMainObject, m_EMFSM.ECList[nIndex].gameObject, MessageType.Landmine, 0.0); helper.CanAddLandmine = false; } } } // Pause commanding enemy mini cells to Attack state // Pause duration depends only on the number of enemy mini cell commanded //helper.StartPauseAddLandmine ((float)nCommandNum * 2f); } #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 }