//A function that evaluate all the nodes of the player and return the most threatening node private GameObject GetMostThreateningThreat() { List <GameObject> Threats = new List <GameObject>(); Threats.Add(Node_Manager.GetNode(Node.LeftNode).gameObject); Threats.Add(Node_Manager.GetNode(Node.RightNode).gameObject); Threats.Add(GameObject.Find("Squad_Captain_Cell")); int nIndexForMostThreating = 0; int nHighestScore = 0; for (int i = 0; i < Threats.Count; i++) { if (Threats[i].name.Contains("Node") && EvaluateNode(Threats[i]) > nHighestScore) { nIndexForMostThreating = i; nHighestScore = EvaluateNode(Threats[i]); } else if (Threats[i].name.Contains("Squad") && Threats[i].GetComponent <PlayerSquadFSM>().AliveChildCount() > nHighestScore) { nIndexForMostThreating = i; nHighestScore = Threats[i].GetComponent <PlayerSquadFSM>().AliveChildCount(); } } return(Threats[nIndexForMostThreating]); }
//constructor public ECTrickAttackState(GameObject _childCell, EnemyChildFSM _ecFSM) { m_Child = _childCell; m_ecFSM = _ecFSM; m_Main = m_ecFSM.m_EMain; m_Nodes = new GameObject[3]; m_ShrinkRate = new Vector3(-0.225f, 0.225f, 0.0f); m_fMaxAcceleration = 40f; m_EMFSM = m_Main.GetComponent <EnemyMainFSM>(); m_Nodes[0] = Node_Manager.GetNode(Node.LeftNode).gameObject; m_Nodes[1] = Node_Manager.GetNode(Node.RightNode).gameObject; m_SquadCaptain = PlayerSquadFSM.Instance.gameObject; BoxCollider2D[] Walls = GameObject.Find("Wall").GetComponents <BoxCollider2D>(); for (int i = 0; i < Walls.Length; i++) { if (Walls[i].offset.y > 39f && Walls[i].offset.x > 7f) { m_RightWall = Walls[i]; } else if (Walls[i].offset.y > 39f && Walls[i].offset.x < -7f) { m_LeftWall = Walls[i]; } } }
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(); } }
private int TotalActiveChildInNodes() { int numChild = 0; numChild += Node_Manager.GetNode(Node.LeftNode).activeChildCount; numChild += Node_Manager.GetNode(Node.RightNode).activeChildCount; return(numChild); }
//Constructor public ECAttackState(GameObject _childCell, EnemyChildFSM _ecFSM) { m_Child = _childCell; m_ecFSM = _ecFSM; m_Main = m_ecFSM.m_EMain; m_SquadCaptain = GameObject.Find("Squad_Captain_Cell"); m_LeftNode = Node_Manager.GetNode(Node.LeftNode); m_RightNode = Node_Manager.GetNode(Node.RightNode); }
public void ActionBurstShot(Node _selectedNode) { Node_Manager selectedNode = Node_Manager.GetNode(_selectedNode); if (selectedNode.activeChildCount < Settings.s_nPlayerActionBurstShotChildCost) { infoText.text = "Not enough\nchild cells\n\nNeeded:\n" + Settings.s_nPlayerActionBurstShotChildCost + " cells"; PresentInfoPanel(); } else { int[] childrenInNode = new int[] { -1 }; switch (_selectedNode) { case Node.LeftNode: childrenInNode = PlayerChildFSM.childrenInLeftNode; break; case Node.RightNode: childrenInNode = PlayerChildFSM.childrenInRightNode; break; } PlayerChildFSM[] formationCells = new PlayerChildFSM[Settings.s_nPlayerActionBurstShotChildCost]; int fcIndex = 0; // Assumes that there will be at least the required amount of cells for (int i = 0; i < childrenInNode.Length; i++) { int poolId = childrenInNode[i]; formationCells[fcIndex] = PlayerChildFSM.playerChildPool[poolId]; formationCells[fcIndex].m_formationCells = formationCells; // arrays are reference types. formationCells[fcIndex].attackMode = PlayerAttackMode.BurstShot; formationCells[fcIndex].m_assignedNode.SendChildToAttack(poolId); formationCells[fcIndex].DeferredChangeState(PCState.ChargeMain); fcIndex++; if (fcIndex == formationCells.Length) { break; } } infoText.text = "BurstShot"; PresentInfoPanel(); } UpdateUI_nodeChildCountText(); }
private bool IsAllThreatEmpty() { List <GameObject> Threats = new List <GameObject>(); Threats.Add(Node_Manager.GetNode(Node.LeftNode).gameObject); Threats.Add(Node_Manager.GetNode(Node.RightNode).gameObject); Threats.Add(GameObject.Find("Squad_Captain_Cell")); for (int i = 0; i < Threats.Count; i++) { if (Threats[i].GetComponent <Node_Manager>() != null && Threats[i].GetComponent <Node_Manager>().activeChildCount > 0) { return(false); } else if (Threats[i].GetComponent <PlayerSquadFSM>() != null && Threats[i].GetComponent <PlayerSquadFSM>().AliveChildCount() > 0) { return(false); } } return(true); }
public void ActionSpawnCaptain() { // Squad Cpt can only spawn one instance. if (PlayerSquadFSM.Instance.bIsAlive == true) { return; } // Prohibit spawning of squad captain before it is permitted if (Tutorial.bIsTutorial && Tutorial.Instance() != null && Tutorial.Instance().tutorialState < TutorialState.SquadCaptainSpawnWaiting) { return; } // Child count criteria met. if (TotalActiveChildInNodes() >= Settings.s_nPlayerSqaudCaptainChildCost) { int childrenLeftToConsume = Settings.s_nPlayerSqaudCaptainChildCost; Node_Manager leftNode = Node_Manager.GetNode(Node.LeftNode); Node_Manager rightNode = Node_Manager.GetNode(Node.RightNode); // Left node more than right. if (leftNode.activeChildCount > rightNode.activeChildCount) { // Use up cells in smaller node, OR till half of spawn cost. for (int i = 0; i < Settings.s_nPlayerSqaudCaptainChildCost / 2; i++) { // Kill them. int poolId = PlayerChildFSM.childrenInRightNode[i]; if (poolId == -1) { break; } PlayerChildFSM.playerChildPool[poolId].SacrificeToSquadCpt(); rightNode.SendChildToAttack(poolId); childrenLeftToConsume--; } // Consume the remaining needed children. for (int i = 0; i < Settings.s_nPlayerSqaudCaptainChildCost; i++) { // Kill them. int poolId = PlayerChildFSM.childrenInLeftNode[i]; if (poolId == -1) { break; } PlayerChildFSM.playerChildPool[poolId].SacrificeToSquadCpt(); leftNode.SendChildToAttack(poolId); childrenLeftToConsume--; if (childrenLeftToConsume == 0) { break; } } } // Right node more than left or equal numbers. else { // Use up cells in smaller node, OR till half of spawn cost. for (int i = 0; i < Settings.s_nPlayerSqaudCaptainChildCost / 2; i++) { // Kill them. int poolId = PlayerChildFSM.childrenInLeftNode[i]; if (poolId == -1) { break; } PlayerChildFSM.playerChildPool[poolId].SacrificeToSquadCpt(); leftNode.SendChildToAttack(poolId); childrenLeftToConsume--; } // Consume the remaining needed children. for (int i = 0; i < Settings.s_nPlayerSqaudCaptainChildCost; i++) { // Kill them. int poolId = PlayerChildFSM.childrenInRightNode[i]; if (poolId == -1) { break; } PlayerChildFSM.playerChildPool[poolId].SacrificeToSquadCpt(); rightNode.SendChildToAttack(poolId); childrenLeftToConsume--; if (childrenLeftToConsume == 0) { break; } } } // Spawn in the Squad Captain. Vector3 spawnPos = m_SquadCaptainNode.position; spawnPos.z = 0.0f; PlayerSquadFSM.Instance.Initialise(spawnPos); PlayerMain.Instance.animate.ExpandContract(1.0f, 1, 1.75f); // Update tutorial state if (Tutorial.Instance() != null && Tutorial.Instance().tutorialState == TutorialState.SquadCaptainSpawnWaiting) { Tutorial.Instance().tutorialState = TutorialState.SquadCaptainSpawnCompleted; } } else { infoText.text = "Not enough\nchild cells\n\nNeeded:\n" + Settings.s_nPlayerSqaudCaptainChildCost + " cells"; PresentInfoPanel(); SetSpawnCtrlVisibility(false); } UpdateUI_nodeChildCountText(); }
public void ActionDefendAvoid(Node _selectedNode) { Node_Manager.GetNode(_selectedNode).ToggleDefenseAvoid(); }
public void UpdateUI_nodeChildCountText() { leftNodeChildText.text = Node_Manager.GetNode(Node.LeftNode).activeChildCount.ToString(); rightNodeChildText.text = Node_Manager.GetNode(Node.RightNode).activeChildCount.ToString(); }