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
	}
예제 #2
0
    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
    }